mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 19:11:50 +00:00
fix tick intervals in headless mode
This commit is contained in:
parent
843cc3769d
commit
0975fcd819
4 changed files with 56 additions and 41 deletions
|
|
@ -8,30 +8,32 @@ Clock::Clock(int tickRate, int tickParts)
|
|||
: tickRate(tickRate), tickParts(tickParts) {
|
||||
}
|
||||
|
||||
bool Clock::update(float delta) {
|
||||
int Clock::update(float delta) {
|
||||
tickTimer += delta;
|
||||
float delay = 1.0f / static_cast<float>(tickRate);
|
||||
if (tickTimer > delay || tickPartsUndone) {
|
||||
if (tickPartsUndone) {
|
||||
tickPartsUndone--;
|
||||
} else {
|
||||
tickTimer = std::fmod(tickTimer, delay);
|
||||
tickPartsUndone = tickParts - 1;
|
||||
}
|
||||
++tickId;
|
||||
return true;
|
||||
if (tickTimer < delay / tickParts) {
|
||||
return 0;
|
||||
}
|
||||
return false;
|
||||
int parts = tickTimer / (delay / tickParts);
|
||||
if (parts) {
|
||||
tickTimer -= parts * delay / tickParts;
|
||||
tickTimer = std::min<float>(tickTimer, delay);
|
||||
}
|
||||
currentTickPart += parts;
|
||||
if (currentTickPart >= tickParts) {
|
||||
currentTickPart %= tickParts;
|
||||
}
|
||||
return parts;
|
||||
}
|
||||
|
||||
int Clock::getPart() const {
|
||||
return currentTickPart;
|
||||
}
|
||||
|
||||
int Clock::getParts() const {
|
||||
return tickParts;
|
||||
}
|
||||
|
||||
int Clock::getPart() const {
|
||||
return tickParts - tickPartsUndone - 1;
|
||||
}
|
||||
|
||||
int Clock::getTickRate() const {
|
||||
return tickRate;
|
||||
}
|
||||
|
|
@ -39,3 +41,7 @@ int Clock::getTickRate() const {
|
|||
int Clock::getTickId() const {
|
||||
return tickId;
|
||||
}
|
||||
|
||||
int Clock::convertPart(int index) const {
|
||||
return (tickParts - currentTickPart) % tickParts + index;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue