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

Fix bug when doing "New Game" after doing "Load Game"

git-svn-id: http://svn.net-core.org/repos/t-engine4@4389 51575b47-30f0-44d4-a5cc-537603b46e54
parent 150cc417
No related branches found
No related tags found
No related merge requests found
......@@ -36,8 +36,8 @@ end
-- Static
function _M:listModules(incompatible, moddir_filter)
local ms = {}
local allmounts = fs.getSearchPath(true)
fs.mount(engine.homepath, "/")
-- print("Search Path: ") for k,e in ipairs(fs.getSearchPath()) do print("*",k,e) end
local knowns = {}
for i, short_name in ipairs(fs.list("/modules/")) do
......@@ -73,7 +73,9 @@ function _M:listModules(incompatible, moddir_filter)
end
ms[m.short_name] = m.versions[1]
end
-- fs.umount(engine.homepath)
fs.reset()
fs.mountAll(allmounts)
return ms
end
......
......@@ -983,6 +983,21 @@ function util.getval(val, ...)
end
end
function fs.reset()
local list = fs.getSearchPath(true)
for i, m in ipairs(list) do
fs.umount(m.path)
end
print("After fs.reset")
table.print(fs.getSearchPath(true))
end
function fs.mountAll(list)
for i, m in ipairs(list) do
fs.mount(m.path, "/" .. (m.mount or ""), true)
end
end
function util.loadfilemods(file, env)
-- Base loader
local prev, err = loadfile(file)
......
......@@ -31,7 +31,7 @@ module(..., package.seeall, class.inherit(Dialog))
function _M:init()
Dialog.init(self, "Load Game", game.w * 0.8, game.h * 0.8)
local list = Module:listSavefiles(function(dir) if dir:find("^boot") then return false else return true end end)
local list = Module:listSavefiles()
self.c_play = Button.new{text=" Play! ", fct=function(text) self:playSave() end}
self.c_delete = Button.new{text="Delete", fct=function(text) self:deleteSave() end}
......
......@@ -74,7 +74,7 @@ function _M:select(item)
end
function _M:generateList()
local list = Module:listModules(self.c_compat.checked, function(dir) if dir:find("^boot") then return false else return true end end)
local list = Module:listModules(self.c_compat.checked)
self.list = {}
for i = 1, #list do
for j, mod in ipairs(list[i].versions) do
......
......@@ -69,7 +69,7 @@ function _M:init()
end
function _M:generateList()
local list = Module:listModules(nil, function(dir) if dir:find("^boot") then return false else return true end end)
local list = Module:listModules()
self.list = {}
for i = 1, #list do
......
......@@ -50,6 +50,8 @@
#define WIDTH 800
#define HEIGHT 600
int g_argc = 0;
char **g_argv;
SDL_Window *window = NULL;
SDL_GLContext maincontext; /* Our opengl context handle */
bool is_fullscreen = FALSE;
......@@ -934,6 +936,9 @@ int main(int argc, char *argv[])
freopen ("te4_log.txt", "w", stdout);
#endif
g_argc = argc;
g_argv = argv;
// Parse arguments
int i;
for (i = 1; i < argc; i++)
......
......@@ -41,6 +41,8 @@ extern int docall (lua_State *L, int narg, int nret);
extern bool fbo_active;
extern bool multitexture_active;
extern long total_keyframes;
extern int g_argc;
extern char **g_argv;
/* Error handling */
struct lua_err_type_s {
......
......@@ -27,6 +27,7 @@
#include "mzip.h"
#include "zlib.h"
#include "types.h"
#include "main.h"
/******************************************************************
******************************************************************
......@@ -358,23 +359,50 @@ static int lua_fs_get_path_separator(lua_State *L)
return 1;
}
static void fs_list_path_double(void *data, const char *path, const char *mount)
{
lua_State *L = (lua_State*)data;
int nb = lua_objlen(L, -1);
lua_pushnumber(L, nb + 1);
lua_newtable(L);
lua_pushliteral(L, "path");
lua_pushstring(L, path);
lua_settable(L, -3);
lua_pushliteral(L, "mount");
lua_pushstring(L, mount);
lua_settable(L, -3);
lua_settable(L, -3);
}
static int lua_fs_get_search_path(lua_State *L)
{
char **rc = PHYSFS_getSearchPath();
if (!lua_toboolean(L, 1))
{
char **rc = PHYSFS_getSearchPath();
char **i;
int nb = 1;
char **i;
int nb = 1;
lua_newtable(L);
for (i = rc; *i != NULL; i++)
lua_newtable(L);
for (i = rc; *i != NULL; i++)
{
lua_pushnumber(L, nb);
lua_pushstring(L, *i);
lua_settable(L, -3);
nb++;
}
PHYSFS_freeList(rc);
}
else
{
lua_pushnumber(L, nb);
lua_pushstring(L, *i);
lua_settable(L, -3);
nb++;
lua_newtable(L);
PHYSFS_getSearchPathCallbackWithMount(fs_list_path_double, L);
}
PHYSFS_freeList(rc);
return 1;
}
......@@ -404,7 +432,6 @@ static int lua_patch_file(lua_State *L)
}
}
static const struct luaL_reg fslib[] =
{
{"patchFile", lua_patch_file},
......
......@@ -1059,6 +1059,19 @@ void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback callback, void *data)
} /* PHYSFS_getSearchPathCallback */
void PHYSFS_getSearchPathCallbackWithMount(PHYSFS_DoubleStringCallback callback, void *data)
{
DirHandle *i;
__PHYSFS_platformGrabMutex(stateLock);
for (i = searchPath; i != NULL; i = i->next)
callback(data, i->dirName, i->mountPoint);
__PHYSFS_platformReleaseMutex(stateLock);
} /* PHYSFS_getSearchPathCallback */
/* Split out to avoid stack allocation in a loop. */
static void setSaneCfgAddPath(const char *i, const size_t l, const char *dirsep,
int archivesFirst)
......
......@@ -2124,6 +2124,7 @@ __EXPORT__ const char *PHYSFS_getMountPoint(const char *dir);
* \sa PHYSFS_getSearchPathCallback
*/
typedef void (*PHYSFS_StringCallback)(void *data, const char *str);
typedef void (*PHYSFS_DoubleStringCallback)(void *data, const char *str1, const char *str2);
/**
......@@ -2229,6 +2230,7 @@ __EXPORT__ void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback c, void *d);
* \sa PHYSFS_getSearchPath
*/
__EXPORT__ void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback c, void *d);
__EXPORT__ void PHYSFS_getSearchPathCallbackWithMount(PHYSFS_DoubleStringCallback callback, void *data);
/**
......
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