From ff0a3df3023c56e12a1a86ed8b6ebc5a78bf57fe Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 9 Apr 2021 21:21:53 +0200 Subject: [PATCH 01/15] - fixed extended music lookup again. # Conflicts: # source/core/parsefuncs.h --- source/core/raze_music.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/source/core/raze_music.cpp b/source/core/raze_music.cpp index b2c3f0aed..c23f0b0ff 100644 --- a/source/core/raze_music.cpp +++ b/source/core/raze_music.cpp @@ -133,21 +133,24 @@ FileReader OpenMusic(const char* musicname) if (!reader.isOpen()) { int lumpnum = LookupMusic(musicname); - if (mus_extendedlookup && lumpnum >= 0) - { - // EDuke also looks in a subfolder named after the main game resource. Do this as well if extended lookup is active. - auto rfn = fileSystem.GetResourceFileName(fileSystem.GetFileContainer(lumpnum)); - auto rfbase = ExtractFileBase(rfn); - FStringf aliasMusicname("music/%s/%s", rfbase.GetChars(), musicname); - int newlumpnum = LookupMusic(aliasMusicname); - if (newlumpnum >= 0) lumpnum = newlumpnum; - } - if (lumpnum == -1) + if (mus_extendedlookup || lumpnum < 0) { + if (lumpnum >= 0) + { + // EDuke also looks in a subfolder named after the main game resource. Do this as well if extended lookup is active. + auto rfn = fileSystem.GetResourceFileName(fileSystem.GetFileContainer(lumpnum)); + auto rfbase = ExtractFileBase(rfn); + FStringf aliasMusicname("music/%s/%s", rfbase.GetChars(), musicname); + int newlumpnum = LookupMusic(aliasMusicname); + if (newlumpnum >= 0) lumpnum = newlumpnum; + } + // Always look in the 'music' subfolder as well. This gets used by multiple setups to store ripped CD tracks. FStringf aliasMusicname("music/%s", musicname); - lumpnum = LookupMusic(aliasMusicname); + int newlumpnum = LookupMusic(aliasMusicname, lumpnum >= 0); + if (newlumpnum >= 0) lumpnum = newlumpnum; } + if (lumpnum == -1 && (g_gameType & GAMEFLAG_SW)) { // Some Shadow Warrior distributions have the music in a subfolder named 'classic'. Check that, too. From 02dedaad4642df80de90c41c41833061f084792e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 9 Apr 2021 22:11:16 +0200 Subject: [PATCH 02/15] - Blood: undid restriction for original QAV for Guns Akimbo shotgun fix. --- source/games/blood/src/weapon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/games/blood/src/weapon.cpp b/source/games/blood/src/weapon.cpp index 3dd797e90..130074dd5 100644 --- a/source/games/blood/src/weapon.cpp +++ b/source/games/blood/src/weapon.cpp @@ -266,7 +266,7 @@ void WeaponDraw(PLAYER *pPlayer, int shade, double xpos, double ypos, int palnum if (pPlayer->weaponTimer == 0) // playing idle QAV? { // Double shotgun fix from BloodGDX. - if (/*!IsOriginalDemo() &&*/ (pPlayer->weaponState == -1 || (pPlayer->curWeapon == 3 && pPlayer->weaponState == 7)) && isOriginalQAV()) + if (/*!IsOriginalDemo() &&*/ (pPlayer->weaponState == -1 || (pPlayer->curWeapon == 3 && pPlayer->weaponState == 7))/* && isOriginalQAV()*/) duration = pQAV->duration - 1; else duration = (PlayClock + MulScale(4, smoothratio, 16)) % pQAV->duration; } From db5fbe3bbb7c1bc1f4e80f189a434eb3d7d4bff0 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 10 Apr 2021 19:14:30 +0200 Subject: [PATCH 03/15] - make the startup banner in the initial console window work. --- source/core/gamecontrol.cpp | 19 +++++++-- source/core/gamecontrol.h | 1 + source/core/searchpaths.cpp | 10 +++++ wadsrc/static/engine/grpinfo.txt | 72 ++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+), 3 deletions(-) diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index c9d0f4dfb..094c586f2 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -717,9 +717,6 @@ static TArray SetupGame() if (groupno == -1) return TArray(); auto& group = groups[groupno]; - if (GameStartupInfo.Name.IsNotEmpty()) I_SetWindowTitle(GameStartupInfo.Name); - else I_SetWindowTitle(group.FileInfo.name); - // Now filter out the data we actually need and delete the rest. usedgroups.Push(group); @@ -818,6 +815,8 @@ void CreateStatusBar() int RunGame() { + GameStartupInfo.FgColor = 0xffffff; + // Set up the console before anything else so that it can receive text. C_InitConsole(1024, 768, true); @@ -836,6 +835,19 @@ int RunGame() G_LoadConfig(); auto usedgroups = SetupGame(); + for (auto& grp : usedgroups) + { + if (grp.FileInfo.name.IsNotEmpty()) + { + if (GameStartupInfo.Name.IsEmpty()) GameStartupInfo.Name = grp.FileInfo.name; + if (grp.FileInfo.FgColor != grp.FileInfo.BgColor && (GameStartupInfo.FgColor != 0 || GameStartupInfo.BkColor != 0)) + { + GameStartupInfo.FgColor = grp.FileInfo.FgColor; + GameStartupInfo.BkColor = grp.FileInfo.BgColor; + } + } + } + I_SetIWADInfo(); InitFileSystem(usedgroups); if (usedgroups.Size() == 0) return 0; @@ -927,6 +939,7 @@ int RunGame() lookups.postLoadTables(); PostLoadSetup(); videoInit(); + if (GameStartupInfo.Name.IsNotEmpty()) I_SetWindowTitle(GameStartupInfo.Name); D_CheckNetGame(); UpdateGenericUI(ui_generic); diff --git a/source/core/gamecontrol.h b/source/core/gamecontrol.h index 8a1cd1685..292c9a4b4 100644 --- a/source/core/gamecontrol.h +++ b/source/core/gamecontrol.h @@ -150,6 +150,7 @@ struct GrpInfo TArray tobedeleted; TArray loadfiles; TArray loadart; + uint32_t FgColor = 0, BgColor = 0; }; diff --git a/source/core/searchpaths.cpp b/source/core/searchpaths.cpp index f2f07e281..61cae25a3 100644 --- a/source/core/searchpaths.cpp +++ b/source/core/searchpaths.cpp @@ -460,6 +460,16 @@ static TArray ParseGrpInfo(const char *fn, FileReader &fr, TMap Date: Sat, 10 Apr 2021 19:28:46 +0200 Subject: [PATCH 04/15] - activate the progress bar on the startup screen. --- source/core/gamecontrol.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index 094c586f2..28516cf0c 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -881,7 +881,8 @@ int RunGame() V_InitScreenSize(); V_InitScreen(); - StartScreen = FStartupScreen::CreateInstance(100); + StartScreen = FStartupScreen::CreateInstance(8); + StartScreen->Progress(); TArray addArt; for (auto& grp : usedgroups) @@ -911,15 +912,20 @@ int RunGame() GameTicRate = 30; CheckUserMap(); GPalette.Init(MAXPALOOKUPS + 2); // one slot for each translation, plus a separate one for the base palettes and the internal one + StartScreen->Progress(); TexMan.Init([]() {}, [](BuildInfo &) {}); V_InitFonts(); + StartScreen->Progress(); TileFiles.Init(); + StartScreen->Progress(); I_InitSound(); + StartScreen->Progress(); Mus_InitMusic(); S_ParseSndInfo(); S_ParseReverbDef(); InitStatistics(); LoadScripts(); + StartScreen->Progress(); SetDefaultStrings(); if (Args->CheckParm("-sounddebug")) C_DoCommand("stat sounddebug"); @@ -927,11 +933,14 @@ int RunGame() enginePreInit(); SetupGameButtons(); gameinfo.mBackButton = "engine/graphics/m_back.png"; + StartScreen->Progress(); gi->app_init(); + StartScreen->Progress(); CreateStatusBar(); SetDefaultMenuColors(); M_Init(); BuildGameMenus(); + StartScreen->Progress(); if (!(paletteloaded & PALETTE_MAIN)) I_FatalError("No palette found."); From 184d9be6b1d00e772a53fdc98d0e63d9d136fdf5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 10 Apr 2021 21:42:53 +0200 Subject: [PATCH 05/15] - fixed palette setup for duplicate base palettes. Due to some old code it could happen that these weren't fully set up and missed their translations. Fixes #301 - Blood's invulnerability palette is identical to the base. --- source/core/palette.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/source/core/palette.cpp b/source/core/palette.cpp index a5c256f41..2625746b3 100644 --- a/source/core/palette.cpp +++ b/source/core/palette.cpp @@ -268,16 +268,13 @@ void LookupTableInfo::postLoadLookups() { const uint8_t* lookup = (uint8_t*)tables[l].Shades.GetChars(); FRemapTable remap; - if (i == 0 || (palette != basepalette && !palette->TwodOnly)) + memcpy(remap.Remap, lookup, 256); + for (int j = 0; j < 256; j++) { - memcpy(remap.Remap, lookup, 256); - for (int j = 0; j < 256; j++) - { - remap.Palette[j] = palette->Palette[remap.Remap[j]]; - } - remap.NumEntries = 256; - GPalette.UpdateTranslation(TRANSLATION(i + Translation_Remap, l), &remap); + remap.Palette[j] = palette->Palette[remap.Remap[j]]; } + remap.NumEntries = 256; + GPalette.UpdateTranslation(TRANSLATION(i + Translation_Remap, l), &remap); } } } From 0bdbf0f1cbcaf4bb19bb2c8567aa5d5e5fb62438 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Apr 2021 08:26:36 +0200 Subject: [PATCH 06/15] - fixed: alpha was never set for voxels. Fixes #304 --- source/build/src/voxmodel.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/build/src/voxmodel.cpp b/source/build/src/voxmodel.cpp index 2e3b37e60..64bf05abb 100644 --- a/source/build/src/voxmodel.cpp +++ b/source/build/src/voxmodel.cpp @@ -137,9 +137,6 @@ int32_t polymost_voxdraw(voxmodel_t* m, tspriteptr_t const tspr, bool rotate) float pc[4]; - pc[0] = pc[1] = pc[2] = 1.f; - - if (!shadowHack) { pc[3] = (tspr->cstat & 2) ? glblend[tspr->blend].def[!!(tspr->cstat & 512)].alpha : 1.0f; @@ -152,6 +149,12 @@ int32_t polymost_voxdraw(voxmodel_t* m, tspriteptr_t const tspr, bool rotate) } else pc[3] = 1.f; GLInterface.SetShade(std::max(0, globalshade), numshades); + + pc[0] = (float)globalr * (1.f / 255.f); + pc[1] = (float)globalg * (1.f / 255.f); + pc[2] = (float)globalb * (1.f / 255.f); + GLInterface.SetColor(pc[0], pc[1], pc[2], pc[3]); + //------------ //transform to Build coords From b3bcedda6ce64e108289fa363653bd9d65177e6f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Apr 2021 08:40:18 +0200 Subject: [PATCH 07/15] - moved backend independent HUD code out of glbackend.cpp. --- source/CMakeLists.txt | 1 + source/core/gamehud.cpp | 139 +++++++++++++++++++++++ source/core/gamehud.h | 8 ++ source/core/mainloop.cpp | 1 + source/games/blood/src/animatesprite.cpp | 1 - source/games/blood/src/credits.cpp | 1 - source/games/blood/src/hudsprites.cpp | 2 +- source/games/blood/src/prediction.cpp | 1 - source/games/blood/src/qav.cpp | 1 - source/games/blood/src/sbar.cpp | 1 - source/games/blood/src/view.cpp | 1 - source/games/duke/src/d_menu.cpp | 1 - source/games/duke/src/game.cpp | 1 - source/games/duke/src/game_misc.cpp | 1 - source/games/duke/src/gameloop.cpp | 1 - source/games/duke/src/inlines.h | 2 +- source/games/duke/src/render.cpp | 1 + source/games/exhumed/src/d_menu.cpp | 1 - source/games/exhumed/src/light.cpp | 1 - source/games/exhumed/src/sequence.cpp | 2 +- source/games/exhumed/src/view.cpp | 1 - source/games/sw/src/d_menu.cpp | 3 - source/games/sw/src/draw.cpp | 1 - source/games/sw/src/jsector.cpp | 1 - source/games/sw/src/panel.cpp | 2 +- source/glbackend/glbackend.cpp | 88 +------------- source/glbackend/glbackend.h | 3 - 27 files changed, 155 insertions(+), 112 deletions(-) create mode 100644 source/core/gamehud.cpp create mode 100644 source/core/gamehud.h diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 63169478b..c4109c07d 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -1046,6 +1046,7 @@ set (PCH_SOURCES core/gameconfigfile.cpp core/gamecvars.cpp core/gamecontrol.cpp + core/gamehud.cpp core/gamefuncs.cpp core/gameinput.cpp core/interpolate.cpp diff --git a/source/core/gamehud.cpp b/source/core/gamehud.cpp new file mode 100644 index 000000000..7b94b95a1 --- /dev/null +++ b/source/core/gamehud.cpp @@ -0,0 +1,139 @@ +/* +** gamehud.cpp +** +** Management of HUD elements +** +**--------------------------------------------------------------------------- +** Copyright 2019-2021 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +*/ + +#include +#include +#include "gamehud.h" +#include "textures.h" +#include "palette.h" +#include "gamecontrol.h" +#include "v_2ddrawer.h" +#include "v_video.h" +#include "build.h" +#include "v_draw.h" +#include "v_font.h" +#include "gamestruct.h" + +F2DDrawer twodpsp; + + +void hud_drawsprite(double sx, double sy, int z, double a, int picnum, int dashade, int dapalnum, int dastat, double alpha) +{ + double dz = z / 65536.; + alpha *= (dastat & RS_TRANS1)? glblend[0].def[!!(dastat & RS_TRANS2)].alpha : 1.; + int palid = TRANSLATION(Translation_Remap + curbasepal, dapalnum); + + if (picanm[picnum].sf & PICANM_ANIMTYPE_MASK) + picnum += animateoffs(picnum, 0); + + auto tex = tileGetTexture(picnum); + + DrawTexture(&twodpsp, tex, sx, sy, + DTA_ScaleX, dz, DTA_ScaleY, dz, + DTA_Color, shadeToLight(dashade), + DTA_TranslationIndex, palid, + DTA_ViewportX, windowxy1.x, DTA_ViewportY, windowxy1.y, + DTA_ViewportWidth, windowxy2.x - windowxy1.x + 1, DTA_ViewportHeight, windowxy2.y - windowxy1.y + 1, + DTA_FullscreenScale, (dastat & RS_STRETCH)? FSMode_ScaleToScreen: FSMode_ScaleToHeight, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, + DTA_CenterOffsetRel, !(dastat & (RS_TOPLEFT | RS_CENTER)), + DTA_TopLeft, !!(dastat & RS_TOPLEFT), + DTA_CenterOffset, !!(dastat & RS_CENTER), + DTA_FlipX, !!(dastat & RS_XFLIPHUD), + DTA_FlipY, !!(dastat & RS_YFLIPHUD), + DTA_Pin, (dastat & RS_ALIGN_R) ? 1 : (dastat & RS_ALIGN_L) ? -1 : 0, + DTA_Rotate, a * -BAngToDegree, + DTA_FlipOffsets, !(dastat & (/*RS_TOPLEFT |*/ RS_CENTER)), + DTA_Alpha, alpha, + TAG_DONE); +} + + +//========================================================================== +// +// DFrameBuffer :: DrawRateStuff +// +// Draws the fps counter, dot ticker, and palette debug. +// +//========================================================================== +CVAR(Bool, vid_fps, false, 0) + + +static FString statFPS() +{ + static int32_t frameCount; + static double lastFrameTime; + static double cumulativeFrameDelay; + static double lastFPS; + + FString output; + + double frameTime = I_msTimeF(); + double frameDelay = frameTime - lastFrameTime; + cumulativeFrameDelay += frameDelay; + + frameCount++; + if (frameDelay >= 0) + { + output.AppendFormat("%5.1f fps (%.1f ms)\n", lastFPS, frameDelay); + + if (cumulativeFrameDelay >= 1000.0) + { + lastFPS = 1000. * frameCount / cumulativeFrameDelay; + frameCount = 0; + cumulativeFrameDelay = 0.0; + } + } + lastFrameTime = frameTime; + return output; +} + +void DrawRateStuff() +{ + // Draws frame time and cumulative fps + if (vid_fps) + { + FString fpsbuff = statFPS(); + + int textScale = active_con_scale(twod); + int rate_x = screen->GetWidth() / textScale - NewConsoleFont->StringWidth(&fpsbuff[0]); + twod->AddColorOnlyQuad(rate_x * textScale, 0, screen->GetWidth(), NewConsoleFont->GetHeight() * textScale, MAKEARGB(255, 0, 0, 0)); + DrawText(twod, NewConsoleFont, CR_WHITE, rate_x, 0, (char*)&fpsbuff[0], + DTA_VirtualWidth, screen->GetWidth() / textScale, + DTA_VirtualHeight, screen->GetHeight() / textScale, + DTA_KeepRatio, true, TAG_DONE); + + } +} + diff --git a/source/core/gamehud.h b/source/core/gamehud.h new file mode 100644 index 000000000..56033bdd3 --- /dev/null +++ b/source/core/gamehud.h @@ -0,0 +1,8 @@ +#pragma once + +#include "v_2ddrawer.h" + +extern F2DDrawer twodpsp; + +void DrawRateStuff(); +void hud_drawsprite(double sx, double sy, int z, double a, int picnum, int dashade, int dapalnum, int dastat, double alpha = 1); diff --git a/source/core/mainloop.cpp b/source/core/mainloop.cpp index efdd496d4..1ffdc6293 100644 --- a/source/core/mainloop.cpp +++ b/source/core/mainloop.cpp @@ -88,6 +88,7 @@ #include "gamestruct.h" #include "savegamehelp.h" #include "v_draw.h" +#include "gamehud.h" CVAR(Bool, vid_activeinbackground, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, r_ticstability, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) diff --git a/source/games/blood/src/animatesprite.cpp b/source/games/blood/src/animatesprite.cpp index fb9e477a9..918e24916 100644 --- a/source/games/blood/src/animatesprite.cpp +++ b/source/games/blood/src/animatesprite.cpp @@ -38,7 +38,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "v_2ddrawer.h" #include "v_video.h" #include "v_font.h" -#include "glbackend/glbackend.h" BEGIN_BLD_NS diff --git a/source/games/blood/src/credits.cpp b/source/games/blood/src/credits.cpp index ea78f4b7b..c18453352 100644 --- a/source/games/blood/src/credits.cpp +++ b/source/games/blood/src/credits.cpp @@ -28,7 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "SmackerDecoder.h" #include "blood.h" #include "animtexture.h" -#include "../glbackend/glbackend.h" #include "raze_sound.h" #include "v_2ddrawer.h" #include "screenjob.h" diff --git a/source/games/blood/src/hudsprites.cpp b/source/games/blood/src/hudsprites.cpp index 6df0ada96..c570b115d 100644 --- a/source/games/blood/src/hudsprites.cpp +++ b/source/games/blood/src/hudsprites.cpp @@ -37,7 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "gstrings.h" #include "v_2ddrawer.h" #include "v_video.h" -#include "glbackend/glbackend.h" +#include "gamehud.h" BEGIN_BLD_NS diff --git a/source/games/blood/src/prediction.cpp b/source/games/blood/src/prediction.cpp index 5d8f877c9..156d70588 100644 --- a/source/games/blood/src/prediction.cpp +++ b/source/games/blood/src/prediction.cpp @@ -38,7 +38,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "v_2ddrawer.h" #include "v_video.h" #include "v_font.h" -#include "glbackend/glbackend.h" BEGIN_BLD_NS diff --git a/source/games/blood/src/qav.cpp b/source/games/blood/src/qav.cpp index 607a73d40..a17d24df6 100644 --- a/source/games/blood/src/qav.cpp +++ b/source/games/blood/src/qav.cpp @@ -27,7 +27,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "compat.h" #include "common_game.h" #include "v_draw.h" -#include "glbackend/glbackend.h" #include "blood.h" BEGIN_BLD_NS diff --git a/source/games/blood/src/sbar.cpp b/source/games/blood/src/sbar.cpp index fe6f16a07..952e40ab8 100644 --- a/source/games/blood/src/sbar.cpp +++ b/source/games/blood/src/sbar.cpp @@ -37,7 +37,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "v_2ddrawer.h" #include "v_video.h" #include "v_font.h" -#include "glbackend/glbackend.h" #include "statusbar.h" #include "automap.h" #include "v_draw.h" diff --git a/source/games/blood/src/view.cpp b/source/games/blood/src/view.cpp index 938156aa7..c85cd6c2f 100644 --- a/source/games/blood/src/view.cpp +++ b/source/games/blood/src/view.cpp @@ -42,7 +42,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "automap.h" #include "gamefuncs.h" #include "v_draw.h" -#include "glbackend/glbackend.h" BEGIN_BLD_NS diff --git a/source/games/duke/src/d_menu.cpp b/source/games/duke/src/d_menu.cpp index 30bcbc469..6af3e4349 100644 --- a/source/games/duke/src/d_menu.cpp +++ b/source/games/duke/src/d_menu.cpp @@ -42,7 +42,6 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms #include "mapinfo.h" #include "gamestate.h" #include "dukeactor.h" -#include "../../glbackend/glbackend.h" BEGIN_DUKE_NS diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index 8b284df75..6a23cc55f 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -38,7 +38,6 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au) #include "st_start.h" #include "i_interface.h" #include "prediction.h" -#include "glbackend/glbackend.h" #include "gamestate.h" BEGIN_DUKE_NS diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index f5ea986d9..81972423a 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -41,7 +41,6 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au) #include "i_interface.h" #include "prediction.h" #include "sbar.h" -#include "glbackend/glbackend.h" #include "gamestate.h" #include "dukeactor.h" #include "interpolate.h" diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index a8321e7d4..917bdf3f7 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -35,7 +35,6 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au) #include "mapinfo.h" #include "texturemanager.h" #include "interpolate.h" -#include "glbackend/glbackend.h" BEGIN_DUKE_NS diff --git a/source/games/duke/src/inlines.h b/source/games/duke/src/inlines.h index abdf69b7c..345633f80 100644 --- a/source/games/duke/src/inlines.h +++ b/source/games/duke/src/inlines.h @@ -1,7 +1,7 @@ #pragma once #include "mathutil.h" -#include "glbackend/glbackend.h" +#include "gamehud.h" #include "global.h" // all inline functions. diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index 42bcc0c07..e3c46670a 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -33,6 +33,7 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au) #include "automap.h" #include "dukeactor.h" #include "interpolate.h" +#include "glbackend/glbackend.h" BEGIN_DUKE_NS diff --git a/source/games/exhumed/src/d_menu.cpp b/source/games/exhumed/src/d_menu.cpp index 17fd07e4c..79061cb69 100644 --- a/source/games/exhumed/src/d_menu.cpp +++ b/source/games/exhumed/src/d_menu.cpp @@ -34,7 +34,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "vm.h" #include "razemenu.h" -#include "../../glbackend/glbackend.h" BEGIN_PS_NS diff --git a/source/games/exhumed/src/light.cpp b/source/games/exhumed/src/light.cpp index ec4a7741a..84db404ec 100644 --- a/source/games/exhumed/src/light.cpp +++ b/source/games/exhumed/src/light.cpp @@ -20,7 +20,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "exhumed.h" #include "view.h" #include "aistuff.h" -#include "../glbackend/glbackend.h" #include #include #include diff --git a/source/games/exhumed/src/sequence.cpp b/source/games/exhumed/src/sequence.cpp index 4845865ae..49e05e1c4 100644 --- a/source/games/exhumed/src/sequence.cpp +++ b/source/games/exhumed/src/sequence.cpp @@ -16,7 +16,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ //------------------------------------------------------------------------- #include "ns.h" -#include "glbackend/glbackend.h" +#include "gamehud.h" #include "sequence.h" #include "engine.h" #include "exhumed.h" diff --git a/source/games/exhumed/src/view.cpp b/source/games/exhumed/src/view.cpp index 8d3e7cf20..485a783d8 100644 --- a/source/games/exhumed/src/view.cpp +++ b/source/games/exhumed/src/view.cpp @@ -29,7 +29,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "mapinfo.h" #include "v_video.h" #include "interpolate.h" -#include "glbackend/glbackend.h" #include "v_draw.h" #include diff --git a/source/games/sw/src/d_menu.cpp b/source/games/sw/src/d_menu.cpp index 84ec2c6e6..eff540c1c 100644 --- a/source/games/sw/src/d_menu.cpp +++ b/source/games/sw/src/d_menu.cpp @@ -51,9 +51,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "v_draw.h" #include "vm.h" -#include "../../glbackend/glbackend.h" - - BEGIN_SW_NS //---------------------------------------------------------------------------- diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 915788055..74e3cc003 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -55,7 +55,6 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "v_2ddrawer.h" #include "v_video.h" #include "v_draw.h" -#include "glbackend/glbackend.h" BEGIN_SW_NS diff --git a/source/games/sw/src/jsector.cpp b/source/games/sw/src/jsector.cpp index 5f153cc4a..a44326e8f 100644 --- a/source/games/sw/src/jsector.cpp +++ b/source/games/sw/src/jsector.cpp @@ -44,7 +44,6 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "pal.h" #include "parent.h" #include "v_video.h" -#include "glbackend/glbackend.h" BEGIN_SW_NS diff --git a/source/games/sw/src/panel.cpp b/source/games/sw/src/panel.cpp index bfa72e046..5494576b0 100644 --- a/source/games/sw/src/panel.cpp +++ b/source/games/sw/src/panel.cpp @@ -37,11 +37,11 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "pal.h" #include "player.h" #include "v_2ddrawer.h" +#include "gamehud.h" #include "weapon.h" #include "razemenu.h" #include "raze_sound.h" -#include "glbackend/glbackend.h" BEGIN_SW_NS diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index b1abfbfce..a8be0093c 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -50,10 +50,10 @@ #include "hw_cvars.h" #include "gamestruct.h" #include "gl_models.h" +#include "gamehud.h" CVAR(Bool, gl_texture, true, 0) -F2DDrawer twodpsp; static int BufferLock = 0; TArray matrixArray; @@ -405,62 +405,6 @@ void renderFinishScene() } } -//========================================================================== -// -// DFrameBuffer :: DrawRateStuff -// -// Draws the fps counter, dot ticker, and palette debug. -// -//========================================================================== -CVAR(Bool, vid_fps, false, 0) - - -static FString statFPS() -{ - static int32_t frameCount; - static double lastFrameTime; - static double cumulativeFrameDelay; - static double lastFPS; - - FString output; - - double frameTime = I_msTimeF(); - double frameDelay = frameTime - lastFrameTime; - cumulativeFrameDelay += frameDelay; - - frameCount++; - if (frameDelay >= 0) - { - output.AppendFormat("%5.1f fps (%.1f ms)\n", lastFPS, frameDelay); - - if (cumulativeFrameDelay >= 1000.0) - { - lastFPS = 1000. * frameCount / cumulativeFrameDelay; - frameCount = 0; - cumulativeFrameDelay = 0.0; - } - } - lastFrameTime = frameTime; - return output; -} - -void DrawRateStuff() -{ - // Draws frame time and cumulative fps - if (vid_fps) - { - FString fpsbuff = statFPS(); - - int textScale = active_con_scale(twod); - int rate_x = screen->GetWidth() / textScale - NewConsoleFont->StringWidth(&fpsbuff[0]); - twod->AddColorOnlyQuad(rate_x * textScale, 0, screen->GetWidth(), NewConsoleFont->GetHeight() * textScale, MAKEARGB(255, 0, 0, 0)); - DrawText(twod, NewConsoleFont, CR_WHITE, rate_x, 0, (char*)&fpsbuff[0], - DTA_VirtualWidth, screen->GetWidth() / textScale, - DTA_VirtualHeight, screen->GetHeight() / textScale, - DTA_KeepRatio, true, TAG_DONE); - - } -} int32_t r_scenebrightness = 0; @@ -533,33 +477,3 @@ void precacheMarkedTiles() } } -void hud_drawsprite(double sx, double sy, int z, double a, int picnum, int dashade, int dapalnum, int dastat, double alpha) -{ - double dz = z / 65536.; - alpha *= (dastat & RS_TRANS1)? glblend[0].def[!!(dastat & RS_TRANS2)].alpha : 1.; - int palid = TRANSLATION(Translation_Remap + curbasepal, dapalnum); - - if (picanm[picnum].sf & PICANM_ANIMTYPE_MASK) - picnum += animateoffs(picnum, 0); - - auto tex = tileGetTexture(picnum); - - DrawTexture(&twodpsp, tex, sx, sy, - DTA_ScaleX, dz, DTA_ScaleY, dz, - DTA_Color, shadeToLight(dashade), - DTA_TranslationIndex, palid, - DTA_ViewportX, windowxy1.x, DTA_ViewportY, windowxy1.y, - DTA_ViewportWidth, windowxy2.x - windowxy1.x + 1, DTA_ViewportHeight, windowxy2.y - windowxy1.y + 1, - DTA_FullscreenScale, (dastat & RS_STRETCH)? FSMode_ScaleToScreen: FSMode_ScaleToHeight, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, - DTA_CenterOffsetRel, !(dastat & (RS_TOPLEFT | RS_CENTER)), - DTA_TopLeft, !!(dastat & RS_TOPLEFT), - DTA_CenterOffset, !!(dastat & RS_CENTER), - DTA_FlipX, !!(dastat & RS_XFLIPHUD), - DTA_FlipY, !!(dastat & RS_YFLIPHUD), - DTA_Pin, (dastat & RS_ALIGN_R) ? 1 : (dastat & RS_ALIGN_L) ? -1 : 0, - DTA_Rotate, a * -BAngToDegree, - DTA_FlipOffsets, !(dastat & (/*RS_TOPLEFT |*/ RS_CENTER)), - DTA_Alpha, alpha, - TAG_DONE); -} - diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index 1a74145e7..3a4f360aa 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -340,13 +340,10 @@ public: }; extern GLInstance GLInterface; -extern F2DDrawer twodpsp; void renderSetProjectionMatrix(const float* p); void renderSetViewMatrix(const float* p); void renderSetVisibility(float v); void renderBeginScene(); void renderFinishScene(); -void DrawRateStuff(); void videoShowFrame(int32_t); -void hud_drawsprite(double sx, double sy, int z, double a, int picnum, int dashade, int dapalnum, int dastat, double alpha = 1); From 9fd3ab6b5ecfd60fffe3c27e99f682babdb5afa7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Apr 2021 09:59:55 +0200 Subject: [PATCH 08/15] - fixed texture precaching. After the migration to GZDoom's full backend this never created any textureds when precaching things. --- source/CMakeLists.txt | 1 + source/build/include/build.h | 4 - source/build/src/polymost.cpp | 40 ------- source/core/precache.cpp | 133 ++++++++++++++++++++++++ source/core/precache.h | 5 + source/games/blood/src/preload.cpp | 1 + source/games/blood/src/view.cpp | 1 + source/games/duke/src/premap_d.cpp | 1 + source/games/duke/src/premap_r.cpp | 1 + source/games/exhumed/src/enginesubs.cpp | 1 + source/games/sw/src/cache.cpp | 1 + source/glbackend/glbackend.cpp | 38 ------- 12 files changed, 145 insertions(+), 82 deletions(-) create mode 100644 source/core/precache.cpp create mode 100644 source/core/precache.h diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index c4109c07d..11f382b2f 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -1061,6 +1061,7 @@ set (PCH_SOURCES core/secrets.cpp core/compositesavegame.cpp core/savegamehelp.cpp + core/precache.cpp core/quotes.cpp core/screenshot.cpp core/raze_music.cpp diff --git a/source/build/include/build.h b/source/build/include/build.h index 5accd465f..027be46bb 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -664,7 +664,6 @@ typedef struct s_equation void renderSetRollAngle(float rolla); #endif -void PrecacheHardwareTextures(int nTile); void Polymost_Startup(); typedef uint16_t polytintflags_t; @@ -842,9 +841,6 @@ extern int32_t rintersect(int32_t x1, int32_t y1, int32_t z1, int32_t x3, int32_t y3, int32_t x4, int32_t y4, int32_t *intx, int32_t *inty, int32_t *intz); -void markTileForPrecache(int tilenum, int palnum); -void precacheMarkedTiles(); - extern int32_t(*animateoffs_replace)(int const tilenum, int fakevar); extern int32_t(*getpalookup_replace)(int32_t davis, int32_t dashade); extern void(*initspritelists_replace)(void); diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 496edb870..a4b04a143 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -99,7 +99,6 @@ static int32_t r_parallaxskyclamping = 1; #define Bfabsf fabsf static int32_t drawingskybox = 0; -static int32_t hicprecaching = 0; static hitdata_t polymost_hitdata; @@ -3543,45 +3542,6 @@ _drawsprite_return: static_assert((int)RS_YFLIP == (int)HUDFLAG_FLIPPED); -void polymost_precache(int32_t dapicnum, int32_t dapalnum, int32_t datype) -{ - // dapicnum and dapalnum are like you'd expect - // datype is 0 for a wall/floor/ceiling and 1 for a sprite - // basically this just means walls are repeating - // while sprites are clamped - - if ((dapalnum < (MAXPALOOKUPS - RESERVEDPALS)) && (!lookups.checkTable(dapalnum))) return;//dapalnum = 0; - - //Printf("precached %d %d type %d\n", dapicnum, dapalnum, datype); - hicprecaching = 1; - int palid = TRANSLATION(Translation_Remap + curbasepal, dapalnum); - auto tex = tileGetTexture(dapicnum); - if (tex->isValid()) - GLInterface.SetTexture(tex, palid, CLAMP_NONE); - hicprecaching = 0; - - if (datype == 0 || !hw_models) return; - - int const mid = md_tilehasmodel(dapicnum, dapalnum); - - if (mid < 0 || models[mid]->mdnum < 2) return; - - int const surfaces = (models[mid]->mdnum == 3) ? ((md3model_t *)models[mid])->head.numsurfs : 0; - - for (int i = 0; i <= surfaces; i++) - { - auto tex = mdloadskin((md2model_t *)models[mid], 0, dapalnum, i, nullptr); - int palid = TRANSLATION(Translation_Remap + curbasepal, dapalnum); - if (tex) GLInterface.SetTexture(tex, palid, CLAMP_NONE); - } -} - -void PrecacheHardwareTextures(int nTile) -{ - // PRECACHE - // This really *really* needs improvement on the game side - the entire precaching logic has no clue about the different needs of a hardware renderer. - polymost_precache(nTile, 0, 1); -} extern char* voxfilenames[MAXVOXELS]; void (*PolymostProcessVoxels_Callback)(void) = NULL; diff --git a/source/core/precache.cpp b/source/core/precache.cpp new file mode 100644 index 000000000..3341630e5 --- /dev/null +++ b/source/core/precache.cpp @@ -0,0 +1,133 @@ +/* +** precache.cpp +** +** +** +**--------------------------------------------------------------------------- +** Copyright 2019-2021 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +*/ + +#include "build.h" +#include "palette.h" +#include "v_video.h" +#include "hw_material.h" +#include "glbackend/gl_models.h" + +static void PrecacheTex(FGameTexture* tex, int palid) +{ + if (!tex || !tex->isValid()) return; + int scaleflags = 0; + if (shouldUpscale(tex, UF_Texture)) scaleflags |= CTF_Upscale; + + auto mat = FMaterial::ValidateTexture(tex, scaleflags); + screen->PrecacheMaterial(mat, palid); +} + +static void doprecache(int32_t dapicnum, int32_t dapalnum, int32_t datype) +{ + // dapicnum and dapalnum are like you'd expect + // datype is 0 for a wall/floor/ceiling and 1 for a sprite + // basically this just means walls are repeating + // while sprites are clamped + + if ((dapalnum < (MAXPALOOKUPS - RESERVEDPALS)) && (!lookups.checkTable(dapalnum))) return;//dapalnum = 0; + + //Printf("precached %d %d type %d\n", dapicnum, dapalnum, datype); + int palid = TRANSLATION(Translation_Remap + curbasepal, dapalnum); + auto tex = tileGetTexture(dapicnum); + PrecacheTex(tex, palid); + + if (datype == 0 || !hw_models) return; + + int const mid = md_tilehasmodel(dapicnum, dapalnum); + + if (mid < 0 || models[mid]->mdnum < 2) + { + int vox = tiletovox[dapicnum]; + if (vox != -1 && voxmodels[vox] && voxmodels[vox]->model) + { + FHWModelRenderer mr(*screen->RenderState(), 0); + voxmodels[vox]->model->BuildVertexBuffer(&mr); + } + return; + } + + int const surfaces = (models[mid]->mdnum == 3) ? ((md3model_t *)models[mid])->head.numsurfs : 0; + + for (int i = 0; i <= surfaces; i++) + { + auto tex = mdloadskin((md2model_t *)models[mid], 0, dapalnum, i, nullptr); + int palid = TRANSLATION(Translation_Remap + curbasepal, dapalnum); + if (tex) PrecacheTex(tex, palid); + } +} + +void PrecacheHardwareTextures(int nTile) +{ + // PRECACHE + // This really *really* needs improvement on the game side - the entire precaching logic has no clue about the different needs of a hardware renderer. + doprecache(nTile, 0, 1); +} + + +TMap cachemap; + +void markTileForPrecache(int tilenum, int palnum) +{ + int i, j; + if ((picanm[tilenum].sf & PICANM_ANIMTYPE_MASK) == PICANM_ANIMTYPE_BACK) + { + i = tilenum - picanm[tilenum].num; + j = tilenum; + } + else + { + i = tilenum; + j = tilenum + picanm[tilenum].num; + } + + for (; i <= j; i++) + { + int64_t val = i + (int64_t(palnum) << 32); + cachemap.Insert(val, true); + } +} + +void precacheMarkedTiles() +{ + decltype(cachemap)::Iterator it(cachemap); + decltype(cachemap)::Pair* pair; + while (it.NextPair(pair)) + { + int dapicnum = pair->Key & 0x7fffffff; + int dapalnum = pair->Key >> 32; + doprecache(dapicnum, dapalnum, 0); + } +} + diff --git a/source/core/precache.h b/source/core/precache.h new file mode 100644 index 000000000..30c6cea27 --- /dev/null +++ b/source/core/precache.h @@ -0,0 +1,5 @@ +#pragma once + +void PrecacheHardwareTextures(int nTile); +void markTileForPrecache(int tilenum, int palnum); +void precacheMarkedTiles(); diff --git a/source/games/blood/src/preload.cpp b/source/games/blood/src/preload.cpp index 5c998974e..4c0e0661d 100644 --- a/source/games/blood/src/preload.cpp +++ b/source/games/blood/src/preload.cpp @@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "blood.h" #include "view.h" #include "g_input.h" +#include "precache.h" BEGIN_BLD_NS diff --git a/source/games/blood/src/view.cpp b/source/games/blood/src/view.cpp index c85cd6c2f..16e6e8c24 100644 --- a/source/games/blood/src/view.cpp +++ b/source/games/blood/src/view.cpp @@ -42,6 +42,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "automap.h" #include "gamefuncs.h" #include "v_draw.h" +#include "precache.h" BEGIN_BLD_NS diff --git a/source/games/duke/src/premap_d.cpp b/source/games/duke/src/premap_d.cpp index e07263069..a3a67e6ea 100644 --- a/source/games/duke/src/premap_d.cpp +++ b/source/games/duke/src/premap_d.cpp @@ -37,6 +37,7 @@ source as it is released. #include "build.h" #include "names_d.h" #include "dukeactor.h" +#include "precache.h" BEGIN_DUKE_NS diff --git a/source/games/duke/src/premap_r.cpp b/source/games/duke/src/premap_r.cpp index 196d6d052..5ff71c275 100644 --- a/source/games/duke/src/premap_r.cpp +++ b/source/games/duke/src/premap_r.cpp @@ -31,6 +31,7 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms #include "names_r.h" #include "mapinfo.h" #include "dukeactor.h" +#include "precache.h" BEGIN_DUKE_NS diff --git a/source/games/exhumed/src/enginesubs.cpp b/source/games/exhumed/src/enginesubs.cpp index e896bd2be..6f64dcefb 100644 --- a/source/games/exhumed/src/enginesubs.cpp +++ b/source/games/exhumed/src/enginesubs.cpp @@ -17,6 +17,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. //------------------------------------------------------------------------- #include "ns.h" #include "engine.h" +#include "precache.h" //#include //#include diff --git a/source/games/sw/src/cache.cpp b/source/games/sw/src/cache.cpp index 654025157..10cec872d 100644 --- a/source/games/sw/src/cache.cpp +++ b/source/games/sw/src/cache.cpp @@ -40,6 +40,7 @@ not load" error messages. #include "misc.h" #include "sounds.h" #include "network.h" +#include "precache.h" BEGIN_SW_NS diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index a8be0093c..1e2ee04ac 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -439,41 +439,3 @@ void videoShowFrame(int32_t w) twod->Clear(); } } - -TMap cachemap; - -void markTileForPrecache(int tilenum, int palnum) -{ - int i, j; - if ((picanm[tilenum].sf & PICANM_ANIMTYPE_MASK) == PICANM_ANIMTYPE_BACK) - { - i = tilenum - picanm[tilenum].num; - j = tilenum; - } - else - { - i = tilenum; - j = tilenum + picanm[tilenum].num; - } - - for (; i <= j; i++) - { - int64_t val = i + (int64_t(palnum) << 32); - cachemap.Insert(val, true); - } -} - -void polymost_precache(int32_t dapicnum, int32_t dapalnum, int32_t datype); - -void precacheMarkedTiles() -{ - decltype(cachemap)::Iterator it(cachemap); - decltype(cachemap)::Pair* pair; - while (it.NextPair(pair)) - { - int dapicnum = pair->Key & 0x7fffffff; - int dapalnum = pair->Key >> 32; - polymost_precache(dapicnum, dapalnum, 0); - } -} - From 387c62d584c92c57e6e5dcdadc6b405159ddff42 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Apr 2021 10:20:52 +0200 Subject: [PATCH 09/15] - rewrote SW's precaching code. * made it palette aware * use backend facilities to track precached data. * fixes bug in animation precaching loops - they only precached the base index over and over again. --- source/games/sw/src/cache.cpp | 828 ++++++++++++++++----------------- source/games/sw/src/game.cpp | 3 - source/games/sw/src/misc.h | 3 - source/games/sw/src/save.cpp | 1 - source/games/sw/src/sprite.cpp | 3 - 5 files changed, 392 insertions(+), 446 deletions(-) diff --git a/source/games/sw/src/cache.cpp b/source/games/sw/src/cache.cpp index 10cec872d..0f290f9f1 100644 --- a/source/games/sw/src/cache.cpp +++ b/source/games/sw/src/cache.cpp @@ -48,488 +48,444 @@ BEGIN_SW_NS // It will save out the tile and sound number every time one caches. // // sw -map $bullet -cacheprint > foofile -extern bool PreCaching; -void PreCacheTable(short table[], int num); -void PreCacheGhost(void); - -void -SetupPreCache(void) +void PreCacheRange(int start_pic, int end_pic, int pal = 0) { - if (PreCaching) - { - precache(); - - - // actors cache ranges are called from SpriteSetup - // only caches the actor if its on the level - - // weapons - PreCacheRange(2000, 2227); - PreCacheRange(4090, 4093); - // Explosions - PreCacheRange(3072, 3225); - // ninja player character - PreCacheRange(1024, 1175); - // console - PreCacheRange(2380, 2409); - PreCacheRange(3600, 3645); - PreCacheRange(2434, 2435); - // common - PreCacheRange(204, 208); - // message font - PreCacheRange(4608, 4701); - // gibs - PreCacheRange(1150,1568); - PreCacheRange(1685,1690); - PreCacheRange(900,944); - PreCacheRange(1670,1681); - // blood - PreCacheRange(1710,1715); - PreCacheRange(2410,2425); - PreCacheRange(389,389); // blood puddle by itself in art file - PreCacheRange(2500,2503); - // shrap - PreCacheRange(3840,3911); - PreCacheRange(3924,3947); - PreCacheRange(1397,1398); - // water *** animated tiles, can be deleted now *** - // PreCacheRange(780,794); - // switches - PreCacheRange(561,584); - PreCacheRange(551,552); - PreCacheRange(1846,1847); - PreCacheRange(1850,1859); - // bullet smoke - PreCacheRange(1748,1753); - // small blue font - PreCacheRange(2930,3023); - // gas can - PreCacheRange(3038,3042); - // lava *** animated tiles, can be deleted now *** - // PreCacheRange(175,182); - // gas clouds & teleport effect - PreCacheRange(3240,3277); - // nuke mushroom cloud - PreCacheRange(3280,3300); - // blood drops - PreCacheRange(1718,1721); - // smoke - PreCacheRange(3948,3968); - // footprints - PreCacheRange(2490,2492); - // player fists - PreCacheRange(4070,4077); - PreCacheRange(4050,4051); - PreCacheRange(4090,4093); - // fish actor - PreCacheRange(3760,3771); - PreCacheRange(3780,3795); - // coins - PreCacheRange(2531,2533); - // respawn markers & console keys - PreCacheRange(2440,2467); - // light/torch sprites - PreCacheRange(537,548); - PreCacheRange(521,528); - PreCacheRange(512,515); - PreCacheRange(396,399); - PreCacheRange(443,446); - // bubbles - PreCacheRange(716,720); - // bullet splashes - PreCacheRange(772,776); - } -} - -void PreCacheRipper(void) -{ - PreCacheRange(1580, 1644); -} - -void PreCacheRipper2(void) -{ - PreCacheRange(4320, 4427); -} - -void PreCacheCoolie(void) -{ - PreCacheGhost(); - PreCacheRange(1400, 1440); - PreCacheRange(4260, 4276); // coolie explode -} - -void PreCacheGhost(void) -{ - PreCacheRange(4277, 4312); -} - -void PreCacheSerpent(void) -{ - PreCacheRange(960, 1016); - PreCacheRange(1300, 1314); -} - -void PreCacheGuardian(void) -{ - PreCacheRange(1469,1497); -} - -void PreCacheNinja(void) -{ - PreCacheRange(4096, 4239); -} - -void PreCacheNinjaGirl(void) -{ - PreCacheRange(5162, 5260); -} - -void PreCacheSumo(void) -{ - PreCacheRange(4490, 4544); -} - -void PreCacheZilla(void) -{ - PreCacheRange(4490, 4544); -} - -void PreCacheEel(void) -{ - PreCacheRange(4430, 4479); -} - -void PreCacheToiletGirl(void) -{ - PreCacheRange(5023, 5027); -} - -void PreCacheWashGirl(void) -{ - PreCacheRange(5032, 5035); -} - -void PreCacheCarGirl(void) -{ - PreCacheRange(4594,4597); -} - -void PreCacheMechanicGirl(void) -{ - PreCacheRange(4590,4593); -} - -void PreCacheSailorGirl(void) -{ - PreCacheRange(4600,4602); -} - -void PreCachePruneGirl(void) -{ - PreCacheRange(4604,4604); -} - -void PreCacheTrash(void) -{ - PreCacheRange(2540, 2546); -} - -void PreCacheBunny(void) -{ - PreCacheRange(4550, 4584); -} - -void PreCacheSkel(void) -{ - PreCacheRange(1320, 1396); -} - -void PreCacheHornet(void) -{ - PreCacheRange(800, 811); -} - -void PreCacheSkull(void) -{ - PreCacheRange(820, 854); -} - -void PreCacheBetty(void) -{ - PreCacheRange(817, 819); -} - -void PreCachePachinko(void) -{ - PreCacheRange(618,623); - PreCacheRange(618,623); - PreCacheRange(4768,4790); - PreCacheRange(4792,4814); - PreCacheRange(4816,4838); - PreCacheRange(4840,4863); -} - -void -PreCacheTable(short table[], int num) -{ - short j; - - for (j = 0; j < num; j++) - { - SET(gotpic[table[j]>>3], 1<<(table[j]&7)); - } -} - -void -PreCacheRange(short start_pic, short end_pic) -{ - short j; - - for (j = start_pic; j <= end_pic; j++) - { - SET(gotpic[j>>3], 1<<(j&7)); - } + for (int j = start_pic; j <= end_pic; j++) + { + markTileForPrecache(j, pal); + } } void PreCacheOverride(void) { - int i; + int i; + StatIterator it(STAT_CEILING_FLOOR_PIC_OVERRIDE); + while ((i = it.NextIndex()) >= 0) + { + int j = SPRITE_TAG2(i); + if(j >= 0 && j <= MAXTILES) + markTileForPrecache(j, 0); + } +} - StatIterator it(STAT_CEILING_FLOOR_PIC_OVERRIDE); - while ((i = it.NextIndex()) >= 0) - { - ASSERT(SPRITE_TAG2(i) >= 0 && SPRITE_TAG2(i) <= MAXTILES); - SET_GOTPIC(SPRITE_TAG2(i)); - } +void precacheMap(void) +{ + int i; + int j; + SECTORp sectp; + WALLp wp; + SPRITEp sp; + + for (sectp = sector; sectp < §or[numsectors]; sectp++) + { + j = sectp->ceilingpicnum; + markTileForPrecache(j, sectp->ceilingpal); + + if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT) + { + for (i = 1; i <= picanm[j].num; i++) + { + markTileForPrecache(j + i, sectp->ceilingpal); + } + } + + j = sectp->floorpicnum; + + markTileForPrecache(j, sectp->floorpal); + + if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT) + { + for (i = 1; i <= picanm[j].num; i++) + { + markTileForPrecache(j + i, sectp->floorpal); + } + } + + } + + for (wp = wall; wp < &wall[numwalls]; wp++) + { + j = wp->picnum; + + markTileForPrecache(j, wp->pal); + + if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT) + { + for (i = 1; i <= picanm[j].num; i++) + { + markTileForPrecache(j + i, wp->pal); + } + } + + if (wp->overpicnum > 0 && wp->overpicnum < MAXTILES) + { + j = wp->overpicnum; + markTileForPrecache(j, wp->pal); + + if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT) + { + for (i = 1; i <= picanm[j].num; i++) + { + markTileForPrecache(j + i, wp->pal); + } + } + } + } +} + +void SetupPreCache(void) +{ + precacheMap(); + + + // actors cache ranges are called from SpriteSetup + // only caches the actor if its on the level + + // weapons + PreCacheRange(2000, 2227); + PreCacheRange(4090, 4093); + // Explosions + PreCacheRange(3072, 3225); + // ninja player character + PreCacheRange(1024, 1175); + // console + PreCacheRange(2380, 2409); + PreCacheRange(3600, 3645); + PreCacheRange(2434, 2435); + // common + PreCacheRange(204, 208); + // message font + PreCacheRange(4608, 4701); + // gibs + PreCacheRange(1150,1568); + PreCacheRange(1685,1690); + PreCacheRange(900,944); + PreCacheRange(1670,1681); + // blood + PreCacheRange(1710,1715); + PreCacheRange(2410,2425); + PreCacheRange(389,389); // blood puddle by itself in art file + PreCacheRange(2500,2503); + // shrap + PreCacheRange(3840,3911); + PreCacheRange(3924,3947); + PreCacheRange(1397,1398); + // water *** animated tiles, can be deleted now *** + // PreCacheRange(780,794); + // switches + PreCacheRange(561,584); + PreCacheRange(551,552); + PreCacheRange(1846,1847); + PreCacheRange(1850,1859); + // bullet smoke + PreCacheRange(1748,1753); + // gas can + PreCacheRange(3038,3042); + // lava *** animated tiles, can be deleted now *** + // PreCacheRange(175,182); + // gas clouds & teleport effect + PreCacheRange(3240,3277); + // nuke mushroom cloud + PreCacheRange(3280,3300); + // blood drops + PreCacheRange(1718,1721); + // smoke + PreCacheRange(3948,3968); + // footprints + PreCacheRange(2490,2492); + // player fists + PreCacheRange(4070,4077); + PreCacheRange(4050,4051); + PreCacheRange(4090,4093); + // fish actor + PreCacheRange(3760,3771); + PreCacheRange(3780,3795); + // coins + PreCacheRange(2531,2533); + // respawn markers & console keys + PreCacheRange(2440,2467); + // light/torch sprites + PreCacheRange(537,548); + PreCacheRange(521,528); + PreCacheRange(512,515); + PreCacheRange(396,399); + PreCacheRange(443,446); + // bubbles + PreCacheRange(716,720); + // bullet splashes + PreCacheRange(772,776); +} + +void PreCacheRipper(int pal) +{ + PreCacheRange(1580, 1644, pal); +} + +void PreCacheRipper2(int pal) +{ + PreCacheRange(4320, 4427, pal); +} + +void PreCacheGhost(int pal) +{ + PreCacheRange(4277, 4312, pal); +} + +void PreCacheCoolie(int pal) +{ + PreCacheGhost(pal); + PreCacheRange(1400, 1440, pal); + PreCacheRange(4260, 4276, pal); // coolie explode +} + +void PreCacheSerpent(int pal) +{ + PreCacheRange(960, 1016, pal); + PreCacheRange(1300, 1314, pal); +} + +void PreCacheGuardian(int pal) +{ + PreCacheRange(1469,1497, pal); +} + +void PreCacheNinja(int pal) +{ + PreCacheRange(4096, 4239, pal); +} + +void PreCacheNinjaGirl(int pal) +{ + PreCacheRange(5162, 5260, pal); +} + +void PreCacheSumo(int pal) +{ + PreCacheRange(4490, 4544, pal); +} + +void PreCacheZilla(int pal) +{ + PreCacheRange(4490, 4544, pal); +} + +void PreCacheEel(int pal) +{ + PreCacheRange(4430, 4479, pal); +} + +void PreCacheToiletGirl(int pal) +{ + PreCacheRange(5023, 5027, pal); +} + +void PreCacheWashGirl(int pal) +{ + PreCacheRange(5032, 5035, pal); +} + +void PreCacheCarGirl(int pal) +{ + PreCacheRange(4594,4597, pal); +} + +void PreCacheMechanicGirl(int pal) +{ + PreCacheRange(4590,4593, pal); +} + +void PreCacheSailorGirl(int pal) +{ + PreCacheRange(4600,4602, pal); +} + +void PreCachePruneGirl(int pal) +{ + PreCacheRange(4604,4604, pal); +} + +void PreCacheTrash(int pal) +{ + PreCacheRange(2540, 2546, pal); +} + +void PreCacheBunny(int pal) +{ + PreCacheRange(4550, 4584, pal); +} + +void PreCacheSkel(int pal) +{ + PreCacheRange(1320, 1396, pal); +} + +void PreCacheHornet(int pal) +{ + PreCacheRange(800, 811, pal); +} + +void PreCacheSkull(int pal) +{ + PreCacheRange(820, 854, pal); +} + +void PreCacheBetty(int pal) +{ + PreCacheRange(817, 819, pal); +} + +void PreCachePachinko(int pal) +{ + PreCacheRange(618,623, pal); + PreCacheRange(618,623, pal); + PreCacheRange(4768,4790, pal); + PreCacheRange(4792,4814, pal); + PreCacheRange(4816,4838, pal); + PreCacheRange(4840,4863, pal); } void PreCacheActor(void) { - int i; - short pic; + int i; + int pic; - for (i=0; i < MAXSPRITES; i++) - { - if (sprite[i].statnum >= MAXSTATUS) - continue; + for (i=0; i < MAXSPRITES; i++) + { + if (sprite[i].statnum >= MAXSTATUS) + continue; - if (User[i]) - pic = User[i]->ID; - else - pic = sprite[i].picnum; + if (User[i]) + pic = User[i]->ID; + else + pic = sprite[i].picnum; - switch (pic) - { - case COOLIE_RUN_R0: - PreCacheCoolie(); - break; + switch (pic) + { + case COOLIE_RUN_R0: + PreCacheCoolie(sprite[i].pal); + break; - case NINJA_RUN_R0: - case NINJA_CRAWL_R0: - PreCacheNinja(); - break; + case NINJA_RUN_R0: + case NINJA_CRAWL_R0: + PreCacheNinja(sprite[i].pal); + break; - case GORO_RUN_R0: - PreCacheGuardian(); - break; + case GORO_RUN_R0: + PreCacheGuardian(sprite[i].pal); + break; - case 1441: - case COOLG_RUN_R0: - PreCacheGhost(); - break; + case 1441: + case COOLG_RUN_R0: + PreCacheGhost(sprite[i].pal); + break; - case EEL_RUN_R0: - PreCacheEel(); - break; + case EEL_RUN_R0: + PreCacheEel(sprite[i].pal); + break; - case SUMO_RUN_R0: - PreCacheZilla(); - break; + case SUMO_RUN_R0: + PreCacheZilla(sprite[i].pal); + break; - case ZILLA_RUN_R0: - PreCacheSumo(); - break; + case ZILLA_RUN_R0: + PreCacheSumo(sprite[i].pal); + break; - case TOILETGIRL_R0: - PreCacheToiletGirl(); - break; + case TOILETGIRL_R0: + PreCacheToiletGirl(sprite[i].pal); + break; - case WASHGIRL_R0: - PreCacheWashGirl(); - break; + case WASHGIRL_R0: + PreCacheWashGirl(sprite[i].pal); + break; - case CARGIRL_R0: - PreCacheCarGirl(); - break; + case CARGIRL_R0: + PreCacheCarGirl(sprite[i].pal); + break; - case MECHANICGIRL_R0: - PreCacheMechanicGirl(); - break; + case MECHANICGIRL_R0: + PreCacheMechanicGirl(sprite[i].pal); + break; - case SAILORGIRL_R0: - PreCacheSailorGirl(); - break; + case SAILORGIRL_R0: + PreCacheSailorGirl(sprite[i].pal); + break; - case PRUNEGIRL_R0: - PreCachePruneGirl(); - break; + case PRUNEGIRL_R0: + PreCachePruneGirl(sprite[i].pal); + break; - case TRASHCAN: - PreCacheTrash(); - break; + case TRASHCAN: + PreCacheTrash(sprite[i].pal); + break; - case BUNNY_RUN_R0: - PreCacheBunny(); - break; + case BUNNY_RUN_R0: + PreCacheBunny(sprite[i].pal); + break; - case RIPPER_RUN_R0: - PreCacheRipper(); - break; + case RIPPER_RUN_R0: + PreCacheRipper(sprite[i].pal); + break; - case RIPPER2_RUN_R0: - PreCacheRipper2(); - break; + case RIPPER2_RUN_R0: + PreCacheRipper2(sprite[i].pal); + break; - case SERP_RUN_R0: - PreCacheSerpent(); - break; + case SERP_RUN_R0: + PreCacheSerpent(sprite[i].pal); + break; - case LAVA_RUN_R0: - break; + case LAVA_RUN_R0: + break; - case SKEL_RUN_R0: - PreCacheSkel(); - break; + case SKEL_RUN_R0: + PreCacheSkel(sprite[i].pal); + break; - case HORNET_RUN_R0: - PreCacheHornet(); - break; + case HORNET_RUN_R0: + PreCacheHornet(sprite[i].pal); + break; - case SKULL_R0: - PreCacheSkull(); - break; + case SKULL_R0: + PreCacheSkull(sprite[i].pal); + break; - case BETTY_R0: - PreCacheBetty(); - break; + case BETTY_R0: + PreCacheBetty(sprite[i].pal); + break; - case GIRLNINJA_RUN_R0: - PreCacheNinjaGirl(); - break; + case GIRLNINJA_RUN_R0: + PreCacheNinjaGirl(sprite[i].pal); + break; - case 623: // Pachinko win light - case PACHINKO1: - case PACHINKO2: - case PACHINKO3: - case PACHINKO4: - PreCachePachinko(); - break; - } - } + case 623: // Pachinko win light + case PACHINKO1: + case PACHINKO2: + case PACHINKO3: + case PACHINKO4: + PreCachePachinko(sprite[i].pal); + break; + + default: + markTileForPrecache(pic, sprite[i].pal); + } + } } void DoTheCache(void) { - int i, cnt=0; - - PreCacheActor(); - PreCacheOverride(); - - for (i = 0; i < MAXTILES; i++) - { - if ((TEST(gotpic[i>>3], 1<<(i&7))) && (!tilePtr(i))) - { - // Without palettes this is rather useless... - if (r_precache) PrecacheHardwareTextures(i); - cnt++; - } - } - - memset(gotpic,0,sizeof(gotpic)); + if (r_precache) + { + SetupPreCache(); + PreCacheActor(); + PreCacheOverride(); + precacheMarkedTiles(); + } } -void -precache(void) -{ - int i; - short j; - SECTORp sectp; - WALLp wp; - SPRITEp sp; - - memset(gotpic,0,sizeof(gotpic)); - - for (sectp = sector; sectp < §or[numsectors]; sectp++) - { - j = sectp->ceilingpicnum; - - SET(gotpic[j>>3], 1<<(j&7)); - - if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT) - { - for (i = 1; i <= picanm[j].num; i++) - { - SET(gotpic[(j+i)>>3], 1<<((j+i)&7)); - } - } - - j = sectp->floorpicnum; - - SET(gotpic[j>>3], 1<<(j&7)); - - if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT) - { - for (i = 1; i <= picanm[j].num; i++) - { - SET(gotpic[(j+i)>>3], 1<<((j+i)&7)); - } - } - - } - - for (wp = wall; wp < &wall[numwalls]; wp++) - { - j = wp->picnum; - - SET(gotpic[j>>3], 1<<(j&7)); - - if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT) - { - for (i = 1; i <= picanm[j].num; i++) - { - SET(gotpic[(j+i)>>3], 1<<((j+i)&7)); - } - } - - if (wp->overpicnum > 0 && wp->overpicnum < MAXTILES) - { - j = wp->overpicnum; - SET(gotpic[j>>3], 1<<(j&7)); - - if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT) - { - for (i = 1; i <= picanm[j].num; i++) - { - SET(gotpic[(j+i)>>3], 1<<((j+i)&7)); - } - } - - } - } - - for (sp = sprite; sp < &sprite[MAXSPRITES]; sp++) - { - if (sp->statnum < MAXSTATUS) - { - j = sp->picnum; - - SET(gotpic[j>>3], 1<<(j&7)); - } - } -} END_SW_NS diff --git a/source/games/sw/src/game.cpp b/source/games/sw/src/game.cpp index 50583459a..064cfc44f 100644 --- a/source/games/sw/src/game.cpp +++ b/source/games/sw/src/game.cpp @@ -106,7 +106,6 @@ bool NewGame = false; bool FinishedLevel = false; short screenpeek = 0; -bool PreCaching = true; int GodMode = false; short Skill = 2; short TotalKillable; @@ -363,8 +362,6 @@ void InitLevel(MapRecord *maprec) STAT_NewLevel(currentLevel->fileName); Player[0].angle.ang = buildang(ang); - SetupPreCache(); - if (sector[0].extra != -1) { NormalVisibility = g_visibility = sector[0].extra; diff --git a/source/games/sw/src/misc.h b/source/games/sw/src/misc.h index 6a8052575..00d518286 100644 --- a/source/games/sw/src/misc.h +++ b/source/games/sw/src/misc.h @@ -11,10 +11,7 @@ enum CACHE_SOUND_PLAY =1 }; -void SetupPreCache(void); -void PreCacheRange(short start_pic, short end_pic); void DoTheCache(void); -void precache(void); void InitCheats(); diff --git a/source/games/sw/src/save.cpp b/source/games/sw/src/save.cpp index 39f4d62e4..6feeff775 100644 --- a/source/games/sw/src/save.cpp +++ b/source/games/sw/src/save.cpp @@ -990,7 +990,6 @@ bool GameInterface::LoadGame() } #endif - SetupPreCache(); DoTheCache(); // this is ok - just duplicating sector list with pointers diff --git a/source/games/sw/src/sprite.cpp b/source/games/sw/src/sprite.cpp index 4a6002369..3eb4309e3 100644 --- a/source/games/sw/src/sprite.cpp +++ b/source/games/sw/src/sprite.cpp @@ -1187,9 +1187,6 @@ ActorSpawn(SPRITEp sp) case 1441: case COOLG_RUN_R0: { - - //PreCacheGhost(); - if (!ActorTestSpawn(sp)) { KillSprite(SpriteNum); From e4cf768fa8d3bd158e5f3268d1c856a67f46ed8f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Apr 2021 10:50:04 +0200 Subject: [PATCH 10/15] - call StartPrecaching to keep Vulkan happy. --- source/core/precache.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/source/core/precache.cpp b/source/core/precache.cpp index 3341630e5..4423f51ab 100644 --- a/source/core/precache.cpp +++ b/source/core/precache.cpp @@ -121,6 +121,7 @@ void markTileForPrecache(int tilenum, int palnum) void precacheMarkedTiles() { + screen->StartPrecaching(); decltype(cachemap)::Iterator it(cachemap); decltype(cachemap)::Pair* pair; while (it.NextPair(pair)) From d663d8459687f99c4c48ef46a13180248f5749f1 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Apr 2021 10:54:10 +0200 Subject: [PATCH 11/15] - changed precaching setup for Exhumed. This looks overly simplistic - I doubt it's enough to catch everything. --- source/games/exhumed/src/enginesubs.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/source/games/exhumed/src/enginesubs.cpp b/source/games/exhumed/src/enginesubs.cpp index 6f64dcefb..7223f822e 100644 --- a/source/games/exhumed/src/enginesubs.cpp +++ b/source/games/exhumed/src/enginesubs.cpp @@ -34,11 +34,6 @@ void resettiming() lastTic = -1; } -void doTileLoad(int i) -{ - if (r_precache) PrecacheHardwareTextures(i); -} - void precache() { int i; @@ -46,15 +41,15 @@ void precache() for (i = 0; i < numsectors; i++) { short j = sector[i].ceilingpicnum; - doTileLoad(j); + markTileForPrecache(j, sector[i].ceilingpal); j = sector[i].floorpicnum; - doTileLoad(j); + markTileForPrecache(j, sector[i].floorpal); } for (i = 0; i < numwalls; i++) { short j = wall[i].picnum; - doTileLoad(j); + markTileForPrecache(j, wall[i].pal); } for (i = 0; i < kMaxSprites; i++) @@ -62,8 +57,9 @@ void precache() if (sprite[i].statnum < kMaxStatus) { short j = sprite[i].picnum; - doTileLoad(j); + markTileForPrecache(j, sprite[i].pal); } } + precacheMarkedTiles(); } END_PS_NS From 63429268710e865e8cae13e71df20cf3d8a8b0d7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Apr 2021 12:10:52 +0200 Subject: [PATCH 12/15] - disabled the QAV preload calls in Blood. Aside from not having been functional, this is ultimately more harmful than useful as it forces loading of a large number of textures at the same time during gameplay instead of spreading them out. --- source/games/blood/src/d_menu.cpp | 2 +- source/games/blood/src/misc.h | 1 - source/games/blood/src/nnexts.cpp | 2 +- source/games/blood/src/player.cpp | 2 +- source/games/blood/src/preload.cpp | 46 ------------------------------ source/games/blood/src/qav.cpp | 12 -------- source/games/blood/src/qav.h | 1 - source/games/blood/src/seq.cpp | 10 ------- source/games/blood/src/seq.h | 1 - source/games/blood/src/view.cpp | 5 ---- source/games/blood/src/weapon.cpp | 2 +- 11 files changed, 4 insertions(+), 80 deletions(-) diff --git a/source/games/blood/src/d_menu.cpp b/source/games/blood/src/d_menu.cpp index 39c305268..8db9fc494 100644 --- a/source/games/blood/src/d_menu.cpp +++ b/source/games/blood/src/d_menu.cpp @@ -69,7 +69,7 @@ CGameMenuItemQAV::CGameMenuItemQAV(int a3, int a4, const char* name, bool widesc data->nSprite = -1; data->x = m_nX; data->y = m_nY; - data->Preload(); + //data->Preload(); duration = data->duration; lastTick = I_GetBuildTime(); } diff --git a/source/games/blood/src/misc.h b/source/games/blood/src/misc.h index 0e5b404e7..09ce772d8 100644 --- a/source/games/blood/src/misc.h +++ b/source/games/blood/src/misc.h @@ -124,7 +124,6 @@ extern int nPrecacheCount; int tileInit(char a1, const char *a2); void tileProcessGLVoxels(void); -void tilePreloadTile(int nTile); void tilePrecacheTile(int nTile, int nType, HitList& hits); char tileGetSurfType(int hit); diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index f90fb1199..a708623e0 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -1326,7 +1326,7 @@ void trPlayerCtrlStartScene(XSPRITE* pXSource, PLAYER* pPlayer, bool force) { pCtrl->qavScene.qavResrc = pQav; pCtrl->qavScene.dummy = -1; - pCtrl->qavScene.qavResrc->Preload(); + //pCtrl->qavScene.qavResrc->Preload(); pPlayer->sceneQav = pXSource->data2; pPlayer->weaponTimer = pCtrl->qavScene.qavResrc->duration; diff --git a/source/games/blood/src/player.cpp b/source/games/blood/src/player.cpp index 28ae4aec8..3fd2f6aae 100644 --- a/source/games/blood/src/player.cpp +++ b/source/games/blood/src/player.cpp @@ -2319,7 +2319,7 @@ void SerializePlayers(FSerializer& arc) if (pQav) { gPlayerCtrl[i].qavScene.qavResrc = pQav; - gPlayerCtrl[i].qavScene.qavResrc->Preload(); + //gPlayerCtrl[i].qavScene.qavResrc->Preload(); } else { diff --git a/source/games/blood/src/preload.cpp b/source/games/blood/src/preload.cpp index 4c0e0661d..f64f5521f 100644 --- a/source/games/blood/src/preload.cpp +++ b/source/games/blood/src/preload.cpp @@ -36,52 +36,6 @@ void fxPrecache(HitList &hits); void gibPrecache(HitList &hits); -void tilePreloadTile(int nTile) -{ - if (!r_precache) return; - int n = 1; - switch (picanm[nTile].extra & 7) - { - case 0: - n = 1; - break; - case 1: - n = 5; - break; - case 2: - n = 8; - break; - case 3: - n = 2; - break; - case 6: - case 7: - if (voxelIndex[nTile] < 0 || voxelIndex[nTile] >= kMaxVoxels) - { - voxelIndex[nTile] = -1; - picanm[nTile].extra &= ~7; - } - break; - } - - while (n--) - { - if (picanm[nTile].sf & PICANM_ANIMTYPE_MASK) - { - for (int frame = picanm[nTile].num; frame >= 0; frame--) - { - if ((picanm[nTile].sf & PICANM_ANIMTYPE_MASK) == PICANM_ANIMTYPE_BACK) - PrecacheHardwareTextures(nTile - frame); - else - PrecacheHardwareTextures(nTile + frame); - } - } - else - PrecacheHardwareTextures(nTile); - nTile += 1 + picanm[nTile].num; - } -} - void tilePrecacheTile(int nTile, int nType, HitList &hits) { int n = 1; diff --git a/source/games/blood/src/qav.cpp b/source/games/blood/src/qav.cpp index a17d24df6..fab15a288 100644 --- a/source/games/blood/src/qav.cpp +++ b/source/games/blood/src/qav.cpp @@ -146,18 +146,6 @@ void QAV::Play(int start, int end, int nCallback, void *pData) } } -void QAV::Preload(void) -{ - for (int i = 0; i < nFrames; i++) - { - for (int j = 0; j < 8; j++) - { - if (frames[i].tiles[j].picnum >= 0) - tilePreloadTile(frames[i].tiles[j].picnum); - } - } -} - void QAV::Precache(HitList &hits) { for (int i = 0; i < nFrames; i++) diff --git a/source/games/blood/src/qav.h b/source/games/blood/src/qav.h index d858a042b..07062c67e 100644 --- a/source/games/blood/src/qav.h +++ b/source/games/blood/src/qav.h @@ -82,7 +82,6 @@ struct QAV void Draw(int ticks, int stat, int shade, int palnum, bool in3dscene); void Draw(double x, double y, int ticks, int stat, int shade, int palnum, bool in3dscene); void Play(int, int, int, void *); - void Preload(void); void Precache(HitList &hits); }; diff --git a/source/games/blood/src/seq.cpp b/source/games/blood/src/seq.cpp index ddbb583a2..7ea06fbdf 100644 --- a/source/games/blood/src/seq.cpp +++ b/source/games/blood/src/seq.cpp @@ -102,16 +102,6 @@ static void (*seqClientCallback[])(int, DBloodActor*) = { // //--------------------------------------------------------------------------- -void Seq::Preload(void) -{ - if (memcmp(signature, "SEQ\x1a", 4) != 0) - I_Error("Invalid sequence"); - if ((version & 0xff00) != 0x300) - I_Error("Obsolete sequence version"); - for (int i = 0; i < nFrames; i++) - tilePreloadTile(seqGetTile(&frames[i])); -} - void Seq::Precache(HitList& hits) { if (memcmp(signature, "SEQ\x1a", 4) != 0) diff --git a/source/games/blood/src/seq.h b/source/games/blood/src/seq.h index 538f460e9..481431c11 100644 --- a/source/games/blood/src/seq.h +++ b/source/games/blood/src/seq.h @@ -59,7 +59,6 @@ struct Seq { short soundId; int flags; SEQFRAME frames[1]; - void Preload(void); void Precache(HitList&); bool isLooping() diff --git a/source/games/blood/src/view.cpp b/source/games/blood/src/view.cpp index 16e6e8c24..28cc22f62 100644 --- a/source/games/blood/src/view.cpp +++ b/source/games/blood/src/view.cpp @@ -132,10 +132,6 @@ void viewDrawText(int nFont, const char *pString, int x, int y, int nShade, int } -void InitStatusBar(void) -{ - if (r_precache) PrecacheHardwareTextures(2200); -} GameStats GameInterface::getStats() { return { gKillMgr.Kills, gKillMgr.TotalKills, gSecretMgr.Founds, gSecretMgr.Total, gFrameCount / kTicsPerSec, gPlayer[myconnectindex].fragCount }; @@ -168,7 +164,6 @@ extern int dword_172CE0[16][3]; void viewInit(void) { Printf("Initializing status bar\n"); - InitStatusBar(); FontSet(0, 4096, 0); FontSet(1, 4192, 1); FontSet(2, 4288, 1); diff --git a/source/games/blood/src/weapon.cpp b/source/games/blood/src/weapon.cpp index 130074dd5..b720fbb80 100644 --- a/source/games/blood/src/weapon.cpp +++ b/source/games/blood/src/weapon.cpp @@ -302,7 +302,7 @@ static void StartQAV(PLAYER *pPlayer, int nWeaponQAV, int callback, bool looped pPlayer->weaponTimer = weaponQAV[nWeaponQAV]->duration; pPlayer->qavCallback = callback; pPlayer->qavLoop = looped; - weaponQAV[nWeaponQAV]->Preload(); + //weaponQAV[nWeaponQAV]->Preload(); WeaponPlay(pPlayer); pPlayer->weaponTimer -= 4; } From 32250f704fc956b9ae235d6d96fd87079686590f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Apr 2021 12:42:59 +0200 Subject: [PATCH 13/15] - mograted Blood's precaching to the backend's implementation. --- source/games/blood/src/fx.cpp | 6 +- source/games/blood/src/gib.cpp | 4 +- source/games/blood/src/misc.h | 6 +- source/games/blood/src/preload.cpp | 256 +++++++++++++---------------- source/games/blood/src/qav.cpp | 4 +- source/games/blood/src/qav.h | 2 +- source/games/blood/src/seq.cpp | 8 +- source/games/blood/src/seq.h | 4 +- source/games/blood/src/weapon.cpp | 4 +- 9 files changed, 134 insertions(+), 160 deletions(-) diff --git a/source/games/blood/src/fx.cpp b/source/games/blood/src/fx.cpp index b78946a40..9ee8ec4fe 100644 --- a/source/games/blood/src/fx.cpp +++ b/source/games/blood/src/fx.cpp @@ -345,13 +345,13 @@ void fxSpawnEjectingShell(spritetype *pSprite, int z, int a3, int a4) } } -void fxPrecache(HitList &hits) +void fxPrecache() { for (int i = 0; i < kFXMax; i++) { - tilePrecacheTile(gFXData[i].at12, 0, hits); + tilePrecacheTile(gFXData[i].at12, 0, 0); if (gFXData[i].at2) - seqPrecacheId(gFXData[i].at2, hits); + seqPrecacheId(gFXData[i].at2, 0); } } diff --git a/source/games/blood/src/gib.cpp b/source/games/blood/src/gib.cpp index 449c6da8b..4e4f68264 100644 --- a/source/games/blood/src/gib.cpp +++ b/source/games/blood/src/gib.cpp @@ -501,7 +501,7 @@ void GibWall(int nWall, GIBTYPE nGibType, CGibVelocity *pVel) } } -void gibPrecache(HitList &hits) +void gibPrecache() { for (int i = 0; i < kGibMax; i++) { @@ -511,7 +511,7 @@ void gibPrecache(HitList &hits) for (int j = 0; j < gibList[i].atc; j++) { if (pThing[j].Kills >= 0) - tilePrecacheTile(pThing[j].Kills, -1, hits); + tilePrecacheTile(pThing[j].Kills, -1, 0); } } } diff --git a/source/games/blood/src/misc.h b/source/games/blood/src/misc.h index 09ce772d8..0a2ad62fa 100644 --- a/source/games/blood/src/misc.h +++ b/source/games/blood/src/misc.h @@ -27,8 +27,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS -using HitList = FixedBitArray; - void playlogos(); unsigned int qrand(void); int wrand(void); @@ -56,7 +54,7 @@ char WeaponUpgrade(PLAYER *pPlayer, char newWeapon); void WeaponProcess(PLAYER *pPlayer); void WeaponUpdateState(PLAYER* pPlayer); void teslaHit(spritetype *pMissile, int a2); -void WeaponPrecache(HitList &hits); +void WeaponPrecache(); struct ZONE { int x, y, z; @@ -124,7 +122,7 @@ extern int nPrecacheCount; int tileInit(char a1, const char *a2); void tileProcessGLVoxels(void); -void tilePrecacheTile(int nTile, int nType, HitList& hits); +void tilePrecacheTile(int nTile, int nType, int palette); char tileGetSurfType(int hit); diff --git a/source/games/blood/src/preload.cpp b/source/games/blood/src/preload.cpp index f64f5521f..06e6703d6 100644 --- a/source/games/blood/src/preload.cpp +++ b/source/games/blood/src/preload.cpp @@ -32,11 +32,11 @@ BEGIN_BLD_NS int nPrecacheCount; -void fxPrecache(HitList &hits); -void gibPrecache(HitList &hits); +void fxPrecache(); +void gibPrecache(); -void tilePrecacheTile(int nTile, int nType, HitList &hits) +void tilePrecacheTile(int nTile, int nType, int palette) { int n = 1; switch (picanm[nTile].extra & 7) @@ -65,20 +65,13 @@ void tilePrecacheTile(int nTile, int nType, HitList &hits) tile = nTile - frame; else tile = nTile + frame; - if (!hits[tile]) - { - nPrecacheCount++; - hits.Set(tile); - } + + markTileForPrecache(tile, palette); } } else { - if (!hits[nTile]) - { - nPrecacheCount++; - hits.Set(nTile); - } + markTileForPrecache(nTile, palette); } nTile += 1 + picanm[nTile].num; } @@ -87,34 +80,34 @@ void tilePrecacheTile(int nTile, int nType, HitList &hits) // To do: This needs to handle the sprite palettes as well to properly precache the needed content. -void viewPrecacheTiles(HitList &hits) +void viewPrecacheTiles() { - tilePrecacheTile(2173, 0, hits); - tilePrecacheTile(2200, 0, hits); - tilePrecacheTile(2201, 0, hits); - tilePrecacheTile(2202, 0, hits); - tilePrecacheTile(2207, 0, hits); - tilePrecacheTile(2208, 0, hits); - tilePrecacheTile(2209, 0, hits); - tilePrecacheTile(2229, 0, hits); - tilePrecacheTile(2260, 0, hits); - tilePrecacheTile(2559, 0, hits); - tilePrecacheTile(2169, 0, hits); - tilePrecacheTile(2578, 0, hits); - tilePrecacheTile(2586, 0, hits); - tilePrecacheTile(2602, 0, hits); + tilePrecacheTile(2173, 0, 0); + tilePrecacheTile(2200, 0, 0); + tilePrecacheTile(2201, 0, 0); + tilePrecacheTile(2202, 0, 0); + tilePrecacheTile(2207, 0, 0); + tilePrecacheTile(2208, 0, 0); + tilePrecacheTile(2209, 0, 0); + tilePrecacheTile(2229, 0, 0); + tilePrecacheTile(2260, 0, 0); + tilePrecacheTile(2559, 0, 0); + tilePrecacheTile(2169, 0, 0); + tilePrecacheTile(2578, 0, 0); + tilePrecacheTile(2586, 0, 0); + tilePrecacheTile(2602, 0, 0); for (int i = 0; i < 10; i++) { - tilePrecacheTile(2190 + i, 0, hits); - tilePrecacheTile(2230 + i, 0, hits); - tilePrecacheTile(2240 + i, 0, hits); - tilePrecacheTile(2250 + i, 0, hits); - tilePrecacheTile(kSBarNumberHealth + i, 0, hits); - tilePrecacheTile(kSBarNumberAmmo + i, 0, hits); - tilePrecacheTile(kSBarNumberInv + i, 0, hits); - tilePrecacheTile(kSBarNumberArmor1 + i, 0, hits); - tilePrecacheTile(kSBarNumberArmor2 + i, 0, hits); - tilePrecacheTile(kSBarNumberArmor3 + i, 0, hits); + tilePrecacheTile(2190 + i, 0, 0); + tilePrecacheTile(2230 + i, 0, 0); + tilePrecacheTile(2240 + i, 0, 0); + tilePrecacheTile(2250 + i, 0, 0); + tilePrecacheTile(kSBarNumberHealth + i, 0, 0); + tilePrecacheTile(kSBarNumberAmmo + i, 0, 0); + tilePrecacheTile(kSBarNumberInv + i, 0, 0); + tilePrecacheTile(kSBarNumberArmor1 + i, 0, 0); + tilePrecacheTile(kSBarNumberArmor2 + i, 0, 0); + tilePrecacheTile(kSBarNumberArmor3 + i, 0, 0); } /* for (int i = 0; i < 5; i++) @@ -125,54 +118,55 @@ void viewPrecacheTiles(HitList &hits) */ for (int i = 0; i < 6; i++) { - tilePrecacheTile(2220 + i, 0, hits); - tilePrecacheTile(2552 + i, 0, hits); + tilePrecacheTile(2220 + i, 0, 0); + tilePrecacheTile(2552 + i, 0, 0); } } -void PrecacheDude(spritetype *pSprite, HitList &hits) +void PrecacheDude(spritetype *pSprite) { + int palette = pSprite->pal; DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type); - seqPrecacheId(pDudeInfo->seqStartID , hits); - seqPrecacheId(pDudeInfo->seqStartID+5, hits); - seqPrecacheId(pDudeInfo->seqStartID+1, hits); - seqPrecacheId(pDudeInfo->seqStartID+2, hits); + seqPrecacheId(pDudeInfo->seqStartID , palette); + seqPrecacheId(pDudeInfo->seqStartID+5, palette); + seqPrecacheId(pDudeInfo->seqStartID+1, palette); + seqPrecacheId(pDudeInfo->seqStartID+2, palette); switch (pSprite->type) { case kDudeCultistTommy: case kDudeCultistShotgun: case kDudeCultistTesla: case kDudeCultistTNT: - seqPrecacheId(pDudeInfo->seqStartID+6 , hits); - seqPrecacheId(pDudeInfo->seqStartID+7 , hits); - seqPrecacheId(pDudeInfo->seqStartID+8 , hits); - seqPrecacheId(pDudeInfo->seqStartID+9 , hits); - seqPrecacheId(pDudeInfo->seqStartID+13, hits); - seqPrecacheId(pDudeInfo->seqStartID+14, hits); - seqPrecacheId(pDudeInfo->seqStartID+15, hits); + seqPrecacheId(pDudeInfo->seqStartID+6 , palette); + seqPrecacheId(pDudeInfo->seqStartID+7 , palette); + seqPrecacheId(pDudeInfo->seqStartID+8 , palette); + seqPrecacheId(pDudeInfo->seqStartID+9 , palette); + seqPrecacheId(pDudeInfo->seqStartID+13, palette); + seqPrecacheId(pDudeInfo->seqStartID+14, palette); + seqPrecacheId(pDudeInfo->seqStartID+15, palette); break; case kDudeZombieButcher: case kDudeGillBeast: - seqPrecacheId(pDudeInfo->seqStartID+6, hits); - seqPrecacheId(pDudeInfo->seqStartID+7, hits); - seqPrecacheId(pDudeInfo->seqStartID+8, hits); - seqPrecacheId(pDudeInfo->seqStartID+9, hits); - seqPrecacheId(pDudeInfo->seqStartID+10, hits); - seqPrecacheId(pDudeInfo->seqStartID+11, hits); + seqPrecacheId(pDudeInfo->seqStartID+6, palette); + seqPrecacheId(pDudeInfo->seqStartID+7, palette); + seqPrecacheId(pDudeInfo->seqStartID+8, palette); + seqPrecacheId(pDudeInfo->seqStartID+9, palette); + seqPrecacheId(pDudeInfo->seqStartID+10, palette); + seqPrecacheId(pDudeInfo->seqStartID+11, palette); break; case kDudeGargoyleStatueFlesh: case kDudeGargoyleStatueStone: - seqPrecacheId(pDudeInfo->seqStartID+6, hits); - seqPrecacheId(pDudeInfo->seqStartID+6, hits); //??? + seqPrecacheId(pDudeInfo->seqStartID+6, palette); + seqPrecacheId(pDudeInfo->seqStartID+6, palette); //??? fallthrough__; case kDudeGargoyleFlesh: case kDudeGargoyleStone: - seqPrecacheId(pDudeInfo->seqStartID+6, hits); - seqPrecacheId(pDudeInfo->seqStartID+7, hits); - seqPrecacheId(pDudeInfo->seqStartID+8, hits); - seqPrecacheId(pDudeInfo->seqStartID+9, hits); + seqPrecacheId(pDudeInfo->seqStartID+6, palette); + seqPrecacheId(pDudeInfo->seqStartID+7, palette); + seqPrecacheId(pDudeInfo->seqStartID+8, palette); + seqPrecacheId(pDudeInfo->seqStartID+9, palette); break; case kDudePhantasm: case kDudeHellHound: @@ -181,88 +175,89 @@ void PrecacheDude(spritetype *pSprite, HitList &hits) case kDudeSpiderBlack: case kDudeSpiderMother: case kDudeTchernobog: - seqPrecacheId(pDudeInfo->seqStartID+6, hits); - seqPrecacheId(pDudeInfo->seqStartID+7, hits); - seqPrecacheId(pDudeInfo->seqStartID+8, hits); + seqPrecacheId(pDudeInfo->seqStartID+6, palette); + seqPrecacheId(pDudeInfo->seqStartID+7, palette); + seqPrecacheId(pDudeInfo->seqStartID+8, palette); break; case kDudeCerberusTwoHead: - seqPrecacheId(pDudeInfo->seqStartID+6, hits); - seqPrecacheId(pDudeInfo->seqStartID+7, hits); + seqPrecacheId(pDudeInfo->seqStartID+6, palette); + seqPrecacheId(pDudeInfo->seqStartID+7, palette); fallthrough__; case kDudeHand: case kDudeBoneEel: case kDudeBat: case kDudeRat: - seqPrecacheId(pDudeInfo->seqStartID+6, hits); - seqPrecacheId(pDudeInfo->seqStartID+7, hits); + seqPrecacheId(pDudeInfo->seqStartID+6, palette); + seqPrecacheId(pDudeInfo->seqStartID+7, palette); break; case kDudeCultistBeast: - seqPrecacheId(pDudeInfo->seqStartID+6, hits); + seqPrecacheId(pDudeInfo->seqStartID+6, palette); break; case kDudeZombieAxeBuried: - seqPrecacheId(pDudeInfo->seqStartID+12, hits); - seqPrecacheId(pDudeInfo->seqStartID+9, hits); + seqPrecacheId(pDudeInfo->seqStartID+12, palette); + seqPrecacheId(pDudeInfo->seqStartID+9, palette); fallthrough__; case kDudeZombieAxeLaying: - seqPrecacheId(pDudeInfo->seqStartID+10, hits); + seqPrecacheId(pDudeInfo->seqStartID+10, palette); fallthrough__; case kDudeZombieAxeNormal: - seqPrecacheId(pDudeInfo->seqStartID+6, hits); - seqPrecacheId(pDudeInfo->seqStartID+7, hits); - seqPrecacheId(pDudeInfo->seqStartID+8, hits); - seqPrecacheId(pDudeInfo->seqStartID+11, hits); - seqPrecacheId(pDudeInfo->seqStartID+13, hits); - seqPrecacheId(pDudeInfo->seqStartID+14, hits); + seqPrecacheId(pDudeInfo->seqStartID+6, palette); + seqPrecacheId(pDudeInfo->seqStartID+7, palette); + seqPrecacheId(pDudeInfo->seqStartID+8, palette); + seqPrecacheId(pDudeInfo->seqStartID+11, palette); + seqPrecacheId(pDudeInfo->seqStartID+13, palette); + seqPrecacheId(pDudeInfo->seqStartID+14, palette); break; } } -void PrecacheThing(spritetype *pSprite, HitList &hits) { +void PrecacheThing(spritetype *pSprite) +{ + int palette = pSprite->pal; switch (pSprite->type) { case kThingGlassWindow: // worthless... case kThingFluorescent: - seqPrecacheId(12, hits); + seqPrecacheId(12, palette); break; case kThingSpiderWeb: - seqPrecacheId(15, hits); + seqPrecacheId(15, palette); break; case kThingMetalGrate: - seqPrecacheId(21, hits); + seqPrecacheId(21, palette); break; case kThingFlammableTree: - seqPrecacheId(25, hits); - seqPrecacheId(26, hits); + seqPrecacheId(25, palette); + seqPrecacheId(26, palette); break; case kTrapMachinegun: - seqPrecacheId(38, hits); - seqPrecacheId(40, hits); - seqPrecacheId(28, hits); + seqPrecacheId(38, palette); + seqPrecacheId(40, palette); + seqPrecacheId(28, palette); break; case kThingObjectGib: //case kThingObjectExplode: weird that only gib object is precached and this one is not break; } - tilePrecacheTile(pSprite->picnum, -1, hits); + tilePrecacheTile(pSprite->picnum, -1, palette); } -void PreloadTiles(HitList & hits) +void PreloadCache() { - nPrecacheCount = 0; + if (!r_precache) return; int skyTile = -1; - hits.Zero(); // Fonts for (int i = 0; i < numsectors; i++) { - tilePrecacheTile(sector[i].floorpicnum, 0, hits); - tilePrecacheTile(sector[i].ceilingpicnum, 0, hits); + tilePrecacheTile(sector[i].floorpicnum, 0, sector[i].floorpal); + tilePrecacheTile(sector[i].ceilingpicnum, 0, sector[i].ceilingpal); if ((sector[i].ceilingstat&1) != 0 && skyTile == -1) skyTile = sector[i].ceilingpicnum; } for (int i = 0; i < numwalls; i++) { - tilePrecacheTile(wall[i].picnum, 0, hits); + tilePrecacheTile(wall[i].picnum, 0, wall[i].pal); if (wall[i].overpicnum >= 0) - tilePrecacheTile(wall[i].overpicnum, 0, hits); + tilePrecacheTile(wall[i].overpicnum, 0, wall[i].pal); } for (int i = 0; i < kMaxSprites; i++) { @@ -272,13 +267,13 @@ void PreloadTiles(HitList & hits) switch (pSprite->statnum) { case kStatDude: - PrecacheDude(pSprite, hits); + PrecacheDude(pSprite); break; case kStatThing: - PrecacheThing(pSprite, hits); + PrecacheThing(pSprite); break; default: - tilePrecacheTile(pSprite->picnum, -1, hits); + tilePrecacheTile(pSprite->picnum, -1, pSprite->pal); break; } } @@ -287,57 +282,38 @@ void PreloadTiles(HitList & hits) // Precache common SEQs for (int i = 0; i < 100; i++) { - seqPrecacheId(i, hits); + seqPrecacheId(i, 0); } - tilePrecacheTile(1147, -1, hits); // water drip - tilePrecacheTile(1160, -1, hits); // blood drip + tilePrecacheTile(1147, -1, 0); // water drip + tilePrecacheTile(1160, -1, 0); // blood drip // Player SEQs - seqPrecacheId(dudeInfo[31].seqStartID+6, hits); - seqPrecacheId(dudeInfo[31].seqStartID+7, hits); - seqPrecacheId(dudeInfo[31].seqStartID+8, hits); - seqPrecacheId(dudeInfo[31].seqStartID+9, hits); - seqPrecacheId(dudeInfo[31].seqStartID+10, hits); - seqPrecacheId(dudeInfo[31].seqStartID+14, hits); - seqPrecacheId(dudeInfo[31].seqStartID+15, hits); - seqPrecacheId(dudeInfo[31].seqStartID+12, hits); - seqPrecacheId(dudeInfo[31].seqStartID+16, hits); - seqPrecacheId(dudeInfo[31].seqStartID+17, hits); - seqPrecacheId(dudeInfo[31].seqStartID+18, hits); + seqPrecacheId(dudeInfo[31].seqStartID+6, 0); + seqPrecacheId(dudeInfo[31].seqStartID+7, 0); + seqPrecacheId(dudeInfo[31].seqStartID+8, 0); + seqPrecacheId(dudeInfo[31].seqStartID+9, 0); + seqPrecacheId(dudeInfo[31].seqStartID+10, 0); + seqPrecacheId(dudeInfo[31].seqStartID+14, 0); + seqPrecacheId(dudeInfo[31].seqStartID+15, 0); + seqPrecacheId(dudeInfo[31].seqStartID+12, 0); + seqPrecacheId(dudeInfo[31].seqStartID+16, 0); + seqPrecacheId(dudeInfo[31].seqStartID+17, 0); + seqPrecacheId(dudeInfo[31].seqStartID+18, 0); if (skyTile > -1 && skyTile < kMaxTiles) { for (int i = 1; i < gSkyCount; i++) - tilePrecacheTile(skyTile+i, 0, hits); + tilePrecacheTile(skyTile+i, 0, 0); } - WeaponPrecache(hits); - viewPrecacheTiles(hits); - fxPrecache(hits); - gibPrecache(hits); + WeaponPrecache(); + viewPrecacheTiles(); + fxPrecache(); + gibPrecache(); I_GetEvent(); -} - -void PreloadCache() -{ - if (!r_precache) return; - HitList hits; - PreloadTiles(hits); - int cnt = 0; - int percentDisplayed = -1; - - for (int i = 0; i < kMaxTiles; i++) - { - if (hits[i]) - { - PrecacheHardwareTextures(i); - - if ((++cnt & 7) == 0) - I_GetEvent(); - } - } + precacheMarkedTiles(); } END_BLD_NS diff --git a/source/games/blood/src/qav.cpp b/source/games/blood/src/qav.cpp index fab15a288..3194b30cd 100644 --- a/source/games/blood/src/qav.cpp +++ b/source/games/blood/src/qav.cpp @@ -146,14 +146,14 @@ void QAV::Play(int start, int end, int nCallback, void *pData) } } -void QAV::Precache(HitList &hits) +void QAV::Precache(int palette) { for (int i = 0; i < nFrames; i++) { for (int j = 0; j < 8; j++) { if (frames[i].tiles[j].picnum >= 0) - tilePrecacheTile(frames[i].tiles[j].picnum, 0, hits); + tilePrecacheTile(frames[i].tiles[j].picnum, 0, palette); } } } diff --git a/source/games/blood/src/qav.h b/source/games/blood/src/qav.h index 07062c67e..8b73ca51c 100644 --- a/source/games/blood/src/qav.h +++ b/source/games/blood/src/qav.h @@ -82,7 +82,7 @@ struct QAV void Draw(int ticks, int stat, int shade, int palnum, bool in3dscene); void Draw(double x, double y, int ticks, int stat, int shade, int palnum, bool in3dscene); void Play(int, int, int, void *); - void Precache(HitList &hits); + void Precache(int palette = 0); }; #pragma pack(pop) diff --git a/source/games/blood/src/seq.cpp b/source/games/blood/src/seq.cpp index 7ea06fbdf..7024d25ea 100644 --- a/source/games/blood/src/seq.cpp +++ b/source/games/blood/src/seq.cpp @@ -102,20 +102,20 @@ static void (*seqClientCallback[])(int, DBloodActor*) = { // //--------------------------------------------------------------------------- -void Seq::Precache(HitList& hits) +void Seq::Precache(int palette) { if (memcmp(signature, "SEQ\x1a", 4) != 0) I_Error("Invalid sequence"); if ((version & 0xff00) != 0x300) I_Error("Obsolete sequence version"); for (int i = 0; i < nFrames; i++) - tilePrecacheTile(seqGetTile(&frames[i]), -1, hits); + tilePrecacheTile(seqGetTile(&frames[i]), -1, palette); } -void seqPrecacheId(int id, HitList& hits) +void seqPrecacheId(int id, int palette) { auto pSeq = getSequence(id); - if (pSeq) pSeq->Precache(hits); + if (pSeq) pSeq->Precache(palette); } //--------------------------------------------------------------------------- diff --git a/source/games/blood/src/seq.h b/source/games/blood/src/seq.h index 481431c11..724f5b081 100644 --- a/source/games/blood/src/seq.h +++ b/source/games/blood/src/seq.h @@ -59,7 +59,7 @@ struct Seq { short soundId; int flags; SEQFRAME frames[1]; - void Precache(HitList&); + void Precache(int palette); bool isLooping() { @@ -96,7 +96,7 @@ inline int seqGetTile(SEQFRAME* pFrame) } int seqRegisterClient(void(*pClient)(int, int)); -void seqPrecacheId(int id, HitList& hits); +void seqPrecacheId(int id, int palette); SEQINST* GetInstance(int a1, int a2); void UnlockInstance(SEQINST* pInst); void seqSpawn(int a1, int a2, int a3, int a4 = -1); diff --git a/source/games/blood/src/weapon.cpp b/source/games/blood/src/weapon.cpp index b720fbb80..8e168f2ff 100644 --- a/source/games/blood/src/weapon.cpp +++ b/source/games/blood/src/weapon.cpp @@ -237,12 +237,12 @@ void WeaponInit(void) } } -void WeaponPrecache(HitList &hits) +void WeaponPrecache() { for (int i = 0; i < kQAVEnd; i++) { if (weaponQAV[i]) - weaponQAV[i]->Precache(hits); + weaponQAV[i]->Precache(); } } From e5e23cd63c6dd644a61d6b3c8ce498bd506bea5f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Apr 2021 13:19:48 +0200 Subject: [PATCH 14/15] - make sure voxels are being precached. In Blood's case it also needs to check the game-side array to find everything. --- source/core/precache.cpp | 51 +++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/source/core/precache.cpp b/source/core/precache.cpp index 4423f51ab..0a4bc0b58 100644 --- a/source/core/precache.cpp +++ b/source/core/precache.cpp @@ -32,13 +32,19 @@ **--------------------------------------------------------------------------- ** */ - +#include "ns.h" #include "build.h" #include "palette.h" #include "v_video.h" #include "hw_material.h" +#include "gamestruct.h" +#include "gamecontrol.h" #include "glbackend/gl_models.h" +BEGIN_BLD_NS +extern short voxelIndex[MAXTILES]; +END_BLD_NS + static void PrecacheTex(FGameTexture* tex, int palid) { if (!tex || !tex->isValid()) return; @@ -49,31 +55,29 @@ static void PrecacheTex(FGameTexture* tex, int palid) screen->PrecacheMaterial(mat, palid); } -static void doprecache(int32_t dapicnum, int32_t dapalnum, int32_t datype) +static void doprecache(int picnum, int palette) { - // dapicnum and dapalnum are like you'd expect - // datype is 0 for a wall/floor/ceiling and 1 for a sprite - // basically this just means walls are repeating - // while sprites are clamped + if ((palette < (MAXPALOOKUPS - RESERVEDPALS)) && (!lookups.checkTable(palette))) return; - if ((dapalnum < (MAXPALOOKUPS - RESERVEDPALS)) && (!lookups.checkTable(dapalnum))) return;//dapalnum = 0; - - //Printf("precached %d %d type %d\n", dapicnum, dapalnum, datype); - int palid = TRANSLATION(Translation_Remap + curbasepal, dapalnum); - auto tex = tileGetTexture(dapicnum); + int palid = TRANSLATION(Translation_Remap + curbasepal, palette); + auto tex = tileGetTexture(picnum); PrecacheTex(tex, palid); - if (datype == 0 || !hw_models) return; + if (!hw_models) return; - int const mid = md_tilehasmodel(dapicnum, dapalnum); + int const mid = md_tilehasmodel(picnum, palette); if (mid < 0 || models[mid]->mdnum < 2) { - int vox = tiletovox[dapicnum]; - if (vox != -1 && voxmodels[vox] && voxmodels[vox]->model) + if (r_voxels) { - FHWModelRenderer mr(*screen->RenderState(), 0); - voxmodels[vox]->model->BuildVertexBuffer(&mr); + int vox = tiletovox[picnum]; + if (vox == -1 && isBlood()) vox = Blood::voxelIndex[picnum]; + if (vox != -1 && voxmodels[vox] && voxmodels[vox]->model) + { + FHWModelRenderer mr(*screen->RenderState(), 0); + voxmodels[vox]->model->BuildVertexBuffer(&mr); + } } return; } @@ -82,19 +86,12 @@ static void doprecache(int32_t dapicnum, int32_t dapalnum, int32_t datype) for (int i = 0; i <= surfaces; i++) { - auto tex = mdloadskin((md2model_t *)models[mid], 0, dapalnum, i, nullptr); - int palid = TRANSLATION(Translation_Remap + curbasepal, dapalnum); + auto tex = mdloadskin((md2model_t *)models[mid], 0, palette, i, nullptr); + int palid = TRANSLATION(Translation_Remap + curbasepal, palette); if (tex) PrecacheTex(tex, palid); } } -void PrecacheHardwareTextures(int nTile) -{ - // PRECACHE - // This really *really* needs improvement on the game side - the entire precaching logic has no clue about the different needs of a hardware renderer. - doprecache(nTile, 0, 1); -} - TMap cachemap; @@ -128,7 +125,7 @@ void precacheMarkedTiles() { int dapicnum = pair->Key & 0x7fffffff; int dapalnum = pair->Key >> 32; - doprecache(dapicnum, dapalnum, 0); + doprecache(dapicnum, dapalnum); } } From 0ee28fb45ea1fdee9cdff11632851c2c3b1fc0c1 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Apr 2021 13:38:23 +0200 Subject: [PATCH 15/15] - also handle SW's voxels. --- source/build/src/polymost.cpp | 2 +- source/core/gamestruct.h | 2 +- source/core/precache.cpp | 4 +++- source/core/precache.h | 1 + source/games/sw/src/game.cpp | 4 ++-- source/games/sw/src/game.h | 8 ++++---- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index a4b04a143..4901b8155 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -2202,7 +2202,7 @@ void polymost_scansector(int32_t sectnum) { if ((spr->cstat&(64+48))!=(64+16) || (r_voxels && tiletovox[spr->picnum] >= 0 && voxmodels[tiletovox[spr->picnum]]) || - (r_voxels && gi->Voxelize(spr->picnum)) || + (r_voxels && gi->Voxelize(spr->picnum) > -1) || DMulScale(bcos(spr->ang), -s.x, bsin(spr->ang), -s.y, 6) > 0) if (renderAddTsprite(z, sectnum)) break; diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index 664c878d3..f6a0dd697 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -101,7 +101,7 @@ struct GameInterface virtual int chaseCamX(binangle ang) { return 0; } virtual int chaseCamY(binangle ang) { return 0; } virtual int chaseCamZ(fixedhoriz horiz) { return 0; } - virtual bool Voxelize(int sprnum) { return false; } + virtual int Voxelize(int sprnum) { return -1; } virtual FString statFPS() { diff --git a/source/core/precache.cpp b/source/core/precache.cpp index 0a4bc0b58..ed660c7cd 100644 --- a/source/core/precache.cpp +++ b/source/core/precache.cpp @@ -72,8 +72,9 @@ static void doprecache(int picnum, int palette) if (r_voxels) { int vox = tiletovox[picnum]; + if (vox == -1) vox = gi->Voxelize(picnum); if (vox == -1 && isBlood()) vox = Blood::voxelIndex[picnum]; - if (vox != -1 && voxmodels[vox] && voxmodels[vox]->model) + if (vox >= 0 && vox < MAXVOXELS && voxmodels[vox] && voxmodels[vox]->model) { FHWModelRenderer mr(*screen->RenderState(), 0); voxmodels[vox]->model->BuildVertexBuffer(&mr); @@ -127,5 +128,6 @@ void precacheMarkedTiles() int dapalnum = pair->Key >> 32; doprecache(dapicnum, dapalnum); } + cachemap.Clear(); } diff --git a/source/core/precache.h b/source/core/precache.h index 30c6cea27..bcf40813f 100644 --- a/source/core/precache.h +++ b/source/core/precache.h @@ -2,4 +2,5 @@ void PrecacheHardwareTextures(int nTile); void markTileForPrecache(int tilenum, int palnum); +void markVoxelForPrecache(int voxnum); void precacheMarkedTiles(); diff --git a/source/games/sw/src/game.cpp b/source/games/sw/src/game.cpp index 064cfc44f..e77e64f6c 100644 --- a/source/games/sw/src/game.cpp +++ b/source/games/sw/src/game.cpp @@ -798,9 +798,9 @@ void GameInterface::FreeLevelData() ::GameInterface::FreeLevelData(); } -bool GameInterface::Voxelize(int sprnum) +int GameInterface::Voxelize(int sprnum) { - return (aVoxelArray[sprnum].Voxel >= 0); + return (aVoxelArray[sprnum].Voxel); } END_SW_NS diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 799aa2065..e9ab4c651 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -2252,10 +2252,10 @@ struct GameInterface : ::GameInterface void WarpToCoords(int x, int y, int z, int a, int h) override; void ToggleThirdPerson() override; void SwitchCoopView() override; - int chaseCamX(binangle ang) { return -ang.bcos(-3); } - int chaseCamY(binangle ang) { return -ang.bsin(-3); } - int chaseCamZ(fixedhoriz horiz) { return horiz.asq16() >> 8; } - bool Voxelize(int sprnum); + int chaseCamX(binangle ang) override { return -ang.bcos(-3); } + int chaseCamY(binangle ang) override { return -ang.bsin(-3); } + int chaseCamZ(fixedhoriz horiz) override { return horiz.asq16() >> 8; } + int Voxelize(int sprnum) override; GameStats getStats() override;