2026-05-06 23:18:42 -04:00
|
|
|
#ifndef _AKGL_SPRITE_H_
|
|
|
|
|
#define _AKGL_SPRITE_H_
|
2025-08-03 10:07:35 -04:00
|
|
|
|
|
|
|
|
#include <SDL3/SDL_properties.h>
|
2026-05-03 23:57:55 -04:00
|
|
|
#include <SDL3/SDL.h>
|
2026-01-05 08:58:06 -05:00
|
|
|
#include <akerror.h>
|
2025-08-03 10:07:35 -04:00
|
|
|
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
#define AKGL_SPRITE_MAX_FRAMES 16
|
|
|
|
|
#define AKGL_SPRITE_MAX_NAME_LENGTH 128
|
|
|
|
|
#define AKGL_SPRITE_MAX_REGISTRY_SIZE 1024
|
|
|
|
|
#define AKGL_SPRITE_SHEET_MAX_FILENAME_LENGTH 512
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
#define AKGL_MAX_HEAP_SPRITE (AKGL_MAX_HEAP_ACTOR * 16)
|
|
|
|
|
#define AKGL_MAX_HEAP_SPRITESHEET AKGL_MAX_HEAP_SPRITE
|
2025-08-03 10:07:35 -04:00
|
|
|
|
|
|
|
|
typedef struct {
|
2026-05-08 22:01:56 -04:00
|
|
|
uint8_t refcount;
|
|
|
|
|
SDL_Texture *texture;
|
|
|
|
|
char name[AKGL_SPRITE_SHEET_MAX_FILENAME_LENGTH];
|
|
|
|
|
uint16_t sprite_w;
|
|
|
|
|
uint16_t sprite_h;
|
2026-05-06 23:18:42 -04:00
|
|
|
} akgl_SpriteSheet;
|
2025-08-03 10:07:35 -04:00
|
|
|
|
|
|
|
|
typedef struct {
|
2026-05-08 22:01:56 -04:00
|
|
|
uint8_t refcount;
|
|
|
|
|
uint8_t frameids[AKGL_SPRITE_MAX_FRAMES]; // which IDs on the spritesheet belong to our frames
|
|
|
|
|
uint32_t frames; // how many frames are in this animation
|
|
|
|
|
uint32_t width;
|
|
|
|
|
uint32_t height;
|
|
|
|
|
uint32_t speed; // how many milliseconds a given sprite frame should be visible before cycling
|
|
|
|
|
bool loop; // when this sprite is done playing, it should immediately start again
|
|
|
|
|
bool loopReverse; // when this sprite is done playing, it should go in reverse order through its frames
|
|
|
|
|
char name[AKGL_SPRITE_MAX_NAME_LENGTH];
|
2026-05-09 14:45:37 -04:00
|
|
|
akgl_SpriteSheet *sheet;
|
2026-05-06 23:18:42 -04:00
|
|
|
} akgl_Sprite;
|
2025-08-03 10:07:35 -04:00
|
|
|
|
|
|
|
|
// initializes a new sprite to use the given sheet and otherwise sets to zero
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_sprite_initialize(akgl_Sprite *spr, char *name, akgl_SpriteSheet *sheet);
|
2025-08-03 10:07:35 -04:00
|
|
|
// loads a given image file into a new spritesheet
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_spritesheet_initialize(akgl_SpriteSheet *sheet, int sprite_w, int sprite_h, char *filename);
|
|
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_sprite_load_json(char *filename);
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2026-05-12 15:21:36 -04:00
|
|
|
akerr_ErrorContext *akgl_sprite_sheet_coords_for_frame(akgl_Sprite *self, SDL_FRect *srccoords, uint8_t frameid);
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
#endif //_AKGL_SPRITE_H_
|