2010-08-02 08:13:51 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 2010 EDuke32 developers and contributors
|
|
|
|
|
|
|
|
This file is part of EDuke32.
|
|
|
|
|
|
|
|
EDuke32 is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License version 2
|
|
|
|
as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2014-07-20 08:55:56 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2010-08-02 08:13:51 +00:00
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2014-11-22 12:32:56 +00:00
|
|
|
#ifndef gamevars_h_
|
|
|
|
#define gamevars_h_
|
2010-08-02 08:13:51 +00:00
|
|
|
|
Patch from Hendricks266 and whatever changes happened to be in my tree. I hope they work ;)
"The most noticeable change is the addition of the "includedefault" CON and DEF command, which will attempt to include eduke.con (or nam.con, or ww2gi.con), then game.con, or duke3d.def, or nam.def, or ww2gi.def. This is useful for TCs like my add-ons, where for my pseudo-mutators I currently say "include EDUKE.CON", but I also have to juggle this terrible order of paths, so that I can have an EDUKE.CON file in my HRP which says "include GAME.CON" to allow the mainline game to actually run, but also allow DukePlus to load its EDUKE.CON file (since it uses that and not an -x switch), and also allow any custom EDUKE.CON files in the root to be used."
git-svn-id: https://svn.eduke32.com/eduke32@1909 1a8010ca-5511-0410-912e-c29ae57300e0
2011-06-19 00:11:52 +00:00
|
|
|
#include "gamedef.h"
|
|
|
|
|
2012-12-12 02:53:08 +00:00
|
|
|
#define MAXGAMEVARS 2048 // must be a power of two
|
|
|
|
#define MAXVARLABEL 26
|
|
|
|
|
2010-08-02 08:13:51 +00:00
|
|
|
// store global game definitions
|
|
|
|
enum GamevarFlags_t {
|
|
|
|
GAMEVAR_PERPLAYER = 0x00000001, // per-player variable
|
|
|
|
GAMEVAR_PERACTOR = 0x00000002, // per-actor variable
|
2011-04-07 01:16:29 +00:00
|
|
|
GAMEVAR_USER_MASK = (GAMEVAR_PERPLAYER|GAMEVAR_PERACTOR),
|
2013-01-20 21:17:15 +00:00
|
|
|
GAMEVAR_RESET = 0x00000008, // INTERNAL, don't use
|
|
|
|
GAMEVAR_DEFAULT = 0x00000100, // UNUSED, but always cleared for user-defined gamevars
|
2010-08-02 08:13:51 +00:00
|
|
|
GAMEVAR_SECRET = 0x00000200, // don't dump...
|
|
|
|
GAMEVAR_NODEFAULT = 0x00000400, // don't reset on actor spawn
|
|
|
|
GAMEVAR_SYSTEM = 0x00000800, // cannot change mode flags...(only default value)
|
|
|
|
GAMEVAR_READONLY = 0x00001000, // values are read-only (no setvar allowed)
|
|
|
|
GAMEVAR_INTPTR = 0x00002000, // plValues is a pointer to an int32_t
|
|
|
|
GAMEVAR_SHORTPTR = 0x00008000, // plValues is a pointer to a short
|
|
|
|
GAMEVAR_CHARPTR = 0x00010000, // plValues is a pointer to a char
|
2011-04-07 01:16:29 +00:00
|
|
|
GAMEVAR_PTR_MASK = (GAMEVAR_INTPTR|GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR),
|
2010-08-02 08:13:51 +00:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2013-01-20 21:17:06 +00:00
|
|
|
#if !defined LUNATIC
|
|
|
|
|
2014-11-22 18:37:16 +00:00
|
|
|
// Alignments for per-player and per-actor variables.
|
2014-11-07 22:07:12 +00:00
|
|
|
#define PLAYER_VAR_ALIGNMENT (sizeof(intptr_t))
|
|
|
|
#define ACTOR_VAR_ALIGNMENT 16
|
|
|
|
|
2014-12-26 17:29:56 +00:00
|
|
|
# define MAXGAMEARRAYS (MAXGAMEVARS>>2) // must be strictly smaller than MAXGAMEVARS
|
2013-05-19 19:29:18 +00:00
|
|
|
# define MAXARRAYLABEL MAXVARLABEL
|
2012-12-12 02:53:08 +00:00
|
|
|
|
2010-08-02 08:13:51 +00:00
|
|
|
enum GamearrayFlags_t {
|
2012-12-13 02:33:53 +00:00
|
|
|
|
|
|
|
GAMEARRAY_READONLY = 0x00001000,
|
|
|
|
GAMEARRAY_WARN = 0x00002000,
|
|
|
|
|
|
|
|
GAMEARRAY_NORMAL = 0x00004000,
|
|
|
|
GAMEARRAY_OFCHAR = 0x00000001,
|
|
|
|
GAMEARRAY_OFSHORT = 0x00000002,
|
|
|
|
GAMEARRAY_OFINT = 0x00000004,
|
|
|
|
GAMEARRAY_TYPE_MASK = GAMEARRAY_OFCHAR|GAMEARRAY_OFSHORT|GAMEARRAY_OFINT,
|
|
|
|
|
|
|
|
GAMEARRAY_VARSIZE = 0x00000020,
|
|
|
|
|
|
|
|
GAMEARRAY_RESET = 0x00000008,
|
|
|
|
/// GAMEARRAY_NORESET = 0x00000001,
|
2010-08-02 08:13:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#pragma pack(push,1)
|
|
|
|
typedef struct {
|
|
|
|
union {
|
|
|
|
intptr_t lValue;
|
|
|
|
intptr_t *plValues; // array of values when 'per-player', or 'per-actor'
|
|
|
|
} val;
|
|
|
|
intptr_t lDefault;
|
|
|
|
uintptr_t dwFlags;
|
|
|
|
char *szLabel;
|
|
|
|
} gamevar_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char *szLabel;
|
2012-05-17 23:54:43 +00:00
|
|
|
intptr_t *plValues; // array of values
|
2010-08-02 08:13:51 +00:00
|
|
|
intptr_t size;
|
2012-12-13 02:33:53 +00:00
|
|
|
intptr_t dwFlags;
|
2010-08-02 08:13:51 +00:00
|
|
|
} gamearray_t;
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
2013-05-19 19:29:18 +00:00
|
|
|
# define GAR_ELTSZ (sizeof(aGameArrays[0].plValues[0]))
|
2012-05-25 15:23:48 +00:00
|
|
|
|
2010-08-02 08:13:51 +00:00
|
|
|
extern gamevar_t aGameVars[MAXGAMEVARS];
|
|
|
|
extern gamearray_t aGameArrays[MAXGAMEARRAYS];
|
|
|
|
extern int32_t g_gameVarCount;
|
|
|
|
extern int32_t g_gameArrayCount;
|
|
|
|
|
2014-09-30 04:16:21 +00:00
|
|
|
int32_t __fastcall Gv_GetVar(int32_t id, int32_t iActor, int32_t iPlayer);
|
|
|
|
void __fastcall Gv_SetVar(int32_t id, int32_t lValue, int32_t iActor, int32_t iPlayer);
|
|
|
|
int32_t __fastcall Gv_GetVarX(int32_t id);
|
|
|
|
void __fastcall Gv_SetVarX(int32_t id, int32_t lValue);
|
2012-12-29 15:21:24 +00:00
|
|
|
|
2010-08-02 08:13:51 +00:00
|
|
|
int32_t Gv_GetVarByLabel(const char *szGameLabel,int32_t lDefault,int32_t iActor,int32_t iPlayer);
|
2012-12-13 02:33:53 +00:00
|
|
|
int32_t Gv_NewArray(const char *pszLabel,void *arrayptr,intptr_t asize,uint32_t dwFlags);
|
2011-09-04 23:06:12 +00:00
|
|
|
int32_t Gv_NewVar(const char *pszLabel,intptr_t lValue,uint32_t dwFlags);
|
2014-10-29 17:05:29 +00:00
|
|
|
|
2014-11-22 12:29:25 +00:00
|
|
|
static inline void A_ResetVars(const int32_t iActor)
|
|
|
|
{
|
2015-01-11 04:53:44 +00:00
|
|
|
for (int i = 0; i < g_gameVarCount; i++)
|
2014-10-29 17:05:29 +00:00
|
|
|
{
|
2014-11-22 12:29:25 +00:00
|
|
|
if ((aGameVars[i].dwFlags & (GAMEVAR_PERACTOR | GAMEVAR_NODEFAULT)) == GAMEVAR_PERACTOR)
|
|
|
|
aGameVars[i].val.plValues[iActor] = aGameVars[i].lDefault;
|
2014-10-29 17:05:29 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-22 12:29:25 +00:00
|
|
|
|
2010-08-02 08:13:51 +00:00
|
|
|
void Gv_DumpValues(void);
|
|
|
|
void Gv_InitWeaponPointers(void);
|
|
|
|
void Gv_RefreshPointers(void);
|
|
|
|
void Gv_ResetVars(void);
|
2013-05-19 19:29:18 +00:00
|
|
|
int32_t Gv_ReadSave(int32_t fil,int32_t newbehav);
|
|
|
|
void Gv_WriteSave(FILE *fil,int32_t newbehav);
|
2013-05-30 18:10:59 +00:00
|
|
|
#else
|
2014-01-31 21:13:03 +00:00
|
|
|
extern int32_t g_noResetVars;
|
|
|
|
extern LUNATIC_CB void (*A_ResetVars)(int32_t iActor);
|
2013-01-01 15:24:18 +00:00
|
|
|
#endif
|
2013-05-30 18:10:59 +00:00
|
|
|
|
2013-02-07 21:00:48 +00:00
|
|
|
void Gv_ResetSystemDefaults(void);
|
2013-01-01 15:24:18 +00:00
|
|
|
void Gv_Init(void);
|
2013-06-02 14:07:56 +00:00
|
|
|
void Gv_FinalizeWeaponDefaults(void);
|
Patch from Hendricks266 and whatever changes happened to be in my tree. I hope they work ;)
"The most noticeable change is the addition of the "includedefault" CON and DEF command, which will attempt to include eduke.con (or nam.con, or ww2gi.con), then game.con, or duke3d.def, or nam.def, or ww2gi.def. This is useful for TCs like my add-ons, where for my pseudo-mutators I currently say "include EDUKE.CON", but I also have to juggle this terrible order of paths, so that I can have an EDUKE.CON file in my HRP which says "include GAME.CON" to allow the mainline game to actually run, but also allow DukePlus to load its EDUKE.CON file (since it uses that and not an -x switch), and also allow any custom EDUKE.CON files in the root to be used."
git-svn-id: https://svn.eduke32.com/eduke32@1909 1a8010ca-5511-0410-912e-c29ae57300e0
2011-06-19 00:11:52 +00:00
|
|
|
|
2013-01-20 21:17:06 +00:00
|
|
|
#if !defined LUNATIC
|
2014-11-22 12:29:25 +00:00
|
|
|
#define VM_GAMEVAR_OPERATOR(func, operator) \
|
|
|
|
static inline void __fastcall func(const int32_t id, const int32_t lValue) \
|
|
|
|
{ \
|
|
|
|
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK | GAMEVAR_PTR_MASK)) \
|
|
|
|
{ \
|
|
|
|
default: aGameVars[id].val.lValue operator lValue; break; \
|
|
|
|
case GAMEVAR_PERPLAYER: \
|
|
|
|
if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_p > MAXPLAYERS - 1)) \
|
|
|
|
break; \
|
|
|
|
aGameVars[id].val.plValues[vm.g_p] operator lValue; \
|
|
|
|
break; \
|
|
|
|
case GAMEVAR_PERACTOR: \
|
|
|
|
if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_i > MAXSPRITES - 1)) \
|
|
|
|
break; \
|
|
|
|
aGameVars[id].val.plValues[vm.g_i] operator lValue; \
|
|
|
|
break; \
|
|
|
|
case GAMEVAR_INTPTR: *((int32_t *)aGameVars[id].val.lValue) operator (int32_t) lValue; break; \
|
|
|
|
case GAMEVAR_SHORTPTR: *((int16_t *)aGameVars[id].val.lValue) operator (int16_t) lValue; break; \
|
|
|
|
case GAMEVAR_CHARPTR: *((uint8_t *)aGameVars[id].val.lValue) operator (uint8_t) lValue; break; \
|
|
|
|
} \
|
2014-10-29 17:05:29 +00:00
|
|
|
}
|
Patch from Hendricks266 and whatever changes happened to be in my tree. I hope they work ;)
"The most noticeable change is the addition of the "includedefault" CON and DEF command, which will attempt to include eduke.con (or nam.con, or ww2gi.con), then game.con, or duke3d.def, or nam.def, or ww2gi.def. This is useful for TCs like my add-ons, where for my pseudo-mutators I currently say "include EDUKE.CON", but I also have to juggle this terrible order of paths, so that I can have an EDUKE.CON file in my HRP which says "include GAME.CON" to allow the mainline game to actually run, but also allow DukePlus to load its EDUKE.CON file (since it uses that and not an -x switch), and also allow any custom EDUKE.CON files in the root to be used."
git-svn-id: https://svn.eduke32.com/eduke32@1909 1a8010ca-5511-0410-912e-c29ae57300e0
2011-06-19 00:11:52 +00:00
|
|
|
|
2014-10-25 03:29:21 +00:00
|
|
|
#if defined(__arm__) || defined(LIBDIVIDE_ALWAYS)
|
2014-11-22 12:29:25 +00:00
|
|
|
static inline void __fastcall Gv_DivVar(const int32_t id, const int32_t lValue)
|
2014-10-25 03:29:21 +00:00
|
|
|
{
|
|
|
|
static libdivide_s32_t sdiv;
|
|
|
|
static int32_t lastlValue;
|
|
|
|
libdivide_s32_t *dptr = &sdiv;
|
|
|
|
intptr_t *iptr = &aGameVars[id].val.lValue;
|
|
|
|
|
2014-10-29 17:05:29 +00:00
|
|
|
if (EDUKE32_PREDICT_FALSE((aGameVars[id].dwFlags & GAMEVAR_PERPLAYER && (unsigned)vm.g_p > MAXPLAYERS - 1) ||
|
|
|
|
(aGameVars[id].dwFlags & GAMEVAR_PERACTOR && (unsigned)vm.g_i > MAXSPRITES - 1)))
|
|
|
|
return;
|
2014-10-25 03:29:21 +00:00
|
|
|
|
2014-10-29 17:05:29 +00:00
|
|
|
if ((unsigned)lValue < DIVTABLESIZE)
|
2014-10-25 03:29:21 +00:00
|
|
|
dptr = (libdivide_s32_t *)&divtable32[lValue];
|
|
|
|
else if (lValue != lastlValue)
|
|
|
|
sdiv = libdivide_s32_gen(lValue), lastlValue = lValue;
|
|
|
|
|
2014-10-29 17:05:29 +00:00
|
|
|
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK | GAMEVAR_PTR_MASK))
|
2014-10-25 03:29:21 +00:00
|
|
|
{
|
2014-10-29 17:05:29 +00:00
|
|
|
case GAMEVAR_PERPLAYER: iptr = &aGameVars[id].val.plValues[vm.g_p];
|
|
|
|
default: break;
|
|
|
|
case GAMEVAR_PERACTOR: iptr = &aGameVars[id].val.plValues[vm.g_i]; break;
|
|
|
|
case GAMEVAR_INTPTR:
|
|
|
|
*((int32_t *)aGameVars[id].val.lValue) =
|
|
|
|
(int32_t)libdivide_s32_do(*((int32_t *)aGameVars[id].val.lValue), dptr);
|
|
|
|
return;
|
|
|
|
case GAMEVAR_SHORTPTR:
|
|
|
|
*((int16_t *)aGameVars[id].val.lValue) =
|
|
|
|
(int16_t)libdivide_s32_do(*((int16_t *)aGameVars[id].val.lValue), dptr);
|
|
|
|
return;
|
|
|
|
case GAMEVAR_CHARPTR:
|
|
|
|
*((uint8_t *)aGameVars[id].val.lValue) =
|
|
|
|
(uint8_t)libdivide_s32_do(*((uint8_t *)aGameVars[id].val.lValue), dptr);
|
|
|
|
return;
|
2014-10-25 03:29:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*iptr = libdivide_s32_do(*iptr, dptr);
|
|
|
|
}
|
|
|
|
#else
|
2014-10-29 17:05:29 +00:00
|
|
|
VM_GAMEVAR_OPERATOR(Gv_DivVar, /= )
|
2014-10-25 03:29:21 +00:00
|
|
|
#endif
|
|
|
|
|
2014-10-29 17:05:29 +00:00
|
|
|
VM_GAMEVAR_OPERATOR(Gv_AddVar, +=)
|
|
|
|
VM_GAMEVAR_OPERATOR(Gv_SubVar, -=)
|
|
|
|
VM_GAMEVAR_OPERATOR(Gv_MulVar, *=)
|
|
|
|
VM_GAMEVAR_OPERATOR(Gv_ModVar, %=)
|
|
|
|
VM_GAMEVAR_OPERATOR(Gv_AndVar, &=)
|
|
|
|
VM_GAMEVAR_OPERATOR(Gv_XorVar, ^=)
|
|
|
|
VM_GAMEVAR_OPERATOR(Gv_OrVar, |=)
|
|
|
|
|
|
|
|
#undef VM_GAMEVAR_OPERATOR
|
2014-10-25 03:29:21 +00:00
|
|
|
|
2013-01-20 21:17:06 +00:00
|
|
|
#endif
|
Patch from Hendricks266 and whatever changes happened to be in my tree. I hope they work ;)
"The most noticeable change is the addition of the "includedefault" CON and DEF command, which will attempt to include eduke.con (or nam.con, or ww2gi.con), then game.con, or duke3d.def, or nam.def, or ww2gi.def. This is useful for TCs like my add-ons, where for my pseudo-mutators I currently say "include EDUKE.CON", but I also have to juggle this terrible order of paths, so that I can have an EDUKE.CON file in my HRP which says "include GAME.CON" to allow the mainline game to actually run, but also allow DukePlus to load its EDUKE.CON file (since it uses that and not an -x switch), and also allow any custom EDUKE.CON files in the root to be used."
git-svn-id: https://svn.eduke32.com/eduke32@1909 1a8010ca-5511-0410-912e-c29ae57300e0
2011-06-19 00:11:52 +00:00
|
|
|
|
2010-08-02 08:13:51 +00:00
|
|
|
#endif
|