Commit 29a92101 authored by Fabio Gimmillaro's avatar Fabio Gimmillaro
Browse files

Merge branch 'develop' of gitlab.fsi.hochschule-trier.de:GameDevWeek/gdw_ss15_cpp into develop

parents f377f143 9e6220db
// 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_;
......@@ -64,6 +66,10 @@ namespace gdw {
gdw::rendering_system& rendering_system() noexcept {
return *rendering_system_;
}
gdw::game_state_machine& game_state_machine() noexcept {
return *game_state_machine_;
}
};
}
......
......@@ -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(float dt) = 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>
#include <util/id.hpp>
#include <game_state_machine/game_state.h>
#include <util/map_helper.h>
namespace gdw {
class engine;
class game_state;
class game_state_machine {
public:
game_state_machine(engine &engine);
~game_state_machine();
template<typename T>
void change_state() {
auto id = type_id<T>();
if(!current_state_ ||
current_state_->id() == id ||
!map_helper::findKey(game_states_, id))
return;
current_state_->on_exit();
current_state_ = game_states_[id].get();
current_state_->on_enter();
}
void update(float dt);
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(float dt);
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(float dt);
void on_enter();
void on_exit();
};
} //Namespace gdw
#endif
#ifndef __LIST_HELPER__
#define __LIST_HELPER__
#include <vector>
#include <list>
#include <algorithm>
namespace gdw {
namespace list_helper {
/** Searches for an element in a given vector.
* Returns true, when found.
*/
template<typename T>
bool findElement(std::vector<T> &vector, T elem) {
auto it = std::find(vector.begin(), vector.end(), elem);
return it != vector.end();
}
template<typename T>
bool findElement(std::list<T> &list, T elem) {
auto it = std::find(list.begin(), list.end(), elem);
return it != list.end();
}
/** Searches for an element in a given vector and removes it.
* Does not respect insertion order.
* Returns true, when found and removed, otherwise false.
*/
template<typename T>
bool removeElement(std::vector<T> &vector, const T& elem) {
auto it = std::find(vector.begin(), vector.end(), elem);
if(it == vector.end())
return false;
auto last = vector.end() -1;
if(it != last)
*it = *last;
vector.pop_back();
return true;
}
} //Namespace List
} // Namespace Util
#endif
#ifndef __MAPHELPER__
#define __MAPHELPER__
#include <map>
#include <unordered_map>
#include <list>
namespace gdw {
namespace map_helper {
template<typename T, typename U>
bool findKey(const std::map<T,U> &map, T key) {
auto it = map.find(key);
return it != map.end();
}
template<typename T, typename U>
bool removeKey(std::map<T,U> &map, T key) {
auto it = map.find(key);
if(it == map.end()) return false;
map.erase(it);
return true;
}
template<typename T, typename U>
bool findKey(const std::unordered_map<T,U> &map, T key) {
auto it = map.find(key);
return it != map.end();
}
template<typename T, typename U>
bool removeKey(std::unordered_map<T,U> &map, T key) {
auto it = map.find(key);
if(it == map.end()) return false;
map.erase(it);
return true;
}
template<typename T, typename U>
std::list<T> getKeys(std::unordered_map<T,U> &map) {
std::list<T> list;
if(!map.empty()) {
auto it = map.begin();
while(it != map.end()) {
list.push_back(it->first);
it++;
}
}
return list;
}
template<typename T, typename U>
std::list<T> getKeys(std::map<T,U> &map) {
std::list<T> list;
if(!map.empty()) {
auto it = map.begin();
while(it != map.end()) {
list.push_back(it->first);
it++;
}
}
return list;
}
} //Namespace List
} //Namespace Util
#endif
......@@ -19,4 +19,4 @@ namespace gdw {
}
#endif //__GDW_STACKTRACE_HPP__
\ No newline at end of file
#endif //__GDW_STACKTRACE_HPP__
......@@ -14,6 +14,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()
......@@ -28,6 +29,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);
auto& wcube = entity_manager_.emplace_back(glm::vec3(0.f), glm::angleAxis(0.f, glm::vec3(0.f)));
wcube.emplace_back<staticmesh_component>("mesh/cube.msh");
......@@ -38,6 +40,7 @@ namespace gdw {
}
void engine::update(float delta_time) {
game_state_machine_->update(delta_time);
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/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::update(float dt) {
if(current_state_)
current_state_->update(dt);
}
} //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>
#include <game_state_machine/game_state_machine.h>
#include <game_state_machine/play_state.h>
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(float dt) {
}
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>
#include <game_state_machine/game_state_machine.h>
#include <game_state_machine/menu_state.h>
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(float dt) {}
void play_state::on_exit() {
}
} //namespace gdw
......@@ -7,8 +7,8 @@
#include <util/stacktrace.hpp>
int main(int argc, char* argv[]) {
try {
gdw::initStacktrace(argv[0]);
try {
gdw::initStacktrace(argv[0]);
gdw::engine e;
e.run();
} catch (std::exception& ex) {
......
This diff is collapsed.
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