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 fscanf( data,
"%d", &check_id );
118 if( check_id !=211282 )
120 n_log(
LOG_ERR,
"file %s: invalid check_id of %d, should be 211282", resfile, check_id );
128 fscanf( data,
"%d %d %d", &gfx -> w, &gfx -> h, &gfx -> nb_frames );
132 gfx -> bmp = al_load_bitmap( file );
135 n_log(
LOG_ERR,
"file %s: unable to load image", file );
140 for(
unsigned int it = 0 ; it < gfx -> nb_frames ; it ++ )
142 fscanf( data,
"%d %d %d", &gfx -> frames[ it ].x, &gfx -> frames[ it ].y, &gfx -> frames[ it ] . duration );
146 lib -> gfxs[ pos ] = gfx ;
162 data -> elapsed += delta_t ;
163 if( data -> elapsed > data -> lib -> gfxs[ data ->
id ] -> frames[ data -> frame ].duration )
165 data -> elapsed = 0 ;
167 if( data -> frame >= data -> lib -> gfxs[ data ->
id ] -> nb_frames )
183 ALLEGRO_BITMAP *bmp = data -> lib -> gfxs[ data -> id ] -> bmp ;
186 unsigned int tilew = data -> lib -> gfxs[ data -> id ] -> w ;
187 unsigned int tileh = data -> lib -> gfxs[ data -> id ] -> h ;
189 int px = data -> lib -> gfxs[ data -> id ] -> frames[ data -> frame ] . x ;
190 int py = data -> lib -> gfxs[ data -> id ] -> frames[ data -> frame ] . y ;
192 unsigned int framex = data -> frame * tilew ;
194 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.