Mapster32/Lunatic: add functionality to connect Lua funcs to s.bar menu [;]+[F].

Hook up those from test/shadexfog.lua and some debugging ones from engine.lua.

git-svn-id: https://svn.eduke32.com/eduke32@4419 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2014-04-06 22:24:14 +00:00
parent e641cf8b57
commit 494c00713b
6 changed files with 281 additions and 2 deletions

View File

@ -8019,6 +8019,12 @@ static void Keys2d(void)
{
FuncMenu();
}
#ifdef LUNATIC
else if (keystatus[KEYSC_SEMI] && PRESSED_KEYSC(F)) // ; F
{
LuaFuncMenu();
}
#endif
else if (!eitherALT && PRESSED_KEYSC(F))
{
if (pointhighlight < 16384 && tcursectornum>=0 && graphicsmode)
@ -12969,6 +12975,15 @@ typedef struct StatusBarMenu_ {
#define MENU_INITIALIZER(MenuName, CustomStartIndex, ProcessFunc, ...) \
{ MenuName, CustomStartIndex, CustomStartIndex, ProcessFunc, {}, ## __VA_ARGS__ }
#ifdef LUNATIC
static void M_Clear(StatusBarMenu *m)
{
m->numentries = 0;
Bmemset(m->auxdata, 0, sizeof(m->auxdata));
Bmemset(m->name, 0, sizeof(m->name));
}
#endif
static void M_UnregisterFunction(StatusBarMenu *m, intptr_t auxdata)
{
int32_t i, j;
@ -13051,6 +13066,12 @@ static void M_EnterMainLoop(StatusBarMenu *m)
int32_t crowmax[3] = {-1, -1, -1};
int32_t xpos = 8, ypos = MENU_BASE_Y+16;
if (m->numentries == 0)
{
printmessage16("%s menu has no entries", m->menuname);
return;
}
Bmemset(disptext, 0, sizeof(disptext));
Bassert((unsigned)m->numentries <= MENU_MAX_ENTRIES);
@ -13388,3 +13409,54 @@ static void FuncMenu_Process(const StatusBarMenu *m, int32_t col, int32_t row)
} // switch (col)
}
#ifdef LUNATIC
typedef const char *(*luamenufunc_t)(void);
static int32_t g_numLuaFuncs = 0;
static luamenufunc_t g_LuaFuncPtrs[MENU_MAX_ENTRIES];
static void LuaFuncMenu_Process(const StatusBarMenu *m, int32_t col, int32_t row)
{
luamenufunc_t func = g_LuaFuncPtrs[col*8 + row];
const char *errmsg;
Bassert(func != NULL);
errmsg = func();
if (errmsg == NULL)
{
printmessage16("Lua function executed successfully");
}
else
{
printmessage16("There were errors executing the Lua function, see OSD");
OSD_Printf("Errors executing Lua function \"%s\": %s\n", m->name[col*8 + row], errmsg);
}
}
static StatusBarMenu g_LuaFuncMenu = MENU_INITIALIZER_EMPTY("Lua functions", LuaFuncMenu_Process);
static void LuaFuncMenu(void)
{
M_EnterMainLoop(&g_LuaFuncMenu);
}
LUNATIC_EXTERN void LM_Register(const char *name, luamenufunc_t funcptr)
{
if (name == NULL || g_numLuaFuncs == MENU_MAX_ENTRIES)
return;
g_LuaFuncPtrs[g_numLuaFuncs] = funcptr;
M_RegisterFunction(&g_LuaFuncMenu, name, g_numLuaFuncs);
g_numLuaFuncs++;
}
LUNATIC_EXTERN void LM_Clear(void)
{
M_Clear(&g_LuaFuncMenu);
g_numLuaFuncs = 0;
Bmemset(g_LuaFuncPtrs, 0, sizeof(g_LuaFuncPtrs));
}
#endif

View File

@ -17,6 +17,7 @@ numyaxbunches;
spritesortcnt;
guniqhudid;
qsetmode;
rendmode;
totalclock;
randomseed;

View File

@ -17,6 +17,7 @@ numyaxbunches;
spritesortcnt;
guniqhudid;
qsetmode;
rendmode;
totalclock;
randomseed;
@ -108,7 +109,10 @@ luaJIT_BC_dis_x64;
g_argv;
_getnumber16;
listsearchpath;
LM_Register;
LM_Clear;
basepaltable;
};

View File

@ -16,6 +16,7 @@ local ismapster32 = (C.LUNATIC_CLIENT == C.LUNATIC_CLIENT_MAPSTER32)
----------
decl[[
const int32_t qsetmode;
int32_t getclosestcol_lim(int32_t r, int32_t g, int32_t b, int32_t lastokcol);
char *palookup[256]; // MAXPALOOKUPS
uint8_t palette[768];
@ -27,6 +28,16 @@ void setblendtab(int32_t blend, const char *tab);
int32_t setpalookup(int32_t palnum, const uint8_t *shtab);
]]
if (ismapster32) then
ffi.cdef[[
int32_t _getnumber16(const char *namestart, int32_t num, int32_t maxnumber, char sign, const char *(func)(int32_t));
typedef const char *(*luamenufunc_t)(void);
void LM_Register(const char *name, luamenufunc_t funcptr);
void LM_Clear(void);
]]
end
----------
@ -419,6 +430,52 @@ if (ismapster32) then
end
end
end
-- Interfaces to Mapster32's status bar menu
local pcall = pcall
function engine.clearMenu()
C.LM_Clear()
end
function engine.registerMenuFunc(name, func)
if (type(name) ~= "string") then
error("invalid argument #1: must be a string", 2)
end
if (type(func) ~= "function") then
error("invalid argument #2: must be a function", 2)
end
local safefunc = function()
local ok, errmsg = pcall(func)
if (not ok) then
return errmsg
end
end
C.LM_Register(name, safefunc)
end
engine.GETNUMFLAG = {
NEG_ALLOWED = 1,
AUTOCOMPL_NAMES = 2,
AUTOCOMPL_TAGLAB = 4,
RET_M1_ON_CANCEL = 8,
NEXTFREE = 16,
}
function engine.getnumber16(namestart, num, maxnumber, flags)
if (C.qsetmode == 200) then
error("getnumber16 must be called from 2D mode", 2)
end
if (type(namestart)~="string") then
error("invalid argument #1: must be a string", 2)
end
return C._getnumber16(namestart, num, maxnumber, flags, nil)
end
end

View File

@ -12,6 +12,7 @@ local error = error
local print = print
local printf = printf
local type = type
local unpack = unpack
local bit = require("bit")
local math = require("math")
@ -106,7 +107,7 @@ end
-- Translate the whole map for use with a shade-x-fog palookup set.
-- .pal becomes the <startpalnum> + former .shade
-- .shade becomes the <fogintensity> [0 .. 31]
-- If <vis> is passed, set all sector's visibility to that value.
-- If <vis> is passed and >= 0, set all sector's visibility to that value.
--
-- Notes:
-- - auto-detects when the translation has been applied with the *same*
@ -116,7 +117,7 @@ function shadexfog.translate(startpalnum, fogintensity, vis)
for i=0,gv.numsectors-1 do
trans(sector[i].ceiling, startpalnum, fogintensity)
trans(sector[i].floor, startpalnum, fogintensity)
if (vis) then
if (vis and vis >= 0) then
sector[i].visibility = vis
end
end
@ -409,6 +410,147 @@ function shadexfog.create_additive_trans(startblendidx, numtables, fullbrightsOK
end
-- Mapster32 Lua menu hooks
local getnumber16 = engine.getnumber16
local GNF = engine.GETNUMFLAG
local GNF_BOOL = GNF.NEXTFREE
local df = GNF.RET_M1_ON_CANCEL -- default getnumber16() flags
local MAXUSERPALOOKUP = 256-1-8 -- KEEPINSYNC engine.lua:check_palidx()
-- wrapped_func = CreateMenuFunction(argdesc)
--
-- <argdesc>: table with [0]=<func> and then, entries { name, init, max [, noret] }
function CreateMenuFunction(argdesc)
return function()
local func = argdesc[0]
assert(type(func) == "function")
local args = {}
for i=1,#argdesc do
local ad = argdesc[i]
assert(type(ad) == "table" and #ad == 3 or #ad == 4)
local moreflags = ad[4] or 0
args[i] = getnumber16(ad[1]..": ", ad[2], ad[3], bit.bor(df, moreflags))
if (bit.band(moreflags, GNF.NEG_ALLOWED)==0 and args[i] < 0) then
return
end
if (bit.band(moreflags, GNF_BOOL)~=0) then
args[i] = (args[i] > 0)
end
end
func(unpack(args))
end
end
engine.clearMenu()
engine.registerMenuFunc(
"Create shadexfog palset",
CreateMenuFunction{
[0] = shadexfog.create,
{ "Starting palnum", 100, MAXUSERPALOOKUP-31 },
{ "Red fog color [0-63]", 0, 63 },
{ "Green fog color [0-63]", 0, 63 },
{ "Blue fog color [0-63]", 0, 63 },
}
)
engine.registerMenuFunc(
"Translate map for shxfog",
CreateMenuFunction{
[0] = shadexfog.translate,
{ "Starting palnum", 100, MAXUSERPALOOKUP-31 },
{ "Fog intensity [0-31]", 0, 31 },
{ "Change all sectors' visibility to (Esc: don't)", 0, 255, GNF.NEG_ALLOWED },
}
)
engine.registerMenuFunc(
"Change pal of everything",
CreateMenuFunction{
[0] = shadexfog.challpal,
{ "Pal to change to", 0, MAXUSERPALOOKUP },
}
)
engine.registerMenuFunc(
"Create alpha trans. tabs",
CreateMenuFunction{
[0] = shadexfog.create_alpha_trans,
{ "Starting blendnum", 1, 255 },
{ "Number of blending tables", 32, 255 },
{ "Fullbright result colors OK?", 0, 1, GNF_BOOL },
}
)
engine.registerMenuFunc(
"Create addtv. trans. tabs",
CreateMenuFunction{
[0] = shadexfog.create_additive_trans,
{ "Starting blendnum", 1, 255 },
{ "Number of blending tables", 32, 255 },
{ "Fullbright result colors OK?", 0, 1, GNF_BOOL },
}
)
engine.registerMenuFunc(
"Create base shade table",
CreateMenuFunction{
[0] = shadexfog.create0,
{ "Pal number", 100, MAXUSERPALOOKUP },
{ "Second attempt?", 1, 1, GNF_BOOL },
}
)
engine.registerMenuFunc(
"Create depth shade tab",
CreateMenuFunction{
[0] = shadexfog.create_depth_shtab,
{ "Pal number", 100, MAXUSERPALOOKUP },
}
)
engine.registerMenuFunc(
"Create vismarker sh. tab",
CreateMenuFunction{
[0] = shadexfog.create_vismarker_shtab,
{ "Pal number", 100, MAXUSERPALOOKUP },
}
)
engine.registerMenuFunc(
"Create c.index remapping",
function()
local palnum = getnumber16("Pal number: ", 100, MAXUSERPALOOKUP, df)
if (palnum < 0) then return end
local remaptab = {}
while (true) do
local srchex = getnumber16("Source hexadecatuple (0: finish): ", 0, 14, df)
if (srchex < 0) then return end
local dsthex = getnumber16("Destn. hexadecatuple (0: finish): ", 0, 14, df)
if (dsthex < 0) then return end
if (srchex == 0 and dsthex == 0) then
break
end
remaptab[srchex] = dsthex
end
shadexfog.createremap(palnum, remaptab)
end
)
engine.registerMenuFunc("_________DEBUG_________", function() end)
engine.registerMenuFunc("Setup dbg. water basepal", engine.setupDebugBasePal)
engine.registerMenuFunc("Linearize default basep.", engine.linearizeBasePal)
do
return shadexfog
end

View File

@ -72,6 +72,9 @@ static void EditSpriteData(int16_t spritenum);
static void EditWallData(int16_t wallnum);
static void EditSectorData(int16_t sectnum);
static void FuncMenu(void);
#ifdef LUNATIC
static void LuaFuncMenu(void);
#endif
#define BASEPALCOUNT 6