Merge pull request #32 from GabrielRavier/makeFlagsMacros

Make some of the Flags.cpp stuff simpler
This commit is contained in:
Clownacy 2019-05-15 15:49:54 +00:00 committed by GitHub
commit b49d3acf2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,12 @@
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
// Macros for setting, un-setting and getting flags
// Each flag is stored in a bit, so we can use the exact same macros we'd use for bits
#define SET_FLAG(x, i) ((x)[(i) / 8] |= 1 << (i) % 8)
#define UNSET_FLAG(x, i) ((x)[(i) / 8] &= ~(1 << (i) % 8))
#define GET_FLAG(x, i) ((x)[(i) / 8] & (1 << (i) % 8))
unsigned char gFlagNPC[1000]; unsigned char gFlagNPC[1000];
unsigned char gSkipFlag[8]; unsigned char gSkipFlag[8];
@ -21,17 +27,17 @@ void InitSkipFlags()
// NPC flags // NPC flags
void SetNPCFlag(long a) void SetNPCFlag(long a)
{ {
gFlagNPC[a / 8] |= 1 << a % 8; SET_FLAG(gFlagNPC, a);
} }
void CutNPCFlag(long a) void CutNPCFlag(long a)
{ {
gFlagNPC[a / 8] &= ~(1 << a % 8); UNSET_FLAG(gFlagNPC, a);
} }
BOOL GetNPCFlag(long a) BOOL GetNPCFlag(long a)
{ {
if (gFlagNPC[a / 8] & (1 << a % 8)) if (GET_FLAG(gFlagNPC, a))
return TRUE; return TRUE;
else else
return FALSE; return FALSE;
@ -40,17 +46,17 @@ BOOL GetNPCFlag(long a)
// Skip flags // Skip flags
void SetSkipFlag(long a) void SetSkipFlag(long a)
{ {
gSkipFlag[a / 8] |= 1 << a % 8; SET_FLAG(gSkipFlag, a);
} }
void CutSkipFlag(long a) void CutSkipFlag(long a)
{ {
gSkipFlag[a / 8] &= ~(1 << a % 8); UNSET_FLAG(gSkipFlag, a);
} }
BOOL GetSkipFlag(long a) BOOL GetSkipFlag(long a)
{ {
if (gSkipFlag[a / 8] & (1 << a % 8)) if (GET_FLAG(gSkipFlag, a))
return TRUE; return TRUE;
else else
return FALSE; return FALSE;