Main.cpp 958 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "server/network/Server.h"
  2. #include "server/Clock.h"
  3. #include "server/GameServer.h"
  4. #include "commands/ConsoleEditor.h"
  5. int main() {
  6. Server server(11196);
  7. if(server.hasError()) {
  8. return 0;
  9. }
  10. Clock tps;
  11. GameServer gameServer(tps);
  12. ServerCommands serverCommands;
  13. Clock clock;
  14. constexpr Clock::Nanos NANOS_PER_TICK = 50000000;
  15. Clock::Nanos lag = 0;
  16. while(serverCommands.isRunning()) {
  17. lag += clock.update();
  18. while(lag >= NANOS_PER_TICK) {
  19. lag -= NANOS_PER_TICK;
  20. tps.update();
  21. ConsoleEditor::clearPrintLine();
  22. server.consumeEvents(gameServer);
  23. gameServer.handleCommands(serverCommands);
  24. gameServer.tick();
  25. ConsoleEditor::printLine();
  26. }
  27. Clock::Nanos waitNanos = NANOS_PER_TICK - lag;
  28. if(waitNanos > 300000) {
  29. clock.wait(waitNanos);
  30. }
  31. }
  32. return 0;
  33. }