- more gamevar cleanup.

This commit is contained in:
Christoph Oelckers 2020-05-13 17:39:30 +02:00
parent d01d4bf44c
commit c9bb23ee42
15 changed files with 1462 additions and 242 deletions

View file

@ -6,6 +6,7 @@ set( PCH_SOURCES
src/actors_lava.cpp
src/bowling.cpp
src/gamedef.cpp
src/gamevar.cpp
src/zz_actors.cpp
src/sectors.cpp
src/sectors_d.cpp

View file

@ -228,14 +228,14 @@ void checkavailweapon(struct player_struct* p)
p->curr_weapon = weap;
if (isWW2GI())
{
SetGameVarID(g_iWeaponVarID, p->curr_weapon, p->i, snum);
SetGameVarID(g_iWeaponVarID, p->curr_weapon, snum, p->i);
if (p->curr_weapon >= 0)
{
SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike[p->curr_weapon][snum], p->i, snum);
SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike[p->curr_weapon][snum], snum, p->i);
}
else
{
SetGameVarID(g_iWorksLikeVarID, -1, p->i, snum);
SetGameVarID(g_iWorksLikeVarID, -1, snum, p->i);
}
OnEvent(EVENT_CHANGEWEAPON, p->i, snum, -1);
}

View file

@ -125,16 +125,16 @@ void addweapon_d(struct player_struct *p, int weapon)
short snum;
snum = sprite[p->i].yvel;
SetGameVarID(g_iWeaponVarID,weapon, p->i, snum);
SetGameVarID(g_iWeaponVarID,weapon, snum, p->i);
if (p->curr_weapon >= 0)
{
SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike[weapon][snum], p->i, snum);
SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike[weapon][snum], snum, p->i);
}
else
{
SetGameVarID(g_iWorksLikeVarID, -1, p->i, snum);
SetGameVarID(g_iWorksLikeVarID, -1, snum, p->i);
}
SetGameVarID(g_iReturnVarID, 0, -1, snum);
SetGameVarID(g_iReturnVarID, 0, snum, -1);
OnEvent(EVENT_CHANGEWEAPON, p->i, snum, -1);
if (GetGameVarID(g_iReturnVarID, -1, snum) == 0)
{

View file

@ -1,52 +0,0 @@
#ifndef EDUKE32_EVENTS_DEFS_H_
#define EDUKE32_EVENTS_DEFS_H_
// the order of these can't be changed or else compatibility with EDuke 2.0 mods will break
// KEEPINSYNC with EventNames[] and lunatic/con_lang.lua
enum GameEvent_t {
EVENT_INIT, // 0
EVENT_ENTERLEVEL,
EVENT_RESETWEAPONS,
EVENT_RESETINVENTORY,
EVENT_HOLSTER,
EVENT_LOOKLEFT, // 5
EVENT_LOOKRIGHT,
EVENT_SOARUP,
EVENT_SOARDOWN,
EVENT_CROUCH,
EVENT_JUMP, // 10
EVENT_RETURNTOCENTER,
EVENT_LOOKUP,
EVENT_LOOKDOWN,
EVENT_AIMUP,
EVENT_FIRE, // 15
EVENT_CHANGEWEAPON,
EVENT_GETSHOTRANGE,
EVENT_GETAUTOAIMANGLE,
EVENT_GETLOADTILE,
EVENT_CHEATGETSTEROIDS, // 20
EVENT_CHEATGETHEAT,
EVENT_CHEATGETBOOT,
EVENT_CHEATGETSHIELD,
EVENT_CHEATGETSCUBA,
EVENT_CHEATGETHOLODUKE, // 25
EVENT_CHEATGETJETPACK,
EVENT_CHEATGETFIRSTAID,
EVENT_QUICKKICK,
EVENT_INVENTORY,
EVENT_USENIGHTVISION, // 30
EVENT_USESTEROIDS,
EVENT_INVENTORYLEFT,
EVENT_INVENTORYRIGHT,
EVENT_HOLODUKEON,
EVENT_HOLODUKEOFF, // 35
EVENT_USEMEDKIT,
EVENT_USEJETPACK,
EVENT_TURNAROUND,
MAXEVENTS,
EVENT_MAXEVENT = MAXEVENTS,
EVENT_AIMDOWN = EVENT_AIMUP,
};
#endif

View file

@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifndef gamedef_h_
#define gamedef_h_
#include "gamevar.h"
#include "actors.h"
#include "build.h" // hashtable_t
#include "cheats.h"
@ -31,20 +32,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_DUKE_NS
#if 0
enum
{
LABEL_ANY = -1,
LABEL_DEFINE = 1,
LABEL_STATE = 2,
LABEL_ACTOR = 4,
LABEL_ACTION = 8,
LABEL_AI = 16,
LABEL_MOVE = 32,
LABEL_EVENT = 0x40,
};
#endif
#define LABEL_HASPARM2 1
#define LABEL_ISSTRING 2
@ -67,8 +54,7 @@ extern int32_t g_zRangeVarID; // var ID of "ZRANGE"
#define g_iWeaponVarID g_weaponVarID
#define g_iWorksLikeVarID g_worksLikeVarID
#include "events_defs.h"
extern intptr_t apScriptGameEvent[MAXEVENTS];
extern intptr_t apScriptGameEvent[EVENT_NUMEVENTS];
extern char g_scriptFileName[BMAX_PATH];

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,129 @@
#pragma once
BEGIN_DUKE_NS
// gamedef.c
//void OnEvent(int iEventID, int i,int p,int x);
enum
{
EVENT_INIT = 0,
EVENT_ENTERLEVEL,
EVENT_RESETWEAPONS, // for each player
EVENT_RESETINVENTORY, // for each player
EVENT_HOLSTER, // for each player
EVENT_LOOKLEFT, // for each player
EVENT_LOOKRIGHT, // for each player
EVENT_SOARUP, // for each player
EVENT_SOARDOWN, // for each player
EVENT_CROUCH, // for each player
EVENT_JUMP, // for each player
EVENT_RETURNTOCENTER, // for each player
EVENT_LOOKUP, // for each player
EVENT_LOOKDOWN, // for each player
EVENT_AIMUP, // for each player
EVENT_AIMDOWN, // for each player
EVENT_FIRE, // for each player
EVENT_CHANGEWEAPON, // for each player
EVENT_GETSHOTRANGE, // for each player
EVENT_GETAUTOAIMANGLE, // for each player
EVENT_GETLOADTILE,
EVENT_CHEATGETSTEROIDS,
EVENT_CHEATGETHEAT,
EVENT_CHEATGETBOOT,
EVENT_CHEATGETSHIELD,
EVENT_CHEATGETSCUBA,
EVENT_CHEATGETHOLODUKE,
EVENT_CHEATGETJETPACK,
EVENT_CHEATGETFIRSTAID,
EVENT_QUICKKICK,
EVENT_INVENTORY,
EVENT_USENIGHTVISION,
EVENT_USESTEROIDS,
EVENT_INVENTORYLEFT,
EVENT_INVENTORYRIGHT,
EVENT_HOLODUKEON,
EVENT_HOLODUKEOFF,
EVENT_USEMEDKIT,
EVENT_USEJETPACK,
EVENT_TURNAROUND,
EVENT_NUMEVENTS,
EVENT_MAXEVENT = EVENT_NUMEVENTS-1
};
enum
{
// store global game definitions
MAXGAMEVARS = 512,
MAXVARLABEL = 26,
MAXGAMEEVENTS = 128
};
enum
{
GAMEVAR_FLAG_PERPLAYER = 1, // per-player variable
GAMEVAR_FLAG_PERACTOR = 2, // per-actor variable
GAMEVAR_FLAG_USER_MASK = 3,
// internal flags only...
GAMEVAR_FLAG_DEFAULT = 256, // allow override
GAMEVAR_FLAG_SECRET = 512, // don't dump...
GAMEVAR_FLAG_NODEFAULT = 1024, // don't add to 'default' array.
GAMEVAR_FLAG_SYSTEM = 2048, // cannot change mode flags...(only default value)
GAMEVAR_FLAG_READONLY = 4096, // values are read-only (no setvar allowed)
GAMEVAR_FLAG_PLONG = 8192, // plValue is a pointer to a long
};
typedef struct
{
union
{
int lValue;
int* plValue;
};
int defaultValue;
unsigned int dwFlags;
char szLabel[MAXVARLABEL];
TArray<int> plArray;
} MATTGAMEVAR;
extern MATTGAMEVAR aGameVars[MAXGAMEVARS];
extern int iGameVarCount;
extern int g_iReturnVarID; // var ID of "RETURN"
extern int g_iWeaponVarID; // var ID of "WEAPON"
extern int g_iWorksLikeVarID; // var ID of "WORKSLIKE"
extern int g_iZRangeVarID; // var ID of "ZRANGE"
extern int g_iAngRangeVarID; // var ID of "ANGRANGE"
extern int g_iAimAngleVarID; // var ID of "AUTOAIMANGLE"
// global crap for event management
extern int g_i, g_p;
extern int g_x;
extern int* g_t;
extern uint8_t killit_flag;
//extern sprite_ype* g_sp;
bool AddGameVar(const char *pszLabel, intptr_t lValue, unsigned dwFlags);
int GetGameID(const char *szGameLabel);
int GetDefID(const char *szGameLabel);
void FreeGameVars(void);
void ClearGameVars(void);
void AddSystemVars();
void ResetGameVars(void);
int GetGameVarID(int id, int sActor, int sPlayer);
void SetGameVarID(int id, int lValue, int sActor, int sPlayer);
int GetGameVar(char* szGameLabel, int lDefault, int sActor, int sPlayer);
void ClearGameEvents();
bool IsGameEvent(int i);
void InitGameVarPointers(void);
void ResetSystemDefaults(void);
END_DUKE_NS

View file

@ -24,15 +24,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define gamevars_h_
#include "gamedef.h"
#include "gamevar.h"
BEGIN_DUKE_NS
#define MAXGAMEVARS 2048 // must be a power of two
#define MAXVARLABEL 26
#define GV_FLAG_CONSTANT (MAXGAMEVARS)
#define GV_FLAG_NEGATIVE (MAXGAMEVARS<<1)
// store global game definitions
enum GamevarFlags_t
{
@ -46,9 +41,6 @@ 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_FLAG_DEFAULT = GAMEVAR_DEFAULT,
GAMEVAR_FLAG_SECRET = 0x200, // placeholder
GAMEVAR_FLAG_READONLY = 0x1000, // placeholder
GAMEVAR_PTR_MASK = GAMEVAR_INT32PTR | GAMEVAR_INT16PTR,
};
@ -85,7 +77,7 @@ int __fastcall Gv_GetVar(int const gameVar);
void __fastcall Gv_GetManyVars(int const numVars, int32_t * const outBuf);
void __fastcall Gv_SetVar(int const gameVar, int const newValue);
inline void SetGameVarID(int var, int newval, int pnum, int snum)
inline void SetGameVarID(int var, int newval, int snum, int pnum)
{
Gv_SetVar(var, newval, snum, pnum);
}
@ -105,7 +97,6 @@ inline int GetGameVar(const char* szGameLabel, int defaultValue, int spriteNum,
return Gv_GetVarByLabel(szGameLabel, defaultValue, spriteNum, playerNum);
}
void Gv_NewVar(const char *pszLabel,intptr_t lValue,uint32_t dwFlags);
#define AddGameVar Gv_NewVar
int GetDefID(const char* label);

View file

@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "quotes.h"
#include "sector.h"
#include "sounds.h"
#include "gamevars.h"
BEGIN_DUKE_NS
@ -204,7 +205,6 @@ G_EXTERN uint32_t g_ambientCnt;
G_EXTERN intptr_t *apScript;
G_EXTERN intptr_t *scriptptr;
G_EXTERN map_t g_mapInfo[(MAXVOLUMES + 1) * MAXLEVELS]; // +1 volume for "intro", "briefing" and "loading" music
G_EXTERN vec2_t g_origins[MAXANIMPOINTS];
struct msx_
{

View file

@ -32,7 +32,6 @@ extern int32_t voting,vote_map,vote_episode;
int G_EnterLevel(int gameMode);
int G_FindLevelByFile(const char *fileName);
void G_CacheMapData(void);
void G_FreeMapState(int levelNum);
void G_NewGame(int volumeNum, int levelNum, int skillNum);
void G_ResetTimers(uint8_t keepgtics);
void G_UpdateScreenArea(void);

View file

@ -45,64 +45,6 @@ typedef struct {
int16_t wallnum, tag;
} animwalltype;
typedef struct {
// this needs to have a copy of everything related to the map/actor state
// see savegame.c
int32_t g_animateGoal[MAXANIMATES], g_animateVel[MAXANIMATES], g_animateCnt;
intptr_t g_animatePtr[MAXANIMATES];
int32_t lockclock;
vec2_t origins[MAXANIMPOINTS];
int32_t randomseed, g_globalRandom;
int32_t pskyidx;
int16_t SpriteDeletionQueue[1024],g_spriteDeleteQueuePos;
int16_t g_animateSect[MAXANIMATES];
int16_t g_cyclers[MAXCYCLERS][6];
int16_t g_mirrorWall[64], g_mirrorSector[64], g_mirrorCount;
int16_t g_animWallCnt;
int16_t g_cloudCnt,g_cloudSect[256],g_cloudX,g_cloudY;
int16_t g_cyclerCnt;
int32_t numsprites;
int16_t tailspritefree;
int16_t headspritesect[MAXSECTORS+1];
int16_t headspritestat[MAXSTATUS+1];
int16_t nextspritesect[MAXSPRITES];
int16_t nextspritestat[MAXSPRITES];
int16_t numsectors;
int16_t numwalls;
int16_t prevspritesect[MAXSPRITES];
int16_t prevspritestat[MAXSPRITES];
uint16_t g_earthquakeTime;
int8_t g_playerSpawnCnt;
FixedBitArray<MAXSECTORS> show2dsector;
actor_t actor[MAXSPRITES];
playerspawn_t g_playerSpawnPoints[MAXPLAYERS];
animwalltype animwall[MAXANIMWALLS];
usectortype sector[MAXSECTORS];
spriteext_t spriteext[MAXSPRITES];
uspritetype sprite[MAXSPRITES];
uwalltype wall[MAXWALLS];
#ifndef NEW_MAP_FORMAT
wallext_t wallext[MAXWALLS];
#endif
intptr_t *vars[MAXGAMEVARS];
#ifdef YAX_ENABLE
int32_t numyaxbunches;
# if !defined NEW_MAP_FORMAT
int16_t yax_bunchnum[MAXSECTORS][2];
int16_t yax_nextwall[MAXWALLS][2];
# endif
#endif
} mapstate_t;
typedef struct {
mapstate_t *savedstate;
} map_t;
void breakwall(short newpn, short spr, short dawallnum);
void activatebysector(int s, int sn);

View file

@ -6497,21 +6497,10 @@ int loaddefinitions_game(const char *fileName, int32_t firstPass)
}
static void G_FreeHashAnim(const char * /*string*/, intptr_t key)
{
Xfree((void *)key);
}
static void G_Cleanup(void)
{
int32_t i;
for (i=(MAXLEVELS*(MAXVOLUMES+1))-1; i>=0; i--) // +1 volume for "intro", "briefing" music
{
G_FreeMapState(i);
}
for (i=MAXPLAYERS-1; i>=0; i--)
{
Xfree(g_player[i].ps);

View file

@ -101,7 +101,7 @@ static void VM_DeleteSprite(int const spriteNum, int const playerNum)
A_DeleteSprite(spriteNum);
}
intptr_t apScriptGameEvent[MAXEVENTS];
intptr_t apScriptGameEvent[EVENT_NUMEVENTS];
static uspritetype dummy_sprite;
static actor_t dummy_actor;
@ -2717,53 +2717,7 @@ GAMEEXEC_STATIC void VM_Execute(native_t loop)
case concmd_addlogvar:
insptr++;
{
int32_t m = 1;
char szBuf[256];
int32_t lVarID = *insptr;
if ((lVarID >= g_gameVarCount) || lVarID < 0)
{
if (*insptr == MAXGAMEVARS) // addlogvar for a constant? Har.
insptr++;
else if (EDUKE32_PREDICT_TRUE(*insptr & GV_FLAG_NEGATIVE))
{
m = -m;
lVarID ^= GV_FLAG_NEGATIVE;
}
else
{
// invalid varID
CON_ERRPRINTF("invalid variable\n");
continue;
}
}
Bsprintf(tempbuf, "CONLOGVAR: L=%d %s ", VM_DECODE_LINE_NUMBER(g_tw), aaGameVars[lVarID].szLabel);
if (aaGameVars[lVarID].flags & GAMEVAR_READONLY)
{
Bsprintf(szBuf, " (read-only)");
Bstrcat(tempbuf, szBuf);
}
if (aaGameVars[lVarID].flags & GAMEVAR_PERPLAYER)
{
Bsprintf(szBuf, " (Per Player. Player=%d)", vm.playerNum);
}
else if (aaGameVars[lVarID].flags & GAMEVAR_PERACTOR)
{
Bsprintf(szBuf, " (Per Actor. Actor=%d)", vm.spriteNum);
}
else
{
Bsprintf(szBuf, " (Global)");
}
Bstrcat(tempbuf, szBuf);
Bsprintf(szBuf, " =%d\n", Gv_GetVar(lVarID) * m);
Bstrcat(tempbuf, szBuf);
Printf(TEXTCOLOR_GREEN "%s", tempbuf);
insptr++;
continue;
}
continue;
case concmd_ifvare:
insptr++;
@ -2788,13 +2742,6 @@ GAMEEXEC_STATIC void VM_Execute(native_t loop)
debug_break();
VM_ScriptInfo(insptr, 64);
G_GameExit("An error has occurred in the " GAMENAME " virtual machine.\n\n");
#if 0
"If you are an end user, please e-mail the file " GAMENAMELOWERCASE ".log\n"
"along with links to any mods you're using to development@voidpoint.com.\n\n"
"If you are a developer, please attach all of your script files\n"
"along with instructions on how to reproduce this error.\n\n"
"Thank you!");
#endif
break;
}
}

View file

@ -119,22 +119,6 @@ void Gv_ResetVars(void) /* this is called during a new game and nowhere else */
void Gv_NewVar(const char *pszLabel, intptr_t lValue, uint32_t dwFlags)
{
if (EDUKE32_PREDICT_FALSE(g_gameVarCount >= MAXGAMEVARS))
{
errorcount++;
ReportError(-1);
Printf("%s:%d: error: too many gamevars!\n",g_scriptFileName,line_number);
return;
}
if (EDUKE32_PREDICT_FALSE(Bstrlen(pszLabel) > (MAXVARLABEL-1)))
{
errorcount++;
ReportError(-1);
Printf("%s:%d: error: variable name `%s' exceeds limit of %d characters.\n",g_scriptFileName,line_number,pszLabel, MAXVARLABEL);
return;
}
int gV = hash_find(&h_gamevars,pszLabel);
if (gV >= 0 && !(aaGameVars[gV].flags & GAMEVAR_RESET))
@ -241,7 +225,7 @@ static FORCE_INLINE int __fastcall getvar__(int const gameVar, int const spriteN
case GAMEVAR_INT16PTR: returnValue = *(int16_t *)var.global; break;
}
return NEGATE_ON_CONDITION(returnValue, gameVar & GV_FLAG_NEGATIVE);
return returnValue;
}
int __fastcall Gv_GetVar(int const gameVar, int const spriteNum, int const playerNum) { return getvar__(gameVar, spriteNum, playerNum); }

View file

@ -1940,9 +1940,6 @@ end_vol4a:
//AddLog("Newgame");
for (bssize_t i=0; i<(MAXVOLUMES*MAXLEVELS); i++)
G_FreeMapState(i);
if (m_coop != 1)
{
for (bssize_t weaponNum = 0; weaponNum < MAX_WEAPONS; weaponNum++)
@ -2478,16 +2475,6 @@ int G_EnterLevel(int gameMode)
return 0;
}
void G_FreeMapState(int levelNum)
{
map_t *const pMapInfo = &g_mapInfo[levelNum];
if (pMapInfo->savedstate == NULL)
return;
ALIGNED_FREE_AND_NULL(pMapInfo->savedstate);
}
void G_SetFog(int fogtype)
{
GLInterface.SetMapFog(fogtype != 0);