diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8fde277c7..f31a9bd26 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -487,7 +487,7 @@ if(${SRB2_CONFIG_HWRENDER}) ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_data.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_defs.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_dll.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_drv.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_gl.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_glob.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_portal.h diff --git a/src/Makefile b/src/Makefile index ccfe7603e..111e586b4 100644 --- a/src/Makefile +++ b/src/Makefile @@ -738,7 +738,7 @@ else ifdef SDL ifdef MINGW $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \ - doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ + doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_gl.h screen.h \ command.h hardware/hw_data.h hardware/hw_defs.h hardware/hw_md2.h \ hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h hardware/hw_portal.h\ hardware/hw_md2load.h hardware/hw_md3load.h hardware/hw_model.h hardware/u_list.h \ @@ -747,7 +747,7 @@ $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ else $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \ - doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ + doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_gl.h screen.h \ command.h hardware/hw_data.h hardware/hw_defs.h hardware/hw_md2.h \ hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h hardware/hw_portal.h \ hardware/hw_md2load.h hardware/hw_md3load.h hardware/hw_model.h hardware/u_list.h \ diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 3f6513128..fddb27cec 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1795,34 +1795,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")); @@ -1830,11 +1830,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; @@ -1844,16 +1844,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; @@ -1867,7 +1866,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) @@ -1876,29 +1875,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 @@ -1907,13 +1906,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) @@ -1922,16 +1921,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; @@ -1940,7 +1940,7 @@ static void CL_LoadReceivedSavegame(boolean reloading) automapactive = false; // load a base level - if (P_LoadNetGame(reloading)) + if (P_LoadNetGame(&save, reloading)) { if (!reloading) { @@ -1960,8 +1960,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(); @@ -6855,6 +6855,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) @@ -6864,8 +6865,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; @@ -6876,6 +6878,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) @@ -6888,8 +6891,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; diff --git a/src/d_netcmd.c b/src/d_netcmd.c index e49f6c17a..076bb10e0 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -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 diff --git a/src/g_game.c b/src/g_game.c index 6c45c99a4..e48c53577 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -292,9 +292,8 @@ UINT32 timesBeatenWithEmeralds; //@TODO put these all in a struct for namespacing purposes? static char demoname[128]; -static UINT8 *demobuffer = NULL; +savebuffer_t demobuf; static UINT8 *demotime_p, *demoinfo_p; -UINT8 *demo_p; static UINT8 *demoend; static UINT8 demoflags; static boolean demosynced = true; // console warning message @@ -353,8 +352,6 @@ consvar_t cv_maxdemosize = {"maxdemosize", "10", CV_SAVE, maxdemosize_cons_t, NU static CV_PossibleValue_t demochangemap_cons_t[] = {{0, "Disabled"}, {1, "Diff Map"}, {2, "Always"}, {0, NULL}}; consvar_t cv_demochangemap = {"netdemo_savemapchange", "Disabled", CV_SAVE, demochangemap_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -static UINT8 *savebuffer; - // Analog Control void SendWeaponPref(void); void SendWeaponPref2(void); @@ -3501,6 +3498,7 @@ void G_LoadGameData(void) INT32 i, j; UINT8 modded = false; UINT8 rtemp; + savebuffer_t save; //For records tic_t rectime; @@ -3522,28 +3520,28 @@ void G_LoadGameData(void) if (M_CheckParm("-resetdata")) return; // Don't load (essentially, reset). - length = FIL_ReadFile(va(pandf, srb2home, gamedatafilename), &savebuffer); + length = FIL_ReadFile(va(pandf, srb2home, gamedatafilename), &save.buffer); if (!length) // Aw, no game data. Their loss! return; - save_p = savebuffer; + save.p = save.buffer; // Version check - if (READUINT32(save_p) != 0xFCAFE211) + if (READUINT32(save.p) != 0xFCAFE211) { const char *gdfolder = "the SRB2Kart folder"; if (strcmp(srb2home,".")) gdfolder = srb2home; - Z_Free(savebuffer); - save_p = NULL; + Z_Free(save.buffer); + save.p = NULL; I_Error("Game data is from another version of SRB2.\nDelete %s(maybe in %s) and try again.", gamedatafilename, gdfolder); } - totalplaytime = READUINT32(save_p); - matchesplayed = READUINT32(save_p); + totalplaytime = READUINT32(save.p); + matchesplayed = READUINT32(save.p); - modded = READUINT8(save_p); + modded = READUINT8(save.p); // Aha! Someone's been screwing with the save file! if ((modded && !savemoddata)) @@ -3553,48 +3551,47 @@ void G_LoadGameData(void) // TODO put another cipher on these things? meh, I don't care... for (i = 0; i < NUMMAPS; i++) - if ((mapvisited[i] = READUINT8(save_p)) > MV_MAX) + if ((mapvisited[i] = READUINT8(save.p)) > MV_MAX) goto datacorrupt; // To save space, use one bit per collected/achieved/unlocked flag for (i = 0; i < MAXEMBLEMS;) { - rtemp = READUINT8(save_p); + rtemp = READUINT8(save.p); for (j = 0; j < 8 && j+i < MAXEMBLEMS; ++j) emblemlocations[j+i].collected = ((rtemp >> j) & 1); i += j; } for (i = 0; i < MAXEXTRAEMBLEMS;) { - rtemp = READUINT8(save_p); + rtemp = READUINT8(save.p); for (j = 0; j < 8 && j+i < MAXEXTRAEMBLEMS; ++j) extraemblems[j+i].collected = ((rtemp >> j) & 1); i += j; } for (i = 0; i < MAXUNLOCKABLES;) { - rtemp = READUINT8(save_p); + rtemp = READUINT8(save.p); for (j = 0; j < 8 && j+i < MAXUNLOCKABLES; ++j) unlockables[j+i].unlocked = ((rtemp >> j) & 1); i += j; } for (i = 0; i < MAXCONDITIONSETS;) { - rtemp = READUINT8(save_p); + rtemp = READUINT8(save.p); for (j = 0; j < 8 && j+i < MAXCONDITIONSETS; ++j) conditionSets[j+i].achieved = ((rtemp >> j) & 1); i += j; } - timesBeaten = READUINT32(save_p); - timesBeatenWithEmeralds = READUINT32(save_p); - //timesBeatenUltimate = READUINT32(save_p); + timesBeaten = READUINT32(save.p); + timesBeatenWithEmeralds = READUINT32(save.p); // Main records for (i = 0; i < NUMMAPS; ++i) { - rectime = (tic_t)READUINT32(save_p); - reclap = (tic_t)READUINT32(save_p); + rectime = (tic_t)READUINT32(save.p); + reclap = (tic_t)READUINT32(save.p); if (rectime || reclap) { @@ -3605,8 +3602,8 @@ void G_LoadGameData(void) } // done - Z_Free(savebuffer); - save_p = NULL; + Z_Free(save.buffer); + save.p = NULL; // Silent update unlockables in case they're out of sync with conditions M_SilentUpdateUnlockablesAndEmblems(); @@ -3620,8 +3617,8 @@ void G_LoadGameData(void) if (strcmp(srb2home,".")) gdfolder = srb2home; - Z_Free(savebuffer); - save_p = NULL; + Z_Free(save.buffer); + save.p = NULL; I_Error("Corrupt game data file.\nDelete %s(maybe in %s) and try again.", gamedatafilename, gdfolder); } @@ -3634,14 +3631,13 @@ void G_SaveGameData(boolean force) size_t length; INT32 i, j; UINT8 btemp; - - //INT32 curmare; + savebuffer_t save; if (!gamedataloaded) return; // If never loaded (-nodata), don't save - save_p = savebuffer = (UINT8 *)malloc(GAMEDATASIZE); - if (!save_p) + save.p = save.buffer = (UINT8 *)malloc(GAMEDATASIZE); + if (!save.p) { CONS_Alert(CONS_ERROR, M_GetText("No more free memory for saving game data\n")); return; @@ -3649,23 +3645,23 @@ void G_SaveGameData(boolean force) if (majormods && !force) { - free(savebuffer); - save_p = savebuffer = NULL; + free(save.buffer); + save.p = save.buffer = NULL; return; } // Version test - WRITEUINT32(save_p, 0xFCAFE211); + WRITEUINT32(save.p, 0xFCAFE211); - WRITEUINT32(save_p, totalplaytime); - WRITEUINT32(save_p, matchesplayed); + WRITEUINT32(save.p, totalplaytime); + WRITEUINT32(save.p, matchesplayed); btemp = (UINT8)(savemoddata); // what used to be here was profoundly dunderheaded - WRITEUINT8(save_p, btemp); + WRITEUINT8(save.p, btemp); // TODO put another cipher on these things? meh, I don't care... for (i = 0; i < NUMMAPS; i++) - WRITEUINT8(save_p, mapvisited[i]); + WRITEUINT8(save.p, mapvisited[i]); // To save space, use one bit per collected/achieved/unlocked flag for (i = 0; i < MAXEMBLEMS;) @@ -3673,7 +3669,7 @@ void G_SaveGameData(boolean force) btemp = 0; for (j = 0; j < 8 && j+i < MAXEMBLEMS; ++j) btemp |= (emblemlocations[j+i].collected << j); - WRITEUINT8(save_p, btemp); + WRITEUINT8(save.p, btemp); i += j; } for (i = 0; i < MAXEXTRAEMBLEMS;) @@ -3681,7 +3677,7 @@ void G_SaveGameData(boolean force) btemp = 0; for (j = 0; j < 8 && j+i < MAXEXTRAEMBLEMS; ++j) btemp |= (extraemblems[j+i].collected << j); - WRITEUINT8(save_p, btemp); + WRITEUINT8(save.p, btemp); i += j; } for (i = 0; i < MAXUNLOCKABLES;) @@ -3689,7 +3685,7 @@ void G_SaveGameData(boolean force) btemp = 0; for (j = 0; j < 8 && j+i < MAXUNLOCKABLES; ++j) btemp |= (unlockables[j+i].unlocked << j); - WRITEUINT8(save_p, btemp); + WRITEUINT8(save.p, btemp); i += j; } for (i = 0; i < MAXCONDITIONSETS;) @@ -3697,33 +3693,33 @@ void G_SaveGameData(boolean force) btemp = 0; for (j = 0; j < 8 && j+i < MAXCONDITIONSETS; ++j) btemp |= (conditionSets[j+i].achieved << j); - WRITEUINT8(save_p, btemp); + WRITEUINT8(save.p, btemp); i += j; } - WRITEUINT32(save_p, timesBeaten); - WRITEUINT32(save_p, timesBeatenWithEmeralds); + WRITEUINT32(save.p, timesBeaten); + WRITEUINT32(save.p, timesBeatenWithEmeralds); // Main records for (i = 0; i < NUMMAPS; i++) { if (mainrecords[i]) { - WRITEUINT32(save_p, mainrecords[i]->time); - WRITEUINT32(save_p, mainrecords[i]->lap); + WRITEUINT32(save.p, mainrecords[i]->time); + WRITEUINT32(save.p, mainrecords[i]->lap); } else { - WRITEUINT32(save_p, 0); - WRITEUINT32(save_p, 0); + WRITEUINT32(save.p, 0); + WRITEUINT32(save.p, 0); } } - length = save_p - savebuffer; + length = save.p - save.buffer; - FIL_WriteFile(va(pandf, srb2home, gamedatafilename), savebuffer, length); - free(savebuffer); - save_p = savebuffer = NULL; + FIL_WriteFile(va(pandf, srb2home, gamedatafilename), save.buffer, length); + free(save.buffer); + save.p = save.buffer = NULL; } #define VERSIONSIZE 16 @@ -3739,22 +3735,23 @@ static void M_ForceLoadGameResponse(INT32 ch) if (ch != 'y' && ch != KEY_ENTER) { //refused - Z_Free(savebuffer); - save_p = savebuffer = NULL; + Z_Free(save.buffer); + save.p = save.buffer = NULL; startonmapnum = 0; M_SetupNextMenu(&SP_LoadDef); return; } // pick up where we left off. - save_p += VERSIONSIZE; + save.p += VERSIONSIZE; + if (!P_LoadGame(startonmapnum)) { M_ClearMenus(true); // so ESC backs out to title M_StartMessage(M_GetText("Savegame file corrupted\n\nPress ESC\n"), NULL, MM_NOTHING); Command_ExitGame_f(); - Z_Free(savebuffer); - save_p = savebuffer = NULL; + Z_Free(save.buffer); + save.p = save.buffer = NULL; startonmapnum = 0; // no cheating! @@ -3763,8 +3760,8 @@ static void M_ForceLoadGameResponse(INT32 ch) } // done - Z_Free(savebuffer); - save_p = savebuffer = NULL; + Z_Free(save.buffer); + save.p = save.buffer = NULL; startonmapnum = 0; //set cursaveslot to -1 so nothing gets saved. @@ -3792,6 +3789,7 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) size_t length; char vcheck[VERSIONSIZE]; char savename[255]; + savebuffer_t save; // memset savedata to all 0, fixes calling perfectly valid saves corrupt because of bots memset(&savedata, 0, sizeof(savedata)); @@ -3803,18 +3801,18 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) sprintf(savename, savegamename, slot); - length = FIL_ReadFile(savename, &savebuffer); + length = FIL_ReadFile(savename, &save.buffer); if (!length) { CONS_Printf(M_GetText("Couldn't read file %s\n"), savename); return; } - save_p = savebuffer; + save.p = save.buffer; memset(vcheck, 0, sizeof (vcheck)); sprintf(vcheck, "version %d", VERSION); - if (strcmp((const char *)save_p, (const char *)vcheck)) + if (strcmp((const char *)save.p, (const char *)vcheck)) { #ifdef SAVEGAME_OTHERVERSIONS M_StartMessage(M_GetText("Save game from different version.\nYou can load this savegame, but\nsaving afterwards will be disabled.\n\nDo you want to continue anyway?\n\n(Press 'Y' to confirm)\n"), @@ -3824,15 +3822,15 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) M_ClearMenus(true); // so ESC backs out to title M_StartMessage(M_GetText("Save game from different version\n\nPress ESC\n"), NULL, MM_NOTHING); Command_ExitGame_f(); - Z_Free(savebuffer); - save_p = savebuffer = NULL; + Z_Free(save.buffer); + save.p = save.buffer = NULL; // no cheating! memset(&savedata, 0, sizeof(savedata)); #endif return; // bad version } - save_p += VERSIONSIZE; + save.p += VERSIONSIZE; if (demo.playback) // reset game engine G_StopDemo(); @@ -3841,13 +3839,13 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) // automapactive = false; // dearchive all the modifications - if (!P_LoadGame(mapoverride)) + if (!P_LoadGame(&save, mapoverride)) { M_ClearMenus(true); // so ESC backs out to title M_StartMessage(M_GetText("Savegame file corrupted\n\nPress ESC\n"), NULL, MM_NOTHING); Command_ExitGame_f(); - Z_Free(savebuffer); - save_p = savebuffer = NULL; + Z_Free(save.buffer); + save.p = save.buffer = NULL; // no cheating! memset(&savedata, 0, sizeof(savedata)); @@ -3855,8 +3853,8 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) } // done - Z_Free(savebuffer); - save_p = savebuffer = NULL; + Z_Free(save.buffer); + save.p = save.buffer = NULL; displayplayers[0] = consoleplayer; multiplayer = false; @@ -3879,6 +3877,7 @@ void G_SaveGame(UINT32 savegameslot) boolean saved; char savename[256] = ""; const char *backup; + savebuffer_t save; sprintf(savename, savegamename, savegameslot); backup = va("%s",savename); @@ -3892,8 +3891,8 @@ void G_SaveGame(UINT32 savegameslot) char name[VERSIONSIZE]; size_t length; - 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 saving game data\n")); return; @@ -3901,14 +3900,14 @@ void G_SaveGame(UINT32 savegameslot) memset(name, 0, sizeof (name)); sprintf(name, "version %d", VERSION); - WRITEMEM(save_p, name, VERSIONSIZE); + WRITEMEM(save.p, name, VERSIONSIZE); - P_SaveGame(); + P_SaveGame(&save); - length = save_p - savebuffer; - saved = FIL_WriteFile(backup, savebuffer, length); - free(savebuffer); - save_p = savebuffer = NULL; + length = save.p - save.buffer; + saved = FIL_WriteFile(backup, save.buffer, length); + free(save.buffer); + save.p = save.buffer = NULL; } gameaction = ga_nothing; @@ -4518,7 +4517,7 @@ void G_ReadDemoExtraData(void) if (leveltime > starttime) { - rewind_t *rewind = CL_SaveRewindPoint(demo_p - demobuffer); + rewind_t *rewind = CL_SaveRewindPoint(demobuf.p - demobuf.buffer); if (rewind) { memcpy(rewind->oldcmd, oldcmd, sizeof (oldcmd)); @@ -4528,11 +4527,11 @@ void G_ReadDemoExtraData(void) memset(name, '\0', 17); - p = READUINT8(demo_p); + p = READUINT8(demobuf.p); while (p < DW_EXTRASTUFF) { - extradata = READUINT8(demo_p); + extradata = READUINT8(demobuf.p); if (extradata & DXD_RESPAWN) { @@ -4544,12 +4543,12 @@ void G_ReadDemoExtraData(void) UINT8 kartspeed, kartweight; // Skin - M_Memcpy(name, demo_p, 16); - demo_p += 16; + M_Memcpy(name, demobuf.p, 16); + demobuf.p += 16; SetPlayerSkin(p, name); - kartspeed = READUINT8(demo_p); - kartweight = READUINT8(demo_p); + kartspeed = READUINT8(demobuf.p); + kartweight = READUINT8(demobuf.p); if (stricmp(skins[players[p].skin].name, name) != 0) FindClosestSkinForStats(p, kartspeed, kartweight); @@ -4560,8 +4559,8 @@ void G_ReadDemoExtraData(void) if (extradata & DXD_COLOR) { // Color - M_Memcpy(name, demo_p, 16); - demo_p += 16; + M_Memcpy(name, demobuf.p, 16); + demobuf.p += 16; for (i = 0; i < MAXSKINCOLORS; i++) if (!stricmp(KartColor_Names[i], name)) // SRB2kart { @@ -4574,12 +4573,12 @@ void G_ReadDemoExtraData(void) if (extradata & DXD_NAME) { // Name - M_Memcpy(player_names[p],demo_p,16); - demo_p += 16; + M_Memcpy(player_names[p],demobuf.p,16); + demobuf.p += 16; } if (extradata & DXD_PLAYSTATE) { - extradata = READUINT8(demo_p); + extradata = READUINT8(demobuf.p); switch (extradata) { case DXD_PST_PLAYING: @@ -4624,7 +4623,7 @@ void G_ReadDemoExtraData(void) } - p = READUINT8(demo_p); + p = READUINT8(demobuf.p); } while (p != DW_END) @@ -4634,7 +4633,7 @@ void G_ReadDemoExtraData(void) switch (p) { case DW_RNG: - rng = READUINT32(demo_p); + rng = READUINT32(demobuf.p); if (P_GetRandSeed() != rng) { P_SetRandSeed(rng); @@ -4645,10 +4644,10 @@ void G_ReadDemoExtraData(void) } } - p = READUINT8(demo_p); + p = READUINT8(demobuf.p); } - if (!(demoflags & DF_GHOST) && *demo_p == DEMOMARKER) + if (!(demoflags & DF_GHOST) && *demobuf.p == DEMOMARKER) { // end of demo data stream G_CheckDemoStatus(); @@ -4665,8 +4664,8 @@ void G_WriteDemoExtraData(void) { if (demo_extradata[i]) { - WRITEUINT8(demo_p, i); - WRITEUINT8(demo_p, demo_extradata[i]); + WRITEUINT8(demobuf.p, i); + WRITEUINT8(demobuf.p, demo_extradata[i]); //if (demo_extradata[i] & DXD_RESPAWN) has no extra data if (demo_extradata[i] & DXD_SKIN) @@ -4674,40 +4673,40 @@ void G_WriteDemoExtraData(void) // Skin memset(name, 0, 16); strncpy(name, skins[players[i].skin].name, 16); - M_Memcpy(demo_p,name,16); - demo_p += 16; + M_Memcpy(demobuf.p,name,16); + demobuf.p += 16; - WRITEUINT8(demo_p, skins[players[i].skin].kartspeed); - WRITEUINT8(demo_p, skins[players[i].skin].kartweight); + WRITEUINT8(demobuf.p, skins[players[i].skin].kartspeed); + WRITEUINT8(demobuf.p, skins[players[i].skin].kartweight); } if (demo_extradata[i] & DXD_COLOR) { // Color memset(name, 0, 16); strncpy(name, KartColor_Names[players[i].skincolor], 16); - M_Memcpy(demo_p,name,16); - demo_p += 16; + M_Memcpy(demobuf.p,name,16); + demobuf.p += 16; } if (demo_extradata[i] & DXD_NAME) { // Name memset(name, 0, 16); memcpy(name, player_names[i], 15); // Keeping 1 null byte for safety, sorry players with name containing more than 15 characters - M_Memcpy(demo_p,name,16); - demo_p += 16; + M_Memcpy(demobuf.p,name,16); + demobuf.p += 16; } if (demo_extradata[i] & DXD_PLAYSTATE) { demo_writerng = 1; if (!playeringame[i]) - WRITEUINT8(demo_p, DXD_PST_LEFT); + WRITEUINT8(demobuf.p, DXD_PST_LEFT); else if ( players[i].spectator && !(players[i].pflags & PF_WANTSTOJOIN) // <= fuck you specifically ) - WRITEUINT8(demo_p, DXD_PST_SPECTATING); + WRITEUINT8(demobuf.p, DXD_PST_SPECTATING); else - WRITEUINT8(demo_p, DXD_PST_PLAYING); + WRITEUINT8(demobuf.p, DXD_PST_PLAYING); } } @@ -4727,36 +4726,36 @@ void G_WriteDemoExtraData(void) { demo_writerng = 0; timeout = 16; - WRITEUINT8(demo_p, DW_RNG); - WRITEUINT32(demo_p, P_GetRandSeed()); + WRITEUINT8(demobuf.p, DW_RNG); + WRITEUINT32(demobuf.p, P_GetRandSeed()); } } - WRITEUINT8(demo_p, DW_END); + WRITEUINT8(demobuf.p, DW_END); } void G_ReadDemoTiccmd(ticcmd_t *cmd, INT32 playernum) { UINT8 ziptic; - if (!demo_p || !demo.deferstart) + if (!demobuf.p || !demo.deferstart) return; - ziptic = READUINT8(demo_p); + ziptic = READUINT8(demobuf.p); if (ziptic & ZT_FWD) - oldcmd[playernum].forwardmove = READSINT8(demo_p); + oldcmd[playernum].forwardmove = READSINT8(demobuf.p); if (ziptic & ZT_SIDE) - oldcmd[playernum].sidemove = READSINT8(demo_p); + oldcmd[playernum].sidemove = READSINT8(demobuf.p); if (ziptic & ZT_ANGLE) - oldcmd[playernum].angleturn = READINT16(demo_p); + oldcmd[playernum].angleturn = READINT16(demobuf.p); if (ziptic & ZT_BUTTONS) - oldcmd[playernum].buttons = READUINT16(demo_p); + oldcmd[playernum].buttons = READUINT16(demobuf.p); if (ziptic & ZT_AIMING) - oldcmd[playernum].aiming = READINT16(demo_p); + oldcmd[playernum].aiming = READINT16(demobuf.p); if (ziptic & ZT_DRIFT) - oldcmd[playernum].driftturn = READINT16(demo_p); + oldcmd[playernum].driftturn = READINT16(demobuf.p); if (ziptic & ZT_LATENCY) - oldcmd[playernum].latency = READUINT8(demo_p); + oldcmd[playernum].latency = READUINT8(demobuf.p); G_CopyTiccmd(cmd, &oldcmd[playernum], 1); @@ -4768,7 +4767,7 @@ void G_ReadDemoTiccmd(ticcmd_t *cmd, INT32 playernum) && !(players[displayplayers[0]].kartstuff[k_spinouttimer] && players[displayplayers[0]].kartstuff[k_sneakertimer])) // Spinning and boosting cancels out spinout localangle[0] += (cmd->angleturn<<16); - if (!(demoflags & DF_GHOST) && *demo_p == DEMOMARKER) + if (!(demoflags & DF_GHOST) && *demobuf.p == DEMOMARKER) { // end of demo data stream G_CheckDemoStatus(); @@ -4781,55 +4780,56 @@ void G_WriteDemoTiccmd(ticcmd_t *cmd, INT32 playernum) char ziptic = 0; UINT8 *ziptic_p; - if (!demo_p) + if (!demobuf.p) return; - ziptic_p = demo_p++; // the ziptic, written at the end of this function + + ziptic_p = demobuf.p++; // the ziptic, written at the end of this function if (cmd->forwardmove != oldcmd[playernum].forwardmove) { - WRITEUINT8(demo_p,cmd->forwardmove); + WRITEUINT8(demobuf.p,cmd->forwardmove); oldcmd[playernum].forwardmove = cmd->forwardmove; ziptic |= ZT_FWD; } if (cmd->sidemove != oldcmd[playernum].sidemove) { - WRITEUINT8(demo_p,cmd->sidemove); + WRITEUINT8(demobuf.p,cmd->sidemove); oldcmd[playernum].sidemove = cmd->sidemove; ziptic |= ZT_SIDE; } if (cmd->angleturn != oldcmd[playernum].angleturn) { - WRITEINT16(demo_p,cmd->angleturn); + WRITEINT16(demobuf.p,cmd->angleturn); oldcmd[playernum].angleturn = cmd->angleturn; ziptic |= ZT_ANGLE; } if (cmd->buttons != oldcmd[playernum].buttons) { - WRITEUINT16(demo_p,cmd->buttons); + WRITEUINT16(demobuf.p,cmd->buttons); oldcmd[playernum].buttons = cmd->buttons; ziptic |= ZT_BUTTONS; } if (cmd->aiming != oldcmd[playernum].aiming) { - WRITEINT16(demo_p,cmd->aiming); + WRITEINT16(demobuf.p,cmd->aiming); oldcmd[playernum].aiming = cmd->aiming; ziptic |= ZT_AIMING; } if (cmd->driftturn != oldcmd[playernum].driftturn) { - WRITEINT16(demo_p,cmd->driftturn); + WRITEINT16(demobuf.p,cmd->driftturn); oldcmd[playernum].driftturn = cmd->driftturn; ziptic |= ZT_DRIFT; } if (cmd->latency != oldcmd[playernum].latency) { - WRITEUINT8(demo_p,cmd->latency); + WRITEUINT8(demobuf.p,cmd->latency); oldcmd[playernum].latency = cmd->latency; ziptic |= ZT_LATENCY; } @@ -4911,10 +4911,14 @@ void G_GhostAddHit(INT32 playernum, mobj_t *victim) void G_WriteAllGhostTics(void) { - UINT8 *save_demo_p = demo_p; -#define CHECKSPACE(num) if (demo_p+(num) > demoend) { demo_p = save_demo_p; G_CheckDemoStatus(); return; } + if (!demobuf.p) + return; + + UINT8 *save_demo_p = demobuf.p; +#define CHECKSPACE(num) if (demobuf.p+(num) > demoend) { demobuf.p = save_demo_p; G_CheckDemoStatus(); return; } INT32 i, counter = leveltime; + for (i = 0; i < MAXPLAYERS; i++) { if (!playeringame[i] || players[i].spectator) @@ -4930,12 +4934,12 @@ void G_WriteAllGhostTics(void) CHECKSPACE(1); - WRITEUINT8(demo_p, i); + WRITEUINT8(demobuf.p, i); G_WriteGhostTic(players[i].mo, i); } CHECKSPACE(1); - WRITEUINT8(demo_p, 0xFF); + WRITEUINT8(demobuf.p, 0xFF); #undef CHECKSPACE } @@ -4948,11 +4952,12 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) UINT8 sprite; UINT8 frame; - UINT8 *save_demo_p = demo_p; -#define CHECKSPACE(num) if (demo_p+(num) > demoend) { demo_p = save_demo_p; G_CheckDemoStatus(); return; } - - if (!demo_p) + if (!demobuf.p) return; + + UINT8 *save_demo_p = demobuf.p; +#define CHECKSPACE(num) if (demobuf.p+(num) > demoend) { demobuf.p = save_demo_p; G_CheckDemoStatus(); return; } + if (!(demoflags & DF_GHOST)) return; // No ghost data to write. @@ -4963,7 +4968,7 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) ghost = ghost->tracer; } - ziptic_p = demo_p++; // the ziptic, written at the end of this function + ziptic_p = demobuf.p++; // the ziptic, written at the end of this function #define MAXMOM (0x7FFF<<8) @@ -4979,9 +4984,9 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) ziptic |= GZT_XYZ; CHECKSPACE(sizeof(fixed_t)*3); - WRITEFIXED(demo_p,oldghost[playernum].x); - WRITEFIXED(demo_p,oldghost[playernum].y); - WRITEFIXED(demo_p,oldghost[playernum].z); + WRITEFIXED(demobuf.p,oldghost[playernum].x); + WRITEFIXED(demobuf.p,oldghost[playernum].y); + WRITEFIXED(demobuf.p,oldghost[playernum].z); } else { @@ -4998,8 +5003,8 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) CHECKSPACE(4); - WRITEINT16(demo_p,momx); - WRITEINT16(demo_p,momy); + WRITEINT16(demobuf.p,momx); + WRITEINT16(demobuf.p,momy); } momx = (INT16)((ghost->z-oldghost[playernum].z + (1<<4))>>8); if (momx != oldghost[playernum].momz) @@ -5009,7 +5014,7 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) CHECKSPACE(2); - WRITEINT16(demo_p,momx); + WRITEINT16(demobuf.p,momx); } // This SHOULD set oldghost.x/y/z to match ghost->x/y/z @@ -5032,7 +5037,7 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) CHECKSPACE(1); - WRITEUINT8(demo_p,oldghost[playernum].angle); + WRITEUINT8(demobuf.p,oldghost[playernum].angle); } // Store the sprite frame. @@ -5044,7 +5049,7 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) CHECKSPACE(1); - WRITEUINT8(demo_p,oldghost[playernum].frame); + WRITEUINT8(demobuf.p,oldghost[playernum].frame); } // Check for sprite set changes @@ -5079,37 +5084,37 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) if (ghostext[playernum].flags) { ziptic |= GZT_EXTRA; - WRITEUINT8(demo_p,ghostext[playernum].flags); + WRITEUINT8(demobuf.p,ghostext[playernum].flags); if (ghostext[playernum].flags & EZT_COLOR) { CHECKSPACE(1); - WRITEUINT8(demo_p,ghostext[playernum].color); + WRITEUINT8(demobuf.p,ghostext[playernum].color); ghostext[playernum].lastcolor = ghostext[playernum].color; } if (ghostext[playernum].flags & EZT_SCALE) { CHECKSPACE(sizeof(fixed_t)); - WRITEFIXED(demo_p,ghostext[playernum].scale); + WRITEFIXED(demobuf.p,ghostext[playernum].scale); ghostext[playernum].lastscale = ghostext[playernum].scale; } if (ghostext[playernum].flags & EZT_HIT) { CHECKSPACE(2); - WRITEUINT16(demo_p,ghostext[playernum].hits); + WRITEUINT16(demobuf.p,ghostext[playernum].hits); for (i = 0; i < ghostext[playernum].hits; i++) { mobj_t *mo = ghostext[playernum].hitlist[i]; CHECKSPACE(4+4+2+sizeof(fixed_t)*3+sizeof(angle_t)); - WRITEUINT32(demo_p,UINT32_MAX); // reserved for some method of determining exactly which mobj this is. (mobjnum doesn't work here.) - WRITEUINT32(demo_p,mo->type); - WRITEUINT16(demo_p,(UINT16)mo->health); - WRITEFIXED(demo_p,mo->x); - WRITEFIXED(demo_p,mo->y); - WRITEFIXED(demo_p,mo->z); - WRITEANGLE(demo_p,mo->angle); + WRITEUINT32(demobuf.p,UINT32_MAX); // reserved for some method of determining exactly which mobj this is. (mobjnum doesn't work here.) + WRITEUINT32(demobuf.p,mo->type); + WRITEUINT16(demobuf.p,(UINT16)mo->health); + WRITEFIXED(demobuf.p,mo->x); + WRITEFIXED(demobuf.p,mo->y); + WRITEFIXED(demobuf.p,mo->z); + WRITEANGLE(demobuf.p,mo->angle); } Z_Free(ghostext[playernum].hitlist); ghostext[playernum].hits = 0; @@ -5118,15 +5123,15 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) if (ghostext[playernum].flags & EZT_SPRITE) { CHECKSPACE(1); - WRITEUINT8(demo_p,sprite); + WRITEUINT8(demobuf.p,sprite); } if (ghostext[playernum].flags & EZT_KART) { CHECKSPACE(12); - WRITEINT32(demo_p, ghostext[playernum].kartitem); - WRITEINT32(demo_p, ghostext[playernum].kartamount); - WRITEINT32(demo_p, ghostext[playernum].kartbumpers); + WRITEINT32(demobuf.p, ghostext[playernum].kartitem); + WRITEINT32(demobuf.p, ghostext[playernum].kartamount); + WRITEINT32(demobuf.p, ghostext[playernum].kartbumpers); } ghostext[playernum].flags = 0; } @@ -5135,7 +5140,7 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) // attention here for the ticcmd size! // latest demos with mouse aiming byte in ticcmd - if (demo_p >= demoend - (13 + 9)) + if (demobuf.p >= demoend - (13 + 9)) { G_CheckDemoStatus(); // no more space return; @@ -5145,15 +5150,18 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) void G_ConsAllGhostTics(void) { - UINT8 p = READUINT8(demo_p); + if (!demobuf.p) + return; + + UINT8 p = READUINT8(demobuf.p); while (p != 0xFF) { G_ConsGhostTic(p); - p = READUINT8(demo_p); + p = READUINT8(demobuf.p); } - if (*demo_p == DEMOMARKER) + if (*demobuf.p == DEMOMARKER) { // end of demo data stream G_CheckDemoStatus(); @@ -5171,7 +5179,7 @@ void G_ConsGhostTic(INT32 playernum) fixed_t syncleeway; boolean nightsfail = false; - if (!demo_p || !demo.deferstart) + if (!demobuf.p || !demo.deferstart) return; if (!(demoflags & DF_GHOST)) return; // No ghost data to use. @@ -5179,33 +5187,34 @@ void G_ConsGhostTic(INT32 playernum) testmo = players[playernum].mo; // Grab ghost data. - ziptic = READUINT8(demo_p); + ziptic = READUINT8(demobuf.p); if (ziptic & GZT_XYZ) { - oldghost[playernum].x = READFIXED(demo_p); - oldghost[playernum].y = READFIXED(demo_p); - oldghost[playernum].z = READFIXED(demo_p); + oldghost[playernum].x = READFIXED(demobuf.p); + oldghost[playernum].y = READFIXED(demobuf.p); + oldghost[playernum].z = READFIXED(demobuf.p); syncleeway = 0; } else { if (ziptic & GZT_MOMXY) { - oldghost[playernum].momx = READINT16(demo_p)<<8; - oldghost[playernum].momy = READINT16(demo_p)<<8; + oldghost[playernum].momx = READINT16(demobuf.p)<<8; + oldghost[playernum].momy = READINT16(demobuf.p)<<8; } if (ziptic & GZT_MOMZ) - oldghost[playernum].momz = READINT16(demo_p)<<8; + oldghost[playernum].momz = READINT16(demobuf.p)<<8; oldghost[playernum].x += oldghost[playernum].momx; oldghost[playernum].y += oldghost[playernum].momy; oldghost[playernum].z += oldghost[playernum].momz; syncleeway = FRACUNIT; } if (ziptic & GZT_ANGLE) - demo_p++; + demobuf.p++; if (ziptic & GZT_SPRITE) - demo_p++; - if(ziptic & GZT_NIGHTS) { + demobuf.p++; + if (ziptic & GZT_NIGHTS) + { if (!testmo || !testmo->player || !(testmo->player->pflags & PF_NIGHTSMODE) || !testmo->tracer) nightsfail = true; else @@ -5214,14 +5223,14 @@ void G_ConsGhostTic(INT32 playernum) if (ziptic & GZT_EXTRA) { // But wait, there's more! - ziptic = READUINT8(demo_p); + ziptic = READUINT8(demobuf.p); if (ziptic & EZT_COLOR) - demo_p++; + demobuf.p++; if (ziptic & EZT_SCALE) - demo_p += sizeof(fixed_t); + demobuf.p += sizeof(fixed_t); if (ziptic & EZT_HIT) { // Resync mob damage. - UINT16 i, count = READUINT16(demo_p); + UINT16 i, count = READUINT16(demobuf.p); thinker_t *th; mobj_t *mobj; @@ -5233,13 +5242,13 @@ void G_ConsGhostTic(INT32 playernum) for (i = 0; i < count; i++) { - demo_p += 4; // reserved. - type = READUINT32(demo_p); - health = READUINT16(demo_p); - x = READFIXED(demo_p); - y = READFIXED(demo_p); - z = READFIXED(demo_p); - demo_p += sizeof(angle_t); // angle, unnecessary for cons. + demobuf.p += 4; // reserved. + type = READUINT32(demobuf.p); + health = READUINT16(demobuf.p); + x = READFIXED(demobuf.p); + y = READFIXED(demobuf.p); + z = READFIXED(demobuf.p); + demobuf.p += sizeof(angle_t); // angle, unnecessary for cons. mobj = NULL; for (th = thinkercap.next; th != &thinkercap; th = th->next) @@ -5261,12 +5270,12 @@ void G_ConsGhostTic(INT32 playernum) } } if (ziptic & EZT_SPRITE) - demo_p++; + demobuf.p++; if (ziptic & EZT_KART) { - ghostext[playernum].kartitem = READINT32(demo_p); - ghostext[playernum].kartamount = READINT32(demo_p); - ghostext[playernum].kartbumpers = READINT32(demo_p); + ghostext[playernum].kartitem = READINT32(demobuf.p); + ghostext[playernum].kartamount = READINT32(demobuf.p); + ghostext[playernum].kartbumpers = READINT32(demobuf.p); } } @@ -5326,7 +5335,7 @@ void G_ConsGhostTic(INT32 playernum) } } - if (*demo_p == DEMOMARKER) + if (*demobuf.p == DEMOMARKER) { // end of demo data stream G_CheckDemoStatus(); @@ -5739,7 +5748,7 @@ void G_ConfirmRewind(tic_t rewindtime) if (rewind) { - demo_p = demobuffer + rewind->demopos; + demobuf.p = demobuf.buffer + rewind->demopos; memcpy(oldcmd, rewind->oldcmd, sizeof (oldcmd)); memcpy(oldghost, rewind->oldghost, sizeof (oldghost)); paused = false; @@ -5887,10 +5896,10 @@ void G_WriteMetalTic(mobj_t *metal) UINT8 ziptic = 0; UINT8 *ziptic_p; - if (!demo_p) // demo_p will be NULL until the race start linedef executor is triggered! + if (!demobuf.p) // demobuf.p will be NULL until the race start linedef executor is triggered! return; - ziptic_p = demo_p++; // the ziptic, written at the end of this function + ziptic_p = demobuf.p++; // the ziptic, written at the end of this function #define MAXMOM (0xFFFF<<8) @@ -5902,9 +5911,9 @@ void G_WriteMetalTic(mobj_t *metal) oldmetal.x = metal->x; oldmetal.y = metal->y; oldmetal.z = metal->z; - WRITEFIXED(demo_p,oldmetal.x); - WRITEFIXED(demo_p,oldmetal.y); - WRITEFIXED(demo_p,oldmetal.z); + WRITEFIXED(demobuf.p,oldmetal.x); + WRITEFIXED(demobuf.p,oldmetal.y); + WRITEFIXED(demobuf.p,oldmetal.z); ziptic |= GZT_XYZ; } else @@ -5918,15 +5927,15 @@ void G_WriteMetalTic(mobj_t *metal) { oldmetal.momx = momx; oldmetal.momy = momy; - WRITEINT16(demo_p,momx); - WRITEINT16(demo_p,momy); + WRITEINT16(demobuf.p,momx); + WRITEINT16(demobuf.p,momy); ziptic |= GZT_MOMXY; } momx = (INT16)((metal->z-oldmetal.z)>>8); if (momx != oldmetal.momz) { oldmetal.momz = momx; - WRITEINT16(demo_p,momx); + WRITEINT16(demobuf.p,momx); ziptic |= GZT_MOMZ; } @@ -5946,7 +5955,7 @@ void G_WriteMetalTic(mobj_t *metal) if (metal->angle>>24 != oldmetal.angle) { oldmetal.angle = metal->angle>>24; - WRITEUINT8(demo_p,oldmetal.angle); + WRITEUINT8(demobuf.p,oldmetal.angle); ziptic |= GZT_ANGLE; } @@ -5959,16 +5968,16 @@ void G_WriteMetalTic(mobj_t *metal) if ((metal->eflags & MFE_VERTICALFLIP) != (oldmetal.eflags & MFE_VERTICALFLIP)) { if (!exttic_p) - exttic_p = demo_p++; + exttic_p = demobuf.p++; exttic |= EZT_FLIP; oldmetal.eflags ^= MFE_VERTICALFLIP; } if (metal->scale != oldmetal.scale) { if (!exttic_p) - exttic_p = demo_p++; + exttic_p = demobuf.p++; exttic |= EZT_SCALE; - WRITEFIXED(demo_p,metal->scale); + WRITEFIXED(demobuf.p,metal->scale); oldmetal.scale = metal->scale; } if (exttic_p) @@ -5982,7 +5991,7 @@ void G_WriteMetalTic(mobj_t *metal) // attention here for the ticcmd size! // latest demos with mouse aiming byte in ticcmd - if (demo_p >= demoend - 32) + if (demobuf.p >= demoend - 32) { G_StopMetalRecording(); // no more space return; @@ -5996,7 +6005,7 @@ void G_RecordDemo(const char *name) { INT32 maxsize; - demo_p = NULL; + demobuf.p = NULL; G_ResetDemoRecording(); demoend = NULL; @@ -6009,10 +6018,10 @@ void G_RecordDemo(const char *name) maxsize = cv_maxdemosize.value*1024*1024; - demobuffer = Z_Malloc(maxsize, PU_STATIC, NULL); - demoend = demobuffer + maxsize; + demobuf.buffer = Z_Malloc(maxsize, PU_STATIC, NULL); + demoend = demobuf.buffer + maxsize; - if (demobuffer) + if (demobuf.buffer) demo.recording = true; else CONS_Alert(CONS_ERROR, "Failed to allocate demo buffer\n"); @@ -6023,14 +6032,14 @@ void G_RecordMetal(void) { INT32 maxsize; maxsize = cv_maxdemosize.value*1024*1024; - if (demobuffer) - Z_Free(demobuffer); - demo_p = NULL; + if (demobuf.buffer) + Z_Free(demobuf.buffer); + demobuf.p = NULL; metalrecording = false; - demobuffer = Z_Malloc(maxsize, PU_STATIC, NULL); - demoend = demobuffer + maxsize; + demobuf.buffer = Z_Malloc(maxsize, PU_STATIC, NULL); + demoend = demobuf.buffer + maxsize; - if (demobuffer) + if (demobuf.buffer) metalrecording = true; else CONS_Alert(CONS_ERROR, "Failed to allocate demo buffer\n"); @@ -6046,28 +6055,32 @@ void G_BeginRecording(void) UINT8 totalfiles; UINT8 *m; - if (demo_p) + if (!cv_recordmultiplayerdemos.value) return; + + if (demobuf.p || demobuf.buffer == NULL) + return; + memset(name,0,sizeof(name)); - demo_p = demobuffer; + demobuf.p = demobuf.buffer; demoflags = DF_GHOST|(multiplayer ? DF_MULTIPLAYER : (modeattacking<important) { nameonly(( filename = va("%s", wadfiles[i]->filename) )); - WRITESTRINGL(demo_p, filename, MAX_WADPATH); - WRITEMEM(demo_p, wadfiles[i]->md5sum, 16); + WRITESTRINGL(demobuf.p, filename, MAX_WADPATH); + WRITEMEM(demobuf.p, wadfiles[i]->md5sum, 16); totalfiles++; } @@ -6117,63 +6130,63 @@ void G_BeginRecording(void) case ATTACKING_NONE: // 0 break; case ATTACKING_RECORD: // 1 - demotime_p = demo_p; - WRITEUINT32(demo_p,UINT32_MAX); // time - WRITEUINT32(demo_p,UINT32_MAX); // lap + demotime_p = demobuf.p; + WRITEUINT32(demobuf.p,UINT32_MAX); // time + WRITEUINT32(demobuf.p,UINT32_MAX); // lap break; default: // 3 break; } - WRITEUINT32(demo_p,P_GetInitSeed()); + WRITEUINT32(demobuf.p, P_GetInitSeed()); // Reserved for extrainfo location from start of file - demoinfo_p = demo_p; - WRITEUINT32(demo_p, 0); + demoinfo_p = demobuf.p; + WRITEUINT32(demobuf.p, 0); // Save netvars - CV_SaveNetVars(&demo_p, true); + CV_SaveNetVars(&demobuf.p, true); // Now store some info for each in-game player for (p = 0; p < MAXPLAYERS; p++) { if (playeringame[p]) { player = &players[p]; - WRITEUINT8(demo_p, p | (player->spectator ? DEMO_SPECTATOR : 0)); + WRITEUINT8(demobuf.p, p | (player->spectator ? DEMO_SPECTATOR : 0)); // Name memset(name, 0, 16); memcpy(name, player_names[p], 15); - M_Memcpy(demo_p,name,16); - demo_p += 16; + M_Memcpy(demobuf.p,name,16); + demobuf.p += 16; // Skin memset(name, 0, 16); strncpy(name, skins[player->skin].name, 16); - M_Memcpy(demo_p,name,16); - demo_p += 16; + M_Memcpy(demobuf.p,name,16); + demobuf.p += 16; // Color memset(name, 0, 16); strncpy(name, KartColor_Names[player->skincolor], 16); - M_Memcpy(demo_p,name,16); - demo_p += 16; + M_Memcpy(demobuf.p,name,16); + demobuf.p += 16; // Score, since Kart uses this to determine where you start on the map - WRITEUINT32(demo_p, player->score); + WRITEUINT32(demobuf.p, player->score); // Kart speed and weight - WRITEUINT8(demo_p, skins[player->skin].kartspeed); - WRITEUINT8(demo_p, skins[player->skin].kartweight); + WRITEUINT8(demobuf.p, skins[player->skin].kartspeed); + WRITEUINT8(demobuf.p, skins[player->skin].kartweight); } } - WRITEUINT8(demo_p, 0xFF); // Denote the end of the player listing + WRITEUINT8(demobuf.p, 0xFF); // Denote the end of the player listing // player lua vars, always saved even if empty... Unless it's record attack. if (demoflags & DF_LUAVARS) - LUA_ArchiveDemo(); + LUA_Archive(&demobuf, false); memset(&oldcmd,0,sizeof(oldcmd)); memset(&oldghost,0,sizeof(oldghost)); @@ -6202,21 +6215,21 @@ void G_BeginMetal(void) { mobj_t *mo = players[consoleplayer].mo; - if (demo_p) + if (demobuf.p || demobuf.buffer == NULL) return; - demo_p = demobuffer; + demobuf.p = demobuf.buffer; // Write header. - M_Memcpy(demo_p, DEMOHEADER, 12); demo_p += 12; - WRITEUINT8(demo_p,VERSION); - WRITEUINT8(demo_p,SUBVERSION); - WRITEUINT16(demo_p,DEMOVERSION); + M_Memcpy(demobuf.p, DEMOHEADER, 12); demobuf.p += 12; + WRITEUINT8(demobuf.p,VERSION); + WRITEUINT8(demobuf.p,SUBVERSION); + WRITEUINT16(demobuf.p,DEMOVERSION); // demo checksum - demo_p += 16; + demobuf.p += 16; - M_Memcpy(demo_p, "METL", 4); demo_p += 4; + M_Memcpy(demobuf.p, "METL", 4); demobuf.p += 4; // Set up our memory. memset(&oldmetal,0,sizeof(oldmetal)); @@ -6230,35 +6243,38 @@ void G_WriteStanding(UINT8 ranking, char *name, INT32 skinnum, UINT8 color, UINT { char temp[17]; - if (demoinfo_p && *(UINT32 *)demoinfo_p == 0) + if (!demobuf.p) + return; + + if (demoinfo_p && *(UINT32 *)demoinfo_p == 0 && demobuf.buffer != NULL) { - WRITEUINT8(demo_p, DEMOMARKER); // add the demo end marker - *(UINT32 *)demoinfo_p = demo_p - demobuffer; + WRITEUINT8(demobuf.p, DEMOMARKER); // add the demo end marker + *(UINT32 *)demoinfo_p = demobuf.p - demobuf.buffer; } - WRITEUINT8(demo_p, DW_STANDING); - WRITEUINT8(demo_p, ranking); + WRITEUINT8(demobuf.p, DW_STANDING); + WRITEUINT8(demobuf.p, ranking); // Name memset(temp, 0, 16); strncpy(temp, name, 16); - M_Memcpy(demo_p,temp,16); - demo_p += 16; + M_Memcpy(demobuf.p,temp,16); + demobuf.p += 16; // Skin memset(temp, 0, 16); strncpy(temp, skins[skinnum].name, 16); - M_Memcpy(demo_p,temp,16); - demo_p += 16; + M_Memcpy(demobuf.p,temp,16); + demobuf.p += 16; // Color memset(temp, 0, 16); strncpy(temp, KartColor_Names[color], 16); - M_Memcpy(demo_p,temp,16); - demo_p += 16; + M_Memcpy(demobuf.p,temp,16); + demobuf.p += 16; // Score/time/whatever - WRITEUINT32(demo_p, val); + WRITEUINT32(demobuf.p, val); } void G_SetDemoTime(UINT32 ptime, UINT32 plap) @@ -6816,6 +6832,9 @@ void G_DoPlayDemo(char *defdemoname) boolean spectator; UINT8 slots[MAXPLAYERS], kartspeed[MAXPLAYERS], kartweight[MAXPLAYERS], numslots = 0; + if (demobuf.buffer == NULL) + return; + G_InitDemoRewind(); skin[16] = '\0'; @@ -6824,7 +6843,7 @@ void G_DoPlayDemo(char *defdemoname) // No demo name means we're restarting the current demo if (defdemoname == NULL) { - demo_p = demobuffer; + demobuf.p = demobuf.buffer; pdemoname = ZZ_Alloc(1); // Easier than adding checks for this everywhere it's freed } else @@ -6843,7 +6862,7 @@ void G_DoPlayDemo(char *defdemoname) if (FIL_CheckExtension(defdemoname)) { //FIL_DefaultExtension(defdemoname, ".lmp"); - if (!FIL_ReadFile(defdemoname, &demobuffer)) + if (!FIL_ReadFile(defdemoname, &demobuf.buffer)) { snprintf(msg, 1024, M_GetText("Failed to read file '%s'.\n"), defdemoname); CONS_Alert(CONS_ERROR, "%s", msg); @@ -6851,7 +6870,7 @@ void G_DoPlayDemo(char *defdemoname) M_StartMessage(msg, NULL, MM_NOTHING); return; } - demo_p = demobuffer; + demobuf.p = demobuf.buffer; } // load demo resource from WAD else if ((l = W_CheckNumForName(defdemoname)) == LUMPERROR) @@ -6864,7 +6883,7 @@ void G_DoPlayDemo(char *defdemoname) } else // it's an internal demo { - demobuffer = demo_p = W_CacheLumpNum(l, PU_STATIC); + demobuf.buffer = demobuf.p = W_CacheLumpNum(l, PU_STATIC); #if defined(SKIPERRORS) && !defined(DEVELOP) skiperrors = true; // SRB2Kart: Don't print warnings for staff ghosts, since they'll inevitably happen when we make bugfixes/changes... #endif @@ -6874,7 +6893,7 @@ void G_DoPlayDemo(char *defdemoname) // read demo header gameaction = ga_nothing; demo.playback = true; - if (memcmp(demo_p, DEMOHEADER, 12)) + if (memcmp(demobuf.p, DEMOHEADER, 12)) { snprintf(msg, 1024, M_GetText("%s is not a SRB2Kart replay file.\n"), pdemoname); CONS_Alert(CONS_ERROR, "%s", msg); @@ -6882,17 +6901,17 @@ void G_DoPlayDemo(char *defdemoname) G_ResetDemoPlayback(pdemoname); return; } - demo_p += 12; // DEMOHEADER + demobuf.p += 12; // DEMOHEADER - version = READUINT8(demo_p); - subversion = READUINT8(demo_p); - demo.version = READUINT16(demo_p); + version = READUINT8(demobuf.p); + subversion = READUINT8(demobuf.p); + demo.version = READUINT16(demobuf.p); switch(demo.version) { case DEMOVERSION: // latest always supported // demo title - M_Memcpy(demo.titlename, demo_p, 64); - demo_p += 64; + M_Memcpy(demo.titlename, demobuf.p, 64); + demobuf.p += 64; break; #ifdef DEMO_COMPAT_100 @@ -6907,8 +6926,8 @@ void G_DoPlayDemo(char *defdemoname) G_ResetDemoPlayback(pdemoname); return; } - demo_p += 16; // demo checksum - if (memcmp(demo_p, "PLAY", 4)) + demobuf.p += 16; // demo checksum + if (memcmp(demobuf.p, "PLAY", 4)) { snprintf(msg, 1024, M_GetText("%s is the wrong type of recording and cannot be played.\n"), pdemoname); CONS_Alert(CONS_ERROR, "%s", msg); @@ -6916,11 +6935,11 @@ void G_DoPlayDemo(char *defdemoname) G_ResetDemoPlayback(pdemoname); return; } - demo_p += 4; // "PLAY" - gamemap = READINT16(demo_p); - demo_p += 16; // mapmd5 + demobuf.p += 4; // "PLAY" + gamemap = READINT16(demobuf.p); + demobuf.p += 16; // mapmd5 - demoflags = READUINT8(demo_p); + demoflags = READUINT8(demobuf.p); #ifdef DEMO_COMPAT_100 if (demo.version == 0x0001) { @@ -6936,17 +6955,17 @@ void G_DoPlayDemo(char *defdemoname) else { #endif - gametype = READUINT8(demo_p); + gametype = READUINT8(demobuf.p); if (demo.title) // Titledemos should always play and ought to always be compatible with whatever wadlist is running. - G_SkipDemoExtraFiles(&demo_p); + G_SkipDemoExtraFiles(&demobuf.p); else if (demo.loadfiles) - G_LoadDemoExtraFiles(&demo_p); + G_LoadDemoExtraFiles(&demobuf.p); else if (demo.ignorefiles) - G_SkipDemoExtraFiles(&demo_p); + G_SkipDemoExtraFiles(&demobuf.p); else { - UINT8 error = G_CheckDemoExtraFiles(&demo_p, false); + UINT8 error = G_CheckDemoExtraFiles(&demobuf.p, false); if (error) { @@ -7006,8 +7025,8 @@ void G_DoPlayDemo(char *defdemoname) case ATTACKING_NONE: // 0 break; case ATTACKING_RECORD: // 1 - hu_demotime = READUINT32(demo_p); - hu_demolap = READUINT32(demo_p); + hu_demotime = READUINT32(demobuf.p); + hu_demolap = READUINT32(demobuf.p); break; default: // 3 modeattacking = ATTACKING_NONE; @@ -7015,33 +7034,33 @@ void G_DoPlayDemo(char *defdemoname) } // Random seed - randseed = READUINT32(demo_p); + randseed = READUINT32(demobuf.p); #ifdef DEMO_COMPAT_100 if (demo.version != 0x0001) #endif - demo_p += 4; // Extrainfo location + demobuf.p += 4; // Extrainfo location #ifdef DEMO_COMPAT_100 if (demo.version == 0x0001) { // Player name - M_Memcpy(player_names[0],demo_p,16); - demo_p += 16; + M_Memcpy(player_names[0],demobuf.p,16); + demobuf.p += 16; // Skin - M_Memcpy(skin,demo_p,16); - demo_p += 16; + M_Memcpy(skin,demobuf.p,16); + demobuf.p += 16; // Color - M_Memcpy(color,demo_p,16); - demo_p += 16; + M_Memcpy(color,demobuf.p,16); + demobuf.p += 16; - demo_p += 5; // Backwards compat - some stats + demobuf.p += 5; // Backwards compat - some stats // SRB2kart - kartspeed[0] = READUINT8(demo_p); - kartweight[0] = READUINT8(demo_p); + kartspeed[0] = READUINT8(demobuf.p); + kartweight[0] = READUINT8(demobuf.p); // - demo_p += 9; // Backwards compat - more stats + demobuf.p += 9; // Backwards compat - more stats // Skin not loaded? if (!SetPlayerSkin(0, skin)) @@ -7072,10 +7091,10 @@ void G_DoPlayDemo(char *defdemoname) } // net var data - CV_LoadNetVars(&demo_p); + CV_LoadNetVars(&demobuf.p); // Sigh ... it's an empty demo. - if (*demo_p == DEMOMARKER) + if (*demobuf.p == DEMOMARKER) { snprintf(msg, 1024, M_GetText("%s contains no data to be played.\n"), pdemoname); CONS_Alert(CONS_ERROR, "%s", msg); @@ -7112,10 +7131,10 @@ void G_DoPlayDemo(char *defdemoname) #endif // net var data - CV_LoadNetVars(&demo_p); + CV_LoadNetVars(&demobuf.p); // Sigh ... it's an empty demo. - if (*demo_p == DEMOMARKER) + if (*demobuf.p == DEMOMARKER) { snprintf(msg, 1024, M_GetText("%s contains no data to be played.\n"), pdemoname); CONS_Alert(CONS_ERROR, "%s", msg); @@ -7153,7 +7172,7 @@ void G_DoPlayDemo(char *defdemoname) memset(playeringame,0,sizeof(playeringame)); // Load players that were in-game when the map started - p = READUINT8(demo_p); + p = READUINT8(demobuf.p); for (i = 1; i < MAXSPLITSCREENPLAYERS; i++) displayplayers[i] = INT32_MAX; @@ -7193,17 +7212,17 @@ void G_DoPlayDemo(char *defdemoname) players[p].spectator = spectator; // Name - M_Memcpy(player_names[p],demo_p,16); - demo_p += 16; + M_Memcpy(player_names[p],demobuf.p,16); + demobuf.p += 16; // Skin - M_Memcpy(skin,demo_p,16); - demo_p += 16; + M_Memcpy(skin,demobuf.p,16); + demobuf.p += 16; SetPlayerSkin(p, skin); // Color - M_Memcpy(color,demo_p,16); - demo_p += 16; + M_Memcpy(color,demobuf.p,16); + demobuf.p += 16; for (i = 0; i < MAXSKINCOLORS; i++) if (!stricmp(KartColor_Names[i],color)) // SRB2kart { @@ -7212,17 +7231,17 @@ void G_DoPlayDemo(char *defdemoname) } // Score, since Kart uses this to determine where you start on the map - players[p].score = READUINT32(demo_p); + players[p].score = READUINT32(demobuf.p); // Kart stats, temporarily - kartspeed[p] = READUINT8(demo_p); - kartweight[p] = READUINT8(demo_p); + kartspeed[p] = READUINT8(demobuf.p); + kartweight[p] = READUINT8(demobuf.p); if (stricmp(skins[players[p].skin].name, skin) != 0) FindClosestSkinForStats(p, kartspeed[p], kartweight[p]); // Look for the next player - p = READUINT8(demo_p); + p = READUINT8(demobuf.p); } // end of player read (the 0xFF marker) @@ -7233,7 +7252,7 @@ void G_DoPlayDemo(char *defdemoname) LUA_ClearState(); // No modeattacking check, DF_LUAVARS won't be present here. - LUA_UnArchiveDemo(); + LUA_UnArchive(&demobuf, false); } splitscreen = 0; @@ -7811,22 +7830,22 @@ void G_StopMetalDemo(void) ATTRNORETURN void FUNCNORETURN G_StopMetalRecording(void) { boolean saved = false; - if (demo_p) + if (demobuf.p && demobuf.buffer != NULL) { - UINT8 *p = demobuffer+16; // checksum position + UINT8 *p = demobuf.buffer+16; // checksum position #ifdef NOMD5 UINT8 i; - WRITEUINT8(demo_p, DEMOMARKER); // add the demo end marker + WRITEUINT8(demobuf.p, DEMOMARKER); // add the demo end marker for (i = 0; i < 16; i++, p++) *p = P_RandomByte(); // This MD5 was chosen by fair dice roll and most likely < 50% correct. #else - WRITEUINT8(demo_p, DEMOMARKER); // add the demo end marker - md5_buffer((char *)p+16, demo_p - (p+16), (void *)p); // make a checksum of everything after the checksum in the file. + WRITEUINT8(demobuf.p, DEMOMARKER); // add the demo end marker + md5_buffer((char *)p+16, demobuf.p - (p+16), (void *)p); // make a checksum of everything after the checksum in the file. #endif - saved = FIL_WriteFile(va("%sMS.LMP", G_BuildMapName(gamemap)), demobuffer, demo_p - demobuffer); // finally output the file. + saved = FIL_WriteFile(va("%sMS.LMP", G_BuildMapName(gamemap)), demobuf.buffer, demobuf.p - demobuf.buffer); // finally output the file. } - Z_Free(demobuffer); - demobuffer = NULL; + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; metalrecording = false; if (saved) I_Error("Saved to %sMS.LMP", G_BuildMapName(gamemap)); @@ -7837,8 +7856,8 @@ ATTRNORETURN void FUNCNORETURN G_StopMetalRecording(void) // called from stopdemo command, map command, and g_checkdemoStatus. void G_StopDemo(void) { - Z_Free(demobuffer); - demobuffer = NULL; + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; if (demo.playback) { CV_SetValue(&cv_director, directorstate); @@ -7946,9 +7965,9 @@ boolean G_CheckDemoStatus(void) void G_ResetDemoRecording(void) { - if (demobuffer) - Z_Free(demobuffer); - demobuffer = NULL; + if (demobuf.buffer) + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; demo.recording = false; } @@ -7956,16 +7975,16 @@ static void G_ResetDemoPlayback(char *pdemoname) { if (pdemoname) Z_Free(pdemoname); - if (demobuffer) - Z_Free(demobuffer); - demobuffer = NULL; + if (demobuf.buffer) + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; demo.playback = false; demo.title = false; } void G_SaveDemo(void) { - if (!demo_p) + if (!demobuf.p) { CONS_Alert(CONS_ERROR, "Failed to save Demo. No Demo pointer exists!\n"); // reset the demo buffer @@ -7973,7 +7992,15 @@ void G_SaveDemo(void) return; } - UINT8 *p = demobuffer+16; // after version + if (demobuf.buffer == NULL) + { + CONS_Alert(CONS_ERROR, "Failed to save Demo. No Demo buffer allocated!\n"); + // reset the demo buffer + G_ResetDemoRecording(); + return; + } + + UINT8 *p = demobuf.buffer+16; // after version UINT32 length; #ifdef NOMD5 UINT8 i; @@ -7982,10 +8009,10 @@ void G_SaveDemo(void) // Ensure extrainfo pointer is always available, even if no info is present. if (demoinfo_p && *(UINT32 *)demoinfo_p == 0) { - WRITEUINT8(demo_p, DEMOMARKER); // add the demo end marker - *(UINT32 *)demoinfo_p = demo_p - demobuffer; + WRITEUINT8(demobuf.p, DEMOMARKER); // add the demo end marker + *(UINT32 *)demoinfo_p = demobuf.p - demobuf.buffer; } - WRITEUINT8(demo_p, DW_END); // Mark end of demo extra data. + WRITEUINT8(demobuf.p, DW_END); // Mark end of demo extra data. M_Memcpy(p, demo.titlename, 64); // Write demo title here p += 64; @@ -8036,11 +8063,11 @@ void G_SaveDemo(void) *p = M_RandomByte(); // This MD5 was chosen by fair dice roll and most likely < 50% correct. #else // Make a checksum of everything after the checksum in the file up to the end of the standard data. Extrainfo is freely modifiable. - md5_buffer((char *)p+16, (demobuffer + length) - (p+16), p); + md5_buffer((char *)p+16, (demobuf.buffer + length) - (p+16), p); #endif - if (FIL_WriteFile(va(pandf, srb2home, demoname), demobuffer, demo_p - demobuffer)) // finally output the file. + if (FIL_WriteFile(va(pandf, srb2home, demoname), demobuf.buffer, demobuf.p - demobuf.buffer)) // finally output the file. demo.savemode = DSM_SAVED; G_ResetDemoRecording(); diff --git a/src/g_game.h b/src/g_game.h index 1cb36869c..7c81ab79e 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -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. diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c index e32a7162a..82cfd31db 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.c @@ -15,6 +15,8 @@ #include "hw_main.h" #include "../i_system.h" +#include "../doomdef.h" + #include "../qs22j.h" // The texture for the next polygon given to HWR_ProcessPolygon. @@ -63,7 +65,7 @@ void HWR_StartBatching(void) currently_batching = true; } -// This replaces the direct calls to pfnSetTexture in cases where batching is available. +// This replaces the direct calls to GL_SetTexture in cases where batching is available. // The texture selection is saved for the next HWR_ProcessPolygon call. // Doing this was easier than getting a texture pointer to HWR_ProcessPolygon. void HWR_SetCurrentTexture(GLMipmap_t *texture) @@ -74,7 +76,7 @@ void HWR_SetCurrentTexture(GLMipmap_t *texture) } else { - HWD.pfnSetTexture(texture); + GL_SetTexture(texture); } } @@ -128,8 +130,8 @@ void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPt } else { - HWD.pfnSetShader((shader_target != SHADER_NONE) ? HWR_GetShaderFromTarget(shader_target) : shader_target); - HWD.pfnDrawPolygon(pSurf, pOutVerts, iNumPts, PolyFlags); + GL_SetShader((shader_target != SHADER_NONE) ? HWR_GetShaderFromTarget(shader_target) : shader_target); + GL_DrawPolygon(pSurf, pOutVerts, iNumPts, PolyFlags); } } @@ -290,13 +292,13 @@ void HWR_RenderBatches(void) if (cv_glshaders.value && gl_shadersavailable) { - HWD.pfnSetShader(currentShader); + GL_SetShader(currentShader); } if (currentPolyFlags & PF_NoTexture) currentTexture = NULL; else - HWD.pfnSetTexture(currentTexture); + GL_SetTexture(currentTexture); while (1)// note: remember handling notexture polyflag as having texture number 0 (also in comparePolygons) { @@ -411,7 +413,7 @@ void HWR_RenderBatches(void) if (changeState || stopFlag) { // execute draw call - HWD.pfnDrawIndexedTriangles(¤tSurfaceInfo, finalVertexArray, finalIndexWritePos, currentPolyFlags, finalVertexIndexArray); + GL_DrawIndexedTriangles(¤tSurfaceInfo, finalVertexArray, finalIndexWritePos, currentPolyFlags, finalVertexIndexArray); // update stats ps_hw_numcalls.value.i++; ps_hw_numverts.value.i += finalIndexWritePos; @@ -429,7 +431,7 @@ void HWR_RenderBatches(void) { if (changeShader) { - HWD.pfnSetShader(nextShader); + GL_SetShader(nextShader); currentShader = nextShader; changeShader = false; @@ -437,8 +439,8 @@ void HWR_RenderBatches(void) } if (changeTexture) { - // texture should be already ready for use from calls to SetTexture during batch collection - HWD.pfnSetTexture(nextTexture); + // texture should be already ready for use from calls to GL_SetTexture during batch collection + GL_SetTexture(nextTexture); currentTexture = nextTexture; changeTexture = false; diff --git a/src/hardware/hw_batching.h b/src/hardware/hw_batching.h index 22a4cc4c0..7f418fc77 100644 --- a/src/hardware/hw_batching.h +++ b/src/hardware/hw_batching.h @@ -15,7 +15,9 @@ #include "hw_defs.h" #include "hw_data.h" -#include "hw_drv.h" +#include "hw_gl.h" + +extern boolean currently_batching; typedef struct { diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index b058bde99..ad140c025 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -14,9 +14,10 @@ #include "../doomdef.h" #ifdef HWRENDER + #include "hw_main.h" #include "hw_glob.h" -#include "hw_drv.h" +#include "hw_gl.h" #include "hw_batching.h" #include "../doomstat.h" //gamemode @@ -73,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; @@ -111,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...) @@ -496,7 +500,7 @@ static void FreeMipmapColormap(INT32 patchnum, void *patch) if (next->data) Z_Free(next->data); next->data = NULL; - HWD.pfnDeleteTexture(next); + GL_DeleteTexture(next); // Free the old colormap mipmap from memory. free(next); @@ -507,7 +511,7 @@ void HWR_FreeMipmapCache(void) { INT32 i; // free references to the textures - HWD.pfnClearMipMapCache(); + GL_ClearMipMapCache(); // free all hardware-converted graphics cached in the heap // our gool is only the textures since user of the texture is the texture cache @@ -574,7 +578,7 @@ GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore) // If hardware does not have the texture, then call pfnSetTexture to upload it if (!gltex->mipmap.downloaded) - HWD.pfnSetTexture(&gltex->mipmap); + GL_SetTexture(&gltex->mipmap); HWR_SetCurrentTexture(&gltex->mipmap); // The system-memory data can be purged now. @@ -662,7 +666,7 @@ void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap) // If hardware does not have the texture, then call pfnSetTexture to upload it if (!glMipmap->downloaded) - HWD.pfnSetTexture(glMipmap); + GL_SetTexture(glMipmap); HWR_SetCurrentTexture(glMipmap); // The system-memory data can be purged now. @@ -691,7 +695,7 @@ static void HWR_LoadMappedPatch(GLMipmap_t *glMipmap, GLPatch_t *glPatch) // If hardware does not have the texture, then call pfnSetTexture to upload it if (!glMipmap->downloaded) - HWD.pfnSetTexture(glMipmap); + GL_SetTexture(glMipmap); HWR_SetCurrentTexture(glMipmap); // The system-memory data can be purged now. @@ -721,7 +725,7 @@ void HWR_GetPatch(GLPatch_t *glPatch) // If hardware does not have the texture, then call pfnSetTexture to upload it if (!glPatch->mipmap->downloaded) - HWD.pfnSetTexture(glPatch->mipmap); + GL_SetTexture(glPatch->mipmap); HWR_SetCurrentTexture(glPatch->mipmap); // The system-memory patch data can be purged now. @@ -896,7 +900,7 @@ void HWR_GetFadeMask(lumpnum_t fademasklumpnum) if (!glMipmap->downloaded && !glMipmap->data) HWR_CacheFadeMask(glMipmap, fademasklumpnum); - HWD.pfnSetTexture(glMipmap); + GL_SetTexture(glMipmap); // The system-memory data can be purged now. Z_ChangeTag(glMipmap->data, PU_HWRCACHE_UNLOCKED); @@ -929,11 +933,11 @@ void HWR_SetPalette(RGBA_t *palette) crushed_palette[i].s.blue = (UINT8)(fblue / 31.0f * 255.0f); crushed_palette[i].s.alpha = 255; } - HWD.pfnSetScreenPalette(crushed_palette); + GL_SetScreenPalette(crushed_palette); } else { - HWD.pfnSetScreenPalette(palette); + GL_SetScreenPalette(palette); } // this part is responsible for keeping track of the palette OUTSIDE of a level. @@ -943,7 +947,7 @@ void HWR_SetPalette(RGBA_t *palette) else { // set the palette for the textures - HWD.pfnSetTexturePalette(palette); + GL_SetPalette(palette); // reset mapPalette so next call to HWR_SetMapPalette will update everything correctly memset(mapPalette, 0, sizeof(mapPalette)); // hardware driver will flush there own cache if cache is non paletized @@ -976,7 +980,7 @@ static void HWR_SetPaletteLookup(RGBA_t *palette) } } #undef STEP_SIZE - HWD.pfnSetPaletteLookup(lut); + GL_SetPaletteLookup(lut); Z_Free(lut); } @@ -1024,7 +1028,7 @@ void HWR_SetMapPalette(void) // in palette rendering mode, this means that all rgba textures now have wrong colors // and the lookup table is outdated HWR_SetPaletteLookup(mapPalette); - HWD.pfnSetTexturePalette(mapPalette); + GL_SetPalette(mapPalette); if (patchformat == GL_TEXFMT_RGBA || textureformat == GL_TEXFMT_RGBA) { @@ -1047,7 +1051,7 @@ UINT32 HWR_CreateLightTable(UINT8 *lighttable) for (i = 0; i < 256 * 32; i++) hw_lighttable[i] = palette[lighttable[i]]; - id = HWD.pfnCreateLightTable(hw_lighttable); + id = GL_CreateLightTable(hw_lighttable); Z_Free(hw_lighttable); return id; } @@ -1083,7 +1087,7 @@ UINT32 HWR_GetLightTableID(extracolormap_t *colormap) void HWR_ClearLightTables(void) { if (vid.glstate == VID_GL_LIBRARY_LOADED) - HWD.pfnClearLightTables(); + GL_ClearLightTables(); } #endif //HWRENDER diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 768e523e0..e38300309 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -18,9 +18,10 @@ #include "../doomdef.h" #ifdef HWRENDER + #include "hw_main.h" #include "hw_glob.h" -#include "hw_drv.h" +#include "hw_gl.h" #include "../m_misc.h" //FIL_WriteFile() #include "../r_draw.h" //viewborderlump @@ -122,7 +123,7 @@ void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option) flags |= PF_ForceWrapY; // clip it since it is used for bunny scroll in doom I - HWD.pfnDrawPolygon(NULL, v, 4, flags); + GL_DrawPolygon(NULL, v, 4, flags); } void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap) @@ -303,10 +304,10 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t else if (alphalevel == 15) Surf.PolyColor.s.alpha = softwaretranstogl_hi[hudtrans]; else Surf.PolyColor.s.alpha = softwaretranstogl[10-alphalevel]; flags |= PF_Modulated; - HWD.pfnDrawPolygon(&Surf, v, 4, flags); + GL_DrawPolygon(&Surf, v, 4, flags); } else - HWD.pfnDrawPolygon(NULL, v, 4, flags); + GL_DrawPolygon(NULL, v, 4, flags); } void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, INT32 option, fixed_t sx, fixed_t sy, fixed_t w, fixed_t h) @@ -460,10 +461,10 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal else if (alphalevel == 15) Surf.PolyColor.s.alpha = softwaretranstogl_hi[cv_translucenthud.value]; else Surf.PolyColor.s.alpha = softwaretranstogl[10-alphalevel]; flags |= PF_Modulated; - HWD.pfnDrawPolygon(&Surf, v, 4, flags); + GL_DrawPolygon(&Surf, v, 4, flags); } else - HWD.pfnDrawPolygon(NULL, v, 4, flags); + GL_DrawPolygon(NULL, v, 4, flags); } // ========================================================================== @@ -539,7 +540,7 @@ void HWR_DrawFlatFill (INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum // BTW, I see we put 0 for PFs, and If I'm right, that // means we take the previous PFs as default // how can we be sure they are ok? - HWD.pfnDrawPolygon(NULL, v, 4, PF_NoDepthTest); //PF_Translucent); + GL_DrawPolygon(NULL, v, 4, PF_NoDepthTest); //PF_Translucent); } @@ -575,10 +576,10 @@ void HWR_FadeScreenMenuBack(UINT16 color, UINT8 strength) Surf.LightTableId = HWR_GetLightTableID(NULL); Surf.LightInfo.light_level = strength; - HWD.pfnMakeScreenTexture(scr_tex); - HWD.pfnSetShader(HWR_GetShaderFromTarget(SHADER_UI_COLORMAP_FADE)); - HWD.pfnDrawScreenTexture(scr_tex, &Surf, PF_ColorMapped|PF_NoDepthTest); - HWD.pfnUnSetShader(); + GL_MakeScreenTexture(scr_tex); + GL_SetShader(HWR_GetShaderFromTarget(SHADER_UI_COLORMAP_FADE)); + GL_DrawScreenTexture(scr_tex, &Surf, PF_ColorMapped|PF_NoDepthTest); + GL_UnSetShader(); return; } @@ -602,7 +603,7 @@ void HWR_FadeScreenMenuBack(UINT16 color, UINT8 strength) poly_flags |= PF_Translucent; } - HWD.pfnDrawPolygon(&Surf, v, 4, poly_flags); + GL_DrawPolygon(&Surf, v, 4, poly_flags); } // Draw the console background with translucency support @@ -629,7 +630,7 @@ void HWR_DrawConsoleBack(UINT32 color, INT32 height) Surf.PolyColor.rgba = UINT2RGBA(color); Surf.PolyColor.s.alpha = 0x80; - HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest); + GL_DrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest); } @@ -785,7 +786,7 @@ void HWR_drawAMline(const fline_t *fl, INT32 color) v2.x = ((float)fl->b.x-(vid.width/2.0f))*(2.0f/vid.width); v2.y = ((float)fl->b.y-(vid.height/2.0f))*(2.0f/vid.height); - HWD.pfnDraw2DLine(&v1, &v2, color_rgba); + GL_Draw2DLine(&v1, &v2, color_rgba); } // -----------------+ @@ -879,7 +880,7 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color) Surf.PolyColor = palette[color&0xFF]; - HWD.pfnDrawPolygon(&Surf, v, 4, + GL_DrawPolygon(&Surf, v, 4, PF_Modulated|PF_NoTexture|PF_NoDepthTest); } @@ -918,7 +919,7 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 clearColour.green = (float)rgbaColour.s.green / 255; clearColour.blue = (float)rgbaColour.s.blue / 255; clearColour.alpha = 1; - HWD.pfnClearBuffer(true, false, false, &clearColour); + GL_ClearBuffer(true, false, false, &clearColour); return; } @@ -989,7 +990,7 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 Surf.PolyColor.rgba = UINT2RGBA(color); Surf.PolyColor.s.alpha = 0x80; - HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest); + GL_DrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest); } // -----------------+ @@ -1029,7 +1030,7 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) clearColour.green = (float)rgbaColour.s.green / 255; clearColour.blue = (float)rgbaColour.s.blue / 255; clearColour.alpha = 1; - HWD.pfnClearBuffer(true, false, false, &clearColour); + GL_ClearBuffer(true, false, false, &clearColour); return; } @@ -1107,7 +1108,7 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) else Surf.PolyColor.s.alpha = softwaretranstogl[10-alphalevel]; } - HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest); + GL_DrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest); } #ifdef HAVE_PNG @@ -1191,7 +1192,7 @@ UINT8 *HWR_GetScreenshot(void) return NULL; // returns 24bit 888 RGB - HWD.pfnReadScreenTexture(HWD_SCREENTEXTURE_GENERIC2, (void *)buf); + GL_ReadScreenTexture(HWD_SCREENTEXTURE_GENERIC2, (void *)buf); return buf; } @@ -1207,7 +1208,7 @@ boolean HWR_Screenshot(const char *pathname) } // returns 24bit 888 RGB - HWD.pfnReadScreenTexture(HWD_SCREENTEXTURE_GENERIC2, (void *)buf); + GL_ReadScreenTexture(HWD_SCREENTEXTURE_GENERIC2, (void *)buf); #ifdef USE_PNG ret = M_SavePNG(pathname, buf, vid.width, vid.height, NULL); diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h deleted file mode 100644 index 78fb53d1e..000000000 --- a/src/hardware/hw_drv.h +++ /dev/null @@ -1,142 +0,0 @@ -// SONIC ROBO BLAST 2 -//----------------------------------------------------------------------------- -// Copyright (C) 1993-1996 by id Software, Inc. -// Copyright (C) 1998-2000 by DooM Legacy Team. -// Copyright (C) 1999-2019 by Sonic Team Junior. -// -// This program is free software distributed under the -// terms of the GNU General Public License, version 2. -// See the 'LICENSE' file for more details. -//----------------------------------------------------------------------------- -/// \file -/// \brief imports/exports for the GPU hardware low-level interface API - -#ifndef __HWR_DRV_H__ -#define __HWR_DRV_H__ - -// this must be here 19991024 by Kin -#include "../screen.h" -#include "hw_data.h" -#include "hw_defs.h" -#include "hw_md2.h" - -#include "hw_dll.h" -#include "../doomdef.h" - -// ========================================================================== -// STANDARD DLL EXPORTS -// ========================================================================== - -EXPORT boolean HWRAPI(Init) (void); -EXPORT void HWRAPI(SetupGLInfo) (void); -EXPORT void HWRAPI(SetTexturePalette) (RGBA_t *ppal); -EXPORT void HWRAPI(FinishUpdate) (INT32 waitvbl); -EXPORT void HWRAPI(Draw2DLine) (F2DCoord *v1, F2DCoord *v2, RGBA_t Color); -EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags); -EXPORT void HWRAPI(DrawIndexedTriangles) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, unsigned int *IndexArray); -EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags); -EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, FBOOLEAN DepthMask, FBOOLEAN StencilMask, FRGBAFloat *ClearColor); -EXPORT void HWRAPI(SetTexture) (GLMipmap_t *TexInfo); -EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *TexInfo); -EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *TexInfo); -EXPORT void HWRAPI(ReadScreenTexture) (int tex, UINT16 *dst_data); -EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip, float farclip); -EXPORT void HWRAPI(ClearMipMapCache) (void); - -//Hurdler: added for backward compatibility -EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value); - -//Hurdler: added for new development - -EXPORT void HWRAPI(DrawModel) (model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface); - -EXPORT void HWRAPI(CreateModelVBOs) (model_t *model); -EXPORT void HWRAPI(SetTransform) (FTransform *stransform); -EXPORT INT32 HWRAPI(GetTextureUsed) (void); - -EXPORT void HWRAPI(RenderSkyDome) (gl_sky_t *sky); - -EXPORT void HWRAPI(FlushScreenTextures) (void); -EXPORT void HWRAPI(DoScreenWipe) (int wipeStart, int wipeEnd); -EXPORT void HWRAPI(DrawScreenTexture) (int tex, FSurfaceInfo *surf, FBITFIELD polyflags); -EXPORT void HWRAPI(MakeScreenTexture) (int tex); -EXPORT void HWRAPI(DrawScreenFinalTexture) (int tex, INT32 width, INT32 height, boolean useshader); - -EXPORT void HWRAPI(RenderVhsEffect) (fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize); - -#define SCREENVERTS 10 -EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]); - -// jimita -EXPORT boolean HWRAPI(InitShaders) (void); -EXPORT void HWRAPI(LoadShader) (int slot, char *code, hwdshaderstage_t stage); -EXPORT boolean HWRAPI(CompileShader) (int slot); -EXPORT void HWRAPI(SetShader) (int slot); -EXPORT void HWRAPI(UnSetShader) (void); - -EXPORT void HWRAPI(SetShaderInfo) (hwdshaderinfo_t info, INT32 value); - -EXPORT void HWRAPI(SetPaletteLookup)(UINT8 *lut); -EXPORT UINT32 HWRAPI(CreateLightTable)(RGBA_t *hw_lighttable); -EXPORT void HWRAPI(ClearLightTables)(void); -EXPORT void HWRAPI(SetScreenPalette)(RGBA_t *palette); - -// ========================================================================== -// HWR DRIVER OBJECT, FOR CLIENT PROGRAM -// ========================================================================== - -#if !defined (_CREATE_DLL_) - -struct hwdriver_s -{ - Init pfnInit; - SetupGLInfo pfnSetupGLInfo; - SetTexturePalette pfnSetTexturePalette; - FinishUpdate pfnFinishUpdate; - Draw2DLine pfnDraw2DLine; - DrawPolygon pfnDrawPolygon; - DrawIndexedTriangles pfnDrawIndexedTriangles; - SetBlend pfnSetBlend; - ClearBuffer pfnClearBuffer; - SetTexture pfnSetTexture; - UpdateTexture pfnUpdateTexture; - DeleteTexture pfnDeleteTexture; - ReadScreenTexture pfnReadScreenTexture; - GClipRect pfnGClipRect; - ClearMipMapCache pfnClearMipMapCache; - SetSpecialState pfnSetSpecialState; - DrawModel pfnDrawModel; - CreateModelVBOs pfnCreateModelVBOs; - SetTransform pfnSetTransform; - GetTextureUsed pfnGetTextureUsed; - PostImgRedraw pfnPostImgRedraw; - FlushScreenTextures pfnFlushScreenTextures; - DoScreenWipe pfnDoScreenWipe; - DrawScreenTexture pfnDrawScreenTexture; - MakeScreenTexture pfnMakeScreenTexture; - RenderVhsEffect pfnRenderVhsEffect; - DrawScreenFinalTexture pfnDrawScreenFinalTexture; - - RenderSkyDome pfnRenderSkyDome; - - InitShaders pfnInitShaders; - LoadShader pfnLoadShader; - CompileShader pfnCompileShader; - SetShader pfnSetShader; - UnSetShader pfnUnSetShader; - - SetShaderInfo pfnSetShaderInfo; - - SetPaletteLookup pfnSetPaletteLookup; - CreateLightTable pfnCreateLightTable; - ClearLightTables pfnClearLightTables; - SetScreenPalette pfnSetScreenPalette; -}; - -extern struct hwdriver_s hwdriver; - -#define HWD hwdriver - -#endif //not defined _CREATE_DLL_ - -#endif //__HWR_DRV_H__ diff --git a/src/hardware/hw_gl.h b/src/hardware/hw_gl.h new file mode 100644 index 000000000..c2a88854f --- /dev/null +++ b/src/hardware/hw_gl.h @@ -0,0 +1,79 @@ +// SONIC ROBO BLAST 2 Kart +//----------------------------------------------------------------------------- +// Copyright (C) 2020 by Jaime "Lactozilla" Passos. +// Copyright (C) 2020 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file hw_gl.h +/// \brief OpenGL low-level interface API + +#ifndef __HWR_GL_H__ +#define __HWR_GL_H__ + +#include "../screen.h" + +#include "hw_data.h" +#include "hw_defs.h" +#include "hw_md2.h" + +#define SCREENVERTS 10 + +boolean GL_Init(void); +void GL_FinishUpdate(INT32 waitvbl); +void SetupGLInfo(void); + +void GL_SetSpecialState(hwdspecialstate_t IdState, INT32 Value); +void GL_SetTransform(FTransform *stransform); +void GL_SetBlend(FBITFIELD PolyFlags); +void GL_SetPalette(RGBA_t *palette); +void GL_ClearBuffer(FBOOLEAN ColorMask, FBOOLEAN DepthMask, FBOOLEAN StencilMask, FRGBAFloat * ClearColor); + +void GL_DrawPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags); +void GL_DrawIndexedTriangles(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, unsigned int *IndexArray); +void GL_Draw2DLine(F2DCoord *v1, F2DCoord *v2, RGBA_t Color); + +void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface); +#define GL_DrawModel(model, frameIndex, duration, tics, nextFrameIndex, pos, hscale, vscale, flipped, hflipped, Surface) GL_DrawModelEx(model, frameIndex, duration, tics, nextFrameIndex, pos, hscale, vscale, flipped, hflipped, Surface) + +void GL_RenderSkyDome(gl_sky_t *sky); + +void GL_SetTexture(GLMipmap_t *pTexInfo); +void GL_DeleteTexture(GLMipmap_t *pTexInfo); + +void GL_Flush(void); +#define GL_ClearMipMapCache GL_Flush + +INT32 GL_GetTextureUsed(void); + +void GL_CreateModelVBOs(model_t *model); + +void GL_ReadScreenTexture(int tex, UINT16 *dst_data); +void GL_GClipRect(INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip, float farclip); + +void GL_MakeScreenTexture(int tex); +void GL_FlushScreenTextures(void); + +void GL_DrawScreenTexture(int tex, FSurfaceInfo *surf, FBITFIELD polyflags); +void GL_DoScreenWipe(int wipeStart, int wipeEnd); +void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize); +void GL_DrawScreenFinalTexture(int tex, INT32 width, INT32 height, boolean useshader); + +void GL_PostImgRedraw(float points[SCREENVERTS][SCREENVERTS][2]); + +boolean GL_InitShaders(void); +void GL_LoadShader(int slot, char *code, hwdshaderstage_t stage); +boolean GL_CompileShader(int slot); +void GL_SetShader(int slot); +void GL_UnSetShader(void); + +void GL_SetShaderInfo(hwdshaderinfo_t info, INT32 value); + +void GL_SetPaletteLookup(UINT8 *lut); +UINT32 GL_CreateLightTable(RGBA_t *hw_lighttable); +void GL_ClearLightTables(void); +void GL_SetScreenPalette(RGBA_t *palette); + +#endif // __HWR_GL_H__ diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index f2de96a79..5eefc9c7e 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -14,13 +14,13 @@ #include #include "../doomstat.h" - -#include "../qs22j.h" +#include "../doomdef.h" #ifdef HWRENDER + #include "hw_main.h" #include "hw_glob.h" -#include "hw_drv.h" +#include "hw_gl.h" #include "hw_batching.h" #include "hw_md2.h" #include "hw_clip.h" @@ -56,6 +56,8 @@ #include "../w_wad.h" #include "../z_zone.h" +#include "../qs22j.h" // fast qsort + // ========================================================================== // Globals // ========================================================================== @@ -63,8 +65,6 @@ #define ABS(x) ((x) < 0 ? -(x) : (x)) #define SOFTLIGHT(llevel) HWR_ShouldUsePaletteRendering() ? ((llevel) >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : (llevel) -struct hwdriver_s hwdriver; - // false if shaders have not been initialized yet, or if shaders are not available boolean gl_shadersavailable = false; @@ -244,7 +244,7 @@ static void CV_screentextures_OnChange(void) CV_SetValue(&cv_glframebuffer, 0); #endif } - HWD.pfnSetSpecialState(HWD_SET_SCREEN_TEXTURES, cv_glscreentextures.value); + GL_SetSpecialState(HWD_SET_SCREEN_TEXTURES, cv_glscreentextures.value); M_UpdateOGLMenu(); } @@ -285,13 +285,13 @@ static void CV_gllightdithering_OnChange(void) static void CV_filtermode_OnChange(void) { ONLY_IF_GL_LOADED - HWD.pfnSetSpecialState(HWD_SET_TEXTUREFILTERMODE, cv_glfiltermode.value); + GL_SetSpecialState(HWD_SET_TEXTUREFILTERMODE, cv_glfiltermode.value); } static void CV_anisotropic_OnChange(void) { ONLY_IF_GL_LOADED - HWD.pfnSetSpecialState(HWD_SET_TEXTUREANISOTROPICMODE, cv_glanisotropicmode.value); + GL_SetSpecialState(HWD_SET_TEXTUREANISOTROPICMODE, cv_glanisotropicmode.value); } static void CV_glpaletterendering_OnChange(void) @@ -326,7 +326,7 @@ boolean HWR_UseShader(void) static void HWR_SetShaderState(void) { - HWD.pfnSetSpecialState(HWD_SET_SHADERS, HWR_UseShader() ? 1 : 0); + GL_SetSpecialState(HWD_SET_SHADERS, HWR_UseShader() ? 1 : 0); } boolean HWR_ShouldUsePaletteRendering(void) @@ -1116,10 +1116,10 @@ static void HWR_DrawSkyWallList(void) surf.PolyColor.rgba = 0xFFFFFFFF; HWR_SetCurrentTexture(NULL); - HWD.pfnUnSetShader(); + GL_UnSetShader(); for (i = 0; i < skyWallVertexArraySize; i++) { - HWD.pfnDrawPolygon(&surf, skyWallVertexArray + i * 4, 4, PF_Occlude|PF_Invisible|PF_NoTexture); + GL_DrawPolygon(&surf, skyWallVertexArray + i * 4, 4, PF_Occlude|PF_Invisible|PF_NoTexture); } } @@ -2471,16 +2471,16 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, { float height; //constant y for all points on the convex flat polygon FOutVector *v3d; - INT32 i; + INT32 i; float flatxref,flatyref; - float fflatsize; - INT32 flatflag; - size_t len; - float scrollx = 0.0f, scrolly = 0.0f; - angle_t angle = 0; + float fflatsize; + INT32 flatflag; + size_t len; + float scrollx = 0.0f, scrolly = 0.0f; + angle_t angle = 0; FSurfaceInfo Surf; - fixed_t tempxsow, tempytow; - size_t nrPlaneVerts; + fixed_t tempxsow, tempytow; + size_t nrPlaneVerts; static FOutVector *planeVerts = NULL; static UINT16 numAllocedPlaneVerts = 0; @@ -2489,8 +2489,6 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, nrPlaneVerts = polysector->numVertices; - height = FIXED_TO_FLOAT(fixedheight); - if (nrPlaneVerts < 3) //not even a triangle ? return; @@ -2508,6 +2506,8 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, Z_Malloc(numAllocedPlaneVerts * sizeof (FOutVector), PU_LEVEL, &planeVerts); } + height = FIXED_TO_FLOAT(fixedheight); + len = W_LumpLength(lumpnum); switch (len) @@ -2705,7 +2705,6 @@ static void HWR_AddPolyObjectPlanes(void) } } - // // HWR_DoCulling // Hardware version of R_DoCulling @@ -2718,6 +2717,7 @@ static boolean HWR_DoCulling(line_t *cullheight, line_t *viewcullheight, float v return false; cullplane = FIXED_TO_FLOAT(cullheight->frontsector->floorheight); + if (cullheight->flags & ML_NOCLIMB) // Group culling { if (!viewcullheight) @@ -3429,6 +3429,7 @@ static void HWR_RotateSpritePolyToAim(gl_vissprite_t *spr, FOutVector *wallVerts // be mobj->z or mobj->z + mobj->height wallVerts[2].y = wallVerts[3].y = (spr->gzt - basey) * gl_viewludsin + basey; wallVerts[0].y = wallVerts[1].y = (lowy - basey) * gl_viewludsin + basey; + // translate back to be around 0 before translating back wallVerts[3].x += ((spr->gzt - basey) * gl_viewludcos) * gl_viewcos; wallVerts[2].x += ((spr->gzt - basey) * gl_viewludcos) * gl_viewcos; @@ -3725,7 +3726,7 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) INT32 shader = SHADER_NONE; - if (!spr->mobj) + if (P_MobjWasRemoved(spr->mobj)) return; if (!spr->mobj->subsector) @@ -3812,8 +3813,9 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) sector_t *sector = spr->mobj->subsector->sector; UINT8 lightlevel = 255; extracolormap_t *colormap = sector->extra_colormap; + const boolean fullbright = (spr->mobj->frame & FF_FULLBRIGHT); - if (!(spr->mobj->frame & FF_FULLBRIGHT)) + if (!fullbright) lightlevel = min(sector->lightlevel, 255); HWR_Lighting(&Surf, lightlevel, colormap); @@ -4202,7 +4204,7 @@ static void HWR_RenderDrawNodes(void) PS_START_TIMING(ps_hw_nodedrawtime); // Okay! Let's draw it all! Woo! - HWD.pfnSetTransform(&atransform); + GL_SetTransform(&atransform); for (i = 0; i < numdrawnodes; i++) { @@ -4274,6 +4276,7 @@ static void HWR_DrawSprites(void) if (spr->mobj && spr->mobj->skin && spr->mobj->sprite == SPR_PLAY) { md2_t *md2; + if (spr->mobj->localskin) { if (spr->mobj->skinlocal) @@ -4351,20 +4354,27 @@ static void HWR_AddSprites(sector_t *sec) // -------------------------------------------------------------------------- static void HWR_AddPrecipitationSprites(void) { - fixed_t drawdist; - fixed_t precipscale = (cv_mobjscaleprecip.value ? mapobjectscale : FRACUNIT); - //const fixed_t drawdist = cv_drawdist_precip.value * mapobjectscale; - INT32 xl, xh, yl, yh, bx, by; precipmobj_t *th; + fixed_t drawdist; + + // save a little time on invisible weather + if (curWeather == PRECIP_BLANK || curWeather == PRECIP_STORM_NORAIN) + { + return; + } + + const fixed_t precipscale = (cv_mobjscaleprecip.value ? mapobjectscale : FRACUNIT); + //const fixed_t drawdist = cv_drawdist_precip.value * mapobjectscale; + if (current_bsp_culling_distance) drawdist = min((fixed_t)current_bsp_culling_distance, (fixed_t)(cv_drawdist_precip.value) * precipscale); else drawdist = ((fixed_t)(cv_drawdist_precip.value) * precipscale); // No to infinite precipitation draw distance. - if (drawdist == 0 || curWeather == PRECIP_BLANK || curWeather == PRECIP_STORM_NORAIN) + if (drawdist == 0) { return; } @@ -4433,11 +4443,6 @@ static void HWR_ProjectSprite(mobj_t *thing) // uncapped/interpolation interpmobjstate_t interp = {0}; - const boolean mirrored = thing->mirrored; - const boolean vflip = (thing->eflags & MFE_VERTICALFLIP); - const boolean hflip = (!(thing->frame & FF_HORIZONTALFLIP) != !mirrored); - const boolean papersprite = (thing->frame & FF_PAPERSPRITE); - if (cv_maxinterpdist.value) dist = R_QuickCamDist(thing->x, thing->y); @@ -4453,6 +4458,11 @@ static void HWR_ProjectSprite(mobj_t *thing) if (interp.spritexscale < 1 || interp.spriteyscale < 1) return; + const boolean mirrored = thing->mirrored; + const boolean vflip = (thing->eflags & MFE_VERTICALFLIP); + const boolean hflip = (!(thing->frame & FF_HORIZONTALFLIP) != !mirrored); + const boolean papersprite = (thing->frame & FF_PAPERSPRITE); + this_scale = FIXED_TO_FLOAT(interp.scale); spritexscale = FIXED_TO_FLOAT(interp.spritexscale); spriteyscale = FIXED_TO_FLOAT(interp.spriteyscale); @@ -5042,7 +5052,7 @@ static void HWR_DrawSkyBackground(void) if (drewsky) return; - HWD.pfnSetBlend(PF_Translucent|PF_NoDepthTest|PF_Modulated); + GL_SetBlend(PF_Translucent|PF_NoDepthTest|PF_Modulated); memcpy(&dometransform, &atransform, sizeof(FTransform)); @@ -5064,9 +5074,9 @@ static void HWR_DrawSkyBackground(void) } if (HWR_UseShader()) - HWD.pfnSetShader(HWR_GetShaderFromTarget(SHADER_SKY)); - HWD.pfnSetTransform(&dometransform); - HWD.pfnRenderSkyDome(&gl_sky); + GL_SetShader(HWR_GetShaderFromTarget(SHADER_SKY)); + GL_SetTransform(&dometransform); + GL_RenderSkyDome(&gl_sky); } // -----------------+ @@ -5074,12 +5084,12 @@ static void HWR_DrawSkyBackground(void) // -----------------+ static inline void HWR_ClearView(void) { - HWD.pfnGClipRect((INT32)gl_viewwindowx, - (INT32)gl_viewwindowy, - (INT32)(gl_viewwindowx + gl_viewwidth), - (INT32)(gl_viewwindowy + gl_viewheight), - ZCLIP_PLANE, FAR_ZCLIP_DEFAULT); - HWD.pfnClearBuffer(false, true, true, NULL); + GL_GClipRect((INT32)gl_viewwindowx, + (INT32)gl_viewwindowy, + (INT32)(gl_viewwindowx + gl_viewwidth), + (INT32)(gl_viewwindowy + gl_viewheight), + ZCLIP_PLANE, FAR_ZCLIP_DEFAULT); + GL_ClearBuffer(false, true, true, NULL); } @@ -5101,7 +5111,7 @@ void HWR_SetViewSize(void) gl_baseviewwindowy = 0; gl_baseviewwindowx = 0; - HWD.pfnFlushScreenTextures(); + GL_FlushScreenTextures(); } // Set view aiming, for the sky dome, the skybox, @@ -5166,7 +5176,7 @@ void HWR_SetTransform(float fpov, player_t *player) atransform.mirrorflip = true; // Set transform. - HWD.pfnSetTransform(&atransform); + GL_SetTransform(&atransform); } void HWR_ClearClipper(void) @@ -5183,8 +5193,8 @@ void HWR_ClearClipper(void) void HWR_SetStencilState(int state, int level) { if (level > -1) - HWD.pfnSetSpecialState(HWD_SET_STENCIL_LEVEL, level); - HWD.pfnSetSpecialState(HWD_SET_PORTAL_MODE, state); + GL_SetSpecialState(HWD_SET_STENCIL_LEVEL, level); + GL_SetSpecialState(HWD_SET_PORTAL_MODE, state); } // Renders the current viewpoint, though takes portal arguments for recursive portals. @@ -5220,6 +5230,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl { HWR_RenderPortal(portal, rootportal, fpov, player, stencil_level); } + HWR_SetPortalState(GLPORTAL_INSIDE); // when portal walls are encountered in following bsp traversal, nothing should be drawn } else @@ -5240,7 +5251,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl } // Set transform. - HWD.pfnSetTransform(&atransform); + GL_SetTransform(&atransform); validcount++; @@ -5284,7 +5295,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl drewsky = false; HWR_DrawSkyBackground(); HWR_SetStencilState(HWR_STENCIL_NORMAL, 0); - HWD.pfnClearBuffer(false, false, true, 0);// clear skywall markings from the stencil buffer + GL_ClearBuffer(false, false, true, 0);// clear skywall markings from the stencil buffer HWR_SetTransform(fpov, player);// restore transform } gl_collect_skywalls = false; @@ -5355,11 +5366,11 @@ static void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) if (!skybox && cv_glrenderdistance.value) { - HWD.pfnGClipRect((INT32)gl_viewwindowx, - (INT32)gl_viewwindowy, - (INT32)(gl_viewwindowx + gl_viewwidth), - (INT32)(gl_viewwindowy + gl_viewheight), - ZCLIP_PLANE, clipping_distances[cv_glrenderdistance.value - 1]); + GL_GClipRect((INT32)gl_viewwindowx, + (INT32)gl_viewwindowy, + (INT32)(gl_viewwindowx + gl_viewwidth), + (INT32)(gl_viewwindowy + gl_viewheight), + ZCLIP_PLANE, clipping_distances[cv_glrenderdistance.value - 1]); current_bsp_culling_distance = bsp_culling_distances[cv_glrenderdistance.value - 1]; } @@ -5367,8 +5378,8 @@ static void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) HWR_RenderViewpoint(NULL, fpov, player, 0, !skybox); // Unset transform and shader - HWD.pfnSetTransform(NULL); - HWD.pfnUnSetShader(); + GL_SetTransform(NULL); + GL_UnSetShader(); // Run post processor effects if (!skybox) @@ -5376,7 +5387,7 @@ static void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) // added by Hurdler for correct splitscreen // moved here by hurdler so it works with the new near clipping plane - HWD.pfnGClipRect(0, 0, vid.width, vid.height, NZCLIP_PLANE, FAR_ZCLIP_DEFAULT); + GL_GClipRect(0, 0, vid.width, vid.height, NZCLIP_PLANE, FAR_ZCLIP_DEFAULT); } // ========================================================================== @@ -5406,11 +5417,13 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) ClearColor.blue = 0.0f; ClearColor.alpha = 1.0f; - HWD.pfnClearBuffer(true, false, false, &ClearColor); + GL_ClearBuffer(true, false, false, &ClearColor); } if (HWR_UseShader() && cv_ripplewater.value) - HWD.pfnSetShaderInfo(HWD_SHADERINFO_LEVELTIME, (INT32)leveltime); // The water surface shader needs the leveltime. + { + GL_SetShaderInfo(HWD_SHADERINFO_LEVELTIME, (INT32)leveltime); // The water surface shader needs the leveltime. + } if (viewnumber > 3) return; @@ -5477,7 +5490,7 @@ static void HWR_TogglePaletteRendering(void) // If the r_opengl "texture palette" stays the same during this switch, these textures // will not be cleared out. However they are still out of date since the // composite texture blending method has changed. Therefore they need to be cleared. - HWD.pfnClearMipMapCache(); + GL_ClearMipMapCache(); } } else @@ -5491,7 +5504,7 @@ static void HWR_TogglePaletteRendering(void) // If the r_opengl "texture palette" stays the same during this switch, these textures // will not be cleared out. However they are still out of date since the // composite texture blending method has changed. Therefore they need to be cleared. - HWD.pfnClearMipMapCache(); + GL_ClearMipMapCache(); } } } @@ -5561,7 +5574,7 @@ void HWR_Startup(void) HWR_TogglePaletteRendering(); if (msaa) - HWD.pfnSetSpecialState(HWD_SET_MSAA, a2c ? 2 : 1); + GL_SetSpecialState(HWD_SET_MSAA, a2c ? 2 : 1); HWR_RegisterCommands(); } @@ -5645,9 +5658,9 @@ void HWR_Shutdown(void) HWR_FreeExtraSubsectors(); HWR_FreeMipmapCache(); HWR_FreeTextureCache(); - HWD.pfnFlushScreenTextures(); + GL_FlushScreenTextures(); #ifdef USE_FBO_OGL - GLFramebuffer_Disable(); + GL_Framebuffer_Disable(); #endif } @@ -5690,12 +5703,12 @@ static void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD INT32 HWR_GetTextureUsed(void) { - return HWD.pfnGetTextureUsed(); + return GL_GetTextureUsed(); } static void HWR_DoPostProcessor(player_t *player) { - HWD.pfnUnSetShader(); + GL_UnSetShader(); // Armageddon Blast Flash! // Could this even be considered postprocessor? @@ -5719,7 +5732,7 @@ static void HWR_DoPostProcessor(player_t *player) Surf.PolyColor.s.alpha = 0xc0; // match software mode - HWD.pfnDrawPolygon(&Surf, v, 4, PF_Modulated|PF_Translucent|PF_NoTexture|PF_NoDepthTest); + GL_DrawPolygon(&Surf, v, 4, PF_Modulated|PF_Translucent|PF_NoTexture|PF_NoDepthTest); } if (cv_glscreentextures.value != 2) // screen textures are needed for the rest of the effects @@ -5727,7 +5740,7 @@ static void HWR_DoPostProcessor(player_t *player) // Capture the screen for intermission and screen waving if (gamestate != GS_INTERMISSION) - HWD.pfnMakeScreenTexture(HWD_SCREENTEXTURE_GENERIC1); + GL_MakeScreenTexture(HWD_SCREENTEXTURE_GENERIC1); if (splitscreen) // Not supported in splitscreen - someone want to add support? return; @@ -5767,28 +5780,28 @@ static void HWR_DoPostProcessor(player_t *player) v[x][y][1] = (y/((float)(SCREENVERTS-1.0f)/9.0f))-4.5f; } } - HWD.pfnPostImgRedraw(v); + GL_PostImgRedraw(v); // Capture the screen again for screen waving on the intermission if (gamestate != GS_INTERMISSION) - HWD.pfnMakeScreenTexture(HWD_SCREENTEXTURE_GENERIC1); + GL_MakeScreenTexture(HWD_SCREENTEXTURE_GENERIC1); } // Flipping of the screen isn't done here anymore } void HWR_StartScreenWipe(void) { - HWD.pfnMakeScreenTexture(HWD_SCREENTEXTURE_WIPE_START); + GL_MakeScreenTexture(HWD_SCREENTEXTURE_WIPE_START); } void HWR_EndScreenWipe(void) { - HWD.pfnMakeScreenTexture(HWD_SCREENTEXTURE_WIPE_END); + GL_MakeScreenTexture(HWD_SCREENTEXTURE_WIPE_END); } void HWR_DrawIntermissionBG(void) { - HWD.pfnDrawScreenTexture(HWD_SCREENTEXTURE_GENERIC1, NULL, 0); + GL_DrawScreenTexture(HWD_SCREENTEXTURE_GENERIC1, NULL, 0); } void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum) @@ -5822,22 +5835,22 @@ void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum) } HWR_GetFadeMask(lumpnum); - HWD.pfnDoScreenWipe(HWD_SCREENTEXTURE_WIPE_START, HWD_SCREENTEXTURE_WIPE_END); + GL_DoScreenWipe(HWD_SCREENTEXTURE_WIPE_START, HWD_SCREENTEXTURE_WIPE_END); } void HWR_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize) { - HWD.pfnRenderVhsEffect(upbary, downbary, updistort, downdistort, barsize); + GL_RenderVhsEffect(upbary, downbary, updistort, downdistort, barsize); } void HWR_MakeScreenFinalTexture(void) { - HWD.pfnMakeScreenTexture(HWD_SCREENTEXTURE_GENERIC2); + GL_MakeScreenTexture(HWD_SCREENTEXTURE_GENERIC2); } void HWR_DrawScreenFinalTexture(INT32 width, INT32 height, boolean useshader) { - HWD.pfnDrawScreenFinalTexture(HWD_SCREENTEXTURE_GENERIC2, width, height, useshader); + GL_DrawScreenFinalTexture(HWD_SCREENTEXTURE_GENERIC2, width, height, useshader); } #endif // HWRENDER diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 3de86bbda..c21823a36 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -25,12 +25,14 @@ #include "../doomstat.h" #ifdef HWRENDER -#include "hw_drv.h" + +#include "hw_gl.h" #include "hw_md2.h" #include "../d_main.h" #include "../r_bsp.h" #include "../r_fps.h" #include "../r_main.h" +#include "../p_setup.h" #include "../m_misc.h" #include "../w_wad.h" #include "../z_zone.h" @@ -43,8 +45,8 @@ #include "hw_main.h" #include "../v_video.h" -#ifdef HAVE_PNG +#ifdef HAVE_PNG #ifndef _MSC_VER #ifndef _LARGEFILE64_SOURCE #define _LARGEFILE64_SOURCE @@ -417,7 +419,7 @@ static void md2_loadTexture(md2_t *model) } } } - HWD.pfnSetTexture(glpatch->mipmap); + GL_SetTexture(glpatch->mipmap); HWR_UnlockCachedPatch(glpatch); } @@ -467,7 +469,7 @@ static void md2_loadBlendTexture(md2_t *model) glpatch->mipmap->width = (UINT16)w; glpatch->mipmap->height = (UINT16)h; } - HWD.pfnSetTexture(glpatch->mipmap); // We do need to do this so that it can be cleared and knows to recreate it when necessary + GL_SetTexture(glpatch->mipmap); // We do need to do this so that it can be cleared and knows to recreate it when necessary HWR_UnlockCachedPatch(glpatch); Z_Free(filename); @@ -1048,7 +1050,7 @@ static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, INT if (colormap == colormaps || colormap == NULL) { // Don't do any blending - HWD.pfnSetTexture(gpatch->mipmap); + GL_SetTexture(gpatch->mipmap); return; } @@ -1063,7 +1065,7 @@ static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, INT if (glMipmap->downloaded && glMipmap->data) { - HWD.pfnSetTexture(glMipmap); // found the colormap, set it to the correct texture + GL_SetTexture(glMipmap); // found the colormap, set it to the correct texture Z_ChangeTag(glMipmap->data, PU_HWRCACHE_UNLOCKED); return; } @@ -1084,7 +1086,7 @@ static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, INT HWR_CreateBlendedTexture(gpatch, blendgpatch, newMipmap, skinnum, color); - HWD.pfnSetTexture(newMipmap); + GL_SetTexture(newMipmap); Z_ChangeTag(newMipmap->data, PU_HWRCACHE_UNLOCKED); } @@ -1233,7 +1235,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr) if (md2->model) { md2_printModelInfo(md2->model); - HWD.pfnCreateModelVBOs(md2->model); + GL_CreateModelVBOs(md2->model); } else { @@ -1288,7 +1290,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr) else { // This is safe, since we know the texture has been downloaded - HWD.pfnSetTexture(gpatch->mipmap); + GL_SetTexture(gpatch->mipmap); } } else @@ -1461,7 +1463,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr) p.mirror = atransform.mirror; // from Kart #endif - HWD.pfnSetShader(SHADER_MODEL); // model shader + GL_SetShader(SHADER_MODEL); // model shader { SINT8 flipfactor = flip ? -1 : 1; @@ -1478,7 +1480,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr) p.y += ox * gl_viewcos; p.z += oy; - HWD.pfnDrawModel(md2->model, frame, durs, tics, nextFrame, &p, md2->scale * xs, md2->scale * ys, flip, hflip, &Surf); + GL_DrawModel(md2->model, frame, durs, tics, nextFrame, &p, md2->scale * xs, md2->scale * ys, flip, hflip, &Surf); } } } diff --git a/src/hardware/hw_portal.c b/src/hardware/hw_portal.c index 120e59e6c..f26e71331 100644 --- a/src/hardware/hw_portal.c +++ b/src/hardware/hw_portal.c @@ -23,7 +23,7 @@ #include "../z_zone.h" #include "hw_clip.h" -#include "hw_drv.h" +#include "hw_gl.h" #include "hw_defs.h" #include "hw_main.h" #include "hw_portal.h" @@ -153,7 +153,7 @@ static void HWR_RenderPortalSeg(gl_portal_t* portal, SINT8 state) // need to work around the r_opengl PF_Invisible bug with this call // similarly as in the linkdraw hack in HWR_DrawSprites - HWD.pfnSetBlend(PF_Translucent|PF_Occlude|PF_Masked); + GL_SetBlend(PF_Translucent|PF_Occlude|PF_Masked); } // Renders a single portal from the current viewpoint. diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index d73efaa37..31ee2c066 100644 --- a/src/hardware/hw_shaders.c +++ b/src/hardware/hw_shaders.c @@ -13,7 +13,7 @@ #include "hw_main.h" #include "hw_glob.h" -#include "hw_drv.h" +#include "hw_gl.h" #include "hw_shaders.h" #include "../z_zone.h" @@ -87,7 +87,7 @@ boolean HWR_InitShaders(void) { int i; - if (!HWD.pfnInitShaders()) + if (!GL_InitShaders()) return false; for (i = 0; i < NUMSHADERTARGETS; i++) @@ -366,16 +366,16 @@ static void HWR_CompileShader(int index) { char *preprocessed = HWR_PreprocessShader(vertex_source); if (!preprocessed) return; - HWD.pfnLoadShader(index, preprocessed, HWD_SHADERSTAGE_VERTEX); + GL_LoadShader(index, preprocessed, HWD_SHADERSTAGE_VERTEX); } if (fragment_source) { char *preprocessed = HWR_PreprocessShader(fragment_source); if (!preprocessed) return; - HWD.pfnLoadShader(index, preprocessed, HWD_SHADERSTAGE_FRAGMENT); + GL_LoadShader(index, preprocessed, HWD_SHADERSTAGE_FRAGMENT); } - gl_shaders[index].compiled = HWD.pfnCompileShader(index); + gl_shaders[index].compiled = GL_CompileShader(index); } // compile or recompile shaders diff --git a/src/hardware/hw_shaders.h b/src/hardware/hw_shaders.h index b540d4ac3..9826ba06f 100644 --- a/src/hardware/hw_shaders.h +++ b/src/hardware/hw_shaders.h @@ -99,6 +99,7 @@ GLSL_DOOM_COLORMAP_NODITHER \ "#endif\n" \ "}\n" + // lighting cap adjustment: // first num (155.0), increase to make it start to go dark sooner // second num (0.26), increase to make it go dark faster diff --git a/src/hardware/r_opengl/ogl_win.c b/src/hardware/r_opengl/ogl_win.c index 8ce44d788..e819e0f68 100644 --- a/src/hardware/r_opengl/ogl_win.c +++ b/src/hardware/r_opengl/ogl_win.c @@ -358,8 +358,8 @@ static INT32 WINAPI SetRes(viddef_t *lvid, vmode_t *pcurrentmode) else textureformatGL = GL_RGB5_A1; - SetModelView(lvid->width, lvid->height); - SetStates(); + GL_SetModelView(lvid->width, lvid->height); + GL_SetStates(); // we need to clear the depth buffer. Very important!!! pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); @@ -526,7 +526,7 @@ EXPORT void HWRAPI(Shutdown) (void) // -----------------+ // FinishUpdate : Swap front and back buffers // -----------------+ -EXPORT void HWRAPI(FinishUpdate) (INT32 waitvbl) +void GL_FinishUpdate (INT32 waitvbl) { #ifdef USE_WGL_SWAP static INT32 oldwaitvbl = 0; @@ -547,23 +547,4 @@ EXPORT void HWRAPI(FinishUpdate) (INT32 waitvbl) SwapBuffers(hDC); } - - -// -----------------+ -// SetPalette : Set the color lookup table for paletted textures -// : in OpenGL, we store values for conversion of paletted graphics when -// : they are downloaded to the 3D card. -// -----------------+ -EXPORT void HWRAPI(SetPalette) (RGBA_t *pal) -{ - INT32 i; - - for (i = 0; i < 256; i++) - { - myPaletteData[i].s.red = pal[i].s.red; - myPaletteData[i].s.green = pal[i].s.green; - myPaletteData[i].s.blue = pal[i].s.blue; - myPaletteData[i].s.alpha = pal[i].s.alpha; - } -} #endif diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index f411f9202..72bb34e61 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -40,8 +40,6 @@ #include "../../r_local.h" // For rendertimefrac, used for the leveltime shader uniform #include "../../i_video.h" -extern fixed_t fovtan; // also extremely bad, I'm just too lazy!!! - struct GLRGBAFloat { GLfloat red; @@ -708,8 +706,8 @@ static gl_shaderstate_t gl_shaderstate; static float shader_leveltime = 0; // Lactozilla: Shader functions -static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i); -static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAFloat *tint, GLRGBAFloat *fade); +static boolean GL_Shader_CompileProgram(gl_shader_t *shader, GLint i); +static void GL_Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAFloat *tint, GLRGBAFloat *fade); static GLRGBAFloat shader_defaultcolor = {1.0f, 1.0f, 1.0f, 1.0f}; @@ -721,7 +719,7 @@ static boolean GLFramebuffer_CheckExt(void) return false; // check if all needed gl extensions are available - return (isExtAvailable("GL_ARB_framebuffer_no_attachments", gl_extensions) && isExtAvailable("GL_ARB_framebuffer_object", gl_extensions) && isExtAvailable("GL_ARB_framebuffer_sRGB", gl_extensions)); + return (GL_isExtAvailable("GL_ARB_framebuffer_no_attachments", gl_extensions) && GL_isExtAvailable("GL_ARB_framebuffer_object", gl_extensions) && GL_isExtAvailable("GL_ARB_framebuffer_sRGB", gl_extensions)); } #endif @@ -793,7 +791,7 @@ void SetupGLFunc4(void) #endif } -EXPORT boolean HWRAPI(InitShaders) (void) +boolean GL_InitShaders(void) { if (!pglUseProgram) return false; @@ -801,7 +799,7 @@ EXPORT boolean HWRAPI(InitShaders) (void) gl_fallback_shader.vertex_shader = Z_StrDup(GLSL_FALLBACK_VERTEX_SHADER); gl_fallback_shader.fragment_shader = Z_StrDup(GLSL_FALLBACK_FRAGMENT_SHADER); - if (!Shader_CompileProgram(&gl_fallback_shader, -1)) + if (!GL_Shader_CompileProgram(&gl_fallback_shader, -1)) { GL_MSG_Error("Failed to compile the fallback shader program!\n"); return false; @@ -810,7 +808,7 @@ EXPORT boolean HWRAPI(InitShaders) (void) return true; } -EXPORT void HWRAPI(LoadShader) (int slot, char *code, hwdshaderstage_t stage) +void GL_LoadShader(int slot, char *code, hwdshaderstage_t stage) { gl_shader_t *shader; @@ -835,12 +833,12 @@ EXPORT void HWRAPI(LoadShader) (int slot, char *code, hwdshaderstage_t stage) #undef LOADSHADER } -EXPORT boolean HWRAPI(CompileShader) (int slot) +boolean GL_CompileShader(int slot) { if (slot < 0 || slot >= HWR_MAXSHADERS) I_Error("CompileShader: Invalid slot %d", slot); - if (Shader_CompileProgram(&gl_shaders[slot], slot)) + if (GL_Shader_CompileProgram(&gl_shaders[slot], slot)) { return true; } @@ -856,7 +854,7 @@ EXPORT boolean HWRAPI(CompileShader) (int slot) // Those are given to the uniforms. // -EXPORT void HWRAPI(SetShaderInfo) (hwdshaderinfo_t info, INT32 value) +void GL_SetShaderInfo(hwdshaderinfo_t info, INT32 value) { switch (info) { @@ -868,11 +866,11 @@ EXPORT void HWRAPI(SetShaderInfo) (hwdshaderinfo_t info, INT32 value) } } -EXPORT void HWRAPI(SetShader) (int slot) +void GL_SetShader(int slot) { if (slot == SHADER_NONE) { - UnSetShader(); + GL_UnSetShader(); return; } if (gl_allowshaders) @@ -899,7 +897,7 @@ EXPORT void HWRAPI(SetShader) (int slot) gl_shadersenabled = false; } -EXPORT void HWRAPI(UnSetShader) (void) +void GL_UnSetShader(void) { if (gl_shadersenabled) // don't repeatedly call glUseProgram if not needed { @@ -918,10 +916,10 @@ EXPORT void HWRAPI(UnSetShader) (void) // -----------------+ // SetNoTexture : Disable texture // -----------------+ -static void SetNoTexture(void) +static void GL_SetNoTexture(void) { // Disable texture. - if (tex_downloaded != NOTEXTURE_NUM) + if (tex_downloaded != NOTEXTURE_NUM && !currently_batching) { if (NOTEXTURE_NUM == 0) pglGenTextures(1, &NOTEXTURE_NUM); @@ -930,7 +928,10 @@ static void SetNoTexture(void) } } -static void GLPerspective(GLfloat fovy, GLfloat aspect) +// -----------------+ +// Perspective : +// -----------------+ +static void GL_Perspective(GLfloat fovy, GLfloat aspect) { GLfloat m[4][4] = { @@ -959,7 +960,7 @@ static void GLPerspective(GLfloat fovy, GLfloat aspect) // -----------------+ // SetModelView : // -----------------+ -void SetModelView(GLint w, GLint h) +void GL_SetModelView(GLint w, GLint h) { //GL_DBG_Printf("SetModelView(): %dx%d\n", (int)w, (int)h); @@ -971,7 +972,7 @@ void SetModelView(GLint w, GLint h) pglMatrixMode(GL_MODELVIEW); pglLoadIdentity(); - GLPerspective(fov, ASPECT_RATIO); + GL_Perspective(fov, ASPECT_RATIO); // added for new coronas' code (without depth buffer) pglGetIntegerv(GL_VIEWPORT, viewport); @@ -981,7 +982,7 @@ void SetModelView(GLint w, GLint h) // -----------------+ // SetStates : Set permanent states // -----------------+ -void SetStates(void) +void GL_SetStates(void) { pglEnable(GL_TEXTURE_2D); // two-dimensional texturing pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); @@ -1001,10 +1002,10 @@ void SetStates(void) // this set CurrentPolyFlags to the actual configuration CurrentPolyFlags = 0xffffffff; - SetBlend(0); + GL_SetBlend(0); tex_downloaded = 0; - SetNoTexture(); + GL_SetNoTexture(); pglPolygonOffset(-1.0f, -1.0f); @@ -1017,7 +1018,7 @@ void SetStates(void) // -----------------+ // DeleteTexture : Deletes a texture from the GPU and frees its data // -----------------+ -EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *pTexInfo) +void GL_DeleteTexture(GLMipmap_t *pTexInfo) { FTextureInfo *head = TexCacheHead; @@ -1049,7 +1050,7 @@ EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *pTexInfo) } #ifdef USE_FBO_OGL -static void GLFramebuffer_GenerateAttachments(void) +static void GL_Framebuffer_GenerateAttachments(void) { if (!supportFBO || !UseScreenFBO()) return; @@ -1081,7 +1082,7 @@ static void GLFramebuffer_GenerateAttachments(void) pglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, RenderbufferObject); // Clear the renderbuffer - ClearBuffer(true, true, true, NULL); + GL_ClearBuffer(true, true, true, NULL); pglBindRenderbuffer(GL_RENDERBUFFER, 0); } @@ -1092,7 +1093,7 @@ static void GLFramebuffer_GenerateAttachments(void) fboinit = true; } -void GLFramebuffer_DeleteAttachments(void) +void GL_Framebuffer_DeleteAttachments(void) { if (!supportFBO || fboinit == false) return; @@ -1115,7 +1116,7 @@ void GLFramebuffer_DeleteAttachments(void) fboinit = false; } -static void GLFramebuffer_Generate(void) +static void GL_Framebuffer_Generate(void) { if (!supportFBO || !UseScreenFBO()) return; @@ -1125,10 +1126,10 @@ static void GLFramebuffer_Generate(void) pglGenFramebuffers(1, &FramebufferObject); if (pglCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE) - GLFramebuffer_GenerateAttachments(); + GL_Framebuffer_GenerateAttachments(); } -static void GLFramebuffer_Delete(void) +static void GL_Framebuffer_Delete(void) { if (!supportFBO || fboinit == false) return; @@ -1136,11 +1137,11 @@ static void GLFramebuffer_Delete(void) if (FramebufferObject) pglDeleteFramebuffers(1, &FramebufferObject); - GLFramebuffer_DeleteAttachments(); + GL_Framebuffer_DeleteAttachments(); FramebufferObject = 0; } -inline void GLFramebuffer_Unbind(void) +inline void GL_Framebuffer_Unbind(void) { if (!supportFBO || fboinit == false) return; @@ -1152,21 +1153,21 @@ inline void GLFramebuffer_Unbind(void) pglBindRenderbuffer(GL_RENDERBUFFER, 0); } -inline void GLFramebuffer_Enable(void) +inline void GL_Framebuffer_Enable(void) { if (!supportFBO || !UseScreenFBO()) return; if (FramebufferObject == 0) - GLFramebuffer_Generate(); + GL_Framebuffer_Generate(); else if (FramebufferTexture == 0 || RenderbufferObject == 0) - GLFramebuffer_GenerateAttachments(); + GL_Framebuffer_GenerateAttachments(); pglBindFramebuffer(GL_FRAMEBUFFER, FramebufferObject); pglBindRenderbuffer(GL_RENDERBUFFER, RenderbufferObject); } -void GLFramebuffer_Disable(void) +void GL_Framebuffer_Disable(void) { if (!supportFBO || fboinit == false) return; @@ -1177,7 +1178,7 @@ void GLFramebuffer_Disable(void) pglBindFramebuffer(GL_FRAMEBUFFER, 0); pglBindRenderbuffer(GL_RENDERBUFFER, 0); - GLFramebuffer_Delete(); + GL_Framebuffer_Delete(); } #endif @@ -1185,7 +1186,7 @@ void GLFramebuffer_Disable(void) // Flush : flush OpenGL textures // : Clear list of downloaded mipmaps // -----------------+ -void Flush(void) +void GL_Flush(void) { while (TexCacheHead) { @@ -1217,7 +1218,7 @@ void Flush(void) // isExtAvailable : Look if an OpenGL extension is available // Returns : true if extension available // -----------------+ -INT32 isExtAvailable(const char *extension, const GLubyte *start) +INT32 GL_isExtAvailable(const char *extension, const GLubyte *start) { GLubyte *where, *terminator; @@ -1244,34 +1245,25 @@ INT32 isExtAvailable(const char *extension, const GLubyte *start) // Init : Initialise the OpenGL interface API // Returns : // -----------------+ -EXPORT boolean HWRAPI(Init) (void) +boolean GL_Init (void) { - return LoadGL(); + return SetupGLfunc(); } // -----------------+ // SetupGLInfo : Retreive and store currently loaded OpenGL version // -----------------+ -EXPORT void HWRAPI(SetupGLInfo) (void) +void SetupGLInfo(void) { const GLubyte *versionGL = pglGetString(GL_VERSION); CONS_Printf("Loaded OpenGL version %s\n", (const char*)versionGL); sscanf((const char*)versionGL, "%d.%d", &majorGL, &minorGL); } - -// -----------------+ -// ClearMipMapCache : Flush OpenGL textures from memory -// -----------------+ -EXPORT void HWRAPI(ClearMipMapCache) (void) -{ - Flush(); -} - // Writes screen texture tex into dst_data. // Pixel format is 24-bit RGB. Row order is top to bottom. // Dimensions are screen_width * screen_height. -EXPORT void HWRAPI(ReadScreenTexture) (int tex, UINT16 *dst_data) +void GL_ReadScreenTexture(int tex, UINT16 *dst_data) { INT32 i; int dst_stride = screen_width * 3; // stride between rows of image data @@ -1284,11 +1276,11 @@ EXPORT void HWRAPI(ReadScreenTexture) (int tex, UINT16 *dst_data) // and draw generic2 back after reading the framebuffer. // this hack is for some reason **much** faster than the simple solution of using glGetTexImage. if (tex != HWD_SCREENTEXTURE_GENERIC2) - DrawScreenTexture(tex, NULL, 0); + GL_DrawScreenTexture(tex, NULL, 0); pglPixelStorei(GL_PACK_ALIGNMENT, 1); pglReadPixels(0, 0, screen_width, screen_height, GL_RGB, GL_UNSIGNED_BYTE, dst_data); if (tex != HWD_SCREENTEXTURE_GENERIC2) - DrawScreenTexture(HWD_SCREENTEXTURE_GENERIC2, NULL, 0); + GL_DrawScreenTexture(HWD_SCREENTEXTURE_GENERIC2, NULL, 0); // Flip image upside down. // In other words, convert OpenGL's "bottom->top" row order into "top->bottom". for(i = 0; i < screen_height/2; i++) @@ -1302,10 +1294,25 @@ EXPORT void HWRAPI(ReadScreenTexture) (int tex, UINT16 *dst_data) free(row); } +// -----------------+ +// SetPalette : Changes the current texture palette +// -----------------+ +void GL_SetPalette(RGBA_t *palette) +{ + INT32 i; + + for (i = 0; i < 256; i++) + { + myPaletteData[i].s = palette[i].s; + } + + GL_Flush(); +} + // -----------------+ // GClipRect : Defines the 2D hardware clipping window // -----------------+ -EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip, float farclip) +void GL_GClipRect(INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip, float farclip) { //GL_DBG_Printf("GClipRect(%d, %d, %d, %d)\n", minx, miny, maxx, maxy); @@ -1316,7 +1323,7 @@ EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, f //pglScissor(minx, screen_height-maxy, maxx-minx, maxy-miny); pglMatrixMode(GL_PROJECTION); pglLoadIdentity(); - GLPerspective(fov, ASPECT_RATIO); + GL_Perspective(fov, ASPECT_RATIO); pglMatrixMode(GL_MODELVIEW); // added for new coronas' code (without depth buffer) @@ -1328,10 +1335,7 @@ EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, f // -----------------+ // ClearBuffer : Clear the color/alpha/depth buffer(s) // -----------------+ -EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, - FBOOLEAN DepthMask, - FBOOLEAN StencilMask, - FRGBAFloat * ClearColor) +void GL_ClearBuffer(FBOOLEAN ColorMask, FBOOLEAN DepthMask, FBOOLEAN StencilMask, FRGBAFloat * ClearColor) { //GL_DBG_Printf("ClearBuffer(%d)\n", alpha); GLbitfield ClearMask = 0; @@ -1353,7 +1357,7 @@ EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, ClearMask |= GL_DEPTH_BUFFER_BIT; } - SetBlend(DepthMask ? PF_Occlude | CurrentPolyFlags : CurrentPolyFlags&~PF_Occlude); + GL_SetBlend(DepthMask ? PF_Occlude | CurrentPolyFlags : CurrentPolyFlags&~PF_Occlude); if (StencilMask) ClearMask |= GL_STENCIL_BUFFER_BIT;// looks like sometimes stencil buffer needs clearing? had a problem with random black screens @@ -1366,9 +1370,7 @@ EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, // -----------------+ // HWRAPI Draw2DLine: Render a 2D line // -----------------+ -EXPORT void HWRAPI(Draw2DLine) (F2DCoord * v1, - F2DCoord * v2, - RGBA_t Color) +void GL_Draw2DLine(F2DCoord * v1, F2DCoord * v2, RGBA_t Color) { //GL_DBG_Printf("DrawLine(): %f %f, %f %f\n", v1->x, v1->y, v2->x, v2->y); GLfloat p[12]; @@ -1415,141 +1417,150 @@ static void Clamp2D(GLenum pname) // -----------------+ // PF_Masked - we could use an ALPHA_TEST of GL_EQUAL, and alpha ref of 0, // is it faster when pixels are discarded ? -EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags) +void GL_SetBlend(FBITFIELD PolyFlags) { - FBITFIELD Xor; - Xor = CurrentPolyFlags^PolyFlags; - if (Xor & (PF_Blending|PF_RemoveYWrap|PF_ForceWrapX|PF_ForceWrapY|PF_Occlude|PF_NoTexture|PF_Modulated|PF_NoDepthTest|PF_Decal|PF_Invisible|PF_NoAlphaTest)) + const FBITFIELD Xor = (CurrentPolyFlags ^ PolyFlags); + + if (!(Xor & (PF_Blending|PF_RemoveYWrap|PF_ForceWrapX|PF_ForceWrapY|PF_Occlude|PF_NoTexture|PF_Modulated|PF_NoDepthTest|PF_Decal|PF_Invisible|PF_NoAlphaTest))) { - if (Xor&(PF_Blending)) // if blending mode must be changed - { - switch (PolyFlags & PF_Blending) { - case PF_Translucent & PF_Blending: - pglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // alpha = level of transparency - pglAlphaFunc(GL_NOTEQUAL, 0.0f); - break; - case PF_Masked & PF_Blending: - // Hurdler: does that mean lighting is only made by alpha src? - // it sounds ok, but not for polygonsmooth - pglBlendFunc(GL_SRC_ALPHA, GL_ZERO); // 0 alpha = holes in texture - pglAlphaFunc(GL_GREATER, 0.5f); - break; - case PF_Additive & PF_Blending: - pglBlendFunc(GL_SRC_ALPHA, GL_ONE); // src * alpha + dest - pglAlphaFunc(GL_NOTEQUAL, 0.0f); - break; - case PF_Environment & PF_Blending: - pglBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - pglAlphaFunc(GL_NOTEQUAL, 0.0f); - break; - case PF_Substractive & PF_Blending: - // good for shadow - // not really but what else ? - pglBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR); - pglAlphaFunc(GL_NOTEQUAL, 0.0f); - break; - case PF_Fog & PF_Fog: - // Sryder: Fog - // multiplies input colour by input alpha, and destination colour by input colour, then adds them - pglBlendFunc(GL_SRC_ALPHA, GL_SRC_COLOR); - pglAlphaFunc(GL_ALWAYS, 0.0f); // Don't discard zero alpha fragments - break; - default : // must be 0, otherwise it's an error - // No blending - pglBlendFunc(GL_ONE, GL_ZERO); // the same as no blending - pglAlphaFunc(GL_GREATER, 0.5f); - break; - } - } - if (Xor & PF_NoAlphaTest) - { - if (PolyFlags & PF_NoAlphaTest) - pglDisable(GL_ALPHA_TEST); - else - pglEnable(GL_ALPHA_TEST); // discard 0 alpha pixels (holes in texture) - } + CurrentPolyFlags = PolyFlags; + return; + } - if (Xor & PF_Decal) + if (Xor & PF_Blending) // if blending mode must be changed + { + switch (PolyFlags & PF_Blending) { - if (PolyFlags & PF_Decal) - pglEnable(GL_POLYGON_OFFSET_FILL); - else - pglDisable(GL_POLYGON_OFFSET_FILL); - } - if (Xor&PF_NoDepthTest) - { - if (PolyFlags & PF_NoDepthTest) - pglDepthFunc(GL_ALWAYS); //pglDisable(GL_DEPTH_TEST); - else - pglDepthFunc(GL_LEQUAL); //pglEnable(GL_DEPTH_TEST); + case (PF_Translucent & PF_Blending): + pglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // alpha = level of transparency + pglAlphaFunc(GL_NOTEQUAL, 0.0f); + break; + case (PF_Masked & PF_Blending): + // Hurdler: does that mean lighting is only made by alpha src? + // it sounds ok, but not for polygonsmooth + pglBlendFunc(GL_SRC_ALPHA, GL_ZERO); // 0 alpha = holes in texture + pglAlphaFunc(GL_GREATER, 0.5f); + break; + case (PF_Additive & PF_Blending): + pglBlendFunc(GL_SRC_ALPHA, GL_ONE); // src * alpha + dest + pglAlphaFunc(GL_NOTEQUAL, 0.0f); + break; + case (PF_Environment & PF_Blending): + pglBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + pglAlphaFunc(GL_NOTEQUAL, 0.0f); + break; + case (PF_Substractive & PF_Blending): + // good for shadow + // not really but what else ? + pglBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR); + pglAlphaFunc(GL_NOTEQUAL, 0.0f); + break; + case (PF_Fog & PF_Fog): + // Sryder: Fog + // multiplies input colour by input alpha, and destination colour by input colour, then adds them + pglBlendFunc(GL_SRC_ALPHA, GL_SRC_COLOR); + pglAlphaFunc(GL_ALWAYS, 0.0f); // Don't discard zero alpha fragments + break; + default : // must be 0, otherwise it's an error + // No blending + pglBlendFunc(GL_ONE, GL_ZERO); // the same as no blending + pglAlphaFunc(GL_GREATER, 0.5f); + break; } + } - if (Xor&PF_RemoveYWrap) - { - if (PolyFlags & PF_RemoveYWrap) - Clamp2D(GL_TEXTURE_WRAP_T); - } + if (Xor & PF_NoAlphaTest) + { + if (PolyFlags & PF_NoAlphaTest) + pglDisable(GL_ALPHA_TEST); + else + pglEnable(GL_ALPHA_TEST); // discard 0 alpha pixels (holes in texture) + } - if (Xor&PF_ForceWrapX) - { - if (PolyFlags & PF_ForceWrapX) - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - } + if (Xor & PF_Decal) + { + if (PolyFlags & PF_Decal) + pglEnable(GL_POLYGON_OFFSET_FILL); + else + pglDisable(GL_POLYGON_OFFSET_FILL); + } + if (Xor & PF_NoDepthTest) + { + if (PolyFlags & PF_NoDepthTest) + pglDepthFunc(GL_ALWAYS); //pglDisable(GL_DEPTH_TEST); + else + pglDepthFunc(GL_LEQUAL); //pglEnable(GL_DEPTH_TEST); + } - if (Xor&PF_ForceWrapY) - { - if (PolyFlags & PF_ForceWrapY) - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - } + if (Xor & PF_RemoveYWrap) + { + if (PolyFlags & PF_RemoveYWrap) + Clamp2D(GL_TEXTURE_WRAP_T); + } - if (Xor&PF_Modulated) - { + if (Xor & PF_ForceWrapX) + { + if (PolyFlags & PF_ForceWrapX) + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + } + + if (Xor & PF_ForceWrapY) + { + if (PolyFlags & PF_ForceWrapY) + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + } + + if (Xor & PF_Modulated) + { #if defined (__unix__) || defined (UNIXCOMMON) - if (oglflags & GLF_NOTEXENV) - { - if (!(PolyFlags & PF_Modulated)) - pglColor4ubv(white); - } - else + if (oglflags & GLF_NOTEXENV) + { + if (!(PolyFlags & PF_Modulated)) + pglColor4ubv(white); + } + else #endif - // mix texture colour with Surface->PolyColor - if (PolyFlags & PF_Modulated) - pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - // colour from texture is unchanged before blending - else - pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - } - - if (Xor & PF_Occlude) // depth test but (no) depth write - { - if (PolyFlags&PF_Occlude) - pglDepthMask(1); - else - pglDepthMask(0); - } - ////Hurdler: not used if we don't define POLYSKY - if (Xor & PF_Invisible) - { - if (PolyFlags&PF_Invisible) - pglBlendFunc(GL_ZERO, GL_ONE); // transparent blending - else - { // big hack: (TODO: manage that better) - // we test only for PF_Masked because PF_Invisible is only used - // (for now) with it (yeah, that's crappy, sorry) - if ((PolyFlags&PF_Blending)==PF_Masked) - pglBlendFunc(GL_SRC_ALPHA, GL_ZERO); - } - } - if (PolyFlags & PF_NoTexture) - SetNoTexture(); + // mix texture colour with Surface->PolyColor + if (PolyFlags & PF_Modulated) + pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + // colour from texture is unchanged before blending + else + pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); } + + if (Xor & PF_Occlude) // depth test but (no) depth write + { + if (PolyFlags & PF_Occlude) + pglDepthMask(1); + else + pglDepthMask(0); + } + + ////Hurdler: not used if we don't define POLYSKY + if (Xor & PF_Invisible) + { + if (PolyFlags&PF_Invisible) + pglBlendFunc(GL_ZERO, GL_ONE); // transparent blending + else + { // big hack: (TODO: manage that better) + // we test only for PF_Masked because PF_Invisible is only used + // (for now) with it (yeah, that's crappy, sorry) + if ((PolyFlags & PF_Blending) == PF_Masked) + pglBlendFunc(GL_SRC_ALPHA, GL_ZERO); + } + } + + if (PolyFlags & PF_NoTexture) + GL_SetNoTexture(); + CurrentPolyFlags = PolyFlags; } -static void AllocTextureBuffer(GLMipmap_t *pTexInfo) +static void GL_AllocTextureBuffer(GLMipmap_t *pTexInfo) { size_t size = pTexInfo->width * pTexInfo->height; + if (size > textureBufferSize) { textureBuffer = realloc(textureBuffer, size * sizeof(RGBA_t)); @@ -1562,7 +1573,7 @@ static void AllocTextureBuffer(GLMipmap_t *pTexInfo) // -----------------+ // UpdateTexture : Updates texture data. // -----------------+ -EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo) +static void GL_UpdateTexture(GLMipmap_t *pTexInfo) { // Upload a texture GLuint num = pTexInfo->downloaded; @@ -1574,7 +1585,9 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo) const GLubyte *pImgData = (const GLubyte *)pTexInfo->data; const GLvoid *ptex = NULL; RGBA_t *tex = NULL; - + + GLint texformat = 0; + // Generate a new texture name. if (!num) { @@ -1585,91 +1598,103 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo) //GL_DBG_Printf("UpdateTexture %d %x\n", (INT32)num, pImgData); - if ((pTexInfo->format == GL_TEXFMT_P_8) || (pTexInfo->format == GL_TEXFMT_AP_88)) + texformat = textureformatGL; + + switch (pTexInfo->format) { - AllocTextureBuffer(pTexInfo); - ptex = tex = textureBuffer; + case GL_TEXFMT_P_8: + case GL_TEXFMT_AP_88: + GL_AllocTextureBuffer(pTexInfo); + ptex = tex = textureBuffer; - for (j = 0; j < h; j++) - { - for (i = 0; i < w; i++) + const int chromakeyed = (pTexInfo->flags & TF_CHROMAKEYED); + + for (j = 0; j < h; j++) { - if ((*pImgData == HWR_PATCHES_CHROMAKEY_COLORINDEX) && - (pTexInfo->flags & TF_CHROMAKEYED)) + for (i = 0; i < w; i++) { - tex[w*j+i].s.red = 0; - tex[w*j+i].s.green = 0; - tex[w*j+i].s.blue = 0; - tex[w*j+i].s.alpha = 0; - pTexInfo->flags |= TF_TRANSPARENT; // there is a hole in it - } - else - { - tex[w*j+i].s.red = myPaletteData[*pImgData].s.red; - tex[w*j+i].s.green = myPaletteData[*pImgData].s.green; - tex[w*j+i].s.blue = myPaletteData[*pImgData].s.blue; - tex[w*j+i].s.alpha = myPaletteData[*pImgData].s.alpha; - } + int idx = (w*j+i); - pImgData++; + if (chromakeyed && (*pImgData == HWR_PATCHES_CHROMAKEY_COLORINDEX)) + { + tex[idx].s.red = 0; + tex[idx].s.green = 0; + tex[idx].s.blue = 0; + tex[idx].s.alpha = 0; + pTexInfo->flags |= TF_TRANSPARENT; // there is a hole in it + } + else + { + tex[idx].s = myPaletteData[*pImgData].s; + } - if (pTexInfo->format == GL_TEXFMT_AP_88) - { - if (!(pTexInfo->flags & TF_CHROMAKEYED)) - tex[w*j+i].s.alpha = *pImgData; + pImgData++; + + if (pTexInfo->format != GL_TEXFMT_AP_88) + continue; + if (chromakeyed) + continue; + + tex[idx].s.alpha = *pImgData; pImgData++; } } - } - } - else if (pTexInfo->format == GL_TEXFMT_RGBA) - { - // Directly upload the texture data without any kind of conversion. - ptex = pImgData; - } - else if (pTexInfo->format == GL_TEXFMT_ALPHA_INTENSITY_88) - { - AllocTextureBuffer(pTexInfo); - ptex = tex = textureBuffer; + break; + case GL_TEXFMT_RGBA: + // Directly upload the texture data without any kind of conversion. + ptex = pImgData; + break; + case GL_TEXFMT_ALPHA_INTENSITY_88: + GL_AllocTextureBuffer(pTexInfo); + ptex = tex = textureBuffer; + texformat = GL_LUMINANCE_ALPHA; - for (j = 0; j < h; j++) - { - for (i = 0; i < w; i++) + for (j = 0; j < h; j++) { - tex[w*j+i].s.red = *pImgData; - tex[w*j+i].s.green = *pImgData; - tex[w*j+i].s.blue = *pImgData; - pImgData++; - tex[w*j+i].s.alpha = *pImgData; - pImgData++; - } - } - } - else if (pTexInfo->format == GL_TEXFMT_ALPHA_8) // Used for fade masks - { - AllocTextureBuffer(pTexInfo); - ptex = tex = textureBuffer; + for (i = 0; i < w; i++) + { + int idx = (w*j+i); - for (j = 0; j < h; j++) - { - for (i = 0; i < w; i++) - { - tex[w*j+i].s.red = 255; // 255 because the fade mask is modulated with the screen texture, so alpha affects it while the colours don't - tex[w*j+i].s.green = 255; - tex[w*j+i].s.blue = 255; - tex[w*j+i].s.alpha = *pImgData; - pImgData++; + tex[idx].s.red = *pImgData; + tex[idx].s.green = *pImgData; + tex[idx].s.blue = *pImgData; + pImgData++; + tex[idx].s.alpha = *pImgData; + pImgData++; + } } - } + break; + case GL_TEXFMT_ALPHA_8: // Used for fade masks + GL_AllocTextureBuffer(pTexInfo); + ptex = tex = textureBuffer; + texformat = GL_ALPHA; + + for (j = 0; j < h; j++) + { + for (i = 0; i < w; i++) + { + int idx = (w*j+i); + + tex[idx].s.red = 255; // 255 because the fade mask is modulated with the screen texture, so alpha affects it while the colours don't + tex[idx].s.green = 255; + tex[idx].s.blue = 255; + tex[idx].s.alpha = *pImgData; + pImgData++; + } + } + break; + default: + GL_MSG_Warning("UpdateTexture: bad format %d\n", pTexInfo->format); + break; } - else - GL_MSG_Warning("UpdateTexture: bad format %d\n", pTexInfo->format); pglBindTexture(GL_TEXTURE_2D, num); tex_downloaded = num; + const int transparent = (pTexInfo->flags & TF_TRANSPARENT); + // disable texture filtering on any texture that has holes so there's no dumb borders or blending issues - if (pTexInfo->flags & TF_TRANSPARENT) + if (transparent) { pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -1680,73 +1705,25 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter); } - if (pTexInfo->format == GL_TEXFMT_ALPHA_INTENSITY_88) + if (MipMap && !transparent) // No mipmaps on transparent stuff { - //pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - if (MipMap) - { - pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); - if (pTexInfo->flags & TF_TRANSPARENT) - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff - else - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); - //pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR_MIPMAP_LINEAR); - } + if (update) + pglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); else - { - if (update) - pglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - else - pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - } - } - else if (pTexInfo->format == GL_TEXFMT_ALPHA_8) - { - //pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - if (MipMap) - { - pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + pglTexImage2D(GL_TEXTURE_2D, 0, texformat, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); - if (pTexInfo->flags & TF_TRANSPARENT) - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff - else - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); - //pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR_MIPMAP_LINEAR); - } - else - { - if (update) - pglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - else - pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - } + // Control the mipmap level of detail + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); } else { - if (MipMap) - { - pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - pglTexImage2D(GL_TEXTURE_2D, 0, textureformatGL, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - - // Control the mipmap level of detail - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); // the lower the number, the higer the detail - if (pTexInfo->flags & TF_TRANSPARENT) - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff - else - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 5); - } + if (update) + pglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); else - { - if (update) - pglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - else - pglTexImage2D(GL_TEXTURE_2D, 0, textureformatGL, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - } + pglTexImage2D(GL_TEXTURE_2D, 0, texformat, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); } if (pTexInfo->flags & TF_WRAPX) @@ -1767,18 +1744,19 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo) // -----------------+ // SetTexture : The mipmap becomes the current texture source // -----------------+ -EXPORT void HWRAPI(SetTexture) (GLMipmap_t *pTexInfo) +void GL_SetTexture(GLMipmap_t *pTexInfo) { if (!pTexInfo) { - SetNoTexture(); + GL_SetNoTexture(); return; } else if (pTexInfo->downloaded) { if (pTexInfo->downloaded != tex_downloaded) { - pglBindTexture(GL_TEXTURE_2D, pTexInfo->downloaded); + if (!currently_batching) + pglBindTexture(GL_TEXTURE_2D, pTexInfo->downloaded); tex_downloaded = pTexInfo->downloaded; } } @@ -1786,7 +1764,7 @@ EXPORT void HWRAPI(SetTexture) (GLMipmap_t *pTexInfo) { FTextureInfo *newTex = calloc(1, sizeof (*newTex)); - UpdateTexture(pTexInfo); + GL_UpdateTexture(pTexInfo); newTex->texture = pTexInfo; newTex->downloaded = (UINT32)pTexInfo->downloaded; @@ -1806,7 +1784,7 @@ EXPORT void HWRAPI(SetTexture) (GLMipmap_t *pTexInfo) } } -static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAFloat *tint, GLRGBAFloat *fade) +static void GL_Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAFloat *tint, GLRGBAFloat *fade) { gl_shader_t *shader = gl_shaderstate.current; @@ -1871,7 +1849,7 @@ static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAF } } -static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i) +static boolean GL_Shader_CompileProgram(gl_shader_t *shader, GLint i) { GLuint gl_vertShader = 0; GLuint gl_fragShader = 0; @@ -2016,13 +1994,13 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i) // code that is common between DrawPolygon and DrawIndexedTriangles // DrawScreenTexture also can use this function for fancier screen texture drawing // the corona thing is there too, i have no idea if that stuff works with DrawIndexedTriangles and batching -static void PreparePolygon(FSurfaceInfo *pSurf, FBITFIELD PolyFlags) +static void GL_PreparePolygon(FSurfaceInfo *pSurf, FBITFIELD PolyFlags) { static GLRGBAFloat poly = {0,0,0,0}; static GLRGBAFloat tint = {0,0,0,0}; static GLRGBAFloat fade = {0,0,0,0}; - SetBlend(PolyFlags); //TODO: inline (#pragma..) + GL_SetBlend(PolyFlags); //TODO: inline (#pragma..) if (pSurf) { @@ -2062,15 +2040,15 @@ static void PreparePolygon(FSurfaceInfo *pSurf, FBITFIELD PolyFlags) } } - Shader_SetUniforms(pSurf, &poly, &tint, &fade); + GL_Shader_SetUniforms(pSurf, &poly, &tint, &fade); } // -----------------+ // DrawPolygon : Render a polygon, set the texture, set render mode // -----------------+ -EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags) +void GL_DrawPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags) { - PreparePolygon(pSurf, PolyFlags); + GL_PreparePolygon(pSurf, PolyFlags); pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].x); pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].s); @@ -2086,9 +2064,9 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI Clamp2D(GL_TEXTURE_WRAP_T); } -EXPORT void HWRAPI(DrawIndexedTriangles) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, unsigned int *IndexArray) +void GL_DrawIndexedTriangles(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, unsigned int *IndexArray) { - PreparePolygon(pSurf, PolyFlags); + GL_PreparePolygon(pSurf, PolyFlags); pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].x); pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].s); @@ -2104,11 +2082,11 @@ static const boolean gl_ext_arb_vertex_buffer_object = true; #define sky_vbo_u (gl_ext_arb_vertex_buffer_object ? &NULL_VBO_VERTEX->u : &sky->data[0].u) #define sky_vbo_r (gl_ext_arb_vertex_buffer_object ? &NULL_VBO_VERTEX->r : &sky->data[0].r) -EXPORT void HWRAPI(RenderSkyDome) (gl_sky_t *sky) +void GL_RenderSkyDome(gl_sky_t *sky) { int i, j; - Shader_SetUniforms(NULL, NULL, NULL, NULL); + GL_Shader_SetUniforms(NULL, NULL, NULL, NULL); // Build the sky dome! Yes! if (sky->rebuild) @@ -2191,7 +2169,7 @@ EXPORT void HWRAPI(RenderSkyDome) (gl_sky_t *sky) // ========================================================================== // // ========================================================================== -EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) +void GL_SetSpecialState(hwdspecialstate_t IdState, INT32 Value) { switch (IdState) { @@ -2199,6 +2177,7 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) gl_allowshaders = Value; break; case HWD_SET_TEXTUREFILTERMODE: + switch (Value) { case HWD_SET_TEXTUREFILTER_TRILINEAR: @@ -2230,16 +2209,17 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) MipMap = GL_TRUE; break; default: - mag_filter = GL_LINEAR; min_filter = GL_NEAREST; + mag_filter = GL_LINEAR; } + if (!supportMipMap) { MipMap = GL_FALSE; min_filter = GL_LINEAR; } - Flush(); //??? if we want to change filter mode by texture, remove this + GL_Flush(); //??? if we want to change filter mode by texture, remove this break; case HWD_SET_MSAA: @@ -2252,9 +2232,9 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) break; case HWD_SET_TEXTUREANISOTROPICMODE: - anisotropic_filter = min(Value,maximumAnisotropy); + anisotropic_filter = min(Value, maximumAnisotropy); if (maximumAnisotropy) - Flush(); //??? if we want to change filter mode by texture, remove this + GL_Flush(); //??? if we want to change filter mode by texture, remove this break; case HWD_SET_SCREEN_TEXTURES: @@ -2340,7 +2320,7 @@ static size_t lerpTinyBufferSize = 0; // Static temporary buffer for doing frame interpolation // 'size' is the vertex size -static void AllocLerpBuffer(size_t size) +static void GL_AllocLerpBuffer(size_t size) { if (lerpBufferSize >= size) return; @@ -2358,7 +2338,7 @@ static void AllocLerpBuffer(size_t size) // Static temporary buffer for doing frame interpolation // 'size' is the vertex size -static void AllocLerpTinyBuffer(size_t size) +static void GL_AllocLerpTinyBuffer(size_t size) { if (lerpTinyBufferSize >= size) return; @@ -2382,7 +2362,7 @@ static void AllocLerpTinyBuffer(size_t size) #define GL_ARRAY_BUFFER 0x8892 #endif -static void CreateModelVBO(mesh_t *mesh, mdlframe_t *frame) +static void GL_CreateModelVBO(mesh_t *mesh, mdlframe_t *frame) { int bufferSize = sizeof(vbo64_t)*mesh->numTriangles * 3; vbo64_t *buffer = (vbo64_t*)malloc(bufferSize); @@ -2450,7 +2430,7 @@ static void CreateModelVBO(mesh_t *mesh, mdlframe_t *frame) pglBindBuffer(GL_ARRAY_BUFFER, 0); } -static void CreateModelVBOTiny(mesh_t *mesh, tinyframe_t *frame) +static void GL_CreateModelVBOTiny(mesh_t *mesh, tinyframe_t *frame) { int bufferSize = sizeof(vbotiny_t)*mesh->numTriangles * 3; vbotiny_t *buffer = (vbotiny_t*)malloc(bufferSize); @@ -2495,9 +2475,10 @@ static void CreateModelVBOTiny(mesh_t *mesh, tinyframe_t *frame) pglBindBuffer(GL_ARRAY_BUFFER, 0); } -EXPORT void HWRAPI(CreateModelVBOs) (model_t *model) +void GL_CreateModelVBOs(model_t *model) { int i; + for (i = 0; i < model->numMeshes; i++) { mesh_t *mesh = &model->meshes[i]; @@ -2511,7 +2492,7 @@ EXPORT void HWRAPI(CreateModelVBOs) (model_t *model) if (frame->vboID) pglDeleteBuffers(1, &frame->vboID); frame->vboID = 0; - CreateModelVBO(mesh, frame); + GL_CreateModelVBO(mesh, frame); } } else if (mesh->tinyframes) @@ -2523,7 +2504,7 @@ EXPORT void HWRAPI(CreateModelVBOs) (model_t *model) if (frame->vboID) pglDeleteBuffers(1, &frame->vboID); frame->vboID = 0; - CreateModelVBOTiny(mesh, frame); + GL_CreateModelVBOTiny(mesh, frame); } } } @@ -2531,7 +2512,7 @@ EXPORT void HWRAPI(CreateModelVBOs) (model_t *model) #define BUFFER_OFFSET(i) ((char*)(i)) -static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface) +void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface) { static GLRGBAFloat poly = {0,0,0,0}; static GLRGBAFloat tint = {0,0,0,0}; @@ -2570,9 +2551,9 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float poly.alpha = byte2float[Surface->PolyColor.s.alpha]; if (poly.alpha < 1) - SetBlend(PF_Translucent|PF_Modulated); + GL_SetBlend(PF_Translucent|PF_Modulated); else - SetBlend(PF_Masked|PF_Modulated|PF_Occlude); + GL_SetBlend(PF_Masked|PF_Modulated|PF_Occlude); pglColor4ubv((GLubyte*)&Surface->PolyColor.s); @@ -2594,7 +2575,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float lt_downloaded = Surface->LightTableId; } - Shader_SetUniforms(Surface, &poly, &tint, &fade); + GL_Shader_SetUniforms(Surface, &poly, &tint, &fade); pglEnable(GL_CULL_FACE); pglEnable(GL_NORMALIZE); @@ -2690,7 +2671,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float int j = 0; // Dangit, I soooo want to do this in a GLSL shader... - AllocLerpTinyBuffer(mesh->numVertices * sizeof(short) * 3); + GL_AllocLerpTinyBuffer(mesh->numVertices * sizeof(short) * 3); vertPtr = vertTinyBuffer; normPtr = normTinyBuffer; @@ -2733,7 +2714,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float int j = 0; // Dangit, I soooo want to do this in a GLSL shader... - AllocLerpBuffer(mesh->numVertices * sizeof(float) * 3); + GL_AllocLerpBuffer(mesh->numVertices * sizeof(float) * 3); vertPtr = vertBuffer; normPtr = normBuffer; @@ -2759,18 +2740,10 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float pglDisable(GL_NORMALIZE); } -// -----------------+ -// HWRAPI DrawModel : Draw a model -// -----------------+ -EXPORT void HWRAPI(DrawModel) (model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface) -{ - DrawModelEx(model, frameIndex, duration, tics, nextFrameIndex, pos, hscale, vscale, flipped, hflipped, Surface); -} - // -----------------+ // SetTransform : // -----------------+ -EXPORT void HWRAPI(SetTransform) (FTransform *stransform) +void GL_SetTransform(FTransform *stransform) { static boolean special_splitscreen; GLdouble used_fov; @@ -2830,10 +2803,10 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) if (special_splitscreen) { used_fov = (float)(atan(tan(used_fov * M_PIl / 360) * 0.8) * 360 / M_PIl); - GLPerspective((GLfloat)used_fov, 2*ASPECT_RATIO); + GL_Perspective((GLfloat)used_fov, 2*ASPECT_RATIO); } else - GLPerspective((GLfloat)used_fov, ASPECT_RATIO); + GL_Perspective((GLfloat)used_fov, ASPECT_RATIO); pglGetFloatv(GL_PROJECTION_MATRIX, projMatrix); // added for new coronas' code (without depth buffer) pglMatrixMode(GL_MODELVIEW); @@ -2841,7 +2814,7 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) pglGetFloatv(GL_MODELVIEW_MATRIX, modelMatrix); // added for new coronas' code (without depth buffer) } -EXPORT INT32 HWRAPI(GetTextureUsed) (void) +INT32 GL_GetTextureUsed(void) { FTextureInfo *tmp = TexCacheHead; INT32 res = 0; @@ -2866,7 +2839,7 @@ EXPORT INT32 HWRAPI(GetTextureUsed) (void) return res; } -EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]) +void GL_PostImgRedraw(float points[SCREENVERTS][SCREENVERTS][2]) { INT32 x, y; float float_x, float_y, float_nextx, float_nexty; @@ -2903,9 +2876,9 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]) pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); pglEnableClientState(GL_TEXTURE_COORD_ARRAY); - for(x=0;x 9) && (big_lap_color) && (cv_biglaps.value) && (!stplyr->exiting)); - else - return ((cv_numlaps.value > 9) && (big_lap) && (cv_biglaps.value) && (!stplyr->exiting)); + return (cv_biglaps.value && (cv_numlaps.value > 9) && (K_UseColorHud() ? big_lap_color : big_lap) && (!stplyr->exiting)); } static void K_drawKartLaps(void) @@ -8717,20 +8715,16 @@ static void K_drawKartLaps(void) } else { - if (!K_UseColorHud()) - { - if (K_BigLapSticker()) - V_DrawScaledPatch(fx, fy, V_HUDTRANS|splitflags, ((stplyr->laps + 1 > 9) ? kp_lapstickerbig2 : kp_lapstickerbig)); - else - V_DrawScaledPatch(fx, fy, V_HUDTRANS|splitflags, kp_lapsticker); - } - else //Colourized hud + if (K_UseColorHud()) // Colourized hud { UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - if (K_BigLapSticker()) - V_DrawMappedPatch(fx, fy, V_HUDTRANS|splitflags, ((stplyr->laps + 1 > 9) ? kp_lapstickerbig2clr : kp_lapstickerbigclr), colormap); - else - V_DrawMappedPatch(fx, fy, V_HUDTRANS|splitflags, kp_lapstickerclr, colormap); + patch_t *biglapclr = (K_BigLap() ? ((stplyr->laps + 1 > 9) ? kp_lapstickerbig2clr : kp_lapstickerbigclr) : kp_lapstickerclr); + V_DrawMappedPatch(fx, fy, V_HUDTRANS|splitflags, biglapclr, colormap); + } + else + { + patch_t *biglap = (K_BigLap() ? ((stplyr->laps + 1 > 9) ? kp_lapstickerbig2 : kp_lapstickerbig) : kp_lapsticker); + V_DrawScaledPatch(fx, fy, V_HUDTRANS|splitflags, biglap); } if (stplyr->exiting) @@ -9351,11 +9345,14 @@ skipcrap: case 1: case 2: case 3: + case 5: { if (!driftgaugegfx) break; - if (cv_driftgaugestyle.value == 1 || cv_driftgaugestyle.value == 3 || (cv_driftgaugestyle.value == 5 && xtra_speedo3)) + const boolean usescaledpatch = (cv_driftgaugestyle.value == 5 && xtra_speedo3); + + if (cv_driftgaugestyle.value == 1 || cv_driftgaugestyle.value == 3 || usescaledpatch) { barx = basex - dup*23; BAR_WIDTH = dup*47; @@ -9373,12 +9370,26 @@ skipcrap: const INT32 width = ((driftcharge - (driftcharge >= driftval ? limit : 0)) * BAR_WIDTH) / limit; const INT32 level = min(driftcharge / driftval, 2); - if (!K_UseColorHud()) - V_DrawMappedPatch(cv_driftgaugestyle.value == 2 ? basex + dup*11 : basex, basey, V_NOSCALESTART|V_OFFSET|drifttrans, cv_driftgaugestyle.value == 2 ? driftgaugesmall : driftgauge, NULL); - else //Colourized hud + if (usescaledpatch) // i hate hud code i hate hud code i hate hud code i hate hud code i hate hud code..... { - UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - V_DrawMappedPatch(cv_driftgaugestyle.value == 2 ? basex + dup*11 : basex, basey, V_NOSCALESTART|V_OFFSET|drifttrans, cv_driftgaugestyle.value == 2 ? driftgaugesmallcolor : driftgaugecolor, colormap); + if (K_UseColorHud() && xtra_speedo_clr3) // Colourized hud + { + UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); + V_DrawStretchyFixedPatch((basex - dup*30)<= driftval*4) // rainbow sparks @@ -9930,13 +9941,14 @@ static void K_drawBattleFullscreen(void) V_DrawString(x-txoff, ty, 0, va("%d", stplyr->kartstuff[k_comebacktimer]/TICRATE)); else { - if (!K_UseColorHud()) - V_DrawFixedPatch(x<kartstuff[k_comebacktimer]/TICRATE)); } diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 6bca10cbe..c621bd256 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -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); diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 9276e61aa..0a8ee9cae 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -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) { diff --git a/src/lua_script.c b/src/lua_script.c index b03a34d32..6f439479e 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -610,7 +610,7 @@ static UINT8 GetUserdataArchType(int index) return ARCH_NULL; } -static UINT8 ArchiveValue(int TABLESINDEX, int myindex) +static UINT8 ArchiveValue(UINT8 **p, int TABLESINDEX, int myindex) { if (myindex < 0) myindex = lua_gettop(gL)+1+myindex; @@ -618,23 +618,23 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { case LUA_TNONE: case LUA_TNIL: - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); break; // This might be a problem. D: case LUA_TLIGHTUSERDATA: case LUA_TTHREAD: case LUA_TFUNCTION: - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); return 2; case LUA_TBOOLEAN: - WRITEUINT8(save_p, ARCH_BOOLEAN); - WRITEUINT8(save_p, lua_toboolean(gL, myindex)); + WRITEUINT8(*p, ARCH_BOOLEAN); + WRITEUINT8(*p, lua_toboolean(gL, myindex)); break; case LUA_TNUMBER: { lua_Integer number = lua_tointeger(gL, myindex); - WRITEUINT8(save_p, ARCH_SIGNED); - WRITEFIXED(save_p, number); + WRITEUINT8(*p, ARCH_SIGNED); + WRITEFIXED(*p, number); break; } case LUA_TSTRING: @@ -642,7 +642,7 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) UINT16 len = (UINT16)lua_objlen(gL, myindex); // get length of string, including embedded zeros const char *s = lua_tostring(gL, myindex); UINT16 i = 0; - WRITEUINT8(save_p, ARCH_STRING); + WRITEUINT8(*p, ARCH_STRING); // if you're wondering why we're writing a string to save_p this way, // it turns out that Lua can have embedded zeros ('\0') in the strings, // so we can't use WRITESTRING as that cuts off when it finds a '\0'. @@ -650,9 +650,9 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) // fixing the awful crashes previously encountered for reading strings longer than 1024 // (yes I know that's kind of a stupid thing to care about, but it'd be evil to trim or ignore them?) // -- Monster Iestyn 05/08/18 - WRITEUINT16(save_p, len); // save size of string + WRITEUINT16(*p, len); // save size of string while (i < len) - WRITECHAR(save_p, s[i++]); // write chars individually, including the embedded zeros + WRITECHAR(*p, s[i++]); // write chars individually, including the embedded zeros break; } case LUA_TTABLE: @@ -678,13 +678,13 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) if (t == 0) { CONS_Alert(CONS_ERROR, "Too many tables to archive!\n"); - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); return 0; } } - WRITEUINT8(save_p, ARCH_TABLE); - WRITEUINT16(save_p, t); + WRITEUINT8(*p, ARCH_TABLE); + WRITEUINT16(*p, t); if (!found) { @@ -700,25 +700,25 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) case ARCH_MOBJINFO: { mobjinfo_t *info = *((mobjinfo_t **)lua_touserdata(gL, myindex)); - WRITEUINT8(save_p, ARCH_MOBJINFO); - WRITEUINT16(save_p, info - mobjinfo); + WRITEUINT8(*p, ARCH_MOBJINFO); + WRITEUINT16(*p, info - mobjinfo); break; } case ARCH_STATE: { state_t *state = *((state_t **)lua_touserdata(gL, myindex)); - WRITEUINT8(save_p, ARCH_STATE); - WRITEUINT16(save_p, state - states); + WRITEUINT8(*p, ARCH_STATE); + WRITEUINT16(*p, state - states); break; } case ARCH_MOBJ: { mobj_t *mobj = *((mobj_t **)lua_touserdata(gL, myindex)); if (!mobj) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_MOBJ); - WRITEUINT32(save_p, mobj->mobjnum); + WRITEUINT8(*p, ARCH_MOBJ); + WRITEUINT32(*p, mobj->mobjnum); } break; } @@ -726,10 +726,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { player_t *player = *((player_t **)lua_touserdata(gL, myindex)); if (!player) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_PLAYER); - WRITEUINT8(save_p, player - players); + WRITEUINT8(*p, ARCH_PLAYER); + WRITEUINT8(*p, player - players); } break; } @@ -737,10 +737,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { mapthing_t *mapthing = *((mapthing_t **)lua_touserdata(gL, myindex)); if (!mapthing) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_MAPTHING); - WRITEUINT16(save_p, mapthing - mapthings); + WRITEUINT8(*p, ARCH_MAPTHING); + WRITEUINT16(*p, mapthing - mapthings); } break; } @@ -748,10 +748,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { vertex_t *vertex = *((vertex_t **)lua_touserdata(gL, myindex)); if (!vertex) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_VERTEX); - WRITEUINT16(save_p, vertex - vertexes); + WRITEUINT8(*p, ARCH_VERTEX); + WRITEUINT16(*p, vertex - vertexes); } break; } @@ -759,10 +759,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { line_t *line = *((line_t **)lua_touserdata(gL, myindex)); if (!line) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_LINE); - WRITEUINT16(save_p, line - lines); + WRITEUINT8(*p, ARCH_LINE); + WRITEUINT16(*p, line - lines); } break; } @@ -770,10 +770,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { side_t *side = *((side_t **)lua_touserdata(gL, myindex)); if (!side) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_SIDE); - WRITEUINT16(save_p, side - sides); + WRITEUINT8(*p, ARCH_SIDE); + WRITEUINT16(*p, side - sides); } break; } @@ -781,10 +781,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { subsector_t *subsector = *((subsector_t **)lua_touserdata(gL, myindex)); if (!subsector) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_SUBSECTOR); - WRITEUINT16(save_p, subsector - subsectors); + WRITEUINT8(*p, ARCH_SUBSECTOR); + WRITEUINT16(*p, subsector - subsectors); } break; } @@ -792,10 +792,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { sector_t *sector = *((sector_t **)lua_touserdata(gL, myindex)); if (!sector) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_SECTOR); - WRITEUINT16(save_p, sector - sectors); + WRITEUINT8(*p, ARCH_SECTOR); + WRITEUINT16(*p, sector - sectors); } break; } @@ -803,10 +803,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { pslope_t *slope = *((pslope_t **)lua_touserdata(gL, myindex)); if (!slope) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_SLOPE); - WRITEUINT16(save_p, slope->id); + WRITEUINT8(*p, ARCH_SLOPE); + WRITEUINT16(*p, slope->id); } break; } @@ -814,15 +814,15 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { mapheader_t *header = *((mapheader_t **)lua_touserdata(gL, myindex)); if (!header) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_MAPHEADER); - WRITEUINT16(save_p, header - *mapheaderinfo); + WRITEUINT8(*p, ARCH_MAPHEADER); + WRITEUINT16(*p, header - *mapheaderinfo); } break; } default: - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); return 2; } break; @@ -830,226 +830,14 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) return 0; } -// because of how this function works it has to be pasted allll over again just to save to demo_p since it returns an uint8 to begin with -static UINT8 ArchiveValueDemo(int TABLESINDEX, int myindex) -{ - if (myindex < 0) - myindex = lua_gettop(gL)+1+myindex; - switch (lua_type(gL, myindex)) - { - case LUA_TNONE: - case LUA_TNIL: - WRITEUINT8(demo_p, ARCH_NULL); - break; - // This might be a problem. D: - case LUA_TLIGHTUSERDATA: - case LUA_TTHREAD: - case LUA_TFUNCTION: - WRITEUINT8(demo_p, ARCH_NULL); - return 2; - case LUA_TBOOLEAN: - WRITEUINT8(demo_p, ARCH_BOOLEAN); - WRITEUINT8(demo_p, lua_toboolean(gL, myindex)); - break; - case LUA_TNUMBER: - { - lua_Integer number = lua_tointeger(gL, myindex); - WRITEUINT8(demo_p, ARCH_SIGNED); - WRITEFIXED(demo_p, number); - break; - } - case LUA_TSTRING: - { - UINT16 len = (UINT16)lua_objlen(gL, myindex); // get length of string, including embedded zeros - const char *s = lua_tostring(gL, myindex); - UINT16 i = 0; - WRITEUINT8(demo_p, ARCH_STRING); - // if you're wondering why we're writing a string to demo_p this way, - // it turns out that Lua can have embedded zeros ('\0') in the strings, - // so we can't use WRITESTRING as that cuts off when it finds a '\0'. - // Saving the size of the string also allows us to get the size of the string on the other end, - // fixing the awful crashes previously encountered for reading strings longer than 1024 - // (yes I know that's kind of a stupid thing to care about, but it'd be evil to trim or ignore them?) - // -- Monster Iestyn 05/08/18 - WRITEUINT16(demo_p, len); // save size of string - while (i < len) - WRITECHAR(demo_p, s[i++]); // write chars individually, including the embedded zeros - break; - } - case LUA_TTABLE: - { - boolean found = false; - INT32 i; - UINT16 t = (UINT16)lua_objlen(gL, TABLESINDEX); - - for (i = 1; i <= t && !found; i++) - { - lua_rawgeti(gL, TABLESINDEX, i); - if (lua_rawequal(gL, myindex, -1)) - { - t = i; - found = true; - } - lua_pop(gL, 1); - } - if (!found) - t++; - - WRITEUINT8(demo_p, ARCH_TABLE); - WRITEUINT16(demo_p, t); - - if (!found) - { - lua_pushvalue(gL, myindex); - lua_rawseti(gL, TABLESINDEX, t); - return 1; - } - break; - } - case LUA_TUSERDATA: - switch (GetUserdataArchType(myindex)) - { - case ARCH_MOBJINFO: - { - mobjinfo_t *info = *((mobjinfo_t **)lua_touserdata(gL, myindex)); - WRITEUINT8(demo_p, ARCH_MOBJINFO); - WRITEUINT16(demo_p, info - mobjinfo); - break; - } - case ARCH_STATE: - { - state_t *state = *((state_t **)lua_touserdata(gL, myindex)); - WRITEUINT8(demo_p, ARCH_STATE); - WRITEUINT16(demo_p, state - states); - break; - } - case ARCH_MOBJ: - { - mobj_t *mobj = *((mobj_t **)lua_touserdata(gL, myindex)); - if (!mobj) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_MOBJ); - WRITEUINT32(demo_p, mobj->mobjnum); - } - break; - } - case ARCH_PLAYER: - { - player_t *player = *((player_t **)lua_touserdata(gL, myindex)); - if (!player) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_PLAYER); - WRITEUINT8(demo_p, player - players); - } - break; - } - case ARCH_MAPTHING: - { - mapthing_t *mapthing = *((mapthing_t **)lua_touserdata(gL, myindex)); - if (!mapthing) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_MAPTHING); - WRITEUINT16(demo_p, mapthing - mapthings); - } - break; - } - case ARCH_VERTEX: - { - vertex_t *vertex = *((vertex_t **)lua_touserdata(gL, myindex)); - if (!vertex) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_VERTEX); - WRITEUINT16(demo_p, vertex - vertexes); - } - break; - } - case ARCH_LINE: - { - line_t *line = *((line_t **)lua_touserdata(gL, myindex)); - if (!line) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_LINE); - WRITEUINT16(demo_p, line - lines); - } - break; - } - case ARCH_SIDE: - { - side_t *side = *((side_t **)lua_touserdata(gL, myindex)); - if (!side) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_SIDE); - WRITEUINT16(demo_p, side - sides); - } - break; - } - case ARCH_SUBSECTOR: - { - subsector_t *subsector = *((subsector_t **)lua_touserdata(gL, myindex)); - if (!subsector) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_SUBSECTOR); - WRITEUINT16(demo_p, subsector - subsectors); - } - break; - } - case ARCH_SECTOR: - { - sector_t *sector = *((sector_t **)lua_touserdata(gL, myindex)); - if (!sector) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_SECTOR); - WRITEUINT16(demo_p, sector - sectors); - } - break; - } - case ARCH_SLOPE: - { - pslope_t *slope = *((pslope_t **)lua_touserdata(gL, myindex)); - if (!slope) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_SLOPE); - WRITEUINT16(demo_p, slope->id); - } - break; - } - case ARCH_MAPHEADER: - { - mapheader_t *header = *((mapheader_t **)lua_touserdata(gL, myindex)); - if (!header) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_MAPHEADER); - WRITEUINT16(demo_p, header - *mapheaderinfo); - } - break; - } - default: - WRITEUINT8(demo_p, ARCH_NULL); - return 2; - } - break; - } - return 0; -} - -static void ArchiveExtVars(void *pointer, const char *ptype) +static void ArchiveExtVars(UINT8 **p, void *pointer, const char *ptype) { int TABLESINDEX; UINT16 i; if (!gL) { if (fastcmp(ptype,"player")) // players must always be included, even if no vars - WRITEUINT16(save_p, 0); + WRITEUINT16(*p, 0); return; } @@ -1065,7 +853,7 @@ static void ArchiveExtVars(void *pointer, const char *ptype) { // no extra values table lua_pop(gL, 1); if (fastcmp(ptype,"player")) // players must always be included, even if no vars - WRITEUINT16(save_p, 0); + WRITEUINT16(*p, 0); return; } @@ -1077,77 +865,20 @@ static void ArchiveExtVars(void *pointer, const char *ptype) if (i == 0) { if (fastcmp(ptype,"player")) // always include players even if they have no extra variables - WRITEUINT16(save_p, 0); + WRITEUINT16(*p, 0); lua_pop(gL, 1); return; } if (fastcmp(ptype,"mobj")) // mobjs must write their mobjnum as a header - WRITEUINT32(save_p, ((mobj_t *)pointer)->mobjnum); - WRITEUINT16(save_p, i); + WRITEUINT32(*p, ((mobj_t *)pointer)->mobjnum); + WRITEUINT16(*p, i); lua_pushnil(gL); while (lua_next(gL, -2)) { I_Assert(lua_type(gL, -2) == LUA_TSTRING); - WRITESTRING(save_p, lua_tostring(gL, -2)); - if (ArchiveValue(TABLESINDEX, -1) == 2) - CONS_Alert(CONS_ERROR, "Type of value for %s entry '%s' (%s) could not be archived!\n", ptype, lua_tostring(gL, -2), luaL_typename(gL, -1)); - lua_pop(gL, 1); - } - - lua_pop(gL, 1); -} - -// simplified for demos -static void ArchiveExtVarsDemo(void *pointer, const char *ptype) -{ - int TABLESINDEX; - UINT16 i; - - if (!gL) { - if (fastcmp(ptype,"player")) // players must always be included, even if no vars - WRITEUINT16(demo_p, 0); - return; - } - - TABLESINDEX = lua_gettop(gL); - - lua_getfield(gL, LUA_REGISTRYINDEX, LREG_EXTVARS); - I_Assert(lua_istable(gL, -1)); - lua_pushlightuserdata(gL, pointer); - lua_rawget(gL, -2); - lua_remove(gL, -2); // pop LREG_EXTVARS - - if (!lua_istable(gL, -1)) - { // no extra values table - lua_pop(gL, 1); - if (fastcmp(ptype,"player")) // players must always be included, even if no vars - WRITEUINT16(demo_p, 0); - return; - } - - lua_pushnil(gL); - for (i = 0; lua_next(gL, -2); i++) - lua_pop(gL, 1); - - // skip anything that has an empty table and isn't a player. - if (i == 0) - { - if (fastcmp(ptype,"player")) // always include players even if they have no extra variables - WRITEUINT16(demo_p, 0); - lua_pop(gL, 1); - return; - } - - if (fastcmp(ptype,"mobj")) // mobjs must write their mobjnum as a header - WRITEUINT32(demo_p, ((mobj_t *)pointer)->mobjnum); - WRITEUINT16(demo_p, i); - lua_pushnil(gL); - while (lua_next(gL, -2)) - { - I_Assert(lua_type(gL, -2) == LUA_TSTRING); - WRITESTRING(demo_p, lua_tostring(gL, -2)); - if (ArchiveValueDemo(TABLESINDEX, -1) == 2) + WRITESTRING(*p, lua_tostring(gL, -2)); + if (ArchiveValue(p, TABLESINDEX, -1) == 2) CONS_Alert(CONS_ERROR, "Type of value for %s entry '%s' (%s) could not be archived!\n", ptype, lua_tostring(gL, -2), luaL_typename(gL, -1)); lua_pop(gL, 1); } @@ -1158,13 +889,14 @@ static void ArchiveExtVarsDemo(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(TABLESINDEX, i); + ArchiveValue(&save->p, TABLESINDEX, i); return n; } -static void ArchiveTables(void) +static void ArchiveTables(UINT8 **p) { int TABLESINDEX; UINT16 i, n; @@ -1183,7 +915,7 @@ static void ArchiveTables(void) while (lua_next(gL, -2)) { // Write key - e = ArchiveValue(TABLESINDEX, -2); // key should be either a number or a string, ArchiveValue can handle this. + e = ArchiveValue(p, TABLESINDEX, -2); // key should be either a number or a string, ArchiveValue can handle this. if (e == 2) // invalid key type (function, thread, lightuserdata, or anything we don't recognise) { lua_pushvalue(gL, -2); @@ -1191,7 +923,7 @@ static void ArchiveTables(void) lua_pop(gL, 1); } // Write value - e = ArchiveValue(TABLESINDEX, -1); + e = ArchiveValue(p, TABLESINDEX, -1); if (e == 1) n++; // the table contained a new table we'll have to archive. :( else if (e == 2) // invalid value type @@ -1204,71 +936,27 @@ static void ArchiveTables(void) lua_pop(gL, 1); } lua_pop(gL, 1); - WRITEUINT8(save_p, ARCH_TEND); + WRITEUINT8(*p, ARCH_TEND); } } -static void ArchiveTablesDemo(void) +static UINT8 UnArchiveValue(UINT8 **p, int TABLESINDEX) { - int TABLESINDEX; - UINT16 i, n; - UINT8 e; - - if (!gL) - return; - - TABLESINDEX = lua_gettop(gL); - - n = (UINT16)lua_objlen(gL, TABLESINDEX); - for (i = 1; i <= n; i++) - { - lua_rawgeti(gL, TABLESINDEX, i); - lua_pushnil(gL); - while (lua_next(gL, -2)) - { - // Write key - e = ArchiveValueDemo(TABLESINDEX, -2); // key should be either a number or a string, ArchiveValue can handle this. - if (e == 2) // invalid key type (function, thread, lightuserdata, or anything we don't recognise) - { - lua_pushvalue(gL, -2); - CONS_Alert(CONS_ERROR, "Index '%s' (%s) of table %d could not be archived!\n", lua_tostring(gL, -1), luaL_typename(gL, -1), i); - lua_pop(gL, 1); - } - // Write value - e = ArchiveValueDemo(TABLESINDEX, -1); - if (e == 1) - n++; // the table contained a new table we'll have to archive. :( - else if (e == 2) // invalid value type - { - lua_pushvalue(gL, -2); - CONS_Alert(CONS_ERROR, "Type of value for table %d entry '%s' (%s) could not be archived!\n", i, lua_tostring(gL, -1), luaL_typename(gL, -1)); - lua_pop(gL, 1); - } - - lua_pop(gL, 1); - } - lua_pop(gL, 1); - WRITEUINT8(demo_p, ARCH_TEND); - } -} - -static UINT8 UnArchiveValue(int TABLESINDEX) -{ - UINT8 type = READUINT8(save_p); + UINT8 type = READUINT8(*p); switch (type) { case ARCH_NULL: lua_pushnil(gL); break; case ARCH_BOOLEAN: - lua_pushboolean(gL, READUINT8(save_p)); + lua_pushboolean(gL, READUINT8(*p)); break; case ARCH_SIGNED: - lua_pushinteger(gL, READFIXED(save_p)); + lua_pushinteger(gL, READFIXED(*p)); break; case ARCH_STRING: { - UINT16 len = READUINT16(save_p); // length of string, including embedded zeros + UINT16 len = READUINT16(*p); // length of string, including embedded zeros char *value; UINT16 i = 0; // See my comments in the ArchiveValue function; @@ -1278,14 +966,14 @@ static UINT8 UnArchiveValue(int TABLESINDEX) value = malloc(len); // make temp buffer of size len // now read the actual string while (i < len) - value[i++] = READCHAR(save_p); // read chars individually, including the embedded zeros + value[i++] = READCHAR(*p); // read chars individually, including the embedded zeros lua_pushlstring(gL, value, len); // push the string (note: this function supports embedded zeros) free(value); // free the buffer break; } case ARCH_TABLE: { - UINT16 tid = READUINT16(save_p); + UINT16 tid = READUINT16(*p); lua_rawgeti(gL, TABLESINDEX, tid); if (lua_isnil(gL, -1)) { @@ -1298,40 +986,40 @@ static UINT8 UnArchiveValue(int TABLESINDEX) break; } case ARCH_MOBJINFO: - LUA_PushUserdata(gL, &mobjinfo[READUINT16(save_p)], META_MOBJINFO); + LUA_PushUserdata(gL, &mobjinfo[READUINT16(*p)], META_MOBJINFO); break; case ARCH_STATE: - LUA_PushUserdata(gL, &states[READUINT16(save_p)], META_STATE); + LUA_PushUserdata(gL, &states[READUINT16(*p)], META_STATE); break; case ARCH_MOBJ: - LUA_PushUserdata(gL, P_FindNewPosition(READUINT32(save_p)), META_MOBJ); + LUA_PushUserdata(gL, P_FindNewPosition(READUINT32(*p)), META_MOBJ); break; case ARCH_PLAYER: - LUA_PushUserdata(gL, &players[READUINT8(save_p)], META_PLAYER); + LUA_PushUserdata(gL, &players[READUINT8(*p)], META_PLAYER); break; case ARCH_MAPTHING: - LUA_PushUserdata(gL, &mapthings[READUINT16(save_p)], META_MAPTHING); + LUA_PushUserdata(gL, &mapthings[READUINT16(*p)], META_MAPTHING); break; case ARCH_VERTEX: - LUA_PushUserdata(gL, &vertexes[READUINT16(save_p)], META_VERTEX); + LUA_PushUserdata(gL, &vertexes[READUINT16(*p)], META_VERTEX); break; case ARCH_LINE: - LUA_PushUserdata(gL, &lines[READUINT16(save_p)], META_LINE); + LUA_PushUserdata(gL, &lines[READUINT16(*p)], META_LINE); break; case ARCH_SIDE: - LUA_PushUserdata(gL, &sides[READUINT16(save_p)], META_SIDE); + LUA_PushUserdata(gL, &sides[READUINT16(*p)], META_SIDE); break; case ARCH_SUBSECTOR: - LUA_PushUserdata(gL, &subsectors[READUINT16(save_p)], META_SUBSECTOR); + LUA_PushUserdata(gL, &subsectors[READUINT16(*p)], META_SUBSECTOR); break; case ARCH_SECTOR: - LUA_PushUserdata(gL, §ors[READUINT16(save_p)], META_SECTOR); + LUA_PushUserdata(gL, §ors[READUINT16(*p)], META_SECTOR); break; case ARCH_SLOPE: - LUA_PushUserdata(gL, P_SlopeById(READUINT16(save_p)), META_SLOPE); + LUA_PushUserdata(gL, P_SlopeById(READUINT16(*p)), META_SLOPE); break; case ARCH_MAPHEADER: - LUA_PushUserdata(gL, mapheaderinfo[READUINT16(save_p)], META_MAPHEADER); + LUA_PushUserdata(gL, mapheaderinfo[READUINT16(*p)], META_MAPHEADER); break; case ARCH_TEND: return 1; @@ -1353,23 +1041,23 @@ static UINT8 UnArchiveValue(int TABLESINDEX) // 2: Read table value // 3: Don't use setfield -static UINT8 UnArchiveValueDemo(int TABLESINDEX, char field[1024]) +static UINT8 UnArchiveValueDemo(UINT8 **p, int TABLESINDEX, char field[1024]) { - UINT8 type = READUINT8(demo_p); + UINT8 type = READUINT8(*p); switch (type) { case ARCH_NULL: lua_pushnil(gL); break; case ARCH_BOOLEAN: - lua_pushboolean(gL, READUINT8(demo_p)); + lua_pushboolean(gL, READUINT8(*p)); break; case ARCH_SIGNED: - lua_pushinteger(gL, READFIXED(demo_p)); + lua_pushinteger(gL, READFIXED(*p)); break; case ARCH_STRING: { - UINT16 len = READUINT16(demo_p); // length of string, including embedded zeros + UINT16 len = READUINT16(*p); // length of string, including embedded zeros char *value; UINT16 i = 0; // See my comments in the ArchiveValue function; @@ -1379,14 +1067,14 @@ static UINT8 UnArchiveValueDemo(int TABLESINDEX, char field[1024]) value = malloc(len); // make temp buffer of size len // now read the actual string while (i < len) - value[i++] = READCHAR(demo_p); // read chars individually, including the embedded zeros + value[i++] = READCHAR(*p); // read chars individually, including the embedded zeros lua_pushlstring(gL, value, len); // push the string (note: this function supports embedded zeros) free(value); // free the buffer break; } case ARCH_TABLE: { - UINT16 tid = READUINT16(demo_p); + UINT16 tid = READUINT16(*p); lua_rawgeti(gL, TABLESINDEX, tid); if (lua_isnil(gL, -1)) { @@ -1399,46 +1087,45 @@ static UINT8 UnArchiveValueDemo(int TABLESINDEX, char field[1024]) break; } case ARCH_MOBJINFO: - LUA_PushUserdata(gL, &mobjinfo[READUINT16(demo_p)], META_MOBJINFO); + LUA_PushUserdata(gL, &mobjinfo[READUINT16(*p)], META_MOBJINFO); break; case ARCH_STATE: - LUA_PushUserdata(gL, &states[READUINT16(demo_p)], META_STATE); + LUA_PushUserdata(gL, &states[READUINT16(*p)], META_STATE); break; case ARCH_MOBJ: - demo_p += sizeof(UINT32); // Skip this data, we can't read a mobj here, it'd point to garbage and crash the game. + *p += sizeof(UINT32); // Skip this data, we can't read a mobj here, it'd point to garbage and crash the game. if (field) CONS_Alert(CONS_WARNING,"Cannot read mobj_t stored in player variable \'%s\'. Desyncs may occur.\n", field); else CONS_Alert(CONS_WARNING,"Couldn't read mobj_t\n"); - return 3; // Don't set the field case ARCH_PLAYER: - LUA_PushUserdata(gL, &players[READUINT8(demo_p)], META_PLAYER); + LUA_PushUserdata(gL, &players[READUINT8(*p)], META_PLAYER); break; case ARCH_MAPTHING: - LUA_PushUserdata(gL, &mapthings[READUINT16(demo_p)], META_MAPTHING); + LUA_PushUserdata(gL, &mapthings[READUINT16(*p)], META_MAPTHING); break; case ARCH_VERTEX: - LUA_PushUserdata(gL, &vertexes[READUINT16(demo_p)], META_VERTEX); + LUA_PushUserdata(gL, &vertexes[READUINT16(*p)], META_VERTEX); break; case ARCH_LINE: - LUA_PushUserdata(gL, &lines[READUINT16(demo_p)], META_LINE); + LUA_PushUserdata(gL, &lines[READUINT16(*p)], META_LINE); break; case ARCH_SIDE: - LUA_PushUserdata(gL, &sides[READUINT16(demo_p)], META_SIDE); + LUA_PushUserdata(gL, &sides[READUINT16(*p)], META_SIDE); break; case ARCH_SUBSECTOR: - LUA_PushUserdata(gL, &subsectors[READUINT16(demo_p)], META_SUBSECTOR); + LUA_PushUserdata(gL, &subsectors[READUINT16(*p)], META_SUBSECTOR); break; case ARCH_SECTOR: - LUA_PushUserdata(gL, §ors[READUINT16(demo_p)], META_SECTOR); + LUA_PushUserdata(gL, §ors[READUINT16(*p)], META_SECTOR); break; case ARCH_SLOPE: - LUA_PushUserdata(gL, P_SlopeById(READUINT16(demo_p)), META_SLOPE); + LUA_PushUserdata(gL, P_SlopeById(READUINT16(*p)), META_SLOPE); break; case ARCH_MAPHEADER: - LUA_PushUserdata(gL, mapheaderinfo[READUINT16(demo_p)], META_MAPHEADER); + LUA_PushUserdata(gL, mapheaderinfo[READUINT16(*p)], META_MAPHEADER); break; case ARCH_TEND: return 1; @@ -1446,10 +1133,10 @@ static UINT8 UnArchiveValueDemo(int TABLESINDEX, char field[1024]) return 0; } -static void UnArchiveExtVars(void *pointer) +static void UnArchiveExtVars(UINT8 **p, void *pointer, boolean network) { int TABLESINDEX; - UINT16 field_count = READUINT16(save_p); + UINT16 field_count = READUINT16(*p); UINT16 i; char field[1024]; @@ -1465,46 +1152,29 @@ static void UnArchiveExtVars(void *pointer) TABLESINDEX = lua_gettop(gL); lua_createtable(gL, 0, field_count); // pointer's ext vars subtable - for (i = 0; i < field_count; i++) + if (network) { - READSTRING(save_p, field); - - if (UnArchiveValue(TABLESINDEX) == 1) + for (i = 0; i < field_count; i++) { - CONS_Alert(CONS_ERROR, "Unexpected end marker when reading ExtVars (field '%s')\n", field); - break; - } + READSTRING(*p, field); - lua_setfield(gL, -2, field); - } + if (UnArchiveValue(p, TABLESINDEX) == 1) + { + CONS_Alert(CONS_ERROR, "Unexpected end marker when reading ExtVars (field '%s')\n", field); + break; + } - lua_getfield(gL, LUA_REGISTRYINDEX, LREG_EXTVARS); - I_Assert(lua_istable(gL, -1)); - lua_pushlightuserdata(gL, pointer); - lua_pushvalue(gL, -3); // pointer's ext vars subtable - lua_rawset(gL, -3); - lua_pop(gL, 2); // pop LREG_EXTVARS and pointer's subtable -} - -static void UnArchiveExtVarsDemo(void *pointer) -{ - int TABLESINDEX; - UINT16 field_count = READUINT16(demo_p); - UINT16 i; - char field[1024]; - - if (field_count == 0) - return; - I_Assert(gL != NULL); - - TABLESINDEX = lua_gettop(gL); - lua_createtable(gL, 0, field_count); // pointer's ext vars subtable - - for (i = 0; i < field_count; i++) - { - READSTRING(demo_p, field); - if (UnArchiveValueDemo(TABLESINDEX, field) != 3) // This will return 3 if we shouldn't set this field. lua_setfield(gL, -2, field); + } + } + else + { + for (i = 0; i < field_count; i++) + { + READSTRING(*p, field); + if (UnArchiveValueDemo(p, TABLESINDEX, field) != 3) // This will return 3 if we shouldn't set this field. + lua_setfield(gL, -2, field); + } } lua_getfield(gL, LUA_REGISTRYINDEX, LREG_EXTVARS); @@ -1518,13 +1188,14 @@ static void UnArchiveExtVarsDemo(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(TABLESINDEX); + UnArchiveValue(&save->p, TABLESINDEX); return n; } -static void UnArchiveTables(void) +static void UnArchiveTables(UINT8 **p, boolean network) { int TABLESINDEX; UINT16 i, n; @@ -1535,6 +1206,7 @@ static void UnArchiveTables(void) TABLESINDEX = lua_gettop(gL); n = (UINT16)lua_objlen(gL, TABLESINDEX); + for (i = 1; i <= n; i++) { lua_rawgeti(gL, TABLESINDEX, i); @@ -1545,64 +1217,39 @@ static void UnArchiveTables(void) continue; } - while (true) - { - if (UnArchiveValue(TABLESINDEX) == 1) // read key - break; - - UINT8 ret = UnArchiveValue(TABLESINDEX); - - if (ret == 1) - { - CONS_Alert(CONS_ERROR, "Unexpected end of save reached (Corrupted save?)\n"); - lua_pop(gL, 1); // Pop key - break; - } - else if (ret == 2) // read value - n++; - - if (lua_isnil(gL, -2)) // if key is nil (if a function etc was accidentally saved) - { - CONS_Alert(CONS_ERROR, "A nil key in table %d was found! (Invalid key type or corrupted save?)\n", i); - lua_pop(gL, 2); // pop key and value instead of setting them in the table, to prevent Lua panic errors - } - else - lua_rawset(gL, -3); - } - lua_pop(gL, 1); - } -} - -static void UnArchiveTablesDemo(void) -{ - int TABLESINDEX; - UINT16 i, n; - - if (!gL) - return; - - TABLESINDEX = lua_gettop(gL); - - n = (UINT16)lua_objlen(gL, TABLESINDEX); - for (i = 1; i <= n; i++) - { - lua_rawgeti(gL, TABLESINDEX, i); while (true) { UINT8 ret; - ret = UnArchiveValueDemo(TABLESINDEX, NULL); - if (ret == 3) - lua_pushnil(gL); - else if (ret == 1) // read key - break; + if (network) + { + if (UnArchiveValue(p, TABLESINDEX) == 1) // read key + break; - ret = UnArchiveValueDemo(TABLESINDEX, NULL); + ret = UnArchiveValue(p, TABLESINDEX); + if (ret == 1) + { + CONS_Alert(CONS_ERROR, "Unexpected end of save reached (Corrupted save?)\n"); + lua_pop(gL, 1); // Pop key + break; + } + else if (ret == 2) // read value + n++; + } + else + { + ret = UnArchiveValueDemo(p, TABLESINDEX, NULL); + if (ret == 3) + lua_pushnil(gL); + else if (ret == 1) // read key + break; - if (ret == 3) - lua_pushnil(gL); - else if (ret == 2) // read value - n++; + ret = UnArchiveValueDemo(p, TABLESINDEX, NULL); + if (ret == 3) + lua_pushnil(gL); + else if (ret == 2) // read value + n++; + } if (lua_isnil(gL, -2)) // if key is nil (if a function etc was accidentally saved) { @@ -1612,6 +1259,7 @@ static void UnArchiveTablesDemo(void) else lua_rawset(gL, -3); } + lua_pop(gL, 1); } } @@ -1629,7 +1277,7 @@ void LUA_Step(void) } } -void LUA_Archive(void) +void LUA_Archive(savebuffer_t *save, boolean network) { INT32 i; thinker_t *th; @@ -1642,31 +1290,36 @@ void LUA_Archive(void) 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(&players[i], "player"); + ArchiveExtVars(&save->p, &players[i], "player"); } - if (gamestate == GS_LEVEL) + if (network == true) { - for (th = thinkercap.next; th != &thinkercap; th = th->next) + if (gamestate == GS_LEVEL) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; + for (th = thinkercap.next; th != &thinkercap; th = th->next) + { + if (th->function.acp1 != (actionf_p1)P_MobjThinker) + continue; - // archive function will determine when to skip mobjs, - // and write mobjnum in otherwise. - ArchiveExtVars(th, "mobj"); + // archive function will determine when to skip mobjs, + // and write mobjnum in otherwise. + ArchiveExtVars(&save->p, th, "mobj"); + } } - } - WRITEUINT32(save_p, UINT32_MAX); // end of mobjs marker, replaces mobjnum. + WRITEUINT32(save->p, UINT32_MAX); // end of mobjs marker, replaces mobjnum. - LUA_HookNetArchive(NetArchive); // call the NetArchive hook in archive mode - ArchiveTables(); + LUA_HookNetArchive(NetArchive, save); // call the NetArchive hook in archive mode + //LUA_HookNetArchive(NetArchive); // call the NetArchive hook in archive mode + } + + ArchiveTables(&save->p); if (gL) lua_pop(gL, 1); // pop tables } -void LUA_UnArchive(void) +void LUA_UnArchive(savebuffer_t *save, boolean network) { UINT32 mobjnum; INT32 i; @@ -1679,66 +1332,29 @@ void LUA_UnArchive(void) { if (!playeringame[i] && i > 0) // same here, this is to synch dediservs properly. continue; - UnArchiveExtVars(&players[i]); + + UnArchiveExtVars(&save->p, &players[i], network); } - do { - mobjnum = READUINT32(save_p); // read a mobjnum - for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - if (((mobj_t *)th)->mobjnum != mobjnum) // find matching mobj - continue; - UnArchiveExtVars(th); // apply variables - } - } while(mobjnum != UINT32_MAX); // repeat until end of mobjs marker. - - LUA_HookNetArchive(NetUnArchive); // call the NetArchive hook in unarchive mode - UnArchiveTables(); - - if (gL) - lua_pop(gL, 1); // pop tables -} - -// simplified versions of LUA_Archive for demos -void LUA_ArchiveDemo(void) -{ - INT32 i; - - if (gL) - lua_newtable(gL); // tables to be archived. - - for (i = 0; i < MAXPLAYERS; i++) + if (network == true) { - 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. - ArchiveExtVarsDemo(&players[i], "player"); + do { + mobjnum = READUINT32(save->p); // read a mobjnum + for (th = thinkercap.next; th != &thinkercap; th = th->next) + { + if (th->function.acp1 != (actionf_p1)P_MobjThinker) + continue; + + if (((mobj_t *)th)->mobjnum == mobjnum) // find matching mobj + UnArchiveExtVars(&save->p, th, network); // apply variables + } + } while(mobjnum != UINT32_MAX); // repeat until end of mobjs marker. + + LUA_HookNetArchive(NetUnArchive, save); // call the NetArchive hook in unarchive mode + //LUA_HookNetArchive(NetUnArchive); // call the NetArchive hook in unarchive mode } - ArchiveTablesDemo(); - - if (gL) - lua_pop(gL, 1); // pop tables -} - -// this time make sure we read from demo_p -void LUA_UnArchiveDemo(void) -{ - INT32 i; - - if (gL) - lua_newtable(gL); // tables to be read - - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i] && i > 0) // same here, this is to synch dediservs properly. - continue; - UnArchiveExtVarsDemo(&players[i]); - } - - UnArchiveTablesDemo(); + UnArchiveTables(&save->p, network); if (gL) lua_pop(gL, 1); // pop tables diff --git a/src/lua_script.h b/src/lua_script.h index 6c8a0c09c..9b8c65e20 100644 --- a/src/lua_script.h +++ b/src/lua_script.h @@ -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); diff --git a/src/p_saveg.c b/src/p_saveg.c index 83f607bf2..898a53d68 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -34,7 +34,6 @@ #include "p_slopes.h" savedata_t savedata; -UINT8 *save_p; // Block UINT32s to attempt to ensure that the correct data is // being sent and received @@ -60,45 +59,45 @@ typedef enum // // P_ArchivePlayer // -static inline void P_ArchivePlayer(void) +static inline void P_ArchivePlayer(savebuffer_t *save) { const player_t *player = &players[consoleplayer]; INT32 pllives = player->lives; if (pllives < 3) // Bump up to 3 lives if the player pllives = 3; // has less than that. - WRITEUINT8(save_p, player->skincolor); - WRITEUINT8(save_p, player->skin); + WRITEUINT8(save->p, player->skincolor); + WRITEUINT8(save->p, player->skin); - WRITEUINT32(save_p, player->score); - WRITEINT32(save_p, pllives); - WRITEINT32(save_p, player->continues); + WRITEUINT32(save->p, player->score); + WRITEINT32(save->p, pllives); + WRITEINT32(save->p, player->continues); if (botskin) { - WRITEUINT8(save_p, botskin); - WRITEUINT8(save_p, botcolor); + WRITEUINT8(save->p, botskin); + WRITEUINT8(save->p, botcolor); } } // // P_UnArchivePlayer // -static inline void P_UnArchivePlayer(void) +static inline void P_UnArchivePlayer(savebuffer_t *save) { - savedata.skincolor = READUINT8(save_p); - savedata.skin = READUINT8(save_p); + savedata.skincolor = READUINT8(save->p); + savedata.skin = READUINT8(save->p); - savedata.score = READINT32(save_p); - savedata.lives = READINT32(save_p); - savedata.continues = READINT32(save_p); + savedata.score = READINT32(save->p); + savedata.lives = READINT32(save->p); + savedata.continues = READINT32(save->p); if (savedata.botcolor) { - savedata.botskin = READUINT8(save_p); + savedata.botskin = READUINT8(save->p); if (savedata.botskin-1 >= numskins) savedata.botskin = 0; - savedata.botcolor = READUINT8(save_p); + savedata.botcolor = READUINT8(save->p); } else savedata.botskin = 0; @@ -107,136 +106,135 @@ static inline void P_UnArchivePlayer(void) // // P_NetArchivePlayers // -static void P_NetArchivePlayers(boolean resending) +static void P_NetArchivePlayers(savebuffer_t *save, boolean resending) { INT32 i, j; UINT16 flags; // size_t q; - WRITEUINT32(save_p, ARCHIVEBLOCK_PLAYERS); + WRITEUINT32(save->p, ARCHIVEBLOCK_PLAYERS); for (i = 0; i < MAXPLAYERS; i++) { if (resending) - WRITESINT8(save_p, (SINT8)adminplayers[i]); + WRITESINT8(save->p, (SINT8)adminplayers[i]); if (!playeringame[i]) continue; flags = 0; - // no longer send ticcmds, player name, skin, or color + // no longer send ticcmds if (resending) - WRITESTRINGN(save_p, player_names[i], MAXPLAYERNAME); + WRITESTRINGN(save->p, player_names[i], MAXPLAYERNAME); - WRITEANGLE(save_p, players[i].aiming); - WRITEANGLE(save_p, players[i].awayviewaiming); - WRITEINT32(save_p, players[i].awayviewtics); - WRITEINT32(save_p, players[i].health); + WRITEANGLE(save->p, players[i].aiming); + WRITEANGLE(save->p, players[i].awayviewaiming); + WRITEINT32(save->p, players[i].awayviewtics); + WRITEINT32(save->p, players[i].health); - WRITESINT8(save_p, players[i].pity); - WRITEINT32(save_p, players[i].currentweapon); - WRITEINT32(save_p, players[i].ringweapons); + WRITESINT8(save->p, players[i].pity); + WRITEINT32(save->p, players[i].currentweapon); + WRITEINT32(save->p, players[i].ringweapons); for (j = 0; j < NUMPOWERS; j++) - WRITEUINT16(save_p, players[i].powers[j]); + WRITEUINT16(save->p, players[i].powers[j]); for (j = 0; j < NUMKARTSTUFF; j++) - WRITEINT32(save_p, players[i].kartstuff[j]); + WRITEINT32(save->p, players[i].kartstuff[j]); - WRITEANGLE(save_p, players[i].frameangle); + WRITEANGLE(save->p, players[i].frameangle); - WRITEUINT8(save_p, players[i].playerstate); - WRITEUINT32(save_p, players[i].pflags); - WRITEUINT8(save_p, players[i].panim); - WRITEUINT8(save_p, players[i].spectator); + WRITEUINT8(save->p, players[i].playerstate); + WRITEUINT32(save->p, players[i].pflags); + WRITEUINT8(save->p, players[i].panim); + WRITEUINT8(save->p, players[i].spectator); - WRITEUINT16(save_p, players[i].flashpal); - WRITEUINT16(save_p, players[i].flashcount); + WRITEUINT16(save->p, players[i].flashpal); + WRITEUINT16(save->p, players[i].flashcount); if (resending) { - WRITEUINT8(save_p, players[i].skincolor); - WRITEINT32(save_p, players[i].skin); + WRITEUINT8(save->p, players[i].skincolor); + WRITEINT32(save->p, players[i].skin); } - - WRITEUINT32(save_p, players[i].score); - WRITEFIXED(save_p, players[i].dashspeed); - WRITEINT32(save_p, players[i].dashtime); - WRITESINT8(save_p, players[i].lives); - WRITESINT8(save_p, players[i].continues); - WRITESINT8(save_p, players[i].xtralife); - WRITEUINT8(save_p, players[i].gotcontinue); - WRITEFIXED(save_p, players[i].speed); - WRITEUINT8(save_p, players[i].jumping); - WRITEUINT8(save_p, players[i].secondjump); - WRITEUINT8(save_p, players[i].fly1); - WRITEUINT8(save_p, players[i].scoreadd); - WRITEUINT32(save_p, players[i].glidetime); - WRITEUINT8(save_p, players[i].climbing); - WRITEINT32(save_p, players[i].deadtimer); - WRITEUINT32(save_p, players[i].exiting); - WRITEUINT8(save_p, players[i].homing); - WRITEUINT32(save_p, players[i].skidtime); + WRITEUINT32(save->p, players[i].score); + WRITEFIXED(save->p, players[i].dashspeed); + WRITEINT32(save->p, players[i].dashtime); + WRITESINT8(save->p, players[i].lives); + WRITESINT8(save->p, players[i].continues); + WRITESINT8(save->p, players[i].xtralife); + WRITEUINT8(save->p, players[i].gotcontinue); + WRITEFIXED(save->p, players[i].speed); + WRITEUINT8(save->p, players[i].jumping); + WRITEUINT8(save->p, players[i].secondjump); + WRITEUINT8(save->p, players[i].fly1); + WRITEUINT8(save->p, players[i].scoreadd); + WRITEUINT32(save->p, players[i].glidetime); + WRITEUINT8(save->p, players[i].climbing); + WRITEINT32(save->p, players[i].deadtimer); + WRITEUINT32(save->p, players[i].exiting); + WRITEUINT8(save->p, players[i].homing); + WRITEUINT32(save->p, players[i].skidtime); //////////////////////////// // Conveyor Belt Movement // //////////////////////////// - WRITEFIXED(save_p, players[i].cmomx); // Conveyor momx - WRITEFIXED(save_p, players[i].cmomy); // Conveyor momy - WRITEFIXED(save_p, players[i].rmomx); // "Real" momx (momx - cmomx) - WRITEFIXED(save_p, players[i].rmomy); // "Real" momy (momy - cmomy) + WRITEFIXED(save->p, players[i].cmomx); // Conveyor momx + WRITEFIXED(save->p, players[i].cmomy); // Conveyor momy + WRITEFIXED(save->p, players[i].rmomx); // "Real" momx (momx - cmomx) + WRITEFIXED(save->p, players[i].rmomy); // "Real" momy (momy - cmomy) ///////////////////// // Race Mode Stuff // ///////////////////// - WRITEINT16(save_p, players[i].numboxes); - WRITEINT16(save_p, players[i].totalring); - WRITEUINT32(save_p, players[i].realtime); - WRITEUINT8(save_p, players[i].laps); + WRITEINT16(save->p, players[i].numboxes); + WRITEINT16(save->p, players[i].totalring); + WRITEUINT32(save->p, players[i].realtime); + WRITEUINT8(save->p, players[i].laps); //////////////////// // CTF Mode Stuff // //////////////////// - WRITEINT32(save_p, players[i].ctfteam); - WRITEUINT16(save_p, players[i].gotflag); + WRITEINT32(save->p, players[i].ctfteam); + WRITEUINT16(save->p, players[i].gotflag); - WRITEINT32(save_p, players[i].weapondelay); - WRITEINT32(save_p, players[i].tossdelay); + WRITEINT32(save->p, players[i].weapondelay); + WRITEINT32(save->p, players[i].tossdelay); - WRITEUINT32(save_p, players[i].starposttime); - WRITEINT16(save_p, players[i].starpostx); - WRITEINT16(save_p, players[i].starposty); - WRITEINT16(save_p, players[i].starpostz); - WRITEINT32(save_p, players[i].starpostnum); - WRITEANGLE(save_p, players[i].starpostangle); + WRITEUINT32(save->p, players[i].starposttime); + WRITEINT16(save->p, players[i].starpostx); + WRITEINT16(save->p, players[i].starposty); + WRITEINT16(save->p, players[i].starpostz); + WRITEINT32(save->p, players[i].starpostnum); + WRITEANGLE(save->p, players[i].starpostangle); - WRITEANGLE(save_p, players[i].angle_pos); - WRITEANGLE(save_p, players[i].old_angle_pos); + WRITEANGLE(save->p, players[i].angle_pos); + WRITEANGLE(save->p, players[i].old_angle_pos); - WRITEINT32(save_p, players[i].flyangle); - WRITEUINT32(save_p, players[i].drilltimer); - WRITEINT32(save_p, players[i].linkcount); - WRITEUINT32(save_p, players[i].linktimer); - WRITEINT32(save_p, players[i].anotherflyangle); - WRITEUINT32(save_p, players[i].nightstime); - WRITEUINT32(save_p, players[i].bumpertime); - WRITEINT32(save_p, players[i].drillmeter); - WRITEUINT8(save_p, players[i].drilldelay); - WRITEUINT8(save_p, players[i].bonustime); - WRITEUINT8(save_p, players[i].mare); + WRITEINT32(save->p, players[i].flyangle); + WRITEUINT32(save->p, players[i].drilltimer); + WRITEINT32(save->p, players[i].linkcount); + WRITEUINT32(save->p, players[i].linktimer); + WRITEINT32(save->p, players[i].anotherflyangle); + WRITEUINT32(save->p, players[i].nightstime); + WRITEUINT32(save->p, players[i].bumpertime); + WRITEINT32(save->p, players[i].drillmeter); + WRITEUINT8(save->p, players[i].drilldelay); + WRITEUINT8(save->p, players[i].bonustime); + WRITEUINT8(save->p, players[i].mare); - WRITEUINT32(save_p, players[i].marebegunat); - WRITEUINT32(save_p, players[i].startedtime); - WRITEUINT32(save_p, players[i].finishedtime); - WRITEINT16(save_p, players[i].finishedrings); - WRITEUINT32(save_p, players[i].marescore); - WRITEUINT32(save_p, players[i].lastmarescore); - WRITEUINT8(save_p, players[i].lastmare); - WRITEINT32(save_p, players[i].maxlink); - WRITEUINT8(save_p, players[i].texttimer); - WRITEUINT8(save_p, players[i].textvar); + WRITEUINT32(save->p, players[i].marebegunat); + WRITEUINT32(save->p, players[i].startedtime); + WRITEUINT32(save->p, players[i].finishedtime); + WRITEINT16(save->p, players[i].finishedrings); + WRITEUINT32(save->p, players[i].marescore); + WRITEUINT32(save->p, players[i].lastmarescore); + WRITEUINT8(save->p, players[i].lastmare); + WRITEINT32(save->p, players[i].maxlink); + WRITEUINT8(save->p, players[i].texttimer); + WRITEUINT8(save->p, players[i].textvar); if (players[i].capsule) flags |= CAPSULE; @@ -250,47 +248,47 @@ static void P_NetArchivePlayers(boolean resending) if (players[i].axis2) flags |= SECONDAXIS; - WRITEINT16(save_p, players[i].lastsidehit); - WRITEINT16(save_p, players[i].lastlinehit); + WRITEINT16(save->p, players[i].lastsidehit); + WRITEINT16(save->p, players[i].lastlinehit); - WRITEUINT32(save_p, players[i].losstime); + WRITEUINT32(save->p, players[i].losstime); - WRITEUINT8(save_p, players[i].timeshit); + WRITEUINT8(save->p, players[i].timeshit); - WRITEINT32(save_p, players[i].onconveyor); + WRITEINT32(save->p, players[i].onconveyor); - WRITEUINT32(save_p, players[i].jointime); - WRITEUINT32(save_p, players[i].spectatorreentry); + WRITEUINT32(save->p, players[i].jointime); + WRITEUINT32(save->p, players[i].spectatorreentry); - WRITEUINT32(save_p, players[i].grieftime); - WRITEUINT8(save_p, players[i].griefstrikes); + WRITEUINT32(save->p, players[i].grieftime); + WRITEUINT8(save->p, players[i].griefstrikes); - WRITEUINT8(save_p, players[i].splitscreenindex); + WRITEUINT8(save->p, players[i].splitscreenindex); - WRITEUINT16(save_p, flags); + WRITEUINT16(save->p, flags); if (flags & CAPSULE) - WRITEUINT32(save_p, players[i].capsule->mobjnum); + WRITEUINT32(save->p, players[i].capsule->mobjnum); if (flags & FIRSTAXIS) - WRITEUINT32(save_p, players[i].axis1->mobjnum); + WRITEUINT32(save->p, players[i].axis1->mobjnum); if (flags & SECONDAXIS) - WRITEUINT32(save_p, players[i].axis2->mobjnum); + WRITEUINT32(save->p, players[i].axis2->mobjnum); if (flags & AWAYVIEW) - WRITEUINT32(save_p, players[i].awayviewmobj->mobjnum); + WRITEUINT32(save->p, players[i].awayviewmobj->mobjnum); - WRITEUINT32(save_p, players[i].charflags); + WRITEUINT32(save->p, players[i].charflags); // SRB2kart - WRITEUINT8(save_p, players[i].kartspeed); - WRITEUINT8(save_p, players[i].kartweight); + WRITEUINT8(save->p, players[i].kartspeed); + WRITEUINT8(save->p, players[i].kartweight); // for (j = 0; j < MAXPREDICTTICS; j++) { - WRITEINT16(save_p, players[i].lturn_max[j]); - WRITEINT16(save_p, players[i].rturn_max[j]); + WRITEINT16(save->p, players[i].lturn_max[j]); + WRITEINT16(save->p, players[i].rturn_max[j]); } } } @@ -298,18 +296,18 @@ static void P_NetArchivePlayers(boolean resending) // // P_NetUnArchivePlayers // -static void P_NetUnArchivePlayers(boolean reloading) +static void P_NetUnArchivePlayers(savebuffer_t *save, boolean reloading) { INT32 i, j; UINT16 flags; - if (READUINT32(save_p) != ARCHIVEBLOCK_PLAYERS) + if (READUINT32(save->p) != ARCHIVEBLOCK_PLAYERS) I_Error("Bad $$$.sav at archive block Players"); for (i = 0; i < MAXPLAYERS; i++) { if (reloading) - adminplayers[i] = (INT32)READSINT8(save_p); + adminplayers[i] = (INT32)READSINT8(save->p); // Do NOT memset player struct to 0 // other areas may initialize data elsewhere @@ -318,167 +316,169 @@ static void P_NetUnArchivePlayers(boolean reloading) continue; // NOTE: sending tics should (hopefully) no longer be necessary - // sending player names, skin and color should not be necessary at all! - // (that data is handled in the server config now) if (reloading) - READSTRINGN(save_p, player_names[i], MAXPLAYERNAME); + READSTRINGN(save->p, player_names[i], MAXPLAYERNAME); - players[i].aiming = READANGLE(save_p); - players[i].awayviewaiming = READANGLE(save_p); - players[i].awayviewtics = READINT32(save_p); - players[i].health = READINT32(save_p); + players[i].aiming = READANGLE(save->p); + players[i].awayviewaiming = READANGLE(save->p); + players[i].awayviewtics = READINT32(save->p); + players[i].health = READINT32(save->p); - players[i].pity = READSINT8(save_p); - players[i].currentweapon = READINT32(save_p); - players[i].ringweapons = READINT32(save_p); + players[i].pity = READSINT8(save->p); + players[i].currentweapon = READINT32(save->p); + players[i].ringweapons = READINT32(save->p); for (j = 0; j < NUMPOWERS; j++) - players[i].powers[j] = READUINT16(save_p); + players[i].powers[j] = READUINT16(save->p); for (j = 0; j < NUMKARTSTUFF; j++) - players[i].kartstuff[j] = READINT32(save_p); + players[i].kartstuff[j] = READINT32(save->p); - players[i].frameangle = READANGLE(save_p); + players[i].frameangle = READANGLE(save->p); - players[i].playerstate = READUINT8(save_p); - players[i].pflags = READUINT32(save_p); - players[i].panim = READUINT8(save_p); - players[i].spectator = READUINT8(save_p); + players[i].playerstate = READUINT8(save->p); + players[i].pflags = READUINT32(save->p); + players[i].panim = READUINT8(save->p); + players[i].spectator = READUINT8(save->p); - players[i].flashpal = READUINT16(save_p); - players[i].flashcount = READUINT16(save_p); + players[i].flashpal = READUINT16(save->p); + players[i].flashcount = READUINT16(save->p); if (reloading) { - players[i].skincolor = READUINT8(save_p); - players[i].skin = READINT32(save_p); + players[i].skincolor = READUINT8(save->p); + players[i].skin = READINT32(save->p); } - players[i].score = READUINT32(save_p); - players[i].dashspeed = READFIXED(save_p); // dashing speed - players[i].dashtime = READINT32(save_p); // dashing speed - players[i].lives = READSINT8(save_p); - players[i].continues = READSINT8(save_p); // continues that player has acquired - players[i].xtralife = READSINT8(save_p); // Ring Extra Life counter - players[i].gotcontinue = READUINT8(save_p); // got continue from stage - players[i].speed = READFIXED(save_p); // Player's speed (distance formula of MOMX and MOMY values) - players[i].jumping = READUINT8(save_p); // Jump counter - players[i].secondjump = READUINT8(save_p); - players[i].fly1 = READUINT8(save_p); // Tails flying - players[i].scoreadd = READUINT8(save_p); // Used for multiple enemy attack bonus - players[i].glidetime = READUINT32(save_p); // Glide counter for thrust - players[i].climbing = READUINT8(save_p); // Climbing on the wall - players[i].deadtimer = READINT32(save_p); // End game if game over lasts too long - players[i].exiting = READUINT32(save_p); // Exitlevel timer - players[i].homing = READUINT8(save_p); // Are you homing? - players[i].skidtime = READUINT32(save_p); // Skid timer + players[i].score = READUINT32(save->p); + players[i].dashspeed = READFIXED(save->p); // dashing speed + players[i].dashtime = READINT32(save->p); // dashing speed + players[i].lives = READSINT8(save->p); + players[i].continues = READSINT8(save->p); // continues that player has acquired + players[i].xtralife = READSINT8(save->p); // Ring Extra Life counter + players[i].gotcontinue = READUINT8(save->p); // got continue from stage + players[i].speed = READFIXED(save->p); // Player's speed (distance formula of MOMX and MOMY values) + players[i].jumping = READUINT8(save->p); // Jump counter + players[i].secondjump = READUINT8(save->p); + players[i].fly1 = READUINT8(save->p); // Tails flying + players[i].scoreadd = READUINT8(save->p); // Used for multiple enemy attack bonus + players[i].glidetime = READUINT32(save->p); // Glide counter for thrust + players[i].climbing = READUINT8(save->p); // Climbing on the wall + players[i].deadtimer = READINT32(save->p); // End game if game over lasts too long + players[i].exiting = READUINT32(save->p); // Exitlevel timer + players[i].homing = READUINT8(save->p); // Are you homing? + players[i].skidtime = READUINT32(save->p); // Skid timer //////////////////////////// // Conveyor Belt Movement // //////////////////////////// - players[i].cmomx = READFIXED(save_p); // Conveyor momx - players[i].cmomy = READFIXED(save_p); // Conveyor momy - players[i].rmomx = READFIXED(save_p); // "Real" momx (momx - cmomx) - players[i].rmomy = READFIXED(save_p); // "Real" momy (momy - cmomy) + players[i].cmomx = READFIXED(save->p); // Conveyor momx + players[i].cmomy = READFIXED(save->p); // Conveyor momy + players[i].rmomx = READFIXED(save->p); // "Real" momx (momx - cmomx) + players[i].rmomy = READFIXED(save->p); // "Real" momy (momy - cmomy) ///////////////////// // Race Mode Stuff // ///////////////////// - players[i].numboxes = READINT16(save_p); // Number of item boxes obtained for Race Mode - players[i].totalring = READINT16(save_p); // Total number of rings obtained for Race Mode - players[i].realtime = READUINT32(save_p); // integer replacement for leveltime - players[i].laps = READUINT8(save_p); // Number of laps (optional) + players[i].numboxes = READINT16(save->p); // Number of item boxes obtained for Race Mode + players[i].totalring = READINT16(save->p); // Total number of rings obtained for Race Mode + players[i].realtime = READUINT32(save->p); // integer replacement for leveltime + players[i].laps = READUINT8(save->p); // Number of laps (optional) //////////////////// // CTF Mode Stuff // //////////////////// - players[i].ctfteam = READINT32(save_p); // 1 == Red, 2 == Blue - players[i].gotflag = READUINT16(save_p); // 1 == Red, 2 == Blue Do you have the flag? + players[i].ctfteam = READINT32(save->p); // 1 == Red, 2 == Blue + players[i].gotflag = READUINT16(save->p); // 1 == Red, 2 == Blue Do you have the flag? - players[i].weapondelay = READINT32(save_p); - players[i].tossdelay = READINT32(save_p); + players[i].weapondelay = READINT32(save->p); + players[i].tossdelay = READINT32(save->p); - players[i].starposttime = READUINT32(save_p); - players[i].starpostx = READINT16(save_p); - players[i].starposty = READINT16(save_p); - players[i].starpostz = READINT16(save_p); - players[i].starpostnum = READINT32(save_p); - players[i].starpostangle = READANGLE(save_p); + players[i].starposttime = READUINT32(save->p); + players[i].starpostx = READINT16(save->p); + players[i].starposty = READINT16(save->p); + players[i].starpostz = READINT16(save->p); + players[i].starpostnum = READINT32(save->p); + players[i].starpostangle = READANGLE(save->p); - players[i].angle_pos = READANGLE(save_p); - players[i].old_angle_pos = READANGLE(save_p); + players[i].angle_pos = READANGLE(save->p); + players[i].old_angle_pos = READANGLE(save->p); - players[i].flyangle = READINT32(save_p); - players[i].drilltimer = READUINT32(save_p); - players[i].linkcount = READINT32(save_p); - players[i].linktimer = READUINT32(save_p); - players[i].anotherflyangle = READINT32(save_p); - players[i].nightstime = READUINT32(save_p); - players[i].bumpertime = READUINT32(save_p); - players[i].drillmeter = READINT32(save_p); - players[i].drilldelay = READUINT8(save_p); - players[i].bonustime = (boolean)READUINT8(save_p); - players[i].mare = READUINT8(save_p); + players[i].flyangle = READINT32(save->p); + players[i].drilltimer = READUINT32(save->p); + players[i].linkcount = READINT32(save->p); + players[i].linktimer = READUINT32(save->p); + players[i].anotherflyangle = READINT32(save->p); + players[i].nightstime = READUINT32(save->p); + players[i].bumpertime = READUINT32(save->p); + players[i].drillmeter = READINT32(save->p); + players[i].drilldelay = READUINT8(save->p); + players[i].bonustime = (boolean)READUINT8(save->p); + players[i].mare = READUINT8(save->p); - players[i].marebegunat = READUINT32(save_p); - players[i].startedtime = READUINT32(save_p); - players[i].finishedtime = READUINT32(save_p); - players[i].finishedrings = READINT16(save_p); - players[i].marescore = READUINT32(save_p); - players[i].lastmarescore = READUINT32(save_p); - players[i].lastmare = READUINT8(save_p); - players[i].maxlink = READINT32(save_p); - players[i].texttimer = READUINT8(save_p); - players[i].textvar = READUINT8(save_p); + players[i].marebegunat = READUINT32(save->p); + players[i].startedtime = READUINT32(save->p); + players[i].finishedtime = READUINT32(save->p); + players[i].finishedrings = READINT16(save->p); + players[i].marescore = READUINT32(save->p); + players[i].lastmarescore = READUINT32(save->p); + players[i].lastmare = READUINT8(save->p); + players[i].maxlink = READINT32(save->p); + players[i].texttimer = READUINT8(save->p); + players[i].textvar = READUINT8(save->p); - players[i].lastsidehit = READINT16(save_p); - players[i].lastlinehit = READINT16(save_p); + players[i].lastsidehit = READINT16(save->p); + players[i].lastlinehit = READINT16(save->p); - players[i].losstime = READUINT32(save_p); + players[i].losstime = READUINT32(save->p); - players[i].timeshit = READUINT8(save_p); + players[i].timeshit = READUINT8(save->p); - players[i].onconveyor = READINT32(save_p); + players[i].onconveyor = READINT32(save->p); - players[i].jointime = READUINT32(save_p); - players[i].spectatorreentry = READUINT32(save_p); + players[i].jointime = READUINT32(save->p); + players[i].spectatorreentry = READUINT32(save->p); - players[i].grieftime = READUINT32(save_p); - players[i].griefstrikes = READUINT8(save_p); + players[i].grieftime = READUINT32(save->p); + players[i].griefstrikes = READUINT8(save->p); - players[i].splitscreenindex = READUINT8(save_p); + players[i].splitscreenindex = READUINT8(save->p); - flags = READUINT16(save_p); + flags = READUINT16(save->p); if (flags & CAPSULE) - players[i].capsule = (mobj_t *)(size_t)READUINT32(save_p); + players[i].capsule = (mobj_t *)(size_t)READUINT32(save->p); if (flags & FIRSTAXIS) - players[i].axis1 = (mobj_t *)(size_t)READUINT32(save_p); + players[i].axis1 = (mobj_t *)(size_t)READUINT32(save->p); if (flags & SECONDAXIS) - players[i].axis2 = (mobj_t *)(size_t)READUINT32(save_p); + players[i].axis2 = (mobj_t *)(size_t)READUINT32(save->p); if (flags & AWAYVIEW) - players[i].awayviewmobj = (mobj_t *)(size_t)READUINT32(save_p); + players[i].awayviewmobj = (mobj_t *)(size_t)READUINT32(save->p); players[i].viewheight = 32<p); // SRB2kart - players[i].kartspeed = READUINT8(save_p); - players[i].kartweight = READUINT8(save_p); + players[i].kartspeed = READUINT8(save->p); + players[i].kartweight = READUINT8(save->p); // for (j = 0; j < MAXPREDICTTICS; j++) { - players[i].lturn_max[j] = READINT16(save_p); - players[i].rturn_max[j] = READINT16(save_p); + players[i].lturn_max[j] = READINT16(save->p); + players[i].rturn_max[j] = READINT16(save->p); } } } +/// +/// World Archiving +/// + #define SD_FLOORHT 0x01 #define SD_CEILHT 0x02 #define SD_FLOORPIC 0x04 @@ -516,7 +516,7 @@ static void P_NetUnArchivePlayers(boolean reloading) // // P_NetArchiveWorld // -static void P_NetArchiveWorld(void) +static void P_NetArchiveWorld(savebuffer_t *save) { size_t i; const line_t *li = lines; @@ -531,8 +531,8 @@ static void P_NetArchiveWorld(void) const sector_t *ss = sectors; UINT8 diff, diff2; - WRITEUINT32(save_p, ARCHIVEBLOCK_WORLD); - put = save_p; + WRITEUINT32(save->p, ARCHIVEBLOCK_WORLD); + put = save->p; for (i = 0; i < numsectors; i++, ss++, ms++) { @@ -744,13 +744,13 @@ static void P_NetArchiveWorld(void) R_ClearTextureNumCache(false); vres_Free(virt); - save_p = put; + save->p = put; } // // P_NetUnArchiveWorld // -static void P_NetUnArchiveWorld(void) +static void P_NetUnArchiveWorld(savebuffer_t *save) { UINT16 i; line_t *li; @@ -758,10 +758,10 @@ static void P_NetUnArchiveWorld(void) UINT8 *get; UINT8 diff, diff2; - if (READUINT32(save_p) != ARCHIVEBLOCK_WORLD) + if (READUINT32(save->p) != ARCHIVEBLOCK_WORLD) I_Error("Bad $$$.sav at archive block World"); - get = save_p; + get = save->p; for (;;) { @@ -903,7 +903,7 @@ static void P_NetUnArchiveWorld(void) si->midtexture = READINT32(get); } - save_p = get; + save->p = get; } // @@ -1027,12 +1027,13 @@ static inline UINT32 SavePlayer(const player_t *player) return 0xFFFFFFFF; } + // // SaveMobjThinker // // Saves a mobj_t thinker // -static void SaveMobjThinker(const thinker_t *th, const UINT8 type) +static void SaveMobjThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const mobj_t *mobj = (const mobj_t *)th; UINT32 diff; @@ -1161,17 +1162,17 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type) if (mobj->type == MT_HOOPCENTER) diff = MD_SPAWNPOINT; - WRITEUINT8(save_p, type); - WRITEUINT32(save_p, diff); + WRITEUINT8(save->p, type); + WRITEUINT32(save->p, diff); if (diff & MD_MORE) - WRITEUINT16(save_p, diff2); + WRITEUINT16(save->p, diff2); // save pointer, at load time we will search this pointer to reinitilize pointers - WRITEUINT32(save_p, (size_t)mobj); + WRITEUINT32(save->p, (size_t)mobj); - WRITEFIXED(save_p, mobj->z); // Force this so 3dfloor problems don't arise. - WRITEFIXED(save_p, mobj->floorz); - WRITEFIXED(save_p, mobj->ceilingz); + WRITEFIXED(save->p, mobj->z); // Force this so 3dfloor problems don't arise. + WRITEFIXED(save->p, mobj->floorz); + WRITEFIXED(save->p, mobj->ceilingz); if (diff & MD_SPAWNPOINT) { @@ -1179,102 +1180,102 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type) for (z = 0; z < nummapthings; z++) if (&mapthings[z] == mobj->spawnpoint) - WRITEUINT16(save_p, z); + WRITEUINT16(save->p, z); if (mobj->type == MT_HOOPCENTER) return; } if (diff & MD_TYPE) - WRITEUINT32(save_p, mobj->type); + WRITEUINT32(save->p, mobj->type); if (diff & MD_POS) { - WRITEFIXED(save_p, mobj->x); - WRITEFIXED(save_p, mobj->y); - WRITEANGLE(save_p, mobj->angle); + WRITEFIXED(save->p, mobj->x); + WRITEFIXED(save->p, mobj->y); + WRITEANGLE(save->p, mobj->angle); } if (diff & MD_MOM) { - WRITEFIXED(save_p, mobj->momx); - WRITEFIXED(save_p, mobj->momy); - WRITEFIXED(save_p, mobj->momz); + WRITEFIXED(save->p, mobj->momx); + WRITEFIXED(save->p, mobj->momy); + WRITEFIXED(save->p, mobj->momz); } if (diff & MD_RADIUS) - WRITEFIXED(save_p, mobj->radius); + WRITEFIXED(save->p, mobj->radius); if (diff & MD_HEIGHT) - WRITEFIXED(save_p, mobj->height); + WRITEFIXED(save->p, mobj->height); if (diff & MD_FLAGS) - WRITEUINT32(save_p, mobj->flags); + WRITEUINT32(save->p, mobj->flags); if (diff & MD_FLAGS2) - WRITEUINT32(save_p, mobj->flags2); + WRITEUINT32(save->p, mobj->flags2); if (diff & MD_HEALTH) - WRITEINT32(save_p, mobj->health); + WRITEINT32(save->p, mobj->health); if (diff & MD_RTIME) - WRITEINT32(save_p, mobj->reactiontime); + WRITEINT32(save->p, mobj->reactiontime); if (diff & MD_STATE) - WRITEUINT16(save_p, mobj->state-states); + WRITEUINT16(save->p, mobj->state-states); if (diff & MD_TICS) - WRITEINT32(save_p, mobj->tics); + WRITEINT32(save->p, mobj->tics); if (diff & MD_SPRITE) - WRITEUINT16(save_p, mobj->sprite); + WRITEUINT16(save->p, mobj->sprite); if (diff & MD_FRAME) { - WRITEUINT32(save_p, mobj->frame); - WRITEUINT16(save_p, mobj->anim_duration); + WRITEUINT32(save->p, mobj->frame); + WRITEUINT16(save->p, mobj->anim_duration); } if (diff & MD_EFLAGS) - WRITEUINT16(save_p, mobj->eflags); + WRITEUINT16(save->p, mobj->eflags); if (diff & MD_PLAYER) - WRITEUINT8(save_p, mobj->player-players); + WRITEUINT8(save->p, mobj->player-players); if (diff & MD_MOVEDIR) - WRITEANGLE(save_p, mobj->movedir); + WRITEANGLE(save->p, mobj->movedir); if (diff & MD_MOVECOUNT) - WRITEINT32(save_p, mobj->movecount); + WRITEINT32(save->p, mobj->movecount); if (diff & MD_THRESHOLD) - WRITEINT32(save_p, mobj->threshold); + WRITEINT32(save->p, mobj->threshold); if (diff & MD_LASTLOOK) - WRITEINT32(save_p, mobj->lastlook); + WRITEINT32(save->p, mobj->lastlook); if (diff & MD_TARGET) - WRITEUINT32(save_p, mobj->target->mobjnum); + WRITEUINT32(save->p, mobj->target->mobjnum); if (diff & MD_TRACER) - WRITEUINT32(save_p, mobj->tracer->mobjnum); + WRITEUINT32(save->p, mobj->tracer->mobjnum); if (diff & MD_FRICTION) - WRITEFIXED(save_p, mobj->friction); + WRITEFIXED(save->p, mobj->friction); if (diff & MD_MOVEFACTOR) - WRITEFIXED(save_p, mobj->movefactor); + WRITEFIXED(save->p, mobj->movefactor); if (diff & MD_FUSE) - WRITEINT32(save_p, mobj->fuse); + WRITEINT32(save->p, mobj->fuse); if (diff & MD_WATERTOP) - WRITEFIXED(save_p, mobj->watertop); + WRITEFIXED(save->p, mobj->watertop); if (diff & MD_WATERBOTTOM) - WRITEFIXED(save_p, mobj->waterbottom); + WRITEFIXED(save->p, mobj->waterbottom); if (diff & MD_SCALE) - WRITEFIXED(save_p, mobj->scale); + WRITEFIXED(save->p, mobj->scale); if (diff & MD_DSCALE) - WRITEFIXED(save_p, mobj->destscale); + WRITEFIXED(save->p, mobj->destscale); if (diff2 & MD2_SCALESPEED) - WRITEFIXED(save_p, mobj->scalespeed); + WRITEFIXED(save->p, mobj->scalespeed); if (diff2 & MD2_CUSVAL) - WRITEINT32(save_p, mobj->cusval); + WRITEINT32(save->p, mobj->cusval); if (diff2 & MD2_CVMEM) - WRITEINT32(save_p, mobj->cvmem); + WRITEINT32(save->p, mobj->cvmem); if (diff2 & MD2_SKIN) - WRITEUINT8(save_p, (UINT8)((skin_t *)mobj->skin - skins)); + WRITEUINT8(save->p, (UINT8)((skin_t *)mobj->skin - skins)); if (diff2 & MD2_COLOR) - WRITEUINT8(save_p, mobj->color); + WRITEUINT8(save->p, mobj->color); if (diff2 & MD2_EXTVAL1) - WRITEINT32(save_p, mobj->extravalue1); + WRITEINT32(save->p, mobj->extravalue1); if (diff2 & MD2_EXTVAL2) - WRITEINT32(save_p, mobj->extravalue2); + WRITEINT32(save->p, mobj->extravalue2); if (diff2 & MD2_HNEXT) - WRITEUINT32(save_p, mobj->hnext->mobjnum); + WRITEUINT32(save->p, mobj->hnext->mobjnum); if (diff2 & MD2_HPREV) - WRITEUINT32(save_p, mobj->hprev->mobjnum); + WRITEUINT32(save->p, mobj->hprev->mobjnum); if (diff2 & MD2_SLOPE) - WRITEUINT16(save_p, mobj->standingslope->id); + WRITEUINT16(save->p, mobj->standingslope->id); if (diff2 & MD2_COLORIZED) - WRITEUINT8(save_p, mobj->colorized); + WRITEUINT8(save->p, mobj->colorized); - WRITEUINT32(save_p, mobj->mobjnum); + WRITEUINT32(save->p, mobj->mobjnum); } // @@ -1282,18 +1283,18 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type) // // Saves a levelspecthink_t thinker // -static void SaveSpecialLevelThinker(const thinker_t *th, const UINT8 type) +static void SaveSpecialLevelThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const levelspecthink_t *ht = (const void *)th; size_t i; - WRITEUINT8(save_p, type); + WRITEUINT8(save->p, type); for (i = 0; i < 16; i++) { - WRITEFIXED(save_p, ht->vars[i]); //var[16] - WRITEFIXED(save_p, ht->var2s[i]); //var[16] + WRITEFIXED(save->p, ht->vars[i]); //var[16] + WRITEFIXED(save->p, ht->var2s[i]); //var[16] } - WRITEUINT32(save_p, SaveLine(ht->sourceline)); - WRITEUINT32(save_p, SaveSector(ht->sector)); + WRITEUINT32(save->p, SaveLine(ht->sourceline)); + WRITEUINT32(save->p, SaveSector(ht->sector)); } // @@ -1301,25 +1302,25 @@ static void SaveSpecialLevelThinker(const thinker_t *th, const UINT8 type) // // Saves a ceiling_t thinker // -static void SaveCeilingThinker(const thinker_t *th, const UINT8 type) +static void SaveCeilingThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const ceiling_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT8(save_p, ht->type); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEFIXED(save_p, ht->bottomheight); - WRITEFIXED(save_p, ht->topheight); - WRITEFIXED(save_p, ht->speed); - WRITEFIXED(save_p, ht->oldspeed); - WRITEFIXED(save_p, ht->delay); - WRITEFIXED(save_p, ht->delaytimer); - WRITEUINT8(save_p, ht->crush); - WRITEINT32(save_p, ht->texture); - WRITEINT32(save_p, ht->direction); - WRITEINT32(save_p, ht->tag); - WRITEINT32(save_p, ht->olddirection); - WRITEFIXED(save_p, ht->origspeed); - WRITEFIXED(save_p, ht->sourceline); + WRITEUINT8(save->p, type); + WRITEUINT8(save->p, ht->type); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEFIXED(save->p, ht->bottomheight); + WRITEFIXED(save->p, ht->topheight); + WRITEFIXED(save->p, ht->speed); + WRITEFIXED(save->p, ht->oldspeed); + WRITEFIXED(save->p, ht->delay); + WRITEFIXED(save->p, ht->delaytimer); + WRITEUINT8(save->p, ht->crush); + WRITEINT32(save->p, ht->texture); + WRITEINT32(save->p, ht->direction); + WRITEINT32(save->p, ht->tag); + WRITEINT32(save->p, ht->olddirection); + WRITEFIXED(save->p, ht->origspeed); + WRITEFIXED(save->p, ht->sourceline); } // @@ -1327,20 +1328,20 @@ static void SaveCeilingThinker(const thinker_t *th, const UINT8 type) // // Saves a floormove_t thinker // -static void SaveFloormoveThinker(const thinker_t *th, const UINT8 type) +static void SaveFloormoveThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const floormove_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT8(save_p, ht->type); - WRITEUINT8(save_p, ht->crush); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEINT32(save_p, ht->direction); - WRITEINT32(save_p, ht->texture); - WRITEFIXED(save_p, ht->floordestheight); - WRITEFIXED(save_p, ht->speed); - WRITEFIXED(save_p, ht->origspeed); - WRITEFIXED(save_p, ht->delay); - WRITEFIXED(save_p, ht->delaytimer); + WRITEUINT8(save->p, type); + WRITEUINT8(save->p, ht->type); + WRITEUINT8(save->p, ht->crush); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEINT32(save->p, ht->direction); + WRITEINT32(save->p, ht->texture); + WRITEFIXED(save->p, ht->floordestheight); + WRITEFIXED(save->p, ht->speed); + WRITEFIXED(save->p, ht->origspeed); + WRITEFIXED(save->p, ht->delay); + WRITEFIXED(save->p, ht->delaytimer); } // @@ -1348,13 +1349,13 @@ static void SaveFloormoveThinker(const thinker_t *th, const UINT8 type) // // Saves a lightflash_t thinker // -static void SaveLightflashThinker(const thinker_t *th, const UINT8 type) +static void SaveLightflashThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const lightflash_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEINT32(save_p, ht->maxlight); - WRITEINT32(save_p, ht->minlight); + WRITEUINT8(save->p, type); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEINT32(save->p, ht->maxlight); + WRITEINT32(save->p, ht->minlight); } // @@ -1362,16 +1363,16 @@ static void SaveLightflashThinker(const thinker_t *th, const UINT8 type) // // Saves a strobe_t thinker // -static void SaveStrobeThinker(const thinker_t *th, const UINT8 type) +static void SaveStrobeThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const strobe_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEINT32(save_p, ht->count); - WRITEINT32(save_p, ht->minlight); - WRITEINT32(save_p, ht->maxlight); - WRITEINT32(save_p, ht->darktime); - WRITEINT32(save_p, ht->brighttime); + WRITEUINT8(save->p, type); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEINT32(save->p, ht->count); + WRITEINT32(save->p, ht->minlight); + WRITEINT32(save->p, ht->maxlight); + WRITEINT32(save->p, ht->darktime); + WRITEINT32(save->p, ht->brighttime); } // @@ -1379,15 +1380,15 @@ static void SaveStrobeThinker(const thinker_t *th, const UINT8 type) // // Saves a glow_t thinker // -static void SaveGlowThinker(const thinker_t *th, const UINT8 type) +static void SaveGlowThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const glow_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEINT32(save_p, ht->minlight); - WRITEINT32(save_p, ht->maxlight); - WRITEINT32(save_p, ht->direction); - WRITEINT32(save_p, ht->speed); + WRITEUINT8(save->p, type); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEINT32(save->p, ht->minlight); + WRITEINT32(save->p, ht->maxlight); + WRITEINT32(save->p, ht->direction); + WRITEINT32(save->p, ht->speed); } // @@ -1395,15 +1396,15 @@ static void SaveGlowThinker(const thinker_t *th, const UINT8 type) // // Saves a fireflicker_t thinker // -static inline void SaveFireflickerThinker(const thinker_t *th, const UINT8 type) +static inline void SaveFireflickerThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const fireflicker_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEINT32(save_p, ht->count); - WRITEINT32(save_p, ht->resetcount); - WRITEINT32(save_p, ht->maxlight); - WRITEINT32(save_p, ht->minlight); + WRITEUINT8(save->p, type); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEINT32(save->p, ht->count); + WRITEINT32(save->p, ht->resetcount); + WRITEINT32(save->p, ht->maxlight); + WRITEINT32(save->p, ht->minlight); } // @@ -1411,27 +1412,27 @@ static inline void SaveFireflickerThinker(const thinker_t *th, const UINT8 type) // // Saves a elevator_t thinker // -static void SaveElevatorThinker(const thinker_t *th, const UINT8 type) +static void SaveElevatorThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const elevator_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT8(save_p, ht->type); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEUINT32(save_p, SaveSector(ht->actionsector)); - WRITEINT32(save_p, ht->direction); - WRITEFIXED(save_p, ht->floordestheight); - WRITEFIXED(save_p, ht->ceilingdestheight); - WRITEFIXED(save_p, ht->speed); - WRITEFIXED(save_p, ht->origspeed); - WRITEFIXED(save_p, ht->low); - WRITEFIXED(save_p, ht->high); - WRITEFIXED(save_p, ht->distance); - WRITEFIXED(save_p, ht->delay); - WRITEFIXED(save_p, ht->delaytimer); - WRITEFIXED(save_p, ht->floorwasheight); - WRITEFIXED(save_p, ht->ceilingwasheight); - WRITEUINT32(save_p, SavePlayer(ht->player)); // was dummy - WRITEUINT32(save_p, SaveLine(ht->sourceline)); + WRITEUINT8(save->p, type); + WRITEUINT8(save->p, ht->type); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEUINT32(save->p, SaveSector(ht->actionsector)); + WRITEINT32(save->p, ht->direction); + WRITEFIXED(save->p, ht->floordestheight); + WRITEFIXED(save->p, ht->ceilingdestheight); + WRITEFIXED(save->p, ht->speed); + WRITEFIXED(save->p, ht->origspeed); + WRITEFIXED(save->p, ht->low); + WRITEFIXED(save->p, ht->high); + WRITEFIXED(save->p, ht->distance); + WRITEFIXED(save->p, ht->delay); + WRITEFIXED(save->p, ht->delaytimer); + WRITEFIXED(save->p, ht->floorwasheight); + WRITEFIXED(save->p, ht->ceilingwasheight); + WRITEUINT32(save->p, SavePlayer(ht->player)); // was dummy + WRITEUINT32(save->p, SaveLine(ht->sourceline)); } // @@ -1439,20 +1440,20 @@ static void SaveElevatorThinker(const thinker_t *th, const UINT8 type) // // Saves a scroll_t thinker // -static inline void SaveScrollThinker(const thinker_t *th, const UINT8 type) +static inline void SaveScrollThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const scroll_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEFIXED(save_p, ht->dx); - WRITEFIXED(save_p, ht->dy); - WRITEINT32(save_p, ht->affectee); - WRITEINT32(save_p, ht->control); - WRITEFIXED(save_p, ht->last_height); - WRITEFIXED(save_p, ht->vdx); - WRITEFIXED(save_p, ht->vdy); - WRITEINT32(save_p, ht->accel); - WRITEINT32(save_p, ht->exclusive); - WRITEUINT8(save_p, ht->type); + WRITEUINT8(save->p, type); + WRITEFIXED(save->p, ht->dx); + WRITEFIXED(save->p, ht->dy); + WRITEINT32(save->p, ht->affectee); + WRITEINT32(save->p, ht->control); + WRITEFIXED(save->p, ht->last_height); + WRITEFIXED(save->p, ht->vdx); + WRITEFIXED(save->p, ht->vdy); + WRITEINT32(save->p, ht->accel); + WRITEINT32(save->p, ht->exclusive); + WRITEUINT8(save->p, ht->type); } // @@ -1460,15 +1461,15 @@ static inline void SaveScrollThinker(const thinker_t *th, const UINT8 type) // // Saves a friction_t thinker // -static inline void SaveFrictionThinker(const thinker_t *th, const UINT8 type) +static inline void SaveFrictionThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const friction_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEINT32(save_p, ht->friction); - WRITEINT32(save_p, ht->movefactor); - WRITEINT32(save_p, ht->affectee); - WRITEINT32(save_p, ht->referrer); - WRITEUINT8(save_p, ht->roverfriction); + WRITEUINT8(save->p, type); + WRITEINT32(save->p, ht->friction); + WRITEINT32(save->p, ht->movefactor); + WRITEINT32(save->p, ht->affectee); + WRITEINT32(save->p, ht->referrer); + WRITEUINT8(save->p, ht->roverfriction); } // @@ -1476,23 +1477,23 @@ static inline void SaveFrictionThinker(const thinker_t *th, const UINT8 type) // // Saves a pusher_t thinker // -static inline void SavePusherThinker(const thinker_t *th, const UINT8 type) +static inline void SavePusherThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const pusher_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT8(save_p, ht->type); - WRITEINT32(save_p, ht->x_mag); - WRITEINT32(save_p, ht->y_mag); - WRITEINT32(save_p, ht->magnitude); - WRITEINT32(save_p, ht->radius); - WRITEINT32(save_p, ht->x); - WRITEINT32(save_p, ht->y); - WRITEINT32(save_p, ht->z); - WRITEINT32(save_p, ht->affectee); - WRITEUINT8(save_p, ht->roverpusher); - WRITEINT32(save_p, ht->referrer); - WRITEINT32(save_p, ht->exclusive); - WRITEINT32(save_p, ht->slider); + WRITEUINT8(save->p, type); + WRITEUINT8(save->p, ht->type); + WRITEINT32(save->p, ht->x_mag); + WRITEINT32(save->p, ht->y_mag); + WRITEINT32(save->p, ht->magnitude); + WRITEINT32(save->p, ht->radius); + WRITEINT32(save->p, ht->x); + WRITEINT32(save->p, ht->y); + WRITEINT32(save->p, ht->z); + WRITEINT32(save->p, ht->affectee); + WRITEUINT8(save->p, ht->roverpusher); + WRITEINT32(save->p, ht->referrer); + WRITEINT32(save->p, ht->exclusive); + WRITEINT32(save->p, ht->slider); } // @@ -1500,13 +1501,13 @@ static inline void SavePusherThinker(const thinker_t *th, const UINT8 type) // // Saves a laserthink_t thinker // -static void SaveLaserThinker(const thinker_t *th, const UINT8 type) +static void SaveLaserThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const laserthink_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEUINT32(save_p, SaveSector(ht->sec)); - WRITEUINT32(save_p, SaveLine(ht->sourceline)); + WRITEUINT8(save->p, type); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEUINT32(save->p, SaveSector(ht->sec)); + WRITEUINT32(save->p, SaveLine(ht->sourceline)); } // @@ -1514,13 +1515,13 @@ static void SaveLaserThinker(const thinker_t *th, const UINT8 type) // // Saves a lightlevel_t thinker // -static void SaveLightlevelThinker(const thinker_t *th, const UINT8 type) +static void SaveLightlevelThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const lightlevel_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEINT32(save_p, ht->destlevel); - WRITEINT32(save_p, ht->speed); + WRITEUINT8(save->p, type); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEINT32(save->p, ht->destlevel); + WRITEINT32(save->p, ht->speed); } // @@ -1528,14 +1529,14 @@ static void SaveLightlevelThinker(const thinker_t *th, const UINT8 type) // // Saves a executor_t thinker // -static void SaveExecutorThinker(const thinker_t *th, const UINT8 type) +static void SaveExecutorThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const executor_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT32(save_p, SaveLine(ht->line)); - WRITEUINT32(save_p, SaveMobjnum(ht->caller)); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEINT32(save_p, ht->timer); + WRITEUINT8(save->p, type); + WRITEUINT32(save->p, SaveLine(ht->line)); + WRITEUINT32(save->p, SaveMobjnum(ht->caller)); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEINT32(save->p, ht->timer); } // @@ -1543,33 +1544,32 @@ static void SaveExecutorThinker(const thinker_t *th, const UINT8 type) // // Saves a disappear_t thinker // -static void SaveDisappearThinker(const thinker_t *th, const UINT8 type) +static void SaveDisappearThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const disappear_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT32(save_p, ht->appeartime); - WRITEUINT32(save_p, ht->disappeartime); - WRITEUINT32(save_p, ht->offset); - WRITEUINT32(save_p, ht->timer); - WRITEINT32(save_p, ht->affectee); - WRITEINT32(save_p, ht->sourceline); - WRITEINT32(save_p, ht->exists); + WRITEUINT8(save->p, type); + WRITEUINT32(save->p, ht->appeartime); + WRITEUINT32(save->p, ht->disappeartime); + WRITEUINT32(save->p, ht->offset); + WRITEUINT32(save->p, ht->timer); + WRITEINT32(save->p, ht->affectee); + WRITEINT32(save->p, ht->sourceline); + WRITEINT32(save->p, ht->exists); } - // // SavePolyrotateThinker // // Saves a polyrotate_t thinker // -static inline void SavePolyrotatetThinker(const thinker_t *th, const UINT8 type) +static inline void SavePolyrotatetThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const polyrotate_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEINT32(save_p, ht->polyObjNum); - WRITEINT32(save_p, ht->speed); - WRITEINT32(save_p, ht->distance); - WRITEUINT8(save_p, ht->turnobjs); + WRITEUINT8(save->p, type); + WRITEINT32(save->p, ht->polyObjNum); + WRITEINT32(save->p, ht->speed); + WRITEINT32(save->p, ht->distance); + WRITEUINT8(save->p, ht->turnobjs); } // @@ -1577,16 +1577,16 @@ static inline void SavePolyrotatetThinker(const thinker_t *th, const UINT8 type) // // Saves a polymovet_t thinker // -static void SavePolymoveThinker(const thinker_t *th, const UINT8 type) +static void SavePolymoveThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const polymove_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEINT32(save_p, ht->polyObjNum); - WRITEINT32(save_p, ht->speed); - WRITEFIXED(save_p, ht->momx); - WRITEFIXED(save_p, ht->momy); - WRITEINT32(save_p, ht->distance); - WRITEANGLE(save_p, ht->angle); + WRITEUINT8(save->p, type); + WRITEINT32(save->p, ht->polyObjNum); + WRITEINT32(save->p, ht->speed); + WRITEFIXED(save->p, ht->momx); + WRITEFIXED(save->p, ht->momy); + WRITEINT32(save->p, ht->distance); + WRITEANGLE(save->p, ht->angle); } // @@ -1594,22 +1594,22 @@ static void SavePolymoveThinker(const thinker_t *th, const UINT8 type) // // Saves a polywaypoint_t thinker // -static void SavePolywaypointThinker(const thinker_t *th, UINT8 type) +static void SavePolywaypointThinker(savebuffer_t *save, const thinker_t *th, UINT8 type) { const polywaypoint_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEINT32(save_p, ht->polyObjNum); - WRITEINT32(save_p, ht->speed); - WRITEINT32(save_p, ht->sequence); - WRITEINT32(save_p, ht->pointnum); - WRITEINT32(save_p, ht->direction); - WRITEUINT8(save_p, ht->comeback); - WRITEUINT8(save_p, ht->wrap); - WRITEUINT8(save_p, ht->continuous); - WRITEUINT8(save_p, ht->stophere); - WRITEFIXED(save_p, ht->diffx); - WRITEFIXED(save_p, ht->diffy); - WRITEFIXED(save_p, ht->diffz); + WRITEUINT8(save->p, type); + WRITEINT32(save->p, ht->polyObjNum); + WRITEINT32(save->p, ht->speed); + WRITEINT32(save->p, ht->sequence); + WRITEINT32(save->p, ht->pointnum); + WRITEINT32(save->p, ht->direction); + WRITEUINT8(save->p, ht->comeback); + WRITEUINT8(save->p, ht->wrap); + WRITEUINT8(save->p, ht->continuous); + WRITEUINT8(save->p, ht->stophere); + WRITEFIXED(save->p, ht->diffx); + WRITEFIXED(save->p, ht->diffy); + WRITEFIXED(save->p, ht->diffz); } // @@ -1617,23 +1617,23 @@ static void SavePolywaypointThinker(const thinker_t *th, UINT8 type) // // Saves a polyslidedoor_t thinker // -static void SavePolyslidedoorThinker(const thinker_t *th, const UINT8 type) +static void SavePolyslidedoorThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const polyslidedoor_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEINT32(save_p, ht->polyObjNum); - WRITEINT32(save_p, ht->delay); - WRITEINT32(save_p, ht->delayCount); - WRITEINT32(save_p, ht->initSpeed); - WRITEINT32(save_p, ht->speed); - WRITEINT32(save_p, ht->initDistance); - WRITEINT32(save_p, ht->distance); - WRITEUINT32(save_p, ht->initAngle); - WRITEUINT32(save_p, ht->angle); - WRITEUINT32(save_p, ht->revAngle); - WRITEFIXED(save_p, ht->momx); - WRITEFIXED(save_p, ht->momy); - WRITEUINT8(save_p, ht->closing); + WRITEUINT8(save->p, type); + WRITEINT32(save->p, ht->polyObjNum); + WRITEINT32(save->p, ht->delay); + WRITEINT32(save->p, ht->delayCount); + WRITEINT32(save->p, ht->initSpeed); + WRITEINT32(save->p, ht->speed); + WRITEINT32(save->p, ht->initDistance); + WRITEINT32(save->p, ht->distance); + WRITEUINT32(save->p, ht->initAngle); + WRITEUINT32(save->p, ht->angle); + WRITEUINT32(save->p, ht->revAngle); + WRITEFIXED(save->p, ht->momx); + WRITEFIXED(save->p, ht->momy); + WRITEUINT8(save->p, ht->closing); } // @@ -1641,54 +1641,41 @@ static void SavePolyslidedoorThinker(const thinker_t *th, const UINT8 type) // // Saves a polyswingdoor_t thinker // -static void SavePolyswingdoorThinker(const thinker_t *th, const UINT8 type) +static void SavePolyswingdoorThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const polyswingdoor_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEINT32(save_p, ht->polyObjNum); - WRITEINT32(save_p, ht->delay); - WRITEINT32(save_p, ht->delayCount); - WRITEINT32(save_p, ht->initSpeed); - WRITEINT32(save_p, ht->speed); - WRITEINT32(save_p, ht->initDistance); - WRITEINT32(save_p, ht->distance); - WRITEUINT8(save_p, ht->closing); + WRITEUINT8(save->p, type); + WRITEINT32(save->p, ht->polyObjNum); + WRITEINT32(save->p, ht->delay); + WRITEINT32(save->p, ht->delayCount); + WRITEINT32(save->p, ht->initSpeed); + WRITEINT32(save->p, ht->speed); + WRITEINT32(save->p, ht->initDistance); + WRITEINT32(save->p, ht->distance); + WRITEUINT8(save->p, ht->closing); } -static void SavePolydisplaceThinker(const thinker_t *th, const UINT8 type) +static void SavePolydisplaceThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const polydisplace_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEINT32(save_p, ht->polyObjNum); - WRITEUINT32(save_p, SaveSector(ht->controlSector)); - WRITEFIXED(save_p, ht->dx); - WRITEFIXED(save_p, ht->dy); - WRITEFIXED(save_p, ht->oldHeights); + WRITEUINT8(save->p, type); + WRITEINT32(save->p, ht->polyObjNum); + WRITEUINT32(save->p, SaveSector(ht->controlSector)); + WRITEFIXED(save->p, ht->dx); + WRITEFIXED(save->p, ht->dy); + WRITEFIXED(save->p, ht->oldHeights); } -/* -// -// SaveWhatThinker -// -// Saves a what_t thinker -// -static inline void SaveWhatThinker(const thinker_t *th, const UINT8 type) -{ - const what_t *ht = (const void *)th; - WRITEUINT8(save_p, type); -} -*/ - // // P_NetArchiveThinkers // // -static void P_NetArchiveThinkers(void) +static void P_NetArchiveThinkers(savebuffer_t *save) { const thinker_t *th; UINT32 numsaved = 0; - WRITEUINT32(save_p, ARCHIVEBLOCK_THINKERS); + WRITEUINT32(save->p, ARCHIVEBLOCK_THINKERS); // save off the current thinkers for (th = thinkercap.next; th != &thinkercap; th = th->next) @@ -1699,7 +1686,7 @@ static void P_NetArchiveThinkers(void) if (th->function.acp1 == (actionf_p1)P_MobjThinker) { - SaveMobjThinker(th, tc_mobj); + SaveMobjThinker(save, th, tc_mobj); continue; } #ifdef PARANOIA @@ -1707,177 +1694,177 @@ static void P_NetArchiveThinkers(void) #endif else if (th->function.acp1 == (actionf_p1)T_MoveCeiling) { - SaveCeilingThinker(th, tc_ceiling); + SaveCeilingThinker(save, th, tc_ceiling); continue; } else if (th->function.acp1 == (actionf_p1)T_CrushCeiling) { - SaveCeilingThinker(th, tc_crushceiling); + SaveCeilingThinker(save, th, tc_crushceiling); continue; } else if (th->function.acp1 == (actionf_p1)T_MoveFloor) { - SaveFloormoveThinker(th, tc_floor); + SaveFloormoveThinker(save, th, tc_floor); continue; } else if (th->function.acp1 == (actionf_p1)T_LightningFlash) { - SaveLightflashThinker(th, tc_flash); + SaveLightflashThinker(save, th, tc_flash); continue; } else if (th->function.acp1 == (actionf_p1)T_StrobeFlash) { - SaveStrobeThinker(th, tc_strobe); + SaveStrobeThinker(save, th, tc_strobe); continue; } else if (th->function.acp1 == (actionf_p1)T_Glow) { - SaveGlowThinker(th, tc_glow); + SaveGlowThinker(save, th, tc_glow); continue; } else if (th->function.acp1 == (actionf_p1)T_FireFlicker) { - SaveFireflickerThinker(th, tc_fireflicker); + SaveFireflickerThinker(save, th, tc_fireflicker); continue; } else if (th->function.acp1 == (actionf_p1)T_MoveElevator) { - SaveElevatorThinker(th, tc_elevator); + SaveElevatorThinker(save, th, tc_elevator); continue; } else if (th->function.acp1 == (actionf_p1)T_ContinuousFalling) { - SaveSpecialLevelThinker(th, tc_continuousfalling); + SaveSpecialLevelThinker(save, th, tc_continuousfalling); continue; } else if (th->function.acp1 == (actionf_p1)T_ThwompSector) { - SaveSpecialLevelThinker(th, tc_thwomp); + SaveSpecialLevelThinker(save, th, tc_thwomp); continue; } else if (th->function.acp1 == (actionf_p1)T_NoEnemiesSector) { - SaveSpecialLevelThinker(th, tc_noenemies); + SaveSpecialLevelThinker(save, th, tc_noenemies); continue; } else if (th->function.acp1 == (actionf_p1)T_EachTimeThinker) { - SaveSpecialLevelThinker(th, tc_eachtime); + SaveSpecialLevelThinker(save, th, tc_eachtime); continue; } else if (th->function.acp1 == (actionf_p1)T_RaiseSector) { - SaveSpecialLevelThinker(th, tc_raisesector); + SaveSpecialLevelThinker(save, th, tc_raisesector); continue; } else if (th->function.acp1 == (actionf_p1)T_CameraScanner) { - SaveElevatorThinker(th, tc_camerascanner); + SaveElevatorThinker(save, th, tc_camerascanner); continue; } else if (th->function.acp1 == (actionf_p1)T_Scroll) { - SaveScrollThinker(th, tc_scroll); + SaveScrollThinker(save, th, tc_scroll); continue; } else if (th->function.acp1 == (actionf_p1)T_Friction) { - SaveFrictionThinker(th, tc_friction); + SaveFrictionThinker(save, th, tc_friction); continue; } else if (th->function.acp1 == (actionf_p1)T_Pusher) { - SavePusherThinker(th, tc_pusher); + SavePusherThinker(save, th, tc_pusher); continue; } else if (th->function.acp1 == (actionf_p1)T_BounceCheese) { - SaveSpecialLevelThinker(th, tc_bouncecheese); + SaveSpecialLevelThinker(save, th, tc_bouncecheese); continue; } else if (th->function.acp1 == (actionf_p1)T_StartCrumble) { - SaveElevatorThinker(th, tc_startcrumble); + SaveElevatorThinker(save, th, tc_startcrumble); continue; } else if (th->function.acp1 == (actionf_p1)T_MarioBlock) { - SaveSpecialLevelThinker(th, tc_marioblock); + SaveSpecialLevelThinker(save, th, tc_marioblock); continue; } else if (th->function.acp1 == (actionf_p1)T_MarioBlockChecker) { - SaveSpecialLevelThinker(th, tc_marioblockchecker); + SaveSpecialLevelThinker(save, th, tc_marioblockchecker); continue; } else if (th->function.acp1 == (actionf_p1)T_SpikeSector) { - SaveSpecialLevelThinker(th, tc_spikesector); + SaveSpecialLevelThinker(save, th, tc_spikesector); continue; } else if (th->function.acp1 == (actionf_p1)T_FloatSector) { - SaveSpecialLevelThinker(th, tc_floatsector); + SaveSpecialLevelThinker(save, th, tc_floatsector); continue; } else if (th->function.acp1 == (actionf_p1)T_BridgeThinker) { - SaveSpecialLevelThinker(th, tc_bridgethinker); + SaveSpecialLevelThinker(save, th, tc_bridgethinker); continue; } else if (th->function.acp1 == (actionf_p1)T_LaserFlash) { - SaveLaserThinker(th, tc_laserflash); + SaveLaserThinker(save, th, tc_laserflash); continue; } else if (th->function.acp1 == (actionf_p1)T_LightFade) { - SaveLightlevelThinker(th, tc_lightfade); + SaveLightlevelThinker(save, th, tc_lightfade); continue; } else if (th->function.acp1 == (actionf_p1)T_ExecutorDelay) { - SaveExecutorThinker(th, tc_executor); + SaveExecutorThinker(save, th, tc_executor); continue; } else if (th->function.acp1 == (actionf_p1)T_Disappear) { - SaveDisappearThinker(th, tc_disappear); + SaveDisappearThinker(save, th, tc_disappear); continue; } else if (th->function.acp1 == (actionf_p1)T_PolyObjRotate) { - SavePolyrotatetThinker(th, tc_polyrotate); + SavePolyrotatetThinker(save, th, tc_polyrotate); continue; } else if (th->function.acp1 == (actionf_p1)T_PolyObjMove) { - SavePolymoveThinker(th, tc_polymove); + SavePolymoveThinker(save, th, tc_polymove); continue; } else if (th->function.acp1 == (actionf_p1)T_PolyObjWaypoint) { - SavePolywaypointThinker(th, tc_polywaypoint); + SavePolywaypointThinker(save, th, tc_polywaypoint); continue; } else if (th->function.acp1 == (actionf_p1)T_PolyDoorSlide) { - SavePolyslidedoorThinker(th, tc_polyslidedoor); + SavePolyslidedoorThinker(save, th, tc_polyslidedoor); continue; } else if (th->function.acp1 == (actionf_p1)T_PolyDoorSwing) { - SavePolyswingdoorThinker(th, tc_polyswingdoor); + SavePolyswingdoorThinker(save, th, tc_polyswingdoor); continue; } else if (th->function.acp1 == (actionf_p1)T_PolyObjFlag) { - SavePolymoveThinker(th, tc_polyflag); + SavePolymoveThinker(save, th, tc_polyflag); continue; } else if (th->function.acp1 == (actionf_p1)T_PolyObjDisplace) { - SavePolydisplaceThinker(th, tc_polydisplace); + SavePolydisplaceThinker(save, th, tc_polydisplace); continue; } #ifdef PARANOIA @@ -1888,7 +1875,7 @@ static void P_NetArchiveThinkers(void) CONS_Debug(DBG_NETPLAY, "%u thinkers saved\n", numsaved); - WRITEUINT8(save_p, tc_end); + WRITEUINT8(save->p, tc_end); } // Now save the pointers, tracer and target, but at load time we must @@ -1907,10 +1894,8 @@ mobj_t *P_FindNewPosition(UINT32 oldposition) mobj = (mobj_t *)th; - if (mobj->mobjnum != oldposition) - continue; - - return mobj; + if (mobj->mobjnum == oldposition) + return mobj; } CONS_Debug(DBG_GAMELOGIC, "mobj not found\n"); return NULL; @@ -1945,7 +1930,7 @@ static inline player_t *LoadPlayer(UINT32 player) // // Loads a mobj_t from a save game // -static void LoadMobjThinker(actionf_p1 thinker) +static void LoadMobjThinker(savebuffer_t *save, actionf_p1 thinker) { thinker_t *next; mobj_t *mobj; @@ -1954,21 +1939,21 @@ static void LoadMobjThinker(actionf_p1 thinker) INT32 i; fixed_t z, floorz, ceilingz; - diff = READUINT32(save_p); + diff = READUINT32(save->p); if (diff & MD_MORE) - diff2 = READUINT16(save_p); + diff2 = READUINT16(save->p); else diff2 = 0; - next = (void *)(size_t)READUINT32(save_p); + next = (void *)(size_t)READUINT32(save->p); - z = READFIXED(save_p); // Force this so 3dfloor problems don't arise. - floorz = READFIXED(save_p); - ceilingz = READFIXED(save_p); + z = READFIXED(save->p); // Force this so 3dfloor problems don't arise. + floorz = READFIXED(save->p); + ceilingz = READFIXED(save->p); if (diff & MD_SPAWNPOINT) { - UINT16 spawnpointnum = READUINT16(save_p); + UINT16 spawnpointnum = READUINT16(save->p); if (mapthings[spawnpointnum].type == 1705 || mapthings[spawnpointnum].type == 1713) // NiGHTS Hoop special case { @@ -1992,7 +1977,7 @@ static void LoadMobjThinker(actionf_p1 thinker) mobj->ceilingz = ceilingz; if (diff & MD_TYPE) - mobj->type = READUINT32(save_p); + mobj->type = READUINT32(save->p); else { for (i = 0; i < NUMMOBJTYPES; i++) @@ -2011,9 +1996,9 @@ static void LoadMobjThinker(actionf_p1 thinker) mobj->info = &mobjinfo[mobj->type]; if (diff & MD_POS) { - mobj->x = READFIXED(save_p); - mobj->y = READFIXED(save_p); - mobj->angle = READANGLE(save_p); + mobj->x = READFIXED(save->p); + mobj->y = READFIXED(save->p); + mobj->angle = READANGLE(save->p); } else { @@ -2023,50 +2008,50 @@ static void LoadMobjThinker(actionf_p1 thinker) } if (diff & MD_MOM) { - mobj->momx = READFIXED(save_p); - mobj->momy = READFIXED(save_p); - mobj->momz = READFIXED(save_p); + mobj->momx = READFIXED(save->p); + mobj->momy = READFIXED(save->p); + mobj->momz = READFIXED(save->p); } // otherwise they're zero, and the memset took care of it if (diff & MD_RADIUS) - mobj->radius = READFIXED(save_p); + mobj->radius = READFIXED(save->p); else mobj->radius = mobj->info->radius; if (diff & MD_HEIGHT) - mobj->height = READFIXED(save_p); + mobj->height = READFIXED(save->p); else mobj->height = mobj->info->height; if (diff & MD_FLAGS) - mobj->flags = READUINT32(save_p); + mobj->flags = READUINT32(save->p); else mobj->flags = mobj->info->flags; if (diff & MD_FLAGS2) - mobj->flags2 = READUINT32(save_p); + mobj->flags2 = READUINT32(save->p); if (diff & MD_HEALTH) - mobj->health = READINT32(save_p); + mobj->health = READINT32(save->p); else mobj->health = mobj->info->spawnhealth; if (diff & MD_RTIME) - mobj->reactiontime = READINT32(save_p); + mobj->reactiontime = READINT32(save->p); else mobj->reactiontime = mobj->info->reactiontime; if (diff & MD_STATE) - mobj->state = &states[READUINT16(save_p)]; + mobj->state = &states[READUINT16(save->p)]; else mobj->state = &states[mobj->info->spawnstate]; if (diff & MD_TICS) - mobj->tics = READINT32(save_p); + mobj->tics = READINT32(save->p); else mobj->tics = mobj->state->tics; if (diff & MD_SPRITE) - mobj->sprite = READUINT16(save_p); + mobj->sprite = READUINT16(save->p); else mobj->sprite = mobj->state->sprite; if (diff & MD_FRAME) { - mobj->frame = READUINT32(save_p); - mobj->anim_duration = READUINT16(save_p); + mobj->frame = READUINT32(save->p); + mobj->anim_duration = READUINT16(save->p); } else { @@ -2074,10 +2059,10 @@ static void LoadMobjThinker(actionf_p1 thinker) mobj->anim_duration = (UINT16)mobj->state->var2; } if (diff & MD_EFLAGS) - mobj->eflags = READUINT16(save_p); + mobj->eflags = READUINT16(save->p); if (diff & MD_PLAYER) { - i = READUINT8(save_p); + i = READUINT8(save->p); mobj->player = &players[i]; mobj->player->mo = mobj; // added for angle prediction @@ -2091,65 +2076,65 @@ static void LoadMobjThinker(actionf_p1 thinker) localangle[3] = mobj->angle; } if (diff & MD_MOVEDIR) - mobj->movedir = READANGLE(save_p); + mobj->movedir = READANGLE(save->p); if (diff & MD_MOVECOUNT) - mobj->movecount = READINT32(save_p); + mobj->movecount = READINT32(save->p); if (diff & MD_THRESHOLD) - mobj->threshold = READINT32(save_p); + mobj->threshold = READINT32(save->p); if (diff & MD_LASTLOOK) - mobj->lastlook = READINT32(save_p); + mobj->lastlook = READINT32(save->p); else mobj->lastlook = -1; if (diff & MD_TARGET) - mobj->target = (mobj_t *)(size_t)READUINT32(save_p); + mobj->target = (mobj_t *)(size_t)READUINT32(save->p); if (diff & MD_TRACER) - mobj->tracer = (mobj_t *)(size_t)READUINT32(save_p); + mobj->tracer = (mobj_t *)(size_t)READUINT32(save->p); if (diff & MD_FRICTION) - mobj->friction = READFIXED(save_p); + mobj->friction = READFIXED(save->p); else mobj->friction = ORIG_FRICTION; if (diff & MD_MOVEFACTOR) - mobj->movefactor = READFIXED(save_p); + mobj->movefactor = READFIXED(save->p); else mobj->movefactor = FRACUNIT; //mobj->movefactor = ORIG_FRICTION_FACTOR; if (diff & MD_FUSE) - mobj->fuse = READINT32(save_p); + mobj->fuse = READINT32(save->p); if (diff & MD_WATERTOP) - mobj->watertop = READFIXED(save_p); + mobj->watertop = READFIXED(save->p); if (diff & MD_WATERBOTTOM) - mobj->waterbottom = READFIXED(save_p); + mobj->waterbottom = READFIXED(save->p); if (diff & MD_SCALE) - mobj->scale = READFIXED(save_p); + mobj->scale = READFIXED(save->p); else mobj->scale = FRACUNIT; if (diff & MD_DSCALE) - mobj->destscale = READFIXED(save_p); + mobj->destscale = READFIXED(save->p); else mobj->destscale = mobj->scale; if (diff2 & MD2_SCALESPEED) - mobj->scalespeed = READFIXED(save_p); + mobj->scalespeed = READFIXED(save->p); else mobj->scalespeed = mapobjectscale/12; if (diff2 & MD2_CUSVAL) - mobj->cusval = READINT32(save_p); + mobj->cusval = READINT32(save->p); if (diff2 & MD2_CVMEM) - mobj->cvmem = READINT32(save_p); + mobj->cvmem = READINT32(save->p); if (diff2 & MD2_SKIN) - mobj->skin = &skins[READUINT8(save_p)]; + mobj->skin = &skins[READUINT8(save->p)]; if (diff2 & MD2_COLOR) - mobj->color = READUINT8(save_p); + mobj->color = READUINT8(save->p); if (diff2 & MD2_EXTVAL1) - mobj->extravalue1 = READINT32(save_p); + mobj->extravalue1 = READINT32(save->p); if (diff2 & MD2_EXTVAL2) - mobj->extravalue2 = READINT32(save_p); + mobj->extravalue2 = READINT32(save->p); if (diff2 & MD2_HNEXT) - mobj->hnext = (mobj_t *)(size_t)READUINT32(save_p); + mobj->hnext = (mobj_t *)(size_t)READUINT32(save->p); if (diff2 & MD2_HPREV) - mobj->hprev = (mobj_t *)(size_t)READUINT32(save_p); + mobj->hprev = (mobj_t *)(size_t)READUINT32(save->p); if (diff2 & MD2_SLOPE) - mobj->standingslope = P_SlopeById(READUINT16(save_p)); + mobj->standingslope = P_SlopeById(READUINT16(save->p)); if (diff2 & MD2_COLORIZED) - mobj->colorized = READUINT8(save_p); + mobj->colorized = READUINT8(save->p); //{ Saturn stuff, needs to be set, but shouldnt be synched @@ -2193,7 +2178,7 @@ static void LoadMobjThinker(actionf_p1 thinker) // set sprev, snext, bprev, bnext, subsector P_SetThingPosition(mobj); - mobj->mobjnum = READUINT32(save_p); + mobj->mobjnum = READUINT32(save->p); if (mobj->player) { @@ -2232,18 +2217,18 @@ static void LoadMobjThinker(actionf_p1 thinker) // 2 - Ceiling Only // 3 - Both // -static void LoadSpecialLevelThinker(actionf_p1 thinker, UINT8 floorOrCeiling) +static void LoadSpecialLevelThinker(savebuffer_t *save, actionf_p1 thinker, UINT8 floorOrCeiling) { levelspecthink_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); size_t i; ht->thinker.function.acp1 = thinker; for (i = 0; i < 16; i++) { - ht->vars[i] = READFIXED(save_p); //var[16] - ht->var2s[i] = READFIXED(save_p); //var[16] + ht->vars[i] = READFIXED(save->p); //var[16] + ht->var2s[i] = READFIXED(save->p); //var[16] } - ht->sourceline = LoadLine(READUINT32(save_p)); - ht->sector = LoadSector(READUINT32(save_p)); + ht->sourceline = LoadLine(READUINT32(save->p)); + ht->sector = LoadSector(READUINT32(save->p)); if (ht->sector) { @@ -2261,25 +2246,25 @@ static void LoadSpecialLevelThinker(actionf_p1 thinker, UINT8 floorOrCeiling) // // Loads a ceiling_t from a save game // -static void LoadCeilingThinker(actionf_p1 thinker) +static void LoadCeilingThinker(savebuffer_t *save, actionf_p1 thinker) { ceiling_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->type = READUINT8(save_p); - ht->sector = LoadSector(READUINT32(save_p)); - ht->bottomheight = READFIXED(save_p); - ht->topheight = READFIXED(save_p); - ht->speed = READFIXED(save_p); - ht->oldspeed = READFIXED(save_p); - ht->delay = READFIXED(save_p); - ht->delaytimer = READFIXED(save_p); - ht->crush = READUINT8(save_p); - ht->texture = READINT32(save_p); - ht->direction = READINT32(save_p); - ht->tag = READINT32(save_p); - ht->olddirection = READINT32(save_p); - ht->origspeed = READFIXED(save_p); - ht->sourceline = READFIXED(save_p); + ht->type = READUINT8(save->p); + ht->sector = LoadSector(READUINT32(save->p)); + ht->bottomheight = READFIXED(save->p); + ht->topheight = READFIXED(save->p); + ht->speed = READFIXED(save->p); + ht->oldspeed = READFIXED(save->p); + ht->delay = READFIXED(save->p); + ht->delaytimer = READFIXED(save->p); + ht->crush = READUINT8(save->p); + ht->texture = READINT32(save->p); + ht->direction = READINT32(save->p); + ht->tag = READINT32(save->p); + ht->olddirection = READINT32(save->p); + ht->origspeed = READFIXED(save->p); + ht->sourceline = READFIXED(save->p); if (ht->sector) ht->sector->ceilingdata = ht; P_AddThinker(&ht->thinker); @@ -2290,20 +2275,20 @@ static void LoadCeilingThinker(actionf_p1 thinker) // // Loads a floormove_t from a save game // -static void LoadFloormoveThinker(actionf_p1 thinker) +static void LoadFloormoveThinker(savebuffer_t *save, actionf_p1 thinker) { floormove_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->type = READUINT8(save_p); - ht->crush = READUINT8(save_p); - ht->sector = LoadSector(READUINT32(save_p)); - ht->direction = READINT32(save_p); - ht->texture = READINT32(save_p); - ht->floordestheight = READFIXED(save_p); - ht->speed = READFIXED(save_p); - ht->origspeed = READFIXED(save_p); - ht->delay = READFIXED(save_p); - ht->delaytimer = READFIXED(save_p); + ht->type = READUINT8(save->p); + ht->crush = READUINT8(save->p); + ht->sector = LoadSector(READUINT32(save->p)); + ht->direction = READINT32(save->p); + ht->texture = READINT32(save->p); + ht->floordestheight = READFIXED(save->p); + ht->speed = READFIXED(save->p); + ht->origspeed = READFIXED(save->p); + ht->delay = READFIXED(save->p); + ht->delaytimer = READFIXED(save->p); if (ht->sector) ht->sector->floordata = ht; P_AddThinker(&ht->thinker); @@ -2314,13 +2299,13 @@ static void LoadFloormoveThinker(actionf_p1 thinker) // // Loads a lightflash_t from a save game // -static void LoadLightflashThinker(actionf_p1 thinker) +static void LoadLightflashThinker(savebuffer_t *save, actionf_p1 thinker) { lightflash_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->sector = LoadSector(READUINT32(save_p)); - ht->maxlight = READINT32(save_p); - ht->minlight = READINT32(save_p); + ht->sector = LoadSector(READUINT32(save->p)); + ht->maxlight = READINT32(save->p); + ht->minlight = READINT32(save->p); if (ht->sector) ht->sector->lightingdata = ht; P_AddThinker(&ht->thinker); @@ -2331,16 +2316,16 @@ static void LoadLightflashThinker(actionf_p1 thinker) // // Loads a strobe_t from a save game // -static void LoadStrobeThinker(actionf_p1 thinker) +static void LoadStrobeThinker(savebuffer_t *save, actionf_p1 thinker) { strobe_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->sector = LoadSector(READUINT32(save_p)); - ht->count = READINT32(save_p); - ht->minlight = READINT32(save_p); - ht->maxlight = READINT32(save_p); - ht->darktime = READINT32(save_p); - ht->brighttime = READINT32(save_p); + ht->sector = LoadSector(READUINT32(save->p)); + ht->count = READINT32(save->p); + ht->minlight = READINT32(save->p); + ht->maxlight = READINT32(save->p); + ht->darktime = READINT32(save->p); + ht->brighttime = READINT32(save->p); if (ht->sector) ht->sector->lightingdata = ht; P_AddThinker(&ht->thinker); @@ -2351,15 +2336,15 @@ static void LoadStrobeThinker(actionf_p1 thinker) // // Loads a glow_t from a save game // -static void LoadGlowThinker(actionf_p1 thinker) +static void LoadGlowThinker(savebuffer_t *save, actionf_p1 thinker) { glow_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->sector = LoadSector(READUINT32(save_p)); - ht->minlight = READINT32(save_p); - ht->maxlight = READINT32(save_p); - ht->direction = READINT32(save_p); - ht->speed = READINT32(save_p); + ht->sector = LoadSector(READUINT32(save->p)); + ht->minlight = READINT32(save->p); + ht->maxlight = READINT32(save->p); + ht->direction = READINT32(save->p); + ht->speed = READINT32(save->p); if (ht->sector) ht->sector->lightingdata = ht; P_AddThinker(&ht->thinker); @@ -2370,15 +2355,15 @@ static void LoadGlowThinker(actionf_p1 thinker) // // Loads a fireflicker_t from a save game // -static void LoadFireflickerThinker(actionf_p1 thinker) +static void LoadFireflickerThinker(savebuffer_t *save, actionf_p1 thinker) { fireflicker_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->sector = LoadSector(READUINT32(save_p)); - ht->count = READINT32(save_p); - ht->resetcount = READINT32(save_p); - ht->maxlight = READINT32(save_p); - ht->minlight = READINT32(save_p); + ht->sector = LoadSector(READUINT32(save->p)); + ht->count = READINT32(save->p); + ht->resetcount = READINT32(save->p); + ht->maxlight = READINT32(save->p); + ht->minlight = READINT32(save->p); if (ht->sector) ht->sector->lightingdata = ht; P_AddThinker(&ht->thinker); @@ -2389,27 +2374,27 @@ static void LoadFireflickerThinker(actionf_p1 thinker) // // Loads a elevator_t from a save game // -static void LoadElevatorThinker(actionf_p1 thinker, UINT8 floorOrCeiling) +static void LoadElevatorThinker(savebuffer_t *save, actionf_p1 thinker, UINT8 floorOrCeiling) { elevator_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->type = READUINT8(save_p); - ht->sector = LoadSector(READUINT32(save_p)); - ht->actionsector = LoadSector(READUINT32(save_p)); - ht->direction = READINT32(save_p); - ht->floordestheight = READFIXED(save_p); - ht->ceilingdestheight = READFIXED(save_p); - ht->speed = READFIXED(save_p); - ht->origspeed = READFIXED(save_p); - ht->low = READFIXED(save_p); - ht->high = READFIXED(save_p); - ht->distance = READFIXED(save_p); - ht->delay = READFIXED(save_p); - ht->delaytimer = READFIXED(save_p); - ht->floorwasheight = READFIXED(save_p); - ht->ceilingwasheight = READFIXED(save_p); - ht->player = LoadPlayer(READUINT32(save_p)); // was dummy - ht->sourceline = LoadLine(READUINT32(save_p)); + ht->type = READUINT8(save->p); + ht->sector = LoadSector(READUINT32(save->p)); + ht->actionsector = LoadSector(READUINT32(save->p)); + ht->direction = READINT32(save->p); + ht->floordestheight = READFIXED(save->p); + ht->ceilingdestheight = READFIXED(save->p); + ht->speed = READFIXED(save->p); + ht->origspeed = READFIXED(save->p); + ht->low = READFIXED(save->p); + ht->high = READFIXED(save->p); + ht->distance = READFIXED(save->p); + ht->delay = READFIXED(save->p); + ht->delaytimer = READFIXED(save->p); + ht->floorwasheight = READFIXED(save->p); + ht->ceilingwasheight = READFIXED(save->p); + ht->player = LoadPlayer(READUINT32(save->p)); // was dummy + ht->sourceline = LoadLine(READUINT32(save->p)); if (ht->sector) { @@ -2427,20 +2412,20 @@ static void LoadElevatorThinker(actionf_p1 thinker, UINT8 floorOrCeiling) // // Loads a scroll_t from a save game // -static void LoadScrollThinker(actionf_p1 thinker) +static void LoadScrollThinker(savebuffer_t *save, actionf_p1 thinker) { scroll_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->dx = READFIXED(save_p); - ht->dy = READFIXED(save_p); - ht->affectee = READINT32(save_p); - ht->control = READINT32(save_p); - ht->last_height = READFIXED(save_p); - ht->vdx = READFIXED(save_p); - ht->vdy = READFIXED(save_p); - ht->accel = READINT32(save_p); - ht->exclusive = READINT32(save_p); - ht->type = READUINT8(save_p); + ht->dx = READFIXED(save->p); + ht->dy = READFIXED(save->p); + ht->affectee = READINT32(save->p); + ht->control = READINT32(save->p); + ht->last_height = READFIXED(save->p); + ht->vdx = READFIXED(save->p); + ht->vdy = READFIXED(save->p); + ht->accel = READINT32(save->p); + ht->exclusive = READINT32(save->p); + ht->type = READUINT8(save->p); P_AddThinker(&ht->thinker); } @@ -2449,15 +2434,15 @@ static void LoadScrollThinker(actionf_p1 thinker) // // Loads a friction_t from a save game // -static inline void LoadFrictionThinker(actionf_p1 thinker) +static inline void LoadFrictionThinker(savebuffer_t *save, actionf_p1 thinker) { friction_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->friction = READINT32(save_p); - ht->movefactor = READINT32(save_p); - ht->affectee = READINT32(save_p); - ht->referrer = READINT32(save_p); - ht->roverfriction = READUINT8(save_p); + ht->friction = READINT32(save->p); + ht->movefactor = READINT32(save->p); + ht->affectee = READINT32(save->p); + ht->referrer = READINT32(save->p); + ht->roverfriction = READUINT8(save->p); P_AddThinker(&ht->thinker); } @@ -2466,23 +2451,23 @@ static inline void LoadFrictionThinker(actionf_p1 thinker) // // Loads a pusher_t from a save game // -static void LoadPusherThinker(actionf_p1 thinker) +static void LoadPusherThinker(savebuffer_t *save, actionf_p1 thinker) { pusher_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->type = READUINT8(save_p); - ht->x_mag = READINT32(save_p); - ht->y_mag = READINT32(save_p); - ht->magnitude = READINT32(save_p); - ht->radius = READINT32(save_p); - ht->x = READINT32(save_p); - ht->y = READINT32(save_p); - ht->z = READINT32(save_p); - ht->affectee = READINT32(save_p); - ht->roverpusher = READUINT8(save_p); - ht->referrer = READINT32(save_p); - ht->exclusive = READINT32(save_p); - ht->slider = READINT32(save_p); + ht->type = READUINT8(save->p); + ht->x_mag = READINT32(save->p); + ht->y_mag = READINT32(save->p); + ht->magnitude = READINT32(save->p); + ht->radius = READINT32(save->p); + ht->x = READINT32(save->p); + ht->y = READINT32(save->p); + ht->z = READINT32(save->p); + ht->affectee = READINT32(save->p); + ht->roverpusher = READUINT8(save->p); + ht->referrer = READINT32(save->p); + ht->exclusive = READINT32(save->p); + ht->slider = READINT32(save->p); ht->source = P_GetPushThing(ht->affectee); P_AddThinker(&ht->thinker); } @@ -2492,14 +2477,14 @@ static void LoadPusherThinker(actionf_p1 thinker) // // Loads a laserthink_t from a save game // -static inline void LoadLaserThinker(actionf_p1 thinker) +static inline void LoadLaserThinker(savebuffer_t *save, actionf_p1 thinker) { laserthink_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ffloor_t *rover = NULL; ht->thinker.function.acp1 = thinker; - ht->sector = LoadSector(READUINT32(save_p)); - ht->sec = LoadSector(READUINT32(save_p)); - ht->sourceline = LoadLine(READUINT32(save_p)); + ht->sector = LoadSector(READUINT32(save->p)); + ht->sec = LoadSector(READUINT32(save->p)); + ht->sourceline = LoadLine(READUINT32(save->p)); for (rover = ht->sector->ffloors; rover; rover = rover->next) if (rover->secnum == (size_t)(ht->sec - sectors) && rover->master == ht->sourceline) @@ -2512,13 +2497,13 @@ static inline void LoadLaserThinker(actionf_p1 thinker) // // Loads a lightlevel_t from a save game // -FUNCINLINE static ATTRINLINE void LoadLightlevelThinker(actionf_p1 thinker) +FUNCINLINE static ATTRINLINE void LoadLightlevelThinker(savebuffer_t *save, actionf_p1 thinker) { lightlevel_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->sector = LoadSector(READUINT32(save_p)); - ht->destlevel = READINT32(save_p); - ht->speed = READINT32(save_p); + ht->sector = LoadSector(READUINT32(save->p)); + ht->destlevel = READINT32(save->p); + ht->speed = READINT32(save->p); if (ht->sector) ht->sector->lightingdata = ht; P_AddThinker(&ht->thinker); @@ -2529,14 +2514,14 @@ FUNCINLINE static ATTRINLINE void LoadLightlevelThinker(actionf_p1 thinker) // // Loads a executor_t from a save game // -static inline void LoadExecutorThinker(actionf_p1 thinker) +static inline void LoadExecutorThinker(savebuffer_t *save, actionf_p1 thinker) { executor_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->line = LoadLine(READUINT32(save_p)); - ht->caller = LoadMobj(READUINT32(save_p)); - ht->sector = LoadSector(READUINT32(save_p)); - ht->timer = READINT32(save_p); + ht->line = LoadLine(READUINT32(save->p)); + ht->caller = LoadMobj(READUINT32(save->p)); + ht->sector = LoadSector(READUINT32(save->p)); + ht->timer = READINT32(save->p); P_AddThinker(&ht->thinker); } @@ -2545,34 +2530,33 @@ static inline void LoadExecutorThinker(actionf_p1 thinker) // // Loads a disappear_t thinker // -static inline void LoadDisappearThinker(actionf_p1 thinker) +static inline void LoadDisappearThinker(savebuffer_t *save, actionf_p1 thinker) { disappear_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->appeartime = READUINT32(save_p); - ht->disappeartime = READUINT32(save_p); - ht->offset = READUINT32(save_p); - ht->timer = READUINT32(save_p); - ht->affectee = READINT32(save_p); - ht->sourceline = READINT32(save_p); - ht->exists = READINT32(save_p); + ht->appeartime = READUINT32(save->p); + ht->disappeartime = READUINT32(save->p); + ht->offset = READUINT32(save->p); + ht->timer = READUINT32(save->p); + ht->affectee = READINT32(save->p); + ht->sourceline = READINT32(save->p); + ht->exists = READINT32(save->p); P_AddThinker(&ht->thinker); } - // // LoadPolyrotateThinker // // Loads a polyrotate_t thinker // -static inline void LoadPolyrotatetThinker(actionf_p1 thinker) +static inline void LoadPolyrotatetThinker(savebuffer_t *save, actionf_p1 thinker) { polyrotate_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->polyObjNum = READINT32(save_p); - ht->speed = READINT32(save_p); - ht->distance = READINT32(save_p); - ht->turnobjs = READUINT8(save_p); + ht->polyObjNum = READINT32(save->p); + ht->speed = READINT32(save->p); + ht->distance = READINT32(save->p); + ht->turnobjs = READUINT8(save->p); P_AddThinker(&ht->thinker); } @@ -2581,16 +2565,16 @@ static inline void LoadPolyrotatetThinker(actionf_p1 thinker) // // Loads a polymovet_t thinker // -static void LoadPolymoveThinker(actionf_p1 thinker) +static void LoadPolymoveThinker(savebuffer_t *save, actionf_p1 thinker) { polymove_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->polyObjNum = READINT32(save_p); - ht->speed = READINT32(save_p); - ht->momx = READFIXED(save_p); - ht->momy = READFIXED(save_p); - ht->distance = READINT32(save_p); - ht->angle = READANGLE(save_p); + ht->polyObjNum = READINT32(save->p); + ht->speed = READINT32(save->p); + ht->momx = READFIXED(save->p); + ht->momy = READFIXED(save->p); + ht->distance = READINT32(save->p); + ht->angle = READANGLE(save->p); P_AddThinker(&ht->thinker); } @@ -2599,22 +2583,22 @@ static void LoadPolymoveThinker(actionf_p1 thinker) // // Loads a polywaypoint_t thinker // -static inline void LoadPolywaypointThinker(actionf_p1 thinker) +static inline void LoadPolywaypointThinker(savebuffer_t *save, actionf_p1 thinker) { polywaypoint_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->polyObjNum = READINT32(save_p); - ht->speed = READINT32(save_p); - ht->sequence = READINT32(save_p); - ht->pointnum = READINT32(save_p); - ht->direction = READINT32(save_p); - ht->comeback = READUINT8(save_p); - ht->wrap = READUINT8(save_p); - ht->continuous = READUINT8(save_p); - ht->stophere = READUINT8(save_p); - ht->diffx = READFIXED(save_p); - ht->diffy = READFIXED(save_p); - ht->diffz = READFIXED(save_p); + ht->polyObjNum = READINT32(save->p); + ht->speed = READINT32(save->p); + ht->sequence = READINT32(save->p); + ht->pointnum = READINT32(save->p); + ht->direction = READINT32(save->p); + ht->comeback = READUINT8(save->p); + ht->wrap = READUINT8(save->p); + ht->continuous = READUINT8(save->p); + ht->stophere = READUINT8(save->p); + ht->diffx = READFIXED(save->p); + ht->diffy = READFIXED(save->p); + ht->diffz = READFIXED(save->p); P_AddThinker(&ht->thinker); } @@ -2623,23 +2607,23 @@ static inline void LoadPolywaypointThinker(actionf_p1 thinker) // // loads a polyslidedoor_t thinker // -static inline void LoadPolyslidedoorThinker(actionf_p1 thinker) +static inline void LoadPolyslidedoorThinker(savebuffer_t *save, actionf_p1 thinker) { polyslidedoor_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->polyObjNum = READINT32(save_p); - ht->delay = READINT32(save_p); - ht->delayCount = READINT32(save_p); - ht->initSpeed = READINT32(save_p); - ht->speed = READINT32(save_p); - ht->initDistance = READINT32(save_p); - ht->distance = READINT32(save_p); - ht->initAngle = READUINT32(save_p); - ht->angle = READUINT32(save_p); - ht->revAngle = READUINT32(save_p); - ht->momx = READFIXED(save_p); - ht->momy = READFIXED(save_p); - ht->closing = READUINT8(save_p); + ht->polyObjNum = READINT32(save->p); + ht->delay = READINT32(save->p); + ht->delayCount = READINT32(save->p); + ht->initSpeed = READINT32(save->p); + ht->speed = READINT32(save->p); + ht->initDistance = READINT32(save->p); + ht->distance = READINT32(save->p); + ht->initAngle = READUINT32(save->p); + ht->angle = READUINT32(save->p); + ht->revAngle = READUINT32(save->p); + ht->momx = READFIXED(save->p); + ht->momy = READFIXED(save->p); + ht->closing = READUINT8(save->p); P_AddThinker(&ht->thinker); } @@ -2648,18 +2632,18 @@ static inline void LoadPolyslidedoorThinker(actionf_p1 thinker) // // Loads a polyswingdoor_t thinker // -static inline void LoadPolyswingdoorThinker(actionf_p1 thinker) +static inline void LoadPolyswingdoorThinker(savebuffer_t *save, actionf_p1 thinker) { polyswingdoor_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->polyObjNum = READINT32(save_p); - ht->delay = READINT32(save_p); - ht->delayCount = READINT32(save_p); - ht->initSpeed = READINT32(save_p); - ht->speed = READINT32(save_p); - ht->initDistance = READINT32(save_p); - ht->distance = READINT32(save_p); - ht->closing = READUINT8(save_p); + ht->polyObjNum = READINT32(save->p); + ht->delay = READINT32(save->p); + ht->delayCount = READINT32(save->p); + ht->initSpeed = READINT32(save->p); + ht->speed = READINT32(save->p); + ht->initDistance = READINT32(save->p); + ht->distance = READINT32(save->p); + ht->closing = READUINT8(save->p); P_AddThinker(&ht->thinker); } @@ -2668,35 +2652,22 @@ static inline void LoadPolyswingdoorThinker(actionf_p1 thinker) // // Loads a polydisplace_t thinker // -static inline void LoadPolydisplaceThinker(actionf_p1 thinker) +static inline void LoadPolydisplaceThinker(savebuffer_t *save, actionf_p1 thinker) { polydisplace_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->polyObjNum = READINT32(save_p); - ht->controlSector = LoadSector(READUINT32(save_p)); - ht->dx = READFIXED(save_p); - ht->dy = READFIXED(save_p); - ht->oldHeights = READFIXED(save_p); + ht->polyObjNum = READINT32(save->p); + ht->controlSector = LoadSector(READUINT32(save->p)); + ht->dx = READFIXED(save->p); + ht->dy = READFIXED(save->p); + ht->oldHeights = READFIXED(save->p); P_AddThinker(&ht->thinker); } -/* -// -// LoadWhatThinker -// -// load a what_t thinker -// -static inline void LoadWhatThinker(actionf_p1 thinker) -{ - what_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); - ht->thinker.function.acp1 = thinker; -} -*/ - // // P_NetUnArchiveThinkers // -static void P_NetUnArchiveThinkers(void) +static void P_NetUnArchiveThinkers(savebuffer_t *save) { thinker_t *currentthinker; thinker_t *next; @@ -2705,7 +2676,7 @@ static void P_NetUnArchiveThinkers(void) UINT32 i; UINT32 numloaded = 0; - if (READUINT32(save_p) != ARCHIVEBLOCK_THINKERS) + if (READUINT32(save->p) != ARCHIVEBLOCK_THINKERS) I_Error("Bad $$$.sav at archive block Thinkers"); // remove all the current thinkers @@ -2737,7 +2708,7 @@ static void P_NetUnArchiveThinkers(void) // read in saved thinkers for (;;) { - tclass = READUINT8(save_p); + tclass = READUINT8(save->p); if (tclass == tc_end) break; // leave the saved thinker reading loop @@ -2746,148 +2717,149 @@ static void P_NetUnArchiveThinkers(void) switch (tclass) { case tc_mobj: - LoadMobjThinker((actionf_p1)P_MobjThinker); + LoadMobjThinker(save, (actionf_p1)P_MobjThinker); break; case tc_ceiling: - LoadCeilingThinker((actionf_p1)T_MoveCeiling); + LoadCeilingThinker(save, (actionf_p1)T_MoveCeiling); break; case tc_crushceiling: - LoadCeilingThinker((actionf_p1)T_CrushCeiling); + LoadCeilingThinker(save, (actionf_p1)T_CrushCeiling); break; case tc_floor: - LoadFloormoveThinker((actionf_p1)T_MoveFloor); + LoadFloormoveThinker(save, (actionf_p1)T_MoveFloor); break; case tc_flash: - LoadLightflashThinker((actionf_p1)T_LightningFlash); + LoadLightflashThinker(save, (actionf_p1)T_LightningFlash); break; case tc_strobe: - LoadStrobeThinker((actionf_p1)T_StrobeFlash); + LoadStrobeThinker(save, (actionf_p1)T_StrobeFlash); break; case tc_glow: - LoadGlowThinker((actionf_p1)T_Glow); + LoadGlowThinker(save, (actionf_p1)T_Glow); break; case tc_fireflicker: - LoadFireflickerThinker((actionf_p1)T_FireFlicker); + LoadFireflickerThinker(save, (actionf_p1)T_FireFlicker); break; case tc_elevator: - LoadElevatorThinker((actionf_p1)T_MoveElevator, 3); + LoadElevatorThinker(save, (actionf_p1)T_MoveElevator, 3); break; case tc_continuousfalling: - LoadSpecialLevelThinker((actionf_p1)T_ContinuousFalling, 3); + LoadSpecialLevelThinker(save, (actionf_p1)T_ContinuousFalling, 3); break; case tc_thwomp: - LoadSpecialLevelThinker((actionf_p1)T_ThwompSector, 3); + LoadSpecialLevelThinker(save, (actionf_p1)T_ThwompSector, 3); break; case tc_noenemies: - LoadSpecialLevelThinker((actionf_p1)T_NoEnemiesSector, 0); + LoadSpecialLevelThinker(save, (actionf_p1)T_NoEnemiesSector, 0); break; case tc_eachtime: - LoadSpecialLevelThinker((actionf_p1)T_EachTimeThinker, 0); + LoadSpecialLevelThinker(save, (actionf_p1)T_EachTimeThinker, 0); break; case tc_raisesector: - LoadSpecialLevelThinker((actionf_p1)T_RaiseSector, 0); + LoadSpecialLevelThinker(save, (actionf_p1)T_RaiseSector, 0); break; /// \todo rewrite all the code that uses an elevator_t but isn't an elevator /// \note working on it! case tc_camerascanner: - LoadElevatorThinker((actionf_p1)T_CameraScanner, 0); + LoadElevatorThinker(save, (actionf_p1)T_CameraScanner, 0); break; case tc_bouncecheese: - LoadSpecialLevelThinker((actionf_p1)T_BounceCheese, 2); + LoadSpecialLevelThinker(save, (actionf_p1)T_BounceCheese, 2); break; case tc_startcrumble: - LoadElevatorThinker((actionf_p1)T_StartCrumble, 1); + LoadElevatorThinker(save, (actionf_p1)T_StartCrumble, 1); break; case tc_marioblock: - LoadSpecialLevelThinker((actionf_p1)T_MarioBlock, 3); + LoadSpecialLevelThinker(save, (actionf_p1)T_MarioBlock, 3); break; case tc_marioblockchecker: - LoadSpecialLevelThinker((actionf_p1)T_MarioBlockChecker, 0); + LoadSpecialLevelThinker(save, (actionf_p1)T_MarioBlockChecker, 0); break; case tc_spikesector: - LoadSpecialLevelThinker((actionf_p1)T_SpikeSector, 0); + LoadSpecialLevelThinker(save, (actionf_p1)T_SpikeSector, 0); break; case tc_floatsector: - LoadSpecialLevelThinker((actionf_p1)T_FloatSector, 0); + LoadSpecialLevelThinker(save, (actionf_p1)T_FloatSector, 0); break; case tc_bridgethinker: - LoadSpecialLevelThinker((actionf_p1)T_BridgeThinker, 3); + LoadSpecialLevelThinker(save, (actionf_p1)T_BridgeThinker, 3); break; case tc_laserflash: - LoadLaserThinker((actionf_p1)T_LaserFlash); + LoadLaserThinker(save, (actionf_p1)T_LaserFlash); break; case tc_lightfade: - LoadLightlevelThinker((actionf_p1)T_LightFade); + LoadLightlevelThinker(save, (actionf_p1)T_LightFade); break; case tc_executor: - LoadExecutorThinker((actionf_p1)T_ExecutorDelay); + LoadExecutorThinker(save, (actionf_p1)T_ExecutorDelay); restoreNum = true; break; case tc_disappear: - LoadDisappearThinker((actionf_p1)T_Disappear); + LoadDisappearThinker(save, (actionf_p1)T_Disappear); break; + case tc_polyrotate: - LoadPolyrotatetThinker((actionf_p1)T_PolyObjRotate); + LoadPolyrotatetThinker(save, (actionf_p1)T_PolyObjRotate); break; case tc_polymove: - LoadPolymoveThinker((actionf_p1)T_PolyObjMove); + LoadPolymoveThinker(save, (actionf_p1)T_PolyObjMove); break; case tc_polywaypoint: - LoadPolywaypointThinker((actionf_p1)T_PolyObjWaypoint); + LoadPolywaypointThinker(save, (actionf_p1)T_PolyObjWaypoint); break; case tc_polyslidedoor: - LoadPolyslidedoorThinker((actionf_p1)T_PolyDoorSlide); + LoadPolyslidedoorThinker(save, (actionf_p1)T_PolyDoorSlide); break; case tc_polyswingdoor: - LoadPolyswingdoorThinker((actionf_p1)T_PolyDoorSwing); + LoadPolyswingdoorThinker(save, (actionf_p1)T_PolyDoorSwing); break; case tc_polyflag: - LoadPolymoveThinker((actionf_p1)T_PolyObjFlag); + LoadPolymoveThinker(save, (actionf_p1)T_PolyObjFlag); break; case tc_polydisplace: - LoadPolydisplaceThinker((actionf_p1)T_PolyObjDisplace); + LoadPolydisplaceThinker(save, (actionf_p1)T_PolyObjDisplace); break; case tc_scroll: - LoadScrollThinker((actionf_p1)T_Scroll); + LoadScrollThinker(save, (actionf_p1)T_Scroll); break; case tc_friction: - LoadFrictionThinker((actionf_p1)T_Friction); + LoadFrictionThinker(save, (actionf_p1)T_Friction); break; case tc_pusher: - LoadPusherThinker((actionf_p1)T_Pusher); + LoadPusherThinker(save, (actionf_p1)T_Pusher); break; default: @@ -2922,29 +2894,29 @@ static void P_NetUnArchiveThinkers(void) #define PD_FLAGS 0x01 #define PD_TRANS 0x02 -static inline void P_ArchivePolyObj(polyobj_t *po) +static inline void P_ArchivePolyObj(savebuffer_t *save, polyobj_t *po) { UINT8 diff = 0; - WRITEINT32(save_p, po->id); - WRITEANGLE(save_p, po->angle); + WRITEINT32(save->p, po->id); + WRITEANGLE(save->p, po->angle); - WRITEFIXED(save_p, po->spawnSpot.x); - WRITEFIXED(save_p, po->spawnSpot.y); + WRITEFIXED(save->p, po->spawnSpot.x); + WRITEFIXED(save->p, po->spawnSpot.y); if (po->flags != po->spawnflags) diff |= PD_FLAGS; if (po->translucency != 0) diff |= PD_TRANS; - WRITEUINT8(save_p, diff); + WRITEUINT8(save->p, diff); if (diff & PD_FLAGS) - WRITEINT32(save_p, po->flags); + WRITEINT32(save->p, po->flags); if (diff & PD_TRANS) - WRITEINT32(save_p, po->translucency); + WRITEINT32(save->p, po->translucency); } -static inline void P_UnArchivePolyObj(polyobj_t *po) +static inline void P_UnArchivePolyObj(savebuffer_t *save, polyobj_t *po) { INT32 id; UINT32 angle; @@ -2956,19 +2928,19 @@ static inline void P_UnArchivePolyObj(polyobj_t *po) // when they first start to run. po->thinker = NULL; - id = READINT32(save_p); + id = READINT32(save->p); - angle = READANGLE(save_p); + angle = READANGLE(save->p); - x = READFIXED(save_p); - y = READFIXED(save_p); + x = READFIXED(save->p); + y = READFIXED(save->p); - diff = READUINT8(save_p); + diff = READUINT8(save->p); if (diff & PD_FLAGS) - po->flags = READINT32(save_p); + po->flags = READINT32(save->p); if (diff & PD_TRANS) - po->translucency = READINT32(save_p); + po->translucency = READINT32(save->p); // if the object is bad or isn't in the id hash, we can do nothing more // with it, so return now @@ -2979,33 +2951,33 @@ static inline void P_UnArchivePolyObj(polyobj_t *po) Polyobj_MoveOnLoad(po, angle, x, y); } -static inline void P_ArchivePolyObjects(void) +static inline void P_ArchivePolyObjects(savebuffer_t *save) { INT32 i; - WRITEUINT32(save_p, ARCHIVEBLOCK_POBJS); + WRITEUINT32(save->p, ARCHIVEBLOCK_POBJS); // save number of polyobjects - WRITEINT32(save_p, numPolyObjects); + WRITEINT32(save->p, numPolyObjects); for (i = 0; i < numPolyObjects; ++i) - P_ArchivePolyObj(&PolyObjects[i]); + P_ArchivePolyObj(save, &PolyObjects[i]); } -static inline void P_UnArchivePolyObjects(void) +static inline void P_UnArchivePolyObjects(savebuffer_t *save) { INT32 i, numSavedPolys; - if (READUINT32(save_p) != ARCHIVEBLOCK_POBJS) + if (READUINT32(save->p) != ARCHIVEBLOCK_POBJS) I_Error("Bad $$$.sav at archive block Pobjs"); - numSavedPolys = READINT32(save_p); + numSavedPolys = READINT32(save->p); if (numSavedPolys != numPolyObjects) I_Error("P_UnArchivePolyObjects: polyobj count inconsistency\n"); for (i = 0; i < numSavedPolys; ++i) - P_UnArchivePolyObj(&PolyObjects[i]); + P_UnArchivePolyObj(save, &PolyObjects[i]); } // // P_FinishMobjs @@ -3097,11 +3069,11 @@ static void P_RelinkPointers(void) // // P_NetArchiveSpecials // -static inline void P_NetArchiveSpecials(void) +static inline void P_NetArchiveSpecials(savebuffer_t *save) { size_t i, z; - WRITEUINT32(save_p, ARCHIVEBLOCK_SPECIALS); + WRITEUINT32(save->p, ARCHIVEBLOCK_SPECIALS); // itemrespawn queue for deathmatch i = iquetail; @@ -3111,56 +3083,56 @@ static inline void P_NetArchiveSpecials(void) { if (&mapthings[z] == itemrespawnque[i]) { - WRITEUINT32(save_p, z); + WRITEUINT32(save->p, z); break; } } - WRITEUINT32(save_p, itemrespawntime[i]); + WRITEUINT32(save->p, itemrespawntime[i]); i = (i + 1) & (ITEMQUESIZE-1); } // end delimiter - WRITEUINT32(save_p, 0xffffffff); + WRITEUINT32(save->p, 0xffffffff); // Sky number - WRITEINT32(save_p, globallevelskynum); + WRITEINT32(save->p, globallevelskynum); // Current global weather type - WRITEUINT8(save_p, globalweather); + WRITEUINT8(save->p, globalweather); if (metalplayback) // Is metal sonic running? { - WRITEUINT8(save_p, 0x01); - G_SaveMetal(&save_p); + WRITEUINT8(save->p, 0x01); + G_SaveMetal(&save->p); } else - WRITEUINT8(save_p, 0x00); + WRITEUINT8(save->p, 0x00); } // // P_NetUnArchiveSpecials // -static void P_NetUnArchiveSpecials(void) +static void P_NetUnArchiveSpecials(savebuffer_t *save) { size_t i; INT32 j; - if (READUINT32(save_p) != ARCHIVEBLOCK_SPECIALS) + if (READUINT32(save->p) != ARCHIVEBLOCK_SPECIALS) I_Error("Bad $$$.sav at archive block Specials"); // BP: added save itemrespawn queue for deathmatch iquetail = iquehead = 0; - while ((i = READUINT32(save_p)) != 0xffffffff) + while ((i = READUINT32(save->p)) != 0xffffffff) { itemrespawnque[iquehead] = &mapthings[i]; - itemrespawntime[iquehead++] = READINT32(save_p); + itemrespawntime[iquehead++] = READINT32(save->p); } - j = READINT32(save_p); + j = READINT32(save->p); if (j != globallevelskynum) P_SetupLevelSky(j, true); - globalweather = READUINT8(save_p); + globalweather = READUINT8(save->p); if (globalweather) { @@ -3175,31 +3147,31 @@ static void P_NetUnArchiveSpecials(void) P_SwitchWeather(globalweather); } - if (READUINT8(save_p) == 0x01) // metal sonic - G_LoadMetal(&save_p); + if (READUINT8(save->p) == 0x01) // metal sonic + G_LoadMetal(&save->p); } // ======================================================================= // Misc // ======================================================================= -static inline void P_ArchiveMisc(void) +static inline void P_ArchiveMisc(savebuffer_t *save) { if (gamecomplete) - WRITEINT16(save_p, gamemap | 8192); + WRITEINT16(save->p, gamemap | 8192); else - WRITEINT16(save_p, gamemap); + WRITEINT16(save->p, gamemap); lastmapsaved = gamemap; - WRITEUINT16(save_p, (botskin ? (emeralds|(1<<10)) : emeralds)+357); - WRITESTRINGN(save_p, timeattackfolder, sizeof(timeattackfolder)); + WRITEUINT16(save->p, (botskin ? (emeralds|(1<<10)) : emeralds)+357); + WRITESTRINGN(save->p, timeattackfolder, sizeof(timeattackfolder)); } -static inline void P_UnArchiveSPGame(INT16 mapoverride) +static inline void P_UnArchiveSPGame(savebuffer_t *save, INT16 mapoverride) { char testname[sizeof(timeattackfolder)]; - gamemap = READINT16(save_p); + gamemap = READINT16(save->p); if (mapoverride != 0) { @@ -3219,12 +3191,12 @@ static inline void P_UnArchiveSPGame(INT16 mapoverride) tokenlist = 0; token = 0; - savedata.emeralds = READUINT16(save_p)-357; + savedata.emeralds = READUINT16(save->p)-357; if (savedata.emeralds & (1<<10)) savedata.botcolor = 0xFF; savedata.emeralds &= 0xff; - READSTRINGN(save_p, testname, sizeof(testname)); + READSTRINGN(save->p, testname, sizeof(testname)); if (strcmp(testname, timeattackfolder)) { @@ -3238,120 +3210,120 @@ static inline void P_UnArchiveSPGame(INT16 mapoverride) playeringame[consoleplayer] = true; } -static void P_NetArchiveMisc(boolean resending) +static void P_NetArchiveMisc(savebuffer_t *save, boolean resending) { UINT32 pig = 0; INT32 i; - WRITEUINT32(save_p, ARCHIVEBLOCK_MISC); + WRITEUINT32(save->p, ARCHIVEBLOCK_MISC); if (resending) - WRITEUINT32(save_p, gametic); + WRITEUINT32(save->p, gametic); + + WRITEINT16(save->p, gamemap); - WRITEINT16(save_p, gamemap); if (gamestate != GS_LEVEL) - WRITEINT16(save_p, GS_WAITINGPLAYERS); // nice hack to put people back into waitingplayers + WRITEINT16(save->p, GS_WAITINGPLAYERS); // nice hack to put people back into waitingplayers else - WRITEINT16(save_p, gamestate); + WRITEINT16(save->p, gamestate); if (resending) - WRITEINT16(save_p, gametype); + WRITEINT16(save->p, gametype); for (i = 0; i < MAXPLAYERS; i++) pig |= (playeringame[i] != 0)<p, pig); - WRITEUINT32(save_p, P_GetRandSeed()); + WRITEUINT32(save->p, P_GetRandSeed()); - WRITEUINT32(save_p, tokenlist); + WRITEUINT32(save->p, tokenlist); - WRITEUINT8(save_p, encoremode); + WRITEUINT8(save->p, encoremode); - WRITEUINT32(save_p, leveltime); - WRITEUINT32(save_p, totalrings); - WRITEINT16(save_p, lastmap); + WRITEUINT32(save->p, leveltime); + WRITEUINT32(save->p, totalrings); + WRITEINT16(save->p, lastmap); for (i = 0; i < 4; i++) { - WRITEINT16(save_p, votelevels[i][0]); - WRITEINT16(save_p, votelevels[i][1]); + WRITEINT16(save->p, votelevels[i][0]); + WRITEINT16(save->p, votelevels[i][1]); } for (i = 0; i < MAXPLAYERS; i++) - WRITESINT8(save_p, votes[i]); + WRITESINT8(save->p, votes[i]); - WRITESINT8(save_p, pickedvote); + WRITESINT8(save->p, pickedvote); - WRITEUINT16(save_p, emeralds); - WRITEUINT8(save_p, stagefailed); + WRITEUINT16(save->p, emeralds); + WRITEUINT8(save->p, stagefailed); - WRITEUINT32(save_p, token); - WRITEINT32(save_p, sstimer); - WRITEUINT32(save_p, bluescore); - WRITEUINT32(save_p, redscore); + WRITEUINT32(save->p, token); + WRITEINT32(save->p, sstimer); + WRITEUINT32(save->p, bluescore); + WRITEUINT32(save->p, redscore); - WRITEINT16(save_p, autobalance); - WRITEINT16(save_p, teamscramble); + WRITEINT16(save->p, autobalance); + WRITEINT16(save->p, teamscramble); for (i = 0; i < MAXPLAYERS; i++) - WRITEINT16(save_p, scrambleplayers[i]); + WRITEINT16(save->p, scrambleplayers[i]); for (i = 0; i < MAXPLAYERS; i++) - WRITEINT16(save_p, scrambleteams[i]); + WRITEINT16(save->p, scrambleteams[i]); - WRITEINT16(save_p, scrambletotal); - WRITEINT16(save_p, scramblecount); + WRITEINT16(save->p, scrambletotal); + WRITEINT16(save->p, scramblecount); - WRITEUINT32(save_p, racecountdown); - WRITEUINT32(save_p, exitcountdown); + WRITEUINT32(save->p, racecountdown); + WRITEUINT32(save->p, exitcountdown); - WRITEFIXED(save_p, gravity); - WRITEFIXED(save_p, mapobjectscale); + WRITEFIXED(save->p, gravity); + WRITEFIXED(save->p, mapobjectscale); - WRITEUINT32(save_p, countdowntimer); - WRITEUINT8(save_p, countdowntimeup); + WRITEUINT32(save->p, countdowntimer); + WRITEUINT8(save->p, countdowntimeup); - WRITEUINT32(save_p, hidetime); + WRITEUINT32(save->p, hidetime); // SRB2kart - WRITEINT32(save_p, numgotboxes); + WRITEINT32(save->p, numgotboxes); - WRITEUINT8(save_p, gamespeed); - WRITEUINT8(save_p, franticitems); - WRITEUINT8(save_p, comeback); + WRITEUINT8(save->p, gamespeed); + WRITEUINT8(save->p, franticitems); + WRITEUINT8(save->p, comeback); for (i = 0; i < 4; i++) - WRITESINT8(save_p, battlewanted[i]); + WRITESINT8(save->p, battlewanted[i]); - WRITEUINT32(save_p, wantedcalcdelay); - WRITEUINT32(save_p, indirectitemcooldown); - WRITEUINT32(save_p, hyubgone); - WRITEUINT32(save_p, mapreset); - WRITEUINT8(save_p, nospectategrief); - WRITEUINT8(save_p, thwompsactive); - WRITESINT8(save_p, spbplace); - WRITEUINT8(save_p, startedInFreePlay); + WRITEUINT32(save->p, wantedcalcdelay); + WRITEUINT32(save->p, indirectitemcooldown); + WRITEUINT32(save->p, hyubgone); + WRITEUINT32(save->p, mapreset); + WRITEUINT8(save->p, nospectategrief); + WRITEUINT8(save->p, thwompsactive); + WRITESINT8(save->p, spbplace); + WRITEUINT8(save->p, startedInFreePlay); // Is it paused? if (paused) - WRITEUINT8(save_p, 0x2f); + WRITEUINT8(save->p, 0x2f); else - WRITEUINT8(save_p, 0x2e); + WRITEUINT8(save->p, 0x2e); } -FUNCINLINE static ATTRINLINE boolean P_NetUnArchiveMisc(boolean reloading) +FUNCINLINE static ATTRINLINE boolean P_NetUnArchiveMisc(savebuffer_t *save, boolean reloading) { UINT32 pig; INT32 i; - UINT8 *old_save_p; - if (READUINT32(save_p) != ARCHIVEBLOCK_MISC) + if (READUINT32(save->p) != ARCHIVEBLOCK_MISC) I_Error("Bad $$$.sav at archive block Misc"); if (reloading) - gametic = READUINT32(save_p); + gametic = READUINT32(save->p); - gamemap = READINT16(save_p); + gamemap = READINT16(save->p); // gamemap changed; we assume that its map header is always valid, // so make it so @@ -3363,26 +3335,23 @@ FUNCINLINE static ATTRINLINE boolean P_NetUnArchiveMisc(boolean reloading) if (!reloading) mapmusflags |= MUSIC_RELOADRESET; - G_SetGamestate(READINT16(save_p)); + G_SetGamestate(READINT16(save->p)); if (reloading) - gametype = READINT16(save_p); + gametype = READINT16(save->p); - pig = READUINT32(save_p); + pig = READUINT32(save->p); for (i = 0; i < MAXPLAYERS; i++) { playeringame[i] = (pig & (1<p)); - tokenlist = READUINT32(save_p); + tokenlist = READUINT32(save->p); - encoremode = (boolean)READUINT8(save_p); - - // FIXME: save_p should not be global!!! - old_save_p = save_p; + encoremode = (boolean)READUINT8(save->p); if (!P_SetupLevel(true, reloading)) { @@ -3390,97 +3359,95 @@ FUNCINLINE static ATTRINLINE boolean P_NetUnArchiveMisc(boolean reloading) return false; } - save_p = old_save_p; - // get the time - leveltime = READUINT32(save_p); - totalrings = READUINT32(save_p); - lastmap = READINT16(save_p); + leveltime = READUINT32(save->p); + totalrings = READUINT32(save->p); + lastmap = READINT16(save->p); for (i = 0; i < 4; i++) { - votelevels[i][0] = READINT16(save_p); - votelevels[i][1] = READINT16(save_p); + votelevels[i][0] = READINT16(save->p); + votelevels[i][1] = READINT16(save->p); } for (i = 0; i < MAXPLAYERS; i++) - votes[i] = READSINT8(save_p); + votes[i] = READSINT8(save->p); - pickedvote = READSINT8(save_p); + pickedvote = READSINT8(save->p); - emeralds = READUINT16(save_p); - stagefailed = READUINT8(save_p); + emeralds = READUINT16(save->p); + stagefailed = READUINT8(save->p); - token = READUINT32(save_p); - sstimer = READINT32(save_p); - bluescore = READUINT32(save_p); - redscore = READUINT32(save_p); + token = READUINT32(save->p); + sstimer = READINT32(save->p); + bluescore = READUINT32(save->p); + redscore = READUINT32(save->p); - autobalance = READINT16(save_p); - teamscramble = READINT16(save_p); + autobalance = READINT16(save->p); + teamscramble = READINT16(save->p); for (i = 0; i < MAXPLAYERS; i++) - scrambleplayers[i] = READINT16(save_p); + scrambleplayers[i] = READINT16(save->p); for (i = 0; i < MAXPLAYERS; i++) - scrambleteams[i] = READINT16(save_p); + scrambleteams[i] = READINT16(save->p); - scrambletotal = READINT16(save_p); - scramblecount = READINT16(save_p); + scrambletotal = READINT16(save->p); + scramblecount = READINT16(save->p); - racecountdown = READUINT32(save_p); - exitcountdown = READUINT32(save_p); + racecountdown = READUINT32(save->p); + exitcountdown = READUINT32(save->p); - gravity = READFIXED(save_p); - mapobjectscale = READFIXED(save_p); + gravity = READFIXED(save->p); + mapobjectscale = READFIXED(save->p); - countdowntimer = (tic_t)READUINT32(save_p); - countdowntimeup = (boolean)READUINT8(save_p); + countdowntimer = (tic_t)READUINT32(save->p); + countdowntimeup = (boolean)READUINT8(save->p); - hidetime = READUINT32(save_p); + hidetime = READUINT32(save->p); // SRB2kart - numgotboxes = READINT32(save_p); + numgotboxes = READINT32(save->p); - gamespeed = READUINT8(save_p); - franticitems = (boolean)READUINT8(save_p); - comeback = (boolean)READUINT8(save_p); + gamespeed = READUINT8(save->p); + franticitems = (boolean)READUINT8(save->p); + comeback = (boolean)READUINT8(save->p); for (i = 0; i < 4; i++) - battlewanted[i] = READSINT8(save_p); + battlewanted[i] = READSINT8(save->p); - wantedcalcdelay = READUINT32(save_p); - indirectitemcooldown = READUINT32(save_p); - hyubgone = READUINT32(save_p); - mapreset = READUINT32(save_p); - nospectategrief = READUINT8(save_p); - thwompsactive = (boolean)READUINT8(save_p); - spbplace = READSINT8(save_p); - startedInFreePlay = READUINT8(save_p); + wantedcalcdelay = READUINT32(save->p); + indirectitemcooldown = READUINT32(save->p); + hyubgone = READUINT32(save->p); + mapreset = READUINT32(save->p); + nospectategrief = READUINT8(save->p); + thwompsactive = (boolean)READUINT8(save->p); + spbplace = READSINT8(save->p); + startedInFreePlay = READUINT8(save->p); // Is it paused? - if (READUINT8(save_p) == 0x2f) + if (READUINT8(save->p) == 0x2f) paused = true; return true; } -void P_SaveGame(void) +void P_SaveGame(savebuffer_t *save) { - P_ArchiveMisc(); - P_ArchivePlayer(); + P_ArchiveMisc(save); + P_ArchivePlayer(save); - WRITEUINT8(save_p, 0x1d); // consistency marker + WRITEUINT8(save->p, 0x1d); // consistency marker } -void P_SaveNetGame(boolean resending) +void P_SaveNetGame(savebuffer_t *save, boolean resending) { thinker_t *th; mobj_t *mobj; INT32 i = 1; // don't start from 0, it'd be confused with a blank pointer otherwise - CV_SaveNetVars(&save_p, false); - P_NetArchiveMisc(resending); + CV_SaveNetVars(&save->p, false); + P_NetArchiveMisc(save, resending); // Assign the mobjnumber for pointer tracking if (gamestate == GS_LEVEL) @@ -3499,20 +3466,20 @@ void P_SaveNetGame(boolean resending) } } - P_NetArchivePlayers(resending); + P_NetArchivePlayers(save, resending); if (gamestate == GS_LEVEL) { - P_NetArchiveWorld(); - P_ArchivePolyObjects(); - P_NetArchiveThinkers(); - P_NetArchiveSpecials(); + P_NetArchiveWorld(save); + P_ArchivePolyObjects(save); + P_NetArchiveThinkers(save); + P_NetArchiveSpecials(save); } - LUA_Archive(); - WRITEUINT8(save_p, 0x1d); // consistency marker + LUA_Archive(save, true); + WRITEUINT8(save->p, 0x1d); // consistency marker } -boolean P_LoadGame(INT16 mapoverride) +boolean P_LoadGame(savebuffer_t *save, INT16 mapoverride) { if (gamestate == GS_INTERMISSION) Y_EndIntermission(); @@ -3520,12 +3487,15 @@ boolean P_LoadGame(INT16 mapoverride) Y_EndVote(); G_SetGamestate(GS_NULL); // should be changed in P_UnArchiveMisc - P_UnArchiveSPGame(mapoverride); - P_UnArchivePlayer(); + P_UnArchiveSPGame(save, mapoverride); + P_UnArchivePlayer(save); // Savegame end marker - if (READUINT8(save_p) != 0x1d) + if (READUINT8(save->p) != 0x1d) + { + CONS_Alert(CONS_ERROR, M_GetText("Corrupt Luabanks! (Failed consistency check)\n")); return false; + } // Only do this after confirming savegame is ok G_DeferedInitNew(false, G_BuildMapName(gamemap), savedata.skin, 0, true); @@ -3534,23 +3504,26 @@ boolean P_LoadGame(INT16 mapoverride) return true; } -boolean P_LoadNetGame(boolean resending) +boolean P_LoadNetGame(savebuffer_t *save, boolean reloading) { - CV_LoadNetVars(&save_p); - if (!P_NetUnArchiveMisc(resending)) + CV_LoadNetVars(&save->p); + + if (!P_NetUnArchiveMisc(save, reloading)) return false; - P_NetUnArchivePlayers(resending); + + P_NetUnArchivePlayers(save, reloading); + if (gamestate == GS_LEVEL) { - P_NetUnArchiveWorld(); - P_UnArchivePolyObjects(); - P_NetUnArchiveThinkers(); - P_NetUnArchiveSpecials(); + P_NetUnArchiveWorld(save); + P_UnArchivePolyObjects(save); + P_NetUnArchiveThinkers(save); + P_NetUnArchiveSpecials(save); P_RelinkPointers(); P_FinishMobjs(); } - LUA_UnArchive(); + LUA_UnArchive(save, true); // This is stupid and hacky, but maybe it'll work! P_SetRandSeed(P_GetInitSeed()); @@ -3561,5 +3534,5 @@ boolean P_LoadNetGame(boolean resending) // precipitation when loading a netgame save. Instead, precip has to be spawned here. // This is done in P_NetUnArchiveSpecials now. - return READUINT8(save_p) == 0x1d; + return READUINT8(save->p) == 0x1d; } diff --git a/src/p_saveg.h b/src/p_saveg.h index 9e73ad8fc..9a0e26c39 100644 --- a/src/p_saveg.h +++ b/src/p_saveg.h @@ -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 diff --git a/src/p_setup.c b/src/p_setup.c index c0ca1d0a6..0e7f89dcf 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -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); } @@ -2908,8 +2908,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)); diff --git a/src/p_user.c b/src/p_user.c index 355c19dfd..3133ee49b 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3383,8 +3383,15 @@ void P_ResetCamera(player_t *player, camera_t *thiscam) thiscam->z = z; thiscam->reset = true; - thiscam->angle = player->mo->angle; - thiscam->aiming = 0; + if (!(thiscam == &camera[0] && (cv_cam_still[0].value)) + && !(thiscam == &camera[1] && (cv_cam_still[1].value)) + && !(thiscam == &camera[2] && (cv_cam_still[2].value)) + && !(thiscam == &camera[3] && (cv_cam_still[3].value))) + { + thiscam->angle = player->mo->angle; + thiscam->aiming = 0; + } + thiscam->relativex = 0; thiscam->subsector = R_PointInSubsectorFast(thiscam->x,thiscam->y); @@ -3500,7 +3507,10 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall focusangle = mo->angle; } - camrotate = cv_cam_rotate[num].value; + if (thiscam == &camera[num]) + camrotate = cv_cam_rotate[num].value; + else + camrotate = 0; if (leveltime < introtime) // Whoooshy camera! { @@ -3604,7 +3614,7 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall } if (!resetcalled && (leveltime > starttime && timeover != 2) - && (t_cam_rotate[num] != -42)) + && (thiscam == &camera[num] && t_cam_rotate[num] != -42)) { angle = FixedAngle(camrotate*FRACUNIT); thiscam->angle = angle; diff --git a/src/r_bsp.c b/src/r_bsp.c index 490540eaa..db6a4378d 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -583,10 +583,10 @@ static void R_AddLine(seg_t *line) clippass: g_walloffscreen = false; + R_ClipPassWallSegment(x1, x2 - 1, false); + if (g_walloffscreen) R_ClipPassWallSegment(x1, x2 - 1, true); - else - R_ClipPassWallSegment(x1, x2 - 1, false); return; clipsolid: diff --git a/src/s_sound.c b/src/s_sound.c index 747585db9..c770957b6 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -935,6 +935,7 @@ void S_ClearSfx(void) static void S_StopChannel(INT32 cnum) { + INT32 i; channel_t *c = &channels[cnum]; if (c->sfxinfo) @@ -943,6 +944,12 @@ static void S_StopChannel(INT32 cnum) if (I_SoundIsPlaying(c->handle)) I_StopSound(c->handle); + // check to see + // if other channels are playing the sound + for (i = 0; i < numofchannels; i++) + if (cnum != i && c->sfxinfo == channels[i].sfxinfo) + break; + // degrade usefulness of sound data c->sfxinfo->usefulness--; c->sfxinfo = 0; diff --git a/src/sdl/Srb2SDL.dsp b/src/sdl/Srb2SDL.dsp index 92821295d..6f799f4fb 100644 --- a/src/sdl/Srb2SDL.dsp +++ b/src/sdl/Srb2SDL.dsp @@ -572,7 +572,7 @@ SOURCE=..\hardware\hw_draw.c # End Source File # Begin Source File -SOURCE=..\hardware\hw_drv.h +SOURCE=..\hardware\hw_gl.h # End Source File # Begin Source File diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c index 23526a98f..d3da79355 100644 --- a/src/sdl/hwsym_sdl.c +++ b/src/sdl/hwsym_sdl.c @@ -43,14 +43,6 @@ #define _CREATE_DLL_ // necessary for Unix AND Windows -#ifdef HWRENDER -#include "../hardware/hw_drv.h" -#include "ogl_sdl.h" -#ifdef STATIC_OPENGL -#include "../hardware/r_opengl/r_opengl.h" -#endif -#endif - #ifdef HW3SOUND #include "../hardware/hw3dsdrv.h" #endif @@ -73,55 +65,7 @@ void *hwSym(const char *funcName,void *handle) { void *funcPointer = NULL; -#ifdef HWRENDER - if (0 == strcmp("SetTexturePalette", funcName)) - funcPointer = &OglSdlSetPalette; - - GETFUNC(Init); - GETFUNC(SetupGLInfo); - GETFUNC(Draw2DLine); - GETFUNC(DrawPolygon); - GETFUNC(DrawIndexedTriangles); - GETFUNC(SetBlend); - GETFUNC(ClearBuffer); - GETFUNC(SetTexture); - GETFUNC(UpdateTexture); - GETFUNC(DeleteTexture); - GETFUNC(ReadScreenTexture); - GETFUNC(GClipRect); - GETFUNC(ClearMipMapCache); - GETFUNC(SetSpecialState); - GETFUNC(GetTextureUsed); - GETFUNC(DrawModel); - GETFUNC(CreateModelVBOs); - GETFUNC(SetTransform); - GETFUNC(PostImgRedraw); - GETFUNC(FlushScreenTextures); - GETFUNC(DoScreenWipe); - GETFUNC(DrawScreenTexture); - GETFUNC(MakeScreenTexture); - GETFUNC(RenderVhsEffect); - GETFUNC(DrawScreenFinalTexture); - - GETFUNC(RenderSkyDome); - - GETFUNC(InitShaders); - GETFUNC(LoadShader); - GETFUNC(CompileShader); - GETFUNC(SetShader); - GETFUNC(UnSetShader); - - GETFUNC(SetShaderInfo); - - GETFUNC(SetPaletteLookup); - GETFUNC(CreateLightTable); - GETFUNC(ClearLightTables); - GETFUNC(SetScreenPalette); - -#else //HWRENDER - if (0 == strcmp("FinishUpdate", funcName)) - return funcPointer; //&FinishUpdate; -#endif //!HWRENDER + if (0) ; #ifdef STATIC3DS GETFUNC(Startup); GETFUNC(AddSfx); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index ca81b8043..7af6455fe 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -74,15 +74,17 @@ #include "../i_video.h" #include "../console.h" #include "../command.h" -#include "sdlmain.h" #include "../i_system.h" #include "../hu_stuff.h" // for chat_on + +#include "sdlmain.h" + #ifdef HWRENDER #include "../hardware/hw_main.h" -#include "../hardware/hw_drv.h" +#include "../hardware/hw_gl.h" #include "../hardware/r_opengl/r_opengl.h" //for supportFBO -// For dynamic referencing of HW rendering functions -#include "hwsym_sdl.h" + +#include "hwsym_sdl.h" // For dynamic referencing of HW rendering functions #include "ogl_sdl.h" #endif @@ -2144,50 +2146,8 @@ void I_StartupGraphics(void) #ifdef HWRENDER if (rendermode == render_opengl) { - HWD.pfnInit = hwSym("Init",NULL); - HWD.pfnSetupGLInfo = hwSym("SetupGLInfo",NULL); - HWD.pfnFinishUpdate = NULL; - HWD.pfnDraw2DLine = hwSym("Draw2DLine",NULL); - HWD.pfnDrawPolygon = hwSym("DrawPolygon",NULL); - HWD.pfnDrawIndexedTriangles = hwSym("DrawIndexedTriangles",NULL); - HWD.pfnSetBlend = hwSym("SetBlend",NULL); - HWD.pfnClearBuffer = hwSym("ClearBuffer",NULL); - HWD.pfnSetTexture = hwSym("SetTexture",NULL); - HWD.pfnUpdateTexture = hwSym("UpdateTexture",NULL); - HWD.pfnDeleteTexture = hwSym("DeleteTexture",NULL); - HWD.pfnReadScreenTexture= hwSym("ReadScreenTexture",NULL); - HWD.pfnGClipRect = hwSym("GClipRect",NULL); - HWD.pfnClearMipMapCache = hwSym("ClearMipMapCache",NULL); - HWD.pfnSetSpecialState = hwSym("SetSpecialState",NULL); - HWD.pfnSetTexturePalette= hwSym("SetTexturePalette",NULL); - HWD.pfnGetTextureUsed = hwSym("GetTextureUsed",NULL); - HWD.pfnDrawModel = hwSym("DrawModel",NULL); - HWD.pfnCreateModelVBOs = hwSym("CreateModelVBOs",NULL); - HWD.pfnSetTransform = hwSym("SetTransform",NULL); - HWD.pfnPostImgRedraw = hwSym("PostImgRedraw",NULL); - HWD.pfnFlushScreenTextures=hwSym("FlushScreenTextures",NULL); - HWD.pfnDoScreenWipe = hwSym("DoScreenWipe",NULL); - HWD.pfnDrawScreenTexture= hwSym("DrawScreenTexture",NULL); - HWD.pfnMakeScreenTexture= hwSym("MakeScreenTexture",NULL); - HWD.pfnRenderVhsEffect = hwSym("RenderVhsEffect",NULL); - HWD.pfnDrawScreenFinalTexture=hwSym("DrawScreenFinalTexture",NULL); + vid.glstate = (VID_LoadOGLAPI() && GL_Init()) ? VID_GL_LIBRARY_LOADED : VID_GL_LIBRARY_ERROR; - HWD.pfnRenderSkyDome = hwSym("RenderSkyDome",NULL); - - HWD.pfnInitShaders = hwSym("InitShaders",NULL); - HWD.pfnLoadShader = hwSym("LoadShader",NULL); - HWD.pfnCompileShader = hwSym("CompileShader",NULL); - HWD.pfnSetShader = hwSym("SetShader",NULL); - HWD.pfnUnSetShader = hwSym("UnSetShader",NULL); - - HWD.pfnSetShaderInfo = hwSym("SetShaderInfo",NULL); - - HWD.pfnSetPaletteLookup = hwSym("SetPaletteLookup",NULL); - HWD.pfnCreateLightTable = hwSym("CreateLightTable",NULL); - HWD.pfnClearLightTables = hwSym("ClearLightTables",NULL); - HWD.pfnSetScreenPalette = hwSym("SetScreenPalette",NULL); - - vid.glstate = HWD.pfnInit() ? VID_GL_LIBRARY_LOADED : VID_GL_LIBRARY_ERROR; // let load the OpenGL library if (vid.glstate == VID_GL_LIBRARY_ERROR) { rendermode = render_soft; diff --git a/src/sdl/macosx/Srb2mac.pbproj/project.pbxproj b/src/sdl/macosx/Srb2mac.pbproj/project.pbxproj index ee0bf4697..a4888ec50 100644 --- a/src/sdl/macosx/Srb2mac.pbproj/project.pbxproj +++ b/src/sdl/macosx/Srb2mac.pbproj/project.pbxproj @@ -1060,8 +1060,8 @@ 8417773A085A106C000C01D8 = { fileEncoding = 30; isa = PBXFileReference; - name = hw_drv.h; - path = ../../hardware/hw_drv.h; + name = hw_gl.h; + path = ../../hardware/hw_gl.h; refType = 2; }; 8417773C085A106C000C01D8 = { diff --git a/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj b/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj index 00930bfb3..9ec22ebcc 100644 --- a/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj +++ b/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj @@ -180,7 +180,7 @@ 1E44AE630B67CC2B00BAD059 /* hw3sound.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = hw3sound.c; path = ../../hardware/hw3sound.c; sourceTree = SOURCE_ROOT; }; 1E44AE640B67CC2B00BAD059 /* hw_cache.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = hw_cache.c; path = ../../hardware/hw_cache.c; sourceTree = SOURCE_ROOT; }; 1E44AE650B67CC2B00BAD059 /* hw_dll.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw_dll.h; path = ../../hardware/hw_dll.h; sourceTree = SOURCE_ROOT; }; - 1E44AE660B67CC2B00BAD059 /* hw_drv.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw_drv.h; path = ../../hardware/hw_drv.h; sourceTree = SOURCE_ROOT; }; + 1E44AE660B67CC2B00BAD059 /* hw_gl.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw_gl.h; path = ../../hardware/hw_gl.h; sourceTree = SOURCE_ROOT; }; 1E44AE680B67CC2B00BAD059 /* hw_light.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = hw_light.c; path = ../../hardware/hw_light.c; sourceTree = SOURCE_ROOT; }; 1E44AE690B67CC2B00BAD059 /* hw_light.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw_light.h; path = ../../hardware/hw_light.h; sourceTree = SOURCE_ROOT; }; 1E44AE6A0B67CC2B00BAD059 /* hw3sound.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw3sound.h; path = ../../hardware/hw3sound.h; sourceTree = SOURCE_ROOT; }; @@ -533,7 +533,7 @@ 1E44AE630B67CC2B00BAD059 /* hw3sound.c */, 1E44AE640B67CC2B00BAD059 /* hw_cache.c */, 1E44AE650B67CC2B00BAD059 /* hw_dll.h */, - 1E44AE660B67CC2B00BAD059 /* hw_drv.h */, + 1E44AE660B67CC2B00BAD059 /* hw_gl.h */, 1E44AE680B67CC2B00BAD059 /* hw_light.c */, 1E44AE690B67CC2B00BAD059 /* hw_light.h */, 1E44AE6A0B67CC2B00BAD059 /* hw3sound.h */, diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index eeac3b84b..9093f9a18 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -38,12 +38,15 @@ #ifdef HWRENDER #include "../hardware/r_opengl/r_opengl.h" #include "../hardware/hw_main.h" +#include "../hardware/hw_gl.h" #include "ogl_sdl.h" #include "../i_system.h" #include "hwsym_sdl.h" #include "../m_argv.h" #include "../i_video.h" +#include "../f_finale.h" + #ifdef DEBUG_TO_FILE #include #if defined (_WIN32) && !defined (__CYGWIN__) @@ -94,7 +97,7 @@ void *GetGLFunc(const char *proc) return SDL_GL_GetProcAddress(proc); } -boolean LoadGL(void) +boolean VID_LoadOGLAPI(void) { #ifndef STATIC_OPENGL const char *OGLLibname = NULL; @@ -111,7 +114,7 @@ boolean LoadGL(void) return 0; } #endif - return SetupGLfunc(); + return true; } /** \brief The OglSdlSurface function @@ -179,7 +182,7 @@ boolean OglSdlSurface(INT32 w, INT32 h) else supportMipMap = true; - if (isExtAvailable("GL_EXT_texture_filter_anisotropic", gl_extensions)) + if (GL_isExtAvailable("GL_EXT_texture_filter_anisotropic", gl_extensions)) pglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnisotropy); else maximumAnisotropy = 1; @@ -199,25 +202,25 @@ boolean OglSdlSurface(INT32 w, INT32 h) // The screen textures need to be flushed if the width or height change so that they be remade for the correct size if (screen_width != w || screen_height != h) { - FlushScreenTextures(); + GL_FlushScreenTextures(); #ifdef USE_FBO_OGL - GLFramebuffer_DeleteAttachments(); + GL_Framebuffer_DeleteAttachments(); #endif } screen_width = (GLint)w; screen_height = (GLint)h; - SetModelView(w, h); - SetStates(); + GL_SetModelView(w, h); + GL_SetStates(); pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); #ifdef USE_FBO_OGL if (UseScreenFBO()) - GLFramebuffer_Enable(); + GL_Framebuffer_Enable(); else - GLFramebuffer_Disable(); + GL_Framebuffer_Disable(); #endif if (!first_init) @@ -257,22 +260,22 @@ void OglSdlFinishUpdate(boolean waitvbl) #ifdef USE_FBO_OGL if (usefbo) { - GLFramebuffer_Unbind(); + GL_Framebuffer_Unbind(); } #endif - - HWR_DrawScreenFinalTexture(sdlw, sdlh, HWR_ShouldUsePaletteRendering()); + + GL_DrawScreenFinalTexture(HWD_SCREENTEXTURE_GENERIC2, sdlw, sdlh, HWR_ShouldUsePaletteRendering()); #ifdef USE_FBO_OGL if (usefbo) { - GLFramebuffer_Enable(); + GL_Framebuffer_Enable(); } #endif SDL_GL_SwapWindow(window); - GClipRect(0, 0, realwidth, realheight, NZCLIP_PLANE, FAR_ZCLIP_DEFAULT); + GL_GClipRect(0, 0, realwidth, realheight, NZCLIP_PLANE, FAR_ZCLIP_DEFAULT); // Sryder: We need to draw the final screen texture again into the other buffer in the original position so that // effects that want to take the old screen can do so after this @@ -291,19 +294,5 @@ void OglSdlFinishUpdate(boolean waitvbl) #endif } -EXPORT void HWRAPI(OglSdlSetPalette) (RGBA_t *palette) -{ - INT32 i; - - for (i = 0; i < 256; i++) - { - myPaletteData[i].s.red = palette[i].s.red; - myPaletteData[i].s.green = palette[i].s.green; - myPaletteData[i].s.blue = palette[i].s.blue; - myPaletteData[i].s.alpha = palette[i].s.alpha; - } - Flush(); -} - #endif //HWRENDER #endif //SDL diff --git a/src/sdl/ogl_sdl.h b/src/sdl/ogl_sdl.h index ad153da93..6d614cd22 100644 --- a/src/sdl/ogl_sdl.h +++ b/src/sdl/ogl_sdl.h @@ -21,12 +21,10 @@ boolean OglSdlSurface(INT32 w, INT32 h); void OglSdlFinishUpdate(boolean vidwait); +boolean VID_LoadOGLAPI(void); extern SDL_Renderer *renderer; extern SDL_GLContext sdlglcontext; extern Uint16 realwidth; extern Uint16 realheight; -#ifdef _CREATE_DLL_ -EXPORT void HWRAPI( OglSdlSetPalette ) (RGBA_t *palette); -#endif