2021-11-27 19:16:41 +00:00
|
|
|
#pragma once
|
2020-07-03 03:48:58 +00:00
|
|
|
|
2022-09-16 15:14:38 +00:00
|
|
|
#include <chrono>
|
2021-11-20 05:48:47 +00:00
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
2021-11-21 06:23:53 +00:00
|
|
|
#include <vector>
|
2020-07-03 03:48:58 +00:00
|
|
|
|
2021-12-02 21:56:49 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
#include <GL/glew.h>
|
2021-12-13 03:17:59 +00:00
|
|
|
#else
|
2021-11-20 05:48:47 +00:00
|
|
|
#include <gl/glew.h>
|
2021-12-02 21:56:49 +00:00
|
|
|
#endif
|
|
|
|
|
2021-11-20 05:48:47 +00:00
|
|
|
#include <GLFW/glfw3.h>
|
2020-07-03 20:26:44 +00:00
|
|
|
|
2021-11-21 06:23:53 +00:00
|
|
|
#include "event/event.h"
|
2022-09-16 15:14:38 +00:00
|
|
|
#include "simpleengine/renderable.h"
|
2021-11-21 06:23:53 +00:00
|
|
|
|
2020-07-03 03:48:58 +00:00
|
|
|
namespace simpleengine {
|
|
|
|
class Game {
|
2021-11-21 06:23:53 +00:00
|
|
|
private:
|
|
|
|
using self = simpleengine::Game;
|
2020-07-03 03:48:58 +00:00
|
|
|
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
|
|
|
|
*/
|
2021-11-21 06:23:53 +00:00
|
|
|
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);
|
2020-07-03 03:48:58 +00:00
|
|
|
virtual ~Game();
|
|
|
|
|
2021-12-07 03:44:47 +00:00
|
|
|
void enable_default_gl_options() const;
|
|
|
|
void enable_gl_option(GLenum option) const;
|
|
|
|
|
2021-11-21 06:23:53 +00:00
|
|
|
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);
|
2021-11-21 06:23:53 +00:00
|
|
|
|
2022-08-18 15:34:05 +00:00
|
|
|
void update(const float& delta_time);
|
|
|
|
void handle_input(const float& delta_time);
|
2022-10-15 03:17:22 +00:00
|
|
|
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);
|
2021-12-02 21:56:49 +00:00
|
|
|
GLFWwindow* get_window();
|
2020-07-03 03:48:58 +00:00
|
|
|
private:
|
2021-11-20 05:48:47 +00:00
|
|
|
static void framebuffer_resize_callback(GLFWwindow*, int fbW, int fbH);
|
2020-07-03 03:48:58 +00:00
|
|
|
|
2021-11-21 06:23:53 +00:00
|
|
|
void initialize(const int& gl_profile, const int& major_version, const int& minor_version,
|
|
|
|
const bool& resizeable, const int& forward_compat = GL_TRUE);
|
|
|
|
|
2021-12-02 21:56:49 +00:00
|
|
|
GLFWwindow* window;
|
2021-11-21 06:23:53 +00:00
|
|
|
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;
|
2021-11-21 06:23:53 +00:00
|
|
|
const bool& window_resizeable;
|
2022-08-18 15:34:05 +00:00
|
|
|
|
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`.
|
2022-10-15 03:17:22 +00:00
|
|
|
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
|
2022-09-16 15:14:38 +00:00
|
|
|
|
2022-08-18 15:34:05 +00:00
|
|
|
float get_delta_time();
|
|
|
|
|
2022-09-16 15:14:38 +00:00
|
|
|
std::chrono::high_resolution_clock::time_point last_frame_time;
|
2020-07-03 03:48:58 +00:00
|
|
|
};
|
2021-11-27 19:16:41 +00:00
|
|
|
}
|