diff --git a/SuperCbr.g1a b/SuperCbr.g1a index 2f53826..1a5974e 100644 Binary files a/SuperCbr.g1a and b/SuperCbr.g1a differ diff --git a/include/base.h b/include/base.h index fb9c75b..a773e88 100644 --- a/include/base.h +++ b/include/base.h @@ -9,4 +9,8 @@ int min(const int x, const int y); int sgn(const int x); +void* malloc_prof(int size); + +void free_prof(void * p); + #endif \ No newline at end of file diff --git a/src/base.c b/src/base.c index a28e631..875464c 100644 --- a/src/base.c +++ b/src/base.c @@ -1,4 +1,6 @@ #include +#include +#include int max(const int x, const int y) { @@ -18,4 +20,31 @@ int sgn(const int x) return -1; else return 0; +} + +static int ram_used=0; + +void* malloc_prof(int size) +{ + void* p=malloc(size); + if (p) + { + ll_sendp(LEVEL_INFO, "\n[std] malloc %d OK", size); + ram_used++; + ll_sendp(LEVEL_INFO, "\n[std] number of zones %d", ram_used); + return p; + } + if (p) + { + ll_sendp(LEVEL_CRITICAL, "\n[std] malloc %d FAILED", size); + return p; + } +} + +void free_prof(void * p) +{ + free(p); + ll_sendp(LEVEL_INFO, "\n[std] free called"); + ram_used--; + ll_sendp(LEVEL_INFO, "\n[std] number of zones %d", ram_used); } \ No newline at end of file diff --git a/src/ennemi.c b/src/ennemi.c index 6a2cf7e..9e0ffd4 100644 --- a/src/ennemi.c +++ b/src/ennemi.c @@ -377,18 +377,18 @@ void display_ennemi_table() void init_ennemi(ennemi_t * table, int s) { - ennemis_global_size=s; + ennemis_global_size=0; if (ennemis_global) { - free(ennemis_global); + free_prof(ennemis_global); ennemis_global=0; } - if (0==ennemis_global_size) + if (0==s) return; - int size=sizeof(ennemi_t)*ennemis_global_size; - ennemis_global=malloc(size); + int size=sizeof(ennemi_t)*s; + ennemis_global=malloc_prof(size); if (ennemis_global==0) malloc_error(); - + ennemis_global_size=s; memcpy(ennemis_global, table, size); } \ No newline at end of file diff --git a/src/level.c b/src/level.c index 1aa702c..c096054 100644 --- a/src/level.c +++ b/src/level.c @@ -46,12 +46,10 @@ static uint8_t pack_access(packed_level_t const * const p, unsigned int x, unsig { if (xwidth && yheight) { - ll_sendp(LEVEL_INFO, "\n[i]pack access at %d,%d",x,y); return p->data[x*p->height+y]; } else { - ll_sendp(LEVEL_WARNING, "\n[w]pack access out of range at %d,%d",x,y); return PACKED_EMPTY; } } @@ -70,28 +68,27 @@ static void unpack_level(packed_level_t * p) ll_sendp(LEVEL_INFO, "\nUnpacking level %dx%d", w,h); - cell_t * c = (cell_t *) malloc(sizeof(cell_t) * w * h); + cell_t * c = (cell_t *) malloc_prof(sizeof(cell_t) * w * h); ll_sendp(LEVEL_INFO, "\n[i]malloc %d", sizeof(cell_t) * w * h); if (c==0) { // overriding parameters w = 232;//p->width; h = 13;//p->height; - ll_sendp(LEVEL_CRITICAL, "\n[e]malloc failed !\n[i]Trying defaults:\n %dx%d", w,h); + ll_sendp(LEVEL_CRITICAL, "\n[e]malloc %d failed !\n[i]Trying defaults:\n %dx%d",sizeof(cell_t) * w * h, w,h); ll_sendp(LEVEL_WARNING, "\n[w]writing into pack new coordinates:\n %dx%d", w,h); p->width=w; p->height=h; - cell_t * c = (cell_t *) malloc(sizeof(cell_t) * w * h); + cell_t * c = (cell_t *) malloc_prof(sizeof(cell_t) * w * h); if (c==0) malloc_error(); } - ll_set_level(LEVEL_WARNING); + //ll_set_level(LEVEL_WARNING); int sx=0, sy=p->height; // Mario start coords - ll_sendp(LEVEL_INFO, "\n[i]Converting...", w,h); ennemi_t ennemis[20]={0}; int nombre_ennemis=0; @@ -283,9 +280,8 @@ static void unpack_level(packed_level_t * p) cell = t; } - ll_sendp(LEVEL_INFO, "\n[i]Converted cell %d,%d\n {%d,%p}\n[i]Writing cell...", x,y, cell.type, cell.data); cell_set(c,w,h,x,y,cell); - ll_sendp(LEVEL_INFO, "\n[i]Wrote cell", x,y, cell.type, cell.data); + @@ -318,7 +314,7 @@ static void unpack_level(packed_level_t * p) ll_sendp(LEVEL_INFO, "\n[i]Converted!\n[i]Sending to level zone...", w,h); world_set(w, h, sx, sy, c); ll_sendp(LEVEL_INFO, "\n[i]Achieved unpacking", w,h); - free(c); + free_prof(c); init_ennemi(ennemis, nombre_ennemis); @@ -328,13 +324,9 @@ void set_level(int w, int l) { new_level(); set_teleporteurs(0,0); - if (map_current) - { - free(map_current); - map_current=0; - } - ennemis_global_size=0; - plateforme_table_size=0; + world_set(0,0,0,0,0); + init_ennemi(0, 0); + init_plateformes(0, 0); if (w+1==1 && l+1==1) // 1-2 { diff --git a/src/main.c b/src/main.c index 232bc97..47aab6c 100755 --- a/src/main.c +++ b/src/main.c @@ -28,6 +28,7 @@ int main(void) sleep_ms(3,1200); //gint_panic_set(system_error); ll_set_panic(); + //ll_set_level(LEVEL_QUIET); launch_ui(); diff --git a/src/plateforme.c b/src/plateforme.c index 8631408..fcbe648 100644 --- a/src/plateforme.c +++ b/src/plateforme.c @@ -8,22 +8,11 @@ #include #include #include +#include int plateforme_table_size=0; plateforme_t* plateformes=0; - -static int sgn(int x) -{ - if (x==0) - return 0; - else if (x>0) - return 1; - return -1; -} - - - void reset_plateforme(plateforme_t* p) { p->x=p->xinit; @@ -136,18 +125,18 @@ int plateforme_check_collide(int x, int y) void init_plateformes(plateforme_t * table, int s) { - plateforme_table_size=s; + plateforme_table_size=0; if (plateformes) { - free(plateformes); + free_prof(plateformes); plateformes=0; } if (0==table) return; int size=sizeof(plateforme_t)*plateforme_table_size; - plateformes=malloc(size); + plateformes=malloc_prof(size); if (plateformes==0) malloc_error(); - + plateforme_table_size=s; memcpy(plateformes, table, size); } \ No newline at end of file diff --git a/src/world.c b/src/world.c index d4dc800..6c59306 100755 --- a/src/world.c +++ b/src/world.c @@ -204,19 +204,14 @@ void world_draw() void world_move() { mkb_update(); - ll_sendp(LEVEL_INFO,"\n[I;%d] Refresh wrld",frame_id); for (int i=0; i Moved ennemies"); bonus_move(); - ll_sendp(LEVEL_INFO,"\n > Moved bonus"); bullet_move(); - ll_sendp(LEVEL_INFO,"\n > Moved bullets"); move_plateformes(); mario_move(); - ll_sendp(LEVEL_INFO,"\n > Moved mario !\n"); teleport_active(); } @@ -228,7 +223,10 @@ void world_set(int w, int h, int x, int y, cell_t const * a) // Free the previous map if (map_current) - free(map_current); + { + free_prof(map_current); + map_current=0; + } // If the new map size is null => invalid map, return if (0==w*h) @@ -236,7 +234,7 @@ void world_set(int w, int h, int x, int y, cell_t const * a) // Calculates the new struct size int size= 4*sizeof(int) + sizeof(cell_t)*w*h; - map_current=(map_t*)malloc(size); + map_current=(map_t*)malloc_prof(size); if (map_current==0) malloc_error();