Lunatic translator: text rendering and other niceties.

git-svn-id: https://svn.eduke32.com/eduke32@3501 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-02-18 16:07:42 +00:00
parent 4c57413da6
commit 185f0a8cc4
8 changed files with 144 additions and 35 deletions

View file

@ -77,9 +77,12 @@ function bcheck.quote_idx(qnum)
error("invalid quote number "..qnum, 3) error("invalid quote number "..qnum, 3)
end end
if (ffiC.ScriptQuotes[qnum] == nil) then local cstr = ffiC.ScriptQuotes[qnum]
if (cstr == nil) then
error("null quote "..qnum, 3) error("null quote "..qnum, 3)
end end
return cstr
end end

View file

@ -439,6 +439,35 @@ function _echo(qnum)
print(ffi.string(ffiC.ScriptQuotes[qnum])) print(ffi.string(ffiC.ScriptQuotes[qnum]))
end end
-- text rendering
function _minitext(x, y, qnum, shade, pal)
local cstr = bcheck.quote_idx(qnum)
ffiC.minitext_(x, y, cstr, shade, pal, 2+8+16)
end
function _digitalnumber(tilenum, x, y, num, shade, pal,
orientation, cx1, cy1, cx2, cy2, zoom)
if (tilenum >= ffiC.MAXTILES-9+0ULL) then
error("invalid base tile number "..tilenum, 2)
end
ffiC.G_DrawTXDigiNumZ(tilenum, x, y, num, shade, pal,
orientation, cx1, cy1, cx2, cy2, zoom)
end
function _gametext(tilenum, x, y, qnum, shade, pal, orientation,
cx1, cy1, cx2, cy2, zoom)
if (tilenum >= ffiC.MAXTILES-255+0ULL) then
error("invalid base tile number "..tilenum, 2)
end
local cstr = bcheck.quote_idx(qnum)
orientation = bit.band(orientation, 2047) -- ROTATESPRITE_MAX-1
ffiC.G_PrintGameText(0, tilenum, bit.arshift(x,1), y, cstr, shade, pal,
orientation, cx1, cy1, cx2, cy2, zoom)
end
local D = { local D = {
-- TODO: dynamic tile remapping -- TODO: dynamic tile remapping
ACTIVATOR = 2, ACTIVATOR = 2,
@ -1241,6 +1270,11 @@ function _startlevel(volume, level)
player[0].gm = bit.bor(player[0].gm, 0x00000008) -- MODE_EOL player[0].gm = bit.bor(player[0].gm, 0x00000008) -- MODE_EOL
end end
function _setaspect(viewingrange, yxaspect)
-- XXX: surely not all values are sane
ffiC.setaspect(viewingrange, yxaspect)
end
--- Exported functions --- --- Exported functions ---

View file

@ -539,6 +539,13 @@ 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);
int32_t FX_StopAllSounds(void); int32_t FX_StopAllSounds(void);
void S_ChangeSoundPitch(int32_t num, int32_t i, int32_t pitchoffset); void S_ChangeSoundPitch(int32_t num, int32_t i, int32_t pitchoffset);
int32_t minitext_(int32_t x,int32_t y,const char *t,int32_t s,int32_t p,int32_t sb);
void G_DrawTXDigiNumZ(int32_t starttile, int32_t x,int32_t y,int32_t n,int32_t s,int32_t pal,
int32_t cs,int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t z);
int32_t G_PrintGameText(int32_t f, int32_t tile, int32_t x, int32_t y, const char *t,
int32_t s, int32_t p, int32_t o,
int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t z);
]] ]]
decl[[ decl[[

View file

@ -265,6 +265,8 @@ void updatesectorz(int32_t x, int32_t y, int32_t z, int16_t *sectnum);
void rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, void rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum,
int8_t dashade, unsigned char dapalnum, int32_t dastat, int8_t dashade, unsigned char dapalnum, int32_t dastat,
int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2); int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2);
void setaspect(int32_t daxrange, int32_t daaspect);
]] ]]
-- misc. functions -- misc. functions
@ -472,6 +474,25 @@ end
local tspritetype_mt = deep_copy(spritetype_mt) local tspritetype_mt = deep_copy(spritetype_mt)
local function get_sprite_idx(spr)
local i = ffi.cast(spritetype_ptr_ct, spr)-ffi.cast(spritetype_ptr_ct, ffiC.sprite)
assert(not (i >= ffiC.MAXSPRITES+0ULL))
return i
end
-- Methods that are specific to sprites
function spritetype_mt.__index.setpos(spr, pos) -- setsprite() clone
spr.x, spr.y, spr.z = pos.x, pos.y, pos.z
local newsect = updatesector(spr, spr.sectnum)
if (newsect < 0) then
return -1
end
ffiC.changespritesect(get_sprite_idx(spr), newsect)
return newsect
end
-- Methods that are specific to tsprites -- Methods that are specific to tsprites
function tspritetype_mt.__index.dup(tspr) function tspritetype_mt.__index.dup(tspr)
if (ffiC.spritesortcnt >= ffiC.MAXSPRITESONSCREEN+0ULL) then if (ffiC.spritesortcnt >= ffiC.MAXSPRITESONSCREEN+0ULL) then

View file

@ -157,4 +157,8 @@ S_CheckSoundPlaying;
S_StopEnvSound; S_StopEnvSound;
FX_StopAllSounds; FX_StopAllSounds;
S_ChangeSoundPitch; S_ChangeSoundPitch;
minitext_;
G_DrawTXDigiNumZ;
G_PrintGameText;
}; };

View file

@ -138,7 +138,7 @@ local function new_initial_codetab()
"local _xmath, _geom = require'xmath', require'geom';", "local _xmath, _geom = require'xmath', require'geom';",
"local sector, sprite, actor, player = sector, sprite, actor, player;", "local sector, sprite, actor, player = sector, sprite, actor, player;",
"local gameactor, gameevent, _gv = gameactor, gameevent, gv;", "local gameactor, gameevent, _gv = gameactor, gameevent, gv;",
"local cansee = cansee;" "local updatesector, updatesectorz, cansee = updatesector, updatesectorz, cansee;"
} }
end end
@ -1343,6 +1343,10 @@ local handle =
soundonce = "_con._soundonce(_aci,%1)", soundonce = "_con._soundonce(_aci,%1)",
} }
local function n_s_fmt(n)
return string.rep("%s,", n-1).."%s"
end
local userdef_common_pat = (arraypat + sp1)/{} * lpeg.Cc(0) * lpeg.Ct(singlememberpat) * sp1 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 -- NOTE about prefixes: most is handled by all_alt_pattern(), however commands
@ -1395,8 +1399,6 @@ local Cinner = {
setplayervar = GetOrSetPerxvarCmd(true, false), setplayervar = GetOrSetPerxvarCmd(true, false),
setactorvar = GetOrSetPerxvarCmd(true, true), setactorvar = GetOrSetPerxvarCmd(true, true),
setsprite = cmd(R,R,R,R),
setvarvar = varvarop / "%1=%2", setvarvar = varvarop / "%1=%2",
addvarvar = varvaropf "+", addvarvar = varvaropf "+",
subvarvar = varvaropf "-", subvarvar = varvaropf "-",
@ -1732,11 +1734,24 @@ local Cinner = {
/ handle.NYI, / handle.NYI,
-- screen text and numbers display -- screen text and numbers display
gametext = cmd(R,R,R,R,R,R,R,R,R,R,R), -- 11 R gametext = cmd(R,R,R,R,R,R,R,R,R,R,R) -- 11 R
gametextz = cmd(R,R,R,R,R,R,R,R,R,R,R,R), -- 12 R / function(...)
digitalnumber = cmd(R,R,R,R,R,R,R,R,R,R,R), -- 11R return format("_con._gametext("..n_s_fmt(11)..",65536)", ...)
digitalnumberz = cmd(R,R,R,R,R,R,R,R,R,R,R,R), -- 12R end,
minitext = cmd(R,R,R,R,R), gametextz = cmd(R,R,R,R,R,R,R,R,R,R,R,R) -- 12 R
/ function(...)
return format("_con._gametext("..n_s_fmt(12)..")", ...)
end,
digitalnumber = cmd(R,R,R,R,R,R,R,R,R,R,R) -- 11R
/ function(...)
return format("_con._digitalnumber("..n_s_fmt(11)..",65536)", ...)
end,
digitalnumberz = cmd(R,R,R,R,R,R,R,R,R,R,R,R) -- 12R
/ function(...)
return format("_con._digitalnumber("..n_s_fmt(12)..")", ...)
end,
minitext = cmd(R,R,R,R,R)
/ "_con._minitext(%1,%2,%3,%4,%5)",
palfrom = (sp1 * tok.define)^-4 palfrom = (sp1 * tok.define)^-4
/ handle.palfrom, / handle.palfrom,
@ -1812,6 +1827,8 @@ local Cinner = {
starttrackvar = cmd(R) starttrackvar = cmd(R)
/ "_con._starttrack(%1)", / "_con._starttrack(%1)",
setaspect = cmd(R,R)
/ "_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 showviewunbiased = cmd(R,R,R,R,R,R,R,R,R,R), -- 10R
smaxammo = cmd(R,R) smaxammo = cmd(R,R)
@ -1822,8 +1839,12 @@ local Cinner = {
/ ACS".flags=%1", / ACS".flags=%1",
ssp = cmd(R,R) ssp = cmd(R,R)
/ handle.NYI, / handle.NYI,
updatesector = cmd(R,R,W), setsprite = cmd(R,R,R,R)
updatesectorz = cmd(R,R,R,W), / "sprite[%1]:setpos(_geom.ivec3(%1,%2,%3))",
updatesector = cmd(R,R,W)
/ format("%%3=updatesector(_geom.ivec3(%%1,%%2),%s)", SPS".sectnum"),
updatesectorz = cmd(R,R,R,W)
/ format("%%4=updatesectorz(_geom.ivec3(%%1,%%2,%%3),%s)", SPS".sectnum"),
getactorangle = cmd(W) getactorangle = cmd(W)
/ ("%1="..SPS".ang"), / ("%1="..SPS".ang"),
@ -1837,17 +1858,15 @@ local Cinner = {
/ "%1=_con._angtotarget(_aci)", / "%1=_con._angtotarget(_aci)",
getceilzofslope = cmd(R,R,R,W) getceilzofslope = cmd(R,R,R,W)
/ "%4=sector[%1]:ceilingzat(%2,%3)", / "%4=sector[%1]:ceilingzat(_geom.ivec3(%2,%3))",
getflorzofslope = cmd(R,R,R,W) getflorzofslope = cmd(R,R,R,W)
/ "%4=sector[%1]:floorzat(%2,%3)", / "%4=sector[%1]:floorzat(_geom.ivec3(%2,%3))",
getcurraddress = cmd(W) getcurraddress = cmd(W)
/ handle.NYI, -- will never be / handle.NYI, -- will never be
getticks = cmd(W) getticks = cmd(W)
/ "%1=_gv.getticks()", / "%1=_gv.getticks()",
gettimedate = cmd(W,W,W,W,W,W,W,W) gettimedate = cmd(W,W,W,W,W,W,W,W)
/ "%1,%2,%3,%4,%5,%6,%7,%8=_con._gettimedate()", / "%1,%2,%3,%4,%5,%6,%7,%8=_con._gettimedate()",
setaspect = cmd(R,R),
} }
local Cif = { local Cif = {
@ -1937,7 +1956,8 @@ local Cif = {
/ function (...) return format("_con._ifp(%d,_pli,_aci)", bit.bor(...)) end, / function (...) return format("_con._ifp(%d,_pli,_aci)", bit.bor(...)) end,
ifsquished = cmd() ifsquished = cmd()
/ "false", -- TODO / "false", -- TODO
ifserver = cmd(), ifserver = cmd()
/ "false", -- TODO_MP
ifrespawn = cmd() ifrespawn = cmd()
/ format("_con._checkrespawn(%s)", SPS""), / format("_con._checkrespawn(%s)", SPS""),
ifoutside = cmd() ifoutside = cmd()
@ -1963,7 +1983,8 @@ local Cif = {
/ "_con._testkey(_pli,29)", -- XXX / "_con._testkey(_pli,29)", -- XXX
ifdead = cmd() ifdead = cmd()
/ SPS".extra<=0", / SPS".extra<=0",
ifclient = cmd(), ifclient = cmd()
/ "false", -- TODO_MP
ifcanshoottarget = cmd() ifcanshoottarget = cmd()
/ "_con._canshoottarget(_dist,_aci)", / "_con._canshoottarget(_dist,_aci)",
ifcanseetarget = cmd() -- XXX: 1536 is SLEEPTIME ifcanseetarget = cmd() -- XXX: 1536 is SLEEPTIME

View file

@ -311,9 +311,9 @@ gameevent(gv.EVENT_ENTERLEVEL,
-- N=10: 190-210 us * 10 = 1.9-2.1 ms -- N=10: 190-210 us * 10 = 1.9-2.1 ms
-- N=100: about 160 us * 100 = about 16 ms -- N=100: about 160 us * 100 = about 16 ms
-- Make the DUKECAR in E1L1 into a static object -- Make the DUKECAR in E1L1 into a zombie actor (temporarily)
if (sprite[24].picnum==2491) then if (sprite[24].picnum==2491) then
sprite.changestat(24, gv.STAT_DEFAULT) sprite.changestat(24, gv.STAT_ZOMBIEACTOR)
end end
checkfail("gameevent('GAME', function() print('qwe') end)", checkfail("gameevent('GAME', function() print('qwe') end)",
@ -321,6 +321,25 @@ gameevent(gv.EVENT_ENTERLEVEL,
end end
) )
local geom = require "geom"
gameevent("LOADACTOR", function(i)
local spr = sprite[i]
if (i==614 and spr.picnum==930) then
-- "police line" ribbon in E1L1
-- clear the hitag so that it doesn't spawn as FALLER from premap
spr.hitag = 0
end
end)
gameactor(930, 1, function(i) -- "police line" ribbon
local spr = sprite[i]
local r = math.random
local d = 20
local v = geom.tovec3(spr) + geom.vec3(r(-d,d), r(-d,d))
spr:setpos(v)
end)
local stat = require("stat") local stat = require("stat")
local hs = stat.new() local hs = stat.new()

View file

@ -1120,6 +1120,22 @@ static inline void prelevel(char g)
} }
} }
#ifdef LUNATIC
if (g_testLua)
{
if (L_IsInitialized(&g_ElState))
{
i = L_RunOnce(&g_ElState, "test.elua");
if (i)
OSD_Printf(OSD_ERROR "Error running the test ELua script (code %d)\n", i);
else
initprintf("ELua test script run ok!\n");
}
else
initprintf("ELua test script: not inited!\n");
}
#endif
i = headspritestat[STAT_DEFAULT]; i = headspritestat[STAT_DEFAULT];
while (i >= 0) while (i >= 0)
{ {
@ -1391,22 +1407,6 @@ static inline void prelevel(char g)
wall[j].pal = 4; wall[j].pal = 4;
} }
} }
#ifdef LUNATIC
if (g_testLua)
{
if (L_IsInitialized(&g_ElState))
{
i = L_RunOnce(&g_ElState, "test.elua");
if (i)
OSD_Printf(OSD_ERROR "Error running the test ELua script (code %d)\n", i);
else
initprintf("ELua test script run ok!\n");
}
else
initprintf("ELua test script: not inited!\n");
}
#endif
} }