All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
kzu_task_scheduler.h File Reference

Task scheduler for periodically calling a set of functions. More...

Namespaces

 kanzi
 

Typedefs

typedef kzsError(* KzuTaskFunction )(kzUint deltaTime, void *userData, kzBool *out_done)
 Scheduled task function. More...
 

Functions

KANZI_API kzsError kzuTaskSchedulerCreate (const struct KzcMemoryManager *memoryManager, struct KzuTaskScheduler **out_taskScheduler)
 Create a new task scheduler. More...
 
KANZI_API kzsError kzuTaskSchedulerDelete (struct KzuTaskScheduler *taskScheduler)
 Delete a task scheduler. More...
 
KANZI_API kzsError kzuTaskSchedulerAddRecurringTask (const struct KzuTaskScheduler *taskScheduler, KzuTaskFunction taskFunction, void *userParameters)
 Add a recurring task to the task scheduler. More...
 
KANZI_API kzsError kzuTaskSchedulerAttachAnimationPlayer (const struct KzuTaskScheduler *taskScheduler, struct KzuAnimationPlayer *animationPlayer)
 Attach an animation player to the master animation player in the task scheduler. More...
 
KANZI_API kzsError kzuTaskSchedulerAttachScrubbableAnimationPlayer (const struct KzuTaskScheduler *taskScheduler, struct KzuAnimationPlayer *animationPlayer)
 Replace the child animation player of the scrubbable animation player. More...
 
KANZI_API void kzuTaskSchedulerSetScrubbableAnimationDeltaTime (struct KzuTaskScheduler *taskScheduler, kzUint deltaTime)
 Set scrubbable animation time. More...
 
KANZI_API struct
KzuAnimationPlayer
kzuTaskSchedulerGetAnimationPlayer (const struct KzuTaskScheduler *taskScheduler)
 Get the master animation player for this task scheduler. More...
 
KANZI_API struct
KzuAnimationPlayer
kzuTaskSchedulerGetRootAnimationPlayer_private (struct KzuTaskScheduler *taskScheduler)
 Gets the root animation player for task scheduler. More...
 
KANZI_API void kzuTaskSchedulerSetRootAnimationPlayer_private (struct KzuTaskScheduler *taskScheduler, struct KzuAnimationPlayer *player)
 Sets the root animation player for task scheduler. More...
 
KANZI_API void kzuTaskSchedulerSetScrubbableAnimationPlayer_private (struct KzuTaskScheduler *taskScheduler, struct KzuAnimationPlayer *player)
 Sets the scrubbable animation player for task scheduler. More...
 
KANZI_API void kzuTaskSchedulerSetAnimationPlayers (struct KzuTaskScheduler *taskScheduler, kanzi::Domain *domain, KzuAnimationPlayer *rootAnimationPlayer, KzuAnimationPlayer *scrubbableAnimationPlayer)
 Set the task scheduler domain. More...
 
KANZI_API kzsError kzuTaskSchedulerRemoveTask (const struct KzuTaskScheduler *taskScheduler, KzuTaskFunction taskFunction, const void *userParameters)
 Remove a task from the task scheduler. More...
 
KANZI_API kzsError kzuTaskSchedulerExecuteAllTasks (struct KzuTaskScheduler *taskScheduler, kzUint deltaTime, kanzi::Node *rootNode)
 Execute all tasks in the task scheduler. More...
 
KANZI_API kzsError kzuTaskSchedulerExecuteRootAnimation_private (struct KzuTaskScheduler *taskScheduler, kanzi::Node *rootNode, kzUint deltaTime)
 Run root animation task from outside task scheduler. More...
 

Detailed Description

Task scheduler for periodically calling a set of functions.

When the application framework is used, Kanzi will automatically create a task scheduler accessible with ::kzaApplicationGetTaskScheduler(). That is used for e.g. playing animations.

Copyright 2008-2020 by Rightware. All rights reserved.

Typedef Documentation

typedef kzsError(* KzuTaskFunction)(kzUint deltaTime, void *userData, kzBool *out_done)

Scheduled task function.

Parameters
deltaTimeElapsed time in milliseconds.
userDataArbitrary pointer previously passed to kzuTaskSchedulerAddRecurringTask().
out_doneSet this to KZ_TRUE to remove the task from the scheduler or KZ_FALSE to keep the the task in execution.
Returns
The function should return KZS_SUCCESS on success. If it returns an error, execution of tasks is aborted and the error is passed forward.

Function Documentation

KANZI_API kzsError kzuTaskSchedulerCreate ( const struct KzcMemoryManager memoryManager,
struct KzuTaskScheduler **  out_taskScheduler 
)

Create a new task scheduler.

KANZI_API kzsError kzuTaskSchedulerDelete ( struct KzuTaskScheduler taskScheduler)

Delete a task scheduler.

KANZI_API kzsError kzuTaskSchedulerAddRecurringTask ( const struct KzuTaskScheduler taskScheduler,
KzuTaskFunction  taskFunction,
void *  userParameters 
)

Add a recurring task to the task scheduler.

Parameters
taskSchedulerThe task scheduler to use.
taskFunctionThe function to call periodically.
userParametersArbitrary pointer that will be passed to the task function.
Returns
KZS_SUCCESS on success.
KANZI_API kzsError kzuTaskSchedulerAttachAnimationPlayer ( const struct KzuTaskScheduler taskScheduler,
struct KzuAnimationPlayer animationPlayer 
)

Attach an animation player to the master animation player in the task scheduler.

This only attaches to the main animation player that is not controlling its own time.

Parameters
taskSchedulerTask scheduler.
animationPlayerAnimation player to set.
Returns
Error code.
KANZI_API kzsError kzuTaskSchedulerAttachScrubbableAnimationPlayer ( const struct KzuTaskScheduler taskScheduler,
struct KzuAnimationPlayer animationPlayer 
)

Replace the child animation player of the scrubbable animation player.

Assumption is that the previous scrubbable animation player is already detached. Will not specifically detach it.

Parameters
taskSchedulerTask scheduler.
animationPlayerAnimation player to set.
Returns
Error code.
KANZI_API void kzuTaskSchedulerSetScrubbableAnimationDeltaTime ( struct KzuTaskScheduler taskScheduler,
kzUint  deltaTime 
)

Set scrubbable animation time.

If not set, next update will use deltaTime as passwd otherwise.

TODO: Remove this whole thing with the new task scheduler and better tasks.

Parameters
deltaTimeTime to use for next update of scrubbable animation player.
KANZI_API struct KzuAnimationPlayer* kzuTaskSchedulerGetAnimationPlayer ( const struct KzuTaskScheduler taskScheduler)

Get the master animation player for this task scheduler.

KANZI_API struct KzuAnimationPlayer* kzuTaskSchedulerGetRootAnimationPlayer_private ( struct KzuTaskScheduler taskScheduler)

Gets the root animation player for task scheduler.

KANZI_API void kzuTaskSchedulerSetRootAnimationPlayer_private ( struct KzuTaskScheduler taskScheduler,
struct KzuAnimationPlayer player 
)

Sets the root animation player for task scheduler.

Use kzuTaskSchedulerSetAnimationPlayers instead if possible.

KANZI_API void kzuTaskSchedulerSetScrubbableAnimationPlayer_private ( struct KzuTaskScheduler taskScheduler,
struct KzuAnimationPlayer player 
)

Sets the scrubbable animation player for task scheduler.

Use kzuTaskSchedulerSetAnimationPlayers instead if possible.

KANZI_API void kzuTaskSchedulerSetAnimationPlayers ( struct KzuTaskScheduler taskScheduler,
kanzi::Domain domain,
KzuAnimationPlayer rootAnimationPlayer,
KzuAnimationPlayer scrubbableAnimationPlayer 
)

Set the task scheduler domain.

Parameters
taskSchedulerTask scheduler to set animation players to.
domainDomain owning the animation players.
rootAnimationPlayerRoot animation player.
scrubbableAnimationPlayerScrubbable animation player.
KANZI_API kzsError kzuTaskSchedulerRemoveTask ( const struct KzuTaskScheduler taskScheduler,
KzuTaskFunction  taskFunction,
const void *  userParameters 
)

Remove a task from the task scheduler.

Parameters
taskSchedulerThe task scheduler to use.
taskFunctionThe function to remove from execution.
userParametersThe pointer that was specified when the task was added to the task scheduler.
Returns
KZU_ERROR_SCHEDULER_TASK_NOT_FOUND if the function with the userParameters was not found. KZS_SUCCESS on success.
KANZI_API kzsError kzuTaskSchedulerExecuteAllTasks ( struct KzuTaskScheduler taskScheduler,
kzUint  deltaTime,
kanzi::Node rootNode 
)

Execute all tasks in the task scheduler.

Parameters
taskSchedulerThe task scheduler to use.
deltaTimeUsually this should be milliseconds elapsed since the last execution, but other values can also be used to e.g. control animations.
rootNodeThe root node of the scheduler. Normally this should be the ::KzuScreen of the application. This is used to disable animations that are attached to nodes under other root nodes, such as nodes which do not belong to any scene.
Returns
KZS_SUCCESS on success. Any error returned by a task function.
KANZI_API kzsError kzuTaskSchedulerExecuteRootAnimation_private ( struct KzuTaskScheduler taskScheduler,
kanzi::Node rootNode,
kzUint  deltaTime 
)

Run root animation task from outside task scheduler.

This function is not called by the task scheduler itself. Exposed so can be called from tests.

Parameters
taskSchedulerTask scheduler to run in.
rootNodeRoot node to use.
deltaTimeAdvanced time in milliseconds.
Returns
Error code.