ref: b49d3acf2cf1329d5f678bf5c042bd4623d67e8a
parent: 42d5bfae5f19aab48e6078e151fc00889843dce7
parent: 0e0cbf94092ff15adcb179efbb7a76582ceb188d
author: Clownacy <Clownacy@users.noreply.github.com>
date: Wed May 15 11:49:54 EDT 2019
Merge pull request #32 from GabrielRavier/makeFlagsMacros Make some of the Flags.cpp stuff simpler
--- a/src/Flags.cpp
+++ b/src/Flags.cpp
@@ -4,6 +4,12 @@
#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 gSkipFlag[8];
@@ -21,17 +27,17 @@
// NPC flags
void SetNPCFlag(long a)
{
- gFlagNPC[a / 8] |= 1 << a % 8;
+ SET_FLAG(gFlagNPC, a);
}
void CutNPCFlag(long a)
{
- gFlagNPC[a / 8] &= ~(1 << a % 8);
+ UNSET_FLAG(gFlagNPC, a);
}
BOOL GetNPCFlag(long a)
{
- if (gFlagNPC[a / 8] & (1 << a % 8))
+ if (GET_FLAG(gFlagNPC, a))
return TRUE;
else
return FALSE;
@@ -40,17 +46,17 @@
// Skip flags
void SetSkipFlag(long a)
{
- gSkipFlag[a / 8] |= 1 << a % 8;
+ SET_FLAG(gSkipFlag, a);
}
void CutSkipFlag(long a)
{
- gSkipFlag[a / 8] &= ~(1 << a % 8);
+ UNSET_FLAG(gSkipFlag, a);
}
BOOL GetSkipFlag(long a)
{
- if (gSkipFlag[a / 8] & (1 << a % 8))
+ if (GET_FLAG(gSkipFlag, a))
return TRUE;
else
return FALSE;