A "Respawn" componet which automatically triggers a Spawner component when the last respawned entity of that spawner is destroyed

This commit is contained in:
2016-03-09 23:48:41 +01:00
parent 123fbf5633
commit 4b6d4e581f
8 changed files with 81 additions and 1 deletions
+22
View File
@@ -0,0 +1,22 @@
#ifndef RespawnSystem_h__
#define RespawnSystem_h__
#include "System.h"
#include "SpawnerSystem.h"
#include "EEntityDeleted.h"
class RespawnSystem : public PureSystem
{
public:
RespawnSystem(SystemParams params);
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cRespawn, double dt) override;
private:
std::unordered_map<EntityWrapper, EntityWrapper> m_LastRespawnedEntity;
EventRelay<RespawnSystem, Events::EntityDeleted> m_EEntityDeleted;
bool OnEntityDeleted(const Events::EntityDeleted& e);
};
#endif
+1 -1
View File
@@ -68,7 +68,7 @@ protected:
const std::string m_ComponentType;
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& scoreScreen, double dt) = 0;
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cComponent, double dt) = 0;
};
class ImpureSystem : public virtual System
+1
View File
@@ -68,4 +68,5 @@
<xs:include schemaLocation="Components/NetworkComponent.xsd"/>
<xs:include schemaLocation="Components/ServerIdentity.xsd"/>
<xs:include schemaLocation="Components/ServerList.xsd"/>
<xs:include schemaLocation="Components/Respawn.xsd"/>
</xs:schema>
+5
View File
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Respawn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Respawn.xsd">
<Delay>0</Delay>
<_RespawnCountdown>0</_RespawnCountdown>
</Respawn>
+17
View File
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="Respawn">
<xs:annotation>
<xs:documentation>Triggers a Spawner component after its last spawned entity is destroyed with an optional delay.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:all>
<xs:element name="Delay" type="t:double" minOccurs="0"/>
<xs:element name="_RespawnCountdown" type="t:double" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
+1
View File
@@ -71,6 +71,7 @@
<xs:element ref="c:NetworkComponent" minOccurs="0"/>
<xs:element ref="c:ServerIdentity" minOccurs="0"/>
<xs:element ref="c:ServerList" minOccurs="0"/>
<xs:element ref="c:Respawn" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
+32
View File
@@ -0,0 +1,32 @@
#include "Core/RespawnSystem.h"
RespawnSystem::RespawnSystem(SystemParams params)
: System(params)
, PureSystem("Respawn")
{
EVENT_SUBSCRIBE_MEMBER(m_EEntityDeleted, &RespawnSystem::OnEntityDeleted);
}
void RespawnSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cRespawn, double dt)
{
if (!entity.HasComponent("Spawner")) {
return;
}
EntityWrapper& lastRespawnedEntity = m_LastRespawnedEntity[entity];
if (!lastRespawnedEntity.Valid()) {
double& _respawnCountdown = cRespawn["_RespawnCountdown"];
_respawnCountdown -= dt;
if (_respawnCountdown <= 0) {
lastRespawnedEntity = SpawnerSystem::Spawn(entity, entity);
_respawnCountdown = cRespawn["Delay"];
}
}
}
bool RespawnSystem::OnEntityDeleted(const Events::EntityDeleted& e)
{
m_LastRespawnedEntity.erase(e.DeletedEntity);
return true;
}
+2
View File
@@ -40,6 +40,7 @@
#include "Game/Systems/MainMenuSystem.h"
#include "Game/Systems/ServerListSystem.h"
#include "Game/Systems/StartSystem.h"
#include "Core/RespawnSystem.h"
#include "Rendering/TextureSprite.h"
@@ -135,6 +136,7 @@ Game::Game(int argc, char* argv[])
m_SystemPipeline->AddSystem<HealthSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<PlayerMovementSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<SpawnerSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<RespawnSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<PlayerSpawnSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<AssaultWeaponBehaviour>(updateOrderLevel, m_Renderer, m_OctreeCollision);
m_SystemPipeline->AddSystem<DefenderWeaponBehaviour>(updateOrderLevel, m_Renderer, m_OctreeCollision);