From 041c40912806b739485dc316effc30f35a19ea7c Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Mon, 22 Feb 2016 17:46:49 +0100 Subject: [PATCH] Misc TestBranch testing --- include/Engine/Core/MemoryPool.h | 2 +- include/Engine/Network/Packet.h | 4 ++-- src/Engine/Network/Client.cpp | 2 +- src/Game/Systems/DamageIndicatorSystem.cpp | 5 +++++ src/Game/Systems/HealthSystem.cpp | 7 ++++++- src/Game/Systems/KillFeedSystem.cpp | 5 +++++ src/Game/Systems/PlayerDeathSystem.cpp | 24 ++++++++++++++++++++-- src/Game/Systems/PlayerSpawnSystem.cpp | 9 ++++++++ src/Game/Systems/SoundSystem.cpp | 3 +++ src/Tests/HealthSystemTest.h | 1 - 10 files changed, 54 insertions(+), 8 deletions(-) diff --git a/include/Engine/Core/MemoryPool.h b/include/Engine/Core/MemoryPool.h index 053e75aa..fe836e52 100644 --- a/include/Engine/Core/MemoryPool.h +++ b/include/Engine/Core/MemoryPool.h @@ -119,7 +119,7 @@ public: m_ExtraMemory.push_back((char*)malloc(m_Stride)); //We should preferably not enter here to avoid performance issues. Set more numMaxElements in constructor instead. 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(); } diff --git a/include/Engine/Network/Packet.h b/include/Engine/Network/Packet.h index b688b8c6..1f3ce6a0 100644 --- a/include/Engine/Network/Packet.h +++ b/include/Engine/Network/Packet.h @@ -24,7 +24,7 @@ public: { // Check if we are trying to add more than the package can fit. 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(); } memcpy(m_Data + m_Offset, &val, sizeof(T)); @@ -35,7 +35,7 @@ public: T ReadPrimitive() { if (m_Offset < m_ReturnDataOffset + sizeof(T)) { - LOG_WARNING("Packet PopFrontPrimitive(): You are trying to remove more than what exists in this packet!"); + //LOG_WARNING("Packet PopFrontPrimitive(): You are trying to remove more than what exists in this packet!"); return -1; } T returnValue; diff --git a/src/Engine/Network/Client.cpp b/src/Engine/Network/Client.cpp index a2f52adb..6342ddf7 100644 --- a/src/Engine/Network/Client.cpp +++ b/src/Engine/Network/Client.cpp @@ -165,7 +165,7 @@ void Client::parsePing() m_IsConnected = true; // Time since last ping was received m_DurationOfPingTime = 1000 * (std::clock() - m_StartPingTime) / static_cast(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); diff --git a/src/Game/Systems/DamageIndicatorSystem.cpp b/src/Game/Systems/DamageIndicatorSystem.cpp index 235eced0..38202f5e 100644 --- a/src/Game/Systems/DamageIndicatorSystem.cpp +++ b/src/Game/Systems/DamageIndicatorSystem.cpp @@ -14,6 +14,8 @@ DamageIndicatorSystem::DamageIndicatorSystem(SystemParams params) bool DamageIndicatorSystem::OnPlayerDamage(Events::PlayerDamage& e) { + LOG_INFO("<- damageindicator"); + if (m_CurrentCamera == EntityID_Invalid) { return false; } @@ -28,6 +30,7 @@ bool DamageIndicatorSystem::OnPlayerDamage(Events::PlayerDamage& e) if (!e.Inflictor.Valid() || !e.Victim.Valid()) { return false; } + LOG_INFO("- damageindicator"); //grab players direction auto playerOrientation = glm::quat((glm::vec3)e.Victim["Transform"]["Orientation"]); @@ -67,6 +70,8 @@ bool DamageIndicatorSystem::OnPlayerDamage(Events::PlayerDamage& e) //simply set the rotation z-wise to the angleBetweenVectors spriteWrapper["Transform"]["Orientation"] = glm::vec3(0, 0, angleBetweenVectors); + LOG_INFO("-> damageindicator"); + return true; } diff --git a/src/Game/Systems/HealthSystem.cpp b/src/Game/Systems/HealthSystem.cpp index 94f23c67..47e158a7 100644 --- a/src/Game/Systems/HealthSystem.cpp +++ b/src/Game/Systems/HealthSystem.cpp @@ -13,8 +13,11 @@ HealthSystem::HealthSystem(SystemParams params) void HealthSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cHealth, double dt) { + //LOG_INFO("<- health updatecomponent"); double& health = cHealth["Health"]; - if (health <= 0.0) { + int healthInt = (int)health; + if (healthInt <= 0 && !entity.HasComponent("Lifetime")) { + LOG_INFO("-> health <= 0"); Events::PlayerDeath ePlayerDeath; ePlayerDeath.Player = entity; m_EventBroker->Publish(ePlayerDeath); @@ -24,6 +27,7 @@ void HealthSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cHea bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e) { + LOG_INFO("<- on player damage"); if (!IsServer && m_NetworkEnabled || !e.Victim.Valid()) { return false; } @@ -31,6 +35,7 @@ bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e) ComponentWrapper cHealth = e.Victim["Health"]; double& health = cHealth["Health"]; health -= e.Damage; + LOG_INFO("-> health onplayerdam"); return true; } diff --git a/src/Game/Systems/KillFeedSystem.cpp b/src/Game/Systems/KillFeedSystem.cpp index 8a16d708..c13b17a1 100644 --- a/src/Game/Systems/KillFeedSystem.cpp +++ b/src/Game/Systems/KillFeedSystem.cpp @@ -54,9 +54,13 @@ void KillFeedSystem::Update(double dt) bool KillFeedSystem::OnPlayerDeath(Events::PlayerDeath& e) { + LOG_INFO("<- killfeed death"); + KillFeedInfo kfInfo; if (e.Player.HasComponent("Team")) { + LOG_INFO("- killfeed death"); + int red = e.Player["Team"].Enum("Team", "Red"); int blue = e.Player["Team"].Enum("Team", "Blue"); @@ -70,6 +74,7 @@ bool KillFeedSystem::OnPlayerDeath(Events::PlayerDeath& e) m_DeathQueue.push_back(kfInfo); } } + LOG_INFO("-> killfeed death"); if(m_DeathQueue.size() > 3) { diff --git a/src/Game/Systems/PlayerDeathSystem.cpp b/src/Game/Systems/PlayerDeathSystem.cpp index 40a98278..dcdc7ffd 100644 --- a/src/Game/Systems/PlayerDeathSystem.cpp +++ b/src/Game/Systems/PlayerDeathSystem.cpp @@ -8,18 +8,31 @@ PlayerDeathSystem::PlayerDeathSystem(SystemParams params) void PlayerDeathSystem::Update(double dt) { + } bool PlayerDeathSystem::OnPlayerDeath(Events::PlayerDeath& e) { + LOG_INFO("<- deathsystem: valid player"); + if (!e.Player.Valid()) { return false; } + LOG_INFO("-> deathsystem: valid player"); + + LOG_INFO("<- create effect"); createDeathEffect(e.Player); - // Delete player - m_World->DeleteEntity(e.Player.ID); + LOG_INFO("-> create effect"); + + // Delete player - only the clients will delete themselves. + if (IsServer && !e.Player.HasComponent("Lifetime")) { + // m_World->DeleteEntity(e.Player.ID); + //m_PlayersToBeDeletedVector.emplace_back(e.Player.ID, 0.25); + e.Player.AttachComponent("Lifetime"); + e.Player["Lifetime"]["Lifetime"] = 0.45; + } return true; } @@ -32,6 +45,8 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player) EntityID deathEffectID = parser.MergeEntities(m_World); EntityWrapper deathEffectEW = EntityWrapper(m_World, deathEffectID); + LOG_INFO("<- effect camera"); + //components that we need from player auto playerCamera = player.FirstChildByName("Camera"); auto playerModel = player.FirstChildByName("PlayerModel"); @@ -43,6 +58,7 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player) } auto playerEntityModel = playerModel["Model"]; auto playerEntityAnimation = playerModel["Animation"]; + LOG_INFO("-> effect camera"); //copy the data from player to explisioneffectmodel playerEntityModel.Copy(deathEffectEW["Model"]); @@ -58,11 +74,15 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player) //effect,camera is relative to playersPosition //deathEffectEW["ExplosionEffect"]["ExplosionOrigin"] = glm::vec3(0, 0, 0); + LOG_INFO("<- localplayer"); //camera (with lifetime) behind the player if (player == LocalPlayer) { auto cam = deathEffectEW.FirstChildByName("Camera"); Events::SetCamera eSetCamera; eSetCamera.CameraEntity = cam; m_EventBroker->Publish(eSetCamera); + LOG_INFO("in localplayer"); } + LOG_INFO("-> localplayer"); + } diff --git a/src/Game/Systems/PlayerSpawnSystem.cpp b/src/Game/Systems/PlayerSpawnSystem.cpp index 6254c674..f1fd0c0f 100644 --- a/src/Game/Systems/PlayerSpawnSystem.cpp +++ b/src/Game/Systems/PlayerSpawnSystem.cpp @@ -164,6 +164,8 @@ bool PlayerSpawnSystem::OnPlayerSpawned(Events::PlayerSpawned& e) bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e) { + LOG_INFO("<- spawnsystem death"); + //Only spawn request if network is disabled or we are server. if (!IsServer && m_NetworkEnabled) { return false; @@ -171,12 +173,18 @@ bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e) if (!e.Player.HasComponent("Team")) { return false; } + if (!e.Player.HasComponent("Lifetime")) { + LOG_INFO("<- spawnsystem death FALSE"); + return false; + } ComponentWrapper cTeam = e.Player["Team"]; //A spectator can't die anyway if ((ComponentInfo::EnumType)cTeam["Team"] == cTeam["Team"].Enum("Spectator")) { return false; } + LOG_INFO("- spawnsystem death"); + if (m_PlayerIDs.count(e.Player.ID) == 0) { return false; } @@ -185,6 +193,7 @@ bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e) req.PlayerID = m_PlayerIDs.at(e.Player.ID); req.Team = cTeam["Team"]; m_SpawnRequests.push_back(req); + LOG_INFO("-> spawnsystem death"); return true; } diff --git a/src/Game/Systems/SoundSystem.cpp b/src/Game/Systems/SoundSystem.cpp index 7101311d..4148c62a 100644 --- a/src/Game/Systems/SoundSystem.cpp +++ b/src/Game/Systems/SoundSystem.cpp @@ -128,10 +128,13 @@ bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e) bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e) { + LOG_INFO("<- sound death"); + Events::PlaySoundOnEntity ev; ev.EmitterID = LocalPlayer.ID; ev.FilePath = "Audio/die/die2.wav"; m_EventBroker->Publish(ev); + LOG_INFO("-> sound death"); return false; } diff --git a/src/Tests/HealthSystemTest.h b/src/Tests/HealthSystemTest.h index 685a06dd..275558d2 100644 --- a/src/Tests/HealthSystemTest.h +++ b/src/Tests/HealthSystemTest.h @@ -6,7 +6,6 @@ #include "Core/EventBroker.h" #include "Rendering/Renderer.h" #include "Core/InputManager.h" -#include "GUI/Frame.h" #include "Core/World.h" #include "Input/InputProxy.h" #include "Input/KeyboardInputHandler.h"