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);
|
||||
}
|
||||
|
||||
// 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
|
||||
* because mouse events are usually way behind */
|
||||
UpdateMouse();
|
||||
|
||||
// Update game and render a frame during idle time (no messages are waiting)
|
||||
Render();
|
||||
|
||||
// Update simulation state
|
||||
StepSimulation();
|
||||
|
||||
if (m_lowCPU)
|
||||
{
|
||||
usleep(20000); // should still give plenty of fps
|
||||
|
@ -1167,10 +1173,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);
|
||||
|
@ -1185,11 +1191,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;
|
||||
|
@ -1197,7 +1198,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()
|
||||
|
|
|
@ -199,9 +199,6 @@ public:
|
|||
//! Returns whether simulation is suspended
|
||||
bool GetSimulationSuspended();
|
||||
|
||||
//! Updates the simulation state
|
||||
void StepSimulation();
|
||||
|
||||
//@{
|
||||
//! Management of simulation speed
|
||||
void SetSimulationSpeed(float speed);
|
||||
|
@ -312,6 +309,8 @@ protected:
|
|||
Event ProcessSystemEvent();
|
||||
//! If applicable, creates a virtual event to match the changed state as of new event
|
||||
Event CreateVirtualEvent(const Event& sourceEvent);
|
||||
//! Prepares a simulation update event
|
||||
Event CreateUpdateEvent();
|
||||
//! Handles some incoming events
|
||||
bool ProcessEvent(const Event& event);
|
||||
//! Renders the image in window
|
||||
|
|
Loading…
Reference in New Issue