| 43 | uintptr_t TimerObject::s_timerId = 0; |
| 44 | |
| 45 | TIMER_ID loop(unsigned int n, float interval, vcallback_t callback, bool bNative) |
| 46 | { |
| 47 | if (n > 0 && interval >= 0) |
| 48 | { |
| 49 | yasio::ref_ptr<TimerObject> timerObj(new TimerObject(std::move(callback))); |
| 50 | |
| 51 | auto timerId = reinterpret_cast<TIMER_ID>(++TimerObject::s_timerId); |
| 52 | |
| 53 | std::string key = fmt::format("STMR#{}", fmt::ptr(timerId)); |
| 54 | |
| 55 | Director::getInstance()->getScheduler()->schedule( |
| 56 | [timerObj](float /*dt*/) { // lambda expression hold the reference of timerObj automatically. |
| 57 | timerObj->callback_(); |
| 58 | }, |
| 59 | STIMER_TARGET(bNative), interval, n - 1, 0, false, key); |
| 60 | |
| 61 | return timerId; |
| 62 | } |
| 63 | return nullptr; |
| 64 | } |
| 65 | |
| 66 | TIMER_ID delay(float delay, vcallback_t callback, bool bNative) |
| 67 | { |
nothing calls this directly
no test coverage detected