Commit d14e5286 authored by Elias Broschin's avatar Elias Broschin
Browse files

game state machine

parent 878bf740
// Add predefined macros for your project here. For example:
// #define THE_ANSWER 42
This diff is collapsed.
lib/glew/auto/src
lib/glew/include/GL
lib/sdl2/i686-w64-mingw32/include/SDL2
lib/sdl2/include
lib/sdl2/test
lib/sdl2/x86_64-w64-mingw32/include/SDL2
lib/sdl2_mixer/i686-w64-mingw32/include/SDL2
lib/sdl2_mixer/x86_64-w64-mingw32/include/SDL2
include/core
include/
lib/
lib/glm/glm/glm.hpp
tools/mesh_converter/lib/assimp/code
tools/mesh_converter/lib/assimp/code/res
tools/mesh_converter/lib/assimp/contrib/ConvertUTF
tools/mesh_converter/lib/assimp/contrib/irrXML
tools/mesh_converter/lib/assimp/contrib/openddlparser/include/openddlparser
tools/mesh_converter/lib/assimp/contrib/poly2tri/poly2tri
tools/mesh_converter/lib/assimp/contrib/poly2tri/poly2tri/common
tools/mesh_converter/lib/assimp/contrib/poly2tri/poly2tri/sweep
tools/mesh_converter/lib/assimp/contrib/unzip
tools/mesh_converter/lib/assimp/contrib/zlib
tools/mesh_converter/lib/assimp/doc
tools/mesh_converter/lib/assimp/include/assimp
tools/mesh_converter/lib/assimp/include/assimp/Compiler
tools/mesh_converter/lib/assimp/include/assimp/port/AndroidJNI
tools/mesh_converter/lib/assimp/port/jassimp/jassimp-native/src
tools/mesh_converter/lib/assimp/samples/DevIL/include/IL
tools/mesh_converter/lib/assimp/samples/glut/GL
tools/mesh_converter/lib/assimp/samples/SimpleAssimpViewX
tools/mesh_converter/lib/assimp/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/include
tools/mesh_converter/lib/assimp/test/unit
tools/mesh_converter/lib/assimp/tools/assimp_cmd
tools/mesh_converter/lib/assimp/tools/assimp_view
include/asset
src/graphics
src/game_state_machine
src/core
glm
tools/mesh_converter/src
include/graphics
lib/gli/test/gtx
lib/gli/test/core
tools/mesh_converter/lib/glm/glm/gtc
lib/gli/external/glm-0.9.5.1/glm
lib/gli/external/glm-0.9.5.1/test/core
src
src/util
tools/mesh_converter/lib/assimp/contrib/clipper
lib/gli/external/glm-0.9.5.1/test/external/gli/core
tools/mesh_converter/lib/assimp/port/AndroidJNI
tools/mesh_converter/lib/glm/glm/detail
lib/glew/src
tools/mesh_converter/lib/glm/test/gtc
tools/mesh_converter/lib/assimp/code/BoostWorkaround/boost/tuple
lib/glm/test/external/gli
lib/glm/test/external/gli/core
lib/gli/external/glm-0.9.5.1/test/external/gli/gtx
lib/glm/glm
tools/mesh_converter/lib/glm/glm/gtx
tools/mesh_converter/lib/glm/test/external/gli
tools/mesh_converter/lib/assimp/code/BoostWorkaround/boost/math
tools/mesh_converter/lib/glm/test/core
tools/mesh_converter/lib/assimp/code/BoostWorkaround/boost
lib/gli/test/gtc
src/ecs
tools/mesh_converter/include
lib/gli/external/glm-0.9.5.1/test/external/gli
include/core
tools/mesh_converter/lib/glm/test/external/gli/core
lib/glm/glm/gtc
lib/gli/test
tools/mesh_converter/lib/glm/test/gtx
src/asset
src/audio
src/core
lib/glm/glm/gtx
lib/glm/test/core
lib/gli/external/glm-0.9.5.1/test/gtx
lib/glm/test/gtx
lib/gli/gli/core
lib/gli/gli
src/rendering
tools/mesh_converter/lib/assimp/samples/SimpleOpenGL
lib/gli/test/bug
lib/gli/external/glm-0.9.5.1/glm/detail
tools/mesh_converter/lib/glm/glm
lib/glew/build/cmake/testbuild
lib/gli/external/glm-0.9.5.1/test/gtc
tools/mesh_converter/lib/assimp/contrib/openddlparser/code
lib/glm/test/gtc
include/rendering
tools/mesh_converter/lib/glm/test/external/gli/gtx
include/util
lib/gli/external/glm-0.9.5.1/glm/virtrev
lib/gli/external/glm-0.9.5.1/glm/gtx
include/ecs
tools/mesh_converter/lib/assimp/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src
include/audio
lib/glm/test/external/gli/gtx
lib/glm/glm/detail
lib/gli/external/glm-0.9.5.1/glm/gtc
include/game_state_machine
......@@ -9,6 +9,7 @@ namespace gdw {
class audio;
class graphics_system;
class rendering_system;
class game_state_machine;
}
namespace gdw {
......@@ -20,6 +21,7 @@ namespace gdw {
std::unique_ptr<gdw::audio> audio_;
std::unique_ptr<gdw::graphics_system> graphics_system_;
std::unique_ptr<gdw::rendering_system> rendering_system_;
std::unique_ptr<gdw::game_state_machine> game_state_machine_;
// needs to be the last one that will be destroyed
gdw::entity_manager entity_manager_;
......
......@@ -3,6 +3,7 @@
#include <memory>
#include <unordered_map>
#include <utility>
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
......
#ifndef GAME_STATE_H
#define GAME_STATE_H
namespace gdw {
class engine;
class game_state {
public:
game_state(engine &engine);
virtual ~game_state();
virtual void update() = 0;
virtual void on_exit() = 0;
virtual void on_enter() = 0;
unsigned long long id() {return id_;}
protected:
engine& engine_;
unsigned long long id_;
};
} //Namespace gdw
#endif // GAME_STATE_H
#ifndef __GAME_STATE_MACHINE__
#define __GAME_STATE_MACHINE__
#include <map>
#include <memory>
namespace gdw {
class engine;
class game_state;
class game_state_machine {
public:
game_state_machine(engine &engine);
~game_state_machine();
void change_state(unsigned long long id);
void update();
private:
gdw::engine& engine_;
std::map<unsigned long long, std::unique_ptr<game_state>> game_states_;
game_state* current_state_;
};
} //Namespace gdw
#endif
#ifndef __MENU_STATE__
#define __MENU_STATE__
#include <game_state_machine/game_state.h>
namespace gdw {
class menu_state : public game_state {
public:
menu_state(engine& engine);
~menu_state();
void update();
void on_enter();
void on_exit();
};
} //Namespace gdw
#endif
#ifndef __PLAY_STATE__
#define __PLAY_STATE__
#include <game_state_machine/game_state.h>
namespace gdw {
class play_state : public game_state {
public:
play_state(engine& engine);
~play_state();
void update();
void on_enter();
void on_exit();
};
} //Namespace gdw
#endif
......@@ -13,6 +13,7 @@
#include <util/config.hpp>
#include <util/logger.hpp>
#include <util/make_unique.hpp>
#include <game_state_machine/game_state_machine.h>
namespace gdw {
engine::engine()
......@@ -27,6 +28,7 @@ namespace gdw {
audio_ = make_unique<gdw::audio>(*this);
graphics_system_ = make_unique<gdw::graphics_system>(*this);
rendering_system_ = make_unique<gdw::rendering_system>(*this);
game_state_machine_ = make_unique<gdw::game_state_machine>(*this);
}
engine::~engine() noexcept {
......@@ -34,6 +36,7 @@ namespace gdw {
}
void engine::update(float delta_time) {
game_state_machine_->update();
graphics_system_->begin();
rendering_system_->update(delta_time);
graphics_system_->end(delta_time);
......
#include <game_state_machine/game_state.h>
namespace gdw {
game_state::game_state(engine &engine):engine_(engine) {
}
game_state::~game_state() {
}
} //Namespace gdw
#include <game_state_machine/game_state_machine.h>
#include <core/engine.hpp>
#include <game_state_machine/game_state.h>
#include <util/id.hpp>
#include <util/make_unique.hpp>
#include <game_state_machine/play_state.h>
#include <game_state_machine/menu_state.h>
namespace gdw {
game_state_machine::game_state_machine(engine& engine):engine_(engine), current_state_(nullptr) {
game_states_[type_id<play_state>()] = make_unique<play_state>(engine);
game_states_[type_id<menu_state>()] = make_unique<menu_state>(engine);
//default state
current_state_ = game_states_[type_id<play_state>()].get();
}
game_state_machine::~game_state_machine() {
}
void game_state_machine::change_state(unsigned long long id) {
if(!current_state_) return;
if(current_state_->id() == id) return;
if(!Util::Map::findKey(states_, type)) return nullptr;
// currentState()->onExit();
// stateStack_.pop();
// stateStack_.push(states_[type].get());
// engine_.uiManager().notifyStateChange(currentState()->type());
// currentState()->onEnter();
// return currentState();
}
void game_state_machine::update() {
if(current_state_)
current_state_->update();
}
} //namespace gdw
#include <game_state_machine/menu_state.h>
#include <util/id.hpp>
#include <core/engine.hpp>
#include <ecs/entity_manager.hpp>
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
#include <ecs/entity.hpp>
namespace gdw {
menu_state::menu_state(engine &engine):game_state(engine) {
id_ = type_id<menu_state>();
}
menu_state::~menu_state() {}
void menu_state::on_enter() {
}
void menu_state::update() {
}
void menu_state::on_exit() {
}
} //namespace gdw
#include <game_state_machine/play_state.h>
#include <util/id.hpp>
#include <core/engine.hpp>
#include <ecs/entity_manager.hpp>
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
#include <ecs/entity.hpp>
namespace gdw {
play_state::play_state(engine &engine):game_state(engine) {
id_ = type_id<play_state>();
}
play_state::~play_state() {}
void play_state::on_enter() {
}
void play_state::update() {
}
void play_state::on_exit() {
}
} //namespace gdw
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment