MCPcopy Create free account
hub / github.com/cocos/cocos-engine / update

Method update

native/cocos/base/Scheduler.cpp:55–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55void Timer::update(float dt) {
56 if (_elapsed == -1) {
57 _elapsed = 0;
58 _timesExecuted = 0;
59 return;
60 }
61
62 // accumulate elapsed time
63 _elapsed += dt;
64
65 // deal with delay
66 if (_useDelay) {
67 if (_elapsed < _delay) {
68 return;
69 }
70 trigger(_delay);
71 _elapsed = _elapsed - _delay;
72 _timesExecuted += 1;
73 _useDelay = false;
74 // after delay, the rest time should compare with interval
75 if (!_runForever && _timesExecuted > _repeat) { //unschedule timer
76 cancel();
77 return;
78 }
79 }
80
81 // if _interval == 0, should trigger once every frame
82 float interval = (_interval > 0) ? _interval : _elapsed;
83 while (_elapsed >= interval) {
84 trigger(interval);
85 _elapsed -= interval;
86 _timesExecuted += 1;
87
88 if (!_runForever && _timesExecuted > _repeat) {
89 cancel();
90 break;
91 }
92
93 if (_elapsed <= 0.F) {
94 break;
95 }
96
97 if (_scheduler->isCurrentTargetSalvaged()) {
98 break;
99 }
100 }
101}
102
103// TimerTargetCallback
104

Callers

nothing calls this directly

Calls 6

endMethod · 0.65
sizeMethod · 0.65
updateMethod · 0.65
beginMethod · 0.45
releaseMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected