Main.cpp 2.0 KB

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