|
12 | 12 | } |
13 | 13 | #define SetT(type, cond) if (IsType(type)) SetType(type, cond) |
14 | 14 |
|
15 | | -static inline void SetVars(int iBind, std::vector<BaseVar*>& vVars = G::Vars) |
| 15 | +// Optimized version - only processes the specific variable bound to this bind |
| 16 | +static inline void SetVars(int iBind, BaseVar* pVar) |
16 | 17 | { |
17 | | - const bool bDefault = iBind == DEFAULT_BIND; |
18 | | - for (auto pVar : vVars) |
19 | | - { |
20 | | - if (pVar->m_iFlags & (NOSAVE | NOBIND) && !bDefault) |
21 | | - continue; |
| 18 | + if (!pVar || (pVar->m_iFlags & (NOSAVE | NOBIND) && iBind != DEFAULT_BIND)) |
| 19 | + return; |
22 | 20 |
|
23 | | - SetT(bool, iBind) |
24 | | - else SetT(int, iBind) |
25 | | - else SetT(float, iBind) |
26 | | - else SetT(IntRange_t, iBind) |
27 | | - else SetT(FloatRange_t, iBind) |
28 | | - else SetT(std::string, iBind) |
29 | | - else SetT(VA_LIST(std::vector<std::pair<std::string, Color_t>>), iBind) |
30 | | - else SetT(Color_t, iBind) |
31 | | - else SetT(Gradient_t, iBind) |
32 | | - else SetT(Vec3, iBind) |
33 | | - else SetT(DragBox_t, iBind) |
34 | | - else SetT(WindowBox_t, iBind) |
35 | | - } |
| 21 | + SetT(bool, iBind) |
| 22 | + else SetT(int, iBind) |
| 23 | + else SetT(float, iBind) |
| 24 | + else SetT(IntRange_t, iBind) |
| 25 | + else SetT(FloatRange_t, iBind) |
| 26 | + else SetT(std::string, iBind) |
| 27 | + else SetT(VA_LIST(std::vector<std::pair<std::string, Color_t>>), iBind) |
| 28 | + else SetT(Color_t, iBind) |
| 29 | + else SetT(Gradient_t, iBind) |
| 30 | + else SetT(Vec3, iBind) |
| 31 | + else SetT(DragBox_t, iBind) |
| 32 | + else SetT(WindowBox_t, iBind) |
36 | 33 | } |
37 | 34 |
|
38 | 35 | static inline void GetBinds(int iParent, CTFPlayer* pLocal, CTFWeaponBase* pWeapon, std::vector<Bind_t>& vBinds) |
@@ -113,7 +110,7 @@ static inline void GetBinds(int iParent, CTFPlayer* pLocal, CTFWeaponBase* pWeap |
113 | 110 |
|
114 | 111 | if (tBind.m_bActive) |
115 | 112 | { |
116 | | - SetVars(iBind, tBind.m_vVars); |
| 113 | + SetVars(iBind, tBind.m_pVar); |
117 | 114 | GetBinds(iBind, pLocal, pWeapon, vBinds); |
118 | 115 | } |
119 | 116 | } |
@@ -145,7 +142,23 @@ void CBinds::Run(CTFPlayer* pLocal, CTFWeaponBase* pWeapon) |
145 | 142 | tKey.m_bIsReleased = tKey.m_bIsReleased || bOldIsReleased; |
146 | 143 | } |
147 | 144 |
|
148 | | - SetVars(DEFAULT_BIND); |
| 145 | + // Set default bind values - iterate through all vars once |
| 146 | + for (auto pVar : G::Vars) |
| 147 | + { |
| 148 | + SetT(bool, DEFAULT_BIND) |
| 149 | + else SetT(int, DEFAULT_BIND) |
| 150 | + else SetT(float, DEFAULT_BIND) |
| 151 | + else SetT(IntRange_t, DEFAULT_BIND) |
| 152 | + else SetT(FloatRange_t, DEFAULT_BIND) |
| 153 | + else SetT(std::string, DEFAULT_BIND) |
| 154 | + else SetT(VA_LIST(std::vector<std::pair<std::string, Color_t>>), DEFAULT_BIND) |
| 155 | + else SetT(Color_t, DEFAULT_BIND) |
| 156 | + else SetT(Gradient_t, DEFAULT_BIND) |
| 157 | + else SetT(Vec3, DEFAULT_BIND) |
| 158 | + else SetT(DragBox_t, DEFAULT_BIND) |
| 159 | + else SetT(WindowBox_t, DEFAULT_BIND) |
| 160 | + } |
| 161 | + |
149 | 162 | GetBinds(DEFAULT_BIND, pLocal, pWeapon, m_vBinds); |
150 | 163 |
|
151 | 164 | for (auto it = m_vBinds.begin(); it < m_vBinds.end(); it++) |
|
0 commit comments