#pragma once #include #include #include #include #ifdef __linux__ #include #else #include #endif #include #include "event/event.h" #include "simpleengine/renderable.h" namespace simpleengine { class Game { private: using self = simpleengine::Game; public: /** * @brief Construct a new Game object. Initializes GLEW and OpenGL * * @param w Width of viewport * @param h Height of viewport * @param window_name The name of the window */ Game(int w, int h, const std::string& window_name, const int& gl_profile = GLFW_OPENGL_CORE_PROFILE, const int& major_version = 4, const int& minor_version = 4, const bool& resizeable = false, const int& forward_compat = GL_TRUE); virtual ~Game(); void enable_default_gl_options() const; void enable_gl_option(GLenum option) const; void add_event(std::shared_ptr event); void add_renderable(std::shared_ptr renderable_event); void set_fps_limit(const int& fps_limit); void set_enable_vsync(const bool& enabled); void update(const float& delta_time); void handle_input(const float& delta_time); void render_window(const float& interpolate_alpha, const float& delta_time); void render_items(const float& interpolate_alpha, const float& delta_time); void exit(); int run(); //void AddEvent(Event* event); GLFWwindow* get_window(); private: static void framebuffer_resize_callback(GLFWwindow*, int fbW, int fbH); void initialize(const int& gl_profile, const int& major_version, const int& minor_version, const bool& resizeable, const int& forward_compat = GL_TRUE); GLFWwindow* window; std::vector> events; std::vector> renderable_events; const bool& window_resizeable; // FPS related stuff void update_enabled_vsync() const; void limit_framerate(const float& delta_time) const; // Triggered at the end of a draw to help limit the FPS to `fps_limit`. int fps_limit = -1; bool enable_vsync = true; int max_engine_tps = 60; // The maximum engine TPS double tps_accumulator = 0.f; //int engine_ticks_second = 0; // The amount of ticks in a second //double last_sec_engine_tick; // The time of the last second float get_delta_time(); std::chrono::high_resolution_clock::time_point last_frame_time; }; }