Skip to content

Commit 3de1591

Browse files
authored
refactor(bitflags): Simplify and improve setup for DAMAGE_TYPE_FLAGS_ALL, DISABLEDMASK_ALL, KINDOFMASK_FS (TheSuperHackers#2159)
1 parent f244a23 commit 3de1591

17 files changed

Lines changed: 65 additions & 129 deletions

File tree

Generals/Code/GameEngine/Include/Common/BitFlags.h

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,21 @@ class BitFlags
5858
/*
5959
just a little syntactic sugar so that there is no "foo = 0" compatible constructor
6060
*/
61-
enum BogusInitType
62-
{
63-
kInit = 0
64-
};
61+
enum BogusInitType { kInit };
62+
enum InitSetAllType { kInitSetAll };
6563

6664
BitFlags()
6765
{
6866
}
6967

68+
// This constructor sets all bits to 1
69+
BitFlags(InitSetAllType)
70+
{
71+
m_bits.set();
72+
}
73+
74+
// TheSuperHackers @todo Replace with variadic template
75+
7076
BitFlags(BogusInitType k, Int idx1)
7177
{
7278
m_bits.set(idx1);
@@ -102,33 +108,15 @@ class BitFlags
102108
m_bits.set(idx5);
103109
}
104110

105-
BitFlags(BogusInitType k,
106-
Int idx1,
107-
Int idx2,
108-
Int idx3,
109-
Int idx4,
110-
Int idx5,
111-
Int idx6,
112-
Int idx7,
113-
Int idx8,
114-
Int idx9,
115-
Int idx10,
116-
Int idx11,
117-
Int idx12
118-
)
111+
// Set all given indices in the array.
112+
BitFlags(BogusInitType, const Int* idxs, Int count)
119113
{
120-
m_bits.set(idx1);
121-
m_bits.set(idx2);
122-
m_bits.set(idx3);
123-
m_bits.set(idx4);
124-
m_bits.set(idx5);
125-
m_bits.set(idx6);
126-
m_bits.set(idx7);
127-
m_bits.set(idx8);
128-
m_bits.set(idx9);
129-
m_bits.set(idx10);
130-
m_bits.set(idx11);
131-
m_bits.set(idx12);
114+
const Int* idx = idxs;
115+
const Int* end = idxs + count;
116+
for (; idx < end; ++idx)
117+
{
118+
m_bits.set(*idx);
119+
}
132120
}
133121

134122
Bool operator==(const BitFlags& that) const

Generals/Code/GameEngine/Include/Common/DisabledTypes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,3 @@ inline void FLIP_DISABLEDMASK(DisabledMaskType& m)
105105
extern const char *TheDisabledNames[];
106106
extern DisabledMaskType DISABLEDMASK_NONE; // inits to all zeroes
107107
extern DisabledMaskType DISABLEDMASK_ALL; // inits to all bits set.
108-
void initDisabledMasks();

Generals/Code/GameEngine/Include/Common/ModelState.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ typedef BitFlags<MODELCONDITION_COUNT> ModelConditionFlags;
222222
#define MAKE_MODELCONDITION_MASK3(k,a,b) ModelConditionFlags(ModelConditionFlags::kInit, (k), (a), (b))
223223
#define MAKE_MODELCONDITION_MASK4(k,a,b,c) ModelConditionFlags(ModelConditionFlags::kInit, (k), (a), (b), (c))
224224
#define MAKE_MODELCONDITION_MASK5(k,a,b,c,d) ModelConditionFlags(ModelConditionFlags::kInit, (k), (a), (b), (c), (d))
225-
#define MAKE_MODELCONDITION_MASK12(a,b,c,d,e,f,g,h,i,j,k,l) ModelConditionFlags(ModelConditionFlags::kInit, (a), (b), (c), (d), (e), (f), (g), (h), (i), (j), (k), (l))
226225

227226
//-------------------------------------------------------------------------------------------------
228227

Generals/Code/GameEngine/Source/Common/GameEngine.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,6 @@ void GameEngine::init()
564564
if(!TheGlobalData->m_playIntro)
565565
TheWritableGlobalData->m_afterIntro = TRUE;
566566

567-
initDisabledMasks();
568-
569567
}
570568
catch (ErrorCode ec)
571569
{
@@ -590,8 +588,6 @@ void GameEngine::init()
590588
if(!TheGlobalData->m_playIntro)
591589
TheWritableGlobalData->m_afterIntro = TRUE;
592590

593-
initDisabledMasks();
594-
595591
resetSubsystems();
596592

597593
HideControlBar();

Generals/Code/GameEngine/Source/Common/System/DisabledTypes.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,4 @@ const char* const DisabledMaskType::s_bitNameList[] =
5050
static_assert(ARRAY_SIZE(DisabledMaskType::s_bitNameList) == DisabledMaskType::NumBits + 1, "Incorrect array size");
5151

5252
DisabledMaskType DISABLEDMASK_NONE; // inits to all zeroes
53-
DisabledMaskType DISABLEDMASK_ALL;
54-
55-
void initDisabledMasks()
56-
{
57-
SET_ALL_DISABLEDMASK_BITS( DISABLEDMASK_ALL );
58-
}
53+
DisabledMaskType DISABLEDMASK_ALL(DisabledMaskType::kInitSetAll);

GeneralsMD/Code/GameEngine/Include/Common/BitFlags.h

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,21 @@ class BitFlags
5858
/*
5959
just a little syntactic sugar so that there is no "foo = 0" compatible constructor
6060
*/
61-
enum BogusInitType
62-
{
63-
kInit = 0
64-
};
61+
enum BogusInitType { kInit };
62+
enum InitSetAllType { kInitSetAll };
6563

6664
BitFlags()
6765
{
6866
}
6967

68+
// This constructor sets all bits to 1
69+
BitFlags(InitSetAllType)
70+
{
71+
m_bits.set();
72+
}
73+
74+
// TheSuperHackers @todo Replace with variadic template
75+
7076
BitFlags(BogusInitType k, Int idx1)
7177
{
7278
m_bits.set(idx1);
@@ -102,33 +108,15 @@ class BitFlags
102108
m_bits.set(idx5);
103109
}
104110

105-
BitFlags(BogusInitType k,
106-
Int idx1,
107-
Int idx2,
108-
Int idx3,
109-
Int idx4,
110-
Int idx5,
111-
Int idx6,
112-
Int idx7,
113-
Int idx8,
114-
Int idx9,
115-
Int idx10,
116-
Int idx11,
117-
Int idx12
118-
)
111+
// Set all given indices in the array.
112+
BitFlags(BogusInitType, const Int* idxs, Int count)
119113
{
120-
m_bits.set(idx1);
121-
m_bits.set(idx2);
122-
m_bits.set(idx3);
123-
m_bits.set(idx4);
124-
m_bits.set(idx5);
125-
m_bits.set(idx6);
126-
m_bits.set(idx7);
127-
m_bits.set(idx8);
128-
m_bits.set(idx9);
129-
m_bits.set(idx10);
130-
m_bits.set(idx11);
131-
m_bits.set(idx12);
114+
const Int* idx = idxs;
115+
const Int* end = idxs + count;
116+
for (; idx < end; ++idx)
117+
{
118+
m_bits.set(*idx);
119+
}
132120
}
133121

134122
Bool operator==(const BitFlags& that) const

GeneralsMD/Code/GameEngine/Include/Common/DisabledTypes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,3 @@ inline void FLIP_DISABLEDMASK(DisabledMaskType& m)
110110
// defined in Common/System/DisabledTypes.cpp
111111
extern DisabledMaskType DISABLEDMASK_NONE; // inits to all zeroes
112112
extern DisabledMaskType DISABLEDMASK_ALL; // inits to all bits set.
113-
void initDisabledMasks();

GeneralsMD/Code/GameEngine/Include/Common/KindOf.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,3 @@ inline void FLIP_KINDOFMASK(KindOfMaskType& m)
215215
// defined in Common/System/Kindof.cpp
216216
extern KindOfMaskType KINDOFMASK_NONE; // inits to all zeroes
217217
extern KindOfMaskType KINDOFMASK_FS; // Initializes all FS types for faction structures.
218-
void initKindOfMasks();

GeneralsMD/Code/GameEngine/Include/Common/ModelState.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ typedef BitFlags<MODELCONDITION_COUNT> ModelConditionFlags;
250250
#define MAKE_MODELCONDITION_MASK3(k,a,b) ModelConditionFlags(ModelConditionFlags::kInit, (k), (a), (b))
251251
#define MAKE_MODELCONDITION_MASK4(k,a,b,c) ModelConditionFlags(ModelConditionFlags::kInit, (k), (a), (b), (c))
252252
#define MAKE_MODELCONDITION_MASK5(k,a,b,c,d) ModelConditionFlags(ModelConditionFlags::kInit, (k), (a), (b), (c), (d))
253-
#define MAKE_MODELCONDITION_MASK12(a,b,c,d,e,f,g,h,i,j,k,l) ModelConditionFlags(ModelConditionFlags::kInit, (a), (b), (c), (d), (e), (f), (g), (h), (i), (j), (k), (l))
254253

255254
//-------------------------------------------------------------------------------------------------
256255

GeneralsMD/Code/GameEngine/Include/GameLogic/Damage.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ inline void SET_ALL_DAMAGE_TYPE_BITS(DamageTypeFlags& m)
155155

156156
extern DamageTypeFlags DAMAGE_TYPE_FLAGS_NONE;
157157
extern DamageTypeFlags DAMAGE_TYPE_FLAGS_ALL;
158-
void initDamageTypeFlags();
159158

160159

161160
//-------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)