12345678910111213141516171819202122232425262728293031323334353637 |
- #include "server/network/Server.h"
- #include "server/Clock.h"
- #include "server/GameServer.h"
- #include "commands/ConsoleEditor.h"
- static const u64 NANOS_PER_TICK = 50000000;
- int main() {
- Server server(11196);
- if(server.hasError()) {
- return 0;
- }
- Clock tps;
- GameServer gameServer(tps);
- ServerCommands serverCommands;
-
- Clock clock;
- u64 lag = 0;
- while(serverCommands.isRunning()) {
- lag += clock.update();
- while(lag >= NANOS_PER_TICK) {
- lag -= NANOS_PER_TICK;
- tps.update();
- ConsoleEditor::clearPrintLine();
- server.consumeEvents(gameServer);
- gameServer.handleCommands(serverCommands);
- gameServer.tick();
- ConsoleEditor::printLine();
- }
- u64 waitNanos = NANOS_PER_TICK - lag;
- if(waitNanos > 300000) {
- clock.wait(waitNanos);
- }
- }
- return 0;
- }
|