our_dick/include/egn/game_state.hpp

92 lines
2.3 KiB
C++

/**
This file is a part of our_dick
Copyright (C) 2020-2022 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OUR_DICK_ENGINE_GAME_STATE_HPP
#define OUR_DICK_ENGINE_GAME_STATE_HPP
#include "observable.hpp"
#include "input.hpp"
#include "wip/renderer.hpp"
#include <stack>
#include <memory>
#include <queue>
namespace egn{
class game;
struct game_state_event {
enum class state_type{
SHOULD_CLOSE,
RESIZE_WINDOW,
};
state_type type;
int value1;
int value2;
};
class game_state_iface;
class game_state_manager : public egn::observable<game_state_event>
{
private:
std::stack<std::unique_ptr<game_state_iface>> m_state_stack;
public:
template<typename... Args>
void emplace_state(Args&&... args);
void push_state(std::unique_ptr<game_state_iface>&& state);
void pop_state(void);
void replace_state(std::unique_ptr<game_state_iface>&& state);
void handle_input(std::queue<egn::input_event>& events);
void update(double time_diff);
void render(void);
};
class game_state_iface
{
protected:
game* m_owner = nullptr;
protected:
game_state_iface(game* owner);
game_state_iface(const game_state_iface& g) = default;
game_state_iface(game_state_iface&& g) = default;
game_state_iface& operator=(const game_state_iface&) = default;
game_state_iface& operator=(game_state_iface&&) = default;
wip::gfx::renderer& renderer(void);
const wip::gfx::renderer& renderer(void)const;
public:
virtual ~game_state_iface(void) = default;
virtual void enter(void) = 0;
virtual void leave(void) = 0;
virtual void handle_input(const egn::input_event& event) = 0;
virtual void update(double time) = 0;
virtual void render(void) = 0;
};
}
#endif