Lunatic translator: userdef access.

git-svn-id: https://svn.eduke32.com/eduke32@3473 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-02-10 16:24:20 +00:00
parent ed2ebdb29a
commit 4f3b139479
5 changed files with 89 additions and 25 deletions

View file

@ -7237,7 +7237,7 @@ FOUNDCHEAT:
break;
case CHEAT_CLIP:
ud.noclip = 1-ud.noclip;
ud.noclip = !ud.noclip;
P_DoQuote(QUOTE_CHEAT_NOCLIP-!ud.noclip, g_player[myconnectindex].ps);
end_cheat();
return;

View file

@ -784,12 +784,48 @@ for member, code in pairs(ProjectileLabels) do
end
end
local UD = function(memb) return "gv._ud"..memb end
local UDRO = function(memb) return { UD(memb) } end
-- NOTE: Only members that actually encountered in existing mods are added here.
local UserdefLabels = {
althud = UD".althud",
auto_run = UDRO".auto_run",
camerasprite = UDRO".camerasprite",
cashman = UDRO".cashman",
clipping = UD".noclip", -- NAME
const_visibility = UD".const_visibility",
crosshair = UD".crosshair",
crosshairscale = UDRO".crosshairscale",
detail = { "1" },
display_bonus_screen = UD".display_bonus_screen",
drawweapon = UDRO".drawweapon",
ffire = UDRO".ffire",
fta_on = UD".fta_on",
god = UDRO".god",
lockout = UDRO".lockout",
pause_on = UDRO".pause_on",
player_skill = UD".player_skill",
m_volume_number = UDRO".m_volume_number",
mouseflip = UDRO".mouseflip",
multimode = { "1" },
overhead_on = UD".overhead_on",
show_level_text = UD".show_level_text",
screen_size = { UD".screen_size", UD":set_screen_size(%%s)" },
screen_tilting = UD".screen_tilting",
showallmap = UDRO".showallmap",
showweapons = UDRO".showweapons",
volume_number = { UD".volume_number", UD":set_volume_number(%%s)" },
weaponswitch = UD".weaponswitch",
}
-- These structs cannot be accessed by inline array exprs in CON:
StructAccessCode2 =
{
tspr = TspriteLabels,
projectile = ProjectileLabels,
thisprojectile = SpriteProjectileLabels,
userdef = UserdefLabels,
}
-- NOTE: These MUST be in reverse lexicographical order!

View file

@ -941,6 +941,24 @@ local projectile_mt = {
}
ffi.metatype("projectile_t", projectile_mt)
local user_defs_mt = {
__index = {
set_screen_size = function(ud, screen_size)
-- TODO: modify .statusbarmode accordingly
ud.screen_size = screen_size
end,
set_volume_number = function(ud, volume_number)
-- XXX: should volume_number==MAXVOLUMES be allowed too?
if (volume_number >= con_lang.MAXVOLUMES+0ULL) then
error("invalid volume number "..volume_number, 2)
end
ud.volume_number = volume_number
end,
},
}
ffi.metatype("user_defs", user_defs_mt)
--- CUSTOM "gv" VARIABLES
local camera_mt = {
-- TODO: "set position" method, which also updates the sectnum
@ -954,6 +972,7 @@ local camera_mt = {
}
gv_access.cam = setmtonce({}, camera_mt)
gv_access._ud = ffiC.ud
-- Support for some CON global system gamevars
gv_access._csv = ffi.new "struct { int32_t RETURN; }"
@ -1524,7 +1543,7 @@ setmetatable(
-- Change the environment of the running Lua thread so that everything
-- what we've set up will be available when this chunk is left.
-- In particular, we need the functions defined after setting this chunk's
-- In particular, we need the globals defined after setting this chunk's
-- environment earlier.
setfenv(0, _G)

View file

@ -1135,14 +1135,14 @@ local setperxvarcmd = -- set<actor/player>var[<idx>].<<varname>> <var>
-- Function generating code for a struct read/write access.
local function StructAccess(Structname, writep, index, membertab)
assert(type(membertab)=="table")
local member, parm2 = membertab[1], membertab[2]
assert(member ~= nil)
-- Lowercase the member name for CON compatibility
local member, parm2 = membertab[1]:lower(), membertab[2]
local MemberCode = conl.StructAccessCode[Structname] or conl.StructAccessCode2[Structname]
-- Look up array+member name first, e.g. "spriteext[%s].angoff".
local armembcode = MemberCode[member]
if (armembcode == nil) then
errprintf("invalid %s member `.%s'", Structname, member)
errprintf("%s: invalid %s member `.%s'", g_lastkw, Structname, member)
return "_MEMBINVALID"
end
@ -1156,20 +1156,29 @@ local function StructAccess(Structname, writep, index, membertab)
end
end
-- Count number of parameters ("%s"), don't count "%%s".
local _, numparms = armembcode:gsub("[^%%]%%s", "", 2)
if (#membertab ~= numparms) then
local nums = { "one", "two" }
errprintf("%s[].%s has %s parameter%s, but %s given", Structname,
member, nums[numparms], numparms==1 and "" or "s",
nums[#membertab])
return "_MEMBINVPARM"
if (Structname~="userdef") then
-- Count number of parameters ("%s"), don't count "%%s".
local _, numparms = armembcode:gsub("[^%%]%%s", "", 2)
if (#membertab ~= numparms) then
local nums = { "one", "two" }
errprintf("%s[].%s has %s parameter%s, but %s given", Structname,
member, nums[numparms], numparms==1 and "" or "s",
nums[#membertab])
return "_MEMBINVPARM"
end
end
-- METHOD_MEMBER
local ismethod = (armembcode:find("%%s",1,true)~=nil)
-- If ismethod is true, then the formatted string will now have an "%s"
return format(armembcode, index, parm2), ismethod
if (Structname=="userdef") then
-- assert(index==nil)
assert(parm2==nil)
return format(armembcode, parm2), ismethod
else
return format(armembcode, index, parm2), ismethod
end
end
@ -1196,19 +1205,17 @@ local Access =
tspr = function(...) return StructAccess("tspr", ...) end,
projectile = function(...) return StructAccess("projectile", ...) end,
thisprojectile = function(...) return StructAccess("thisprojectile", ...) end,
userdef = function(...) return StructAccess("userdef", ...) end,
}
local function GetStructCmd(accessfunc)
local pattern = getstructcmd /
local function GetStructCmd(accessfunc, pattern)
return (pattern or getstructcmd) /
function(idx, memb, var)
return format("%s=%s", var, accessfunc(false, idx, memb))
end
return pattern
end
local function SetStructCmd(accessfunc)
local pattern = setstructcmd
local function SetStructCmd(accessfunc, pattern)
local function capfunc(idx, memb, var)
local membercode, ismethod = accessfunc(true, idx, memb)
if (ismethod) then
@ -1226,7 +1233,7 @@ local function SetStructCmd(accessfunc)
end
end
return pattern / capfunc
return (pattern or setstructcmd) / capfunc
end
-- <Setp>: whether the perxvar is set
@ -1298,6 +1305,8 @@ local handle =
soundonce = "_con._soundonce(_aci,%1)",
}
local userdef_common_pat = (arraypat + sp1)/{} * lpeg.Cc(0) * lpeg.Ct(singlememberpat) * sp1
-- NOTE about prefixes: most is handled by all_alt_pattern(), however commands
-- that have no arguments and that are prefixes of other commands MUST be
-- suffixed with a "* #sp1" pattern.
@ -1330,7 +1339,7 @@ local Cinner = {
-- arrays, I highly doubt that they worked (much less were safe) in CON.
-- We disallow them unless CONs in the wild crop up that actually used
-- these.
getuserdef = (arraypat + sp1)/{} * singlememberpat * sp1 * tok.wvar / handle.NYI,
getuserdef = GetStructCmd(Access.userdef, userdef_common_pat * tok.wvar),
getplayervar = GetOrSetPerxvarCmd(false, false),
getactorvar = GetOrSetPerxvarCmd(false, true),
@ -1344,7 +1353,7 @@ local Cinner = {
setprojectile = SetStructCmd(Access.projectile),
setthisprojectile = SetStructCmd(Access.thisprojectile),
settspr = SetStructCmd(Access.tspr),
setuserdef = (arraypat + sp1)/{} * singlememberpat * sp1 * tok.rvar / handle.NYI,
setuserdef = SetStructCmd(Access.userdef, userdef_common_pat * tok.rvar),
setplayervar = GetOrSetPerxvarCmd(true, false),
setactorvar = GetOrSetPerxvarCmd(true, true),

View file

@ -3025,7 +3025,7 @@ cheat_for_port_credits2:
mgametextpal(d,yy, ud.shadows ? "On" : "Off", MENUHIGHLIGHT(io), 0);
break;
case 9:
if (x==io) ud.screen_tilting = 1-ud.screen_tilting;
if (x==io) ud.screen_tilting = !ud.screen_tilting;
#ifdef USE_OPENGL
if (!ud.screen_tilting) setrollangle(0);
#endif
@ -3162,7 +3162,7 @@ cheat_for_port_credits2:
break;
}
case 3:
if (x==io) ud.althud = 1-ud.althud;
if (x==io) ud.althud = !ud.althud;
modval(0,1,(int32_t *)&ud.althud,1,probey==io);
mgametextpal(d,yy, ud.althud ? "Yes" : "No", MENUHIGHLIGHT(io), 0);
break;