From dfe766a1001245a8b67482fcac1fed43a9745567 Mon Sep 17 00:00:00 2001 From: Damien Appert Date: Thu, 23 Sep 2010 10:31:21 +0000 Subject: j'ai parsé les style/*/*.ini ^^ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///var/svn/2010-netlemmings/trunk@62 077b3477-7977-48bd-8428-443f22f7bfda --- .../SDL_tuto/TestParserLemmingsLVL/parse_ini.lex | 25 ++++- .../SDL_tuto/TestParserLemmingsLVL/parse_ini.yy | 106 +++++++++++++++++++-- 2 files changed, 119 insertions(+), 12 deletions(-) (limited to 'sdl-test') diff --git a/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.lex b/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.lex index 1ad9735..48a913a 100644 --- a/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.lex +++ b/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.lex @@ -66,7 +66,7 @@ COMMENT "#"[^\n]* BEGIN(STR_M); return STYLE; } -"name" { +"name" { printf("name\n"); printf("--AUTO STR_M--\n"); BEGIN(STR_M); @@ -78,6 +78,25 @@ COMMENT "#"[^\n]* BEGIN(STR_M); return SLEM; } +"bgColor" { + printf("bgColor\n"); + printf("--AUTO STR_M--\n"); + BEGIN(STR_M); + return BGCOLOR; + } +"debrisColor" { + printf("debrisColor\n"); + printf("--AUTO STR_M--\n"); + BEGIN(STR_M); + return DEBRISCOLOR; + } +"particleColor" { + printf("particleColor\n"); + printf("--AUTO STR_M--\n"); + BEGIN(STR_M); + return PARTICLECOLOR; + } + {BLANK}*"="{BLANK}* { printf("STR_M-> [=]\n"); printf("--AUTO STR_MM--\n"); @@ -106,10 +125,10 @@ COMMENT "#"[^\n]* } "#"[^\n]*\n { - printf("[COMMENT]\n[\\n]\n"); + printf("[COMMENT:%s]\n[\\n]\n",yytext); yylineno++; } /* Single line Comment*/ - +\r /* http://fr.wikipedia.org/wiki/Fin_de_ligne : CRLF*/ \n { printf("[\\n]\n"); yylineno++; diff --git a/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.yy b/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.yy index 93bdc4d..5c1d894 100644 --- a/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.yy +++ b/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.yy @@ -93,6 +93,15 @@ int UD; // upside down struct objectT *next; }; + + struct sprite { + int id; + int frames; + int anim; + int type; + int sound; + struct sprite *next; + }; @@ -131,6 +140,7 @@ struct objectT *objet; //objet struct objectT *terrain;//terrain struct objectT *steel;//parties indestructibles + struct sprite *spr;// paramettre des objets spr.id==objet.id }; extern int yylineno; // Bidouille pour avoir le numero de ligne du lexer ^^ @@ -155,6 +165,11 @@ void clean_up(); int lancement(); + + // SPRITES + //void animeGif(SDL_Surface objet,, ); + + %} @@ -168,6 +183,9 @@ %token STYLE %token NAME %token SLEM +%token BGCOLOR +%token DEBRISCOLOR +%token PARTICLECOLOR %token AFF %token EOL %token VIR @@ -233,16 +251,25 @@ decl: STYLE AFF val { printf("superlemming value invalid: %d %s\n",res,$3->ptr.str);exit(99); } } +| BGCOLOR AFF val {} +| DEBRISCOLOR AFF val {} +| PARTICLECOLOR AFF val {} | IDENT AFF val EOL { enum ident t; // TYPE TERRAIN - int i,state=0; + int i=0,state=0; // cette variable sert a derteminer dans quel cas on se trouve // state==0: aucun token detecter // state==1: token para de la map detecter // state==2: token xPos detecter // state==3: token terrain_ detecter - // state==4: token object_ detecter - + // state==4: token object_ detecter + // state==5: token steel_ detecter + // state==6: token frames_ detecter + // state==7: token anim_ detecter + // state==8: token type_ detecter + // state==9: token sound_ detecter + // state==10: token title detecter + struct objectT **listeItem=NULL; //printf("'%s' ^\n ", $1); // donne les parametres de la map @@ -277,8 +304,40 @@ decl: STYLE AFF val { listeItem=&gInit->steel; } + if(strncmp($1,"frames_",7) == 0){ + state=6; + struct sprite *s = malloc(sizeof(struct sprite)); + if(gInit->spr == NULL){ + s->id=0; + } else { + s->id=gInit->spr->id+1; + } + s->frames=$3->ptr.ints->val; + s->next=gInit->spr; + gInit->spr=s; + } + + if(strncmp($1,"anim_",5) == 0){ + state=7; + gInit->spr->anim = $3->ptr.ints->val ; + } + + if(strncmp($1,"type_",5) == 0){ + state=8; + gInit->spr->type = $3->ptr.ints->val ; + } + + if(strncmp($1,"sound_",6) == 0){ + state=9; + gInit->spr->sound = $3->ptr.ints->val ; + } + + if(strncmp($1,"tiles",5) == 0){ + state=10; + } + - if(state>2){ + if(state>2 && state<6){ struct list_int *curr=$3->ptr.ints; struct objectT *o = malloc(sizeof(struct objectT)); @@ -684,6 +743,7 @@ void afficher(struct gameInit *gInit){ printf("LES OBJETS:\n"); struct objectT *o; + struct sprite *s; o=gInit->objet; while ( o !=NULL ) { @@ -705,6 +765,13 @@ void afficher(struct gameInit *gInit){ } printf("LE NOM DU NIVEAU:\n"); printf("name = %s\n",gInit->name); + + printf("LES SPRITES:\n"); + s=gInit->spr; + while ( s !=NULL ) { + printf("spr_%d:\n\tframes_%d = %d\n\tanim_%d = %d\n\ttype_%d = %d\n\tsound_%d = %d\n",s->id,s->id, s->frames,s->id,s->anim,s->id,s->type,s->id,s->sound); + s=s->next; + } } @@ -713,19 +780,35 @@ int load_files(struct gameInit *gInit) { int res, lt,ltt; char *folder; + char *spriteINI; yyparse(gInit); + + fclose(yyin); + printf("CLOSE 1\n"); lt = (strlen("../../../styles/")); ltt = (strlen(tabType[gInit->tType])); folder = malloc(sizeof(char)*(lt+ltt+1)); - - afficher(gInit); + spriteINI = malloc(sizeof(char)*(lt+ltt*2+5));// *2:dossier/fichier, +4: .ini, +1: string //folder = "/home/jazzblue/Bureau/Projet-Lemmings/trunk/styles/dirt"; //printf("test segFault\n"); sprintf(folder,"../../../styles/%s",tabType[gInit->tType]); + sprintf(spriteINI,"%s/%s.ini",folder,tabType[gInit->tType]); //printf("test2\n"); + + 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); + } + + yyparse(gInit); + + fclose(yyin); + printf("CLOSE 2\n"); + afficher(gInit); // printf("\n--> %s\n", folder); // printf("test segFault DONE\n"); @@ -781,6 +864,7 @@ int res,res2; gInit.objet = NULL; gInit.terrain = NULL; gInit.steel = NULL; + gInit.spr = NULL; //gInit.objet.debut=malloc(sizeof(struct objectT)); @@ -815,6 +899,8 @@ int res,res2; return res; } + + camera.w=screen->w; camera.h=screen->h; @@ -841,7 +927,7 @@ SDL_FillRect( background, &background->clip_rect, SDL_MapRGB( background->format while ( o !=NULL ) { offset.x = o->x; offset.y = o->y; - if ((res2=SDL_BlitSurface(tabGif[gInit.tabCptObjet[0]+o->id+1], NULL, background, &offset)) != 0){ + if ((res2=SDL_BlitSurface(tabGif[gInit.tabCptObjet[0]+o->id+1], NULL, level, &offset)) != 0){ printf("ERREUR [%d] SDL_BlitSurface : ",res); } @@ -1001,15 +1087,17 @@ int main (int argc, char **argv) sprintf(temp,"%s",argv[1]); } yyin=fopen(temp, "r"); + //yyin=fopen("./fichierTest.ini", "r"); if (yyin==NULL) { fprintf(stderr,"Filename INVALIDE: %s\n",temp); perror("Impossible d'ouvrir le niveau"); exit(42); } - + res=lancement(); - fclose(yyin); + //fclose(yyin); fait dans lancement return res; + } -- cgit v1.2.3