diff options
author | Damien Appert <dappert> | 2010-10-15 18:51:30 +0000 |
---|---|---|
committer | Damien Appert <dappert> | 2010-10-15 18:51:30 +0000 |
commit | 3a1d80b01f27927d43374f7a712d4d51e4db6b15 (patch) | |
tree | bff55a6b4f0b6ed3007ea195902679e82970f542 /sdl-test | |
parent | 00c237f2f55484887aa078bc438d03fa05cbcb7a (diff) | |
download | 2010-netlemmings-3a1d80b01f27927d43374f7a712d4d51e4db6b15.tar.gz 2010-netlemmings-3a1d80b01f27927d43374f7a712d4d51e4db6b15.tar.bz2 2010-netlemmings-3a1d80b01f27927d43374f7a712d4d51e4db6b15.zip |
debug
git-svn-id: file:///var/svn/2010-netlemmings/trunk@100 077b3477-7977-48bd-8428-443f22f7bfda
Diffstat (limited to 'sdl-test')
-rw-r--r-- | sdl-test/SDL_tuto/TestParserLemmingsLVL/Makefile | 2 | ||||
-rw-r--r-- | sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.yy | 509 | ||||
-rwxr-xr-x | sdl-test/SDL_tuto/TestParserLemmingsLVL/test.sh | 10 |
3 files changed, 316 insertions, 205 deletions
diff --git a/sdl-test/SDL_tuto/TestParserLemmingsLVL/Makefile b/sdl-test/SDL_tuto/TestParserLemmingsLVL/Makefile index 15f43e0..e50cd1e 100644 --- a/sdl-test/SDL_tuto/TestParserLemmingsLVL/Makefile +++ b/sdl-test/SDL_tuto/TestParserLemmingsLVL/Makefile @@ -3,7 +3,7 @@ TARGET = main OBJECTS = -CFLAGS = -O3 -Wall -g -I/usr/include/SDL -L/usr/lib +CFLAGS = -Wall -g -I/usr/include/SDL -L/usr/lib LIBS = -lSDL -lSDL_image -lfl CC = gcc diff --git a/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.yy b/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.yy index fbb22e5..82b0495 100644 --- a/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.yy +++ b/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.yy @@ -109,7 +109,9 @@ Uint32 ccc_s = 0xff00ff; - + // error + + Uint32 ccc_error = 0x6666669; // Config Cam @@ -388,35 +390,35 @@ SDL_Surface* flipSurfaceUD_LR(SDL_Surface* src, enum sens sensO, Uint32 c); - void load_fields(char *folder, struct gameInit *gInit, int tabnum[255] ); + int load_fields(char *folder, struct gameInit *gInit, int tabnum[255] ); - void afficher(struct gameInit *gInit); + int afficher(struct gameInit *gInit); - void load_files(struct gameInit *gInit); - - void clean_up(); + int load_files(struct gameInit *gInit); + + int clean_up(); int anim_objet(int typeS, int typeO, int cptFps, int frames, int *cpt, struct gameInit *gInit);// returne le state de l'oblet a afficher Uint32 get_pixel32( int x, int y, SDL_Surface *surface ); - void putPixel(SDL_Surface *surface,Uint16 x,Uint16 y,Uint32 color); + int putPixel(SDL_Surface *surface,Uint16 x,Uint16 y,Uint32 color); - void stateLemming(struct gameInit *gInit, SDL_Surface *s); + int stateLemming(struct gameInit *gInit, SDL_Surface *s); struct listeSimplementChainee* rev_listeO (struct listeSimplementChainee* liste); - void initGame(struct gameInit *gInit); + int initGame(struct gameInit *gInit); - void creationLemming(struct gameInit *gInit); + int creationLemming(struct gameInit *gInit); - void paint_terrain (struct gameInit *gInit, int choix); + int paint_terrain (struct gameInit *gInit, int choix); - void paint_objet (struct gameInit *gInit, int cptFps); + int paint_objet (struct gameInit *gInit, int cptFps); - void supprLem (struct gameInit *gInit, int cptFps); + int supprLem (struct gameInit *gInit, int cptFps); - void paint_lemming (struct gameInit *gInit, int cptFps); + int paint_lemming (struct gameInit *gInit, int cptFps); int test_O_UD(int UD); @@ -424,31 +426,28 @@ Uint32* tab_of_string_to_Uint32 (char* c, int taille); - void paint_letters (char* text); + int paint_letters (char* text); - void findTerrain( struct gameInit *gInit,int x, int y, int x0); + int findTerrain( struct gameInit *gInit,int x, int y, int x0); - void paint_cursor(SDL_Surface *dst1,SDL_Surface *dst2, SDL_Surface *src, int x, int y, int x0, struct gameInit *gInit); + int paint_cursor(SDL_Surface *dst1,SDL_Surface *dst2, SDL_Surface *src, int x, int y, int x0, struct gameInit *gInit); - void print_num(SDL_Surface *dst, SDL_Surface *font, int x, int y, int value); + int print_num(SDL_Surface *dst, SDL_Surface *font, int x, int y, int value); - void print_alpha(SDL_Surface *dst, SDL_Surface *src, int x, int y, char* msg); + int print_alpha(SDL_Surface *dst, SDL_Surface *src, int x, int y, char* msg); - void testAlpha(SDL_Surface *dst, SDL_Surface *src,SDL_Surface *src2, int x, int y); + int testAlpha(SDL_Surface *dst, SDL_Surface *src,SDL_Surface *src2, int x, int y); - void legende (struct gameInit *gInit); + int legende (struct gameInit *gInit); - void paint_interface(struct gameInit *gInit); + int paint_interface(struct gameInit *gInit); - void giveSkill (struct gameInit *gInit, struct listeSimplementChainee* k, int skill ); + int giveSkill (struct gameInit *gInit, struct listeSimplementChainee* k, int skill ); - void mouse_action (struct gameInit *gInit, int x, int y, int camX , int camY); + int mouse_action (struct gameInit *gInit, int x, int y, int camX , int camY); int lancement(); - // SPRITES - //void animeGif(SDL_Surface objet,, ); - int paint_stencil=0; %} @@ -525,7 +524,7 @@ if(res!=99){ gInit->mapI.map.superLemming=res; } else { - printf("superlemming value invalid: %d %s\n",res,$3->ptr.str);exit(99); + printf("superlemming value invalid: %d %s\n",res,$3->ptr.str);return(3); } } | BGCOLOR AFF val { @@ -626,7 +625,7 @@ if(strncmp($1,"frames_",7) == 0){ state=6; // 1ER CAS - if(gInit->mapI.map.tilesObjet == 0){printf("ERREUR: tilesObjet == 0 => exit to prevent a segFault\n");exit(66);}; + if(gInit->mapI.map.tilesObjet == 0){printf("ERREUR: tilesObjet == 0 => exit to prevent a segFault\n");exit(4);}; if(gInit->mapI.map.tabDataSprO == NULL){ gInit->mapI.map.tabDataSprO= malloc((sizeof(struct spriteObjet))*(gInit->mapI.map.tilesObjet)); gInit->cptGame[15] = -1; @@ -654,7 +653,7 @@ state=10; if($3->ptr.ints->val!=gInit->mapI.map.tiles){ printf("BUG: variable parse && nbrFichier are different\n"); - exit(86); + return(5); } //gInit->mapI.map.tiles=$3->ptr.ints->val; } @@ -753,7 +752,7 @@ case 22: gInit->mapI.lemmingDATA[gInit->cptGame[15]].imask->stateI=curr->val;break; case 23: gInit->mapI.lemmingDATA[gInit->cptGame[15]].imask->dirI=curr->val;break; // en cas de BUG - default: printf("BUG parser i = %d\n",i);exit(6); + default: printf("BUG parser i = %d\n",i);exit(7); } curr=curr->next; ++i; @@ -768,7 +767,7 @@ if(state == 0) { printf("BUG: no parse for this token : %s \n",$1); - exit(6); + exit(8); } } } // FIN ok==0 @@ -805,7 +804,7 @@ void yyerror(struct gameInit *gInit, char *s) { //fprintf(stderr, "Syntax Error : '%s' at l%d,c%d-l%d,c%d\n", s, @$.first_column, @$.last_line, @$.last_column); // Nécessite l'option %locations et un lexer qui va bien fprintf(stderr, "(stdin):%i: error: %s\n", yylineno, s); - exit(1); + exit(9); } Uint32 string_to_Uint32 (char* c,int taille){ @@ -814,7 +813,7 @@ Uint32 string_to_Uint32 (char* c,int taille){ int i,n,lc = strlen(c); int t[taille]; if(lc-3 != taille){ - printf("ERREUR: wrong format .. expect (strlen[%s] - 3)==%d but it's = %d\n",c,taille,lc-3);exit(54); + printf("ERREUR: wrong format .. expect (strlen[%s] - 3)==%d but it's = %d\n",c,taille,lc-3);return(10); } u32c = 0; for(i=0;i<taille;++i){ @@ -924,7 +923,7 @@ int anim_objet(int typeS, int typeO, int cptFps, int frames, int *cpt, struct g f=(frames-1); } break; - default : printf("BUG typeSprite : %d\n",typeS); exit(89); + default : printf("BUG typeSprite : %d\n",typeS); exit(11); } /* switch(typeO){ @@ -936,7 +935,7 @@ int anim_objet(int typeS, int typeO, int cptFps, int frames, int *cpt, struct g case 7 : f=cptFps%(frames);break;//FIXME case 8 : f=cptFps%(frames);break;//FIXME case 32 : f=cptFps%(frames);break;//FIXME - default : printf("BUG typeObjet : %d\n",type0); exit(89); + default : printf("BUG typeObjet : %d\n",type0); return(12); } }*/ /* # animation types @@ -961,31 +960,42 @@ Uint32 get_pixel32( int x, int y, SDL_Surface *surface ) { //Convertie les pixels en 32 bit Uint32 *pixels = (Uint32 *)surface->pixels; - // printf("4) x=%d,y=%d,p =%X\n",x,y,pixels[ ( y * surface->w ) + x ]); + //printf("4) x=%d,y=%d,p =%X\n",x,y,pixels[ ( y * surface->w ) + x ]); //Recupere le pixel demande - if((((y * surface->w ) + x) > surface->h*surface->w)|| + /*printf("out get_pixel32 !! => (((y %d * surface->w %d ) + x %d) => %d >= surface->h %d *surface->w %d = %d)\n",y,surface->w,x,(y * surface->w ) + x,surface->h,surface->w,surface->h*surface->w);*/ + if ( surface==NULL ) { printf("ludo1\n"); exit(42); } + if ( pixels==NULL ) { + printf("ludo2\n"); + exit(42); } + + if((((y * surface->w ) + x) >= surface->h*surface->w)|| (((y * surface->w ) + x) < 0)){ - printf("out get_pixel32 !! => (((y %d * surface->w %d ) + x %d) => %d > surface->h %d *surface->w %d = %d)\n",y,surface->w,x,(y * surface->w ) + x,surface->h,surface->w,surface->h*surface->w); - exit (65); + if(y==surface->h){printf("get C'EST PAS ASSEZ GROS POUR TOI !!!! y=surface->h\n"); + return (ccc_error);} + printf("out get_pixel32 !! => (((y %d * surface->w %d ) + x %d) => %d >= surface->h %d *surface->w %d = %d)\n",y,surface->w,x,(y * surface->w ) + x,surface->h,surface->w,surface->h*surface->w); + return (ccc_error); } + return pixels[ ( y * surface->w ) + x ]; } -void putPixel(SDL_Surface *surface,Uint16 x,Uint16 y,Uint32 colori) +int putPixel(SDL_Surface *surface,Uint16 x,Uint16 y,Uint32 colori) { /* bpp de la surface ecran */ Uint8 bpp = surface->format->BytesPerPixel; /* pointeur vers le pixel a remplacer */ - if((((y * surface->w ) + x) > surface->h*surface->w)|| + if((((y * surface->w ) + x) >= surface->h*surface->w)|| (((y * surface->w ) + x) < 0)){ - printf("out putPixel !! => (((y %d * surface->w %d ) + x %d) => %d > surface->h %d *surface->w %d = %d)\n",y,surface->w,x,(y * surface->w ) + x,surface->h,surface->w,surface->h*surface->w); - exit (65); + if(y==surface->h){printf("put C'EST PAS ASSEZ GROS POUR TOI !!!! y=surface->h\n"); + return (ccc_error);} + printf("out putPixel !! => (((y %d * surface->w %d ) + x %d) => %d >= surface->h %d *surface->w %d = %d)\n",y,surface->w,x,(y * surface->w ) + x,surface->h,surface->w,surface->h*surface->w); + return (14); } - + Uint8 *p = ((Uint8 *)surface->pixels) + y * surface->pitch + x * bpp; /*printf("pixel R = %X G = %X B = %X A=%X bpp = %d, ccc=%X \n", @@ -1021,10 +1031,10 @@ void putPixel(SDL_Surface *surface,Uint16 x,Uint16 y,Uint32 colori) } break; } - + return 0; } -void stateLemming(struct gameInit *gInit, SDL_Surface *surf ){ +int stateLemming(struct gameInit *gInit, SDL_Surface *surf ){ struct listeSimplementChainee *unl; struct listeSimplementChainee *k; @@ -1260,6 +1270,7 @@ void stateLemming(struct gameInit *gInit, SDL_Surface *surf ){ // test pixel under lemming foot // floater ? + if(get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] , surf ) == ccc_error ) {return (101);} if ((step==0)&& (unl->data.pl->cptFall >= FLOATER_TO_FALLER )&& (unl->data.pl->floater == 1) && @@ -1272,6 +1283,7 @@ void stateLemming(struct gameInit *gInit, SDL_Surface *surf ){ unl->ID=4; unl->y += 1; for(i=1;i<MAX_LEM_FALL_FLOATER;++i){ + if(get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] + i , surf ) == ccc_error ) {return (102);} if (get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] + i , surf ) == gInit->mapI.map.cmap.bgColor ) { unl->y += 1; @@ -1282,6 +1294,7 @@ void stateLemming(struct gameInit *gInit, SDL_Surface *surf ){ } // splat ? + if(get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] , surf ) == ccc_error ) {return (103);} if ((step==0)&& (unl->data.pl->cptFall >= FALLER_MAX )&& (get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] , surf ) != gInit->mapI.map.cmap.bgColor )){ @@ -1295,12 +1308,14 @@ void stateLemming(struct gameInit *gInit, SDL_Surface *surf ){ } // faller ? + if(get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] , surf ) == ccc_error ) {return (104);} if ((unl->ID!=4)&&(step==0)&&(get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] , surf ) == gInit->mapI.map.cmap.bgColor )){ // tombe: unl->ID=1; unl->y += 1; unl->data.pl->cptFall +=1; for(i=1;i<MAX_LEM_FALL;++i){ + if(get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] + i , surf ) == ccc_error ) {return (105);} if (get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] + i , surf ) == gInit->mapI.map.cmap.bgColor ) { unl->y += 1; @@ -1312,6 +1327,7 @@ void stateLemming(struct gameInit *gInit, SDL_Surface *surf ){ // walker collision + if(get_pixel32( pixCtrlLem[0][2] , pixCtrlLem[1][2] , surf ) == ccc_error ) {return (106);} if ((step==0)&&(get_pixel32( pixCtrlLem[0][2] , pixCtrlLem[1][2] , surf ) != gInit->mapI.map.cmap.bgColor )){ if(unl->data.pl->cptJump > MAX_JUMPER_STEP){ @@ -1334,6 +1350,7 @@ void stateLemming(struct gameInit *gInit, SDL_Surface *surf ){ // walker //printf("val pix test IN %d x=%d, y=%d\n",get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] , surf ),pixCtrlLem[0][0],pixCtrlLem[1][0]); + if(get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] , surf ) == ccc_error ) {return (107);} if ((step==0)&&(get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] , surf ) != gInit->mapI.map.cmap.bgColor )){ // marche: if(unl->ID==1){unl->y-=2;}//FIXME @@ -1363,17 +1380,17 @@ void stateLemming(struct gameInit *gInit, SDL_Surface *surf ){ } - return; + return 0; } -void print_num(SDL_Surface *dst, SDL_Surface *src, int x, int y, int value) +int print_num(SDL_Surface *dst, SDL_Surface *src, int x, int y, int value) { char buf[9]; int i,r,v,p=0; int max = 1000000000; SDL_Rect from; if(value >= 10000000000){ - printf("value out of Bound %d\n",value);exit(35); + printf("value out of Bound %d\n",value);return(15); } v=value; @@ -1400,10 +1417,11 @@ void print_num(SDL_Surface *dst, SDL_Surface *src, int x, int y, int value) from.y = buf[i] * (from.h); SDL_BlitSurface(src, &from, dst, &to); } + return 0; } -void testAlpha(SDL_Surface *dst, SDL_Surface *src,SDL_Surface *src2, int x, int y){ +int testAlpha(SDL_Surface *dst, SDL_Surface *src,SDL_Surface *src2, int x, int y){ SDL_Rect from; SDL_Rect to; int i; @@ -1421,10 +1439,11 @@ void testAlpha(SDL_Surface *dst, SDL_Surface *src,SDL_Surface *src2, int x, int //print_num(screen, src2, to.x + 20, to.y, i); } + return 0; } -void print_alpha(SDL_Surface *dst, SDL_Surface *src, int x, int y, char* msg) +int print_alpha(SDL_Surface *dst, SDL_Surface *src, int x, int y, char* msg) { SDL_Rect from; SDL_Rect to; @@ -1448,6 +1467,7 @@ void print_alpha(SDL_Surface *dst, SDL_Surface *src, int x, int y, char* msg) SDL_BlitSurface(src, &from, dst, &to); } } + return 0; } @@ -1457,7 +1477,7 @@ int init() //Initialisation de tous les sous-systèmes de SDL if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) { - return 1; + return 90; } //Mise en place de l'écran @@ -1585,7 +1605,7 @@ SDL_Surface *load_image( char* filename, Uint32 cbg ) } -void load_fields(char *folder, struct gameInit *gInit, int tabNum[255] ) { +int load_fields(char *folder, struct gameInit *gInit, int tabNum[255] ) { int i, lt,total,cpt=-1,llem; char *temp; char *filepath; @@ -1614,7 +1634,7 @@ void load_fields(char *folder, struct gameInit *gInit, int tabNum[255] ) { gInit->mapI.map.tabGif[i+1+cpt] = flipSurfaceUD_LR(load_image(filepath,ccc_terrain),UD,ccc_terrain); if((gInit->mapI.map.tabGif[i+cpt] == NULL)||(gInit->mapI.map.tabGif[i+1+cpt] == NULL)) { printf("ERREUR load_file Objet: %s\n", filepath); - exit(17); + return(16); } else { //printf("load_file ok : %i -> '%s' + flip_LR\n", i+cpt, filepath); } @@ -1631,7 +1651,7 @@ void load_fields(char *folder, struct gameInit *gInit, int tabNum[255] ) { gInit->mapI.map.tabGif[i+1+cpt] = flipSurfaceUD_LR(load_image(filepath,ccc_objet),UD,ccc_objet); if((gInit->mapI.map.tabGif[i+cpt] == NULL)||(gInit->mapI.map.tabGif[i+1+cpt] == NULL)) { printf("ERREUR load_file Objet: %s\n", filepath); - exit(17); + return(17); } else { //printf("load_file ok : %i -> '%s' + flip_LR\n", i+cpt, filepath); } @@ -1647,7 +1667,7 @@ void load_fields(char *folder, struct gameInit *gInit, int tabNum[255] ) { gInit->mapI.map.tabGif[i+cpt] = load_image(filepath,ccc_steel); if(gInit->mapI.map.tabGif[i+cpt] == NULL) { printf("ERREUR load_file steel: %s\n", filepath); - exit(17); + return(18); } else { //printf("load_file ok : %i -> '%s'\n", i+cpt, filepath); } @@ -1664,7 +1684,7 @@ void load_fields(char *folder, struct gameInit *gInit, int tabNum[255] ) { gInit->mapI.map.tabGif[i+cpt] = flipSurfaceUD_LR(load_image(filepath,ccc_lemming),LR,ccc_lemming); if((gInit->mapI.map.tabGif[i+cpt] == NULL)||(gInit->mapI.map.tabGif[i+1+cpt] == NULL)) { printf("ERREUR load_file lemmingsDATA: %s\n", filepath); - exit(17); + return(19); } else { //printf("load_file ok : %i -> '%s' + flip_LR\n", i+cpt, filepath); } @@ -1674,61 +1694,61 @@ void load_fields(char *folder, struct gameInit *gInit, int tabNum[255] ) { gInit->mapI.map.tabGif[0]= load_image("../../../misc/lemmfont.gif",gInit->mapI.map.cmap.bgColor); if ( gInit->mapI.map.tabGif[0] == NULL ) { printf("ERREUR load_file lemmfont.gif: %s\n", "../../../misc/lemmfont.gif"); - exit(17); + return(20); } //1: numfont.gif gInit->mapI.map.tabGif[1]= load_image("../../../misc/numfont.gif",gInit->mapI.map.cmap.bgColor); if ( gInit->mapI.map.tabGif[1] == NULL ) { printf("ERREUR load_file numfont.gif: %s\n", "../../../misc/numfont.gif"); - exit(17); + return(21); } //2: countdown.gif gInit->mapI.map.tabGif[2]= load_image("../../../misc/countdown.gif",gInit->mapI.map.cmap.bgColor); if ( gInit->mapI.map.tabGif[2] == NULL ) { printf("ERREUR load_file countdown.gif: %s\n", "../../../misc/countdown.gif"); - exit(17); + return(22); } //3: cursor.gif gInit->mapI.map.tabGif[3]= load_image("../../../misc/cursor.gif",ccc_cursor);//gInit->mapI.map.cmap.bgColor); if ( gInit->mapI.map.tabGif[3] == NULL ) { printf("ERREUR load_file cursor.gif: %s\n", "../../../misc/cursor.gif"); - exit(17); + return(23); } //4: explode.gif gInit->mapI.map.tabGif[4]= load_image("../../../misc/explode.gif",gInit->mapI.map.cmap.bgColor); if ( gInit->mapI.map.tabGif[4] == NULL ) { printf("ERREUR load_file explode.gif: %s\n", "../../../misc/explode.gif"); - exit(17); + return(24); } //5: border.gif gInit->mapI.map.tabGif[5]= load_image("../../../misc/border.gif",gInit->mapI.map.cmap.bgColor); if ( gInit->mapI.map.tabGif[5] == NULL ) { printf("ERREUR load_file border.gif: %s\n", "../../../misc/border.gif"); - exit(17); + return(25); } //6: replay.gif gInit->mapI.map.tabGif[6]= load_image("../../../misc/replay.gif",gInit->mapI.map.cmap.bgColor); if ( gInit->mapI.map.tabGif[6] == NULL ) { printf("ERREUR load_file replay.gif: %s\n", "../../../misc/replay.gif"); - exit(17); + return(26); } //7: select.gif gInit->mapI.map.tabGif[7]= load_image("../../../misc/select.gif",gInit->mapI.map.cmap.bgColor); if ( gInit->mapI.map.tabGif[7] == NULL ) { printf("ERREUR load_file select.gif: %s\n", "../../../misc/select.gif"); - exit(17); + return(27); } // 8: font7x10.bmp gInit->mapI.map.tabGif[8]= load_image("./font7x10.bmp",gInit->mapI.map.cmap.bgColor); if ( gInit->mapI.map.tabGif[8] == NULL ) { printf("ERREUR load_file font7x10.bmp: %s\n", "./font7x10.bmp"); - exit(17); + return(28); } // 9: alphabet.gif gInit->mapI.map.tabGif[9]= load_image("./alphabet.gif",ccc_cursor); if ( gInit->mapI.map.tabGif[9] == NULL ) { printf("ERREUR load_file alphabet.gif: %s\n", "./alphabet.gif"); - exit(17); + return(29); } //icone.gif cpt=NBR_ADD_OBJ; @@ -1742,19 +1762,22 @@ void load_fields(char *folder, struct gameInit *gInit, int tabNum[255] ) { gInit->mapI.map.tabGif[i+cpt] = load_image(filepath,ccc_icon); if(gInit->mapI.map.tabGif[i+cpt] == NULL) { printf("ERREUR load_file icon: %s\n", filepath); - exit(17); + return(30); } else { //printf("load_file ok : %i -> '%s' + flip_LR\n", i+cpt, filepath); } } free(filepath); free(folderLem); + + return 0; } -void load_files(struct gameInit *gInit) +int load_files(struct gameInit *gInit) { int lt,ltt,ltlem; + int err=0; int res, lterrain, lobjet, lsteel; char *folder; char *spriteINI; @@ -1805,7 +1828,7 @@ void load_files(struct gameInit *gInit) rep = opendir(folder); if (rep==NULL) { printf("Erreur opendir('%s')\n", folder); - exit(9); + return(31); } while ((lecture = readdir(rep))) { @@ -1831,7 +1854,7 @@ void load_files(struct gameInit *gInit) yyin=fopen(spriteINI, "r"); if (yyin==NULL) { fprintf(stderr,"Filename INVALIDE: %s\n",spriteINI); - perror("Impossible d'ouvrir le fichier de configuration des sprite"); exit(42); + perror("Impossible d'ouvrir le fichier de configuration des sprite"); return(32); } yyparse(gInit); fclose(yyin); @@ -1839,13 +1862,14 @@ void load_files(struct gameInit *gInit) yyin=fopen(lemINI, "r"); if (yyin==NULL) { fprintf(stderr,"Filename INVALIDE: %s\n",lemINI); - perror("Impossible d'ouvrir le fichier de configuration des lemmings"); exit(42); + perror("Impossible d'ouvrir le fichier de configuration des lemmings"); return(33); } yyparse(gInit); fclose(yyin); printf("CLOSE 3\n"); - load_fields(folder, gInit, tabNum); + err=load_fields(folder, gInit, tabNum); + if(err!=0){return err;} //printf("REVERSE t.lt\n"); gInit->t.lt=(struct listeSimplementChainee*)rev_listeO(gInit->t.lt); @@ -1855,7 +1879,8 @@ void load_files(struct gameInit *gInit) gInit->s.ls=(struct listeSimplementChainee*)rev_listeO(gInit->s.ls); // AFFICHAGE DES INFOS DE LA MAP - afficher(gInit); + err=afficher(gInit); + if(err!=0){return err;} //Si tout s'est bien passé free(terrainGif); @@ -1864,9 +1889,11 @@ void load_files(struct gameInit *gInit) free(folder); free(spriteINI); free(lemINI); + + return 0; } -void afficher(struct gameInit *gInit){ +int afficher(struct gameInit *gInit){ int i; struct listeSimplementChainee *k; @@ -1903,7 +1930,7 @@ void afficher(struct gameInit *gInit){ k=gInit->t.lt; i=0; while ( k !=NULL ) { - if(k->data.pt != NULL){//{printf("paraTerrain non initialiser\n");exit(32);} + if(k->data.pt != NULL){//{printf("paraTerrain non initialiser\n");return(34);} printf("\tterrain_%d = %d, %d, %d, %d\n",i,k->ID, k->x, k->y,k->data.pt->modif); } ++i; @@ -1915,7 +1942,7 @@ void afficher(struct gameInit *gInit){ k=gInit->o.lo; i=0; while ( k !=NULL ) { - if(k->data.po != NULL){ //{printf("paraObjet non initialiser\n");exit(32);} + if(k->data.po != NULL){ //{printf("paraObjet non initialiser\n");return(35);} printf("\tobject_%d = %d, %d, %d, %d, %d\n",i,k->ID, k->x, k->y, k->data.po->paintMode,k->data.po->UD); } ++i; @@ -1927,7 +1954,7 @@ void afficher(struct gameInit *gInit){ k=gInit->s.ls; i=0; while ( k !=NULL ) { - if(k->data.ps != NULL){//{printf("paraSteel non initialiser\n");exit(32);} + if(k->data.ps != NULL){//{printf("paraSteel non initialiser\n");return(36);} printf("\tsteel_%d = %d, %d, %d, %d, %d\n",i,k->ID=i, k->x, k->y, k->data.ps->w,k->data.ps->h); // FIXME big fuck here with "=" } ++i; @@ -1951,18 +1978,21 @@ void afficher(struct gameInit *gInit){ printf("\timask_%d = %d , %d\n",i,gInit->mapI.lemmingDATA[i].imask->stateI,gInit->mapI.lemmingDATA[i].imask->dirI); } } + return 0; } -void clean_up() +int clean_up() { //On libère la feuille de sprites // SDL_FreeSurface( faces ); SDL_FreeSurface( pTerrain ); //On quitte SDL SDL_Quit(); + + return 0; } -void initGame(struct gameInit *gInit){ +int initGame(struct gameInit *gInit){ int i; @@ -2013,6 +2043,7 @@ void initGame(struct gameInit *gInit){ // lemmingJobAndSprite gInit->mapI.lemmingDATA=NULL; + return 0; } int test_O_UD(int UD){ @@ -2027,7 +2058,7 @@ int test_O_UD(int UD){ return 0; } -void creationLemming(struct gameInit *gInit){ +int creationLemming(struct gameInit *gInit){ int nbLem; struct listeSimplementChainee *k=NULL; struct listeSimplementChainee *kTemp=NULL; @@ -2047,7 +2078,7 @@ void creationLemming(struct gameInit *gInit){ if(gInit->mapI.nbrEntry==0){ printf("ERREUR ALGO: nbrEntry == 0\n"); - exit(43); + return(37); } @@ -2064,13 +2095,13 @@ void creationLemming(struct gameInit *gInit){ coorE[i][1]=k->y; ++i; if(i>=gInit->mapI.nbrEntry){break;} - if(i>9){printf("ERREUR: too many entry\n");exit(23);} + if(i>9){printf("ERREUR: too many entry\n");return(38);} } k=k->next; } if(k == NULL){ printf("BUG: NO ENTRY IN THIS LEVEL ...\n"); - exit(23); + return(39); } gInit->l.ll->x=coorE[0][0]; gInit->l.ll->y=coorE[0][1]; @@ -2131,16 +2162,18 @@ void creationLemming(struct gameInit *gInit){ //printf("REVERSE l.ll\n"); gInit->l.ll=(struct listeSimplementChainee*)rev_listeO(gInit->l.ll); + return 0; } -void paint_terrain (struct gameInit *gInit, int choix){ +int paint_terrain (struct gameInit *gInit, int choix){ struct listeSimplementChainee *k=NULL; SDL_Rect offset; SDL_Surface *sf; + int err=0; int overwrite=0; int remove=0; int paint=0; - int tx,ty=0,tybis; + int tx,ty=0; int cpt=0; int ok=0; Uint32 color; @@ -2163,26 +2196,27 @@ void paint_terrain (struct gameInit *gInit, int choix){ (k->data.pt->modif != 14) ) { printf("WTF ... k->data.pt->modif == %d\n",k->data.pt->modif); - exit(34); + return(40); } - for(tybis=0;tybis<sf->h;++tybis){ - ty =k->y+tybis; //((k->data.pt->modif & 4) == 4)? k->y-tybis : k->y+tybis; - if(ty<0) {continue;} - if(ty>pTerrain->h){continue;} - for(tx=k->x;tx<sf->w+k->x;++tx){ - if(tx<0) {continue;} - if(tx>pTerrain->w){continue;} + for(ty=k->y;ty<sf->h+k->y;++ty){ + if(ty<0) {continue;} + if(ty>=pTerrain->h){continue;} + for(tx=k->x;tx<sf->w+k->x;++tx){ + if(tx<0) {continue;} + if(tx>=pTerrain->w){continue;} overwrite = ((k->data.pt->modif & 8) == 8)? 0 : 1; remove = ((k->data.pt->modif & 2) == 2)? 1 : 0; + color = get_pixel32(tx-k->x,ty-k->y,sf); - + if(color==ccc_error){return 666;} if (color == ccc_black) { //putPixel(pStencil,tx,ty , ccc_tEmpty ); continue; } paint=0; if(!overwrite){ + if((get_pixel32(tx,ty,pStencil)==ccc_error)){return 667;} // don't overwrite -> only paint if background is transparent if(((get_pixel32(tx,ty,pStencil)>>24) & 0xff ) == 0) {// ccc_tEmpty){ @@ -2190,8 +2224,10 @@ void paint_terrain (struct gameInit *gInit, int choix){ } } else if(remove){ // if(((get_pixel32(tx,ty,pStencil)) & ccc_tFull) != 0){ - putPixel(pTerrain,tx,ty , gInit->mapI.map.cmap.bgColor); - putPixel(pStencil,tx,ty , ccc_tRemove );//ccc_tEmpty); + err=putPixel(pTerrain,tx,ty , gInit->mapI.map.cmap.bgColor); + if(err!=0){return err;} + err=putPixel(pStencil,tx,ty , ccc_tRemove );//ccc_tEmpty); + if(err!=0){return err;} // } } else { @@ -2201,15 +2237,21 @@ void paint_terrain (struct gameInit *gInit, int choix){ if(paint==1){ if(!overwrite){ if(!remove){ - putPixel(pTerrain,tx,ty ,color); - putPixel(pStencil,tx,ty , ccc_tNoOverwrite );//ccc_tBrick); + err=putPixel(pTerrain,tx,ty ,color); + if(err!=0){return err;} + err=putPixel(pStencil,tx,ty , ccc_tNoOverwrite );//ccc_tBrick); + if(err!=0){return err;} } else { - putPixel(pTerrain,tx,ty ,color); - putPixel(pStencil,tx,ty , ccc_tRemoveNoOverwrite );//ccc_tBrick); + err=putPixel(pTerrain,tx,ty ,color); + if(err!=0){return err;} + err=putPixel(pStencil,tx,ty , ccc_tRemoveNoOverwrite );//ccc_tBrick); + if(err!=0){return err;} } } else { - putPixel(pTerrain,tx,ty ,color); - putPixel(pStencil,tx,ty , ccc_tFull );//ccc_tBrick); + err=putPixel(pTerrain,tx,ty ,color); + if(err!=0){return err;} + err=putPixel(pStencil,tx,ty , ccc_tFull );//ccc_tBrick); + if(err!=0){return err;} } } }//fin tx @@ -2230,8 +2272,7 @@ void paint_terrain (struct gameInit *gInit, int choix){ offset.w = k->data.ps->w; offset.h = k->data.ps->h; - for(tybis=0;tybis<offset.h;++tybis){ - ty =k->y+tybis; //((k->data.pt->modif & 4) == 4)? k->y-tybis : k->y+tybis; + for(ty=k->y;ty<offset.h+k->y;++ty){ if(ty<0) {continue;} if(ty>pTerrain->h){continue;} for(tx=k->x;tx<offset.w+k->x;++tx){ @@ -2239,10 +2280,12 @@ void paint_terrain (struct gameInit *gInit, int choix){ if(tx>pTerrain->w){continue;} color = get_pixel32(tx,ty,pStencil); + if(color==ccc_error){return 668;} if (color == ccc_black){ continue; } else { - putPixel(pStencil,tx,ty , ccc_s ); + err=putPixel(pStencil,tx,ty , ccc_s ); + if(err!=0){return err;} } } } @@ -2251,14 +2294,15 @@ void paint_terrain (struct gameInit *gInit, int choix){ } //} - + return 0; } -void paint_objet (struct gameInit *gInit, int cptFps){ +int paint_objet (struct gameInit *gInit, int cptFps){ SDL_Rect offset,objetAnim,rStencil; SDL_Surface *sf; struct listeSimplementChainee *k=NULL; int res; + int err=0; int type=0; int ox,oy; int mode=0; @@ -2336,6 +2380,9 @@ void paint_objet (struct gameInit *gInit, int cptFps){ color = get_pixel32(ox,oy,pStencil); color2 = get_pixel32(objetAnim.x+ox-k->x,objetAnim.y+oy-k->y,sf); color3 = get_pixel32(ox,oy,pTerrain); + if(color==ccc_error){return 669;} + if(color2==ccc_error){return 670;} + if(color3==ccc_error){return 671;} // pixel transparency in object.gif if(color2!=ccc_vide){ if(mode==8){ @@ -2343,14 +2390,16 @@ void paint_objet (struct gameInit *gInit, int cptFps){ if(color3==gInit->mapI.map.cmap.bgColor){ continue; } - putPixel(pSpr_Lem,ox,oy,color2); + err=putPixel(pSpr_Lem,ox,oy,color2); + if(err!=0){return err;} } if(mode==4){ // NO_OVERWRITE if(color3!=gInit->mapI.map.cmap.bgColor){ continue; } - putPixel(pSpr_Lem,ox,oy,color2); + err=putPixel(pSpr_Lem,ox,oy,color2); + if(err!=0){return err;} } } else {// utile pour affiner les formes sur le pStencil if((k->ID!=3)&&(k->ID!=4)){continue;} @@ -2363,22 +2412,31 @@ void paint_objet (struct gameInit *gInit, int cptFps){ switch(type){ case 0://passive - putPixel(pStencil, ox,oy, ccc_oPassive);break; + err=putPixel(pStencil, ox,oy, ccc_oPassive); + if(err!=0){return err;} break; case 3://no digging to the left - putPixel(pStencil, ox,oy, ccc_oNoDigLeft);break; + err=putPixel(pStencil, ox,oy, ccc_oNoDigLeft); + if(err!=0){return err;} break; case 4://no digging to the right - putPixel(pStencil, ox,oy, ccc_oNoDigRight);break; + err=putPixel(pStencil, ox,oy, ccc_oNoDigRight); + if(err!=0){return err;}break; case 5://trap which makes lemmings drown (water/quick sand/mud) - putPixel(pStencil, ox,oy, ccc_oTrapDrown);break; + err=putPixel(pStencil, ox,oy, ccc_oTrapDrown); + if(err!=0){return err;} break; case 6://trap which replaces lemming with death animation - putPixel(pStencil, ox,oy, ccc_oTrapAndNoLem);break; + err=putPixel(pStencil, ox,oy, ccc_oTrapAndNoLem); + if(err!=0){return err;} break; case 7://trap which triggers lemming death animation - putPixel(pStencil, ox,oy, ccc_oTrapAndLem);break; + err=putPixel(pStencil, ox,oy, ccc_oTrapAndLem); + if(err!=0){return err;} break; case 8://exit - putPixel(pStencil, ox,oy, ccc_oExit);break; + err=putPixel(pStencil, ox,oy, ccc_oExit); + if(err!=0){return err;} break; case 32://entry - putPixel(pStencil, ox,oy, ccc_oEntry);break; - default:putPixel(pStencil, ox,oy, ccc_oUnknow);break; + err=putPixel(pStencil, ox,oy, ccc_oEntry); + if(err!=0){return err;} break; + default:err=putPixel(pStencil, ox,oy, ccc_oUnknow); + if(err!=0){return err;} break; } // if ((res=SDL_BlitSurface(sf, &objetAnim, pSpr_Lem, &offset)) != 0) @@ -2392,17 +2450,17 @@ void paint_objet (struct gameInit *gInit, int cptFps){ k=k->next; } ///FIN TEST: SPR + return 0; +} - } - - void paint_lemming (struct gameInit *gInit, int cptFps){ +int paint_lemming (struct gameInit *gInit, int cptFps){ //DEBUT TEST: LEM SDL_Rect offset,objetAnim; SDL_Surface *sf; struct listeSimplementChainee *k=NULL; int res; - + int err=0; k=gInit->l.ll; while ( k !=NULL ) { @@ -2426,7 +2484,7 @@ void paint_objet (struct gameInit *gInit, int cptFps){ ((gInit->l.nbrInput-(gInit->l.nbr + gInit->l.nbrDied + gInit->l.nbrSafe))>0)&& (cptFps>(gInit->cptGame[15]+(8 + 99 - gInit->mapI.paraMap[0]))) ){ - printf("ERREUR cptFps %d > gInit->cptGame[15] %d + (8 + 99 - gInit->mapI.paraMap[0] %d) => res = %d\n",cptFps,gInit->cptGame[15],gInit->mapI.paraMap[0],cptFps-(gInit->cptGame[15]+(8 + 99 - gInit->mapI.paraMap[0]))); exit(87); + printf("ERREUR cptFps %d > gInit->cptGame[15] %d + (8 + 99 - gInit->mapI.paraMap[0] %d) => res = %d\n",cptFps,gInit->cptGame[15],gInit->mapI.paraMap[0],cptFps-(gInit->cptGame[15]+(8 + 99 - gInit->mapI.paraMap[0]))); return(41); }*/ if( (k->ID==18)&& @@ -2457,10 +2515,14 @@ void paint_objet (struct gameInit *gInit, int cptFps){ k=k->next; } ///FIN TEST: LEM - stateLemming(gInit,pTerrain); + err=stateLemming(gInit,pTerrain); + if(err==156){printf("here\n");return 3453;} + if(err!=0){return err;} + + return 0; } - void giveSkill (struct gameInit *gInit, struct listeSimplementChainee* k, int skill ){ + int giveSkill (struct gameInit *gInit, struct listeSimplementChainee* k, int skill ){ switch(skill){ //climber @@ -2500,14 +2562,15 @@ void paint_objet (struct gameInit *gInit, int cptFps){ } - return ; + return 0; } - void findTerrain( struct gameInit *gInit,int x, int y, int x0){ + int findTerrain( struct gameInit *gInit,int x, int y, int x0){ SDL_Rect to; int i=0; int cpt=0; + int err=0; SDL_Surface *sf; struct listeSimplementChainee *k=NULL; k=gInit->t.lt; @@ -2545,20 +2608,22 @@ void paint_objet (struct gameInit *gInit, int cptFps){ to.w=sf->w; to.h=1; SDL_FillRect(pStencil, &to, ccc_red); - print_num(pStencil, gInit->mapI.map.tabGif[1], k->x + 2, k->y + 2, i); + err=print_num(pStencil, gInit->mapI.map.tabGif[1], k->x + 2, k->y + 2, i); + if(err!=0){return err;} } ++i; k=k->next; } - + return 0; } - void paint_cursor(SDL_Surface *dst1,SDL_Surface *dst2, SDL_Surface *src, int x, int y, int x0, struct gameInit *gInit) + int paint_cursor(SDL_Surface *dst1,SDL_Surface *dst2, SDL_Surface *src, int x, int y, int x0, struct gameInit *gInit) { SDL_Rect from, to; int f=0; + int err=0; struct listeSimplementChainee *k=NULL; /* Render! */ @@ -2586,19 +2651,20 @@ void paint_objet (struct gameInit *gInit, int cptFps){ if((gInit->cptGame[18]==1)&&(gInit->cptGame[17]!=404)){ switch(gInit->cptGame[17]){ - case 2 : giveSkill(gInit,k,2);break;//climber - case 3 : giveSkill(gInit,k,4);break;//floater - case 4 : giveSkill(gInit,k,10);break;//bomber + case 2 : err=giveSkill(gInit,k,2);break;//climber + case 3 : err=giveSkill(gInit,k,4);break;//floater + case 4 : err=giveSkill(gInit,k,10);break;//bomber - case 5 : giveSkill(gInit,k,6);break;//stopper + case 5 : err=giveSkill(gInit,k,6);break;//stopper - case 6 : giveSkill(gInit,k,11);break;//builder - case 7 : giveSkill(gInit,k,14);break;//basher - case 8 : giveSkill(gInit,k,15);break;//miner - case 9 : giveSkill(gInit,k,13);break;//digger + case 6 : err=giveSkill(gInit,k,11);break;//builder + case 7 : err=giveSkill(gInit,k,14);break;//basher + case 8 : err=giveSkill(gInit,k,15);break;//miner + case 9 : err=giveSkill(gInit,k,13);break;//digger default: break; } + if(err!=0){return err;} gInit->cptGame[18]=0; } //end giveSkill @@ -2620,13 +2686,14 @@ void paint_objet (struct gameInit *gInit, int cptFps){ } } } - + return 0; } - void legende (struct gameInit *gInit){ + int legende (struct gameInit *gInit){ SDL_Rect rStencil; int decalY = 11; + int err=0; //char* msg=NULL; rStencil.x= 400; @@ -2634,75 +2701,93 @@ void paint_objet (struct gameInit *gInit, int cptFps){ rStencil.w= 10; rStencil.h= 10; - print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Terrain:"); + err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Terrain:"); + if(err!=0){return err;} rStencil.y += decalY; SDL_FillRect(screen, &rStencil, ccc_tRemove); - print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y ,"Remove"); + err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y ,"Remove"); + if(err!=0){return err;} rStencil.y += decalY; SDL_FillRect(screen, &rStencil, ccc_tRemoveNoOverwrite); - print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"No Overwrite Remove"); + err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"No Overwrite Remove"); + if(err!=0){return err;} rStencil.y += decalY; SDL_FillRect(screen, &rStencil, ccc_tFull); - print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Full"); + err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Full"); + if(err!=0){return err;} rStencil.y += decalY; SDL_FillRect(screen, &rStencil, ccc_tNoOverwrite); - print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"No Overwrite"); + err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"No Overwrite"); + if(err!=0){return err;} rStencil.y += decalY; // object rStencil.x = 30; rStencil.y = LEVEL_HEIGHT + 1; - print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Objet:"); + err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Objet:"); + if(err!=0){return err;} rStencil.y += decalY; SDL_FillRect(screen, &rStencil, ccc_oPassive); - print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Passive"); + err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Passive"); + if(err!=0){return err;} rStencil.y += decalY; SDL_FillRect(screen, &rStencil, ccc_oNoDigLeft); - print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"No digging to the left"); + err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"No digging to the left"); + if(err!=0){return err;} rStencil.y += decalY; SDL_FillRect(screen, &rStencil, ccc_oNoDigRight); - print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"No digging to the right"); + err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"No digging to the right"); + if(err!=0){return err;} rStencil.y += decalY; SDL_FillRect(screen, &rStencil, ccc_oExit); - print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Exit"); + err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Exit"); + if(err!=0){return err;} rStencil.y += decalY; SDL_FillRect(screen, &rStencil, ccc_oEntry); - print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Entry"); + err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Entry"); + if(err!=0){return err;} rStencil.y += decalY; SDL_FillRect(screen, &rStencil, ccc_oTrapDrown); - print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Trap which makes lemmings drown (water/quick sand/mud)"); + err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Trap which makes lemmings drown (water/quick sand/mud)"); + if(err!=0){return err;} rStencil.y += decalY; SDL_FillRect(screen, &rStencil, ccc_oTrapAndNoLem); - print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Trap which replaces lemming with death animation"); + err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Trap which replaces lemming with death animation"); + if(err!=0){return err;} rStencil.y += decalY; SDL_FillRect(screen, &rStencil, ccc_oTrapAndLem); - print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Trap which triggers lemming death animation"); + err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Trap which triggers lemming death animation"); + if(err!=0){return err;} rStencil.y += decalY; SDL_FillRect(screen, &rStencil, ccc_oUnknow); - print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Unknow"); + err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Unknow"); + if(err!=0){return err;} rStencil.y += decalY + 2; - print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x +15 ,rStencil.y,"Steel:"); + err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x +15 ,rStencil.y,"Steel:"); + if(err!=0){return err;} rStencil.y += decalY; SDL_FillRect(screen, &rStencil, ccc_s); - print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Indestructible terrain"); - + err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Indestructible terrain"); + if(err!=0){return err;} + return 0; } - void paint_interface (struct gameInit *gInit){ + int paint_interface (struct gameInit *gInit){ int i,n; + int err=0; SDL_Rect to,from; SDL_Surface *sf; @@ -2723,16 +2808,19 @@ void paint_objet (struct gameInit *gInit, int cptFps){ if(i+4 < 12){ n=gInit->mapI.paraMap[i+4]; - print_num(screen, gInit->mapI.map.tabGif[1], (to.x+7+(((n/10)>0)?0:5))+(sf->w*(2)), to.y-12, + err=print_num(screen, gInit->mapI.map.tabGif[1], (to.x+7+(((n/10)>0)?0:5))+(sf->w*(2)), to.y-12, n); + if(err!=0){return err;} } SDL_BlitSurface(sf, &from, screen, &to); } n=gInit->mapI.paraMap[0]; - print_num(screen, gInit->mapI.map.tabGif[1],INTER_BUTTON_X + 20 + (((n/10)>0)?0:5), to.y-12, n); + err=print_num(screen, gInit->mapI.map.tabGif[1],INTER_BUTTON_X + 20 + (((n/10)>0)?0:5), to.y-12, n); + if(err!=0){return err;} + return 0; } - void mouse_action (struct gameInit *gInit, int x, int y, int camX, int camY ){ + int mouse_action (struct gameInit *gInit, int x, int y, int camX, int camY ){ int i,numB; SDL_Surface *sf; @@ -2790,10 +2878,10 @@ void paint_objet (struct gameInit *gInit, int cptFps){ //gInit.cptGame[NBR_BUTTON_LEMMING] gInit->cptGame[18]=1; } - + return 0; } - void supprLem (struct gameInit *gInit, int cptFps){ + int supprLem (struct gameInit *gInit, int cptFps){ struct listeSimplementChainee *k=NULL; // refresh liste all of 100 tick if(cptFps % 100 == 0) @@ -2830,6 +2918,7 @@ void paint_objet (struct gameInit *gInit, int cptFps){ } printf("nbrInput = %d\nnbrInGame = %d\nnbrDied = %d\nnbrSafe = %d\n",gInit->l.nbrInput,gInit->l.nbr,gInit->l.nbrDied,gInit->l.nbrSafe); } + return 0; } @@ -2837,6 +2926,7 @@ void paint_objet (struct gameInit *gInit, int cptFps){ int lancement (){ int res,cptFps/*,i*/; + int err=0; //Ce qui va nous permettre de quitter int quit = 0; SDL_Rect camera,inter; @@ -2849,6 +2939,7 @@ void paint_objet (struct gameInit *gInit, int cptFps){ //La structure d'evenement SDL_Event event; + event.type=0; /* camera.x=160; @@ -2860,18 +2951,18 @@ void paint_objet (struct gameInit *gInit, int cptFps){ struct gameInit gInit; // constructor ... - initGame(&gInit); + err=initGame(&gInit); + if(err!=0){return err;} //Initialisation - res=init(); - if ( res != 0 ) { - return res; - } + err=init(); + if(err!=0){return err;} //printf("DONE\n"); //printf("DEBUG3: load_file ... \n"); //Chargement des fichiers - load_files(&gInit); + err=load_files(&gInit); + if(err!=0){return err;} // paraMap for(res=4;res<IDENT_COUNT;++res){ @@ -2879,7 +2970,8 @@ void paint_objet (struct gameInit *gInit, int cptFps){ } // CREATION OF SOME LEMMING - creationLemming(&gInit); + err=creationLemming(&gInit); + if(err!=0){return err;} mouseX = gInit.mapI.xPos; camera.x=gInit.mapI.xPos; @@ -2904,7 +2996,8 @@ void paint_objet (struct gameInit *gInit, int cptFps){ gInit.cptGame[15]=0; //paint_terrain => pTerrain - paint_terrain(&gInit,0); + err=paint_terrain(&gInit,0); + if(err!=0){return err;} //Tant que l'utilisateur n'a pas quitter @@ -2930,7 +3023,8 @@ void paint_objet (struct gameInit *gInit, int cptFps){ switch (event.type) { case SDL_MOUSEMOTION: { mouseX = event.motion.x; mouseY = event.motion.y;break; } - case SDL_MOUSEBUTTONDOWN: { mouse_action (&gInit, mouseX, mouseY,camera.x,camera.y ); + case SDL_MOUSEBUTTONDOWN: { err=mouse_action (&gInit, mouseX, mouseY,camera.x,camera.y ); + if(err!=0){return err;} break;} case SDL_QUIT : { //On quitte le programme @@ -2958,34 +3052,43 @@ void paint_objet (struct gameInit *gInit, int cptFps){ if(paint_stencil==1){ SDL_FillRect( pStencil, NULL, ccc_black); - paint_terrain(&gInit,1); + err=paint_terrain(&gInit,1); + if(err!=0){return err;} } // SPR => pSpr_Lem - paint_objet (&gInit,cptFps); - + err=paint_objet (&gInit,cptFps); + if(err!=0){return err;} + // SUPPR LEM => gInit - supprLem(&gInit,cptFps); + err=supprLem(&gInit,cptFps); + if(err!=0){return err;} // LEM => pSpr_Lem if(paint_stencil==0){ - paint_lemming (&gInit,cptFps); + err=paint_lemming (&gInit,cptFps); + if(err!=0){return err;} } // INTERFACE => screen if(paint_stencil==0){ - paint_interface (&gInit); + err=paint_interface (&gInit); + if(err!=0){return err;} } else { //testAlpha(screen, gInit.mapI.map.tabGif[9],gInit.mapI.map.tabGif[1],2,330); - legende (&gInit); + err=legende (&gInit); + if(err!=0){return err;} } // CURSOR => pSpr_Lem, screen if(paint_stencil==0){ - paint_cursor (pSpr_Lem,screen, gInit.mapI.map.tabGif[3], mouseX+camera.x, mouseY+camera.y, mouseX, &gInit); + err=paint_cursor (pSpr_Lem,screen, gInit.mapI.map.tabGif[3], mouseX+camera.x, mouseY+camera.y, mouseX, &gInit); + if(err!=0){return err;} } else { - findTerrain(&gInit,mouseX+camera.x, mouseY+camera.y, mouseX); - paint_cursor (pStencil,screen, gInit.mapI.map.tabGif[3], mouseX+camera.x, mouseY+camera.y, mouseX, &gInit); + err=findTerrain(&gInit,mouseX+camera.x, mouseY+camera.y, mouseX); + if(err!=0){return err;} + err=paint_cursor (pStencil,screen, gInit.mapI.map.tabGif[3], mouseX+camera.x, mouseY+camera.y, mouseX, &gInit); + if(err!=0){return err;} printf("x=%d y=%d\n",mouseX+camera.x,mouseY+camera.y); } @@ -3014,7 +3117,7 @@ void paint_objet (struct gameInit *gInit, int cptFps){ //if (cptFps == 250) {decalFps = 99; } // limte fps - if(FPS<=decalFps){printf("BUG: FPS < 0 : (FPS %d - decalFps %d) < 0",FPS,decalFps);exit(23);} else { + if(FPS<=decalFps){printf("BUG: FPS < 0 : (FPS %d - decalFps %d) < 0",FPS,decalFps);return(42);} else { while((FPS>decalFps)&&(((float)fps_count * 1000.0 / (SDL_GetTicks()-fps_start)) > FPS-decalFps) ){ if((FPS-decalFps)<=120){// useless ? SDL_Delay(3); @@ -3023,33 +3126,40 @@ void paint_objet (struct gameInit *gInit, int cptFps){ temps = SDL_GetTicks(); //heure - print_num(screen, gInit.mapI.map.tabGif[1], screen->w-160, screen->h-40, temps/(1000*3600)); + err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-160, screen->h-40, temps/(1000*3600)); + if(err!=0){return err;} //minute - print_num(screen, gInit.mapI.map.tabGif[1], screen->w-130, screen->h-40, (temps/(1000*60))%60); + err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-130, screen->h-40, (temps/(1000*60))%60); + if(err!=0){return err;} //seconde - print_num(screen, gInit.mapI.map.tabGif[1], screen->w-100, screen->h-40, (temps/1000)%60); + err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-100, screen->h-40, (temps/1000)%60); + if(err!=0){return err;} - print_num(screen, gInit.mapI.map.tabGif[1], screen->w-100, screen->h-12, cptFps); - print_num(screen, gInit.mapI.map.tabGif[1], screen->w-37, screen->h-12, fps); + err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-100, screen->h-12, cptFps); + if(err!=0){return err;} + err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-37, screen->h-12, fps); + if(err!=0){return err;} //Mise à jour de l'écran if( SDL_Flip( screen ) == -1 ) { - return 1; + return 4; } //SDL_Delay(1); - if(FPS<=decalFps){printf("BUG: FPS < 0 : (FPS %d - decalFps %d) < 0",FPS,decalFps);exit(23);} else { + if(FPS<=decalFps){printf("BUG: FPS < 0 : (FPS %d - decalFps %d) < 0",FPS,decalFps);return(43);} else { temps = SDL_GetTicks(); //printf("cptFps = %d, time: %ld:%ld:%ld \n",cptFps,temps/(1000*3600),(temps/(1000*60))%60,(temps/1000)%60); } cptFps++; + //quit = 1; } //On libère les images et on quitte SDL - clean_up(); + err=clean_up(); + if(err!=0){return err;} return 0; } @@ -3067,7 +3177,7 @@ void paint_objet (struct gameInit *gInit, int cptFps){ fprintf(stderr,"\nOption:\n\t- 1: on se place dans le dossier 1_orig\n"); fprintf(stderr,"\t- 2: on se place dans le dossier 2_ohno\n"); fprintf(stderr,"Filename:\n\t- numero du lvl (ex: 1, 4, 13, 65b )\n"); - exit(1); + return(44); } if (argc==3) { i=1; @@ -3076,14 +3186,14 @@ void paint_objet (struct gameInit *gInit, int cptFps){ if (num >= 100) ++i; if (num >= 1000){ fprintf(stderr,"Too many lvl (%d > 999)\n",num); - exit(9); + return(45); } temp0=malloc(sizeof(char)*(3-i));// => [00] [0] [] switch(i){ case 1 : temp0 = "00";break; case 2 : temp0 = "0";break; case 3 : temp0 = "";break; - default:fprintf(stderr,"BUG: i[=%d] > 3 ERREUR\n",i);exit(8); + default:fprintf(stderr,"BUG: i[=%d] > 3 ERREUR\n",i);return(46); } lt = (strlen("../../../../trunk/level/1_orig/lvl.ini")+5);// + 4 : 4 chiffres lvl.ini, +1 : string @@ -3091,7 +3201,7 @@ void paint_objet (struct gameInit *gInit, int cptFps){ switch(atoi(argv[1])){ case 1 : sprintf(temp,"../../../../trunk/level/1_orig/lvl0%s%d.ini",temp0,num);break; case 2 : sprintf(temp,"../../../../trunk/level/2_ohno/lvl1%s%d.ini",temp0,num);break; - default:fprintf(stderr,"ERREUR: dossier [%d] inconnu\n",atoi(argv[1]));exit(8); + default:fprintf(stderr,"ERREUR: dossier [%d] inconnu\n",atoi(argv[1]));return(47); } } else { temp=malloc(sizeof(char)*(strlen(argv[1])+1)); @@ -3101,7 +3211,7 @@ void paint_objet (struct gameInit *gInit, int cptFps){ // yyin=fopen("./lvlTest01.ini", "r"); if (yyin==NULL) { fprintf(stderr,"Filename INVALIDE: %s\n",temp); - perror("Impossible d'ouvrir le niveau"); exit(42); } + perror("Impossible d'ouvrir le niveau"); return(48); } /* for(i=0;i<256;++i){ @@ -3115,7 +3225,6 @@ void paint_objet (struct gameInit *gInit, int cptFps){ }}}*/ res=lancement(); - //fclose(yyin); fait dans lancement return res; diff --git a/sdl-test/SDL_tuto/TestParserLemmingsLVL/test.sh b/sdl-test/SDL_tuto/TestParserLemmingsLVL/test.sh index 60cd82d..54ad7ed 100755 --- a/sdl-test/SDL_tuto/TestParserLemmingsLVL/test.sh +++ b/sdl-test/SDL_tuto/TestParserLemmingsLVL/test.sh @@ -2,14 +2,15 @@ > ./log make - +res=0 find /home/jazzblue/Bureau/Projet-Lemmings/trunk/level -name 'lvl*.ini' | while read f do echo -n "'$f'" ./main $f >/dev/null - if [ $? -eq 0 ] + res=$? + if [ $res -eq 0 ] then echo "$f OK" >> ./log - else echo "$f FAILED" >> ./log + else echo "$f FAIL: $res" >> ./log fi done @@ -17,9 +18,10 @@ find /home/jazzblue/Bureau/Projet-Lemmings/trunk/level -name 'tame*.ini' | while do echo -n "'$f'" ./main $f >/dev/null + res=$? if [ $? -eq 0 ] then echo "$f OK" >> ./log - else echo "$f FAILED" >> ./log + else echo "$f FAIL: $res" >> ./log fi done |