spacebox/src/Game.hpp

87 lines
2.0 KiB
C++

#ifndef Game_h_
#define Game_h_
#include <string>
#include <iostream>
#include <list>
#include <sstream>
#define SDL_MAIN_HANDLED
#include <SDL.h>
#include <SDL_mixer.h>
#include <SDL_ttf.h>
#define GL_GLEXT_PROTOTYPES
#define GLEW_STATIC
#include "glew/glew.h"
#include "Node.hpp"
#include "Configuration.hpp"
#include "Delegate.hpp"
#include "Display.hpp"
#include "Recorder.hpp"
#include "Input.hpp"
// #include "Sprite.hpp"
// struct FPSIndicator : Sprite
// {
// FPSIndicator(Node*);
// };
struct Game : Node
{
Game(const Game&) = delete;
Game& operator=(const Game&) = delete;
Game(Game&&) = delete;
Game& operator=(Game&&) = delete;
SDL_Window* window;
SDL_Renderer* renderer = NULL;
SDL_GLContext glcontext = NULL;
// 768, 432
// 864, 486
int frame_time_overflow = 0, framerate, ticks, last_frame_timestamp,
frame_count_timestamp, last_frame_length;
float frame_length;
bool done = false, show_framerate = true, is_gl_context = true;
Configuration configuration = Configuration(this);
Delegate delegate = Delegate(this);
Display display = Display(this);
Recorder recorder = Recorder(this);
Input input = Input(this);
Game();
~Game();
void print_error(std::string);
void print_sdl_error(std::string);
void print_gl_attributes();
void load_sdl_context();
void load_gl_context();
GLuint create_gl_texture();
bool log_gl_errors(std::string);
void log_display_mode();
void log_surface_format(SDL_Surface*, std::string = "surface");
std::string get_pixel_format_string(Uint32);
void run();
void flag_to_end();
virtual void update() {};
void set_framerate(int);
void handle_quit_event(SDL_Event&);
void quit();
std::string get_class_name() { return "Game"; }
template<typename T>
float get_weighted_amount(T amount)
{
return (last_frame_length / (1000.0 / 60)) * amount;
}
};
#include "Sprite.hpp"
#endif