mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 02:51:49 +00:00
fix ServerMainloop timer
This commit is contained in:
parent
8a4f1e16f3
commit
008e11b4b7
4 changed files with 13 additions and 5 deletions
|
|
@ -40,13 +40,21 @@ void ServerMainloop::run() {
|
|||
double targetDelta = 1.0 / static_cast<double>(TPS);
|
||||
double delta = targetDelta;
|
||||
auto begin = system_clock::now();
|
||||
auto startupTime = begin;
|
||||
while (process->isActive()) {
|
||||
if (engine.isQuitSignal()) {
|
||||
process->terminate();
|
||||
logger.info() << "script has been terminated due to quit signal";
|
||||
break;
|
||||
}
|
||||
time.step(delta);
|
||||
if (coreParams.testMode) {
|
||||
time.step(delta);
|
||||
} else {
|
||||
auto now = system_clock::now();
|
||||
time.update(
|
||||
duration_cast<microseconds>(now - startupTime).count() / 1e6);
|
||||
delta = time.getDelta();
|
||||
}
|
||||
process->update();
|
||||
if (controller) {
|
||||
controller->getLevel()->getWorld()->updateTimers(delta);
|
||||
|
|
@ -57,8 +65,6 @@ void ServerMainloop::run() {
|
|||
auto end = system_clock::now();
|
||||
platform::sleep(targetDelta * 1000 -
|
||||
duration_cast<microseconds>(end - begin).count() / 1000);
|
||||
end = system_clock::now();
|
||||
delta = duration_cast<microseconds>(end - begin).count() / 1e6;
|
||||
begin = end;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue