Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slow loading #72

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 35 additions & 40 deletions Hurrican/src/Gameplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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();
Expand All @@ -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<float>(230+i*10), LoadInfoText[i], D3DCOLOR_RGBA(0, 255, 0, i*10));*/
pMenu->DrawProgressBar();

DirectGraphics.ShowBackBuffer();

Timer.wait(1);
Timer.update();

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion Hurrican/src/Gameplay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 53 additions & 5 deletions Hurrican/src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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<int>(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<int>((RENDERWIDTH - 360) / 2), static_cast<int>((RENDERHEIGHT - 60) / 2) + 5, 0x88FFFFFF);

LoadingBar.SetRect(0, 0, static_cast<int>(LoadingProgress), 19);
LoadingBar.RenderSprite(static_cast<int>((RENDERWIDTH - 318) / 2), static_cast<int>((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;
}
}
5 changes: 5 additions & 0 deletions Hurrican/src/Menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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; }
Expand Down
8 changes: 8 additions & 0 deletions Hurrican/src/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,11 @@ void TimerClass::WriteLogValues() {
Protokoll << "Minimum FPS : " << static_cast<int>(FPSMinimum) << std::endl;
Protokoll << "Average FPS : " << static_cast<int>(DurchschnittFramerate) << std::endl;
}

// --------------------------------------------------------------------------------------
// Get the current time
// --------------------------------------------------------------------------------------

std::int64_t TimerClass::getTime() const {
return aktuelleZeit;
}
1 change: 1 addition & 0 deletions Hurrican/src/Timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Loading