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

Timer fix #63

Merged
merged 2 commits into from
Nov 12, 2023
Merged
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
28 changes: 10 additions & 18 deletions Hurrican/src/Gameplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,26 +263,18 @@ void GameLoop() {

constexpr float SPD_INC = 0.3f;
float const SpeedFaktorMax = SpeedFaktor;
float i = 0;

while (i < SpeedFaktorMax) {
// If the hardware can not render fast enough the logic catch up becomes too large
// In this case the logic needs to be broken up into chunks
if (SpeedFaktorMax < SPD_INC) // hardware is fast and sync does not need to be split
{
SpeedFaktor = SpeedFaktorMax;
i = SpeedFaktorMax;
} else if (SpeedFaktorMax - i <
SPD_INC) // sync has been split and only a small value is needed to meet the total sync request
{
SpeedFaktor = SpeedFaktorMax - i;
i = SpeedFaktorMax;
} else // hardware is not fast and sync does need to be split into chunks
{
SpeedFaktor = SPD_INC;
i += SPD_INC;
}
int chunks = 1;

// If the hardware can not render fast enough the logic catch up becomes too large
// In this case the logic needs to be broken up into chunks
if (SpeedFaktorMax > SPD_INC) {
chunks = ceilf(SpeedFaktorMax / SPD_INC);
SpeedFaktor = SpeedFaktorMax / chunks;
}

// Run the Logic
for (int i = 0; i < chunks; i++) {
for (int p = 0; p < NUMPLAYERS; p++) {
Player[p].WasDamaged = false;

Expand Down
5 changes: 3 additions & 2 deletions Hurrican/src/Timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
// Klassen Deklaration
// --------------------------------------------------------------------------------------

// The Timer class needs the global SpeedFactor variable
extern float SpeedFaktor;

class TimerClass {
private:
std::int64_t vergangeneFrames; // Vergangene Frames seit Beginn (für Schnitt)
Expand All @@ -40,7 +43,6 @@ class TimerClass {
double vergangeneZeit; // Zeit seit dem vorherigen Frame
double aktuelleFramerate; // Aktuelle Framerate
int maxFPS; // Maximum Framerate (Framebremse)
float SpeedFaktor; // Faktor, mit dem alle Werte verrechnet werden

public:
TimerClass(); // Konstruktor
Expand Down Expand Up @@ -69,7 +71,6 @@ class TimerClass {
// Externals
// --------------------------------------------------------------------------------------

extern float SpeedFaktor;
extern TimerClass Timer;

#endif
Loading