initial fixes
This commit is contained in:
@@ -119,7 +119,7 @@ public:
|
|||||||
m_ExtraMemory.push_back((char*)malloc(m_Stride));
|
m_ExtraMemory.push_back((char*)malloc(m_Stride));
|
||||||
//We should preferably not enter here to avoid performance issues. Set more numMaxElements in constructor instead.
|
//We should preferably not enter here to avoid performance issues. Set more numMaxElements in constructor instead.
|
||||||
if (!DisableMemoryPool::Value) {
|
if (!DisableMemoryPool::Value) {
|
||||||
LOG_DEBUG("Allocated slots exceed Pool size, extra memory allocated dynamically. Pool size: %u, dynamic size: %u.", m_NumSlots, m_ExtraMemory.size());
|
//LOG_DEBUG("Allocated slots exceed Pool size, extra memory allocated dynamically. Pool size: %u, dynamic size: %u.", m_NumSlots, m_ExtraMemory.size());
|
||||||
}
|
}
|
||||||
return m_ExtraMemory.back();
|
return m_ExtraMemory.back();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public:
|
|||||||
{
|
{
|
||||||
// Check if we are trying to add more than the package can fit.
|
// Check if we are trying to add more than the package can fit.
|
||||||
if (m_MaxPacketSize < m_Offset + sizeof(T)) {
|
if (m_MaxPacketSize < m_Offset + sizeof(T)) {
|
||||||
LOG_WARNING("Packet AddPrimitive(): You are trying to add more than we have allocated for! New size is %i bytes\n", m_MaxPacketSize*2);
|
//LOG_WARNING("Packet AddPrimitive(): You are trying to add more than we have allocated for! New size is %i bytes\n", m_MaxPacketSize*2);
|
||||||
resizeData();
|
resizeData();
|
||||||
}
|
}
|
||||||
memcpy(m_Data + m_Offset, &val, sizeof(T));
|
memcpy(m_Data + m_Offset, &val, sizeof(T));
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "Engine/Collision/ETrigger.h"
|
#include "Engine/Collision/ETrigger.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
#include "Core/ConfigFile.h"
|
||||||
|
|
||||||
class HealthPickupSystem : public ImpureSystem
|
class HealthPickupSystem : public ImpureSystem
|
||||||
{
|
{
|
||||||
@@ -34,9 +35,11 @@ private:
|
|||||||
std::vector<NewHealthPickup> m_ETriggerTouchVector;
|
std::vector<NewHealthPickup> m_ETriggerTouchVector;
|
||||||
struct EntityAtMaxValuePickupStruct {
|
struct EntityAtMaxValuePickupStruct {
|
||||||
EntityWrapper player;
|
EntityWrapper player;
|
||||||
EntityWrapper pickup;
|
NewHealthPickup pickup;
|
||||||
|
EntityWrapper trigger;
|
||||||
};
|
};
|
||||||
std::vector<EntityAtMaxValuePickupStruct> m_PickupAtMaximum;
|
std::vector<EntityAtMaxValuePickupStruct> m_PickupAtMaximum;
|
||||||
void DoPickup(EntityWrapper &player, EntityWrapper &trigger);
|
void DoPickup(EntityWrapper &player, EntityWrapper &trigger);
|
||||||
|
void DoPickup(EntityWrapper &player, NewHealthPickup &triggerCopy, EntityWrapper &trigger);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -187,7 +187,7 @@ void Client::parsePing()
|
|||||||
m_IsConnected = true;
|
m_IsConnected = true;
|
||||||
// Time since last ping was received
|
// Time since last ping was received
|
||||||
m_DurationOfPingTime = 1000 * (std::clock() - m_StartPingTime) / static_cast<double>(CLOCKS_PER_SEC);
|
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();
|
m_StartPingTime = std::clock();
|
||||||
|
|
||||||
Packet packet(MessageType::Ping, m_SendPacketID);
|
Packet packet(MessageType::Ping, m_SendPacketID);
|
||||||
|
|||||||
@@ -55,9 +55,6 @@ void AmmoPickupSystem::Update(double dt)
|
|||||||
|
|
||||||
bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
||||||
{
|
{
|
||||||
if (e.Entity != LocalPlayer) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
//TODO: add other weapontypes
|
//TODO: add other weapontypes
|
||||||
if (!e.Entity.HasComponent("AssaultWeapon")) {
|
if (!e.Entity.HasComponent("AssaultWeapon")) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -14,16 +14,20 @@ void HealthPickupSystem::Update(double dt)
|
|||||||
auto& somePickup = *it;
|
auto& somePickup = *it;
|
||||||
//set the double timer value (value 3)
|
//set the double timer value (value 3)
|
||||||
somePickup.DecreaseThisRespawnTimer -= dt;
|
somePickup.DecreaseThisRespawnTimer -= dt;
|
||||||
if (somePickup.DecreaseThisRespawnTimer < 0) {
|
if (somePickup.DecreaseThisRespawnTimer < 0.0) {
|
||||||
|
LOG_INFO("loading healthpickup xml");
|
||||||
|
|
||||||
//spawn and delete the vector item
|
//spawn and delete the vector item
|
||||||
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/HealthPickup.xml");
|
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/HealthPickup.xml");
|
||||||
EntityFileParser parser(entityFile);
|
EntityFileParser parser(entityFile);
|
||||||
EntityID healthPickupID = parser.MergeEntities(m_World);
|
EntityID healthPickupID = parser.MergeEntities(m_World);
|
||||||
|
LOG_INFO("finished loading healthpickup xml");
|
||||||
|
|
||||||
//let the world know a pickup has spawned (graphics effects, etc)
|
//let the world know a pickup has spawned (graphics effects, etc)
|
||||||
Events::PickupSpawned ePickupSpawned;
|
Events::PickupSpawned ePickupSpawned;
|
||||||
ePickupSpawned.Pickup = EntityWrapper(m_World, healthPickupID);
|
ePickupSpawned.Pickup = EntityWrapper(m_World, healthPickupID);
|
||||||
m_EventBroker->Publish(ePickupSpawned);
|
m_EventBroker->Publish(ePickupSpawned);
|
||||||
|
LOG_INFO("event published");
|
||||||
|
|
||||||
//set values from the old entity to the new entity
|
//set values from the old entity to the new entity
|
||||||
auto& newHealthPickupEntity = EntityWrapper(m_World, healthPickupID);
|
auto& newHealthPickupEntity = EntityWrapper(m_World, healthPickupID);
|
||||||
@@ -40,14 +44,15 @@ void HealthPickupSystem::Update(double dt)
|
|||||||
}
|
}
|
||||||
//still touching AmmoPickupAtMaxHealthAmmo?
|
//still touching AmmoPickupAtMaxHealthAmmo?
|
||||||
for (auto& it = m_PickupAtMaximum.begin(); it != m_PickupAtMaximum.end(); ++it) {
|
for (auto& it = m_PickupAtMaximum.begin(); it != m_PickupAtMaximum.end(); ++it) {
|
||||||
if (!it->player.Valid() || !it->pickup.Valid()) {
|
if (!it->player.Valid()) {
|
||||||
|
LOG_INFO("player no longer valid, erasing maxPickup");
|
||||||
m_PickupAtMaximum.erase(it);
|
m_PickupAtMaximum.erase(it);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
if ((double)it->player["Health"]["Health"] < (double)it->player["Health"]["MaxHealth"]) {
|
if ((double)it->player["Health"]["Health"] < (double)it->player["Health"]["MaxHealth"]) {
|
||||||
LOG_INFO("maxhealth found in pickupmax.. yada yada");
|
LOG_INFO("maxhealth found in pickupmax.. yada yada");
|
||||||
DoPickup(it->player, it->pickup);
|
DoPickup(it->player, it->pickup, it->trigger);
|
||||||
m_PickupAtMaximum.erase(it);
|
m_PickupAtMaximum.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -60,10 +65,14 @@ bool HealthPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
|||||||
if (!e.Trigger.HasComponent("HealthPickup")) {
|
if (!e.Trigger.HasComponent("HealthPickup")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
LOG_INFO("touch start");
|
||||||
|
|
||||||
//cant pick up healthpacks if you are already at MaxHealth
|
//cant pick up healthpacks if you are already at MaxHealth
|
||||||
if ((double)e.Entity["Health"]["Health"] >= (double)e.Entity["Health"]["MaxHealth"]) {
|
if ((double)e.Entity["Health"]["Health"] >= (double)e.Entity["Health"]["MaxHealth"]) {
|
||||||
LOG_INFO("trigger enter at maxhealth");
|
LOG_INFO("triggertouch enter at maxhealth");
|
||||||
m_PickupAtMaximum.push_back({ e.Entity, e.Trigger });
|
//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;
|
return false;
|
||||||
}
|
}
|
||||||
LOG_INFO("touch doing pickup");
|
LOG_INFO("touch doing pickup");
|
||||||
@@ -75,6 +84,7 @@ bool HealthPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) {
|
|||||||
//triggerleave erases possible m_PickupAtMaximum
|
//triggerleave erases possible m_PickupAtMaximum
|
||||||
for (auto& it = m_PickupAtMaximum.begin(); it != m_PickupAtMaximum.end(); ++it) {
|
for (auto& it = m_PickupAtMaximum.begin(); it != m_PickupAtMaximum.end(); ++it) {
|
||||||
if (it->pickup.ID == e.Trigger.ID && it->player.ID == e.Entity.ID) {
|
if (it->pickup.ID == e.Trigger.ID && it->player.ID == e.Entity.ID) {
|
||||||
|
LOG_INFO("trigger leave - erasing max");
|
||||||
m_PickupAtMaximum.erase(it);
|
m_PickupAtMaximum.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -84,14 +94,17 @@ bool HealthPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) {
|
|||||||
|
|
||||||
void HealthPickupSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) {
|
void HealthPickupSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) {
|
||||||
double healthGiven = 0.01*(double)trigger["HealthPickup"]["HealthGain"] * (double)player["Health"]["MaxHealth"];
|
double healthGiven = 0.01*(double)trigger["HealthPickup"]["HealthGain"] * (double)player["Health"]["MaxHealth"];
|
||||||
|
LOG_INFO("do pickup start");
|
||||||
|
|
||||||
//personEntered = e.Entity, thingEntered = e.Trigger
|
//personEntered = e.Entity, thingEntered = e.Trigger
|
||||||
Events::PlayerHealthPickup ePlayerHealthPickup;
|
//only the server will increase the players hp and set it in the next delta
|
||||||
ePlayerHealthPickup.HealthAmount = healthGiven;
|
if (player.ID != LocalPlayer.ID && ResourceManager::Load<ConfigFile>("Config.ini")->Get("Networking.StartNetwork", false)) {
|
||||||
ePlayerHealthPickup.Player = player;
|
Events::PlayerHealthPickup ePlayerHealthPickup;
|
||||||
m_EventBroker->Publish(ePlayerHealthPickup);
|
ePlayerHealthPickup.HealthAmount = healthGiven;
|
||||||
LOG_INFO("event published");
|
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)
|
//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
|
//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"],
|
m_ETriggerTouchVector.push_back({ (glm::vec3)trigger["Transform"]["Position"] ,trigger["HealthPickup"]["HealthGain"],
|
||||||
@@ -102,3 +115,24 @@ void HealthPickupSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger)
|
|||||||
m_World->DeleteEntity(trigger.ID);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user