Compare commits

..

2 Commits

Author SHA1 Message Date
viktorljung bdbf864934 spawning 1 shield on server and one on client 2016-03-14 16:46:03 +01:00
viktorljung f269caafed spawning shield on server and client 2016-03-14 16:02:20 +01:00
11 changed files with 18 additions and 15266 deletions
-45
View File
@@ -1,45 +0,0 @@
#ifndef HealthPickupSystem_h__
#define HealthPickupSystem_h__
#include "Core/System.h"
#include "Core/Transform.h"
#include "Core/ResourceManager.h"
#include "Core/EntityFileParser.h"
#include "Core/EPickupSpawned.h"
#include "Core/EPlayerHealthPickup.h"
#include "Engine/Collision/ETrigger.h"
#include "Common.h"
#include <tuple>
#include "Core/ConfigFile.h"
class HealthPickupSystem : public ImpureSystem
{
public:
HealthPickupSystem(SystemParams params);
virtual void Update(double dt) override;
private:
EventRelay<HealthPickupSystem, Events::TriggerTouch> m_ETriggerTouch;
bool OnTriggerTouch(Events::TriggerTouch& e);
EventRelay<HealthPickupSystem, Events::TriggerLeave> m_ETriggerLeave;
bool OnTriggerLeave(Events::TriggerLeave& e);
struct NewHealthPickup {
glm::vec3 Pos;
double HealthGain;
double RespawnTimer;
double DecreaseThisRespawnTimer;
EntityID parentID;
};
std::vector<NewHealthPickup> m_ETriggerTouchVector;
struct EntityAtMaxValuePickupStruct {
EntityWrapper player;
NewHealthPickup pickup;
EntityWrapper trigger;
};
std::vector<EntityAtMaxValuePickupStruct> m_PickupAtMaximum;
void DoPickup(EntityWrapper &player, EntityWrapper &trigger);
void DoPickup(EntityWrapper &player, NewHealthPickup &triggerCopy, EntityWrapper &trigger);
};
#endif
+2 -20
View File
@@ -31,17 +31,8 @@
<Components>
<c:Animation>
<AnimationName>ActivateShieldU</AnimationName>
<Loop>false</Loop>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="Idle">
<Components>
<c:Animation>
<AnimationName>ShieldFrontU</AnimationName>
<Play>true</Play>
<Loop>false</Loop>
</c:Animation>
<c:Transform/>
</Components>
@@ -74,16 +65,7 @@
<Components>
<c:Animation>
<AnimationName>ActivateShieldU</AnimationName>
<Loop>false</Loop>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="Idle">
<Components>
<c:Animation>
<AnimationName>ShieldFrontU</AnimationName>
<Play>true</Play>
<Loop>false</Loop>
</c:Animation>
<c:Transform/>
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -225,7 +225,7 @@ void Client::parsePing()
m_IsConnected = true;
// Time since last ping was received
m_DurationOfPingTime = 1000 * (std::clock() - m_StartPingTime) / static_cast<double>(CLOCKS_PER_SEC);
//LOG_INFO("%i: response time with ctime(ms): %f", m_PacketID, m_DurationOfPingTime);
LOG_INFO("%i: response time with ctime(ms): %f", m_PacketID, m_DurationOfPingTime);
m_StartPingTime = std::clock();
Packet packet(MessageType::Ping, m_SendPacketID);
-138
View File
@@ -1,138 +0,0 @@
#include "Systems/HealthPickupSystem.h"
HealthPickupSystem::HealthPickupSystem(SystemParams params)
: System(params)
{
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &HealthPickupSystem::OnTriggerTouch);
EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &HealthPickupSystem::OnTriggerLeave);
}
void HealthPickupSystem::Update(double dt)
{
for (auto it = m_ETriggerTouchVector.begin(); it != m_ETriggerTouchVector.end(); ++it)
{
auto& somePickup = *it;
//set the double timer value (value 3)
somePickup.DecreaseThisRespawnTimer -= dt;
if (somePickup.DecreaseThisRespawnTimer < 0.0) {
LOG_INFO("loading healthpickup xml");
//spawn and delete the vector item
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/HealthPickup.xml");
EntityFileParser parser(entityFile);
EntityID healthPickupID = parser.MergeEntities(m_World);
LOG_INFO("finished loading healthpickup xml");
//let the world know a pickup has spawned (graphics effects, etc)
Events::PickupSpawned ePickupSpawned;
ePickupSpawned.Pickup = EntityWrapper(m_World, healthPickupID);
m_EventBroker->Publish(ePickupSpawned);
LOG_INFO("event published");
//set values from the old entity to the new entity
auto& newHealthPickupEntity = EntityWrapper(m_World, healthPickupID);
LOG_INFO("healthpickup id %i", healthPickupID);
newHealthPickupEntity["Transform"]["Position"] = somePickup.Pos;
newHealthPickupEntity["HealthPickup"]["HealthGain"] = somePickup.HealthGain;
newHealthPickupEntity["HealthPickup"]["RespawnTimer"] = somePickup.RespawnTimer;
m_World->SetParent(newHealthPickupEntity.ID, somePickup.parentID);
LOG_INFO("healthpickup parented to %i", somePickup.parentID);
//erase the current element (somePickup)
m_ETriggerTouchVector.erase(it);
break;
}
}
//still touching AmmoPickupAtMaxHealthAmmo?
for (auto& it = m_PickupAtMaximum.begin(); it != m_PickupAtMaximum.end(); ++it) {
if (!it->player.Valid()) {
LOG_INFO("player no longer valid, erasing maxPickup");
m_PickupAtMaximum.erase(it);
break;
}
if ((double)it->player["Health"]["Health"] < (double)it->player["Health"]["MaxHealth"]) {
LOG_INFO("maxhealth found in pickupmax.. yada yada");
DoPickup(it->player, it->pickup, it->trigger);
m_PickupAtMaximum.erase(it);
break;
}
}
}
bool HealthPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
{
LOG_INFO("OnTriggerTouch");
if (!e.Trigger.HasComponent("HealthPickup")) {
return false;
}
LOG_INFO("touch start");
//cant pick up healthpacks if you are already at MaxHealth
if ((double)e.Entity["Health"]["Health"] >= (double)e.Entity["Health"]["MaxHealth"]) {
LOG_INFO("triggertouch enter at maxhealth");
//push back a copy of the entitys data, rather than e.trigger. since the server might delete e.trigger before client can use it
m_PickupAtMaximum.push_back({ e.Entity,{ (glm::vec3)e.Trigger["Transform"]["Position"] ,e.Trigger["HealthPickup"]["HealthGain"],
e.Trigger["HealthPickup"]["RespawnTimer"],e.Trigger["HealthPickup"]["RespawnTimer"], m_World->GetParent(e.Trigger.ID) } , e.Trigger });
return false;
}
LOG_INFO("touch doing pickup");
DoPickup(e.Entity, e.Trigger);
return true;
}
bool HealthPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) {
//triggerleave erases possible m_PickupAtMaximum
for (auto& it = m_PickupAtMaximum.begin(); it != m_PickupAtMaximum.end(); ++it) {
if (it->trigger.ID == e.Trigger.ID && it->player.ID == e.Entity.ID) {
LOG_INFO("trigger leave - erasing max");
m_PickupAtMaximum.erase(it);
break;
}
}
return true;
}
void HealthPickupSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) {
double healthGiven = 0.01*(double)trigger["HealthPickup"]["HealthGain"] * (double)player["Health"]["MaxHealth"];
LOG_INFO("do pickup start");
//personEntered = e.Entity, thingEntered = e.Trigger
//only the server will increase the players hp and set it in the next delta
if (player.ID != LocalPlayer.ID && ResourceManager::Load<ConfigFile>("Config.ini")->Get("Networking.StartNetwork", false)) {
Events::PlayerHealthPickup ePlayerHealthPickup;
ePlayerHealthPickup.HealthAmount = healthGiven;
ePlayerHealthPickup.Player = player;
m_EventBroker->Publish(ePlayerHealthPickup);
LOG_INFO("do pickup event published");
}
//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({ (glm::vec3)trigger["Transform"]["Position"] ,trigger["HealthPickup"]["HealthGain"],
trigger["HealthPickup"]["RespawnTimer"],trigger["HealthPickup"]["RespawnTimer"], m_World->GetParent(trigger.ID) });
LOG_INFO("pickup set id to %i", trigger.ID);
//delete the healthpickup
m_World->DeleteEntity(trigger.ID);
}
//to be used with at-max-health-pickup
void HealthPickupSystem::DoPickup(EntityWrapper &player, NewHealthPickup &triggerCopy, EntityWrapper &trigger) {
double healthGiven = 0.01*triggerCopy.HealthGain * (double)player["Health"]["MaxHealth"];
LOG_INFO("do pickup start");
//only the server will increase the players hp and set it in the next delta
if (player.ID != LocalPlayer.ID && ResourceManager::Load<ConfigFile>("Config.ini")->Get("Networking.StartNetwork", false)) {
Events::PlayerHealthPickup ePlayerHealthPickup;
ePlayerHealthPickup.HealthAmount = healthGiven;
ePlayerHealthPickup.Player = player;
m_EventBroker->Publish(ePlayerHealthPickup);
LOG_INFO("do pickup event published");
}
m_ETriggerTouchVector.push_back(triggerCopy);
//LOG_INFO("pickup set id to %i", trigger.ID);
//delete the healthpickup
if (trigger.Valid()) {
m_World->DeleteEntity(trigger.ID);
}
}
@@ -160,9 +160,9 @@ bool DefenderWeaponBehaviour::OnInputCommand(ComponentWrapper cWeapon, WeaponInf
}
}
if (IsServer) {
SpawnerSystem::Spawn(attachment, attachment);
}
SpawnerSystem::Spawn(attachment, attachment);
/*
EntityWrapper backAttachment = attachment.FirstChildByName("Back");
if (backAttachment.Valid()) {
@@ -172,7 +172,11 @@ bool DefenderWeaponBehaviour::OnInputCommand(ComponentWrapper cWeapon, WeaponInf
eDeployShieldAttachement.Restart = true;
eDeployShieldAttachement.Start = true;
m_EventBroker->Publish(eDeployShieldAttachement);
} else {
LOG_ERROR("back shield invalid");
}
EntityWrapper frontAttachment = attachment.FirstChildByName("Front");
if (frontAttachment.Valid()) {
Events::AutoAnimationBlend eDeployShieldAttachement;
@@ -182,7 +186,10 @@ bool DefenderWeaponBehaviour::OnInputCommand(ComponentWrapper cWeapon, WeaponInf
eDeployShieldAttachement.Start = true;
m_EventBroker->Publish(eDeployShieldAttachement);
} else {
LOG_ERROR("front shield invalid");
}
*/
if (IsClient) {
EntityWrapper root = wi.FirstPersonEntity;
@@ -2,7 +2,7 @@
using boost::unit_test_framework::test_suite;
using boost::unit_test_framework::test_case;
#include "HealthPickupTest.h"
#include "PickupSpawnTest.h"
BOOST_AUTO_TEST_SUITE(PickupSpawnTestSuite)
@@ -41,7 +41,7 @@ PickupSpawnTest::PickupSpawnTest(int runTestNumber)
// Create system pipeline
m_SystemPipeline = new SystemPipeline(m_World, m_EventBroker, false, false);
m_SystemPipeline->AddSystem<HealthSystem>(0);
m_SystemPipeline->AddSystem<HealthPickupSystem>(1);
m_SystemPipeline->AddSystem<PickupSpawnSystem>(1);
//must register components (Components.xsd), else you cant create entities. Easiest done by loading a test xsd file
auto file = ResourceManager::Load<EntityXMLFile>("Schema/Entities/HealthPickup.xml");
@@ -31,7 +31,7 @@
#include "Collision/CollisionSystem.h"
#include "Core/EntityXMLFileWriter.h"
#include "Game/Systems/HealthSystem.h"
#include "Game/Systems/HealthPickupSystem.h"
#include "Game/Systems/PickupSpawnSystem.h"
#include "Core/ResourceManager.h"
@@ -56,9 +56,9 @@ private:
EntityID m_PlayerID, m_HealthPickupID;
int m_RunTestNumber;
EventRelay<HealthPickupSystem, Events::PlayerHealthPickup> m_HP;
EventRelay<PickupSpawnSystem, Events::PlayerHealthPickup> m_HP;
bool OnHealthPickup(Events::PlayerHealthPickup& e);
EventRelay<HealthPickupSystem, Events::PickupSpawned> m_PS;
EventRelay<PickupSpawnSystem, Events::PickupSpawned> m_PS;
bool OnPickupSpawned(Events::PickupSpawned& e);
bool m_TestStage1Success = false;