23 n_log(
LOG_ERR,
"Invalid size (<1) for anim lib creation" );
35 n_log(
LOG_ERR,
"Unable to allocate a gfx_lib of size %d", size );
40 lib -> name = strdup( name );
42 lib -> name = strdup(
"generic-name" );
44 lib -> nb_max_gfxs = size ;
60 for( uint32_t it = 0 ; it < (*lib) -> nb_max_gfxs ; it ++ )
100 if( pos >= lib -> nb_max_gfxs )
102 n_log(
LOG_ERR,
"invalid position %d, can only go from 0 to %d in anim lib %s", pos, lib -> nb_max_gfxs, lib -> name );
105 if( lib -> gfxs[ pos ] != NULL )
107 n_log(
LOG_ERR,
"there already is a gfx at pos %d in anim lib %s", pos, lib -> name );
111 FILE *data = fopen( resfile,
"r");
117 if( fscanf( data,
"%d", &check_id ) != 1 || check_id !=211282 )
119 n_log(
LOG_ERR,
"file %s: invalid check_id of %d, should be 211282", resfile, check_id );
127 if( fscanf( data,
"%d %d %d", &gfx -> w, &gfx -> h, &gfx -> nb_frames ) != 3 )
129 n_log(
LOG_ERR,
"file %s: invalid &gfx -> w, &gfx -> h, &gfx -> nb_frames !", resfile );
135 gfx -> bmp = al_load_bitmap( file );
138 n_log(
LOG_ERR,
"file %s: unable to load image", file );
143 for(
unsigned int it = 0 ; it < gfx -> nb_frames ; it ++ )
145 if( fscanf( data,
"%d %d %d", &gfx -> frames[ it ].x, &gfx -> frames[ it ].y, &gfx -> frames[ it ] . duration ) != 3 )
147 n_log(
LOG_ERR,
"file %s: invalid &gfx -> frames[ %d ].x, &gfx -> frames[ %d ].y, &gfx -> frames[ %d ] . duration !", resfile, it, it, it);
154 lib -> gfxs[ pos ] = gfx ;
170 data -> elapsed += delta_t ;
171 if( data -> elapsed > data -> lib -> gfxs[ data ->
id ] -> frames[ data -> frame ].duration )
173 data -> elapsed = 0 ;
175 if( data -> frame >= data -> lib -> gfxs[ data ->
id ] -> nb_frames )
191 ALLEGRO_BITMAP *bmp = data -> lib -> gfxs[ data -> id ] -> bmp ;
194 unsigned int tilew = data -> lib -> gfxs[ data -> id ] -> w ;
195 unsigned int tileh = data -> lib -> gfxs[ data -> id ] -> h ;
197 int px = data -> lib -> gfxs[ data -> id ] -> frames[ data -> frame ] . x ;
198 int py = data -> lib -> gfxs[ data -> id ] -> frames[ data -> frame ] . y ;
200 unsigned int framex = data -> frame * tilew ;
202 al_draw_bitmap_region( bmp, framex, 0, tilew, tileh, x - px, y - py, 0 );
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.