Make gamestructures a proper object

git-svn-id: https://svn.eduke32.com/eduke32@8734 1a8010ca-5511-0410-912e-c29ae57300e0

# Conflicts:
#	GNUmakefile
#	platform/Windows/eduke32.vcxproj
#	platform/Windows/eduke32.vcxproj.filters
#	source/duke3d/src/gamedef.cpp
#	source/duke3d/src/gameexec.cpp
#	source/duke3d/src/gamevars.cpp
#	source/duke3d/src/m32def.cpp
#	source/duke3d/src/m32def.h
#	source/duke3d/src/m32exec.cpp
#	source/duke3d/src/m32structures.cpp
This commit is contained in:
terminx 2020-03-12 01:09:43 +00:00 committed by Christoph Oelckers
parent 21ec33ac51
commit 7dc1a3c904
7 changed files with 122 additions and 82 deletions

View file

@ -39,6 +39,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "menu/menu.h" #include "menu/menu.h"
#include "stringtable.h" #include "stringtable.h"
#include "mapinfo.h" #include "mapinfo.h"
#include "gamestructures.h"
void C_CON_SetButtonAlias(int num, const char* text); void C_CON_SetButtonAlias(int num, const char* text);
void C_CON_ClearButtonAlias(int num); void C_CON_ClearButtonAlias(int num);
@ -1197,7 +1198,7 @@ static inline bool C_IsLabelChar(const char c, int32_t const i)
return (isalnum(c) || c == '_' || c == '*' || c == '?' || (i > 0 && (c == '+' || c == '-'))); return (isalnum(c) || c == '_' || c == '*' || c == '?' || (i > 0 && (c == '+' || c == '-')));
} }
static inline int32_t C_GetLabelNameID(const memberlabel_t *pLabel, hashtable_t const * const table, const char *psz) static inline int32_t C_GetLabelNameID(memberlabel_t const *pLabel, hashtable_t const * const table, const char *psz)
{ {
// find the label psz in the table pLabel. // find the label psz in the table pLabel.
// returns the ID for the label, or -1 // returns the ID for the label, or -1
@ -5929,7 +5930,7 @@ void C_Compile(const char *fileName)
actorMinMs = 1e308; actorMinMs = 1e308;
scriptInitTables(); scriptInitTables();
scriptInitStructTables(); VM_InitHashTables();
Gv_Init(); Gv_Init();
C_InitProjectiles(); C_InitProjectiles();

View file

@ -143,38 +143,6 @@ extern const char *EventNames[MAXEVENTS];
#if !defined LUNATIC #if !defined LUNATIC
extern intptr_t *g_scriptPtr; extern intptr_t *g_scriptPtr;
typedef struct
{
const char *name;
int32_t lId;
uint32_t flags;
int16_t maxParm2;
int16_t offset;
} memberlabel_t;
extern const memberlabel_t ActorLabels[];
extern const memberlabel_t InputLabels[];
extern const memberlabel_t PalDataLabels[];
extern const memberlabel_t PlayerLabels[];
extern const memberlabel_t ProjectileLabels[];
extern const memberlabel_t SectorLabels[];
extern const memberlabel_t TileDataLabels[];
extern const memberlabel_t TsprLabels[];
extern const memberlabel_t UserdefsLabels[];
extern const memberlabel_t WallLabels[];
extern hashtable_t h_actor;
extern hashtable_t h_input;
extern hashtable_t h_paldata;
extern hashtable_t h_player;
extern hashtable_t h_projectile;
extern hashtable_t h_sector;
extern hashtable_t h_tiledata;
extern hashtable_t h_tsprite;
extern hashtable_t h_userdef;
extern hashtable_t h_wall;
#endif #endif
typedef projectile_t defaultprojectile_t; typedef projectile_t defaultprojectile_t;

View file

@ -25,9 +25,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "anim.h" #include "anim.h"
#include "cmdline.h" #include "cmdline.h"
#include "imagehelpers.h" #include "imagehelpers.h"
#include "communityapi.h"
#include "compat.h" #include "compat.h"
#include "duke3d.h" #include "duke3d.h"
#include "gamestructures.h"
#include "input.h"
#include "menus.h" #include "menus.h"
#include "osdcmds.h" #include "osdcmds.h"
#include "savegame.h" #include "savegame.h"
@ -87,7 +89,6 @@ double g_eventTotalMs[MAXEVENTS], g_actorTotalMs[MAXTILES], g_actorMinMs[MAXTILE
GAMEEXEC_STATIC void VM_Execute(int const loop = false); GAMEEXEC_STATIC void VM_Execute(int const loop = false);
# include "gamestructures.cpp"
#endif #endif
#if !defined LUNATIC #if !defined LUNATIC

View file

@ -20,30 +20,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// this is all the crap for accessing the game's structs through the CON VM #include "gamestructures.h"
// I got a 3-4 fps gain by inlining these...
#include "compat.h"
#include "gamedef.h"
#include "sector.h"
#include "gameexec.h"
#include "global.h"
#ifndef gamevars_c_
int32_t __fastcall VM_GetUserdef(int32_t labelNum, int const lParm2);
void __fastcall VM_SetUserdef(int const labelNum, int const lParm2, int32_t const newValue);
int32_t __fastcall VM_GetActiveProjectile(int const spriteNum, int32_t labelNum);
void __fastcall VM_SetActiveProjectile(int const spriteNum, int const labelNum, int32_t const newValue);
int32_t __fastcall VM_GetPlayer(int const playerNum, int32_t labelNum, int const lParm2);
void __fastcall VM_SetPlayer(int const playerNum, int const labelNum, int const lParm2, int32_t const newValue);
int32_t __fastcall VM_GetPlayerInput(int const playerNum, int32_t labelNum);
void __fastcall VM_SetPlayerInput(int const playerNum, int const labelNum, int32_t const newValue);
int32_t __fastcall VM_GetWall(int const wallNum, int32_t labelNum);
void __fastcall VM_SetWall(int const wallNum, int const labelNum, int32_t const newValue);
int32_t __fastcall VM_GetSector(int const sectNum, int32_t labelNum);
void __fastcall VM_SetSector(int const sectNum, int const labelNum, int32_t newValue);
int32_t __fastcall VM_GetSprite(int const spriteNum, int32_t labelNum, int const lParm2);
void __fastcall VM_SetSprite(int const spriteNum, int const labelNum, int const lParm2, int32_t const newValue);
int32_t __fastcall VM_GetProjectile(int const tileNum, int32_t labelNum);
void __fastcall VM_SetProjectile(int const tileNum, int const labelNum, int32_t const newValue);
int32_t __fastcall VM_GetTileData(int const tileNum, int32_t labelNum);
void __fastcall VM_SetTileData(int const tileNum, int const labelNum, int32_t const newValue);
int32_t __fastcall VM_GetPalData(int const palNum, int32_t labelNum);
#else
#define LABEL_SETUP_UNMATCHED(struct, memb, name, idx) \ #define LABEL_SETUP_UNMATCHED(struct, memb, name, idx) \
{ \ { \
name, idx, sizeof(struct[0].memb) | (is_unsigned<decltype(struct[0].memb)>::value ? LABEL_UNSIGNED : 0), 0, \ name, idx, sizeof(struct[0].memb) | (is_unsigned<decltype(struct[0].memb)>::value ? LABEL_UNSIGNED : 0), 0, \
@ -52,7 +36,7 @@ int32_t __fastcall VM_GetPalData(int const palNum, int32_t labelNum);
#define LABEL_SETUP(struct, memb, idx) LABEL_SETUP_UNMATCHED(struct, memb, #memb, idx) #define LABEL_SETUP(struct, memb, idx) LABEL_SETUP_UNMATCHED(struct, memb, #memb, idx)
const memberlabel_t SectorLabels[] = { memberlabel_t const SectorLabels[] = {
{ "wallptr", SECTOR_WALLPTR, sizeof(sector[0].wallptr) | LABEL_WRITEFUNC, 0, offsetof(usectortype, wallptr) }, { "wallptr", SECTOR_WALLPTR, sizeof(sector[0].wallptr) | LABEL_WRITEFUNC, 0, offsetof(usectortype, wallptr) },
LABEL_SETUP(sector, wallnum, SECTOR_WALLNUM), LABEL_SETUP(sector, wallnum, SECTOR_WALLNUM),
@ -176,7 +160,7 @@ void __fastcall VM_SetSector(int const sectNum, int const labelNum, int32_t newV
} }
} }
const memberlabel_t WallLabels[]= memberlabel_t const WallLabels[]=
{ {
LABEL_SETUP(wall, x, WALL_X), LABEL_SETUP(wall, x, WALL_X),
LABEL_SETUP(wall, y, WALL_Y), LABEL_SETUP(wall, y, WALL_Y),
@ -247,7 +231,7 @@ void __fastcall VM_SetWall(int const wallNum, int const labelNum, int32_t const
} }
const memberlabel_t ActorLabels[]= memberlabel_t const ActorLabels[]=
{ {
LABEL_SETUP(sprite, x, ACTOR_X), LABEL_SETUP(sprite, x, ACTOR_X),
LABEL_SETUP(sprite, y, ACTOR_Y), LABEL_SETUP(sprite, y, ACTOR_Y),
@ -357,7 +341,7 @@ int32_t __fastcall VM_GetSprite(int const spriteNum, int32_t labelNum, int const
return labelNum; return labelNum;
} }
const memberlabel_t TsprLabels[] = memberlabel_t const TsprLabels[] =
{ {
// tsprite access // tsprite access
@ -386,7 +370,7 @@ const memberlabel_t TsprLabels[] =
LABEL_SETUP_UNMATCHED(sprite, extra, "tsprextra", ACTOR_EXTRA), LABEL_SETUP_UNMATCHED(sprite, extra, "tsprextra", ACTOR_EXTRA),
}; };
const memberlabel_t PlayerLabels[]= memberlabel_t const PlayerLabels[]=
{ {
{ "zoom", PLAYER_ZOOM, 0, 0, -1 }, { "zoom", PLAYER_ZOOM, 0, 0, -1 },
{ "loogiex", PLAYER_LOOGIEX, LABEL_HASPARM2, 64, -1 }, { "loogiex", PLAYER_LOOGIEX, LABEL_HASPARM2, 64, -1 },
@ -963,7 +947,7 @@ void __fastcall VM_SetPlayer(int const playerNum, int const labelNum, int const
} }
} }
const memberlabel_t ProjectileLabels[]= memberlabel_t const ProjectileLabels[]=
{ {
{ "workslike", PROJ_WORKSLIKE, 0, 0, -1 }, { "workslike", PROJ_WORKSLIKE, 0, 0, -1 },
{ "spawns", PROJ_SPAWNS, 0, 0, -1 }, { "spawns", PROJ_SPAWNS, 0, 0, -1 },
@ -1185,7 +1169,7 @@ void __fastcall VM_SetActiveProjectile(int const spriteNum, int const labelNum,
} }
} }
const memberlabel_t UserdefsLabels[]= memberlabel_t const UserdefsLabels[]=
{ {
{ "god", USERDEFS_GOD, 0, 0, -1 }, { "god", USERDEFS_GOD, 0, 0, -1 },
{ "warp_on", USERDEFS_WARP_ON, 0, 0, -1 }, { "warp_on", USERDEFS_WARP_ON, 0, 0, -1 },
@ -1759,7 +1743,7 @@ void __fastcall VM_SetUserdef(int const labelNum, int const lParm2, int32_t cons
} }
} }
const memberlabel_t InputLabels[]= memberlabel_t const InputLabels[]=
{ {
{ "avel", INPUT_AVEL, 0, 0, -1 }, { "avel", INPUT_AVEL, 0, 0, -1 },
{ "q16avel", INPUT_Q16AVEL, 0, 0, -1 }, { "q16avel", INPUT_Q16AVEL, 0, 0, -1 },
@ -1829,7 +1813,7 @@ void __fastcall VM_SetPlayerInput(int const playerNum, int const labelNum, int32
} }
} }
const memberlabel_t TileDataLabels[]= memberlabel_t const TileDataLabels[]=
{ {
// tilesiz[] // tilesiz[]
{ "xsize", TILEDATA_XSIZE, 0, 0, -1 }, { "xsize", TILEDATA_XSIZE, 0, 0, -1 },
@ -1902,7 +1886,7 @@ void __fastcall VM_SetTileData(int const tileNum, int const labelNum, int32_t ne
} }
} }
const memberlabel_t PalDataLabels[]= memberlabel_t const PalDataLabels[]=
{ {
// g_noFloorPal[] // g_noFloorPal[]
{ "nofloorpal", PALDATA_NOFLOORPAL, 0, 0, -1 }, { "nofloorpal", PALDATA_NOFLOORPAL, 0, 0, -1 },
@ -1938,10 +1922,6 @@ hashtable_t h_tsprite = { ACTOR_END>>1, NULL };
hashtable_t h_userdef = { USERDEFS_END>>1, NULL }; hashtable_t h_userdef = { USERDEFS_END>>1, NULL };
hashtable_t h_wall = { WALL_END>>1, NULL }; hashtable_t h_wall = { WALL_END>>1, NULL };
static hashtable_t *const struct_tables[] = {
&h_actor, &h_input, &h_paldata, &h_player, &h_projectile, &h_sector, &h_tiledata, &h_tsprite, &h_userdef, &h_wall,
};
#define STRUCT_HASH_SETUP(table, labels) \ #define STRUCT_HASH_SETUP(table, labels) \
do \ do \
{ \ { \
@ -1950,9 +1930,9 @@ static hashtable_t *const struct_tables[] = {
EDUKE32_STATIC_ASSERT(ARRAY_SSIZE(labels) != 0); \ EDUKE32_STATIC_ASSERT(ARRAY_SSIZE(labels) != 0); \
} while (0) } while (0)
void scriptInitStructTables(void) void VM_InitHashTables(void)
{ {
for (auto table : struct_tables) for (auto table : vmStructHashTablePtrs)
hash_init(table); hash_init(table);
inithashnames(); inithashnames();
@ -1971,4 +1951,3 @@ void scriptInitStructTables(void)
} }
#undef STRUCT_HASH_SETUP #undef STRUCT_HASH_SETUP
#endif

View file

@ -0,0 +1,94 @@
//-------------------------------------------------------------------------
/*
Copyright (C) 2004-2020 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
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//-------------------------------------------------------------------------
#pragma once
#ifndef gamestructures_h__
#define gamestructures_h__
#include "compat.h"
#include "hash.h"
#ifdef __cplusplus
extern "C" {
#endif
int32_t __fastcall VM_GetUserdef(int32_t labelNum, int const lParm2);
void __fastcall VM_SetUserdef(int const labelNum, int const lParm2, int32_t const newValue);
int32_t __fastcall VM_GetActiveProjectile(int const spriteNum, int32_t labelNum);
void __fastcall VM_SetActiveProjectile(int const spriteNum, int const labelNum, int32_t const newValue);
int32_t __fastcall VM_GetPlayer(int const playerNum, int32_t labelNum, int const lParm2);
void __fastcall VM_SetPlayer(int const playerNum, int const labelNum, int const lParm2, int32_t const newValue);
int32_t __fastcall VM_GetPlayerInput(int const playerNum, int32_t labelNum);
void __fastcall VM_SetPlayerInput(int const playerNum, int const labelNum, int32_t const newValue);
int32_t __fastcall VM_GetWall(int const wallNum, int32_t labelNum);
void __fastcall VM_SetWall(int const wallNum, int const labelNum, int32_t const newValue);
int32_t __fastcall VM_GetSector(int const sectNum, int32_t labelNum);
void __fastcall VM_SetSector(int const sectNum, int const labelNum, int32_t newValue);
int32_t __fastcall VM_GetSprite(int const spriteNum, int32_t labelNum, int const lParm2);
void __fastcall VM_SetSprite(int const spriteNum, int const labelNum, int const lParm2, int32_t const newValue);
int32_t __fastcall VM_GetProjectile(int const tileNum, int32_t labelNum);
void __fastcall VM_SetProjectile(int const tileNum, int const labelNum, int32_t const newValue);
int32_t __fastcall VM_GetTileData(int const tileNum, int32_t labelNum);
void __fastcall VM_SetTileData(int const tileNum, int const labelNum, int32_t const newValue);
int32_t __fastcall VM_GetPalData(int const palNum, int32_t labelNum);
typedef struct
{
const char *name;
int32_t lId;
uint32_t flags;
int16_t maxParm2;
int16_t offset;
} memberlabel_t;
extern memberlabel_t const ActorLabels[];
extern memberlabel_t const InputLabels[];
extern memberlabel_t const PalDataLabels[];
extern memberlabel_t const PlayerLabels[];
extern memberlabel_t const ProjectileLabels[];
extern memberlabel_t const SectorLabels[];
extern memberlabel_t const TileDataLabels[];
extern memberlabel_t const TsprLabels[];
extern memberlabel_t const UserdefsLabels[];
extern memberlabel_t const WallLabels[];
extern hashtable_t h_actor;
extern hashtable_t h_input;
extern hashtable_t h_paldata;
extern hashtable_t h_player;
extern hashtable_t h_projectile;
extern hashtable_t h_sector;
extern hashtable_t h_tiledata;
extern hashtable_t h_tsprite;
extern hashtable_t h_userdef;
extern hashtable_t h_wall;
static hashtable_t *const vmStructHashTablePtrs[] = {
&h_actor, &h_input, &h_paldata, &h_player, &h_projectile, &h_sector, &h_tiledata, &h_tsprite, &h_userdef, &h_wall,
};
#ifdef __cplusplus
}
#endif
#endif // gamestructures_h__

View file

@ -29,8 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "menu/menu.h" #include "menu/menu.h"
BEGIN_DUKE_NS BEGIN_DUKE_NS
#include "gamestructures.h"
#define gamevars_c_
#ifdef LUNATIC #ifdef LUNATIC
int32_t g_noResetVars; int32_t g_noResetVars;
@ -63,8 +62,6 @@ intptr_t *aplWeaponSpawnTime[MAX_WEAPONS]; // the frame at which to spawn a
intptr_t *aplWeaponTotalTime[MAX_WEAPONS]; // The total time the weapon is cycling before next fire. intptr_t *aplWeaponTotalTime[MAX_WEAPONS]; // The total time the weapon is cycling before next fire.
intptr_t *aplWeaponWorksLike[MAX_WEAPONS]; // What original the weapon works like intptr_t *aplWeaponWorksLike[MAX_WEAPONS]; // What original the weapon works like
# include "gamestructures.cpp"
// Frees the memory for the *values* of game variables and arrays. Resets their // Frees the memory for the *values* of game variables and arrays. Resets their
// counts to zero. Call this function as many times as needed. // counts to zero. Call this function as many times as needed.
// //
@ -109,7 +106,7 @@ void Gv_Clear(void)
for (auto & gameArray : aGameArrays) for (auto & gameArray : aGameArrays)
DO_FREE_AND_NULL(gameArray.szLabel); DO_FREE_AND_NULL(gameArray.szLabel);
for (auto i : struct_tables) for (auto i : vmStructHashTablePtrs)
hash_free(i); hash_free(i);
} }

View file

@ -152,7 +152,7 @@ static FORCE_INLINE void A_ResetVars(int const spriteNum)
gv.pValues[spriteNum] = gv.defaultValue; gv.pValues[spriteNum] = gv.defaultValue;
} }
} }
void scriptInitStructTables(void); void VM_InitHashTables(void);
void Gv_DumpValues(void); void Gv_DumpValues(void);
void Gv_InitWeaponPointers(void); void Gv_InitWeaponPointers(void);
void Gv_RefreshPointers(void); void Gv_RefreshPointers(void);