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();
G_Startup(); // a bunch of stuff including compiling cons
g_player[0].playerquitflag = 1;
// NOTE: Allocating the DukePlayer_t structs has to be before compiling scripts,
// because in Lunatic, the {pipe,trip}bomb* members are initialized.
for (i=0; i<MAXPLAYERS; i++)
{
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));
}
G_Startup(); // a bunch of stuff including compiling cons
g_player[0].playerquitflag = 1;
g_player[myconnectindex].ps->palette = BASEPAL;
i = 1;

View file

@ -1271,7 +1271,20 @@ static void Gv_AddSystemVars(void)
ADDWEAPONVAR(i, SelectSound);
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_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
-- without their declarations, they will be sitting there like a stone.
local gv_ = {}
-- [key]=true forbids, [key]=<table> overrides
-- [key]=<boolean> forbids, [key]=<non-boolean (e.g. table, function)> overrides
local gv_access = {}
-- This is for declarations of arrays or pointers which should not be
@ -163,6 +163,9 @@ local DUKEPLAYER_STRUCT = [[
uint32_t interface_toggle_flag;
int32_t pipebombControl, pipebombLifetime, pipebombLifetimeVar;
int32_t tripbombControl, tripbombLifetime, tripbombLifetimeVar;
int32_t zrange;
int16_t angrange, autoaimang;
@ -470,6 +473,13 @@ typedef struct {
} user_defs;
]])
-- EXTERNALLY EXPOSED GAME VARIABLES
ffi.cdef[[
const int32_t screenpeek;
hudweapon_t hudweap;
]]
-- INTERNAL VARIABLES/FUNCTIONS
decl[[
const char *g_sizes_of_what[];
int32_t g_sizes_of[];
@ -484,11 +494,11 @@ tiledata_t g_tile[MAXTILES];
char *ScriptQuotes[];
const int32_t playerswhenstarted;
const int32_t screenpeek;
int32_t lastvisinc;
int16_t g_spriteDeleteQueueSize;
int16_t BlimpSpawnSprites[15];
int32_t g_scriptVersion;
const int32_t g_currentFrameRate;
int32_t A_IncurDamage(int32_t sn); // not bound-checked!
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);
]]
-- functions
decl[[
int32_t kopen4loadfrommod(const char *filename, char searchfirst);
int32_t kfilelength(int32_t handle);
@ -879,6 +888,7 @@ local player_mt = {
}
ffi.metatype("DukePlayer_t", player_mt)
--- CUSTOM "gv" VARIABLES
local camera_mt = {
-- TODO: "set position" method, which also updates the sectnum
__index = ffiC.g_camera,
@ -893,6 +903,23 @@ local 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.
for i=1,#con_lang.labels do
local strbuf = {"enum {"}
@ -1272,7 +1299,7 @@ local tmpmt = {
if (gv_access[key] == nil) then
return ffiC[key]
end
if (type(gv_access[key])=="table") then
if (type(gv_access[key])~="boolean") then
-- overridden...
return gv_access[key]
end

View file

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

View file

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

View file

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

View file

@ -156,11 +156,22 @@ local function new_initial_gvartab()
xdim = RO "_gv.xdim",
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",
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",
cameray = RW "_gv.cam.pos.y",
cameraz = RW "_gv.cam.pos.z",
@ -169,6 +180,30 @@ local function new_initial_gvartab()
camerasect = RW "_gv.cam.sect",
cameradist = RW "_gv.cam.dist",
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
@ -247,10 +282,14 @@ local function mangle_name(name, prefix)
return prefix..name
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")
g_funcname[statename] = ourname
return ourname
return true, ourname
end
local function on_state_end(funcname, codetab)
@ -290,8 +329,8 @@ local function errprintf(fmt, ...)
perrprintf(g_lastkwpos, fmt, ...)
else
printf("%s ???: error: "..fmt, g_filename, ...)
increment_numerrors()
end
increment_numerrors()
end
local function pwarnprintf(pos, fmt, ...)
@ -852,6 +891,10 @@ local tok =
-- for definelevelname,
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)
* sp1 * stmt_list_or_eps * "enda"
--== block delimiters (no recursion) ==--
--== block delimiters (no syntactic recursion) ==--
local Cblock = {
-- actor (...)
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"
/ 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,
}

View file

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