#ifndef WRAPPER_H #define WRAPPER_H #include #include #include using namespace std; class IClient { public: virtual void tick() = 0; virtual void renderTick(float lag) = 0; virtual void onKeyEvent(int key, int scancode, int action, int mods) = 0; virtual void onMouseClick(int button, int action, int mods) = 0; }; class DummyClient : public IClient { public: static DummyClient dummy; void tick() override { cout << "Dummy tick" << endl; }; void renderTick(float lag) override { cout << "Dummy renderTick" << endl; }; void onKeyEvent(int key, int scancode, int action, int mods) override { cout << "Dummy onKeyEvent" << endl; }; void onMouseClick(int button, int action, int mods) override { cout << "Dummy onMouseClick" << endl; }; private: DummyClient() {}; }; class Engine { public: static bool init(int width, int height, const char* name); static void start(IClient& client); static void stop(); void printError(); static int getScale(); static int getWidth(); static int getHeight(); static GLint getUniformLocation(const GLchar* name); static void setMatrix(GLint location, const GLfloat* m); static void setInt(GLint location, GLint i); static void setFloat(GLint location, GLfloat f1, GLfloat f2, GLfloat f3, GLfloat f4); private: static const uint64_t NANOS_PER_TICK = 50000000; static const int MAX_TICKS_PER_FRAME = 5; static GLchar* readFile(const char* name); static bool checkShaderErrors(const char* name, GLuint shader); static GLuint compileProgram(GLuint& vShader, GLuint& fShader, const GLchar* vertex, const GLchar* fragment); static GLuint createProgram(GLuint& vShader, GLuint& fShader); static void onKeyEvent(GLFWwindow* w, int key, int scancode, int action, int mods); static void onMouseClick(GLFWwindow* w, int button, int action, int mods); static void onWindowResize(GLFWwindow* w, int width, int height); static void updateScale(); static IClient* client; static GLFWwindow* window; static GLuint vShader; static GLuint fShader; static GLuint program; static int scale; static int width; static int height; }; #endif