Lunatic translator: codegen fixes, setgamepalette, -fno=onlycheck option.

git-svn-id: https://svn.eduke32.com/eduke32@3523 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-02-25 15:31:09 +00:00
parent 0354e38843
commit b92c487c6f
4 changed files with 53 additions and 25 deletions

View file

@ -1291,7 +1291,7 @@ function _getlastpal(spritenum)
end end
-- G_GetAngleDelta(a1, a2) -- G_GetAngleDelta(a1, a2)
function _angdiffabs(a1, a2) function _angdiff(a1, a2)
a1 = bit.band(a1, 2047) a1 = bit.band(a1, 2047)
a2 = bit.band(a2, 2047) a2 = bit.band(a2, 2047)
-- a1 and a2 are in [0, 2047] -- a1 and a2 are in [0, 2047]
@ -1557,6 +1557,10 @@ function _setaspect(viewingrange, yxaspect)
ffiC.setaspect(viewingrange, yxaspect) ffiC.setaspect(viewingrange, yxaspect)
end end
function _setgamepalette(pli, basepal)
ffiC.P_SetGamePalette(player[pli], basepal)
end
--- Game arrays --- --- Game arrays ---
@ -1762,7 +1766,7 @@ local peractorvar_mt = {
-- * All values equal to the default one are cleared. -- * All values equal to the default one are cleared.
__call = function(acv) __call = function(acv)
for i=0,ffiC.MAXSPRITES-1 do for i=0,ffiC.MAXSPRITES-1 do
if (ffiC.sprite[i].statnum == ffiC.MAXSTATUS or acv[i]==acv._defval) then if (ffiC.sprite[i].statnum == ffiC.MAXSTATUS or rawget(acv, i)==acv._defval) then
rawset(acv, i, nil) rawset(acv, i, nil)
end end
end end

View file

@ -144,7 +144,8 @@ __attribute__((packed)) struct {
const int16_t owner; const int16_t owner;
int16_t movflag,tempang,timetosleep; //6b int16_t movflag,tempang,timetosleep; //6b
const int16_t lightId, lightcount, lightmaxrange, cgg; //8b const int16_t lightId, lightcount, lightmaxrange;
int16_t cgg;
int16_t actorstayput; int16_t actorstayput;
const int16_t dispicnum; const int16_t dispicnum;
int16_t shootzvel; int16_t shootzvel;
@ -528,6 +529,7 @@ int32_t G_CheckActivatorMotion(int32_t lotag);
int32_t A_Dodge(spritetype *s); int32_t A_Dodge(spritetype *s);
int32_t A_MoveSprite(int32_t spritenum, const vec3_t *change, uint32_t cliptype); int32_t A_MoveSprite(int32_t spritenum, const vec3_t *change, uint32_t cliptype);
void P_DoQuote(int32_t q, DukePlayer_t *p); void P_DoQuote(int32_t q, DukePlayer_t *p);
void P_SetGamePalette(DukePlayer_t *player, uint8_t palid, int32_t set);
void G_AddUserQuote(const char *daquote); void G_AddUserQuote(const char *daquote);
void G_ClearCameraView(DukePlayer_t *ps); void G_ClearCameraView(DukePlayer_t *ps);
void G_DrawTileGeneric(int32_t x, int32_t y, int32_t zoom, int32_t tilenum, void G_DrawTileGeneric(int32_t x, int32_t y, int32_t zoom, int32_t tilenum,

View file

@ -137,6 +137,7 @@ G_CheckActivatorMotion;
A_Dodge; A_Dodge;
A_MoveSprite; A_MoveSprite;
P_DoQuote; P_DoQuote;
P_SetGamePalette;
G_AddUserQuote; G_AddUserQuote;
G_ClearCameraView; G_ClearCameraView;
G_DrawTileGeneric; G_DrawTileGeneric;

View file

@ -14,6 +14,7 @@ local arg = arg
local assert = assert local assert = assert
local ipairs = ipairs local ipairs = ipairs
local loadstring = loadstring
local pairs = pairs local pairs = pairs
local pcall = pcall local pcall = pcall
local print = print local print = print
@ -93,7 +94,7 @@ local g_warn = { ["not-redefined"]=true, ["bad-identifier"]=true,
["number-conversion"]=true, ["system-gamevar"]=true, } ["number-conversion"]=true, ["system-gamevar"]=true, }
-- Code generation options. -- Code generation options.
local g_cgopt = { ["no"]=false, ["_incomplete"]=false, } local g_cgopt = { ["no"]=false, }
-- How many 'if' statements are following immediately each other, -- How many 'if' statements are following immediately each other,
-- needed to cope with CONs dangling-else resolution -- needed to cope with CONs dangling-else resolution
@ -1271,7 +1272,7 @@ local varop = cmd(W,D)
local varvarop = cmd(W,R) local varvarop = cmd(W,R)
local function varopf(op) local function varopf(op)
if (#op == 1) then if (#op <= 2) then
return varop / ("%1=%1"..op.."%2") return varop / ("%1=%1"..op.."%2")
else else
return varop / ("%1="..op.."(%1,%2)") return varop / ("%1="..op.."(%1,%2)")
@ -1279,7 +1280,7 @@ local function varopf(op)
end end
local function varvaropf(op) local function varvaropf(op)
if (#op == 1) then if (#op <= 2) then
return varvarop / ("%1=%1"..op.."%2") return varvarop / ("%1=%1"..op.."%2")
else else
return varvarop / ("%1="..op.."(%1,%2)") return varvarop / ("%1="..op.."(%1,%2)")
@ -1504,6 +1505,7 @@ local handle =
{ {
NYI = function() NYI = function()
errprintf("command `%s' not yet implemented", g_lastkw) errprintf("command `%s' not yet implemented", g_lastkw)
return ""
end, end,
dynNYI = function() dynNYI = function()
@ -1554,7 +1556,8 @@ local handle =
qsprintf = function(qdst, qsrc, ...) qsprintf = function(qdst, qsrc, ...)
local codes = {...} local codes = {...}
return format("_con._qsprintf(%d,%d,%s)", qdst, qsrc, table.concat(codes, ',')) return format("_con._qsprintf(%d,%d%s%s)", qdst, qsrc,
#codes>0 and "," or "", table.concat(codes, ','))
end, end,
move = function(mv, ...) move = function(mv, ...)
@ -1641,7 +1644,9 @@ local Cinner = {
setvarvar = varvarop / "%1=%2", setvarvar = varvarop / "%1=%2",
addvarvar = varvaropf "+", addvarvar = varvaropf "+",
subvarvar = varvaropf "-", -- NOTE the space after the minus sign so that e.g. "subvar x -1" won't get
-- translated to "x=x--1" (-- being the Lua line comment start).
subvarvar = varvaropf "- ",
mulvarvar = varvaropf "*", mulvarvar = varvaropf "*",
divvarvar = varvaropf "_con._div", divvarvar = varvaropf "_con._div",
modvarvar = varvaropf "_con._mod", modvarvar = varvaropf "_con._mod",
@ -1652,7 +1657,7 @@ local Cinner = {
setvar = varop / "%1=%2", setvar = varop / "%1=%2",
addvar = varopf "+", addvar = varopf "+",
subvar = varopf "-", subvar = varopf "- ",
mulvar = varopf "*", mulvar = varopf "*",
divvar = varopf "_con._div", divvar = varopf "_con._div",
modvar = varopf "_con._mod", modvar = varopf "_con._mod",
@ -1746,7 +1751,8 @@ local Cinner = {
/ "_con._echo(%1)", / "_con._echo(%1)",
activatecheat = cmd(R) activatecheat = cmd(R)
/ handle.NYI, / handle.NYI,
setgamepalette = cmd(R), setgamepalette = cmd(R)
/ "_con._setgamepalette(_pli,%1)",
-- Sound commands -- Sound commands
sound = cmd(D) sound = cmd(D)
@ -1951,7 +1957,7 @@ local Cinner = {
/ handle.dynNYI, / handle.dynNYI,
savegamevar = cmd(R) savegamevar = cmd(R)
/ handle.dynNYI, / handle.dynNYI,
readgamevar = cmd(R) readgamevar = cmd(W)
/ handle.dynNYI, / handle.dynNYI,
savenn = cmd(D) savenn = cmd(D)
/ handle.dynNYI, / handle.dynNYI,
@ -2096,8 +2102,10 @@ local Cinner = {
setaspect = cmd(R,R) setaspect = cmd(R,R)
/ "_con._setaspect(%1,%2)", / "_con._setaspect(%1,%2)",
showview = cmd(R,R,R,R,R,R,R,R,R,R), -- 10R showview = cmd(R,R,R,R,R,R,R,R,R,R) -- 10R
showviewunbiased = cmd(R,R,R,R,R,R,R,R,R,R), -- 10R / "", -- TODO
showviewunbiased = cmd(R,R,R,R,R,R,R,R,R,R) -- 10R
/ "", -- TODO
smaxammo = cmd(R,R) smaxammo = cmd(R,R)
/ PLS":set_max_ammo_amount(%1,%2)", / PLS":set_max_ammo_amount(%1,%2)",
gmaxammo = cmd(R,W) gmaxammo = cmd(R,W)
@ -2386,7 +2394,7 @@ local function after_if_cmd_Cmt(subj, pos, ...)
return nil return nil
end end
if (not g_cgopt["_incomplete"] and capts[1] ~= nil) then if (capts[1] ~= nil) then
assert(#capts <= 3) assert(#capts <= 3)
for i=1,#capts do for i=1,#capts do
assert(type(capts[i]=="string")) assert(type(capts[i]=="string"))
@ -2870,14 +2878,15 @@ local function handle_cmdline_arg(str)
g_warn[warnstr] = val g_warn[warnstr] = val
ok = true ok = true
end end
elseif (str:sub(2)=="fno") then elseif (str:sub(2,4)=="fno") then
-- Disable printing code. -- Disable printing code.
if (#str >= 5 and str:sub(5)=="=onlycheck") then
g_cgopt["no"] = "onlycheck"
ok = true
else
g_cgopt["no"] = true g_cgopt["no"] = true
ok = true ok = true
elseif (str:sub(2)=="f_incomplete") then end
-- TEMP
g_cgopt["_incomplete"] = true
ok = true
elseif (kind=="I" and #str >= 3) then elseif (kind=="I" and #str >= 3) then
-- default directory (only ONCE, not search path) -- default directory (only ONCE, not search path)
g_defaultDir = str:sub(3) g_defaultDir = str:sub(3)
@ -2936,13 +2945,25 @@ if (string.dump) then
print_on_failure(msg) print_on_failure(msg)
end end
if (not g_cgopt["no"]) then if (not (g_cgopt["no"]==true)) then
local file = require("io").stderr local onlycheck = (g_cgopt["no"] == "onlycheck")
local io = require("io")
local file = onlycheck and io.stdout or io.stderr
local code = get_code_string(g_curcode)
local func, errmsg = loadstring(code, "CON")
file:write(format("-- GENERATED CODE for \"%s\":\n", filename)) file:write(format("-- GENERATED CODE for \"%s\":\n", filename))
file:write(get_code_string(g_curcode)) if (func == nil) then
file:write(format("-- (invalid Lua code: %s)\n", errmsg))
end
if (not onlycheck) then
file:write(code)
file:write("\n") file:write("\n")
end end
end end
end
else else
-- running from EDuke32 -- running from EDuke32
function compile(filenames) function compile(filenames)