From 8c7f41fadcf5094d360686f227712298d6f6e5a5 Mon Sep 17 00:00:00 2001 From: Mia Date: Fri, 22 Dec 2023 17:24:58 +0100 Subject: [PATCH] implemented the idea of it --- Hurrican/src/Gameplay.cpp | 75 ++++++++++++++++++--------------------- Hurrican/src/Gameplay.hpp | 2 +- Hurrican/src/Menu.cpp | 58 +++++++++++++++++++++++++++--- Hurrican/src/Menu.hpp | 5 +++ Hurrican/src/Timer.cpp | 8 +++++ Hurrican/src/Timer.hpp | 1 + 6 files changed, 103 insertions(+), 46 deletions(-) diff --git a/Hurrican/src/Gameplay.cpp b/Hurrican/src/Gameplay.cpp index 3a45de9f..f4cea1fe 100644 --- a/Hurrican/src/Gameplay.cpp +++ b/Hurrican/src/Gameplay.cpp @@ -176,8 +176,15 @@ void InitNewGameLevel() { pMenu->ResetProgressBar(); DisplayLoadInfo(""); - Timer.wait(1000); - Timer.update(); + + pMenu->loading_wait_for_keypress = true; + while (pMenu->loading_wait_for_keypress) { + pMenu->WaitForKeypress(); + } + while (!DirectInput.AreAllKeysReleased()) { + DirectInput.UpdateTastatur(); + DirectInput.UpdateJoysticks(); + } // Menu Musik ausfaden // DKS - Was already commented out: @@ -899,15 +906,32 @@ void SaveConfig() { // mehrere Zeilen anzeigen und immer bei neuem Text eins nach oben rutschen // -------------------------------------------------------------------------------------- -bool DisplayLoadInfo(const char Text[100]) { +double last_displayed; + +// TODO: Text parameter is currently unused. +// This was used in the demo version of Hurrican +// to display a scrolling buffer of text while loading +bool DisplayLoadInfo(std::string /*Text*/) { if (NochKeinFullScreen || pMenu == nullptr) return false; - // TODO FIX - /* - strrev (Text); // String umdrehen - strnset(Text, ' ', 2); // Ersten zwei (vorher letzten Zwei = \n) Buchstaben löschen - strrev (Text); // Wieder richtig herum drehen - */ + + // Limit the frames displayed by this + Timer.update(); + const float elapsed = Timer.getTime() - last_displayed; + + float frame_time; + if (Timer.GetMaxFPS() == 0) { + frame_time = (1. / 60.) * 1000; + } else { + frame_time = (1. / Timer.GetMaxFPS()) * 1000; + } + + if (elapsed < frame_time) { + pMenu->UpdateProgressBar(); + return true; + } else { + last_displayed = Timer.getTime(); + } // Anzeigen im Loadingscreen DirectGraphics.ClearBackBuffer(); @@ -926,41 +950,12 @@ bool DisplayLoadInfo(const char Text[100]) { buf.c_str(), 0xFFFFFFFF); #endif - // Hint anzeigen - // DKS - Added support for displaying hints on low-resolution devices: - if (DisplayHintNr > -1) { - if (CommandLineParams.LowRes) { - const char *text = TextArray[TEXT::HINT1 + DisplayHintNr]; - constexpr float Y_POS = 270.0f; - constexpr float Y_INC = 28.0f; - constexpr int MAX_WIDTH = RENDERWIDTH - 20; - if (pDefaultFont->StringLength(text, 0) > MAX_WIDTH) { - // Split the line in two if too long to display on low-res device: - char text1[255]; - char text2[255]; - SplitLine(text1, text2, text); - pDefaultFont->DrawTextCenterAlign(320.0f, Y_POS, text1, 0xFFFFFFFF, 0); - pDefaultFont->DrawTextCenterAlign(320.0f, Y_POS + Y_INC, text2, 0xFFFFFFFF, 0); - } else { - pDefaultFont->DrawTextCenterAlign(320.0f, Y_POS, text, 0xFFFFFFFF, 0); - } - } else { - pDefaultFont->DrawTextCenterAlign(320.0f, 270.0f, TextArray[TEXT::HINT1 + DisplayHintNr], 0xFFFFFFFF, 0); - } - } - - pMenu->LoadingScreen.RenderSprite((RENDERWIDTH - 360) / 2, (RENDERHEIGHT - 60) / 2 + 5, 0x88FFFFFF); - + pMenu->DrawHint(); pMenu->UpdateProgressBar(); - - /*for (i=0; i<24; i++) - pDefaultFont->DrawText(10, static_cast(230+i*10), LoadInfoText[i], D3DCOLOR_RGBA(0, 255, 0, i*10));*/ + pMenu->DrawProgressBar(); DirectGraphics.ShowBackBuffer(); - Timer.wait(1); - Timer.update(); - return true; } diff --git a/Hurrican/src/Gameplay.hpp b/Hurrican/src/Gameplay.hpp index faa6d9ac..df927438 100644 --- a/Hurrican/src/Gameplay.hpp +++ b/Hurrican/src/Gameplay.hpp @@ -43,7 +43,7 @@ bool LoadConfig(); // Konfigurationen laden void SaveConfig(); // Konfigurationen speichern void CreateDefaultControlsConfig(int player); // Load per-player default controls configuration void CreateDefaultConfig(); // DefaultKonfigurationen erstellen -bool DisplayLoadInfo(const char Text[100]); // Text beim Loading anzeigen +bool DisplayLoadInfo(std::string Text); // Text beim Loading anzeigen bool NewDemo(const char Filename[]); // Neues Demo aufzeichnen void RecordDemo(); // Spielereingaben sichern bool LoadDemo(const char Filename[]); // Demo laden diff --git a/Hurrican/src/Menu.cpp b/Hurrican/src/Menu.cpp index d614d666..57f2b3fb 100644 --- a/Hurrican/src/Menu.cpp +++ b/Hurrican/src/Menu.cpp @@ -2634,6 +2634,30 @@ void MenuClass::CheckForNewHighscore() { // Progress bar // -------------------------------------------------------------------------------------- +void MenuClass::DrawHint() { + if (DisplayHintNr > -1) { + if (CommandLineParams.LowRes) { + const char *text = TextArray[TEXT::HINT1 + DisplayHintNr]; + constexpr float Y_POS = 270.0f; + constexpr float Y_INC = 28.0f; + constexpr int MAX_WIDTH = RENDERWIDTH - 20; + if (pDefaultFont->StringLength(text, 0) > MAX_WIDTH) { + // Split the line in two if too long to display on low-res device: + char text1[255]; + char text2[255]; + SplitLine(text1, text2, text); + pDefaultFont->DrawTextCenterAlign(320.0f, Y_POS, text1, 0xFFFFFFFF, 0); + pDefaultFont->DrawTextCenterAlign(320.0f, Y_POS + Y_INC, text2, 0xFFFFFFFF, 0); + } else { + pDefaultFont->DrawTextCenterAlign(320.0f, Y_POS, text, 0xFFFFFFFF, 0); + } + } else { + pDefaultFont->DrawTextCenterAlign(320.0f, 270.0f, TextArray[TEXT::HINT1 + DisplayHintNr], 0xFFFFFFFF, 0); + } + } + +} + void MenuClass::ResetProgressBar() { LoadingProgress = 320.0f; } @@ -2645,14 +2669,38 @@ void MenuClass::StartProgressBar(int items) { } void MenuClass::UpdateProgressBar() { - LoadingScreen.RenderSprite((RENDERWIDTH - 360) / 2, (RENDERHEIGHT - 60) / 2 + 5, 0x88FFFFFF); - - LoadingBar.SetRect(0, 0, static_cast(LoadingProgress), 19); - LoadingBar.RenderSprite((RENDERWIDTH - 318) / 2, (RENDERHEIGHT - 19) / 2 + 5, 0x88FFFFFF); - LoadingItemsLoaded++; LoadingProgress += 318.0f / LoadingItemsToLoad; if (LoadingProgress > 318.0f) LoadingProgress = 318.0f; } + +void MenuClass::DrawProgressBar() { + LoadingScreen.RenderSprite(static_cast((RENDERWIDTH - 360) / 2), static_cast((RENDERHEIGHT - 60) / 2) + 5, 0x88FFFFFF); + + LoadingBar.SetRect(0, 0, static_cast(LoadingProgress), 19); + LoadingBar.RenderSprite(static_cast((RENDERWIDTH - 318) / 2), static_cast((RENDERHEIGHT - 19) / 2) + 5, 0x88FFFFFF); +} + +void MenuClass::WaitForKeypress() { + DirectGraphics.ClearBackBuffer(); + pMenu->ShowMenuBack(); + + DirectGraphics.SetAdditiveMode(); + + pDefaultFont->DrawTextCenterAlign(320, 200, "Press any key to continue!", 0xFFFFFFFF); + DrawHint(); + + DirectGraphics.ShowBackBuffer(); + + Timer.update(); + Timer.wait(); + + DirectInput.UpdateTastatur(); + DirectInput.UpdateJoysticks(); + + if (DirectInput.AnyKeyDown() || DirectInput.AnyButtonDown()) { + loading_wait_for_keypress = false; + } +} diff --git a/Hurrican/src/Menu.hpp b/Hurrican/src/Menu.hpp index 8c3fce24..a96f7abd 100644 --- a/Hurrican/src/Menu.hpp +++ b/Hurrican/src/Menu.hpp @@ -200,6 +200,8 @@ class MenuClass { char NewName[32]; // Neuer Highscore Name bool control_reassignment_occuring; // Für Tasten / Button Konfiguration + bool loading_wait_for_keypress; + float Rotation; // Rotationsgrad int RotationDir; // Rotationsrichtung @@ -216,9 +218,12 @@ class MenuClass { void ResetHighscore(); // Highscoreliste resetten void ShowLanguageInfo(); // Infos aus der Language file anzeigen void CheckForNewHighscore(); + void DrawHint(); void ResetProgressBar(); void StartProgressBar(int items); void UpdateProgressBar(); + void DrawProgressBar(); + void WaitForKeypress(); #ifndef NDEBUG int ItemsLoaded() const { return LoadingItemsLoaded; } diff --git a/Hurrican/src/Timer.cpp b/Hurrican/src/Timer.cpp index 9cd6d98d..4a156b3b 100644 --- a/Hurrican/src/Timer.cpp +++ b/Hurrican/src/Timer.cpp @@ -201,3 +201,11 @@ void TimerClass::WriteLogValues() { Protokoll << "Minimum FPS : " << static_cast(FPSMinimum) << std::endl; Protokoll << "Average FPS : " << static_cast(DurchschnittFramerate) << std::endl; } + +// -------------------------------------------------------------------------------------- +// Get the current time +// -------------------------------------------------------------------------------------- + +std::int64_t TimerClass::getTime() const { + return aktuelleZeit; +} diff --git a/Hurrican/src/Timer.hpp b/Hurrican/src/Timer.hpp index f2f9d015..58eca297 100644 --- a/Hurrican/src/Timer.hpp +++ b/Hurrican/src/Timer.hpp @@ -62,6 +62,7 @@ class TimerClass { void setSpeedFactor(float Wert);// Set the speed factor void resetMaxMinFPS(); // Max und Min FPS resetten void WriteLogValues(); // Werte in Logdatei sichern + std::int64_t getTime() const; // Variable mit der aktuellen FrameRate synchronisieren inline float sync(float val) const { return val * SpeedFaktor; }