mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-10 23:02:03 +00:00
- preparations for gamevar code replacement - thinning out of code that's to be removed
This commit is contained in:
parent
c28ea5792a
commit
d01d4bf44c
5 changed files with 56 additions and 265 deletions
|
@ -1161,7 +1161,7 @@ int parsecommand()
|
|||
ReportError(ERROR_NOTAGAMEDEF);
|
||||
return 0;
|
||||
}
|
||||
if (aGameVars[i].dwFlags & GAMEVAR_FLAG_READONLY)
|
||||
if (aaGameVars[i].dwFlags & GAMEVAR_FLAG_READONLY)
|
||||
{
|
||||
errorcount++;
|
||||
ReportError(ERROR_VARREADONLY);
|
||||
|
@ -1191,7 +1191,7 @@ int parsecommand()
|
|||
ReportError(ERROR_NOTAGAMEDEF);
|
||||
return 0;
|
||||
}
|
||||
if (aGameVars[i].dwFlags & GAMEVAR_FLAG_READONLY)
|
||||
if (aaGameVars[i].dwFlags & GAMEVAR_FLAG_READONLY)
|
||||
{
|
||||
errorcount++;
|
||||
ReportError(ERROR_VARREADONLY);
|
||||
|
|
|
@ -46,17 +46,11 @@ enum GamevarFlags_t
|
|||
GAMEVAR_READONLY = 0x00001000, // values are read-only (no setvar allowed)
|
||||
GAMEVAR_INT32PTR = 0x00002000, // plValues is a pointer to an int32_t
|
||||
GAMEVAR_INT16PTR = 0x00008000, // plValues is a pointer to a short
|
||||
GAMEVAR_NORESET = 0x00020000, // var values are not reset when restoring map state
|
||||
GAMEVAR_SPECIAL = 0x00040000, // flag for structure member shortcut vars
|
||||
GAMEVAR_NOMULTI = 0x00080000, // don't attach to multiplayer packets
|
||||
GAMEVAR_Q16PTR = 0x00100000, // plValues is a pointer to a q16.16
|
||||
GAMEVAR_SERIALIZE = 0x00200000, // write into permasaves
|
||||
GAMEVAR_FLAG_DEFAULT = GAMEVAR_DEFAULT,
|
||||
GAMEVAR_FLAG_SECRET = 0x200, // placeholder
|
||||
GAMEVAR_FLAG_READONLY = 0x1000, // placeholder
|
||||
|
||||
GAMEVAR_RAWQ16PTR = GAMEVAR_Q16PTR | GAMEVAR_SPECIAL, // plValues is a pointer to a q16.16 but we don't want conversion
|
||||
GAMEVAR_PTR_MASK = GAMEVAR_INT32PTR | GAMEVAR_INT16PTR | GAMEVAR_Q16PTR | GAMEVAR_RAWQ16PTR,
|
||||
GAMEVAR_PTR_MASK = GAMEVAR_INT32PTR | GAMEVAR_INT16PTR,
|
||||
};
|
||||
|
||||
// Alignments for per-player and per-actor variables.
|
||||
|
@ -82,7 +76,7 @@ typedef struct
|
|||
} gamevar_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
extern gamevar_t aGameVars[MAXGAMEVARS];
|
||||
extern gamevar_t aaGameVars[MAXGAMEVARS];
|
||||
extern int32_t g_gameVarCount;
|
||||
|
||||
int __fastcall Gv_GetVar(int const gameVar, int const spriteNum, int const playerNum);
|
||||
|
@ -115,14 +109,6 @@ void Gv_NewVar(const char *pszLabel,intptr_t lValue,uint32_t dwFlags);
|
|||
|
||||
int GetDefID(const char* label);
|
||||
|
||||
static FORCE_INLINE void A_ResetVars(int const spriteNum)
|
||||
{
|
||||
for (auto &gv : aGameVars)
|
||||
{
|
||||
if ((gv.flags & (GAMEVAR_PERACTOR|GAMEVAR_NODEFAULT)) == GAMEVAR_PERACTOR)
|
||||
gv.pValues[spriteNum] = gv.defaultValue;
|
||||
}
|
||||
}
|
||||
void Gv_DumpValues(void);
|
||||
void Gv_InitWeaponPointers(void);
|
||||
void Gv_RefreshPointers(void);
|
||||
|
@ -138,7 +124,7 @@ void Gv_FinalizeWeaponDefaults(void);
|
|||
#define VM_GAMEVAR_OPERATOR(func, operator) \
|
||||
static FORCE_INLINE ATTRIBUTE((flatten)) void __fastcall func(int const id, int32_t const operand) \
|
||||
{ \
|
||||
auto &var = aGameVars[id]; \
|
||||
auto &var = aaGameVars[id]; \
|
||||
\
|
||||
switch (var.flags & (GAMEVAR_USER_MASK | GAMEVAR_PTR_MASK)) \
|
||||
{ \
|
||||
|
@ -152,13 +138,6 @@ void Gv_FinalizeWeaponDefaults(void);
|
|||
var.pValues[vm.spriteNum & (MAXSPRITES-1)] operator operand; \
|
||||
break; \
|
||||
case GAMEVAR_INT32PTR: *(int32_t *)var.pValues operator(int32_t) operand; break; \
|
||||
case GAMEVAR_INT16PTR: *(int16_t *)var.pValues operator(int16_t) operand; break; \
|
||||
case GAMEVAR_Q16PTR: \
|
||||
{ \
|
||||
Fix16 *pfix = (Fix16 *)var.global; \
|
||||
*pfix operator fix16_from_int(operand); \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ static FORCE_INLINE int32_t VM_EventInlineInternal__(int const eventNum, int con
|
|||
g_player[playerNum&(MAXPLAYERS-1)].ps,
|
||||
&actor[spriteNum&(MAXSPRITES-1)] };
|
||||
|
||||
auto &globalReturn = aGameVars[g_returnVarID].global;
|
||||
auto &globalReturn = aaGameVars[g_returnVarID].global;
|
||||
|
||||
struct
|
||||
{
|
||||
|
@ -2676,8 +2676,8 @@ GAMEEXEC_STATIC void VM_Execute(native_t loop)
|
|||
tw = *insptr++;
|
||||
int const nValue = Gv_GetVar(*insptr++);
|
||||
|
||||
if ((aGameVars[tw].flags & (GAMEVAR_USER_MASK | GAMEVAR_PTR_MASK)) == 0)
|
||||
aGameVars[tw].global = nValue;
|
||||
if ((aaGameVars[tw].flags & (GAMEVAR_USER_MASK | GAMEVAR_PTR_MASK)) == 0)
|
||||
aaGameVars[tw].global = nValue;
|
||||
else
|
||||
Gv_SetVar(tw, nValue);
|
||||
}
|
||||
|
@ -2738,18 +2738,18 @@ GAMEEXEC_STATIC void VM_Execute(native_t loop)
|
|||
continue;
|
||||
}
|
||||
}
|
||||
Bsprintf(tempbuf, "CONLOGVAR: L=%d %s ", VM_DECODE_LINE_NUMBER(g_tw), aGameVars[lVarID].szLabel);
|
||||
Bsprintf(tempbuf, "CONLOGVAR: L=%d %s ", VM_DECODE_LINE_NUMBER(g_tw), aaGameVars[lVarID].szLabel);
|
||||
|
||||
if (aGameVars[lVarID].flags & GAMEVAR_READONLY)
|
||||
if (aaGameVars[lVarID].flags & GAMEVAR_READONLY)
|
||||
{
|
||||
Bsprintf(szBuf, " (read-only)");
|
||||
Bstrcat(tempbuf, szBuf);
|
||||
}
|
||||
if (aGameVars[lVarID].flags & GAMEVAR_PERPLAYER)
|
||||
if (aaGameVars[lVarID].flags & GAMEVAR_PERPLAYER)
|
||||
{
|
||||
Bsprintf(szBuf, " (Per Player. Player=%d)", vm.playerNum);
|
||||
}
|
||||
else if (aGameVars[lVarID].flags & GAMEVAR_PERACTOR)
|
||||
else if (aaGameVars[lVarID].flags & GAMEVAR_PERACTOR)
|
||||
{
|
||||
Bsprintf(szBuf, " (Per Actor. Actor=%d)", vm.spriteNum);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ BEGIN_DUKE_NS
|
|||
|
||||
#define gamevars_c_
|
||||
|
||||
gamevar_t aGameVars[MAXGAMEVARS];
|
||||
gamevar_t aaGameVars[MAXGAMEVARS];
|
||||
int32_t g_gameVarCount = 0;
|
||||
|
||||
// pointers to weapon gamevar data
|
||||
|
@ -62,7 +62,7 @@ intptr_t *aplWeaponWorksLike[MAX_WEAPONS]; // What original the weapon work
|
|||
// Returns: old g_gameVarCount | (g_gameArrayCount<<16).
|
||||
int Gv_Free(void)
|
||||
{
|
||||
for (auto &gameVar : aGameVars)
|
||||
for (auto &gameVar : aaGameVars)
|
||||
{
|
||||
if (gameVar.flags & GAMEVAR_USER_MASK)
|
||||
ALIGNED_FREE_AND_NULL(gameVar.pValues);
|
||||
|
@ -86,175 +86,23 @@ void Gv_Clear(void)
|
|||
Gv_Free();
|
||||
|
||||
// Now, only do work that Gv_Free() hasn't done.
|
||||
for (auto & gameVar : aGameVars)
|
||||
for (auto & gameVar : aaGameVars)
|
||||
DO_FREE_AND_NULL(gameVar.szLabel);
|
||||
}
|
||||
|
||||
// Note that this entire function is totally architecture dependent and needs to be fixed (which won't be easy...)
|
||||
int Gv_ReadSave(FileReader &kFile)
|
||||
{
|
||||
char tbuf[12];
|
||||
|
||||
if (kFile.Read(tbuf, 12)!=12) goto corrupt;
|
||||
if (Bmemcmp(tbuf, "BEG: EDuke32", 12)) { Printf("BEG ERR\n"); return 2; }
|
||||
|
||||
Gv_Free(); // nuke 'em from orbit, it's the only way to be sure...
|
||||
|
||||
if (kFile.Read(&g_gameVarCount,sizeof(g_gameVarCount)) != sizeof(g_gameVarCount)) goto corrupt;
|
||||
for (bssize_t i=0; i<g_gameVarCount; i++)
|
||||
{
|
||||
char *const olabel = aGameVars[i].szLabel;
|
||||
|
||||
if (kFile.Read(&aGameVars[i], sizeof(gamevar_t)) != sizeof(gamevar_t))
|
||||
goto corrupt;
|
||||
|
||||
aGameVars[i].szLabel = (char *)Xrealloc(olabel, MAXVARLABEL * sizeof(uint8_t));
|
||||
|
||||
if (kFile.Read(aGameVars[i].szLabel, MAXVARLABEL) != MAXVARLABEL)
|
||||
goto corrupt;
|
||||
hash_add(&h_gamevars, aGameVars[i].szLabel,i, 1);
|
||||
|
||||
if (aGameVars[i].flags & GAMEVAR_PERPLAYER)
|
||||
{
|
||||
aGameVars[i].pValues = (intptr_t*)Xaligned_alloc(PLAYER_VAR_ALIGNMENT, MAXPLAYERS * sizeof(intptr_t));
|
||||
if (kFile.Read(aGameVars[i].pValues,sizeof(intptr_t) * MAXPLAYERS) != sizeof(intptr_t) * MAXPLAYERS) goto corrupt;
|
||||
}
|
||||
else if (aGameVars[i].flags & GAMEVAR_PERACTOR)
|
||||
{
|
||||
aGameVars[i].pValues = (intptr_t*)Xaligned_alloc(ACTOR_VAR_ALIGNMENT, MAXSPRITES * sizeof(intptr_t));
|
||||
if (kFile.Read(aGameVars[i].pValues,sizeof(intptr_t) * MAXSPRITES) != sizeof(intptr_t) * MAXSPRITES) goto corrupt;
|
||||
}
|
||||
}
|
||||
|
||||
Gv_InitWeaponPointers();
|
||||
|
||||
// Gv_RefreshPointers();
|
||||
|
||||
uint8_t savedstate[MAXVOLUMES*MAXLEVELS];
|
||||
Bmemset(savedstate, 0, sizeof(savedstate));
|
||||
|
||||
if (kFile.Read(savedstate, sizeof(savedstate)) != sizeof(savedstate)) goto corrupt;
|
||||
|
||||
for (bssize_t i = 0; i < (MAXVOLUMES * MAXLEVELS); i++)
|
||||
{
|
||||
G_FreeMapState(i);
|
||||
|
||||
if (!savedstate[i])
|
||||
continue;
|
||||
|
||||
g_mapInfo[i].savedstate = (mapstate_t *)Xaligned_alloc(ACTOR_VAR_ALIGNMENT, sizeof(mapstate_t));
|
||||
if (kFile.Read(g_mapInfo[i].savedstate, sizeof(mapstate_t)) != sizeof(mapstate_t)) return -8;
|
||||
|
||||
mapstate_t &sv = *g_mapInfo[i].savedstate;
|
||||
|
||||
for (bssize_t j = 0; j < g_gameVarCount; j++)
|
||||
{
|
||||
if (aGameVars[j].flags & GAMEVAR_NORESET) continue;
|
||||
if (aGameVars[j].flags & GAMEVAR_PERPLAYER)
|
||||
{
|
||||
sv.vars[j] = (intptr_t *) Xaligned_alloc(PLAYER_VAR_ALIGNMENT, MAXPLAYERS * sizeof(intptr_t));
|
||||
if (kFile.Read(sv.vars[j], sizeof(intptr_t) * MAXPLAYERS) != sizeof(intptr_t) * MAXPLAYERS) return -9;
|
||||
}
|
||||
else if (aGameVars[j].flags & GAMEVAR_PERACTOR)
|
||||
{
|
||||
sv.vars[j] = (intptr_t *) Xaligned_alloc(ACTOR_VAR_ALIGNMENT, MAXSPRITES * sizeof(intptr_t));
|
||||
if (kFile.Read(sv.vars[j], sizeof(intptr_t) * MAXSPRITES) != sizeof(intptr_t) * MAXSPRITES) return -10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (kFile.Read(tbuf, 12) != 12) return -13;
|
||||
if (Bmemcmp(tbuf, "EOF: EDuke32", 12)) { Printf("EOF ERR\n"); return 2; }
|
||||
|
||||
return 0;
|
||||
|
||||
corrupt:
|
||||
return -7;
|
||||
}
|
||||
|
||||
// Note that this entire function is totally architecture dependent and needs to be fixed (which won't be easy...)
|
||||
void Gv_WriteSave(FileWriter &fil)
|
||||
{
|
||||
// AddLog("Saving Game Vars to File");
|
||||
fil.Write("BEG: EDuke32", 12);
|
||||
|
||||
fil.Write(&g_gameVarCount,sizeof(g_gameVarCount));
|
||||
|
||||
for (bssize_t i = 0; i < g_gameVarCount; i++)
|
||||
{
|
||||
fil.Write(&(aGameVars[i]), sizeof(gamevar_t));
|
||||
fil.Write(aGameVars[i].szLabel, sizeof(uint8_t) * MAXVARLABEL);
|
||||
|
||||
if (aGameVars[i].flags & GAMEVAR_PERPLAYER)
|
||||
fil.Write(aGameVars[i].pValues, sizeof(intptr_t) * MAXPLAYERS);
|
||||
else if (aGameVars[i].flags & GAMEVAR_PERACTOR)
|
||||
fil.Write(aGameVars[i].pValues, sizeof(intptr_t) * MAXSPRITES);
|
||||
}
|
||||
|
||||
uint8_t savedstate[MAXVOLUMES * MAXLEVELS];
|
||||
Bmemset(savedstate, 0, sizeof(savedstate));
|
||||
|
||||
for (bssize_t i = 0; i < (MAXVOLUMES * MAXLEVELS); i++)
|
||||
if (g_mapInfo[i].savedstate != NULL)
|
||||
savedstate[i] = 1;
|
||||
|
||||
fil.Write(savedstate, sizeof(savedstate));
|
||||
|
||||
for (bssize_t i = 0; i < (MAXVOLUMES * MAXLEVELS); i++)
|
||||
{
|
||||
if (!savedstate[i]) continue;
|
||||
|
||||
mapstate_t &sv = *g_mapInfo[i].savedstate;
|
||||
|
||||
fil.Write(g_mapInfo[i].savedstate, sizeof(mapstate_t));
|
||||
|
||||
for (bssize_t j = 0; j < g_gameVarCount; j++)
|
||||
{
|
||||
if (aGameVars[j].flags & GAMEVAR_NORESET) continue;
|
||||
if (aGameVars[j].flags & GAMEVAR_PERPLAYER)
|
||||
fil.Write(sv.vars[j], sizeof(intptr_t) * MAXPLAYERS);
|
||||
else if (aGameVars[j].flags & GAMEVAR_PERACTOR)
|
||||
fil.Write(sv.vars[j], sizeof(intptr_t) * MAXSPRITES);
|
||||
}
|
||||
}
|
||||
|
||||
fil.Write("EOF: EDuke32", 12);
|
||||
}
|
||||
|
||||
void Gv_DumpValues(void)
|
||||
{
|
||||
buildprint("// Current Game Definitions\n\n");
|
||||
|
||||
for (bssize_t i=0; i<g_gameVarCount; i++)
|
||||
{
|
||||
buildprint("gamevar ", aGameVars[i].szLabel, " ");
|
||||
|
||||
if (aGameVars[i].flags & (GAMEVAR_INT32PTR))
|
||||
buildprint(*(int32_t *)aGameVars[i].global);
|
||||
else if (aGameVars[i].flags & (GAMEVAR_INT16PTR))
|
||||
buildprint(*(int16_t *)aGameVars[i].global);
|
||||
else
|
||||
buildprint(aGameVars[i].global);
|
||||
|
||||
if (aGameVars[i].flags & (GAMEVAR_PERPLAYER))
|
||||
buildprint(" GAMEVAR_PERPLAYER");
|
||||
else if (aGameVars[i].flags & (GAMEVAR_PERACTOR))
|
||||
buildprint(" GAMEVAR_PERACTOR");
|
||||
else
|
||||
buildprint(" ", aGameVars[i].flags/* & (GAMEVAR_USER_MASK)*/);
|
||||
|
||||
buildprint(" // ");
|
||||
if (aGameVars[i].flags & (GAMEVAR_SYSTEM))
|
||||
buildprint(" (system)");
|
||||
if (aGameVars[i].flags & (GAMEVAR_PTR_MASK))
|
||||
buildprint(" (pointer)");
|
||||
if (aGameVars[i].flags & (GAMEVAR_READONLY))
|
||||
buildprint(" (read only)");
|
||||
if (aGameVars[i].flags & (GAMEVAR_SPECIAL))
|
||||
buildprint(" (special)");
|
||||
buildprint("\n");
|
||||
}
|
||||
buildprint("\n// end of game definitions\n");
|
||||
}
|
||||
|
||||
// XXX: This function is very strange.
|
||||
|
@ -262,7 +110,7 @@ void Gv_ResetVars(void) /* this is called during a new game and nowhere else */
|
|||
{
|
||||
Gv_Free();
|
||||
|
||||
for (auto &aGameVar : aGameVars)
|
||||
for (auto &aGameVar : aaGameVars)
|
||||
{
|
||||
if (aGameVar.szLabel != NULL)
|
||||
Gv_NewVar(aGameVar.szLabel, (aGameVar.flags & GAMEVAR_NODEFAULT) ? aGameVar.global : aGameVar.defaultValue, aGameVar.flags);
|
||||
|
@ -289,16 +137,16 @@ void Gv_NewVar(const char *pszLabel, intptr_t lValue, uint32_t dwFlags)
|
|||
|
||||
int gV = hash_find(&h_gamevars,pszLabel);
|
||||
|
||||
if (gV >= 0 && !(aGameVars[gV].flags & GAMEVAR_RESET))
|
||||
if (gV >= 0 && !(aaGameVars[gV].flags & GAMEVAR_RESET))
|
||||
{
|
||||
// found it...
|
||||
if (EDUKE32_PREDICT_FALSE(aGameVars[gV].flags & (GAMEVAR_PTR_MASK)))
|
||||
if (EDUKE32_PREDICT_FALSE(aaGameVars[gV].flags & (GAMEVAR_PTR_MASK)))
|
||||
{
|
||||
ReportError(-1);
|
||||
Printf("%s:%d: warning: cannot redefine internal gamevar `%s'.\n",g_scriptFileName,line_number,label+(labelcnt<<6));
|
||||
return;
|
||||
}
|
||||
else if (EDUKE32_PREDICT_FALSE(!(aGameVars[gV].flags & GAMEVAR_SYSTEM)))
|
||||
else if (EDUKE32_PREDICT_FALSE(!(aaGameVars[gV].flags & GAMEVAR_SYSTEM)))
|
||||
{
|
||||
// it's a duplicate in error
|
||||
warningcount++;
|
||||
|
@ -311,55 +159,55 @@ void Gv_NewVar(const char *pszLabel, intptr_t lValue, uint32_t dwFlags)
|
|||
gV = g_gameVarCount;
|
||||
|
||||
// If it's a user gamevar...
|
||||
if ((aGameVars[gV].flags & GAMEVAR_SYSTEM) == 0)
|
||||
if ((aaGameVars[gV].flags & GAMEVAR_SYSTEM) == 0)
|
||||
{
|
||||
// Allocate and set its label
|
||||
if (aGameVars[gV].szLabel == NULL)
|
||||
aGameVars[gV].szLabel = (char *)Xcalloc(MAXVARLABEL,sizeof(uint8_t));
|
||||
if (aaGameVars[gV].szLabel == NULL)
|
||||
aaGameVars[gV].szLabel = (char *)Xcalloc(MAXVARLABEL,sizeof(uint8_t));
|
||||
|
||||
if (aGameVars[gV].szLabel != pszLabel)
|
||||
Bstrcpy(aGameVars[gV].szLabel,pszLabel);
|
||||
if (aaGameVars[gV].szLabel != pszLabel)
|
||||
Bstrcpy(aaGameVars[gV].szLabel,pszLabel);
|
||||
|
||||
// and the flags
|
||||
aGameVars[gV].flags=dwFlags;
|
||||
aaGameVars[gV].flags=dwFlags;
|
||||
|
||||
// only free if per-{actor,player}
|
||||
if (aGameVars[gV].flags & GAMEVAR_USER_MASK)
|
||||
ALIGNED_FREE_AND_NULL(aGameVars[gV].pValues);
|
||||
if (aaGameVars[gV].flags & GAMEVAR_USER_MASK)
|
||||
ALIGNED_FREE_AND_NULL(aaGameVars[gV].pValues);
|
||||
}
|
||||
|
||||
// if existing is system, they only get to change default value....
|
||||
aGameVars[gV].defaultValue = lValue;
|
||||
aGameVars[gV].flags &= ~GAMEVAR_RESET;
|
||||
aaGameVars[gV].defaultValue = lValue;
|
||||
aaGameVars[gV].flags &= ~GAMEVAR_RESET;
|
||||
|
||||
if (gV == g_gameVarCount)
|
||||
{
|
||||
// we're adding a new one.
|
||||
hash_add(&h_gamevars, aGameVars[gV].szLabel, g_gameVarCount++, 0);
|
||||
hash_add(&h_gamevars, aaGameVars[gV].szLabel, g_gameVarCount++, 0);
|
||||
}
|
||||
|
||||
// Set initial values. (Or, override values for system gamevars.)
|
||||
if (aGameVars[gV].flags & GAMEVAR_PERPLAYER)
|
||||
if (aaGameVars[gV].flags & GAMEVAR_PERPLAYER)
|
||||
{
|
||||
if (!aGameVars[gV].pValues)
|
||||
if (!aaGameVars[gV].pValues)
|
||||
{
|
||||
aGameVars[gV].pValues = (intptr_t *) Xaligned_alloc(PLAYER_VAR_ALIGNMENT, MAXPLAYERS * sizeof(intptr_t));
|
||||
Bmemset(aGameVars[gV].pValues, 0, MAXPLAYERS * sizeof(intptr_t));
|
||||
aaGameVars[gV].pValues = (intptr_t *) Xaligned_alloc(PLAYER_VAR_ALIGNMENT, MAXPLAYERS * sizeof(intptr_t));
|
||||
Bmemset(aaGameVars[gV].pValues, 0, MAXPLAYERS * sizeof(intptr_t));
|
||||
}
|
||||
for (bssize_t j=MAXPLAYERS-1; j>=0; --j)
|
||||
aGameVars[gV].pValues[j]=lValue;
|
||||
aaGameVars[gV].pValues[j]=lValue;
|
||||
}
|
||||
else if (aGameVars[gV].flags & GAMEVAR_PERACTOR)
|
||||
else if (aaGameVars[gV].flags & GAMEVAR_PERACTOR)
|
||||
{
|
||||
if (!aGameVars[gV].pValues)
|
||||
if (!aaGameVars[gV].pValues)
|
||||
{
|
||||
aGameVars[gV].pValues = (intptr_t *) Xaligned_alloc(ACTOR_VAR_ALIGNMENT, MAXSPRITES * sizeof(intptr_t));
|
||||
Bmemset(aGameVars[gV].pValues, 0, MAXSPRITES * sizeof(intptr_t));
|
||||
aaGameVars[gV].pValues = (intptr_t *) Xaligned_alloc(ACTOR_VAR_ALIGNMENT, MAXSPRITES * sizeof(intptr_t));
|
||||
Bmemset(aaGameVars[gV].pValues, 0, MAXSPRITES * sizeof(intptr_t));
|
||||
}
|
||||
for (bssize_t j=MAXSPRITES-1; j>=0; --j)
|
||||
aGameVars[gV].pValues[j]=lValue;
|
||||
aaGameVars[gV].pValues[j]=lValue;
|
||||
}
|
||||
else aGameVars[gV].global = lValue;
|
||||
else aaGameVars[gV].global = lValue;
|
||||
}
|
||||
|
||||
static int Gv_GetVarIndex(const char *szGameLabel)
|
||||
|
@ -377,7 +225,7 @@ static int Gv_GetVarIndex(const char *szGameLabel)
|
|||
|
||||
static FORCE_INLINE int __fastcall getvar__(int const gameVar, int const spriteNum, int const playerNum)
|
||||
{
|
||||
auto const &var = aGameVars[gameVar & (MAXGAMEVARS-1)];
|
||||
auto const &var = aaGameVars[gameVar & (MAXGAMEVARS-1)];
|
||||
|
||||
int returnValue = 0;
|
||||
int const varFlags = var.flags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK);
|
||||
|
@ -389,10 +237,8 @@ static FORCE_INLINE int __fastcall getvar__(int const gameVar, int const spriteN
|
|||
returnValue = var.pValues[playerNum & (MAXPLAYERS-1)];
|
||||
else switch (varFlags & GAMEVAR_PTR_MASK)
|
||||
{
|
||||
case GAMEVAR_RAWQ16PTR:
|
||||
case GAMEVAR_INT32PTR: returnValue = *(int32_t *)var.global; break;
|
||||
case GAMEVAR_INT16PTR: returnValue = *(int16_t *)var.global; break;
|
||||
case GAMEVAR_Q16PTR: returnValue = fix16_to_int(*(fix16_t *)var.global); break;
|
||||
}
|
||||
|
||||
return NEGATE_ON_CONDITION(returnValue, gameVar & GV_FLAG_NEGATIVE);
|
||||
|
@ -409,7 +255,7 @@ void __fastcall Gv_GetManyVars(int const numVars, int32_t * const outBuf)
|
|||
|
||||
static FORCE_INLINE void __fastcall setvar__(int const gameVar, int const newValue, int const spriteNum, int const playerNum)
|
||||
{
|
||||
gamevar_t &var = aGameVars[gameVar];
|
||||
gamevar_t &var = aaGameVars[gameVar];
|
||||
int const varFlags = var.flags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK);
|
||||
|
||||
if (!varFlags) var.global=newValue;
|
||||
|
@ -419,10 +265,8 @@ static FORCE_INLINE void __fastcall setvar__(int const gameVar, int const newVal
|
|||
var.pValues[playerNum & (MAXPLAYERS-1)] = newValue;
|
||||
else switch (varFlags & GAMEVAR_PTR_MASK)
|
||||
{
|
||||
case GAMEVAR_RAWQ16PTR:
|
||||
case GAMEVAR_INT32PTR: *((int32_t *)var.global) = (int32_t)newValue; break;
|
||||
case GAMEVAR_INT16PTR: *((int16_t *)var.global) = (int16_t)newValue; break;
|
||||
case GAMEVAR_Q16PTR: *(fix16_t *)var.global = fix16_from_int((int16_t)newValue); break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -446,7 +290,7 @@ static intptr_t *Gv_GetVarDataPtr(const char *szGameLabel)
|
|||
if (EDUKE32_PREDICT_FALSE((unsigned)gameVar >= MAXGAMEVARS))
|
||||
return NULL;
|
||||
|
||||
gamevar_t &var = aGameVars[gameVar];
|
||||
gamevar_t &var = aaGameVars[gameVar];
|
||||
|
||||
if (var.flags & (GAMEVAR_USER_MASK | GAMEVAR_PTR_MASK))
|
||||
return var.pValues;
|
||||
|
@ -769,7 +613,7 @@ void Gv_Init(void)
|
|||
{
|
||||
#if !defined LUNATIC
|
||||
// already initialized
|
||||
if (aGameVars[0].flags)
|
||||
if (aaGameVars[0].flags)
|
||||
return;
|
||||
#else
|
||||
static int32_t inited=0;
|
||||
|
@ -839,16 +683,16 @@ void Gv_InitWeaponPointers(void)
|
|||
|
||||
void Gv_RefreshPointers(void)
|
||||
{
|
||||
aGameVars[Gv_GetVarIndex("COOP")].global = (intptr_t)&ud.coop;
|
||||
aGameVars[Gv_GetVarIndex("FFIRE")].global = (intptr_t)&ud.ffire;
|
||||
aGameVars[Gv_GetVarIndex("LEVEL")].global = (intptr_t)&ud.level_number;
|
||||
aGameVars[Gv_GetVarIndex("MARKER")].global = (intptr_t)&ud.marker;
|
||||
aGameVars[Gv_GetVarIndex("MONSTERS_OFF")].global = (intptr_t)&ud.monsters_off;
|
||||
aGameVars[Gv_GetVarIndex("MULTIMODE")].global = (intptr_t)&ud.multimode;
|
||||
aGameVars[Gv_GetVarIndex("RESPAWN_INVENTORY")].global = (intptr_t)&ud.respawn_inventory;
|
||||
aGameVars[Gv_GetVarIndex("RESPAWN_ITEMS")].global = (intptr_t)&ud.respawn_items;
|
||||
aGameVars[Gv_GetVarIndex("RESPAWN_MONSTERS")].global = (intptr_t)&ud.respawn_monsters;
|
||||
aGameVars[Gv_GetVarIndex("VOLUME")].global = (intptr_t)&ud.volume_number;
|
||||
aaGameVars[Gv_GetVarIndex("COOP")].global = (intptr_t)&ud.coop;
|
||||
aaGameVars[Gv_GetVarIndex("FFIRE")].global = (intptr_t)&ud.ffire;
|
||||
aaGameVars[Gv_GetVarIndex("LEVEL")].global = (intptr_t)&ud.level_number;
|
||||
aaGameVars[Gv_GetVarIndex("MARKER")].global = (intptr_t)&ud.marker;
|
||||
aaGameVars[Gv_GetVarIndex("MONSTERS_OFF")].global = (intptr_t)&ud.monsters_off;
|
||||
aaGameVars[Gv_GetVarIndex("MULTIMODE")].global = (intptr_t)&ud.multimode;
|
||||
aaGameVars[Gv_GetVarIndex("RESPAWN_INVENTORY")].global = (intptr_t)&ud.respawn_inventory;
|
||||
aaGameVars[Gv_GetVarIndex("RESPAWN_ITEMS")].global = (intptr_t)&ud.respawn_items;
|
||||
aaGameVars[Gv_GetVarIndex("RESPAWN_MONSTERS")].global = (intptr_t)&ud.respawn_monsters;
|
||||
aaGameVars[Gv_GetVarIndex("VOLUME")].global = (intptr_t)&ud.volume_number;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -933,44 +933,12 @@ static uint8_t *svdiff;
|
|||
|
||||
#include "gamedef.h"
|
||||
|
||||
#define SV_SKIPMASK (/*GAMEVAR_SYSTEM|*/ GAMEVAR_READONLY | GAMEVAR_PTR_MASK | /*GAMEVAR_NORESET |*/ GAMEVAR_SPECIAL)
|
||||
#define SV_SKIPMASK (GAMEVAR_READONLY | GAMEVAR_PTR_MASK)
|
||||
|
||||
static char svgm_vars_string [] = "blK:vars";
|
||||
// setup gamevar data spec for snapshotting and diffing... gamevars must be loaded when called
|
||||
static void sv_makevarspec()
|
||||
{
|
||||
int vcnt = 0;
|
||||
|
||||
for (int i = 0; i < g_gameVarCount; i++)
|
||||
vcnt += (aGameVars[i].flags & SV_SKIPMASK) ? 0 : 1;
|
||||
|
||||
svgm_vars = (dataspec_gv_t *)Xrealloc(svgm_vars, (vcnt + 2) * sizeof(dataspec_gv_t));
|
||||
|
||||
svgm_vars[0].flags = DS_STRING;
|
||||
svgm_vars[0].ptr = svgm_vars_string;
|
||||
svgm_vars[0].cnt = 1;
|
||||
|
||||
vcnt = 1;
|
||||
|
||||
for (int i = 0; i < g_gameVarCount; i++)
|
||||
{
|
||||
if (aGameVars[i].flags & SV_SKIPMASK)
|
||||
continue;
|
||||
|
||||
unsigned const per = aGameVars[i].flags & GAMEVAR_USER_MASK;
|
||||
|
||||
svgm_vars[vcnt].flags = 0;
|
||||
svgm_vars[vcnt].ptr = (per == 0) ? &aGameVars[i].global : aGameVars[i].pValues;
|
||||
svgm_vars[vcnt].size = sizeof(intptr_t);
|
||||
svgm_vars[vcnt].cnt = (per == 0) ? 1 : (per == GAMEVAR_PERPLAYER ? MAXPLAYERS : MAXSPRITES);
|
||||
|
||||
++vcnt;
|
||||
}
|
||||
|
||||
svgm_vars[vcnt].flags = DS_END;
|
||||
svgm_vars[vcnt].ptr = NULL;
|
||||
svgm_vars[vcnt].size = 0;
|
||||
svgm_vars[vcnt].cnt = 0;
|
||||
}
|
||||
|
||||
void sv_freemem()
|
||||
|
|
Loading…
Reference in a new issue