@@ -259,7 +259,7 @@ namespace App
259259 // / kMsgAppUpdate message. Every frame uses a Clock object to compare the elapsed time since
260260 // / this task as scheduled. The listener is removed once the task has finished executing.
261261 // /
262- // / @param function A void function with no parameters, that will be executed every frame .
262+ // / @param function A void function with no parameters, that will be executed after the scheduled time .
263263 // / @param scheduleTime The time that has to pass, in seconds, since the task is scheduled for it to be executed.
264264 inline ScheduledTaskListenerPtr ScheduleTask (const VoidFunction_T& function, float scheduleTime) {
265265 auto listener = new ScheduledTaskListener (function, scheduleTime, 0 .0f );
@@ -268,6 +268,14 @@ namespace App
268268 return listener;
269269 }
270270
271+ // / @param function A void function with parameters, that will be executed after the scheduled time.
272+ // / @param scheduleTime The time that has to pass, in seconds, since the task is scheduled for it to be executed.
273+ template <typename Func, typename ... Args>
274+ inline ScheduledTaskListenerPtr ScheduleTaskWithArgs (Func&& function, float scheduleTime, Args&&... args) {
275+ auto boundFunction = [=]() { function (args...); };
276+ return ScheduleTask (boundFunction, scheduleTime);
277+ }
278+
271279 // /
272280 // / Executes a class method after a certain time (measured in seconds) has passed from ths call. The method
273281 // / is executed only once, and the time starts counting since this ScheduleTask method has been called.
@@ -280,7 +288,7 @@ namespace App
280288 // / this task as scheduled. The listener is removed once the task has finished executing.
281289 // /
282290 // / @param object The object to which the method will be called.
283- // / @param method A void method with no parameters, that will be executed every frame .
291+ // / @param method A void method with no parameters, that will be executed after the scheduled time .
284292 // / @param scheduleTime The time that has to pass, in seconds, since the task is scheduled for it to be executed.
285293 template <class T >
286294 inline ScheduledTaskListenerPtr ScheduleTask (T* object, VoidMethod_T<T> method, float scheduleTime) {
@@ -289,6 +297,27 @@ namespace App
289297 }, scheduleTime);
290298 }
291299
300+ // / @param object The object to which the method will be called.
301+ // / @param function A void function with parameters, that will be executed after the scheduled time.
302+ // / @param scheduleTime The time that has to pass, in seconds, since the task is scheduled for it to be executed.
303+ template <class ObjT , class MethodT , class ... MethodArgs, class ... CallArgs>
304+ inline ScheduledTaskListenerPtr ScheduleTaskWithArgs (
305+ ObjT* object,
306+ void (MethodT::* method)(MethodArgs...),
307+ float scheduleTime,
308+ CallArgs&&... args)
309+ {
310+ static_assert (std::is_base_of_v<MethodT, ObjT>,
311+ " Object must derive from method's class" );
312+
313+ // Own the data safely for delayed execution
314+ auto boundFunction = [object, method, args...]() {
315+ (static_cast <MethodT*>(object)->*method)(args...);
316+ };
317+
318+ return ScheduleTask (boundFunction, scheduleTime);
319+ }
320+
292321 // /
293322 // / Executes a function after a certain time (measured in seconds) has passed from this call,
294323 // / and then keeps repeating it after a certain period (defined by the repeatRate parameter) parameter. The function is executed only
@@ -366,7 +395,7 @@ namespace Simulator
366395 // / kMsgAppUpdate message. Every frame uses a cGonzagoTimer object to compare the elapsed time since
367396 // / this task as scheduled. The listener is removed once the task has finished executing.
368397 // /
369- // / @param function A void function with no parameters, that will be executed every frame .
398+ // / @param function A void function with no parameters, that will be executed after the scheduled time .
370399 // / @param scheduleTime The time that has to pass, in seconds, since the task is scheduled for it to be executed.
371400 inline SimScheduledTaskListenerPtr ScheduleTask (const App::VoidFunction_T& function, float scheduleTime) {
372401 auto listener = new ScheduledTaskListener (function, scheduleTime, 0 .0f );
@@ -375,6 +404,14 @@ namespace Simulator
375404 return listener;
376405 }
377406
407+ // / @param function A void function with parameters, that will be executed after the scheduled time.
408+ // / @param scheduleTime The time that has to pass, in seconds, since the task is scheduled for it to be executed.
409+ template <typename Func, typename ... Args>
410+ inline SimScheduledTaskListenerPtr ScheduleTaskWithArgs (Func&& function, float scheduleTime, Args&&... args) {
411+ auto boundFunction = [=]() { function (args...); };
412+ return ScheduleTask (boundFunction, scheduleTime);
413+ }
414+
378415 // /
379416 // / Executes a class method after a certain time (measured in seconds) has passed from ths call. The method
380417 // / is executed only once, and the time starts counting since this ScheduleTask method has been called.
@@ -387,7 +424,7 @@ namespace Simulator
387424 // / this task as scheduled. The listener is removed once the task has finished executing.
388425 // /
389426 // / @param object The object to which the method will be called.
390- // / @param method A void method with no parameters, that will be executed every frame .
427+ // / @param method A void method with no parameters, that will be executed after the scheduled time .
391428 // / @param scheduleTime The time that has to pass, in seconds, since the task is scheduled for it to be executed.
392429 template <class T >
393430 inline SimScheduledTaskListenerPtr ScheduleTask (T* object, App::VoidMethod_T<T> method, float scheduleTime) {
@@ -396,6 +433,27 @@ namespace Simulator
396433 }, scheduleTime);
397434 }
398435
436+ // / @param object The object to which the method will be called.
437+ // / @param method A void method with parameters, that will be executed after the scheduled time.
438+ // / @param scheduleTime The time that has to pass, in seconds, since the task is scheduled for it to be executed.
439+ template <class ObjT , class MethodT , class ... MethodArgs, class ... CallArgs>
440+ inline SimScheduledTaskListenerPtr ScheduleTaskWithArgs (
441+ ObjT* object,
442+ void (MethodT::* method)(MethodArgs...),
443+ float scheduleTime,
444+ CallArgs&&... args)
445+ {
446+ static_assert (std::is_base_of_v<MethodT, ObjT>,
447+ " Object must derive from method's class" );
448+
449+ // Own the data safely for delayed execution
450+ auto boundFunction = [object, method, args...]() {
451+ (static_cast <MethodT*>(object)->*method)(args...);
452+ };
453+
454+ return ScheduleTask (boundFunction, scheduleTime);
455+ }
456+
399457 // /
400458 // / Executes a function after a certain time (measured in seconds) has passed from this call,
401459 // / and then keeps repeating it after a certain period (defined by the repeatRate parameter) parameter. The function is executed only
0 commit comments