From 40dcd65afa6b4b1f96f8e1e6ecfc99fd27366971 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sun, 13 Oct 2013 18:49:54 -0700 Subject: [PATCH] Generalize the getGameState functions. --- sc2/src/uqm/globdata.c | 26 +++++++++++++------------- sc2/src/uqm/globdata.h | 20 ++++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/sc2/src/uqm/globdata.c b/sc2/src/uqm/globdata.c index 20e39a470..a387313c1 100644 --- a/sc2/src/uqm/globdata.c +++ b/sc2/src/uqm/globdata.c @@ -48,31 +48,31 @@ GLOBDATA GlobData; BYTE -getGameState (int startBit, int endBit) +getGameState (BYTE *state, int startBit, int endBit) { return (BYTE) (((startBit >> 3) == (endBit >> 3) - ? (GLOBAL (GameState[startBit >> 3]) >> (startBit & 7)) - : ((GLOBAL (GameState[startBit >> 3]) >> (startBit & 7)) - | (GLOBAL (GameState[endBit >> 3]) + ? (state[startBit >> 3] >> (startBit & 7)) + : ((state[startBit >> 3] >> (startBit & 7)) + | (state[endBit >> 3] << (endBit - startBit - (endBit & 7))))) & ((1 << (endBit - startBit + 1)) - 1)); } void -setGameState (int startBit, int endBit, BYTE val +setGameState (BYTE *state, int startBit, int endBit, BYTE val #ifdef STATE_DEBUG , const char *name #endif ) { - GLOBAL (GameState[startBit >> 3]) = - (GLOBAL (GameState[startBit >> 3]) + state[startBit >> 3] = + (state[startBit >> 3] & (BYTE) ~(((1 << (endBit - startBit + 1)) - 1) << (startBit & 7))) | (BYTE)((val) << (startBit & 7)); if ((startBit >> 3) < (endBit >> 3)) { - GLOBAL (GameState[endBit >> 3]) = - (GLOBAL (GameState[endBit >> 3]) + state[endBit >> 3] = + (state[endBit >> 3] & (BYTE)~((1 << ((endBit & 7) + 1)) - 1)) | (BYTE)((val) >> (endBit - startBit - (endBit & 7))); } @@ -82,21 +82,21 @@ setGameState (int startBit, int endBit, BYTE val } DWORD -getGameState32 (int startBit) +getGameState32 (BYTE *state, int startBit) { DWORD v; int shift; for (v = 0, shift = 0; shift < 32; shift += 8, startBit += 8) { - v |= getGameState (startBit, startBit + 7) << shift; + v |= getGameState (state, startBit, startBit + 7) << shift; } return v; } void -setGameState32 (int startBit, DWORD val +setGameState32 (BYTE *state, int startBit, DWORD val #ifdef STATE_DEBUG , const char *name #endif @@ -107,7 +107,7 @@ setGameState32 (int startBit, DWORD val for (i = 0; i < 4; ++i, v >>= 8, startBit += 8) { - setGameState (startBit, startBit + 7, v & 0xff + setGameState (state, startBit, startBit + 7, v & 0xff #ifdef STATE_DEBUG , "(ignored)" #endif diff --git a/sc2/src/uqm/globdata.h b/sc2/src/uqm/globdata.h index 031b57df7..60b528b83 100644 --- a/sc2/src/uqm/globdata.h +++ b/sc2/src/uqm/globdata.h @@ -972,36 +972,36 @@ extern GLOBDATA GlobData; //#define STATE_DEBUG -extern BYTE getGameState (int startBit, int endBit); -extern void setGameState (int startBit, int endBit, BYTE val +extern BYTE getGameState (BYTE *state, int startBit, int endBit); +extern void setGameState (BYTE *state, int startBit, int endBit, BYTE val #ifdef STATE_DEBUG , const char *name #endif ); -#define GET_GAME_STATE(SName) getGameState ((SName), (END_##SName)) +#define GET_GAME_STATE(SName) getGameState (GLOBAL(GameState), (SName), (END_##SName)) #ifdef STATE_DEBUG # define SET_GAME_STATE(SName, val) \ - setGameState ((SName), (END_##SName), (val), #SName) + setGameState (GLOBAL(GameState), (SName), (END_##SName), (val), #SName) #else # define SET_GAME_STATE(SName, val) \ - setGameState ((SName), (END_##SName), (val)) + setGameState (GLOBAL(GameState), (SName), (END_##SName), (val)) #endif -extern DWORD getGameState32 (int startBit); -extern void setGameState32 (int startBit, DWORD val +extern DWORD getGameState32 (BYTE *state, int startBit); +extern void setGameState32 (BYTE *state, int startBit, DWORD val #ifdef STATE_DEBUG , const char *name #endif ); -#define GET_GAME_STATE_32(SName) getGameState32 ((SName)) +#define GET_GAME_STATE_32(SName) getGameState32 (GLOBAL(GameState), (SName)) #ifdef STATE_DEBUG # define SET_GAME_STATE_32(SName, val) \ - setGameState32 ((SName), (val), #SName) + setGameState32 (GLOBAL(GameState), (SName), (val), #SName) #else # define SET_GAME_STATE_32(SName, val) \ - setGameState32 ((SName), (val)) + setGameState32 (GLOBAL(GameState), (SName), (val)) #endif