From 5bfbfa3c5bd4c41dc957b23b1c6418f2cff7bd8b Mon Sep 17 00:00:00 2001 From: helixhorned Date: Thu, 30 May 2013 18:10:59 +0000 Subject: [PATCH] Lunatic: also reset per-actor gamevars from spawns originating from C. Take care not to do it twice. Still untested though. git-svn-id: https://svn.eduke32.com/eduke32@3830 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/game.c | 10 +++++++-- polymer/eduke32/source/gamevars.h | 4 ++++ polymer/eduke32/source/lunatic/control.lua | 25 +++++++++++++++------- polymer/eduke32/source/lunatic/defs.ilua | 3 +++ polymer/eduke32/source/lunatic/dynsymlist | 3 +++ 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 8cd052f4c..343fc6a36 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -4187,9 +4187,15 @@ int32_t A_InsertSprite(int32_t whatsect,int32_t s_x,int32_t s_y,int32_t s_z,int3 Bmemset(&spriteext[i], 0, sizeof(spriteext_t)); Bmemset(&spritesmooth[i], 0, sizeof(spritesmooth_t)); -#if !defined LUNATIC - A_ResetVars(i); + +#if defined LUNATIC + if (!g_noResetVars) #endif + A_ResetVars(i); +#if defined LUNATIC + g_noResetVars = 0; +#endif + if (G_HaveEvent(EVENT_EGS)) { int32_t pl=A_FindPlayer(s, &p); diff --git a/polymer/eduke32/source/gamevars.h b/polymer/eduke32/source/gamevars.h index 31ef8a6c2..772c0eef8 100644 --- a/polymer/eduke32/source/gamevars.h +++ b/polymer/eduke32/source/gamevars.h @@ -111,7 +111,11 @@ void Gv_RefreshPointers(void); void Gv_ResetVars(void); int32_t Gv_ReadSave(int32_t fil,int32_t newbehav); void Gv_WriteSave(FILE *fil,int32_t newbehav); +#else +int32_t g_noResetVars; +LUNATIC_CB void (*A_ResetVars)(int32_t iActor); #endif + void Gv_ResetSystemDefaults(void); void Gv_Init(void); diff --git a/polymer/eduke32/source/lunatic/control.lua b/polymer/eduke32/source/lunatic/control.lua index 362406055..4ffe8dcdc 100644 --- a/polymer/eduke32/source/lunatic/control.lua +++ b/polymer/eduke32/source/lunatic/control.lua @@ -178,29 +178,38 @@ local function check_isnumber(...) end end + -- Table of all per-actor gamevars active in the system. -- [] = true local g_actorvar = setmetatable({}, { __mode="k" }) --- Reset per-actor gamevars for the sprite that would be inserted by an +local function A_ResetVars(i) + for acv in pairs(g_actorvar) do + acv:_clear(i) + end +end + +ffiC.A_ResetVars = A_ResetVars + +-- Reset per-actor gamevars for the sprite that would be inserted by the next -- insertsprite() call. --- KEEPINSYNC with insertsprite() logic in engine.c! -- TODO_MP (Net_InsertSprite() is not handled) -- -- NOTE: usually, a particular actor's code doesn't use ALL per-actor gamevars, -- so there should be a way to clear only a subset of them (maybe those that -- were defined in "its" module?). -local function A_ResetVars() +local function A_ResetVarsNextIns() + -- KEEPINSYNC with insertsprite() logic in engine.c! local i = ffiC.headspritestat[ffiC.MAXSTATUS] if (i < 0) then return end - for acv in pairs(g_actorvar) do - acv:_clear(i) - end + ffiC.g_noResetVars = 1 + return A_ResetVars(i) end + -- Lunatic's "insertsprite" is a wrapper around the game "A_InsertSprite", not -- the engine "insertsprite". -- @@ -245,7 +254,7 @@ function insertsprite(tab_or_tilenum, ...) error("invalid 'statnum' argument to insertsprite: must be a status number (0 .. MAXSTATUS-1)", 2) end - A_ResetVars() + A_ResetVarsNextIns() return CF.A_InsertSprite(sectnum, pos.x, pos.y, pos.z, tilenum, shade, xrepeat, yrepeat, ang, xvel, zvel, @@ -267,7 +276,7 @@ function spawn(parentspritenum, tilenum, addtodelqueue) return -1 end - A_ResetVars() + A_ResetVarsNextIns() local i = CF.A_Spawn(parentspritenum, tilenum) if (addtodelqueue) then diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index 7b6d86b81..dc1d47543 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -593,6 +593,9 @@ tiledata_t g_tile[MAXTILES]; projectile_t ProjectileData[MAXTILES]; projectile_t SpriteProjectile[MAXSPRITES]; +int32_t g_noResetVars; +void (*A_ResetVars)(int32_t iActor); + // Used from lunacon.lua for dynamic tile remapping: struct { diff --git a/polymer/eduke32/source/lunatic/dynsymlist b/polymer/eduke32/source/lunatic/dynsymlist index 46d246e7b..bd28a11ac 100644 --- a/polymer/eduke32/source/lunatic/dynsymlist +++ b/polymer/eduke32/source/lunatic/dynsymlist @@ -139,6 +139,9 @@ g_tile; ProjectileData; SpriteProjectile; +g_noResetVars; +A_ResetVars; + g_dynTileList; ScriptQuotes;