mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-24 10:40:46 +00:00
LunaCON: implement NORESET flag for gamevars.
git-svn-id: https://svn.eduke32.com/eduke32@4140 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
ceebc8077c
commit
77574e30b9
3 changed files with 47 additions and 14 deletions
|
@ -2261,10 +2261,13 @@ do
|
|||
-- Handle global gamevars first.
|
||||
for i=1,#modvars do
|
||||
local varname = modvars[i]
|
||||
local excludedVars = modname==CON_MODULE_NAME and varname=="_V" and
|
||||
package_loaded[CON_MODULE_NAME]._V._IS_NORESET_GAMEVAR or nil
|
||||
|
||||
-- Serialize gamevar named 'varname' from module named 'modname'.
|
||||
-- XXX: May error. This will terminate EDuke32 since this callback
|
||||
-- is run unprotected.
|
||||
if (sb:add("M."..varname, package_loaded[modname][varname])) then
|
||||
if (sb:add("M."..varname, package_loaded[modname][varname], excludedVars)) then
|
||||
-- We couldn't serialize that gamevar.
|
||||
slenptr[0] = -1
|
||||
-- Signal which gamevar that was.
|
||||
|
|
|
@ -827,6 +827,10 @@ local function check_sysvar_def_attempt(identifier)
|
|||
errprintf("cannot define reserved symbol `actorvar'")
|
||||
return true
|
||||
end
|
||||
if (identifier=="_IS_NORESET_GAMEVAR") then
|
||||
errprintf("cannot define reserved symbol `_IS_NORESET_GAMEVAR'")
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local Define = {}
|
||||
|
@ -1391,11 +1395,6 @@ function Cmd.gamevar(identifier, initval, flags)
|
|||
return
|
||||
end
|
||||
|
||||
if (bit.band(flags, GVFLAG.NORESET) ~= 0) then
|
||||
warnprintf("gamevar \"%s\" flag NORESET (131072): not yet implemented",
|
||||
identifier)
|
||||
end
|
||||
|
||||
local perPlayer = (bit.band(flags, GVFLAG.PERPLAYER) ~= 0)
|
||||
local perActor = (bit.band(flags, GVFLAG.PERACTOR) ~= 0)
|
||||
|
||||
|
@ -1406,12 +1405,14 @@ function Cmd.gamevar(identifier, initval, flags)
|
|||
|
||||
local ogv = g_gamevar[identifier]
|
||||
local isSessionVar = (bit.band(flags, GVFLAG.NODEFAULT) ~= 0)
|
||||
local storeWithSavegames = (bit.band(flags, GVFLAG.NORESET) == 0)
|
||||
|
||||
if (isSessionVar and (perPlayer or perActor)) then
|
||||
if (ogv == nil) then -- warn only once per gamevar
|
||||
warnprintf("per-%s for session gamevars: not yet implemented (made into %s)",
|
||||
warnprintf("per-%s session gamevar `%s': NYI, made %s",
|
||||
perPlayer and "player" or "actor",
|
||||
perPlayer and "global" or "plain")
|
||||
identifier,
|
||||
perPlayer and "global" or "non-session")
|
||||
end
|
||||
|
||||
if (perActor) then
|
||||
|
@ -1490,7 +1491,9 @@ function Cmd.gamevar(identifier, initval, flags)
|
|||
local gv = { name=mangle_name(identifier, "V"), flags=flags }
|
||||
g_gamevar[identifier] = gv
|
||||
|
||||
addcode("if _S then")
|
||||
if (storeWithSavegames) then
|
||||
addcode("if _S then")
|
||||
end
|
||||
|
||||
if (perActor) then
|
||||
addcodef("%s=_con.actorvar(%d)", gv.name, initval)
|
||||
|
@ -1501,7 +1504,9 @@ function Cmd.gamevar(identifier, initval, flags)
|
|||
addcodef("%s=%d", gv.name, initval)
|
||||
end
|
||||
|
||||
addcode("end")
|
||||
if (storeWithSavegames) then
|
||||
addcode("end")
|
||||
end
|
||||
end
|
||||
|
||||
function Cmd.dynamicremap()
|
||||
|
@ -3549,6 +3554,15 @@ end
|
|||
|
||||
-- <lineinfop>: Get line info?
|
||||
local function get_code_string(codetab, lineinfop)
|
||||
-- Create meta-info gamevar: which gamevars have bit NORESET set?
|
||||
codetab[#codetab+1] = "_V._IS_NORESET_GAMEVAR={"
|
||||
for identifier, gv in pairs(g_gamevar) do
|
||||
if (bit.band(gv.flags, GVFLAG.NORESET) ~= 0) then
|
||||
codetab[#codetab+1] = format("[%q]=true,", identifier)
|
||||
end
|
||||
end
|
||||
codetab[#codetab+1] = "}"
|
||||
|
||||
-- Return defined labels in a table...
|
||||
codetab[#codetab+1] = "return {"
|
||||
for label, val in pairs(g_labeldef) do
|
||||
|
|
|
@ -66,6 +66,7 @@ local savebuffer_mt = {
|
|||
--== vvv INTERNAL vvv ===---
|
||||
resetRefs = function(self)
|
||||
self.numrefs = 0
|
||||
self.recursionDepth = 0
|
||||
self.val2ref = {}
|
||||
self.havereq = {}
|
||||
end,
|
||||
|
@ -92,8 +93,10 @@ local savebuffer_mt = {
|
|||
|
||||
-- Add an entry of Lua object <value> that can be referenced by
|
||||
-- <lhscode> on the left hand side of an assignment.
|
||||
-- <excludedKeys>: if non-nil, should be table
|
||||
-- [<key_string>] = true. See EXCLUDE_KEYS below.
|
||||
-- Returns 'true' if <value> cannot be serialized.
|
||||
add = function(self, lhscode, value)
|
||||
add = function(self, lhscode, value, excludedKeys)
|
||||
local valcode = basicSerialize(value)
|
||||
|
||||
if (valcode == nil) then
|
||||
|
@ -129,13 +132,25 @@ local savebuffer_mt = {
|
|||
return true
|
||||
end
|
||||
|
||||
-- EXCLUDE_KEYS
|
||||
local isNORESET = (self.recursionDepth == 0 and
|
||||
excludedKeys and excludedKeys[k])
|
||||
|
||||
-- Generate the name under which the table element
|
||||
-- is referenced.
|
||||
local refcode2 = format("%s[%s]", refcode, keystr)
|
||||
|
||||
-- Recurse!
|
||||
if (self:add(refcode2, v)) then
|
||||
return true
|
||||
if (isNORESET) then
|
||||
self:emitAssign(refcode2, format("M._V[%s]", keystr))
|
||||
else
|
||||
-- Recurse!
|
||||
self.recursionDepth = self.recursionDepth+1
|
||||
local ret = self:add(refcode2, v)
|
||||
self.recursionDepth = self.recursionDepth-1
|
||||
|
||||
if (ret) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -187,6 +202,7 @@ function savebuffer()
|
|||
-- .strbuf: array of Lua code pieces
|
||||
local sb = {
|
||||
numrefs=0, val2ref={}, havereq={},
|
||||
recursionDepth = 0,
|
||||
strbuf=sb_get_initial_strbuf()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue