Commit d2a5b660 authored by Benjamin Barz's avatar Benjamin Barz
Browse files

branch was merged; ignore or delete this

parents 20d63a79 f3ef5f8e
......@@ -2,10 +2,15 @@ cmake_minimum_required(VERSION 3.1)
project(gdw_ss15_cpp)
#use clang instead of g++
set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
#set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -stdlib=libc++")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -Wall -Wextra")
#set compiler options
if (${CMAKE_CXX_COMPILER} MATCHES "clang")
set(CMAKE_CXX_FLAGS "${CMAKE_FXX_FLAGS} -stdlib=libc++")
endif ()
#define symbols for debug build
if (CMAKE_BUILD_TYPE STREQUAL Debug)
......@@ -24,8 +29,10 @@ include_directories(
"${CMAKE_CURRENT_SOURCE_DIR}/lib/glew/include"
"${CMAKE_CURRENT_SOURCE_DIR}/lib/gli"
"${CMAKE_CURRENT_SOURCE_DIR}/lib/glm"
"${CMAKE_CURRENT_SOURCE_DIR}/lib/sdl2/include"
"${CMAKE_CURRENT_SOURCE_DIR}/lib/sdl2_mixer/x86_64-w64-mingw32/include/SDL2"
"${CMAKE_CURRENT_SOURCE_DIR}/lib/awesomium_1.7.5/include"
"${CMAKE_CURRENT_SOURCE_DIR}/include"
)
FILE(GLOB_RECURSE clion_all_headers
......
This diff is collapsed.
......@@ -111,3 +111,19 @@ src/physics
src/physics/collision
include/input
src/input
lib/recastnavigation/DetourTileCache/Source
lib/recastnavigation/DetourTileCache/Include
lib/recastnavigation/RecastDemo/Source
include/gameplay
lib/recastnavigation/Detour/Include
lib/recastnavigation/DebugUtils/Source
lib/recastnavigation/DetourCrowd/Source
lib/recastnavigation/RecastDemo/Contrib
src/gameplay
lib/recastnavigation/Detour/Source
lib/recastnavigation/Recast/Source
lib/recastnavigation/DebugUtils/Include
lib/recastnavigation/DetourCrowd/Include
lib/recastnavigation/RecastDemo/Contrib/fastlz
lib/recastnavigation/RecastDemo/Include
lib/recastnavigation/Recast/Include
......@@ -7,3 +7,7 @@ music_volume : 100
sound_volume : 100
debug_render : false
shadow_resolution : 256
camX : 0
camY : -20
camZ : 32
camAngle : 50
\ No newline at end of file
......@@ -2,11 +2,13 @@
#define __PLAY_STATE__
#include <game_state_machine/game_state.h>
#include <memory>
namespace gdw {
class entity;
class movement_component;
class level_manager;
class play_state : public game_state {
public:
......@@ -16,14 +18,16 @@ public:
void update(float dt);
void on_enter();
void on_exit();
private:
entity* wcube_;
movement_component* wcube_move_;
float y_rot;
int rotateDirection;
gdw::level_manager* level_manager() {return level_manager_.get();}
void handle_player_input();
private:
std::unique_ptr<gdw::level_manager> level_manager_;
float y_rot;
int rotateDirection;
//auto move;
};
} //Namespace gdw
......
#ifndef __LEVEL_MANAGER__
#define __LEVEL_MANAGER__
#include <vector>
#include <memory>
#include <glm/glm.hpp>
namespace gdw {
class entity;
class engine;
class level_manager {
public:
level_manager(engine& engine);
~level_manager();
void build_stage();
entity* player();
entity* camera();
void create_victim(float y);
void update(float dt);
float player_speed() {return player_speed_;}
void create_asteroid(glm::vec2 pos);
private:
private:
engine& engine_;
std::vector<unsigned long long> victims_;
std::vector<unsigned long long> asteroids_;
unsigned long long player_;
unsigned long long camera_;
//Player Attributes
const float player_speed_;
};
} //Namespace gdw
#endif
......@@ -18,15 +18,15 @@ namespace gdw{
~collision_component();
gdw::collision_shape* collision_shape() {return collision_shape_.get();}
void set_trigger(std::function<void()> trigger) {trigger_ = trigger;}
void call_trigger() {trigger_();}
void set_trigger(std::function<void(unsigned long long, unsigned long long)> trigger) {trigger_ = trigger;}
void call_trigger(unsigned long long self_id, unsigned long long coll_id) {trigger_(self_id, coll_id);}
static unsigned long long type_id() {
return gdw::type_id<gdw::collision_component>();
}
private:
std::unique_ptr<gdw::collision_shape> collision_shape_;
std::function<void()> trigger_;
std::function<void(unsigned long long, unsigned long long)> trigger_;
};
}
......
......@@ -6,9 +6,9 @@
#include <ecs/component.hpp>
#include <util/id.hpp>
#include <ecs/entity.hpp>
namespace gdw {
class entity;
class engine;
}
......
......@@ -20,6 +20,9 @@
#include <util/make_unique.hpp>
#include <util/logger.hpp>
#include <input/input.hpp>
#include <time.h>
#include <gameplay/level_manager.h>
#include <glm/gtx/intersect.hpp>
#include <input/input.hpp>
#include <SDL_keycode.h>
......@@ -28,95 +31,103 @@ namespace gdw {
play_state::play_state(engine &engine):game_state(engine) {
id_ = type_id<play_state>();
y_rot = 180.f;
y_rot = M_PI/2;
rotateDirection = 0;
level_manager_ = make_unique<gdw::level_manager>(engine);
}
play_state::~play_state() {}
void play_state::on_enter() {
level_manager_->build_stage();
}
auto& entity_manager = engine_.entity_manager();
auto& rendering_system = engine_.rendering_system();
auto& camera = entity_manager.emplace_back(glm::vec3(0.f, 6.f, 15.f), glm::angleAxis(glm::radians(-20.f), glm::vec3(1.f, 0.f, 0.f)));
camera.emplace_back<camera_component>();
rendering_system.active_camera(camera.id());
void play_state::update(float dt) {
handle_player_input();
level_manager_->update(dt);
/*
float rotSpeed = 3.5f;
// left
if(rotateDirection == -1) {
if(y_rot > -M_PI/2) {
y_rot -= rotSpeed;
} else {
y_rot = -M_PI/2;
rotateDirection = 0;
move->add_force(glm::vec3(-level_manager_->player_speed(), 0.f, 0.f));
//wcube_move_->add_force(glm::vec3((-sideSpeed*dt), 0, 0));
}
// right
} else if(rotateDirection == 1) {
if(y_rot < M_PI/2) {
y_rot += rotSpeed;
} else {
y_rot = M_PI/2;
rotateDirection = 0;
move->add_force(level_manager_->player_speed(), 0, 0));
}
}
if(rotateDirection != 0) {
move->rotation(glm::angleAxis(y_rot, glm::vec3(0.f, 1.f, 0.f)));
//wcube_move_->set_angular_speed(0.f, dt*rotSpeed*rotateDirection, 0.f);
}*/
auto& light = entity_manager.emplace_back(glm::vec3(5.f), glm::angleAxis(0.f, glm::vec3(0.f)));
light.emplace_back<light_component>(glm::vec3(1.f), 10.f);
}
auto& sun = entity_manager.emplace_back(glm::vec3(1.f, 0.3f, 1.f), glm::angleAxis(0.f, glm::vec3(0.f)));
sun.emplace_back<directional_light_component>(glm::vec3(1.f), 1.f);
sun.emplace_back<shadow_component>(40.f);
void play_state::on_exit() {
auto& plane = entity_manager.emplace_back(glm::vec3(0.f), glm::angleAxis(0.f, glm::vec3(0.f)));
plane.emplace_back<staticmesh_component>("mesh/plane.msh");
}
wcube_ = &engine_.entity_manager().emplace_back(glm::vec3(0.f, 1.2f, 0.f), glm::angleAxis(glm::radians(90.f), glm::vec3(0.f, 1.f, 0.f)));
wcube_->emplace_back<staticmesh_component>("mesh/pirate_ship.msh");
void play_state::handle_player_input() {
auto player = level_manager_->player();
auto move = player->component<movement_component>();
if(!move) return;
auto input = engine_.input();
wcube_move_ = &wcube_->emplace_back<movement_component>();
if(input.isKeyDown(SDLK_a)) {
rotateDirection = -1;
//move->add_force(glm::vec3(-level_manager_->player_speed(), 0.f, 0.f));
}
if(input.isKeyDown(SDLK_d)) {
rotateDirection = 1;
//move->add_force(glm::vec3(level_manager_->player_speed(), 0.f, 0.f));
}
// wcube2_ = &engine_.entity_manager().emplace_back(glm::vec3(0.f), glm::angleAxis(0.f, glm::vec3(0.f)));
// wcube2_->emplace_back<staticmesh_component>("mesh/cube.msh");
// auto &wcube_col2_ = wcube2_->emplace_back<collision_component>(new sphere(glm::vec3(0.f), 1.2f));
// //wcube_col2_.set_trigger([](){std::cout << "trigger 2" << std::endl;});
// wcube2_move_ = &wcube2_->emplace_back<movement_component>();
//wcube_move_->set_damping(100.f);
//wcube_move_->set_mass(1.f);
y_rot = 0.f;
rotateDirection = M_PI/2;
}
if(input.isMouseButtonDown(1)) {
float x = (input.mousePos().x/800.0f) * 2.0f -1;
float y = (input.mousePos().y/600.0f) * 2.0f -1;
void play_state::update(float dt) {
auto cam = level_manager_->camera()->component<camera_component>();
auto camera = level_manager_->camera();
auto mouse_pos = glm::vec2(x, -y);
auto inv_proj_view = glm::inverse(cam->projection_view());
auto world_pos_near = inv_proj_view * glm::vec4(mouse_pos,0.1f,1.f);
auto world_pos_far = inv_proj_view * glm::vec4(mouse_pos,0.9f,1.f);
world_pos_near /= world_pos_near.w;
world_pos_far /= world_pos_far.w;
//todo: checken, ob schiff im bild
if (engine_.input().isKeyDown(SDLK_LEFT) && wcube_->position().x > -2.f ) {
rotateDirection = -1;
}
if (engine_.input().isKeyDown(SDLK_RIGHT) && wcube_->position().x < 2.f ) {
rotateDirection = 1;
}
float sideSpeed = 150.f;
float rotSpeed = 3.5f;
// left
if(rotateDirection == -1) {
if(y_rot > -M_PI/2) {
y_rot -= dt*rotSpeed;
} else {
y_rot = -M_PI/2;
rotateDirection = 0;
wcube_move_->add_force(glm::vec3((-sideSpeed*dt), 0, 0));
}
// right
} else if(rotateDirection == 1) {
if(y_rot < M_PI/2) {
y_rot += dt*rotSpeed;
} else {
y_rot = M_PI/2;
rotateDirection = 0;
wcube_move_->add_force(glm::vec3((sideSpeed*dt), 0, 0));
}
}
if(rotateDirection != 0) {
wcube_move_->owner().rotation(glm::angleAxis(y_rot, glm::vec3(0.f, 1.f, 0.f)));
//wcube_move_->set_angular_speed(0.f, dt*rotSpeed*rotateDirection, 0.f);
}
auto ray_dir = world_pos_far - world_pos_near;
auto final_pos = world_pos_near + ray_dir;
auto& entity_manager = engine_.entity_manager();
//auto plane_normal = glm::normalize(glm::angleAxis(glm::radians(90.f), glm::vec3(1,0,0)) * glm::vec3(0,0,1));
auto plane_normal = glm::vec3(0,0,1);
}
float d = glm::dot(glm::vec3(0,15,0) - glm::vec3(world_pos_near), plane_normal) / glm::dot(glm::vec3(glm::normalize(-ray_dir)), plane_normal);
void play_state::on_exit() {
auto intersection_point = camera->position()-glm::vec3((glm::normalize(ray_dir))*d);
auto &asteroid = entity_manager.emplace_back(intersection_point, glm::angleAxis(glm::radians(0.f), glm::vec3(0.f, 0.f, 0.f)));
asteroid.emplace_back<staticmesh_component>("mesh/cube.msh");
asteroid.scale(glm::vec3(1.f));
}
}
} //namespace gdw
#include <gameplay/level_manager.h>
#include <core/engine.hpp>
#include <ecs/entity_manager.hpp>
#include <rendering/rendering_system.hpp>
#include <rendering/camera_component.hpp>
#include <rendering/light_component.hpp>
#include <rendering/shadow_component.hpp>
#include <rendering/directional_light_component.hpp>
#include <rendering/staticmesh_component.hpp>
#include <physics/movement/movement_component.h>
#include <ecs/entity.hpp>
#include <time.h>
#include <iostream>
#include <util/config_manager.hpp>
#include <util/config.hpp>
#include <string>
#include <util/list_helper.h>
namespace gdw {
level_manager::level_manager(engine& engine):engine_(engine), player_speed_(80.f) {
}
level_manager::~level_manager() {
}
//Make dependent on stage later
void level_manager::build_stage() {
auto& entity_manager = engine_.entity_manager();
auto& rendering_system = engine_.rendering_system();
auto ptr = engine_.config_manager().load("config/settings");
float cam_x = ptr->get<float>("camX", 0.f);
float cam_y = ptr->get<float>("camY", 0.f);
float cam_z = ptr->get<float>("camZ", 0.f);
float cam_rad = ptr->get<float>("camAngle", 0.f);
auto& camera = entity_manager.emplace_back(glm::vec3(cam_x, cam_y, cam_z), glm::angleAxis(glm::radians(cam_rad), glm::vec3(1.f, 0.f, 0.f)));
camera.emplace_back<camera_component>();
camera_ = camera.id();
rendering_system.active_camera(camera_);
auto& light = entity_manager.emplace_back(glm::vec3(5.f), glm::angleAxis(0.f, glm::vec3(0.f)));
light.emplace_back<light_component>(glm::vec3(1.f), 10.f);
auto& sun = entity_manager.emplace_back(glm::vec3(1.f, 0.3f, 1.f), glm::angleAxis(0.f, glm::vec3(0.f)));
sun.emplace_back<directional_light_component>(glm::vec3(1.f), 1.f);
sun.emplace_back<shadow_component>(40.f);
auto& plane = entity_manager.emplace_back(glm::vec3(0.f, 15.f, 0.f), glm::angleAxis(glm::radians(90.f), glm::vec3(1,0,0)));
plane.emplace_back<staticmesh_component>("mesh/plane.msh");
plane.scale(glm::vec3(2.f));
auto& player = engine_.entity_manager().emplace_back(glm::vec3(0.f, 0.f, 3.f), glm::angleAxis(glm::radians(90.f), glm::vec3(0.f, 1.f, 0.f)));
player.rotation(glm::angleAxis(glm::radians(90.f), glm::vec3(1,0,0))*player.rotation());
player.emplace_back<staticmesh_component>("mesh/pirate_ship.msh");
auto &player_move = player.emplace_back<movement_component>();
player_move.set_damping(5.f);
player_ = player.id();
//Build Asteroids
constexpr int asteroid_count = 6;
constexpr int max = 2;
constexpr int min = 1;
constexpr float off = 36.f / asteroid_count;
srand (time(0));
for(int i = 0; i < asteroid_count; i++) {
int r = (rand() % max + min);
//if(r > 1)
create_asteroid(glm::vec2(-15+(off*i),24));
}
srand (time(0)+2);
for(int i = 0; i < asteroid_count; i++) {
int r = (rand() % max + min);
//if(r > 1)
create_asteroid(glm::vec2(-15+(off*i),16));
}
srand (time(0)+5);
for(int i = 0; i < asteroid_count; i++) {
int r = (rand() % max + min);
//if(r > 1)
create_asteroid(glm::vec2(-15+(off*i),8));
}
srand (time(0)+7);
for(int i = 0; i < asteroid_count; i++) {
int r = (rand() % max + min);
//if(r > 1)
create_asteroid(glm::vec2(-15+(off*i),32));
}
}
void level_manager::update(float dt) {
static float t = 10.f;
t += dt;
if(t >= 3.f) {
srand (time(0));
constexpr int max = 32;
constexpr int min = 8;
int y = (rand() % max + min);
create_victim(y);
t = 0.f;
}
std::vector<unsigned long long> del_queue;
for(int i = 0; i < victims_.size(); i++) {
auto victim = engine_.entity_manager().resolve(victims_[i]);
if(!victim) continue;
auto move = victim->component<movement_component>();
if(!move) continue;
move->add_force(glm::vec3(10.f,0.f,0.f));
if(victim->position().x >= 30.f) {
del_queue.emplace_back(victims_[i]);
}
}
for(auto &id : del_queue) {
list_helper::removeElement(victims_, id);
engine_.entity_manager().erase(id);
}
}
entity* level_manager::player() {
return engine_.entity_manager().resolve(player_);
}
entity* level_manager::camera() {
return engine_.entity_manager().resolve(camera_);
}
void level_manager::create_asteroid(glm::vec2 pos) {
auto& entity_manager = engine_.entity_manager();
auto &asteroid = entity_manager.emplace_back(glm::vec3(pos, 3.f), glm::angleAxis(glm::radians(0.f), glm::vec3(0.f, 0.f, 0.f)));
asteroid.emplace_back<staticmesh_component>("mesh/cube.msh");
}
void level_manager::create_victim(float y) {
auto& entity_manager = engine_.entity_manager();
auto &victim = entity_manager.emplace_back(glm::vec3(-20.f, y, 3.f), glm::angleAxis(glm::radians(90.f), glm::vec3(0.f, 1.f, 0.f)));
victim.rotation(glm::angleAxis(glm::radians(90.f), glm::vec3(1,0,0))*victim.rotation());
victim.scale(glm::vec3(0.4f));
victim.emplace_back<staticmesh_component>("mesh/pirate_ship.msh");
auto &move = victim.emplace_back<movement_component>();
move.set_damping(2.f);
victims_.emplace_back(victim.id());
}
} //Namespace gdw
#include <gameplay/scene_manager.h>
#include <core/engine.hpp>
#include <ecs/entity_manager.hpp>
#include <rendering/rendering_system.hpp>
#include <rendering/camera_component.hpp>
#include <rendering/light_component.hpp>
#include <rendering/shadow_component.hpp>
#include <rendering/directional_light_component.hpp>
#include <rendering/staticmesh_component.hpp>
#include <physics/movement/movement_component.h>
#include <ecs/entity.hpp>
#include <time.h>
#include <iostream>
#include <util/config_manager.hpp>
#include <util/config.hpp>
#include <string>
namespace gdw {
scene_manager::scene_manager(engine& engine):engine_(engine) {
}
scene_manager::~scene_manager() {
}
//Make dependent on stage later
void scene_manager::build_stage() {
auto& entity_manager = engine_.entity_manager();
auto& rendering_system = engine_.rendering_system();
auto ptr = engine_.config_manager().load("config/settings");
float cam_x = ptr->get<float>("camX", 0.f);
float cam_y = ptr->get<float>("camY", 0.f);
float cam_z = ptr->get<float>("camZ", 0.f);
float cam_rad = ptr->get<float>("camAngle", 0.f);
auto& camera = entity_manager.emplace_back(glm::vec3(cam_x, cam_y, cam_z), glm::angleAxis(glm::radians(cam_rad), glm::vec3(1.f, 0.f, 0.f)));
camera.emplace_back<camera_component>();
rendering_system.active_camera(camera.id());
auto& light = entity_manager.emplace_back(glm::vec3(5.f), glm::angleAxis(0.f, glm::vec3(0.f)));
light.emplace_back<light_component>(glm::vec3(1.f), 10.f);
auto& sun = entity_manager.emplace_back(glm::vec3(1.f, 0.3f, 1.f), glm::angleAxis(0.f, glm::vec3(0.f)));
sun.emplace_back<directional_light_component>(glm::vec3(1.f), 1.f);
sun.emplace_back<shadow_component>(40.f);
auto& plane = entity_manager.emplace_back(glm::vec3(0.f, 15.f, 0.f), glm::angleAxis(glm::radians(90.f), glm::vec3(1,0,0)));
plane.emplace_back<staticmesh_component>("mesh/plane.msh");
plane.scale(glm::vec3(2.f));
auto& player = engine_.entity_manager().emplace_back(glm::vec3(0.f, 0.f, 3.f), glm::angleAxis(glm::radians(90.f), glm::vec3(0.f, 1.f, 0.f)));
player.rotation(glm::angleAxis(glm::radians(90.f), glm::vec3(1,0,0))*player.rotation());
player.emplace_back<staticmesh_component>("mesh/pirate_ship.msh");
player_ = player.id();
//Build Asteroids
constexpr int asteroid_count = 6;
constexpr int max = 2;
constexpr int min = 1;
constexpr float off = 36.f / asteroid_count;
srand (time(0));
for(int i = 0; i < asteroid_count; i++) {
int r = (rand() % max + min);
//if(r > 1)
create_asteroid(glm::vec2(-15+(off*i),24));
}
srand (time(0)+2);
for(int i = 0; i < asteroid_count; i++) {
int r = (rand() % max + min);
//if(r > 1)
create_asteroid(glm::vec2(-15+(off*i),16));
}
srand (time(0)+5);
for(int i = 0; i < asteroid_count; i++) {
int r = (rand() % max + min);
//if(r > 1)
create_asteroid(glm::vec2(-15+(off*i),8));
}
srand (time(0)+7);
for(int i = 0; i < asteroid_count; i++) {
int r = (rand() % max + min);
//if(r > 1)
create_asteroid(glm::vec2(-15+(off*i),32));
}
}