From 020be8d4b59180e2d3e874971a76a7bf5e81f68d Mon Sep 17 00:00:00 2001 From: helixhorned Date: Thu, 30 May 2013 18:10:52 +0000 Subject: [PATCH] Lunatic: reset per-actor gamevars on actor spawn, untested. git-svn-id: https://svn.eduke32.com/eduke32@3828 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/lunatic/control.lua | 34 +++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/polymer/eduke32/source/lunatic/control.lua b/polymer/eduke32/source/lunatic/control.lua index 563a4e8b6..362406055 100644 --- a/polymer/eduke32/source/lunatic/control.lua +++ b/polymer/eduke32/source/lunatic/control.lua @@ -178,6 +178,29 @@ 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 +-- 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 i = ffiC.headspritestat[ffiC.MAXSTATUS] + if (i < 0) then + return + end + + for acv in pairs(g_actorvar) do + acv:_clear(i) + end +end + -- Lunatic's "insertsprite" is a wrapper around the game "A_InsertSprite", not -- the engine "insertsprite". -- @@ -222,6 +245,8 @@ function insertsprite(tab_or_tilenum, ...) error("invalid 'statnum' argument to insertsprite: must be a status number (0 .. MAXSTATUS-1)", 2) end + A_ResetVars() + return CF.A_InsertSprite(sectnum, pos.x, pos.y, pos.z, tilenum, shade, xrepeat, yrepeat, ang, xvel, zvel, owner, statnum) @@ -242,6 +267,8 @@ function spawn(parentspritenum, tilenum, addtodelqueue) return -1 end + A_ResetVars() + local i = CF.A_Spawn(parentspritenum, tilenum) if (addtodelqueue) then CF.A_AddToDeleteQueue(i) @@ -2042,11 +2069,15 @@ local actorvar_methods = { _cleanup = function(acv) for i=0,ffiC.MAXSPRITES-1 do if (ffiC.sprite[i].statnum == ffiC.MAXSTATUS or rawget(acv, i)==acv._defval) then - rawset(acv, i, nil) + acv:_clear(i) end end end, + _clear = function(acv, i) + rawset(acv, i, nil) + end, + --- Serialization --- @@ -2086,5 +2117,6 @@ local actorvar_mt = { -- : optional, a table of =value function actorvar(initval, values) local acv = setmetatable({ _defval=initval }, actorvar_mt) + g_actorvar[acv] = true return set_values_from_table(acv, values) end