MCPcopy Create free account
hub / github.com/defold/defold / UpdateTimers

Function UpdateTimers

engine/script/src/script_timer.cpp:217–309  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215 }
216
217 void UpdateTimers(HTimerWorld timer_world, float dt)
218 {
219 assert(timer_world != 0x0);
220 DM_PROFILE("Update");
221
222 timer_world->m_InUpdate = 1;
223
224 // We make a copy of the indices, as it's possible the m_Instances may be altered
225 // Any timers added during this update call, will be updated the next frame
226 uint32_t size = CopyIndices(timer_world->m_Instances, timer_world->m_ScratchBuffer);
227
228 DM_PROPERTY_ADD_U32(rmtp_TimerCount, size);
229
230 for (uint32_t i = 0; i < size; ++i)
231 {
232 uint16_t index = timer_world->m_ScratchBuffer[i];
233 Timer* timer = GetTimerFromIndex(timer_world, index);
234 if (!timer)
235 {
236 continue;
237 }
238
239 if (timer->m_IsAlive == 0)
240 {
241 continue;
242 }
243
244 timer->m_Remaining -= dt;
245 if (timer->m_Remaining > 0.0f)
246 {
247 continue;
248 }
249
250 float elapsed_time = timer->m_Delay - timer->m_Remaining - timer->m_PrevCycleExcess;
251
252 TimerEventType eventType = timer->m_Repeat == 0 ? TIMER_EVENT_TRIGGER_WILL_DIE : TIMER_EVENT_TRIGGER_WILL_REPEAT;
253 timer->m_Callback(timer_world, eventType, timer->m_Handle, elapsed_time, timer->m_Owner, timer->m_UserData);
254
255 if (timer_world->m_IsDirty)
256 {
257 // If the containers were reallocated, the current timer pointer needs to get fetched again
258 timer = GetTimerFromIndex(timer_world, index);
259 assert(timer);
260 }
261
262 if (timer->m_IsAlive == 0)
263 {
264 continue;
265 }
266
267 if (timer->m_Repeat == 0)
268 {
269 timer->m_IsAlive = 0;
270 continue;
271 }
272
273 if (timer->m_Delay == 0.0f)
274 {

Callers 2

TimerUpdateScriptWorldFunction · 0.85
TEST_FFunction · 0.85

Calls 5

CopyIndicesFunction · 0.85
GetTimerFromIndexFunction · 0.85
floorFunction · 0.85
FreeTimerFunction · 0.85
assertFunction · 0.50

Tested by 1

TEST_FFunction · 0.68