I'm in the process of reworking a bit field that I built to condense a collection of rule activation flags for a game I'm working on. I need to change the "multiplierRule" so that it can represent 2 different variations of the same rule as well as an "inactive" state.
This is the current definition of the field:
#define RuleActive 1
#define RuleInactive !RuleActive
union bitFlags {
unsigned short flagGroup; //provide a 16-bit backbone (on 32-bit systems)
struct { //the bit field
unsigned multiplierRule : 1; //multiples-of-a-kind rule,
//"on" causes values to be 2x,3x,4x three-of-a-kind value resp.
unsigned straightRule : 1; //"on" activates bonus for a straight in a single roll
unsigned threePairRule : 1; //"on" activates bonus for three pairs in a single roll
unsigned hardWinRule : 1; //"on" activates the hard win rule-set
}; //close the bit field structure
}; //close the union
#endif // BITFLAGS_H
In theory, if I change the definition of "multiplierRule" to multiplierRule : 2;
that should allow me to store the values -1, 0, 1 but it won't compile. Is there a different keyword that I need to use in place of "unsigned"? I used "signed" and it seems to work, but it appears to be expanding the field out to 32-bits, it's really not a big deal, but I would prefer to keep it 16-bits if I can.
I know I can just expand the unsigned field to 2 bits then use the values 0,1,2,3 to represent different statuses, and I still may, but I figure I may as well figure this out if I can.
I've done a couple google searches, but mostly I'm finding discussion about other methods that are supposedly more efficient. Nothing I saw really touches on storing negative values in fields that are length > 1.
Any suggestions would be greatly appreciated.