fix clock.cpp

This commit is contained in:
Xertis 2026-08-11 14:32:12 +03:00
parent a4b2085afc
commit b3bde8b968
2 changed files with 4 additions and 6 deletions

View file

@ -1,6 +1,5 @@
#include "Clock.hpp" #include "Clock.hpp"
#include <cmath>
#include <algorithm> #include <algorithm>
using namespace util; using namespace util;
@ -20,10 +19,8 @@ int Clock::update(float delta) {
tickTimer -= parts * delay / tickParts; tickTimer -= parts * delay / tickParts;
tickTimer = std::min<float>(tickTimer, delay); tickTimer = std::min<float>(tickTimer, delay);
} }
currentTickPart += parts; lastPartsStart = currentTickPart;
if (currentTickPart >= tickParts) { currentTickPart = (currentTickPart + parts) % tickParts;
currentTickPart %= tickParts;
}
return parts; return parts;
} }
@ -40,5 +37,5 @@ int Clock::getTickId() const {
} }
int Clock::convertPart(int index) const { int Clock::convertPart(int index) const {
return (tickParts - currentTickPart) % tickParts + index; return (lastPartsStart + index) % tickParts;
} }

View file

@ -8,6 +8,7 @@ namespace util {
float tickTimer = 0.0f; float tickTimer = 0.0f;
int tickId = 0; int tickId = 0;
int currentTickPart = 0; int currentTickPart = 0;
int lastPartsStart = 0;
public: public:
Clock(int tickRate, int tickParts); Clock(int tickRate, int tickParts);