From 8d2d36457f41a376d4bc0d62580157f92ccce929 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 8 Sep 2020 18:28:41 +0200 Subject: [PATCH] - consolidated the map name display on startup Fixes #275 --- source/blood/src/blood.cpp | 3 +- source/blood/src/view.cpp | 46 ++---------------------- source/core/d_net.cpp | 12 +++---- source/core/mainloop.cpp | 4 +++ source/core/savegamehelp.cpp | 9 +++-- source/core/statusbar.cpp | 56 +++++++++++++++++++++++++++--- source/core/statusbar.h | 6 ++++ source/exhumed/src/engine.h | 1 - source/exhumed/src/init.cpp | 6 ++-- source/games/duke/src/2d_d.cpp | 5 --- source/games/duke/src/2d_r.cpp | 5 --- source/games/duke/src/gameloop.cpp | 3 -- source/games/duke/src/global.cpp | 1 - source/games/duke/src/global.h | 1 - source/games/duke/src/premap.cpp | 5 ++- source/games/duke/src/savegame.cpp | 1 - source/games/duke/src/sbar.h | 1 - source/games/duke/src/sbar_d.cpp | 11 ------ source/games/duke/src/sbar_r.cpp | 9 ----- source/sw/src/game.cpp | 2 ++ 20 files changed, 85 insertions(+), 102 deletions(-) diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index d8a5d44a4..d141ca732 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -63,6 +63,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "choke.h" #include "d_net.h" #include "v_video.h" +#include "statusbar.h" BEGIN_BLD_NS @@ -242,7 +243,7 @@ void StartLevel(MapRecord* level) paused = 0; levelTryPlayMusic(); gChoke.reset(); - Printf(TEXTCOLOR_GOLD "%s: %s\n", level->LabelName(), level->DisplayName()); + setLevelStarted(level); } diff --git a/source/blood/src/view.cpp b/source/blood/src/view.cpp index d68ff8e39..cc3080621 100644 --- a/source/blood/src/view.cpp +++ b/source/blood/src/view.cpp @@ -228,23 +228,6 @@ GameStats GameInterface::getStats() return { gKillMgr.Kills, gKillMgr.TotalKills, gSecretMgr.Founds, gSecretMgr.Total, gFrameCount / kTicsPerSec, gPlayer[myconnectindex].fragCount }; } -void viewDrawMapTitle(void) -{ - if (!hud_showmapname || M_Active()) - return; - - int const fadeStartTic = kTicsPerSec; - int const fadeEndTic = int(1.5f*kTicsPerSec); - if (gFrameCount > fadeEndTic) - return; - int const alpha = 255 - clamp((gFrameCount-fadeStartTic)*255/(fadeEndTic-fadeStartTic), 0, 255); - - if (alpha != 0) - { - viewDrawText(1, currentLevel->DisplayName(), 160, 50, -128, 0, 1, 1, 0, alpha); - } -} - void viewDrawAimedPlayerName(void) { if (!cl_idplayers || (gView->aim.dx == 0 && gView->aim.dy == 0)) @@ -411,19 +394,9 @@ void viewSetMessage(const char *pMessage, const int pal, const MESSAGE_PRIORITY Printf(printlevel|PRINT_NOTIFY, "%s\n", pMessage); } - -char errMsg[256]; - void viewSetErrorMessage(const char *pMessage) { - if (!pMessage) - { - strcpy(errMsg, ""); - } - else - { - strcpy(errMsg, pMessage); - } + Printf(PRINT_BOLD|PRINT_NOTIFY, "%s\n", pMessage); } void DoLensEffect(void) @@ -1014,7 +987,6 @@ void viewDrawScreen(bool sceneonly) } #endif - viewDrawMapTitle(); viewDrawAimedPlayerName(); if (paused) { @@ -1025,10 +997,6 @@ void viewDrawScreen(bool sceneonly) FStringf gTempStr("] %s [", gProfile[gView->nPlayer].name); viewDrawText(0, gTempStr, 160, 10, 0, 0, 1, 0); } - if (errMsg[0]) - { - viewDrawText(0, errMsg, 160, 20, 0, 0, 1, 0); - } if (cl_interpolate) { RestoreInterpolations(); @@ -1041,22 +1009,12 @@ bool GameInterface::GenerateSavePic() return true; } - -#define LOW_FPS 60 -#define SLOW_FRAME_TIME 20 - -#if defined GEKKO -# define FPS_YOFFSET 16 -#else -# define FPS_YOFFSET 0 -#endif - FString GameInterface::GetCoordString() { FString out; out.Format("pos= %d, %d, %d - angle = %2.3f", - gMe->pSprite->x, gMe->pSprite->y, gMe->pSprite->z, gMe->pSprite->ang); + gMe->pSprite->x, gMe->pSprite->y, gMe->pSprite->z, gMe->pSprite->ang * (360./2048)); return out; } diff --git a/source/core/d_net.cpp b/source/core/d_net.cpp index 8c1edbbb5..7863f21f6 100644 --- a/source/core/d_net.cpp +++ b/source/core/d_net.cpp @@ -1017,12 +1017,12 @@ void NetUpdate (void) int mod = maketic - ticdup; int modp, j; - int svel; - int fvel; - int64_t q16avel; - int64_t q16horz; - int64_t q16horiz; // only used by SW - int64_t q16ang; // only used by SW + int svel = 0; + int fvel = 0; + int64_t q16avel = 0; + int64_t q16horz = 0; + int64_t q16horiz = 0; // only used by SW + int64_t q16ang = 0; // only used by SW for (j = 0; j < ticdup; ++j) { diff --git a/source/core/mainloop.cpp b/source/core/mainloop.cpp index 2f1dddbd1..5f1ae9b9f 100644 --- a/source/core/mainloop.cpp +++ b/source/core/mainloop.cpp @@ -84,6 +84,8 @@ #include "build.h" #include "g_input.h" #include "mapinfo.h" +#include "automap.h" +#include "statusbar.h" CVAR(Bool, vid_activeinbackground, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, r_ticstability, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) @@ -292,6 +294,7 @@ static void GameTicker() gameupdatetime.Reset(); gameupdatetime.Clock(); gi->Ticker(); + levelTextTime--; gameupdatetime.Unclock(); break; @@ -348,6 +351,7 @@ void Display() twodpsp.SetSize(screen->GetWidth(), screen->GetHeight()); gi->Render(); DrawFullscreenBlends(); + drawMapTitle(); break; } [[fallthrough]]; diff --git a/source/core/savegamehelp.cpp b/source/core/savegamehelp.cpp index e7c826356..b90fa3bfa 100644 --- a/source/core/savegamehelp.cpp +++ b/source/core/savegamehelp.cpp @@ -52,6 +52,7 @@ #include "raze_sound.h" #include "gamestruct.h" #include "automap.h" +#include "statusbar.h" static CompositeSavegameWriter savewriter; static FResourceFile *savereader; @@ -75,6 +76,7 @@ static void SerializeSession(FSerializer& arc) quoteMgr.Serialize(arc); S_SerializeSounds(arc); SerializeAutomap(arc); + SerializeHud(arc); } //============================================================================= @@ -189,16 +191,17 @@ bool OpenSaveGameForWrite(const char* filename, const char *name) auto savesig = gi->GetSaveSig(); auto gs = gi->getStats(); FStringf timeStr("%02d:%02d", gs.timesecnd / 60, gs.timesecnd % 60); + auto lev = currentLevel; savegameinfo.AddString("Software", buf) ("Save Version", savesig.currentsavever) .AddString("Engine", savesig.savesig) .AddString("Game Resource", fileSystem.GetResourceFileName(1)) - .AddString("Map Name", currentLevel->DisplayName()) + .AddString("Map Name", lev->DisplayName()) .AddString("Creation Time", myasctime()) .AddString("Title", name) - .AddString("Map File", currentLevel->fileName) - .AddString("Map Label", currentLevel->labelName) + .AddString("Map File", lev->fileName) + .AddString("Map Label", lev->labelName) .AddString("Map Time", timeStr); const char *fn = currentLevel->fileName; diff --git a/source/core/statusbar.cpp b/source/core/statusbar.cpp index f159a9cf7..3bd1615ae 100644 --- a/source/core/statusbar.cpp +++ b/source/core/statusbar.cpp @@ -762,11 +762,12 @@ void DBaseStatusBar::PrintLevelStats(FLevelStats &stats) void DBaseStatusBar::PrintAutomapInfo(FLevelStats& stats) { + auto lev = currentLevel; FString mapname; if (am_showlabel) - mapname.Format(TEXTCOLOR_ESCAPESTR "%c%s: " TEXTCOLOR_ESCAPESTR "%c%s", stats.letterColor+'A', currentLevel->LabelName(), stats.standardColor+'A', currentLevel->DisplayName()); + mapname.Format(TEXTCOLOR_ESCAPESTR "%c%s: " TEXTCOLOR_ESCAPESTR "%c%s", stats.letterColor+'A', lev->LabelName(), stats.standardColor+'A', lev->DisplayName()); else - mapname = currentLevel->DisplayName(); + mapname = lev->DisplayName(); double y; double scale = stats.fontscale * (am_textfont? *hud_statscale : 1); // the tiny default font used by all games here cannot be scaled for readability purposes. @@ -784,13 +785,13 @@ void DBaseStatusBar::PrintAutomapInfo(FLevelStats& stats) { y = 200 - stats.screenbottomspace - spacing; } - const auto &volname = gVolumeNames[volfromlevelnum(currentLevel->levelNumber)]; + const auto &volname = gVolumeNames[volfromlevelnum(lev->levelNumber)]; if (volname.IsEmpty() && am_nameontop) y = 1; DrawText(twod, stats.font, stats.standardColor, 2 * hud_statscale, y, mapname, DTA_FullscreenScale, FSMode_ScaleToHeight, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_KeepRatio, true, TAG_DONE); y -= spacing; - if (!(currentLevel->flags & MI_USERMAP) && !(g_gameType & GAMEFLAG_PSEXHUMED) && volname.IsNotEmpty()) + if (!(lev->flags & MI_USERMAP) && !(g_gameType & GAMEFLAG_PSEXHUMED) && volname.IsNotEmpty()) DrawText(twod, stats.font, stats.standardColor, 2 * hud_statscale, y, GStrings.localize(volname), DTA_FullscreenScale, FSMode_ScaleToHeight, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_KeepRatio, true, TAG_DONE); @@ -857,4 +858,51 @@ void setViewport(int viewSize) videoSetViewableArea(x0, y0, x1, y1); } +//============================================================================ +// +// +// +//============================================================================ + +int levelTextTime; + +void SerializeHud(FSerializer &arc) +{ + if (arc.BeginObject("hud")) + { + arc("texttimer", levelTextTime) + .EndObject(); + } +} + +void setLevelStarted(MapRecord *mi) +{ + levelTextTime = 85; + Printf(TEXTCOLOR_GOLD "%s: %s\n", mi->LabelName(), mi->DisplayName()); +} + +void drawMapTitle() +{ + if (!hud_showmapname || levelTextTime <= 0 || M_Active()) + return; + + double alpha = levelTextTime > 16? 1.0 : levelTextTime / 16.; + if (alpha > 0) + { + double scale = (g_gameType & GAMEFLAG_RRALL)? 0.4 : (g_gameType & GAMEFLAG_SW)? 0.7 : 1.0; + auto text = currentLevel->DisplayName(); + double x = 160 - BigFont->StringWidth(text) * scale / 2.; + double y = (g_gameType & GAMEFLAG_BLOOD)? 50 : 100 - BigFont->GetHeight()/2.; + bool shadow = true; + + if (shadow) + { + DrawText(twod, BigFont, CR_UNDEFINED, x+1, y+1, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Color, 0xff000000, DTA_Alpha, alpha / 2., DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE); + } + DrawText(twod, BigFont, CR_UNDEFINED, x, y, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Alpha, alpha, DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE); + } +} + + + diff --git a/source/core/statusbar.h b/source/core/statusbar.h index df201309c..c6580e3ae 100644 --- a/source/core/statusbar.h +++ b/source/core/statusbar.h @@ -344,5 +344,11 @@ enum DI_Flags void SBar_DrawString(DBaseStatusBar* self, DHUDFont* font, const FString& string, double x, double y, int flags, int trans, double alpha, int wrapwidth, int linespacing, double scaleX, double scaleY); void setViewport(int viewSize); +struct MapRecord; +void setLevelStarted(MapRecord *); +void drawMapTitle(); +class FSerializer; +void SerializeHud(FSerializer &arc); +extern int levelTextTime; #endif /* __SBAR_H__ */ diff --git a/source/exhumed/src/engine.h b/source/exhumed/src/engine.h index 54a2c64b5..3f5909851 100644 --- a/source/exhumed/src/engine.h +++ b/source/exhumed/src/engine.h @@ -83,7 +83,6 @@ extern int SectDepth[]; extern short SectSoundSect[]; extern int SectAbove[]; -uint8_t LoadLevel(int nMap); void LoadObjects(); // light diff --git a/source/exhumed/src/init.cpp b/source/exhumed/src/init.cpp index 8383366b6..9283f061d 100644 --- a/source/exhumed/src/init.cpp +++ b/source/exhumed/src/init.cpp @@ -31,6 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "status.h" #include #include +#include "statusbar.h" BEGIN_PS_NS @@ -78,7 +79,6 @@ uint8_t LoadLevel(int nMap) initspritelists(); - currentLevel = FindMapByLevelNum(nMap); // init stuff { @@ -177,10 +177,10 @@ uint8_t LoadLevel(int nMap) void InitLevel(int level) // todo: use a map record { StopCD(); + currentLevel = FindMapByLevelNum(level); if (!LoadLevel(level)) { I_Error("Can't load level %d...\n", level); } - currentLevel = FindMapByLevelNum(level); for (int i = 0; i < nTotalPlayers; i++) { @@ -207,7 +207,7 @@ void InitLevel(int level) // todo: use a map record if (nTrack != 0) nTrack--; playCDtrack((nTrack % 8) + 11, true); - + setLevelStarted(currentLevel); } void InitNewGame() diff --git a/source/games/duke/src/2d_d.cpp b/source/games/duke/src/2d_d.cpp index 291e88296..2d965f1f3 100644 --- a/source/games/duke/src/2d_d.cpp +++ b/source/games/duke/src/2d_d.cpp @@ -1082,9 +1082,4 @@ void PrintPaused_d() BigText(160, 100, GStrings("Game Paused")); } -void PrintLevelName_d(double alpha) -{ - BigText(160, 114, currentLevel->DisplayName(), alpha); -} - END_DUKE_NS diff --git a/source/games/duke/src/2d_r.cpp b/source/games/duke/src/2d_r.cpp index 1c0739d1f..6c304cba4 100644 --- a/source/games/duke/src/2d_r.cpp +++ b/source/games/duke/src/2d_r.cpp @@ -641,10 +641,5 @@ void PrintPaused_r() BigText(160, 100, GStrings("Game Paused"), 0); } -void PrintLevelName_r(double alpha) -{ - BigText(160, 114, currentLevel->DisplayName(), 0, alpha); -} - END_DUKE_NS diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index dc7c23e56..7df82aa33 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -84,9 +84,6 @@ void GameInterface::Ticker() } } - if (levelTextTime > 0) - levelTextTime--; - fi.think(); if ((everyothertime & 1) == 0) diff --git a/source/games/duke/src/global.cpp b/source/games/duke/src/global.cpp index 7d5ea3ae4..23c505901 100644 --- a/source/games/duke/src/global.cpp +++ b/source/games/duke/src/global.cpp @@ -76,7 +76,6 @@ int rtsplaying; int tempwallptr; weaponhit hittype[MAXSPRITES]; bool sound445done; // this was local state inside a function, but this must be maintained globally and serialized -int levelTextTime; // must be serialized uint16_t frags[MAXPLAYERS][MAXPLAYERS]; player_struct ps[MAXPLAYERS]; int spriteqamount = 64; diff --git a/source/games/duke/src/global.h b/source/games/duke/src/global.h index db8bcf98c..8df389daf 100644 --- a/source/games/duke/src/global.h +++ b/source/games/duke/src/global.h @@ -62,7 +62,6 @@ extern int rtsplaying; extern int tempwallptr; extern weaponhit hittype[MAXSPRITES]; extern bool sound445done; -extern int levelTextTime; extern uint16_t frags[MAXPLAYERS][MAXPLAYERS]; extern player_struct ps[MAXPLAYERS]; extern int spriteqamount; diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index d3fbc24f1..bba0d8227 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -749,7 +749,6 @@ void resettimevars(void) { cloudclock = 0; ud.levelclock = 0; - levelTextTime = 85; if (camsprite >= 0) hittype[camsprite].temp_data[0] = 0; } @@ -872,7 +871,7 @@ static int LoadTheMap(MapRecord *mi, struct player_struct *p, int gamemode) return 1; } currentLevel = mi; - SECRET_SetMapName(currentLevel->DisplayName(), currentLevel->name); + SECRET_SetMapName(mi->DisplayName(), mi->name); STAT_NewLevel(mi->fileName); G_LoadMapHack(mi->fileName); @@ -990,7 +989,7 @@ int enterlevel(MapRecord *mi, int gamemode) ps[myconnectindex].over_shoulder_on = 0; clearfrags(); resettimevars(); // Here we go - Printf(TEXTCOLOR_GOLD "%s: %s\n", mi->LabelName(), mi->DisplayName()); + setLevelStarted(mi); return 0; } diff --git a/source/games/duke/src/savegame.cpp b/source/games/duke/src/savegame.cpp index 9f83148ac..f89775f34 100644 --- a/source/games/duke/src/savegame.cpp +++ b/source/games/duke/src/savegame.cpp @@ -408,7 +408,6 @@ void GameInterface::SerializeGameState(FSerializer& arc) ("rtsplaying", rtsplaying) ("tempwallptr", tempwallptr) ("sound445done", sound445done) - ("leveltexttime", levelTextTime) .Array("players", ps, ud.multimode) ("spriteqamount", spriteqamount) .Array("shadedsector", shadedsector, numsectors) diff --git a/source/games/duke/src/sbar.h b/source/games/duke/src/sbar.h index c6f167087..f1423d76f 100644 --- a/source/games/duke/src/sbar.h +++ b/source/games/duke/src/sbar.h @@ -27,7 +27,6 @@ public: }; -extern int levelTextTime; void DrawBorder(); END_DUKE_NS diff --git a/source/games/duke/src/sbar_d.cpp b/source/games/duke/src/sbar_d.cpp index 71bba951a..7179bfdfe 100644 --- a/source/games/duke/src/sbar_d.cpp +++ b/source/games/duke/src/sbar_d.cpp @@ -440,7 +440,6 @@ public: }; -void PrintLevelName_d(double alpha); void drawstatusbar_d(int snum) { @@ -453,16 +452,6 @@ void drawstatusbar_d(int snum) { dsb.Statusbar(snum); } - - if (hud_showmapname && levelTextTime > 1 && !M_Active()) - { - double alpha; - if (levelTextTime > 16) alpha = 1.; - else alpha = (levelTextTime) / 16.; - PrintLevelName_d(alpha); - } - - } END_DUKE_NS diff --git a/source/games/duke/src/sbar_r.cpp b/source/games/duke/src/sbar_r.cpp index 5f590a41e..2615b0b80 100644 --- a/source/games/duke/src/sbar_r.cpp +++ b/source/games/duke/src/sbar_r.cpp @@ -457,15 +457,6 @@ void drawstatusbar_r(int snum) { dsb.Statusbar(snum); } - - if (hud_showmapname && levelTextTime > 1 && !M_Active()) - { - double alpha; - if (levelTextTime > 16) alpha = 1.; - else alpha = (levelTextTime) / 16.; - PrintLevelName_r(alpha); - } - } END_DUKE_NS diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index 1adcd10d6..bd494198d 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -43,6 +43,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "network.h" #include "pal.h" #include "automap.h" +#include "statusbar.h" #include "mytypes.h" @@ -391,6 +392,7 @@ void InitLevel(MapRecord *maprec) // reset NewGame NewGame = false; + setLevelStarted(maprec); } //---------------------------------------------------------------------------