2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @file character.h
|
|
|
|
|
* @brief Declares the public character API.
|
|
|
|
|
*/
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
#ifndef _AKGL_CHARACTER_H_
|
|
|
|
|
#define _AKGL_CHARACTER_H_
|
2025-08-03 10:07:35 -04:00
|
|
|
|
|
|
|
|
#include <SDL3/SDL_properties.h>
|
2026-05-08 22:01:56 -04:00
|
|
|
#include "types.h"
|
2025-08-03 10:07:35 -04:00
|
|
|
#include "sprite.h"
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
#define AKGL_SPRITE_MAX_CHARACTER_NAME_LENGTH 128
|
|
|
|
|
#define AKGL_MAX_HEAP_CHARACTER 256
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2026-07-30 01:10:31 -04:00
|
|
|
/** @brief Defines reusable movement parameters and actor-state sprite bindings. */
|
2026-05-06 23:18:42 -04:00
|
|
|
typedef struct akgl_Character {
|
2026-05-26 10:36:31 -04:00
|
|
|
uint8_t refcount;
|
|
|
|
|
char name[AKGL_SPRITE_MAX_CHARACTER_NAME_LENGTH];
|
|
|
|
|
SDL_PropertiesID state_sprites;
|
|
|
|
|
uint64_t speedtime;
|
|
|
|
|
float32_t ax;
|
|
|
|
|
float32_t ay;
|
|
|
|
|
float32_t az;
|
|
|
|
|
float32_t sx;
|
|
|
|
|
float32_t sy;
|
|
|
|
|
float32_t sz;
|
|
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *(*sprite_add)(struct akgl_Character *, akgl_Sprite *, int);
|
|
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *(*sprite_get)(struct akgl_Character *, int, akgl_Sprite **);
|
2026-05-06 23:18:42 -04:00
|
|
|
} akgl_Character;
|
2025-08-03 10:07:35 -04:00
|
|
|
|
|
|
|
|
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Character initialize.
|
|
|
|
|
* @param basechar Character whose state-to-sprite map is accessed.
|
|
|
|
|
* @param name Registry key or human-readable object name.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_KEY When the corresponding validation or operation fails.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_character_initialize(akgl_Character *basechar, char *name);
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Character sprite add.
|
|
|
|
|
* @param basechar Character whose state-to-sprite map is accessed.
|
|
|
|
|
* @param ref Sprite reference to associate with the character.
|
|
|
|
|
* @param state Actor-state bit mask used as a sprite-map key.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_character_sprite_add(akgl_Character *basechar, akgl_Sprite *ref, int state);
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Character sprite get.
|
|
|
|
|
* @param basechar Character whose state-to-sprite map is accessed.
|
|
|
|
|
* @param state Actor-state bit mask used as a sprite-map key.
|
|
|
|
|
* @param dest Output destination populated by the function.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_KEY When the corresponding validation or operation fails.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_character_sprite_get(akgl_Character *basechar, int state, akgl_Sprite **dest);
|
2025-08-03 10:07:35 -04:00
|
|
|
|
|
|
|
|
// This is an SDL iterator so we can't return our error state from it.
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Character state sprites iterate.
|
|
|
|
|
* @param userdata Caller data supplied to the SDL property iterator.
|
|
|
|
|
* @param props SDL property collection being iterated.
|
|
|
|
|
* @param name Registry key or human-readable object name.
|
|
|
|
|
*/
|
2026-05-06 23:18:42 -04:00
|
|
|
void akgl_character_state_sprites_iterate(void *userdata, SDL_PropertiesID props, const char *name);
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Character load json.
|
|
|
|
|
* @param filename Path to the source asset or JSON document.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_character_load_json(char *filename);
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
#endif // _AKGL_CHARACTER_H_
|