Merge remote-tracking branch 'origin/master' into TextRendering

# Conflicts:
#	include/Engine/Rendering/RenderQueue.h
#	include/Engine/Rendering/RenderSystem.h
#	include/Game/Game.h
#	resources/Schema/Types/Entity.xsd
#	src/Engine/Rendering/RenderSystem.cpp
This commit is contained in:
viktorljung
2016-01-18 17:44:26 +01:00
159 changed files with 4202 additions and 990 deletions
+12 -6
View File
@@ -10,17 +10,23 @@ include_directories(
${Boost_INCLUDE_DIRS}
)
file(GLOB SOURCE_FILES
"${INCLUDE_PATH}/*.h"
#"*.cpp"
file(GLOB SOURCE_FILES_Systems
"${INCLUDE_PATH}/Systems/*.h"
"Systems/*.cpp"
)
#source_group(Core FILES ${SOURCE_FILES})
source_group(Systems FILES ${SOURCE_FILES_Systems})
file(GLOB SOURCE_FILES_Events
"${INCLUDE_PATH}/Events/*.h"
"Events/*.cpp"
)
source_group(Events FILES ${SOURCE_FILES_Events})
set(SOURCE_FILES
${SOURCE_FILES}
"Game.cpp"
"HealthSystem.cpp"
"PlayerSystem.cpp"
${SOURCE_FILES_Systems}
${SOURCE_FILES_Events}
)
set(LIBRARIES
+34 -9
View File
@@ -1,19 +1,28 @@
#include "Game.h"
#include "Collision/CollidableOctreeSystem.h"
#include "Collision/TriggerSystem.h"
#include "Collision/CollisionSystem.h"
#include "Game/HealthSystem.h"
#include "Systems/RaptorCopterSystem.h"
#include "Systems/HealthSystem.h"
#include "Systems/PlayerMovementSystem.h"
#include "Systems/SpawnerSystem.h"
#include "Systems/PlayerSpawnSystem.h"
#include "Core/EntityFileWriter.h"
Game::Game(int argc, char* argv[])
{
ResourceManager::RegisterType<ConfigFile>("ConfigFile");
ResourceManager::RegisterType<Sound>("Sound");
ResourceManager::RegisterType<Model>("Model");
ResourceManager::RegisterType<RawModel>("RawModel");
ResourceManager::RegisterType<Texture>("Texture");
ResourceManager::RegisterType<ShaderProgram>("ShaderProgram");
ResourceManager::RegisterType<EntityFile>("EntityFile");
ResourceManager::RegisterType<Font>("FontFile");
m_Config = ResourceManager::Load<ConfigFile>("Config.ini");
ResourceManager::UseThreading = m_Config->Get<bool>("Multithreading.ResourceLoading", true);
DisableMemoryPool::Value = m_Config->Get<bool>("Debug.DisableMemoryPool", false);
LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get<int>("Debug.LogLevel", 1));
// Create the core event broker
@@ -56,22 +65,30 @@ Game::Game(int argc, char* argv[])
EntityFileParser fp(file);
fp.MergeEntities(m_World);
}
//SO MUCH TEMP PLEASE REMOVE ME OMFG VIKTOR HELP
m_Renderer->m_World = m_World;
// Create Octrees
m_OctreeCollision = new Octree(AABB(glm::vec3(-100), glm::vec3(100)), 4);
m_OctreeFrustrumCulling = new Octree(AABB(glm::vec3(-100), glm::vec3(100)), 4);
// Create system pipeline
m_SystemPipeline = new SystemPipeline(m_EventBroker);
//All systems with orderlevel 0 will be updated first.
// All systems with orderlevel 0 will be updated first.
unsigned int updateOrderLevel = 0;
m_SystemPipeline->AddSystem<RaptorCopterSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<PlayerSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<EditorSystem>(updateOrderLevel, m_Renderer);
m_SystemPipeline->AddSystem<HealthSystem>(updateOrderLevel);
//Collision and TriggerSystem should update after player.
m_SystemPipeline->AddSystem<PlayerMovementSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<SpawnerSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<PlayerSpawnSystem>(updateOrderLevel);
// Populate Octree with collidables
++updateOrderLevel;
m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<TriggerSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<CollidableOctreeSystem>(updateOrderLevel, m_OctreeCollision);
// Collision and TriggerSystem should update after player.
++updateOrderLevel;
m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel, m_OctreeCollision);
m_SystemPipeline->AddSystem<TriggerSystem>(updateOrderLevel, m_OctreeCollision);
++updateOrderLevel;
m_SystemPipeline->AddSystem<RenderSystem>(updateOrderLevel, m_Renderer, m_RenderFrame);
@@ -80,12 +97,19 @@ Game::Game(int argc, char* argv[])
//boost::thread workerThread(&Game::networkFunction, this);
networkFunction();
}
// Invoke sound system
m_SoundSystem = new SoundSystem(m_World, m_EventBroker, m_Config->Get<bool>("Debug.EditorEnabled", false));
m_LastTime = glfwGetTime();
}
Game::~Game()
{
delete m_SystemPipeline;
delete m_SoundSystem;
delete m_OctreeFrustrumCulling;
delete m_OctreeCollision;
delete m_World;
delete m_FrameStack;
delete m_InputProxy;
@@ -119,9 +143,10 @@ void Game::Tick()
}
// Iterate through systems and update world!
m_SystemPipeline->Update(m_World, dt);
debugTick(dt);
m_Renderer->Update(dt);
m_EventBroker->Process<Client>();
m_SoundSystem->Update(dt);
GLERROR("Game::Tick m_RenderQueueFactory->Update");
m_Renderer->Draw(*m_RenderFrame);
GLERROR("Game::Tick m_Renderer->Draw");
-42
View File
@@ -1,42 +0,0 @@
#include "PlayerSystem.h"
void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, double dt)
{
player["Velocity"] = glm::vec3(0.f, 0.f, 0.f);
if ((bool&)player["Forward"] == true) {
((glm::vec3&)player["Velocity"]).z = m_Speed * float(dt) * -1;
}
if ((bool&)player["Left"] == true) {
((glm::vec3&)player["Velocity"]).x = m_Speed * float(dt) * -1;
}
if ((bool&)player["Back"] == true) {
((glm::vec3&)player["Velocity"]).z = m_Speed * float(dt);
}
if ((bool&)player["Right"] == true) {
((glm::vec3&)player["Velocity"]).x = m_Speed * float(dt);
}
if ((glm::vec3)player["Velocity"] != glm::vec3(0.f)) {
ComponentWrapper& transform = world->GetComponent(player.EntityID, "Transform");
(glm::vec3&)transform["Position"] += (glm::vec3)player["Velocity"];
}
}
bool PlayerSystem::OnTouch(const Events::TriggerTouch &event)
{
LOG_INFO("Player entity %i touched widget (entity %i).", event.Entity, event.Trigger);
return false;
}
bool PlayerSystem::OnEnter(const Events::TriggerEnter &event)
{
LOG_INFO("Player entity %i entered widget (entity %i).", event.Entity, event.Trigger);
return false;
}
bool PlayerSystem::OnLeave(const Events::TriggerLeave &event)
{
LOG_INFO("Player entity %i left widget (entity %i).", event.Entity, event.Trigger);
return false;
}
@@ -1,32 +1,32 @@
#include "HealthSystem.h"
#include <algorithm>
#include "Systems/HealthSystem.h"
HealthSystem::HealthSystem(EventBroker* eventBroker)
: PureSystem(eventBroker, "Health")
: System(eventBroker)
, PureSystem("Health")
{
//subscribe/listenTo playerdamage,healthpickup events (using the eventBroker)
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &HealthSystem::OnPlayerDamaged);
EVENT_SUBSCRIBE_MEMBER(m_EPlayerHealthPickup, &HealthSystem::OnPlayerHealthPickup);
}
void HealthSystem::UpdateComponent(World *world, ComponentWrapper &health, double dt)
void HealthSystem::UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& component, double dt)
{
//if entityID of health is 9 then the players ID is also 9 (player,health are connected to the same entity)
ComponentWrapper player = world->GetComponent(health.EntityID, "Player");
double maxHealth = (double)health["MaxHealth"];
ComponentWrapper player = world->GetComponent(component.EntityID, "Player");
double maxHealth = (double)component["MaxHealth"];
//process the DeltaHealthVector and change the entitys health accordingly
for (size_t i = m_DeltaHealthVector.size(); i > 0; i--)
{
auto deltaHP = m_DeltaHealthVector[i - 1];
//if we have a healthchange for the current player and health is greater than 0, then apply it
if (std::get<0>(deltaHP) == player.EntityID && (double)health["Health"] > 0.0f) {
if (std::get<0>(deltaHP) == player.EntityID && (double)component["Health"] > 0.0f) {
//get the deltaHP value from the tuple and make sure you dont get more than maxHealth
double newHealth = std::min((double)health["Health"] + (double)std::get<1>(deltaHP), maxHealth);
health["Health"] = newHealth;
double newHealth = std::min((double)component["Health"] + (double)std::get<1>(deltaHP), maxHealth);
component["Health"] = newHealth;
m_DeltaHealthVector.erase(m_DeltaHealthVector.begin() + i - 1);
//check if health is <= 0
if ((double)health["Health"] <= 0.0f) {
if ((double)component["Health"] <= 0.0f) {
//publish death event
Events::PlayerDeath e;
e.PlayerID = player.EntityID;
+16
View File
@@ -0,0 +1,16 @@
#include "Systems/PlayerMovementSystem.h"
void PlayerMovementSystem::UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& component, double dt)
{
ComponentWrapper& cTransform = entity["Transform"];
if (!entity.HasComponent("Physics")) {
return;
}
ComponentWrapper& cPhysics = entity["Physics"];
glm::vec3& velocity = cPhysics["Velocity"];
velocity.y -= 9.82 * dt;
glm::vec3& position = cTransform["Position"];
position += velocity * (float)dt;
}
+51
View File
@@ -0,0 +1,51 @@
#include "Systems/PlayerSpawnSystem.h"
PlayerSpawnSystem::PlayerSpawnSystem(EventBroker* eventBroker)
: System(eventBroker)
{
EVENT_SUBSCRIBE_MEMBER(m_OnInputCommand, &PlayerSpawnSystem::OnInputCommand);
}
void PlayerSpawnSystem::Update(World* world, double dt)
{
auto playerSpawns = world->GetComponents("PlayerSpawn");
if (playerSpawns == nullptr) {
return;
}
for (auto& team : m_SpawnRequests) {
for (auto& cPlayerSpawn : *playerSpawns) {
EntityWrapper spawner(world, cPlayerSpawn.EntityID);
if (!spawner.HasComponent("Spawner")) {
continue;
}
// If the spawner has a team affiliation, check it
if (spawner.HasComponent("Team")) {
if ((int)spawner["Team"]["Team"] != team) {
continue;
}
}
// Spawn the player!
EntityWrapper player = SpawnerSystem::Spawn(spawner);
// Set the player team affiliation
player["Team"]["Team"] = team;
}
}
m_SpawnRequests.clear();
}
bool PlayerSpawnSystem::OnInputCommand(const Events::InputCommand& e)
{
if (e.Command != "PickTeam") {
return false;
}
if (e.Value != 0) {
m_SpawnRequests.push_back((int)e.Value);
}
return true;
}
+61
View File
@@ -0,0 +1,61 @@
#include "Systems/SpawnerSystem.h"
SpawnerSystem::SpawnerSystem(EventBroker* eventBroker) : System(eventBroker)
{
EVENT_SUBSCRIBE_MEMBER(m_OnSpawnerSpawn, &SpawnerSystem::OnSpawnerSpawn);
}
EntityWrapper SpawnerSystem::Spawn(EntityWrapper spawner, EntityWrapper parent /*= EntityWrapper::Invalid*/)
{
// Spawn the entity in the parent's world if it exists, otherwise in the spawner's world
World* world = parent.World;
if (world == nullptr) {
world = spawner.World;
}
// Find any SpawnPoints existing as children of spawner
auto children = spawner.World->GetChildren(spawner.ID);
std::vector<EntityWrapper> spawnPoints;
for (auto kv = children.first; kv != children.second; ++kv) {
const EntityID& child = kv->second;
if (spawner.World->HasComponent(child, "SpawnPoint")) {
spawnPoints.push_back(EntityWrapper(spawner.World, child));
}
}
// Choose a random SpawnPoint
EntityWrapper spawnPoint = spawner;
if (!spawnPoints.empty()) {
if (spawnPoints.size() > 1) {
static std::random_device randomDevice;
static std::mt19937 randomGenerator(randomDevice());
std::uniform_int_distribution<> distribution(0, std::distance(spawnPoints.begin(), spawnPoints.end()) - 1);
auto randomSpawnPointIt = spawnPoints.begin();
std::advance(randomSpawnPointIt, distribution(randomGenerator));
spawnPoint = *randomSpawnPointIt;
} else {
spawnPoint = spawnPoints.front();
}
}
// Load the entity file and parse it
const std::string& entityFilePath = spawner["Spawner"]["EntityFile"];
auto entityFile = ResourceManager::Load<EntityFile>(entityFilePath);
if (entityFile == nullptr) {
return EntityWrapper::Invalid;
}
EntityFileParser parser(entityFile);
EntityWrapper spawnedEntity(world, parser.MergeEntities(world, parent.ID));
// Set its position and orientation to that of the SpawnPoint
spawnedEntity["Transform"]["Position"] = Transform::AbsolutePosition(spawnPoint.World, spawnPoint.ID);
spawnedEntity["Transform"]["Orientation"] = glm::eulerAngles(Transform::AbsoluteOrientation(spawnPoint.World, spawnPoint.ID));
return spawnedEntity;
}
bool SpawnerSystem::OnSpawnerSpawn(Events::SpawnerSpawn& e)
{
EntityWrapper spawnedEntity = Spawn(e.Spawner, e.Parent);
return true;
}