mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Merge branch 'remove-lua_save_p' into 'save_p-unglobal'
Let LUA_Archive / LUA_UnArchive use savebuffer_t See merge request KartKrew/Kart!837
This commit is contained in:
commit
d4beb91e18
7 changed files with 355 additions and 358 deletions
|
|
@ -5798,7 +5798,7 @@ static void Command_Archivetest_f(void)
|
|||
|
||||
// test archive
|
||||
CONS_Printf("LUA_Archive...\n");
|
||||
LUA_Archive(&save.p, true);
|
||||
LUA_Archive(&save, true);
|
||||
WRITEUINT8(save.p, 0x7F);
|
||||
wrote = (UINT32)(save.p - save.buffer);
|
||||
|
||||
|
|
@ -5809,7 +5809,7 @@ static void Command_Archivetest_f(void)
|
|||
// test unarchive
|
||||
save.p = save.buffer;
|
||||
CONS_Printf("LUA_UnArchive...\n");
|
||||
LUA_UnArchive(&save.p, true);
|
||||
LUA_UnArchive(&save, true);
|
||||
i = READUINT8(save.p);
|
||||
if (i != 0x7F || wrote != (UINT32)(save.p - save.buffer))
|
||||
CONS_Printf("Savegame corrupted. (write %u, read %u)\n", wrote, (UINT32)(save.p - save.buffer));
|
||||
|
|
|
|||
656
src/g_demo.c
656
src/g_demo.c
File diff suppressed because it is too large
Load diff
|
|
@ -18,8 +18,6 @@
|
|||
#include "doomstat.h"
|
||||
#include "d_event.h"
|
||||
|
||||
extern UINT8 *demo_p;
|
||||
|
||||
// ======================================
|
||||
// DEMO playback/recording related stuff.
|
||||
// ======================================
|
||||
|
|
|
|||
|
|
@ -834,7 +834,7 @@ int LUA_HookHurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source, UINT8 d
|
|||
return hook.status;
|
||||
}
|
||||
|
||||
void LUA_HookNetArchive(lua_CFunction archFunc)
|
||||
void LUA_HookNetArchive(lua_CFunction archFunc, savebuffer_t *save)
|
||||
{
|
||||
const hook_t * map = &hookIds[HOOK(NetVars)];
|
||||
Hook_State hook;
|
||||
|
|
@ -852,8 +852,9 @@ void LUA_HookNetArchive(lua_CFunction archFunc)
|
|||
|
||||
// tables becomes an upvalue of archFunc
|
||||
lua_pushvalue(gL, -1);
|
||||
lua_pushcclosure(gL, archFunc, 1);
|
||||
// stack: tables, archFunc
|
||||
lua_pushlightuserdata(gL, save);
|
||||
lua_pushcclosure(gL, archFunc, 2);
|
||||
// stack: tables, savebuffer_t, archFunc
|
||||
|
||||
init_hook_call(&hook, 0, res_none);
|
||||
call_mapped(&hook, map);
|
||||
|
|
|
|||
|
|
@ -41,8 +41,6 @@ lua_State *gL = NULL;
|
|||
|
||||
int hook_defrosting;
|
||||
|
||||
static UINT8 **lua_save_p = NULL; // FIXME: Remove this horrible hack
|
||||
|
||||
// List of internal libraries to load from SRB2
|
||||
static lua_CFunction liblist[] = {
|
||||
LUA_EnumLib, // global metatable for enums
|
||||
|
|
@ -1355,9 +1353,10 @@ static void ArchiveExtVars(UINT8 **p, void *pointer, const char *ptype)
|
|||
static int NetArchive(lua_State *L)
|
||||
{
|
||||
int TABLESINDEX = lua_upvalueindex(1);
|
||||
savebuffer_t *save = lua_touserdata(L, lua_upvalueindex(2));
|
||||
int i, n = lua_gettop(L);
|
||||
for (i = 1; i <= n; i++)
|
||||
ArchiveValue(lua_save_p, TABLESINDEX, i);
|
||||
ArchiveValue(&save->p, TABLESINDEX, i);
|
||||
return n;
|
||||
}
|
||||
|
||||
|
|
@ -1568,9 +1567,10 @@ static void UnArchiveExtVars(UINT8 **p, void *pointer)
|
|||
static int NetUnArchive(lua_State *L)
|
||||
{
|
||||
int TABLESINDEX = lua_upvalueindex(1);
|
||||
savebuffer_t *save = lua_touserdata(L, lua_upvalueindex(2));
|
||||
int i, n = lua_gettop(L);
|
||||
for (i = 1; i <= n; i++)
|
||||
UnArchiveValue(lua_save_p, TABLESINDEX);
|
||||
UnArchiveValue(&save->p, TABLESINDEX);
|
||||
return n;
|
||||
}
|
||||
|
||||
|
|
@ -1628,7 +1628,7 @@ void LUA_Step(void)
|
|||
lua_gc(gL, LUA_GCSTEP, 1);
|
||||
}
|
||||
|
||||
void LUA_Archive(UINT8 **p, boolean network)
|
||||
void LUA_Archive(savebuffer_t *save, boolean network)
|
||||
{
|
||||
INT32 i;
|
||||
thinker_t *th;
|
||||
|
|
@ -1641,7 +1641,7 @@ void LUA_Archive(UINT8 **p, boolean network)
|
|||
if (!playeringame[i] && i > 0) // NEVER skip player 0, this is for dedi servs.
|
||||
continue;
|
||||
// all players in game will be archived, even if they just add a 0.
|
||||
ArchiveExtVars(p, &players[i], "player");
|
||||
ArchiveExtVars(&save->p, &players[i], "player");
|
||||
}
|
||||
|
||||
if (network == true)
|
||||
|
|
@ -1655,23 +1655,22 @@ void LUA_Archive(UINT8 **p, boolean network)
|
|||
|
||||
// archive function will determine when to skip mobjs,
|
||||
// and write mobjnum in otherwise.
|
||||
ArchiveExtVars(p, th, "mobj");
|
||||
ArchiveExtVars(&save->p, th, "mobj");
|
||||
}
|
||||
}
|
||||
|
||||
WRITEUINT32(*p, UINT32_MAX); // end of mobjs marker, replaces mobjnum.
|
||||
WRITEUINT32(save->p, UINT32_MAX); // end of mobjs marker, replaces mobjnum.
|
||||
|
||||
lua_save_p = p;
|
||||
LUA_HookNetArchive(NetArchive); // call the NetArchive hook in archive mode
|
||||
LUA_HookNetArchive(NetArchive, save); // call the NetArchive hook in archive mode
|
||||
}
|
||||
|
||||
ArchiveTables(p);
|
||||
ArchiveTables(&save->p);
|
||||
|
||||
if (gL)
|
||||
lua_pop(gL, 1); // pop tables
|
||||
}
|
||||
|
||||
void LUA_UnArchive(UINT8 **p, boolean network)
|
||||
void LUA_UnArchive(savebuffer_t *save, boolean network)
|
||||
{
|
||||
UINT32 mobjnum;
|
||||
INT32 i;
|
||||
|
|
@ -1684,28 +1683,27 @@ void LUA_UnArchive(UINT8 **p, boolean network)
|
|||
{
|
||||
if (!playeringame[i] && i > 0) // same here, this is to synch dediservs properly.
|
||||
continue;
|
||||
UnArchiveExtVars(p, &players[i]);
|
||||
UnArchiveExtVars(&save->p, &players[i]);
|
||||
}
|
||||
|
||||
if (network == true)
|
||||
{
|
||||
do {
|
||||
mobjnum = READUINT32(*p); // read a mobjnum
|
||||
mobjnum = READUINT32(save->p); // read a mobjnum
|
||||
for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next)
|
||||
{
|
||||
if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed)
|
||||
continue;
|
||||
if (((mobj_t *)th)->mobjnum != mobjnum) // find matching mobj
|
||||
continue;
|
||||
UnArchiveExtVars(p, th); // apply variables
|
||||
UnArchiveExtVars(&save->p, th); // apply variables
|
||||
}
|
||||
} while(mobjnum != UINT32_MAX); // repeat until end of mobjs marker.
|
||||
|
||||
lua_save_p = p;
|
||||
LUA_HookNetArchive(NetUnArchive); // call the NetArchive hook in unarchive mode
|
||||
LUA_HookNetArchive(NetUnArchive, save); // call the NetArchive hook in unarchive mode
|
||||
}
|
||||
|
||||
UnArchiveTables(p);
|
||||
UnArchiveTables(&save->p);
|
||||
|
||||
if (gL)
|
||||
lua_pop(gL, 1); // pop tables
|
||||
|
|
|
|||
|
|
@ -53,8 +53,8 @@ void LUA_DumpFile(const char *filename);
|
|||
#endif
|
||||
fixed_t LUA_EvalMath(const char *word);
|
||||
void LUA_Step(void);
|
||||
void LUA_Archive(UINT8 **p, boolean network);
|
||||
void LUA_UnArchive(UINT8 **p, boolean network);
|
||||
void LUA_Archive(savebuffer_t *save, boolean network);
|
||||
void LUA_UnArchive(savebuffer_t *save, boolean network);
|
||||
|
||||
int LUA_PushGlobals(lua_State *L, const char *word);
|
||||
int LUA_WriteGlobals(lua_State *L, const char *word);
|
||||
|
|
@ -63,7 +63,7 @@ void Got_Luacmd(UINT8 **cp, INT32 playernum); // lua_consolelib.c
|
|||
void LUA_CVarChanged(void *cvar); // lua_consolelib.c
|
||||
int Lua_optoption(lua_State *L, int narg,
|
||||
const char *def, const char *const lst[]);
|
||||
void LUA_HookNetArchive(lua_CFunction archFunc);
|
||||
void LUA_HookNetArchive(lua_CFunction archFunc, savebuffer_t *save);
|
||||
|
||||
void LUA_PushTaggableObjectArray
|
||||
( lua_State *L,
|
||||
|
|
|
|||
|
|
@ -5164,7 +5164,7 @@ void P_SaveNetGame(savebuffer_t *save, boolean resending)
|
|||
P_NetArchiveTubeWaypoints(save);
|
||||
P_NetArchiveWaypoints(save);
|
||||
}
|
||||
LUA_Archive(&save->p, true);
|
||||
LUA_Archive(save, true);
|
||||
|
||||
P_NetArchiveRNG(save);
|
||||
|
||||
|
|
@ -5214,7 +5214,7 @@ boolean P_LoadNetGame(savebuffer_t *save, boolean reloading)
|
|||
P_FinishMobjs();
|
||||
}
|
||||
|
||||
LUA_UnArchive(&save->p, true);
|
||||
LUA_UnArchive(save, true);
|
||||
|
||||
P_NetUnArchiveRNG(save);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue