summaryrefslogtreecommitdiffstats
path: root/src/app/app.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/app.cpp')
-rw-r--r--src/app/app.cpp113
1 files changed, 102 insertions, 11 deletions
diff --git a/src/app/app.cpp b/src/app/app.cpp
index c936ac1..2155cf4 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -26,6 +26,7 @@
#include "common/image.h"
#include "common/key.h"
+#include "graphics/engine/modelmanager.h"
#include "graphics/opengl/gldevice.h"
#include "object/robotmain.h"
@@ -98,6 +99,7 @@ CApplication::CApplication()
m_engine = nullptr;
m_device = nullptr;
+ m_modelManager = nullptr;
m_robotMain = nullptr;
m_sound = nullptr;
@@ -126,6 +128,12 @@ CApplication::CApplication()
m_curTimeStamp = CreateTimeStamp();
m_lastTimeStamp = CreateTimeStamp();
+ for (int i = 0; i < PCNT_MAX; ++i)
+ {
+ m_performanceCounters[i][0] = CreateTimeStamp();
+ m_performanceCounters[i][1] = CreateTimeStamp();
+ }
+
m_joystickEnabled = false;
m_mouseMode = MOUSE_SYSTEM;
@@ -171,6 +179,12 @@ CApplication::~CApplication()
DestroyTimeStamp(m_baseTimeStamp);
DestroyTimeStamp(m_curTimeStamp);
DestroyTimeStamp(m_lastTimeStamp);
+
+ for (int i = 0; i < PCNT_MAX; ++i)
+ {
+ DestroyTimeStamp(m_performanceCounters[i][0]);
+ DestroyTimeStamp(m_performanceCounters[i][1]);
+ }
}
ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
@@ -250,6 +264,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
GetLogger()->Message("\n");
GetLogger()->Message("List of available options:\n");
GetLogger()->Message(" -help this help\n");
+ GetLogger()->Message(" -vbo enable OpenGL VBOs\n");
GetLogger()->Message(" -datadir path set custom data directory path\n");
GetLogger()->Message(" -debug enable debug mode (more info printed in logs)\n");
GetLogger()->Message(" -loglevel level set log level to level (one of: trace, debug, info, warn, error, none)\n");
@@ -400,6 +415,9 @@ bool CApplication::Create()
return false;
}
+ // Create model manager
+ m_modelManager = new Gfx::CModelManager(m_engine);
+
// Create the robot application.
m_robotMain = new CRobotMain(m_iMan, this);
@@ -479,6 +497,12 @@ void CApplication::Destroy()
m_sound = nullptr;
}
+ if (m_modelManager != nullptr)
+ {
+ delete m_modelManager;
+ m_modelManager = nullptr;
+ }
+
if (m_engine != nullptr)
{
m_engine->Destroy();
@@ -693,6 +717,14 @@ int CApplication::Run()
while (true)
{
+ ResetPerformanceCounters();
+
+ if (m_active)
+ {
+ StartPerformanceCounter(PCNT_ALL);
+ StartPerformanceCounter(PCNT_EVENT_PROCESSING);
+ }
+
// To be sure no old event remains
m_private->currentEvent.type = SDL_NOEVENT;
@@ -804,15 +836,38 @@ int CApplication::Run()
m_robotMain->EventProcess(event);
}
+ StopPerformanceCounter(PCNT_EVENT_PROCESSING);
+
+ StartPerformanceCounter(PCNT_UPDATE_ALL);
+
+ // Prepare and process step simulation event
+ event = CreateUpdateEvent();
+ if (event.type != EVENT_NULL && m_robotMain != nullptr)
+ {
+ StartPerformanceCounter(PCNT_UPDATE_ENGINE);
+ m_engine->FrameUpdate();
+ StopPerformanceCounter(PCNT_UPDATE_ENGINE);
+
+ m_sound->FrameMove(m_relTime);
+
+ StartPerformanceCounter(PCNT_UPDATE_GAME);
+ m_robotMain->EventProcess(event);
+ StopPerformanceCounter(PCNT_UPDATE_GAME);
+ }
+
+ StopPerformanceCounter(PCNT_UPDATE_ALL);
+
/* Update mouse position explicitly right before rendering
* because mouse events are usually way behind */
UpdateMouse();
- // Update game and render a frame during idle time (no messages are waiting)
+ StartPerformanceCounter(PCNT_RENDER_ALL);
Render();
+ StopPerformanceCounter(PCNT_RENDER_ALL);
- // Update simulation state
- StepSimulation();
+ StopPerformanceCounter(PCNT_ALL);
+
+ UpdatePerformanceCountersData();
if (m_lowCPU)
{
@@ -1142,10 +1197,10 @@ void CApplication::SetSimulationSpeed(float speed)
GetLogger()->Info("Simulation speed = %.2f\n", speed);
}
-void CApplication::StepSimulation()
+Event CApplication::CreateUpdateEvent()
{
if (m_simulationSuspended)
- return;
+ return Event(EVENT_NULL);
CopyTimeStamp(m_lastTimeStamp, m_curTimeStamp);
GetCurrentTimeStamp(m_curTimeStamp);
@@ -1160,11 +1215,6 @@ void CApplication::StepSimulation()
m_exactRelTime = m_simulationSpeed * m_realRelTime;
m_relTime = (m_simulationSpeed * m_realRelTime) / 1e9f;
-
- m_engine->FrameUpdate();
- m_sound->FrameMove(m_relTime);
-
-
Event frameEvent(EVENT_FRAME);
frameEvent.systemEvent = true;
frameEvent.trackedKeysState = m_trackedKeys;
@@ -1172,7 +1222,8 @@ void CApplication::StepSimulation()
frameEvent.mousePos = m_mousePos;
frameEvent.mouseButtonsState = m_mouseButtonsState;
frameEvent.rTime = m_relTime;
- m_eventQueue->AddEvent(frameEvent);
+
+ return frameEvent;
}
float CApplication::GetSimulationSpeed()
@@ -1516,3 +1567,43 @@ bool CApplication::GetLowCPU()
{
return m_lowCPU;
}
+
+void CApplication::StartPerformanceCounter(PerformanceCounter counter)
+{
+ GetCurrentTimeStamp(m_performanceCounters[counter][0]);
+}
+
+void CApplication::StopPerformanceCounter(PerformanceCounter counter)
+{
+ GetCurrentTimeStamp(m_performanceCounters[counter][1]);
+}
+
+float CApplication::GetPerformanceCounterData(PerformanceCounter counter)
+{
+ return m_performanceCountersData[counter];
+}
+
+void CApplication::ResetPerformanceCounters()
+{
+ for (int i = 0; i < PCNT_MAX; ++i)
+ {
+ StartPerformanceCounter(static_cast<PerformanceCounter>(i));
+ StopPerformanceCounter(static_cast<PerformanceCounter>(i));
+ }
+}
+
+void CApplication::UpdatePerformanceCountersData()
+{
+ long long sum = TimeStampExactDiff(m_performanceCounters[PCNT_ALL][0],
+ m_performanceCounters[PCNT_ALL][1]);
+
+ for (int i = 0; i < PCNT_MAX; ++i)
+ {
+ long long diff = TimeStampExactDiff(m_performanceCounters[i][0],
+ m_performanceCounters[i][1]);
+
+ m_performanceCountersData[static_cast<PerformanceCounter>(i)] =
+ static_cast<float>(diff) / static_cast<float>(sum);
+ }
+}
+