summaryrefslogblamecommitdiffstats
path: root/include/game.hpp
blob: d20510bbf51174ec417a5044b9c7358e14100fca (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13












                          
                            







                                                             
                                                                          





























                                                                                                         
#ifndef GAME_HPP
#define GAME_HPP 1

#include "window.hpp"
#include "camera.hpp"
#include "ecs.hpp"
#include "system.hpp"
#include "timeman.hpp"
#include "input.hpp"

#include <memory>

#define WINCTX_GAME "Game"
#define WINCTX_TITLE "Title"

class Game
{
public:
    enum class State {
        STOPPED, RUNNING, RUNNING_INPUT, PAUSED, PAUSED_INPUT
    };

    static void setup(unsigned w, unsigned h, const std::string &sysname);
    static void cleanup();

    static void turn();
    static void setState(State state) { m_state = state; }
    static void setContext(const std::string &id) { m_currentContext = id; }

    static bool running() { return m_state != State::STOPPED; }
    static bool paused() { return m_state == State::PAUSED || m_state == State::PAUSED_INPUT; }
    static bool inputMode() { return m_state == State::RUNNING_INPUT || m_state == State::PAUSED_INPUT; }

    struct WindowContexts {
        WindowContext &operator[](const std::string &id) { return Game::m_contexts.at(id); }
        WindowContext &operator()() { return Game::m_contexts.at(Game::m_currentContext); }
    };
    static WindowContexts contexts;
private:
    static std::unordered_map<std::string, WindowContext> m_contexts;
    static std::string m_currentContext;
    
    static std::unique_ptr<Camera> m_camera;
    static std::unique_ptr<System> m_system;
    static SystemView m_systemView;
    
    static input::Context m_inputContext;
    
    static double m_delta;
    static State m_state;
};

#endif