MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / Load

Method Load

engine/Poseidon/UI/Settings/ControlsConfig.cpp:63–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61}
62
63bool ControlsConfig::Load(const std::string& path)
64{
65 std::error_code ec;
66 if (!std::filesystem::exists(path, ec))
67 return false;
68
69 ParamFile cfg;
70 cfg.Parse(RString(path.c_str()));
71
72 UserActionDesc* descs = InputSubsystem::GetUserActionDesc();
73 for (int i = 0; i < UAN; i++)
74 {
75 const ParamEntry* entry = cfg.FindEntry(KeyName(descs[i]));
76 if (entry)
77 {
78 AutoArray<int>& slot = bindings[i];
79 slot.Resize(0);
80 int n = entry->GetSize();
81 for (int j = 0; j < n; j++)
82 {
83 int code = (*entry)[j];
84 // Defensive: drop joystick-class entries that somehow
85 // ended up in controls.cfg (legacy file pre-split).
86 // They'll be re-loaded from gamepad.cfg.
87 if (code != -1 && IsKbmCode(code))
88 slot.Add(code);
89 }
90 slot.Compact();
91 }
92
93 // Modifiers are optional in the file; default to -1 per binding
94 // when missing so old configs (no _mod lines) still load.
95 AutoArray<int>& mods = modifiers[i];
96 mods.Resize(0);
97 const ParamEntry* modEntry = cfg.FindEntry(ModName(descs[i]));
98 if (modEntry)
99 {
100 int n = modEntry->GetSize();
101 for (int j = 0; j < n; j++)
102 mods.Add((int)(*modEntry)[j]);
103 }
104 // Pad / truncate so the parallel array exactly matches the
105 // primary binding list length.
106 while (mods.Size() < bindings[i].Size())
107 mods.Add(-1);
108 if (mods.Size() > bindings[i].Size())
109 mods.Resize(bindings[i].Size());
110 mods.Compact();
111 }
112 return true;
113}
114
115bool ControlsConfig::Save(const std::string& path) const
116{

Callers

nothing calls this directly

Calls 11

KeyNameFunction · 0.85
IsKbmCodeFunction · 0.85
ModNameFunction · 0.85
RStringClass · 0.50
ParseMethod · 0.45
FindEntryMethod · 0.45
ResizeMethod · 0.45
GetSizeMethod · 0.45
AddMethod · 0.45
CompactMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected