Refactoring: Changed HealthPickupSystem to use a struct instead. Removed the Id in EPickupSpawned

This commit is contained in:
verysecrethero
2016-02-05 18:05:46 +01:00
parent be628d9406
commit 4103c878ec
5 changed files with 71 additions and 17 deletions
+11 -13
View File
@@ -8,10 +8,12 @@ PickupSpawnSystem::PickupSpawnSystem(World* m_World, EventBroker* eventBroker)
void PickupSpawnSystem::Update(double dt)
{
for (auto &healthPickupPosition : m_ETriggerTouchVector) {
for (auto it = m_ETriggerTouchVector.begin(); it != m_ETriggerTouchVector.end(); ++it)
{
auto& healthPickupPosition = *it;
//set the double timer value (value 3)
std::get<3>(healthPickupPosition) -= dt;
if (std::get<3>(healthPickupPosition) < 0) {
healthPickupPosition.DecreaseThisRespawnTimer -= dt;
if (healthPickupPosition.DecreaseThisRespawnTimer < 0) {
//spawn and delete the vector item
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/HealthPickup.xml");
EntityFileParser parser(entityFile);
@@ -19,18 +21,17 @@ void PickupSpawnSystem::Update(double dt)
//let the world know a pickup has spawned (graphics effects, etc)
Events::PickupSpawned ePickupSpawned;
ePickupSpawned.PickupID = healthPickupID;
ePickupSpawned.Pickup = EntityWrapper(m_World, healthPickupID);
m_EventBroker->Publish(ePickupSpawned);
//set values from the old entity to the new entity
auto& newHealthPickupEntity = EntityWrapper(m_World, healthPickupID);
newHealthPickupEntity["Transform"]["Position"] = std::get<0>(healthPickupPosition);
newHealthPickupEntity["HealthPickup"]["HealthGain"] = std::get<1>(healthPickupPosition);
newHealthPickupEntity["HealthPickup"]["RespawnTimer"] = std::get<2>(healthPickupPosition);
newHealthPickupEntity["Transform"]["Position"] = healthPickupPosition.Pos;
newHealthPickupEntity["HealthPickup"]["HealthGain"] = healthPickupPosition.HealthGain;
newHealthPickupEntity["HealthPickup"]["RespawnTimer"] = healthPickupPosition.RespawnTimer;
//erase the current element (healthPickupPosition)
m_ETriggerTouchVector.erase(std::remove(m_ETriggerTouchVector.begin(), m_ETriggerTouchVector.end(), healthPickupPosition), m_ETriggerTouchVector.end());
m_ETriggerTouchVector.erase(it);
break;
}
}
@@ -50,11 +51,8 @@ bool PickupSpawnSystem::OnTriggerTouch(Events::TriggerTouch& e)
//copy position, healthgain, respawntimer (twice since one of the values will be counted down to 0, the other will be set in the new object)
//we need to copy all values since each value can be different for each healthPickup
m_ETriggerTouchVector.push_back(std::make_tuple(
(glm::vec3)e.Trigger["Transform"]["Position"],
e.Trigger["HealthPickup"]["HealthGain"],
e.Trigger["HealthPickup"]["RespawnTimer"],
e.Trigger["HealthPickup"]["RespawnTimer"]));
m_ETriggerTouchVector.push_back({ (glm::vec3)e.Trigger["Transform"]["Position"] ,e.Trigger["HealthPickup"]["HealthGain"],
e.Trigger["HealthPickup"]["RespawnTimer"],e.Trigger["HealthPickup"]["RespawnTimer"] });
//delete the healthpickup
m_World->DeleteEntity(e.Trigger.ID);