From 78cf86f630ab63b7e5079780b4f41605eb281032 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sun, 12 Dec 2010 14:37:17 +0000 Subject: Gestion du misc/lemming.ini, chargement des gifs du dossier misc/, continuation du système de dirty rectangles (touche d pour debugguer), début de gestion du curseur du jeu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///var/svn/2010-netlemmings/trunk@205 077b3477-7977-48bd-8428-443f22f7bfda --- src/game.c | 3 +- src/graphic.c | 69 +++++++++++++----- src/include/data_config.h | 9 +++ src/include/data_ini.h | 17 +++++ src/include/data_localgame.h | 9 ++- src/include/data_ress.h | 7 +- src/include/graphic.h | 7 +- src/include/loader.h | 4 +- src/include/parser.h | 1 + src/loader.c | 150 ++++++++++++++++++++++++++++++++++++--- src/netlem.c | 146 ++++++++++++++++++------------------- src/parser/parse_ini.lex | 7 ++ src/parser/parse_ini.yy | 73 +++++++++++++++++-- src/test/testfunc_001_lex.sh | 2 +- src/test/testfunc_002_parse.sh | 2 +- src/test/testfunc_003_loadress.c | 5 ++ 16 files changed, 387 insertions(+), 124 deletions(-) create mode 100644 src/include/data_config.h diff --git a/src/game.c b/src/game.c index e692da5..63f61a3 100644 --- a/src/game.c +++ b/src/game.c @@ -9,8 +9,7 @@ void play(tick_t tick, int *dirtRectsCount, SDL_Rect **directRects ) { //TODO : boucle de jeu principale ici (maj état de jeu) - *dirtRectsCount=0; - *directRects=NULL; + printf("%p - %i\n", (void *) *directRects, *dirtRectsCount); SDL_Delay(rand()%8); } diff --git a/src/graphic.c b/src/graphic.c index 18e62c2..576cbfa 100644 --- a/src/graphic.c +++ b/src/graphic.c @@ -70,6 +70,52 @@ SDL_Surface * loadGif(char *filePath) { return IMG_Load(filePath); } +int init(char *winCaption, gameConfig_t *conf, gameGraphics_t *gGraph) { + int result; + + memset(gGraph,0,sizeof(gameGraphics_t)); + + // SDL subsystems initialization + result = SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO ); + if ( result != 0 ) { + logs2(LOG_ERROR, "init(), SDL_Init()", SDL_GetError()); + return 1; + } + + // Screen setup + gGraph->screen = SDL_SetVideoMode(conf->screen.w, conf->screen.h, 32, SDL_HWSURFACE | SDL_ASYNCBLIT); + if( gGraph->screen == NULL ) { + logs2(LOG_ERROR, "init(), SDL_SetVideoMode()", SDL_GetError()); + return 2; + } + + // SDL main window caption + SDL_WM_SetCaption(winCaption, NULL); + + // We dont want to see the standard mouse cursor in our main window + //TODO: SDL_ShowCursor(0); + + // Memory allocation and initialization for all display layers + gGraph->surfaces.terrain = createSurface(LEVEL_WIDTH, LEVEL_HEIGHT); + if( gGraph->surfaces.terrain == NULL ) { + logs2(LOG_ERROR, "init(), SDL_createSurface()", SDL_GetError()); + return 3; + } + + gGraph->surfaces.stencil = createSurface(LEVEL_WIDTH, LEVEL_HEIGHT); + if( gGraph->surfaces.stencil == NULL ) { + logs2(LOG_ERROR, "init(), SDL_createSurface()", SDL_GetError()); + return 3; + } + + gGraph->surfaces.tmpSurf = createSurface(LEVEL_WIDTH, LEVEL_HEIGHT); + if( gGraph->surfaces.tmpSurf == NULL ) { + logs2(LOG_ERROR, "init(), SDL_createSurface()", SDL_GetError()); + return 3; + } + + return 0; +} int paintTerrain(gameIni_t *gIni, gameRess_t *gRess, gameGraphics_t *gGraph) { int res, i, modifier; int x,y,xmin,xmax,ymin,ymax,y2,xdst,ydst; @@ -178,43 +224,30 @@ int paintTerrain(gameIni_t *gIni, gameRess_t *gRess, gameGraphics_t *gGraph) { int repaint(gameGraphSurfaces_t *srcSurfs, SDL_Rect *srcRect, SDL_Surface *dstSurf, SDL_Rect dstRect) { int objToRepaintCount, i, res; gameGraphObjState_t *objToRepaint; - SDL_Surface *tmpSurf; - tmpSurf=createSurface(srcRect->w, srcRect->h); - - if (tmpSurf==NULL) { - logs(LOG_ERROR, "repain(), createSurface() has failed"); - return 1; - } objToRepaintCount=findAndZSortObjects(srcSurfs->objectsStat, srcRect, &objToRepaint); for(i=0;i0) break; - res=paintObject(objToRepaint+i, srcRect, tmpSurf); + res=paintObject(objToRepaint+i, srcRect, dstSurf, &dstRect); if ( res!=0 ) { logs(LOG_DEBUG, "repaint(), paintObject() failed"); } } - res=SDL_BlitSurface(srcSurfs->terrain, srcRect, tmpSurf, NULL); + res=SDL_BlitSurface(srcSurfs->terrain, srcRect, dstSurf, &dstRect); if ( res!=0 ) { logs2(LOG_DEBUG, "repaint(), SDL_BlitSurface()", SDL_GetError()); } for(;iscreen.w=640; + conf->screen.h=480; + conf->screen.x=0; + conf->screen.y=0; + //TODO : charger vraiment le fichier de conf ^^ +} + +int loadIni(gameIni_t *gIni, char *filepath) { + int res; + + yyin=fopen(filepath, "r"); + if (yyin == NULL ) { + fprintf(stderr, "load_ini(), Could not open '%s'\n", filepath); + return 1; + } + res=parse(gIni); + fclose(yyin); + return res; +} + int loadRessources(gameIni_t *gIni, gameRess_t *gRess) { - int i, filenamelen; + int i, res, filenamelen; char *filepath; filenamelen = sizeof(char)*(strlen(PATH_STYLE)+2*strlen(gIni->style.name)+strlen("//om_00.gif")+1); @@ -73,18 +98,123 @@ int loadRessources(gameIni_t *gIni, gameRess_t *gRess) { } free(filepath); - return 0; + + res=_loadMiscRessources(gIni, gRess); + + return res; } -int loadIni(gameIni_t *gIni, char *filepath) { - int res; +int _loadMiscRessources(gameIni_t *gIni, gameRess_t *gRess) { + int i, filenamelen; + char *filepath; - yyin=fopen(filepath, "r"); - if (yyin == NULL ) { - fprintf(stderr, "load_ini(), Could not open '%s'\n", filepath); + filenamelen = sizeof(char)*(strlen(PATH_MISC)+16); + filepath = malloc(filenamelen); + + gRess->misc.lemmingAnims=malloc(sizeof(SDL_Surface *)*gIni->misc.lemmingAnimCount); + if (gRess->misc.lemmingAnims==NULL) { + logp(LOG_ERROR, "_loadMiscRessources(), malloc()"); return 1; } - res=parse(gIni); - fclose(yyin); - return res; + + gRess->misc.lemmingMasks=malloc(sizeof(SDL_Surface *)*gIni->misc.lemmingAnimCount); + if (gRess->misc.lemmingMasks==NULL) { + logp(LOG_ERROR, "_loadMiscRessources(), malloc()"); + return 1; + } + + gRess->misc.lemmingImasks=malloc(sizeof(SDL_Surface *)*gIni->misc.lemmingAnimCount); + if (gRess->misc.lemmingImasks==NULL) { + logp(LOG_ERROR, "_loadMiscRessources(), malloc()"); + return 1; + } + + for(i=0; i < gIni->misc.lemmingAnimCount ; ++i) { + snprintf(filepath, filenamelen, "%s/lemm_%d.gif", PATH_MISC, i); + gRess->misc.lemmingAnims[i] = loadGif(filepath); + if (gRess->misc.lemmingAnims[i]==NULL) { + logs2(LOG_WARN, "_loadMiscRessources(), loadGif() error for ", filepath); + return 2; + } + + if ( gIni->misc.lemmingAnims[i].haveImask == 1 ) { + snprintf(filepath, filenamelen, "%s/mask_%d.gif", PATH_MISC, i); + gRess->misc.lemmingImasks[i] = loadGif(filepath); + if (gRess->misc.lemmingImasks[i]==NULL) { + logs2(LOG_WARN, "_loadMiscRessources(), loadGif() error for ", filepath); + return 2; + } + } + + if ( gIni->misc.lemmingAnims[i].haveMask == 1 ) { + snprintf(filepath, filenamelen, "%s/mask_%d.gif", PATH_MISC, i); + gRess->misc.lemmingImasks[i] = loadGif(filepath); + if (gRess->misc.lemmingImasks[i]==NULL) { + logs2(LOG_WARN, "_loadMiscRessources(), loadGif() error for ", filepath); + return 2; + } + } + } + + gRess->misc.icons=malloc(sizeof(SDL_Surface *)*MISC_ICON_COUNT); + if (gRess->misc.icons==NULL) { + logp(LOG_ERROR, "_loadMiscRessources(), malloc()"); + return 1; + } + + for(i=0; i < MISC_ICON_COUNT ; ++i) { + snprintf(filepath, filenamelen, "%s/icon_%d.gif", PATH_MISC, i); + gRess->misc.icons[i] = loadGif(filepath); + if (gRess->misc.icons[i]==NULL) { + logs2(LOG_WARN, "_loadMiscRessources(), loadGif() error for ", filepath); + return 2; + } + } + + snprintf(filepath, filenamelen, "%s/lemmfont.gif", PATH_MISC); + gRess->misc.font1 = loadGif(filepath); + if (gRess->misc.font1==NULL) { + logs2(LOG_WARN, "_loadMiscRessources(), loadGif() error for ", filepath); + return 2; + } + + snprintf(filepath, filenamelen, "%s/numfont.gif", PATH_MISC); + gRess->misc.font2 = loadGif(filepath); + if (gRess->misc.font2==NULL) { + logs2(LOG_WARN, "_loadMiscRessources(), loadGif() error for ", filepath); + return 2; + } + + snprintf(filepath, filenamelen, "%s/lemmfont2.gif", PATH_MISC); + gRess->misc.font2 = loadGif(filepath); + if (gRess->misc.font2==NULL) { + logs2(LOG_WARN, "_loadMiscRessources(), loadGif() error for ", filepath); + return 2; + } + + snprintf(filepath, filenamelen, "%s/countdown.gif", PATH_MISC); + gRess->misc.countdown = loadGif(filepath); + if (gRess->misc.countdown==NULL) { + logs2(LOG_WARN, "_loadMiscRessources(), loadGif() error for ", filepath); + return 2; + } + + snprintf(filepath, filenamelen, "%s/cursor.gif", PATH_MISC); + gRess->misc.cursor = loadGif(filepath); + if (gRess->misc.cursor==NULL) { + logs2(LOG_WARN, "_loadMiscRessources(), loadGif() error for ", filepath); + return 2; + } + + snprintf(filepath, filenamelen, "%s/explode.gif", PATH_MISC); + gRess->misc.explode = loadGif(filepath); + if (gRess->misc.explode==NULL) { + logs2(LOG_WARN, "_loadMiscRessources(), loadGif() error for ", filepath); + return 2; + } + + free(filepath); + + return 0; } + diff --git a/src/netlem.c b/src/netlem.c index 47d8126..2b62fb2 100644 --- a/src/netlem.c +++ b/src/netlem.c @@ -45,14 +45,10 @@ int loadLevelProc(void *a); // Client-specific functions void signals(int signum); -int init(gameConfig_t *conf, gameGraphics_t *gGraph); -void loadGameConfig(gameConfig_t *conf); -void processLocalEvents(SDL_Rect *viewport, SDL_Rect *screen, SDL_Rect *terrain); +void processLocalEvents(gameGraphics_t *gGraph); int act(tick_t *tick, int loadProgress, TCPsocket sockClient, int *dirtRectsCount, SDL_Rect **dirtRects); int updateGraphics(gameGraphics_t *gGraph); - - int main(int argc, char **argv) { int drift_ms=0, endMainLoop, result; @@ -105,11 +101,13 @@ int main(int argc, char **argv) { loadGameConfig(&conf); // Libraries initialization - result=init(&conf, &gGraph); + result=init(WIN_CAPTION, &conf, &gGraph); if(result!=0) { logs(LOG_ERROR,"main(), init()"); return 3; } + atexit(SDL_Quit); + signal(2,signals); // Synchronization tools intialization semGameStart=SDL_CreateSemaphore(0); @@ -162,7 +160,7 @@ int main(int argc, char **argv) { // Process local player keyboard and mouse events // (note: remote events are processed by network read thread) - processLocalEvents(&(gGraph.viewport), &(gGraph.screen->clip_rect), &(gGraph.surfaces.terrain->clip_rect)); + processLocalEvents(&gGraph); endMainLoop=act(&tick, loadProgress, client.sockClient, &(gGraph.dirtRectsCount), &(gGraph.dirtRects)); @@ -237,57 +235,6 @@ void signals(int signum) { } } -int init(gameConfig_t *conf, gameGraphics_t *gGraph) { - int result; - - memset(gGraph,0,sizeof(gameGraphics_t)); - - // SDL subsystems initialization - result = SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO ); - if ( result != 0 ) { - logs2(LOG_ERROR, "init(), SDL_Init()", SDL_GetError()); - return 1; - } - atexit(SDL_Quit); - signal(2,signals); - - // Screen setup - gGraph->screen = SDL_SetVideoMode(conf->screen.w, conf->screen.h, 32, SDL_HWSURFACE | SDL_ASYNCBLIT); - if( gGraph->screen == NULL ) { - logs2(LOG_ERROR, "init(), SDL_SetVideoMode()", SDL_GetError()); - return 2; - } - - // SDL main window caption - SDL_WM_SetCaption(WIN_CAPTION, NULL); - - // We dont want to see the standard mouse cursor in our main window - //TODO: SDL_ShowCursor(0); - - // Memory allocation and initialization for all display layers - gGraph->surfaces.terrain = createSurface(LEVEL_WIDTH, LEVEL_HEIGHT); - if( gGraph->surfaces.terrain == NULL ) { - logs2(LOG_ERROR, "init(), SDL_createSurface()", SDL_GetError()); - return 3; - } - - gGraph->surfaces.stencil = createSurface(LEVEL_WIDTH, LEVEL_HEIGHT); - if( gGraph->surfaces.stencil == NULL ) { - logs2(LOG_ERROR, "init(), SDL_createSurface()", SDL_GetError()); - return 3; - } - - return 0; -} - -void loadGameConfig(gameConfig_t *conf) { - conf->screen.w=640; - conf->screen.h=480; - conf->screen.x=0; - conf->screen.y=0; - //TODO : charger vraiment le fichier de conf ^^ -} - int act(tick_t *tick, int loadProgress, TCPsocket sockClient, int *dirtRectsCount, SDL_Rect **dirtRects) { int res; @@ -475,7 +422,9 @@ int loadLevelProc(void *a) { #define MAP_SCROLL_BOUND 32 #define MAP_SCROLL_SPEED 16 -void processLocalEvents(SDL_Rect *viewport, SDL_Rect *screen, SDL_Rect *terrain) { +//FIXME : tous les champs de gGraph utilisés dans cette méthode devraient être déplacés dans une structure autre +//void processLocalEvents(SDL_Rect *viewport, SDL_Rect *screen, SDL_Rect *terrain, int *debugFlags) { +void processLocalEvents(gameGraphics_t *gGraph) { static int mouseActive=1, mouseX=100, mouseY=100; SDL_Event event; @@ -503,8 +452,14 @@ void processLocalEvents(SDL_Rect *viewport, SDL_Rect *screen, SDL_Rect *terrain) // if(zoomY <= 0.) {zoomY=0.1;} // break; // } - case SDLK_ESCAPE : changeState(eEnd); break; - default:break; + case SDLK_ESCAPE: + changeState(eEnd); + break; + case SDLK_d: + gGraph->debugFlags ^= DEBUG_DIRTYRECTANGLES; + break; + default: + break; } break; case SDL_ACTIVEEVENT: @@ -515,6 +470,15 @@ void processLocalEvents(SDL_Rect *viewport, SDL_Rect *screen, SDL_Rect *terrain) case SDL_MOUSEMOTION: mouseX = event.motion.x; mouseY = event.motion.y; + + //FIXME : utiliser une méthode addDirtRect + gGraph->dirtRects=malloc(1*sizeof(SDL_Rect)); + gGraph->dirtRects[0].x=mouseX-16; + gGraph->dirtRects[0].y=mouseY-16; + gGraph->dirtRects[0].w=32; + gGraph->dirtRects[0].h=32; + gGraph->dirtRectsCount=1; + break; case SDL_MOUSEBUTTONDOWN: //err=mouse_action(&gInit, mouseX, mouseY,camera.x,camera.y ); @@ -529,15 +493,15 @@ void processLocalEvents(SDL_Rect *viewport, SDL_Rect *screen, SDL_Rect *terrain) switch(getState()) { case eMultiGame: if (mouseActive) { - if(mouseY <= terrain->h){ - if (mouseX > (screen->w - MAP_SCROLL_BOUND)){ - if (viewport->x < (terrain->w - screen->w ) ) { - viewport->x += MAP_SCROLL_SPEED; + if(mouseY <= gGraph->surfaces.terrain->h){ + if (mouseX > (gGraph->screen->w - MAP_SCROLL_BOUND)){ + if (gGraph->viewport.x < (gGraph->surfaces.terrain->w - gGraph->screen->clip_rect.w ) ) { + gGraph->viewport.x += MAP_SCROLL_SPEED; } } if (mouseX < MAP_SCROLL_BOUND){ - if (viewport->x >= MAP_SCROLL_SPEED ) { - viewport->x -= MAP_SCROLL_SPEED; + if (gGraph->viewport.x >= MAP_SCROLL_SPEED ) { + gGraph->viewport.x -= MAP_SCROLL_SPEED; } } } @@ -553,44 +517,74 @@ void processLocalEvents(SDL_Rect *viewport, SDL_Rect *screen, SDL_Rect *terrain) int updateGraphics(gameGraphics_t *gGraph) { int i, res; static SDL_Rect lastViewport= {-1,-1,-1,-1}; - SDL_Rect srcRect/*, dstRect*/; + SDL_Rect srcRect; + SDL_Surface *tmpSurf; //TODO : modifier les calques switch(getState()) { case eMultiWaitLoading: + //TODO break; case eMultiGame: // If we had a camera movement, we have to refesh all the screen - // if ( memcmp(&lastViewport, &(gGraph->viewport), sizeof(SDL_Rect)) != 0) { + //if ( memcmp(&lastViewport, &(gGraph->viewport), sizeof(SDL_Rect)) != 0) { if ( lastViewport.x != gGraph->viewport.x ) { //lastViewport=gGraph->viewport; lastViewport.x=gGraph->viewport.x; if ( gGraph->dirtRectsCount > 0 ) { free(gGraph->dirtRects); } - // Put only one dirt rectagle, of the size of the screen + // Put only one dirt rectangle, of the size of the screen gGraph->dirtRects=malloc(1*sizeof(SDL_Rect)); memcpy(gGraph->dirtRects, &(gGraph->screen->clip_rect), sizeof(SDL_Rect)); gGraph->dirtRectsCount=1; } - // We use a dirt rectangle method for performance + // We use a dirty rectangle method for performance + tmpSurf=gGraph->surfaces.tmpSurf; for(i=0; idirtRectsCount; i++) { srcRect.x=gGraph->dirtRects[i].x+lastViewport.x; srcRect.y=gGraph->dirtRects[i].y+lastViewport.y; srcRect.w=gGraph->dirtRects[i].w; srcRect.h=gGraph->dirtRects[i].h; - res=repaint(&gGraph->surfaces, &srcRect, gGraph->screen, gGraph->dirtRects[i]); + res=repaint(&gGraph->surfaces, &srcRect, tmpSurf, srcRect); if ( res != 0 ) { - logs(LOG_WARN, "updateGraphics(), repain() failed"); + logs(LOG_WARN, "updateGraphics(), repaint() failed"); } - SDL_UpdateRect(gGraph->screen, + if ( (gGraph->debugFlags & DEBUG_DIRTYRECTANGLES) == 0 ) { + res=SDL_BlitSurface(tmpSurf, &srcRect, gGraph->screen, gGraph->dirtRects+i); + if ( res!=0 ) { + logs2(LOG_DEBUG, "repaint(), SDL_BlitSurface()", SDL_GetError()); + } + + SDL_UpdateRect(gGraph->screen, gGraph->dirtRects[i].x, gGraph->dirtRects[i].y, gGraph->dirtRects[i].w, gGraph->dirtRects[i].h); + } + } + if (gGraph->dirtRectsCount > 0) { + gGraph->dirtRectsCount=0; + free(gGraph->dirtRects); + } + + if ( (gGraph->debugFlags & DEBUG_DIRTYRECTANGLES) == DEBUG_DIRTYRECTANGLES ) { + srcRect.x=lastViewport.x; + srcRect.y=lastViewport.y; + srcRect.w=gGraph->screen->clip_rect.w; + srcRect.h=gGraph->screen->clip_rect.h; + res=SDL_BlitSurface(tmpSurf, &srcRect, gGraph->screen, NULL); + if ( res!=0 ) { + logs2(LOG_DEBUG, "repaint(), SDL_BlitSurface()", SDL_GetError()); + } + SDL_UpdateRect(gGraph->screen, 0,0,0,0); + + SDL_LockSurface(tmpSurf); + for(i=0; i < tmpSurf->pitch * tmpSurf->h ; ++i) { + ((Uint8 *)tmpSurf->pixels)[i] *= 0.9; + } + SDL_UnlockSurface(tmpSurf); } - gGraph->dirtRectsCount=0; - free(gGraph->dirtRects); break; default: break; diff --git a/src/parser/parse_ini.lex b/src/parser/parse_ini.lex index adaa070..0b3f2b0 100644 --- a/src/parser/parse_ini.lex +++ b/src/parser/parse_ini.lex @@ -86,6 +86,13 @@ COMMENT "#"[^\n]* "codeSeed" { BEGIN(TYPE_OTHER); return CODESEED; } "music_" { BEGIN(TYPE_STR); return MUSIC; } "level_" { BEGIN(TYPE_OTHER); return LEVEL; } + +"lemm_" { BEGIN(TYPE_OTHER); return LEMM; } +"pos_" { BEGIN(TYPE_OTHER); return POS; } +"mask_" { BEGIN(TYPE_OTHER); return MASK; } +"imask_" { BEGIN(TYPE_OTHER); return IMASK; } + + "fun_" { BEGIN(TYPE_OTHER); return DIFFICULTY; } "tricky_" { BEGIN(TYPE_OTHER); return DIFFICULTY; } "taxing_" { BEGIN(TYPE_OTHER); return DIFFICULTY; } diff --git a/src/parser/parse_ini.yy b/src/parser/parse_ini.yy index 0927011..ead019d 100644 --- a/src/parser/parse_ini.yy +++ b/src/parser/parse_ini.yy @@ -13,7 +13,9 @@ extern int yyparse(gameIni_t *gIni); int yylex(); void yyerror(gameIni_t *gIni, char *s); + void yyassert(int condition, char what[], char why[]); +int parse(gameIni_t *gIni); void callocIfNull(void **ptr, size_t nmemb, size_t size); uint32_t convrgb(uint32_t in); @@ -30,7 +32,9 @@ uint32_t convrgb(uint32_t in); %token BGCOLOR DEBRISCOLOR PARTICLECOLOR %token XPOS OBJECT TERRAIN STEEL RELEASERATE NUMLEMMINGS NUMTORESCUE TIMELIMIT %token NUMCLIMBERS NUMFLOATERS NUMBOMBERS NUMBLOCKERS NUMBUILDERS NUMBASHERS NUMMINERS NUMDIGGERS -%token MAXFALLDISTANCE CODESEED MUSIC LEVEL DIFFICULTY +%token MAXFALLDISTANCE CODESEED MUSIC LEVEL +%token LEMM POS MASK IMASK +%token DIFFICULTY %token AFF %token VIR @@ -156,8 +160,8 @@ decl: BGCOLOR AFF INTHEX { gIni->style.bgColor = convrgb($3); } if ( gIni->firstPass==1 ) { yyassert($2>=0 && $2=0 , "object_ id value", OUT_OF_BOUNDS); - yyassert($6%2==0 , "object_ xpos is odd", BAD_VALUE); - yyassert($8%2==0 , "object_ ypos is odd", BAD_VALUE); + //yyassert($6%2==0 , "object_ xpos is odd", BAD_VALUE); + //yyassert($8%2==0 , "object_ ypos is odd", BAD_VALUE); yyassert($10==0 || $10==4 || $10==8, "object_ paintMode value", BAD_VALUE); yyassert($12==0 || $12==1, "object_ ud value", BAD_VALUE); @@ -175,8 +179,8 @@ decl: BGCOLOR AFF INTHEX { gIni->style.bgColor = convrgb($3); } if ( gIni->firstPass==1 ) { yyassert($2>=0 && $2=0 , "terrain_ id value", OUT_OF_BOUNDS); - yyassert($6%2==0 , "terrain_ xpos is odd", BAD_VALUE); - yyassert($8%2==0 , "terrain_ ypos is odd", BAD_VALUE); + //yyassert($6%2==0 , "terrain_ xpos is odd", BAD_VALUE); + //yyassert($8%2==0 , "terrain_ ypos is odd", BAD_VALUE); yyassert($10>=0 && $10<16, "terrain_ modifier value", BAD_VALUE); gIni->level.terrainCount++; @@ -191,8 +195,8 @@ decl: BGCOLOR AFF INTHEX { gIni->style.bgColor = convrgb($3); } | STEEL INT AFF INT VIR INT VIR INT VIR INT { if ( gIni->firstPass==1 ) { yyassert($2>=0 && $2=0 && $4=0 && $6=0 && $8<=STEEL_MAX_WIDTH, "steel_ width value", BAD_VALUE); @@ -207,6 +211,58 @@ decl: BGCOLOR AFF INTHEX { gIni->style.bgColor = convrgb($3); } gIni->level.steels[$2].height = $10; } } +| LEMM INT AFF INT VIR INT VIR INT { + if ( gIni->firstPass==1 ) { + yyassert($2>=0 && $2=0 , "lemm_ frame value", OUT_OF_BOUNDS); + yyassert($6==1 || $6==2, "lemm_ dirs", BAD_VALUE); + yyassert($8==0 || $8==1, "lemm_ animType value", BAD_VALUE); + + gIni->misc.lemmingAnimCount++; + } else { + yyassert($2misc.lemmingAnimCount, "lemm_ index", OUT_OF_BOUNDS); + gIni->misc.lemmingAnims[$2].lemmFrames = $4; + gIni->misc.lemmingAnims[$2].lemmDirs = $6; + gIni->misc.lemmingAnims[$2].lemmAnimType = $8; + } + } +| POS INT AFF INT VIR INT VIR INT { + if ( gIni->firstPass==1 ) { + yyassert($2>=0 && $2=0, "pos_ x value", OUT_OF_BOUNDS); + yyassert($6>=0, "pos_ y dirs", BAD_VALUE); + yyassert($8==8, "pos_ flags value", BAD_VALUE); + } else { + yyassert($2misc.lemmingAnimCount, "pos_ index", OUT_OF_BOUNDS); + gIni->misc.lemmingAnims[$2].xPos = $4; + gIni->misc.lemmingAnims[$2].yPos = $6; + gIni->misc.lemmingAnims[$2].posFlags = $8; + } + } +| MASK INT AFF INT VIR INT VIR INT { + if ( gIni->firstPass==1 ) { + yyassert($2>=0 && $2=0 , "mask_ frame value", OUT_OF_BOUNDS); + yyassert($6==1 || $6==2, "mask_ dirs value", BAD_VALUE); + yyassert($8>=0, "mask_ startFrame value", BAD_VALUE); + } else { + yyassert($2misc.lemmingAnimCount, "mask_ index", OUT_OF_BOUNDS); + gIni->misc.lemmingAnims[$2].maskFrames = $4; + gIni->misc.lemmingAnims[$2].maskDirs = $6; + gIni->misc.lemmingAnims[$2].maskStartFrame = $8; + } + } +| IMASK INT AFF INT VIR INT { + if ( gIni->firstPass==1 ) { + yyassert($2>=0 && $2=0 , "imask_ frame value", OUT_OF_BOUNDS); + yyassert($6==1 || $6==2, "imask_ dirs value", BAD_VALUE); + } else { + yyassert($2misc.lemmingAnimCount, "imask_ index", OUT_OF_BOUNDS); + gIni->misc.lemmingAnims[$2].imaskFrames = $4; + gIni->misc.lemmingAnims[$2].imaskDirs = $6; + } + } | NAME AFF STR { gIni->level.name = $3; } /* TODO : attention, si fichier levelpack, name n'est pas le nom d'unniveau */ /* levelpack.ini */ | MAXFALLDISTANCE AFF INT { @@ -235,7 +291,10 @@ int parse(gameIni_t *gIni) { callocIfNull((void **)&gIni->level.terrains, gIni->level.terrainCount, sizeof(struct levelItem)); callocIfNull((void **)&gIni->level.steels, gIni->level.steelCount, sizeof(struct levelItem)); + callocIfNull((void **)&gIni->misc.lemmingAnims, gIni->misc.lemmingAnimCount, sizeof(struct lemmingAnim)); + rewind(yyin); + yylineno=0; gIni->firstPass=0; yyparse(gIni); diff --git a/src/test/testfunc_001_lex.sh b/src/test/testfunc_001_lex.sh index fdc96f6..7327eff 100755 --- a/src/test/testfunc_001_lex.sh +++ b/src/test/testfunc_001_lex.sh @@ -17,6 +17,6 @@ function do_test() { done } -find ../styles/ ../level/ -name *.ini | do_test src/test/testfunc_001_lex +find ../styles/ ../level/ ../misc/ -name *.ini | do_test src/test/testfunc_001_lex diff --git a/src/test/testfunc_002_parse.sh b/src/test/testfunc_002_parse.sh index 29b7556..c21e74e 100755 --- a/src/test/testfunc_002_parse.sh +++ b/src/test/testfunc_002_parse.sh @@ -17,4 +17,4 @@ function do_test() { done } -find ../styles/ ../level/ -name *.ini | do_test src/test/testfunc_002_parse +find ../styles/ ../level/ ../misc/ -name *.ini | do_test src/test/testfunc_002_parse diff --git a/src/test/testfunc_003_loadress.c b/src/test/testfunc_003_loadress.c index cf207cf..97da25c 100644 --- a/src/test/testfunc_003_loadress.c +++ b/src/test/testfunc_003_loadress.c @@ -7,6 +7,7 @@ #include "utils.h" #define PATH_STYLE "../styles" +#define PATH_MISC "../misc" #define PATH_LEVEL "../level" #define MAX_PATH_LEN 255 @@ -48,6 +49,10 @@ int main(int argc, char **argv) { res=loadIni(&gIni, filepath); if (res!=0) exit(res); + // Loading misc/lemming.ini + snprintf(filepath, MAX_PATH_LEN, "%s/lemming.ini", PATH_MISC); + res=loadIni(&gIni, filepath); + if (res!=0) exit(res); res=loadRessources(&gIni, &gRess); -- cgit v1.2.3