Merge branch 'Saturn-Next' into freecamstuffs

This commit is contained in:
Alug committed 2024-12-29 16:16:49 +01:00
commit 2112be8ef7
13 files changed
+1687 -2021

No files matched your search

+46 -42
View File
@@ -1756,34 +1756,34 @@ static boolean SV_ResendingSavegameToAnyone(void)
static void SV_SendSaveGame(INT32 node, boolean resending)
{
size_t length, compressedlen;
UINT8 *savebuffer;
savebuffer_t save;
UINT8 *compressedsave;
UINT8 *buffertosend;
// first save it in a malloced buffer
savebuffer = (UINT8 *)malloc(SAVEGAMESIZE);
if (!savebuffer)
save.buffer = (UINT8 *)malloc(SAVEGAMESIZE);
if (!save.buffer)
{
CONS_Alert(CONS_ERROR, M_GetText("No more free memory for savegame\n"));
return;
}
// Leave room for the uncompressed length.
save_p = savebuffer + sizeof(UINT32);
save.p = save.buffer + sizeof(UINT32);
P_SaveNetGame(resending);
P_SaveNetGame(&save, resending);
length = save_p - savebuffer;
length = save.p - save.buffer;
if (length > SAVEGAMESIZE)
{
free(savebuffer);
save_p = NULL;
free(save.buffer);
save.p = NULL;
I_Error("Savegame buffer overrun");
}
// Allocate space for compressed save: one byte fewer than for the
// uncompressed data to ensure that the compression is worthwhile.
compressedsave = malloc(length - 1);
compressedsave = Z_Malloc(length - 1, PU_STATIC, NULL);
if (!compressedsave)
{
CONS_Alert(CONS_ERROR, M_GetText("No more free memory for savegame\n"));
@@ -1791,11 +1791,11 @@ static void SV_SendSaveGame(INT32 node, boolean resending)
}
// Attempt to compress it.
if((compressedlen = lzf_compress(savebuffer + sizeof(UINT32), length - sizeof(UINT32), compressedsave + sizeof(UINT32), length - sizeof(UINT32) - 1)))
if ((compressedlen = lzf_compress(save.buffer + sizeof(UINT32), length - sizeof(UINT32), compressedsave + sizeof(UINT32), length - sizeof(UINT32) - 1)))
{
// Compressing succeeded; send compressed data
free(savebuffer);
free(save.buffer);
// State that we're compressed.
buffertosend = compressedsave;
@@ -1805,16 +1805,15 @@ static void SV_SendSaveGame(INT32 node, boolean resending)
else
{
// Compression failed to make it smaller; send original
free(compressedsave);
Z_Free(compressedsave);
// State that we're not compressed
buffertosend = savebuffer;
WRITEUINT32(savebuffer, 0);
buffertosend = save.buffer;
WRITEUINT32(save.buffer, 0);
}
SV_SendRam(node, buffertosend, length, SF_RAM, 0);
save_p = NULL;
SV_SendRam(node, buffertosend, length, SF_Z_RAM, 0);
save.p = NULL;
// Remember when we started sending the savegame so we can handle timeouts
sendingsavegame[node] = true;
@@ -1828,7 +1827,7 @@ static consvar_t cv_dumpconsistency = {"dumpconsistency", "Off", CV_NETVAR, CV_O
static void SV_SavedGame(void)
{
size_t length;
UINT8 *savebuffer;
savebuffer_t save;
char tmpsave[264];
if (!cv_dumpconsistency.value)
@@ -1837,29 +1836,29 @@ static void SV_SavedGame(void)
sprintf(tmpsave, "%s" PATHSEP TMPSAVENAME, srb2home);
// first save it in a malloced buffer
save_p = savebuffer = (UINT8 *)malloc(SAVEGAMESIZE);
if (!save_p)
save.p = save.buffer = (UINT8 *)malloc(SAVEGAMESIZE);
if (!save.p)
{
CONS_Alert(CONS_ERROR, M_GetText("No more free memory for savegame\n"));
return;
}
P_SaveNetGame(false);
P_SaveNetGame(&save);
length = save_p - savebuffer;
length = save.p - save.buffer;
if (length > SAVEGAMESIZE)
{
free(savebuffer);
save_p = NULL;
free(save.buffer);
save.p = NULL;
I_Error("Savegame buffer overrun");
}
// then save it!
if (!FIL_WriteFile(tmpsave, savebuffer, length))
if (!FIL_WriteFile(tmpsave, save.buffer, length))
CONS_Printf(M_GetText("Didn't save %s for netgame"), tmpsave);
free(savebuffer);
save_p = NULL;
free(save.buffer);
save.p = NULL;
}
#undef TMPSAVENAME
@@ -1868,13 +1867,13 @@ static void SV_SavedGame(void)
static void CL_LoadReceivedSavegame(boolean reloading)
{
UINT8 *savebuffer = NULL;
savebuffer_t save;
size_t length, decompressedlen;
char tmpsave[264];
sprintf(tmpsave, "%s" PATHSEP TMPSAVENAME, srb2home);
length = FIL_ReadFile(tmpsave, &savebuffer);
length = FIL_ReadFile(tmpsave, &save.buffer);
CONS_Printf(M_GetText("Loading savegame length %s\n"), sizeu1(length));
if (!length)
@@ -1883,16 +1882,17 @@ static void CL_LoadReceivedSavegame(boolean reloading)
return;
}
save_p = savebuffer;
save.p = save.buffer;
// Decompress saved game if necessary.
decompressedlen = READUINT32(save_p);
if(decompressedlen > 0)
decompressedlen = READUINT32(save.p);
if (decompressedlen > 0)
{
UINT8 *decompressedbuffer = Z_Malloc(decompressedlen, PU_STATIC, NULL);
lzf_decompress(save_p, length - sizeof(UINT32), decompressedbuffer, decompressedlen);
Z_Free(savebuffer);
save_p = savebuffer = decompressedbuffer;
lzf_decompress(save.p, length - sizeof(UINT32), decompressedbuffer, decompressedlen);
Z_Free(save.buffer);
save.p = save.buffer = decompressedbuffer;
}
paused = false;
@@ -1901,7 +1901,7 @@ static void CL_LoadReceivedSavegame(boolean reloading)
automapactive = false;
// load a base level
if (P_LoadNetGame(reloading))
if (P_LoadNetGame(&save, reloading))
{
if (!reloading)
{
@@ -1921,8 +1921,8 @@ static void CL_LoadReceivedSavegame(boolean reloading)
}
// done
Z_Free(savebuffer);
save_p = NULL;
Z_Free(save.buffer);
save.p = NULL;
if (unlink(tmpsave) == -1)
CONS_Alert(CONS_ERROR, M_GetText("Can't delete %s\n"), tmpsave);
consistancy[gametic%TICQUEUE] = Consistancy();
@@ -6807,6 +6807,7 @@ void CL_ClearRewinds(void)
rewind_t *CL_SaveRewindPoint(size_t demopos)
{
savebuffer_t save;
rewind_t *rewind;
if (rewindhead && rewindhead->leveltime + REWIND_POINT_INTERVAL > leveltime)
@@ -6816,8 +6817,9 @@ rewind_t *CL_SaveRewindPoint(size_t demopos)
if (!rewind)
return NULL;
save_p = rewind->savebuffer;
P_SaveNetGame(false);
save.buffer = save.p = rewind->savebuffer;
P_SaveNetGame(&save, false);
rewind->leveltime = leveltime;
rewind->next = rewindhead;
rewind->demopos = demopos;
@@ -6828,6 +6830,7 @@ rewind_t *CL_SaveRewindPoint(size_t demopos)
rewind_t *CL_RewindToTime(tic_t time)
{
savebuffer_t save;
rewind_t *rewind;
while (rewindhead && rewindhead->leveltime > time)
@@ -6840,8 +6843,9 @@ rewind_t *CL_RewindToTime(tic_t time)
if (!rewindhead)
return NULL;
save_p = rewindhead->savebuffer;
P_LoadNetGame(false);
save.buffer = save.p = rewindhead->savebuffer;
P_LoadNetGame(&save, false);
wipegamestate = gamestate; // No fading back in!
timeinmap = leveltime;
+11 -12
View File
@@ -5896,10 +5896,9 @@ static void Command_Togglemodified_f(void)
modifiedgame = !modifiedgame;
}
extern UINT8 *save_p;
static void Command_Archivetest_f(void)
{
UINT8 *buf;
savebuffer_t save;
UINT32 i, wrote;
thinker_t *th;
if (gamestate != GS_LEVEL)
@@ -5915,28 +5914,28 @@ static void Command_Archivetest_f(void)
((mobj_t *)th)->mobjnum = i++;
// allocate buffer
buf = save_p = ZZ_Alloc(1024);
save.buffer = save.p = ZZ_Alloc(1024);
// test archive
CONS_Printf("LUA_Archive...\n");
LUA_Archive();
WRITEUINT8(save_p, 0x7F);
wrote = (UINT32)(save_p-buf);
LUA_Archive(&save, true);
WRITEUINT8(save.p, 0x7F);
wrote = (UINT32)(save.p - save.buffer);
// clear Lua state, so we can really see what happens!
CONS_Printf("Clearing state!\n");
LUA_ClearExtVars();
// test unarchive
save_p = buf;
save.p = save.buffer;
CONS_Printf("LUA_UnArchive...\n");
LUA_UnArchive();
i = READUINT8(save_p);
if (i != 0x7F || wrote != (UINT32)(save_p-buf))
CONS_Printf("Savegame corrupted. (write %u, read %u)\n", wrote, (UINT32)(save_p-buf));
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));
// free buffer
Z_Free(buf);
Z_Free(save.buffer);
CONS_Printf("Done. No crash.\n");
}
#endif
+374 -347
View File
File diff suppressed because it is too large. Load diff
+2 -1
View File
@@ -17,6 +17,7 @@
#include "doomdef.h"
#include "doomstat.h"
#include "d_event.h"
#include "p_saveg.h"
#include "m_textinput.h"
extern char gamedatafilename[64];
@@ -33,7 +34,7 @@ extern INT32 player_name_changes[MAXPLAYERS];
extern player_t players[MAXPLAYERS];
extern boolean playeringame[MAXPLAYERS];
extern UINT8 *demo_p;
extern savebuffer_t demobuf;
// ======================================
// DEMO playback/recording related stuff.
+5 -2
View File
@@ -74,6 +74,9 @@ static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, GLMipm
(void)patchheight; // This parameter is unused
if (!mipmap)
return;
if (originPatch) // originPatch can be NULL here, unlike in the software version
originy = originPatch->originy;
@@ -112,11 +115,11 @@ static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, GLMipm
alpha = 0xFF;
// Make pixel transparent if chroma keyed
if ((mipmap->flags & TF_CHROMAKEYED) && (texel == HWR_PATCHES_CHROMAKEY_COLORINDEX))
if ((mipmap && mipmap->flags & TF_CHROMAKEYED) && (texel == HWR_PATCHES_CHROMAKEY_COLORINDEX))
alpha = 0x00;
//Hurdler: 25/04/2000: now support colormap in hardware mode
if (mipmap->colormap)
if (mipmap && mipmap->colormap)
texel = mipmap->colormap[texel];
// hope compiler will get this switch out of the loops (dreams...)
+2 -2
View File
@@ -1829,7 +1829,7 @@ static int lib_sStartSoundAtVolume(lua_State *L)
return LUA_ErrInvalid(L, "player_t");
}
if (!player || P_IsLocalPlayer(player))
S_StartSoundAtVolume(origin, sound_id, volume);
S_StartSoundAtVolume(origin, sound_id, volume);
return 0;
}
@@ -1931,7 +1931,7 @@ static int lib_sChangeMusic(lua_State *L)
music_flags = (UINT16)((music_num & 0x7FFF0000) >> 16);
else
#endif
music_flags = (UINT16)luaL_optinteger(L, 4, 0);
music_flags = (UINT16)luaL_optinteger(L, 4, 0);
position = (UINT32)luaL_optinteger(L, 5, 0);
prefadems = (UINT32)luaL_optinteger(L, 6, 0);
+33
View File
@@ -934,6 +934,7 @@ int LUA_HookHurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source)
return hook.status;
}
#if 0
void LUA_HookNetArchive(lua_CFunction archFunc)
{
const hook_t * map = &hookIds[HOOK(NetVars)];
@@ -964,6 +965,38 @@ void LUA_HookNetArchive(lua_CFunction archFunc)
// stack: tables
}
}
#endif
void LUA_HookNetArchive(lua_CFunction archFunc, savebuffer_t *save) //
{
const hook_t * map = &hookIds[HOOK(NetVars)];
Hook_State hook;
/* this is a remarkable case where the stack isn't reset */
if (map->numHooks > 0)
{
// stack: tables
I_Assert(lua_gettop(gL) > 0);
I_Assert(lua_istable(gL, -1));
push_error_handler();
lua_insert(gL, EINDEX);
begin_hook_values(&hook);
// tables becomes an upvalue of archFunc
lua_pushvalue(gL, -1);
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);
lua_pop(gL, 1); // pop archFunc
lua_remove(gL, EINDEX); // pop error handler
// stack: tables
}
}
void LUA_HookPlayerQuit(player_t *plr, int reason)
{
+189 -573
View File
File diff suppressed because it is too large. Load diff
+5 -6
View File
@@ -13,6 +13,7 @@
#include "m_fixed.h"
#include "doomtype.h"
#include "d_player.h"
#include "p_saveg.h"
#include "blua/lua.h"
#include "blua/lualib.h"
@@ -55,17 +56,15 @@ void LUA_InvalidateLevel(void);
void LUA_InvalidateMapthings(void);
void LUA_InvalidatePlayer(player_t *player);
void LUA_Step(void);
void LUA_Archive(void);
void LUA_UnArchive(void);
void LUA_ArchiveDemo(void);
void LUA_UnArchiveDemo(void);
void LUA_Archive(savebuffer_t *save, boolean network);
void LUA_UnArchive(savebuffer_t *save, boolean network);
void Got_Luacmd(UINT8 **cp, INT32 playernum); // lua_consolelib.c
void LUA_CVarChanged(const char *name); // lua_consolelib.c
int Lua_optoption(lua_State *L, int narg, int def, int list_ref);
int Lua_CreateFieldTable(lua_State *L, const char *const lst[]);
void LUA_HookNetArchive(lua_CFunction archFunc);
void LUA_HookNetArchive(lua_CFunction archFunc, savebuffer_t *save);
//void LUA_HookNetArchive(lua_CFunction archFunc);
// Console wrapper
void COM_Lua_f(void);
+987 -1014
View File
File diff suppressed because it is too large. Load diff
+16 -8
View File
@@ -21,13 +21,6 @@
// Persistent storage/archiving.
// These are the load / save game routines.
void P_SaveGame(void);
void P_SaveNetGame(boolean resending);
boolean P_LoadGame(INT16 mapoverride);
boolean P_LoadNetGame(boolean resending);
mobj_t *P_FindNewPosition(UINT32 oldposition);
typedef struct
{
UINT8 skincolor;
@@ -41,6 +34,21 @@ typedef struct
} savedata_t;
extern savedata_t savedata;
extern UINT8 *save_p;
typedef struct
{
UINT8 *buffer;
UINT8 *p;
} savebuffer_t;
// Persistent storage/archiving.
// These are the load / save game routines.
void P_SaveGame(savebuffer_t *save);
void P_SaveNetGame(savebuffer_t *save, boolean resending);
boolean P_LoadGame(savebuffer_t *save, INT16 mapoverride);
boolean P_LoadNetGame(savebuffer_t *save, boolean reloading);
mobj_t *P_FindNewPosition(UINT32 oldposition);
#endif
+15 -14
View File
@@ -1001,14 +1001,14 @@ void P_WriteThings(lumpnum_t lumpnum)
size_t i, length;
mapthing_t *mt;
UINT8 *data;
UINT8 *savebuffer, *savebuf_p;
savebuffer_t save;
INT16 temp;
data = W_CacheLumpNum(lumpnum, PU_LEVEL);
savebuf_p = savebuffer = (UINT8 *)malloc(nummapthings * sizeof (mapthing_t));
save.p = save.buffer = (UINT8 *)malloc(nummapthings * sizeof (mapthing_t));
if (!savebuf_p)
if (!save.p)
{
CONS_Alert(CONS_ERROR, M_GetText("No more free memory for thing writing!\n"));
return;
@@ -1017,23 +1017,23 @@ void P_WriteThings(lumpnum_t lumpnum)
mt = mapthings;
for (i = 0; i < nummapthings; i++, mt++)
{
WRITEINT16(savebuf_p, mt->x);
WRITEINT16(savebuf_p, mt->y);
WRITEINT16(save.p, mt->x);
WRITEINT16(save.p, mt->y);
WRITEINT16(savebuf_p, mt->angle);
WRITEINT16(save.p, mt->angle);
temp = (INT16)(mt->type + ((INT16)mt->extrainfo << 12));
WRITEINT16(savebuf_p, temp);
WRITEUINT16(savebuf_p, mt->options);
WRITEINT16(save.p, temp);
WRITEUINT16(save.p, mt->options);
}
Z_Free(data);
length = savebuf_p - savebuffer;
length = save.p - save.buffer;
FIL_WriteFile(va("newthings%d.lmp", gamemap), savebuffer, length);
free(savebuffer);
savebuf_p = NULL;
FIL_WriteFile(va("newthings%d.lmp", gamemap), save.buffer, length);
free(save.buffer);
save.p = NULL;
CONS_Printf(M_GetText("newthings%d.lmp saved.\n"), gamemap);
}
@@ -2910,8 +2910,9 @@ boolean P_SetupLevel(boolean skipprecip, boolean reloadinggamestate)
: mapheaderinfo[gamemap - 1]->numlaps);
// Start recording replay in multiplayer with a temp filename
//Ensure dedis only record a replay if there is a player at the start of the map, otherwise we get invalid replays!
if (!demo.playback && multiplayer && D_NumPlayers()) {
// Ensure dedis only record a replay if there is a player at the start of the map, otherwise we get invalid replays!
if (!demo.playback && multiplayer && D_NumPlayers())
{
static char buf[256];
sprintf(buf, "replay"PATHSEP"online"PATHSEP"%d-%s", (int) (time(NULL)), G_BuildMapName(gamemap));
+2
View File
@@ -45,6 +45,8 @@
#include "../m_argv.h"
#include "../i_video.h"
#include "../f_finale.h"
#ifdef DEBUG_TO_FILE
#include <stdarg.h>
#if defined (_WIN32) && !defined (__CYGWIN__)