Main loop enhancement
Frame updates were posted one frame behind in event queuedev-ui
parent
688315ab76
commit
3845efbbff
|
@ -829,16 +829,22 @@ int CApplication::Run()
|
||||||
m_robotMain->EventProcess(event);
|
m_robotMain->EventProcess(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prepare and process step simulation event
|
||||||
|
event = CreateUpdateEvent();
|
||||||
|
if (event.type != EVENT_NULL && m_robotMain != nullptr)
|
||||||
|
{
|
||||||
|
m_engine->FrameUpdate();
|
||||||
|
m_sound->FrameMove(m_relTime);
|
||||||
|
|
||||||
|
m_robotMain->EventProcess(event);
|
||||||
|
}
|
||||||
|
|
||||||
/* Update mouse position explicitly right before rendering
|
/* Update mouse position explicitly right before rendering
|
||||||
* because mouse events are usually way behind */
|
* because mouse events are usually way behind */
|
||||||
UpdateMouse();
|
UpdateMouse();
|
||||||
|
|
||||||
// Update game and render a frame during idle time (no messages are waiting)
|
|
||||||
Render();
|
Render();
|
||||||
|
|
||||||
// Update simulation state
|
|
||||||
StepSimulation();
|
|
||||||
|
|
||||||
if (m_lowCPU)
|
if (m_lowCPU)
|
||||||
{
|
{
|
||||||
usleep(20000); // should still give plenty of fps
|
usleep(20000); // should still give plenty of fps
|
||||||
|
@ -1167,10 +1173,10 @@ void CApplication::SetSimulationSpeed(float speed)
|
||||||
GetLogger()->Info("Simulation speed = %.2f\n", speed);
|
GetLogger()->Info("Simulation speed = %.2f\n", speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CApplication::StepSimulation()
|
Event CApplication::CreateUpdateEvent()
|
||||||
{
|
{
|
||||||
if (m_simulationSuspended)
|
if (m_simulationSuspended)
|
||||||
return;
|
return Event(EVENT_NULL);
|
||||||
|
|
||||||
CopyTimeStamp(m_lastTimeStamp, m_curTimeStamp);
|
CopyTimeStamp(m_lastTimeStamp, m_curTimeStamp);
|
||||||
GetCurrentTimeStamp(m_curTimeStamp);
|
GetCurrentTimeStamp(m_curTimeStamp);
|
||||||
|
@ -1185,11 +1191,6 @@ void CApplication::StepSimulation()
|
||||||
m_exactRelTime = m_simulationSpeed * m_realRelTime;
|
m_exactRelTime = m_simulationSpeed * m_realRelTime;
|
||||||
m_relTime = (m_simulationSpeed * m_realRelTime) / 1e9f;
|
m_relTime = (m_simulationSpeed * m_realRelTime) / 1e9f;
|
||||||
|
|
||||||
|
|
||||||
m_engine->FrameUpdate();
|
|
||||||
m_sound->FrameMove(m_relTime);
|
|
||||||
|
|
||||||
|
|
||||||
Event frameEvent(EVENT_FRAME);
|
Event frameEvent(EVENT_FRAME);
|
||||||
frameEvent.systemEvent = true;
|
frameEvent.systemEvent = true;
|
||||||
frameEvent.trackedKeysState = m_trackedKeys;
|
frameEvent.trackedKeysState = m_trackedKeys;
|
||||||
|
@ -1197,7 +1198,8 @@ void CApplication::StepSimulation()
|
||||||
frameEvent.mousePos = m_mousePos;
|
frameEvent.mousePos = m_mousePos;
|
||||||
frameEvent.mouseButtonsState = m_mouseButtonsState;
|
frameEvent.mouseButtonsState = m_mouseButtonsState;
|
||||||
frameEvent.rTime = m_relTime;
|
frameEvent.rTime = m_relTime;
|
||||||
m_eventQueue->AddEvent(frameEvent);
|
|
||||||
|
return frameEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CApplication::GetSimulationSpeed()
|
float CApplication::GetSimulationSpeed()
|
||||||
|
|
|
@ -199,9 +199,6 @@ public:
|
||||||
//! Returns whether simulation is suspended
|
//! Returns whether simulation is suspended
|
||||||
bool GetSimulationSuspended();
|
bool GetSimulationSuspended();
|
||||||
|
|
||||||
//! Updates the simulation state
|
|
||||||
void StepSimulation();
|
|
||||||
|
|
||||||
//@{
|
//@{
|
||||||
//! Management of simulation speed
|
//! Management of simulation speed
|
||||||
void SetSimulationSpeed(float speed);
|
void SetSimulationSpeed(float speed);
|
||||||
|
@ -312,6 +309,8 @@ protected:
|
||||||
Event ProcessSystemEvent();
|
Event ProcessSystemEvent();
|
||||||
//! If applicable, creates a virtual event to match the changed state as of new event
|
//! If applicable, creates a virtual event to match the changed state as of new event
|
||||||
Event CreateVirtualEvent(const Event& sourceEvent);
|
Event CreateVirtualEvent(const Event& sourceEvent);
|
||||||
|
//! Prepares a simulation update event
|
||||||
|
Event CreateUpdateEvent();
|
||||||
//! Handles some incoming events
|
//! Handles some incoming events
|
||||||
bool ProcessEvent(const Event& event);
|
bool ProcessEvent(const Event& event);
|
||||||
//! Renders the image in window
|
//! Renders the image in window
|
||||||
|
|
Loading…
Reference in New Issue