Main.cpp 2.0 KB

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