Add void timer function support. (without metaprogramming)

This commit is contained in:
Kirigaya Kazuto 2017-05-05 09:02:39 +08:00
parent 1641dbf4bc
commit 3e2479e216

View File

@ -467,11 +467,21 @@ namespace MiniEngine
{ {
public: public:
Timer(); Timer();
/// Uint32 func(Uint32,void*) ...
/// void func(Uint32,...)
template<typename VoidCallable,typename... Args>
Timer(Uint32 interval,VoidCallable&& vcallable,Args&&... args) : Timer()
{
auto realCall=[&](Uint32 ims)->Uint32{vcallable(ims,args...);return interval;};
auto pfunc=new std::function<Uint32(Uint32 interval)>(realCall);
_real_timer_call(_global_timer_executor,interval,pfunc);
}
/// Uint32 func(Uint32,...)
template<typename Callable,typename... Args> template<typename Callable,typename... Args>
Timer(Callable&& callable,Uint32 interval,Args&&... args) : Timer() Timer(Callable&& callable,Uint32 interval,Args&&... args) : Timer()
{ {
auto realCall=[&](Uint32 interval)->Uint32{return callable(interval,args...);}; auto realCall=[&](Uint32 ims)->Uint32{return callable(ims,args...);};
auto pfunc=new std::function<Uint32(Uint32 interval)>(realCall); auto pfunc=new std::function<Uint32(Uint32 interval)>(realCall);
_real_timer_call(_global_timer_executor,interval,pfunc); _real_timer_call(_global_timer_executor,interval,pfunc);
} }