#ifndef WINDOW_H #define WINDOW_H #include #include #include "input/Buttons.h" #include "input/TextInput.h" #include "rendering/WindowOptions.h" #include "utils/Clock.h" #include "utils/Error.h" class Window final { static int glfwCounter; static int glewCounter; Error error; TextInput*& textInput; GLFWwindow* window; Clock fps; Clock tps; Size size; Buttons buttons; public: Window(TextInput*& textInput, const WindowOptions& options); ~Window(); Window(const Window&) = delete; Window& operator=(const Window&) = delete; Window(Window&&) = delete; Window& operator=(Window&&) = delete; const Error& getError() const; const Clock& getFrameClock() const; const Clock& getTickClock() const; const Size& getSize() const; Buttons& getButtons(); void trapCursor(bool trap); template void run(T& game, Clock::Nanos nanosPerTick) { glfwShowWindow(window); Clock::Nanos lag = 0; while(!glfwWindowShouldClose(window) && game.isRunning()) { lag += fps.update(); while(lag >= nanosPerTick) { lag -= nanosPerTick; tps.update(); buttons.tick(); game.tick(); } game.render(static_cast(lag) / nanosPerTick); glfwSwapBuffers(window); glfwPollEvents(); } } private: static void onKey(GLFWwindow* w, int key, int scancode, int action, int mods); static void onChar(GLFWwindow* w, unsigned int codepoint); static void onResize(GLFWwindow* w, int width, int height); static void onMouse(GLFWwindow* w, int button, int action, int mods); static void onMouseMove(GLFWwindow* w, double x, double y); }; #endif