SimpleEngine/include/simpleengine/game.h

75 lines
2.6 KiB
C
Raw Permalink Normal View History

#pragma once
2022-09-16 15:14:38 +00:00
#include <chrono>
2021-11-20 05:48:47 +00:00
#include <string>
#include <memory>
#include <vector>
#ifdef __linux__
#include <GL/glew.h>
#else
2021-11-20 05:48:47 +00:00
#include <gl/glew.h>
#endif
2021-11-20 05:48:47 +00:00
#include <GLFW/glfw3.h>
2020-07-03 20:26:44 +00:00
#include "event/event.h"
2022-09-16 15:14:38 +00:00
#include "simpleengine/renderable.h"
namespace simpleengine {
class Game {
private:
using self = simpleengine::Game;
public:
2021-11-20 05:48:47 +00:00
/**
* @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 add_event(std::shared_ptr<simpleengine::Event> event);
2022-09-16 15:14:38 +00:00
void add_renderable(std::shared_ptr<simpleengine::Renderable> renderable_event);
void set_fps_limit(const int& fps_limit);
void set_enable_vsync(const bool& enabled);
void update(const float& delta_time);
void input_update(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);
2021-11-20 05:48:47 +00:00
void exit();
int run();
2021-03-13 03:01:33 +00:00
2021-11-20 05:48:47 +00:00
//void AddEvent(Event* event);
GLFWwindow* get_window();
private:
2021-11-20 05:48:47 +00:00
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<std::shared_ptr<simpleengine::Event>> events;
2022-09-16 15:14:38 +00:00
std::vector<std::shared_ptr<simpleengine::Renderable>> renderable_events;
const bool& window_resizeable;
2022-09-16 15:14:38 +00:00
// 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;
// Engine TPS related stuff
2022-10-16 19:42:19 +00:00
int max_engine_tps = 120; // The maximum engine TPS
float fixed_delta_time = 1.f / (float) max_engine_tps; // The delta time from fixed timestep
float tps_accumulator = 0.f;
2022-09-16 15:14:38 +00:00
float get_delta_time();
2022-09-16 15:14:38 +00:00
std::chrono::high_resolution_clock::time_point last_frame_time;
};
}