Skip to content

Commit b3d5493

Browse files
committed
input: restore original defaults when changing pad handlers
This fixes the vibration threshold being 0 when going to DS3 and back. Probably also fixes a lot of other tiny bugs.
1 parent 735588a commit b3d5493

File tree

5 files changed

+102
-23
lines changed

5 files changed

+102
-23
lines changed

Utilities/Config.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -553,19 +553,12 @@ void cfg::node::from_default()
553553
}
554554
}
555555

556-
void cfg::_bool::from_default()
556+
void cfg::node::restore_defaults()
557557
{
558-
m_value = def;
559-
}
560-
561-
void cfg::string::from_default()
562-
{
563-
m_value = def;
564-
}
565-
566-
void cfg::set_entry::from_default()
567-
{
568-
m_set = {};
558+
for (auto& node : m_nodes)
559+
{
560+
node->restore_defaults();
561+
}
569562
}
570563

571564
std::string cfg::map_entry::get_value(std::string_view key)

Utilities/Config.h

Lines changed: 80 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ namespace cfg
9090
// Reset defaults
9191
virtual void from_default() = 0;
9292

93+
// Restore default members
94+
virtual void restore_defaults() = 0;
95+
9396
// Convert to string (optional)
9497
virtual std::string to_string() const
9598
{
@@ -151,18 +154,23 @@ namespace cfg
151154

152155
// Set default values
153156
void from_default() override;
157+
158+
// Restore default members
159+
void restore_defaults() override;
154160
};
155161

156162
class _bool final : public _base
157163
{
158164
atomic_t<bool> m_value;
165+
bool original_def;
159166

160167
public:
161168
bool def;
162169

163170
_bool(node* owner, std::string name, bool def = false, bool dynamic = false)
164171
: _base(type::_bool, owner, std::move(name), dynamic)
165172
, m_value(def)
173+
, original_def(def)
166174
, def(def)
167175
{
168176
}
@@ -177,7 +185,15 @@ namespace cfg
177185
return m_value;
178186
}
179187

180-
void from_default() override;
188+
void from_default() override
189+
{
190+
m_value = def;
191+
}
192+
193+
void restore_defaults() override
194+
{
195+
def = original_def;
196+
}
181197

182198
std::string to_string() const override
183199
{
@@ -220,14 +236,16 @@ namespace cfg
220236
class _enum : public _base
221237
{
222238
atomic_t<T> m_value;
239+
T original_def;
223240

224241
public:
225-
const T def;
242+
T def;
226243

227-
_enum(node* owner, const std::string& name, T value = {}, bool dynamic = false)
244+
_enum(node* owner, const std::string& name, T def = {}, bool dynamic = false)
228245
: _base(type::_enum, owner, name, dynamic)
229-
, m_value(value)
230-
, def(value)
246+
, m_value(def)
247+
, original_def(def)
248+
, def(def)
231249
{
232250
}
233251

@@ -256,6 +274,11 @@ namespace cfg
256274
m_value = def;
257275
}
258276

277+
void restore_defaults() override
278+
{
279+
def = original_def;
280+
}
281+
259282
std::string to_string() const override
260283
{
261284
std::string result;
@@ -300,6 +323,7 @@ namespace cfg
300323
using int_type = std::conditional_t<Min >= s32{smin} && Max <= s32{smax}, s32, s64>;
301324

302325
atomic_t<int_type> m_value;
326+
int_type original_def;
303327

304328
public:
305329
int_type def;
@@ -311,6 +335,7 @@ namespace cfg
311335
_int(node* owner, const std::string& name, int_type def = std::min<int_type>(Max, std::max<int_type>(Min, 0)), bool dynamic = false)
312336
: _base(type::_int, owner, name, dynamic)
313337
, m_value(def)
338+
, original_def(def)
314339
, def(def)
315340
{
316341
}
@@ -330,6 +355,11 @@ namespace cfg
330355
m_value = def;
331356
}
332357

358+
void restore_defaults() override
359+
{
360+
def = original_def;
361+
}
362+
333363
std::string to_string() const override
334364
{
335365
return std::to_string(m_value);
@@ -372,6 +402,7 @@ namespace cfg
372402

373403
using float_type = f64;
374404
atomic_t<float_type> m_value;
405+
float_type original_def;
375406

376407
public:
377408
float_type def;
@@ -383,6 +414,7 @@ namespace cfg
383414
_float(node* owner, const std::string& name, float_type def = std::min<float_type>(Max, std::max<float_type>(Min, 0)), bool dynamic = false)
384415
: _base(type::_int, owner, name, dynamic)
385416
, m_value(def)
417+
, original_def(def)
386418
, def(def)
387419
{
388420
}
@@ -402,6 +434,11 @@ namespace cfg
402434
m_value = def;
403435
}
404436

437+
void restore_defaults() override
438+
{
439+
def = original_def;
440+
}
441+
405442
std::string to_string() const override
406443
{
407444
std::string result;
@@ -464,6 +501,7 @@ namespace cfg
464501
using int_type = std::conditional_t<Max <= u32{umax}, u32, u64>;
465502

466503
atomic_t<int_type> m_value;
504+
int_type original_def;
467505

468506
public:
469507
int_type def;
@@ -475,6 +513,7 @@ namespace cfg
475513
uint(node* owner, const std::string& name, int_type def = std::max<int_type>(Min, 0), bool dynamic = false)
476514
: _base(type::uint, owner, name, dynamic)
477515
, m_value(def)
516+
, original_def(def)
478517
, def(def)
479518
{
480519
}
@@ -494,6 +533,11 @@ namespace cfg
494533
m_value = def;
495534
}
496535

536+
void restore_defaults() override
537+
{
538+
def = original_def;
539+
}
540+
497541
std::string to_string() const override
498542
{
499543
return std::to_string(m_value);
@@ -538,13 +582,15 @@ namespace cfg
538582
class string : public _base
539583
{
540584
atomic_ptr<std::string> m_value;
585+
std::string original_def;
541586

542587
public:
543588
std::string def;
544589

545590
string(node* owner, std::string name, std::string def = {}, bool dynamic = false)
546591
: _base(type::string, owner, std::move(name), dynamic)
547592
, m_value(def)
593+
, original_def(def)
548594
, def(std::move(def))
549595
{
550596
}
@@ -554,7 +600,15 @@ namespace cfg
554600
return *m_value.load().get();
555601
}
556602

557-
void from_default() override;
603+
void from_default() override
604+
{
605+
m_value = def;
606+
}
607+
608+
void restore_defaults() override
609+
{
610+
def = original_def;
611+
}
558612

559613
std::string to_string() const override
560614
{
@@ -595,7 +649,14 @@ namespace cfg
595649
m_set = std::move(set);
596650
}
597651

598-
void from_default() override;
652+
void from_default() override
653+
{
654+
m_set = {};
655+
}
656+
657+
void restore_defaults() override
658+
{
659+
}
599660

600661
std::vector<std::string> to_list() const override
601662
{
@@ -636,6 +697,10 @@ namespace cfg
636697
void erase(std::string_view key);
637698

638699
void from_default() override;
700+
701+
void restore_defaults() override
702+
{
703+
}
639704
};
640705

641706
class node_map_entry final : public map_entry
@@ -665,6 +730,10 @@ namespace cfg
665730
void set_map(map_of_type<logs::level>&& map);
666731

667732
void from_default() override;
733+
734+
void restore_defaults() override
735+
{
736+
}
668737
};
669738

670739
struct device_info
@@ -702,5 +771,9 @@ namespace cfg
702771
void set_map(map_of_type<device_info>&& map);
703772

704773
void from_default() override;
774+
775+
void restore_defaults() override
776+
{
777+
}
705778
};
706779
}

rpcs3/Emu/Io/PadHandler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ void PadHandlerBase::init_configs()
200200
{
201201
for (u32 i = 0; i < MAX_GAMEPADS; i++)
202202
{
203+
// We need to restore the original defaults first.
204+
m_pad_configs[i].restore_defaults();
205+
206+
// Set and apply actual defaults depending on pad handler
203207
init_config(&m_pad_configs[i]);
204208
}
205209
}

rpcs3/Input/gui_pad_thread.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,18 @@ std::shared_ptr<PadHandlerBase> gui_pad_thread::GetHandler(pad_handler type)
234234

235235
void gui_pad_thread::InitPadConfig(cfg_pad& cfg, pad_handler type, std::shared_ptr<PadHandlerBase>& handler)
236236
{
237+
// We need to restore the original defaults first.
238+
cfg.restore_defaults();
239+
237240
if (!handler)
238241
{
239242
handler = GetHandler(type);
243+
}
240244

241-
if (handler)
242-
{
243-
handler->init_config(&cfg);
244-
}
245+
if (handler)
246+
{
247+
// Set and apply actual defaults depending on pad handler
248+
handler->init_config(&cfg);
245249
}
246250
}
247251

rpcs3/Input/pad_thread.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,12 +883,17 @@ std::shared_ptr<PadHandlerBase> pad_thread::GetHandler(pad_handler type)
883883

884884
void pad_thread::InitPadConfig(cfg_pad& cfg, pad_handler type, std::shared_ptr<PadHandlerBase>& handler)
885885
{
886+
// We need to restore the original defaults first.
887+
cfg.restore_defaults();
888+
886889
if (!handler)
887890
{
888891
handler = GetHandler(type);
889892
}
890893

891894
ensure(!!handler);
895+
896+
// Set and apply actual defaults depending on pad handler
892897
handler->init_config(&cfg);
893898
}
894899

0 commit comments

Comments
 (0)