mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-24 10:40:46 +00:00
Lunatic: back up generated LunaCON code, recreate Lua state on map entering.
git-svn-id: https://svn.eduke32.com/eduke32@3787 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
e8ff49b6ef
commit
9d858b9883
7 changed files with 76 additions and 25 deletions
|
@ -120,7 +120,7 @@ int L_CreateState(L_State *estate, const char *name, void (*StateSetupFunc)(lua_
|
||||||
|
|
||||||
void L_DestroyState(L_State *estate)
|
void L_DestroyState(L_State *estate)
|
||||||
{
|
{
|
||||||
if (!estate->L)
|
if (!L_IsInitialized(estate))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Bfree(estate->name);
|
Bfree(estate->name);
|
||||||
|
|
|
@ -9836,6 +9836,50 @@ static void A_InitEnemyFlags(void)
|
||||||
extern int32_t startwin_run(void);
|
extern int32_t startwin_run(void);
|
||||||
static void G_SetupGameButtons(void);
|
static void G_SetupGameButtons(void);
|
||||||
|
|
||||||
|
#ifdef LUNATIC
|
||||||
|
// Will be used to store CON code translated to Lua.
|
||||||
|
int32_t g_elCONSize;
|
||||||
|
char *g_elCON; // NOT 0-terminated!
|
||||||
|
|
||||||
|
LUNATIC_EXTERN void El_SetCON(const char *conluacode)
|
||||||
|
{
|
||||||
|
int32_t slen = Bstrlen(conluacode);
|
||||||
|
|
||||||
|
g_elCON = Bmalloc(slen);
|
||||||
|
if (g_elCON == NULL)
|
||||||
|
G_GameExit("OUT OF MEMORY in El_SetCON!");
|
||||||
|
|
||||||
|
g_elCONSize = slen;
|
||||||
|
Bmemcpy(g_elCON, conluacode, slen);
|
||||||
|
}
|
||||||
|
|
||||||
|
void El_CreateGameState(void)
|
||||||
|
{
|
||||||
|
int32_t i;
|
||||||
|
|
||||||
|
El_DestroyState(&g_ElState);
|
||||||
|
|
||||||
|
if ((i = El_CreateState(&g_ElState, "game")))
|
||||||
|
{
|
||||||
|
initprintf("Lunatic: Error initializing global ELua state (code %d)\n", i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
extern const char luaJIT_BC_defs[];
|
||||||
|
|
||||||
|
if ((i = L_RunString(&g_ElState, (char *)luaJIT_BC_defs, 0,
|
||||||
|
LUNATIC_DEFS_BC_SIZE, "defs.ilua")))
|
||||||
|
{
|
||||||
|
initprintf("Lunatic: Error preparing global ELua state (code %d)\n", i);
|
||||||
|
El_DestroyState(&g_ElState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i)
|
||||||
|
G_GameExit("Failure setting up Lunatic!");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void G_Startup(void)
|
static void G_Startup(void)
|
||||||
{
|
{
|
||||||
int32_t i;
|
int32_t i;
|
||||||
|
@ -9858,24 +9902,7 @@ static void G_Startup(void)
|
||||||
setbasepaltable(basepaltable, BASEPALCOUNT);
|
setbasepaltable(basepaltable, BASEPALCOUNT);
|
||||||
|
|
||||||
#ifdef LUNATIC
|
#ifdef LUNATIC
|
||||||
if ((i = El_CreateState(&g_ElState, "test")))
|
El_CreateGameState();
|
||||||
{
|
|
||||||
initprintf("Lunatic: Error initializing global ELua state (code %d)\n", i);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
extern const char luaJIT_BC_defs[];
|
|
||||||
|
|
||||||
if ((i = L_RunString(&g_ElState, (char *)luaJIT_BC_defs, 0,
|
|
||||||
LUNATIC_DEFS_BC_SIZE, "defs.ilua")))
|
|
||||||
{
|
|
||||||
initprintf("Lunatic: Error preparing global ELua state (code %d)\n", i);
|
|
||||||
El_DestroyState(&g_ElState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i)
|
|
||||||
G_GameExit("Failure setting up Lunatic!");
|
|
||||||
C_InitQuotes();
|
C_InitQuotes();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -296,6 +296,10 @@ void Yax_SetBunchZs(int32_t sectnum, int32_t cf, int32_t daz);
|
||||||
#define Yax_SetBunchZs(sectnum, cf, daz)
|
#define Yax_SetBunchZs(sectnum, cf, daz)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef LUNATIC
|
||||||
|
void El_CreateGameState(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
void A_SpawnCeilingGlass(int32_t i,int32_t sectnum,int32_t n);
|
void A_SpawnCeilingGlass(int32_t i,int32_t sectnum,int32_t n);
|
||||||
void A_SpawnGlass(int32_t i,int32_t n);
|
void A_SpawnGlass(int32_t i,int32_t n);
|
||||||
void A_SpawnRandomGlass(int32_t i,int32_t wallnum,int32_t n);
|
void A_SpawnRandomGlass(int32_t i,int32_t wallnum,int32_t n);
|
||||||
|
|
|
@ -566,6 +566,10 @@ int32_t g_RETURN; // deprecated from Lua
|
||||||
decl("map_t MapInfo[$*$];", con_lang.MAXVOLUMES+1, con_lang.MAXLEVELS)
|
decl("map_t MapInfo[$*$];", con_lang.MAXVOLUMES+1, con_lang.MAXLEVELS)
|
||||||
|
|
||||||
decl[[
|
decl[[
|
||||||
|
int32_t g_elCONSize;
|
||||||
|
char *g_elCON;
|
||||||
|
void El_SetCON(const char *conluacode);
|
||||||
|
|
||||||
const char *s_buildRev;
|
const char *s_buildRev;
|
||||||
const char *g_sizes_of_what[];
|
const char *g_sizes_of_what[];
|
||||||
int32_t g_sizes_of[];
|
int32_t g_sizes_of[];
|
||||||
|
@ -1660,8 +1664,9 @@ G_.g_tile = g_tile
|
||||||
|
|
||||||
local concode
|
local concode
|
||||||
|
|
||||||
--- Compile CONs
|
--- Get Lua code for CON (+ mutator) code.
|
||||||
do
|
if (ffiC.g_elCONSize == 0) then
|
||||||
|
-- Compiling CON for the first time.
|
||||||
read_into_string = readintostr_mod -- for lunacon
|
read_into_string = readintostr_mod -- for lunacon
|
||||||
local lunacon = require("lunacon")
|
local lunacon = require("lunacon")
|
||||||
|
|
||||||
|
@ -1684,6 +1689,15 @@ do
|
||||||
end
|
end
|
||||||
assert(lineinfo)
|
assert(lineinfo)
|
||||||
|
|
||||||
|
-- Back up the translated code on the C side.
|
||||||
|
assert(type(concode)=="string")
|
||||||
|
ffiC.El_SetCON(concode)
|
||||||
|
else
|
||||||
|
-- CON was already compiled.
|
||||||
|
concode = ffi.string(ffiC.g_elCON, ffiC.g_elCONSize)
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
-- Translate one Lua line number to a CON file name + line number
|
-- Translate one Lua line number to a CON file name + line number
|
||||||
local function transline(lnum)
|
local function transline(lnum)
|
||||||
return string.format("%s:%d", lineinfo:getfline(tonumber(lnum)))
|
return string.format("%s:%d", lineinfo:getfline(tonumber(lnum)))
|
||||||
|
|
|
@ -86,6 +86,10 @@ luaJIT_BC_engine_maptext;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
g_elCONSize;
|
||||||
|
g_elCON;
|
||||||
|
El_SetCON;
|
||||||
|
|
||||||
s_buildRev;
|
s_buildRev;
|
||||||
g_sizes_of_what;
|
g_sizes_of_what;
|
||||||
g_sizes_of;
|
g_sizes_of;
|
||||||
|
|
|
@ -52,12 +52,12 @@ local mt = {
|
||||||
local tout = ffi.new("uint32_t [4]")
|
local tout = ffi.new("uint32_t [4]")
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
s.y = get_rand_u32()
|
s.y = get_rand_u32(tin)
|
||||||
until (s.y ~= 0) -- y must not be zero!
|
until (s.y ~= 0) -- y must not be zero!
|
||||||
|
|
||||||
s.x = get_rand_u32()
|
s.x = get_rand_u32(tin)
|
||||||
s.z = get_rand_u32()
|
s.z = get_rand_u32(tin)
|
||||||
s.c = get_rand_u32() % 698769068 + 1 -- Should be less than 698769069
|
s.c = get_rand_u32(tin) % 698769068 + 1 -- Should be less than 698769069
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1120,6 +1120,8 @@ static inline void prelevel(char g)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef LUNATIC
|
#ifdef LUNATIC
|
||||||
|
El_CreateGameState();
|
||||||
|
|
||||||
if (g_testLua)
|
if (g_testLua)
|
||||||
{
|
{
|
||||||
if (L_IsInitialized(&g_ElState))
|
if (L_IsInitialized(&g_ElState))
|
||||||
|
|
Loading…
Reference in a new issue