Main.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "client/input/Controller.h"
  2. #include "client/rendering/Engine.h"
  3. #include "client/rendering/Framebuffers.h"
  4. #include "client/rendering/RenderSettings.h"
  5. #include "client/rendering/Shaders.h"
  6. #include "gaming-core/network/Client.h"
  7. #include "gaming-core/network/ENet.h"
  8. #include "gaming-core/rendering/Window.h"
  9. #include "gaming-core/rendering/WindowOptions.h"
  10. #include "gaming-core/utils/Clock.h"
  11. #include "gaming-core/wrapper/GL.h"
  12. #include "gaming-core/wrapper/GLEW.h"
  13. #include "gaming-core/wrapper/GLFW.h"
  14. void updateSize(const Window& window, Size& size, Framebuffers& framebuffers) {
  15. Size newSize = window.getSize();
  16. if(newSize.width != size.width || newSize.height != size.height) {
  17. size = newSize;
  18. GL::setViewport(size.width, size.height);
  19. framebuffers.resize(size);
  20. }
  21. }
  22. int main() {
  23. ENet enet;
  24. if(enet.init()) {
  25. std::cout << "cannot initialize enet\n";
  26. return 0;
  27. }
  28. Client client;
  29. if(client.hasError()) {
  30. std::cout << client.getError() << '\n';
  31. return 0;
  32. }
  33. if(GLFW::init()) {
  34. return 0;
  35. }
  36. Size size(1024, 620);
  37. WindowOptions options(4, 0, size, false, "test");
  38. TextInput textInput;
  39. Window window(textInput, options);
  40. if(window.hasError() || GLEW::init()) {
  41. return 0;
  42. }
  43. Shaders shaders;
  44. if(shaders.hasError()) {
  45. return 0;
  46. }
  47. Framebuffers framebuffers;
  48. if(framebuffers.init(size)) {
  49. return 0;
  50. }
  51. RenderSettings renderSettings;
  52. Engine engine(shaders, framebuffers, size, renderSettings);
  53. Buttons buttons(window);
  54. Controller controller(buttons);
  55. Clock fps;
  56. Clock tps;
  57. Game game(textInput, controller, fps, tps, renderSettings, size, client);
  58. window.show();
  59. GL::printError("setup error");
  60. const Clock::Nanos nanosPerTick = 50000000;
  61. Clock::Nanos lag = 0;
  62. while(!window.shouldClose() && game.isRunning()) {
  63. GL::printError("loop error");
  64. updateSize(window, size, framebuffers);
  65. engine.renderTick(static_cast<float>(lag) / nanosPerTick, game);
  66. window.swapBuffers();
  67. lag += fps.update();
  68. while(lag >= nanosPerTick) {
  69. lag -= nanosPerTick;
  70. tps.update();
  71. buttons.tick();
  72. game.tick();
  73. }
  74. glfwPollEvents();
  75. }
  76. return 0;
  77. }