Mercurial > molko
diff libmlk-core/mlk/core/action.h @ 509:a11cd7ea3a37
core: doxygenize action
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sat, 04 Mar 2023 08:52:57 +0100 |
parents | c1f64d451230 |
children | 6e8f6640e05b |
line wrap: on
line diff
--- a/libmlk-core/mlk/core/action.h Fri Mar 03 19:45:00 2023 +0100 +++ b/libmlk-core/mlk/core/action.h Sat Mar 04 08:52:57 2023 +0100 @@ -1,5 +1,5 @@ /* - * action.h -- action states + * action.h -- generic in game actions * * Copyright (c) 2020-2023 David Demelier <markand@malikania.fr> * @@ -19,39 +19,162 @@ #ifndef MLK_CORE_ACTION_H #define MLK_CORE_ACTION_H +/** + * \file mlk/core/action.h + * \brief Generic in game actions. + * + * This module help creating user interaction within the gameplay by adding + * actions. They have the following properties: + * + * - Can handle user input and events, + * - Can be updated through the game loop, + * - Can be drawn. + * + * Most more high level objects can handle actions to add flexibility (like in + * battles, maps, etc). + */ + #include "core.h" union mlk_event; +/** + * \struct mlk_action + * \brief Action structure + * + * Use this structure to create an action that may handle input, be updated and + * drawn. + */ struct mlk_action { + /** + * (read-write, borrowed, optional) + * + * Arbitrary user data. + */ void *data; - void (*start)(struct mlk_action *); - void (*handle)(struct mlk_action *, const union mlk_event *); - int (*update)(struct mlk_action *, unsigned int); - void (*draw)(struct mlk_action *); - void (*end)(struct mlk_action *); + + /** + * (optional) + * + * Start the action. + * + * Use this function when the action should start. + * + * \param self this action + */ + void (*start)(struct mlk_action *self); + + /** + * (optional) + * + * Handle an event. + * + * \param self this action + * \param event the event + */ + void (*handle)(struct mlk_action *self, const union mlk_event *event); + + /** + * (optional) + * + * Update the action with the given ticks since last frame. + * + * The callback should return non-zero if it is considered complete. + * + * \param self this action + * \param ticks frame ticks + * \return non-zero if complete + */ + int (*update)(struct mlk_action *self, unsigned int ticks); + + /** + * (optional) + * + * Draw the action. + * + * \param self this action + */ + void (*draw)(struct mlk_action *self); + + /** + * (optional) + * + * Terminate the action. + * + * In contrast to finish, this function should be called after the + * action was considered complete. + * + * \param self this action + */ + void (*end)(struct mlk_action *self); + + /** + * (optional) + * + * Dispose resources allocated by/for the action. + * + * \param self this action + */ void (*finish)(struct mlk_action *); }; MLK_CORE_BEGIN_DECLS -void -mlk_action_start(struct mlk_action *); - +/** + * Invoke ::mlk_action::start function if not null. + * + * \pre action != NULL + * \param action the action + */ void -mlk_action_handle(struct mlk_action *, const union mlk_event *); +mlk_action_start(struct mlk_action *action); -int -mlk_action_update(struct mlk_action *, unsigned int); +/** + * Invoke ::mlk_action::handle function if not null. + * + * \pre action != NULL + * \param action the action + * \param event the event + */ +void +mlk_action_handle(struct mlk_action *action, const union mlk_event *event); -void -mlk_action_draw(struct mlk_action *); +/** + * Invoke ::mlk_action::update function if not null. + * + * \pre action != NULL + * \param action the action + * \param ticks frame ticks + */ +int +mlk_action_update(struct mlk_action *action, unsigned int ticks); +/** + * Invoke ::mlk_action::draw function if not null. + * + * \pre action != NULL + * \param action the action + */ void -mlk_action_end(struct mlk_action *); +mlk_action_draw(struct mlk_action *action); +/** + * Invoke ::mlk_action::end function if not null. + * + * \pre action != NULL + * \param action the action + */ void -mlk_action_finish(struct mlk_action *); +mlk_action_end(struct mlk_action *action); + +/** + * Invoke ::mlk_action::finish function if not null. + * + * \pre action != NULL + * \param action the action + */ +void +mlk_action_finish(struct mlk_action *action); MLK_CORE_END_DECLS