Compare commits
6 Commits
bugfix
...
Benchmarking
| Author | SHA1 | Date | |
|---|---|---|---|
| 89555fa0aa | |||
| c98887fa68 | |||
| 14d133bd31 | |||
| 086bdbce70 | |||
| 2cf54819ae | |||
| 683b4cc3cf |
@@ -52,6 +52,7 @@
|
|||||||
#include "Physics/CBoxShape.h"
|
#include "Physics/CBoxShape.h"
|
||||||
#include "Physics/ESetImpulse.h"
|
#include "Physics/ESetImpulse.h"
|
||||||
|
|
||||||
|
#include "Core/EKeyDown.h"
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
{
|
{
|
||||||
@@ -227,6 +228,9 @@ public:
|
|||||||
m_World->CommitEntity(ent);
|
m_World->CommitEntity(ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::OnStopSound);
|
||||||
|
m_EKeyDown = decltype(m_EKeyDown)(std::bind(&Engine::OnKeyDown, this, std::placeholders::_1));
|
||||||
|
m_EventBroker->Subscribe(m_EKeyDown);
|
||||||
m_LastTime = glfwGetTime();
|
m_LastTime = glfwGetTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,12 +242,24 @@ public:
|
|||||||
double dt = currentTime - m_LastTime;
|
double dt = currentTime - m_LastTime;
|
||||||
m_LastTime = currentTime;
|
m_LastTime = currentTime;
|
||||||
|
|
||||||
|
double start = glfwGetTime();
|
||||||
ResourceManager::Update();
|
ResourceManager::Update();
|
||||||
|
double stop = glfwGetTime();
|
||||||
|
double time = stop - start;
|
||||||
|
tm.resourceManagerT += time;
|
||||||
|
|
||||||
// Update input
|
// Update input
|
||||||
|
start = glfwGetTime();
|
||||||
m_InputManager->Update(dt);
|
m_InputManager->Update(dt);
|
||||||
|
stop = glfwGetTime();
|
||||||
|
time = stop - start;
|
||||||
|
tm.inputManagerT += time;
|
||||||
|
|
||||||
|
start = glfwGetTime();
|
||||||
m_World->Update(dt);
|
m_World->Update(dt);
|
||||||
|
stop = glfwGetTime();
|
||||||
|
time = stop - start;
|
||||||
|
tm.worldT += time;
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -263,11 +279,21 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO Fill up the renderQueue with models (Temp fix)
|
//TODO Fill up the renderQueue with models (Temp fix)
|
||||||
|
start = glfwGetTime();
|
||||||
TEMPAddToRenderQueue();
|
TEMPAddToRenderQueue();
|
||||||
|
stop = glfwGetTime();
|
||||||
|
time = stop - start;
|
||||||
|
tm.addToRenderQueueT += time;
|
||||||
|
|
||||||
// Render scene
|
// Render scene
|
||||||
//TODO send renderqueue to draw.
|
//TODO send renderqueue to draw.
|
||||||
|
start = glfwGetTime();
|
||||||
m_Renderer->Draw(m_RendererQueue);
|
m_Renderer->Draw(m_RendererQueue);
|
||||||
|
stop = glfwGetTime();
|
||||||
|
time = stop - start;
|
||||||
|
tm.rendererT += time;
|
||||||
|
|
||||||
|
m_EventBroker->Process<Engine>();
|
||||||
|
|
||||||
// Swap event queues
|
// Swap event queues
|
||||||
m_EventBroker->Clear();
|
m_EventBroker->Clear();
|
||||||
@@ -416,6 +442,52 @@ private:
|
|||||||
std::shared_ptr<InputManager> m_InputManager;
|
std::shared_ptr<InputManager> m_InputManager;
|
||||||
std::shared_ptr<World> m_World;
|
std::shared_ptr<World> m_World;
|
||||||
|
|
||||||
|
struct TickMetric
|
||||||
|
{
|
||||||
|
double resourceManagerT = 0;
|
||||||
|
double inputManagerT = 0;
|
||||||
|
double worldT = 0;
|
||||||
|
double addToRenderQueueT = 0;
|
||||||
|
double rendererT = 0;
|
||||||
|
double Total()
|
||||||
|
{
|
||||||
|
return resourceManagerT
|
||||||
|
+ inputManagerT
|
||||||
|
+ worldT
|
||||||
|
+ addToRenderQueueT
|
||||||
|
+ rendererT;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
TickMetric tm;
|
||||||
|
|
||||||
|
dd::EventRelay<Engine, dd::Events::KeyDown> m_EKeyDown;
|
||||||
|
bool OnKeyDown(const dd::Events::KeyDown &event)
|
||||||
|
{
|
||||||
|
if (event.KeyCode == 78)
|
||||||
|
{
|
||||||
|
double total = tm.Total();
|
||||||
|
|
||||||
|
std::ofstream outFile;
|
||||||
|
outFile.open("../tools/engine-metrics.txt");
|
||||||
|
outFile.clear();
|
||||||
|
outFile << "----------------------- Time measurements -----------------------\n";
|
||||||
|
outFile << "Type: ResourceManager->Update()" << std::endl;
|
||||||
|
outFile << "Total: " << tm.resourceManagerT / total * 100 << " %" << std::endl << std::endl;
|
||||||
|
outFile << "Type: InputManager->Update()" << std::endl;
|
||||||
|
outFile << "Total: " << tm.inputManagerT / total * 100 << " %" << std::endl << std::endl;
|
||||||
|
outFile << "Type: World->Update()" << std::endl;
|
||||||
|
outFile << "Total: " << tm.worldT / total * 100 << " %" << std::endl << std::endl;
|
||||||
|
outFile << "Type: AddToRenderQueue()" << std::endl;
|
||||||
|
outFile << "Total: " << tm.addToRenderQueueT / total * 100 << " %" << std::endl << std::endl;
|
||||||
|
outFile << "Type: Renderer->Draw()" << std::endl;
|
||||||
|
outFile << "Total: " << tm.rendererT / total * 100 << " %" << std::endl << std::endl;
|
||||||
|
outFile << "-----------------------------------------------------------------";
|
||||||
|
outFile.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
double m_LastTime;
|
double m_LastTime;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -37,6 +37,8 @@
|
|||||||
#include "EComponentCreated.h"
|
#include "EComponentCreated.h"
|
||||||
#include "ResourceManager.h"
|
#include "ResourceManager.h"
|
||||||
|
|
||||||
|
#include "EKeyDown.h"
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -52,6 +54,10 @@ public:
|
|||||||
, m_LastEntityID(0) { }
|
, m_LastEntityID(0) { }
|
||||||
~World() { }
|
~World() { }
|
||||||
|
|
||||||
|
dd::EventRelay<World, dd::Events::KeyDown> m_EKeyDown;
|
||||||
|
bool OnKeyDown(const dd::Events::KeyDown &event);
|
||||||
|
|
||||||
|
|
||||||
/** Initialize the world.
|
/** Initialize the world.
|
||||||
|
|
||||||
|
|
||||||
@@ -248,6 +254,15 @@ protected:
|
|||||||
EntityID GenerateEntityID();
|
EntityID GenerateEntityID();
|
||||||
|
|
||||||
void RecycleEntityID(EntityID id);
|
void RecycleEntityID(EntityID id);
|
||||||
|
|
||||||
|
private:
|
||||||
|
//Benchmarking
|
||||||
|
struct TimeMeasure {
|
||||||
|
double EventTime;
|
||||||
|
double SystemTime;
|
||||||
|
double RSystemTime;
|
||||||
|
};
|
||||||
|
std::map<std::string, TimeMeasure> m_typeToTimeMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
|
|||||||
+69
-4
@@ -58,11 +58,36 @@ void dd::World::Update(double dt)
|
|||||||
{
|
{
|
||||||
const std::string &type = pair.first;
|
const std::string &type = pair.first;
|
||||||
auto system = pair.second;
|
auto system = pair.second;
|
||||||
EventBroker->Process(type);
|
|
||||||
system->Update(dt);
|
|
||||||
RecursiveUpdate(system, dt, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
std::map<std::string, TimeMeasure>::iterator it = m_typeToTimeMap.find(type.c_str());
|
||||||
|
if (it == m_typeToTimeMap.end()) {
|
||||||
|
//Does not contain item
|
||||||
|
TimeMeasure t;
|
||||||
|
t.EventTime = 0;
|
||||||
|
t.SystemTime = 0;
|
||||||
|
t.RSystemTime = 0;
|
||||||
|
m_typeToTimeMap[type.c_str()] = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
double start = glfwGetTime();
|
||||||
|
EventBroker->Process(type);
|
||||||
|
double stop = glfwGetTime();
|
||||||
|
double t1 = stop - start;
|
||||||
|
m_typeToTimeMap[type.c_str()].EventTime += t1;
|
||||||
|
|
||||||
|
start = glfwGetTime();
|
||||||
|
system->Update(dt);
|
||||||
|
stop = glfwGetTime();
|
||||||
|
double t2 = stop - start;
|
||||||
|
m_typeToTimeMap[type.c_str()].SystemTime += t2;
|
||||||
|
|
||||||
|
start = glfwGetTime();
|
||||||
|
RecursiveUpdate(system, dt, 0);
|
||||||
|
stop = glfwGetTime();
|
||||||
|
double t3 = stop - start;
|
||||||
|
m_typeToTimeMap[type.c_str()].RSystemTime += t3;
|
||||||
|
}
|
||||||
|
EventBroker->Process<World>();
|
||||||
ProcessEntityRemovals();
|
ProcessEntityRemovals();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,6 +186,8 @@ void dd::World::Initialize()
|
|||||||
system->RegisterResourceTypes(ResourceManager);
|
system->RegisterResourceTypes(ResourceManager);
|
||||||
system->Initialize();
|
system->Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &World::OnKeyDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
int dd::World::CommitEntity(EntityID entity)
|
int dd::World::CommitEntity(EntityID entity)
|
||||||
@@ -232,3 +259,41 @@ void dd::World::SetEntityParent(EntityID entity, EntityID newParent)
|
|||||||
m_EntityParents[entity] = newParent;
|
m_EntityParents[entity] = newParent;
|
||||||
m_EntityChildren[newParent].push_back(entity);
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
es.Score = brick->Score;
|
es.Score = brick->Score;
|
||||||
EventBroker->Publish(es);
|
EventBroker->Publish(es);
|
||||||
|
|
||||||
std::cout << NumberOfBricks() << std::endl;
|
//std::cout << NumberOfBricks() << std::endl;
|
||||||
//std::cout << "Score: " << Score() << std::endl;
|
//std::cout << "Score: " << Score() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user