Skip to content
Snippets Groups Projects
Commit 9bdbc03b authored by dg's avatar dg
Browse files

* some more info in the savefile description for ToME

* the engine can reboot its lua state when unloading a module, to clean things up



git-svn-id: http://svn.net-core.org/repos/t-engine4@661 51575b47-30f0-44d4-a5cc-537603b46e54
parent 04eb5968
No related branches found
No related tags found
No related merge requests found
......@@ -94,6 +94,7 @@ function _M:loadDefinition(dir, team)
fs.mount(src, "/", false)
end
local m = require(mod.starter)
print("[MODULE LOADER] loading module", mod.long_name, "["..mod.starter.."]", "::", m[1] and m[1].__CLASSNAME, m[2] and m[2].__CLASSNAME)
return m[1], m[2]
end
......
......@@ -75,4 +75,4 @@ game = false
engine.Game:setResolution(config.settings.window.size)
engine.interface.GameMusic:soundSystemStatus(config.settings.sound.enabled, true)
util.showMainMenu()
util.showMainMenu(true)
......@@ -387,10 +387,16 @@ function util.findFreeGrid(sx, sy, radius, block, what)
return gs[1][1], gs[1][2]
end
function util.showMainMenu()
local Menu = require("special.mainmenu.class.Game")
game = Menu.new()
game:run()
function util.showMainMenu(no_reboot)
if no_reboot then
local Menu = require("special.mainmenu.class.Game")
game = Menu.new()
game:run()
else
-- Tell the C engine to discard the current lua state and make a new one
print("[MAIN] rebooting lua state")
core.game.reboot()
end
end
function rng.mbonus(max, level, max_level)
......
......@@ -218,7 +218,11 @@ end
function _M:getSaveDescription()
return {
name = self.player.name,
description = ([[Exploring level %d of %s.]]):format(self.level.level, self.zone.name),
description = ([[%s the level %d %s %s.
Exploring level %d of %s.]]):format(
self.player.name, self.player.level, self.player.descriptor.subrace, self.player.descriptor.subclass,
self.level.level, self.zone.name
),
}
end
......
......@@ -168,6 +168,7 @@ function _M:selectStepNew()
end
display_module.drawDialog = function(self, s)
if not game.step and not game.mod_list then return end
local lines = game.mod_list[game.step.selected].description:splitLines(self.w - 8, self.font)
local r, g, b
for i = 1, #lines do
......@@ -230,6 +231,7 @@ function _M:selectStepLoad()
if self.step and self.step.close then self.step:close() end
display_module.drawDialog = function(self, s)
if not game.step and not game.mod_list then return end
local lines = list[game.step.selected].description:splitLines(self.w - 8, self.font)
local r, g, b
for i = 1, #lines do
......
......@@ -392,8 +392,15 @@ static int lua_exit_engine(lua_State *L)
exit_engine = TRUE;
return 0;
}
extern bool reboot_lua;
static int lua_reboot_lua(lua_State *L)
{
reboot_lua = TRUE;
return 0;
}
static const struct luaL_reg gamelib[] =
{
{"reboot", lua_reboot_lua},
{"set_current_game", lua_set_current_game},
{"exit_engine", lua_exit_engine},
{NULL, NULL},
......
......@@ -47,6 +47,7 @@ lua_State *L = NULL;
int current_mousehandler = LUA_NOREF;
int current_keyhandler = LUA_NOREF;
int current_game = LUA_NOREF;
bool reboot_lua = FALSE;
bool exit_engine = FALSE;
bool no_sound = FALSE;
bool isActive = TRUE;
......@@ -420,6 +421,95 @@ void do_resize(int w, int h, bool fullscreen)
resizeWindow(screen->w, screen->h);
}
void boot_lua(int state, bool rebooting, int argc, char *argv[])
{
reboot_lua = FALSE;
if (state == 1)
{
const char *selfexe;
/* When rebooting we destroy the lua state to free memory and we reset physfs */
if (rebooting)
{
lua_close(L);
PHYSFS_deinit();
}
/***************** Physfs Init *****************/
PHYSFS_init(argv[0]);
selfexe = get_self_executable(argc, argv);
if (selfexe)
{
PHYSFS_mount(selfexe, "/", 1);
}
else
{
printf("NO SELFEXE: bootstrapping from CWD\n");
PHYSFS_mount("bootstrap", "/bootstrap", 1);
}
/***************** Lua Init *****************/
L = lua_open(); /* create state */
luaL_openlibs(L); /* open libraries */
luaopen_core(L);
luaopen_socket_core(L);
luaopen_mime_core(L);
luaopen_struct(L);
luaopen_profiler(L);
luaopen_lpeg(L);
luaopen_map(L);
luaopen_particles(L);
luaopen_sound(L);
// Make the uids repository
lua_newtable(L);
lua_setglobal(L, "__uids");
// Tell the boostrapping code the selfexe path
if (selfexe)
lua_pushstring(L, selfexe);
else
lua_pushnil(L);
lua_setglobal(L, "__SELFEXE");
// Will be useful
#ifdef __APPLE__
lua_pushboolean(L, TRUE);
lua_setglobal(L, "__APPLE__");
#endif
// Run bootstrapping
if (!luaL_loadfile(L, "/bootstrap/boot.lua"))
{
docall(L, 0, 0);
}
// Could not load bootstrap! Try to mount the engine from working directory as last resort
else
{
printf("WARNING: No bootstrap code found, defaulting to working directory for engine code!\n");
PHYSFS_mount("game/thirdparty", "/", 1);
PHYSFS_mount("game/", "/", 1);
}
// And run the lua engine pre init scripts
luaL_loadfile(L, "/engine/pre-init.lua");
docall(L, 0, 0);
}
else if (state == 2)
{
SDL_WM_SetCaption("T4Engine", NULL);
// Now we can open lua lanes, the physfs paths are set and it can load it's lanes-keeper.lua file
luaopen_lanes(L);
// And run the lua engine scripts
luaL_loadfile(L, "/engine/init.lua");
docall(L, 0, 0);
}
}
/**
* Program entry point.
*/
......@@ -434,71 +524,10 @@ void do_resize(int w, int h, bool fullscreen)
int main(int argc, char *argv[])
{
const char *selfexe;
// RNG init
init_gen_rand(time(NULL));
/***************** Physfs Init *****************/
PHYSFS_init(argv[0]);
selfexe = get_self_executable(argc, argv);
if (selfexe)
{
PHYSFS_mount(selfexe, "/", 1);
}
else
{
printf("NO SELFEXE: bootstrapping from CWD\n");
PHYSFS_mount("bootstrap", "/bootstrap", 1);
}
/***************** Lua Init *****************/
L = lua_open(); /* create state */
luaL_openlibs(L); /* open libraries */
luaopen_core(L);
luaopen_socket_core(L);
luaopen_mime_core(L);
luaopen_struct(L);
luaopen_profiler(L);
luaopen_lpeg(L);
luaopen_map(L);
luaopen_particles(L);
luaopen_sound(L);
// Make the uids repository
lua_newtable(L);
lua_setglobal(L, "__uids");
// Tell the boostrapping code the selfexe path
if (selfexe)
lua_pushstring(L, selfexe);
else
lua_pushnil(L);
lua_setglobal(L, "__SELFEXE");
// Will be useful
#ifdef __APPLE__
lua_pushboolean(L, TRUE);
lua_setglobal(L, "__APPLE__");
#endif
// Run bootstrapping
if (!luaL_loadfile(L, "/bootstrap/boot.lua"))
{
docall(L, 0, 0);
}
// Could not load bootstrap! Try to mount the engine from working directory as last resort
else
{
printf("WARNING: No bootstrap code found, defaulting to working directory for engine code!\n");
PHYSFS_mount("game/thirdparty", "/", 1);
PHYSFS_mount("game/", "/", 1);
}
// And run the lua engine pre init scripts
luaL_loadfile(L, "/engine/pre-init.lua");
docall(L, 0, 0);
boot_lua(1, FALSE, argc, argv);
// initialize engine and set up resolution and depth
Uint32 flags=SDL_INIT_VIDEO | SDL_INIT_TIMER;
......@@ -533,12 +562,7 @@ int main(int argc, char *argv[])
/* Sets up OpenGL double buffering */
resizeWindow(WIDTH, HEIGHT);
// Now we can open lua lanes, the physfs paths are set and it can load it's lanes-keeper.lua file
luaopen_lanes(L);
// And run the lua engine scripts
luaL_loadfile(L, "/engine/init.lua");
docall(L, 0, 0);
boot_lua(2, FALSE, argc, argv);
pass_command_args(argc, argv);
......@@ -610,6 +634,13 @@ int main(int argc, char *argv[])
/* draw the scene */
if (isActive && !tickPaused) on_tick();
/* Reboot the lua engine */
if (reboot_lua)
{
boot_lua(1, TRUE, argc, argv);
boot_lua(2, TRUE, argc, argv);
}
}
SDL_Quit();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment