Lunatic translator: more of the same.

- more predefined vars
- fix recursive states and ones with a stray "else" before the end

git-svn-id: https://svn.eduke32.com/eduke32@3409 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-01-19 18:28:55 +00:00
parent fb1db25c4e
commit d63ddb6e39
8 changed files with 119 additions and 14 deletions

View file

@ -10405,10 +10405,8 @@ int32_t app_main(int32_t argc, const char **argv)
Net_GetPackets(); Net_GetPackets();
G_Startup(); // a bunch of stuff including compiling cons // NOTE: Allocating the DukePlayer_t structs has to be before compiling scripts,
// because in Lunatic, the {pipe,trip}bomb* members are initialized.
g_player[0].playerquitflag = 1;
for (i=0; i<MAXPLAYERS; i++) for (i=0; i<MAXPLAYERS; i++)
{ {
if (!g_player[i].ps) g_player[i].ps = (DukePlayer_t *)Bcalloc(1, sizeof(DukePlayer_t)); if (!g_player[i].ps) g_player[i].ps = (DukePlayer_t *)Bcalloc(1, sizeof(DukePlayer_t));
@ -10418,6 +10416,10 @@ int32_t app_main(int32_t argc, const char **argv)
if (!g_player[i].sync) g_player[i].sync = (input_t *)Bcalloc(1, sizeof(input_t)); if (!g_player[i].sync) g_player[i].sync = (input_t *)Bcalloc(1, sizeof(input_t));
} }
G_Startup(); // a bunch of stuff including compiling cons
g_player[0].playerquitflag = 1;
g_player[myconnectindex].ps->palette = BASEPAL; g_player[myconnectindex].ps->palette = BASEPAL;
i = 1; i = 1;

View file

@ -1271,7 +1271,20 @@ static void Gv_AddSystemVars(void)
ADDWEAPONVAR(i, SelectSound); ADDWEAPONVAR(i, SelectSound);
ADDWEAPONVAR(i, FlashColor); ADDWEAPONVAR(i, FlashColor);
} }
#if !defined LUNATIC_ONLY #ifdef LUNATIC
for (i=0; i<MAXPLAYERS; i++)
{
DukePlayer_t *ps = g_player[i].ps;
ps->pipebombControl = NAM ? PIPEBOMB_TIMER : PIPEBOMB_REMOTE;
ps->pipebombLifetime = NAM_GRENADE_LIFETIME;
ps->pipebombLifetimeVar = NAM_GRENADE_LIFETIME_VAR;
ps->tripbombControl = TRIPBOMB_TRIPWIRE;
ps->tripbombLifetime = NAM_GRENADE_LIFETIME;
ps->tripbombLifetimeVar = NAM_GRENADE_LIFETIME_VAR;
}
#else
Gv_NewVar("GRENADE_LIFETIME", NAM_GRENADE_LIFETIME, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); Gv_NewVar("GRENADE_LIFETIME", NAM_GRENADE_LIFETIME, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM);
Gv_NewVar("GRENADE_LIFETIME_VAR", NAM_GRENADE_LIFETIME_VAR, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); Gv_NewVar("GRENADE_LIFETIME_VAR", NAM_GRENADE_LIFETIME_VAR, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM);

View file

@ -27,7 +27,7 @@ local type = type
-- NOTE: This exposes C library functions from e.g. the global C namespace, but -- NOTE: This exposes C library functions from e.g. the global C namespace, but
-- without their declarations, they will be sitting there like a stone. -- without their declarations, they will be sitting there like a stone.
local gv_ = {} local gv_ = {}
-- [key]=true forbids, [key]=<table> overrides -- [key]=<boolean> forbids, [key]=<non-boolean (e.g. table, function)> overrides
local gv_access = {} local gv_access = {}
-- This is for declarations of arrays or pointers which should not be -- This is for declarations of arrays or pointers which should not be
@ -163,6 +163,9 @@ local DUKEPLAYER_STRUCT = [[
uint32_t interface_toggle_flag; uint32_t interface_toggle_flag;
int32_t pipebombControl, pipebombLifetime, pipebombLifetimeVar;
int32_t tripbombControl, tripbombLifetime, tripbombLifetimeVar;
int32_t zrange; int32_t zrange;
int16_t angrange, autoaimang; int16_t angrange, autoaimang;
@ -470,6 +473,13 @@ typedef struct {
} user_defs; } user_defs;
]]) ]])
-- EXTERNALLY EXPOSED GAME VARIABLES
ffi.cdef[[
const int32_t screenpeek;
hudweapon_t hudweap;
]]
-- INTERNAL VARIABLES/FUNCTIONS
decl[[ decl[[
const char *g_sizes_of_what[]; const char *g_sizes_of_what[];
int32_t g_sizes_of[]; int32_t g_sizes_of[];
@ -484,11 +494,11 @@ tiledata_t g_tile[MAXTILES];
char *ScriptQuotes[]; char *ScriptQuotes[];
const int32_t playerswhenstarted; const int32_t playerswhenstarted;
const int32_t screenpeek;
int32_t lastvisinc; int32_t lastvisinc;
int16_t g_spriteDeleteQueueSize; int16_t g_spriteDeleteQueueSize;
int16_t BlimpSpawnSprites[15]; int16_t BlimpSpawnSprites[15];
int32_t g_scriptVersion; int32_t g_scriptVersion;
const int32_t g_currentFrameRate;
int32_t A_IncurDamage(int32_t sn); // not bound-checked! int32_t A_IncurDamage(int32_t sn); // not bound-checked!
void P_AddWeaponMaybeSwitch(DukePlayer_t *ps, int32_t weap); void P_AddWeaponMaybeSwitch(DukePlayer_t *ps, int32_t weap);
@ -513,7 +523,6 @@ int32_t S_CheckSoundPlaying(int32_t i, int32_t num);
void S_StopEnvSound(int32_t num, int32_t i); void S_StopEnvSound(int32_t num, int32_t i);
]] ]]
-- functions
decl[[ decl[[
int32_t kopen4loadfrommod(const char *filename, char searchfirst); int32_t kopen4loadfrommod(const char *filename, char searchfirst);
int32_t kfilelength(int32_t handle); int32_t kfilelength(int32_t handle);
@ -879,6 +888,7 @@ local player_mt = {
} }
ffi.metatype("DukePlayer_t", player_mt) ffi.metatype("DukePlayer_t", player_mt)
--- CUSTOM "gv" VARIABLES
local camera_mt = { local camera_mt = {
-- TODO: "set position" method, which also updates the sectnum -- TODO: "set position" method, which also updates the sectnum
__index = ffiC.g_camera, __index = ffiC.g_camera,
@ -893,6 +903,23 @@ local camera_mt = {
gv_access.cam = setmetatable({}, camera_mt) gv_access.cam = setmetatable({}, camera_mt)
function gv_access._get_framerate()
return ffiC.g_currentFrameRate
end
function gv_access.currentEpisode()
return ffiC.ud.volume_number
end
function gv_access.currentLevel()
return ffiC.ud.level_number
end
function gv_access.currentRenderMode()
-- TODO: USE_OPENGL=0 build
return ffiC.rendmode
end
-- Declare all con_lang.labels constants in the global FFI namespace. -- Declare all con_lang.labels constants in the global FFI namespace.
for i=1,#con_lang.labels do for i=1,#con_lang.labels do
local strbuf = {"enum {"} local strbuf = {"enum {"}
@ -1272,7 +1299,7 @@ local tmpmt = {
if (gv_access[key] == nil) then if (gv_access[key] == nil) then
return ffiC[key] return ffiC[key]
end end
if (type(gv_access[key])=="table") then if (type(gv_access[key])~="boolean") then
-- overridden... -- overridden...
return gv_access[key] return gv_access[key]
end end

View file

@ -200,10 +200,13 @@ ffi.cdef[[
const int16_t numsectors, numwalls; const int16_t numsectors, numwalls;
const int32_t numyaxbunches; // XXX const int32_t numyaxbunches; // XXX
const int32_t totalclock; const int32_t totalclock;
int32_t randomseed; // DEPRECATED
const int32_t xdim, ydim; const int32_t xdim, ydim;
const int32_t windowx1, windowy1, windowx2, windowy2;
]] ]]
decl[[ decl[[
const int32_t rendmode;
const int16_t headspritesect[MAXSECTORS+1], headspritestat[MAXSTATUS+1]; const int16_t headspritesect[MAXSECTORS+1], headspritestat[MAXSTATUS+1];
const int16_t prevspritesect[MAXSPRITES], prevspritestat[MAXSPRITES]; const int16_t prevspritesect[MAXSPRITES], prevspritestat[MAXSPRITES];
const int16_t nextspritesect[MAXSPRITES], nextspritestat[MAXSPRITES]; const int16_t nextspritesect[MAXSPRITES], nextspritestat[MAXSPRITES];

View file

@ -11,9 +11,15 @@ numsectors;
numwalls; numwalls;
numyaxbunches; numyaxbunches;
rendmode;
totalclock; totalclock;
randomseed;
xdim; xdim;
ydim; ydim;
windowx1;
windowy1;
windowx2;
windowy2;
yax_getbunch; yax_getbunch;
@ -85,11 +91,13 @@ g_tile;
ScriptQuotes; ScriptQuotes;
screenpeek; screenpeek;
hudweap;
playerswhenstarted; playerswhenstarted;
lastvisinc; lastvisinc;
g_spriteDeleteQueueSize; g_spriteDeleteQueueSize;
BlimpSpawnSprites; BlimpSpawnSprites;
g_scriptVersion; g_scriptVersion;
g_currentFrameRate;
luaJIT_BC_lunacon; luaJIT_BC_lunacon;
luaJIT_BC_con_lang; luaJIT_BC_con_lang;

View file

@ -11,9 +11,15 @@ numsectors;
numwalls; numwalls;
numyaxbunches; numyaxbunches;
rendmode;
totalclock; totalclock;
randomseed;
xdim; xdim;
ydim; ydim;
windowx1;
windowy1;
windowx2;
windowy2;
yax_getbunch; yax_getbunch;

View file

@ -156,11 +156,22 @@ local function new_initial_gvartab()
xdim = RO "_gv.xdim", xdim = RO "_gv.xdim",
ydim = RO "_gv.ydim", ydim = RO "_gv.ydim",
windowx1 = RO "_gv.windowx1",
windowy1 = RO "_gv.windowy1",
windowx2 = RO "_gv.windowx2",
windowy2 = RO "_gv.windowy2",
numsectors = RO "_gv.numsectors", numsectors = RO "_gv.numsectors",
NUMSECTORS = RO "_gv.numsectors", NUMSECTORS = RO "_gv.numsectors",
NUMWALLS = RO "_gv.numwalls", NUMWALLS = RO "_gv.numwalls",
randomseed = RW "_gv.randomseed",
totalclock = RO "_gv.totalclock",
framerate = RO "_gv._get_framerate()",
rendmode = RO "_gv.currentRenderMode()",
screenpeek = RO "_gv.screenpeek",
camerax = RW "_gv.cam.pos.x", camerax = RW "_gv.cam.pos.x",
cameray = RW "_gv.cam.pos.y", cameray = RW "_gv.cam.pos.y",
cameraz = RW "_gv.cam.pos.z", cameraz = RW "_gv.cam.pos.z",
@ -169,6 +180,30 @@ local function new_initial_gvartab()
camerasect = RW "_gv.cam.sect", camerasect = RW "_gv.cam.sect",
cameradist = RW "_gv.cam.dist", cameradist = RW "_gv.cam.dist",
cameraclock = RW "_gv.cam.clock", cameraclock = RW "_gv.cam.clock",
-- HUD weapon gamevars
currentweapon = RW "_gv.hudweap.cur",
weaponcount = RW "_gv.hudweap.count",
weapon_xoffset = RW "_gv.hudweap.gunposx",
looking_angSR1 = RW "_gv.hudweap.lookhalfang",
gun_pos = RW "_gv.hudweap.gunposy",
looking_arc = RW "_gv.hudweap.lookhoriz",
gs = RW "_gv.hudweap.shade",
-- Some per-player gamevars
ZRANGE = RW(PLS".zrange"),
ANGRANGE = RW(PLS".angrange"),
AUTOAIMANGLE = RW(PLS".autoaimang"),
PIPEBOMB_CONTROL = RW(PLS".pipebombControl"),
GRENADE_LIFETIME = RW(PLS".pipebombLifetime"),
GRENADE_LIFETIME_VAR = RW(PLS".pipebombLifetimeVar"),
TRIPBOMB_CONTROL = RW(PLS".tripbombControl"),
STICKYBOMB_LIFETIME = RW(PLS".tripbombLifetime"),
STICKYBOMB_LIFETIME_VAR = RW(PLS".tripbombLifetimeVar"),
VOLUME = RO "_gv.currentEpisode()",
LEVEL = RO "_gv.currentLevel()",
} }
for w=0,MAX_WEAPONS-1 do for w=0,MAX_WEAPONS-1 do
@ -247,10 +282,14 @@ local function mangle_name(name, prefix)
return prefix..name return prefix..name
end end
local function on_state_begin(statename) local function on_state_begin_Cmt(_subj, _pos, statename)
-- We must register the state name early (Cmt) because otherwise, it won't
-- be found in a recursive state. XXX: The real issue seems to be the use
-- of "Cmt"s in other places, which messes up the sequence of running the
-- semantic actions.
local ourname = mangle_name(statename, "F") local ourname = mangle_name(statename, "F")
g_funcname[statename] = ourname g_funcname[statename] = ourname
return ourname return true, ourname
end end
local function on_state_end(funcname, codetab) local function on_state_end(funcname, codetab)
@ -290,9 +329,9 @@ local function errprintf(fmt, ...)
perrprintf(g_lastkwpos, fmt, ...) perrprintf(g_lastkwpos, fmt, ...)
else else
printf("%s ???: error: "..fmt, g_filename, ...) printf("%s ???: error: "..fmt, g_filename, ...)
end
increment_numerrors() increment_numerrors()
end end
end
local function pwarnprintf(pos, fmt, ...) local function pwarnprintf(pos, fmt, ...)
printf("%s %s: warning: "..fmt, g_filename, linecolstr(pos), ...) printf("%s %s: warning: "..fmt, g_filename, linecolstr(pos), ...)
@ -852,6 +891,10 @@ local tok =
-- for definelevelname, -- for definelevelname,
time = lpeg.C(alphanum*alphanum^-1*":"*alphanum*alphanum^-1), time = lpeg.C(alphanum*alphanum^-1*":"*alphanum*alphanum^-1),
state_ends = Pat("ends")
+ POS() * "else" * sp1 * "ends"
/ function(pos) pwarnprintf(pos, "stray `else' at end of state") end,
} }
@ -1760,7 +1803,7 @@ local common_actor_end = sp1 * lpeg.Ct(tok.define *
)^-1) )^-1)
* sp1 * stmt_list_or_eps * "enda" * sp1 * stmt_list_or_eps * "enda"
--== block delimiters (no recursion) ==-- --== block delimiters (no syntactic recursion) ==--
local Cblock = { local Cblock = {
-- actor (...) -- actor (...)
actor = lpeg.Cc(nil) * common_actor_end / on_actor_end, actor = lpeg.Cc(nil) * common_actor_end / on_actor_end,
@ -1773,7 +1816,7 @@ local Cblock = {
onevent = sp1 * tok.define * sp1 * stmt_list_or_eps * "endevent" onevent = sp1 * tok.define * sp1 * stmt_list_or_eps * "endevent"
/ on_event_end, / on_event_end,
state = sp1 * (tok.identifier/on_state_begin) * sp1 * stmt_list_or_eps * "ends" state = sp1 * (lpeg.Cmt(tok.identifier, on_state_begin_Cmt)) * sp1 * stmt_list_or_eps * tok.state_ends
/ on_state_end, / on_state_end,
} }

View file

@ -165,6 +165,9 @@ typedef struct {
uint32_t interface_toggle_flag; uint32_t interface_toggle_flag;
#ifdef LUNATIC #ifdef LUNATIC
int32_t pipebombControl, pipebombLifetime, pipebombLifetimeVar;
int32_t tripbombControl, tripbombLifetime, tripbombLifetimeVar;
int32_t zrange; int32_t zrange;
int16_t angrange, autoaimang; int16_t angrange, autoaimang;
#endif #endif