@@ -116,13 +116,15 @@ Qor :: Qor(const Args& args, std::string appname="qor"):
116
116
#endif
117
117
118
118
m_pWindow = make_shared<Window>(m_Args, &m_Resources);
119
+ m_MaxFPS = m_pWindow->refresh_rate ();
119
120
120
121
// auto& renderer = CEGUI::OpenGLRenderer::bootstrapSystem();
121
122
// CEGUI::OpenGLRenderer::create();
122
123
// CEGUI::System::create(renderer);
123
124
124
125
m_pInput = make_shared<Input>(m_pWindow.get ());
125
126
m_pTimer = make_shared<Freq>();
127
+ m_TPSAlarm.timer (m_pTimer->timeline ());
126
128
m_FPSAlarm.timer (m_pTimer->timeline ());
127
129
// m_pGUI = make_shared<GUI>(m_pTimer.get(), m_pWindow.get(), &m_Resources);
128
130
// m_pGUI->init();
@@ -167,6 +169,7 @@ Qor :: Qor(const Args& args, std::string appname="qor"):
167
169
// m_pCanvas = kit::make_unique<Canvas>(m_pWindow->size().x, m_pWindow->size().y);
168
170
m_pPipeline = make_shared<Pipeline>(m_pWindow.get (), m_Args, &m_Resources);
169
171
172
+ m_TPSAlarm.set (Freq::Time::seconds (1 .0f ));
170
173
m_FPSAlarm.set (Freq::Time::seconds (1 .0f ));
171
174
}
172
175
@@ -182,24 +185,38 @@ Qor :: ~Qor()
182
185
void Qor :: logic()
183
186
{
184
187
Freq::Time t;
185
- if (m_FPSAlarm .elapsed ()) {
186
- m_FPSAlarm .set (Freq::Time::seconds (1 .0f ));
187
- m_FPS = m_FramesLastSecond ;
188
- LOGf (" FPS : %s" , m_FPS );
189
- m_FramesLastSecond = 0 ;
188
+ if (m_TPSAlarm .elapsed ()) {
189
+ m_TPSAlarm .set (Freq::Time::seconds (1 .0f ));
190
+ m_TPS = m_TicksLastSecond ;
191
+ LOGf (" Ticks : %s" , m_TPS );
192
+ m_TicksLastSecond = 0 ;
190
193
}
191
- while (!(t = m_pTimer->tick ()).ui ())
194
+ m_TickAccum = 0 ;
195
+ while (true )
192
196
{
197
+ // accumulated enough time to advance?
198
+ t = m_pTimer->tick ();
199
+ m_TickAccum += t.s ();
200
+ m_FrameAccum += t.s ();
201
+ if (m_MaxTick < K_EPSILON) // MaxTick==0 for unlimited ticks
202
+ break ;
203
+ if ((m_TickAccum > 1 .0f /m_MaxTick) ||
204
+ (m_MaxFPS > K_EPSILON && m_FrameAccum > 1 .0f /m_MaxFPS))
205
+ break ;
193
206
try {
194
207
this_thread::yield ();
195
208
}catch (...){
196
209
quit ();
197
210
return ;
198
211
}
199
212
}
200
- // t = m_pTimer->tick();
201
- ++m_FramesLastSecond;
213
+ // LOGf("%s", m_TickAccum);
214
+
215
+ ++m_TicksLastSecond;
202
216
217
+ bool pipeline_dirty = m_pPipeline->dirty ();
218
+ int pipeline_idlemode = m_pPipeline->idle ();
219
+
203
220
m_pInput->logic (t);
204
221
if (m_pInput->quit_flag ())
205
222
{
@@ -208,17 +225,39 @@ void Qor :: logic()
208
225
}
209
226
// m_pAudio->logic(t.ms());
210
227
228
+ // Get pipeline idlemode and dirty state BEFORE logic() (since this changes)
229
+ // Do not execute state logic if pipeline is using logic idle mode
211
230
m_pPipeline->logic (t);
212
- if (state ()){
213
- state ()->logic (t);
214
- }
231
+ if (not (pipeline_idlemode & Pipeline::IDLE_LOGIC) || pipeline_dirty)
232
+ if (state ()){
233
+ state ()->logic (t);
234
+ }
215
235
}
216
236
217
237
void Qor :: render()
218
238
{
219
239
if (Headless::enabled ())
220
240
return ;
221
-
241
+
242
+ bool pipeline_dirty = m_pPipeline->dirty ();
243
+ int pipeline_idlemode = m_pPipeline->idle ();
244
+ if ((pipeline_idlemode & Pipeline::IDLE_RENDER) && not pipeline_dirty)
245
+ return ;
246
+
247
+ if (m_FPSAlarm.elapsed ()) {
248
+ m_FPSAlarm.set (Freq::Time::seconds (1 .0f ));
249
+ m_FPS = m_FramesLastSecond;
250
+ LOGf (" FPS: %s" , m_FPS);
251
+ m_FramesLastSecond = 0 ;
252
+ }
253
+
254
+ if (m_MaxFPS > K_EPSILON) // max fps limit?
255
+ if (m_FrameAccum < 1 .0f /m_MaxFPS) // not time for frame
256
+ return ; // do more logic() before render
257
+ m_FrameAccum = 0 ;
258
+
259
+ ++m_FramesLastSecond;
260
+
222
261
if (state ())
223
262
state ()->render ();
224
263
m_pWindow->render ();
0 commit comments