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

# Conflicts:
#	include/Engine/Rendering/RenderSystem.h
#	src/Engine/Rendering/RenderSystem.cpp
This commit is contained in:
viktorljung
2016-01-22 17:02:56 +01:00
95 changed files with 2515 additions and 1282 deletions
+8 -4
View File
@@ -9,6 +9,7 @@
#include "Systems/PlayerSpawnSystem.h"
#include "Core/EntityFileWriter.h"
#include "Game/Systems/CapturePointSystem.h"
#include "Game/Systems/WeaponSystem.h"
Game::Game(int argc, char* argv[])
{
@@ -29,7 +30,6 @@ Game::Game(int argc, char* argv[])
// Create the core event broker
m_EventBroker = new EventBroker();
// Create the renderer
m_Renderer = new Renderer(m_EventBroker);
m_Renderer->SetFullscreen(m_Config->Get<bool>("Video.Fullscreen", false));
@@ -72,17 +72,17 @@ Game::Game(int argc, char* argv[])
m_OctreeCollision = new Octree<AABB>(AABB(glm::vec3(-100), glm::vec3(100)), 4);
m_OctreeFrustrumCulling = new Octree<AABB>(AABB(glm::vec3(-100), glm::vec3(100)), 4);
// Create system pipeline
m_SystemPipeline = new SystemPipeline(m_EventBroker);
m_SystemPipeline = new SystemPipeline(m_World, m_EventBroker);
// All systems with orderlevel 0 will be updated first.
unsigned int updateOrderLevel = 0;
m_SystemPipeline->AddSystem<RaptorCopterSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<EditorSystem>(updateOrderLevel, m_Renderer);
m_SystemPipeline->AddSystem<HealthSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<PlayerMovementSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<InterpolationSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<SpawnerSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<PlayerSpawnSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<WeaponSystem>(updateOrderLevel, m_Renderer);
// Populate Octree with collidables
++updateOrderLevel;
m_SystemPipeline->AddSystem<CollidableOctreeSystem>(updateOrderLevel, m_OctreeCollision);
@@ -93,6 +93,8 @@ Game::Game(int argc, char* argv[])
++updateOrderLevel;
m_SystemPipeline->AddSystem<CapturePointSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<RenderSystem>(updateOrderLevel, m_Renderer, m_RenderFrame);
++updateOrderLevel;
m_SystemPipeline->AddSystem<EditorSystem>(updateOrderLevel, m_Renderer, m_RenderFrame);
// Invoke network
if (m_Config->Get<bool>("Networking.StartNetwork", false)) {
@@ -144,12 +146,14 @@ void Game::Tick()
m_ClientOrServer->Update();
}
// Iterate through systems and update world!
m_SystemPipeline->Update(m_World, dt);
m_EventBroker->Process<SystemPipeline>();
m_SystemPipeline->Update(dt);
debugTick(dt);
m_Renderer->Update(dt);
m_SoundSystem->Update(dt);
GLERROR("Game::Tick m_RenderQueueFactory->Update");
m_Renderer->Draw(*m_RenderFrame);
m_RenderFrame->Clear();
GLERROR("Game::Tick m_Renderer->Draw");
m_EventBroker->Swap();
m_EventBroker->Clear();
+15 -15
View File
@@ -1,9 +1,9 @@
#include "Systems/CapturePointSystem.h"
#include <algorithm>
CapturePointSystem::CapturePointSystem(EventBroker* eventBroker)
: System(eventBroker),
PureSystem("CapturePoint")
CapturePointSystem::CapturePointSystem(World* world, EventBroker* eventBroker)
: System(world, eventBroker)
, PureSystem("CapturePoint")
{
//subscribe/listenTo playerdamage,healthpickup events (using the eventBroker)
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch);
@@ -13,22 +13,22 @@ CapturePointSystem::CapturePointSystem(EventBroker* eventBroker)
//here all capturepoints will update their component
//NOTE: needs to run each frame, since we're possibly modifying the captureTimer for the capturePoints by dt
void CapturePointSystem::UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& capturePoint, double dt)
void CapturePointSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& capturePoint, double dt)
{
if (m_WinnerWasFound) {
return;
}
const int capturePointNumber = capturePoint["CapturePointNumber"];
const bool hasTeamComponent = world->HasComponent(capturePoint.EntityID, "Team");
const bool hasTeamComponent = m_World->HasComponent(capturePoint.EntityID, "Team");
//if point doesnt have a teamComponent yet, add one. since:
//what if capture point has no team -> we cant get/use the team enum from it...
if (!hasTeamComponent) {
world->AttachComponent(capturePoint.EntityID, "Team");
ComponentWrapper& teamComponent = world->GetComponent(capturePoint.EntityID, "Team");
m_World->AttachComponent(capturePoint.EntityID, "Team");
ComponentWrapper& teamComponent = m_World->GetComponent(capturePoint.EntityID, "Team");
teamComponent["Team"] = (int)teamComponent["Team"].Enum("Spectator");
}
ComponentWrapper& teamComponent = world->GetComponent(capturePoint.EntityID, "Team");
ComponentWrapper& teamComponent = m_World->GetComponent(capturePoint.EntityID, "Team");
const int redTeam = (int)teamComponent["Team"].Enum("Red");
const int blueTeam = (int)teamComponent["Team"].Enum("Blue");
const int spectatorTeam = (int)teamComponent["Team"].Enum("Spectator");
@@ -66,7 +66,7 @@ void CapturePointSystem::UpdateComponent(World* world, EntityWrapper& entity, Co
nextPossibleCapturePoint["Blue"] = -1;
for (size_t i = 0; i < m_NumberOfCapturePoints; i++)
{
ComponentWrapper& capturePointOwnedBy = world->GetComponent(m_CapturePointNumberToEntityIDMap[i], "Team");
ComponentWrapper& capturePointOwnedBy = m_World->GetComponent(m_CapturePointNumberToEntityIDMap[i], "Team");
if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint == 0) {
nextPossibleCapturePoint["Red"] = i + 1;
}
@@ -76,7 +76,7 @@ void CapturePointSystem::UpdateComponent(World* world, EntityWrapper& entity, Co
}
for (int i = m_NumberOfCapturePoints - 1; i >= 0; i--)
{
ComponentWrapper& capturePointOwnedBy = world->GetComponent(m_CapturePointNumberToEntityIDMap[i], "Team");
ComponentWrapper& capturePointOwnedBy = m_World->GetComponent(m_CapturePointNumberToEntityIDMap[i], "Team");
if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint != 0) {
nextPossibleCapturePoint["Red"] = i - 1;
}
@@ -89,7 +89,7 @@ void CapturePointSystem::UpdateComponent(World* world, EntityWrapper& entity, Co
if (m_ResetTimers) {
for (size_t i = 0; i < m_NumberOfCapturePoints; i++)
{
ComponentWrapper& capturePoint = world->GetComponent(m_CapturePointNumberToEntityIDMap[i], "CapturePoint");
ComponentWrapper& capturePoint = m_World->GetComponent(m_CapturePointNumberToEntityIDMap[i], "CapturePoint");
if ((int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Red"] &&
(int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Blue"]) {
capturePoint["CaptureTimer"] = 0.0;
@@ -113,21 +113,21 @@ void CapturePointSystem::UpdateComponent(World* world, EntityWrapper& entity, Co
if (std::get<1>(triggerTouched) == capturePoint.EntityID) {
//some player has touched this - lets figure out: what team, health
EntityID playerID = std::get<0>(triggerTouched);
if (!world->HasComponent(playerID, "Player")) {
if (!m_World->HasComponent(playerID, "Player")) {
//if a non-player has entered the capturePoint, just erase that event and continue
m_ETriggerTouchVector.erase(m_ETriggerTouchVector.begin() + i - 1);
continue;
}
bool hasHealthComponent = world->HasComponent(playerID, "Health");
bool hasHealthComponent = m_World->HasComponent(playerID, "Health");
if (hasHealthComponent) {
double currentHealth = world->GetComponent(playerID, "Health")["Health"];
double currentHealth = m_World->GetComponent(playerID, "Health")["Health"];
//check if player is dead
if ((int)currentHealth == 0) {
continue;
}
}
//check team - spectatorNumber = "no team"
int teamNumber = world->GetComponent(playerID, "Team")["Team"];
int teamNumber = m_World->GetComponent(playerID, "Team")["Team"];
if (teamNumber == redTeam) {
redTeamPlayersStandingInside++;
} else if (teamNumber == blueTeam) {
+7 -4
View File
@@ -1,7 +1,7 @@
#include "Systems/HealthSystem.h"
HealthSystem::HealthSystem(EventBroker* eventBroker)
: System(eventBroker)
HealthSystem::HealthSystem(World* m_World, EventBroker* eventBroker)
: System(m_World, eventBroker)
, PureSystem("Health")
{
//subscribe/listenTo playerdamage,healthpickup events (using the eventBroker)
@@ -9,9 +9,10 @@ HealthSystem::HealthSystem(EventBroker* eventBroker)
EVENT_SUBSCRIBE_MEMBER(m_EPlayerHealthPickup, &HealthSystem::OnPlayerHealthPickup);
}
void HealthSystem::UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& component, double dt)
void HealthSystem::UpdateComponent(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 = m_World->GetComponent(component.EntityID, "Player");
double maxHealth = (double)component["MaxHealth"];
//process the DeltaHealthVector and change the entitys health accordingly
@@ -37,7 +38,8 @@ void HealthSystem::UpdateComponent(World* world, EntityWrapper& entity, Componen
if (std::get<0>(m_DeltaHealthVector[j - 1]) == component.EntityID)
m_DeltaHealthVector.erase(m_DeltaHealthVector.begin() + j - 1);
}
//break the loop if the player is dead
//delete the player and break the loop
m_World->DeleteEntity(entity.ID);
break;
}
}
@@ -57,3 +59,4 @@ bool HealthSystem::OnPlayerHealthPickup(const Events::PlayerHealthPickup& e)
m_DeltaHealthVector.push_back(std::make_tuple(e.PlayerHealedID, e.HealthAmount));
return true;
}
+1 -1
View File
@@ -20,7 +20,7 @@
// }
//}
void InterpolationSystem::UpdateComponent(World * world, EntityWrapper& entity, ComponentWrapper & transform, double dt)
void InterpolationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& transform, double dt)
{
if (m_NextTransform.find(transform.EntityID) != m_NextTransform.end()) { // Exists in map
m_NextTransform[transform.EntityID].interpolationTime += dt;
+1 -1
View File
@@ -1,6 +1,6 @@
#include "Systems/PlayerMovementSystem.h"
void PlayerMovementSystem::UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& component, double dt)
void PlayerMovementSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt)
{
ComponentWrapper& cTransform = entity["Transform"];
if (!entity.HasComponent("Physics")) {
+5 -5
View File
@@ -1,21 +1,21 @@
#include "Systems/PlayerSpawnSystem.h"
PlayerSpawnSystem::PlayerSpawnSystem(EventBroker* eventBroker)
: System(eventBroker)
PlayerSpawnSystem::PlayerSpawnSystem(World* m_World, EventBroker* eventBroker)
: System(m_World, eventBroker)
{
EVENT_SUBSCRIBE_MEMBER(m_OnInputCommand, &PlayerSpawnSystem::OnInputCommand);
}
void PlayerSpawnSystem::Update(World* world, double dt)
void PlayerSpawnSystem::Update(double dt)
{
auto playerSpawns = world->GetComponents("PlayerSpawn");
auto playerSpawns = m_World->GetComponents("PlayerSpawn");
if (playerSpawns == nullptr) {
return;
}
for (auto& team : m_SpawnRequests) {
for (auto& cPlayerSpawn : *playerSpawns) {
EntityWrapper spawner(world, cPlayerSpawn.EntityID);
EntityWrapper spawner(m_World, cPlayerSpawn.EntityID);
if (!spawner.HasComponent("Spawner")) {
continue;
}
+2 -1
View File
@@ -1,6 +1,7 @@
#include "Systems/SpawnerSystem.h"
SpawnerSystem::SpawnerSystem(EventBroker* eventBroker) : System(eventBroker)
SpawnerSystem::SpawnerSystem(World* world, EventBroker* eventBroker)
: System(world, eventBroker)
{
EVENT_SUBSCRIBE_MEMBER(m_OnSpawnerSpawn, &SpawnerSystem::OnSpawnerSpawn);
}
+53
View File
@@ -0,0 +1,53 @@
#include "Systems/WeaponSystem.h"
WeaponSystem::WeaponSystem(World* world, EventBroker* eventBroker, IRenderer* renderer)
: System(world, eventBroker)
, ImpureSystem()
, m_Renderer(renderer)
{
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &WeaponSystem::OnInputCommand);
EVENT_SUBSCRIBE_MEMBER(m_EShoot, &WeaponSystem::OnShoot);
}
void WeaponSystem::Update(double dt)
{
for (int i = m_EShootVector.size(); i > 0; i--)
{
//TODO: check if player has enough ammo and if weapon has a cooldown or not
//pick the object
PickData pickDataFromShot = m_Renderer->Pick(std::get<1>(m_EShootVector[i - 1]));
if (pickDataFromShot.Entity == EntityID_Invalid) {
m_EShootVector.erase(m_EShootVector.begin() + i - 1);
continue;
}
//if its a player, do PlayerDamage event
const bool hasPlayerComponent = m_World->HasComponent(pickDataFromShot.Entity, "Player");
if (hasPlayerComponent) {
Events::PlayerDamage ePlayerDamage;
//TODO: damage based on weapontype/class?
//TODO: multiple shots at the same time? (shotgunner)
ePlayerDamage.DamageAmount = 25;
ePlayerDamage.PlayerDamagedID = pickDataFromShot.Entity;
m_EventBroker->Publish(ePlayerDamage);
}
m_EShootVector.erase(m_EShootVector.begin() + i - 1);
}
}
bool WeaponSystem::OnInputCommand(const Events::InputCommand& e)
{
if (e.Command == "PrimaryFire" && e.Value > 0) {
Events::Shoot eShoot;
eShoot.shooter = e.PlayerID;
m_EventBroker->Publish(eShoot);
}
return true;
}
bool WeaponSystem::OnShoot(const Events::Shoot& e) {
//screen center, based on current resolution!
Rectangle screenResolution = m_Renderer->Resolution();
glm::vec2 centerScreen = glm::vec2(screenResolution.Width / 2, screenResolution.Height / 2);
m_EShootVector.push_back(std::make_pair(e.shooter, centerScreen));
return true;
}