Main.cpp 751 B

123456789101112131415161718192021222324252627282930313233
  1. #include "server/Game.h"
  2. #include "server/GameServer.h"
  3. #include "server/commands/Commands.h"
  4. #include "server/snuviscript/Snuvi.h"
  5. void loop() {
  6. Clock clock;
  7. constexpr Clock::Nanos NANOS_PER_TICK = 50000000;
  8. Clock::Nanos lag = 0;
  9. while(Game::isRunning()) {
  10. lag += clock.update();
  11. while(lag >= NANOS_PER_TICK) {
  12. lag -= NANOS_PER_TICK;
  13. GameServer::tick();
  14. Game::tick();
  15. }
  16. Clock::Nanos waitNanos = NANOS_PER_TICK - lag;
  17. if(waitNanos > 300000) {
  18. clock.wait(waitNanos);
  19. }
  20. }
  21. }
  22. int main() {
  23. Snuvi::init();
  24. Commands::init();
  25. if(GameServer::init(11196, 50)) {
  26. return 0;
  27. }
  28. Game::init();
  29. loop();
  30. return 0;
  31. }