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
This commit is contained in:
helixhorned 2013-05-30 18:10:59 +00:00
parent 97f857ec39
commit 5bfbfa3c5b
5 changed files with 35 additions and 10 deletions

View file

@ -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);

View file

@ -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);

View file

@ -178,29 +178,38 @@ local function check_isnumber(...)
end
end
-- Table of all per-actor gamevars active in the system.
-- [<actorvar reference>] = 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

View file

@ -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
{

View file

@ -139,6 +139,9 @@ g_tile;
ProjectileData;
SpriteProjectile;
g_noResetVars;
A_ResetVars;
g_dynTileList;
ScriptQuotes;