Lunatic: add preliminary helper code for local gamevar saving.

git-svn-id: https://svn.eduke32.com/eduke32@3858 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-06-07 10:18:20 +00:00
parent 34138cdc96
commit 528366da46
2 changed files with 33 additions and 5 deletions

View File

@ -443,7 +443,7 @@ local function A_FP_ManhattanDist(ps, spr)
end
-- Returns: player index, distance
-- TODO: MP case
-- TODO_MP
function _findplayer(pli, spritenum)
return 0, A_FP_ManhattanDist(player[pli], sprite[spritenum])
end
@ -981,7 +981,7 @@ function _pstomp(ps, i)
end
function _pkick(ps, spr)
-- TODO: multiplayer branch
-- TODO_MP
if (spr.picnum~=D.APLAYER and ps.quick_kick==0) then
ps.quick_kick = 14
end
@ -1514,7 +1514,7 @@ function _ifp(flags, pli, aci)
elseif (band(l,32768)~=0 and sprite[ps.i].extra <= 0) then
return true
elseif (band(l,65536)~=0) then
-- TODO: multiplayer branch
-- TODO_MP
if (_angdiffabs(ps.ang, ffiC.getangle(sprite[aci].x-ps.pos.x, sprite[aci].y-ps.pos.y)) < 128) then
return true
end
@ -2119,8 +2119,8 @@ local actorvar_methods = {
_serialize = function(acv)
local strtab = { OUR_NAME..".actorvar(", tostring(acv._defval), ",{" }
-- TODO: Must clean up sometime if not saving, too. (That is, what is
-- A_ResetVars() in the C-CON build.)
-- NOTE: We also clean up when spawning a sprite, too. (See
-- A_ResetVars() and related functions above.)
acv:_cleanup()
return serialize_array(acv, strtab, ffiC.MAXSPRITES)
end,

View File

@ -1352,6 +1352,7 @@ end
local package_loaded = {} -- [<modname>] = false/true/table
local modname_stack = {} -- [<depth>]=string
local module_gamevars = {} -- [<modname>] = { <gvname1>, <gvname2>, ... }
local module_gvlocali = {} -- [<modname>] = { <localidx_beg>, <localidx_end> }
local function getcurmodname(thisfuncname)
if (#modname_stack == 0) then
@ -1379,6 +1380,24 @@ local function readintostr_mod(fn)
end
local debug = require("debug")
-- Get the number of active locals in the function that calls the function
-- calling this one.
local function getnumlocals(l)
-- 200 is the max. number of locals at one level
for i=1,200 do
-- level:
-- 0 is getlocal() itself.
-- 1 is this function.
-- 2 is the function calling getnumlocals()
-- 3 is the function calling that one.
if (debug.getlocal(3, i) == nil) then
return i-1
end
end
end
local required_module_mt = {
__newindex = function()
-- TODO: allow gamevars to be nil?
@ -1420,6 +1439,13 @@ local function our_require(modname, ...)
end
module_gamevars[thismodname] = gvnames
local gvmodi = module_gvlocali[thismodname]
gvmodi[2] = getnumlocals()
if (ffiC._DEBUG_LUNATIC ~= 0) then
printf("Module '%s' has %d locals, index %d to %d", thismodname,
gvmodi[2]-gvmodi[1]+1, gvmodi[1], gvmodi[2])
end
return
end
@ -1500,6 +1526,8 @@ local function our_module()
package_loaded[modname] = M
-- change the environment of the function which called us:
setfenv(2, M)
module_gvlocali[modname] = { getnumlocals()+1 }
end
-- overridden 'error' that always passes a string to the base 'error'