Main.cpp 942 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "server/Game.h"
  2. #include "server/GameServer.h"
  3. #include "server/commands/Commands.h"
  4. #include "server/snuviscript/Snuvi.h"
  5. #include "utils/Logger.h"
  6. void loop() {
  7. Clock clock;
  8. constexpr Clock::Nanos NANOS_PER_TICK = 50000000;
  9. Clock::Nanos lag = 0;
  10. while(Game::isRunning()) {
  11. lag += clock.update();
  12. while(lag >= NANOS_PER_TICK) {
  13. lag -= NANOS_PER_TICK;
  14. GameServer::tick();
  15. Game::tick();
  16. }
  17. Clock::Nanos waitNanos = NANOS_PER_TICK - lag;
  18. if(waitNanos > 300000) {
  19. clock.wait(waitNanos);
  20. }
  21. }
  22. }
  23. void init(Server* server) {
  24. Snuvi::init();
  25. Commands::init();
  26. GameServer::init(server);
  27. Game::testWorld();
  28. }
  29. int main() {
  30. Server server;
  31. Error error = server.start(11196, 50);
  32. if(error.has()) {
  33. LOG_ERROR(error.message);
  34. return 0;
  35. }
  36. init(&server);
  37. loop();
  38. return 0;
  39. }