From 191a6ca76fc825f0e7479f6ee2e6d175d2498a5d Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 16 Sep 2024 12:42:29 +0200 Subject: [PATCH 01/99] unglobalize savebuffer needs some cleanup --- src/d_clisrv.c | 83 +- src/d_netcmd.c | 23 +- src/g_game.c | 157 ++-- src/lua_script.c | 613 +++---------- src/lua_script.h | 8 +- src/p_saveg.c | 2275 ++++++++++++++++++++++++---------------------- src/p_saveg.h | 24 +- src/p_setup.c | 24 +- 8 files changed, 1492 insertions(+), 1715 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index a5899796a..474d3f19a 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1793,28 +1793,28 @@ static boolean SV_SendServerConfig(INT32 node) 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"); } @@ -1828,11 +1828,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; @@ -1846,12 +1846,12 @@ static void SV_SendSaveGame(INT32 node, boolean resending) 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; + save.p = NULL; // Remember when we started sending the savegame so we can handle timeouts sendingsavegame[node] = true; @@ -1865,7 +1865,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) @@ -1874,29 +1874,31 @@ 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")); + free(save.buffer); + save.p = NULL; 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 @@ -1905,13 +1907,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) @@ -1920,16 +1922,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; @@ -1938,7 +1941,7 @@ static void CL_LoadReceivedSavegame(boolean reloading) automapactive = false; // load a base level - if (P_LoadNetGame(reloading)) + if (P_LoadNetGame(&save, reloading)) { if (!reloading) { @@ -1958,8 +1961,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(); @@ -6842,6 +6845,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) @@ -6851,8 +6855,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; @@ -6863,6 +6868,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) @@ -6875,8 +6881,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 3cd815dee..d85280f08 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -5819,10 +5819,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) @@ -5838,28 +5837,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.p, 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.p, 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 27758119b..5f5cce736 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -354,8 +354,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 static void UserAnalog_OnChange(void); static void UserAnalog2_OnChange(void); @@ -3918,6 +3916,7 @@ void G_LoadGameData(void) INT32 i, j; UINT8 modded = false; UINT8 rtemp; + savebuffer_t save; //For records tic_t rectime; @@ -3939,28 +3938,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)) @@ -3970,48 +3969,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) { @@ -4022,8 +4020,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(); @@ -4037,8 +4035,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); } @@ -4051,14 +4049,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; @@ -4066,23 +4063,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;) @@ -4090,7 +4087,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;) @@ -4098,7 +4095,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;) @@ -4106,7 +4103,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;) @@ -4114,33 +4111,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 @@ -4156,22 +4153,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! @@ -4180,8 +4178,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. @@ -4209,6 +4207,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)); @@ -4220,18 +4219,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"), @@ -4241,15 +4240,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(); @@ -4258,13 +4257,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)); @@ -4272,17 +4271,14 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) } // done - Z_Free(savebuffer); - save_p = savebuffer = NULL; + Z_Free(save.buffer); + save.p = save.buffer = NULL; -// gameaction = ga_nothing; -// G_SetGamestate(GS_LEVEL); displayplayers[0] = consoleplayer; multiplayer = false; splitscreen = 0; SplitScreen_OnChange(); // not needed? -// G_DeferedInitNew(sk_medium, G_BuildMapName(1), 0, 0, 1); if (setsizeneeded) R_ExecuteSetViewSize(); @@ -4299,6 +4295,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); @@ -4312,8 +4309,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; @@ -4321,14 +4318,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; @@ -6585,7 +6582,7 @@ void G_BeginRecording(void) // player lua vars, always saved even if empty... Unless it's record attack. if (demoflags & DF_LUAVARS) - LUA_ArchiveDemo(); + LUA_Archive(&demo_p, false); memset(&oldcmd,0,sizeof(oldcmd)); memset(&oldghost,0,sizeof(oldghost)); @@ -7689,7 +7686,7 @@ void G_DoPlayDemo(char *defdemoname) LUA_ClearState(); // No modeattacking check, DF_LUAVARS won't be present here. - LUA_UnArchiveDemo(); + LUA_UnArchiveDemo(&demo_p); } splitscreen = 0; diff --git a/src/lua_script.c b/src/lua_script.c index 9d5bef4a7..5e8b4315f 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -40,6 +40,8 @@ static lua_State *mL = NULL; int hook_defrosting; +static UINT8 **lua_save_p = NULL; // FIXME: Remove this horrible hack + // List of internal libraries to load from SRB2 static lua_CFunction liblist[] = { LUA_EnumLib, // global metatable for enums @@ -608,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; @@ -616,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: @@ -640,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'. @@ -648,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: @@ -676,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) { @@ -698,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; } @@ -724,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; } @@ -735,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; } @@ -746,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; } @@ -757,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; } @@ -768,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; } @@ -779,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; } @@ -790,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; } @@ -801,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; } @@ -812,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; @@ -828,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; } @@ -1063,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; } @@ -1075,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,11 +891,11 @@ static int NetArchive(lua_State *L) int TABLESINDEX = lua_upvalueindex(1); int i, n = lua_gettop(L); for (i = 1; i <= n; i++) - ArchiveValue(TABLESINDEX, i); + ArchiveValue(lua_save_p, TABLESINDEX, i); return n; } -static void ArchiveTables(void) +static void ArchiveTables(UINT8 **p) { int TABLESINDEX; UINT16 i, n; @@ -1181,7 +914,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); @@ -1189,7 +922,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 @@ -1202,57 +935,13 @@ 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: @@ -1262,11 +951,11 @@ static UINT8 UnArchiveValue(int TABLESINDEX) lua_pushboolean(gL, READUINT8(save_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; @@ -1276,14 +965,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)) { @@ -1296,40 +985,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; @@ -1345,23 +1034,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; @@ -1371,14 +1060,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)) { @@ -1391,13 +1080,13 @@ 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 @@ -1406,31 +1095,31 @@ static UINT8 UnArchiveValueDemo(int TABLESINDEX, char field[1024]) 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; @@ -1438,10 +1127,10 @@ static UINT8 UnArchiveValueDemo(int TABLESINDEX, char field[1024]) return 0; } -static void UnArchiveExtVars(void *pointer) +static void UnArchiveExtVars(UINT8 **p, void *pointer) { int TABLESINDEX; - UINT16 field_count = READUINT16(save_p); + UINT16 field_count = READUINT16(*p); UINT16 i; char field[1024]; @@ -1459,8 +1148,8 @@ static void UnArchiveExtVars(void *pointer) for (i = 0; i < field_count; i++) { - READSTRING(save_p, field); - UnArchiveValue(TABLESINDEX); + READSTRING(*p, field); + UnArchiveValue(p, TABLESINDEX); lua_setfield(gL, -2, field); } @@ -1472,10 +1161,10 @@ static void UnArchiveExtVars(void *pointer) lua_pop(gL, 2); // pop LREG_EXTVARS and pointer's subtable } -static void UnArchiveExtVarsDemo(void *pointer) +static void UnArchiveExtVarsDemo(UINT8 **p, void *pointer) { int TABLESINDEX; - UINT16 field_count = READUINT16(demo_p); + UINT16 field_count = READUINT16(*p); UINT16 i; char field[1024]; @@ -1488,8 +1177,8 @@ static void UnArchiveExtVarsDemo(void *pointer) 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. + 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); } @@ -1506,11 +1195,11 @@ static int NetUnArchive(lua_State *L) int TABLESINDEX = lua_upvalueindex(1); int i, n = lua_gettop(L); for (i = 1; i <= n; i++) - UnArchiveValue(TABLESINDEX); + UnArchiveValue(lua_save_p, TABLESINDEX); return n; } -static void UnArchiveTables(void) +static void UnArchiveTables(UINT8 **p) { int TABLESINDEX; UINT16 i, n; @@ -1526,9 +1215,9 @@ static void UnArchiveTables(void) lua_rawgeti(gL, TABLESINDEX, i); while (true) { - if (UnArchiveValue(TABLESINDEX) == 1) // read key + if (UnArchiveValue(p, TABLESINDEX) == 1) // read key break; - if (UnArchiveValue(TABLESINDEX) == 2) // read value + if (UnArchiveValue(p, TABLESINDEX) == 2) // read value n++; if (lua_isnil(gL, -2)) // if key is nil (if a function etc was accidentally saved) { @@ -1542,7 +1231,7 @@ static void UnArchiveTables(void) } } -static void UnArchiveTablesDemo(void) +static void UnArchiveTablesDemo(UINT8 **p) { int TABLESINDEX; UINT16 i, n; @@ -1560,13 +1249,13 @@ static void UnArchiveTablesDemo(void) { UINT8 ret; - ret = UnArchiveValueDemo(TABLESINDEX, NULL); + ret = UnArchiveValueDemo(p, TABLESINDEX, NULL); if (ret == 3) lua_pushnil(gL); else if (ret == 1) // read key break; - ret = UnArchiveValueDemo(TABLESINDEX, NULL); + ret = UnArchiveValueDemo(p, TABLESINDEX, NULL); if (ret == 3) lua_pushnil(gL); @@ -1593,7 +1282,7 @@ void LUA_Step(void) lua_gc(gL, LUA_GCSTEP, 1); } -void LUA_Archive(void) +void LUA_Archive(UINT8 **p, boolean network) { INT32 i; thinker_t *th; @@ -1606,31 +1295,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(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(p, th, "mobj"); + } } - } - WRITEUINT32(save_p, UINT32_MAX); // end of mobjs marker, replaces mobjnum. + WRITEUINT32(*p, UINT32_MAX); // end of mobjs marker, replaces mobjnum. - LUAh_NetArchiveHook(NetArchive); // call the NetArchive hook in archive mode - ArchiveTables(); + lua_save_p = p; + LUAh_NetArchiveHook(NetArchive); // call the NetArchive hook in archive mode + } + + ArchiveTables(p); if (gL) lua_pop(gL, 1); // pop tables } -void LUA_UnArchive(void) +void LUA_UnArchive(UINT8 **p) { UINT32 mobjnum; INT32 i; @@ -1643,52 +1337,33 @@ void LUA_UnArchive(void) { if (!playeringame[i] && i > 0) // same here, this is to synch dediservs properly. continue; - UnArchiveExtVars(&players[i]); + UnArchiveExtVars(p, &players[i]); } do { - mobjnum = READUINT32(save_p); // read a mobjnum + mobjnum = READUINT32(*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 + + UnArchiveExtVars(p, th); // apply variables } } while(mobjnum != UINT32_MAX); // repeat until end of mobjs marker. + lua_save_p = p; LUAh_NetArchiveHook(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 (!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"); - } - - ArchiveTablesDemo(); + UnArchiveTables(p); if (gL) lua_pop(gL, 1); // pop tables } // this time make sure we read from demo_p -void LUA_UnArchiveDemo(void) +void LUA_UnArchiveDemo(UINT8 **p) { INT32 i; @@ -1699,10 +1374,10 @@ void LUA_UnArchiveDemo(void) { if (!playeringame[i] && i > 0) // same here, this is to synch dediservs properly. continue; - UnArchiveExtVarsDemo(&players[i]); + UnArchiveExtVarsDemo(p, &players[i]); } - UnArchiveTablesDemo(); + UnArchiveTablesDemo(p); if (gL) lua_pop(gL, 1); // pop tables diff --git a/src/lua_script.h b/src/lua_script.h index 9903315c2..7039603a5 100644 --- a/src/lua_script.h +++ b/src/lua_script.h @@ -55,11 +55,11 @@ 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_Archive(UINT8 **p, boolean network); +void LUA_UnArchive(UINT8 **p); -void LUA_ArchiveDemo(void); -void LUA_UnArchiveDemo(void); +// keeping this around since demos are kinda ass +void LUA_UnArchiveDemo(UINT8 **p); void Got_Luacmd(UINT8 **cp, INT32 playernum); // lua_consolelib.c void LUA_CVarChanged(const char *name); // lua_consolelib.c diff --git a/src/p_saveg.c b/src/p_saveg.c index b8a517f0e..695ecac76 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); + WRITEUINT16(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); + WRITEUINT16(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 = READUINT16(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 = READUINT16(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,128 @@ static inline void P_UnArchivePlayer(void) // // P_NetArchivePlayers // -static void P_NetArchivePlayers(boolean resending) +static void P_NetArchivePlayers(savebuffer_t *save) { 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); - } - - - 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); + 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); //////////////////////////// // 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 +241,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 +289,18 @@ static void P_NetArchivePlayers(boolean resending) // // P_NetUnArchivePlayers // -static void P_NetUnArchivePlayers(boolean resending) +static void P_NetUnArchivePlayers(savebuffer_t *save) { 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 (resending) - 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 //memset(&players[i], 0, sizeof (player_t)); @@ -317,167 +308,191 @@ static void P_NetUnArchivePlayers(boolean resending) 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 (resending) - 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 (resending) - { - 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].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 //////////////////////////// // 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); } } } +static void P_NetArchiveWaypoints(savebuffer_t *save) +{ + INT32 i, j; + + for (i = 0; i < NUMWAYPOINTSEQUENCES; i++) + { + WRITEUINT16(save->p, numwaypoints[i]); + for (j = 0; j < numwaypoints[i]; j++) + WRITEUINT32(save->p, waypoints[i][j] ? waypoints[i][j]->mobjnum : 0); + } +} + +static void P_NetUnArchiveWaypoints(savebuffer_t *save) +{ + INT32 i, j; + UINT32 mobjnum; + + for (i = 0; i < NUMWAYPOINTSEQUENCES; i++) + { + numwaypoints[i] = READUINT16(save->p); + for (j = 0; j < numwaypoints[i]; j++) + { + mobjnum = READUINT32(save->p); + waypoints[i][j] = (mobjnum == 0) ? NULL : P_FindNewPosition(mobjnum); + } + } +} + +/// +/// World Archiving +/// + #define SD_FLOORHT 0x01 #define SD_CEILHT 0x02 #define SD_FLOORPIC 0x04 @@ -515,7 +530,7 @@ static void P_NetUnArchivePlayers(boolean resending) // // P_NetArchiveWorld // -static void P_NetArchiveWorld(void) +static void P_NetArchiveWorld(savebuffer_t *save) { size_t i; const line_t *li = lines; @@ -530,8 +545,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++) { @@ -743,13 +758,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; @@ -757,10 +772,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 (;;) { @@ -902,7 +917,7 @@ static void P_NetUnArchiveWorld(void) si->midtexture = READINT32(get); } - save_p = get; + save->p = get; } // @@ -992,6 +1007,8 @@ typedef enum tc_noenemies, tc_eachtime, tc_disappear, + tc_dynslopeline, + tc_dynslopevert, tc_polyrotate, // haleyjd 03/26/06: polyobjects tc_polymove, tc_polywaypoint, @@ -1026,12 +1043,18 @@ static inline UINT32 SavePlayer(const player_t *player) return 0xFFFFFFFF; } +static UINT32 SaveSlope(const pslope_t *slope) +{ + if (slope) return (UINT32)(slope->id); + 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; @@ -1068,7 +1091,7 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type) diff2 = 0; // not the default but the most probable - if (mobj->momx != 0 || mobj->momy != 0 || mobj->momz != 0) + if (mobj->momx != 0 || mobj->momy != 0 || mobj->momz != 0 || mobj->pmomz !=0) diff |= MD_MOM; if (mobj->radius != mobj->info->radius) diff |= MD_RADIUS; @@ -1160,17 +1183,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) { @@ -1178,102 +1201,103 @@ 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); + WRITEFIXED(save->p, mobj->pmomz); } 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)); + WRITEUINT16(save->p, (UINT16)((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); } // @@ -1281,18 +1305,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)); } // @@ -1300,25 +1324,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); } // @@ -1326,20 +1350,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); } // @@ -1347,13 +1371,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); } // @@ -1361,16 +1385,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); } // @@ -1378,15 +1402,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); } // @@ -1394,15 +1418,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); } // @@ -1410,27 +1434,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)); } // @@ -1438,20 +1462,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); } // @@ -1459,15 +1483,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); } // @@ -1475,23 +1499,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); } // @@ -1499,13 +1523,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)); } // @@ -1513,13 +1537,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); } // @@ -1527,14 +1551,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); } // @@ -1542,33 +1566,47 @@ 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); } +/// Save a dynamic slope thinker. +static inline void SaveDynamicSlopeThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) +{ + const dynplanethink_t* ht = (const void*)th; + + WRITEUINT8(save->p, type); + WRITEUINT8(save->p, ht->type); + WRITEUINT32(save->p, SaveSlope(ht->slope)); + WRITEUINT32(save->p, SaveLine(ht->sourceline)); + WRITEFIXED(save->p, ht->extent); + + WRITEMEM(save->p, ht->tags, sizeof(ht->tags)); + WRITEMEM(save->p, ht->vex, sizeof(ht->vex)); +} // // 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); } // @@ -1576,16 +1614,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); } // @@ -1593,22 +1631,23 @@ 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); + WRITEUINT32(save->p, SaveMobjnum(ht->target)); } // @@ -1616,23 +1655,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); } // @@ -1640,29 +1679,29 @@ 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); } /* @@ -1671,10 +1710,10 @@ static void SavePolydisplaceThinker(const thinker_t *th, const UINT8 type) // // Saves a what_t thinker // -static inline void SaveWhatThinker(const thinker_t *th, const UINT8 type) +static inline void SaveWhatThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const what_t *ht = (const void *)th; - WRITEUINT8(save_p, type); + WRITEUINT8(save->p, type); } */ @@ -1682,12 +1721,12 @@ static inline void SaveWhatThinker(const thinker_t *th, const UINT8 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) @@ -1698,7 +1737,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 @@ -1706,188 +1745,198 @@ 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_DynamicSlopeLine) + { + SaveDynamicSlopeThinker(save, th, tc_dynslopeline); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_DynamicSlopeVert) + { + SaveDynamicSlopeThinker(save, th, tc_dynslopevert); 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 - else if (th->function.acp1 != P_RemoveThinkerDelayed) // wait garbage collection + else if (th->function.acv != P_RemoveThinkerDelayed) // wait garbage collection I_Error("unknown thinker type %p", th->function.acp1); #endif } 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 @@ -1905,11 +1954,8 @@ mobj_t *P_FindNewPosition(UINT32 oldposition) continue; 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; @@ -1939,12 +1985,25 @@ static inline player_t *LoadPlayer(UINT32 player) return &players[player]; } +static inline pslope_t *LoadSlope(UINT32 slopeid) +{ + pslope_t *p = slopelist; + if (slopeid > slopecount) return NULL; + do + { + if (p->id == slopeid) + return p; + } while ((p = p->next)); + return NULL; +} + + // // LoadMobjThinker // // 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; @@ -1953,21 +2012,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 { @@ -1991,7 +2050,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++) @@ -2010,9 +2069,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 { @@ -2022,50 +2081,51 @@ 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); + mobj->pmomz = 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 { @@ -2073,10 +2133,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 @@ -2090,65 +2150,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[READUINT16(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 @@ -2197,7 +2257,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) { @@ -2236,18 +2296,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) { @@ -2265,25 +2325,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); @@ -2294,20 +2354,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); @@ -2318,13 +2378,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); @@ -2335,16 +2395,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); @@ -2355,15 +2415,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); @@ -2374,15 +2434,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); @@ -2393,27 +2453,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) { @@ -2431,20 +2491,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); } @@ -2453,15 +2513,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); } @@ -2470,23 +2530,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); } @@ -2496,14 +2556,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) @@ -2516,13 +2576,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); @@ -2533,14 +2593,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); } @@ -2549,17 +2609,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); +} + +/// Save a dynamic slope thinker. +static inline void LoadDynamicSlopeThinker(savebuffer_t *save, actionf_p1 thinker) +{ + dynplanethink_t* ht = Z_Malloc(sizeof(*ht), PU_LEVSPEC, NULL); + ht->thinker.function.acp1 = thinker; + + ht->type = READUINT8(save->p); + ht->slope = LoadSlope(READUINT32(save->p)); + ht->sourceline = LoadLine(READUINT32(save->p)); + ht->extent = READFIXED(save->p); + READMEM(save->p, ht->tags, sizeof(ht->tags)); + READMEM(save->p, ht->vex, sizeof(ht->vex)); + P_AddThinker(&ht->thinker); } @@ -2569,14 +2645,14 @@ static inline void LoadDisappearThinker(actionf_p1 thinker) // // 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); } @@ -2585,16 +2661,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); } @@ -2603,22 +2679,23 @@ 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); + ht->target = LoadMobj(READUINT32(save->p)); P_AddThinker(&ht->thinker); } @@ -2627,23 +2704,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); } @@ -2652,18 +2729,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); } @@ -2672,15 +2749,15 @@ 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); } @@ -2690,7 +2767,7 @@ static inline void LoadPolydisplaceThinker(actionf_p1 thinker) // // load a what_t thinker // -static inline void LoadWhatThinker(actionf_p1 thinker) +static inline void LoadWhatThinker(savebuffer_t *save, actionf_p1 thinker) { what_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2700,7 +2777,7 @@ static inline void LoadWhatThinker(actionf_p1 thinker) // // P_NetUnArchiveThinkers // -static void P_NetUnArchiveThinkers(void) +static void P_NetUnArchiveThinkers(savebuffer_t *save) { thinker_t *currentthinker; thinker_t *next; @@ -2709,7 +2786,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 @@ -2741,7 +2818,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 @@ -2750,148 +2827,158 @@ 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_dynslopeline: + LoadDynamicSlopeThinker(save, (actionf_p1)T_DynamicSlopeLine); + break; + + case tc_dynslopevert: + LoadDynamicSlopeThinker(save, (actionf_p1)T_DynamicSlopeVert); + 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); + restoreNum = true; 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: @@ -2904,17 +2991,27 @@ static void P_NetUnArchiveThinkers(void) if (restoreNum) { executor_t *delay = NULL; + polywaypoint_t *polywp = NULL; UINT32 mobjnum; for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1 != (actionf_p1)T_ExecutorDelay) + if (currentthinker->function.acp1 == (actionf_p1)T_ExecutorDelay) + { + delay = (void *)currentthinker; + if ((mobjnum = (UINT32)(size_t)delay->caller)) + delay->caller = P_FindNewPosition(mobjnum); + } + } + for (currentthinker = thinkercap.next; currentthinker != &thinkercap; + currentthinker = currentthinker->next) + { + if (currentthinker->function.acp1 != (actionf_p1)T_PolyObjWaypoint) continue; - - delay = (void *)currentthinker; - - if ((mobjnum = (UINT32)(size_t)delay->caller)) - delay->caller = P_FindNewPosition(mobjnum); + polywp = (void *)currentthinker; + if (!(mobjnum = (UINT32)(size_t)polywp->target)) + continue; + polywp->target = P_FindNewPosition(mobjnum); } } } @@ -2926,29 +3023,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; @@ -2960,19 +3057,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 @@ -2983,33 +3080,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 @@ -3023,11 +3120,11 @@ static inline void P_FinishMobjs(void) for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - - mobj = (mobj_t *)currentthinker; - mobj->info = &mobjinfo[mobj->type]; + if (currentthinker->function.acp1 == (actionf_p1)P_MobjThinker) + { + mobj = (mobj_t *)currentthinker; + mobj->info = &mobjinfo[mobj->type]; + } } } @@ -3041,69 +3138,69 @@ static void P_RelinkPointers(void) for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1 != (actionf_p1)P_MobjThinker) - continue; + if (currentthinker->function.acp1 == (actionf_p1)P_MobjThinker) + { + mobj = (mobj_t *)currentthinker; - mobj = (mobj_t *)currentthinker; + if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) + continue; - if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) - continue; - - if (mobj->tracer) - { - temp = (UINT32)(size_t)mobj->tracer; - mobj->tracer = NULL; - if (!P_SetTarget(&mobj->tracer, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "tracer not found on %d\n", mobj->type); - } - if (mobj->target) - { - temp = (UINT32)(size_t)mobj->target; - mobj->target = NULL; - if (!P_SetTarget(&mobj->target, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "target not found on %d\n", mobj->type); - } - if (mobj->hnext) - { - temp = (UINT32)(size_t)mobj->hnext; - mobj->hnext = NULL; - if (!P_SetTarget(&mobj->hnext, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "hnext not found on %d\n", mobj->type); - } - if (mobj->hprev) - { - temp = (UINT32)(size_t)mobj->hprev; - mobj->hprev = NULL; - if (!P_SetTarget(&mobj->hprev, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "hprev not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->capsule) - { - temp = (UINT32)(size_t)mobj->player->capsule; - mobj->player->capsule = NULL; - if (!P_SetTarget(&mobj->player->capsule, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "capsule not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->axis1) - { - temp = (UINT32)(size_t)mobj->player->axis1; - mobj->player->axis1 = NULL; - if (!P_SetTarget(&mobj->player->axis1, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "axis1 not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->axis2) - { - temp = (UINT32)(size_t)mobj->player->axis2; - mobj->player->axis2 = NULL; - if (!P_SetTarget(&mobj->player->axis2, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "axis2 not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->awayviewmobj) - { - temp = (UINT32)(size_t)mobj->player->awayviewmobj; - mobj->player->awayviewmobj = NULL; - if (!P_SetTarget(&mobj->player->awayviewmobj, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "awayviewmobj not found on %d\n", mobj->type); + if (mobj->tracer) + { + temp = (UINT32)(size_t)mobj->tracer; + mobj->tracer = NULL; + if (!P_SetTarget(&mobj->tracer, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "tracer not found on %d\n", mobj->type); + } + if (mobj->target) + { + temp = (UINT32)(size_t)mobj->target; + mobj->target = NULL; + if (!P_SetTarget(&mobj->target, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "target not found on %d\n", mobj->type); + } + if (mobj->hnext) + { + temp = (UINT32)(size_t)mobj->hnext; + mobj->hnext = NULL; + if (!P_SetTarget(&mobj->hnext, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "hnext not found on %d\n", mobj->type); + } + if (mobj->hprev) + { + temp = (UINT32)(size_t)mobj->hprev; + mobj->hprev = NULL; + if (!P_SetTarget(&mobj->hprev, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "hprev not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->capsule) + { + temp = (UINT32)(size_t)mobj->player->capsule; + mobj->player->capsule = NULL; + if (!P_SetTarget(&mobj->player->capsule, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "capsule not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->axis1) + { + temp = (UINT32)(size_t)mobj->player->axis1; + mobj->player->axis1 = NULL; + if (!P_SetTarget(&mobj->player->axis1, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "axis1 not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->axis2) + { + temp = (UINT32)(size_t)mobj->player->axis2; + mobj->player->axis2 = NULL; + if (!P_SetTarget(&mobj->player->axis2, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "axis2 not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->awayviewmobj) + { + temp = (UINT32)(size_t)mobj->player->awayviewmobj; + mobj->player->awayviewmobj = NULL; + if (!P_SetTarget(&mobj->player->awayviewmobj, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "awayviewmobj not found on %d\n", mobj->type); + } } } } @@ -3111,11 +3208,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; @@ -3125,56 +3222,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) { @@ -3189,31 +3286,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) { @@ -3233,12 +3330,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)) { @@ -3252,120 +3349,117 @@ 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); - - WRITEINT16(save_p, gamemap); + WRITEUINT32(save->p, gametic); + 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++) + for (i = 0; i < 12; 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 @@ -3377,26 +3471,22 @@ 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)) { @@ -3404,129 +3494,126 @@ 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++) + for (i = 0; i < 12; 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) { for (th = thinkercap.next; th != &thinkercap; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - - mobj = (mobj_t *)th; - - if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) - continue; - - mobj->mobjnum = i++; + if (th->function.acp1 == (actionf_p1)P_MobjThinker) + { + mobj = (mobj_t *)th; + if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) + continue; + mobj->mobjnum = i++; + } } } - P_NetArchivePlayers(resending); + P_NetArchivePlayers(save); if (gamestate == GS_LEVEL) { - P_NetArchiveWorld(); - P_ArchivePolyObjects(); - P_NetArchiveThinkers(); - P_NetArchiveSpecials(); + P_NetArchiveWorld(save); + P_ArchivePolyObjects(save); + P_NetArchiveThinkers(save); + P_NetArchiveSpecials(save); + P_NetArchiveWaypoints(save); } - LUA_Archive(); - WRITEUINT8(save_p, 0x1d); // consistency marker + LUA_Archive(&save->p, 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(); @@ -3534,11 +3621,11 @@ 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) return false; // Only do this after confirming savegame is ok @@ -3548,23 +3635,27 @@ 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); + 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_NetUnArchiveWaypoints(save); P_RelinkPointers(); P_FinishMobjs(); } - LUA_UnArchive(); + LUA_UnArchive(&save->p, true); // This is stupid and hacky, but maybe it'll work! P_SetRandSeed(P_GetInitSeed()); @@ -3575,5 +3666,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 671ba92ac..3ad668cd2 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -997,14 +997,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; @@ -1013,23 +1013,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); } From 539315710c382a63c75e8d6ad6749c0a16454eb3 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 16 Sep 2024 12:18:01 +0200 Subject: [PATCH 02/99] clean up --- src/lua_script.c | 3 +- src/p_saveg.c | 342 ++++++++++++++++------------------------------- 2 files changed, 119 insertions(+), 226 deletions(-) diff --git a/src/lua_script.c b/src/lua_script.c index 5e8b4315f..aec9a3037 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -948,7 +948,7 @@ static UINT8 UnArchiveValue(UINT8 **p, int TABLESINDEX) 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(*p)); @@ -1091,7 +1091,6 @@ static UINT8 UnArchiveValueDemo(UINT8 **p, int TABLESINDEX, char field[1024]) 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: diff --git a/src/p_saveg.c b/src/p_saveg.c index 695ecac76..9e3e8f888 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -106,7 +106,7 @@ static inline void P_UnArchivePlayer(savebuffer_t *save) // // P_NetArchivePlayers // -static void P_NetArchivePlayers(savebuffer_t *save) +static void P_NetArchivePlayers(savebuffer_t *save, boolean resending) { INT32 i, j; UINT16 flags; @@ -116,7 +116,8 @@ static void P_NetArchivePlayers(savebuffer_t *save) for (i = 0; i < MAXPLAYERS; i++) { - WRITESINT8(save->p, (SINT8)adminplayers[i]); + if (resending) + WRITESINT8(save->p, (SINT8)adminplayers[i]); if (!playeringame[i]) continue; @@ -125,7 +126,9 @@ static void P_NetArchivePlayers(savebuffer_t *save) // no longer send ticcmds - WRITESTRINGN(save->p, player_names[i], MAXPLAYERNAME); + if (resending) + 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); @@ -150,8 +153,12 @@ static void P_NetArchivePlayers(savebuffer_t *save) WRITEUINT16(save->p, players[i].flashpal); WRITEUINT16(save->p, players[i].flashcount); - WRITEUINT8(save->p, players[i].skincolor); - WRITEINT32(save->p, players[i].skin); + if (resending) + { + 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); @@ -289,7 +296,7 @@ static void P_NetArchivePlayers(savebuffer_t *save) // // P_NetUnArchivePlayers // -static void P_NetUnArchivePlayers(savebuffer_t *save) +static void P_NetUnArchivePlayers(savebuffer_t *save, boolean resending) { INT32 i, j; UINT16 flags; @@ -299,7 +306,8 @@ static void P_NetUnArchivePlayers(savebuffer_t *save) for (i = 0; i < MAXPLAYERS; i++) { - adminplayers[i] = (INT32)READSINT8(save->p); + if (resending) + adminplayers[i] = (INT32)READSINT8(save->p); // Do NOT memset player struct to 0 // other areas may initialize data elsewhere @@ -309,7 +317,9 @@ static void P_NetUnArchivePlayers(savebuffer_t *save) // NOTE: sending tics should (hopefully) no longer be necessary - READSTRINGN(save->p, player_names[i], MAXPLAYERNAME); + if (resending) + 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); @@ -334,8 +344,12 @@ static void P_NetUnArchivePlayers(savebuffer_t *save) players[i].flashpal = READUINT16(save->p); players[i].flashcount = READUINT16(save->p); - players[i].skincolor = READUINT8(save->p); - players[i].skin = READINT32(save->p); + if (resending) + { + 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 @@ -461,34 +475,6 @@ static void P_NetUnArchivePlayers(savebuffer_t *save) } } -static void P_NetArchiveWaypoints(savebuffer_t *save) -{ - INT32 i, j; - - for (i = 0; i < NUMWAYPOINTSEQUENCES; i++) - { - WRITEUINT16(save->p, numwaypoints[i]); - for (j = 0; j < numwaypoints[i]; j++) - WRITEUINT32(save->p, waypoints[i][j] ? waypoints[i][j]->mobjnum : 0); - } -} - -static void P_NetUnArchiveWaypoints(savebuffer_t *save) -{ - INT32 i, j; - UINT32 mobjnum; - - for (i = 0; i < NUMWAYPOINTSEQUENCES; i++) - { - numwaypoints[i] = READUINT16(save->p); - for (j = 0; j < numwaypoints[i]; j++) - { - mobjnum = READUINT32(save->p); - waypoints[i][j] = (mobjnum == 0) ? NULL : P_FindNewPosition(mobjnum); - } - } -} - /// /// World Archiving /// @@ -1007,8 +993,6 @@ typedef enum tc_noenemies, tc_eachtime, tc_disappear, - tc_dynslopeline, - tc_dynslopevert, tc_polyrotate, // haleyjd 03/26/06: polyobjects tc_polymove, tc_polywaypoint, @@ -1043,11 +1027,6 @@ static inline UINT32 SavePlayer(const player_t *player) return 0xFFFFFFFF; } -static UINT32 SaveSlope(const pslope_t *slope) -{ - if (slope) return (UINT32)(slope->id); - return 0xFFFFFFFF; -} // // SaveMobjThinker @@ -1091,7 +1070,7 @@ static void SaveMobjThinker(savebuffer_t *save, const thinker_t *th, const UINT8 diff2 = 0; // not the default but the most probable - if (mobj->momx != 0 || mobj->momy != 0 || mobj->momz != 0 || mobj->pmomz !=0) + if (mobj->momx != 0 || mobj->momy != 0 || mobj->momz != 0) diff |= MD_MOM; if (mobj->radius != mobj->info->radius) diff |= MD_RADIUS; @@ -1219,7 +1198,6 @@ static void SaveMobjThinker(savebuffer_t *save, const thinker_t *th, const UINT8 WRITEFIXED(save->p, mobj->momx); WRITEFIXED(save->p, mobj->momy); WRITEFIXED(save->p, mobj->momz); - WRITEFIXED(save->p, mobj->pmomz); } if (diff & MD_RADIUS) WRITEFIXED(save->p, mobj->radius); @@ -1579,21 +1557,6 @@ static void SaveDisappearThinker(savebuffer_t *save, const thinker_t *th, const WRITEINT32(save->p, ht->exists); } -/// Save a dynamic slope thinker. -static inline void SaveDynamicSlopeThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) -{ - const dynplanethink_t* ht = (const void*)th; - - WRITEUINT8(save->p, type); - WRITEUINT8(save->p, ht->type); - WRITEUINT32(save->p, SaveSlope(ht->slope)); - WRITEUINT32(save->p, SaveLine(ht->sourceline)); - WRITEFIXED(save->p, ht->extent); - - WRITEMEM(save->p, ht->tags, sizeof(ht->tags)); - WRITEMEM(save->p, ht->vex, sizeof(ht->vex)); -} - // // SavePolyrotateThinker // @@ -1647,7 +1610,6 @@ static void SavePolywaypointThinker(savebuffer_t *save, const thinker_t *th, UIN WRITEFIXED(save->p, ht->diffx); WRITEFIXED(save->p, ht->diffy); WRITEFIXED(save->p, ht->diffz); - WRITEUINT32(save->p, SaveMobjnum(ht->target)); } // @@ -1704,19 +1666,6 @@ static void SavePolydisplaceThinker(savebuffer_t *save, const thinker_t *th, con WRITEFIXED(save->p, ht->oldHeights); } -/* -// -// SaveWhatThinker -// -// Saves a what_t thinker -// -static inline void SaveWhatThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) -{ - const what_t *ht = (const void *)th; - WRITEUINT8(save->p, type); -} -*/ - // // P_NetArchiveThinkers // @@ -1883,16 +1832,6 @@ static void P_NetArchiveThinkers(savebuffer_t *save) SaveDisappearThinker(save, th, tc_disappear); continue; } - else if (th->function.acp1 == (actionf_p1)T_DynamicSlopeLine) - { - SaveDynamicSlopeThinker(save, th, tc_dynslopeline); - continue; - } - else if (th->function.acp1 == (actionf_p1)T_DynamicSlopeVert) - { - SaveDynamicSlopeThinker(save, th, tc_dynslopevert); - continue; - } else if (th->function.acp1 == (actionf_p1)T_PolyObjRotate) { SavePolyrotatetThinker(save, th, tc_polyrotate); @@ -1954,6 +1893,7 @@ mobj_t *P_FindNewPosition(UINT32 oldposition) continue; mobj = (mobj_t *)th; + if (mobj->mobjnum == oldposition) return mobj; } @@ -1985,19 +1925,6 @@ static inline player_t *LoadPlayer(UINT32 player) return &players[player]; } -static inline pslope_t *LoadSlope(UINT32 slopeid) -{ - pslope_t *p = slopelist; - if (slopeid > slopecount) return NULL; - do - { - if (p->id == slopeid) - return p; - } while ((p = p->next)); - return NULL; -} - - // // LoadMobjThinker // @@ -2084,7 +2011,6 @@ static void LoadMobjThinker(savebuffer_t *save, actionf_p1 thinker) mobj->momx = READFIXED(save->p); mobj->momy = READFIXED(save->p); mobj->momz = READFIXED(save->p); - mobj->pmomz = READFIXED(save->p); } // otherwise they're zero, and the memset took care of it if (diff & MD_RADIUS) @@ -2623,23 +2549,6 @@ static inline void LoadDisappearThinker(savebuffer_t *save, actionf_p1 thinker) P_AddThinker(&ht->thinker); } -/// Save a dynamic slope thinker. -static inline void LoadDynamicSlopeThinker(savebuffer_t *save, actionf_p1 thinker) -{ - dynplanethink_t* ht = Z_Malloc(sizeof(*ht), PU_LEVSPEC, NULL); - ht->thinker.function.acp1 = thinker; - - ht->type = READUINT8(save->p); - ht->slope = LoadSlope(READUINT32(save->p)); - ht->sourceline = LoadLine(READUINT32(save->p)); - ht->extent = READFIXED(save->p); - READMEM(save->p, ht->tags, sizeof(ht->tags)); - READMEM(save->p, ht->vex, sizeof(ht->vex)); - - P_AddThinker(&ht->thinker); -} - - // // LoadPolyrotateThinker // @@ -2695,7 +2604,6 @@ static inline void LoadPolywaypointThinker(savebuffer_t *save, actionf_p1 thinke ht->diffx = READFIXED(save->p); ht->diffy = READFIXED(save->p); ht->diffz = READFIXED(save->p); - ht->target = LoadMobj(READUINT32(save->p)); P_AddThinker(&ht->thinker); } @@ -2933,14 +2841,6 @@ static void P_NetUnArchiveThinkers(savebuffer_t *save) LoadDisappearThinker(save, (actionf_p1)T_Disappear); break; - case tc_dynslopeline: - LoadDynamicSlopeThinker(save, (actionf_p1)T_DynamicSlopeLine); - break; - - case tc_dynslopevert: - LoadDynamicSlopeThinker(save, (actionf_p1)T_DynamicSlopeVert); - break; - case tc_polyrotate: LoadPolyrotatetThinker(save, (actionf_p1)T_PolyObjRotate); break; @@ -2991,27 +2891,17 @@ static void P_NetUnArchiveThinkers(savebuffer_t *save) if (restoreNum) { executor_t *delay = NULL; - polywaypoint_t *polywp = NULL; UINT32 mobjnum; for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1 == (actionf_p1)T_ExecutorDelay) - { - delay = (void *)currentthinker; - if ((mobjnum = (UINT32)(size_t)delay->caller)) - delay->caller = P_FindNewPosition(mobjnum); - } - } - for (currentthinker = thinkercap.next; currentthinker != &thinkercap; - currentthinker = currentthinker->next) - { - if (currentthinker->function.acp1 != (actionf_p1)T_PolyObjWaypoint) + if (currentthinker->function.acp1 != (actionf_p1)T_ExecutorDelay) continue; - polywp = (void *)currentthinker; - if (!(mobjnum = (UINT32)(size_t)polywp->target)) - continue; - polywp->target = P_FindNewPosition(mobjnum); + + delay = (void *)currentthinker; + + if ((mobjnum = (UINT32)(size_t)delay->caller)) + delay->caller = P_FindNewPosition(mobjnum); } } } @@ -3120,11 +3010,11 @@ static inline void P_FinishMobjs(void) for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1 == (actionf_p1)P_MobjThinker) - { - mobj = (mobj_t *)currentthinker; - mobj->info = &mobjinfo[mobj->type]; - } + if (currentthinker->function.acp1 != (actionf_p1)P_MobjThinker) + continue; + + mobj = (mobj_t *)currentthinker; + mobj->info = &mobjinfo[mobj->type]; } } @@ -3138,69 +3028,69 @@ static void P_RelinkPointers(void) for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1 == (actionf_p1)P_MobjThinker) + if (currentthinker->function.acp1 != (actionf_p1)P_MobjThinker) + continue; + + mobj = (mobj_t *)currentthinker; + + if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) + continue; + + if (mobj->tracer) { - mobj = (mobj_t *)currentthinker; - - if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) - continue; - - if (mobj->tracer) - { - temp = (UINT32)(size_t)mobj->tracer; - mobj->tracer = NULL; - if (!P_SetTarget(&mobj->tracer, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "tracer not found on %d\n", mobj->type); - } - if (mobj->target) - { - temp = (UINT32)(size_t)mobj->target; - mobj->target = NULL; - if (!P_SetTarget(&mobj->target, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "target not found on %d\n", mobj->type); - } - if (mobj->hnext) - { - temp = (UINT32)(size_t)mobj->hnext; - mobj->hnext = NULL; - if (!P_SetTarget(&mobj->hnext, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "hnext not found on %d\n", mobj->type); - } - if (mobj->hprev) - { - temp = (UINT32)(size_t)mobj->hprev; - mobj->hprev = NULL; - if (!P_SetTarget(&mobj->hprev, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "hprev not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->capsule) - { - temp = (UINT32)(size_t)mobj->player->capsule; - mobj->player->capsule = NULL; - if (!P_SetTarget(&mobj->player->capsule, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "capsule not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->axis1) - { - temp = (UINT32)(size_t)mobj->player->axis1; - mobj->player->axis1 = NULL; - if (!P_SetTarget(&mobj->player->axis1, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "axis1 not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->axis2) - { - temp = (UINT32)(size_t)mobj->player->axis2; - mobj->player->axis2 = NULL; - if (!P_SetTarget(&mobj->player->axis2, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "axis2 not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->awayviewmobj) - { - temp = (UINT32)(size_t)mobj->player->awayviewmobj; - mobj->player->awayviewmobj = NULL; - if (!P_SetTarget(&mobj->player->awayviewmobj, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "awayviewmobj not found on %d\n", mobj->type); - } + temp = (UINT32)(size_t)mobj->tracer; + mobj->tracer = NULL; + if (!P_SetTarget(&mobj->tracer, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "tracer not found on %d\n", mobj->type); + } + if (mobj->target) + { + temp = (UINT32)(size_t)mobj->target; + mobj->target = NULL; + if (!P_SetTarget(&mobj->target, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "target not found on %d\n", mobj->type); + } + if (mobj->hnext) + { + temp = (UINT32)(size_t)mobj->hnext; + mobj->hnext = NULL; + if (!P_SetTarget(&mobj->hnext, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "hnext not found on %d\n", mobj->type); + } + if (mobj->hprev) + { + temp = (UINT32)(size_t)mobj->hprev; + mobj->hprev = NULL; + if (!P_SetTarget(&mobj->hprev, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "hprev not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->capsule) + { + temp = (UINT32)(size_t)mobj->player->capsule; + mobj->player->capsule = NULL; + if (!P_SetTarget(&mobj->player->capsule, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "capsule not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->axis1) + { + temp = (UINT32)(size_t)mobj->player->axis1; + mobj->player->axis1 = NULL; + if (!P_SetTarget(&mobj->player->axis1, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "axis1 not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->axis2) + { + temp = (UINT32)(size_t)mobj->player->axis2; + mobj->player->axis2 = NULL; + if (!P_SetTarget(&mobj->player->axis2, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "axis2 not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->awayviewmobj) + { + temp = (UINT32)(size_t)mobj->player->awayviewmobj; + mobj->player->awayviewmobj = NULL; + if (!P_SetTarget(&mobj->player->awayviewmobj, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "awayviewmobj not found on %d\n", mobj->type); } } } @@ -3380,7 +3270,7 @@ static void P_NetArchiveMisc(savebuffer_t *save, boolean resending) WRITEUINT32(save->p, totalrings); WRITEINT16(save->p, lastmap); - for (i = 0; i < 12; i++) + for (i = 0; i < 4; i++) { WRITEINT16(save->p, votelevels[i][0]); WRITEINT16(save->p, votelevels[i][1]); @@ -3473,7 +3363,8 @@ FUNCINLINE static ATTRINLINE boolean P_NetUnArchiveMisc(savebuffer_t *save, bool G_SetGamestate(READINT16(save->p)); - gametype = READINT16(save->p); + if (reloading) + gametype = READINT16(save->p); pig = READUINT32(save->p); for (i = 0; i < MAXPLAYERS; i++) @@ -3499,7 +3390,7 @@ FUNCINLINE static ATTRINLINE boolean P_NetUnArchiveMisc(savebuffer_t *save, bool totalrings = READUINT32(save->p); lastmap = READINT16(save->p); - for (i = 0; i < 12; i++) + for (i = 0; i < 4; i++) { votelevels[i][0] = READINT16(save->p); votelevels[i][1] = READINT16(save->p); @@ -3589,24 +3480,25 @@ void P_SaveNetGame(savebuffer_t *save, boolean resending) { for (th = thinkercap.next; th != &thinkercap; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_MobjThinker) - { - mobj = (mobj_t *)th; - if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) - continue; - mobj->mobjnum = i++; - } + if (th->function.acp1 != (actionf_p1)P_MobjThinker) + continue; + + mobj = (mobj_t *)th; + + if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) + continue; + + mobj->mobjnum = i++; } } - P_NetArchivePlayers(save); + P_NetArchivePlayers(save, resending); if (gamestate == GS_LEVEL) { P_NetArchiveWorld(save); P_ArchivePolyObjects(save); P_NetArchiveThinkers(save); P_NetArchiveSpecials(save); - P_NetArchiveWaypoints(save); } LUA_Archive(&save->p, true); @@ -3626,7 +3518,10 @@ boolean P_LoadGame(savebuffer_t *save, INT16 mapoverride) // Savegame end marker 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); @@ -3642,7 +3537,7 @@ boolean P_LoadNetGame(savebuffer_t *save, boolean reloading) if (!P_NetUnArchiveMisc(save, reloading)) return false; - P_NetUnArchivePlayers(save); + P_NetUnArchivePlayers(save, reloading); if (gamestate == GS_LEVEL) { @@ -3650,12 +3545,11 @@ boolean P_LoadNetGame(savebuffer_t *save, boolean reloading) P_UnArchivePolyObjects(save); P_NetUnArchiveThinkers(save); P_NetUnArchiveSpecials(save); - P_NetUnArchiveWaypoints(save); P_RelinkPointers(); P_FinishMobjs(); } - LUA_UnArchive(&save->p, true); + LUA_UnArchive(&save->p); // This is stupid and hacky, but maybe it'll work! P_SetRandSeed(P_GetInitSeed()); From 2a3a33226ed0efb37f074a237499bc614e601bb7 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 16 Sep 2024 12:37:25 +0200 Subject: [PATCH 03/99] fixup demo savebuf --- src/d_netcmd.c | 4 +- src/g_game.c | 599 +++++++++++++++++++++++----------------------- src/g_game.h | 3 +- src/lua_hooklib.c | 7 +- src/lua_script.c | 211 +++++++--------- src/lua_script.h | 10 +- src/p_saveg.c | 4 +- 7 files changed, 390 insertions(+), 448 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index d85280f08..8bd240db5 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -5841,7 +5841,7 @@ static void Command_Archivetest_f(void) // test archive CONS_Printf("LUA_Archive...\n"); - LUA_Archive(&save.p, true); + LUA_Archive(&save, true); WRITEUINT8(save.p, 0x7F); wrote = (UINT32)(save.p - save.buffer); @@ -5852,7 +5852,7 @@ static void Command_Archivetest_f(void) // test unarchive save.p = save.buffer; CONS_Printf("LUA_UnArchive...\n"); - LUA_UnArchive(&save.p, true); + LUA_UnArchive(&save, true); i = READUINT8(save.p); if (i != 0x7F || wrote != (UINT32)(save.p - save.buffer)) CONS_Printf("Savegame corrupted. (write %u, read %u)\n", wrote, (UINT32)(save.p - save.buffer)); diff --git a/src/g_game.c b/src/g_game.c index 5f5cce736..c115aa257 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -293,9 +293,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 @@ -509,8 +508,8 @@ static CV_PossibleValue_t driftsparkpulse_t[] = {{0, "MIN"}, {FRACUNIT*3, "MAX"} consvar_t cv_driftsparkpulse = {"driftsparkpulse", "1.4", CV_FLOAT | CV_SAVE, driftsparkpulse_t, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t stretchfactor_t[] = { - {0, "Off"}, {FRACUNIT/8, "0.125"}, {FRACUNIT/4, "0.250"}, - {3*FRACUNIT/8, "0.375"}, {FRACUNIT/2, "0.500"}, {5*FRACUNIT/8, "0.625"}, + {0, "Off"}, {FRACUNIT/8, "0.125"}, {FRACUNIT/4, "0.250"}, + {3*FRACUNIT/8, "0.375"}, {FRACUNIT/2, "0.500"}, {5*FRACUNIT/8, "0.625"}, {3*FRACUNIT/4, "0.750"}, {7*FRACUNIT/8, "0.875"}, {FRACUNIT, "Max"}, {0, NULL}}; consvar_t cv_gravstretch = {"gravstretch", "0", CV_SAVE, stretchfactor_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -978,7 +977,7 @@ static INT32 Joy3Axis(axis_input_e axissel) } if (flp) retaxis = -retaxis; //flip it around return retaxis; - + } else { @@ -998,7 +997,7 @@ static INT32 Joy3Axis(axis_input_e axissel) } if (flp) retaxis = -retaxis; //flip it around return retaxis; - + } } @@ -1073,7 +1072,7 @@ static INT32 Joy4Axis(axis_input_e axissel) } if (flp) retaxis = -retaxis; //flip it around return retaxis; - + } else { @@ -1093,7 +1092,7 @@ static INT32 Joy4Axis(axis_input_e axissel) } if (flp) retaxis = -retaxis; //flip it around return retaxis; - + } } @@ -4732,7 +4731,7 @@ INT32 G_FindMapByNameOrCode(const char *mapname, char **realmapnamep) INT32 newmapnum = -1; size_t mapnamelen = strlen(mapname); char *p; - + if (mapnamelen == 1) { if (mapname[0] == '*') // current map @@ -4934,7 +4933,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)); @@ -4944,11 +4943,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) { @@ -4960,12 +4959,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); @@ -4976,8 +4975,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 { @@ -4990,12 +4989,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: @@ -5040,7 +5039,7 @@ void G_ReadDemoExtraData(void) } - p = READUINT8(demo_p); + p = READUINT8(demobuf.p); } while (p != DW_END) @@ -5050,7 +5049,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); @@ -5061,10 +5060,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(); @@ -5081,8 +5080,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) @@ -5090,40 +5089,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); } } @@ -5143,36 +5142,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); @@ -5184,7 +5183,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(); @@ -5197,55 +5196,55 @@ 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; } @@ -5327,8 +5326,7 @@ 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; } +#define CHECKSPACE(num) if (demobuf.p+(num) > demoend) {G_CheckDemoStatus(); return; } INT32 i, counter = leveltime; for (i = 0; i < MAXPLAYERS; i++) @@ -5346,12 +5344,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 } @@ -5364,10 +5362,9 @@ 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; } +#define CHECKSPACE(num) if (demobuf.p+(num) > demoend) {G_CheckDemoStatus(); return; } - if (!demo_p) + if (!demobuf.p) return; if (!(demoflags & DF_GHOST)) return; // No ghost data to write. @@ -5379,7 +5376,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) @@ -5395,9 +5392,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 { @@ -5414,8 +5411,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) @@ -5425,7 +5422,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 @@ -5448,7 +5445,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. @@ -5460,7 +5457,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 @@ -5495,37 +5492,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; @@ -5534,15 +5531,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; } @@ -5551,7 +5548,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; @@ -5561,15 +5558,15 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) void G_ConsAllGhostTics(void) { - UINT8 p = READUINT8(demo_p); + 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(); @@ -5587,7 +5584,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. @@ -5595,32 +5592,32 @@ 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++; + demobuf.p++; if(ziptic & GZT_NIGHTS) { if (!testmo || !testmo->player || !(testmo->player->pflags & PF_NIGHTSMODE) || !testmo->tracer) nightsfail = true; @@ -5630,14 +5627,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; @@ -5649,13 +5646,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) @@ -5677,12 +5674,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); } } @@ -5742,7 +5739,7 @@ void G_ConsGhostTic(INT32 playernum) } } - if (*demo_p == DEMOMARKER) + if (*demobuf.p == DEMOMARKER) { // end of demo data stream G_CheckDemoStatus(); @@ -6155,7 +6152,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; @@ -6303,10 +6300,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) @@ -6318,9 +6315,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 @@ -6334,15 +6331,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; } @@ -6362,7 +6359,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; } @@ -6375,16 +6372,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) @@ -6398,7 +6395,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; @@ -6412,11 +6409,11 @@ void G_RecordDemo(const char *name) { INT32 maxsize; - demo_p = NULL; + demobuf.p = NULL; demo.recording = false; - if (demobuffer) - free(demobuffer); - demobuffer = NULL; + if (demobuf.buffer) + free(demobuf.buffer); + demobuf.buffer = NULL; demoend = NULL; if (cv_recordmultiplayerdemos.value) @@ -6428,10 +6425,10 @@ void G_RecordDemo(const char *name) maxsize = cv_maxdemosize.value*1024*1024; - demobuffer = malloc(maxsize); - demoend = demobuffer + maxsize; + demobuf.buffer = malloc(maxsize); + demoend = demobuf.buffer + maxsize; - if (demobuffer) + if (demobuf.buffer) demo.recording = true; else CONS_Alert(CONS_ERROR, "Failed to allocate demo buffer\n"); @@ -6442,14 +6439,14 @@ void G_RecordMetal(void) { INT32 maxsize; maxsize = cv_maxdemosize.value*1024*1024; - if (demobuffer) - free(demobuffer); - demo_p = NULL; + if (demobuf.buffer) + free(demobuf.buffer); + demobuf.p = NULL; metalrecording = false; - demobuffer = malloc(maxsize); - demoend = demobuffer + maxsize; + demobuf.buffer = malloc(maxsize); + demoend = demobuf.buffer + maxsize; - if (demobuffer) + if (demobuf.buffer) metalrecording = true; else CONS_Alert(CONS_ERROR, "Failed to allocate demo buffer\n"); @@ -6465,11 +6462,11 @@ void G_BeginRecording(void) UINT8 totalfiles; UINT8 *m; - if (demo_p) + if (demobuf.p) 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++; } @@ -6526,63 +6523,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_Archive(&demo_p, false); + LUA_Archive(&demobuf.p, false); memset(&oldcmd,0,sizeof(oldcmd)); memset(&oldghost,0,sizeof(oldghost)); @@ -6611,21 +6608,21 @@ void G_BeginMetal(void) { mobj_t *mo = players[consoleplayer].mo; - if (demo_p) + if (demobuf.p) 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)); @@ -6641,33 +6638,33 @@ void G_WriteStanding(UINT8 ranking, char *name, INT32 skinnum, UINT8 color, UINT 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_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) @@ -7233,7 +7230,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 @@ -7252,7 +7249,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); @@ -7260,7 +7257,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) @@ -7273,7 +7270,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 @@ -7283,29 +7280,29 @@ 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); M_StartMessage(msg, NULL, MM_NOTHING); Z_Free(pdemoname); - Z_Free(demobuffer); - demobuffer = NULL; + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; demo.playback = false; demo.title = false; 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 @@ -7318,30 +7315,30 @@ void G_DoPlayDemo(char *defdemoname) CONS_Alert(CONS_ERROR, "%s", msg); M_StartMessage(msg, NULL, MM_NOTHING); Z_Free(pdemoname); - Z_Free(demobuffer); - demobuffer = NULL; + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; demo.playback = false; demo.title = false; 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); M_StartMessage(msg, NULL, MM_NOTHING); Z_Free(pdemoname); - Z_Free(demobuffer); - demobuffer = NULL; + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; demo.playback = false; demo.title = false; 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) { @@ -7351,8 +7348,8 @@ void G_DoPlayDemo(char *defdemoname) CONS_Alert(CONS_ERROR, "%s", msg); M_StartMessage(msg, NULL, MM_NOTHING); Z_Free(pdemoname); - Z_Free(demobuffer); - demobuffer = NULL; + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; demo.playback = false; demo.title = false; return; @@ -7361,17 +7358,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) { @@ -7412,8 +7409,8 @@ void G_DoPlayDemo(char *defdemoname) if (!CON_Ready()) // In the console they'll just see the notice there! No point pulling them out. M_StartMessage(msg, NULL, MM_NOTHING); Z_Free(pdemoname); - Z_Free(demobuffer); - demobuffer = NULL; + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; demo.playback = false; demo.title = false; return; @@ -7435,8 +7432,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; @@ -7444,33 +7441,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)) @@ -7479,8 +7476,8 @@ void G_DoPlayDemo(char *defdemoname) CONS_Alert(CONS_ERROR, "%s", msg); M_StartMessage(msg, NULL, MM_NOTHING); Z_Free(pdemoname); - Z_Free(demobuffer); - demobuffer = NULL; + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; demo.playback = false; demo.title = false; return; @@ -7493,8 +7490,8 @@ void G_DoPlayDemo(char *defdemoname) CONS_Alert(CONS_ERROR, "%s", msg); M_StartMessage(msg, NULL, MM_NOTHING); Z_Free(pdemoname); - Z_Free(demobuffer); - demobuffer = NULL; + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; demo.playback = false; demo.title = false; return; @@ -7509,17 +7506,17 @@ 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); M_StartMessage(msg, NULL, MM_NOTHING); Z_Free(pdemoname); - Z_Free(demobuffer); - demobuffer = NULL; + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; demo.playback = false; demo.title = false; return; @@ -7553,17 +7550,17 @@ 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); M_StartMessage(msg, NULL, MM_NOTHING); Z_Free(pdemoname); - Z_Free(demobuffer); - demobuffer = NULL; + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; demo.playback = false; demo.title = false; return; @@ -7598,7 +7595,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; @@ -7617,8 +7614,8 @@ void G_DoPlayDemo(char *defdemoname) CONS_Alert(CONS_ERROR, "%s", msg); M_StartMessage(msg, NULL, MM_NOTHING); Z_Free(pdemoname); - Z_Free(demobuffer); - demobuffer = NULL; + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; demo.playback = false; demo.title = false; return; @@ -7632,8 +7629,8 @@ void G_DoPlayDemo(char *defdemoname) CONS_Alert(CONS_ERROR, "%s", msg); M_StartMessage(msg, NULL, MM_NOTHING); Z_Free(pdemoname); - Z_Free(demobuffer); - demobuffer = NULL; + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; demo.playback = false; demo.title = false; return; @@ -7646,17 +7643,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 { @@ -7665,28 +7662,28 @@ 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) -// so this is where we are to read our lua variables (if possible!) + // end of player read (the 0xFF marker) + // so this is where we are to read our lua variables (if possible!) if (demoflags & DF_LUAVARS) // again, used for compability, lua shit will be saved to replays regardless of if it's even been loaded { if (!gL) // No Lua state! ...I guess we'll just start one... LUA_ClearState(); // No modeattacking check, DF_LUAVARS won't be present here. - LUA_UnArchiveDemo(&demo_p); + LUA_UnArchive(&demobuf.p, false); } splitscreen = 0; @@ -8267,22 +8264,22 @@ void G_StopMetalDemo(void) ATTRNORETURN void FUNCNORETURN G_StopMetalRecording(void) { boolean saved = false; - if (demo_p) + if (demobuf.p) { - 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. } - free(demobuffer); - demobuffer = NULL; + free(demobuf.buffer); + demobuf.buffer = NULL; metalrecording = false; if (saved) I_Error("Saved to %sMS.LMP", G_BuildMapName(gamemap)); @@ -8293,13 +8290,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; - if (demo.playback) - { - CV_SetValue(&cv_director, directorstate); - directorstate = 0; - } + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; demo.playback = false; if (demo.title) modeattacking = false; @@ -8391,6 +8383,7 @@ boolean G_CheckDemoStatus(void) G_SaveDemo(); return true; } + demo.recording = false; return false; @@ -8398,7 +8391,7 @@ boolean G_CheckDemoStatus(void) void G_SaveDemo(void) { - UINT8 *p = demobuffer+16; // after version + UINT8 *p = demobuf.buffer+16; // after version UINT32 length; #ifdef NOMD5 UINT8 i; @@ -8407,10 +8400,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; @@ -8461,14 +8454,14 @@ 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; - free(demobuffer); - demobuffer = NULL; + free(demobuf.buffer); + demobuf.buffer = NULL; demo.recording = false; if (modeattacking != ATTACKING_RECORD) @@ -8537,7 +8530,6 @@ boolean G_DemoTitleResponder(event_t *ev) void G_SetGamestate(gamestate_t newstate) { gamestate = newstate; - #ifdef HAVE_DISCORDRPC DRPC_UpdatePresence(); #endif @@ -8610,4 +8602,3 @@ INT32 G_TicsToMilliseconds(tic_t tics) { return (INT32)((tics%TICRATE) * (1000.00f/TICRATE)); } - diff --git a/src/g_game.h b/src/g_game.h index 14decd858..7fbf98a8c 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" extern char gamedatafilename[64]; extern char timeattackfolder[64]; @@ -32,7 +33,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/lua_hooklib.c b/src/lua_hooklib.c index 1aadea9a3..442c12f88 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -1480,7 +1480,7 @@ boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source) return hooked; } -void LUAh_NetArchiveHook(lua_CFunction archFunc) +void LUAh_NetArchiveHook(lua_CFunction archFunc, savebuffer_t *save) { hook_p hookp; int errorhandlerindex; @@ -1501,8 +1501,9 @@ void LUAh_NetArchiveHook(lua_CFunction archFunc) // tables becomes an upvalue of archFunc lua_pushvalue(gL, -3); - lua_pushcclosure(gL, archFunc, 1); - // stack: tables, archFunc + lua_pushlightuserdata(gL, save); + lua_pushcclosure(gL, archFunc, 2); + // stack: tables, savebuffer_t, archFunc for (hookp = roothook; hookp; hookp = hookp->next) { diff --git a/src/lua_script.c b/src/lua_script.c index aec9a3037..2440be7ab 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -40,8 +40,6 @@ static lua_State *mL = NULL; int hook_defrosting; -static UINT8 **lua_save_p = NULL; // FIXME: Remove this horrible hack - // List of internal libraries to load from SRB2 static lua_CFunction liblist[] = { LUA_EnumLib, // global metatable for enums @@ -889,9 +887,10 @@ static void ArchiveExtVars(UINT8 **p, void *pointer, const char *ptype) static int NetArchive(lua_State *L) { int TABLESINDEX = lua_upvalueindex(1); + savebuffer_t *save = lua_touserdata(L, lua_upvalueindex(2)); int i, n = lua_gettop(L); for (i = 1; i <= n; i++) - ArchiveValue(lua_save_p, TABLESINDEX, i); + ArchiveValue(&save->p, TABLESINDEX, i); return n; } @@ -1126,7 +1125,7 @@ static UINT8 UnArchiveValueDemo(UINT8 **p, int TABLESINDEX, char field[1024]) return 0; } -static void UnArchiveExtVars(UINT8 **p, void *pointer) +static void UnArchiveExtVars(UINT8 **p, void *pointer, boolean isdemo) { int TABLESINDEX; UINT16 field_count = READUINT16(*p); @@ -1145,40 +1144,23 @@ static void UnArchiveExtVars(UINT8 **p, 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 (isdemo) { - READSTRING(*p, field); - UnArchiveValue(p, TABLESINDEX); - lua_setfield(gL, -2, field); + 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); - 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(UINT8 **p, void *pointer) -{ - int TABLESINDEX; - UINT16 field_count = READUINT16(*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++) + else { - READSTRING(*p, field); - if (UnArchiveValueDemo(p, TABLESINDEX, field) != 3) // This will return 3 if we shouldn't set this field. + for (i = 0; i < field_count; i++) + { + READSTRING(*p, field); + UnArchiveValue(p, TABLESINDEX); lua_setfield(gL, -2, field); + } } lua_getfield(gL, LUA_REGISTRYINDEX, LREG_EXTVARS); @@ -1192,13 +1174,14 @@ static void UnArchiveExtVarsDemo(UINT8 **p, void *pointer) static int NetUnArchive(lua_State *L) { int TABLESINDEX = lua_upvalueindex(1); + savebuffer_t *save = lua_touserdata(L, lua_upvalueindex(2)); int i, n = lua_gettop(L); for (i = 1; i <= n; i++) - UnArchiveValue(lua_save_p, TABLESINDEX); + UnArchiveValue(&save->p, TABLESINDEX); return n; } -static void UnArchiveTables(UINT8 **p) +static void UnArchiveTables(UINT8 **p, boolean isdemo) { int TABLESINDEX; UINT16 i, n; @@ -1209,67 +1192,60 @@ static void UnArchiveTables(UINT8 **p) TABLESINDEX = lua_gettop(gL); n = (UINT16)lua_objlen(gL, TABLESINDEX); - for (i = 1; i <= n; i++) + if (isdemo) { - lua_rawgeti(gL, TABLESINDEX, i); - while (true) + for (i = 1; i <= n; i++) { - if (UnArchiveValue(p, TABLESINDEX) == 1) // read key - break; - if (UnArchiveValue(p, TABLESINDEX) == 2) // read value - n++; - if (lua_isnil(gL, -2)) // if key is nil (if a function etc was accidentally saved) + lua_rawgeti(gL, TABLESINDEX, i); + while (true) { - 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 + UINT8 ret; + + ret = UnArchiveValueDemo(p, TABLESINDEX, NULL); + if (ret == 3) + lua_pushnil(gL); + else if (ret == 1) // read key + break; + + 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) + { + 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); } - else - lua_rawset(gL, -3); + lua_pop(gL, 1); } - lua_pop(gL, 1); } -} - -static void UnArchiveTablesDemo(UINT8 **p) -{ - int TABLESINDEX; - UINT16 i, n; - - if (!gL) - return; - - TABLESINDEX = lua_gettop(gL); - - n = (UINT16)lua_objlen(gL, TABLESINDEX); - for (i = 1; i <= n; i++) + else { - lua_rawgeti(gL, TABLESINDEX, i); - while (true) + for (i = 1; i <= n; i++) { - UINT8 ret; - - ret = UnArchiveValueDemo(p, TABLESINDEX, NULL); - if (ret == 3) - lua_pushnil(gL); - else if (ret == 1) // read key - break; - - 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) + lua_rawgeti(gL, TABLESINDEX, i); + while (true) { - 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 + if (UnArchiveValue(p, TABLESINDEX) == 1) // read key + break; + if (UnArchiveValue(p, TABLESINDEX) == 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); } - else - lua_rawset(gL, -3); + lua_pop(gL, 1); } - lua_pop(gL, 1); } } @@ -1281,7 +1257,7 @@ void LUA_Step(void) lua_gc(gL, LUA_GCSTEP, 1); } -void LUA_Archive(UINT8 **p, boolean network) +void LUA_Archive(savebuffer_t *save, boolean network) { INT32 i; thinker_t *th; @@ -1294,7 +1270,7 @@ void LUA_Archive(UINT8 **p, boolean network) if (!playeringame[i] && i > 0) // NEVER skip player 0, this is for dedi servs. continue; // all players in game will be archived, even if they just add a 0. - ArchiveExtVars(p, &players[i], "player"); + ArchiveExtVars(&save->p, &players[i], "player"); } if (network == true) @@ -1308,22 +1284,21 @@ void LUA_Archive(UINT8 **p, boolean network) // archive function will determine when to skip mobjs, // and write mobjnum in otherwise. - ArchiveExtVars(p, th, "mobj"); + ArchiveExtVars(&save->p, &players[i], "player"); } } - WRITEUINT32(*p, UINT32_MAX); // end of mobjs marker, replaces mobjnum. + WRITEUINT32(save->p, UINT32_MAX); // end of mobjs marker, replaces mobjnum. - lua_save_p = p; - LUAh_NetArchiveHook(NetArchive); // call the NetArchive hook in archive mode + LUAh_NetArchiveHook(NetArchive, save); // call the NetArchive hook in archive mode } - ArchiveTables(p); + ArchiveTables(&save->p); if (gL) lua_pop(gL, 1); // pop tables } -void LUA_UnArchive(UINT8 **p) +void LUA_UnArchive(savebuffer_t *save, boolean network) { UINT32 mobjnum; INT32 i; @@ -1336,47 +1311,23 @@ void LUA_UnArchive(UINT8 **p) { if (!playeringame[i] && i > 0) // same here, this is to synch dediservs properly. continue; - UnArchiveExtVars(p, &players[i]); + UnArchiveExtVars(&save->p, &players[i], !network); } - do { - mobjnum = READUINT32(*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(p, th); // apply variables - } - } while(mobjnum != UINT32_MAX); // repeat until end of mobjs marker. - - lua_save_p = p; - LUAh_NetArchiveHook(NetUnArchive); // call the NetArchive hook in unarchive mode - UnArchiveTables(p); - - if (gL) - lua_pop(gL, 1); // pop tables -} - -// this time make sure we read from demo_p -void LUA_UnArchiveDemo(UINT8 **p) -{ - INT32 i; - - if (gL) - lua_newtable(gL); // tables to be read - - for (i = 0; i < MAXPLAYERS; i++) + if (network == true) { - if (!playeringame[i] && i > 0) // same here, this is to synch dediservs properly. - continue; - UnArchiveExtVarsDemo(p, &players[i]); + 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 + && ((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. + + LUAh_NetArchiveHook(NetUnArchive, save); // call the NetArchive hook in unarchive mode } - UnArchiveTablesDemo(p); + 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 7039603a5..f0b77e80e 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,14 @@ void LUA_InvalidateLevel(void); void LUA_InvalidateMapthings(void); void LUA_InvalidatePlayer(player_t *player); void LUA_Step(void); -void LUA_Archive(UINT8 **p, boolean network); -void LUA_UnArchive(UINT8 **p); - -// keeping this around since demos are kinda ass -void LUA_UnArchiveDemo(UINT8 **p); +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 LUAh_NetArchiveHook(lua_CFunction archFunc); +void LUAh_NetArchiveHook(lua_CFunction archFunc, savebuffer_t *save); // Console wrapper void COM_Lua_f(void); diff --git a/src/p_saveg.c b/src/p_saveg.c index 9e3e8f888..50247a852 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3501,7 +3501,7 @@ void P_SaveNetGame(savebuffer_t *save, boolean resending) P_NetArchiveSpecials(save); } - LUA_Archive(&save->p, true); + LUA_Archive(save, true); WRITEUINT8(save->p, 0x1d); // consistency marker } @@ -3549,7 +3549,7 @@ boolean P_LoadNetGame(savebuffer_t *save, boolean reloading) P_FinishMobjs(); } - LUA_UnArchive(&save->p); + LUA_UnArchive(save); // This is stupid and hacky, but maybe it'll work! P_SetRandSeed(P_GetInitSeed()); From ee2d934525d78ab135e0b1644e59a68199095f07 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 16 Sep 2024 12:40:03 +0200 Subject: [PATCH 04/99] rest smol fixes --- src/g_game.c | 9 +++++++-- src/p_saveg.c | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index c115aa257..0cf3393e2 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -6579,7 +6579,7 @@ void G_BeginRecording(void) // player lua vars, always saved even if empty... Unless it's record attack. if (demoflags & DF_LUAVARS) - LUA_Archive(&demobuf.p, false); + LUA_Archive(&demobuf, false); memset(&oldcmd,0,sizeof(oldcmd)); memset(&oldghost,0,sizeof(oldghost)); @@ -7683,7 +7683,7 @@ void G_DoPlayDemo(char *defdemoname) LUA_ClearState(); // No modeattacking check, DF_LUAVARS won't be present here. - LUA_UnArchive(&demobuf.p, false); + LUA_UnArchive(&demobuf, false); } splitscreen = 0; @@ -8292,6 +8292,11 @@ void G_StopDemo(void) { Z_Free(demobuf.buffer); demobuf.buffer = NULL; + if (demo.playback) + { + CV_SetValue(&cv_director, directorstate); + directorstate = 0; + } demo.playback = false; if (demo.title) modeattacking = false; diff --git a/src/p_saveg.c b/src/p_saveg.c index 50247a852..cf3d9d3e3 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3549,7 +3549,7 @@ boolean P_LoadNetGame(savebuffer_t *save, boolean reloading) P_FinishMobjs(); } - LUA_UnArchive(save); + LUA_UnArchive(save, true); // This is stupid and hacky, but maybe it'll work! P_SetRandSeed(P_GetInitSeed()); From e88702e10ceb1e774073988e394dd036be32e629 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 16 Sep 2024 12:53:02 +0200 Subject: [PATCH 05/99] fix demo checkspace --- src/g_game.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 0cf3393e2..8c61084ce 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -5326,7 +5326,8 @@ void G_GhostAddHit(INT32 playernum, mobj_t *victim) void G_WriteAllGhostTics(void) { -#define CHECKSPACE(num) if (demobuf.p+(num) > demoend) {G_CheckDemoStatus(); 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++) @@ -5362,7 +5363,8 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) UINT8 sprite; UINT8 frame; -#define CHECKSPACE(num) if (demobuf.p+(num) > demoend) {G_CheckDemoStatus(); return; } + UINT8 *save_demo_p = demobuf.p; +#define CHECKSPACE(num) if (demobuf.p+(num) > demoend) { demobuf.p = save_demo_p; G_CheckDemoStatus(); return; } if (!demobuf.p) return; From 065572ef64525d140e79cb0a7e7f25f9e87980a8 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 16 Sep 2024 12:56:09 +0200 Subject: [PATCH 06/99] more fixup --- src/p_saveg.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index cf3d9d3e3..e3a1f1f6d 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1259,7 +1259,7 @@ static void SaveMobjThinker(savebuffer_t *save, const thinker_t *th, const UINT8 if (diff2 & MD2_CVMEM) WRITEINT32(save->p, mobj->cvmem); if (diff2 & MD2_SKIN) - WRITEUINT16(save->p, (UINT16)((skin_t *)mobj->skin - skins)); + WRITEUINT8(save->p, (UINT8)((skin_t *)mobj->skin - skins)); if (diff2 & MD2_COLOR) WRITEUINT8(save->p, mobj->color); if (diff2 & MD2_EXTVAL1) @@ -1868,7 +1868,7 @@ static void P_NetArchiveThinkers(savebuffer_t *save) continue; } #ifdef PARANOIA - else if (th->function.acv != P_RemoveThinkerDelayed) // wait garbage collection + else if (th->function.acp1 != P_RemoveThinkerDelayed) // wait garbage collection I_Error("unknown thinker type %p", th->function.acp1); #endif } @@ -2120,7 +2120,7 @@ static void LoadMobjThinker(savebuffer_t *save, actionf_p1 thinker) if (diff2 & MD2_CVMEM) mobj->cvmem = READINT32(save->p); if (diff2 & MD2_SKIN) - mobj->skin = &skins[READUINT16(save->p)]; + mobj->skin = &skins[READUINT8(save->p)]; if (diff2 & MD2_COLOR) mobj->color = READUINT8(save->p); if (diff2 & MD2_EXTVAL1) @@ -2669,19 +2669,6 @@ static inline void LoadPolydisplaceThinker(savebuffer_t *save, actionf_p1 thinke P_AddThinker(&ht->thinker); } -/* -// -// LoadWhatThinker -// -// load a what_t thinker -// -static inline void LoadWhatThinker(savebuffer_t *save, actionf_p1 thinker) -{ - what_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); - ht->thinker.function.acp1 = thinker; -} -*/ - // // P_NetUnArchiveThinkers // @@ -2851,7 +2838,6 @@ static void P_NetUnArchiveThinkers(savebuffer_t *save) case tc_polywaypoint: LoadPolywaypointThinker(save, (actionf_p1)T_PolyObjWaypoint); - restoreNum = true; break; case tc_polyslidedoor: @@ -3248,13 +3234,16 @@ static void P_NetArchiveMisc(savebuffer_t *save, boolean resending) if (resending) WRITEUINT32(save->p, gametic); + WRITEINT16(save->p, gamemap); + if (gamestate != GS_LEVEL) WRITEINT16(save->p, GS_WAITINGPLAYERS); // nice hack to put people back into waitingplayers else WRITEINT16(save->p, gamestate); - WRITEINT16(save->p, gametype); + if (resending) + WRITEINT16(save->p, gametype); for (i = 0; i < MAXPLAYERS; i++) pig |= (playeringame[i] != 0)< Date: Mon, 16 Sep 2024 13:20:44 +0200 Subject: [PATCH 07/99] Contain end & size into savebuffer_t --- src/d_clisrv.c | 31 +++++++++++++++++++------------ src/d_clisrv.h | 3 ++- src/d_netcmd.c | 4 +++- src/g_game.c | 46 ++++++++++++++++++++++------------------------ src/p_saveg.h | 8 ++++++++ 5 files changed, 54 insertions(+), 38 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 474d3f19a..86aaeb3e3 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1788,8 +1788,6 @@ static boolean SV_SendServerConfig(INT32 node) } #ifdef JOININGAME -#define SAVEGAMESIZE (768*1024) - static void SV_SendSaveGame(INT32 node, boolean resending) { size_t length, compressedlen; @@ -1798,7 +1796,8 @@ static void SV_SendSaveGame(INT32 node, boolean resending) UINT8 *buffertosend; // first save it in a malloced buffer - save.buffer = (UINT8 *)malloc(SAVEGAMESIZE); + save.size = NETSAVEGAMESIZE; + save.buffer = (UINT8 *)malloc(save.size); if (!save.buffer) { CONS_Alert(CONS_ERROR, M_GetText("No more free memory for savegame\n")); @@ -1807,14 +1806,14 @@ static void SV_SendSaveGame(INT32 node, boolean resending) // Leave room for the uncompressed length. save.p = save.buffer + sizeof(UINT32); + save.end = save.buffer + save.size; P_SaveNetGame(&save, resending); length = save.p - save.buffer; - if (length > SAVEGAMESIZE) + if (length > NETSAVEGAMESIZE) { free(save.buffer); - save.p = NULL; I_Error("Savegame buffer overrun"); } @@ -1831,7 +1830,6 @@ static void SV_SendSaveGame(INT32 node, boolean resending) if ((compressedlen = lzf_compress(save.buffer + sizeof(UINT32), length - sizeof(UINT32), compressedsave + sizeof(UINT32), length - sizeof(UINT32) - 1))) { // Compressing succeeded; send compressed data - free(save.buffer); // State that we're compressed. @@ -1842,7 +1840,6 @@ static void SV_SendSaveGame(INT32 node, boolean resending) else { // Compression failed to make it smaller; send original - free(compressedsave); // State that we're not compressed @@ -1851,7 +1848,6 @@ static void SV_SendSaveGame(INT32 node, boolean resending) } SV_SendRam(node, buffertosend, length, SF_RAM, 0); - save.p = NULL; // Remember when we started sending the savegame so we can handle timeouts sendingsavegame[node] = true; @@ -1874,7 +1870,8 @@ static void SV_SavedGame(void) sprintf(tmpsave, "%s" PATHSEP TMPSAVENAME, srb2home); // first save it in a malloced buffer - save.p = save.buffer = (UINT8 *)malloc(SAVEGAMESIZE); + save.size = NETSAVEGAMESIZE; + save.p = save.buffer = (UINT8 *)malloc(save.size); if (!save.p) { CONS_Alert(CONS_ERROR, M_GetText("No more free memory for savegame\n")); @@ -1883,13 +1880,14 @@ static void SV_SavedGame(void) return; } + save.end = save.buffer + save.size; + P_SaveNetGame(&save); length = save.p - save.buffer; - if (length > SAVEGAMESIZE) + if (length > NETSAVEGAMESIZE) { free(save.buffer); - save.p = NULL; I_Error("Savegame buffer overrun"); } @@ -1898,7 +1896,6 @@ static void SV_SavedGame(void) CONS_Printf(M_GetText("Didn't save %s for netgame"), tmpsave); free(save.buffer); - save.p = NULL; } #undef TMPSAVENAME @@ -1923,6 +1920,8 @@ static void CL_LoadReceivedSavegame(boolean reloading) } save.p = save.buffer; + save.size = length; + save.end = save.buffer + save.size; // Decompress saved game if necessary. decompressedlen = READUINT32(save.p); @@ -1930,9 +1929,13 @@ static void CL_LoadReceivedSavegame(boolean reloading) if (decompressedlen > 0) { UINT8 *decompressedbuffer = Z_Malloc(decompressedlen, PU_STATIC, NULL); + lzf_decompress(save.p, length - sizeof(UINT32), decompressedbuffer, decompressedlen); Z_Free(save.buffer); + save.p = save.buffer = decompressedbuffer; + save.size = decompressedlen; + save.end = save.buffer + decompressedlen; } paused = false; @@ -6856,6 +6859,8 @@ rewind_t *CL_SaveRewindPoint(size_t demopos) return NULL; save.buffer = save.p = rewind->savebuffer; + save.size = NETSAVEGAMESIZE; + save.end = save.buffer + save.size; P_SaveNetGame(&save, false); rewind->leveltime = leveltime; @@ -6882,6 +6887,8 @@ rewind_t *CL_RewindToTime(tic_t time) return NULL; save.buffer = save.p = rewindhead->savebuffer; + save.size = NETSAVEGAMESIZE; + save.end = save.buffer + save.size; P_LoadNetGame(&save, false); wipegamestate = gamestate; // No fading back in! diff --git a/src/d_clisrv.h b/src/d_clisrv.h index cc123b1d2..feb2965f1 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -19,6 +19,7 @@ #include "tables.h" #include "d_player.h" #include "mserv.h" +#include "p_saveg.h" // NETSAVEGAMESIZE /* The 'packet version' is used to distinguish packet formats. @@ -659,7 +660,7 @@ extern UINT8 hu_redownloadinggamestate; extern UINT8 hu_stopped; // kart, true when the game is stopped for players due to a disconnecting or connecting player typedef struct rewind_s { - UINT8 savebuffer[(768*1024)]; + UINT8 savebuffer[NETSAVEGAMESIZE]; tic_t leveltime; size_t demopos; diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 8bd240db5..334feffde 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -5837,7 +5837,9 @@ static void Command_Archivetest_f(void) ((mobj_t *)th)->mobjnum = i++; // allocate buffer - save.buffer = save.p = ZZ_Alloc(1024); + save.size = 1024; + save.buffer = save.p = ZZ_Alloc(save.size); + save.end = save.buffer + save.size; // test archive CONS_Printf("LUA_Archive...\n"); diff --git a/src/g_game.c b/src/g_game.c index 8c61084ce..c4e2d8077 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -71,9 +71,6 @@ JoyType_t Joystick2; JoyType_t Joystick3; JoyType_t Joystick4; -// 1024 bytes is plenty for a savegame -#define SAVEGAMESIZE (1024) - // SRB2kart char gamedatafilename[64] = "kartdata.dat"; char timeattackfolder[64] = "kart"; @@ -295,7 +292,6 @@ UINT32 timesBeatenWithEmeralds; static char demoname[128]; savebuffer_t demobuf; static UINT8 *demotime_p, *demoinfo_p; -static UINT8 *demoend; static UINT8 demoflags; static boolean demosynced = true; // console warning message @@ -4053,12 +4049,14 @@ void G_SaveGameData(boolean force) if (!gamedataloaded) return; // If never loaded (-nodata), don't save - save.p = save.buffer = (UINT8 *)malloc(GAMEDATASIZE); + save.size = length; + save.p = save.buffer = (UINT8 *)malloc(save.size); if (!save.p) { CONS_Alert(CONS_ERROR, M_GetText("No more free memory for saving game data\n")); return; } + save.end = save.buffer + save.size; if (majormods && !force) { @@ -4136,7 +4134,6 @@ void G_SaveGameData(boolean force) FIL_WriteFile(va(pandf, srb2home, gamedatafilename), save.buffer, length); free(save.buffer); - save.p = save.buffer = NULL; } #define VERSIONSIZE 16 @@ -4226,6 +4223,8 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) } save.p = save.buffer; + save.size = length; + save.end = save.buffer + save.size; memset(vcheck, 0, sizeof (vcheck)); sprintf(vcheck, "version %d", VERSION); @@ -4240,7 +4239,6 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) M_StartMessage(M_GetText("Save game from different version\n\nPress ESC\n"), NULL, MM_NOTHING); Command_ExitGame_f(); Z_Free(save.buffer); - save.p = save.buffer = NULL; // no cheating! memset(&savedata, 0, sizeof(savedata)); @@ -4252,9 +4250,6 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) if (demo.playback) // reset game engine G_StopDemo(); -// paused = false; -// automapactive = false; - // dearchive all the modifications if (!P_LoadGame(&save, mapoverride)) { @@ -4271,7 +4266,6 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) // done Z_Free(save.buffer); - save.p = save.buffer = NULL; displayplayers[0] = consoleplayer; multiplayer = false; @@ -4308,12 +4302,14 @@ void G_SaveGame(UINT32 savegameslot) char name[VERSIONSIZE]; size_t length; - save.p = save.buffer = (UINT8 *)malloc(SAVEGAMESIZE); + save.size = SAVEGAMESIZE; + save.p = save.buffer = (UINT8 *)malloc(save.size); if (!save.p) { CONS_Alert(CONS_ERROR, M_GetText("No more free memory for saving game data\n")); return; } + save.end = save.buffer + save.size; memset(name, 0, sizeof (name)); sprintf(name, "version %d", VERSION); @@ -4324,7 +4320,6 @@ void G_SaveGame(UINT32 savegameslot) length = save.p - save.buffer; saved = FIL_WriteFile(backup, save.buffer, length); free(save.buffer); - save.p = save.buffer = NULL; } gameaction = ga_nothing; @@ -4825,7 +4820,7 @@ INT32 G_FindMapByNameOrCode(const char *mapname, char **realmapnamep) #define ZT_AIMING 0x10 #define ZT_DRIFT 0x20 #define ZT_LATENCY 0x40 -#define DEMOMARKER 0x80 // demoend +#define DEMOMARKER 0x80 // demobuf.end UINT8 demo_extradata[MAXPLAYERS]; UINT8 demo_writerng; // 0=no, 1=yes, 2=yes but on a timeout @@ -5253,7 +5248,7 @@ void G_WriteDemoTiccmd(ticcmd_t *cmd, INT32 playernum) // attention here for the ticcmd size! // latest demos with mouse aiming byte in ticcmd - if (!(demoflags & DF_GHOST) && ziptic_p > demoend - 9) + if (!(demoflags & DF_GHOST) && ziptic_p > demobuf.end - 9) { G_CheckDemoStatus(); // no more space return; @@ -5327,7 +5322,7 @@ void G_GhostAddHit(INT32 playernum, mobj_t *victim) void G_WriteAllGhostTics(void) { UINT8 *save_demo_p = demobuf.p; -#define CHECKSPACE(num) if (demobuf.p+(num) > demoend) { demobuf.p = save_demo_p; G_CheckDemoStatus(); return; } +#define CHECKSPACE(num) if (demobuf.p+(num) > demobuf.end) { demobuf.p = save_demo_p; G_CheckDemoStatus(); return; } INT32 i, counter = leveltime; for (i = 0; i < MAXPLAYERS; i++) @@ -5364,7 +5359,7 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) UINT8 frame; UINT8 *save_demo_p = demobuf.p; -#define CHECKSPACE(num) if (demobuf.p+(num) > demoend) { demobuf.p = save_demo_p; G_CheckDemoStatus(); return; } +#define CHECKSPACE(num) if (demobuf.p+(num) > demobuf.end) { demobuf.p = save_demo_p; G_CheckDemoStatus(); return; } if (!demobuf.p) return; @@ -5550,7 +5545,7 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) // attention here for the ticcmd size! // latest demos with mouse aiming byte in ticcmd - if (demobuf.p >= demoend - (13 + 9)) + if (demobuf.p >= demobuf.end - (13 + 9)) { G_CheckDemoStatus(); // no more space return; @@ -6397,7 +6392,7 @@ void G_WriteMetalTic(mobj_t *metal) // attention here for the ticcmd size! // latest demos with mouse aiming byte in ticcmd - if (demobuf.p >= demoend - 32) + if (demobuf.p >= demobuf.end - 32) { G_StopMetalRecording(); // no more space return; @@ -6411,12 +6406,13 @@ void G_RecordDemo(const char *name) { INT32 maxsize; + demobuf.size = 0; demobuf.p = NULL; demo.recording = false; if (demobuf.buffer) free(demobuf.buffer); demobuf.buffer = NULL; - demoend = NULL; + demobuf.end = NULL; if (cv_recordmultiplayerdemos.value) { @@ -6427,8 +6423,9 @@ void G_RecordDemo(const char *name) maxsize = cv_maxdemosize.value*1024*1024; - demobuf.buffer = malloc(maxsize); - demoend = demobuf.buffer + maxsize; + demobuf.size = maxsize; + demobuf.buffer = (UINT8 *)malloc(maxsize); + demobuf.end = demobuf.buffer + demobuf.size; if (demobuf.buffer) demo.recording = true; @@ -6443,10 +6440,11 @@ void G_RecordMetal(void) maxsize = cv_maxdemosize.value*1024*1024; if (demobuf.buffer) free(demobuf.buffer); + demobuf.size = maxsize; + demobuf.buffer = (UINT8 *)malloc(maxsize); demobuf.p = NULL; metalrecording = false; - demobuf.buffer = malloc(maxsize); - demoend = demobuf.buffer + maxsize; + demobuf.end = demobuf.buffer + demobuf.size; if (demobuf.buffer) metalrecording = true; diff --git a/src/p_saveg.h b/src/p_saveg.h index 9a0e26c39..c8b83d004 100644 --- a/src/p_saveg.h +++ b/src/p_saveg.h @@ -18,6 +18,12 @@ #pragma interface #endif +// 1024 bytes is plenty for a savegame +#define SAVEGAMESIZE (1024) + +// For netgames +#define NETSAVEGAMESIZE (768*1024) + // Persistent storage/archiving. // These are the load / save game routines. @@ -39,6 +45,8 @@ typedef struct { UINT8 *buffer; UINT8 *p; + UINT8 *end; + size_t size; } savebuffer_t; // Persistent storage/archiving. From 42eb8d1af5fc84aced6b1be72726c45e78afd646 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 16 Sep 2024 13:36:13 +0200 Subject: [PATCH 08/99] Only save demo if demobuf.p is ready --- src/g_game.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/g_game.c b/src/g_game.c index c4e2d8077..bf0934f00 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -8385,7 +8385,10 @@ boolean G_CheckDemoStatus(void) if (demo.recording && (modeattacking || demo.savemode != DSM_NOTSAVING)) { - G_SaveDemo(); + if (demobuf.p) + { + G_SaveDemo(); + } return true; } From 8bc081d937b641bac7687b9f921cec804c3850c4 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 16 Sep 2024 13:36:53 +0200 Subject: [PATCH 09/99] Use Zone memory functions for sending compressed saves --- src/d_clisrv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 86aaeb3e3..1205d275f 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1819,7 +1819,7 @@ static void SV_SendSaveGame(INT32 node, boolean resending) // 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")); @@ -1840,14 +1840,14 @@ 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 = save.buffer; WRITEUINT32(save.buffer, 0); } - SV_SendRam(node, buffertosend, length, SF_RAM, 0); + SV_SendRam(node, buffertosend, length, SF_Z_RAM, 0); // Remember when we started sending the savegame so we can handle timeouts sendingsavegame[node] = true; From 0d999d7a70f90f4c8c8f078449ed85186814977c Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 16 Sep 2024 17:17:19 +0200 Subject: [PATCH 10/99] Revert "Contain end & size into savebuffer_t" This reverts commit 1a810bc92349f3ff289f7a4fa292d9ddb415b363. --- src/d_clisrv.c | 30 +++++++++++------------------- src/d_clisrv.h | 3 +-- src/d_netcmd.c | 4 +--- src/g_game.c | 46 ++++++++++++++++++++++++---------------------- src/p_saveg.h | 8 -------- 5 files changed, 37 insertions(+), 54 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 1205d275f..0446c3bf1 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1788,6 +1788,8 @@ static boolean SV_SendServerConfig(INT32 node) } #ifdef JOININGAME +#define SAVEGAMESIZE (768*1024) + static void SV_SendSaveGame(INT32 node, boolean resending) { size_t length, compressedlen; @@ -1796,8 +1798,7 @@ static void SV_SendSaveGame(INT32 node, boolean resending) UINT8 *buffertosend; // first save it in a malloced buffer - save.size = NETSAVEGAMESIZE; - save.buffer = (UINT8 *)malloc(save.size); + save.buffer = (UINT8 *)malloc(SAVEGAMESIZE); if (!save.buffer) { CONS_Alert(CONS_ERROR, M_GetText("No more free memory for savegame\n")); @@ -1806,14 +1807,14 @@ static void SV_SendSaveGame(INT32 node, boolean resending) // Leave room for the uncompressed length. save.p = save.buffer + sizeof(UINT32); - save.end = save.buffer + save.size; P_SaveNetGame(&save, resending); length = save.p - save.buffer; - if (length > NETSAVEGAMESIZE) + if (length > SAVEGAMESIZE) { free(save.buffer); + save.p = NULL; I_Error("Savegame buffer overrun"); } @@ -1830,6 +1831,7 @@ static void SV_SendSaveGame(INT32 node, boolean resending) if ((compressedlen = lzf_compress(save.buffer + sizeof(UINT32), length - sizeof(UINT32), compressedsave + sizeof(UINT32), length - sizeof(UINT32) - 1))) { // Compressing succeeded; send compressed data + free(save.buffer); // State that we're compressed. @@ -1848,6 +1850,7 @@ static void SV_SendSaveGame(INT32 node, boolean resending) } 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; @@ -1870,8 +1873,7 @@ static void SV_SavedGame(void) sprintf(tmpsave, "%s" PATHSEP TMPSAVENAME, srb2home); // first save it in a malloced buffer - save.size = NETSAVEGAMESIZE; - save.p = save.buffer = (UINT8 *)malloc(save.size); + save.p = save.buffer = (UINT8 *)malloc(SAVEGAMESIZE); if (!save.p) { CONS_Alert(CONS_ERROR, M_GetText("No more free memory for savegame\n")); @@ -1880,14 +1882,13 @@ static void SV_SavedGame(void) return; } - save.end = save.buffer + save.size; - P_SaveNetGame(&save); length = save.p - save.buffer; - if (length > NETSAVEGAMESIZE) + if (length > SAVEGAMESIZE) { free(save.buffer); + save.p = NULL; I_Error("Savegame buffer overrun"); } @@ -1896,6 +1897,7 @@ static void SV_SavedGame(void) CONS_Printf(M_GetText("Didn't save %s for netgame"), tmpsave); free(save.buffer); + save.p = NULL; } #undef TMPSAVENAME @@ -1920,8 +1922,6 @@ static void CL_LoadReceivedSavegame(boolean reloading) } save.p = save.buffer; - save.size = length; - save.end = save.buffer + save.size; // Decompress saved game if necessary. decompressedlen = READUINT32(save.p); @@ -1929,13 +1929,9 @@ static void CL_LoadReceivedSavegame(boolean reloading) if (decompressedlen > 0) { UINT8 *decompressedbuffer = Z_Malloc(decompressedlen, PU_STATIC, NULL); - lzf_decompress(save.p, length - sizeof(UINT32), decompressedbuffer, decompressedlen); Z_Free(save.buffer); - save.p = save.buffer = decompressedbuffer; - save.size = decompressedlen; - save.end = save.buffer + decompressedlen; } paused = false; @@ -6859,8 +6855,6 @@ rewind_t *CL_SaveRewindPoint(size_t demopos) return NULL; save.buffer = save.p = rewind->savebuffer; - save.size = NETSAVEGAMESIZE; - save.end = save.buffer + save.size; P_SaveNetGame(&save, false); rewind->leveltime = leveltime; @@ -6887,8 +6881,6 @@ rewind_t *CL_RewindToTime(tic_t time) return NULL; save.buffer = save.p = rewindhead->savebuffer; - save.size = NETSAVEGAMESIZE; - save.end = save.buffer + save.size; P_LoadNetGame(&save, false); wipegamestate = gamestate; // No fading back in! diff --git a/src/d_clisrv.h b/src/d_clisrv.h index feb2965f1..cc123b1d2 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -19,7 +19,6 @@ #include "tables.h" #include "d_player.h" #include "mserv.h" -#include "p_saveg.h" // NETSAVEGAMESIZE /* The 'packet version' is used to distinguish packet formats. @@ -660,7 +659,7 @@ extern UINT8 hu_redownloadinggamestate; extern UINT8 hu_stopped; // kart, true when the game is stopped for players due to a disconnecting or connecting player typedef struct rewind_s { - UINT8 savebuffer[NETSAVEGAMESIZE]; + UINT8 savebuffer[(768*1024)]; tic_t leveltime; size_t demopos; diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 334feffde..8bd240db5 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -5837,9 +5837,7 @@ static void Command_Archivetest_f(void) ((mobj_t *)th)->mobjnum = i++; // allocate buffer - save.size = 1024; - save.buffer = save.p = ZZ_Alloc(save.size); - save.end = save.buffer + save.size; + save.buffer = save.p = ZZ_Alloc(1024); // test archive CONS_Printf("LUA_Archive...\n"); diff --git a/src/g_game.c b/src/g_game.c index bf0934f00..282556d87 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -71,6 +71,9 @@ JoyType_t Joystick2; JoyType_t Joystick3; JoyType_t Joystick4; +// 1024 bytes is plenty for a savegame +#define SAVEGAMESIZE (1024) + // SRB2kart char gamedatafilename[64] = "kartdata.dat"; char timeattackfolder[64] = "kart"; @@ -292,6 +295,7 @@ UINT32 timesBeatenWithEmeralds; static char demoname[128]; savebuffer_t demobuf; static UINT8 *demotime_p, *demoinfo_p; +static UINT8 *demoend; static UINT8 demoflags; static boolean demosynced = true; // console warning message @@ -4049,14 +4053,12 @@ void G_SaveGameData(boolean force) if (!gamedataloaded) return; // If never loaded (-nodata), don't save - save.size = length; - save.p = save.buffer = (UINT8 *)malloc(save.size); + 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; } - save.end = save.buffer + save.size; if (majormods && !force) { @@ -4134,6 +4136,7 @@ void G_SaveGameData(boolean force) FIL_WriteFile(va(pandf, srb2home, gamedatafilename), save.buffer, length); free(save.buffer); + save.p = save.buffer = NULL; } #define VERSIONSIZE 16 @@ -4223,8 +4226,6 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) } save.p = save.buffer; - save.size = length; - save.end = save.buffer + save.size; memset(vcheck, 0, sizeof (vcheck)); sprintf(vcheck, "version %d", VERSION); @@ -4239,6 +4240,7 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) M_StartMessage(M_GetText("Save game from different version\n\nPress ESC\n"), NULL, MM_NOTHING); Command_ExitGame_f(); Z_Free(save.buffer); + save.p = save.buffer = NULL; // no cheating! memset(&savedata, 0, sizeof(savedata)); @@ -4250,6 +4252,9 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) if (demo.playback) // reset game engine G_StopDemo(); +// paused = false; +// automapactive = false; + // dearchive all the modifications if (!P_LoadGame(&save, mapoverride)) { @@ -4266,6 +4271,7 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) // done Z_Free(save.buffer); + save.p = save.buffer = NULL; displayplayers[0] = consoleplayer; multiplayer = false; @@ -4302,14 +4308,12 @@ void G_SaveGame(UINT32 savegameslot) char name[VERSIONSIZE]; size_t length; - save.size = SAVEGAMESIZE; - save.p = save.buffer = (UINT8 *)malloc(save.size); + 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; } - save.end = save.buffer + save.size; memset(name, 0, sizeof (name)); sprintf(name, "version %d", VERSION); @@ -4320,6 +4324,7 @@ void G_SaveGame(UINT32 savegameslot) length = save.p - save.buffer; saved = FIL_WriteFile(backup, save.buffer, length); free(save.buffer); + save.p = save.buffer = NULL; } gameaction = ga_nothing; @@ -4820,7 +4825,7 @@ INT32 G_FindMapByNameOrCode(const char *mapname, char **realmapnamep) #define ZT_AIMING 0x10 #define ZT_DRIFT 0x20 #define ZT_LATENCY 0x40 -#define DEMOMARKER 0x80 // demobuf.end +#define DEMOMARKER 0x80 // demoend UINT8 demo_extradata[MAXPLAYERS]; UINT8 demo_writerng; // 0=no, 1=yes, 2=yes but on a timeout @@ -5248,7 +5253,7 @@ void G_WriteDemoTiccmd(ticcmd_t *cmd, INT32 playernum) // attention here for the ticcmd size! // latest demos with mouse aiming byte in ticcmd - if (!(demoflags & DF_GHOST) && ziptic_p > demobuf.end - 9) + if (!(demoflags & DF_GHOST) && ziptic_p > demoend - 9) { G_CheckDemoStatus(); // no more space return; @@ -5322,7 +5327,7 @@ void G_GhostAddHit(INT32 playernum, mobj_t *victim) void G_WriteAllGhostTics(void) { UINT8 *save_demo_p = demobuf.p; -#define CHECKSPACE(num) if (demobuf.p+(num) > demobuf.end) { demobuf.p = save_demo_p; G_CheckDemoStatus(); return; } +#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++) @@ -5359,7 +5364,7 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) UINT8 frame; UINT8 *save_demo_p = demobuf.p; -#define CHECKSPACE(num) if (demobuf.p+(num) > demobuf.end) { demobuf.p = save_demo_p; G_CheckDemoStatus(); return; } +#define CHECKSPACE(num) if (demobuf.p+(num) > demoend) { demobuf.p = save_demo_p; G_CheckDemoStatus(); return; } if (!demobuf.p) return; @@ -5545,7 +5550,7 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) // attention here for the ticcmd size! // latest demos with mouse aiming byte in ticcmd - if (demobuf.p >= demobuf.end - (13 + 9)) + if (demobuf.p >= demoend - (13 + 9)) { G_CheckDemoStatus(); // no more space return; @@ -6392,7 +6397,7 @@ void G_WriteMetalTic(mobj_t *metal) // attention here for the ticcmd size! // latest demos with mouse aiming byte in ticcmd - if (demobuf.p >= demobuf.end - 32) + if (demobuf.p >= demoend - 32) { G_StopMetalRecording(); // no more space return; @@ -6406,13 +6411,12 @@ void G_RecordDemo(const char *name) { INT32 maxsize; - demobuf.size = 0; demobuf.p = NULL; demo.recording = false; if (demobuf.buffer) free(demobuf.buffer); demobuf.buffer = NULL; - demobuf.end = NULL; + demoend = NULL; if (cv_recordmultiplayerdemos.value) { @@ -6423,9 +6427,8 @@ void G_RecordDemo(const char *name) maxsize = cv_maxdemosize.value*1024*1024; - demobuf.size = maxsize; - demobuf.buffer = (UINT8 *)malloc(maxsize); - demobuf.end = demobuf.buffer + demobuf.size; + demobuf.buffer = malloc(maxsize); + demoend = demobuf.buffer + maxsize; if (demobuf.buffer) demo.recording = true; @@ -6440,11 +6443,10 @@ void G_RecordMetal(void) maxsize = cv_maxdemosize.value*1024*1024; if (demobuf.buffer) free(demobuf.buffer); - demobuf.size = maxsize; - demobuf.buffer = (UINT8 *)malloc(maxsize); demobuf.p = NULL; metalrecording = false; - demobuf.end = demobuf.buffer + demobuf.size; + demobuf.buffer = malloc(maxsize); + demoend = demobuf.buffer + maxsize; if (demobuf.buffer) metalrecording = true; diff --git a/src/p_saveg.h b/src/p_saveg.h index c8b83d004..9a0e26c39 100644 --- a/src/p_saveg.h +++ b/src/p_saveg.h @@ -18,12 +18,6 @@ #pragma interface #endif -// 1024 bytes is plenty for a savegame -#define SAVEGAMESIZE (1024) - -// For netgames -#define NETSAVEGAMESIZE (768*1024) - // Persistent storage/archiving. // These are the load / save game routines. @@ -45,8 +39,6 @@ typedef struct { UINT8 *buffer; UINT8 *p; - UINT8 *end; - size_t size; } savebuffer_t; // Persistent storage/archiving. From 3f1c8db362e0d8cd83649af08f444075ce3254c3 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 16 Sep 2024 17:33:17 +0200 Subject: [PATCH 11/99] some stuff i forgor --- src/lua_script.c | 77 ++++++++++++++++++++++++++---------------------- src/p_saveg.c | 8 ++--- 2 files changed, 46 insertions(+), 39 deletions(-) diff --git a/src/lua_script.c b/src/lua_script.c index 2440be7ab..43553f381 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1125,7 +1125,7 @@ static UINT8 UnArchiveValueDemo(UINT8 **p, int TABLESINDEX, char field[1024]) return 0; } -static void UnArchiveExtVars(UINT8 **p, void *pointer, boolean isdemo) +static void UnArchiveExtVars(UINT8 **p, void *pointer, boolean network) { int TABLESINDEX; UINT16 field_count = READUINT16(*p); @@ -1144,13 +1144,13 @@ static void UnArchiveExtVars(UINT8 **p, void *pointer, boolean isdemo) TABLESINDEX = lua_gettop(gL); lua_createtable(gL, 0, field_count); // pointer's ext vars subtable - if (isdemo) + if (network) { 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); + UnArchiveValue(p, TABLESINDEX); + lua_setfield(gL, -2, field); } } else @@ -1158,8 +1158,8 @@ static void UnArchiveExtVars(UINT8 **p, void *pointer, boolean isdemo) for (i = 0; i < field_count; i++) { READSTRING(*p, field); - UnArchiveValue(p, TABLESINDEX); - lua_setfield(gL, -2, field); + if (UnArchiveValueDemo(p, TABLESINDEX, field) != 3) // This will return 3 if we shouldn't set this field. + lua_setfield(gL, -2, field); } } @@ -1181,7 +1181,7 @@ static int NetUnArchive(lua_State *L) return n; } -static void UnArchiveTables(UINT8 **p, boolean isdemo) +static void UnArchiveTables(UINT8 **p, boolean network) { int TABLESINDEX; UINT16 i, n; @@ -1192,7 +1192,30 @@ static void UnArchiveTables(UINT8 **p, boolean isdemo) TABLESINDEX = lua_gettop(gL); n = (UINT16)lua_objlen(gL, TABLESINDEX); - if (isdemo) + + if (network) + { + for (i = 1; i <= n; i++) + { + lua_rawgeti(gL, TABLESINDEX, i); + while (true) + { + if (UnArchiveValue(p, TABLESINDEX) == 1) // read key + break; + if (UnArchiveValue(p, TABLESINDEX) == 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); + } + } + else { for (i = 1; i <= n; i++) { @@ -1225,28 +1248,7 @@ static void UnArchiveTables(UINT8 **p, boolean isdemo) lua_pop(gL, 1); } } - else - { - for (i = 1; i <= n; i++) - { - lua_rawgeti(gL, TABLESINDEX, i); - while (true) - { - if (UnArchiveValue(p, TABLESINDEX) == 1) // read key - break; - if (UnArchiveValue(p, TABLESINDEX) == 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); - } - } + } void LUA_Step(void) @@ -1311,7 +1313,8 @@ void LUA_UnArchive(savebuffer_t *save, boolean network) { if (!playeringame[i] && i > 0) // same here, this is to synch dediservs properly. continue; - UnArchiveExtVars(&save->p, &players[i], !network); + + UnArchiveExtVars(&save->p, &players[i], network); } if (network == true) @@ -1319,15 +1322,19 @@ void LUA_UnArchive(savebuffer_t *save, boolean 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 - && ((mobj_t *)th)->mobjnum == mobjnum) // find matching mobj - UnArchiveExtVars(&save->p, th, !network); // apply variables + { + 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. LUAh_NetArchiveHook(NetUnArchive, save); // call the NetArchive hook in unarchive mode } - UnArchiveTables(&save->p, !network); + UnArchiveTables(&save->p, network); if (gL) lua_pop(gL, 1); // pop tables diff --git a/src/p_saveg.c b/src/p_saveg.c index e3a1f1f6d..e7f447762 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -67,7 +67,7 @@ static inline void P_ArchivePlayer(savebuffer_t *save) pllives = 3; // has less than that. WRITEUINT8(save->p, player->skincolor); - WRITEUINT16(save->p, player->skin); + WRITEUINT8(save->p, player->skin); WRITEUINT32(save->p, player->score); WRITEINT32(save->p, pllives); @@ -75,7 +75,7 @@ static inline void P_ArchivePlayer(savebuffer_t *save) if (botskin) { - WRITEUINT16(save->p, botskin); + WRITEUINT8(save->p, botskin); WRITEUINT8(save->p, botcolor); } } @@ -86,7 +86,7 @@ static inline void P_ArchivePlayer(savebuffer_t *save) static inline void P_UnArchivePlayer(savebuffer_t *save) { savedata.skincolor = READUINT8(save->p); - savedata.skin = READUINT16(save->p); + savedata.skin = READUINT8(save->p); savedata.score = READINT32(save->p); savedata.lives = READINT32(save->p); @@ -94,7 +94,7 @@ static inline void P_UnArchivePlayer(savebuffer_t *save) if (savedata.botcolor) { - savedata.botskin = READUINT16(save->p); + savedata.botskin = READUINT8(save->p); if (savedata.botskin-1 >= numskins) savedata.botskin = 0; savedata.botcolor = READUINT8(save->p); From 8cfc8a549292dcd7e24ea8d49e097e86387fecd1 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 16 Sep 2024 17:52:10 +0200 Subject: [PATCH 12/99] "player" --- src/lua_script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua_script.c b/src/lua_script.c index 43553f381..af6312428 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1286,7 +1286,7 @@ void LUA_Archive(savebuffer_t *save, boolean network) // archive function will determine when to skip mobjs, // and write mobjnum in otherwise. - ArchiveExtVars(&save->p, &players[i], "player"); + ArchiveExtVars(&save->p, &players[i], "mobj"); } } WRITEUINT32(save->p, UINT32_MAX); // end of mobjs marker, replaces mobjnum. From 3aa55ee9c398228b86ed35621a1af4e3bb929678 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 16 Sep 2024 18:12:46 +0200 Subject: [PATCH 13/99] dont need this --- src/d_clisrv.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 0446c3bf1..f1ace4aa1 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1877,8 +1877,6 @@ static void SV_SavedGame(void) if (!save.p) { CONS_Alert(CONS_ERROR, M_GetText("No more free memory for savegame\n")); - free(save.buffer); - save.p = NULL; return; } From 7493b3d2abb9a0125dab7235598064e023c9fe36 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Sep 2024 22:10:57 +0200 Subject: [PATCH 14/99] Revert "clean up leveload a bit" This reverts commit c14af4a136a5a56f2bc3bb4343ecb559f5aeb6a7. --- src/p_setup.c | 306 +++++++++++++++++++++++++------------------------- 1 file changed, 152 insertions(+), 154 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index b2fe2116a..501914564 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -578,7 +578,6 @@ FUNCINLINE static ATTRINLINE void P_LoadRawSubsectors(void *data) size_t numlevelflats; levelflat_t *levelflats; -levelflat_t *foundflats; //SoM: Other files want this info. size_t P_PrecacheLevelFlats(void) @@ -704,9 +703,18 @@ static void P_LoadRawSectors(UINT8 *data) { mapsector_t *ms = (mapsector_t *)data; sector_t *ss = sectors; + levelflat_t *foundflats; size_t i; + // Allocate a big chunk of memory as big as our MAXLEVELFLATS limit. + //Fab : FIXME: allocate for whatever number of flats - 512 different flats per level should be plenty + foundflats = calloc(MAXLEVELFLATS, sizeof (*foundflats)); + if (foundflats == NULL) + I_Error("Ran out of memory while loading sectors\n"); + + numlevelflats = 0; + // For each counted sector, copy the sector raw data from our cache pointer ms, to the global table pointer ss. for (i = 0; i < numsectors; i++, ss++, ms++) { @@ -767,6 +775,16 @@ static void P_LoadRawSectors(UINT8 *data) ss->floorspeed = 0; ss->ceilspeed = 0; } + + // set the sky flat num + skyflatnum = P_AddLevelFlat(SKYFLATNAME, foundflats); + + // copy table for global usage + levelflats = M_Memcpy(Z_Calloc(numlevelflats * sizeof (*levelflats), PU_LEVEL, NULL), foundflats, numlevelflats * sizeof (levelflat_t)); + free(foundflats); + + // search for animated flats and set up + P_SetupLevelFlatAnims(); } // @@ -1451,6 +1469,7 @@ static void P_LoadRawSideDefs2(void *data) break; } } + R_ClearTextureNumCache(true); } static boolean LineInBlock(fixed_t cx1, fixed_t cy1, fixed_t cx2, fixed_t cy2, fixed_t bx1, fixed_t by1) @@ -1967,32 +1986,12 @@ static void P_LoadMapData(const virtres_t* virt) lines = Z_Calloc(numlines * sizeof (*lines), PU_LEVEL, NULL); mapthings = Z_Calloc(nummapthings * sizeof (*mapthings), PU_LEVEL, NULL); - // Allocate a big chunk of memory as big as our MAXLEVELFLATS limit. - //Fab : FIXME: allocate for whatever number of flats - 512 different flats per level should be plenty - foundflats = calloc(MAXLEVELFLATS, sizeof (*foundflats)); - if (foundflats == NULL) - I_Error("Ran out of memory while loading sectors\n"); - numlevelflats = 0; - // Strict map data P_LoadRawVertexes(virtvertexes->data); P_LoadRawSectors(virtsectors->data); P_LoadRawLineDefs(virtlinedefs->data); P_SetupLines(); P_LoadRawSideDefs2(virtsidedefs->data); - P_PrepareRawThings(virtthings->data); - - R_ClearTextureNumCache(true); - - // set the sky flat num - skyflatnum = P_AddLevelFlat(SKYFLATNAME, foundflats); - - // copy table for global usage - levelflats = M_Memcpy(Z_Calloc(numlevelflats * sizeof (*levelflats), PU_LEVEL, NULL), foundflats, numlevelflats * sizeof (levelflat_t)); - free(foundflats); - - // search for animated flats and set up - P_SetupLevelFlatAnims(); } /** Sets up a sky texture to use for the level. @@ -2243,6 +2242,16 @@ static void P_LoadMapFromFile(void) P_PrepareRawThings(vres_Find(curmapvirt, "THINGS")->data); P_MakeMapMD5(curmapvirt, &mapmd5); + + // We do the following silly + // construction because vres_Free + // no-sells deletions of pointers + // that are == curmapvirt. + { + virtres_t *temp = curmapvirt; + curmapvirt = NULL; + vres_Free(temp); + } } static void P_RunLevelScript(const char *scriptname) @@ -2478,129 +2487,6 @@ static boolean P_CanSave(void) return false; // SRB2Kart: no SP, no saving. } -static void P_InitGametype(void) -{ - INT32 i; - - for (i = 0; i < MAXPLAYERS; i++) - if (playeringame[i]) - { - players[i].pflags &= ~PF_NIGHTSMODE; - - // Start players with pity shields if possible - players[i].pity = -1; - - if (!G_RaceGametype()) - { - players[i].mo = NULL; - G_DoReborn(i); - } - else // gametype is GT_COOP or GT_RACE - { - players[i].mo = NULL; - - if (players[i].starposttime) - { - G_SpawnPlayer(i, true); - } - else - G_SpawnPlayer(i, false); - } - } - - if (modeattacking == ATTACKING_RECORD && !demo.playback) - P_LoadRecordGhosts(); - - if (G_TagGametype()) - { - INT32 realnumplayers = 0; - INT32 playersactive[MAXPLAYERS]; - - //I just realized how problematic this code can be. - //D_NumPlayers() will not always cover the scope of the netgame. - //What if one player is node 0 and the other node 31? - //The solution? Make a temp array of all players that are currently playing and pick from them. - //Future todo? When a player leaves, shift all nodes down so D_NumPlayers() can be used as intended? - //Also, you'd never have to loop through all 32 players slots to find anything ever again. - for (i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i] && !players[i].spectator) - { - playersactive[realnumplayers] = i; //stores the player's node in the array. - realnumplayers++; - } - } - - if (realnumplayers) //this should also fix the dedicated crash bug. You only pick a player if one exists to be picked. - { - i = P_RandomKey(realnumplayers); - players[playersactive[i]].pflags |= PF_TAGIT; //choose our initial tagger before map starts. - - // Taken and modified from G_DoReborn() - // Remove the player so he can respawn elsewhere. - // first dissasociate the corpse - if (players[playersactive[i]].mo) - P_RemoveMobj(players[playersactive[i]].mo); - - G_SpawnPlayer(playersactive[i], false); //respawn the lucky player in his dedicated spawn location. - } - else - CONS_Printf(M_GetText("No player currently available to become IT. Awaiting available players.\n")); - - } - else if (G_RaceGametype() && server) - CV_StealthSetValue(&cv_numlaps, - ((netgame || multiplayer) && cv_basenumlaps.value - && (!(mapheaderinfo[gamemap - 1]->levelflags & LF_SECTIONRACE) - || (mapheaderinfo[gamemap - 1]->numlaps > cv_basenumlaps.value))) - ? cv_basenumlaps.value - : 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()) { - static char buf[256]; - sprintf(buf, "replay"PATHSEP"online"PATHSEP"%d-%s", (int) (time(NULL)), G_BuildMapName(gamemap)); - - I_mkdir(va("%s"PATHSEP"replay", srb2home), 0755); - I_mkdir(va("%s"PATHSEP"replay"PATHSEP"online", srb2home), 0755); - G_RecordDemo(buf); - if (dedicated) - G_BeginRecording(); //this has to move here, since dedicated servers dont run got_mapcmd - } - - wantedcalcdelay = wantedfrequency*2; - indirectitemcooldown = 0; - hyubgone = 0; - mapreset = 0; - nospectategrief = 0; - thwompsactive = false; - spbplace = -1; - - startedInFreePlay = false; - { - UINT8 nump = 0; - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i] || players[i].spectator) - { - continue; - } - - nump++; - if (nump == 2) - { - break; - } - } - - if (nump <= 1) - { - startedInFreePlay = true; - } - } -} - struct minimapinfo minimapinfo; static void P_InitMinimapInfo(void) { @@ -2936,19 +2822,131 @@ boolean P_SetupLevel(boolean skipprecip, boolean reloadinggamestate) // none of this needs to be done because it's not the beginning of the map when // a netgame save is being loaded, and could actively be harmful by messing with // the client's view of the data.) - if (!fromnetsave) - P_InitGametype(); + if (fromnetsave) + goto netgameskip; + // ========== - // Now safe to free. - // We do the following silly - // construction because vres_Free - // no-sells deletions of pointers - // that are == curmapvirt. + for (i = 0; i < MAXPLAYERS; i++) + if (playeringame[i]) + { + players[i].pflags &= ~PF_NIGHTSMODE; + + // Start players with pity shields if possible + players[i].pity = -1; + + if (!G_RaceGametype()) + { + players[i].mo = NULL; + G_DoReborn(i); + } + else // gametype is GT_COOP or GT_RACE + { + players[i].mo = NULL; + + if (players[i].starposttime) + { + G_SpawnPlayer(i, true); + } + else + G_SpawnPlayer(i, false); + } + } + + if (modeattacking == ATTACKING_RECORD && !demo.playback) + P_LoadRecordGhosts(); + + if (G_TagGametype()) { - virtres_t *temp = curmapvirt; - curmapvirt = NULL; - vres_Free(temp); + INT32 realnumplayers = 0; + INT32 playersactive[MAXPLAYERS]; + + //I just realized how problematic this code can be. + //D_NumPlayers() will not always cover the scope of the netgame. + //What if one player is node 0 and the other node 31? + //The solution? Make a temp array of all players that are currently playing and pick from them. + //Future todo? When a player leaves, shift all nodes down so D_NumPlayers() can be used as intended? + //Also, you'd never have to loop through all 32 players slots to find anything ever again. + for (i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i] && !players[i].spectator) + { + playersactive[realnumplayers] = i; //stores the player's node in the array. + realnumplayers++; + } + } + + if (realnumplayers) //this should also fix the dedicated crash bug. You only pick a player if one exists to be picked. + { + i = P_RandomKey(realnumplayers); + players[playersactive[i]].pflags |= PF_TAGIT; //choose our initial tagger before map starts. + + // Taken and modified from G_DoReborn() + // Remove the player so he can respawn elsewhere. + // first dissasociate the corpse + if (players[playersactive[i]].mo) + P_RemoveMobj(players[playersactive[i]].mo); + + G_SpawnPlayer(playersactive[i], false); //respawn the lucky player in his dedicated spawn location. + } + else + CONS_Printf(M_GetText("No player currently available to become IT. Awaiting available players.\n")); + } + else if (G_RaceGametype() && server) + CV_StealthSetValue(&cv_numlaps, + ((netgame || multiplayer) && cv_basenumlaps.value + && (!(mapheaderinfo[gamemap - 1]->levelflags & LF_SECTIONRACE) + || (mapheaderinfo[gamemap - 1]->numlaps > cv_basenumlaps.value))) + ? cv_basenumlaps.value + : 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()) { + static char buf[256]; + sprintf(buf, "replay"PATHSEP"online"PATHSEP"%d-%s", (int) (time(NULL)), G_BuildMapName(gamemap)); + + I_mkdir(va("%s"PATHSEP"replay", srb2home), 0755); + I_mkdir(va("%s"PATHSEP"replay"PATHSEP"online", srb2home), 0755); + G_RecordDemo(buf); + if (dedicated) + G_BeginRecording(); //this has to move here, since dedicated servers dont run got_mapcmd + } + + wantedcalcdelay = wantedfrequency*2; + indirectitemcooldown = 0; + hyubgone = 0; + mapreset = 0; + nospectategrief = 0; + thwompsactive = false; + spbplace = -1; + + startedInFreePlay = false; + { + UINT8 nump = 0; + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] || players[i].spectator) + { + continue; + } + + nump++; + if (nump == 2) + { + break; + } + } + + if (nump <= 1) + { + startedInFreePlay = true; + } + } + + // =========== + // landing point for netgames. + netgameskip: if (!reloadinggamestate) { From cc44a5785d723eb3b6f6f0f5135e88423a3da4e6 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Sep 2024 23:08:24 +0200 Subject: [PATCH 15/99] lets not archive players as mobjs --- src/lua_script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua_script.c b/src/lua_script.c index af6312428..b4d479658 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1286,7 +1286,7 @@ void LUA_Archive(savebuffer_t *save, boolean network) // archive function will determine when to skip mobjs, // and write mobjnum in otherwise. - ArchiveExtVars(&save->p, &players[i], "mobj"); + ArchiveExtVars(&save->p, th, "mobj"); } } WRITEUINT32(save->p, UINT32_MAX); // end of mobjs marker, replaces mobjnum. From a87ac3e35e625cec7cc5719372bb3521db953a6c Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Sep 2024 01:34:41 +0200 Subject: [PATCH 16/99] Revert "extra check" This reverts commit 0bb1efcd50342949dbe99c8490aad7b94e86e00a. --- src/k_kart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/k_kart.c b/src/k_kart.c index 747966ce3..1fbe36794 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -9404,7 +9404,7 @@ skipcrap: case 5: if (driftgaugegfx) { - if (cv_driftgaugestyle.value == 1 || cv_driftgaugestyle.value == 3 || (cv_driftgaugestyle.value == 5 && xtra_speedo3)) + if (cv_driftgaugestyle.value == 1 || cv_driftgaugestyle.value == 3 || cv_driftgaugestyle.value == 5) { barx = basex - dup*23; BAR_WIDTH = dup*47; From df10262ebb9c022bedf9061d070a2818a90f6acb Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Sep 2024 01:34:47 +0200 Subject: [PATCH 17/99] Revert "beta hud driftgauge" This reverts commit 26e8c2ca2bc8473fdd4c649ea0c86317c2fd609f. --- src/d_netcmd.c | 4 ++-- src/k_kart.c | 28 +++++++--------------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 79745251c..076b1ee8f 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -537,11 +537,11 @@ consvar_t cv_nametagscore = {"kartnametagscore", "Off", CV_SAVE, CV_OnOff, NULL, consvar_t cv_shownametagfinish = {"kartshownametagfinished", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_shownametagspectator = {"kartshownametagspectator", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; - static CV_PossibleValue_t driftgaugeoffset_cons_t[] = { {-FRACUNIT*128, "MIN"}, {FRACUNIT*128, "MAX"}, {0, NULL}}; + static CV_PossibleValue_t driftgaugestyle_cons_t[] = { - {1, "Default"}, {2, "Small"}, {3, "Big Numbers"}, {4, "Numbers Only"}, {5, "Extra"}, {0, NULL}}; + {1, "Default"}, {2, "Small"}, {3, "Big Numbers"}, {4, "Numbers Only"}, {0, NULL}}; consvar_t cv_driftgauge = {"kartdriftgauge", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_driftgaugeofs = {"kartdriftgaugeoffset", "-20", CV_FLOAT|CV_SAVE, driftgaugeoffset_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; diff --git a/src/k_kart.c b/src/k_kart.c index 1fbe36794..9ed535d3b 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -8874,7 +8874,7 @@ static void K_drawKartSpeedometer(void) { UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); V_DrawStretchyFixedPatch((SPDM_X-1)<= driftval*4) // rainbow sparks From 7f1217b2ab0e3ca86722ad23c6c42bfbf55ef5ec Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Oct 2024 21:56:08 +0200 Subject: [PATCH 18/99] Attempt to fix a lua panic when unarchiveing extvars (print error to console instead. Not sure if it would be safe for game to read from save afterwards though) https://github.com/alufolie91/saturn-32p/commit/a770ecdbd4afd56a9d8325eae47f0c69f71661ee#diff-0c6396d5a9ad45f461741cd44ffb2c0d3cf0eb2ec7b0500053005196fe53f1a6R1462 --- src/lua_script.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lua_script.c b/src/lua_script.c index b4d479658..2b96abe1e 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1149,7 +1149,13 @@ static void UnArchiveExtVars(UINT8 **p, void *pointer, boolean network) for (i = 0; i < field_count; i++) { READSTRING(*p, field); - UnArchiveValue(p, TABLESINDEX); + + if (UnArchiveValue(p, TABLESINDEX) == 1) + { + CONS_Alert(CONS_ERROR, "Unexpected end marker when reading ExtVars (field '%s')\n", field); + break; + } + lua_setfield(gL, -2, field); } } From d0c50c49a73ef8b4c35da3bb1c5bdcba8e40bf3c Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Oct 2024 22:04:50 +0200 Subject: [PATCH 19/99] Add few checks to prevent game crashing if netgame archive becomes corrupted https://github.com/alufolie91/saturn-32p/commit/1e47728ea8c60a1f04130170ddfab9b02e1a7e4c#diff-0c6396d5a9ad45f461741cd44ffb2c0d3cf0eb2ec7b0500053005196fe53f1a6R1517 --- src/lua_script.c | 76 +++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/src/lua_script.c b/src/lua_script.c index 2b96abe1e..971317992 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1021,6 +1021,9 @@ static UINT8 UnArchiveValue(UINT8 **p, int TABLESINDEX) break; case ARCH_TEND: return 1; + default: + CONS_Alert(CONS_ERROR, "Unknown value type unarchived, save is corrupted!\n"); + return 1; } return 0; } @@ -1199,37 +1202,37 @@ static void UnArchiveTables(UINT8 **p, boolean network) n = (UINT16)lua_objlen(gL, TABLESINDEX); - if (network) + for (i = 1; i <= n; i++) { - for (i = 1; i <= n; i++) + lua_rawgeti(gL, TABLESINDEX, i); + + if (!lua_istable(gL, -1)) { - lua_rawgeti(gL, TABLESINDEX, i); - while (true) + CONS_Alert(CONS_ERROR, "Value in tables list #%d is not a table! (corrupted save?)\n", i); + continue; + } + + while (true) + { + UINT8 ret; + + if (network) { if (UnArchiveValue(p, TABLESINDEX) == 1) // read key break; - if (UnArchiveValue(p, TABLESINDEX) == 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); - } - } - else - { - for (i = 1; i <= n; i++) - { - lua_rawgeti(gL, TABLESINDEX, i); - while (true) - { - UINT8 ret; + 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); @@ -1237,24 +1240,23 @@ static void UnArchiveTables(UINT8 **p, boolean network) break; 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) - { - 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); - } - } + 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); + } } void LUA_Step(void) From cb94235ac1844a900987e663e94e66216bdf2a5c Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 4 May 2024 18:14:34 +0300 Subject: [PATCH 20/99] If corrupted save received, leave netgame --- src/lua_script.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lua_script.c b/src/lua_script.c index 971317992..97f0bc94e 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -22,6 +22,8 @@ #include "p_saveg.h" #include "p_local.h" #include "p_slopes.h" // for P_SlopeById +#include "s_sound.h" +#include "m_menu.h" #ifdef LUA_ALLOW_BYTECODE #include "d_netfil.h" // for LUA_DumpFile #endif @@ -1023,6 +1025,9 @@ static UINT8 UnArchiveValue(UINT8 **p, int TABLESINDEX) return 1; default: CONS_Alert(CONS_ERROR, "Unknown value type unarchived, save is corrupted!\n"); + G_SetExitGameFlag(); + S_StartSound(NULL, sfx_syfail); // he he he + M_StartMessage(M_GetText("Corrupted save received\nPress ESC\n"), NULL, MM_NOTHING); return 1; } return 0; From 7304988071cba17b792a21348481eabbbaf6b89b Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Dec 2024 03:12:48 +0100 Subject: [PATCH 21/99] fix conflitc --- src/hardware/hw_batching.c | 22 +-- src/hardware/hw_batching.h | 4 +- src/hardware/hw_cache.c | 30 ++-- src/hardware/hw_draw.c | 42 ++--- src/hardware/hw_gpu.h | 76 +++++++++ src/hardware/hw_main.c | 112 ++++++------- src/hardware/hw_md2.c | 24 +-- src/hardware/hw_portal.c | 4 +- src/hardware/hw_shaders.c | 10 +- src/hardware/hw_shaders.h | 1 + src/hardware/r_opengl/ogl_win.c | 25 +-- src/hardware/r_opengl/r_opengl.c | 269 +++++++++++++++---------------- src/hardware/r_opengl/r_opengl.h | 23 +-- src/sdl/hwsym_sdl.c | 58 +------ src/sdl/i_video.c | 46 +----- src/sdl/ogl_sdl.c | 49 +++--- src/sdl/ogl_sdl.h | 4 +- 17 files changed, 379 insertions(+), 420 deletions(-) create mode 100644 src/hardware/hw_gpu.h 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..2825b0820 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_gpu.h" + +extern boolean currently_batching; typedef struct { diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 652e1e903..bfb1df1f1 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -16,7 +16,7 @@ #ifdef HWRENDER #include "hw_main.h" #include "hw_glob.h" -#include "hw_drv.h" +#include "hw_gpu.h" #include "hw_batching.h" #include "../doomstat.h" //gamemode @@ -494,7 +494,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); @@ -505,7 +505,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 @@ -572,7 +572,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. @@ -660,7 +660,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. @@ -689,7 +689,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. @@ -719,7 +719,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. @@ -894,7 +894,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); @@ -927,11 +927,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. @@ -941,7 +941,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 @@ -974,7 +974,7 @@ static void HWR_SetPaletteLookup(RGBA_t *palette) } } #undef STEP_SIZE - HWD.pfnSetPaletteLookup(lut); + GL_SetPaletteLookup(lut); Z_Free(lut); } @@ -1022,7 +1022,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) { @@ -1045,7 +1045,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; } @@ -1081,7 +1081,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..bfb1909e5 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -20,7 +20,7 @@ #ifdef HWRENDER #include "hw_main.h" #include "hw_glob.h" -#include "hw_drv.h" +#include "hw_gpu.h" #include "../m_misc.h" //FIL_WriteFile() #include "../r_draw.h" //viewborderlump @@ -122,7 +122,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 +303,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 +460,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 +539,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 +575,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 +602,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 +629,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 +785,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 +879,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 +918,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 +989,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 +1029,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 +1107,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 +1191,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 +1207,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_gpu.h b/src/hardware/hw_gpu.h new file mode 100644 index 000000000..384587b37 --- /dev/null +++ b/src/hardware/hw_gpu.h @@ -0,0 +1,76 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 2020 by Jaime "Lactozilla" Passos. +// +// 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_gpu.h +/// \brief GPU low-level interface API + +#ifndef __HWR_GPU_H__ +#define __HWR_GPU_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_UpdateTexture (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_GPU_H__ diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 5e24e6eae..e084b78f6 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -14,13 +14,14 @@ #include #include "../doomstat.h" +#include "../doomdef.h" #include "../qs22j.h" #ifdef HWRENDER #include "hw_main.h" #include "hw_glob.h" -#include "hw_drv.h" +#include "hw_gpu.h" #include "hw_batching.h" #include "hw_md2.h" #include "hw_clip.h" @@ -63,8 +64,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; @@ -242,7 +241,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(); } @@ -283,13 +282,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) @@ -324,7 +323,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) @@ -1117,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); } } @@ -4226,7 +4225,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++) { @@ -5072,7 +5071,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)); @@ -5094,9 +5093,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); } // -----------------+ @@ -5104,12 +5103,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); } @@ -5131,7 +5130,7 @@ void HWR_SetViewSize(void) gl_baseviewwindowy = 0; gl_baseviewwindowx = 0; - HWD.pfnFlushScreenTextures(); + GL_FlushScreenTextures(); } // Set view aiming, for the sky dome, the skybox, @@ -5196,7 +5195,7 @@ void HWR_SetTransform(float fpov, player_t *player) atransform.mirrorflip = true; // Set transform. - HWD.pfnSetTransform(&atransform); + GL_SetTransform(&atransform); } void HWR_ClearClipper(void) @@ -5213,8 +5212,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. @@ -5270,7 +5269,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl } // Set transform. - HWD.pfnSetTransform(&atransform); + GL_SetTransform(&atransform); validcount++; @@ -5314,7 +5313,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; @@ -5385,11 +5384,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]; } @@ -5397,8 +5396,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) @@ -5406,7 +5405,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); } // ========================================================================== @@ -5436,11 +5435,14 @@ 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. + if (HWR_UseShader()) + { + if (cv_ripplewater.value) + GL_SetShaderInfo(HWD_SHADERINFO_LEVELTIME, (INT32)leveltime); // The water surface shader needs the leveltime. + } if (viewnumber > 3) return; @@ -5507,7 +5509,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 @@ -5521,7 +5523,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(); } } } @@ -5591,7 +5593,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); } startupdone = true; } @@ -5605,9 +5607,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 } @@ -5650,12 +5652,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? @@ -5679,7 +5681,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 @@ -5687,7 +5689,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; @@ -5727,28 +5729,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) @@ -5782,22 +5784,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..5018496dd 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -25,12 +25,13 @@ #include "../doomstat.h" #ifdef HWRENDER -#include "hw_drv.h" +#include "hw_gpu.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" @@ -417,7 +418,7 @@ static void md2_loadTexture(md2_t *model) } } } - HWD.pfnSetTexture(glpatch->mipmap); + GL_SetTexture(glpatch->mipmap); HWR_UnlockCachedPatch(glpatch); } @@ -467,7 +468,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,11 +1049,11 @@ 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; } - // search for the Mipmap + // search for the mimmap // skip the first (no colormap translated) for (glMipmap = gpatch->mipmap; glMipmap->nextcolormap; ) { @@ -1063,7 +1064,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,10 +1085,11 @@ 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); } + // -----------------+ // HWR_DrawMD2 : Draw MD2 // : @@ -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..7b5f93b97 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_gpu.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..2068cbb99 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_gpu.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 19c03a7be..37ce52cae 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; @@ -706,8 +704,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}; @@ -719,7 +717,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 @@ -791,7 +789,7 @@ void SetupGLFunc4(void) #endif } -EXPORT boolean HWRAPI(InitShaders) (void) +boolean GL_InitShaders(void) { if (!pglUseProgram) return false; @@ -799,7 +797,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; @@ -808,7 +806,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; @@ -833,12 +831,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; } @@ -854,7 +852,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) { @@ -866,11 +864,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) @@ -897,7 +895,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 { @@ -916,10 +914,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); @@ -928,7 +926,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] = { @@ -957,7 +958,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); @@ -969,7 +970,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); @@ -979,7 +980,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); @@ -999,10 +1000,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); @@ -1015,7 +1016,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; @@ -1047,7 +1048,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; @@ -1079,7 +1080,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); } @@ -1090,7 +1091,7 @@ static void GLFramebuffer_GenerateAttachments(void) fboinit = true; } -void GLFramebuffer_DeleteAttachments(void) +void GL_Framebuffer_DeleteAttachments(void) { if (!supportFBO || fboinit == false) return; @@ -1113,7 +1114,7 @@ void GLFramebuffer_DeleteAttachments(void) fboinit = false; } -static void GLFramebuffer_Generate(void) +static void GL_Framebuffer_Generate(void) { if (!supportFBO || !UseScreenFBO()) return; @@ -1123,10 +1124,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; @@ -1134,11 +1135,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; @@ -1150,21 +1151,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; @@ -1175,7 +1176,7 @@ void GLFramebuffer_Disable(void) pglBindFramebuffer(GL_FRAMEBUFFER, 0); pglBindRenderbuffer(GL_RENDERBUFFER, 0); - GLFramebuffer_Delete(); + GL_Framebuffer_Delete(); } #endif @@ -1183,7 +1184,7 @@ void GLFramebuffer_Disable(void) // Flush : flush OpenGL textures // : Clear list of downloaded mipmaps // -----------------+ -void Flush(void) +void GL_Flush(void) { while (TexCacheHead) { @@ -1215,7 +1216,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; @@ -1242,34 +1243,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 @@ -1282,11 +1274,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++) @@ -1300,10 +1292,24 @@ EXPORT void HWRAPI(ReadScreenTexture) (int tex, UINT16 *dst_data) free(row); } +// -----------------+ +// SetPalette : Changes the current texture palette +// -----------------+ +void GL_SetPalette(RGBA_t *palette) +{ + size_t palsize = (sizeof(RGBA_t) * 256); + // on a palette change, you have to reload all of the textures + if (memcmp(&myPaletteData, palette, palsize)) + { + memcpy(&myPaletteData, palette, palsize); + 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); @@ -1314,7 +1320,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) @@ -1326,10 +1332,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; @@ -1351,7 +1354,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 @@ -1364,9 +1367,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]; @@ -1413,7 +1414,7 @@ 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; @@ -1540,12 +1541,12 @@ EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags) } } if (PolyFlags & PF_NoTexture) - SetNoTexture(); + 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) @@ -1560,7 +1561,7 @@ static void AllocTextureBuffer(GLMipmap_t *pTexInfo) // -----------------+ // UpdateTexture : Updates texture data. // -----------------+ -EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo) +void GL_UpdateTexture(GLMipmap_t *pTexInfo) { // Upload a texture GLuint num = pTexInfo->downloaded; @@ -1572,7 +1573,7 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo) const GLubyte *pImgData = (const GLubyte *)pTexInfo->data; const GLvoid *ptex = NULL; RGBA_t *tex = NULL; - + // Generate a new texture name. if (!num) { @@ -1585,7 +1586,7 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo) if ((pTexInfo->format == GL_TEXFMT_P_8) || (pTexInfo->format == GL_TEXFMT_AP_88)) { - AllocTextureBuffer(pTexInfo); + GL_AllocTextureBuffer(pTexInfo); ptex = tex = textureBuffer; for (j = 0; j < h; j++) @@ -1627,7 +1628,7 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo) } else if (pTexInfo->format == GL_TEXFMT_ALPHA_INTENSITY_88) { - AllocTextureBuffer(pTexInfo); + GL_AllocTextureBuffer(pTexInfo); ptex = tex = textureBuffer; for (j = 0; j < h; j++) @@ -1645,7 +1646,7 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo) } else if (pTexInfo->format == GL_TEXFMT_ALPHA_8) // Used for fade masks { - AllocTextureBuffer(pTexInfo); + GL_AllocTextureBuffer(pTexInfo); ptex = tex = textureBuffer; for (j = 0; j < h; j++) @@ -1765,18 +1766,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; } } @@ -1784,7 +1786,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; @@ -1804,7 +1806,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; @@ -1869,7 +1871,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; @@ -2014,13 +2016,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) { @@ -2060,15 +2062,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); @@ -2084,9 +2086,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); @@ -2102,11 +2104,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) @@ -2189,7 +2191,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) { @@ -2237,7 +2239,7 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) 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,7 +2254,7 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) case HWD_SET_TEXTUREANISOTROPICMODE: 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: @@ -2338,7 +2340,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; @@ -2356,7 +2358,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; @@ -2380,7 +2382,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); @@ -2448,7 +2450,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); @@ -2493,9 +2495,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]; @@ -2509,7 +2512,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) @@ -2521,7 +2524,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); } } } @@ -2529,7 +2532,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}; @@ -2568,9 +2571,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); @@ -2592,7 +2595,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); @@ -2688,7 +2691,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; @@ -2731,7 +2734,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; @@ -2757,18 +2760,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; @@ -2828,10 +2823,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); @@ -2839,7 +2834,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; @@ -2864,7 +2859,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; @@ -2901,9 +2896,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 Date: Sun, 8 Dec 2024 03:13:50 +0100 Subject: [PATCH 22/99] delet this --- src/hardware/hw_drv.h | 142 ----------------------------------------- src/hardware/hw_main.c | 5 +- 2 files changed, 2 insertions(+), 145 deletions(-) delete mode 100644 src/hardware/hw_drv.h 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_main.c b/src/hardware/hw_main.c index e084b78f6..cbac939c4 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5438,10 +5438,9 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) GL_ClearBuffer(true, false, false, &ClearColor); } - if (HWR_UseShader()) + if (HWR_UseShader() && cv_ripplewater.value) { - if (cv_ripplewater.value) - GL_SetShaderInfo(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) From e5b12ece358463df647e38fec1e3f72e89a16b4d Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Dec 2024 03:15:14 +0100 Subject: [PATCH 23/99] change this --- src/sdl/ogl_sdl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index a5d171107..cfa6683bd 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -261,8 +261,7 @@ void OglSdlFinishUpdate(boolean waitvbl) } #endif - //HWR_DrawScreenFinalTexture(sdlw, sdlh); - GL_DrawScreenFinalTexture(HWD_SCREENTEXTURE_GENERIC2, sdlw, sdlh, true); + GL_DrawScreenFinalTexture(HWD_SCREENTEXTURE_GENERIC2, sdlw, sdlh, HWR_ShouldUsePaletteRendering()); #ifdef USE_FBO_OGL if (UseScreenFBO()) From c1b771fdc84bb61ff0fc4a727fa6852a4561a062 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Dec 2024 03:16:13 +0100 Subject: [PATCH 24/99] fix make files --- src/CMakeLists.txt | 2 +- src/Makefile | 4 ++-- src/sdl/macosx/Srb2mac.pbproj/project.pbxproj | 4 ++-- src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8fde277c7..35669ce52 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_gpu.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 4df4e1fe8..b2cac197e 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_gpu.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_gpu.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/sdl/macosx/Srb2mac.pbproj/project.pbxproj b/src/sdl/macosx/Srb2mac.pbproj/project.pbxproj index ee0bf4697..3d8c7a82e 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_gpu.h; + path = ../../hardware/hw_gpu.h; refType = 2; }; 8417773C085A106C000C01D8 = { diff --git a/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj b/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj index 00930bfb3..8a2f00c9c 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_gpu.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw_gpu.h; path = ../../hardware/hw_gpu.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_gpu.h */, 1E44AE680B67CC2B00BAD059 /* hw_light.c */, 1E44AE690B67CC2B00BAD059 /* hw_light.h */, 1E44AE6A0B67CC2B00BAD059 /* hw3sound.h */, From 3f16f42adfe2f8beeefb31e6e2a412b94330f84e Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Dec 2024 05:03:36 +0100 Subject: [PATCH 25/99] forgor --- src/sdl/ogl_sdl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index cfa6683bd..95b05d583 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -281,10 +281,8 @@ void OglSdlFinishUpdate(boolean waitvbl) && (!UseScreenFBO()) #endif ) - HWR_DrawScreenFinalTexture(realwidth, realheight, false); - - //HWR_DrawScreenFinalTexture(realwidth, realheight); - //GL_DrawScreenFinalTexture(HWD_SCREENTEXTURE_GENERIC2, realwidth, realheight); + //HWR_DrawScreenFinalTexture(realwidth, realheight, false); + GL_DrawScreenFinalTexture(HWD_SCREENTEXTURE_GENERIC2, realwidth, realheight, false); } #endif //HWRENDER From cd9ee7d1394c0a47df49f6037436416a072167b7 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Dec 2024 15:31:28 +0100 Subject: [PATCH 26/99] smol cleanup --- src/hardware/hw_gpu.h | 73 +++++++++++++++++--------------- src/hardware/r_opengl/r_opengl.h | 2 - 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/hardware/hw_gpu.h b/src/hardware/hw_gpu.h index 384587b37..0d63296c6 100644 --- a/src/hardware/hw_gpu.h +++ b/src/hardware/hw_gpu.h @@ -13,64 +13,67 @@ #define __HWR_GPU_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); +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_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_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_UpdateTexture (GLMipmap_t *pTexInfo); -void GL_DeleteTexture (GLMipmap_t *pTexInfo); +void GL_RenderSkyDome(gl_sky_t *sky); + +void GL_SetTexture(GLMipmap_t *pTexInfo); +void GL_UpdateTexture(GLMipmap_t *pTexInfo); +void GL_DeleteTexture(GLMipmap_t *pTexInfo); void GL_Flush(void); #define GL_ClearMipMapCache GL_Flush -INT32 GL_GetTextureUsed (void); +INT32 GL_GetTextureUsed(void); -void GL_CreateModelVBOs (model_t *model); +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_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_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_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]); +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); +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_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); +void GL_SetPaletteLookup(UINT8 *lut); +UINT32 GL_CreateLightTable(RGBA_t *hw_lighttable); +void GL_ClearLightTables(void); +void GL_SetScreenPalette(RGBA_t *palette); #endif // __HWR_GPU_H__ diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index a03febd3c..c453e4ebf 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -130,8 +130,6 @@ extern GLbyte screen_depth; extern GLint maximumAnisotropy; extern boolean supportMipMap; -extern struct GPURenderingAPI GLInterfaceAPI; - /** \brief OpenGL flags for video driver */ extern INT32 oglflags; From b03e74c366ec66532617bc9653819d758ba0189e Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Dec 2024 15:39:52 +0100 Subject: [PATCH 27/99] rename to "hw_gl" --- src/CMakeLists.txt | 2 +- src/Makefile | 4 ++-- src/hardware/hw_batching.h | 2 +- src/hardware/hw_cache.c | 3 ++- src/hardware/hw_draw.c | 3 ++- src/hardware/{hw_gpu.h => hw_gl.h} | 13 +++++++------ src/hardware/hw_main.c | 7 ++++--- src/hardware/hw_md2.c | 5 +++-- src/hardware/hw_portal.c | 2 +- src/hardware/hw_shaders.c | 2 +- src/hardware/r_opengl/r_opengl.h | 3 ++- src/sdl/Srb2SDL.dsp | 2 +- src/sdl/i_video.c | 10 ++++++---- src/sdl/macosx/Srb2mac.pbproj/project.pbxproj | 4 ++-- src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj | 4 ++-- src/sdl/ogl_sdl.c | 2 +- 16 files changed, 38 insertions(+), 30 deletions(-) rename src/hardware/{hw_gpu.h => hw_gl.h} (93%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 35669ce52..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_gpu.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 b2cac197e..fcdb34d46 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_gpu.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_gpu.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/hardware/hw_batching.h b/src/hardware/hw_batching.h index 2825b0820..7f418fc77 100644 --- a/src/hardware/hw_batching.h +++ b/src/hardware/hw_batching.h @@ -15,7 +15,7 @@ #include "hw_defs.h" #include "hw_data.h" -#include "hw_gpu.h" +#include "hw_gl.h" extern boolean currently_batching; diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index bfb1df1f1..4df24bd16 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_gpu.h" +#include "hw_gl.h" #include "hw_batching.h" #include "../doomstat.h" //gamemode diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index bfb1909e5..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_gpu.h" +#include "hw_gl.h" #include "../m_misc.h" //FIL_WriteFile() #include "../r_draw.h" //viewborderlump diff --git a/src/hardware/hw_gpu.h b/src/hardware/hw_gl.h similarity index 93% rename from src/hardware/hw_gpu.h rename to src/hardware/hw_gl.h index 0d63296c6..aacb1b1fb 100644 --- a/src/hardware/hw_gpu.h +++ b/src/hardware/hw_gl.h @@ -1,16 +1,17 @@ -// SONIC ROBO BLAST 2 +// 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_gpu.h -/// \brief GPU low-level interface API +/// \file hw_gl.h +/// \brief OpenGL low-level interface API -#ifndef __HWR_GPU_H__ -#define __HWR_GPU_H__ +#ifndef __HWR_GL_H__ +#define __HWR_GL_H__ #include "../screen.h" @@ -76,4 +77,4 @@ UINT32 GL_CreateLightTable(RGBA_t *hw_lighttable); void GL_ClearLightTables(void); void GL_SetScreenPalette(RGBA_t *palette); -#endif // __HWR_GPU_H__ +#endif // __HWR_GL_H__ diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index cbac939c4..77045a723 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -16,12 +16,11 @@ #include "../doomstat.h" #include "../doomdef.h" -#include "../qs22j.h" - #ifdef HWRENDER + #include "hw_main.h" #include "hw_glob.h" -#include "hw_gpu.h" +#include "hw_gl.h" #include "hw_batching.h" #include "hw_md2.h" #include "hw_clip.h" @@ -57,6 +56,8 @@ #include "../w_wad.h" #include "../z_zone.h" +#include "../qs22j.h" // fast qsort + // ========================================================================== // Globals // ========================================================================== diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 5018496dd..0612b8e65 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -25,7 +25,8 @@ #include "../doomstat.h" #ifdef HWRENDER -#include "hw_gpu.h" + +#include "hw_gl.h" #include "hw_md2.h" #include "../d_main.h" #include "../r_bsp.h" @@ -44,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 diff --git a/src/hardware/hw_portal.c b/src/hardware/hw_portal.c index 7b5f93b97..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_gpu.h" +#include "hw_gl.h" #include "hw_defs.h" #include "hw_main.h" #include "hw_portal.h" diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index 2068cbb99..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_gpu.h" +#include "hw_gl.h" #include "hw_shaders.h" #include "../z_zone.h" diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index c453e4ebf..dfa754f1e 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -43,8 +43,9 @@ #endif #define _CREATE_DLL_ // necessary for Unix AND Windows + #include "../../doomdef.h" -#include "../hw_gpu.h" +#include "../hw_gl.h" #include "../../z_zone.h" // ========================================================================== 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/i_video.c b/src/sdl/i_video.c index af8faea41..c880eb263 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_gpu.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 diff --git a/src/sdl/macosx/Srb2mac.pbproj/project.pbxproj b/src/sdl/macosx/Srb2mac.pbproj/project.pbxproj index 3d8c7a82e..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_gpu.h; - path = ../../hardware/hw_gpu.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 8a2f00c9c..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_gpu.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw_gpu.h; path = ../../hardware/hw_gpu.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_gpu.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 95b05d583..006ad87fb 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -38,7 +38,7 @@ #ifdef HWRENDER #include "../hardware/r_opengl/r_opengl.h" #include "../hardware/hw_main.h" -#include "../hardware/hw_gpu.h" +#include "../hardware/hw_gl.h" #include "ogl_sdl.h" #include "../i_system.h" #include "hwsym_sdl.h" From 74088c1d2683a6751d91884d1f7d0e4de83d6979 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Dec 2024 15:43:46 +0100 Subject: [PATCH 28/99] use loop instead of memcpy for setpalette idk last time this died with models for some reason kek --- src/hardware/r_opengl/r_opengl.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 37ce52cae..29c6f2ba2 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1297,13 +1297,17 @@ void GL_ReadScreenTexture(int tex, UINT16 *dst_data) // -----------------+ void GL_SetPalette(RGBA_t *palette) { - size_t palsize = (sizeof(RGBA_t) * 256); - // on a palette change, you have to reload all of the textures - if (memcmp(&myPaletteData, palette, palsize)) + INT32 i; + + for (i = 0; i < 256; i++) { - memcpy(&myPaletteData, palette, palsize); - GL_Flush(); + 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; } + + GL_Flush(); } // -----------------+ From f3d1bf1106a629fb63a6cfc41fc3e9625754e814 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 11 Dec 2024 04:35:43 +0100 Subject: [PATCH 29/99] clean up GL_UpdateTexture use switches and reduce code dupe --- src/hardware/r_opengl/r_opengl.c | 216 +++++++++++++------------------ 1 file changed, 90 insertions(+), 126 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 29c6f2ba2..ffd00fa59 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1578,6 +1578,8 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) const GLvoid *ptex = NULL; RGBA_t *tex = NULL; + GLint texformat = 0; + // Generate a new texture name. if (!num) { @@ -1588,85 +1590,86 @@ void GL_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)) + switch (pTexInfo->format) { - GL_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++) + 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; - } + if ((*pImgData == HWR_PATCHES_CHROMAKEY_COLORINDEX) && + (pTexInfo->flags & TF_CHROMAKEYED)) + { + 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; + } - pImgData++; + pImgData++; - if (pTexInfo->format == GL_TEXFMT_AP_88) + if (pTexInfo->format == GL_TEXFMT_AP_88) + { + if (!(pTexInfo->flags & TF_CHROMAKEYED)) + tex[w*j+i].s.alpha = *pImgData; + pImgData++; + } + } + } + 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; + + for (j = 0; j < h; j++) + { + for (i = 0; i < w; i++) { - if (!(pTexInfo->flags & TF_CHROMAKEYED)) - tex[w*j+i].s.alpha = *pImgData; + 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_RGBA) - { - // Directly upload the texture data without any kind of conversion. - ptex = pImgData; - } - else if (pTexInfo->format == GL_TEXFMT_ALPHA_INTENSITY_88) - { - GL_AllocTextureBuffer(pTexInfo); - ptex = tex = textureBuffer; + break; + case GL_TEXFMT_ALPHA_8: // Used for fade masks + GL_AllocTextureBuffer(pTexInfo); + ptex = tex = textureBuffer; - 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++; + 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++; + } } - } + break; + default: + GL_MSG_Warning("UpdateTexture: bad format %d\n", pTexInfo->format); + break; } - else if (pTexInfo->format == GL_TEXFMT_ALPHA_8) // Used for fade masks - { - GL_AllocTextureBuffer(pTexInfo); - ptex = tex = textureBuffer; - - 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++; - } - } - } - else - GL_MSG_Warning("UpdateTexture: bad format %d\n", pTexInfo->format); pglBindTexture(GL_TEXTURE_2D, num); tex_downloaded = num; @@ -1683,73 +1686,34 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter); } - if (pTexInfo->format == GL_TEXFMT_ALPHA_INTENSITY_88) + switch (pTexInfo->format) { - //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_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_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - } + case GL_TEXFMT_ALPHA_INTENSITY_88: + texformat = GL_LUMINANCE_ALPHA; + break; + case GL_TEXFMT_ALPHA_8: + texformat = GL_ALPHA; + break; + default: + texformat = textureformatGL; + break; } - 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); - 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); - } + if (MipMap) + { + pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); + pglTexImage2D(GL_TEXTURE_2D, 0, texformat, 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 higher the detail + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, (pTexInfo->flags & TF_TRANSPARENT) ? 0 : 4); // No mipmaps on transparent stuff } 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) @@ -2256,7 +2220,7 @@ void GL_SetSpecialState(hwdspecialstate_t IdState, INT32 Value) break; case HWD_SET_TEXTUREANISOTROPICMODE: - anisotropic_filter = min(Value,maximumAnisotropy); + anisotropic_filter = min(Value, maximumAnisotropy); if (maximumAnisotropy) GL_Flush(); //??? if we want to change filter mode by texture, remove this break; From 37649a0d3cc984142efd5d002d8b763efb6081a8 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 11 Dec 2024 14:23:28 +0100 Subject: [PATCH 30/99] more cleanup GL_UpdateTexture also some optimizations --- src/hardware/r_opengl/r_opengl.c | 90 +++++++++++++++++--------------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index ffd00fa59..c42335d4d 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1590,6 +1590,8 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) //GL_DBG_Printf("UpdateTexture %d %x\n", (INT32)num, pImgData); + texformat = textureformatGL; + switch (pTexInfo->format) { case GL_TEXFMT_P_8: @@ -1597,35 +1599,36 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) GL_AllocTextureBuffer(pTexInfo); ptex = tex = textureBuffer; + const int chromakeyed = (pTexInfo->flags & TF_CHROMAKEYED); + for (j = 0; j < h; j++) { for (i = 0; i < w; i++) { - if ((*pImgData == HWR_PATCHES_CHROMAKEY_COLORINDEX) && - (pTexInfo->flags & TF_CHROMAKEYED)) + int idx = (w*j+i); + + if ((*pImgData == HWR_PATCHES_CHROMAKEY_COLORINDEX) && chromakeyed) { - 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; + 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[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; + tex[idx].s = myPaletteData[*pImgData].s; } pImgData++; - 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++; } } break; @@ -1636,16 +1639,19 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) 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++) { - tex[w*j+i].s.red = *pImgData; - tex[w*j+i].s.green = *pImgData; - tex[w*j+i].s.blue = *pImgData; + int idx = (w*j+i); + + tex[idx].s.red = *pImgData; + tex[idx].s.green = *pImgData; + tex[idx].s.blue = *pImgData; pImgData++; - tex[w*j+i].s.alpha = *pImgData; + tex[idx].s.alpha = *pImgData; pImgData++; } } @@ -1653,15 +1659,18 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) 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++) { - 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; + 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++; } } @@ -1674,8 +1683,10 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) 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); @@ -1686,27 +1697,18 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter); } - switch (pTexInfo->format) - { - case GL_TEXFMT_ALPHA_INTENSITY_88: - texformat = GL_LUMINANCE_ALPHA; - break; - case GL_TEXFMT_ALPHA_8: - texformat = GL_ALPHA; - break; - default: - texformat = textureformatGL; - break; - } - - if (MipMap) + if (MipMap && !transparent) // No mipmaps on transparent stuff { pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - pglTexImage2D(GL_TEXTURE_2D, 0, texformat, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + + if (update) + pglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + else + pglTexImage2D(GL_TEXTURE_2D, 0, texformat, 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 higher the detail - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, (pTexInfo->flags & TF_TRANSPARENT) ? 0 : 4); // No mipmaps on transparent stuff + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); } else { @@ -2167,6 +2169,7 @@ void GL_SetSpecialState(hwdspecialstate_t IdState, INT32 Value) gl_allowshaders = Value; break; case HWD_SET_TEXTUREFILTERMODE: + switch (Value) { case HWD_SET_TEXTUREFILTER_TRILINEAR: @@ -2198,9 +2201,10 @@ void GL_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; From 1ab20814e97e977339ecf3736032af415f1c6609 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 11 Dec 2024 14:39:24 +0100 Subject: [PATCH 31/99] simplify GL_SetPalette can just copy the whole struct --- src/hardware/r_opengl/r_opengl.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index c42335d4d..d33dfd560 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1301,10 +1301,7 @@ void GL_SetPalette(RGBA_t *palette) 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; + myPaletteData[i].s = palette[i].s; } GL_Flush(); From 8e273a1f19b3b3cbf5a7e1f3eb6f1417f6be9da2 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 11 Dec 2024 21:58:45 +0100 Subject: [PATCH 32/99] GL_UpdateTexture can be static --- src/hardware/hw_gl.h | 1 - src/hardware/r_opengl/r_opengl.c | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hardware/hw_gl.h b/src/hardware/hw_gl.h index aacb1b1fb..c2a88854f 100644 --- a/src/hardware/hw_gl.h +++ b/src/hardware/hw_gl.h @@ -41,7 +41,6 @@ void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics void GL_RenderSkyDome(gl_sky_t *sky); void GL_SetTexture(GLMipmap_t *pTexInfo); -void GL_UpdateTexture(GLMipmap_t *pTexInfo); void GL_DeleteTexture(GLMipmap_t *pTexInfo); void GL_Flush(void); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index d33dfd560..061a1430e 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1562,7 +1562,7 @@ static void GL_AllocTextureBuffer(GLMipmap_t *pTexInfo) // -----------------+ // UpdateTexture : Updates texture data. // -----------------+ -void GL_UpdateTexture(GLMipmap_t *pTexInfo) +static void GL_UpdateTexture(GLMipmap_t *pTexInfo) { // Upload a texture GLuint num = pTexInfo->downloaded; @@ -2865,9 +2865,10 @@ void GL_PostImgRedraw(float points[SCREENVERTS][SCREENVERTS][2]) pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); pglEnableClientState(GL_TEXTURE_COORD_ARRAY); - for(x = 0; x < SCREENVERTS-1;x ++) + + for (x = 0; x < SCREENVERTS-1;x ++) { - for(y = 0; y < SCREENVERTS-1; y++) + for (y = 0; y < SCREENVERTS-1; y++) { float stCoords[8]; float vertCoords[12]; From 3dec352245b1939b1479578e9fe4e3731446c371 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 11 Dec 2024 22:14:06 +0100 Subject: [PATCH 33/99] smol cleanup GL_SetBlend use early return since i likeit more --- src/hardware/r_opengl/r_opengl.c | 244 ++++++++++++++++--------------- 1 file changed, 126 insertions(+), 118 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 061a1430e..989b4ed1e 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1417,139 +1417,148 @@ static void Clamp2D(GLenum pname) // is it faster when pixels are discarded ? 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) - GL_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 GL_AllocTextureBuffer(GLMipmap_t *pTexInfo) { size_t size = pTexInfo->width * pTexInfo->height; + if (size > textureBufferSize) { textureBuffer = realloc(textureBuffer, size * sizeof(RGBA_t)); @@ -2865,10 +2874,9 @@ void GL_PostImgRedraw(float points[SCREENVERTS][SCREENVERTS][2]) pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); pglEnableClientState(GL_TEXTURE_COORD_ARRAY); - - for (x = 0; x < SCREENVERTS-1;x ++) + for(x = 0; x < SCREENVERTS-1;x ++) { - for (y = 0; y < SCREENVERTS-1; y++) + for(y = 0; y < SCREENVERTS-1; y++) { float stCoords[8]; float vertCoords[12]; From 99e4870a524272f16218e33d6bd69ef90580e9ed Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 12 Dec 2024 02:31:44 +0100 Subject: [PATCH 34/99] check for the flag first --- src/hardware/r_opengl/r_opengl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 989b4ed1e..077bdbbbe 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1613,7 +1613,7 @@ static void GL_UpdateTexture(GLMipmap_t *pTexInfo) { int idx = (w*j+i); - if ((*pImgData == HWR_PATCHES_CHROMAKEY_COLORINDEX) && chromakeyed) + if (chromakeyed && (*pImgData == HWR_PATCHES_CHROMAKEY_COLORINDEX)) { tex[idx].s.red = 0; tex[idx].s.green = 0; From c46ff7daff628ad924d80a70b5f38581b59fc2e7 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Dec 2024 21:18:57 +0100 Subject: [PATCH 35/99] use P_MobjWasRemoved for HWR_DrawSprite --- src/hardware/hw_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 5c947c770..da4d5f7e4 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3725,7 +3725,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) From e38580c9c2e2ef8e69134236ee90bafe25176083 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Dec 2024 17:44:48 +0100 Subject: [PATCH 36/99] dont remember removing this in s_sound --- src/s_sound.c | 7 +++++++ 1 file changed, 7 insertions(+) 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; From c8193380e7f102186d5a9f5cf2228d0d07347442 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Dec 2024 17:45:43 +0100 Subject: [PATCH 37/99] make some cam stuff behave exactly like vanilla again no clue if this changes anything at all, but cam stuff be causing so many issues id rather just have it behave like it used to --- src/p_user.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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; From a434ce2080748035fb07a254f4acfd82a8d2f447 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 26 Dec 2024 00:57:19 +0100 Subject: [PATCH 38/99] super smol optimizations --- src/hardware/hw_main.c | 55 +++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index da4d5f7e4..3f4ee2375 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -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; @@ -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); @@ -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); @@ -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 From 0bd2c6220dd4dc80203d1a4d7c8871a056d6fd35 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 26 Dec 2024 01:00:27 +0100 Subject: [PATCH 39/99] drifgauge gfx using the extra 3 speedometer sticker arsepain + smol cleanup colorhud --- src/hardware/hw_md2.c | 3 +- src/info.c | 1 - src/info.h | 1 - src/k_kart.c | 76 +++++++++++++++++++++++++------------------ 4 files changed, 45 insertions(+), 36 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 0612b8e65..c21823a36 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1054,7 +1054,7 @@ static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, INT return; } - // search for the mimmap + // search for the Mipmap // skip the first (no colormap translated) for (glMipmap = gpatch->mipmap; glMipmap->nextcolormap; ) { @@ -1090,7 +1090,6 @@ static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, INT Z_ChangeTag(newMipmap->data, PU_HWRCACHE_UNLOCKED); } - // -----------------+ // HWR_DrawMD2 : Draw MD2 // : diff --git a/src/info.c b/src/info.c index f8cb9a6f1..7afc76bf6 100644 --- a/src/info.c +++ b/src/info.c @@ -21,7 +21,6 @@ #include "d_player.h" #include "lzf.h" -// Hey, moron! If you change this table, don't forget about the sprite enum in info.h and the sprite lights in hw_light.c! char sprnames[NUMSPRITES + 1][5] = { "NULL","UNKN","THOK","PLAY","POSS","SPOS","FISH","BUZZ","RBUZ","JETB", diff --git a/src/info.h b/src/info.h index 6b2726f7e..4d24f729a 100644 --- a/src/info.h +++ b/src/info.h @@ -457,7 +457,6 @@ extern boolean actionsoverridden[NUMACTIONS]; #define NUMSPRITEFREESLOTS NUMMOBJFREESLOTS #define NUMSTATEFREESLOTS (NUMMOBJFREESLOTS*8) -// Hey, moron! If you change this table, don't forget about sprnames in info.c and the sprite lights in hw_light.c! typedef enum sprite { SPR_NULL, // invisible object diff --git a/src/k_kart.c b/src/k_kart.c index 67de6275e..bc9c7399d 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -7106,7 +7106,8 @@ void K_LoadKartHUDGraphics(void) skp_speedpatchesachi[4] = W_CachePatchName("SP_APERC", PU_HUDGFX); } - if (big_lap){ + if (big_lap) + { kp_lapstickerbig = W_CachePatchName("K_STLAPB", PU_HUDGFX); kp_lapstickerbig2 = W_CachePatchName("K_STLA2B", PU_HUDGFX); } @@ -7171,14 +7172,14 @@ void K_LoadKartHUDGraphics(void) // Nametags if (nametaggfx) { - nametagpic = W_CachePatchName("NTLINE", PU_HUDGFX); nametagline = W_CachePatchName("NTLINEV", PU_HUDGFX); nametagspeed = W_CachePatchName("NTSP", PU_HUDGFX); nametagweight = W_CachePatchName("NTWH", PU_HUDGFX); } - if (driftgaugegfx){ + if (driftgaugegfx) + { driftgauge = W_CachePatchName("K_DGAU", PU_HUDGFX); driftgaugecolor = W_CachePatchName("K_DCAU", PU_HUDGFX); driftgaugesmall = W_CachePatchName("K_DGSU", PU_HUDGFX); @@ -8164,13 +8165,13 @@ void K_drawKartTimestamp(tic_t drawtime, INT32 TX, INT32 TY, INT16 emblemmap, UI } } - if (!K_UseColorHud()) - V_DrawScaledPatch(TX, TY, splitflags, ((mode == 2) ? kp_lapstickerwide : kp_timestickerwide)); - else //Colourized hud + if (K_UseColorHud()) // Colourized hud { UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); V_DrawMappedPatch(TX, TY, splitflags, ((mode == 2) ? kp_lapstickerwideclr : kp_timestickerwideclr), colormap); } + else + V_DrawScaledPatch(TX, TY, splitflags, ((mode == 2) ? kp_lapstickerwide : kp_timestickerwide)); TX += 33; @@ -8673,12 +8674,9 @@ void HU_DrawTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, I } } -static boolean K_BigLapSticker(void) +static boolean K_BigLap(void) { - if (K_UseColorHud()) - return ((cv_numlaps.value > 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)); } From 0b5879ffb35430602edf7ad55397d3a082127df8 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 26 Dec 2024 01:00:52 +0100 Subject: [PATCH 40/99] fix compile --- src/hardware/hw_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 3f4ee2375..5eefc9c7e 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5574,8 +5574,8 @@ 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(); } startupdone = true; From 126fce9119eef74d86ac7cdb73beda7dc39fe804 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 26 Dec 2024 01:07:49 +0100 Subject: [PATCH 41/99] 1px --- src/k_kart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index bc9c7399d..a6aa76e4d 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -9375,10 +9375,10 @@ skipcrap: if (K_UseColorHud() && xtra_speedo_clr3) // Colourized hud { UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - V_DrawStretchyFixedPatch((basex - dup*30)< Date: Thu, 26 Dec 2024 15:49:47 +0100 Subject: [PATCH 42/99] whoops this never did anything lol --- src/r_bsp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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: From 38ef55b8698ccfd98f696cc2a1d52155b13c1902 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Dec 2024 15:40:11 +0100 Subject: [PATCH 43/99] add a mipmap check here ig --- src/hardware/hw_cache.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 16b6b3735..ad140c025 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -74,6 +74,9 @@ static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, GLMipm (void)patchheight; // This parameter is unused + if (!mipmap) + return; + if (originPatch) // originPatch can be NULL here, unlike in the software version originy = originPatch->originy; @@ -112,11 +115,11 @@ static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, GLMipm alpha = 0xFF; // Make pixel transparent if chroma keyed - if ((mipmap->flags & TF_CHROMAKEYED) && (texel == HWR_PATCHES_CHROMAKEY_COLORINDEX)) + if ((mipmap && mipmap->flags & TF_CHROMAKEYED) && (texel == HWR_PATCHES_CHROMAKEY_COLORINDEX)) alpha = 0x00; //Hurdler: 25/04/2000: now support colormap in hardware mode - if (mipmap->colormap) + if (mipmap && mipmap->colormap) texel = mipmap->colormap[texel]; // hope compiler will get this switch out of the loops (dreams...) From 22e65cd5e75ef791c23933eb72c319032d0fdbc9 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Dec 2024 15:58:43 +0100 Subject: [PATCH 44/99] fixup conflicts --- src/g_game.c | 41 +++++++++++++++++++---------------------- src/lua_hooklib.c | 33 +++++++++++++++++++++++++++++++++ src/lua_script.c | 9 +++++---- src/p_saveg.c | 6 +++--- 4 files changed, 60 insertions(+), 29 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 9bee4a399..708083939 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -5995,7 +5995,7 @@ void G_RecordDemo(const char *name) { INT32 maxsize; - demo_p = NULL; + demobuf.p = NULL; G_ResetDemoRecording(); demoend = NULL; @@ -6008,8 +6008,8 @@ 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 (demobuf.buffer) demo.recording = true; @@ -6022,12 +6022,12 @@ 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 (demobuf.buffer) metalrecording = true; @@ -6124,7 +6124,7 @@ void G_BeginRecording(void) break; } - WRITEUINT32(demobuf.p,P_GetInitSeed()); + WRITEUINT32(demobuf.p, P_GetInitSeed()); // Reserved for extrainfo location from start of file demoinfo_p = demobuf.p; @@ -7824,8 +7824,8 @@ ATTRNORETURN void FUNCNORETURN G_StopMetalRecording(void) #endif 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)); @@ -7934,10 +7934,7 @@ boolean G_CheckDemoStatus(void) if (modeattacking || demo.savemode != DSM_NOTSAVING) { - if (demobuf.p) - { - G_SaveDemo(); - } + G_SaveDemo(); return true; } @@ -7948,9 +7945,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; } @@ -7958,16 +7955,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 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 cb28cc906..6f439479e 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1309,11 +1309,11 @@ void LUA_Archive(savebuffer_t *save, boolean network) } WRITEUINT32(save->p, UINT32_MAX); // end of mobjs marker, replaces mobjnum. - LUAh_NetArchiveHook(NetArchive, save); // call the NetArchive hook in archive mode + LUA_HookNetArchive(NetArchive, save); // call the NetArchive hook in archive mode + //LUA_HookNetArchive(NetArchive); // call the NetArchive hook in archive mode } - LUA_HookNetArchive(NetArchive); // call the NetArchive hook in archive mode - ArchiveTables(); + ArchiveTables(&save->p); if (gL) lua_pop(gL, 1); // pop tables @@ -1350,7 +1350,8 @@ void LUA_UnArchive(savebuffer_t *save, boolean network) } } while(mobjnum != UINT32_MAX); // repeat until end of mobjs marker. - LUAh_NetArchiveHook(NetUnArchive, save); // call the NetArchive hook in unarchive mode + LUA_HookNetArchive(NetUnArchive, save); // call the NetArchive hook in unarchive mode + //LUA_HookNetArchive(NetUnArchive); // call the NetArchive hook in unarchive mode } UnArchiveTables(&save->p, network); diff --git a/src/p_saveg.c b/src/p_saveg.c index 4b79bc886..898a53d68 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -296,7 +296,7 @@ static void P_NetArchivePlayers(savebuffer_t *save, boolean resending) // // P_NetUnArchivePlayers // -static void P_NetUnArchivePlayers(boolean reloading) +static void P_NetUnArchivePlayers(savebuffer_t *save, boolean reloading) { INT32 i, j; UINT16 flags; @@ -307,7 +307,7 @@ static void P_NetUnArchivePlayers(boolean reloading) 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,7 +318,7 @@ static void P_NetUnArchivePlayers(boolean reloading) // NOTE: sending tics should (hopefully) no longer be necessary 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); From 8e10bcc7398b6c1c95fa482ee4430e0361d81020 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Dec 2024 15:59:10 +0100 Subject: [PATCH 45/99] add a bunch of extra checks into demo stuff buffer may be NULL in some cases should fix dedis crashing when replay recording is disabled --- src/g_game.c | 46 +++++++++++++++++++++++++++++++++++++--------- src/p_setup.c | 5 +++-- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 708083939..e48c53577 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4782,6 +4782,7 @@ void G_WriteDemoTiccmd(ticcmd_t *cmd, INT32 playernum) if (!demobuf.p) return; + ziptic_p = demobuf.p++; // the ziptic, written at the end of this function if (cmd->forwardmove != oldcmd[playernum].forwardmove) @@ -4910,10 +4911,14 @@ void G_GhostAddHit(INT32 playernum, mobj_t *victim) void G_WriteAllGhostTics(void) { + 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) @@ -4947,11 +4952,12 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) UINT8 sprite; UINT8 frame; + 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 (!demobuf.p) - return; if (!(demoflags & DF_GHOST)) return; // No ghost data to write. @@ -5144,6 +5150,9 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) void G_ConsAllGhostTics(void) { + if (!demobuf.p) + return; + UINT8 p = READUINT8(demobuf.p); while (p != 0xFF) @@ -5204,7 +5213,8 @@ void G_ConsGhostTic(INT32 playernum) demobuf.p++; if (ziptic & GZT_SPRITE) demobuf.p++; - if(ziptic & GZT_NIGHTS) { + if (ziptic & GZT_NIGHTS) + { if (!testmo || !testmo->player || !(testmo->player->pflags & PF_NIGHTSMODE) || !testmo->tracer) nightsfail = true; else @@ -6045,8 +6055,12 @@ void G_BeginRecording(void) UINT8 totalfiles; UINT8 *m; - if (demobuf.p) + if (!cv_recordmultiplayerdemos.value) return; + + if (demobuf.p || demobuf.buffer == NULL) + return; + memset(name,0,sizeof(name)); demobuf.p = demobuf.buffer; @@ -6056,7 +6070,7 @@ void G_BeginRecording(void) demoflags |= DF_ENCORE; if (!modeattacking && gL) // Ghosts don't read luavars, and you shouldn't ever need to save Lua in replays, you doof! - // SERIOUSLY THOUGH WHY WOULD YOU LOAD HOSTMOD AND RECORD A GHOST WITH IT !???? + // SERIOUSLY THOUGH WHY WOULD YOU LOAD HOSTMOD AND RECORD A GHOST WITH IT !???? demoflags |= DF_LUAVARS; // Setup header. @@ -6201,7 +6215,7 @@ void G_BeginMetal(void) { mobj_t *mo = players[consoleplayer].mo; - if (demobuf.p) + if (demobuf.p || demobuf.buffer == NULL) return; demobuf.p = demobuf.buffer; @@ -6229,7 +6243,10 @@ 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(demobuf.p, DEMOMARKER); // add the demo end marker *(UINT32 *)demoinfo_p = demobuf.p - demobuf.buffer; @@ -6815,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'; @@ -7810,7 +7830,7 @@ void G_StopMetalDemo(void) ATTRNORETURN void FUNCNORETURN G_StopMetalRecording(void) { boolean saved = false; - if (demobuf.p) + if (demobuf.p && demobuf.buffer != NULL) { UINT8 *p = demobuf.buffer+16; // checksum position #ifdef NOMD5 @@ -7972,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; diff --git a/src/p_setup.c b/src/p_setup.c index 280c91935..0e7f89dcf 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -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)); From a15615a2299835dda888daefaf4bf8d01b1f0cac Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Dec 2024 16:01:35 +0100 Subject: [PATCH 46/99] add missing include --- src/sdl/ogl_sdl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 65fae4dd4..9093f9a18 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -45,6 +45,8 @@ #include "../m_argv.h" #include "../i_video.h" +#include "../f_finale.h" + #ifdef DEBUG_TO_FILE #include #if defined (_WIN32) && !defined (__CYGWIN__) From eceb671ea801cb1c9816979fefd696d8b08a6ce5 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Dec 2024 16:01:35 +0100 Subject: [PATCH 47/99] add missing include --- src/sdl/ogl_sdl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 65fae4dd4..9093f9a18 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -45,6 +45,8 @@ #include "../m_argv.h" #include "../i_video.h" +#include "../f_finale.h" + #ifdef DEBUG_TO_FILE #include #if defined (_WIN32) && !defined (__CYGWIN__) From 66f89fb4adbcb7117aa95abe4bbad6216758382e Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Dec 2024 16:03:56 +0100 Subject: [PATCH 48/99] oops --- src/lua_baselib.c | 4 ++-- src/lua_script.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) 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_script.h b/src/lua_script.h index cf17ccbfa..9b8c65e20 100644 --- a/src/lua_script.h +++ b/src/lua_script.h @@ -63,7 +63,8 @@ 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); From 55dfdc723fe534f8c908676d839bb1198d89da7c Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Dec 2024 17:14:47 +0100 Subject: [PATCH 49/99] fix demo playback --- src/g_game.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index e48c53577..10367a293 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -6832,9 +6832,6 @@ 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'; From cbc3f8e917cafa63949520ca587bacc9dd74dd70 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Dec 2024 17:38:36 +0100 Subject: [PATCH 50/99] add warning for non allocated demobuffer --- src/g_game.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 10367a293..dd5a48a3d 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -6058,8 +6058,16 @@ void G_BeginRecording(void) if (!cv_recordmultiplayerdemos.value) return; - if (demobuf.p || demobuf.buffer == NULL) + if (demobuf.buffer == NULL) + { + CONS_Alert(CONS_ERROR, "Failed to allocate demo buffer\n"); return; + } + + if (demobuf.p) + { + return; + } memset(name,0,sizeof(name)); @@ -6215,7 +6223,13 @@ void G_BeginMetal(void) { mobj_t *mo = players[consoleplayer].mo; - if (demobuf.p || demobuf.buffer == NULL) + if (demobuf.buffer == NULL) + { + CONS_Alert(CONS_ERROR, "Failed to allocate demo buffer\n"); + return; + } + + if (demobuf.p) return; demobuf.p = demobuf.buffer; From 70e64d947145cdf21ccb896097102447738c5762 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Dec 2024 17:43:09 +0100 Subject: [PATCH 51/99] reset demo recording in those places --- src/g_game.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/g_game.c b/src/g_game.c index dd5a48a3d..8f6103551 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -6056,16 +6056,21 @@ void G_BeginRecording(void) UINT8 *m; if (!cv_recordmultiplayerdemos.value) + { + G_ResetDemoRecording(); return; + } if (demobuf.buffer == NULL) { CONS_Alert(CONS_ERROR, "Failed to allocate demo buffer\n"); + G_ResetDemoRecording(); return; } if (demobuf.p) { + G_ResetDemoRecording(); return; } @@ -6225,12 +6230,18 @@ void G_BeginMetal(void) if (demobuf.buffer == NULL) { - CONS_Alert(CONS_ERROR, "Failed to allocate demo buffer\n"); + CONS_Alert(CONS_ERROR, "Failed to allocate metal demo buffer\n"); + metalrecording = false; return; } if (demobuf.p) + { + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; + metalrecording = false; return; + } demobuf.p = demobuf.buffer; From b3323b7c2d19d7b2e73fe99f9fd926f3ba06b3f3 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Dec 2024 17:45:20 +0100 Subject: [PATCH 52/99] change error msg --- src/g_game.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 8f6103551..67e808476 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -6063,7 +6063,7 @@ void G_BeginRecording(void) if (demobuf.buffer == NULL) { - CONS_Alert(CONS_ERROR, "Failed to allocate demo buffer\n"); + CONS_Alert(CONS_ERROR, "No demo buffer allocated\n"); G_ResetDemoRecording(); return; } @@ -6230,7 +6230,7 @@ void G_BeginMetal(void) if (demobuf.buffer == NULL) { - CONS_Alert(CONS_ERROR, "Failed to allocate metal demo buffer\n"); + CONS_Alert(CONS_ERROR, "No metal demo buffer allocated\n"); metalrecording = false; return; } From aa222b68617b75fc00db2303be1468f99f31456a Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Dec 2024 11:10:41 +0100 Subject: [PATCH 53/99] slight cleanup director --- src/d_netcmd.c | 1 + src/g_game.c | 8 +++----- src/g_game.h | 2 -- src/k_director.c | 47 ++++++++++++++++++++++++----------------------- src/k_director.h | 1 + src/st_stuff.c | 9 +++------ src/st_stuff.h | 2 -- 7 files changed, 32 insertions(+), 38 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 076bb10e0..4f8a2b684 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -573,6 +573,7 @@ static CV_PossibleValue_t ps_descriptor_cons_t[] = { consvar_t cv_ps_descriptor = {"ps_descriptor", "Average", 0, ps_descriptor_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_director = {"director", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_kartdebugdirector = {"debugdirector", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_showdirectorhud = {"showdirectorhud", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; diff --git a/src/g_game.c b/src/g_game.c index 67e808476..e7dc9d92d 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -883,6 +883,7 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) thiscam = (player->bot == 2 ? &camera[0] : &camera[forplayer]); else thiscam = &camera[forplayer]; + lang = localangle[forplayer]; laim = localaiming[forplayer]; th = turnheld[forplayer]; @@ -1208,9 +1209,6 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) { displayplayers[0] = consoleplayer; G_FixCamera(1); - // i dont like this lmao - if (cv_director.value) - CV_SetValue(&cv_director, 0); } } @@ -1546,8 +1544,8 @@ boolean G_Responder(event_t *ev) COM_ImmedExecute("changeteam4 spectator"); } } - if (ev->data1 == gamecontrol[gc_director][0] - || ev->data1 == gamecontrol[gc_director][1]) + + if (ev->data1 == gamecontrol[gc_director][0] || ev->data1 == gamecontrol[gc_director][1]) { K_ToggleDirector(); } diff --git a/src/g_game.h b/src/g_game.h index 7c81ab79e..3a957d00a 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -438,8 +438,6 @@ FUNCMATH INT32 G_TicsToSeconds(tic_t tics); FUNCMATH INT32 G_TicsToCentiseconds(tic_t tics); FUNCMATH INT32 G_TicsToMilliseconds(tic_t tics); -boolean K_DirectorIsPlayerAlone(void); // idk where else to put this lol - // Don't split up TOL handling INT16 G_TOLFlag(INT32 pgametype); diff --git a/src/k_director.c b/src/k_director.c index dafea6072..611c64701 100644 --- a/src/k_director.c +++ b/src/k_director.c @@ -12,6 +12,7 @@ //#include "k_kart.h" #include "doomdef.h" +#include "doomstat.h" #include "g_game.h" #include "v_video.h" #include "k_director.h" @@ -28,6 +29,7 @@ struct directorinfo { + player_t* viewplayer; tic_t cooldown; // how long has it been since we last switched? tic_t freeze; // when nonzero, fixed switch pending, freeze logic! INT32 attacker; // who to switch to when freeze delay elapses @@ -38,7 +40,7 @@ struct directorinfo INT32 boredom[MAXPLAYERS]; // how long has a given position had no credible attackers? } directorinfo; -boolean K_DirectorIsPlayerAlone(void) +static boolean K_DirectorIsPlayerAlone(void) { UINT8 pingame = 0; @@ -67,9 +69,16 @@ static fixed_t ScaleFromMap(fixed_t n, fixed_t scale) return FixedMul(n, FixedDiv(scale, mapobjectscale)); } +boolean K_DirectorIsAvailable(void) +{ + if ((demo.playback && demo.title) || modeattacking) + return false; + return ((gamestate == GS_LEVEL) && (demo.playback || (players[consoleplayer].spectator && !K_DirectorIsPlayerAlone()))); +} + static boolean K_DirectorIsEnabled(void) { - return cv_director.value && !splitscreen && (gamestate == GS_LEVEL && (((!playeringame[consoleplayer] || players[consoleplayer].spectator)) || (demo.playback && !demo.freecam && (!demo.title || !modeattacking))) && !K_DirectorIsPlayerAlone()); + return (cv_director.value && K_DirectorIsAvailable()); } void K_InitDirector(void) @@ -80,6 +89,7 @@ void K_InitDirector(void) directorinfo.freeze = 0; directorinfo.attacker = 0; directorinfo.maxdist = 0; + directorinfo.viewplayer = NULL; for (playernum = 0; playernum < MAXPLAYERS; playernum++) { @@ -104,8 +114,8 @@ static fixed_t K_GetDistanceToFinish(player_t player) continue; dist = P_AproxDistance(P_AproxDistance(mo->x - player.mo->x, - mo->y - player.mo->y), - mo->z - player.mo->z) / FRACUNIT; + mo->y - player.mo->y), + mo->z - player.mo->z) / FRACUNIT; break; } @@ -124,7 +134,7 @@ static fixed_t K_GetDistanceToFinish(player_t player) dist = P_AproxDistance(P_AproxDistance(mo->x - player.mo->x, mo->y - player.mo->y), - mo->z - player.mo->z) / FRACUNIT; + mo->z - player.mo->z) / FRACUNIT; break; } @@ -213,11 +223,6 @@ static void K_DirectorSwitch(INT32 player, boolean force) return; } - if (P_IsDisplayPlayer(&players[player])) - { - return; - } - if (players[player].exiting) { return; @@ -250,7 +255,7 @@ void K_DirectorFollowAttack(player_t *player, mobj_t *inflictor, mobj_t *source) return; } - if (!P_IsDisplayPlayer(player)) + if (directorinfo.viewplayer != player) { return; } @@ -319,8 +324,8 @@ void K_DrawDirectorDebugger(void) void K_UpdateDirector(void) { - INT32 *displayplayerp = &displayplayers[0]; INT32 targetposition; + directorinfo.viewplayer = &players[displayplayers[0]]; if (!K_DirectorIsEnabled()) { @@ -391,25 +396,19 @@ void K_UpdateDirector(void) target = directorinfo.sortedplayers[targetposition]; // stop here since we're already viewing this player - if (*displayplayerp == target) + if (displayplayers[0] == target) { break; } - // if this is a splitscreen player, try next pair - if (P_IsDisplayPlayer(&players[target])) - { - continue; - } - // if we're certain the back half of the pair is actually in this position, try to switch if (!players[target].kartstuff[k_positiondelay]) { K_DirectorSwitch(target, false); } - // even if we're not certain, if we're certain we're watching the WRONG player, try to switch - if (players[*displayplayerp].kartstuff[k_position] != targetposition+1 && !players[*displayplayerp].kartstuff[k_positiondelay]) + // even if we're not certain, if we're cetain we're watching the WRONG player, try to switch + if (directorinfo.viewplayer->kartstuff[k_position] != targetposition+1 && !directorinfo.viewplayer->kartstuff[k_positiondelay]) { K_DirectorSwitch(target, false); } @@ -420,9 +419,11 @@ void K_UpdateDirector(void) void K_ToggleDirector(void) { - if (!directortextactive) + if (!K_DirectorIsAvailable()) return; + G_AdjustView(1, 1, true); + if (!K_DirectorIsEnabled()) { directorinfo.cooldown = 0; // switch immediately @@ -430,5 +431,5 @@ void K_ToggleDirector(void) directortoggletimer = 0; - COM_ImmedExecute("add director 1"); + CV_SetValue(&cv_director, (cv_director.value ^ 1)); } diff --git a/src/k_director.h b/src/k_director.h index 3be71b675..30b44d9cf 100644 --- a/src/k_director.h +++ b/src/k_director.h @@ -10,6 +10,7 @@ /// \file k_director.h /// \brief SRB2kart automatic spectator camera. +boolean K_DirectorIsAvailable(void); void K_InitDirector(void); void K_UpdateDirector(void); void K_DrawDirectorDebugger(void); diff --git a/src/st_stuff.c b/src/st_stuff.c index 30b8b5cf7..aaa926515 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -16,6 +16,7 @@ #include "doomdef.h" #include "g_game.h" #include "g_input.h" +#include "k_director.h" #include "r_local.h" #include "p_local.h" #include "f_finale.h" @@ -156,8 +157,6 @@ static patch_t *envelope; player_t *stplyr; UINT8 stplyrnum; -boolean directortextactive = false; - // SRB2kart hudinfo_t hudinfo[NUMHUDITEMS] = @@ -665,14 +664,13 @@ static void ST_overlayDrawer(void) if (!hu_showscores) // hide the following if TAB is held { - if (cv_showdirectorhud.value && !splitscreen && ((demo.playback && !demo.freecam && (!demo.title || !modeattacking)) || !P_IsLocalPlayer(stplyr)) && !K_DirectorIsPlayerAlone()) + // TODO: splitscreen support! + if (cv_showdirectorhud.value && !splitscreen && !P_IsLocalPlayer(stplyr) && K_DirectorIsAvailable()) { char directortext[20] = {0}; snprintf(directortext, 20, "Director: %s", cv_director.value ? "On" : "Off"); - directortextactive = true; - if ((!demo.playback && directortoggletimer < 13*TICRATE) || (demo.playback && directortoggletimer < 4*TICRATE)) { if (renderisnewtic) @@ -687,7 +685,6 @@ static void ST_overlayDrawer(void) else { directortoggletimer = 0; - directortextactive = false; } if (cv_showviewpointtext.value) diff --git a/src/st_stuff.h b/src/st_stuff.h index 308dae2a0..250db1e7f 100644 --- a/src/st_stuff.h +++ b/src/st_stuff.h @@ -146,6 +146,4 @@ extern UINT16 objectsdrawn; extern consvar_t cv_lessflicker; extern consvar_t cv_stagetitle; -extern boolean directortextactive; - #endif From 588dac343ea6270ab1831a28d95c86b878c3881c Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Dec 2024 11:24:14 +0100 Subject: [PATCH 54/99] dont disable this.... if its disabled kek --- src/m_menu.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index a4121d448..8cfe16a97 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3396,12 +3396,10 @@ void PDistort_menu_Onchange(void) { if (!cv_sloperoll.value) { - OP_PlayerDistortMenu[sloperotate].status = IT_GRAYEDOUT; OP_PlayerDistortMenu[sliptide].status = IT_GRAYEDOUT; } else { - OP_PlayerDistortMenu[sloperotate].status = IT_STRING | IT_CVAR; OP_PlayerDistortMenu[sliptide].status = IT_STRING | IT_CVAR; } From aca48d45b32f5ec09c960a999f5e5abb1273731f Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Dec 2024 17:29:27 +0100 Subject: [PATCH 55/99] fix potential crash with perfstats https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2576 --- src/m_perfstats.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/m_perfstats.c b/src/m_perfstats.c index 3c5526678..14980b162 100644 --- a/src/m_perfstats.c +++ b/src/m_perfstats.c @@ -452,7 +452,7 @@ static int PS_DrawPerfRows(int x, int y, int color, perfstatrow_t *rows) return draw_y; } -static void PS_UpdateMetricHistory(ps_metric_t *metric, boolean time_metric, boolean frame_metric, boolean set_user) +static void PS_UpdateMetricHistory(ps_metric_t *metric, boolean time_metric, boolean frame_metric) { int index = frame_metric ? ps_frame_index : ps_tick_index; @@ -460,7 +460,7 @@ static void PS_UpdateMetricHistory(ps_metric_t *metric, boolean time_metric, boo { // allocate history table int value_size = time_metric ? sizeof(precise_t) : sizeof(INT32); - void** memory_user = set_user ? &metric->history : NULL; + void** memory_user = &metric->history; metric->history = Z_Calloc(value_size * cv_ps_samplesize.value, PU_PERFSTATS, memory_user); @@ -490,7 +490,7 @@ static void PS_UpdateRowHistories(perfstatrow_t *rows, boolean frame_metric) for (row = rows; row->lores_label; row++) { if (PS_IsRowValid(row)) - PS_UpdateMetricHistory(row->metric, !!(row->flags & PS_TIME), frame_metric, true); + PS_UpdateMetricHistory(row->metric, !!(row->flags & PS_TIME), frame_metric); } } @@ -670,17 +670,17 @@ void PS_UpdateTickStats(void) if (cv_perfstats.value == 3) { for (i = 0; i < thinkframe_hooks_length; i++) - PS_UpdateMetricHistory(&thinkframe_hooks[i].time_taken, true, false, false); + PS_UpdateMetricHistory(&thinkframe_hooks[i].time_taken, true, false); } else if (cv_perfstats.value == 4) { for (i = 0; i < prethinkframe_hooks_length; i++) - PS_UpdateMetricHistory(&prethinkframe_hooks[i].time_taken, true, false, false); + PS_UpdateMetricHistory(&prethinkframe_hooks[i].time_taken, true, false); } else if (cv_perfstats.value == 5) { for (i = 0; i < postthinkframe_hooks_length; i++) - PS_UpdateMetricHistory(&postthinkframe_hooks[i].time_taken, true, false, false); + PS_UpdateMetricHistory(&postthinkframe_hooks[i].time_taken, true, false); } } if (cv_perfstats.value) From 182500c2d2880fb6e2a7263702b5b2ec3bd11177 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Dec 2024 17:34:13 +0100 Subject: [PATCH 56/99] fix potential Fix segfault when aborting HTTP download --- src/d_netfil.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/d_netfil.c b/src/d_netfil.c index 2559cbcf1..fd0bf879c 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -111,6 +111,7 @@ static fileused_t transferFiles[UINT8_MAX + 1]; // Receiver structure INT32 fileneedednum; // Number of files needed to join the server fileneeded_t fileneeded[MAX_WADFILES]; // List of needed files +static I_mutex downloadmutex; char downloaddir[512] = "DOWNLOAD"; #ifdef CLIENT_LOADINGSCREEN @@ -1327,6 +1328,7 @@ void CURLPrepareFile(const char* url, int dfilenum) curl_starttime = time(NULL); curl_running = true; + #ifdef HAVE_THREADS I_spawn_thread("http-download", (I_thread_fn)CURLGetFile, NULL); #endif @@ -1336,10 +1338,15 @@ void CURLPrepareFile(const char* url, int dfilenum) void CURLAbortFile(void) { curl_running = false; + + // lock and unlock to wait for the download thread to exit + I_lock_mutex(&downloadmutex); + I_unlock_mutex(downloadmutex); } void CURLGetFile(void) { + I_lock_mutex(&downloadmutex); CURLMcode mc; /* return code used by curl_multi_wait() */ CURLcode easyres; /* Return from easy interface */ CURLMsg *m; /* for picking up messages with the transfer status */ @@ -1432,6 +1439,7 @@ void CURLGetFile(void) multi_handle = NULL; } curl_running = false; + I_unlock_mutex(downloadmutex); } HTTP_login * From 82f9f2f73faf21a5902947cc236bdf24de66f499 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 14 Dec 2024 22:49:03 +0100 Subject: [PATCH 57/99] delet all the hardware sound crap psure it doesent even properly work at this point --- src/Makefile | 73 +- src/d_main.c | 11 - src/doomdef.h | 18 +- src/hardware/hw3dsdrv.h | 85 -- src/hardware/hw3sound.c | 996 ------------- src/hardware/hw3sound.h | 106 -- src/hardware/hws_data.h | 123 -- src/hardware/s_ds3d/s_ds3d.c | 1237 ----------------- src/hardware/s_ds3d/s_ds3d.dev | 59 - src/hardware/s_ds3d/s_ds3d.dsp | 99 -- src/hardware/s_fmod/s_fmod.c | 1201 ---------------- src/hardware/s_fmod/s_fmod.dev | 59 - src/hardware/s_fmod/s_fmod.dsp | 97 -- src/hardware/s_openal/s_openal.c | 998 ------------- src/hardware/s_openal/s_openal.dev | 59 - src/hardware/s_openal/s_openal.dsp | 98 -- src/locale/en.po | 30 - src/locale/srb2.pot | 30 - src/p_enemy.c | 4 - src/p_spec.c | 4 - src/p_user.c | 4 - src/s_sound.c | 88 +- src/s_sound.h | 2 - src/sdl/Makefile.cfg | 16 - src/sdl/Srb2SDL.dsp | 29 +- src/sdl/Srb2SDL.dsw | 12 - src/sdl/Srb2SDL.props | 6 +- src/sdl/hwsym_sdl.c | 31 +- src/sdl/macosx/Srb2mac.pbproj/project.pbxproj | 80 +- .../macosx/Srb2mac.xcodeproj/project.pbxproj | 22 - src/sdl/sdl_sound.c | 210 +-- 31 files changed, 37 insertions(+), 5850 deletions(-) delete mode 100644 src/hardware/hw3dsdrv.h delete mode 100644 src/hardware/hw3sound.c delete mode 100644 src/hardware/hw3sound.h delete mode 100644 src/hardware/hws_data.h delete mode 100644 src/hardware/s_ds3d/s_ds3d.c delete mode 100644 src/hardware/s_ds3d/s_ds3d.dev delete mode 100644 src/hardware/s_ds3d/s_ds3d.dsp delete mode 100644 src/hardware/s_fmod/s_fmod.c delete mode 100644 src/hardware/s_fmod/s_fmod.dev delete mode 100644 src/hardware/s_fmod/s_fmod.dsp delete mode 100644 src/hardware/s_openal/s_openal.c delete mode 100644 src/hardware/s_openal/s_openal.dev delete mode 100644 src/hardware/s_openal/s_openal.dsp diff --git a/src/Makefile b/src/Makefile index 111e586b4..3b090873f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -31,18 +31,6 @@ # compile all HW render and 3D sound DLLs for the set # opengl_dll # Pure Mingw only, compile OpenGL HW render DLL -# minigl_dll -# Pure Mingw only, compile MiniGL HW render DLL -# ds3d_dll -# Pure Mingw only, compile DirectX DirectSound HW sound DLL -# fmod_dll -# Pure Mingw only, compile FMOD HW sound DLL -# openal_dll -# Pure Mingw only, compile OpenAL HW sound DLL -# fmod_so -# Non-Mingw, compile FMOD HW sound SO -# openal_so -# Non-Mingw, compile OpenAL HW sound SO # # # Addon: @@ -69,10 +57,7 @@ # Compile without SDL_Mixer, add 'NOMIXER=1' # Compile without BSD API, add 'NONET=1' # Compile without IPX/SPX, add 'NOIPX=1' -# Compile Mingw/SDL with S_DS3S, add 'DS3D=1' # Compile without libopenmpt, add 'NOOPENMPT=1' -# Compile with S_FMOD3D, add 'FMOD=1' (WIP) -# Compile with S_OPENAL, add 'OPENAL=1' (WIP) # To link with the whole SDL_Image lib to load Icons, add 'SDL_IMAGE=1' but it isn't not realy needed # To link with SDLMain to hide console or make on a console-less binary, add 'SDLMAIN=1' # @@ -691,7 +676,7 @@ else dll : opengl_dll endif ifdef MINGW -all_dll: opengl_dll ds3d_dll fmod_dll openal_dll +all_dll: opengl_dll opengl_dll: $(BIN)/r_opengl.dll $(BIN)/r_opengl.dll: $(OBJDIR)/ogl_win.o $(OBJDIR)/r_opengl.o @@ -701,37 +686,6 @@ $(BIN)/r_opengl.dll: $(OBJDIR)/ogl_win.o $(OBJDIR)/r_opengl.o ifndef NOUPX -$(UPX) $(UPX_OPTS) $@ endif - -ds3d_dll: $(BIN)/s_ds3d.dll -$(BIN)/s_ds3d.dll: $(OBJDIR)/s_ds3d.o - @echo Linking S_DS3d.dll... - $(CC) --shared $^ -o $@ -g -Wl,--add-stdcall-alias -ldsound -luuid - -fmod_dll: $(BIN)/s_fmod.dll -$(BIN)/s_fmod.dll: $(OBJDIR)/s_fmod.o - -$(MKDIR) $(BIN) - @echo Linking S_FMOD.dll... - $(CC) --shared $^ -o $@ -g -Wl,--add-stdcall-alias -lfmod - -openal_dll: $(BIN)/s_openal.dll -$(BIN)/s_openal.dll: $(OBJDIR)/s_openal.o - -$(MKDIR) $(BIN) - @echo Linking S_OpenAL.dll... - $(CC) --shared $^ -o $@ -g -Wl,--add-stdcall-alias -lopenal32 -else -all_dll: fmod_so openal_so - -fmod_so: $(BIN)/s_fmod.so -$(BIN)/s_fmod.so: $(OBJDIR)/s_fmod.o - -$(MKDIR) $(BIN) - @echo Linking S_FMOD.so... - $(CC) --shared $^ -o $@ -g --nostartfiles -lm -lfmod - -openal_so: $(BIN)/s_openal.so -$(BIN)/s_openal.so: $(OBJDIR)/s_openal.o - -$(MKDIR) $(BIN) - @echo Linking S_OpenAL.so... - $(CC) --shared $^ -o $@ -g --nostartfiles -lm -lopenal endif else @@ -823,31 +777,6 @@ $(OBJDIR)/win_dbg.o: win32/win_dbg.c $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ endif -ifdef STATICHS -$(OBJDIR)/s_openal.o: hardware/s_openal/s_openal.c hardware/hw3dsdrv.h \ - hardware/hw_dll.h - $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ - -$(OBJDIR)/s_fmod.o: hardware/s_fmod/s_fmod.c hardware/hw3dsdrv.h \ - hardware/hw_dll.h - $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ - -ifdef MINGW -$(OBJDIR)/s_ds3d.o: hardware/s_ds3d/s_ds3d.c hardware/hw3dsdrv.h \ - hardware/hw_dll.h - $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ -endif -else - -$(OBJDIR)/s_fmod.o: hardware/s_fmod/s_fmod.c hardware/hw3dsdrv.h \ - hardware/hw_dll.h - $(CC) $(ARCHOPTS) -Os -o $(OBJDIR)/s_fmod.o -DHW3SOUND -DUNIXCOMMON -shared -nostartfiles -c hardware/s_fmod/s_fmod.c - -$(OBJDIR)/s_openal.o: hardware/s_openal/s_openal.c hardware/hw3dsdrv.h \ - hardware/hw_dll.h - $(CC) $(ARCHOPTS) -Os -o $(OBJDIR)/s_openal.o -DHW3SOUND -DUNIXCOMMON -shared -nostartfiles -c hardware/s_openal/s_openal.c -endif - ifdef FILTERS $(OBJDIR)/%.o: $(INTERFACE)/filter/%.c @echo $< needs deps diff --git a/src/d_main.c b/src/d_main.c index 642870a86..a44c12ad6 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -85,10 +85,6 @@ #include "hardware/hw_main.h" // 3D View Rendering #endif -#ifdef HW3SOUND -#include "hardware/hw3sound.h" -#endif - #ifdef HAVE_DISCORDRPC #include "discord.h" #endif @@ -737,10 +733,6 @@ void D_SRB2Loop(void) interp = R_UsingFrameInterpolation() && !dedicated; doDisplay = false; -#ifdef HW3SOUND - HW3S_BeginFrameUpdate(); -#endif - renderisnewtic = (realtics > 0 || singletics); if (renderisnewtic) @@ -848,9 +840,6 @@ void D_SRB2Loop(void) // consoleplayer -> displayplayers (hear sounds from viewpoint) S_UpdateSounds(); // move positional sounds -#ifdef HW3SOUND - HW3S_EndFrameUpdate(); -#endif LUA_Step(); diff --git a/src/doomdef.h b/src/doomdef.h index c8d2a28f7..8751b6a86 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -21,7 +21,6 @@ #define SOUND_DUMMY 0 #define SOUND_SDL 1 #define SOUND_MIXER 2 -#define SOUND_FMOD 3 #ifndef SOUND #ifdef HAVE_SDL @@ -29,9 +28,6 @@ // Use Mixer interface? #ifdef HAVE_MIXER #define SOUND SOUND_MIXER - #ifdef HW3SOUND - #undef HW3SOUND - #endif #endif // Use generic SDL interface. @@ -40,18 +36,8 @@ #endif #else // No SDL. - -// Use FMOD? -#ifdef HAVE_FMOD - #define SOUND SOUND_FMOD - #ifdef HW3SOUND - #undef HW3SOUND - #endif -#else - // No more interfaces. :( - #define SOUND SOUND_DUMMY -#endif - +// No more interfaces. :( +#define SOUND SOUND_DUMMY #endif #endif diff --git a/src/hardware/hw3dsdrv.h b/src/hardware/hw3dsdrv.h deleted file mode 100644 index 8811d4546..000000000 --- a/src/hardware/hw3dsdrv.h +++ /dev/null @@ -1,85 +0,0 @@ -// Emacs style mode select -*- C++ -*- -//----------------------------------------------------------------------------- -// -// Copyright (C) 2001 by DooM Legacy Team. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -//----------------------------------------------------------------------------- -/// \file -/// \brief 3D sound import/export prototypes for low-level hardware interface - -#ifndef __HW_3DS_DRV_H__ -#define __HW_3DS_DRV_H__ - -// Use standart hardware API -#include "hw_dll.h" -#include "hws_data.h" - -#if defined (HAVE_SDL) || !defined (HWD) -EXPORT void HWRAPI(Shutdown) (void); -#endif - -// Use standart Init and Shutdown functions - -EXPORT INT32 HWRAPI (Startup) (I_Error_t FatalErrorFunction, snddev_t *snd_dev); -EXPORT u_int HWRAPI (AddSfx) (sfx_data_t *sfx); -EXPORT INT32 HWRAPI (AddSource) (source3D_data_t *src, u_int sfxhandle); -EXPORT INT32 HWRAPI (StartSource) (INT32 handle); -EXPORT void HWRAPI (StopSource) (INT32 handle); -EXPORT INT32 HWRAPI (GetHW3DSVersion) (void); -EXPORT void HWRAPI (BeginFrameUpdate) (void); -EXPORT void HWRAPI (EndFrameUpdate) (void); -EXPORT INT32 HWRAPI (IsPlaying) (INT32 handle); -EXPORT void HWRAPI (UpdateListener) (listener_data_t *data, INT32 num); -EXPORT void HWRAPI (UpdateSourceParms) (INT32 handle, INT32 vol, INT32 sep); -EXPORT void HWRAPI (SetGlobalSfxVolume) (INT32 volume); -EXPORT INT32 HWRAPI (SetCone) (INT32 handle, cone_def_t *cone_def); -EXPORT void HWRAPI (Update3DSource) (INT32 handle, source3D_pos_t *data); -EXPORT INT32 HWRAPI (ReloadSource) (INT32 handle, u_int sfxhandle); -EXPORT void HWRAPI (KillSource) (INT32 handle); -EXPORT void HWRAPI (KillSfx) (u_int sfxhandle); -EXPORT void HWRAPI (GetHW3DSTitle) (char *buf, size_t size); - - -#if !defined (_CREATE_DLL_) - -struct hardware3ds_s -{ - Startup pfnStartup; - AddSfx pfnAddSfx; - AddSource pfnAddSource; - StartSource pfnStartSource; - StopSource pfnStopSource; - GetHW3DSVersion pfnGetHW3DSVersion; - BeginFrameUpdate pfnBeginFrameUpdate; - EndFrameUpdate pfnEndFrameUpdate; - IsPlaying pfnIsPlaying; - UpdateListener pfnUpdateListener; - UpdateSourceParms pfnUpdateSourceParms; - SetGlobalSfxVolume pfnSetGlobalSfxVolume; - SetCone pfnSetCone; - Update3DSource pfnUpdate3DSource; - ReloadSource pfnReloadSource; - KillSource pfnKillSource; - KillSfx pfnKillSfx; - Shutdown pfnShutdown; - GetHW3DSTitle pfnGetHW3DSTitle; -}; - -extern struct hardware3ds_s hw3ds_driver; - -#define HW3DS hw3ds_driver - - -#endif // _CREATE_DLL_ - -#endif // __HW_3DS_DRV_H__ diff --git a/src/hardware/hw3sound.c b/src/hardware/hw3sound.c deleted file mode 100644 index 2594a5df9..000000000 --- a/src/hardware/hw3sound.c +++ /dev/null @@ -1,996 +0,0 @@ -// Emacs style mode select -*- C++ -*- -//----------------------------------------------------------------------------- -// -// Copyright (C) 2001 by DooM Legacy Team. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -//----------------------------------------------------------------------------- -/// \file -/// \brief Hardware 3D sound general code - -#include "../doomdef.h" - -#ifdef HW3SOUND - -#include "../i_sound.h" -#include "../s_sound.h" -#include "../w_wad.h" -#include "../z_zone.h" -#include "../g_game.h" -#include "../tables.h" -#include "../sounds.h" -#include "../r_main.h" -#include "../r_things.h" -#include "../m_random.h" -#include "../p_local.h" -#include "hw3dsdrv.h" -#include "hw3sound.h" - -#define ANGLE2DEG(x) (((double)(x)) / ((double)ANGLE_45/45)) -#define NORM_PITCH 128 -#define NORM_PRIORITY 64 -#define NORM_SEP 128 -#if 1 -#define TPS(x) (x) -#else //Alam_GBC: MPS, not MPF! -#define TPS(x) ((float)(x)/(float)TICRATE) -#endif - -struct hardware3ds_s hw3ds_driver; - - -typedef struct source_s -{ - sfxinfo_t *sfxinfo; - const void *origin; - INT32 handle; // Internal source handle - channel_type_t type; // Sound type (attack, scream, etc) -} source_t; - - -typedef struct ambient_sdata_s -{ - source3D_data_t left; - source3D_data_t right; -} ambient_sdata_t; - - -typedef struct ambient_source_s -{ - source_t left; - source_t right; -} ambient_source_t; - -// Static sources -// This sources always creates -static source_t p_attack_source; // Player attack source -static source_t p_attack_source2; // Player2 attack source -static source_t p_scream_source; // Player scream source -static source_t p_scream_source2; // Player2 scream source - - -static ambient_source_t ambient_source; // Ambinet sound sources - -// abuse??? -//static source3D_data_t p_attack_sdata; // ?? Now just holds precalculated player attack source data -//static source3D_data_t p_default_sdata;// ?? ---- // ---- // ---- // ---- player scream source data - -static ambient_sdata_t ambient_sdata; // Precalculated datas of an ambient sound sources - -// Stack of dynamic sources -static source_t *sources = NULL; // Much like original channels -static INT32 num_sources = 0; - -// Current mode of 3D sound system -// Default is original (stereo) mode -INT32 hws_mode = HWS_DEFAULT_MODE; - -//============================================================================= -void HW3S_SetSourcesNum(void) -{ - INT32 i; - - // Allocating the internal channels for mixing - // (the maximum number of sounds rendered - // simultaneously) within zone memory. - if (sources) - HW3S_StopSounds(); - Z_Free(sources); - - if (cv_numChannels.value <= STATIC_SOURCES_NUM) - I_Error("HW3S_SetSourcesNum: Number of sound sources cannot be less than %d\n", STATIC_SOURCES_NUM + 1); - - num_sources = cv_numChannels.value - STATIC_SOURCES_NUM; - - sources = (source_t *) Z_Malloc(num_sources * sizeof (*sources), PU_STATIC, 0); - - // Free all channels for use - for (i = 0; i < num_sources; i++) - { - sources[i].sfxinfo = NULL; - sources[i].type = CT_NORMAL; - sources[i].handle = -1; - } -} - - -//============================================================================= -static void HW3S_KillSource(INT32 snum) -{ - source_t * s = &sources[snum]; - - if (s->sfxinfo) - { - HW3DS.pfnStopSource(s->handle); - HW3DS.pfnKillSource(s->handle); - s->handle = -1; - s->sfxinfo->usefulness--; - s->origin = NULL; - s->sfxinfo = NULL; - } -} - - -//============================================================================= -/* -static void HW3S_StopSource(INT32 snum) -{ - source_t * s = &sources[snum]; - - if (s->sfxinfo) - { - // stop the sound playing - HW3DS.pfnStopSource(s->handle); - } -} -*/ - - -//============================================================================= -void HW3S_StopSound(void *origin) -{ - INT32 snum; - - for (snum = 0; snum < num_sources; snum++) - { - if (sources[snum].sfxinfo && sources[snum].origin == origin) - { - HW3S_KillSource(snum); - break; - } - } -} - -void HW3S_StopSoundByID(void *origin, sfxenum_t sfx_id) -{ - INT32 snum; - - for (snum = 0; snum < num_sources; snum++) - { - if (sources[snum].sfxinfo == &S_sfx[sfx_id] && sources[snum].origin == origin) - { - HW3S_KillSource(snum); - break; - } - } -} - -void HW3S_StopSoundByNum(sfxenum_t sfxnum) -{ - INT32 snum; - - for (snum = 0; snum < num_sources; snum++) - { - if (sources[snum].sfxinfo == &S_sfx[sfxnum]) - { - HW3S_KillSource(snum); - break; - } - } -} - -//============================================================================= -void HW3S_StopSounds(void) -{ - INT32 snum; - - // kill all playing sounds at start of level - // (trust me - a good idea) - for (snum = 0; snum < num_sources; snum++) - if (sources[snum].sfxinfo) - HW3S_KillSource(snum); - - // Also stop all static sources - HW3DS.pfnStopSource(p_attack_source.handle); - HW3DS.pfnStopSource(p_attack_source2.handle); - HW3DS.pfnStopSource(p_scream_source.handle); - HW3DS.pfnStopSource(p_scream_source2.handle); - HW3DS.pfnStopSource(ambient_source.left.handle); - HW3DS.pfnStopSource(ambient_source.right.handle); -} - - -//============================================================================= -static INT32 HW3S_GetSource(const void *origin, sfxinfo_t *sfxinfo, boolean splitsound) -{ - // - // If none available, return -1. Otherwise source #. - // source number to use - - INT32 snum; - source_t * src; - INT32 sep = NORM_SEP, pitch = NORM_PITCH, volume = 255; - - (void)splitsound; - - // Find an open source - for (snum = 0, src = sources; snum < num_sources; src++, snum++) - { - if (!src->sfxinfo) - break; - -#if 0 - if (origin && src->origin == origin) - { - HW3S_KillSource(snum); - break; - } -#endif - } - -#if 0 - // Check to see if it is audible - if (origin && origin != listenmobj) - { - INT32 rc; - rc = S_AdjustSoundParams(listenmobj, origin, &volume, &sep, &pitch, sfxinfo); - if (!rc) - return -1; - } -#else - (void)origin; - (void)pitch; - (void)volume; - (void)sep; -#endif - - // None available - if (snum == num_sources) - { - // Look for lower priority - for (snum = 0, src = sources; snum < num_sources; src++, snum++) - if (src->sfxinfo->priority <= sfxinfo->priority) - break; - - if (snum == num_sources) - { - // No lower priority. Sorry, Charlie. - return -1; - } - else - { - // Otherwise, kick out lower priority - HW3S_KillSource(snum); - } - } - return snum; -} - - -//============================================================================= -static void HW3S_FillSourceParameters - (const mobj_t *origin, - source3D_data_t *data, - channel_type_t c_type) -{ - fixed_t x = 0, y = 0, z = 0; - - data->max_distance = MAX_DISTANCE; - data->min_distance = MIN_DISTANCE; - - if (origin && origin != players[displayplayers[0]].mo) - { - data->head_relative = false; - - data->pos.momx = TPS(FIXED_TO_FLOAT(origin->momx)); - data->pos.momy = TPS(FIXED_TO_FLOAT(origin->momy)); - data->pos.momz = TPS(FIXED_TO_FLOAT(origin->momz)); - - x = origin->x; - y = origin->y; - z = origin->z; - - if (c_type == CT_ATTACK) - { - const angle_t an = origin->angle >> ANGLETOFINESHIFT; - x += FixedMul(16*FRACUNIT, FINECOSINE(an)); - y += FixedMul(16*FRACUNIT, FINESINE(an)); - z += origin->height >> 1; - } - - else if (c_type == CT_SCREAM) - z += origin->height - (5 * FRACUNIT); - } - else - { - data->head_relative = true; - - data->pos.momx = 0.0f; - data->pos.momy = 0.0f; - data->pos.momz = 0.0f; - } - data->pos.x = FIXED_TO_FLOAT(x); - data->pos.y = FIXED_TO_FLOAT(y); - data->pos.z = FIXED_TO_FLOAT(z); -} - -#define HEADER_SIZE 8 -//============================================================== -/* -static void make_outphase_sfx(void *dest, void *src, INT32 size) -{ - SINT8 *s = (SINT8 *)src + HEADER_SIZE, *d = (SINT8 *)dest + HEADER_SIZE; - - M_Memcpy(dest, src, HEADER_SIZE); - size -= HEADER_SIZE; - - while (size--) - *d++ = -(*s++); -} -*/ - -//INT32 HW3S_Start3DSound(const void *origin, source3D_data_t *source_parm, cone_def_t *cone_parm, channel_type_t channel, INT32 sfx_id, INT32 vol, INT32 pitch); -//============================================================================= -INT32 HW3S_I_StartSound(const void *origin_p, source3D_data_t *source_parm, channel_type_t c_type, sfxenum_t sfx_id, INT32 volume, INT32 pitch, INT32 sep) -{ - sfxinfo_t *sfx; - const mobj_t *origin = (const mobj_t *)origin_p; - source3D_data_t source3d_data; - INT32 s_num = 0; - source_t *source = NULL; - mobj_t *listenmobj = players[displayplayers[0]].mo; // TODO: Kart 4P does not support sounds properly here - mobj_t *listenmobj2 = NULL; - - if (splitscreen) listenmobj2 = players[displayplayers[1]].mo; - - if (sound_disabled) - return -1; - - sfx = &S_sfx[sfx_id]; - - if (sfx->skinsound!=-1 && origin && origin->skin) - { - // it redirect player sound to the sound in the skin table - sfx_id = ((skin_t *)origin->skin)->soundsid[sfx->skinsound]; - sfx = &S_sfx[sfx_id]; - } - - if (!sfx->data) - sfx->data = HW3S_GetSfx(sfx); - - // judgecutor 08-16-2002 - // Sound pitching for both Doom and Heretic -#if 0 - if (cv_rndsoundpitch.value) - { - /*if (gamemode != heretic) - { - if (sfx_id >= sfx_sawup && sfx_id <= sfx_sawhit) - pitch += 8 - (M_RandomByte()&15); - else if (sfx_id != sfx_itemup && sfx_id != sfx_tink) - pitch += 16 - (M_RandomByte()&31); - } - else*/ - pitch = 128 + (M_RandomByte() & 7) - (M_RandomByte() & 7); - } -#endif - - if (pitch < 0) - pitch = NORMAL_PITCH; - - if (pitch > 255) - pitch = 255; - - if (sep < 0) - sep = 128; - - if (splitscreen && listenmobj2) // Copy the sound for the split player - { - if (c_type != CT_NORMAL && origin && (origin == listenmobj2)) - { - if (c_type == CT_ATTACK) - { - if (origin == listenmobj2) - source = &p_attack_source; - else - source = &p_attack_source2; - } - else - { - if (origin == listenmobj2) - source = &p_scream_source; - else - source = &p_scream_source2; - } - - if (source->sfxinfo != sfx) - { - HW3DS.pfnStopSource(source->handle); - source->handle = HW3DS.pfnReloadSource(source->handle, sfx->volume); - //I_OutputMsg("PlayerSound data reloaded\n"); - } - } - else if (c_type == CT_AMBIENT) - { - // sfx_data_t outphased_sfx; - - if (ambient_source.left.sfxinfo != sfx) - { - HW3DS.pfnStopSource(ambient_source.left.handle); - HW3DS.pfnStopSource(ambient_source.right.handle); - - // judgecutor: - // Outphased sfx's temporarily not used!!! - /* - outphased_sfx.data = Z_Malloc(sfx_data.length, PU_STATIC, 0); - make_outphase_sfx(outphased_sfx.data, sfx_data.data, sfx_data.length); - outphased_sfx.length = sfx_data.length; - outphased_sfx.id = sfx_data.id; - */ - ambient_source.left.handle = HW3DS.pfnReloadSource(ambient_source.left.handle, (u_int)sfx->length); - //ambient_source.right.handle = HW3DS.pfnReloadSource(ambient_source.right.handle, &outphased_sfx); - ambient_source.right.handle = HW3DS.pfnReloadSource(ambient_source.right.handle, (u_int)sfx->length); - ambient_source.left.sfxinfo = ambient_source.right.sfxinfo = sfx; - //Z_Free(outphased_sfx.data); - } - - HW3DS.pfnUpdateSourceParms(ambient_source.left.handle, volume, -1); - HW3DS.pfnUpdateSourceParms(ambient_source.right.handle, volume, -1); - - if (sfx->usefulness++ < 0) - sfx->usefulness = -1; - - // Ambient sound is special case - HW3DS.pfnStartSource(ambient_source.left.handle); - HW3DS.pfnStartSource(ambient_source.right.handle); - } - else - { - s_num = HW3S_GetSource(origin, sfx, true); - - if (s_num < 0) - { - //I_OutputMsg("No free source, aborting\n"); - return -1; - } - - source = &sources[s_num]; - - if (origin && c_type == CT_NORMAL) - { - if (!source_parm) - { - source_parm = &source3d_data; - source3d_data.permanent = 0; - HW3S_FillSourceParameters(origin, source_parm, c_type); - } - - source->handle = HW3DS.pfnAddSource(source_parm, (u_int)sfx->length); - } - else - source->handle = HW3DS.pfnAddSource(NULL, (u_int)sfx->length); - } - - // increase the usefulness - if (sfx->usefulness++ < 0) - sfx->usefulness = -1; - - source->sfxinfo = sfx; - source->origin = origin; - HW3DS.pfnStartSource(source->handle); - } - - if (c_type != CT_NORMAL && origin && (origin == listenmobj)) - { - if (c_type == CT_ATTACK) - { - if (origin == listenmobj) - source = &p_attack_source; - else - source = &p_attack_source2; - } - else - { - if (origin == listenmobj) - source = &p_scream_source; - else - source = &p_scream_source2; - } - - if (source->sfxinfo != sfx) - { - HW3DS.pfnStopSource(source->handle); - source->handle = HW3DS.pfnReloadSource(source->handle, sfx->volume); - //I_OutputMsg("PlayerSound data reloaded\n"); - } - } - else if (c_type == CT_AMBIENT) - { -// sfx_data_t outphased_sfx; - - if (ambient_source.left.sfxinfo != sfx) - { - HW3DS.pfnStopSource(ambient_source.left.handle); - HW3DS.pfnStopSource(ambient_source.right.handle); - - // judgecutor: - // Outphased sfx's temporarily not used!!! -/* - outphased_sfx.data = Z_Malloc(sfx_data.length, PU_STATIC, 0); - make_outphase_sfx(outphased_sfx.data, sfx_data.data, sfx_data.length); - outphased_sfx.length = sfx_data.length; - outphased_sfx.id = sfx_data.id; -*/ - ambient_source.left.handle = HW3DS.pfnReloadSource(ambient_source.left.handle, (u_int)sfx->length); - //ambient_source.right.handle = HW3DS.pfnReloadSource(ambient_source.right.handle, &outphased_sfx); - ambient_source.right.handle = HW3DS.pfnReloadSource(ambient_source.right.handle, (u_int)sfx->length); - ambient_source.left.sfxinfo = ambient_source.right.sfxinfo = sfx; - //Z_Free(outphased_sfx.data); - } - - HW3DS.pfnUpdateSourceParms(ambient_source.left.handle, volume, -1); - HW3DS.pfnUpdateSourceParms(ambient_source.right.handle, volume, -1); - - if (sfx->usefulness++ < 0) - sfx->usefulness = -1; - - // Ambient sound is special case - HW3DS.pfnStartSource(ambient_source.left.handle); - HW3DS.pfnStartSource(ambient_source.right.handle); - return -1; - } - else - { - s_num = HW3S_GetSource(origin, sfx, false); - - if (s_num < 0) - { - //I_OutputMsg("No free source, aborting\n"); - return -1; - } - - source = &sources[s_num]; - - if (origin && c_type == CT_NORMAL) - { - if (!source_parm) - { - source_parm = &source3d_data; - source3d_data.permanent = 0; - HW3S_FillSourceParameters(origin, source_parm, c_type); - } - - source->handle = HW3DS.pfnAddSource(source_parm, (u_int)sfx->length); - } - else - source->handle = HW3DS.pfnAddSource(NULL, (u_int)sfx->length); - - } - - // increase the usefulness - if (sfx->usefulness++ < 0) - sfx->usefulness = -1; - - source->sfxinfo = sfx; - source->origin = origin; - HW3DS.pfnStartSource(source->handle); - return s_num; - -} - - -// Start normal sound -//============================================================================= -void HW3S_StartSound(const void *origin, sfxenum_t sfx_id) -{ - HW3S_I_StartSound(origin, NULL, CT_NORMAL, sfx_id, 255, NORMAL_PITCH, NORMAL_SEP); -} - - -//============================================================================= -void S_StartAttackSound(const void *origin, sfxenum_t sfx_id) -{ - if (hws_mode != HWS_DEFAULT_MODE) - HW3S_I_StartSound(origin, NULL, CT_ATTACK, sfx_id, 255, NORMAL_PITCH, NORMAL_SEP); - else - S_StartSound(origin, sfx_id); -} - -void S_StartScreamSound(const void *origin, sfxenum_t sfx_id) -{ - if (hws_mode != HWS_DEFAULT_MODE) - HW3S_I_StartSound(origin, NULL, CT_SCREAM, sfx_id, 255, NORMAL_PITCH, NORMAL_SEP); - else - S_StartSound(origin, sfx_id); -} - -#if 0 /// NOTE: not used -void S_StartAmbientSound(sfxenum_t sfx_id, INT32 volume) -{ - if (hws_mode != HWS_DEFAULT_MODE) - { - volume += 30; - if (volume > 255) - volume = 255; - - HW3S_I_StartSound(NULL, NULL, CT_AMBIENT, sfx_id, volume, NORMAL_PITCH, NORMAL_SEP); - } - else - S_StartSoundAtVolume(NULL, sfx_id, volume); -} -#endif - -FUNCMATH static inline float AmbientPos(angle_t an) -{ - const fixed_t fm = FixedMul(FLOAT_TO_FIXED(MIN_DISTANCE), FINESINE(an>>ANGLETOFINESHIFT)); - return FIXED_TO_FLOAT(fm); -} - - -//============================================================================= -INT32 HW3S_Init(I_Error_t FatalErrorFunction, snddev_t *snd_dev) -{ - INT32 succ; - source3D_data_t source_data; - - if (HW3DS.pfnStartup(FatalErrorFunction, snd_dev)) - { - // Attack source - source_data.head_relative = 1; - source_data.pos.x = 0.0f; - source_data.pos.y = 16.0f; - source_data.pos.z = -FIXED_TO_FLOAT(mobjinfo[MT_PLAYER].height >> 1); - source_data.pos.momx = 0.0f; - source_data.pos.momy = 0.0f; - source_data.pos.momz = 0.0f; - source_data.min_distance = MIN_DISTANCE; - source_data.max_distance = MAX_DISTANCE; - source_data.permanent = 1; - - p_attack_source.sfxinfo = NULL; - - M_Memcpy(&p_attack_source2, &p_attack_source, sizeof (source_t)); - - p_attack_source.handle = HW3DS.pfnAddSource(&source_data, sfx_None); - p_attack_source2.handle = HW3DS.pfnAddSource(&source_data, sfx_None); - - // Scream source - source_data.pos.y = 0; - source_data.pos.z = 0; - - p_scream_source.sfxinfo = NULL; - - M_Memcpy(&p_scream_source2, &p_scream_source, sizeof (source_t)); - - p_scream_source.handle = HW3DS.pfnAddSource(&source_data, sfx_None); - p_scream_source2.handle = HW3DS.pfnAddSource(&source_data, sfx_None); - - //FIXED_TO_FLOAT(mobjinfo[MT_PLAYER].height - (5 * FRACUNIT)); - - // Ambient sources (left and right) at 210 and 330 degree - // relative to listener - memset(&ambient_sdata, 0, sizeof (ambient_sdata)); - - ambient_sdata.left.head_relative = 1; - ambient_sdata.left.pos.x = ambient_sdata.left.pos.y = AmbientPos(ANG210); - ambient_sdata.left.max_distance = MAX_DISTANCE; - ambient_sdata.left.min_distance = MIN_DISTANCE; - - ambient_sdata.left.permanent = 1; - - M_Memcpy(&ambient_sdata.right, &ambient_sdata.left, sizeof (source3D_data_t)); - - ambient_sdata.right.pos.x = -ambient_sdata.left.pos.x; - ambient_source.left.handle = HW3DS.pfnAddSource(&ambient_sdata.left, sfx_None); - ambient_source.right.handle = HW3DS.pfnAddSource(&ambient_sdata.right, sfx_None); - - succ = p_attack_source.handle > -1 && p_scream_source.handle > -1 && - p_attack_source2.handle > -1 && p_scream_source2.handle > -1 && - ambient_source.left.handle > -1 && ambient_source.right.handle > -1; - - //I_OutputMsg("Player handles: attack %d, default %d\n", p_attack_source.handle, p_scream_source.handle); - return succ; - } - return 0; -} - - - - -//============================================================================= -INT32 HW3S_GetVersion(void) -{ - return HW3DS.pfnGetHW3DSVersion(); -} - - -//============================================================================= -void HW3S_BeginFrameUpdate(void) -{ - if (hws_mode != HWS_DEFAULT_MODE) - HW3DS.pfnBeginFrameUpdate(); -} - - -//============================================================================= -void HW3S_EndFrameUpdate(void) -{ - if (hws_mode != HWS_DEFAULT_MODE) - HW3DS.pfnEndFrameUpdate(); -} - - - -//============================================================================= -INT32 HW3S_SoundIsPlaying(INT32 handle) -{ - return HW3DS.pfnIsPlaying(handle); -} - -INT32 HW3S_OriginPlaying(void *origin) -{ - INT32 snum; - - if (!origin) - return 0; - for (snum = 0; snum < num_sources; snum++) - if (sources[snum].origin == origin) - return 1; - return 0; -} - -INT32 HW3S_IdPlaying(sfxenum_t id) -{ - INT32 snum; - for (snum = 0; snum < num_sources; snum++) - if ((size_t)(sources[snum].sfxinfo - S_sfx) == (size_t)id) - return 1; - return 0; -} - -INT32 HW3S_SoundPlaying(void *origin, sfxenum_t id) -{ - INT32 snum; - - if (!origin) - return 0; - - for (snum = 0; snum < num_sources; snum++) - { - if (sources[snum].origin == origin - && (size_t)(sources[snum].sfxinfo - S_sfx) == (size_t)id) - return 1; - } - return 0; -} - -//============================================================================= -static void HW3S_UpdateListener(mobj_t *listener) -{ - listener_data_t data; - - if (!listener || !listener->player) - return; - - if (camera.chase) - { - data.x = FIXED_TO_FLOAT(camera.x); - data.y = FIXED_TO_FLOAT(camera.y); - data.z = FIXED_TO_FLOAT(camera.z + camera.height - (5 * FRACUNIT)); - - data.f_angle = ANGLE2DEG(camera.angle); - data.h_angle = ANGLE2DEG(camera.aiming); - - data.momx = TPS(FIXED_TO_FLOAT(camera.momx)); - data.momy = TPS(FIXED_TO_FLOAT(camera.momy)); - data.momz = TPS(FIXED_TO_FLOAT(camera.momz)); - } - else - { - data.x = FIXED_TO_FLOAT(listener->x); - data.y = FIXED_TO_FLOAT(listener->y); - data.z = FIXED_TO_FLOAT(listener->z + listener->height - (5 * FRACUNIT)); - - data.f_angle = ANGLE2DEG(listener->angle); - data.h_angle = ANGLE2DEG(listener->player->aiming); - - data.momx = TPS(FIXED_TO_FLOAT(listener->momx)); - data.momy = TPS(FIXED_TO_FLOAT(listener->momy)); - data.momz = TPS(FIXED_TO_FLOAT(listener->momz)); - } - HW3DS.pfnUpdateListener(&data, 1); -} - -static void HW3S_UpdateListener2(mobj_t *listener) -{ - listener_data_t data; - - if (!listener || !listener->player) - { - HW3DS.pfnUpdateListener(NULL, 2); - return; - } - - if (camera2.chase) - { - data.x = FIXED_TO_FLOAT(camera2.x); - data.y = FIXED_TO_FLOAT(camera2.y); - data.z = FIXED_TO_FLOAT(camera2.z + camera2.height - (5 * FRACUNIT)); - - data.f_angle = ANGLE2DEG(camera2.angle); - data.h_angle = ANGLE2DEG(camera2.aiming); - - data.momx = TPS(FIXED_TO_FLOAT(camera2.momx)); - data.momy = TPS(FIXED_TO_FLOAT(camera2.momy)); - data.momz = TPS(FIXED_TO_FLOAT(camera2.momz)); - } - else - { - data.x = FIXED_TO_FLOAT(listener->x); - data.y = FIXED_TO_FLOAT(listener->y); - data.z = FIXED_TO_FLOAT(listener->z + listener->height - (5 * FRACUNIT)); - - data.f_angle = ANGLE2DEG(listener->angle); - data.h_angle = ANGLE2DEG(listener->player->aiming); - - data.momx = TPS(FIXED_TO_FLOAT(listener->momx)); - data.momy = TPS(FIXED_TO_FLOAT(listener->momy)); - data.momz = TPS(FIXED_TO_FLOAT(listener->momz)); - } - - HW3DS.pfnUpdateListener(&data, 2); -} - -void HW3S_SetSfxVolume(INT32 volume) -{ - HW3DS.pfnSetGlobalSfxVolume(volume); -} - - -static void HW3S_Update3DSource(source_t *src) -{ - source3D_data_t data; - data.permanent = 0; - HW3S_FillSourceParameters(src->origin, &data, src->type); - HW3DS.pfnUpdate3DSource(src->handle, &data.pos); - -} - -void HW3S_UpdateSources(void) -{ - mobj_t *listener = players[displayplayers[0]].mo; - mobj_t *listener2 = NULL; - source_t *src; - INT32 audible, snum, volume, sep, pitch; - - if (splitscreen) listener2 = players[displayplayers[1]].mo; - - HW3S_UpdateListener2(listener2); - HW3S_UpdateListener(listener); - - for (snum = 0, src = sources; snum < num_sources; src++, snum++) - { - if (src->sfxinfo) - { -#if 0 - if (HW3DS.pfnIsPlaying(src->handle)) - { - if (src->origin) - { - // initialize parameters - volume = 255; // 8 bits internal volume precision - pitch = NORM_PITCH; - sep = NORM_SEP; - - // check non-local sounds for distance clipping - // or modify their params - if (src->origin && listener != src->origin && !(listener2 && src->origin == listener2)) - { - INT32 audible2; - INT32 volume2 = volume, sep2 = sep, pitch2 = pitch; - audible = S_AdjustSoundParams(listener, src->origin, &volume, &sep, &pitch, - src->sfxinfo); - - if (listener2) - { - audible2 = S_AdjustSoundParams(listener2, - src->origin, &volume2, &sep2, &pitch2, src->sfxinfo); - if (audible2 && (!audible || (audible && volume2 > volume))) - { - audible = true; - volume = volume2; - sep = sep2; - pitch = pitch2; - } - } - - if (audible) - HW3S_Update3DSource(src); // Update positional sources - else - HW3S_KillSource(snum); //Kill it! - } - } - } - else - { - // Source allocated but stopped. Kill. - HW3S_KillSource(snum); - } -#else - if (src->origin && listener != src->origin && !(listener2 && src->origin == listener2)) - HW3S_Update3DSource(src); // Update positional sources - (void)pitch; - (void)sep; - (void)volume; - (void)audible; -#endif - } - } -} - -void HW3S_Shutdown(void) -{ - HW3DS.pfnShutdown(); -} - -void *HW3S_GetSfx(sfxinfo_t *sfx) -{ - sfx_data_t sfx_data; - - if (sfx->lumpnum == LUMPERROR) - sfx->lumpnum = S_GetSfxLumpNum (sfx); - - sfx_data.length = W_LumpLength(sfx->lumpnum); - sfx_data.data = Z_Malloc(sfx_data.length, PU_SOUND, &sfx->data); - W_ReadLump(sfx->lumpnum, sfx_data.data); - sfx_data.priority = sfx->priority; - - sfx->length = HW3DS.pfnAddSfx(&sfx_data); - - Z_ChangeTag(sfx->data, PU_CACHE); - - return sfx_data.data; -} - -void HW3S_FreeSfx(sfxinfo_t *sfx) -{ - INT32 snum; - - for (snum = 0; snum < num_sources; snum++) - { - if (sources[snum].sfxinfo == sfx) - { - HW3S_KillSource(snum); - break; - } - } - - if (sfx->length > 0) - HW3DS.pfnKillSfx((u_int)sfx->length); - sfx->length = 0; - - sfx->lumpnum = LUMPERROR; - - Z_Free(sfx->data); - sfx->data = NULL; -} - -#endif diff --git a/src/hardware/hw3sound.h b/src/hardware/hw3sound.h deleted file mode 100644 index a8a475b69..000000000 --- a/src/hardware/hw3sound.h +++ /dev/null @@ -1,106 +0,0 @@ -// Emacs style mode select -*- C++ -*- -//----------------------------------------------------------------------------- -// -// Copyright (C) 2001 by DooM Legacy Team. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -//----------------------------------------------------------------------------- -/// \file -/// \brief High-level functions of hardware 3D sound - -#ifndef __HW3_SOUND_H__ -#define __HW3_SOUND_H__ - -#ifdef HW3SOUND -#include "hws_data.h" -//#include "../s_sound.h" -//#include "../p_mobj.h" - -// Default sound mode (original stereo mode) -enum -{ - HWS_DEFAULT_MODE = 0, - HWS_DS3D, - HWS_OTHER, - HWS_FMOD3D, - HWS_OPENAL, -}; - -typedef enum -{ - CT_NORMAL = 0, - CT_ATTACK, - CT_SCREAM, - CT_AMBIENT, -} channel_type_t; - -extern INT32 hws_mode; // Current sound mode - -#if defined (HW3DS) || defined (DOXYGEN) -INT32 HW3S_Init(I_Error_t FatalErrorFunction, snddev_t *snd_dev); -#endif -void HW3S_Shutdown(void); -INT32 HW3S_GetVersion(void); - -// Common case - start 3D or 2D source -void HW3S_StartSound(const void *origin, sfxenum_t sfx_id); - -// Special cases of 3D sources -void S_StartAmbientSound(sfxenum_t sfx_id, INT32 volume); -void S_StartAttackSound(const void *origin, sfxenum_t sfx_id); -void S_StartScreamSound(const void *origin, sfxenum_t sfx_id); - -// Starts 3D sound with specified parameters -// origin - for object movement tracking. NULL are possible value (no movement tracking) -// source_parm - 3D source parameters (position etc.) -// cone_parm - 3D source cone parameters. NULL are possible value (default cone will be used) -// channel - -// sfx_id - sfx id -// vol - sound volume -// pitch - sound pitching value -// Returns: - sound id -INT32 HW3S_I_StartSound(const void *origin, source3D_data_t *source_parm, channel_type_t channel, sfxenum_t sfx_id, INT32 vol, INT32 pitch, INT32 sep); -void HW3S_StopSoundByID(void *origin, sfxenum_t sfx_id); -void HW3S_StopSoundByNum(sfxenum_t sfxnum); -void HW3S_StopSound(void *origin); -void HW3S_StopSounds(void); - -void HW3S_BeginFrameUpdate(void); -void HW3S_EndFrameUpdate(void); - -void HW3S_UpdateSources(void); - -void HW3S_SetSfxVolume(INT32 volume); - -// Utility functions -INT32 HW3S_SoundIsPlaying(INT32 handle); -void HW3S_SetSourcesNum(void); - -INT32 HW3S_OriginPlaying(void *origin); -INT32 HW3S_IdPlaying(sfxenum_t id); -INT32 HW3S_SoundPlaying(void *origin, sfxenum_t id); - -void *HW3S_GetSfx(sfxinfo_t *sfx); -void HW3S_FreeSfx(sfxinfo_t *sfx); - -#else // HW3SOUND - -//#define S_StartAmbientSound(i,v) S_StartSoundAtVolume(NULL, i, v) -#define S_StartAttackSound S_StartSound -#define S_StartScreamSound S_StartSound - -#endif // HW3SOUND - -INT32 S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, - INT32 *vol, INT32 *sep, INT32 *pitch, sfxinfo_t *sfxinfo); - -#endif // __HW3_SOUND_H__ diff --git a/src/hardware/hws_data.h b/src/hardware/hws_data.h deleted file mode 100644 index b890d976b..000000000 --- a/src/hardware/hws_data.h +++ /dev/null @@ -1,123 +0,0 @@ -// Emacs style mode select -*- C++ -*- -//----------------------------------------------------------------------------- -// -// Copyright (C) 2005 by SRB2 Jr. Team. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -//----------------------------------------------------------------------------- -/// \file -/// \brief 3D sound definitions - -#ifndef __HWS_DATA_H__ -#define __HWS_DATA_H__ - -#define NORMAL_SEP 128 - -// abuse? -#define STATIC_SOURCES_NUM 6 // Total number of static sources - -#define MIN_DISTANCE 160.0f -#define MAX_DISTANCE 1200.0f - -typedef struct source_pos_s -{ - double x; - double y; - double z; -} source_pos_t; - -typedef struct source3D_pos_s -{ - float x; - float y; - float z; - //float angle; - float momx; - float momy; - float momz; - -} source3D_pos_t; - - -enum {NORMAL_PITCH = 128}; - -/*typedef struct source2D_data_s -{ - INT32 volume; - INT32 sep; - -} source2D_data_t;*/ - - -// General 3D sound source description -typedef struct source3D_data_s -{ - float min_distance; // - float max_distance; // - INT32 head_relative; // - INT32 permanent; // - source3D_pos_t pos; // source position in 3D - -} source3D_data_t; - - -// Sound data -typedef struct sfx_data_s -{ - size_t length; - void *data; - INT32 priority; - INT32 sep; // Only when source is 2D sound -} sfx_data_t; - - -// Sound cone (for 3D sources) -typedef struct cone_def_s -{ - float inner; - float outer; - INT32 outer_gain; - /*float f_angle; - float h_angle;*/ -} cone_def_t; - - -typedef struct listener_data_s -{ - // Listener position - double x; - double y; - double z; - - // Listener front and head orientation (degrees) - double f_angle; - double h_angle; - - // Listener momentums - double momx; - double momy; - double momz; -} listener_data_t; - -typedef struct snddev_s -{ - INT32 sample_rate; - INT32 bps; - size_t numsfxs; - -// Windows specific data -#ifdef _WIN32 - UINT32 cooplevel; - HWND hWnd; -#endif -} snddev_t; - -#endif //__HWS_DATA_H__ diff --git a/src/hardware/s_ds3d/s_ds3d.c b/src/hardware/s_ds3d/s_ds3d.c deleted file mode 100644 index 5299c1795..000000000 --- a/src/hardware/s_ds3d/s_ds3d.c +++ /dev/null @@ -1,1237 +0,0 @@ -// Emacs style mode select -*- C++ -*- -//----------------------------------------------------------------------------- -// -// Copyright (C) 2001 by DooM Legacy Team. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -//----------------------------------------------------------------------------- -/// \file -/// \brief General driver for 3D sound system -/// -/// Implementend via DirectSound3D API - -#define INITGUID -//#define WIN32_LEAN_AND_MEAN -#define RPC_NO_WINDOWS_H -#include -#include -#define DIRECTSOUND_VERSION 0x0700 /* version 7.0 */ - -#ifdef __MINGW32__ -#define NONAMELESSUNION -#endif -#include - -#if (defined (DIRECTSOUND_VERSION) && (DIRECTSOUND_VERSION >= 0x0700)) -#define DX7 //Enable DX7 or up only code -#undef DUMMYUNIONNAMEN -#endif - -#ifdef __MINGW32__ -//#undef DX7 -#endif - -#define _CREATE_DLL_ -#include "../hw3dsdrv.h" -#include "../../m_fixed.h" -#include "../../doomdef.h" -//#define VERSIONSTRING "v1.08" - -#undef DEBUG_TO_FILE -#define DEBUG_TO_FILE - -#if defined ( HAVE_SDL ) && !defined ( LOGMESSAGES ) -#undef DEBUG_TO_FILE -#endif - - -// Internal sound stack -typedef struct stack_snd_s -{ - // Sound data - LPDIRECTSOUNDBUFFER dsbuffer; - - // 3D data of 3D source - LPDIRECTSOUND3DBUFFER dsbuffer3D; // 3D data - - // Current parameters of 3D source - // Valid only when source is 3D source - // (dsbuffer3D is not NULL) - DS3DBUFFER parameters; - - // Currently unused - INT32 sfx_id; - - // Currently unused - INT32 LRU; - - // Flag of static source - // Driver does not manage intrenally such sources - INT32 permanent; - -} stack_t; - -// Just for now... -#define SOUND_ALLOCATE_DELTA 16 // Amount of sources per stack incrementation -#define MAX_LRU 16 // Maximum iterations to keep source in stack - -static stack_t *_stack; // Sound stack -static INT32 allocated_sounds; // Size of stack - -static INT32 srate; // Default sample rate - - -// output all debugging messages to this file -#if defined (DEBUG_TO_FILE) -#include -FILE *logstream = NULL; -#endif - -static LPDIRECTSOUND DSnd = NULL; // Main DirectSound object -static LPDIRECTSOUNDBUFFER PrimaryBuffer = NULL; // -static LPDIRECTSOUND3DLISTENER Listener = NULL; // - -static DS3DLISTENER listener_parms; // Listener papameters - -#ifdef DX7 -static BOOL virtualization; // TRUE if HRTF virtualization enabled -#endif - -static DWORD update_mode; // Current update mode of listener -//static DWORD max_3d_buffers; - -static I_Error_t I_ErrorDS3D = NULL; - -//static stack_snd_t sound_stack[MAX_SOUNDS]; - -// Safe buffer release -#define RELEASE_BUFFER(buf) {if (buf) { IDirectSoundBuffer_Release(buf); (buf) = NULL; }} -#define RELEASE_3DBUFFER(buf) {if (buf) { IDirectSound3DBuffer_Release(buf); (buf) = NULL; }} - -// Default flags for buffers -#define _2DSOURCE_FLAGS (DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_STICKYFOCUS | DSBCAPS_STATIC | DSBCAPS_CTRLFREQUENCY) -#define _3DSOURCE_FLAGS (DSBCAPS_CTRL3D | DSBCAPS_STATIC | DSBCAPS_MUTE3DATMAXDISTANCE | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY) - - -enum {IS_2DSOURCE = 0, IS_3DSOURCE = 1}; - -#define NEW_HANDLE -1 - -#ifdef _WINDOWS -BOOL WINAPI DllMain(HINSTANCE hinstDLL, // handle to DLL module - DWORD fdwReason, // reason for calling function - LPVOID lpvReserved) // reserved -{ - // Perform actions based on the reason for calling - UNREFERENCED_PARAMETER(lpvReserved); - switch ( fdwReason ) - { - case DLL_PROCESS_ATTACH: - // Initialize once for each new process. - // Return FALSE to fail DLL load. -#ifdef DEBUG_TO_FILE - logstream = fopen("s_ds3d.log", "wt"); - if (logstream == NULL) - return FALSE; -#endif - DisableThreadLibraryCalls(hinstDLL); - break; - - case DLL_THREAD_ATTACH: - // Do thread-specific initialization. - break; - - case DLL_THREAD_DETACH: - // Do thread-specific cleanup. - break; - - case DLL_PROCESS_DETACH: - // Perform any necessary cleanup. -#ifdef DEBUG_TO_FILE - if (logstream) - { - fclose(logstream); - logstream = NULL; - } -#endif - break; - } - return TRUE; // Successful DLL_PROCESS_ATTACH. -} -#endif - -// ************************************************************************** -// FUNCTIONS -// ************************************************************************** - -/*************************************************************** - * - * DBG_Printf - * Output error messages to debug log if DEBUG_TO_FILE is defined, - * else do nothing - * - *************************************************************** - */ -// -----------------+ -// DBG_Printf : Output error messages to debug log if DEBUG_TO_FILE is defined, -// : else do nothing -// Returns : -// -----------------+ -void DBG_Printf(const char *lpFmt, ... ) -{ -#ifdef DEBUG_TO_FILE - char str[4096] = ""; - va_list arglist; - - va_start(arglist, lpFmt); - vsnprintf(str, 4096, lpFmt, arglist); - va_end(arglist); - - if (logstream) - fwrite(str, strlen(str), 1, logstream); -#endif -} - - -/*************************************************************** - * - * Grow intrenal sound stack by SOUND_ALLOCATE_DELTA amount - * - *************************************************************** - */ -static BOOL reallocate_stack(void) -{ - stack_t *new_stack; - - if (_stack) - new_stack = realloc(_stack, sizeof (stack_t) * (allocated_sounds + SOUND_ALLOCATE_DELTA)); - else - new_stack = malloc(sizeof (stack_t) * (allocated_sounds + SOUND_ALLOCATE_DELTA)); - if (new_stack) - { - _stack = new_stack; - ZeroMemory(&_stack[allocated_sounds], SOUND_ALLOCATE_DELTA * sizeof (stack_t)); - allocated_sounds += SOUND_ALLOCATE_DELTA; - } - return (new_stack != NULL); -} - - -/*************************************************************** - * - * Destroys source in stack - * - *************************************************************** - */ -static void kill_sound(stack_t *snd) -{ - //stack_t *snd = _stack + handle; - - if (snd->dsbuffer3D) - RELEASE_3DBUFFER(snd->dsbuffer3D); - - if (snd->dsbuffer) - RELEASE_BUFFER(snd->dsbuffer); - - ZeroMemory(snd, sizeof (stack_t)); -} - - -/*************************************************************** - * - * Returns TRUE if source currently playing - * - *************************************************************** - */ -static BOOL is_playing(stack_t *snd) -{ - DWORD status; - LPDIRECTSOUNDBUFFER dsbuffer = snd->dsbuffer; - - if (dsbuffer == NULL) - return 0; - - IDirectSoundBuffer_GetStatus(dsbuffer, &status); - - return (status & (DSBSTATUS_PLAYING | DSBSTATUS_LOOPING)); -} - - -/*************************************************************** - * - * Creates DirectSound buffer and fills with sound data - * NULL sound data pointer are valid (empty buffer - * will be created) - * - *************************************************************** - */ -static LPDIRECTSOUNDBUFFER create_buffer (void *data, INT32 length, BOOL as3d) -{ - LPDIRECTSOUNDBUFFER dsbuffer; - HRESULT hr; - WAVEFORMATEX wfm; - DSBUFFERDESC dsbdesc; - LPVOID lpvAudio1; // receives address of lock start - DWORD dwBytes1; // receives number of bytes locked - LPVOID lpvAudio2; // receives address of lock start - DWORD dwBytes2; // receives number of bytes locked - - ZeroMemory(&wfm, sizeof (WAVEFORMATEX)); - wfm.wFormatTag = WAVE_FORMAT_PCM; - wfm.nChannels = 1; - wfm.nSamplesPerSec = data?*((UINT16 *)data+1):srate; //mostly 11025, but some at 22050. - wfm.wBitsPerSample = 8; - wfm.nBlockAlign = (WORD)(wfm.wBitsPerSample / 8 * wfm.nChannels); - wfm.nAvgBytesPerSec = wfm.nSamplesPerSec * wfm.nBlockAlign; - - // Set up DSBUFFERDESC structure. - ZeroMemory (&dsbdesc, sizeof (DSBUFFERDESC) ); - dsbdesc.dwSize = sizeof (DSBUFFERDESC); - dsbdesc.dwFlags = as3d?_3DSOURCE_FLAGS:_2DSOURCE_FLAGS; - dsbdesc.dwBufferBytes = length; - dsbdesc.lpwfxFormat = &wfm; - - // DirectX 7.0 and above! - // Try to enable full HRTF virtualization algorithm for - // two-speakers or headphones -#ifdef DX7 - if (as3d) - dsbdesc.guid3DAlgorithm = (virtualization?DS3DALG_HRTF_FULL:DS3DALG_DEFAULT); -#endif - - hr = IDirectSound_CreateSoundBuffer (DSnd, &dsbdesc, &dsbuffer, NULL); - - // CreateSoundBuffer might return DS_NO_VIRTUALIZATION so uses FAILED - // macro rather than check explictly for DS_OK value - if (FAILED(hr)) - { - DBG_Printf("CreateSoundBuffer FAILED. Code %d\n", hr); - return NULL; - } - - if (data) - { - hr = IDirectSoundBuffer_Lock(dsbuffer, 0, length, &lpvAudio1, &dwBytes1, &lpvAudio2, &dwBytes2, 0); - - // If DSERR_BUFFERLOST is returned, restore and retry lock. - if (hr == DSERR_BUFFERLOST) - { - hr = IDirectSoundBuffer_Restore(dsbuffer); - if (FAILED(hr)) - I_ErrorDS3D("Restore fail on %x, code %d\n",dsbuffer, hr); - hr = IDirectSoundBuffer_Lock(dsbuffer, 0, length, &lpvAudio1, &dwBytes1, &lpvAudio2, &dwBytes2, 0); - if (FAILED(hr)) - I_ErrorDS3D("Lock fail(2) on %x, code %d\n",dsbuffer, hr); - } - else - if (FAILED(hr)) - I_ErrorDS3D("Lock fail(1) on %x, code %d\n",dsbuffer, hr); - - // copy wave data into the buffer (note: dwBytes1 should equal to dsbdesc->dwBufferBytes ...) - CopyMemory (lpvAudio1, (LPBYTE)data+8, dwBytes1); - - if ( dwBytes2 && lpvAudio2) - CopyMemory(lpvAudio2, ((LPBYTE)data + 8) + dwBytes1, dwBytes2); - - - // finally, unlock the buffer - hr = IDirectSoundBuffer_Unlock(dsbuffer, lpvAudio1, dwBytes1, lpvAudio2, dwBytes2); - - if (FAILED(hr)) - I_ErrorDS3D("Unlock fail on %x, code %d\n",dsbuffer, hr); - } - - return dsbuffer; -} - - -/*************************************************************** - * - * Creates 3D source data buffer - * - *************************************************************** - */ -static LPDIRECTSOUND3DBUFFER create_3dbuffer(LPDIRECTSOUNDBUFFER dsbuffer, LPDIRECTSOUND3DBUFFER source3d) -{ - HRESULT hr; - - hr = IDirectSoundBuffer_QueryInterface(dsbuffer, - &IID_IDirectSound3DBuffer, (void **)&source3d); - - if (FAILED(hr)) - { - DBG_Printf("Couldn't obtain 3D Buffer interface. Code %d\n", hr); - return NULL; - } -#ifdef DX7 - if (hr == DS_NO_VIRTUALIZATION) - { - DBG_Printf("The 3D virtualization is not supported under this OS.\n"); - virtualization = FALSE; - } -#endif - return source3d; -} - - -/*************************************************************** - * - * Returns free (unused) source stack slot - * If none available sound stack will be increased - * - *************************************************************** - */ -static INT32 find_handle(INT32 new_sfx_id, INT32 new_is3d) -{ - INT32 free_sfx; - stack_t *snd; - - // At first do look for sound with same sfx ID and reuse it - new_sfx_id = new_is3d = 0; - for (free_sfx = 0, snd = _stack; free_sfx < allocated_sounds; snd++, free_sfx++) - { - - if (snd->permanent) - continue; -/* - if (!is_playing(snd)) - { - if (same_sfx == 0 && snd->sfx_id == new_sfx_id && snd->dsbuffer) - { - same_sfx = i; - continue; - } - - if (snd->sfx_id && ++snd->LRU >= MAX_LRU) - kill_sound(snd); - } -*/ - if (snd->dsbuffer == 0) - break; - //free_sfx = i; - } - - // No suitable resource found so increase sound stack - if (free_sfx == allocated_sounds) - { - DBG_Printf("No free or same sfx found so increase stack (currently %d srcs)\n", allocated_sounds); - free_sfx = reallocate_stack() ? free_sfx : -1; - } - - return free_sfx; -} - - -/*************************************************************** - * - * Recalculates volume from Doom scale to DirectSound scale - * - *************************************************************** - */ -static INT32 recalc_volume(INT32 base_vol, INT32 steps) -{ - return (base_vol * ((DSBVOLUME_MAX-DSBVOLUME_MIN)/4)) / steps - + (DSBVOLUME_MAX - ((DSBVOLUME_MAX-DSBVOLUME_MIN)/4)); -} - - -/*************************************************************** - * - * Updates sound volume of the DirectSound buffer - * - *************************************************************** - */ -static void UpdateSoundVolume (LPDIRECTSOUNDBUFFER lpSnd, INT32 volume) -{ - /*volume = (volume * ((DSBVOLUME_MAX-DSBVOLUME_MIN)/4)) / 256 + - (DSBVOLUME_MAX - ((DSBVOLUME_MAX-DSBVOLUME_MIN)/4)); - - IDirectSoundBuffer_SetVolume (lpSnd, volume);*/ - IDirectSoundBuffer_SetVolume (lpSnd, recalc_volume(volume, 256)); -} - - -// -------------------------------------------------------------------------- -// Update the panning for a secondary buffer, make sure it was created with -// DSBCAPS_CTRLPAN -// -------------------------------------------------------------------------- -#define DSBPAN_RANGE (DSBPAN_RIGHT-(DSBPAN_LEFT)) - -//Doom sounds pan range 0-255 (128 is centre) -#define SEP_RANGE 256 -static void Update2DSoundPanning (LPDIRECTSOUNDBUFFER lpSnd, INT32 sep) -{ - HRESULT hr; - hr = IDirectSoundBuffer_SetPan (lpSnd, (sep * DSBPAN_RANGE)/SEP_RANGE - DSBPAN_RIGHT); - //if (FAILED(hr)) - // DEBFILE(va("SetPan FAILED for sep %d pan %d\n", sep, (sep * DSBPAN_RANGE)/SEP_RANGE - DSBPAN_RIGHT)); -} - - - -/****************************************************************************** - * - * Initialise driver and listener - * - *****************************************************************************/ -EXPORT BOOL HWRAPI( Startup ) (I_Error_t FatalErrorFunction, snddev_t *snd_dev) -{ - HRESULT hr; - DSBUFFERDESC desc; - WAVEFORMATEX wfm; - DSCAPS dscaps; - DWORD speakers; - DWORD speaker_config; - DWORD speaker_geometry; - - I_ErrorDS3D = FatalErrorFunction; - DBG_Printf ("S_DS3D Init(): DirectSound3D driver for SRB2 v1.09"); // Tails - - DBG_Printf("Initialising DirectSound3D...\n"); - hr = DirectSoundCreate( NULL, &DSnd, NULL); - if (FAILED(hr)) - { - DBG_Printf("Failed to obtain DirectSound\n"); - return FALSE; - } - - hr = IDirectSound_SetCooperativeLevel(DSnd, snd_dev->hWnd, snd_dev->cooplevel); - if (FAILED(hr)) - { - DBG_Printf("Couldn't set coopertive level\n"); - return FALSE; - } - - dscaps.dwSize = sizeof (DSCAPS); - - IDirectSound_GetCaps(DSnd, &dscaps); - IDirectSound_GetSpeakerConfig(DSnd, &speakers); - - DBG_Printf("Sound hardware capabilities:\n"); - DBG_Printf(" Driver is %scertified.\n", (dscaps.dwFlags & DSCAPS_CERTIFIED) == DSCAPS_CERTIFIED?"":"not "); - DBG_Printf(" Maximum hardware mixing buffers %d\n", dscaps.dwMaxHwMixingAllBuffers); - DBG_Printf(" Maximum hardware 3D buffers %d\n", dscaps.dwFreeHw3DAllBuffers); - - speaker_config = DSSPEAKER_CONFIG(speakers); - speaker_geometry = DSSPEAKER_GEOMETRY(speakers); - - DBG_Printf("Current speaker configuration: "); - - switch (speaker_config) - { -#ifdef DX7 - case DSSPEAKER_5POINT1: - DBG_Printf("5.1 (5 speakers with subwoofer).\n"); - break; -#endif - case DSSPEAKER_HEADPHONE: - DBG_Printf("headphone.\n"); - break; - - case DSSPEAKER_MONO: - DBG_Printf("single speaker (mono).\n"); - break; - - case DSSPEAKER_QUAD: - DBG_Printf("quadrophonic\n"); - break; - - case DSSPEAKER_SURROUND: - DBG_Printf("surround.\n"); - break; - - case DSSPEAKER_STEREO: - DBG_Printf("stereo with %s geometry ", - speaker_geometry == DSSPEAKER_GEOMETRY_WIDE - ? "wide (arc of 20 deg.)" - : speaker_geometry == DSSPEAKER_GEOMETRY_NARROW - ? "narrow (arc of 10 deg.)" - : speaker_geometry == DSSPEAKER_GEOMETRY_MIN - ? "min (arc of 5 deg.)" - : speaker_geometry == DSSPEAKER_GEOMETRY_MAX - ? "max (arc of 180 deg.)" - : "unknown"); - break; - default: - DBG_Printf("undetectable.\n"); - - } - - update_mode = DS3D_IMMEDIATE; - - // Create primary sound buffer - ZeroMemory(&desc, sizeof (DSBUFFERDESC)); - desc.dwSize = sizeof (DSBUFFERDESC); - desc.dwFlags = DSBCAPS_CTRL3D | DSBCAPS_PRIMARYBUFFER | DSBCAPS_CTRLVOLUME; - desc.dwBufferBytes = 0; - desc.lpwfxFormat = NULL; - - hr = IDirectSound_CreateSoundBuffer(DSnd, &desc, &PrimaryBuffer, NULL); - if (FAILED(hr)) - { - DBG_Printf("CreateSoundBuffer FAILED (ErrNo %d)\n", hr); - return FALSE; - } - - // Query for 3D Listener object - hr = IDirectSoundBuffer_QueryInterface(PrimaryBuffer, - &IID_IDirectSound3DListener, (void **)&Listener); - - if (FAILED(hr)) - { - DBG_Printf("Couldn't obtain 3D Listener interface (ErrNo %d)\n", hr); - return FALSE; - } - - // Set up initial listsner parameters - IDirectSound3DListener_SetDistanceFactor(Listener, 1.0f/72.0f, DS3D_IMMEDIATE); - IDirectSound3DListener_SetRolloffFactor(Listener, 1.6f, DS3D_IMMEDIATE); - //IDirectSound3DListener_SetRolloffFactor(Listener, DS3D_MAXROLLOFFFACTOR, DS3D_IMMEDIATE); - listener_parms.dwSize = sizeof (DS3DLISTENER); - IDirectSound3DListener_GetAllParameters(Listener, &listener_parms); - - ZeroMemory (&wfm, sizeof (WAVEFORMATEX)); - wfm.wFormatTag = WAVE_FORMAT_PCM; - wfm.nChannels = 2; - wfm.nSamplesPerSec = srate = snd_dev->sample_rate; - wfm.wBitsPerSample = (WORD)snd_dev->bps; - wfm.nBlockAlign = (WORD)(wfm.wBitsPerSample / 8 * wfm.nChannels); - wfm.nAvgBytesPerSec = wfm.nSamplesPerSec * wfm.nBlockAlign; - - if (snd_dev->cooplevel >= DSSCL_PRIORITY) - { - hr = IDirectSoundBuffer_SetFormat(PrimaryBuffer, &wfm); - if (FAILED(hr)) - DBG_Printf("Couldn't set primary buffer format.\n"); - - DBG_Printf(" Compacting onboard sound-memory..."); - hr = IDirectSound_Compact(DSnd); - DBG_Printf(" %s\n", SUCCEEDED(hr) ? M_GetText("Done\n") : M_GetText("Failed\n")); - } - -#ifdef DX7 - // Initially enables HRTF virtualization (may be changed later) - virtualization = TRUE; -#endif - - _stack = NULL; - allocated_sounds = 0; - IDirectSoundBuffer_Play(PrimaryBuffer, 0, 0, DSBPLAY_LOOPING); - return reallocate_stack(); -} - - - -/*************************************************************** - * - * Shutdown driver - * - *************************************************************** - */ -EXPORT void HWRAPI( Shutdown ) (void) -{ - INT32 i; - - DBG_Printf ("S_DS3D Shutdown()\n"); - - for (i = 0; i < allocated_sounds; i++) - { - StopSource(i); - kill_sound(_stack + i); - } - - if (_stack) - free(_stack); - - if (Listener) - { - IDirectSound3DListener_Release(Listener); - Listener = NULL; - } - - if (PrimaryBuffer) - RELEASE_BUFFER(PrimaryBuffer); - - if (DSnd) - { - IDirectSound_Release(DSnd); - DSnd = NULL; - } - -} - - - -EXPORT INT32 HWRAPI (IsPlaying) (INT32 handle) -{ - if (handle < 0 || handle >= allocated_sounds) - return FALSE; - - return is_playing(_stack + handle); -} - - -// Calculate sound pitching -static float recalc_pitch(INT32 doom_pitch) -{ - return doom_pitch < NORMAL_PITCH ? - (float)(doom_pitch + NORMAL_PITCH) / (NORMAL_PITCH * 2) - :(float)doom_pitch / (float)NORMAL_PITCH; -} - - -static stack_t *setup_source(INT32 handle, sfx_data_t *sfx, BOOL is_3dsource) -{ - stack_t *snd; - //INT32 handle; - INT32 data_length; - LPDIRECTSOUNDBUFFER dsbuffer = NULL; - LPDIRECTSOUND3DBUFFER ds3dbuffer = NULL; - - if (handle == NEW_HANDLE) - handle = find_handle(sfx?sfx->id:0, is_3dsource); - - snd = _stack + handle; - - // Check for reused source - if (snd->dsbuffer) - return snd; - - data_length = sfx?sfx->length - 8:DSBSIZE_MIN; - - dsbuffer = create_buffer(sfx ? sfx->data : NULL, data_length, is_3dsource); - if (dsbuffer) - { - - if (is_3dsource) - { - ds3dbuffer = create_3dbuffer(dsbuffer, ds3dbuffer); - if (!ds3dbuffer) - { - RELEASE_BUFFER(dsbuffer); - return NULL; - } - snd->parameters.dwSize = sizeof (DS3DBUFFER); - IDirectSound3DBuffer_GetAllParameters(ds3dbuffer, &snd->parameters); - } - - // judgecutor: sound pitching - if (sfx) - { - DWORD freq; - - freq = (DWORD)((float)(*((UINT16 *)sfx->data+1)) * recalc_pitch(sfx->pitch)); - IDirectSoundBuffer_SetFrequency(dsbuffer, freq); - } - - snd->dsbuffer = dsbuffer; - snd->dsbuffer3D = ds3dbuffer; - snd->LRU = 0; - snd->sfx_id = sfx ? sfx->id : 0; - if (!is_3dsource) - snd->permanent = 0; - return snd; - } - return NULL; - -} - -/****************************************************************************** - * - * Creates 2D (stereo) source - * - ******************************************************************************/ -EXPORT INT32 HWRAPI ( Add2DSource ) (sfx_data_t *sfx) -{ - stack_t *snd; - - if (!sfx) - return -1; - - snd = setup_source(NEW_HANDLE, sfx, IS_2DSOURCE); - if (snd) - { - UpdateSoundVolume(snd->dsbuffer, sfx->volume); - Update2DSoundPanning(snd->dsbuffer, sfx->sep); - } - return snd - _stack; -} - -/****************************************************************************** - * - * Creates 3D source - * - ******************************************************************************/ - -EXPORT INT32 HWRAPI ( Add3DSource ) (source3D_data_t *src, sfx_data_t *sfx) -{ - stack_t *snd; - - snd = setup_source(NEW_HANDLE, sfx, IS_3DSOURCE); - - if (snd) - { - - /*x = src->pos.x; - y = src->pos.z; - z = src->pos.y; - - IDirectSound3DBuffer_SetPosition(source, x, y, z, update_mode); - IDirectSound3DBuffer_SetVelocity(source, src->pos.momx, src->pos.momz, src->pos.momy, update_mode); - IDirectSound3DBuffer_SetMode(source, src->head_relative?DS3DMODE_HEADRELATIVE:DS3DMODE_NORMAL, update_mode);*/ - -#ifdef DUMMYUNIONNAMEN - snd->parameters.vPosition.DUMMYUNIONNAMEN(9).x = src->pos.x; - snd->parameters.vPosition.DUMMYUNIONNAMEN(10).y = src->pos.z; - snd->parameters.vPosition.DUMMYUNIONNAMEN(11).z = src->pos.y; - - snd->parameters.vVelocity.DUMMYUNIONNAMEN(9).x = src->pos.momx; - snd->parameters.vVelocity.DUMMYUNIONNAMEN(10).y = src->pos.momz; - snd->parameters.vVelocity.DUMMYUNIONNAMEN(11).z = src->pos.momy; -#else - snd->parameters.vPosition.x = src->pos.x; - snd->parameters.vPosition.y = src->pos.z; - snd->parameters.vPosition.z = src->pos.y; - - snd->parameters.vVelocity.x = src->pos.momx; - snd->parameters.vVelocity.y = src->pos.momz; - snd->parameters.vVelocity.z = src->pos.momy; -#endif - snd->parameters.dwMode = src->head_relative ? DS3DMODE_HEADRELATIVE : DS3DMODE_NORMAL; - - snd->parameters.flMinDistance = src->min_distance; - snd->parameters.flMaxDistance = src->max_distance; - //snd->parameters.flMaxDistance = DS3D_DEFAULTMAXDISTANCE; - - snd->permanent = src->permanent; - - UpdateSoundVolume(snd->dsbuffer, sfx?sfx->volume:255); - IDirectSound3DBuffer_SetAllParameters(snd->dsbuffer3D, &snd->parameters, DS3D_IMMEDIATE); - IDirectSoundBuffer_SetCurrentPosition(snd->dsbuffer, 0); - } - - return (snd - _stack); -} - -/****************************************************************************** - * - * Destroy source and remove it from stack if it is a 2D source. - * Otherwise put source into cache - * - *****************************************************************************/ -EXPORT void HWRAPI (KillSource) (INT32 handle) -{ - - if (handle < 0 || handle >= allocated_sounds) - return; -/* - if (_stack[handle].dsbuffer3D) - { - // It's a 3D source so let him chance to be reused :-) - _stack[handle].LRU = 1; - } - else - { */ - // No, it is a 2D source so kill him - kill_sound(_stack + handle); - //} -} - - -/****************************************************************************** - * - * Update volume and separation (panning) of 2D source - * - *****************************************************************************/ -EXPORT void HWRAPI (Update2DSoundParms) (INT32 handle, INT32 vol, INT32 sep) -{ - LPDIRECTSOUNDBUFFER dsbuffer; - - if (handle < 0 || handle >= allocated_sounds) - return; - - if ((_stack+handle)->dsbuffer3D) - return; - dsbuffer = (_stack + handle)->dsbuffer; - - UpdateSoundVolume(dsbuffer, vol); - Update2DSoundPanning(dsbuffer, sep); -} - - - -// -------------------------------------------------------------------------- -// Set the global volume for sound effects -// -------------------------------------------------------------------------- -EXPORT void HWRAPI (SetGlobalSfxVolume) (INT32 volume) -{ - INT32 vol; - HRESULT hr; - - // use the last quarter of volume range - if (volume) - vol = recalc_volume(volume, 31); - else - vol = DSBVOLUME_MIN; - - hr = IDirectSoundBuffer_SetVolume (PrimaryBuffer, vol); -} - -EXPORT void HWRAPI ( StopSource) (INT32 handle) -{ - LPDIRECTSOUNDBUFFER dsbuffer; - - if (handle < 0 || handle >= allocated_sounds) - return; - - dsbuffer = (_stack + handle)->dsbuffer; - - if (dsbuffer) - { - IDirectSoundBuffer_Stop(dsbuffer); - IDirectSoundBuffer_SetCurrentPosition(dsbuffer, 0); - } -} - - -EXPORT INT32 HWRAPI ( GetHW3DSVersion) (void) -{ - return VERSION; -} - - -EXPORT void HWRAPI (BeginFrameUpdate) (void) -{ - update_mode = DS3D_DEFERRED; -} - - -EXPORT void HWRAPI (EndFrameUpdate) (void) -{ - if (update_mode == DS3D_DEFERRED) - IDirectSound3DListener_CommitDeferredSettings(Listener); - - update_mode = DS3D_IMMEDIATE; -} - - -/****************************************************************************** - * UpdateListener - * - * Set up main listener properties: - * - position - * - orientation - * - velocity - *****************************************************************************/ -EXPORT void HWRAPI (UpdateListener) (listener_data_t *data) -{ - D3DVECTOR pos; - D3DVECTOR face; - D3DVECTOR head; - D3DVECTOR velocity; - double f_angle; - //double h_angle, t_angle; - //double f_cos, f_sin, t_sin; - -#ifdef DUMMYUNIONNAMEN - pos.DUMMYUNIONNAMEN(9).x = (D3DVALUE)data->x; - pos.DUMMYUNIONNAMEN(10).y = (D3DVALUE)data->z; - pos.DUMMYUNIONNAMEN(11).z = (D3DVALUE)data->y; - - velocity.DUMMYUNIONNAMEN(9).x = (D3DVALUE)data->momx; - velocity.DUMMYUNIONNAMEN(10).y = (D3DVALUE)data->momz; - velocity.DUMMYUNIONNAMEN(11).z = (D3DVALUE)data->momy; -#else - pos.x = (D3DVALUE)data->x; - pos.y = (D3DVALUE)data->z; - pos.z = (D3DVALUE)data->y; - - velocity.x = (D3DVALUE)data->momx; - velocity.y = (D3DVALUE)data->momz; - velocity.z = (D3DVALUE)data->momy; -#endif - f_angle = (data->f_angle) / 180 * M_PI; - //h_angle = data->h_angle / 180 * M_PI; - //h_angle = 90 / 180 * M_PI; - - // Treat listener orientation angles as spherical coordinates. - // x = sin h * cos f - // y = sin h * sin f - // z = cos h - - // Front vector - //t_angle = (M_PI/2 - h_angle); - //t_angle = M_PI/2; - - //face.x = (t_sin = sin(t_angle)) * (f_cos = cos(f_angle)); - //face.z = t_sin * (f_sin = sin(f_angle)); - //face.y = cos(t_angle); -#ifdef DUMMYUNIONNAMEN - face.DUMMYUNIONNAMEN(9).x = (D3DVALUE)cos(f_angle); - face.DUMMYUNIONNAMEN(11).z = (D3DVALUE)sin(f_angle); - face.DUMMYUNIONNAMEN(10).y = 0.0f; - - head.DUMMYUNIONNAMEN(9).x = 0.0f; - head.DUMMYUNIONNAMEN(10).y = 1.0f; - head.DUMMYUNIONNAMEN(11).z = 0.0f; -#else - face.x = (D3DVALUE)cos(f_angle); - face.z = (D3DVALUE)sin(f_angle); - face.y = 0.0f; - - head.x = 0.0f; - head.y = 1.0f; - head.z = 0.0f; -#endif - // Top vector - //h_angle = (-data->h_angle) / 180 * M_PI; - -/* - t_angle = -h_angle; - - head.z = (t_sin = sin(t_angle)) * f_cos; - head.x = t_sin * f_sin; - head.y = cos(t_angle); -*/ - - // Update at once - CopyMemory(&listener_parms.vPosition, &pos, sizeof (D3DVECTOR)); - CopyMemory(&listener_parms.vOrientFront, &face, sizeof (D3DVECTOR)); - CopyMemory(&listener_parms.vOrientTop, &head, sizeof (D3DVECTOR)); - CopyMemory(&listener_parms.vVelocity, &velocity, sizeof (D3DVECTOR)); - //IDirectSound3DListener_SetAllParameters(Listener, &listener_parms, DS3D_IMMEDIATE); - IDirectSound3DListener_SetAllParameters(Listener, &listener_parms, update_mode); -} - -EXPORT void HWRAPI (UpdateListener2) (listener_data_t *data) -{ - D3DVECTOR pos; - D3DVECTOR face; - D3DVECTOR head; - D3DVECTOR velocity; - double f_angle; - //double h_angle, t_angle; - //double f_cos, f_sin, t_sin; - - if (!data) return; - -#ifdef DUMMYUNIONNAMEN - pos.DUMMYUNIONNAMEN(9).x = (D3DVALUE)data->x; - pos.DUMMYUNIONNAMEN(10).y = (D3DVALUE)data->z; - pos.DUMMYUNIONNAMEN(11).z = (D3DVALUE)data->y; - - velocity.DUMMYUNIONNAMEN(9).x = (D3DVALUE)data->momx; - velocity.DUMMYUNIONNAMEN(10).y = (D3DVALUE)data->momz; - velocity.DUMMYUNIONNAMEN(11).z = (D3DVALUE)data->momy; -#else - pos.x = (D3DVALUE)data->x; - pos.y = (D3DVALUE)data->z; - pos.z = (D3DVALUE)data->y; - - velocity.x = (D3DVALUE)data->momx; - velocity.y = (D3DVALUE)data->momz; - velocity.z = (D3DVALUE)data->momy; -#endif - f_angle = (data->f_angle) / 180 * M_PI; - //h_angle = data->h_angle / 180 * M_PI; - //h_angle = 90 / 180 * M_PI; - - // Treat listener orientation angles as spherical coordinates. - // x = sin h * cos f - // y = sin h * sin f - // z = cos h - - // Front vector - //t_angle = (M_PI/2 - h_angle); - //t_angle = M_PI/2; - - //face.x = (t_sin = sin(t_angle)) * (f_cos = cos(f_angle)); - //face.z = t_sin * (f_sin = sin(f_angle)); - //face.y = cos(t_angle); -#ifdef DUMMYUNIONNAMEN - face.DUMMYUNIONNAMEN(9).x = cos(f_angle); - face.DUMMYUNIONNAMEN(11).z = sin(f_angle); - face.DUMMYUNIONNAMEN(10).y = 0.0f; - - head.DUMMYUNIONNAMEN(9).x = 0.0f; - head.DUMMYUNIONNAMEN(10).y = 1.0f; - head.DUMMYUNIONNAMEN(11).z = 0.0f; -#else - face.x = (D3DVALUE)cos(f_angle); - face.z = (D3DVALUE)sin(f_angle); - face.y = 0.0f; - - head.x = 0.0f; - head.y = 1.0f; - head.z = 0.0f; -#endif - - // Top vector - //h_angle = (-data->h_angle) / 180 * M_PI; - -/* - t_angle = -h_angle; - - head.z = (t_sin = sin(t_angle)) * f_cos; - head.x = t_sin * f_sin; - head.y = cos(t_angle); -*/ - - // Update at once - CopyMemory(&listener_parms.vPosition, &pos, sizeof (D3DVECTOR)); - CopyMemory(&listener_parms.vOrientFront, &face, sizeof (D3DVECTOR)); - CopyMemory(&listener_parms.vOrientTop, &head, sizeof (D3DVECTOR)); - CopyMemory(&listener_parms.vVelocity, &velocity, sizeof (D3DVECTOR)); - //IDirectSound3DListener_SetAllParameters(Listener, &listener_parms, DS3D_IMMEDIATE); - //Alam_GBC: 2 Listeners? - //IDirectSound3DListener_SetAllParameters(Listener, &listener_parms, update_mode); -} - -EXPORT INT32 HWRAPI (SetCone) (INT32 handle, cone_def_t *cone_def) -{ - stack_t *snd; - //DS3DBUFFER parms; - - if (handle < 0 || handle >= allocated_sounds) - return -1; - - snd = _stack + handle; - - if (snd->dsbuffer3D) - { - - /*f_angle = cone_def->f_angle / 180 * M_PI; - h_angle = (90 - cone_def->h_angle) / 180 * M_PI; - parms.vConeOrientation.x = sin(h_angle) * cos(f_angle); - parms.vConeOrientation.z = sin(h_angle) * sin(f_angle); - parms.vConeOrientation.y = cos(h_angle);*/ - - snd->parameters.dwInsideConeAngle = (DWORD)cone_def->inner; - snd->parameters.dwOutsideConeAngle = (DWORD)cone_def->outer; - snd->parameters.lConeOutsideVolume = recalc_volume(cone_def->outer_gain, 256); - - return IDirectSound3DBuffer_SetAllParameters(snd->dsbuffer3D, &snd->parameters, update_mode); - } - - return -1; -} - -EXPORT void HWRAPI (Update3DSource) (INT32 handle, source3D_pos_t *data) -{ - stack_t *snd; - - if (handle < 0 || handle >= allocated_sounds) - return; - - snd = _stack + handle; - if (snd->dsbuffer3D) - { - - /*parms.dwSize = sizeof (DS3DBUFFER); - IDirectSound3DBuffer_GetAllParameters(snd, &parms);*/ - - //angle = data->angle * 180 / M_PI; - -#ifdef DUMMYUNIONNAMEN - snd->parameters.vPosition.DUMMYUNIONNAMEN(9).x = data->x; - snd->parameters.vPosition.DUMMYUNIONNAMEN(10).y = data->z; - snd->parameters.vPosition.DUMMYUNIONNAMEN(11).z = data->y; -#else - snd->parameters.vPosition.x = data->x; - snd->parameters.vPosition.y = data->z; - snd->parameters.vPosition.z = data->y; -#endif - - /*parms.vConeOrientation.x = cos(angle); - parms.vConeOrientation.z = sin(angle); - parms.vConeOrientation.y = 0;*/ - -#ifdef DUMMYUNIONNAMEN - snd->parameters.vVelocity.x = data->momx; - snd->parameters.vVelocity.y = data->momz; - snd->parameters.vVelocity.z = data->momy; -#else - snd->parameters.vVelocity.x = data->momx; - snd->parameters.vVelocity.y = data->momz; - snd->parameters.vVelocity.z = data->momy; -#endif - - //snd->parameters.flMinDistance = data->min_distance; - //snd->parameters.flMaxDistance = data->max_distance; - //snd->parameters.dwMode = pos->head_realtive?DS3DMODE_HEADREALTIVE:DS3DMODE_NORMAL; - - IDirectSound3DBuffer_SetAllParameters(snd->dsbuffer3D, &snd->parameters, update_mode); - } -} - - -EXPORT INT32 HWRAPI (StartSource) (INT32 handle) -{ - LPDIRECTSOUNDBUFFER snd; - - if (handle < 0 || handle >= allocated_sounds) - return -1; - - snd = (_stack + handle)->dsbuffer; - IDirectSoundBuffer_SetCurrentPosition(snd, 0); - return IDirectSoundBuffer_Play(snd, 0, 0, 0); - -} - -//------------------------------------------------------------- -// Load new sound data into source -//------------------------------------------------------------- -EXPORT INT32 HWRAPI (Reload3DSource) (INT32 handle, sfx_data_t *data) -{ - DS3DBUFFER temp; - stack_t *snd; - INT32 perm; - - // DirectX could not load new sound data into source - // so recreate sound buffers - if (handle < 0 || handle >= allocated_sounds) - return -1; - - snd = _stack + handle; - CopyMemory(&temp, &snd->parameters, sizeof (DS3DBUFFER)); - perm = snd->permanent; - - kill_sound(snd); - - snd = setup_source(handle, data, IS_3DSOURCE); - /*snd->dsbuffer = create_buffer(data->data, data->length, true); - if (snd->dsbuffer == NULL) - return -1; - snd->dsbuffer3D = create_3dbuffer(snd->dsbuffer, snd->dsbuffer3D); - if (snd->dsbuffer3D == NULL) - { - RELEASE_BUFFER(snd->dsbuffer); - return -1; - } - - snd->sfx_id = data->id; - snd->LRU = 0;*/ - if (snd) - { - snd->permanent = perm; - IDirectSound3DBuffer_SetAllParameters(snd->dsbuffer3D, &temp, DS3D_IMMEDIATE); - CopyMemory(&snd->parameters, &temp, sizeof (DS3DBUFFER)); - } - - return(snd - _stack); -} - -EXPORT void HWRAPI (UpdateSourceVolume) (INT32 handle, INT32 volume) -{ - if (handle < 0 || handle >= allocated_sounds) - return; - UpdateSoundVolume((_stack + handle)->dsbuffer, volume); -} diff --git a/src/hardware/s_ds3d/s_ds3d.dev b/src/hardware/s_ds3d/s_ds3d.dev deleted file mode 100644 index 1b51b1b77..000000000 --- a/src/hardware/s_ds3d/s_ds3d.dev +++ /dev/null @@ -1,59 +0,0 @@ -[Project] -FileName=s_ds3d.dev -Name=s_ds3d -Ver=1 -IsCpp=1 -Type=3 -Compiler=-D_M_IX86=500_@@_-Wall_@@_-D_WINDOWS_@@_-Os_@@_-fno-strict-aliasing_@@_-fomit-frame-pointer_@@_ -CppCompiler= -Includes= -Linker=--def ../s_mingw.def_@@_-luuid_@@_-ldsound_@@_ -Libs= -UnitCount=1 -Folders= -ObjFiles= -PrivateResource= -ResourceIncludes= -MakeIncludes= -Icon= -ExeOutput=C:\srb2demo2 -ObjectOutput=..\..\..\objs\Mingw\s_ds3d -OverrideOutput=1 -OverrideOutputName=s_ds3d.dll -HostApplication= -CommandLine= -IncludeVersionInfo=0 -SupportXPThemes=0 -CompilerSet=0 -CompilerSettings=00000000000000000111d0 -UseCustomMakefile=0 -CustomMakefile= - -[Unit1] -FileName=s_ds3d.c -Folder= -Compile=1 -CompileCpp=0 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[VersionInfo] -Major=0 -Minor=1 -Release=1 -Build=1 -LanguageID=1033 -CharsetID=1252 -CompanyName= -FileVersion=0.1 -FileDescription=Developed using the Dev-C++ IDE -InternalName= -LegalCopyright= -LegalTrademarks= -OriginalFilename=s_ds3d.exe -ProductName=s_ds3d -ProductVersion=0.1 -AutoIncBuildNr=0 - diff --git a/src/hardware/s_ds3d/s_ds3d.dsp b/src/hardware/s_ds3d/s_ds3d.dsp deleted file mode 100644 index a82207c97..000000000 --- a/src/hardware/s_ds3d/s_ds3d.dsp +++ /dev/null @@ -1,99 +0,0 @@ -# Microsoft Developer Studio Project File - Name="s_ds3d" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=s_ds3d - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "s_ds3d.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "s_ds3d.mak" CFG="s_ds3d - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "s_ds3d - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "s_ds3d - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "s_ds3d - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\..\..\bin\VC\Release\s_ds3d" -# PROP Intermediate_Dir "..\..\..\objs\VC\Release\s_ds3d" -# PROP Ignore_Export_Lib 1 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "S_DS3D_EXPORTS" /YX /FD /c -# ADD CPP /nologo /G5 /MT /W3 /GX /Zi /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /FD /c -# SUBTRACT CPP /YX -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x419 /d "NDEBUG" -# ADD RSC /l 0x40c /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 dsound.lib /nologo /dll /pdb:"..\..\..\bin\VC\Release\s_ds3d.pdb" /machine:I386 /out:"..\..\..\bin\VC\Release\s_ds3d.dll" -# SUBTRACT LINK32 /pdb:none - -!ELSEIF "$(CFG)" == "s_ds3d - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\..\..\bin\VC\Debug\s_ds3d" -# PROP Intermediate_Dir "..\..\..\objs\VC\Debug\s_ds3d" -# PROP Ignore_Export_Lib 1 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "S_DS3D_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /FD /GZ /c -# SUBTRACT CPP /YX -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 -# ADD BASE RSC /l 0x419 /d "_DEBUG" -# ADD RSC /l 0x40c /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 dsound.lib /nologo /dll /pdb:"..\..\..\bin\VC\Debug\s_ds3d.pdb" /debug /machine:I386 /out:"..\..\..\bin\VC\Debug\s_ds3d.dll" /pdbtype:sept -# SUBTRACT LINK32 /pdb:none /incremental:no /nodefaultlib - -!ENDIF - -# Begin Target - -# Name "s_ds3d - Win32 Release" -# Name "s_ds3d - Win32 Debug" -# Begin Source File - -SOURCE=.\s_ds3d.c -# End Source File -# End Target -# End Project diff --git a/src/hardware/s_fmod/s_fmod.c b/src/hardware/s_fmod/s_fmod.c deleted file mode 100644 index 5d4422bb1..000000000 --- a/src/hardware/s_fmod/s_fmod.c +++ /dev/null @@ -1,1201 +0,0 @@ -// Emacs style mode select -*- C++ -*- -//----------------------------------------------------------------------------- -// -// Copyright (C) 2001 by DooM Legacy Team. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -//----------------------------------------------------------------------------- -/// \file -/// \brief General driver for 3D sound system -/// -/// Implementend via FMOD_SOUND API - -#ifdef _WINDOWS -//#define WIN32_LEAN_AND_MEAN -#define RPC_NO_WINDOWS_H -#include -#else -#include -#include -#include -#include -#include -#endif - -#include -FILE *logstream = NULL; - -#ifdef __MINGW32__ -#include -#else -#include -#endif - -#ifdef FSOUND_INIT_DONTLATENCYADJUST //Alam: why didn't I think about this before? :) -#define FSOUND_Sample_Load(index,data,mode,length) FSOUND_Sample_Load(index,data,mode,0,length) -#else -#define OLDFMOD //Alam: Yea! -#endif - -#ifdef __MINGW32__ -#include -#else -#include /* optional */ -#endif - -#define MAXCHANNEL 1024 - -#undef DEBUG_TO_FILE -#if defined ( HAVE_SDL ) && !defined ( LOGMESSAGES ) -#define DEBUG_TO_FILE -#endif - -#ifndef MORESTUFF -//#define MORESTUFF -#define REL2D -#endif - -#define _CREATE_DLL_ -#include "../../doomdef.h" -#include "../hw3dsdrv.h" -#define INT2CHAR(p) (char *)p + 8 - -//Doom sound sample format -#define FSOUND_UNORMAL (FSOUND_8BITS | FSOUND_MONO | FSOUND_UNSIGNED) -//Load Raw -#define FSOUND_RAWLOAD (FSOUND_LOADRAW | FSOUND_LOADMEMORY) -//Load Sample Raw from pointer -#define FSOUND_DOOMLOAD (FSOUND_UNORMAL | FSOUND_RAWLOAD) -//length of SFX -#define SFXLENGTH (sfx->length-8) - -//SRB2 treats +X as east, +Y as north, +Z as up. -//FSOUND treats +X as right, +Y as up, and +Z as forwards. -//So SRB2's XZY is FSOUND's XYZ -//And FSOUND's XZY is SRB2's XYZ - -static I_Error_t I_ErrorFMOD = NULL; - -static FSOUND_SAMPLE *blankfmsample = NULL; - -// Calculate sound pitching -static float recalc_pitch(INT32 doom_pitch) -{ -#ifdef MORESTUFF - return (float)1; -#else - return doom_pitch < NORMAL_PITCH ? - (float)(doom_pitch + NORMAL_PITCH) / (NORMAL_PITCH * 2) - :(float)doom_pitch / (float)NORMAL_PITCH; -#endif -} - -/*************************************************************** - * - * DBG_Printf - * Output error messages to debug log if DEBUG_TO_FILE is defined, - * else do nothing - * - ************************************************************** - */ -// -----------------+ -// DBG_Printf : Output error messages to debug log if DEBUG_TO_FILE is defined, -// : else do nothing -// Returns : -// -----------------+ -FUNCPRINTF void DBG_Printf(const char *lpFmt, ...) -{ -#ifdef DEBUG_TO_FILE - char str[4096] = ""; - va_list arglist; - - va_start(arglist, lpFmt); - vsnprintf(str, 4096, lpFmt, arglist); - va_end(arglist); - - if (logstream) - fwrite(str, strlen(str), 1, logstream); -#endif -} - -// Start of head_relative system for FMOD3D - -typedef struct rellistener_s -{ - float pos[3]; - INT32 active; - float vel[3]; - -} rellistener_s_t; //Easy - -static rellistener_s_t rellistener[2]; //The 2 listeners - -typedef struct relarray_s -{ - INT32 handle; // handle number - INT32 chan; // real channel - INT32 listener; // for which listener - rellistener_s_t pos; // source position in 3D -} relarray_s_t; - -static relarray_s_t relarray[STATIC_SOURCES_NUM+1]; // array of chans - - -//set listener -static void relset(INT32 which) -{ - INT32 i; - - if (which == -2 || which == -1) - { - which = -which; - - memset(&rellistener[which-1], 0, sizeof (rellistener_s_t)); //Delete me - for (i = 0; i <= STATIC_SOURCES_NUM; i++) - { - if (relarray[i].pos.active && relarray[i].listener == which) - { - FSOUND_SetPaused(relarray[i].chan,true); - relarray[i].pos.active = false; - } - } - return; - } - else if (which == 1 || which ==2) - { - float pos[3], vel[3]; // Temp bin - which -= 1; //Hello! - - //Get update - FSOUND_3D_Listener_GetAttributes(&pos[0],&vel[0],NULL,NULL,NULL,NULL,NULL,NULL); - memcpy(&rellistener[which].pos[0],&pos[0],sizeof (pos)); - memcpy(&rellistener[which].vel[0],&vel[0],sizeof (vel)); - - if (!rellistener[which].active) - for (i = 0; i <= STATIC_SOURCES_NUM; i++) - { - if (!relarray[i].pos.active && relarray[i].listener == which) - { - FSOUND_SetPaused(relarray[i].chan,false); - relarray[i].pos.active = true; - } - } - - rellistener[which].active = which; - } - else - { - memset(&rellistener[0], 0, sizeof (rellistener_s_t)); - memset(&rellistener[1], 0, sizeof (rellistener_s_t)); - } -} - -//setup system -static void relsetup() -{ - INT32 i; - - // Setup the rel array for use - for (i = 0; i <= STATIC_SOURCES_NUM; i++) - { - relarray[i].handle = FSOUND_FREE; - relarray[i].chan = FSOUND_FREE; - relarray[i].listener = (i == 1 || i == 3)?2:1; - memset(&relarray[i].pos, 0, sizeof (rellistener_s_t)); - } - - // Set up the Listener array - relset(0); -} - - -//checkup for stack -static INT32 relstack(INT32 chan) -{ - INT32 i; - - for (i = 0; i <= STATIC_SOURCES_NUM; i++) - { - if (relarray[i].pos.active && relarray[i].handle == chan) - return i; - } - return -1; -} - -//checkup for fake rel chan -static INT32 relcheckup(INT32 chan) -{ - INT32 i = relstack(chan); - - if (i == -1) - return chan; - else - return relarray[i].chan; -} - - //Update place rel chan's vol -static void relvol(INT32 chan) -{ - INT32 vol = FSOUND_GetVolume(chan); - INT32 error = FSOUND_GetError(); - - if (chan == relcheckup(chan)) - return; - - if (!vol && error) - DBG_Printf("FMOD(relvol, FSOUND_GetVolume, Channel # %i): %s\n",chan,FMOD_ErrorString(error)); - else if (!FSOUND_SetVolume(relcheckup(chan), vol)) - DBG_Printf("FMOD(relvol, FSOUND_SetVolume, Channel # %i): %s\n",chan,FMOD_ErrorString(FSOUND_GetError())); -} - -//Copy rel chan -static INT32 relcopy(INT32 handle) -{ - FSOUND_SAMPLE *fmsample = NULL; - INT32 chan = -1; - float pos[3]; - float vel[3]; - - if (!FSOUND_3D_GetAttributes(handle,&pos[0],&vel[0])) - if (FSOUND_GetError() != FMOD_ERR_NONE) DBG_Printf("FMOD(relcopy, FSOUND_3D_GetAttributes, Channel # %i): %s\n",handle,FMOD_ErrorString(FSOUND_GetError())); - - fmsample = FSOUND_GetCurrentSample(handle); - - if (fmsample) - { -#ifdef REL2D - if (!FSOUND_Sample_SetMode(fmsample, FSOUND_2D)) - DBG_Printf("FMOD(relcopy, FSOUND_Sample_SetMode, handle# %i): %s\n",handle,FMOD_ErrorString(FSOUND_GetError())); -#endif - chan = FSOUND_PlaySoundEx(FSOUND_FREE,fmsample,NULL,true); - - if (chan == -1) - { - if (FSOUND_GetError() != FMOD_ERR_NONE) DBG_Printf("FMOD(relcopy, FSOUND_PlaySoundEx, handle# %i): %s\n",handle,FMOD_ErrorString(FSOUND_GetError())); - return FSOUND_FREE; - } -#ifdef MORESTUFF - else - DBG_Printf("FMOD(relcopy, Main): Copy Handle#%i to channel#%i\n",handle,chan); -#endif - } - else - { - if (FSOUND_GetError() != FMOD_ERR_NONE) - DBG_Printf("FMOD(relcopy, FSOUND_GetCurrentSample, handle# %i): %s\n",handle,FMOD_ErrorString(FSOUND_GetError())); - chan = FSOUND_PlaySoundEx(FSOUND_FREE,blankfmsample,NULL,true); - //return FSOUND_FREE; - } - - if (FSOUND_GetCurrentSample(chan)) - { - - if (!FSOUND_SetCurrentPosition(chan, 0)) - DBG_Printf("FMOD(relcopy, FSOUND_SetCurrentPosition, handle#%i, channel# %i): %s\n",handle,chan,FMOD_ErrorString(FSOUND_GetError())); -#ifndef REL2D - if (!FSOUND_3D_SetAttributes(chan,pos,vel)) - DBG_Printf("FMOD(relcopy, FSOUND_3D_SetAttributes, handle#%i, channel#%i): %s\n",handle,chan,FMOD_ErrorString(FSOUND_GetError())); -#endif -/* - if (!FSOUND_SetReserved(chan, TURE)) - DBG_Printf("FMOD(relcopy, FSOUND_SetReserved, handle#%i, channel# %i): %s\n",handle,chan,FMOD_ErrorString(FSOUND_GetError())); -*/ - return chan; - } - - return FSOUND_FREE; -} - -//update the rel chans -static void relupdate(INT32 handle) -{ - if (handle == FSOUND_FREE) - { - INT32 stack; - - for (stack = 0; stack <= STATIC_SOURCES_NUM;stack++) - { - //if (FSOUND_GetCurrentSample(relarray[stack].handle)) - // relarray[stack].chan = relcopy(relarray[stack].handle); - - if (relarray[stack].chan != FSOUND_FREE) - { - relarray[stack].pos.active = false; - relupdate(relarray[stack].chan); - } - else - relarray[stack].pos.active = false; - } - } - else if (handle == relcheckup(handle)) - return; -#ifndef REL2D - else - { - float pos[3], vel[3]; - INT32 stack = relstack(handle); - INT32 chan = relcheckup(handle); - INT32 which = relarray[stack].listener; - - pos[0] = relarray[stack].pos.pos[0] + rellistener[which].pos[0]; - pos[1] = relarray[stack].pos.pos[1] + rellistener[which].pos[1]; - pos[2] = relarray[stack].pos.pos[2] + rellistener[which].pos[2]; - vel[0] = relarray[stack].pos.vel[0] + rellistener[which].vel[0]; - vel[1] = relarray[stack].pos.vel[1] + rellistener[which].vel[1]; - vel[2] = relarray[stack].pos.vel[2] + rellistener[which].vel[2]; - - if (!FSOUND_3D_SetAttributes(chan,pos,vel)) - DBG_Printf("FMOD(relupdate, FSOUND_3D_SetAttributes, Handle #%i,Channel #%i): %s\n",handle, chan,FMOD_ErrorString(FSOUND_GetError())); - } -#endif -} - - //Update place rel chan's pos -static void relplace(INT32 chan) -{ - float pos[3], vel[3]; // Temp bin - - if (chan == relcheckup(chan)) - return; - - if (!FSOUND_3D_GetAttributes(chan,&pos[0],&vel[0])) - { - if (FSOUND_GetError() != FMOD_ERR_NONE) DBG_Printf("FMOD(relplace, FSOUND_3D_GetAttributes, Channel # %i): %s\n",chan,FMOD_ErrorString(FSOUND_GetError())); - } - else - { - INT32 stack = relstack(chan); - - if (stack == -1) - return; - - memcpy(&relarray[stack].pos.pos,&pos,sizeof (pos)); - memcpy(&relarray[stack].pos.vel,&vel,sizeof (vel)); - relupdate(chan); - } -} - -//New rel chan -static void reladd(INT32 chan) -{ - if (chan != relcheckup(chan)) - return; - else - { - INT32 stack = STATIC_SOURCES_NUM; - { - if (relarray[0].handle == FSOUND_FREE) - stack = 0; - else if (relarray[1].handle == FSOUND_FREE) - stack = 1; - else if (relarray[2].handle == FSOUND_FREE) - stack = 2; - else if (relarray[3].handle == FSOUND_FREE) - stack = 3; - else if (relarray[4].handle == FSOUND_FREE) - stack = 4; - else if (relarray[5].handle == FSOUND_FREE) - stack = 5; - else - DBG_Printf("No more room in relarray\n"); - } - - relarray[stack].handle = chan; - relarray[stack].chan = relcopy(chan); - - if (relarray[stack].chan != FSOUND_FREE) - { - relarray[stack].pos.active = true; - relupdate(chan); - } - else - relarray[stack].pos.active = false; - } -} - -// End of head_relative system for FMOD3D - - -/****************************************************************************** - * - * Initialise driver and listener - * - *****************************************************************************/ -EXPORT INT32 HWRAPI(Startup) (I_Error_t FatalErrorFunction, snddev_t *snd_dev) -{ - boolean inited = false; - INT32 i = 0; - - I_ErrorFMOD = FatalErrorFunction; - - if (FSOUND_GetVersion() < FMOD_VERSION) - { - DBG_Printf("Error : You are using the wrong DLL version!\nYou should be using FMOD %.02f\n", FMOD_VERSION); - return inited; - } - else - DBG_Printf("S_FMOD Init(): FMOD_SOUND driver for SRB2Kart %s\n",VERSIONSTRING); - - if (!FSOUND_SetMinHardwareChannels(STATIC_SOURCES_NUM*4)) - DBG_Printf("FMOD(Startup,FSOUND_SetMinHardwareChannels,# of Channels Min: %i): %s\n",STATIC_SOURCES_NUM*4, FMOD_ErrorString(FSOUND_GetError())); - - if (!FSOUND_SetMaxHardwareChannels(0)) - DBG_Printf("FMOD(Startup,FSOUND_SetMaxHardwareChannels,# of Channels Min: %i): %s\n",0, FMOD_ErrorString(FSOUND_GetError())); - - for (i = 0; i < FSOUND_GetNumDrivers(); i++) - { - UINT32 caps = 0; - DBG_Printf("Driver Caps, if any\n"); - - if (FSOUND_GetDriverCaps(i, &caps)) - { - DBG_Printf("FMOD: Driver# %d - %s\n", i+1, FSOUND_GetDriverName(i)); // print driver names - if (caps & FSOUND_CAPS_HARDWARE) - DBG_Printf("This sound hardware supports hardware accelerated 3d sound.\n"); - - if (caps & FSOUND_CAPS_EAX2) - DBG_Printf("This sound hardware supports hardware accelerated 3d sound with EAX 2 reverb.\n"); - - if (caps & FSOUND_CAPS_EAX3) - DBG_Printf("This sound hardware supports hardware accelerated 3d sound with EAX 3 reverb.\n"); - } - else - DBG_Printf("FMOD(Startup,FSOUND_GetDriverCaps,%s): %s\n",FSOUND_GetDriverName(i), FMOD_ErrorString(FSOUND_GetError())); - } -#if defined (_WIN32) || defined (_WIN64) - if (!FSOUND_SetHWND(snd_dev->hWnd)) - { - DBG_Printf("FMOD(Startup,FSOUND_SetHWND): %s\n", FMOD_ErrorString(FSOUND_GetError())); - return inited; - } - else -#endif - { - DBG_Printf("Initialising FMOD %.02f\n",FMOD_VERSION); - inited = FSOUND_Init(snd_dev->sample_rate,MAXCHANNEL,0); - } - - if (!inited) - { - DBG_Printf("FMOD(Startup,Main): %s\n", FMOD_ErrorString(FSOUND_GetError())); - } - else - { -#ifdef OLDFMOD - DBG_Printf(" Maximum hardware mixing buffers %d\n", FSOUND_GetNumHardwareChannels()); -#else - INT32 num2DC, num3DC, numDC; - - if (FSOUND_GetNumHWChannels(&num2DC,&num3DC,&numDC)) - { - DBG_Printf(" Maximum hardware 2D buffers %d\n", num2DC); - DBG_Printf(" Maximum hardware 3D buffers %d\n", num3DC); - DBG_Printf(" Maximum hardware mixing buffers %d\n", numDC); - } - else - DBG_Printf("FMOD(Startup,FSOUND_GetNumHWChannels): %s\n", FMOD_ErrorString(FSOUND_GetError())); -#endif - - DBG_Printf("FMOD is up and running at %i KHZ\n",FSOUND_GetOutputRate()); - DBG_Printf("Sound hardware capabilities:\n"); - - if (FSOUND_GetDriverName(FSOUND_GetDriver())) - DBG_Printf(" Driver is %s\n",FSOUND_GetDriverName(FSOUND_GetDriver())); - else - DBG_Printf("FMOD(Startup,FSOUND_GetDriverName): %s\n", FMOD_ErrorString(FSOUND_GetError())); - - FSOUND_3D_SetDistanceFactor(1.0f/72.0f); - FSOUND_3D_SetRolloffFactor(0); - FSOUND_3D_SetRolloffFactor(1.6f); -#ifdef MORESTUFF - FSOUND_3D_SetDopplerFactor(0); -#endif - - switch (FSOUND_GetOutput()) - { - case FSOUND_OUTPUT_NOSOUND: - DBG_Printf("FMOD driver: NoSound driver, all calls to this succeed but do nothing.\n"); - break; - case FSOUND_OUTPUT_WINMM: - DBG_Printf("FMOD driver: Windows Multimedia driver.\n"); - break; - case FSOUND_OUTPUT_DSOUND: - DBG_Printf("FMOD driver: DirectSound driver. You need this to get EAX2 or EAX3 support, or FX api support.\n"); - break; - case FSOUND_OUTPUT_A3D: - DBG_Printf("FMOD driver: A3D driver.\n"); - break; - case FSOUND_OUTPUT_OSS: - DBG_Printf("FMOD driver: Linux/Unix OSS (Open Sound System) driver, i.e. the kernel sound drivers.\n"); - break; - case FSOUND_OUTPUT_ESD: - DBG_Printf("FMOD driver: Linux/Unix ESD (Enlightment Sound Daemon) driver.\n"); - break; - case FSOUND_OUTPUT_ALSA: - DBG_Printf("FMOD driver: Linux Alsa driver.\n"); - break; - case FSOUND_OUTPUT_MAC: - DBG_Printf("FMOD driver: Mac SoundManager driver\n"); - break; - case FSOUND_OUTPUT_NOSOUND_NONREALTIME: - DBG_Printf("FMOD driver: This is the same as nosound, but the sound generation is driven by FSOUND_Update\n"); - break; - case FSOUND_OUTPUT_ASIO: - DBG_Printf("FMOD driver: Low latency ASIO driver\n"); - break; - default: - DBG_Printf("FMOD driver: Unknown Sound Driver\n"); - break; - } - - relsetup(); - - blankfmsample = FSOUND_Sample_Alloc(FSOUND_UNMANAGED,1,FSOUND_UNORMAL,11025,127,FSOUND_STEREOPAN,127); - - if (!blankfmsample) - DBG_Printf("FMOD(Startup,FSOUND_Sample_Alloc): %s\n", FMOD_ErrorString(FSOUND_GetError())); - else if (!FSOUND_Sample_SetMaxPlaybacks(blankfmsample,STATIC_SOURCES_NUM*2)) - DBG_Printf("FMOD(Startup,FSOUND_Sample_SetMaxPlaybacks): %s\n", FMOD_ErrorString(FSOUND_GetError())); - } - return inited; -} - -EXPORT void HWRAPI(Shutdown) (void) -{ - DBG_Printf("Shuting down FMOD\n"); - FSOUND_Sample_Free(blankfmsample); - DBG_Printf("Shutdown of FMOD done\n"); - FSOUND_Close(); -} - -/****************************************************************************** - * - * Creates 3D source - * - ******************************************************************************/ - -EXPORT INT32 HWRAPI (Add3DSource) (source3D_data_t *src, sfx_data_t *sfx) -{ - FSOUND_SAMPLE *fmsample = NULL; - INT32 chan = -1; - float pos[3]; - float vel[3]; -#ifdef MORESTUFF - src->min_distance = MIN_DISTANCE; - src->max_distance = MAX_DISTANCE; -#endif - - pos[0] = src->pos.x; - pos[1] = src->pos.z; - pos[2] = src->pos.y; - vel[0] = src->pos.momx; - vel[1] = src->pos.momz; - vel[2] = src->pos.momy; - if (sfx) - fmsample = FSOUND_Sample_Load(FSOUND_FREE, INT2CHAR(sfx->data), FSOUND_DOOMLOAD, SFXLENGTH); - else - fmsample = blankfmsample; - - if (fmsample) - { - if (sfx && !FSOUND_Sample_SetDefaults(fmsample, - (INT32)((*((UINT16 *)sfx->data+1))*recalc_pitch(sfx->pitch)), - (sfx->volume == -1 ? 255 : sfx->volume), - (sfx->sep == NORMAL_SEP ? FSOUND_STEREOPAN : sfx->sep), - (sfx->priority) - ) - ) - DBG_Printf("FMOD(Add3DSource, FSOUND_Sample_SetDefaults, SFX's ID# %i): %s\n", sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); -#if 0 - if (!FSOUND_Sample_SetMinMaxDistance(fmsample, src->min_distance, src->max_distance)) - DBG_Printf("FMOD(Add3DSource, FSOUND_Sample_SetMinMaxDistance, SFX's ID# %i): %s\n", sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); -#endif - chan = FSOUND_PlaySoundEx(FSOUND_FREE,fmsample,NULL,true); - - if (chan == -1) - { - DBG_Printf("FMOD(Add3DSource, FSOUND_PlaySoundEx, SFX's ID# %i): %s\n",sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); - return chan; - } - else - { - if (!sfx) - DBG_Printf("FMOD(Add3DSource, Main): Added blank-sound added to channel %i\n",chan); -#ifdef MORESTUFF - else DBG_Printf("FMOD(Add3DSource, Main): Added sfxid# %i added to channel %i\n",sfx->id,chan); -#endif - } - } - else - { - if (sfx) - DBG_Printf("FMOD(Add3DSource, FSOUND_Sample_Load, sfxid# %i): %s\n",sfx->id,FMOD_ErrorString(FSOUND_GetError())); - else - DBG_Printf("FMOD(Add3DSource, FSOUND_Sample_Alloc): %s\n", FMOD_ErrorString(FSOUND_GetError())); - - return chan; - } - - if (FSOUND_GetCurrentSample(chan)) - { - if (!FSOUND_SetCurrentPosition(chan, 0)) - DBG_Printf("FMOD(Add3DSource, FSOUND_SetCurrentPosition, channel %i, sfxid# %i): %s\n", chan,sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); - - if (!FSOUND_3D_SetAttributes(chan,pos,vel)) - DBG_Printf("FMOD(Add3DSource, FSOUND_3D_SetAttributes, channel %i, sfxid# %i): %s\n", chan,sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); - - if (!FSOUND_SetReserved(chan, (signed char)src->permanent)) - DBG_Printf("FMOD(Add3DSource, FSOUND_SetReserved, channel %i, sfxid# %i): %s\n", chan,sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); - - if (src->head_relative) reladd(chan); - } - - return chan; -} - -/****************************************************************************** - * - * Creates 2D (stereo) source - * - ******************************************************************************/ -EXPORT INT32 HWRAPI (Add2DSource) (sfx_data_t *sfx) -{ - FSOUND_SAMPLE *fmsample = NULL; - INT32 chan = -1; - - if (!sfx) - return chan; - - fmsample = FSOUND_Sample_Load(FSOUND_FREE, INT2CHAR(sfx->data), FSOUND_DOOMLOAD, SFXLENGTH); - - if (fmsample) - { - if (!FSOUND_Sample_SetDefaults(fmsample, - (INT32)((float)(*((UINT16 *)sfx->data+1)) * recalc_pitch(sfx->pitch)), - sfx->volume == -1 ? 255 : sfx->volume, - sfx->sep == NORMAL_SEP ? FSOUND_STEREOPAN : sfx->sep, - sfx->priority)) - DBG_Printf("FMOD(Add2DSource, FSOUND_Sample_SetDefaults, sfxid# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError())); - - if (!FSOUND_Sample_SetMode(fmsample,FSOUND_2D)) - DBG_Printf("FMOD(Add2DSource, FSOUND_Sample_SetMode, sfxid# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError())); - - chan = FSOUND_PlaySoundEx(FSOUND_FREE,fmsample,NULL,true); - - if (chan == -1) - { - DBG_Printf("FMOD(Add2DSource, FSOUND_PlaySoundEx, sfxid# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError())); - return chan; - } -#ifdef MORESTUFF - else DBG_Printf("FMOD(Add2DSource, FSOUND_PlaySoundEx): sfxid# %i is playing on channel %i\n", sfx->id,chan); -#endif - } - else - { - DBG_Printf("FMOD(Add2DSource,FSOUND_Sample_Load, sfxid# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError())); - return chan; - } - - if (FSOUND_GetCurrentSample(chan)) - { - if (!FSOUND_SetCurrentPosition(chan, 0)) - DBG_Printf("FMOD(Add2DSource, FSOUND_SetCurrentPosition, channel %i, sfxid# %i): %s\n", chan,sfx->id,FMOD_ErrorString(FSOUND_GetError())); - } - - return chan; -} - -EXPORT INT32 HWRAPI (StartSource) (INT32 chan) -{ - FSOUND_SAMPLE *fmsample; - if (chan < 0) - return -1; - - fmsample = FSOUND_GetCurrentSample(chan); - - if (!fmsample) - return -1; - -#ifdef MORESTUFF - if (FSOUND_Sample_GetMode(fmsample) & FSOUND_2D) - { - DBG_Printf("FMOD(StartSource,Main): Starting 2D channel %i?\n",chan); - //return -1; - } - else - { - DBG_Printf("FMOD(StartSource,Main): Starting 3D Channel %i?\n",chan); - //return -1; - } -#endif - - if (FSOUND_GetPaused(relcheckup(chan))) - { - if (!FSOUND_SetPaused(relcheckup(chan), false)) - DBG_Printf("FMOD(StartSource,FSOUND_SetPaused, channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError())); - else if (relstack(chan) != -1) - relarray[relstack(chan)].pos.active = false; - } - else - DBG_Printf("FMOD(StartSource,FSOUND_GetPaused): Channel %i is playing already",chan); - - return chan; -} - -EXPORT void HWRAPI (StopSource) (INT32 chan) -{ - FSOUND_SAMPLE *fmsample; - - if (chan < 0) - return; - - fmsample = FSOUND_GetCurrentSample(chan); - - if (!fmsample) - return; - - if (!FSOUND_GetPaused(relcheckup(chan))) - { - if (!FSOUND_SetPaused(relcheckup(chan),true)) - { - DBG_Printf("FMOD(StopSource,FSOUND_SetPaused, channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError())); - } - else if (relstack(chan) != -1) - { - relarray[relstack(chan)].pos.active = false; - } - } -#ifdef MORESTUFF - else - DBG_Printf("FMOD(StopSource,FSOUND_GetPaused): Channel %i is stopped already\n",chan); -#endif -} - -EXPORT INT32 HWRAPI (GetHW3DSVersion) (void) -{ - return VERSION; -} - -EXPORT void HWRAPI (BeginFrameUpdate) (void) -{ - FSOUND_Update(); -} - -EXPORT void HWRAPI (EndFrameUpdate) (void) -{ - relupdate(FSOUND_FREE); -} - -EXPORT INT32 HWRAPI (IsPlaying) (INT32 chan) -{ - if (chan < 0) - return false; - - if (!FSOUND_GetCurrentSample(chan)) - return false; - - return FSOUND_IsPlaying(relcheckup(chan)); -} - -/****************************************************************************** - * UpdateListener - * - * Set up main listener properties: - * - position - * - orientation - * - velocity - *****************************************************************************/ -EXPORT void HWRAPI (UpdateListener) (listener_data_t *data) -{ - if (data) - { - float pos[3]; - float vel[3]; - double f_angle = 0; - if (data->f_angle) f_angle = (data->f_angle) / 180 * M_PI; - pos[0] = (float)data->x; - pos[1] = (float)data->z; - pos[2] = (float)data->y; - vel[0] = (float)data->momx; - vel[1] = (float)data->momz; - vel[2] = (float)data->momy; - - FSOUND_3D_Listener_SetAttributes(pos,vel,(float)cos(f_angle),0.0f,(float)sin(f_angle), 0.0f , 1.0f, 0.0f); - relset(1); - } - else - { - relset(-1); - DBG_Printf("Error: 1st listener data is missing\n"); - } -} - -EXPORT void HWRAPI (UpdateListener2) (listener_data_t *data) -{ - if (data) - { - float pos[3]; - float vel[3]; - double f_angle = 0; - if (data->f_angle) f_angle = (data->f_angle) / 180 * M_PI; - pos[0] = (float)data->x; - pos[1] = (float)data->z; - pos[2] = (float)data->y; - vel[0] = (float)data->momx; - vel[1] = (float)data->momz; - vel[2] = (float)data->momy; - - FSOUND_3D_Listener_SetCurrent(1,2); - FSOUND_3D_Listener_SetAttributes(pos,vel,(float)cos(f_angle),0.0f,(float)sin(f_angle), 0.0f , 1.0f, 0.0f); - relset(2); - FSOUND_3D_Listener_SetCurrent(0,2); - } - else - { - relset(-2); - FSOUND_3D_Listener_SetCurrent(0,1); - } -} - -EXPORT void HWRAPI (UpdateSourceVolume) (INT32 chan, INT32 vol) -{ - if (chan < 0) - return; - - if (!FSOUND_GetCurrentSample(chan)) - return; - - if (!FSOUND_SetVolume(chan,vol)) - DBG_Printf("FMOD(UpdateSourceVolume, FSOUND_SetVolume, channel %i to volume %i): %s\n", chan,vol,FMOD_ErrorString(FSOUND_GetError())); - else - { -#ifdef MORESTUFF - DBG_Printf("FMOD(UpdateSourceVolume, Main): channel %i is set to the volume of %i", chan,vol); -#endif - relvol(chan); - } -} - -/****************************************************************************** - * - * Update volume and separation (panning) of 2D source - * - *****************************************************************************/ -EXPORT void HWRAPI (Update2DSoundParms) (INT32 chan, INT32 vol, INT32 sep) -{ - FSOUND_SAMPLE *fmsample; - - if (chan < 0) - return; - - fmsample = FSOUND_GetCurrentSample(chan); - - if (fmsample) - { - if (!FSOUND_Sample_GetMode(fmsample) & FSOUND_2D) - { - DBG_Printf("FMOD(Update2DSoundParms,Main): 2D Vol/Pan on 3D channel %i?\n",chan); - //return; - } - } - else - return; - - if (!FSOUND_SetPaused(chan, true)) - DBG_Printf("FMOD(Update2DSoundParms, FSOUND_SetPaused, Pause, channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError())); - - if (!FSOUND_SetVolume(chan,vol)) - DBG_Printf("FMOD(Update2DSoundParms, , channel %i to volume %i): %s\n", chan,vol,FMOD_ErrorString(FSOUND_GetError())); - - if (!FSOUND_SetPan(chan, sep == NORMAL_SEP ? FSOUND_STEREOPAN : sep)) - DBG_Printf("FMOD(Update2DSoundParms, FSOUND_SetPan, channel %i to sep %i): %s\n", chan,sep,FMOD_ErrorString(FSOUND_GetError())); - - if (!FSOUND_SetPaused(chan, false)) - DBG_Printf("FMOD(Update2DSoundParms, FSOUND_SetPaused, Resume, channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError())); -} - -// -------------------------------------------------------------------------- -// Set the global volume for sound effects -// -------------------------------------------------------------------------- -EXPORT void HWRAPI (SetGlobalSfxVolume) (INT32 vol) -{ - INT32 realvol = (vol<<3)+(vol>>2); - - FSOUND_SetSFXMasterVolume(realvol); -#ifdef MORESTUFF - DBG_Printf("FMOD(SetGlobalSfxVolume, Main, the volume is set to %i): %s\n", realvol,FMOD_ErrorString(FSOUND_GetError())); -#endif -} - -//Alam_GBC: Not Used? -EXPORT INT32 HWRAPI (SetCone) (INT32 chan, cone_def_t *cone_def) -{ - FSOUND_SAMPLE *fmsample; - - if (chan < 0) - return -1; - - fmsample = FSOUND_GetCurrentSample(chan); - - if (fmsample) - { - if (FSOUND_Sample_GetMode(fmsample) & FSOUND_2D) - { - DBG_Printf("FMOD(Update3DSource,Main): 3D Cone on 2D Channel %i?\n",chan); - return -1; - } - } - - if (cone_def) - { - return -1; - } - else - { - return 1; - } - -} - -EXPORT void HWRAPI (Update3DSource) (INT32 chan, source3D_pos_t *sfx) -{ - float pos[3]; - float vel[3]; - FSOUND_SAMPLE *fmsample; - - pos[0] = sfx->x; - pos[1] = sfx->z; - pos[2] = sfx->y; - vel[0] = sfx->momx; - vel[1] = sfx->momz; - vel[2] = sfx->momy; - if (chan < 0) - return; - - fmsample = FSOUND_GetCurrentSample(chan); - - if (!fmsample) - return; - - if (fmsample) - { - if (FSOUND_Sample_GetMode(fmsample) & FSOUND_2D) - { - //DBG_Printf("FMOD(Update3DSource,Main): 3D Pos/Vel on 2D Channel %i?\n",chan); - //return; - } - } - else - { - return; - } - - if (!FSOUND_3D_SetAttributes(chan,pos,vel)) - DBG_Printf("FMOD(Update3DSource,FSOUND_3D_SetAttributes, onto channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError())); - else - relplace(chan); -} - -//------------------------------------------------------------- -// Load new sound data into source -//------------------------------------------------------------- -EXPORT INT32 HWRAPI (Reload3DSource) (INT32 handle, sfx_data_t *sfx) -{ - source3D_data_t src; - float pos[3], vel[3]; - INT32 chan = relcheckup(handle); - FSOUND_SAMPLE *fmsample; - - if (handle < 0 || !sfx) - return -1; - - fmsample = FSOUND_GetCurrentSample(chan); - - if (!fmsample) - return -1; - - if (FSOUND_Sample_GetMode(fmsample) & FSOUND_2D) - { - DBG_Printf("FMOD(Reload3DSource,Main): New 3D Sound on 2D Channel %i?\n",handle); - return -1; - } -#ifdef MORESTUFF - else - DBG_Printf("FMOD(Reload3DSource, Main, sending new sfx# %i to chan %i)\n",sfx->id,handle); -#endif - -#ifdef OLDFMOD - src.min_distance = MIN_DISTANCE; - src.max_distance = MAX_DISTANCE; -#else - if (!FSOUND_3D_GetMinMaxDistance(handle,&src.min_distance,&src.min_distance)) - DBG_Printf("FMOD(Reload3DSource, FSOUND_3D_GetMinMaxDistance, channel %i, for sfxid# %i): %s\n",handle, sfx->id,FMOD_ErrorString(FSOUND_GetError())); -#endif - src.head_relative = (handle != chan); - src.permanent = FSOUND_GetReserved(handle); - if (!FSOUND_3D_GetAttributes(handle,&pos[0],&vel[0])) - DBG_Printf("FMOD(Reload3DSource, FSOUND_3D_GetAttributes, channel %i, for sfxid# %i): %s\n",handle,sfx->id,FMOD_ErrorString(FSOUND_GetError())); - - //if (handle == chan) - { - if (fmsample != blankfmsample) FSOUND_Sample_Free(fmsample); - } - //else - { - // fmsample = FSOUND_GetCurrentSample(handle); - } - - fmsample = FSOUND_Sample_Load(FSOUND_FREE, INT2CHAR(sfx->data), FSOUND_DOOMLOAD, SFXLENGTH); - - if (!FSOUND_StopSound(chan)) - DBG_Printf("FMOD(Reload3DSource,FSOUND_StopSound, of channel %i for sfxid# %i): %s\n", handle,sfx->id,FMOD_ErrorString(FSOUND_GetError())); - - if (fmsample) - { - if (!FSOUND_Sample_SetDefaults(fmsample, - (INT32)((float)(*((UINT16 *)sfx->data+1)) * recalc_pitch(sfx->pitch)), - sfx->volume == -1 ? 255 : sfx->volume, - sfx->sep == NORMAL_SEP ? FSOUND_STEREOPAN : sfx->sep, - sfx->priority)) - DBG_Printf("FMOD(Reload3DSource, FSOUND_Sample_SetDefaults, for sfxid# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError())); - - if (!FSOUND_Sample_SetMinMaxDistance(fmsample, src.min_distance, src.max_distance)) - DBG_Printf("FMOD(Reload3DSource, FSOUND_Sample_SetMinMaxDistance, SFX's ID# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError())); - - chan = FSOUND_PlaySoundEx(chan,fmsample,NULL,true); - - if (chan == -1) - { - DBG_Printf("FMOD(Reload3DSource, FSOUND_PlaySoundEx, for sfxid# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError())); - return chan; - } - - if (FSOUND_GetCurrentSample(chan)) - { - if (!FSOUND_SetCurrentPosition(chan, 0)) - DBG_Printf("FMOD(Reload3DSource, FSOUND_SetCurrentPosition, channel %i, sfxid# %i): %s\n", chan,sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); - - if (!FSOUND_3D_SetAttributes(chan,pos,vel)) - DBG_Printf("FMOD(Reload3DSource, FSOUND_3D_SetAttributes, channel %i, sfxid# %i): %s\n", chan,sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); - - if (!FSOUND_SetReserved(chan, (signed char)src.permanent)) - DBG_Printf("FMOD(Reload3DSource, FSOUND_SetReserved, channel %i, sfxid# %i): %s\n", chan,sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); - - if (src.head_relative) relupdate(handle); - } - } - else - DBG_Printf("FMOD(Reload3DSource,FSOUND_Sample_Load, for sfxid# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError())); - - return chan; -} - -/****************************************************************************** - * - * Destroy source and remove it from stack if it is a 2D source. - * Otherwise put source into cache - * - *****************************************************************************/ -EXPORT void HWRAPI (KillSource) (INT32 chan) -{ - FSOUND_SAMPLE *fmsample; - INT32 relchan; - - if (chan < 0) - return; - - relchan = relcheckup(chan); - - fmsample = FSOUND_GetCurrentSample(chan); - - if (!fmsample) - return; - -#ifdef MORESTUFF - if (FSOUND_IsPlaying(relchan)) - if (!FSOUND_SetLoopMode(relchan, FSOUND_LOOP_OFF)) - DBG_Printf("FMOD(KillSource,FSOUND_SetLoopMode, for channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError())); //Alam_GBC: looping off - else -#endif - if (!FSOUND_StopSound(relchan)) - { - DBG_Printf("FMOD(KillSource,FSOUND_StopSound, for channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError())); - } -#ifdef MORESTUFF - else DBG_Printf("FMOD(KillSource, Main, for channel %i)\n", chan); -#endif - if (fmsample != blankfmsample) FSOUND_Sample_Free(fmsample); -} - -#ifdef _WINDOWS -BOOL WINAPI DllMain(HINSTANCE hinstDLL, // handle to DLL module - DWORD fdwReason, // reason for calling function - LPVOID lpvReserved) // reserved -{ - // Perform actions based on the reason for calling. - UNREFERENCED_PARAMETER(lpvReserved); - switch (fdwReason) - { - case DLL_PROCESS_ATTACH: - // Initialize once for each new process. - // Return FALSE to fail DLL load. -#ifdef DEBUG_TO_FILE - logstream = fopen("s_fmod.log", "wt"); - if (logstream == NULL) - return FALSE; -#endif - DisableThreadLibraryCalls(hinstDLL); - break; - - case DLL_THREAD_ATTACH: - // Do thread-specific initialization. - break; - - case DLL_THREAD_DETACH: - // Do thread-specific cleanup. - break; - - case DLL_PROCESS_DETACH: - // Perform any necessary cleanup. -#ifdef DEBUG_TO_FILE - if (logstream) - { - fclose(logstream); - logstream = NULL; - } -#endif - break; - } - return TRUE; // Successful DLL_PROCESS_ATTACH. -} -#elif !defined (HAVE_SDL) - -// ************************************************************************** -// FUNCTIONS -// ************************************************************************** - -EXPORT void _init() -{ -#ifdef DEBUG_TO_FILE - logstream = fopen("s_fmod.log","wt"); -#endif -} - -EXPORT void _fini() -{ -#ifdef DEBUG_TO_FILE - if (logstream) - fclose(logstream); -#endif -} -#endif diff --git a/src/hardware/s_fmod/s_fmod.dev b/src/hardware/s_fmod/s_fmod.dev deleted file mode 100644 index 01e21e2b7..000000000 --- a/src/hardware/s_fmod/s_fmod.dev +++ /dev/null @@ -1,59 +0,0 @@ -[Project] -FileName=s_fmod.dev -Name=s_fmod -Ver=1 -IsCpp=1 -Type=3 -Compiler=-D_M_IX86=500_@@_-Wall_@@_-D_WINDOWS_@@_-Os_@@_-fomit-frame-pointer_@@_ -CppCompiler= -Includes=..\..\win32\FMOD -Linker=--def ../s_mingw.def_@@_-lfmod_@@_ -Libs=..\..\win32\FMOD -UnitCount=1 -Folders= -ObjFiles= -PrivateResource= -ResourceIncludes= -MakeIncludes= -Icon= -ExeOutput=C:\srb2demo2 -ObjectOutput=..\..\..\objs\Mingw\s_fmod -OverrideOutput=1 -OverrideOutputName=s_fmod.dll -HostApplication= -CommandLine= -IncludeVersionInfo=0 -SupportXPThemes=0 -CompilerSet=0 -CompilerSettings=00000000000000000111d0 -UseCustomMakefile=0 -CustomMakefile= - -[Unit1] -FileName=s_fmod.c -Folder= -Compile=1 -CompileCpp=0 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[VersionInfo] -Major=1 -Minor=0 -Release=8 -Build=42 -LanguageID=1033 -CharsetID=1252 -CompanyName=Alam Arias -FileVersion=1.42 -FileDescription=SRB2 Sound API DLL for FMOD -InternalName=Super FMOD! -LegalCopyright= -LegalTrademarks= -OriginalFilename=s_fmod.dll -ProductName=s_fmod -ProductVersion=0.1 -AutoIncBuildNr=0 - diff --git a/src/hardware/s_fmod/s_fmod.dsp b/src/hardware/s_fmod/s_fmod.dsp deleted file mode 100644 index c9a1fb743..000000000 --- a/src/hardware/s_fmod/s_fmod.dsp +++ /dev/null @@ -1,97 +0,0 @@ -# Microsoft Developer Studio Project File - Name="s_fmod" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=s_fmod - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "s_fmod.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "s_fmod.mak" CFG="s_fmod - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "s_fmod - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "s_fmod - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "s_fmod - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\..\..\bin\VC\Release\s_fmod" -# PROP Intermediate_Dir "..\..\..\objs\VC\Release\s_fmod" -# PROP Ignore_Export_Lib 1 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "S_FMOD_EXPORTS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /Zi /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /FR /FD /c -# SUBTRACT CPP /YX -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 fmodvc.lib /nologo /dll /pdb:"..\..\..\bin\VC\Release\s_fmod.pdb" /machine:I386 /out:"..\..\..\bin\VC\Release\s_fmod.dll" - -!ELSEIF "$(CFG)" == "s_fmod - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\..\..\bin\VC\Debug\s_fmod" -# PROP Intermediate_Dir "..\..\..\objs\VC\Debug\s_fmod" -# PROP Ignore_Export_Lib 1 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "S_FMOD_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /FR /FD /GZ /c -# SUBTRACT CPP /YX -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 fmodvc.lib /nologo /dll /pdb:"..\..\..\bin\VC\Debug\s_fmod.pdb" /debug /machine:I386 /out:"..\..\..\bin\VC\Debug\s_fmod.dll" /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "s_fmod - Win32 Release" -# Name "s_fmod - Win32 Debug" -# Begin Source File - -SOURCE=.\s_fmod.c -# End Source File -# End Target -# End Project diff --git a/src/hardware/s_openal/s_openal.c b/src/hardware/s_openal/s_openal.c deleted file mode 100644 index 7f91ccf2c..000000000 --- a/src/hardware/s_openal/s_openal.c +++ /dev/null @@ -1,998 +0,0 @@ -// Emacs style mode select -*- C++ -*- -//----------------------------------------------------------------------------- -// -// Copyright (C) 2001 by DooM Legacy Team. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -//----------------------------------------------------------------------------- -/// \file -/// \brief General driver for 3D sound system -/// -/// Implementend via OpenAL API - -#ifdef _WINDOWS -//#define WIN32_LEAN_AND_MEAN -#define RPC_NO_WINDOWS_H -#include -#include -FILE* logstream = NULL; -#else -#include -#include -#include -#include -#include -#include -#ifndef HAVE_SDL // let not make a logstream here is we are inline the HW3D in the SDL binary -FILE* logstream = NULL; -#endif -#endif - -#ifdef __APPLE__ -#include //Main AL -#include //Helpers -#else -#include //Main AL -#include //Helpers -#endif - -#define _CREATE_DLL_ -#include "../../doomdef.h" -#include "../hw3dsdrv.h" - -//#undef DEBUG_TO_FILE -//#if defined ( HAVE_SDL ) && !defined ( LOGMESSAGES ) -#define DEBUG_TO_FILE -//#endif - -// Internal sound stack -typedef struct stack_snd_s -{ - ALuint ALsource;// 3D data of 3D source - - ALint sfx_id;// Currently unused - - ALint LRU;// Currently unused - - ALboolean permanent;// Flag of static source -} stack_snd_t; - -#ifndef AL_INVALID -#define AL_INVALID (-1) -#endif - -static I_Error_t I_ErrorOpenAl = NULL; -static stack_snd_t *ALstack = NULL; // Sound stack -static ALsizei allocated_sounds = 0; // Size of stack -static ALsizei allocate_delta = 16; -static ALCdevice *ALCDevice = NULL; -static ALCcontext *ALContext = NULL; -static ALenum ALo_Lasterror = AL_NO_ERROR; -static ALenum ALCo_Lasterror = ALC_NO_ERROR; - -static ALenum ALo_GetError(ALvoid) -{ - ALo_Lasterror = alGetError(); - return ALo_Lasterror; -} - -static ALenum ALCo_GetError(ALvoid) -{ - ALCo_Lasterror = alcGetError(ALCDevice); - return ALCo_Lasterror; -} - -static ALfloat ALvol(ALint vol, ALsizei step) -{ - return ((ALfloat)vol)/(ALfloat)step; -} - -/* -static ALfloat Alpitch(ALint pitch) -{ -#if 1 - pitch = NORMAL_PITCH; -#endif - return pitch < NORMAL_PITCH ? - (float)(pitch + NORMAL_PITCH) / (NORMAL_PITCH * 2) - :(float)pitch / (float)NORMAL_PITCH; -} -*/ - -static const ALchar *GetALErrorString(ALenum err) -{ - switch (err) - { - case AL_NO_ERROR: - return "There no error"; - break; - - case AL_INVALID_NAME: - return "Invalid name"; - break; - - case AL_INVALID_ENUM: - return "Invalid enum"; - break; - - case AL_INVALID_VALUE: - return "Invalid value"; - break; - - case AL_INVALID_OPERATION: - return "Invalid operation"; - break; - - case AL_OUT_OF_MEMORY: - return "Out Of Memory"; - break; - - default: - return alGetString(err); - break; - } -} - -static const ALchar *GetALCErrorString(ALenum err) -{ - switch (err) - { - case ALC_NO_ERROR: - return "There no error"; - break; - - case ALC_INVALID_DEVICE: - return "Invalid Device"; - break; - - case ALC_INVALID_CONTEXT: - return "Invalid Context"; - break; - - case ALC_INVALID_ENUM: - return "Invalid enum"; - break; - - case ALC_INVALID_VALUE: - return "Invalid value"; - break; - - case ALC_OUT_OF_MEMORY: - return "Out Of Memory"; - break; - - default: - return alcGetString(ALCDevice, err); - break; - } -} - -/*************************************************************** - * - * DBG_Printf - * Output error messages to debug log if DEBUG_TO_FILE is defined, - * else do nothing - * - ************************************************************** - */ -// -----------------+ -// DBG_Printf : Output error messages to debug log if DEBUG_TO_FILE is defined, -// : else do nothing -// Returns : -// -----------------+ -FUNCPRINTF void DBG_Printf(const char *lpFmt, ... ) -{ -#ifdef DEBUG_TO_FILE - char str[4096] = ""; - va_list arglist; - - va_start(arglist, lpFmt); - vsnprintf(str, 4096, lpFmt, arglist); - va_end(arglist); - if (logstream) - fwrite(str, strlen(str), 1 , logstream); -#else - lpFmt = NULL; -#endif -} - -/*************************************************************** - * - * Grow internal sound stack by allocate_delta amount - * - *************************************************************** - */ -static ALboolean reallocate_stack(void) -{ - stack_snd_t *new_stack; - if (ALstack) - new_stack = realloc(ALstack, sizeof (stack_snd_t) * (allocated_sounds + allocate_delta)); - else - new_stack = malloc(sizeof (stack_snd_t) * (allocate_delta)); - if (new_stack) - { - ALsizei clean_stack; - ALstack = new_stack; - memset(&ALstack[allocated_sounds], 0, allocate_delta * sizeof (stack_snd_t)); - for (clean_stack = allocated_sounds; clean_stack < allocated_sounds; clean_stack++) - ALstack[clean_stack].ALsource = (ALuint)AL_INVALID; - allocated_sounds += allocate_delta; - return AL_TRUE; - } - return AL_FALSE; -} - - -/*************************************************************** - * - * Destroys source in stack - * - *************************************************************** - */ -static ALvoid kill_sound(stack_snd_t *snd) -{ - if (alIsSource(snd->ALsource)) - alDeleteSources(1,&snd->ALsource); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: alDeleteSources, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - memset(snd,0, sizeof (stack_snd_t)); - snd->ALsource = (ALuint)AL_INVALID; -} - -/*************************************************************** - * - * Returns free (unused) source stack slot - * If none available sound stack will be increased - * - *************************************************************** - */ -static ALsizei find_handle(void) -{ - ALsizei free_sfx = 0; - stack_snd_t *snd; - - for (snd = ALstack; free_sfx < allocated_sounds; snd++, free_sfx++) - { - if (snd->permanent) - continue; - if (snd->ALsource==(ALuint)AL_INVALID) - break; - if (!alIsSource(snd->ALsource)) - break; - ALo_GetError(); - if (snd->sfx_id == 0) - break; - } - - // No suitable resource found so increase sound stack - //DBG_Printf("sfx chan %d\n", free_sfx); - if (free_sfx == allocated_sounds) - { - DBG_Printf("No free or same sfx found so increase stack (currently %d srcs)\n", allocated_sounds); - free_sfx = reallocate_stack() ? free_sfx : (ALsizei)AL_INVALID; - } - return free_sfx; -} - -static ALvoid ALSetPan(ALuint sid, INT32 sep) -{ - ALfloat facing[3] ={0.0f, 0.0f, 0.0f}; //Alam: bad? - const ALfloat fsep = (ALfloat)sep; - const ALfloat nsep = (ALfloat)NORMAL_SEP; - if (sep) - { - facing[0] = (ALfloat)(fsep/nsep); - facing[2] = 1.0f; - } - alSourcefv(sid, AL_POSITION, facing); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: alSourcefv, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } -} - - -/****************************************************************************** - * - * Initialise driver and listener - * - *****************************************************************************/ -EXPORT INT32 HWRAPI( Startup ) (I_Error_t FatalErrorFunction, snddev_t *snd_dev) -{ - ALenum model = AL_INVERSE_DISTANCE_CLAMPED; - ALCboolean inited = ALC_FALSE; - ALCint AlSetup[8] = {ALC_FREQUENCY,22050,ALC_REFRESH,35,ALC_SYNC,AL_FALSE,ALC_INVALID,ALC_INVALID}; -#if (defined (_WIN32) || defined (_WIN64)) && 0 - const ALCubyte *ALCdriver = alcGetString(NULL,ALC_DEFAULT_DEVICE_SPECIFIER); - const ALCubyte *DSdriver = "DirectSound"; - - if (!strcmp((const ALCbyte *)ALCdriver,"DirectSound3D")) //Alam: OpenAL's DS3D is buggy - ALCDevice = alcOpenDevice(DSdriver); //Open DirectSound - else //Alam: The OpenAl device - ALCDevice = alcOpenDevice(ALCdriver); //Open Default -#else - ALCDevice = alcOpenDevice(alcGetString(NULL,ALC_DEFAULT_DEVICE_SPECIFIER)); -#endif - if (ALCo_GetError() != ALC_NO_ERROR || !ALCDevice) - { - DBG_Printf("S_OpenAl: Error %s when opening device!\n", GetALCErrorString(ALCo_Lasterror)); - return inited; - } - else - { - DBG_Printf("Driver Name : %s\n", alcGetString(ALCDevice,ALC_DEVICE_SPECIFIER)); - DBG_Printf("Extensions : %s\n", alcGetString(ALCDevice,ALC_EXTENSIONS)); - DBG_Printf("S_OpenAl: OpenAl Device %s opened\n",alcGetString(ALCDevice, ALC_DEVICE_SPECIFIER)); - } - - I_ErrorOpenAl = FatalErrorFunction; - - AlSetup[1] = snd_dev->sample_rate; //ALC_FREQUENCY - AlSetup[1] = 44100; - AlSetup[3] = 35; //ALC_REFRESH - - //Alam: The Environment? - ALContext = alcCreateContext(ALCDevice,AlSetup); - if (ALCo_GetError() != ALC_NO_ERROR || !ALContext) - { - DBG_Printf("S_OpenAl: Error %s when making the environment!\n",GetALCErrorString(ALCo_Lasterror)); - return inited; - } - else - { - DBG_Printf("S_OpenAl: OpenAl environment made\n"); - } - - alcMakeContextCurrent(ALContext); - if (ALCo_GetError() != ALC_NO_ERROR) - { - DBG_Printf("S_OpenAl: Error %s when setting the environment!\n",GetALCErrorString(ALCo_Lasterror)); - return inited; - } - else - { - DBG_Printf("S_OpenAl: OpenAl environment setted up\n"); - } - - DBG_Printf("Vendor : %s\n", alGetString(AL_VENDOR)); - DBG_Printf("Renderer : %s\n", alGetString(AL_RENDERER)); - DBG_Printf("Version : %s\n", alGetString(AL_VERSION)); - DBG_Printf("Extensions : %s\n", alGetString(AL_EXTENSIONS)); - - alDopplerFactor(0.0f); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("S_OpenAl: Error %s when setting Doppler Factor!\n",GetALErrorString(ALo_Lasterror)); - return inited; - } - else - { - DBG_Printf("S_OpenAl: Doppler Factor of %f setted\n", alGetDouble(AL_DOPPLER_FACTOR)); - } - - alSpeedOfSound(600.0f); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("S_OpenAl: Error %s when setting Speed of Sound!\n",GetALErrorString(ALo_Lasterror)); - return inited; - } - else - { - DBG_Printf("S_OpenAl: Speed of Sound set to %f\n", alGetDouble(AL_SPEED_OF_SOUND)); - } - - alDistanceModel(model); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("S_OpenAl: Error %s when setting Distance Model!\n",GetALErrorString(ALo_Lasterror)); - return inited; - } - else - { - //DBG_Printf("S_OpenAl: %s mode setted\n",alGetString(model)); - } - - inited = reallocate_stack(); - - return inited; -} - -/****************************************************************************** - * - * Shutdown 3D Sound - * - ******************************************************************************/ -EXPORT void HWRAPI( Shutdown ) ( void ) -{ - ALsizei i; - - DBG_Printf ("S_OpenAL Shutdown()\n"); - - for (i = 0; i < allocated_sounds; i++) - { - StopSource(i); - kill_sound(ALstack + i); - } - -#if defined(linux) || defined(__linux) || defined(__linux__) - alcMakeContextCurrent(NULL); - //TODO:check? -#endif - - if (ALContext) - { - alcDestroyContext(ALContext); - ALContext = NULL; - } - - if (ALstack) - { - free(ALstack); - ALstack = NULL; - } - - //TODO:check? - if (ALCDevice) - { - alcCloseDevice(ALCDevice); - ALCDevice = NULL; - } - //TODO:check? -} - -#ifdef _MSC_VER -#pragma warning(disable : 4200) -#pragma pack(1) -#endif - -typedef struct -{ - ALushort header; // 3? - ALushort samplerate; // 11025+ - ALushort samples; // number of samples - ALushort dummy; // 0 - ALubyte data[0]; // data; -} ATTRPACK dssfx_t; - -#ifdef _MSC_VER -#pragma pack() -#pragma warning(default : 4200) -#endif - -static ALsizei getfreq(ALvoid *sfxdata, size_t len) -{ - dssfx_t *dsfx = sfxdata; - const ALsizei freq = SHORT(dsfx->samplerate); - - if (len <= 8) - return 0; - else - return freq; -} - -static ALsizei makechan(ALuint sfxhandle, ALboolean perm) -{ - ALsizei chan = find_handle(); - - if (chan == (ALsizei)AL_INVALID) return chan; - - alGenSources(1, &ALstack[chan].ALsource); - if (ALo_GetError() != AL_NO_ERROR || !alIsSource(ALstack[chan].ALsource)) - { - DBG_Printf("S_OpenAl: Error %s when make an ALSource!\n",GetALErrorString(ALo_Lasterror)); - ALstack[chan].ALsource = (ALuint)AL_INVALID; - return (ALsizei)AL_INVALID; - } - - ALstack[chan].permanent = perm; - - alSourceQueueBuffers(ALstack[chan].ALsource, 1, &sfxhandle); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("S_OpenAl: Error %s when queue up an alSource!\n",GetALErrorString(ALo_Lasterror)); - } - - return chan; -} - -/****************************************************************************** - * - * Creates ?D source - * - ******************************************************************************/ -EXPORT INT32 HWRAPI ( AddSource ) (source3D_data_t *src, u_int sfxhandle) -{ - ALsizei chan = makechan(sfxhandle, (ALboolean)(src?src->permanent:AL_FALSE)); - ALuint sid = (ALuint)AL_INVALID; - if (chan == (ALsizei)AL_INVALID) - return AL_INVALID; - else - sid = ALstack[chan].ALsource; - - if (src) //3D - { -#if 0 - alSourcef(sid, AL_REFERENCE_DISTANCE, src->min_distance); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: AL_REFERENCE_DISTANCE, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - - alSourcef(sid, AL_MAX_DISTANCE, src->max_distance); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: AL_MAX_DISTANCE, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } -#endif - - if (src->head_relative) - alSourcei(sid, AL_SOURCE_RELATIVE, AL_TRUE); - else - alSourcei(sid, AL_SOURCE_RELATIVE, AL_FALSE); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: AL_SOURCE_RELATIVE, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - - alSource3f(sid, AL_POSITION, src->pos.x, src->pos.z, src->pos.y); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: AL_POSITION, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - alSource3f(sid, AL_VELOCITY, src->pos.momx, src->pos.momz, src->pos.momy); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: AL_VELOCITY, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - } - else //2D - { - alSourcei(sid, AL_SOURCE_RELATIVE, AL_TRUE); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: AL_SOURCE_RELATIVE, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - } - - alSourcef(sid, AL_ROLLOFF_FACTOR, 0.0f); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: AL_ROLLOFF_FACTOR, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - - alSourcef(sid, AL_REFERENCE_DISTANCE, 0.0f); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: AL_REFERENCE_DISTANC, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - return chan; -} - -EXPORT INT32 HWRAPI ( StartSource ) (INT32 chan) -{ - ALint state = AL_NONE; - ALuint sid = (ALuint)AL_INVALID; - - if (chan <= AL_INVALID || !alIsSource(ALstack[chan].ALsource)) - return AL_FALSE; - else - sid = ALstack[chan].ALsource; - - ALo_GetError(); - - alSourcePlay(sid); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: alSourcePlay, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - - alGetSourcei(sid, AL_SOURCE_STATE, &state); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: alGetSourcei, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - - return (state == AL_PLAYING); -} - -EXPORT void HWRAPI ( StopSource) (INT32 chan) -{ - ALuint sfxhandle = AL_NONE; - ALuint sid = (ALuint)AL_INVALID; - if (chan <= AL_INVALID || !alIsSource(ALstack[chan].ALsource)) - return; - else - sid = ALstack[chan].ALsource; - - ALo_GetError(); - -#if 1 - alSourceQueueBuffers(sid, 1, &sfxhandle); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: alSourceQueueBuffers, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } -#else - alSourceStop(sid); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: alSourceStop, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } -#endif -} - -EXPORT INT32 HWRAPI ( GetHW3DSVersion) (void) -{ - return VERSION; -} - -EXPORT void HWRAPI (BeginFrameUpdate) (void) -{ - alcSuspendContext(ALContext); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: alcSuspendContext, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } -} - -EXPORT void HWRAPI (EndFrameUpdate) (void) -{ - alcProcessContext(ALContext); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: alcProcessContext, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } -} - -EXPORT INT32 HWRAPI (IsPlaying) (INT32 chan) -{ - ALint state = AL_NONE; - ALuint sid = (ALuint)AL_INVALID; - - if (chan <= AL_INVALID || !alIsSource(ALstack[chan].ALsource)) - return AL_FALSE; - else - sid = ALstack[chan].ALsource; - - ALo_GetError(); - - alGetSourcei(sid, AL_SOURCE_STATE, &state); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: alGetSourcei, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - - return (state == AL_PLAYING); -} - -/****************************************************************************** - * UpdateListener - * - * Set up main listener properties: - * - position - * - orientation - * - velocity - *****************************************************************************/ -EXPORT void HWRAPI (UpdateListener) (listener_data_t *data, INT32 num) -{ - if (num != 1) return; - - if (data) - { - ALfloat facing[6]; - ALdouble f_angle = 0.0; - if (data->f_angle) f_angle = (ALdouble)((data->f_angle) / 180.0l * M_PIl); - facing[0] = (ALfloat)cos(f_angle); - facing[1] = 0.0f; - facing[2] = (ALfloat)sin(f_angle); - facing[3] = 0.0f; - facing[4] = 1.0f; - facing[5] = 0.0f; - - alListener3f(AL_POSITION,(ALfloat)-data->x,(ALfloat)data->z,(ALfloat)data->y); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: AL_POSITIO, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - - alListener3f(AL_VELOCITY,(ALfloat)data->momx,(ALfloat)data->momz,(ALfloat)data->momy); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: AL_VELOCITY, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - - alListenerfv(AL_ORIENTATION, facing); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: AL_ORIENTATION, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - } - else - { - DBG_Printf("Error: 1st listener data is missing\n"); - } -} - -/****************************************************************************** - * - * Update volume for 2D source and separation (panning) of 2D source - * - *****************************************************************************/ -EXPORT void HWRAPI (UpdateSourceParms) (INT32 chan, INT32 vol, INT32 sep) -{ - ALuint sid = AL_NONE; - ALint is2d = AL_FALSE; - if (chan > AL_INVALID && !alIsSource(ALstack[chan].ALsource)) - return; - else - sid = ALstack[chan].ALsource; - - alGetSourcei(sid, AL_SOURCE_RELATIVE, &is2d); - - if (!is2d) - return; - - if (vol != -1) - { - alSourcef(sid,AL_GAIN,ALvol(vol,256)); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: alSourcef, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - } - - if (sep != -1) - { - ALSetPan(sid,sep-NORMAL_SEP); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: ALSetPan, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - } -} - -// -------------------------------------------------------------------------- -// Set the global volume for sound effects -// -------------------------------------------------------------------------- -EXPORT void HWRAPI (SetGlobalSfxVolume) (INT32 vol) -{ - alListenerf(AL_GAIN, ALvol(vol,32)); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: AL_GAIN, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } -} - -//Alam: Not Used? -EXPORT INT32 HWRAPI (SetCone) (INT32 chan, cone_def_t *cone_def) -{ - ALuint sid = AL_NONE; - ALint is2d = AL_FALSE; - if (chan > AL_INVALID && !alIsSource(ALstack[chan].ALsource)) - return AL_FALSE; - else - sid = ALstack[chan].ALsource; - - alGetSourcei(sid, AL_SOURCE_RELATIVE, &is2d); - - if(is2d || !cone_def) - return AL_FALSE; - - alSourcef(sid,AL_CONE_INNER_ANGLE,cone_def->inner); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: AL_CONE_INNER_ANGLE, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - - alSourcef(sid,AL_CONE_OUTER_ANGLE,cone_def->outer); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: AL_CONE_OUTER_ANGL, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - - alSourcei(sid,AL_CONE_OUTER_GAIN, cone_def->outer_gain); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: AL_CONE_OUTER_GAIN, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - - return AL_TRUE; -} - -EXPORT void HWRAPI (Update3DSource) (INT32 chan, source3D_pos_t *sfx) -{ - ALuint sid = AL_NONE; - ALint is2d = AL_FALSE; - if (chan > AL_INVALID && !alIsSource(ALstack[chan].ALsource)) - return; - else - sid = ALstack[chan].ALsource; - - alGetSourcei(sid, AL_SOURCE_RELATIVE, &is2d); - - if (is2d) - return; - - alSource3f(sid, AL_POSITION, sfx->x, sfx->z, sfx->y); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: AL_POSITION, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - - alSource3f(sid, AL_VELOCITY, sfx->momx, sfx->momz, sfx->momy); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("%s: AL_VELOCITY, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } -} - -//------------------------------------------------------------- -// Load new sound data into source -//------------------------------------------------------------- -EXPORT INT32 HWRAPI (ReloadSource) (INT32 chan, u_int sfxhandle) -{ - ALuint sid; - - if (chan <= AL_INVALID || !alIsSource(ALstack[chan].ALsource) || !alIsBuffer(sfxhandle)) - return AL_INVALID; - else - sid = ALstack[chan].ALsource; - - ALo_GetError(); - - alSourceQueueBuffers(sid, 1, &sfxhandle); - if (ALo_GetError() == AL_INVALID_OPERATION) //Alam: not needed? - { - alSourceStop(sid); - alSourcei(sid, AL_BUFFER, sfxhandle); - ALo_GetError(); - } - if (ALo_Lasterror != AL_NO_ERROR) - { - DBG_Printf("%s: alSourcei, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } - - return chan; -} - -/****************************************************************************** - * - * Destroy source and remove it from stack if it is a 2D source. - * Otherwise put source into cache - * - *****************************************************************************/ -EXPORT void HWRAPI (KillSource) (INT32 chan) -{ - if (chan > AL_INVALID && (ALsizei)chan <= allocated_sounds) - kill_sound(ALstack + chan); -} - -EXPORT u_int HWRAPI (AddSfx) (sfx_data_t *sfx) -{ - ALuint chan = (ALuint)AL_INVALID; - ALsizei freq = 11025; - ALubyte *data = NULL; - ALsizei size = 0; - - if (!sfx) - return 0; - else - { - data = ((ALubyte *)sfx->data)+8; - size = (ALsizei)(sfx->length-8); - } - - alGenBuffers(1, &chan); - if (ALo_GetError() != AL_NO_ERROR || !alIsBuffer(chan)) - { - DBG_Printf("S_OpenAl: Error %s when make an ALBuffer!\n",GetALErrorString(ALo_Lasterror)); - return (u_int)AL_INVALID; - } - - freq = getfreq(sfx->data, sfx->length); - - alBufferData(chan, AL_FORMAT_MONO8, data, size, freq); - if (ALo_GetError() != AL_NO_ERROR) - { - DBG_Printf("S_OpenAl: Error %s when setting up a alBuffer!\n",GetALErrorString(ALo_Lasterror)); - } - - return chan; -} - -EXPORT void HWRAPI (KillSfx) (u_int sfxhandle) -{ - ALuint ALsfx = sfxhandle; - if (!alIsBuffer(ALsfx)) - return; - alDeleteBuffers(1, &ALsfx); - if (ALo_GetError() == AL_INVALID_OPERATION) - { - // Buffer leak - } - else if (ALo_Lasterror != AL_NO_ERROR) - { - DBG_Printf("%s: alDeleteBuffers, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); - } -} - -EXPORT void HWRAPI (GetHW3DSTitle) (char *buf, size_t size) -{ - strncpy(buf, "OpenAL", size); -} - - -#ifdef _WINDOWS -BOOL WINAPI DllMain(HINSTANCE hinstDLL, // handle to DLL module - DWORD fdwReason, // reason for calling function - LPVOID lpvReserved) // reserved -{ - // Perform actions based on the reason for calling. - UNREFERENCED_PARAMETER(lpvReserved); - switch ( fdwReason ) - { - case DLL_PROCESS_ATTACH: - // Initialize once for each new process. - // Return FALSE to fail DLL load. -#ifdef DEBUG_TO_FILE - logstream = fopen("s_openal.log", "wt"); - if (logstream == NULL) - return FALSE; -#endif - DisableThreadLibraryCalls(hinstDLL); - break; - - case DLL_THREAD_ATTACH: - // Do thread-specific initialization. - break; - - case DLL_THREAD_DETACH: - // Do thread-specific cleanup. - break; - - case DLL_PROCESS_DETACH: - // Perform any necessary cleanup. -#ifdef DEBUG_TO_FILE - if ( logstream) - { - fclose(logstream); - logstream = NULL; - } -#endif - break; - } - return TRUE; // Successful DLL_PROCESS_ATTACH. -} -#elif !defined (_WINDOWS) - -// ************************************************************************** -// FUNCTIONS -// ************************************************************************** - -EXPORT void _init() -{ -#ifdef DEBUG_TO_FILE - logstream = fopen("s_openal.log", "w+"); -#endif -} - -EXPORT void _fini() -{ -#ifdef DEBUG_TO_FILE - if (logstream) - fclose(logstream); - logstream = NULL; -#endif -} -#endif - diff --git a/src/hardware/s_openal/s_openal.dev b/src/hardware/s_openal/s_openal.dev deleted file mode 100644 index c8fb9e62b..000000000 --- a/src/hardware/s_openal/s_openal.dev +++ /dev/null @@ -1,59 +0,0 @@ -[Project] -FileName=s_openal.dev -Name=s_openal -Ver=1 -IsCpp=1 -Type=3 -Compiler=-D_M_IX86=500_@@_-Wall_@@_-fexceptions_@@_-D_WINDOWS_@@_ -CppCompiler= -Includes= -Linker=--def ../s_mingw.def_@@_-lopenal32_@@_ -Libs= -UnitCount=1 -Folders= -ObjFiles= -PrivateResource= -ResourceIncludes= -MakeIncludes= -Icon= -ExeOutput=..\..\..\bin -ObjectOutput=..\..\..\objs\Mingw\s_opengl -OverrideOutput=0 -OverrideOutputName=s_openal.dll -HostApplication= -CommandLine= -UseCustomMakefile=0 -CustomMakefile= -IncludeVersionInfo=0 -SupportXPThemes=0 -CompilerSet=0 -CompilerSettings=0000000010001001001001 - -[Unit1] -FileName=s_openal.c -Folder= -Compile=1 -CompileCpp=0 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[VersionInfo] -Major=0 -Minor=1 -Release=1 -Build=1 -LanguageID=1033 -CharsetID=1252 -CompanyName= -FileVersion=0.1 -FileDescription=Developed using the Dev-C++ IDE -InternalName= -LegalCopyright= -LegalTrademarks= -OriginalFilename=s_openal.dll -ProductName=s_openal -ProductVersion=0.1 -AutoIncBuildNr=0 - diff --git a/src/hardware/s_openal/s_openal.dsp b/src/hardware/s_openal/s_openal.dsp deleted file mode 100644 index ac7fbaa84..000000000 --- a/src/hardware/s_openal/s_openal.dsp +++ /dev/null @@ -1,98 +0,0 @@ -# Microsoft Developer Studio Project File - Name="s_openal" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=s_openal - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "s_openal.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "s_openal.mak" CFG="s_openal - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "s_openal - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "s_openal - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "s_openal - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\..\..\bin\VC\Release\s_openal" -# PROP Intermediate_Dir "..\..\..\objs\VC\Release\s_openal" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "S_OPENAL_EXPORTS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /YX /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /win32 -# SUBTRACT MTL /mktyplib203 -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 OpenAL32.lib /nologo /dll /pdb:"..\..\..\bin\VC\Release\s_openal.pdb" /machine:I386 /out:"C:\srb2demo2\s_openal.dll" -# SUBTRACT LINK32 /pdb:none - -!ELSEIF "$(CFG)" == "s_openal - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\..\..\bin\VC\Debug\s_openal" -# PROP Intermediate_Dir "..\..\..\objs\VC\Debug\s_openal" -# PROP Ignore_Export_Lib 1 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "S_OPENAL_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /D "_MBCS" /D "_USRDLL" /D "S_OPENAL_EXPORTS" /YX /FD /GZ /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 OpenAL32.lib /nologo /dll /pdb:"..\..\..\bin\VC\Debug\s_openal.pdb" /debug /machine:I386 /out:"C:\srb2demo2\s_openaldebug.dll" /pdbtype:sept -# SUBTRACT LINK32 /pdb:none - -!ENDIF - -# Begin Target - -# Name "s_openal - Win32 Release" -# Name "s_openal - Win32 Debug" -# Begin Source File - -SOURCE=.\s_openal.c -# End Source File -# End Target -# End Project diff --git a/src/locale/en.po b/src/locale/en.po index ce4510802..b20dd837f 100644 --- a/src/locale/en.po +++ b/src/locale/en.po @@ -1910,15 +1910,6 @@ msgstr "" msgid " Not found: %s\n" msgstr "" -#: hardware/s_ds3d/s_ds3d.c:617 p_tick.c:168 sdl/i_sound.c:1347 -#: win32/win_snd.c:1073 win32/win_snd.c:1431 -msgid "Done\n" -msgstr "" - -#: hardware/s_ds3d/s_ds3d.c:617 win32/win_snd.c:1073 -msgid "Failed\n" -msgstr "" - #: hu_stuff.c:375 msgid "The chat is muted. You can't say anything at the moment.\n" msgstr "" @@ -3174,21 +3165,6 @@ msgstr "" msgid "I_ShutdownMusic: " msgstr "" -#: sdl/i_sound.c:1494 -msgid " disabled loading FMOD\n" -msgstr "" - -#: sdl/i_sound.c:1513 -msgid " failed to load FMOD\n" -msgstr "" - -#: sdl/i_sound.c:1522 win32/win_snd.c:1237 -#, c-format -msgid "" -"Wrong FMOD DLL version.\n" -"You should be using FMOD %s\n" -msgstr "" - #: sdl/i_sound.c:1611 msgid "I_InitMusic:" msgstr "" @@ -3803,12 +3779,6 @@ msgstr "" msgid "%d mixer devices available\n" msgstr "" -#: win32/win_snd.c:1227 -msgid "" -" failed to load FMOD\n" -" no DigiMusic support\n" -msgstr "" - #: win32/win_snd.c:1289 msgid "No MIDI devices available, music is disabled\n" msgstr "" diff --git a/src/locale/srb2.pot b/src/locale/srb2.pot index c61cbcc97..a25ea69ae 100644 --- a/src/locale/srb2.pot +++ b/src/locale/srb2.pot @@ -1994,15 +1994,6 @@ msgstr "" msgid " Not found: %s\n" msgstr "" -#: hardware/s_ds3d/s_ds3d.c:617 p_tick.c:168 sdl/i_sound.c:1347 -#: win32/win_snd.c:1071 win32/win_snd.c:1429 -msgid "Done\n" -msgstr "" - -#: hardware/s_ds3d/s_ds3d.c:617 win32/win_snd.c:1071 -msgid "Failed\n" -msgstr "" - #: hu_stuff.c:405 msgid "The chat is muted. You can't say anything at the moment.\n" msgstr "" @@ -3377,21 +3368,6 @@ msgstr "" msgid "I_ShutdownMusic: " msgstr "" -#: sdl/i_sound.c:1494 -msgid " disabled loading FMOD\n" -msgstr "" - -#: sdl/i_sound.c:1513 -msgid " failed to load FMOD\n" -msgstr "" - -#: sdl/i_sound.c:1522 win32/win_snd.c:1235 -#, c-format -msgid "" -"Wrong FMOD DLL version.\n" -"You should be using FMOD %s\n" -msgstr "" - #: sdl/i_sound.c:1611 msgid "I_InitMusic:" msgstr "" @@ -3999,12 +3975,6 @@ msgstr "" msgid "%d mixer devices available\n" msgstr "" -#: win32/win_snd.c:1225 -msgid "" -" failed to load FMOD\n" -" no DigiMusic support\n" -msgstr "" - #: win32/win_snd.c:1287 msgid "No MIDI devices available, music is disabled\n" msgstr "" diff --git a/src/p_enemy.c b/src/p_enemy.c index 96b0a16df..dfb237d74 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -25,10 +25,6 @@ #include "lua_hook.h" #include "k_kart.h" // SRB2kart -#ifdef HW3SOUND -#include "hardware/hw3sound.h" -#endif - boolean LUA_CallAction(enum actionnum actionnum, mobj_t *actor); INT32 var1; diff --git a/src/p_spec.c b/src/p_spec.c index 8ccfed3c3..d272764be 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -40,10 +40,6 @@ #include "k_kart.h" // SRB2kart #include "console.h" // CON_LogMessage -#ifdef HW3SOUND -#include "hardware/hw3sound.h" -#endif - // Not sure if this is necessary, but it was in w_wad.c, so I'm putting it here too -Shadow Hog #include diff --git a/src/p_user.c b/src/p_user.c index 3133ee49b..afce1d7a7 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -50,10 +50,6 @@ #include "console.h" // CON_LogMessage #include "m_menu.h" -#ifdef HW3SOUND -#include "hardware/hw3sound.h" -#endif - #ifdef HWRENDER #include "hardware/hw_main.h" #endif diff --git a/src/s_sound.c b/src/s_sound.c index c770957b6..d5ea1d4c7 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -33,13 +33,7 @@ #include "lua_hook.h" // MusicChange hook -#ifdef HW3SOUND -// 3D Sound Interface -#include "hardware/hw3sound.h" -#else static boolean S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, INT32 *vol, INT32 *sep, INT32 *pitch, sfxinfo_t *sfxinfo); -#endif - static void SetChannelsNum(void); static void Command_Tunes_f(void); static void Command_RestartAudio_f(void); @@ -330,14 +324,6 @@ static void SetChannelsNum(void) if (cv_numChannels.value == 999999999) //Alam_GBC: OH MY ROD!(ROD rimmiced with GOD!) CV_StealthSet(&cv_numChannels,cv_numChannels.defaultvalue); -#ifdef HW3SOUND - if (hws_mode != HWS_DEFAULT_MODE) - { - HW3S_SetSourcesNum(); - return; - } -#endif - if (cv_numChannels.value) channels = (channel_t *)Z_Calloc(cv_numChannels.value * sizeof (channel_t), PU_STATIC, NULL); numofchannels = (channels ? cv_numChannels.value : 0); @@ -387,14 +373,6 @@ void S_StopSounds(void) { INT32 cnum; -#ifdef HW3SOUND - if (hws_mode != HWS_DEFAULT_MODE) - { - HW3S_StopSounds(); - return; - } -#endif - // kill all playing sounds at start of level for (cnum = 0; cnum < numofchannels; cnum++) if (channels[cnum].sfxinfo) @@ -409,13 +387,7 @@ void S_StopSoundByID(void *origin, sfxenum_t sfx_id) // be stopped by new sounds. if (!origin) return; -#ifdef HW3SOUND - if (hws_mode != HWS_DEFAULT_MODE) - { - HW3S_StopSoundByID(origin, sfx_id); - return; - } -#endif + for (cnum = 0; cnum < numofchannels; cnum++) { if (channels[cnum].sfxinfo == &S_sfx[sfx_id] && channels[cnum].origin == origin) @@ -429,13 +401,6 @@ void S_StopSoundByNum(sfxenum_t sfxnum) { INT32 cnum; -#ifdef HW3SOUND - if (hws_mode != HWS_DEFAULT_MODE) - { - HW3S_StopSoundByNum(sfxnum); - return; - } -#endif for (cnum = 0; cnum < numofchannels; cnum++) { if (channels[cnum].sfxinfo == &S_sfx[sfxnum]) @@ -510,14 +475,6 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume) } } -#ifdef HW3SOUND - if (hws_mode != HWS_DEFAULT_MODE) - { - HW3S_StartSound(origin, sfx_id); - return; - }; -#endif - for (i = 0; i <= splitscreen; i++) { player_t *player = &players[displayplayers[i]]; @@ -690,12 +647,7 @@ void S_StartSound(const void *origin, sfxenum_t sfx_id) } // the volume is handled 8 bits -#ifdef HW3SOUND - if (hws_mode != HWS_DEFAULT_MODE) - HW3S_StartSound(origin, sfx_id); - else -#endif - S_StartSoundAtVolume(origin, sfx_id, 255); + S_StartSoundAtVolume(origin, sfx_id, 255); } void S_StopSound(void *origin) @@ -707,13 +659,6 @@ void S_StopSound(void *origin) if (!origin) return; -#ifdef HW3SOUND - if (hws_mode != HWS_DEFAULT_MODE) - { - HW3S_StopSound(origin); - return; - } -#endif for (cnum = 0; cnum < numofchannels; cnum++) { if (channels[cnum].sfxinfo && channels[cnum].origin == origin) @@ -760,7 +705,6 @@ void S_UpdateSounds(void) I_UpdateMumble(NULL, listener[0]); #endif - // Stop cutting FMOD out. WE'RE sick of it. I_UpdateSound(); return; } @@ -795,15 +739,6 @@ void S_UpdateSounds(void) I_UpdateMumble(players[consoleplayer].mo, listener[0]); #endif -#ifdef HW3SOUND - if (hws_mode != HWS_DEFAULT_MODE) - { - HW3S_UpdateSources(); - I_UpdateSound(); - return; - } -#endif - for (i = 0; i <= splitscreen; i++) { player_t *player = &players[displayplayers[i]]; @@ -918,12 +853,8 @@ void S_SetSfxVolume(INT32 volume) CV_SetValue(&cv_soundvolume, volume&0x1F); actualsfxvolume = cv_soundvolume.value; // check for change of var -#ifdef HW3SOUND - hws_mode == HWS_DEFAULT_MODE ? I_SetSfxVolume(volume&0x1F) : HW3S_SetSfxVolume(volume&0x1F); -#else // now hardware volume I_SetSfxVolume(volume&0x1F); -#endif } void S_ClearSfx(void) @@ -1119,11 +1050,6 @@ INT32 S_OriginPlaying(void *origin) if (!origin) return false; -#ifdef HW3SOUND - if (hws_mode != HWS_DEFAULT_MODE) - return HW3S_OriginPlaying(origin); -#endif - for (cnum = 0; cnum < numofchannels; cnum++) if (channels[cnum].origin == origin) return 1; @@ -1136,11 +1062,6 @@ INT32 S_IdPlaying(sfxenum_t id) { INT32 cnum; -#ifdef HW3SOUND - if (hws_mode != HWS_DEFAULT_MODE) - return HW3S_IdPlaying(id); -#endif - for (cnum = 0; cnum < numofchannels; cnum++) if ((size_t)(channels[cnum].sfxinfo - S_sfx) == (size_t)id) return 1; @@ -1155,11 +1076,6 @@ INT32 S_SoundPlaying(void *origin, sfxenum_t id) if (!origin) return 0; -#ifdef HW3SOUND - if (hws_mode != HWS_DEFAULT_MODE) - return HW3S_SoundPlaying(origin, id); -#endif - for (cnum = 0; cnum < numofchannels; cnum++) { if (channels[cnum].origin == origin diff --git a/src/s_sound.h b/src/s_sound.h index be4ed381d..124b74de3 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -296,10 +296,8 @@ void S_StartSoundName(void *mo, const char *soundname); void S_StopSoundByID(void *origin, sfxenum_t sfx_id); void S_StopSoundByNum(sfxenum_t sfxnum); -#ifndef HW3SOUND #define S_StartAttackSound S_StartSound #define S_StartScreamSound S_StartSound -#endif #ifdef MUSICSLOT_COMPATIBILITY // For compatibility with code/scripts relying on older versions diff --git a/src/sdl/Makefile.cfg b/src/sdl/Makefile.cfg index 72a94dca8..3cf04509b 100644 --- a/src/sdl/Makefile.cfg +++ b/src/sdl/Makefile.cfg @@ -90,22 +90,6 @@ ifdef MINGW endif endif -ifndef NOHW -ifdef OPENAL -ifdef MINGW - LIBS:=-lopenal32 $(LIBS) -else - LIBS:=-lopenal $(LIBS) -endif -else -ifdef MINGW -ifdef DS3D - LIBS:=-ldsound -luuid $(LIBS) -endif -endif -endif -endif - ifndef NOLIBBACKTRACE OPTS+=-DHAVE_LIBBACKTRACE ifdef MINGW64 diff --git a/src/sdl/Srb2SDL.dsp b/src/sdl/Srb2SDL.dsp index 6f799f4fb..35e5ec32b 100644 --- a/src/sdl/Srb2SDL.dsp +++ b/src/sdl/Srb2SDL.dsp @@ -45,7 +45,7 @@ MTL=midl.exe # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /G5 /W3 /GX /Zi /Ot /Og /Oi /Op /Oy /Ob1 /I "..\..\libs\libpng-src" /I "..\..\libs\zlib" /D "NDEBUG" /D "SDLMAIN" /D "NO_STDIO_REDIRECT" /D "USE_WGL_SWAP" /D "DIRECTFULLSCREEN" /D "HAVE_SDL" /D "HWRENDER" /D "HW3SOUND" /D "HAVE_FILTER" /D "HAVE_MIXER" /D "USEASM" /D "HAVE_PNG" /FR /FD /GF /c +# ADD CPP /nologo /G5 /W3 /GX /Zi /Ot /Og /Oi /Op /Oy /Ob1 /I "..\..\libs\libpng-src" /I "..\..\libs\zlib" /D "NDEBUG" /D "SDLMAIN" /D "NO_STDIO_REDIRECT" /D "USE_WGL_SWAP" /D "DIRECTFULLSCREEN" /D "HAVE_SDL" /D "HWRENDER" /D "HAVE_FILTER" /D "HAVE_MIXER" /D "USEASM" /D "HAVE_PNG" /FR /FD /GF /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" # SUBTRACT RSC /x @@ -72,7 +72,7 @@ LINK32=link.exe # PROP Target_Dir "" MTL=midl.exe # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /G6 /W4 /WX /Gm /GX /ZI /Od /Op /I "..\..\libs\libpng-src" /I "..\..\libs\zlib" /D "_DEBUG" /D "USE_WGL_SWAP" /D "DIRECTFULLSCREEN" /D "HAVE_SDL" /D "HWRENDER" /D "HW3SOUND" /D "HAVE_FILTER" /D "HAVE_MIXER" /D "USEASM" /D "HAVE_PNG" /FR /FD /GZ /c +# ADD CPP /nologo /G6 /W4 /WX /Gm /GX /ZI /Od /Op /I "..\..\libs\libpng-src" /I "..\..\libs\zlib" /D "_DEBUG" /D "USE_WGL_SWAP" /D "DIRECTFULLSCREEN" /D "HAVE_SDL" /D "HWRENDER" /D "HAVE_FILTER" /D "HAVE_MIXER" /D "USEASM" /D "HAVE_PNG" /FR /FD /GZ /c # SUBTRACT CPP /YX # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" @@ -536,18 +536,6 @@ SOURCE=..\y_inter.h # PROP Default_Filter "" # Begin Source File -SOURCE=..\hardware\hw3dsdrv.h -# End Source File -# Begin Source File - -SOURCE=..\hardware\hw3sound.c -# End Source File -# Begin Source File - -SOURCE=..\hardware\hw3sound.h -# End Source File -# Begin Source File - SOURCE=..\hardware\hw_bsp.c # End Source File # Begin Source File @@ -580,14 +568,6 @@ SOURCE=..\hardware\hw_glob.h # End Source File # Begin Source File -SOURCE=..\hardware\hw_light.c -# End Source File -# Begin Source File - -SOURCE=..\hardware\hw_light.h -# End Source File -# Begin Source File - SOURCE=..\hardware\hw_main.c # End Source File # Begin Source File @@ -604,11 +584,6 @@ SOURCE=..\hardware\hw_md2.h # End Source File # Begin Source File -SOURCE=..\hardware\hws_data.h -# End Source File -# End Group -# Begin Group "I_Interface" - # PROP Default_Filter "" # Begin Source File diff --git a/src/sdl/Srb2SDL.dsw b/src/sdl/Srb2SDL.dsw index 4f8f7bdce..888d2fcf3 100644 --- a/src/sdl/Srb2SDL.dsw +++ b/src/sdl/Srb2SDL.dsw @@ -36,18 +36,6 @@ Package=<4> ############################################################################### -Project: "s_openal"=..\hardware\s_openal\s_openal.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - Project: "zlib"=..\..\libs\zlib\projects\visualc6\zlib.dsp - Package Owner=<4> Package=<5> diff --git a/src/sdl/Srb2SDL.props b/src/sdl/Srb2SDL.props index 75839a5b2..f02b9b35e 100644 --- a/src/sdl/Srb2SDL.props +++ b/src/sdl/Srb2SDL.props @@ -6,10 +6,10 @@ - HAVE_ZLIB;HAVE_LIBGME;USE_WGL_SWAP;DIRECTFULLSCREEN;HAVE_SDL;HWRENDER;HW3SOUND;HAVE_FILTER;HAVE_MIXER;SDLMAIN;%(PreprocessorDefinitions) + HAVE_ZLIB;HAVE_LIBGME;USE_WGL_SWAP;DIRECTFULLSCREEN;HAVE_SDL;HWRENDER;HAVE_FILTER;HAVE_MIXER;SDLMAIN;%(PreprocessorDefinitions) - USE_WGL_SWAP;DIRECTFULLSCREEN;HAVE_SDL;HWRENDER;HW3SOUND;HAVE_FILTER;HAVE_MIXER;SDLMAIN;%(PreprocessorDefinitions) + USE_WGL_SWAP;DIRECTFULLSCREEN;HAVE_SDL;HWRENDER;HAVE_FILTER;HAVE_MIXER;SDLMAIN;%(PreprocessorDefinitions) - \ No newline at end of file + diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c index d3da79355..4b1988c6f 100644 --- a/src/sdl/hwsym_sdl.c +++ b/src/sdl/hwsym_sdl.c @@ -43,10 +43,6 @@ #define _CREATE_DLL_ // necessary for Unix AND Windows -#ifdef HW3SOUND -#include "../hardware/hw3dsdrv.h" -#endif - #define GETFUNC(func) \ else if (0 == strcmp(#func, funcName)) \ funcPointer = &func \ @@ -66,35 +62,16 @@ void *hwSym(const char *funcName,void *handle) { void *funcPointer = NULL; if (0) ; -#ifdef STATIC3DS - GETFUNC(Startup); - GETFUNC(AddSfx); - GETFUNC(AddSource); - GETFUNC(StartSource); - GETFUNC(StopSource); - GETFUNC(GetHW3DSVersion); - GETFUNC(BeginFrameUpdate); - GETFUNC(EndFrameUpdate); - GETFUNC(IsPlaying); - GETFUNC(UpdateListener); - GETFUNC(UpdateSourceParms); - GETFUNC(SetGlobalSfxVolume); - GETFUNC(SetCone); - GETFUNC(Update3DSource); - GETFUNC(ReloadSource); - GETFUNC(KillSource); - GETFUNC(Shutdown); - GETFUNC(GetHW3DSTitle); -#endif #ifdef NOLOADSO else funcPointer = handle; #else else if (handle) - funcPointer = SDL_LoadFunction(handle,funcName); + funcPointer = SDL_LoadFunction(handle, funcName); #endif if (!funcPointer) I_OutputMsg("hwSym for %s: %s\n", funcName, SDL_GetError()); + return funcPointer; } @@ -103,8 +80,6 @@ void *hwSym(const char *funcName,void *handle) \param hwfile Open a handle to the SO \return Handle to SO - - */ void *hwOpen(const char *hwfile) @@ -125,8 +100,6 @@ void *hwOpen(const char *hwfile) \param handle Close the handle of the SO \return void - - */ void hwClose(void *handle) diff --git a/src/sdl/macosx/Srb2mac.pbproj/project.pbxproj b/src/sdl/macosx/Srb2mac.pbproj/project.pbxproj index a4888ec50..24f05a04c 100644 --- a/src/sdl/macosx/Srb2mac.pbproj/project.pbxproj +++ b/src/sdl/macosx/Srb2mac.pbproj/project.pbxproj @@ -255,12 +255,6 @@ path = ../../../bin/Resources/drill.dta; refType = 2; }; - 6755C8BF101802C300A80195 = { - isa = PBXFileReference; - name = fmod.dll; - path = ../../../bin/Resources/fmod.dll; - refType = 2; - }; 6755C8C0101802C300A80195 = { isa = PBXFileReference; name = knux.plr; @@ -425,14 +419,6 @@ name = r_opengl; refType = 4; }; - 677B5ECA10180D7100A80195 = { - children = ( - 84F202CA08A92AA0000C01D8, - ); - isa = PBXGroup; - name = s_openal; - refType = 4; - }; 67B2D0C91018779900A80195 = { fileRef = 84177748085A1097000C01D8; isa = PBXBuildFile; @@ -1071,20 +1057,6 @@ path = ../../hardware/hw_glob.h; refType = 2; }; - 8417773D085A106C000C01D8 = { - fileEncoding = 30; - isa = PBXFileReference; - name = hw_light.c; - path = ../../hardware/hw_light.c; - refType = 2; - }; - 8417773E085A106C000C01D8 = { - fileEncoding = 30; - isa = PBXFileReference; - name = hw_light.h; - path = ../../hardware/hw_light.h; - refType = 2; - }; 8417773F085A106C000C01D8 = { fileEncoding = 30; isa = PBXFileReference; @@ -1113,41 +1085,6 @@ path = ../../hardware/hw_md2.h; refType = 2; }; - 84177743085A106C000C01D8 = { - fileEncoding = 30; - isa = PBXFileReference; - name = hw_trick.c; - path = ../../hardware/hw_trick.c; - refType = 2; - }; - 84177744085A106C000C01D8 = { - fileEncoding = 30; - isa = PBXFileReference; - name = hw3dsdrv.h; - path = ../../hardware/hw3dsdrv.h; - refType = 2; - }; - 84177745085A106C000C01D8 = { - fileEncoding = 30; - isa = PBXFileReference; - name = hw3sound.c; - path = ../../hardware/hw3sound.c; - refType = 2; - }; - 84177746085A106C000C01D8 = { - fileEncoding = 30; - isa = PBXFileReference; - name = hw3sound.h; - path = ../../hardware/hw3sound.h; - refType = 2; - }; - 84177747085A106C000C01D8 = { - fileEncoding = 30; - isa = PBXFileReference; - name = hws_data.h; - path = ../../hardware/hws_data.h; - refType = 2; - }; 84177748085A1097000C01D8 = { fileEncoding = 30; isa = PBXFileReference; @@ -2136,7 +2073,7 @@ buildSettings = { DEBUGGING_SYMBOLS = NO; FRAMEWORK_SEARCH_PATHS = "\"$(LOCAL_LIBRARY_DIR)/Frameworks\""; - HEADER_SEARCH_PATHS = "\"$(LOCAL_LIBRARY_DIR)/Frameworks/SDL.framework/Headers\" \"$(LOCAL_LIBRARY_DIR)/Frameworks/SDL_mixer.framework/Headers\" \"$(LOCAL_LIBRARY_DIR)/Frameworks/OpenAL.framework/Headers\" \"$(LOCAL_LIBRARY_DIR)/Frameworks/libpng.framework/Headers\""; + HEADER_SEARCH_PATHS = "\"$(LOCAL_LIBRARY_DIR)/Frameworks/SDL.framework/Headers\" \"$(LOCAL_LIBRARY_DIR)/Frameworks/SDL_mixer.framework/Headers\" \"$(LOCAL_LIBRARY_DIR)/Frameworks/libpng.framework/Headers\""; INSTALL_PATH = "$(HOME)/Applications"; JAVA_COMPILER_DEBUGGING_SYMBOLS = NO; OPTIMIZATION_CFLAGS = "-O2"; @@ -2328,7 +2265,7 @@ ); buildSettings = { FRAMEWORK_SEARCH_PATHS = "\"$(LOCAL_LIBRARY_DIR)/Frameworks\""; - HEADER_SEARCH_PATHS = "\"$(LOCAL_LIBRARY_DIR)/Frameworks/SDL.framework/Headers\" \"$(LOCAL_LIBRARY_DIR)/Frameworks/SDL_mixer.framework/Headers\" \"$(LOCAL_LIBRARY_DIR)/Frameworks/OpenAL.framework/Headers\" \"$(LOCAL_LIBRARY_DIR)/Frameworks/libpng.framework/Headers\""; + HEADER_SEARCH_PATHS = "\"$(LOCAL_LIBRARY_DIR)/Frameworks/SDL.framework/Headers\" \"$(LOCAL_LIBRARY_DIR)/Frameworks/SDL_mixer.framework/Headers\" \"$(LOCAL_LIBRARY_DIR)/Frameworks/libpng.framework/Headers\""; INSTALL_PATH = "$(HOME)/Applications"; OPTIMIZATION_CFLAGS = "-O0"; OTHER_CFLAGS = "-DMAC_ALERT -DUNIXCOMMON -DSDLMAIN -DHAVE_MIXER -DHAVE_PNG -D_BIG_ENDIAN -DSTDC_HEADERS -DSDL -Wall -W -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings -Wsign-compare -Waggregate-return -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -fno-strict-aliasing -fno-exceptions -D_DEBUG"; @@ -3521,19 +3458,6 @@ settings = { }; }; - 84F202C708A92A5D000C01D8 = { - isa = PBXFrameworkReference; - name = OpenAL.framework; - path = /Library/Frameworks/OpenAL.framework; - refType = 0; - }; - 84F202CA08A92AA0000C01D8 = { - fileEncoding = 30; - isa = PBXFileReference; - name = s_openal.c; - path = ../../hardware/s_openal/s_openal.c; - refType = 2; - }; }; rootObject = 84177702085A0C64000C01D8; } diff --git a/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj b/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj index 9ec22ebcc..c95642240 100644 --- a/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj +++ b/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj @@ -13,13 +13,10 @@ 1E32C4290B6E6D5D0029E058 /* libpng.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1E32C4140B6E6D5D0029E058 /* libpng.framework */; }; 1E32C42B0B6E6D6E0029E058 /* libpng.framework in Copy Frameworks into .app bundle */ = {isa = PBXBuildFile; fileRef = 1E32C4140B6E6D5D0029E058 /* libpng.framework */; }; 1E44AE750B67CC2B00BAD059 /* hw_bsp.c in Sources */ = {isa = PBXBuildFile; fileRef = 1E44AE610B67CC2B00BAD059 /* hw_bsp.c */; }; - 1E44AE770B67CC2B00BAD059 /* hw3sound.c in Sources */ = {isa = PBXBuildFile; fileRef = 1E44AE630B67CC2B00BAD059 /* hw3sound.c */; }; 1E44AE780B67CC2B00BAD059 /* hw_cache.c in Sources */ = {isa = PBXBuildFile; fileRef = 1E44AE640B67CC2B00BAD059 /* hw_cache.c */; }; - 1E44AE7C0B67CC2B00BAD059 /* hw_light.c in Sources */ = {isa = PBXBuildFile; fileRef = 1E44AE680B67CC2B00BAD059 /* hw_light.c */; }; 1E44AE800B67CC2B00BAD059 /* hw_draw.c in Sources */ = {isa = PBXBuildFile; fileRef = 1E44AE6C0B67CC2B00BAD059 /* hw_draw.c */; }; 1E44AE820B67CC2B00BAD059 /* hw_main.c in Sources */ = {isa = PBXBuildFile; fileRef = 1E44AE6E0B67CC2B00BAD059 /* hw_main.c */; }; 1E44AE840B67CC2B00BAD059 /* hw_md2.c in Sources */ = {isa = PBXBuildFile; fileRef = 1E44AE700B67CC2B00BAD059 /* hw_md2.c */; }; - 1E44AE860B67CC2B00BAD059 /* hw_trick.c in Sources */ = {isa = PBXBuildFile; fileRef = 1E44AE720B67CC2B00BAD059 /* hw_trick.c */; }; 1E44AEA40B67CC8500BAD059 /* d_clisrv.c in Sources */ = {isa = PBXBuildFile; fileRef = 1E44AE8D0B67CC8400BAD059 /* d_clisrv.c */; }; 1E44AEA70B67CC8500BAD059 /* d_main.c in Sources */ = {isa = PBXBuildFile; fileRef = 1E44AE900B67CC8400BAD059 /* d_main.c */; }; 1E44AEA80B67CC8500BAD059 /* d_net.c in Sources */ = {isa = PBXBuildFile; fileRef = 1E44AE910B67CC8500BAD059 /* d_net.c */; }; @@ -174,16 +171,11 @@ 1E32C4140B6E6D5D0029E058 /* libpng.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = libpng.framework; path = /Library/Frameworks/libpng.framework; sourceTree = ""; }; 1E44AE440B67CBE800BAD059 /* music.dta */ = {isa = PBXFileReference; lastKnownFileType = text; name = music.dta; path = ../../../bin/Resources/music.dta; sourceTree = SOURCE_ROOT; }; 1E44AE4B0B67CBE800BAD059 /* srb2.wad */ = {isa = PBXFileReference; lastKnownFileType = text; name = srb2.wad; path = ../../../bin/Resources/srb2.wad; sourceTree = SOURCE_ROOT; }; - 1E44AE600B67CC2B00BAD059 /* hw3dsdrv.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw3dsdrv.h; path = ../../hardware/hw3dsdrv.h; sourceTree = SOURCE_ROOT; }; 1E44AE610B67CC2B00BAD059 /* hw_bsp.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = hw_bsp.c; path = ../../hardware/hw_bsp.c; sourceTree = SOURCE_ROOT; }; 1E44AE620B67CC2B00BAD059 /* hw_defs.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw_defs.h; path = ../../hardware/hw_defs.h; sourceTree = SOURCE_ROOT; }; - 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_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; }; 1E44AE6B0B67CC2B00BAD059 /* hw_data.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw_data.h; path = ../../hardware/hw_data.h; sourceTree = SOURCE_ROOT; }; 1E44AE6C0B67CC2B00BAD059 /* hw_draw.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = hw_draw.c; path = ../../hardware/hw_draw.c; sourceTree = SOURCE_ROOT; }; 1E44AE6D0B67CC2B00BAD059 /* hw_glob.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw_glob.h; path = ../../hardware/hw_glob.h; sourceTree = SOURCE_ROOT; }; @@ -191,9 +183,6 @@ 1E44AE6F0B67CC2B00BAD059 /* hw_main.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw_main.h; path = ../../hardware/hw_main.h; sourceTree = SOURCE_ROOT; }; 1E44AE700B67CC2B00BAD059 /* hw_md2.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = hw_md2.c; path = ../../hardware/hw_md2.c; sourceTree = SOURCE_ROOT; }; 1E44AE710B67CC2B00BAD059 /* hw_md2.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hw_md2.h; path = ../../hardware/hw_md2.h; sourceTree = SOURCE_ROOT; }; - 1E44AE720B67CC2B00BAD059 /* hw_trick.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = hw_trick.c; path = ../../hardware/hw_trick.c; sourceTree = SOURCE_ROOT; }; - 1E44AE730B67CC2B00BAD059 /* hws_data.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hws_data.h; path = ../../hardware/hws_data.h; sourceTree = SOURCE_ROOT; }; - 1E44AE8A0B67CC6000BAD059 /* asm_defs.inc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.pascal; name = asm_defs.inc; path = ../../asm_defs.inc; sourceTree = SOURCE_ROOT; }; 1E44AE8D0B67CC8400BAD059 /* d_clisrv.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = d_clisrv.c; path = ../../d_clisrv.c; sourceTree = SOURCE_ROOT; }; 1E44AE8E0B67CC8400BAD059 /* d_clisrv.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = d_clisrv.h; path = ../../d_clisrv.h; sourceTree = SOURCE_ROOT; }; 1E44AE8F0B67CC8400BAD059 /* d_event.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = d_event.h; path = ../../d_event.h; sourceTree = SOURCE_ROOT; }; @@ -527,16 +516,11 @@ 1E44AE5C0B67CC0F00BAD059 /* Hw_Hardware */ = { isa = PBXGroup; children = ( - 1E44AE600B67CC2B00BAD059 /* hw3dsdrv.h */, 1E44AE610B67CC2B00BAD059 /* hw_bsp.c */, 1E44AE620B67CC2B00BAD059 /* hw_defs.h */, - 1E44AE630B67CC2B00BAD059 /* hw3sound.c */, 1E44AE640B67CC2B00BAD059 /* hw_cache.c */, 1E44AE650B67CC2B00BAD059 /* hw_dll.h */, 1E44AE660B67CC2B00BAD059 /* hw_gl.h */, - 1E44AE680B67CC2B00BAD059 /* hw_light.c */, - 1E44AE690B67CC2B00BAD059 /* hw_light.h */, - 1E44AE6A0B67CC2B00BAD059 /* hw3sound.h */, 1E44AE6B0B67CC2B00BAD059 /* hw_data.h */, 1E44AE6C0B67CC2B00BAD059 /* hw_draw.c */, 1E44AE6D0B67CC2B00BAD059 /* hw_glob.h */, @@ -544,8 +528,6 @@ 1E44AE6F0B67CC2B00BAD059 /* hw_main.h */, 1E44AE700B67CC2B00BAD059 /* hw_md2.c */, 1E44AE710B67CC2B00BAD059 /* hw_md2.h */, - 1E44AE720B67CC2B00BAD059 /* hw_trick.c */, - 1E44AE730B67CC2B00BAD059 /* hws_data.h */, ); name = Hw_Hardware; sourceTree = ""; @@ -1072,13 +1054,10 @@ buildActionMask = 2147483647; files = ( 1E44AE750B67CC2B00BAD059 /* hw_bsp.c in Sources */, - 1E44AE770B67CC2B00BAD059 /* hw3sound.c in Sources */, 1E44AE780B67CC2B00BAD059 /* hw_cache.c in Sources */, - 1E44AE7C0B67CC2B00BAD059 /* hw_light.c in Sources */, 1E44AE800B67CC2B00BAD059 /* hw_draw.c in Sources */, 1E44AE820B67CC2B00BAD059 /* hw_main.c in Sources */, 1E44AE840B67CC2B00BAD059 /* hw_md2.c in Sources */, - 1E44AE860B67CC2B00BAD059 /* hw_trick.c in Sources */, 1E44AEA40B67CC8500BAD059 /* d_clisrv.c in Sources */, 1E44AEA70B67CC8500BAD059 /* d_main.c in Sources */, 1E44AEA80B67CC8500BAD059 /* d_net.c in Sources */, @@ -1108,7 +1087,6 @@ 1E44AF220B67CE4100BAD059 /* mserv.c in Sources */, 1E44AF3C0B67CE5F00BAD059 /* p_enemy.c in Sources */, 1E44AF3D0B67CE5F00BAD059 /* p_inter.c in Sources */, - 1E44AF3E0B67CE5F00BAD059 /* p_fab.c in Sources */, 1E44AF3F0B67CE5F00BAD059 /* p_lights.c in Sources */, 1E44AF400B67CE5F00BAD059 /* p_map.c in Sources */, 1E44AF410B67CE5F00BAD059 /* p_maputl.c in Sources */, diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 33714f32a..58aa5ee91 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -69,12 +69,6 @@ #include "../d_main.h" -#ifdef HW3SOUND -#include "../hardware/hw3dsdrv.h" -#include "../hardware/hw3sound.h" -#include "hwsym_sdl.h" -#endif - #ifdef HAVE_LIBGME #include "gme/gme.h" #endif @@ -195,11 +189,7 @@ static void Snd_LockAudio(void) //Alam: Lock audio data and uninstall audio call { if (Snd_Mutex) SDL_LockMutex(Snd_Mutex); else if (sound_disabled) return; - else if (midi_disabled && digital_disabled -#ifdef HW3SOUND - && hws_mode == HWS_DEFAULT_MODE -#endif - ) SDL_LockAudio(); + else if (midi_disabled && digital_disabled) SDL_LockAudio(); #ifdef HAVE_MIXER else if (musicStarted) Mix_SetPostMix(NULL, NULL); #endif @@ -209,11 +199,7 @@ static void Snd_UnlockAudio(void) //Alam: Unlock audio data and reinstall audio { if (Snd_Mutex) SDL_UnlockMutex(Snd_Mutex); else if (sound_disabled) return; - else if (midi_disabled && digital_disabled -#ifdef HW3SOUND - && hws_mode == HWS_DEFAULT_MODE -#endif - ) SDL_UnlockAudio(); + else if (midi_disabled && digital_disabled) SDL_UnlockAudio(); #ifdef HAVE_MIXER else if (musicStarted) Mix_SetPostMix(audio.callback, audio.userdata); #endif @@ -536,11 +522,6 @@ void *I_GetSfx(sfxinfo_t *sfx) // else if (sfx->lumpnum != S_GetSfxLumpNum(sfx)) // I_FreeSfx(sfx); -#ifdef HW3SOUND - if (hws_mode != HWS_DEFAULT_MODE) - return HW3S_GetSfx(sfx); -#endif - if (sfx->data) return sfx->data; //Alam: I have it done! @@ -555,39 +536,31 @@ void I_FreeSfx(sfxinfo_t * sfx) // if (sfx->lumpnum<0) // return; -#ifdef HW3SOUND - if (hws_mode != HWS_DEFAULT_MODE) - { - HW3S_FreeSfx(sfx); - } - else -#endif - { - size_t i; + size_t i; - for (i = 1; i < NUMSFX; i++) + for (i = 1; i < NUMSFX; i++) + { + // Alias? Example is the chaingun sound linked to pistol. + if (S_sfx[i].data == sfx->data) { - // Alias? Example is the chaingun sound linked to pistol. - if (S_sfx[i].data == sfx->data) - { - if (S_sfx+i != sfx) S_sfx[i].data = NULL; - S_sfx[i].lumpnum = LUMPERROR; - S_sfx[i].length = 0; - } + if (S_sfx+i != sfx) S_sfx[i].data = NULL; + S_sfx[i].lumpnum = LUMPERROR; + S_sfx[i].length = 0; } - //Snd_LockAudio(); //Alam: too much? - // Loop all channels, check. - for (i = 0; i < NUM_CHANNELS; i++) - { - // Active, and using the same SFX? - if (channels[i].end && channels[i].id == sfx->data) - { - channels[i].end = NULL; // Reset. - } - } - //Snd_UnlockAudio(); //Alam: too much? - Z_Free(sfx->data); } + //Snd_LockAudio(); //Alam: too much? + // Loop all channels, check. + for (i = 0; i < NUM_CHANNELS; i++) + { + // Active, and using the same SFX? + if (channels[i].end && channels[i].id == sfx->data) + { + channels[i].end = NULL; // Reset. + } + } + //Snd_UnlockAudio(); //Alam: too much? + Z_Free(sfx->data); + sfx->data = NULL; sfx->lumpnum = LUMPERROR; } @@ -1081,62 +1054,6 @@ void I_UpdateSoundParams(INT32 handle, UINT8 vol, UINT8 sep, UINT8 pitch) } -#ifdef HW3SOUND - -static void *soundso = NULL; - -static INT32 Init3DSDriver(const char *soName) -{ - if (soName) soundso = hwOpen(soName); -#if defined (_WIN32) && defined (_X86_) && !defined (STATIC3DS) - HW3DS.pfnStartup = hwSym("Startup@8",soundso); - HW3DS.pfnShutdown = hwSym("Shutdown@0",soundso); - HW3DS.pfnAddSfx = hwSym("AddSfx@4",soundso); - HW3DS.pfnAddSource = hwSym("AddSource@8",soundso); - HW3DS.pfnStartSource = hwSym("StartSource@4",soundso); - HW3DS.pfnStopSource = hwSym("StopSource@4",soundso); - HW3DS.pfnGetHW3DSVersion = hwSym("GetHW3DSVersion@0",soundso); - HW3DS.pfnBeginFrameUpdate = hwSym("BeginFrameUpdate@0",soundso); - HW3DS.pfnEndFrameUpdate = hwSym("EndFrameUpdate@0",soundso); - HW3DS.pfnIsPlaying = hwSym("IsPlaying@4",soundso); - HW3DS.pfnUpdateListener = hwSym("UpdateListener@8",soundso); - HW3DS.pfnUpdateSourceParms = hwSym("UpdateSourceParms@12",soundso); - HW3DS.pfnSetCone = hwSym("SetCone@8",soundso); - HW3DS.pfnSetGlobalSfxVolume = hwSym("SetGlobalSfxVolume@4",soundso); - HW3DS.pfnUpdate3DSource = hwSym("Update3DSource@8",soundso); - HW3DS.pfnReloadSource = hwSym("ReloadSource@8",soundso); - HW3DS.pfnKillSource = hwSym("KillSource@4",soundso); - HW3DS.pfnKillSfx = hwSym("KillSfx@4",soundso); - HW3DS.pfnGetHW3DSTitle = hwSym("GetHW3DSTitle@8",soundso); -#else - HW3DS.pfnStartup = hwSym("Startup",soundso); - HW3DS.pfnShutdown = hwSym("Shutdown",soundso); - HW3DS.pfnAddSfx = hwSym("AddSfx",soundso); - HW3DS.pfnAddSource = hwSym("AddSource",soundso); - HW3DS.pfnStartSource = hwSym("StartSource",soundso); - HW3DS.pfnStopSource = hwSym("StopSource",soundso); - HW3DS.pfnGetHW3DSVersion = hwSym("GetHW3DSVersion",soundso); - HW3DS.pfnBeginFrameUpdate = hwSym("BeginFrameUpdate",soundso); - HW3DS.pfnEndFrameUpdate = hwSym("EndFrameUpdate",soundso); - HW3DS.pfnIsPlaying = hwSym("IsPlaying",soundso); - HW3DS.pfnUpdateListener = hwSym("UpdateListener",soundso); - HW3DS.pfnUpdateSourceParms = hwSym("UpdateSourceParms",soundso); - HW3DS.pfnSetCone = hwSym("SetCone",soundso); - HW3DS.pfnSetGlobalSfxVolume = hwSym("SetGlobalSfxVolume",soundso); - HW3DS.pfnUpdate3DSource = hwSym("Update3DSource",soundso); - HW3DS.pfnReloadSource = hwSym("ReloadSource",soundso); - HW3DS.pfnKillSource = hwSym("KillSource",soundso); - HW3DS.pfnKillSfx = hwSym("KillSfx",soundso); - HW3DS.pfnGetHW3DSTitle = hwSym("GetHW3DSTitle",soundso); -#endif - -// if (HW3DS.pfnUpdateListener2 && HW3DS.pfnUpdateListener2 != soundso) - return true; -// else -// return false; -} -#endif - void I_ShutdownSound(void) { if (sound_disabled || !sound_started) @@ -1144,15 +1061,6 @@ void I_ShutdownSound(void) CONS_Printf("I_ShutdownSound: "); -#ifdef HW3SOUND - if (hws_mode != HWS_DEFAULT_MODE) - { - HW3S_Shutdown(); - hwClose(soundso); - return; - } -#endif - if (midi_disabled && digital_disabled) SDL_CloseAudio(); CONS_Printf("%s", M_GetText("shut down\n")); @@ -1169,9 +1077,6 @@ void I_UpdateSound(void) void I_StartupSound(void) { -#ifdef HW3SOUND - const char *sdrv_name = NULL; -#endif #ifndef HAVE_MIXER #ifndef NO_MIDI midi_disabled = @@ -1228,75 +1133,6 @@ void I_StartupSound(void) if (sound_disabled) return; -#ifdef HW3SOUND -#ifdef STATIC3DS - if (M_CheckParm("-3dsound") || M_CheckParm("-ds3d")) - { - hws_mode = HWS_OPENAL; - } -#elif defined (_WIN32) - if (M_CheckParm("-ds3d")) - { - hws_mode = HWS_DS3D; - sdrv_name = "s_ds3d.dll"; - } - else if (M_CheckParm("-fmod3d")) - { - hws_mode = HWS_FMOD3D; - sdrv_name = "s_fmod.dll"; - } - else if (M_CheckParm("-openal")) - { - hws_mode = HWS_OPENAL; - sdrv_name = "s_openal.dll"; - } -#else - if (M_CheckParm("-fmod3d")) - { - hws_mode = HWS_FMOD3D; - sdrv_name = "./s_fmod.so"; - } - else if (M_CheckParm("-openal")) - { - hws_mode = HWS_OPENAL; - sdrv_name = "./s_openal.so"; - } -#endif - else if (M_CheckParm("-sounddriver") && M_IsNextParm()) - { - hws_mode = HWS_OTHER; - sdrv_name = M_GetNextParm(); - } - if (hws_mode != HWS_DEFAULT_MODE) - { - if (Init3DSDriver(sdrv_name)) - { - snddev_t snddev; - - //sound_disabled = true; - //I_AddExitFunc(I_ShutdownSound); - snddev.bps = 16; - snddev.sample_rate = audio.freq; - snddev.numsfxs = NUMSFX; -#if defined (_WIN32) - snddev.cooplevel = 0x00000002; - snddev.hWnd = vid.WndParent; -#endif - if (HW3S_Init(I_Error, &snddev)) - { - audio.userdata = NULL; - CONS_Printf("%s", M_GetText(" Using 3D sound driver\n")); - return; - } - CONS_Printf("%s", M_GetText(" Failed loading 3D sound driver\n")); - // Falls back to default sound system - HW3S_Shutdown(); - hwClose(soundso); - } - CONS_Printf("%s", M_GetText(" Failed loading 3D sound driver\n")); - hws_mode = HWS_DEFAULT_MODE; - } -#endif if (!musicStarted && SDL_OpenAudio(&audio, &audio) < 0) { CONS_Printf("%s", M_GetText(" couldn't open audio with desired format\n")); From f7ba2607170a54de468b48c557e5173ee6a15052 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Dec 2024 19:59:42 +0100 Subject: [PATCH 58/99] just skip missing/broken fields in musiccredit handling like vanilla kek still will throw warnings but atleast will show stuff if theres anything left in the musicdef --- src/s_sound.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index d5ea1d4c7..06f6be1eb 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1229,12 +1229,13 @@ ReadMusicDefFields (UINT16 wadnum, int line, char *stoken, musicdef_t **defp) if (!stricmp(stoken, "lump")) { value = strtok(NULL, " "); + if (!value) { CONS_Alert(CONS_WARNING, "MUSICDEF: Field '%s' is missing name. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line); - return false; + goto skip_lump; } else { @@ -1255,6 +1256,10 @@ ReadMusicDefFields (UINT16 wadnum, int line, char *stoken, musicdef_t **defp) (*defp) = def; } + +skip_lump: + stoken = strtok(NULL, " "); + line++; } else { @@ -1271,7 +1276,7 @@ ReadMusicDefFields (UINT16 wadnum, int line, char *stoken, musicdef_t **defp) CONS_Alert(CONS_WARNING, "MUSICDEF: Field '%s' is missing value. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line); - return false; + goto skip_field; } else { @@ -1323,6 +1328,10 @@ ReadMusicDefFields (UINT16 wadnum, int line, char *stoken, musicdef_t **defp) else CONS_Alert(CONS_WARNING, "MUSICDEF: Invalid field '%s'. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line); #undef ADDDEF + +skip_field: + stoken = strtok(NULL, "= "); + line++; } } From fef98e478dc11da4977f849d5956fa4d2f93d747 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Dec 2024 17:55:50 +0100 Subject: [PATCH 59/99] add extra driftgauge option before i forger about it again --- src/d_netcmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 4f8a2b684..a6943fe6a 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -548,7 +548,7 @@ consvar_t cv_shownametagspectator = {"kartshownametagspectator", "No", CV_SAVE, static CV_PossibleValue_t driftgaugeoffset_cons_t[] = { {-FRACUNIT*128, "MIN"}, {FRACUNIT*128, "MAX"}, {0, NULL}}; static CV_PossibleValue_t driftgaugestyle_cons_t[] = { - {1, "Default"}, {2, "Small"}, {3, "Big Numbers"}, {4, "Numbers Only"}, {0, NULL}}; + {1, "Default"}, {2, "Small"}, {3, "Big Numbers"}, {4, "Numbers Only"}, {5, "Extra"}, {0, NULL}}; consvar_t cv_driftgauge = {"kartdriftgauge", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_driftgaugeofs = {"kartdriftgaugeoffset", "-20", CV_FLOAT|CV_SAVE, driftgaugeoffset_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; From ffc7832ec76df571666da187cfeaaa42360e900a Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 31 Dec 2024 00:57:32 +0100 Subject: [PATCH 60/99] attempt to optimize column drawers a little --- src/r_draw8.c | 665 +++++++++++++++++++++++++++++-------------------- src/r_things.c | 3 + 2 files changed, 400 insertions(+), 268 deletions(-) diff --git a/src/r_draw8.c b/src/r_draw8.c index 3c7562beb..30fe49372 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -34,17 +34,19 @@ void R_DrawColumn_8(void) count = dc_yh - dc_yl; if (count < 0) // Zero length, column does not exceed a pixel. + { return; + } + -#ifdef RANGECHECK if ((unsigned)dc_x >= (unsigned)vid.width || dc_yl < 0 || dc_yh >= vid.height) + { return; -#endif + } // Framebuffer destination address. // Use ylookup LUT to avoid multiply with ScreenWidth. // Use columnofs LUT for subwindows? - dest = &topleft[dc_yl*vid.width + dc_x]; count++; @@ -55,10 +57,15 @@ void R_DrawColumn_8(void) // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // This is as fast as it gets. + register const UINT8 *source = dc_source; + register const lighttable_t *colormap = dc_colormap; + + register INT32 heightmask = dc_texheight-1; + + if (dc_texheight & heightmask) // not a power of 2 -- killough { - register const UINT8 *source = dc_source; - register const lighttable_t *colormap = dc_colormap; - register INT32 heightmask = dc_texheight-1; + heightmask++; + heightmask <<= FRACBITS; if (dc_sourcelength <= 0) { @@ -73,55 +80,77 @@ void R_DrawColumn_8(void) npow2max = dc_sourcelength; } - if (dc_texheight & heightmask) // not a power of 2 -- killough + if (frac < 0) { - heightmask++; - heightmask <<= FRACBITS; - - if (frac < 0) - while ((frac += heightmask) < 0); - else - while (frac >= heightmask) - frac -= heightmask; - - do + while ((frac += heightmask) < 0) { - // Re-map color indices from wall texture column - // using a lighting/special effects LUT. - // heightmask is the Tutti-Frutti fix - - // -1 is the lower clamp bound because column posts have a "safe" byte before the real data - // and a few bytes after as well - *dest = colormap[source[CLAMP(frac>>FRACBITS, npow2min, npow2max)]]; - dest += vid.width; - - // Avoid overflow. - if (fracstep > 0x7FFFFFFF - frac) - frac += fracstep - heightmask; - else - frac += fracstep; - - while (frac >= heightmask) - frac -= heightmask; - } while (--count); + ; + } } else { - while ((count -= 2) >= 0) // texture height is a power of 2 + while (frac >= heightmask) { - *dest = colormap[source[(frac>>FRACBITS) & heightmask]]; - dest += vid.width; - frac += fracstep; + frac -= heightmask; + } + } - *dest = colormap[source[(frac>>FRACBITS) & heightmask]]; - dest += vid.width; + do + { + // Re-map color indices from wall texture column + // using a lighting/special effects LUT. + // heightmask is the Tutti-Frutti fix + + // -1 is the lower clamp bound because column posts have a "safe" byte before the real data + // and a few bytes after as well + + // jartha: faster on my AMD FX-6300 CPU. + // Faster than ternaries, faster than std::min/std::max. Don't ask me why. + // I tested by viewing a non-PO2 texture from a consistent distance so it covered the entire screen. + // The framerate difference was about 50 frames at 640x400. + INT32 n = frac >> FRACBITS; + if (n < npow2min) + n = npow2min; + if (n > npow2max) + n = npow2max; + *dest = colormap[source[n]]; + + dest += vid.width; + + // Avoid overflow. + if (fracstep > 0x7FFFFFFF - frac) + { + frac += fracstep - heightmask; + } + else + { frac += fracstep; } - if (count & 1) + while (frac >= heightmask) { - *dest = colormap[source[(frac>>FRACBITS) & heightmask]]; + frac -= heightmask; } + } while (--count); + } + else + { + while ((count -= 2) >= 0) // texture height is a power of 2 + { + *dest = colormap[source[(frac>>FRACBITS) & heightmask]]; + + dest += vid.width; + frac += fracstep; + + *dest = colormap[source[(frac>>FRACBITS) & heightmask]]; + + dest += vid.width; + frac += fracstep; + } + + if (count & 1) + { + *dest = colormap[source[(frac>>FRACBITS) & heightmask]]; } } } @@ -139,34 +168,37 @@ void R_Draw2sMultiPatchColumn_8(void) count = dc_yh - dc_yl; if (count < 0) // Zero length, column does not exceed a pixel. + { return; + } -#ifdef RANGECHECK if ((unsigned)dc_x >= (unsigned)vid.width || dc_yl < 0 || dc_yh >= vid.height) + { return; -#endif + } // Framebuffer destination address. // Use ylookup LUT to avoid multiply with ScreenWidth. // Use columnofs LUT for subwindows? - - //dest = ylookup[dc_yl] + columnofs[dc_x]; dest = &topleft[dc_yl*vid.width + dc_x]; count++; // Determine scaling, which is the only mapping to be done. fracstep = dc_iscale; - //frac = dc_texturemid + (dc_yl - centery)*fracstep; frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // This is as fast as it gets. + register const UINT8 *source = dc_source; + register const lighttable_t *colormap = dc_colormap; + register INT32 heightmask = dc_texheight-1; + register UINT8 val; + + if (dc_texheight & heightmask) // not a power of 2 -- killough { - register const UINT8 *source = dc_source; - register const lighttable_t *colormap = dc_colormap; - register INT32 heightmask = dc_texheight-1; - register UINT8 val; + heightmask++; + heightmask <<= FRACBITS; if (dc_sourcelength <= 0) { @@ -181,74 +213,94 @@ void R_Draw2sMultiPatchColumn_8(void) npow2max = dc_sourcelength; } - if (dc_texheight & heightmask) // not a power of 2 -- killough + if (frac < 0) { - heightmask++; - heightmask <<= FRACBITS; - - if (frac < 0) - while ((frac += heightmask) < 0); - else - while (frac >= heightmask) - frac -= heightmask; - - do + while ((frac += heightmask) < 0) { - // Re-map color indices from wall texture column - // using a lighting/special effects LUT. - // heightmask is the Tutti-Frutti fix - - // -1 is the lower clamp bound because column posts have a "safe" byte before the real data - // and a few bytes after as well - val = source[CLAMP(frac>>FRACBITS, npow2min, npow2max)]; - - if (val != TRANSPARENTPIXEL) - { - *dest = colormap[val]; - } - - dest += vid.width; - - // Avoid overflow. - if (fracstep > 0x7FFFFFFF - frac) - frac += fracstep - heightmask; - else - frac += fracstep; - - while (frac >= heightmask) - frac -= heightmask; - } while (--count); + ; + } } else { - while ((count -= 2) >= 0) // texture height is a power of 2 + while (frac >= heightmask) { - val = source[(frac>>FRACBITS) & heightmask]; - if (val != TRANSPARENTPIXEL) - { - *dest = colormap[val]; - } + frac -= heightmask; + } + } - dest += vid.width; - frac += fracstep; + do + { + // Re-map color indices from wall texture column + // using a lighting/special effects LUT. + // heightmask is the Tutti-Frutti fix - val = source[(frac>>FRACBITS) & heightmask]; - if (val != TRANSPARENTPIXEL) - { - *dest = colormap[val]; - } + // -1 is the lower clamp bound because column posts have a "safe" byte before the real data + // and a few bytes after as well - dest += vid.width; + // jartha: faster on my AMD FX-6300 CPU. + // Faster than ternaries, faster than std::min/std::max. Don't ask me why. + // I tested by viewing a non-PO2 texture from a consistent distance so it covered the entire screen. + // The framerate difference was about 50 frames at 640x400. + INT32 n = frac >> FRACBITS; + if (n < npow2min) + n = npow2min; + if (n > npow2max) + n = npow2max; + + val = source[n]; + + if (val != TRANSPARENTPIXEL) + { + *dest = colormap[val]; + } + + dest += vid.width; + + // Avoid overflow. + if (fracstep > 0x7FFFFFFF - frac) + { + frac += fracstep - heightmask; + } + else + { frac += fracstep; } - if (count & 1) + while (frac >= heightmask) { - val = source[(frac>>FRACBITS) & heightmask]; - if (val != TRANSPARENTPIXEL) - { - *dest = colormap[val]; - } + frac -= heightmask; + } + } while (--count); + } + else + { + while ((count -= 2) >= 0) // texture height is a power of 2 + { + val = source[(frac>>FRACBITS) & heightmask]; + if (val != TRANSPARENTPIXEL) + { + *dest = colormap[val]; + } + + dest += vid.width; + frac += fracstep; + + val = source[(frac>>FRACBITS) & heightmask]; + if (val != TRANSPARENTPIXEL) + { + *dest = colormap[val]; + } + + dest += vid.width; + frac += fracstep; + } + + if (count & 1) + { + val = source[(frac>>FRACBITS) & heightmask]; + if (val != TRANSPARENTPIXEL) + { + *dest = colormap[val]; } } } @@ -266,35 +318,38 @@ void R_Draw2sMultiPatchTranslucentColumn_8(void) count = dc_yh - dc_yl; if (count < 0) // Zero length, column does not exceed a pixel. + { return; + } -#ifdef RANGECHECK if ((unsigned)dc_x >= (unsigned)vid.width || dc_yl < 0 || dc_yh >= vid.height) + { return; -#endif + } // Framebuffer destination address. // Use ylookup LUT to avoid multiply with ScreenWidth. // Use columnofs LUT for subwindows? - - //dest = ylookup[dc_yl] + columnofs[dc_x]; dest = &topleft[dc_yl*vid.width + dc_x]; count++; // Determine scaling, which is the only mapping to be done. fracstep = dc_iscale; - //frac = dc_texturemid + (dc_yl - centery)*fracstep; frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // This is as fast as it gets. + register const UINT8 *source = dc_source; + register const UINT8 *transmap = dc_transmap; + register const lighttable_t *colormap = dc_colormap; + register INT32 heightmask = dc_texheight-1; + register UINT8 val; + + if (dc_texheight & heightmask) // not a power of 2 -- killough { - register const UINT8 *source = dc_source; - register const UINT8 *transmap = dc_transmap; - register const lighttable_t *colormap = dc_colormap; - register INT32 heightmask = dc_texheight-1; - register UINT8 val; + heightmask++; + heightmask <<= FRACBITS; if (dc_sourcelength <= 0) { @@ -309,74 +364,94 @@ void R_Draw2sMultiPatchTranslucentColumn_8(void) npow2max = dc_sourcelength; } - if (dc_texheight & heightmask) // not a power of 2 -- killough + if (frac < 0) { - heightmask++; - heightmask <<= FRACBITS; - - if (frac < 0) - while ((frac += heightmask) < 0); - else - while (frac >= heightmask) - frac -= heightmask; - - do + while ((frac += heightmask) < 0) { - // Re-map color indices from wall texture column - // using a lighting/special effects LUT. - // heightmask is the Tutti-Frutti fix - - // -1 is the lower clamp bound because column posts have a "safe" byte before the real data - // and a few bytes after as well - val = source[CLAMP(frac>>FRACBITS, npow2min, npow2max)]; - - if (val != TRANSPARENTPIXEL) - { - *dest = *(transmap + (colormap[val]<<8) + (*dest)); - } - - dest += vid.width; - - // Avoid overflow. - if (fracstep > 0x7FFFFFFF - frac) - frac += fracstep - heightmask; - else - frac += fracstep; - - while (frac >= heightmask) - frac -= heightmask; - } while (--count); + ; + } } else { - while ((count -= 2) >= 0) // texture height is a power of 2 + while (frac >= heightmask) { - val = source[(frac>>FRACBITS) & heightmask]; - if (val != TRANSPARENTPIXEL) - { - *dest = *(transmap + (colormap[val]<<8) + (*dest)); - } + frac -= heightmask; + } + } - dest += vid.width; - frac += fracstep; + do + { + // Re-map color indices from wall texture column + // using a lighting/special effects LUT. + // heightmask is the Tutti-Frutti fix - val = source[(frac>>FRACBITS) & heightmask]; - if (val != TRANSPARENTPIXEL) - { - *dest = *(transmap + (colormap[val]<<8) + (*dest)); - } + // -1 is the lower clamp bound because column posts have a "safe" byte before the real data + // and a few bytes after as well - dest += vid.width; + // jartha: faster on my AMD FX-6300 CPU. + // Faster than ternaries, faster than std::min/std::max. Don't ask me why. + // I tested by viewing a non-PO2 texture from a consistent distance so it covered the entire screen. + // The framerate difference was about 50 frames at 640x400. + INT32 n = frac >> FRACBITS; + if (n < npow2min) + n = npow2min; + if (n > npow2max) + n = npow2max; + + val = source[n]; + + if (val != TRANSPARENTPIXEL) + { + *dest = *(transmap + (colormap[val]<<8) + (*dest)); + } + + dest += vid.width; + + // Avoid overflow. + if (fracstep > 0x7FFFFFFF - frac) + { + frac += fracstep - heightmask; + } + else + { frac += fracstep; } - if (count & 1) + while (frac >= heightmask) { - val = source[(frac>>FRACBITS) & heightmask]; - if (val != TRANSPARENTPIXEL) - { - *dest = *(transmap + (colormap[val]<<8) + (*dest)); - } + frac -= heightmask; + } + } while (--count); + } + else + { + while ((count -= 2) >= 0) // texture height is a power of 2 + { + val = source[(frac>>FRACBITS) & heightmask]; + if (val != TRANSPARENTPIXEL) + { + *dest = *(transmap + (colormap[val]<<8) + (*dest)); + } + + dest += vid.width; + frac += fracstep; + + val = source[(frac>>FRACBITS) & heightmask]; + if (val != TRANSPARENTPIXEL) + { + *dest = *(transmap + (colormap[val]<<8) + (*dest)); + } + + dest += vid.width; + frac += fracstep; + } + + if (count & 1) + { + val = source[(frac>>FRACBITS) & heightmask]; + if (val != TRANSPARENTPIXEL) + { + *dest = *(transmap + (colormap[val]<<8) + (*dest)); } } } @@ -396,21 +471,22 @@ void R_DrawShadeColumn_8(void) return; count = dc_yh - dc_yl; - if (count < 0) - return; -#ifdef RANGECHECK + if (count < 0) // Zero length, column does not exceed a pixel. + { + return; + } + if ((unsigned)dc_x >= (unsigned)vid.width || dc_yl < 0 || dc_yh >= vid.height) - I_Error("R_DrawShadeColumn_8: %d to %d at %d", dc_yl, dc_yh, dc_x); -#endif + { + return; + } // FIXME. As above. - //dest = ylookup[dc_yl] + columnofs[dc_x]; dest = &topleft[dc_yl*vid.width + dc_x]; // Looks familiar. fracstep = dc_iscale; - //frac = dc_texturemid + (dc_yl - centery)*fracstep; frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); // Here we do an additional index re-mapping. @@ -438,29 +514,33 @@ void R_DrawTranslucentColumn_8(void) count = dc_yh - dc_yl + 1; if (count <= 0) // Zero length, column does not exceed a pixel. + { return; + } -#ifdef RANGECHECK if ((unsigned)dc_x >= (unsigned)vid.width || dc_yl < 0 || dc_yh >= vid.height) - I_Error("R_DrawTranslucentColumn_8: %d to %d at %d", dc_yl, dc_yh, dc_x); -#endif + { + return; + } // FIXME. As above. - //dest = ylookup[dc_yl] + columnofs[dc_x]; dest = &topleft[dc_yl*vid.width + dc_x]; // Looks familiar. fracstep = dc_iscale; - //frac = dc_texturemid + (dc_yl - centery)*fracstep; frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // This is as fast as it gets. + register const UINT8 *source = dc_source; + register const UINT8 *transmap = dc_transmap; + register const lighttable_t *colormap = dc_colormap; + register INT32 heightmask = dc_texheight - 1; + + if (dc_texheight & heightmask) { - register const UINT8 *source = dc_source; - register const UINT8 *transmap = dc_transmap; - register const lighttable_t *colormap = dc_colormap; - register INT32 heightmask = dc_texheight - 1; + heightmask++; + heightmask <<= FRACBITS; if (dc_sourcelength <= 0) { @@ -475,53 +555,68 @@ void R_DrawTranslucentColumn_8(void) npow2max = dc_sourcelength; } - if (dc_texheight & heightmask) + if (frac < 0) { - heightmask++; - heightmask <<= FRACBITS; - - if (frac < 0) - while ((frac += heightmask) < 0) - ; - else - while (frac >= heightmask) - frac -= heightmask; - - do + while ((frac += heightmask) < 0) { - // Re-map color indices from wall texture column - // using a lighting/special effects LUT. - // heightmask is the Tutti-Frutti fix - - // -1 is the lower clamp bound because column posts have a "safe" byte before the real data - // and a few bytes after as well - *dest = *(transmap + (colormap[source[CLAMP(frac>>FRACBITS, npow2min, npow2max)]]<<8) + (*dest)); - - dest += vid.width; - - if ((frac += fracstep) >= heightmask) - frac -= heightmask; + ; } - while (--count); } else { - while ((count -= 2) >= 0) // texture height is a power of 2 + while (frac >= heightmask) { - *dest = *(transmap + (colormap[source[(frac>>FRACBITS)&heightmask]]<<8) + (*dest)); - dest += vid.width; - frac += fracstep; - - *dest = *(transmap + (colormap[source[(frac>>FRACBITS)&heightmask]]<<8) + (*dest)); - dest += vid.width; - frac += fracstep; + frac -= heightmask; } + } - if (count & 1) + do + { + // Re-map color indices from wall texture column + // using a lighting/special effects LUT. + // heightmask is the Tutti-Frutti fix + + // -1 is the lower clamp bound because column posts have a "safe" byte before the real data + // and a few bytes after as well + + // jartha: faster on my AMD FX-6300 CPU. + // Faster than ternaries, faster than std::min/std::max. Don't ask me why. + // I tested by viewing a non-PO2 texture from a consistent distance so it covered the entire screen. + // The framerate difference was about 50 frames at 640x400. + INT32 n = frac >> FRACBITS; + if (n < npow2min) + n = npow2min; + if (n > npow2max) + n = npow2max; + + *dest = *(transmap + (colormap[source[n]]<<8) + (*dest)); + + dest += vid.width; + + if ((frac += fracstep) >= heightmask) { - *dest = *(transmap + (colormap[source[(frac>>FRACBITS)&heightmask]]<<8) + (*dest)); + frac -= heightmask; } } + while (--count); + } + else + { + while ((count -= 2) >= 0) // texture height is a power of 2 + { + *dest = *(transmap + (colormap[source[(frac>>FRACBITS)&heightmask]]<<8) + (*dest)); + dest += vid.width; + frac += fracstep; + + *dest = *(transmap + (colormap[source[(frac>>FRACBITS)&heightmask]]<<8) + (*dest)); + dest += vid.width; + frac += fracstep; + } + + if (count & 1) + { + *dest = *(transmap + (colormap[source[(frac>>FRACBITS)&heightmask]]<<8) + (*dest)); + } } } @@ -540,21 +635,30 @@ void R_DrawTranslatedTranslucentColumn_8(void) count = dc_yh - dc_yl + 1; if (count <= 0) // Zero length, column does not exceed a pixel. + { return; + } + + if ((unsigned)dc_x >= (unsigned)vid.width || dc_yl < 0 || dc_yh >= vid.height) + { + return; + } // FIXME. As above. - //dest = ylookup[dc_yl] + columnofs[dc_x]; dest = &topleft[dc_yl*vid.width + dc_x]; // Looks familiar. fracstep = dc_iscale; - //frac = dc_texturemid + (dc_yl - centery)*fracstep; frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // This is as fast as it gets. + register INT32 heightmask = dc_texheight - 1; + + if (dc_texheight & heightmask) { - register INT32 heightmask = dc_texheight - 1; + heightmask++; + heightmask <<= FRACBITS; if (dc_sourcelength <= 0) { @@ -569,52 +673,68 @@ void R_DrawTranslatedTranslucentColumn_8(void) npow2max = dc_sourcelength; } - if (dc_texheight & heightmask) + if (frac < 0) { - heightmask++; - heightmask <<= FRACBITS; - - if (frac < 0) - while ((frac += heightmask) < 0) - ; - else - while (frac >= heightmask) - frac -= heightmask; - - do + while ((frac += heightmask) < 0) { - // Re-map color indices from wall texture column - // using a lighting/special effects LUT. - // heightmask is the Tutti-Frutti fix - - // -1 is the lower clamp bound because column posts have a "safe" byte before the real data - // and a few bytes after as well - *dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[CLAMP(frac>>FRACBITS, npow2min, npow2max)]]]<<8) + (*dest)); - dest += vid.width; - - if ((frac += fracstep) >= heightmask) - frac -= heightmask; + ; } - while (--count); } else { - while ((count -= 2) >= 0) // texture height is a power of 2 + while (frac >= heightmask) { - *dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest)); - dest += vid.width; - frac += fracstep; - - *dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest)); - dest += vid.width; - frac += fracstep; + frac -= heightmask; } + } - if (count & 1) + do + { + // Re-map color indices from wall texture column + // using a lighting/special effects LUT. + // heightmask is the Tutti-Frutti fix + + // -1 is the lower clamp bound because column posts have a "safe" byte before the real data + // and a few bytes after as well + + // jartha: faster on my AMD FX-6300 CPU. + // Faster than ternaries, faster than std::min/std::max. Don't ask me why. + // I tested by viewing a non-PO2 texture from a consistent distance so it covered the entire screen. + // The framerate difference was about 50 frames at 640x400. + INT32 n = frac >> FRACBITS; + if (n < npow2min) + n = npow2min; + if (n > npow2max) + n = npow2max; + + *dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[n]]]<<8) + (*dest)); + + dest += vid.width; + + if ((frac += fracstep) >= heightmask) { - *dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest)); + frac -= heightmask; } } + while (--count); + } + else + { + while ((count -= 2) >= 0) // texture height is a power of 2 + { + *dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest)); + dest += vid.width; + frac += fracstep; + + *dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest)); + dest += vid.width; + frac += fracstep; + } + + if (count & 1) + { + *dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest)); + } } } @@ -630,21 +750,22 @@ void R_DrawTranslatedColumn_8(void) register fixed_t frac, fracstep; count = dc_yh - dc_yl; - if (count < 0) - return; -#ifdef RANGECHECK + if (count < 0) + { + return; + } + if ((unsigned)dc_x >= (unsigned)vid.width || dc_yl < 0 || dc_yh >= vid.height) - I_Error("R_DrawTranslatedColumn_8: %d to %d at %d", dc_yl, dc_yh, dc_x); -#endif + { + return; + } // FIXME. As above. - //dest = ylookup[dc_yl] + columnofs[dc_x]; dest = &topleft[dc_yl*vid.width + dc_x]; // Looks familiar. fracstep = dc_iscale; - //frac = dc_texturemid + (dc_yl-centery)*fracstep; frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); // Here we do an additional index re-mapping. @@ -709,7 +830,9 @@ void R_DrawSpan_8 (void) dest = ylookup[ds_y] + columnofs[ds_x1]; if (dest+8 > deststop) + { return; + } while (count >= 8) { @@ -752,12 +875,18 @@ void R_CalcTiltedLighting(fixed_t start, fixed_t end) // I wanna do some optimizing by checking for out-of-range segments on either side to fill in all at once, // but I'm too bad at coding to not crash the game trying to do that. I guess this is fast enough for now... - for (i = left; i <= right; i++) { + for (i = left; i <= right; i++) + { tiltlighting[i] = (start += step) >> FRACBITS; + if (tiltlighting[i] < 0) + { tiltlighting[i] = 0; + } else if (tiltlighting[i] >= MAXLIGHTSCALE) + { tiltlighting[i] = MAXLIGHTSCALE-1; + } } } diff --git a/src/r_things.c b/src/r_things.c index 94d108fec..511c26bd6 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -623,6 +623,7 @@ void R_DrawMaskedColumn(column_t *column) { dc_source = (UINT8 *)column + 3; dc_sourcelength = column->length; + dc_texheight = column->length; dc_texturemid = basetexturemid - (topdelta<length); dc_sourcelength = column->length; + dc_texheight = column->length; + for (s = (UINT8 *)column+2+column->length, d = dc_source; d < dc_source+column->length; --s) *d++ = *s; dc_texturemid = basetexturemid - (topdelta< Date: Wed, 1 Jan 2025 05:06:52 +0100 Subject: [PATCH 61/99] dont iterate through precip blockmap if there is no precip --- src/hardware/hw_main.c | 2 +- src/r_things.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 5eefc9c7e..aaf1cb2e6 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4360,7 +4360,7 @@ static void HWR_AddPrecipitationSprites(void) fixed_t drawdist; // save a little time on invisible weather - if (curWeather == PRECIP_BLANK || curWeather == PRECIP_STORM_NORAIN) + if (curWeather == PRECIP_NONE || curWeather == PRECIP_BLANK || curWeather == PRECIP_STORM_NORAIN) { return; } diff --git a/src/r_things.c b/src/r_things.c index 511c26bd6..ca534f54b 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1979,7 +1979,7 @@ void R_AddPrecipitationSprites(void) precipmobj_t *th, *next; // no, no infinite draw distance for precipitation. this option at zero is supposed to turn it off - if (drawdist == 0 || curWeather == PRECIP_BLANK || curWeather == PRECIP_STORM_NORAIN) + if (drawdist == 0 || curWeather == PRECIP_NONE || curWeather == PRECIP_BLANK || curWeather == PRECIP_STORM_NORAIN) { return; } From 3ade8b09c5e6a9e44a4de6e409139ad859f6f20f Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 1 Jan 2025 05:10:52 +0100 Subject: [PATCH 62/99] move early return even earlier so theres no need to constantly init scale and drawdist --- src/hardware/hw_main.c | 2 +- src/r_things.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index aaf1cb2e6..3d7fbbd50 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4359,7 +4359,7 @@ static void HWR_AddPrecipitationSprites(void) fixed_t drawdist; - // save a little time on invisible weather + // save a little time if theres no or invisible weather if (curWeather == PRECIP_NONE || curWeather == PRECIP_BLANK || curWeather == PRECIP_STORM_NORAIN) { return; diff --git a/src/r_things.c b/src/r_things.c index ca534f54b..9bdb9ea67 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1972,14 +1972,20 @@ void R_AddSprites(sector_t *sec, INT32 lightlevel) // void R_AddPrecipitationSprites(void) { - fixed_t precipscale = (cv_mobjscaleprecip.value ? mapobjectscale : FRACUNIT); - fixed_t drawdist = ((fixed_t)(cv_drawdist_precip.value) * precipscale); - INT32 xl, xh, yl, yh, bx, by; precipmobj_t *th, *next; + // save a little time if theres no or invisible weather + if (curWeather == PRECIP_NONE || curWeather == PRECIP_BLANK || curWeather == PRECIP_STORM_NORAIN) + { + return; + } + + const fixed_t precipscale = (cv_mobjscaleprecip.value ? mapobjectscale : FRACUNIT); + const fixed_t drawdist = ((fixed_t)(cv_drawdist_precip.value) * precipscale); + // no, no infinite draw distance for precipitation. this option at zero is supposed to turn it off - if (drawdist == 0 || curWeather == PRECIP_NONE || curWeather == PRECIP_BLANK || curWeather == PRECIP_STORM_NORAIN) + if (drawdist == 0) { return; } From 5e1d43b5affe45e0b5382ec3362e8a1d8df30da1 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 1 Jan 2025 06:18:05 +0100 Subject: [PATCH 63/99] those will never be changed ever --- src/g_game.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index e7dc9d92d..c4fbec8bc 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -701,9 +701,7 @@ const char *G_BuildMapName(INT32 map) */ INT16 G_ClipAimingPitch(INT32 *aiming) { - INT32 limitangle; - - limitangle = ANGLE_90 - 1; + static const INT32 limitangle = ANGLE_90 - 1; if (*aiming > limitangle) *aiming = limitangle; @@ -715,10 +713,8 @@ INT16 G_ClipAimingPitch(INT32 *aiming) INT16 G_SoftwareClipAimingPitch(INT32 *aiming) { - INT32 limitangle; - // note: the current software mode implementation doesn't have true perspective - limitangle = ANGLE_90 - ANG10; // Some viewing fun, but not too far down... + static const INT32 limitangle = ANGLE_90 - ANG10; // Some viewing fun, but not too far down... if (*aiming > limitangle) *aiming = limitangle; From 8f0c5fb5084d3adaefc4e7a8536b96ac567ffb2a Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 1 Jan 2025 17:06:03 +0100 Subject: [PATCH 64/99] always close any menus when using "connect" command --- src/d_clisrv.c | 3 ++- src/m_menu.c | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 5d04b98e0..e6cc26690 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3069,9 +3069,10 @@ static void Command_connect(void) return; } + M_ClearMenus(true); + if (Playing() || demo.title) { - M_ClearMenus(true); if (demo.title) G_CheckDemoStatus(); diff --git a/src/m_menu.c b/src/m_menu.c index 8cfe16a97..42cf93f9c 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4587,7 +4587,7 @@ void M_ClearMenus(boolean callexitmenufunc) if (currentMenu->quitroutine && callexitmenufunc && !currentMenu->quitroutine()) return; // we can't quit this menu (also used to set parameter from the menu) -// Save the config file. I'm sick of crashing the game later and losing all my changes! + // Save the config file. I'm sick of crashing the game later and losing all my changes! COM_BufAddText(va("saveconfig \"%s\" -silent\n", configfile)); if (currentMenu == &MessageDef) // Oh sod off! @@ -9600,16 +9600,17 @@ static void M_DrawConnectMenu(void) highlightflags, va("%u of %d", serverlistpage+1, numPages)); // Did you change the Server Browser address? Have a little reminder. - #ifdef MASTERSERVER +#ifdef MASTERSERVER if (CV_IsSetToDefault(&cv_masterserver)) mservflags = mservflags|highlightflags|V_30TRANS; else mservflags = mservflags|warningflags; + V_DrawRightAlignedSmallString(BASEVIDWIDTH - currentMenu->x, currentMenu->y+3 + MP_ConnectMenu[mp_connect_refresh].alphaKey, mservflags, va("MS: %s", cv_masterserver.string)); M_DrawServerCountAndHorizontalBar(); - #endif +#endif // When switching pages, slide the old page and the // new page across the screen From 8da59dc288f734d0926c39de853a94f8d0ee02ca Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 1 Jan 2025 17:36:47 +0100 Subject: [PATCH 65/99] slightly cleanup rumble and led ticker --- src/d_main.c | 7 +++++-- src/p_tick.c | 17 +++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index a44c12ad6..f9e1ca27e 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -171,14 +171,17 @@ static inline void D_DeviceLEDTick(void) UINT16 color[MAXSPLITSCREENPLAYERS]; UINT16 curcolor[MAXSPLITSCREENPLAYERS]; - if (I_NumJoys() == 0 || (cv_gamepadled[0].value == 0 && cv_gamepadled[1].value == 0 && cv_gamepadled[2].value == 0 && cv_gamepadled[3].value == 0)) + if (I_NumJoys() == 0) { return; } for (i = 0; i <= splitscreen; i++) { - if (cv_usejoystick[i].value == 0) + if (!cv_usejoystick[i].value) + continue; + + if (!cv_gamepadled[i].value) continue; color[i] = G_GetSkinColor(i); diff --git a/src/p_tick.c b/src/p_tick.c index 3b0cadde8..9d5c8539b 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -354,21 +354,25 @@ static void P_DeviceRumbleTick(void) { UINT8 i; - if (I_NumJoys() == 0 || (cv_rumble[0].value == 0 && cv_rumble[1].value == 0 && cv_rumble[2].value == 0 && cv_rumble[3].value == 0)) + if (I_NumJoys() == 0 || gamestate != GS_LEVEL) { return; } for (i = 0; i <= splitscreen; i++) { - player_t *player = &players[displayplayers[i]]; UINT16 low = 0; UINT16 high = 0; - if (!P_IsLocalPlayer(player)) + if (!cv_usejoystick[i].value) continue; - if (cv_usejoystick[i].value == 0) + if (!cv_rumble[i].value) + continue; + + player_t *player = &players[displayplayers[i]]; + + if (!P_IsLocalPlayer(player)) continue; if (!playeringame[displayplayers[i]] || player->spectator) @@ -402,10 +406,11 @@ static void P_DeviceRumbleTick(void) high = 65536 / 256; } - if (low == 0 && high == 0) + // hack alert! i just dont want this thing constantly resetting the rumble lol + if (low == 0 && high == 0) continue; - G_PlayerDeviceRumble(i, low, high, 57); // hack alert! i just dont want this think constantly resetting the rumble lol + G_PlayerDeviceRumble(i, low, high, 57); } } From bb3a65f8ffc8e85a27f4aa234fcb343a1598e450 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 1 Jan 2025 19:58:49 +0300 Subject: [PATCH 66/99] Repurpose ST_DrawTextInput into M_DrawTextInputScroll, and move its definition into m_textinput.c. M_DrawTextInput is now a macro using M_DrawTextInputScroll --- src/m_menu.c | 36 ++++-------------------- src/m_menu.h | 4 --- src/m_textinput.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ src/m_textinput.h | 5 ++++ src/st_stuff.c | 71 +---------------------------------------------- 5 files changed, 82 insertions(+), 105 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 42cf93f9c..03eeef210 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4980,33 +4980,6 @@ void M_DrawTextBoxFlags(INT32 x, INT32 y, INT32 width, INT32 boxlines, INT32 fla V_DrawFill(x+5, y+5, width*8+6, boxlines*8+6, 239|flags); } -void M_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags) -{ - INT32 skullx = x; - - V_DrawString(x, y, V_ALLOWLOWERCASE|flags, input->buffer); - - // draw text cursor for name - if (input->length) - skullx = x+V_SubStringWidth(input->buffer, input->cursor, V_ALLOWLOWERCASE); - - if (skullAnimCounter < 4) // blink cursor - V_DrawCharacter(skullx, y+3, '_'|flags, false); - - // draw selection - if (input->select != input->cursor) - { - size_t start = min(input->select, input->cursor); - size_t end = max(input->select, input->cursor); - - size_t len = end - start; - - INT32 startx = V_SubStringWidth(input->buffer, start, V_ALLOWLOWERCASE); - - V_DrawFill(x+startx, y, V_SubStringWidth(input->buffer+start, len, V_ALLOWLOWERCASE), 8, 103|V_TRANSLUCENT|flags); - } -} - // horizontally centered text static void M_CentreText(INT32 y, const char *string) { @@ -10195,7 +10168,8 @@ static void M_StartServerMenu(INT32 choice) // CONNECT VIA IP // ============== -static char setupm_ip[28]; +#define SETUPM_IP_MAXSIZE ((28-1)*8) +static char setupm_ip[64]; static textinput_t setupm_input_ip; #endif @@ -10203,8 +10177,8 @@ void M_Multiplayer(INT32 choice) { (void)choice; #ifndef NONET - memset(setupm_ip, 0, 28); - M_TextInputInit(&setupm_input_ip, setupm_ip, 28); + memset(setupm_ip, 0, sizeof(setupm_ip)); + M_TextInputInit(&setupm_input_ip, setupm_ip, sizeof(setupm_ip)); #endif M_SetupNextMenu(&MP_MainDef); } @@ -10243,7 +10217,7 @@ Update the maxplayers label... if (itemOn != 9) V_DrawString(x+8,y+12, V_ALLOWLOWERCASE, setupm_ip); else - M_DrawTextInput(x+8, y+12, &setupm_input_ip, 0); + M_DrawTextInputScroll(x+8, y+12, &setupm_input_ip, 0, SETUPM_IP_MAXSIZE); #endif // character bar, ripped off the color bar :V diff --git a/src/m_menu.h b/src/m_menu.h index 9806773b4..72864c669 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -64,10 +64,6 @@ void M_DrawTextBox(INT32 x, INT32 y, INT32 width, INT32 boxlines); // Same but with extra flags applied void M_DrawTextBoxFlags(INT32 x, INT32 y, INT32 width, INT32 boxlines, INT32 flags); -// Draw text input -typedef struct textinput_s textinput_t; -void M_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags); - // Used in d_netcmd to restart time attack void M_ModeAttackRetry(INT32 choice); diff --git a/src/m_textinput.c b/src/m_textinput.c index 266a8f300..dfe9f5a64 100644 --- a/src/m_textinput.c +++ b/src/m_textinput.c @@ -1,4 +1,7 @@ #include "m_textinput.h" +#include "m_menu.h" // MAXSTRINGLENGTH +#include "v_video.h" +#include "r_main.h" // renderisnewtic #include "i_system.h" #include "keys.h" #include "console.h" @@ -132,6 +135,8 @@ void M_TextInputInit(textinput_t *input, char *buffer, size_t buffer_size) input->buffer = buffer; input->buffer_size = buffer_size; + input->skull = 0; + M_TextInputClear(input); } @@ -314,3 +319,69 @@ boolean M_TextInputHandle(textinput_t *input, INT32 key) return true; } + +void M_DrawTextInputScroll(INT32 x, INT32 y, textinput_t *input, INT32 flags, INT32 MAXINPUTWIDTH) +{ + if (renderisnewtic) + input->skull++; + input->skull %= 8; + + char nametodraw[MAXSTRINGLENGTH*2+1] = {0}; + + size_t drawstart = 0; + size_t drawend = 0; // Only used for selection + + INT32 skullx = x; + + while (V_SubStringWidth(input->buffer+drawstart, input->cursor-drawstart, V_ALLOWLOWERCASE) > MAXINPUTWIDTH) + ++drawstart; + + size_t drawlength = V_SubStringLengthToFit(input->buffer+drawstart, MAXINPUTWIDTH+8, V_ALLOWLOWERCASE)+1; + drawend = drawstart + drawlength; + + memcpy(nametodraw, input->buffer+drawstart, drawlength); + + if (input->length) + skullx += V_SubStringWidth(nametodraw, input->cursor-drawstart, V_ALLOWLOWERCASE); + + V_DrawString(x, y, V_ALLOWLOWERCASE|flags, nametodraw); + + // draw text cursor for name + if (input->skull < 4) // blink cursor + V_DrawCharacter(skullx, y+3, '_'|flags, false); + + // draw selection + if (input->select != input->cursor) + { + size_t start = min(input->select, input->cursor); + size_t end = max(input->select, input->cursor); + + INT32 startx = 0; + INT32 width = 0; + + // I couldn't figure out one formula so here's bunch of separate cases + if (start < drawstart && end > drawend) // Selection covers whole visible portion of demo name + { + startx = -2; + width = V_StringWidth(nametodraw, V_ALLOWLOWERCASE)+4; + } + else if (start < drawstart) // Only left side of selection is off visible part + { + startx = -2; + size_t len = (end - start) - (drawstart - start); + width = V_SubStringWidth(nametodraw, len, V_ALLOWLOWERCASE)+2; + } + else if (end > drawend) // Only right side of selection is off visible part + { + startx = V_SubStringWidth(nametodraw, start-drawstart, V_ALLOWLOWERCASE); + width = V_StringWidth(nametodraw+(start-drawstart), V_ALLOWLOWERCASE)+2; + } + else // All selection is on visible part + { + startx = V_SubStringWidth(nametodraw, start-drawstart, V_ALLOWLOWERCASE); + width = V_SubStringWidth(nametodraw+(start-drawstart), end-start, V_ALLOWLOWERCASE); + } + + V_DrawFill(x+startx, y, width, 8, 103|V_TRANSLUCENT|flags); + } +} diff --git a/src/m_textinput.h b/src/m_textinput.h index aad5e94ab..649288ec4 100644 --- a/src/m_textinput.h +++ b/src/m_textinput.h @@ -10,6 +10,8 @@ typedef struct textinput_s { char *buffer; size_t buffer_size; + + unsigned skull; } textinput_t; void M_TextInputInit(textinput_t *input, char *buffer, size_t buffer_size); @@ -20,4 +22,7 @@ void M_TextInputSetString(textinput_t *input, const char *c); boolean M_TextInputHandle(textinput_t *input, INT32 key); +#define M_DrawTextInput(x, y, input, flags) M_DrawTextInputScroll((x), (y), (input), (flags), ((input)->buffer_size-1)*8) +void M_DrawTextInputScroll(INT32 x, INT32 y, textinput_t *input, INT32 flags, INT32 MAXINPUTWIDTH); + #endif diff --git a/src/st_stuff.c b/src/st_stuff.c index aaa926515..fa64b3709 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -829,82 +829,13 @@ static void ST_overlayDrawer(void) } } -static void ST_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags) -{ - static UINT8 skullAnimCounter = 0; - static const INT32 MAXINPUTWIDTH = (MAXSTRINGLENGTH-1)*8; - - if (renderisnewtic) - skullAnimCounter++; - skullAnimCounter %= 8; - - char nametodraw[MAXSTRINGLENGTH*2+1] = {0}; - - size_t drawstart = 0; - size_t drawend = 0; // Only used for selection - - INT32 skullx = x; - - while (V_SubStringWidth(input->buffer+drawstart, input->cursor-drawstart, V_ALLOWLOWERCASE) > MAXINPUTWIDTH) - ++drawstart; - - size_t drawlength = V_SubStringLengthToFit(input->buffer+drawstart, MAXINPUTWIDTH+8, V_ALLOWLOWERCASE)+1; - drawend = drawstart + drawlength; - - memcpy(nametodraw, input->buffer+drawstart, drawlength); - - if (input->length) - skullx += V_SubStringWidth(nametodraw, input->cursor-drawstart, V_ALLOWLOWERCASE); - - V_DrawString(x, y, V_ALLOWLOWERCASE|flags, nametodraw); - - // draw text cursor for name - if (skullAnimCounter < 4) // blink cursor - V_DrawCharacter(skullx, y+3, '_'|flags, false); - - // draw selection - if (input->select != input->cursor) - { - size_t start = min(input->select, input->cursor); - size_t end = max(input->select, input->cursor); - - INT32 startx = 0; - INT32 width = 0; - - // I couldn't figure out one formula so here's bunch of separate cases - if (start < drawstart && end > drawend) // Selection covers whole visible portion of demo name - { - startx = -2; - width = V_StringWidth(nametodraw, V_ALLOWLOWERCASE)+4; - } - else if (start < drawstart) // Only left side of selection is off visible part - { - startx = -2; - size_t len = (end - start) - (drawstart - start); - width = V_SubStringWidth(nametodraw, len, V_ALLOWLOWERCASE)+2; - } - else if (end > drawend) // Only right side of selection is off visible part - { - startx = V_SubStringWidth(nametodraw, start-drawstart, V_ALLOWLOWERCASE); - width = V_StringWidth(nametodraw+(start-drawstart), V_ALLOWLOWERCASE)+2; - } - else // All selection is on visible part - { - startx = V_SubStringWidth(nametodraw, start-drawstart, V_ALLOWLOWERCASE); - width = V_SubStringWidth(nametodraw+(start-drawstart), end-start, V_ALLOWLOWERCASE); - } - - V_DrawFill(x+startx, y, width, 8, 103|V_TRANSLUCENT|flags); - } -} - void ST_DrawDemoTitleEntry(void) { #define x (BASEVIDWIDTH/2 - 139) #define y (BASEVIDHEIGHT/2) M_DrawTextBox(x, y + 4, MAXSTRINGLENGTH, 1); - ST_DrawTextInput(x + 8, y + 12, &demo.titlenameinput, 0); + M_DrawTextInputScroll(x + 8, y + 12, &demo.titlenameinput, 0, (MAXSTRINGLENGTH-1)*8); M_DrawTextBox(x + 30, y - 24, 26, 1); V_DrawString(x + 38, y - 16, V_ALLOWLOWERCASE, "Enter the name of the replay."); From e321d759c0bc8461d5ab7bccf96a718dd5edd2e3 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 1 Jan 2025 20:01:54 +0300 Subject: [PATCH 67/99] Thats not defined or used anywhere, bad automerge maybe? --- src/st_stuff.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index fa64b3709..8b431b2f0 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -788,8 +788,6 @@ static void ST_overlayDrawer(void) snprintf(directortoggle, 32, "%s - Toggle Director", item1 != NULL ? item1 : item2 != NULL ? item2 : "Not Bound"); V_DrawString(2, BASEVIDHEIGHT-10, V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_HUDTRANSHALF, directortoggle); - - directortextactive = true; } else { From 5d44b445581323f4dfa914dc3be1aa5c8c80a2fe Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 1 Jan 2025 21:34:02 +0100 Subject: [PATCH 68/99] use FRACUNIT in rumbleticker + some changes - brakedrift will now add to any rumble thats currently going on - both hyu and invul now rumble less heavy on offroad --- src/p_tick.c | 59 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/src/p_tick.c b/src/p_tick.c index 9d5c8539b..4f91ff89b 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -365,21 +365,31 @@ static void P_DeviceRumbleTick(void) UINT16 high = 0; if (!cv_usejoystick[i].value) + { continue; + } if (!cv_rumble[i].value) + { continue; + } player_t *player = &players[displayplayers[i]]; if (!P_IsLocalPlayer(player)) + { continue; + } if (!playeringame[displayplayers[i]] || player->spectator) + { continue; + } if (player->mo == NULL) + { continue; + } if (player->exiting) { @@ -389,26 +399,50 @@ static void P_DeviceRumbleTick(void) if (player->kartstuff[k_spinouttimer]) { - low = high = 65536 / 4; + low = high = FRACUNIT / 4; } else if (player->kartstuff[k_sneakertimer] > (sneakertime-(TICRATE/2))) { - low = high = 65536 / 8; + low = high = FRACUNIT / 8; } - else if ((player->kartstuff[k_offroad] && !player->kartstuff[k_hyudorotimer]) + else if ((player->kartstuff[k_offroad]) && P_IsObjectOnGround(player->mo) && player->speed != 0) { - low = high = 65536 / 64; + if (player->kartstuff[k_hyudorotimer]) + { + high = FRACUNIT / 128; + } + else if (player->kartstuff[k_invincibilitytimer]) + { + high = FRACUNIT / 64; + } + else + { + low = high = FRACUNIT / 64; + } } - else if (player->kartstuff[k_brakedrift]) + + if (player->kartstuff[k_brakedrift]) { - low = 0; - high = 65536 / 256; + high += FRACUNIT / 256; } // hack alert! i just dont want this thing constantly resetting the rumble lol if (low == 0 && high == 0) + { continue; + } + + // pls dont overflow or smth lel + if (low > FRACUNIT-1) + { + low = FRACUNIT-1; + } + + if (high > FRACUNIT-1) + { + high = FRACUNIT-1; + } G_PlayerDeviceRumble(i, low, high, 57); } @@ -782,8 +816,15 @@ void P_PreTicker(INT32 frames) // Run any "after all the other thinkers" stuff for (i = 0; i < MAXPLAYERS; i++) - if (playeringame[i] && players[i].mo && !P_MobjWasRemoved(players[i].mo)) - P_PlayerAfterThink(&players[i]); + { + if (!playeringame[i]) + continue; + + if (!players[i].mo || P_MobjWasRemoved(players[i].mo)) + continue; + + P_PlayerAfterThink(&players[i]); + } LUA_HookThinkFrame(); From 54fda32591a7fd4cfa6bf1859d361f45c8fad30e Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 1 Jan 2025 21:52:54 +0100 Subject: [PATCH 69/99] logic error lmao oops --- src/p_tick.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/p_tick.c b/src/p_tick.c index 4f91ff89b..af4facd53 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -424,7 +424,7 @@ static void P_DeviceRumbleTick(void) if (player->kartstuff[k_brakedrift]) { - high += FRACUNIT / 256; + high = CLAMP((high + FRACUNIT / 256), 0, UINT16_MAX); } // hack alert! i just dont want this thing constantly resetting the rumble lol @@ -433,17 +433,6 @@ static void P_DeviceRumbleTick(void) continue; } - // pls dont overflow or smth lel - if (low > FRACUNIT-1) - { - low = FRACUNIT-1; - } - - if (high > FRACUNIT-1) - { - high = FRACUNIT-1; - } - G_PlayerDeviceRumble(i, low, high, 57); } } From 30dc0abc2512020d342c7d7982ef0fec93e314cc Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 2 Jan 2025 17:07:41 +0100 Subject: [PATCH 70/99] move camera noclip stuff into its own function its not used in kart anyways and moving it makes crap more readable --- src/p_user.c | 406 ++++++++++++++++++++++++++------------------------- 1 file changed, 208 insertions(+), 198 deletions(-) diff --git a/src/p_user.c b/src/p_user.c index afce1d7a7..51900717e 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3398,6 +3398,212 @@ void P_ResetCamera(player_t *player, camera_t *thiscam) while (!P_MoveChaseCamera(player,thiscam,true) && ++tries < 2*TICRATE); } +#ifndef NOCLIPCAM // Disable all z-clipping for noclip cam +static boolean P_CheckNoclipCameraPosition(player_t *player, camera_t *thiscam, fixed_t x, fixed_t y, fixed_t z, boolean resetcalled) +{ + subsector_t *newsubsec; + boolean cameranoclip; + mobj_t *mo = player->mo; + + cameranoclip = ((player->pflags & (PF_NOCLIP|PF_NIGHTSMODE)) + || (mo->flags & (MF_NOCLIP|MF_NOCLIPHEIGHT)) // Noclipping player camera noclips too!! + || (leveltime < introtime)); // Kart intro cam + + // move camera down to move under lower ceilings + newsubsec = R_IsPointInSubsector(((mo->x>>FRACBITS) + (thiscam->x>>FRACBITS))<<(FRACBITS-1), ((mo->y>>FRACBITS) + (thiscam->y>>FRACBITS))<<(FRACBITS-1)); + + if (!newsubsec) + newsubsec = thiscam->subsector; + + if (newsubsec) + { + fixed_t myfloorz, myceilingz; + fixed_t midz = thiscam->z + (thiscam->z - mo->z)/2; + fixed_t midx = ((mo->x>>FRACBITS) + (thiscam->x>>FRACBITS))<<(FRACBITS-1); + fixed_t midy = ((mo->y>>FRACBITS) + (thiscam->y>>FRACBITS))<<(FRACBITS-1); + + // Cameras use the heightsec's heights rather then the actual sector heights. + // If you can see through it, why not move the camera through it too? + if (newsubsec->sector->camsec >= 0) + { + myfloorz = sectors[newsubsec->sector->camsec].floorheight; + myceilingz = sectors[newsubsec->sector->camsec].ceilingheight; + } + else if (newsubsec->sector->heightsec >= 0) + { + myfloorz = sectors[newsubsec->sector->heightsec].floorheight; + myceilingz = sectors[newsubsec->sector->heightsec].ceilingheight; + } + else + { + myfloorz = P_CameraGetFloorZ(thiscam, newsubsec->sector, midx, midy, NULL); + myceilingz = P_CameraGetCeilingZ(thiscam, newsubsec->sector, midx, midy, NULL); + } + + // Check list of fake floors and see if floorz/ceilingz need to be altered. + if (newsubsec->sector->ffloors) + { + ffloor_t *rover; + fixed_t delta1, delta2; + INT32 thingtop = midz + thiscam->height; + + for (rover = newsubsec->sector->ffloors; rover; rover = rover->next) + { + fixed_t topheight, bottomheight; + if (!(rover->flags & FF_BLOCKOTHERS) || !(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERALL) || GETSECSPECIAL(rover->master->frontsector->special, 4) == 12) + continue; + + topheight = P_CameraGetFOFTopZ(thiscam, newsubsec->sector, rover, midx, midy, NULL); + bottomheight = P_CameraGetFOFBottomZ(thiscam, newsubsec->sector, rover, midx, midy, NULL); + + delta1 = midz - (bottomheight + + ((topheight - bottomheight)/2)); + delta2 = thingtop - (bottomheight + + ((topheight - bottomheight)/2)); + if (topheight > myfloorz && abs(delta1) < abs(delta2)) + myfloorz = topheight; + if (bottomheight < myceilingz && abs(delta1) >= abs(delta2)) + myceilingz = bottomheight; + } + } + + // Check polyobjects and see if floorz/ceilingz need to be altered + { + INT32 xl, xh, yl, yh, bx, by; + validcount++; + + xl = (unsigned)(tmbbox[BOXLEFT] - bmaporgx)>>MAPBLOCKSHIFT; + xh = (unsigned)(tmbbox[BOXRIGHT] - bmaporgx)>>MAPBLOCKSHIFT; + yl = (unsigned)(tmbbox[BOXBOTTOM] - bmaporgy)>>MAPBLOCKSHIFT; + yh = (unsigned)(tmbbox[BOXTOP] - bmaporgy)>>MAPBLOCKSHIFT; + + BMBOUNDFIX(xl, xh, yl, yh); + + for (by = yl; by <= yh; by++) + { + for (bx = xl; bx <= xh; bx++) + { + INT32 offset; + polymaplink_t *plink; // haleyjd 02/22/06 + + if (bx < 0 || by < 0 || bx >= bmapwidth || by >= bmapheight) + continue; + + offset = by*bmapwidth + bx; + + // haleyjd 02/22/06: consider polyobject lines + plink = polyblocklinks[offset]; + + while (plink) + { + polyobj_t *po = plink->po; + + if (po->validcount != validcount) // if polyobj hasn't been checked + { + sector_t *polysec; + fixed_t delta1, delta2, thingtop; + fixed_t polytop, polybottom; + + po->validcount = validcount; + + if (!P_PointInsidePolyobj(po, x, y) || !(po->flags & POF_SOLID)) + { + plink = (polymaplink_t *)(plink->link.next); + continue; + } + + // We're inside it! Yess... + polysec = po->lines[0]->backsector; + + if (GETSECSPECIAL(polysec->special, 4) == 12) + { // Camera noclip polyobj. + plink = (polymaplink_t *)(plink->link.next); + continue; + } + + if (po->flags & POF_CLIPPLANES) + { + polytop = polysec->ceilingheight; + polybottom = polysec->floorheight; + } + else + { + polytop = INT32_MAX; + polybottom = INT32_MIN; + } + + thingtop = midz + thiscam->height; + delta1 = midz - (polybottom + ((polytop - polybottom)/2)); + delta2 = thingtop - (polybottom + ((polytop - polybottom)/2)); + + if (polytop > myfloorz && abs(delta1) < abs(delta2)) + myfloorz = polytop; + + if (polybottom < myceilingz && abs(delta1) >= abs(delta2)) + myceilingz = polybottom; + } + plink = (polymaplink_t *)(plink->link.next); + } + } + } + } + + // crushed camera + if (myceilingz <= myfloorz + thiscam->height && !resetcalled && !cameranoclip) + { + P_ResetCamera(player, thiscam); + return true; + } + + // camera fit? + if (myceilingz != myfloorz + && myceilingz - thiscam->height < z) + { + z = myceilingz - thiscam->height-FixedMul(11*FRACUNIT, mo->scale); + // is the camera fit is there own sector + } + + // Make the camera a tad smarter with 3d floors + if (newsubsec->sector->ffloors && !cameranoclip) + { + ffloor_t *rover; + + for (rover = newsubsec->sector->ffloors; rover; rover = rover->next) + { + fixed_t topheight, bottomheight; + if ((rover->flags & FF_BLOCKOTHERS) && (rover->flags & FF_RENDERALL) && (rover->flags & FF_EXISTS) && GETSECSPECIAL(rover->master->frontsector->special, 4) == 12) + { + topheight = P_CameraGetFOFTopZ(thiscam, newsubsec->sector, rover, midx, midy, NULL); + bottomheight = P_CameraGetFOFBottomZ(thiscam, newsubsec->sector, rover, midx, midy, NULL); + + if (bottomheight - thiscam->height < z + && midz < bottomheight) + z = bottomheight - thiscam->height-FixedMul(11*FRACUNIT, mo->scale); + + else if (topheight + thiscam->height > z + && midz > topheight) + z = topheight; + + if ((mo->z >= topheight && midz < bottomheight) + || ((mo->z < bottomheight && mo->z+mo->height < topheight) && midz >= topheight)) + { + // Can't see + if (!resetcalled) + P_ResetCamera(player, thiscam); + return true; + } + } + } + } + } + + if (thiscam->z < thiscam->floorz && !cameranoclip) + thiscam->z = thiscam->floorz; + + return false; +} +#endif + boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcalled) { static boolean lookbackactive[MAXSPLITSCREENPLAYERS]; @@ -3411,10 +3617,6 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall UINT8 timeover; mobj_t *mo; fixed_t f1, f2; -#ifndef NOCLIPCAM - boolean cameranoclip; - subsector_t *newsubsec; -#endif democam.soundmobj = NULL; // reset this each frame, we don't want the game crashing for stupid reasons now do we @@ -3472,12 +3674,6 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall mo = player->mo; -#ifndef NOCLIPCAM - cameranoclip = ((player->pflags & (PF_NOCLIP|PF_NIGHTSMODE)) - || (mo->flags & (MF_NOCLIP|MF_NOCLIPHEIGHT)) // Noclipping player camera noclips too!! - || (leveltime < introtime)); // Kart intro cam -#endif - if (player->pflags & PF_TIMEOVER) // 1 for momentum keep, 2 for turnaround timeover = (player->kartstuff[k_timeovercam] > 2*TICRATE ? 2 : 1); else @@ -3663,194 +3859,8 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall z = mo->z + pviewheight + camheight; #ifndef NOCLIPCAM // Disable all z-clipping for noclip cam - // move camera down to move under lower ceilings - newsubsec = R_IsPointInSubsector(((mo->x>>FRACBITS) + (thiscam->x>>FRACBITS))<<(FRACBITS-1), ((mo->y>>FRACBITS) + (thiscam->y>>FRACBITS))<<(FRACBITS-1)); - - if (!newsubsec) - newsubsec = thiscam->subsector; - - if (newsubsec) - { - fixed_t myfloorz, myceilingz; - fixed_t midz = thiscam->z + (thiscam->z - mo->z)/2; - fixed_t midx = ((mo->x>>FRACBITS) + (thiscam->x>>FRACBITS))<<(FRACBITS-1); - fixed_t midy = ((mo->y>>FRACBITS) + (thiscam->y>>FRACBITS))<<(FRACBITS-1); - - // Cameras use the heightsec's heights rather then the actual sector heights. - // If you can see through it, why not move the camera through it too? - if (newsubsec->sector->camsec >= 0) - { - myfloorz = sectors[newsubsec->sector->camsec].floorheight; - myceilingz = sectors[newsubsec->sector->camsec].ceilingheight; - } - else if (newsubsec->sector->heightsec >= 0) - { - myfloorz = sectors[newsubsec->sector->heightsec].floorheight; - myceilingz = sectors[newsubsec->sector->heightsec].ceilingheight; - } - else - { - myfloorz = P_CameraGetFloorZ(thiscam, newsubsec->sector, midx, midy, NULL); - myceilingz = P_CameraGetCeilingZ(thiscam, newsubsec->sector, midx, midy, NULL); - } - - // Check list of fake floors and see if floorz/ceilingz need to be altered. - if (newsubsec->sector->ffloors) - { - ffloor_t *rover; - fixed_t delta1, delta2; - INT32 thingtop = midz + thiscam->height; - - for (rover = newsubsec->sector->ffloors; rover; rover = rover->next) - { - fixed_t topheight, bottomheight; - if (!(rover->flags & FF_BLOCKOTHERS) || !(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERALL) || GETSECSPECIAL(rover->master->frontsector->special, 4) == 12) - continue; - - topheight = P_CameraGetFOFTopZ(thiscam, newsubsec->sector, rover, midx, midy, NULL); - bottomheight = P_CameraGetFOFBottomZ(thiscam, newsubsec->sector, rover, midx, midy, NULL); - - delta1 = midz - (bottomheight - + ((topheight - bottomheight)/2)); - delta2 = thingtop - (bottomheight - + ((topheight - bottomheight)/2)); - if (topheight > myfloorz && abs(delta1) < abs(delta2)) - myfloorz = topheight; - if (bottomheight < myceilingz && abs(delta1) >= abs(delta2)) - myceilingz = bottomheight; - } - } - - // Check polyobjects and see if floorz/ceilingz need to be altered - { - INT32 xl, xh, yl, yh, bx, by; - validcount++; - - xl = (unsigned)(tmbbox[BOXLEFT] - bmaporgx)>>MAPBLOCKSHIFT; - xh = (unsigned)(tmbbox[BOXRIGHT] - bmaporgx)>>MAPBLOCKSHIFT; - yl = (unsigned)(tmbbox[BOXBOTTOM] - bmaporgy)>>MAPBLOCKSHIFT; - yh = (unsigned)(tmbbox[BOXTOP] - bmaporgy)>>MAPBLOCKSHIFT; - - BMBOUNDFIX(xl, xh, yl, yh); - - for (by = yl; by <= yh; by++) - for (bx = xl; bx <= xh; bx++) - { - INT32 offset; - polymaplink_t *plink; // haleyjd 02/22/06 - - if (bx < 0 || by < 0 || bx >= bmapwidth || by >= bmapheight) - continue; - - offset = by*bmapwidth + bx; - - // haleyjd 02/22/06: consider polyobject lines - plink = polyblocklinks[offset]; - - while (plink) - { - polyobj_t *po = plink->po; - - if (po->validcount != validcount) // if polyobj hasn't been checked - { - sector_t *polysec; - fixed_t delta1, delta2, thingtop; - fixed_t polytop, polybottom; - - po->validcount = validcount; - - if (!P_PointInsidePolyobj(po, x, y) || !(po->flags & POF_SOLID)) - { - plink = (polymaplink_t *)(plink->link.next); - continue; - } - - // We're inside it! Yess... - polysec = po->lines[0]->backsector; - - if (GETSECSPECIAL(polysec->special, 4) == 12) - { // Camera noclip polyobj. - plink = (polymaplink_t *)(plink->link.next); - continue; - } - - if (po->flags & POF_CLIPPLANES) - { - polytop = polysec->ceilingheight; - polybottom = polysec->floorheight; - } - else - { - polytop = INT32_MAX; - polybottom = INT32_MIN; - } - - thingtop = midz + thiscam->height; - delta1 = midz - (polybottom + ((polytop - polybottom)/2)); - delta2 = thingtop - (polybottom + ((polytop - polybottom)/2)); - - if (polytop > myfloorz && abs(delta1) < abs(delta2)) - myfloorz = polytop; - - if (polybottom < myceilingz && abs(delta1) >= abs(delta2)) - myceilingz = polybottom; - } - plink = (polymaplink_t *)(plink->link.next); - } - } - } - - // crushed camera - if (myceilingz <= myfloorz + thiscam->height && !resetcalled && !cameranoclip) - { - P_ResetCamera(player, thiscam); - return true; - } - - // camera fit? - if (myceilingz != myfloorz - && myceilingz - thiscam->height < z) - { - z = myceilingz - thiscam->height-FixedMul(11*FRACUNIT, mo->scale); - // is the camera fit is there own sector - } - - // Make the camera a tad smarter with 3d floors - if (newsubsec->sector->ffloors && !cameranoclip) - { - ffloor_t *rover; - - for (rover = newsubsec->sector->ffloors; rover; rover = rover->next) - { - fixed_t topheight, bottomheight; - if ((rover->flags & FF_BLOCKOTHERS) && (rover->flags & FF_RENDERALL) && (rover->flags & FF_EXISTS) && GETSECSPECIAL(rover->master->frontsector->special, 4) == 12) - { - topheight = P_CameraGetFOFTopZ(thiscam, newsubsec->sector, rover, midx, midy, NULL); - bottomheight = P_CameraGetFOFBottomZ(thiscam, newsubsec->sector, rover, midx, midy, NULL); - - if (bottomheight - thiscam->height < z - && midz < bottomheight) - z = bottomheight - thiscam->height-FixedMul(11*FRACUNIT, mo->scale); - - else if (topheight + thiscam->height > z - && midz > topheight) - z = topheight; - - if ((mo->z >= topheight && midz < bottomheight) - || ((mo->z < bottomheight && mo->z+mo->height < topheight) && midz >= topheight)) - { - // Can't see - if (!resetcalled) - P_ResetCamera(player, thiscam); - return true; - } - } - } - } - } - - if (thiscam->z < thiscam->floorz && !cameranoclip) - thiscam->z = thiscam->floorz; + if (P_CheckNoclipCameraPosition(player, thiscam, x, y, z, resetcalled)) + return true; #endif // NOCLIPCAM // point viewed by the camera From e105d8f51eae21b711202ecbdb42a8d42b134e68 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 3 Jan 2025 15:54:44 +0100 Subject: [PATCH 71/99] apparently this is slower for everything but rendering --- src/d_clisrv.c | 2 +- src/hardware/hw_main.c | 2 +- src/hardware/hw_portal.c | 2 +- src/p_mobj.c | 4 ++-- src/p_setup.c | 4 ++-- src/p_user.c | 4 ++-- src/r_fps.c | 2 +- src/r_main.h | 11 ----------- src/s_sound.c | 4 ++-- 9 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index e6cc26690..af6a82289 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1959,7 +1959,7 @@ static void CL_ReloadReceivedSavegame(void) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - camera[i].subsector = R_PointInSubsectorFast(camera[i].x, camera[i].y); + camera[i].subsector = R_PointInSubsector(camera[i].x, camera[i].y); } cl_redownloadinggamestate = false; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 3d7fbbd50..0c2de5227 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3172,7 +3172,7 @@ static gl_vissprite_t *HWR_NewVisSprite(void) // Finds a floor through which light does not pass. static fixed_t HWR_OpaqueFloorAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t height) { - const sector_t *sec = R_PointInSubsectorFast(x, y)->sector; + const sector_t *sec = R_PointInSubsector(x, y)->sector; fixed_t floorz = sec->floorheight; if (sec->ffloors) diff --git a/src/hardware/hw_portal.c b/src/hardware/hw_portal.c index f26e71331..27d77af2e 100644 --- a/src/hardware/hw_portal.c +++ b/src/hardware/hw_portal.c @@ -132,7 +132,7 @@ void HWR_PortalFrame(gl_portal_t* portal) { portalclipline = NULL; portalcullsector = NULL; - viewsector = R_PointInSubsectorFast(viewx, viewy)->sector; + viewsector = R_PointInSubsector(viewx, viewy)->sector; } } diff --git a/src/p_mobj.c b/src/p_mobj.c index 03e7e9f99..4a7a34918 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3337,7 +3337,7 @@ boolean P_CameraThinker(player_t *player, camera_t *thiscam, boolean resetcalled if (!itsatwodlevel) P_CheckCameraPosition(thiscam->x, thiscam->y, thiscam); - thiscam->subsector = R_PointInSubsectorFast(thiscam->x, thiscam->y); + thiscam->subsector = R_PointInSubsector(thiscam->x, thiscam->y); thiscam->floorz = tmfloorz; thiscam->ceilingz = tmceilingz; @@ -10415,7 +10415,7 @@ void P_PrecipitationEffects(void) for (y = yl; y <= yh; y += RADIUSSTEP) for (x = xl; x <= xh; x += RADIUSSTEP) { - if (R_PointInSubsectorFast((fixed_t)x, (fixed_t)y)->sector->ceilingpic != skyflatnum) // Found the outdoors! + if (R_PointInSubsector((fixed_t)x, (fixed_t)y)->sector->ceilingpic != skyflatnum) // Found the outdoors! continue; newdist = S_CalculateSoundDistance(players[displayplayers[0]].mo->x, players[displayplayers[0]].mo->y, 0, (fixed_t)x, (fixed_t)y, 0); diff --git a/src/p_setup.c b/src/p_setup.c index 0e7f89dcf..477b805db 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2437,7 +2437,7 @@ static void P_SetupCamera(UINT8 pnum, camera_t *cam) cam->y = players[pnum].mo->y; cam->z = players[pnum].mo->z; cam->angle = players[pnum].mo->angle; - cam->subsector = R_PointInSubsectorFast(cam->x, cam->y); // make sure camera has a subsector set -- Monster Iestyn (12/11/18) + cam->subsector = R_PointInSubsector(cam->x, cam->y); // make sure camera has a subsector set -- Monster Iestyn (12/11/18) } else { @@ -2462,7 +2462,7 @@ static void P_SetupCamera(UINT8 pnum, camera_t *cam) cam->y = thing->y; cam->z = thing->z; cam->angle = FixedAngle((fixed_t)thing->angle << FRACBITS); - cam->subsector = R_PointInSubsectorFast(cam->x, cam->y); // make sure camera has a subsector set -- Monster Iestyn (12/11/18) + cam->subsector = R_PointInSubsector(cam->x, cam->y); // make sure camera has a subsector set -- Monster Iestyn (12/11/18) } } diff --git a/src/p_user.c b/src/p_user.c index 51900717e..0e587e659 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3348,7 +3348,7 @@ void P_DemoCameraMovement(camera_t *cam) democam.soundmobj = awayviewmobj_hack; // update subsector to avoid crashes; - cam->subsector = R_PointInSubsectorFast(cam->x, cam->y); + cam->subsector = R_PointInSubsector(cam->x, cam->y); } void P_ResetCamera(player_t *player, camera_t *thiscam) @@ -3390,7 +3390,7 @@ void P_ResetCamera(player_t *player, camera_t *thiscam) thiscam->relativex = 0; - thiscam->subsector = R_PointInSubsectorFast(thiscam->x,thiscam->y); + thiscam->subsector = R_PointInSubsector(thiscam->x,thiscam->y); thiscam->radius = 20*FRACUNIT; thiscam->height = 16*FRACUNIT; diff --git a/src/r_fps.c b/src/r_fps.c index b861dea56..92eb37a32 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -198,7 +198,7 @@ void R_InterpolateView(fixed_t frac, boolean forceinvalid) viewcos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); viewplayer = newview->player; - viewsector = R_PointInSubsectorFast(viewx, viewy)->sector; + viewsector = R_PointInSubsector(viewx, viewy)->sector; R_SetupFreelook(); } diff --git a/src/r_main.h b/src/r_main.h index 523e924d5..c66c9bf55 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -140,17 +140,6 @@ FUNCINLINE static ATTRINLINE subsector_t *R_PointInSubsector(fixed_t x, fixed_t return &subsectors[nodenum & ~NF_SUBSECTOR]; } -// uses R_PointOnSideFast -// SHOULD NOT BE USED FOR ANYTHING GAMEPLAY RELATED!! -FUNCINLINE static ATTRINLINE subsector_t *R_PointInSubsectorFast(fixed_t x, fixed_t y) -{ - size_t nodenum = numnodes-1; - - while (!(nodenum & NF_SUBSECTOR)) - nodenum = nodes[nodenum].children[R_PointOnSideFast(x, y, nodes+nodenum)]; - - return &subsectors[nodenum & ~NF_SUBSECTOR]; -} #define R_PointToDist(x, y) R_PointToDist2(viewx, viewy, x, y) #define R_PointToDist2(px2, py2, px1, py1) FixedHypot((px1) - (px2), (py1) - (py2)) diff --git a/src/s_sound.c b/src/s_sound.c index 06f6be1eb..4181d57d4 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -962,7 +962,7 @@ boolean S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, INT32 INT64 x, y, yl, yh, xl, xh; fixed_t newdist; - if (R_PointInSubsectorFast(listensource.x, listensource.y)->sector->ceilingpic == skyflatnum) + if (R_PointInSubsector(listensource.x, listensource.y)->sector->ceilingpic == skyflatnum) approx_dist = 0; else { @@ -975,7 +975,7 @@ boolean S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, INT32 for (y = yl; y <= yh; y += FRACUNIT*64) for (x = xl; x <= xh; x += FRACUNIT*64) { - if (R_PointInSubsectorFast(x, y)->sector->ceilingpic == skyflatnum) + if (R_PointInSubsector(x, y)->sector->ceilingpic == skyflatnum) { // Found the outdoors! newdist = S_CalculateSoundDistance(listensource.x, listensource.y, 0, x, y, 0); From 8b94aded16a095efd3d58b42ca5bd597b2d88646 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 2 Jan 2025 22:18:52 +0100 Subject: [PATCH 72/99] smol fix --- src/p_mobj.c | 3 +++ src/r_main.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 4a7a34918..30bc10c9a 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3568,11 +3568,14 @@ static void CalculatePrecipFloor(precipmobj_t *mobj) { // recalculate floorz each time const sector_t *mobjsecsubsec; + if (mobj && mobj->subsector && mobj->subsector->sector) mobjsecsubsec = mobj->subsector->sector; else return; + mobj->floorz = P_GetSectorFloorZAt(mobjsecsubsec, mobj->x, mobj->y); + if (mobjsecsubsec->ffloors) { ffloor_t *rover; diff --git a/src/r_main.h b/src/r_main.h index c66c9bf55..bb407ab4f 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -104,7 +104,7 @@ FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSide(fixed_t x, fixed_t y, FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSideFast(fixed_t x, fixed_t y, const node_t *node) { // use cross product to determine side quickly - return ((INT64)y - node->y) * node->dx - ((INT64)x - node->x) * node->dy > 0; + return ((((INT64)y - node->y) * node->dx - ((INT64)x - node->x) * node->dy) >= 0); } FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSegSide(fixed_t x, fixed_t y, const seg_t *line) @@ -115,7 +115,7 @@ FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSegSide(fixed_t x, fixed_t fixed_t ldy = line->v2->y - ly; // use cross product to determine side quickly - return ((INT64)y - ly) * ldx - ((INT64)x - lx) * ldy > 0; + return ((((INT64)y - ly) * ldx - ((INT64)x - lx) * ldy) >= 0); } angle_t R_PointToAngle(fixed_t x, fixed_t y); From c5b70ccc4aae9880768310f40263dac85be52a66 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 3 Jan 2025 15:51:38 +0100 Subject: [PATCH 73/99] do NOT repeatedly call M_Responder!! "thread safety" or smth also put stuff into two seperate functions, since i started hating nesting --- src/d_main.c | 71 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index f9e1ca27e..ac4326f65 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -165,6 +165,48 @@ UINT8 ctrldown = 0; // 0x1 left, 0x2 right UINT8 altdown = 0; // 0x1 left, 0x2 right boolean capslock = 0; // gee i wonder what this does. +static void D_PadScrollInput(int input) +{ + event_t myev = {0, 0, 0, 0}; + myev.type = ev_keydown; + myev.data1 = input; + D_PostEvent(&myev); // put into eventlist +} + +#define SCROLLDELAY 19 // TICRATE * ( (k+2) (1 - [wz + h + j - q]^2 - [(gk + 2g + k + 1)(h + j) + h - z]^2 - [16(k + 1)^3(k + 2)(n + 1)^2 + 1 - f^2]^2 calculated by my butt + +// this is absolutely awful and i hate it lmao +// but le hAx0r to make dpad also be able to scroll in the menu +static void D_GamePadMenuScrollTicker(void) +{ + static SINT8 menuInputDelayTimer = 0; + int key = 0; // butt-on output + + // wish i had a switch ono + if (DPADUPSCROLL) + key = KEY_UPARROW; + else if (DPADDOWNSCROLL) + key = KEY_DOWNARROW; + else if (DPADLEFTSCROLL) + key = KEY_LEFTARROW; + else if (DPADRIGHTSCROLL) + key = KEY_RIGHTARROW; + + if (key) + { + if (menuInputDelayTimer < SCROLLDELAY) + menuInputDelayTimer++; + + if (menuInputDelayTimer == SCROLLDELAY) + D_PadScrollInput(key); + } + else + { + menuInputDelayTimer = 0; + } +} +#undef SCROLLDELAY + static inline void D_DeviceLEDTick(void) { UINT8 i; @@ -651,7 +693,6 @@ static boolean D_Display(void) // ========================================================================= tic_t rendergametic; -static SINT8 menuInputDelayTimer = 0; void D_SRB2Loop(void) { @@ -774,35 +815,11 @@ void D_SRB2Loop(void) doDisplay = true; } -#define DPADSCROLLINPUT(INPUT)\ - {\ - myev.data1 = INPUT;\ - M_Responder(&myev);\ - } // this is absolutely awful and i hate it lmao - if (menuactive && (DPADUPSCROLL || DPADDOWNSCROLL || DPADLEFTSCROLL || DPADRIGHTSCROLL)) + if (menuactive) { - event_t myev; - myev.type = ev_keydown; - - if (menuInputDelayTimer < 19) - menuInputDelayTimer++; - - if (menuInputDelayTimer == 19) // TICRATE * ( (k+2) (1 - [wz + h + j - q]^2 - [(gk + 2g + k + 1)(h + j) + h - z]^2 - [16(k + 1)^3(k + 2)(n + 1)^2 + 1 - f^2]^2 calculated by my butt - { - if (DPADUPSCROLL) - DPADSCROLLINPUT(KEY_UPARROW) - else if (DPADDOWNSCROLL) - DPADSCROLLINPUT(KEY_DOWNARROW) - else if (DPADLEFTSCROLL) - DPADSCROLLINPUT(KEY_LEFTARROW) - else if (DPADRIGHTSCROLL) - DPADSCROLLINPUT(KEY_RIGHTARROW) - } + D_GamePadMenuScrollTicker(); } - else - menuInputDelayTimer = 0; -#undef DPADSCROLLINPUT D_DeviceLEDTick(); } From b69bb8500318f4c3ed0387c685a9a1b90cb7a334 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 3 Jan 2025 20:09:28 +0100 Subject: [PATCH 74/99] remove redundant stuff can just set this all the time, its only used when menu is active anyways so it doesent matter if we set it --- src/d_main.c | 5 ++--- src/m_menu.c | 26 ++++++++------------------ 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index ac4326f65..94fe8792d 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -165,7 +165,7 @@ UINT8 ctrldown = 0; // 0x1 left, 0x2 right UINT8 altdown = 0; // 0x1 left, 0x2 right boolean capslock = 0; // gee i wonder what this does. -static void D_PadScrollInput(int input) +static void D_PadMenuScrollInput(int input) { event_t myev = {0, 0, 0, 0}; myev.type = ev_keydown; @@ -198,7 +198,7 @@ static void D_GamePadMenuScrollTicker(void) menuInputDelayTimer++; if (menuInputDelayTimer == SCROLLDELAY) - D_PadScrollInput(key); + D_PadMenuScrollInput(key); } else { @@ -815,7 +815,6 @@ void D_SRB2Loop(void) doDisplay = true; } - // this is absolutely awful and i hate it lmao if (menuactive) { D_GamePadMenuScrollTicker(); diff --git a/src/m_menu.c b/src/m_menu.c index 03eeef210..6272f57fa 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3675,40 +3675,28 @@ boolean M_Responder(event_t *ev) break; case KEY_HAT1: ch = KEY_UPARROW; + DPADUPSCROLL = true; break; case KEY_HAT1 + 1: ch = KEY_DOWNARROW; + DPADDOWNSCROLL = true; break; case KEY_HAT1 + 2: ch = KEY_LEFTARROW; + DPADLEFTSCROLL = true; break; case KEY_HAT1 + 3: ch = KEY_RIGHTARROW; + DPADRIGHTSCROLL = true; break; } if (menuactive) { - switch (ev->data1) // if you pressed it set those to true - { - case KEY_HAT1: - DPADUPSCROLL = true; - break; - case KEY_HAT1 + 1: - DPADDOWNSCROLL = true; - break; - case KEY_HAT1 + 2: - DPADLEFTSCROLL = true; - break; - case KEY_HAT1 + 3: - DPADRIGHTSCROLL = true; - break; - } - if (currentMenu == &MISC_ChangeLevelDef || currentMenu == &MP_OfflineServerDef || currentMenu == &MP_ServerDef) { - if (ev->data1 == gamecontrol[gc_fire][0] - || ev->data1 == gamecontrol[gc_fire][1]) + if (ch == gamecontrol[gc_fire][0] + || ch == gamecontrol[gc_fire][1]) { COM_ImmedExecute("add kartencore 1"); } @@ -4383,10 +4371,12 @@ void M_StartControlPanel(void) menuactive = true; + // reset those just in case the game missed the keyup event DPADUPSCROLL = false; DPADDOWNSCROLL = false; DPADLEFTSCROLL = false; DPADRIGHTSCROLL = false; + // if (demo.playback) { From 98db1a57576d0875babb70ad04215507b28a4bca Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Jan 2025 00:32:23 +0100 Subject: [PATCH 75/99] Further improve sleep accuracy on UNIX systems hanichad https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2583 --- src/sdl/i_system.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 882535203..102f1b162 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2121,16 +2121,24 @@ void I_Sleep(UINT32 ms) void I_SleepDuration(precise_t duration) { -#if defined(__linux__) || defined(__FreeBSD__) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__HAIKU__) UINT64 precision = I_GetPrecisePrecision(); - struct timespec ts = { - .tv_sec = duration / precision, - .tv_nsec = duration * 1000000000 / precision % 1000000000, - }; - int status; - do status = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, &ts); - while (status == EINTR); -#else + precise_t dest = I_GetPreciseTime() + duration; + if (duration > 100000) + { + duration -= 100000; // 0.1 ms slack + struct timespec ts = { + .tv_sec = duration / precision, + .tv_nsec = duration * 1000000000 / precision % 1000000000, + }; + int status; + do status = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, &ts); + while (status == EINTR); + } + + // busy-wait the rest + while (((INT64)dest - (INT64)I_GetPreciseTime()) > 0); +#elif defined (MIN_SLEEP_DURATION_MS) UINT64 precision = I_GetPrecisePrecision(); INT32 sleepvalue = cv_sleep.value; UINT64 delaygranularity; @@ -2159,7 +2167,6 @@ void I_SleepDuration(precise_t duration) } // Otherwise, this is a spinloop. - cur = I_GetPreciseTime(); } #endif From 92649a393dbb240866c176173433c4870ee81fdf Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Jan 2025 00:41:41 +0100 Subject: [PATCH 76/99] dont cast "infinity" to int lel --- src/d_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_main.c b/src/d_main.c index 94fe8792d..9bbaa6017 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -743,7 +743,7 @@ void D_SRB2Loop(void) { // Casting the return value of a function is bad practice (apparently) - double budget = round((1.0 / R_GetFramerateCap()) * I_GetPrecisePrecision()); + double budget = ((R_GetFramerateCap() == 0) ? 0.0 : round((1.0 / R_GetFramerateCap()) * I_GetPrecisePrecision())); capbudget = (precise_t) budget; } From 8ff5cc7cbb21af85ee60c6779df4f40b7cafb67e Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Jan 2025 15:11:09 +0100 Subject: [PATCH 77/99] --------- --- src/k_kart.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index a6aa76e4d..70410e1c3 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -8179,11 +8179,7 @@ void K_drawKartTimestamp(tic_t drawtime, INT32 TX, INT32 TY, INT16 emblemmap, UI ; else if (mode && !drawtime) { - // apostrophe location _'__ __ - V_DrawKartString(TX+24, TY+3, splitflags, va("'")); - - // quotation mark location _ __"__ - V_DrawKartString(TX+60, TY+3, splitflags, va("\"")); + V_DrawKartString(TX, TY+3, splitflags, va("--'--\"--")); } else { From 7ca2051f8458d14ecdf44b76b67837c797834eee Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Jan 2025 17:41:02 +0100 Subject: [PATCH 78/99] Adjust slack based on precision https://git.do.srb2.org/STJr/SRB2/-/commit/d20552c49d9fd6a2075ebd7d46b0b133c69f1dbe?merge_request_iid=2583 --- src/sdl/i_system.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 102f1b162..86e818901 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2124,9 +2124,9 @@ void I_SleepDuration(precise_t duration) #if defined(__linux__) || defined(__FreeBSD__) || defined(__HAIKU__) UINT64 precision = I_GetPrecisePrecision(); precise_t dest = I_GetPreciseTime() + duration; - if (duration > 100000) + if (duration * 100000 / precision > 1) { - duration -= 100000; // 0.1 ms slack + duration -= (precision / 10000); // 0.1 ms slack struct timespec ts = { .tv_sec = duration / precision, .tv_nsec = duration * 1000000000 / precision % 1000000000, From 718fe7e8ae86bac9d1c89a987cd422daaebb6086 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Jan 2025 20:12:19 +0100 Subject: [PATCH 79/99] slight slep optimization https://git.do.srb2.org/STJr/SRB2/-/commit/1da55066d43ed6a0cb666999c20316bef463024b?merge_request_iid=2583 --- src/sdl/i_system.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 86e818901..2c8b59ce1 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2124,9 +2124,10 @@ void I_SleepDuration(precise_t duration) #if defined(__linux__) || defined(__FreeBSD__) || defined(__HAIKU__) UINT64 precision = I_GetPrecisePrecision(); precise_t dest = I_GetPreciseTime() + duration; - if (duration * 100000 / precision > 1) + precise_t slack = (precision / 10000); // 0.1 ms slack + if (duration > slack) { - duration -= (precision / 10000); // 0.1 ms slack + duration -= slack; struct timespec ts = { .tv_sec = duration / precision, .tv_nsec = duration * 1000000000 / precision % 1000000000, From 890779713ac34ebd469fae41924cda18543ece5e Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Jan 2025 21:23:45 +0100 Subject: [PATCH 80/99] turn off any active menus when using demo play commands --- src/d_netcmd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index a6943fe6a..dfd8eda5e 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2435,6 +2435,9 @@ static void Command_Playdemo_f(void) return; } + // turn off any open menus + M_ClearMenus(true); + // disconnect from server here? if (demo.playback) G_StopDemo(); @@ -2480,6 +2483,9 @@ static void Command_Timedemo_f(void) return; } + // turn off any open menus + M_ClearMenus(true); + // disconnect from server here? if (demo.playback) G_StopDemo(); From e796f7e81fa91e9ee95ff4819436d22ae0af2c6e Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Jan 2025 21:24:48 +0100 Subject: [PATCH 81/99] thats not timedemo lel --- src/d_netcmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index dfd8eda5e..eaec437fe 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2431,7 +2431,7 @@ static void Command_Playdemo_f(void) if (!demo.playback && gamestate == GS_LEVEL) // special case: allow starting another demo while watching a demo { - CONS_Printf(M_GetText("You can't time a demo while in a game.\n")); + CONS_Printf(M_GetText("You can't play a demo while in a game.\n")); return; } From 7177b396e05ab3a94045b3abca05b55b0c8eeb7d Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Jan 2025 23:02:27 +0100 Subject: [PATCH 82/99] any of those may be NULL in MakePatch no idea but this crap keeps crashing in some other place every single time i add a check somewhere else --- src/hardware/hw_cache.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index ad140c025..65e120002 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -410,6 +410,16 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe // patch may be NULL if glMipmap has been initialised already and makebitmap is false void HWR_MakePatch (patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipmap, boolean makebitmap) { + if (glMipmap == NULL) + return; + + if (patch == NULL || glPatch == NULL) + { + Z_Free(glMipmap->data); + glMipmap->data = NULL; + return; + } + // don't do it twice (like a cache) if (glMipmap->width == 0) { From afa66d0418681237d2f32f0b9944cd2490ff101c Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 6 Jan 2025 19:01:58 +0100 Subject: [PATCH 83/99] double the slack for slep --- src/sdl/i_system.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 2c8b59ce1..ff1651c3b 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2124,7 +2124,7 @@ void I_SleepDuration(precise_t duration) #if defined(__linux__) || defined(__FreeBSD__) || defined(__HAIKU__) UINT64 precision = I_GetPrecisePrecision(); precise_t dest = I_GetPreciseTime() + duration; - precise_t slack = (precision / 10000); // 0.1 ms slack + precise_t slack = (precision / 5000); // 0.2 ms slack if (duration > slack) { duration -= slack; From dbb5c1482b59550a44792b2a74478e26cf26bc57 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 6 Jan 2025 19:49:29 +0100 Subject: [PATCH 84/99] add a little extra safety here ig this crashed on levelload once so idk maybe player was null ig --- src/d_main.c | 4 ++-- src/r_main.c | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 9bbaa6017..95f7c895d 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -485,11 +485,11 @@ static boolean D_Display(void) { PS_START_TIMING(ps_rendercalltime); - R_ApplyLevelInterpolators(R_UsingFrameInterpolation() ? rendertimefrac : FRACUNIT); + R_ApplyLevelInterpolators(rendertimefrac); for (i = 0; i <= splitscreen; i++) { - if (players[displayplayers[i]].mo || players[displayplayers[i]].playerstate == PST_DEAD) + if (!P_MobjWasRemoved(players[displayplayers[i]].mo) || players[displayplayers[i]].playerstate == PST_DEAD) { viewssnum = i; diff --git a/src/r_main.c b/src/r_main.c index 9541fef41..511bbe293 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1060,11 +1060,13 @@ subsector_t *R_IsPointInSubsector(fixed_t x, fixed_t y) mobj_t *viewmobj; -static void -R_SetupCommonFrame -( player_t * player, - subsector_t * subsector) +static void R_SetupCommonFrame(player_t * player, subsector_t * subsector) { + if (!player) + { + return; + } + newview->player = player; newview->x += quake.x; @@ -1073,7 +1075,7 @@ R_SetupCommonFrame newview->roll = R_ViewRollAngle(player); - if (subsector) + if (subsector != NULL) newview->sector = subsector->sector; else newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; @@ -1214,7 +1216,7 @@ void R_SetupFrame(int s, boolean skybox) { player_t *player = &players[displayplayers[s]]; camera_t *thiscam = &camera[s]; - boolean chasecam = (cv_chasecam[s].value != 0); + boolean chasecam = (cv_chasecam[s].value); subsector_t * subsector = NULL; R_SetViewContext(VIEWCONTEXT_PLAYER1 + s); @@ -1263,7 +1265,10 @@ void R_SetupFrame(int s, boolean skybox) newview->y = thiscam->y; newview->z = thiscam->z + (thiscam->height>>1); - R_SetupCommonFrame(player, thiscam->subsector); + if (thiscam != NULL) + subsector = thiscam->subsector; + + R_SetupCommonFrame(player, subsector); } else // use the player's eyes view { From ce31ceda651cdefbee9aaebefcbc7d5bf494eeaf Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 7 Jan 2025 14:52:19 +0300 Subject: [PATCH 85/99] If available, add map title into crash log --- src/sdl/i_system.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index ff1651c3b..d3de6f6b0 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -178,6 +178,7 @@ static char returnWadPath[256]; #include "../d_net.h" #include "../g_game.h" #include "../filesrch.h" +#include "../z_zone.h" // Z_Free #include "endtxt.h" #include "sdlmain.h" @@ -344,7 +345,17 @@ static void write_backtrace(bt_crash_reason_t reason) fprintf(out, "Compiled: %s %s, commit %s, branch %s\n", compdate, comptime, comprevision, compbranch); if (gamestate == GS_LEVEL) - fprintf(out, "Game map: %s\n", G_BuildMapName(gamemap)); + { + char *title = G_BuildMapTitle(gamemap); + + if (title) + { + fprintf(out, "Game map: %s (%s)\n", title, G_BuildMapName(gamemap)); + Z_Free(title); + } + else + fprintf(out, "Game map: %s\n", G_BuildMapName(gamemap)); + } fprintf(out, "Time of crash: %s\n", asctime(timeinfo)); From 864d747e3bbdcb6df62992ec92ed3b2f15e6cded Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Jan 2025 19:49:36 +0100 Subject: [PATCH 86/99] check if subsector has sector before assigning --- src/r_main.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 511bbe293..2ccd926af 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1062,11 +1062,6 @@ mobj_t *viewmobj; static void R_SetupCommonFrame(player_t * player, subsector_t * subsector) { - if (!player) - { - return; - } - newview->player = player; newview->x += quake.x; @@ -1075,7 +1070,7 @@ static void R_SetupCommonFrame(player_t * player, subsector_t * subsector) newview->roll = R_ViewRollAngle(player); - if (subsector != NULL) + if (subsector && subsector->sector) newview->sector = subsector->sector; else newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; From 5c5a5e200e1e8b3c68ef8a33efdde53585bdc2bd Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Jan 2025 20:16:28 +0100 Subject: [PATCH 87/99] fix fbo crap once again --- src/sdl/i_video.c | 5 ----- src/sdl/ogl_sdl.c | 3 ++- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 7af6455fe..609afc30a 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -707,11 +707,6 @@ static void I_CheckDesktopRes(void) int currentDisplayIndex = -1; SDL_DisplayMode curmode; - if (desktopwidth == vid.width && desktopheight == vid.height) - { - return; - } - desktopwidth = 0; desktopheight = 0; diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 9093f9a18..8a3a0eabb 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -289,7 +289,8 @@ void OglSdlFinishUpdate(boolean waitvbl) #if defined (__unix__) #ifdef USE_FBO_OGL - xwaylandcrap = false; + if (loaded_config == true) + xwaylandcrap = false; #endif #endif } From c0d4599a35196a691508f3476ee663c89c431689 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Jan 2025 23:48:41 +0100 Subject: [PATCH 88/99] TEST: revert sleep stuff for now dedi may sometimes get stuck here somehow --- src/sdl/i_system.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index d3de6f6b0..7302a12e1 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2134,22 +2134,13 @@ void I_SleepDuration(precise_t duration) { #if defined(__linux__) || defined(__FreeBSD__) || defined(__HAIKU__) UINT64 precision = I_GetPrecisePrecision(); - precise_t dest = I_GetPreciseTime() + duration; - precise_t slack = (precision / 5000); // 0.2 ms slack - if (duration > slack) - { - duration -= slack; - struct timespec ts = { - .tv_sec = duration / precision, - .tv_nsec = duration * 1000000000 / precision % 1000000000, - }; - int status; - do status = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, &ts); - while (status == EINTR); - } - - // busy-wait the rest - while (((INT64)dest - (INT64)I_GetPreciseTime()) > 0); + struct timespec ts = { + .tv_sec = duration / precision, + .tv_nsec = duration * 1000000000 / precision % 1000000000, + }; + int status; + do status = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, &ts); + while (status == EINTR); #elif defined (MIN_SLEEP_DURATION_MS) UINT64 precision = I_GetPrecisePrecision(); INT32 sleepvalue = cv_sleep.value; From ee8fd22f3659498747dd03b3c4f40705c8ea1e19 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 8 Jan 2025 00:13:27 +0100 Subject: [PATCH 89/99] oops fix software lel --- src/r_things.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 9bdb9ea67..1cca7bbed 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -623,7 +623,6 @@ void R_DrawMaskedColumn(column_t *column) { dc_source = (UINT8 *)column + 3; dc_sourcelength = column->length; - dc_texheight = column->length; dc_texturemid = basetexturemid - (topdelta<length); dc_sourcelength = column->length; - dc_texheight = column->length; for (s = (UINT8 *)column+2+column->length, d = dc_source; d < dc_source+column->length; --s) *d++ = *s; From bb91d8e1e33acea5312536d27e4fffbb0977a099 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 8 Jan 2025 01:33:37 +0100 Subject: [PATCH 90/99] dont rumble in freecam + player fix --- src/p_tick.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/p_tick.c b/src/p_tick.c index af4facd53..ec77d50cf 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -364,6 +364,8 @@ static void P_DeviceRumbleTick(void) UINT16 low = 0; UINT16 high = 0; + player_t *player = ((i == 0) ? &players[consoleplayer] : &players[displayplayers[i]]); + if (!cv_usejoystick[i].value) { continue; @@ -374,14 +376,12 @@ static void P_DeviceRumbleTick(void) continue; } - player_t *player = &players[displayplayers[i]]; - - if (!P_IsLocalPlayer(player)) + if (player->spectator) { continue; } - if (!playeringame[displayplayers[i]] || player->spectator) + if (camera[i].freecam) { continue; } From f74cd97c4b1567125e29e2465bb7e1790e9aef61 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Jan 2025 22:47:35 +0100 Subject: [PATCH 91/99] clean up this mess a little --- src/r_patch.c | 574 ++++++++++++-------------------------------------- src/r_patch.h | 6 +- 2 files changed, 131 insertions(+), 449 deletions(-) diff --git a/src/r_patch.c b/src/r_patch.c index 50dda0c5f..75bd3361c 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -28,425 +28,6 @@ #include "hardware/hw_glob.h" #endif -static unsigned char imgbuf[1<<26]; - -// -// R_CheckIfPatch -// -// Returns true if the lump is a valid patch. -// -boolean R_CheckIfPatch(lumpnum_t lump) -{ - size_t size; - INT16 width, height; - patch_t *patch; - boolean result; - - size = W_LumpLength(lump); - - // minimum length of a valid Doom patch - if (size < 13) - return false; - - patch = (patch_t *)W_CacheLumpNum(lump, PU_STATIC); - - width = SHORT(patch->width); - height = SHORT(patch->height); - - result = (height > 0 && height <= 16384 && width > 0 && width <= 16384 && width < (INT16)(size / 4)); - - if (result) - { - // The dimensions seem like they might be valid for a patch, so - // check the column directory for extra security. All columns - // must begin after the column directory, and none of them must - // point past the end of the patch. - INT16 x; - - for (x = 0; x < width; x++) - { - UINT32 ofs = LONG(patch->columnofs[x]); - - // Need one byte for an empty column (but there's patches that don't know that!) - if (ofs < (UINT32)width * 4 + 8 || ofs >= (UINT32)size) - { - result = false; - break; - } - } - } - - return result; -} - -// -// R_TextureToFlat -// -// Convert a texture to a flat. -// -void R_TextureToFlat(size_t tex, UINT8 *flat) -{ - texture_t *texture = textures[tex]; - - fixed_t col, ofs; - column_t *column; - UINT8 *desttop, *dest, *deststop; - UINT8 *source; - - // yea - R_CheckTextureCache(tex); - - desttop = flat; - deststop = desttop + (texture->width * texture->height); - - for (col = 0; col < texture->width; col++, desttop++) - { - // no post_t info - if (!texture->holes) - { - column = (column_t *)(R_GetColumn(tex, col)); - source = (UINT8 *)(column); - dest = desttop; - for (ofs = 0; dest < deststop && ofs < texture->height; ofs++) - { - if (source[ofs] != TRANSPARENTPIXEL) - *dest = source[ofs]; - dest += texture->width; - } - } - else - { - INT32 topdelta, prevdelta = -1; - column = (column_t *)((UINT8 *)R_GetColumn(tex, col) - 3); - while (column->topdelta != 0xff) - { - topdelta = column->topdelta; - if (topdelta <= prevdelta) - topdelta += prevdelta; - prevdelta = topdelta; - - dest = desttop + (topdelta * texture->width); - source = (UINT8 *)column + 3; - for (ofs = 0; dest < deststop && ofs < column->length; ofs++) - { - if (source[ofs] != TRANSPARENTPIXEL) - *dest = source[ofs]; - dest += texture->width; - } - column = (column_t *)((UINT8 *)column + column->length + 4); - } - } - } -} - -// -// R_PatchToFlat -// -// Convert a patch to a flat. -// -void R_PatchToFlat(patch_t *patch, UINT8 *flat) -{ - fixed_t col, ofs; - column_t *column; - UINT8 *desttop, *dest, *deststop; - UINT8 *source; - - desttop = flat; - deststop = desttop + (SHORT(patch->width) * SHORT(patch->height)); - - for (col = 0; col < SHORT(patch->width); col++, desttop++) - { - INT32 topdelta, prevdelta = -1; - column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[col])); - - while (column->topdelta != 0xff) - { - topdelta = column->topdelta; - if (topdelta <= prevdelta) - topdelta += prevdelta; - prevdelta = topdelta; - - dest = desttop + (topdelta * SHORT(patch->width)); - source = (UINT8 *)(column) + 3; - for (ofs = 0; dest < deststop && ofs < column->length; ofs++) - { - *dest = source[ofs]; - dest += SHORT(patch->width); - } - column = (column_t *)((UINT8 *)column + column->length + 4); - } - } -} - -// -// R_PatchToMaskedFlat -// -// Convert a patch to a masked flat. -// Now, what is a "masked" flat anyway? -// It means the flat uses two bytes to store image data. -// The upper byte is used to store the transparent pixel, -// and the lower byte stores a palette index. -// -void R_PatchToMaskedFlat(patch_t *patch, UINT16 *raw, boolean flip) -{ - fixed_t col, ofs; - column_t *column; - UINT16 *desttop, *dest, *deststop; - UINT8 *source; - - desttop = raw; - deststop = desttop + (SHORT(patch->width) * SHORT(patch->height)); - - for (col = 0; col < SHORT(patch->width); col++, desttop++) - { - INT32 topdelta, prevdelta = -1; - column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[flip ? (patch->width-1-col) : col])); - while (column->topdelta != 0xff) - { - topdelta = column->topdelta; - if (topdelta <= prevdelta) - topdelta += prevdelta; - prevdelta = topdelta; - dest = desttop + (topdelta * SHORT(patch->width)); - source = (UINT8 *)(column) + 3; - for (ofs = 0; dest < deststop && ofs < column->length; ofs++) - { - *dest = source[ofs]; - dest += SHORT(patch->width); - } - column = (column_t *)((UINT8 *)column + column->length + 4); - } - } -} - -// -// R_FlatToPatch -// -// Convert a flat to a patch. -// -patch_t *R_FlatToPatch(UINT8 *raw, UINT16 width, UINT16 height, UINT16 leftoffset, UINT16 topoffset, size_t *destsize, boolean transparency) -{ - UINT32 x, y; - UINT8 *img; - UINT8 *imgptr = imgbuf; - UINT8 *colpointers, *startofspan; - size_t size = 0; - - if (!raw) - return NULL; - - // Write image size and offset - WRITEINT16(imgptr, width); - WRITEINT16(imgptr, height); - WRITEINT16(imgptr, leftoffset); - WRITEINT16(imgptr, topoffset); - - // Leave placeholder to column pointers - colpointers = imgptr; - imgptr += width*4; - - // Write columns - for (x = 0; x < width; x++) - { - int lastStartY = 0; - int spanSize = 0; - startofspan = NULL; - - // Write column pointer - WRITEINT32(colpointers, imgptr - imgbuf); - - // Write pixels - for (y = 0; y < height; y++) - { - UINT8 paletteIndex = raw[((y * width) + x)]; - boolean opaque = transparency ? (paletteIndex != TRANSPARENTPIXEL) : true; - - // End span if we have a transparent pixel - if (!opaque) - { - if (startofspan) - WRITEUINT8(imgptr, 0); - startofspan = NULL; - continue; - } - - // Start new column if we need to - if (!startofspan || spanSize == 255) - { - int writeY = y; - - // If we reached the span size limit, finish the previous span - if (startofspan) - WRITEUINT8(imgptr, 0); - - if (y > 254) - { - // Make sure we're aligned to 254 - if (lastStartY < 254) - { - WRITEUINT8(imgptr, 254); - WRITEUINT8(imgptr, 0); - imgptr += 2; - lastStartY = 254; - } - - // Write stopgap empty spans if needed - writeY = y - lastStartY; - - while (writeY > 254) - { - WRITEUINT8(imgptr, 254); - WRITEUINT8(imgptr, 0); - imgptr += 2; - writeY -= 254; - } - } - - startofspan = imgptr; - WRITEUINT8(imgptr, writeY); - imgptr += 2; - spanSize = 0; - - lastStartY = y; - } - - // Write the pixel - WRITEUINT8(imgptr, paletteIndex); - spanSize++; - startofspan[1] = spanSize; - } - - if (startofspan) - WRITEUINT8(imgptr, 0); - - WRITEUINT8(imgptr, 0xFF); - } - - size = imgptr-imgbuf; - img = Z_Malloc(size, PU_STATIC, NULL); - memcpy(img, imgbuf, size); - - Z_Free(raw); - - if (destsize != NULL) - *destsize = size; - return (patch_t *)img; -} - -// -// R_MaskedFlatToPatch -// -// Convert a masked flat to a patch. -// Explanation of "masked" flats in R_PatchToMaskedFlat. -// -patch_t *R_MaskedFlatToPatch(UINT16 *raw, UINT16 width, UINT16 height, UINT16 leftoffset, UINT16 topoffset, size_t *destsize) -{ - UINT32 x, y; - UINT8 *img; - UINT8 *imgptr = imgbuf; - UINT8 *colpointers, *startofspan; - size_t size = 0; - - if (!raw) - return NULL; - - // Write image size and offset - WRITEINT16(imgptr, width); - WRITEINT16(imgptr, height); - WRITEINT16(imgptr, leftoffset); - WRITEINT16(imgptr, topoffset); - - // Leave placeholder to column pointers - colpointers = imgptr; - imgptr += width*4; - - // Write columns - for (x = 0; x < width; x++) - { - int lastStartY = 0; - int spanSize = 0; - startofspan = NULL; - - // Write column pointer - WRITEINT32(colpointers, imgptr - imgbuf); - - // Write pixels - for (y = 0; y < height; y++) - { - UINT16 pixel = raw[((y * width) + x)]; - UINT8 paletteIndex = (pixel & 0xFF); - UINT8 opaque = (pixel != 0xFF00); // If 1, we have a pixel - - // End span if we have a transparent pixel - if (!opaque) - { - if (startofspan) - WRITEUINT8(imgptr, 0); - startofspan = NULL; - continue; - } - - // Start new column if we need to - if (!startofspan || spanSize == 255) - { - int writeY = y; - - // If we reached the span size limit, finish the previous span - if (startofspan) - WRITEUINT8(imgptr, 0); - - if (y > 254) - { - // Make sure we're aligned to 254 - if (lastStartY < 254) - { - WRITEUINT8(imgptr, 254); - WRITEUINT8(imgptr, 0); - imgptr += 2; - lastStartY = 254; - } - - // Write stopgap empty spans if needed - writeY = y - lastStartY; - - while (writeY > 254) - { - WRITEUINT8(imgptr, 254); - WRITEUINT8(imgptr, 0); - imgptr += 2; - writeY -= 254; - } - } - - startofspan = imgptr; - WRITEUINT8(imgptr, writeY); - imgptr += 2; - spanSize = 0; - - lastStartY = y; - } - - // Write the pixel - WRITEUINT8(imgptr, paletteIndex); - spanSize++; - startofspan[1] = spanSize; - } - - if (startofspan) - WRITEUINT8(imgptr, 0); - - WRITEUINT8(imgptr, 0xFF); - } - - size = imgptr-imgbuf; - img = Z_Malloc(size, PU_STATIC, NULL); - memcpy(img, imgbuf, size); - - if (destsize != NULL) - *destsize = size; - return (patch_t *)img; -} - // // R_ParseSpriteInfoFrame // @@ -745,6 +326,124 @@ void R_LoadSpriteInfoLumps(UINT16 wadnum, UINT16 numlumps) } } + +static unsigned char imgbuf[1<<26]; + +// +// R_MaskedFlatToPatch +// +// Convert a masked flat to a patch. +// Explanation of "masked" flats in R_PatchToMaskedFlat. +// +void *R_MaskedFlatToPatch(UINT16 *raw, UINT16 width, UINT16 height, UINT16 leftoffset, UINT16 topoffset, size_t *destsize) +{ + UINT32 x, y; + UINT8 *img; + UINT8 *imgptr = imgbuf; + UINT8 *colpointers, *startofspan; + size_t size = 0; + + if (!raw) + return NULL; + + // Write image size and offset + WRITEINT16(imgptr, width); + WRITEINT16(imgptr, height); + WRITEINT16(imgptr, leftoffset); + WRITEINT16(imgptr, topoffset); + + // Leave placeholder to column pointers + colpointers = imgptr; + imgptr += width*4; + + // Write columns + for (x = 0; x < width; x++) + { + int lastStartY = 0; + int spanSize = 0; + startofspan = NULL; + + // Write column pointer + WRITEINT32(colpointers, imgptr - imgbuf); + + // Write pixels + for (y = 0; y < height; y++) + { + UINT16 pixel = raw[((y * width) + x)]; + UINT8 paletteIndex = (pixel & 0xFF); + UINT8 opaque = (pixel != 0xFF00); // If 1, we have a pixel + + // End span if we have a transparent pixel + if (!opaque) + { + if (startofspan) + WRITEUINT8(imgptr, 0); + startofspan = NULL; + continue; + } + + // Start new column if we need to + if (!startofspan || spanSize == 255) + { + int writeY = y; + + // If we reached the span size limit, finish the previous span + if (startofspan) + WRITEUINT8(imgptr, 0); + + if (y > 254) + { + // Make sure we're aligned to 254 + if (lastStartY < 254) + { + WRITEUINT8(imgptr, 254); + WRITEUINT8(imgptr, 0); + imgptr += 2; + lastStartY = 254; + } + + // Write stopgap empty spans if needed + writeY = y - lastStartY; + + while (writeY > 254) + { + WRITEUINT8(imgptr, 254); + WRITEUINT8(imgptr, 0); + imgptr += 2; + writeY -= 254; + } + } + + startofspan = imgptr; + WRITEUINT8(imgptr, writeY); + imgptr += 2; + spanSize = 0; + + lastStartY = y; + } + + // Write the pixel + WRITEUINT8(imgptr, paletteIndex); + spanSize++; + startofspan[1] = spanSize; + } + + if (startofspan) + WRITEUINT8(imgptr, 0); + + WRITEUINT8(imgptr, 0xFF); + } + + size = imgptr-imgbuf; + img = Z_Malloc(size, PU_STATIC, NULL); + memcpy(img, imgbuf, size); + + if (destsize != NULL) + *destsize = size; + + return img; +} + static UINT16 GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip) { fixed_t ofs; @@ -904,10 +603,6 @@ void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle UINT32 i; patch_t *rotated; -#ifdef HWRENDER - patch_t *hwpatch; -#endif - UINT16 *rawdst, *rawconv; size_t size; INT32 bflip = (flip != 0x00); @@ -1020,29 +715,20 @@ void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle } // make patch - rotated = R_MaskedFlatToPatch(rawconv, width, height, 0, 0, &size); - { - rotated->leftoffset = ox; - rotated->topoffset = oy; - } -#ifdef HWRENDER - if (rendermode == render_opengl) - { - hwpatch = R_CreateHardwarePatch(rotated); - } -#endif // HWRENDER - - //Z_ChangeTag(rotated, PU_PATCH_ROTATED); // important for memory clearing -#ifdef HWRENDER - if (rendermode == render_opengl) - Z_SetUser(hwpatch, (void **)(&rotsprite->patches[idx])); - else -#endif - Z_SetUser(rotated, (void **)(&rotsprite->patches[idx])); - - Z_Free(rawconv); + rotated = (patch_t *)R_MaskedFlatToPatch(rawconv, width, height, 0, 0, &size); rotated->leftoffset = ox; rotated->topoffset = oy; + +#ifdef HWRENDER + if (rendermode == render_opengl) + { + rotated = R_CreateHardwarePatch(rotated); + } +#endif // HWRENDER + + //Z_ChangeTag(rotated, PU_LEVEL); + Z_SetUser(rotated, (void **)(&rotsprite->patches[idx])); + Z_Free(rawconv); } #endif diff --git a/src/r_patch.h b/src/r_patch.h index 5edaa46fb..447f1b4fc 100644 --- a/src/r_patch.h +++ b/src/r_patch.h @@ -40,11 +40,7 @@ typedef struct // Conversions between patches / flats / textures... boolean R_CheckIfPatch(lumpnum_t lump); -void R_TextureToFlat(size_t tex, UINT8 *flat); -void R_PatchToFlat(patch_t *patch, UINT8 *flat); -void R_PatchToMaskedFlat(patch_t *patch, UINT16 *raw, boolean flip); -patch_t *R_FlatToPatch(UINT8 *raw, UINT16 width, UINT16 height, UINT16 leftoffset, UINT16 topoffset, size_t *destsize, boolean transparency); -patch_t *R_MaskedFlatToPatch(UINT16 *raw, UINT16 width, UINT16 height, UINT16 leftoffset, UINT16 topoffset, size_t *destsize); +void *R_MaskedFlatToPatch(UINT16 *raw, UINT16 width, UINT16 height, UINT16 leftoffset, UINT16 topoffset, size_t *destsize); // SpriteInfo extern spriteinfo_t spriteinfo[NUMSPRITES]; From ddc8e4a29e739bba81b651759ef2f50d973254da Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 8 Jan 2025 01:46:56 +0100 Subject: [PATCH 92/99] clean up gamepad led stuff --- src/d_main.c | 2 +- src/g_input.c | 50 ++++++++++++++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 95f7c895d..09218fe72 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -207,7 +207,7 @@ static void D_GamePadMenuScrollTicker(void) } #undef SCROLLDELAY -static inline void D_DeviceLEDTick(void) +static void D_DeviceLEDTick(void) { UINT8 i; UINT16 color[MAXSPLITSCREENPLAYERS]; diff --git a/src/g_input.c b/src/g_input.c index 7f2fff283..1f3c69464 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -908,18 +908,23 @@ static const char *gamecontrolname[num_gamecontrols] = #include "k_kart.h" -inline UINT16 G_GetSkinColor(INT32 player) +UINT16 G_GetSkinColor(INT32 playernum) { - // make rgb rainbow vomit when invul or flash blue when grow - if (cv_ledpowerup[player].value && gamestate == GS_LEVEL && players[displayplayers[player]].mo && (players[displayplayers[player]].kartstuff[k_invincibilitytimer] || players[displayplayers[player]].powers[pw_invulnerability] || players[displayplayers[player]].kartstuff[k_growshrinktimer])) - return players[displayplayers[player]].mo->color; + if (gamestate == GS_LEVEL) + { + player_t *player = &players[displayplayers[playernum]]; - // take actual player skincolour when ingame - if (gamestate == GS_LEVEL && players[displayplayers[player]].skincolor) - return players[displayplayers[player]].skincolor; + // make rgb rainbow vomit when invul or flash blue when grow + if (cv_ledpowerup[playernum].value && player->mo && (player->kartstuff[k_invincibilitytimer] || player->kartstuff[k_growshrinktimer] || player->powers[pw_invulnerability])) + return player->mo->color; + + // take actual player skincolour when ingame + if (player->skincolor) + return player->skincolor; + } // otherwise just fallback to whatever the cvar is - switch (player) + switch (playernum) { case 0: return cv_playercolor.value; @@ -939,49 +944,50 @@ inline UINT16 G_GetSkinColor(INT32 player) } } -void G_SetPlayerGamepadIndicatorColor(INT32 player, UINT16 color) +void G_SetPlayerGamepadIndicatorColor(INT32 playernum, UINT16 color) { INT32 device; UINT16 skincolor; byteColor_t byte_color; - I_Assert(player >= 0 && player < MAXSPLITSCREENPLAYERS); + I_Assert(playernum >= 0 && playernum < MAXSPLITSCREENPLAYERS); - if (cv_gamepadled[player].value == 0) + if (cv_gamepadled[playernum].value == 0) return; - device = cv_usejoystick[player].value; + device = cv_usejoystick[playernum].value; if (device <= 0) { return; } - skincolor = color ? color : G_GetSkinColor(player); + skincolor = color ? color : G_GetSkinColor(playernum); byte_color = V_GetColor(colortranslations[skincolor][8]).s; I_SetGamepadIndicatorColor(device, byte_color.red, byte_color.green, byte_color.blue); } -static void G_ResetPlayerGamepadIndicatorColor(INT32 player) +static void G_ResetPlayerGamepadIndicatorColor(INT32 playernum) { - if (cv_gamepadled[player].value == 0) + if (cv_gamepadled[playernum].value == 0) { - INT32 device = cv_usejoystick[player].value; + INT32 device = cv_usejoystick[playernum].value; + if (device <= 0) return; I_SetGamepadIndicatorColor(device, 0, 0, 255); } else - G_SetPlayerGamepadIndicatorColor(player, 0); + G_SetPlayerGamepadIndicatorColor(playernum, 0); } -static void G_ResetPlayerDeviceRumble(INT32 player) +static void G_ResetPlayerDeviceRumble(INT32 playernum) { INT32 device_id; - device_id = cv_usejoystick[player].value; + device_id = cv_usejoystick[playernum].value; if (device_id < 1) { @@ -1006,16 +1012,16 @@ void G_ResetAllDeviceRumbles(void) } } -void G_PlayerDeviceRumble(INT32 player, UINT16 low_strength, UINT16 high_strength, UINT32 duration) +void G_PlayerDeviceRumble(INT32 playernum, UINT16 low_strength, UINT16 high_strength, UINT32 duration) { INT32 device_id; - if (cv_rumble[player].value == 0) + if (cv_rumble[playernum].value == 0) { return; } - device_id = cv_usejoystick[player].value; + device_id = cv_usejoystick[playernum].value; if (device_id < 1) { From cdfef0f884019bd8f5871adfb61a2743ef2273fb Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 8 Jan 2025 01:48:55 +0100 Subject: [PATCH 93/99] oops forgor those --- src/g_input.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/g_input.h b/src/g_input.h index 18fff51a4..f6e69337d 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -134,11 +134,10 @@ extern INT32 gamecontrol4[num_gamecontrols][2]; // peace to my little coder fingers! // check a gamecontrol being active or not -UINT16 G_GetSkinColor(INT32 player); -INT32 G_GetDeviceForPlayer(INT32 player); -void G_SetPlayerGamepadIndicatorColor(INT32 player, UINT16 color); -void G_PlayerDeviceRumble(INT32 player, UINT16 low_strength, UINT16 high_strength, UINT32 duration); +UINT16 G_GetSkinColor(INT32 playernum); +void G_SetPlayerGamepadIndicatorColor(INT32 playernum, UINT16 color); void G_ResetAllDeviceRumbles(void); +void G_PlayerDeviceRumble(INT32 playernum, UINT16 low_strength, UINT16 high_strength, UINT32 duration); // remaps the input event to a game control. void G_MapEventsToControls(event_t *ev); From d01ed388958ee6322f69315cd60615201908c36a Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 8 Jan 2025 03:17:14 +0100 Subject: [PATCH 94/99] fix "connect" command not saving to last server --- src/d_clisrv.c | 2 ++ src/i_tcp.c | 4 ---- src/m_menu.c | 4 ---- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index af6a82289..775668d5b 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3132,6 +3132,8 @@ static void Command_connect(void) CONS_Alert(CONS_ERROR, M_GetText("There is no network driver\n")); } + CV_Set(&cv_lastserver, I_GetNodeAddress(servernode)); + if (splitscreen != cv_splitplayers.value-1) { splitscreen = cv_splitplayers.value-1; diff --git a/src/i_tcp.c b/src/i_tcp.c index 14dd8b5ed..54c446258 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -1669,7 +1669,6 @@ boolean I_InitTcpNetwork(void) // server address only in ip if (serverhostname[0]) { - CV_Set(&cv_lastserver, serverhostname); COM_BufAddText("connect \""); COM_BufAddText(serverhostname); COM_BufAddText("\"\n"); @@ -1679,9 +1678,6 @@ boolean I_InitTcpNetwork(void) } else { - // Not quite sure if we want to save that but i'll do that for now - CV_Set(&cv_lastserver, "any"); - // so we're on a LAN COM_BufAddText("connect any\n"); diff --git a/src/m_menu.c b/src/m_menu.c index 6272f57fa..a2732c3a7 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -9433,9 +9433,6 @@ static void M_Connect(INT32 choice) { // do not call menuexitfunc M_ClearMenus(false); - - CV_Set(&cv_lastserver, I_GetNodeAddress(serverlist[choice-FIRSTSERVERLINE + serverlistpage * SERVERS_PER_PAGE].node)); - COM_BufAddText(va("connect node %d\n", serverlist[choice-FIRSTSERVERLINE + serverlistpage * SERVERS_PER_PAGE].node)); } @@ -10364,7 +10361,6 @@ static void M_ConnectIP(INT32 choice) M_ClearMenus(true); - CV_Set(&cv_lastserver,setupm_ip); COM_BufAddText(va("connect \"%s\"\n", setupm_ip)); // A little "please wait" message. From 165803c95c069be734b78be6f04220d64f1aa6ca Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 8 Jan 2025 04:00:57 +0100 Subject: [PATCH 95/99] toggle for smol positionnum and posnum animation --- src/g_game.h | 2 ++ src/k_kart.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/g_game.h b/src/g_game.h index 3a957d00a..d092f229f 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -167,6 +167,8 @@ DECL_HUD_OFFSET(stat); // Stats #undef DECL_HUD_OFFSET_Y extern consvar_t cv_showinput; +extern consvar_t cv_posanim; +extern consvar_t cv_smallposnum; extern consvar_t cv_newspeedometer; extern consvar_t cv_saltyhop; diff --git a/src/k_kart.c b/src/k_kart.c index 70410e1c3..b8174dc57 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -79,6 +79,10 @@ consvar_t cv_showstats = {"showstats", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, consvar_t cv_showinput = {"showinput", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_showlaptimes = {"showlaptimes", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_posanim = {"postitionanimation", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_smallposnum = {"smallpositionnumber", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + + CV_PossibleValue_t speedo_cons_t[NUMSPEEDOSTUFF]; consvar_t cv_newspeedometer = {"newspeedometer", "Default", CV_SAVE, speedo_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -723,6 +727,10 @@ void K_RegisterKartStuff(void) CV_RegisterVar(&cv_showstats); CV_RegisterVar(&cv_showinput); + + CV_RegisterVar(&cv_posanim); + CV_RegisterVar(&cv_smallposnum); + CV_RegisterVar(&cv_showlaptimes); CV_RegisterVar(&cv_newspeedometer); @@ -8309,13 +8317,13 @@ static void K_DrawKartPositionNum(INT32 num) boolean flipvdraw = false; // used only for 2p splitscreen so overtaking doesn't make 1P's position fly off the screen. boolean overtake = false; - if (stplyr->kartstuff[k_positiondelay] || stplyr->exiting) + if ((cv_posanim.value && stplyr->kartstuff[k_positiondelay]) || stplyr->exiting) { scale *= 2; overtake = true; // this is used for splitscreen stuff in conjunction with flipdraw. } - if (splitscreen || (cv_showinput.value && !splitscreen)) + if (splitscreen || cv_smallposnum.value || cv_showinput.value) scale /= 2; W = FixedMul(W<>FRACBITS; From 51e367a61d40caae37e472c9f1ff0d9d14d6e30c Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 8 Jan 2025 04:01:48 +0100 Subject: [PATCH 96/99] move saturn hud cvars to k_kart and fix driftgauge extra showing if there is no patch for it its kinda dumb, since technically would allow to not load all of em but im lazy and dont wanna change possiblevalues around --- src/d_main.c | 18 +++++++---- src/d_netcmd.c | 65 -------------------------------------- src/k_kart.c | 86 ++++++++++++++++++++++++++++++++++++++++++-------- src/k_kart.h | 1 + 4 files changed, 86 insertions(+), 84 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 09218fe72..209e7fb76 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1571,8 +1571,10 @@ void D_SRB2Main(void) // Possible value that changes depending on whether required files for speedometer are found or not CV_PossibleValue_t speedo_cons_temp[NUMSPEEDOSTUFF] = {{1, "Default"}, {0, NULL}, {0, NULL}, {0, NULL}, {0, NULL}, {0, NULL}}; + CV_PossibleValue_t driftgaugestyle_cons_temp[NUMSPEEDOSTUFF] = {{1, "Default"}, {2, "Small"}, {3, "Big Numbers"}, {4, "Numbers Only"}, {0, NULL}, {0, NULL}}; // ugh i dont want this but bleh unsigned last_speedo_i = 0; -#define PUSHSPEEDO(id, name) { ++last_speedo_i; speedo_cons_temp[last_speedo_i].value = id; speedo_cons_temp[last_speedo_i].strvalue = name; } + unsigned last_driftgauge_i = 0; +#define PUSHCONS(cons, i, id, name) { ++i; cons[i].value = id; cons[i].strvalue = name; } if (found_extra_kart || found_extra2_kart || found_extra3_kart) // found the funny, add it in! { @@ -1588,7 +1590,7 @@ void D_SRB2Main(void) if (W_CheckMultipleLumps("SP_SMSTC", "K_TRNULL", "SP_MKMH", "SP_MMPH", "SP_MFRAC", "SP_MPERC", NULL)) { xtra_speedo = true; - PUSHSPEEDO(2, "Small"); + PUSHCONS(speedo_cons_temp, last_speedo_i, 2, "Small"); } if (W_LumpExists("SC_SMSTC")) @@ -1598,7 +1600,7 @@ void D_SRB2Main(void) if (W_CheckMultipleLumps("SP_AMSTC", "K_TRNULL", "SP_AKMH", "SP_AMPH", "SP_AFRAC", "SP_APERC", NULL)) { achi_speedo = true; - PUSHSPEEDO(3, "Achii"); + PUSHCONS(speedo_cons_temp, last_speedo_i, 3, "Achii"); } if (W_CheckMultipleLumps("SC_AMSTC", "K_TRNULL", "SC_AKMH", "SC_AMPH", "SC_AFRAC", "SC_APERC", NULL)) @@ -1624,7 +1626,7 @@ void D_SRB2Main(void) "K_KZSP20", "K_KZSP21", "K_KZSP22", "K_KZSP23", "K_KZSP24", "K_KZSP25", NULL)) { kartzspeedo = true; - PUSHSPEEDO(4, "P-Meter"); + PUSHCONS(speedo_cons_temp, last_speedo_i, 4, "P-Meter"); } // stat display for extended player setup @@ -1637,7 +1639,9 @@ void D_SRB2Main(void) nametaggfx = true; if (W_CheckMultipleLumps("K_DGAU","K_DCAU","K_DGSU","K_DCSU", NULL)) + { driftgaugegfx = true; + } if (found_extra3_kart) { @@ -1645,7 +1649,8 @@ void D_SRB2Main(void) if (W_LumpExists("SP_SM3TC")) { xtra_speedo3 = true; - PUSHSPEEDO(5, "Extra"); + PUSHCONS(speedo_cons_temp, last_speedo_i, 5, "Extra"); + PUSHCONS(driftgaugestyle_cons_temp, last_driftgauge_i, 5, "Extra"); } if (W_LumpExists("SC_SM3TC")) @@ -1653,8 +1658,9 @@ void D_SRB2Main(void) } } -#undef PUSHSPEEDO +#undef PUSHCONS memcpy(speedo_cons_t, speedo_cons_temp, sizeof(speedo_cons_t)); + memcpy(driftgaugestyle_cons_t, driftgaugestyle_cons_temp, sizeof(driftgaugestyle_cons_t)); // Do it before P_InitMapData because PNG patch // conversion sometimes needs the palette diff --git a/src/d_netcmd.c b/src/d_netcmd.c index eaec437fe..b01f87e5a 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -490,12 +490,6 @@ consvar_t cv_pingstyle = {"pingstyle", "New", CV_SAVE, cv_pingstyle_cons_t, 0, 0 consvar_t cv_luaimmersion = {"luaimmersion", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_minihead = {"smallminimapplayers", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; - -consvar_t cv_showminimapnames = {"showminimapnames", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; - -consvar_t cv_showlapemblem = {"showlapemblem", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; - consvar_t cv_showviewpointtext = {"showviewpointtext", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_showdownloadprompt = {"showdownloadprompt", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; @@ -516,45 +510,6 @@ consvar_t cv_mute = {"mute", "Off", CV_NETVAR|CV_CALL, CV_OnOff, Mute_OnChange, consvar_t cv_sleep = {"cpusleep", "1", CV_SAVE, sleeping_cons_t, NULL, -1, NULL, NULL, 0, 0, NULL}; -static CV_PossibleValue_t nametagtrans_cons_t[] = { - {0, "Never"}, {1, "Far only"}, {2, "Dynamic"}, {3, "Always"}, {4, "HUD Trans."}, {0, NULL}}; -/*static CV_PossibleValue_t nametagscaling_cons_t[] = { - {0, "MIN"}, {320, "MAX"}, {0, NULL}};*/ -static CV_PossibleValue_t nametagdistance_cons_t[] = { - {0, "MIN"}, {640, "MAX"}, {0, NULL}}; -static CV_PossibleValue_t nametagmaxplayer_cons_t[] = { - {1, "MIN"}, {MAXPLAYERS, "MAX"}, {0, NULL}}; -static CV_PossibleValue_t nametagsize_cons_t[] = { - {0, "Off"}, {1, "Small"}, {2, "Minimal"}, {0, NULL}}; -static CV_PossibleValue_t nametagrestat_cons_t[] = { - {0, "Off"}, {1, "Restat"}, {2, "Always"}, {0, NULL}}; - -consvar_t cv_nametag = {"kartnametag", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_nametagtrans = {"kartnametagtransparency", "Dynamic", CV_SAVE, nametagtrans_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_nametagfacerank = {"kartnametagfacerank", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_nametagrestat = {"kartnametagrestat", "Restat", CV_SAVE, nametagrestat_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_nametagdist = {"kartnametagdist", "320", CV_SAVE, nametagdistance_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_nametagmaxplayers = {"kartnametagmaxplayers", "3", CV_SAVE, nametagmaxplayer_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_nametagmaxlenght = {"kartnametagmaxlenght", "12", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; -//consvar_t cv_nametagscaling = {"nametagscaling", "160", CV_SAVE, nametagscaling_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_showownnametag = {"kartnametagshowown", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_smallnametags = {"kartnametagsmall", "Off", CV_SAVE, nametagsize_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_nametaghop = {"kartnametaghop", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_nametagscore = {"kartnametagscore", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_shownametagfinish = {"kartshownametagfinished", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_shownametagspectator = {"kartshownametagspectator", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; - - -static CV_PossibleValue_t driftgaugeoffset_cons_t[] = { - {-FRACUNIT*128, "MIN"}, {FRACUNIT*128, "MAX"}, {0, NULL}}; -static CV_PossibleValue_t driftgaugestyle_cons_t[] = { - {1, "Default"}, {2, "Small"}, {3, "Big Numbers"}, {4, "Numbers Only"}, {5, "Extra"}, {0, NULL}}; - -consvar_t cv_driftgauge = {"kartdriftgauge", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_driftgaugeofs = {"kartdriftgaugeoffset", "-20", CV_FLOAT|CV_SAVE, driftgaugeoffset_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_driftgaugetrans = {"kartdriftgaugetransparency", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_driftgaugestyle = {"kartdriftgaugestyle", "1", CV_SAVE, driftgaugestyle_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; - static CV_PossibleValue_t skinselectspin_cons_t[] = { {0, "Off"}, {1, "Slow"}, {2, "2"}, {3, "3"}, {4, "4"}, {5, "5"}, {6, "6"}, {7, "7"}, {8, "8"}, {9, "9"}, {10, "Fast"}, {SKINSELECTSPIN_PAIN, "Pain"}, {0, NULL}}; consvar_t cv_skinselectspin = {"skinselectspin", "5", CV_SAVE, skinselectspin_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -1122,26 +1077,6 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_soundtest); - CV_RegisterVar(&cv_nametag); - CV_RegisterVar(&cv_nametagtrans); - CV_RegisterVar(&cv_nametagfacerank); - CV_RegisterVar(&cv_nametagmaxplayers); - CV_RegisterVar(&cv_nametagmaxlenght); - //CV_RegisterVar(&cv_nametagscaling); - CV_RegisterVar(&cv_nametagdist); - CV_RegisterVar(&cv_showownnametag); - CV_RegisterVar(&cv_smallnametags); - CV_RegisterVar(&cv_nametagrestat); - CV_RegisterVar(&cv_nametaghop); - CV_RegisterVar(&cv_nametagscore); - CV_RegisterVar(&cv_shownametagfinish); - CV_RegisterVar(&cv_shownametagspectator); - - CV_RegisterVar(&cv_driftgauge); - CV_RegisterVar(&cv_driftgaugeofs); - CV_RegisterVar(&cv_driftgaugetrans); - CV_RegisterVar(&cv_driftgaugestyle); - CV_RegisterVar(&cv_perfstats); CV_RegisterVar(&cv_ps_thinkframe_page); CV_RegisterVar(&cv_ps_samplesize); diff --git a/src/k_kart.c b/src/k_kart.c index b8174dc57..8afc37819 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -82,9 +82,18 @@ consvar_t cv_showlaptimes = {"showlaptimes", "Off", CV_SAVE, CV_OnOff, NULL, 0, consvar_t cv_posanim = {"postitionanimation", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_smallposnum = {"smallpositionnumber", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_minihead = {"smallminimapplayers", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_showminimapnames = {"showminimapnames", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_highresportrait = {"highresportrait", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; //make char potraits use their high-res version instead + +consvar_t cv_showlapemblem = {"showlapemblem", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_darkitembox = {"darkitembox", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; //itembox gets a dark box with specific items +consvar_t cv_biglaps = {"biglaphud", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; //here for ppl who dont want to make 2 more patches for their custom hud CV_PossibleValue_t speedo_cons_t[NUMSPEEDOSTUFF]; consvar_t cv_newspeedometer = {"newspeedometer", "Default", CV_SAVE, speedo_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_battlespeedo = {"battlespeedo", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; //toggle for showing the speedometer in battlemode //hardcode saltyhop mhhm consvar_t cv_saltyhop = {"hardcodehop", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -98,13 +107,45 @@ consvar_t cv_colorizeditembox = {"colorizeditembox", "Off", CV_SAVE, CV_OnOff, N static CV_PossibleValue_t HudColor_cons_t[MAXSKINCOLORS+1]; consvar_t cv_colorizedhudcolor = {"colorizedhudcolor", "Skin Color", CV_SAVE, HudColor_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_highresportrait = {"highresportrait", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; //make char potraits use their high-res version instead +// driftgauge stuffs +static CV_PossibleValue_t driftgaugeoffset_cons_t[] = { + {-FRACUNIT*128, "MIN"}, {FRACUNIT*128, "MAX"}, {0, NULL}}; +CV_PossibleValue_t driftgaugestyle_cons_t[NUMSPEEDOSTUFF]; -consvar_t cv_darkitembox = {"darkitembox", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; //itembox gets a dark box with specific items +consvar_t cv_driftgauge = {"kartdriftgauge", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_driftgaugeofs = {"kartdriftgaugeoffset", "-20", CV_FLOAT|CV_SAVE, driftgaugeoffset_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_driftgaugetrans = {"kartdriftgaugetransparency", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_driftgaugestyle = {"kartdriftgaugestyle", "1", CV_SAVE, driftgaugestyle_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_biglaps = {"biglaphud", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; //here for ppl who dont want to make 2 more patches for their custom hud +// nametags +static CV_PossibleValue_t nametagtrans_cons_t[] = { + {0, "Never"}, {1, "Far only"}, {2, "Dynamic"}, {3, "Always"}, {4, "HUD Trans."}, {0, NULL}}; +/*static CV_PossibleValue_t nametagscaling_cons_t[] = { + {0, "MIN"}, {320, "MAX"}, {0, NULL}};*/ +static CV_PossibleValue_t nametagdistance_cons_t[] = { + {0, "MIN"}, {640, "MAX"}, {0, NULL}}; +static CV_PossibleValue_t nametagmaxplayer_cons_t[] = { + {1, "MIN"}, {MAXPLAYERS, "MAX"}, {0, NULL}}; +static CV_PossibleValue_t nametagsize_cons_t[] = { + {0, "Off"}, {1, "Small"}, {2, "Minimal"}, {0, NULL}}; +static CV_PossibleValue_t nametagrestat_cons_t[] = { + {0, "Off"}, {1, "Restat"}, {2, "Always"}, {0, NULL}}; + +consvar_t cv_nametag = {"kartnametag", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_nametagtrans = {"kartnametagtransparency", "Dynamic", CV_SAVE, nametagtrans_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_nametagfacerank = {"kartnametagfacerank", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_nametagrestat = {"kartnametagrestat", "Restat", CV_SAVE, nametagrestat_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_nametagdist = {"kartnametagdist", "320", CV_SAVE, nametagdistance_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_nametagmaxplayers = {"kartnametagmaxplayers", "3", CV_SAVE, nametagmaxplayer_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_nametagmaxlenght = {"kartnametagmaxlenght", "12", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; +//consvar_t cv_nametagscaling = {"nametagscaling", "160", CV_SAVE, nametagscaling_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_showownnametag = {"kartnametagshowown", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_smallnametags = {"kartnametagsmall", "Off", CV_SAVE, nametagsize_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_nametaghop = {"kartnametaghop", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_nametagscore = {"kartnametagscore", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_shownametagfinish = {"kartshownametagfinished", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_shownametagspectator = {"kartshownametagspectator", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_battlespeedo = {"battlespeedo", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; //toggle for showing the speedometer in battlemode // SOME IMPORTANT VARIABLES DEFINED IN DOOMDEF.H: // gamespeed is cc (0 for easy, 1 for normal, 2 for hard) @@ -736,9 +777,11 @@ void K_RegisterKartStuff(void) CV_RegisterVar(&cv_battlespeedo); - CV_RegisterVar(&cv_saltyhop); - CV_RegisterVar(&cv_saltyhopsfx); - CV_RegisterVar(&cv_saltysquish); + CV_RegisterVar(&cv_minihead); + CV_RegisterVar(&cv_showminimapnames); + CV_RegisterVar(&cv_showlapemblem); + + CV_RegisterVar(&cv_stagetitle); //Colourized HUD CV_RegisterVar(&cv_colorizedhud); @@ -751,14 +794,31 @@ void K_RegisterKartStuff(void) CV_RegisterVar(&cv_highresportrait); + CV_RegisterVar(&cv_nametag); + CV_RegisterVar(&cv_nametagtrans); + CV_RegisterVar(&cv_nametagfacerank); + CV_RegisterVar(&cv_nametagmaxplayers); + CV_RegisterVar(&cv_nametagmaxlenght); + //CV_RegisterVar(&cv_nametagscaling); + CV_RegisterVar(&cv_nametagdist); + CV_RegisterVar(&cv_showownnametag); + CV_RegisterVar(&cv_smallnametags); + CV_RegisterVar(&cv_nametagrestat); + CV_RegisterVar(&cv_nametaghop); + CV_RegisterVar(&cv_nametagscore); + CV_RegisterVar(&cv_shownametagfinish); + CV_RegisterVar(&cv_shownametagspectator); + + CV_RegisterVar(&cv_driftgauge); + CV_RegisterVar(&cv_driftgaugeofs); + CV_RegisterVar(&cv_driftgaugetrans); + CV_RegisterVar(&cv_driftgaugestyle); + + CV_RegisterVar(&cv_saltyhop); + CV_RegisterVar(&cv_saltyhopsfx); + CV_RegisterVar(&cv_saltysquish); CV_RegisterVar(&cv_slamsound); - CV_RegisterVar(&cv_minihead); - CV_RegisterVar(&cv_showminimapnames); - CV_RegisterVar(&cv_showlapemblem); - - CV_RegisterVar(&cv_stagetitle); - CV_RegisterVar(&cv_lessflicker); CV_RegisterVar(&cv_mouseturn); diff --git a/src/k_kart.h b/src/k_kart.h index 647ae3bf0..34c59c622 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -36,6 +36,7 @@ extern consvar_t cv_battlespeedo; #define NUMSPEEDOSTUFF 6 extern CV_PossibleValue_t speedo_cons_t[NUMSPEEDOSTUFF]; +extern CV_PossibleValue_t driftgaugestyle_cons_t[NUMSPEEDOSTUFF]; boolean K_IsPlayerLosing(player_t *player); boolean K_IsPlayerWanted(player_t *player); From 38b52b826a83e84b4cc5177aefcc148631462653 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 8 Jan 2025 12:00:41 +0300 Subject: [PATCH 97/99] huh --- src/p_tick.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/p_tick.c b/src/p_tick.c index ec77d50cf..9d5a64cf3 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -381,11 +381,6 @@ static void P_DeviceRumbleTick(void) continue; } - if (camera[i].freecam) - { - continue; - } - if (player->mo == NULL) { continue; From d9f0c55fee5d5456af4c4c28d927fbe3c31f0de0 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 10 Jan 2025 22:31:31 +0100 Subject: [PATCH 98/99] "Invinciblity" --- src/m_menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/m_menu.c b/src/m_menu.c index a2732c3a7..c4fad470c 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2160,7 +2160,7 @@ static menuitem_t OP_MonitorToggleMenu[] = {IT_KEYHANDLER | IT_NOTHING, NULL, "Jawz x2", M_HandleMonitorToggles, KRITEM_DUALJAWZ}, {IT_KEYHANDLER | IT_NOTHING, NULL, "Ballhogs", M_HandleMonitorToggles, KITEM_BALLHOG}, {IT_KEYHANDLER | IT_NOTHING, NULL, "Self-Propelled Bombs", M_HandleMonitorToggles, KITEM_SPB}, - {IT_KEYHANDLER | IT_NOTHING, NULL, "Invinciblity", M_HandleMonitorToggles, KITEM_INVINCIBILITY}, + {IT_KEYHANDLER | IT_NOTHING, NULL, "Invincibility", M_HandleMonitorToggles, KITEM_INVINCIBILITY}, {IT_KEYHANDLER | IT_NOTHING, NULL, "Grow", M_HandleMonitorToggles, KITEM_GROW}, {IT_KEYHANDLER | IT_NOTHING, NULL, "Shrink", M_HandleMonitorToggles, KITEM_SHRINK}, {IT_KEYHANDLER | IT_NOTHING, NULL, "Thunder Shields", M_HandleMonitorToggles, KITEM_THUNDERSHIELD}, From 2a948ca4c2c82b04e71664a6aa60a306d874dc47 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 10 Jan 2025 22:46:05 +0100 Subject: [PATCH 99/99] move this --- src/m_menu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index c4fad470c..ace9d585e 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4336,10 +4336,11 @@ void M_Drawer(void) #ifdef HWRENDER if (rendermode == render_opengl) - V_DrawThinString(0, 0, V_GREENMAP|V_SNAPTOTOP|V_SNAPTOLEFT|V_TRANSLUCENT|V_ALLOWLOWERCASE, ("Opengl")); + V_DrawThinString(0, 0, V_GREENMAP|V_SNAPTOTOP|V_SNAPTOLEFT|V_TRANSLUCENT|V_ALLOWLOWERCASE, ("Opengl")); + else #endif if (rendermode == render_soft) - V_DrawThinString(0, 0, V_REDMAP|V_SNAPTOTOP|V_SNAPTOLEFT|V_TRANSLUCENT|V_ALLOWLOWERCASE, ("Software")); + V_DrawThinString(0, 0, V_REDMAP|V_SNAPTOTOP|V_SNAPTOLEFT|V_TRANSLUCENT|V_ALLOWLOWERCASE, ("Software")); } } }