mirror of
https://github.com/ZDoom/raze-gles.git
synced 2025-01-27 09:20:51 +00:00
Lunatic t.: {read,save}gamevar, fix break in nested while, fix rotatesprite16.
git-svn-id: https://svn.eduke32.com/eduke32@3533 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
fe4090b9fd
commit
8955316bba
5 changed files with 102 additions and 13 deletions
|
@ -276,6 +276,13 @@ function rotatesprite(x, y, zoom, ang, tilenum, shade, pal, orientation,
|
||||||
check_tile_idx(tilenum)
|
check_tile_idx(tilenum)
|
||||||
orientation = bit.band(orientation, 2047) -- ROTATESPRITE_MAX-1
|
orientation = bit.band(orientation, 2047) -- ROTATESPRITE_MAX-1
|
||||||
|
|
||||||
|
-- XXX: This is the same as the check in gameexec.c, but ideally we'd want
|
||||||
|
-- rotatesprite to accept all coordinates and simply draw nothing if they
|
||||||
|
-- denote an area beyond the screen.
|
||||||
|
if (not (x >= -320 and x < 640) or not (y >= -200 and y < 400)) then
|
||||||
|
error(format("invalid coordinates (%.03f, %.03f)", x, y), 2)
|
||||||
|
end
|
||||||
|
|
||||||
-- TODO: check that it works correctly with all coordinates, also if one
|
-- TODO: check that it works correctly with all coordinates, also if one
|
||||||
-- border is outside the screen etc...
|
-- border is outside the screen etc...
|
||||||
ffiC.rotatesprite(65536*x, 65536*y, zoom, ang, tilenum, shade, pal, bit.bor(2,orientation),
|
ffiC.rotatesprite(65536*x, 65536*y, zoom, ang, tilenum, shade, pal, bit.bor(2,orientation),
|
||||||
|
@ -1578,6 +1585,34 @@ function _setgamepalette(pli, basepal)
|
||||||
ffiC.P_SetGamePalette(player[pli], basepal)
|
ffiC.P_SetGamePalette(player[pli], basepal)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Gamevar persistence in the configuration file
|
||||||
|
|
||||||
|
function _savegamevar(name, val)
|
||||||
|
if (ffiC.ud.config.scripthandle < 0) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
assert(type(name)=="string")
|
||||||
|
assert(type(val)=="number")
|
||||||
|
|
||||||
|
ffiC.SCRIPT_PutNumber(ffiC.ud.config.scripthandle, "Gamevars", name,
|
||||||
|
val, 0, 0);
|
||||||
|
end
|
||||||
|
|
||||||
|
function _readgamevar(name)
|
||||||
|
if (ffiC.ud.config.scripthandle < 0) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
assert(type(name)=="string")
|
||||||
|
|
||||||
|
local v = ffi.new("int32_t [1]")
|
||||||
|
ffiC.SCRIPT_GetNumber(ffiC.ud.config.scripthandle, "Gamevars", name, v);
|
||||||
|
-- NOTE: doesn't examine SCRIPT_GetNumber() return value and returns 0 if
|
||||||
|
-- there was no such gamevar saved, like C-CON.
|
||||||
|
return v[0]
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Game arrays ---
|
--- Game arrays ---
|
||||||
|
|
||||||
|
|
|
@ -595,6 +595,10 @@ void C_DefineLevelName(int32_t vol, int32_t lev, const char *fn,
|
||||||
void C_DefineProjectile(int32_t j, int32_t what, int32_t val);
|
void C_DefineProjectile(int32_t j, int32_t what, int32_t val);
|
||||||
void C_DefineGameFuncName(int32_t idx, const char *name);
|
void C_DefineGameFuncName(int32_t idx, const char *name);
|
||||||
int32_t C_SetDefName(const char *name);
|
int32_t C_SetDefName(const char *name);
|
||||||
|
|
||||||
|
int32_t SCRIPT_GetNumber(int32_t scripthandle, const char *sectionname, const char *entryname, int32_t *number);
|
||||||
|
void SCRIPT_PutNumber(int32_t scripthandle, const char *sectionname, const char *entryname, int32_t number,
|
||||||
|
int32_t hexadecimal, int32_t defaultvalue);
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,9 @@ C_DefineProjectile;
|
||||||
C_DefineGameFuncName;
|
C_DefineGameFuncName;
|
||||||
C_SetDefName;
|
C_SetDefName;
|
||||||
|
|
||||||
|
SCRIPT_GetNumber;
|
||||||
|
SCRIPT_PutNumber;
|
||||||
|
|
||||||
actor;
|
actor;
|
||||||
g_camera;
|
g_camera;
|
||||||
ud;
|
ud;
|
||||||
|
|
|
@ -28,8 +28,12 @@ local unpack = unpack
|
||||||
local read_into_string = read_into_string
|
local read_into_string = read_into_string
|
||||||
local ffi, ffiC
|
local ffi, ffiC
|
||||||
|
|
||||||
if (string.dump) then
|
if (string.dump) then -- running stand-alone
|
||||||
bit = require("bit")
|
local ljp = pcall(function() require("ffi") end)
|
||||||
|
-- "lbit" is the same module as LuaJIT's "bit" (LuaBitOp:
|
||||||
|
-- http://bitop.luajit.org/), but under a different name for (IMO) less
|
||||||
|
-- confusion. Useful for running with Rio Lua for cross-checking.
|
||||||
|
bit = ljp and require("bit") or require("lbit")
|
||||||
require("strict")
|
require("strict")
|
||||||
else
|
else
|
||||||
bit = require("bit")
|
bit = require("bit")
|
||||||
|
@ -948,7 +952,7 @@ function Cmd.gamearray(identifier, initsize)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if (initsize >= 0x7fffffff+0ULL) then
|
if (not (initsize >= 0 and initsize < 0x7fffffff)) then
|
||||||
errprintf("invalid initial size %d for gamearray `%s'", initsize, identifier)
|
errprintf("invalid initial size %d for gamearray `%s'", initsize, identifier)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -1587,7 +1591,35 @@ local handle =
|
||||||
end,
|
end,
|
||||||
|
|
||||||
rotatesprite16 = function(...)
|
rotatesprite16 = function(...)
|
||||||
return format("_con.rotatesprite(%s,%s/65536,%s/65536,%s,%s,%s,%s,%s,%s,%s,%s,%s)", ...)
|
return format("_con.rotatesprite(%s/65536,%s/65536,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", ...)
|
||||||
|
end,
|
||||||
|
|
||||||
|
-- readgamevar or savegamevar
|
||||||
|
RSgamevar = function(identifier, dosave)
|
||||||
|
-- check identifier for sanity
|
||||||
|
if (not identifier:match("^[A-Za-z][A-Za-z0-9_]*$")) then
|
||||||
|
errprintf("%s: invalid identifier name `%s' for config file persistence",
|
||||||
|
g_lastkw)
|
||||||
|
return "_BADRSGV()"
|
||||||
|
end
|
||||||
|
|
||||||
|
local gv = g_gamevar[identifier]
|
||||||
|
if (gv and bit.band(gv.flags, GVFLAG.PERX_MASK)==GVFLAG.PERACTOR) then
|
||||||
|
-- Per-player are kind of global without multiplayer anyway. TODO_MP
|
||||||
|
errprintf("can only %s global or per-player gamevars", g_lastkw,
|
||||||
|
dosave and "save" or "read")
|
||||||
|
return "_BADRSGV()"
|
||||||
|
end
|
||||||
|
|
||||||
|
-- NOTE: more strict than C-CON: we require the gamevar being writable
|
||||||
|
-- even if we're saving it.
|
||||||
|
local code = lookup.gamevar(identifier, nil, true)
|
||||||
|
|
||||||
|
if (dosave) then
|
||||||
|
return format("_con._savegamevar(%q,%s)", identifier, code)
|
||||||
|
else
|
||||||
|
return format("%s=_con._readgamevar(%q)", code, identifier)
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
state = function(statename)
|
state = function(statename)
|
||||||
|
@ -1618,7 +1650,7 @@ local Cinner = {
|
||||||
["break"] = cmd()
|
["break"] = cmd()
|
||||||
/ function()
|
/ function()
|
||||||
return g_isWhile[#g_isWhile]
|
return g_isWhile[#g_isWhile]
|
||||||
and format("goto l%d", g_whilenum)
|
and format("goto l%d", #g_isWhile)
|
||||||
or "do return end"
|
or "do return end"
|
||||||
end,
|
end,
|
||||||
["return"] = cmd() -- NLCF
|
["return"] = cmd() -- NLCF
|
||||||
|
@ -1976,10 +2008,10 @@ local Cinner = {
|
||||||
/ handle.dynNYI,
|
/ handle.dynNYI,
|
||||||
savemapstate = cmd()
|
savemapstate = cmd()
|
||||||
/ handle.dynNYI,
|
/ handle.dynNYI,
|
||||||
savegamevar = cmd(R)
|
savegamevar = cmd(I)
|
||||||
/ handle.dynNYI,
|
/ function(id) return handle.RSgamevar(id, true) end,
|
||||||
readgamevar = cmd(W)
|
readgamevar = cmd(I)
|
||||||
/ handle.dynNYI,
|
/ function(id) return handle.RSgamevar(id, false) end,
|
||||||
savenn = cmd(D)
|
savenn = cmd(D)
|
||||||
/ handle.dynNYI,
|
/ handle.dynNYI,
|
||||||
save = cmd(D)
|
save = cmd(D)
|
||||||
|
@ -2621,10 +2653,9 @@ function on.while_begin(v1, v2)
|
||||||
end
|
end
|
||||||
|
|
||||||
function on.while_end()
|
function on.while_end()
|
||||||
|
local whilenum = #g_isWhile
|
||||||
table.remove(g_isWhile)
|
table.remove(g_isWhile)
|
||||||
local code=format("::l%d:: end", g_whilenum)
|
return format("::l%d:: end", whilenum)
|
||||||
g_whilenum = g_whilenum+1
|
|
||||||
return code
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function on.switch_begin()
|
function on.switch_begin()
|
||||||
|
@ -2838,7 +2869,6 @@ function on.parse_begin()
|
||||||
g_iflevel = 0
|
g_iflevel = 0
|
||||||
g_ifelselevel = 0
|
g_ifelselevel = 0
|
||||||
g_isWhile = {}
|
g_isWhile = {}
|
||||||
g_whilenum = 0
|
|
||||||
g_have_file[g_filename] = true
|
g_have_file[g_filename] = true
|
||||||
|
|
||||||
-- set up new state
|
-- set up new state
|
||||||
|
|
|
@ -107,4 +107,21 @@ onevent EVENT_ENTERLEVEL
|
||||||
userquote 30
|
userquote 30
|
||||||
endswitch
|
endswitch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// nested whilevar*n
|
||||||
|
setvar j -1
|
||||||
|
setvar k -1
|
||||||
|
whilevarn j 0
|
||||||
|
{
|
||||||
|
whilevarn k 0
|
||||||
|
{
|
||||||
|
setvar k 0
|
||||||
|
break
|
||||||
|
setvar k 1
|
||||||
|
}
|
||||||
|
|
||||||
|
setvar j 0
|
||||||
|
break
|
||||||
|
setvar j -1
|
||||||
|
}
|
||||||
endevent
|
endevent
|
||||||
|
|
Loading…
Reference in a new issue