From 185597d3b3f597e2dbba9820ebcb9cc4b8c08281 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sun, 2 Jun 2013 14:07:56 +0000 Subject: [PATCH] LunaCON: proper handling of dynamic remappings with weapon defaults. That is, the gamevars named WEAPONx_* in CON will now have the remapped value if they were not overridden from CON ('gamevar' at file scope). For C-CON, everything except signaling an override from the CON parser is in place. git-svn-id: https://svn.eduke32.com/eduke32@3848 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/game.c | 7 +- polymer/eduke32/source/gamevars.c | 71 +++++++++++++++---- polymer/eduke32/source/gamevars.h | 1 + polymer/eduke32/source/lunatic/defs.ilua | 20 +++++- .../eduke32/source/lunatic/defs_common.lua | 2 +- polymer/eduke32/source/lunatic/dynsymlist | 2 + polymer/eduke32/source/lunatic/lunacon.lua | 2 +- polymer/eduke32/source/m32vars.c | 2 - 8 files changed, 88 insertions(+), 19 deletions(-) diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 2f7ca504d..1098836c1 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -10671,6 +10671,9 @@ static void G_Startup(void) G_InitDynamicTiles(); G_InitDynamicSounds(); + + // These depend on having the dynamic tile and/or sound mappings set up: + Gv_FinalizeWeaponDefaults(); G_PostCreateGameState(); if (g_netServer || ud.multimode > 1) G_CheckGametype(); @@ -10920,11 +10923,11 @@ static int32_t check_filename_casing(void) const char *g_sizes_of_what[] = { "sectortype", "walltype", "spritetype", "spriteext_t", "actor_t", "DukePlayer_t", "playerdata_t", - "user_defs", "tiledata_t" }; + "user_defs", "tiledata_t", "weapondata_t" }; int32_t g_sizes_of[] = { sizeof(sectortype), sizeof(walltype), sizeof(spritetype), sizeof(spriteext_t), sizeof(actor_t), sizeof(DukePlayer_t), sizeof(playerdata_t), - sizeof(user_defs), sizeof(tiledata_t) }; + sizeof(user_defs), sizeof(tiledata_t), sizeof(weapondata_t) }; DukePlayer_t *g_player_ps[MAXPLAYERS]; #endif diff --git a/polymer/eduke32/source/gamevars.c b/polymer/eduke32/source/gamevars.c index 9ab7236c1..6b760189c 100644 --- a/polymer/eduke32/source/gamevars.c +++ b/polymer/eduke32/source/gamevars.c @@ -1067,6 +1067,12 @@ void Gv_ResetSystemDefaults(void) //AddLog("EOF:ResetWeaponDefaults"); } +// Will set members that were overridden at CON translation time to 1. +// For example, if +// gamevar WEAPON1_SHOOTS 2200 GAMEVAR_PERPLAYER +// was specified at file scope, g_weaponOverridden[1].Shoots will be 1. +weapondata_t g_weaponOverridden[MAX_WEAPONS]; + static weapondata_t weapondefaults[MAX_WEAPONS] = { /* WorksLike, Clip, Reload, FireDelay, TotalTime, HoldDelay, @@ -1199,6 +1205,9 @@ static int32_t G_StaticToDynamicSound(int32_t sound) } } +// Initialize WEAPONx_* gamevars. Since for Lunatic, they reside on the C side, +// they're set directly. In C-CON, a new CON variable is defined together with +// its initial value. #ifdef LUNATIC # define ADDWEAPONVAR(Weapidx, Membname) do { \ int32_t j; \ @@ -1213,6 +1222,54 @@ static int32_t G_StaticToDynamicSound(int32_t sound) } while (0) #endif +// After CON translation, get not-overridden members from weapondefaults[] back +// into the live arrays! (That is, g_playerWeapon[][] for Lunatic, WEAPONx_* +// gamevars on the CON side in C-CON.) +#ifdef LUNATIC +# define POSTADDWEAPONVAR(Weapidx, Membname) ADDWEAPONVAR(Weapidx, Membname) +#else +// NYI +# define POSTADDWEAPONVAR(Weapidx, Membname) do {} while (0) +#endif + +// Finish a default weapon member after CON translation. If it was not +// overridden from CON itself (see example at g_weaponOverridden[]), we set +// both the weapondefaults[] entry (probably dead by now) and the live value. +#define FINISH_WEAPON_DEFAULT_X(What, i, Membname) do { \ + if (!g_weaponOverridden[i].Membname) \ + { \ + weapondefaults[i].Membname = G_StaticToDynamic##What(weapondefaults[i].Membname); \ + POSTADDWEAPONVAR(i, Membname); \ + } \ +} while (0) + +#define FINISH_WEAPON_DEFAULT_TILE(i, Membname) FINISH_WEAPON_DEFAULT_X(Tile, i, Membname) +#define FINISH_WEAPON_DEFAULT_SOUND(i, Membname) FINISH_WEAPON_DEFAULT_X(Sound, i, Membname) + +// Process the dynamic {tile,sound} mappings after CON has been translated. +// We cannot do this before, because the dynamic maps are not yet set up then. +void Gv_FinalizeWeaponDefaults(void) +{ + int32_t i; + + for (i=0; i= ffiC.MAX_WEAPONS+0ULL)) + + -- Set g_weaponOverridden[wi][member], but without invoking + -- weapondata_t's __newindex metamethod (i.e. us)! + ffi.cast(weapondata_ptr_ct, ffiC.g_weaponOverridden[wi])[member] = 1 + end end, } ffi.metatype("weapondata_t", weapondata_mt) diff --git a/polymer/eduke32/source/lunatic/defs_common.lua b/polymer/eduke32/source/lunatic/defs_common.lua index fd3fa4e12..54eb7a721 100644 --- a/polymer/eduke32/source/lunatic/defs_common.lua +++ b/polymer/eduke32/source/lunatic/defs_common.lua @@ -16,7 +16,7 @@ local bit = require("bit") -- 2: disable JIT compilation -- 4: load LuaJIT's 'v' module, printing trace info -- 8: load LuaJIT's 'dump' module, printing generated IR/machine code -ffi.cdef "enum { _DEBUG_LUNATIC=2 }" +ffi.cdef "enum { _DEBUG_LUNATIC=1 }" if (bit.band(ffiC._DEBUG_LUNATIC, 2)~=0) then require("jit").off() diff --git a/polymer/eduke32/source/lunatic/dynsymlist b/polymer/eduke32/source/lunatic/dynsymlist index f173bd9c1..31b6538c9 100644 --- a/polymer/eduke32/source/lunatic/dynsymlist +++ b/polymer/eduke32/source/lunatic/dynsymlist @@ -124,6 +124,7 @@ C_DefineSkillName; C_DefineLevelName; C_DefineProjectile; C_DefineGameFuncName; +C_DefineGameType; C_SetDefName; SCRIPT_GetNumber; @@ -135,6 +136,7 @@ ud; g_player; g_player_ps; g_playerWeapon; +g_weaponOverridden; g_tile; ProjectileData; SpriteProjectile; diff --git a/polymer/eduke32/source/lunatic/lunacon.lua b/polymer/eduke32/source/lunatic/lunacon.lua index f5611dd86..d007cccc9 100644 --- a/polymer/eduke32/source/lunatic/lunacon.lua +++ b/polymer/eduke32/source/lunatic/lunacon.lua @@ -1222,7 +1222,7 @@ function Cmd.gamevar(identifier, initval, flags) -- Emit code to set the variable at Lua parse time. if (bit.band(oflags, GVFLAG.PERPLAYER) ~= 0) then - -- Replace player index by 0. + -- Replace player index by 0. PLAYER_0. -- TODO_MP: init for all players. local pvar, numrepls = ogv.name:gsub("_pli", "0") assert(numrepls>=1) diff --git a/polymer/eduke32/source/m32vars.c b/polymer/eduke32/source/m32vars.c index 7747ccee0..b8a566501 100644 --- a/polymer/eduke32/source/m32vars.c +++ b/polymer/eduke32/source/m32vars.c @@ -518,8 +518,6 @@ static void Gv_AddSystemVars(void) // only call ONCE int32_t hlcnt_id, hlscnt_id; - //AddLog("Gv_AddSystemVars"); - // special vars for struct access // MUST be at top and in this order!!! Gv_NewVar("sprite", -1, GAMEVAR_READONLY | GAMEVAR_SYSTEM | GAMEVAR_SPECIAL);