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

fix

git-svn-id: http://svn.net-core.org/repos/t-engine4@2994 51575b47-30f0-44d4-a5cc-537603b46e54
parent 89551d48
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,9 @@ else
end
-- Look for a core
function get_core(type, id)
function get_core(coretype, id)
coretype = coretype or "te4core"
local homepath = fs.getUserPath()..fs.getPathSeparator()..fs.getHomePath()..fs.getPathSeparator().."4.0"
fs.mount(homepath, "/", 1)
......@@ -33,20 +35,23 @@ function get_core(type, id)
local usable = {}
for i, file in ipairs(fs.list("/engines/cores/")) do
if file:find("%.tec$") then
print("Possible engine core", file)
if id > 0 and file == type.."-"..id..".tec" then usable[#usable+1] = {file=file, id=id}
elseif id == -1 and file:find(type) then
print("Looking for cores", coretype, id, " <=> ", file)
if id > 0 and file == coretype.."-"..id..".tec" then
usable[#usable+1] = {file=file, id=id}
print("Possible engine core", file)
elseif id == -1 and file:find(coretype) then
local _, _, cid = file:find("%-([0-9]+)%.tec$")
cid = tonumber(cid)
if cid then
usable[#usable+1] = {file=file, id=cid}
print("Possible engine core", file)
end
end
end
end
-- Order the cores to find the newest
table.sort(usable, function(a, b) return b.id < a.id end)
for i, file in ipairs(usable) do print("Selected cores:", file.file) end
for i, file in ipairs(usable) do print("Selected cores:", file.id, file.file) end
-- Check for sanity and tell the runner to use it
local core = "/engines/cores/"..usable[1].file
......
......@@ -949,7 +949,7 @@ function util.showMainMenu(no_reboot, reboot_engine, reboot_engine_version, rebo
else
-- Tell the C engine to discard the current lua state and make a new one
print("[MAIN] rebooting lua state: ", reboot_engine, reboot_engine_version, reboot_module, reboot_name, reboot_new)
core.game.reboot(-1, reboot_engine or "te4", reboot_engine_version or "LATEST", reboot_module or "boot", reboot_name or "player", reboot_new, reboot_einfo or "")
core.game.reboot("te4core", -1, reboot_engine or "te4", reboot_engine_version or "LATEST", reboot_module or "boot", reboot_name or "player", reboot_new, reboot_einfo or "")
end
end
......
......@@ -142,33 +142,22 @@ static int lua_exit_engine(lua_State *L)
exit_engine = TRUE;
return 0;
}
extern int reboot_lua;
extern bool reboot_new;
extern char *reboot_engine, *reboot_engine_version, *reboot_module, *reboot_name, *reboot_einfo;
static int lua_reboot_lua(lua_State *L)
{
if (reboot_engine) free(reboot_engine);
if (reboot_engine_version) free(reboot_engine_version);
if (reboot_module) free(reboot_module);
if (reboot_name) free(reboot_name);
if (reboot_einfo) free(reboot_einfo);
reboot_lua = luaL_checknumber(L, 1);
reboot_engine = (char *)luaL_checkstring(L, 2);
reboot_engine_version = (char *)luaL_checkstring(L, 3);
reboot_module = (char *)luaL_checkstring(L, 4);
reboot_name = (char *)luaL_checkstring(L, 5);
reboot_new = lua_toboolean(L, 6);
reboot_einfo = (char *)luaL_checkstring(L, 7);
core_def->define(
core_def,
luaL_checkstring(L, 1),
luaL_checknumber(L, 2),
luaL_checkstring(L, 3),
luaL_checkstring(L, 4),
luaL_checkstring(L, 5),
luaL_checkstring(L, 6),
lua_toboolean(L, 7),
luaL_checkstring(L, 8)
);
// By default reboot the same core -- this skips some initializations
if (reboot_lua == -1) reboot_lua = TE4CORE_VERSION;
if (reboot_engine) reboot_engine = strdup(reboot_engine);
if (reboot_engine_version) reboot_engine_version = strdup(reboot_engine_version);
if (reboot_module) reboot_module = strdup(reboot_module);
if (reboot_name) reboot_name = strdup(reboot_name);
if (reboot_einfo) reboot_einfo = strdup(reboot_einfo);
if (core_def->corenum == -1) core_def->corenum = TE4CORE_VERSION;
return 0;
}
......
......@@ -53,10 +53,7 @@ bool no_debug = FALSE;
int current_mousehandler = LUA_NOREF;
int current_keyhandler = LUA_NOREF;
int current_game = LUA_NOREF;
int reboot_lua = 0;
bool reboot_new = FALSE;
char *request_profile = "default";
char *reboot_engine = NULL, *reboot_engine_version = NULL, *reboot_module = NULL, *reboot_name = NULL, *reboot_einfo = NULL;
core_boot_type *core_def = NULL;
bool exit_engine = FALSE;
bool no_sound = FALSE;
bool isActive = TRUE;
......@@ -668,7 +665,7 @@ void do_resize(int w, int h, bool fullscreen)
void boot_lua(int state, bool rebooting, int argc, char *argv[])
{
reboot_lua = 0;
core_def->corenum = 0;
if (state == 1)
{
......@@ -776,14 +773,13 @@ void boot_lua(int state, bool rebooting, int argc, char *argv[])
// And run the lua engine scripts
if (!luaL_loadfile(L, "/loader/init.lua"))
{
if (reboot_engine) lua_pushstring(L, reboot_engine); else lua_pushnil(L);
if (reboot_engine_version) lua_pushstring(L, reboot_engine_version); else lua_pushnil(L);
if (reboot_module) lua_pushstring(L, reboot_module); else lua_pushnil(L);
if (reboot_name) lua_pushstring(L, reboot_name); else lua_pushnil(L);
lua_pushboolean(L, reboot_new);
if (reboot_einfo) lua_pushstring(L, reboot_einfo); else lua_pushnil(L);
if (request_profile) lua_pushstring(L, request_profile); else lua_pushnil(L);
docall(L, 7, 0);
if (core_def->reboot_engine) lua_pushstring(L, core_def->reboot_engine); else lua_pushnil(L);
if (core_def->reboot_engine_version) lua_pushstring(L, core_def->reboot_engine_version); else lua_pushnil(L);
if (core_def->reboot_module) lua_pushstring(L, core_def->reboot_module); else lua_pushnil(L);
if (core_def->reboot_name) lua_pushstring(L, core_def->reboot_name); else lua_pushnil(L);
lua_pushboolean(L, core_def->reboot_new);
if (core_def->reboot_einfo) lua_pushstring(L, core_def->reboot_einfo); else lua_pushnil(L);
docall(L, 6, 0);
}
else
{
......@@ -795,8 +791,9 @@ void boot_lua(int state, bool rebooting, int argc, char *argv[])
/**
* Core entry point.
*/
void _te4_export te4main(int argc, char *argv[], core_boot_type *core_def)
void _te4_export te4main(int argc, char *argv[], core_boot_type *given_core_def)
{
core_def = given_core_def;
core_def->corenum = 0;
// Get cpu cores
......@@ -811,13 +808,7 @@ void _te4_export te4main(int argc, char *argv[], core_boot_type *core_def)
for (i = 1; i < argc; i++)
{
char *arg = argv[i];
if (!strncmp(arg, "-P", 2)) request_profile = strdup(arg+2);
if (!strncmp(arg, "-M", 2)) reboot_module = strdup(arg+2);
if (!strncmp(arg, "-u", 2)) reboot_name = strdup(arg+2);
if (!strncmp(arg, "-E", 2)) reboot_einfo = strdup(arg+2);
if (!strncmp(arg, "-n", 2)) reboot_new = TRUE;
if (!strncmp(arg, "--no-debug", 10)) no_debug = TRUE;
if (!strncmp(arg, "--flush-stdout", 14)) setvbuf(stdout, (char *) NULL, _IOLBF, 0);;
if (!strncmp(arg, "--no-debug", 10)) no_debug = 0;
}
// initialize engine and set up resolution and depth
......@@ -949,10 +940,10 @@ void _te4_export te4main(int argc, char *argv[], core_boot_type *core_def)
if (!realtime_timer_id && isActive && !tickPaused) on_tick();
/* Reboot the lua engine */
if (reboot_lua)
if (core_def->corenum)
{
// Just reboot the lua VM
if (reboot_lua == TE4CORE_VERSION && 0)
if (core_def->corenum == TE4CORE_VERSION && 0)
{
tickPaused = FALSE;
setupRealtime(0);
......@@ -962,13 +953,10 @@ void _te4_export te4main(int argc, char *argv[], core_boot_type *core_def)
// Clean up and tell the runner to run a different core
else
{
lua_close(L);
free_particles_thread();
free_profile_thread();
lua_close(L);
PHYSFS_deinit();
core_def->corenum = reboot_lua;
break;
}
}
......
......@@ -21,6 +21,8 @@
#ifndef _MAIN_H_
#define _MAIN_H_
#include "runner/core.h"
#if defined(SELFEXE_LINUX)
#define _te4_export
#elif defined(SELFEXE_WINDOWS)
......@@ -51,6 +53,7 @@ struct lua_err_type_s {
typedef struct lua_err_type_s lua_err_type;
extern lua_err_type *last_lua_error_head, *last_lua_error_tail;
extern void del_lua_error();
extern core_boot_type *core_def;
#endif
......@@ -21,7 +21,9 @@
#ifndef TE4CORE_H
#define TE4CORE_H
typedef struct {
struct core_def_s {
void (*define)(struct core_def_s *core_def, const char *coretype, int id, const char *reboot_engine, const char *reboot_engine_version, const char *reboot_module, const char *reboot_name, int reboot_new, const char *reboot_einfo);
int corenum;
char *coretype;
......@@ -31,6 +33,8 @@ typedef struct {
char *reboot_name;
char *reboot_einfo;
int reboot_new;
} core_boot_type;
};
typedef struct core_def_s core_boot_type;
#endif
......@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef SELFEXE_WINDOWS
#include <windows.h>
......@@ -35,6 +36,26 @@
#include "core.h"
#include "getself.h"
// Update core to run
void define_core(core_boot_type *core_def, const char *coretype, int id, const char *reboot_engine, const char *reboot_engine_version, const char *reboot_module, const char *reboot_name, int reboot_new, const char *reboot_einfo)
{
if (core_def->coretype) free(core_def->coretype);
if (core_def->reboot_engine) free(core_def->reboot_engine);
if (core_def->reboot_engine_version) free(core_def->reboot_engine_version);
if (core_def->reboot_module) free(core_def->reboot_module);
if (core_def->reboot_name) free(core_def->reboot_name);
if (core_def->reboot_einfo) free(core_def->reboot_einfo);
core_def->corenum = id;
core_def->coretype = coretype ? strdup(coretype) : NULL;
core_def->reboot_engine = reboot_engine ? strdup(reboot_engine) : NULL;
core_def->reboot_engine_version = reboot_engine_version ? strdup(reboot_engine_version) : NULL;
core_def->reboot_module = reboot_module ? strdup(reboot_module) : NULL;
core_def->reboot_name = reboot_name ? strdup(reboot_name) : NULL;
core_def->reboot_einfo = reboot_einfo ? strdup(reboot_einfo) : NULL;
core_def->reboot_new = reboot_new;
}
// Load the shared lib containing the core and calls te4main inside it, passing control to that core
void run_core(core_boot_type *core_def, int argc, char **argv)
{
......@@ -78,7 +99,7 @@ void run_core(core_boot_type *core_def, int argc, char **argv)
// Get the core
lua_getglobal(L, "get_core");
lua_pushstring(L, core_def->coretype);
if (core_def->coretype) lua_pushstring(L, core_def->coretype); else lua_pushnil(L);
lua_pushnumber(L, core_def->corenum);
lua_call(L, 2, 1);
char *core = strdup((char*)lua_tostring(L, -1));
......@@ -160,19 +181,25 @@ void run_core(core_boot_type *core_def, int argc, char **argv)
int main(int argc, char **argv)
{
core_boot_type core_def;
core_boot_type *core_def = calloc(1, sizeof(core_boot_type));
core_def.corenum = -1; // Start with latest core
core_def.coretype = "te4core";
core_def.reboot_engine = NULL;
core_def.reboot_engine_version = NULL;
core_def.reboot_module = NULL;
core_def.reboot_name = NULL;
core_def.reboot_einfo = NULL;
core_def.reboot_new = 0;
core_def->define = &define_core;
core_def->define(core_def, "te4core", -1, NULL, NULL, NULL, NULL, 0, NULL);
// Parse arguments
int i;
for (i = 1; i < argc; i++)
{
char *arg = argv[i];
if (!strncmp(arg, "-M", 2)) core_def->reboot_module = strdup(arg+2);
if (!strncmp(arg, "-u", 2)) core_def->reboot_name = strdup(arg+2);
if (!strncmp(arg, "-E", 2)) core_def->reboot_einfo = strdup(arg+2);
if (!strncmp(arg, "-n", 2)) core_def->reboot_new = 0;
if (!strncmp(arg, "--flush-stdout", 14)) setvbuf(stdout, (char *) NULL, _IOLBF, 0);;
}
// Run the requested cores until we want no more
while (core_def.corenum) run_core(&core_def, argc, argv);
while (core_def->corenum) run_core(core_def, argc, argv);
exit(EXIT_SUCCESS);
}
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