diff --git a/source/duke3d/src/gamedef.cpp b/source/duke3d/src/gamedef.cpp index dc6aa5cdd..c600a123b 100644 --- a/source/duke3d/src/gamedef.cpp +++ b/source/duke3d/src/gamedef.cpp @@ -39,6 +39,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "menu/menu.h" #include "stringtable.h" #include "mapinfo.h" +#include "gamestructures.h" void C_CON_SetButtonAlias(int num, const char* text); 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 == '-'))); } -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. // returns the ID for the label, or -1 @@ -5929,7 +5930,7 @@ void C_Compile(const char *fileName) actorMinMs = 1e308; scriptInitTables(); - scriptInitStructTables(); + VM_InitHashTables(); Gv_Init(); C_InitProjectiles(); diff --git a/source/duke3d/src/gamedef.h b/source/duke3d/src/gamedef.h index 5e5819b04..9d784bab3 100644 --- a/source/duke3d/src/gamedef.h +++ b/source/duke3d/src/gamedef.h @@ -143,38 +143,6 @@ extern const char *EventNames[MAXEVENTS]; #if !defined LUNATIC 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 typedef projectile_t defaultprojectile_t; diff --git a/source/duke3d/src/gameexec.cpp b/source/duke3d/src/gameexec.cpp index cb98ec494..ab1eaba55 100644 --- a/source/duke3d/src/gameexec.cpp +++ b/source/duke3d/src/gameexec.cpp @@ -25,9 +25,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "anim.h" #include "cmdline.h" #include "imagehelpers.h" +#include "communityapi.h" #include "compat.h" #include "duke3d.h" - +#include "gamestructures.h" +#include "input.h" #include "menus.h" #include "osdcmds.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); -# include "gamestructures.cpp" #endif #if !defined LUNATIC diff --git a/source/duke3d/src/gamestructures.cpp b/source/duke3d/src/gamestructures.cpp index f8150d56a..0fb408de7 100644 --- a/source/duke3d/src/gamestructures.cpp +++ b/source/duke3d/src/gamestructures.cpp @@ -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 -// I got a 3-4 fps gain by inlining these... +#include "gamestructures.h" + +#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) \ { \ name, idx, sizeof(struct[0].memb) | (is_unsigned::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) -const memberlabel_t SectorLabels[] = { +memberlabel_t const SectorLabels[] = { { "wallptr", SECTOR_WALLPTR, sizeof(sector[0].wallptr) | LABEL_WRITEFUNC, 0, offsetof(usectortype, wallptr) }, 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, 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, y, ACTOR_Y), @@ -357,7 +341,7 @@ int32_t __fastcall VM_GetSprite(int const spriteNum, int32_t labelNum, int const return labelNum; } -const memberlabel_t TsprLabels[] = +memberlabel_t const TsprLabels[] = { // tsprite access @@ -386,7 +370,7 @@ const memberlabel_t TsprLabels[] = LABEL_SETUP_UNMATCHED(sprite, extra, "tsprextra", ACTOR_EXTRA), }; -const memberlabel_t PlayerLabels[]= +memberlabel_t const PlayerLabels[]= { { "zoom", PLAYER_ZOOM, 0, 0, -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 }, { "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 }, { "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 }, { "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[] { "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[] { "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_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) \ do \ { \ @@ -1950,9 +1930,9 @@ static hashtable_t *const struct_tables[] = { EDUKE32_STATIC_ASSERT(ARRAY_SSIZE(labels) != 0); \ } while (0) -void scriptInitStructTables(void) +void VM_InitHashTables(void) { - for (auto table : struct_tables) + for (auto table : vmStructHashTablePtrs) hash_init(table); inithashnames(); @@ -1971,4 +1951,3 @@ void scriptInitStructTables(void) } #undef STRUCT_HASH_SETUP -#endif diff --git a/source/duke3d/src/gamestructures.h b/source/duke3d/src/gamestructures.h new file mode 100644 index 000000000..a3fb1e145 --- /dev/null +++ b/source/duke3d/src/gamestructures.h @@ -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__ \ No newline at end of file diff --git a/source/duke3d/src/gamevars.cpp b/source/duke3d/src/gamevars.cpp index 6a0fdc041..6a0c7d069 100644 --- a/source/duke3d/src/gamevars.cpp +++ b/source/duke3d/src/gamevars.cpp @@ -29,8 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "menu/menu.h" BEGIN_DUKE_NS - -#define gamevars_c_ +#include "gamestructures.h" #ifdef LUNATIC 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 *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 // counts to zero. Call this function as many times as needed. // @@ -109,7 +106,7 @@ void Gv_Clear(void) for (auto & gameArray : aGameArrays) DO_FREE_AND_NULL(gameArray.szLabel); - for (auto i : struct_tables) + for (auto i : vmStructHashTablePtrs) hash_free(i); } diff --git a/source/duke3d/src/gamevars.h b/source/duke3d/src/gamevars.h index b413f3850..89262e7af 100644 --- a/source/duke3d/src/gamevars.h +++ b/source/duke3d/src/gamevars.h @@ -152,7 +152,7 @@ static FORCE_INLINE void A_ResetVars(int const spriteNum) gv.pValues[spriteNum] = gv.defaultValue; } } -void scriptInitStructTables(void); +void VM_InitHashTables(void); void Gv_DumpValues(void); void Gv_InitWeaponPointers(void); void Gv_RefreshPointers(void);