20 n_log(
LOG_ERR,
"Invalid size (<1) for anim lib creation");
31 n_log(
LOG_ERR,
"Unable to allocate a gfx_lib of size %d", size);
36 lib->
name = strdup(name);
38 lib->
name = strdup(
"generic-name");
53 for (uint32_t it = 0; it < (*lib)->nb_max_gfxs; it++) {
91 if (lib->
gfxs[pos] != NULL) {
92 n_log(
LOG_ERR,
"there already is a gfx at pos %d in anim lib %s", pos, lib->
name);
96 FILE* data = fopen(resfile,
"r");
103 int check_fscanf = 0;
106 check_fscanf = fscanf(data,
"%d", &check_id);
107 if (check_fscanf == 1 && check_id == 211282) {
111 n_log(
LOG_ERR,
"file %s: invalid check_id of %d, should be 211282", resfile, check_id);
116 if (fscanf(data,
"%d %d %d", &gfx->
w, &gfx->
h, &gfx->
nb_frames) != 3) {
117 n_log(
LOG_ERR,
"file %s: invalid &gfx -> w, &gfx -> h, &gfx -> nb_frames !", resfile);
138 gfx->
bmp = al_load_bitmap(file);
146 for (
unsigned int it = 0; it < gfx->
nb_frames; it++) {
147 if (fscanf(data,
"%d %d %d", &gfx->
frames[it].x, &gfx->
frames[it].y, &gfx->
frames[it].duration) != 3) {
148 n_log(
LOG_ERR,
"file %s: invalid &gfx -> frames[ %d ].x, &gfx -> frames[ %d ].y, &gfx -> frames[ %d ] . duration !", resfile, it, it, it);
156 lib->
gfxs[pos] = gfx;
188 ALLEGRO_BITMAP* bmp = data->
lib->
gfxs[data->id]->
bmp;
190 unsigned int tilew = data->
lib->
gfxs[data->id]->
w;
191 unsigned int tileh = data->
lib->
gfxs[data->id]->
h;
196 unsigned int framex = data->
frame * tilew;
198 al_draw_bitmap_region(bmp, framex, 0, tilew, tileh, x - px, y - py, 0);
unsigned int nb_frames
nb frames in anim
unsigned int w
width of a frame
unsigned int elapsed
elapsed time since last frame change
char * name
name of the anim library
ANIM_GFX ** gfxs
Stack of gfxs.
unsigned int h
height of a frame
ANIM_FRAME * frames
each frame properties
unsigned int frame
id of the current frame
ALLEGRO_BITMAP * bmp
bitmap with a list of lil' bitmap inside
ANIM_LIB * lib
pointer to an anim gfx library
unsigned int nb_max_gfxs
size of the stack
int delete_bmp_from_lib(ANIM_LIB *lib, unsigned int id)
Delete the frame at 'id' from 'lib'.
int add_bmp_to_lib(ANIM_LIB *lib, unsigned int pos, char *file, char *resfile)
add a bitmap to a ANIM_LIB *lib
int draw_anim(ANIM_DATA *data, int x, int y)
blit an ANIM_DATA at position x,y ( current selected video buffer is used )
ANIM_LIB * create_anim_library(char *name, unsigned int size)
Allocate an animation library.
int update_anim(ANIM_DATA *data, unsigned int delta_t)
compute and update an ANIM_DATA context based on elapsed delta_t time in usecs
int destroy_anim_lib(ANIM_LIB **lib)
Destroy an animation library.
struct of the properties of a frame in an animation
structure of a library of gfxs
#define FreeNoLog(__ptr)
Free Handler without log.
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define __n_assert(__ptr, __ret)
macro to assert things
#define Free(__ptr)
Free Handler to get errors.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_ERR
error conditions
Animations graphics and animations parameters.