From 14d133bd313500551c378cd43d3ca5b484016e8d Mon Sep 17 00:00:00 2001 From: Stiffly Date: Thu, 24 Sep 2015 17:25:14 +0200 Subject: [PATCH] Metrics for individual systems. Press N --- include/Core/World.h | 6 +++++ src/game/Core/World.cpp | 49 ++++++++++++++++++++++++++++------ src/game/Game/LevelSystem.cpp | 2 +- src/game/Sound/SoundSystem.cpp | 2 +- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/include/Core/World.h b/include/Core/World.h index 3b5d216..b5bd9bc 100644 --- a/include/Core/World.h +++ b/include/Core/World.h @@ -37,6 +37,8 @@ #include "EComponentCreated.h" #include "ResourceManager.h" +#include "EKeyDown.h" + namespace dd { @@ -52,6 +54,10 @@ public: , m_LastEntityID(0) { } ~World() { } + dd::EventRelay m_EKeyDown; + bool OnKeyDown(const dd::Events::KeyDown &event); + + /** Initialize the world. diff --git a/src/game/Core/World.cpp b/src/game/Core/World.cpp index 2439cab..958056c 100644 --- a/src/game/Core/World.cpp +++ b/src/game/Core/World.cpp @@ -87,14 +87,7 @@ void dd::World::Update(double dt) double t3 = stop - start; m_typeToTimeMap[type.c_str()].RSystemTime += t3; } - - for (auto item : m_typeToTimeMap) - { - LOG_INFO("Type %s", item.first.c_str()); - LOG_INFO("Events: %f", item.second.EventTime); - LOG_INFO("Systems: %f", item.second.SystemTime); - LOG_INFO("Recursive Systems: %f", item.second.RSystemTime); - } + EventBroker->Process(); ProcessEntityRemovals(); } @@ -193,6 +186,8 @@ void dd::World::Initialize() system->RegisterResourceTypes(ResourceManager); system->Initialize(); } + + EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &World::OnKeyDown); } int dd::World::CommitEntity(EntityID entity) @@ -264,3 +259,41 @@ void dd::World::SetEntityParent(EntityID entity, EntityID newParent) m_EntityParents[entity] = newParent; m_EntityChildren[newParent].push_back(entity); } + +bool dd::World::OnKeyDown(const dd::Events::KeyDown &event) +{ + if (event.KeyCode == 78) + { + double eventTot = 0; + double updateTot = 0; + double rUpdateTot = 0; + double total = 0; + + for (auto item : m_typeToTimeMap) + { + eventTot += item.second.EventTime; + updateTot += item.second.SystemTime; + rUpdateTot += item.second.RSystemTime; + } + total = eventTot + updateTot + rUpdateTot; + + std::ofstream outFile; + outFile.open("../tools/system-metrics.txt"); + outFile.clear(); + outFile << "----------------------- Time measurements -----------------------\n"; + for (auto item : m_typeToTimeMap) + { + outFile << "Type: " << item.first.c_str() << std::endl; + outFile << "Events: " << item.second.EventTime << " s. " << item.second.EventTime / eventTot * 100 << " % of total event time.\n"; + outFile << "Update: " << item.second.SystemTime << " s. " << item.second.SystemTime / updateTot * 100 << " % of total update time.\n"; + outFile << "Recursive Update: " << item.second.RSystemTime << " s. " << item.second.RSystemTime / rUpdateTot * 100 << " % of total recursive update time.\n"; + double totalComplexity = (item.second.EventTime + item.second.SystemTime + item.second.RSystemTime) / total * 100; + outFile << "Total: " << totalComplexity << "% total system time." << std::endl << std::endl; + } + outFile << "-----------------------------------------------------------------"; + outFile.close(); + return true; + + } + //return false; +} diff --git a/src/game/Game/LevelSystem.cpp b/src/game/Game/LevelSystem.cpp index 366b6e7..90a655c 100755 --- a/src/game/Game/LevelSystem.cpp +++ b/src/game/Game/LevelSystem.cpp @@ -162,7 +162,7 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event) es.Score = brick->Score; EventBroker->Publish(es); - std::cout << "Score: " << Score() << std::endl; + //std::cout << "Score: " << Score() << std::endl; return true; } diff --git a/src/game/Sound/SoundSystem.cpp b/src/game/Sound/SoundSystem.cpp index 724f4cd..aaca752 100644 --- a/src/game/Sound/SoundSystem.cpp +++ b/src/game/Sound/SoundSystem.cpp @@ -100,7 +100,7 @@ bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event) //Play - //alSourcePlay(source); + alSourcePlay(source); return true; }