Main.cpp 889 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <iostream>
  2. #include "gaming-core/network/ENet.h"
  3. #include "gaming-core/network/Server.h"
  4. #include "gaming-core/utils/Clock.h"
  5. #include "server/GameServer.h"
  6. int main() {
  7. ENet enet;
  8. if(enet.init()) {
  9. std::cout << "cannot initialize enet\n";
  10. return 0;
  11. }
  12. Server server(11196, 50);
  13. if(server.hasError()) {
  14. return 0;
  15. }
  16. GameServer gameServer(server);
  17. Clock clock;
  18. constexpr Clock::Nanos NANOS_PER_TICK = 50000000;
  19. Clock::Nanos lag = 0;
  20. while(gameServer.isRunning()) {
  21. lag += clock.update();
  22. while(lag >= NANOS_PER_TICK) {
  23. lag -= NANOS_PER_TICK;
  24. server.consumeEvents(gameServer);
  25. gameServer.tick();
  26. }
  27. Clock::Nanos waitNanos = NANOS_PER_TICK - lag;
  28. if(waitNanos > 300000) {
  29. clock.wait(waitNanos);
  30. }
  31. }
  32. return 0;
  33. }