From ee60d05a1f3ebda199ed1517915bf017c78f0e31 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sat, 4 Dec 2010 21:31:35 +0000 Subject: Diverses améliorations, un peu de refactoring, intégration du chargement des niveaux (manque à gérer les levelpacks au départ). netlem segfault brutalement mais j'ai plus l'énergie de debugger ce soir. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///var/svn/2010-netlemmings/trunk@183 077b3477-7977-48bd-8428-443f22f7bfda --- src/graphic.c | 64 +++++++++++----------- src/include/data_ini.h | 2 + src/include/graphic.h | 3 +- src/include/loader.h | 1 + src/include/netlem_state_machine.h | 4 +- src/include/parser.h | 2 +- src/loader.c | 20 ++++++- src/netlem.c | 102 +++++++++++++++++++++++------------ src/netlem_state_machine.c | 25 +++++---- src/parser/parse_ini.yy | 6 ++- src/test/testfunc_003_loadress.c | 22 +++----- src/test/testfunc_004_buildterrain.c | 29 ++++------ 12 files changed, 164 insertions(+), 116 deletions(-) diff --git a/src/graphic.c b/src/graphic.c index f67613e..a0587bc 100644 --- a/src/graphic.c +++ b/src/graphic.c @@ -73,37 +73,37 @@ SDL_Surface * loadGif(char *filePath) { return IMG_Load(filePath); } -int paintTerrain(gameIni_t *gIni, gameRess_t *gRess, SDL_Surface **terrain, SDL_Surface **stencil) { - int res, i; - int x,y,xmin,xmax,ymin,ymax,y2,xdst, ydst; +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; Uint32 dstPixel, dstStencil; SDL_Surface *tile; - *terrain=createSurface(LEVEL_WIDTH, LEVEL_HEIGHT); - if (*terrain==NULL) { + gGraph->terrain=createSurface(LEVEL_WIDTH, LEVEL_HEIGHT); + if (gGraph->terrain==NULL) { logs(LOG_ERROR, "paintTerrain(), SDL_CreateRGBSurface() returns NULL"); return 1; } - *stencil=createSurface(LEVEL_WIDTH, LEVEL_HEIGHT); - if (*stencil==NULL) { + gGraph->stencil=createSurface(LEVEL_WIDTH, LEVEL_HEIGHT); + if (gGraph->stencil==NULL) { logs(LOG_ERROR, "paintTerrain(), SDL_CreateRGBSurface() returns NULL"); return 2; } - res=SDL_FillRect(*terrain, &((*terrain)->clip_rect), gIni->style.bgColor); + res=SDL_FillRect(gGraph->terrain, &(gGraph->terrain->clip_rect), gIni->style.bgColor); if (res!=0) { logs(LOG_WARN, "paintTerrain(), SDL_FillRect() failed"); return 3; } - res=SDL_FillRect(*stencil, &((*stencil)->clip_rect), ccc_nothing); + res=SDL_FillRect(gGraph->stencil, &(gGraph->stencil->clip_rect), ccc_nothing); if (res!=0) { logs(LOG_WARN, "paintTerrain(), SDL_FillRect() failed"); return 4; } - SDL_LockSurface(*terrain); - SDL_LockSurface(*stencil); + SDL_LockSurface(gGraph->terrain); + SDL_LockSurface(gGraph->stencil); for(i=0 ; i < gIni->level.terrainCount ; i++) { //FIXME : check sanity for id value tile=gRess->style.tiles[gIni->level.terrains[i].id]; @@ -121,27 +121,28 @@ int paintTerrain(gameIni_t *gIni, gameRess_t *gRess, SDL_Surface **terrain, SDL_ // 4 : Upside Down // 2 : REMOVE : oublier (rendre transparent) tous les pixels qu'on a déjà plaqué + modifier=gIni->level.terrains[i].modifier; // If we match the Lemini hack, change the value to NO_OVERRIDE - if (gIni->level.terrains[i].modifier == 15) { - gIni->level.terrains[i].modifier=8; + if (modifier == 15) { + modifier=8; } // If both REMOVE and NO_OVERRIDE is enabled, prefer NO_OVERRIDE (turn off REMOVE flag) - if ((gIni->level.terrains[i].modifier & 10) == 10) { - gIni->level.terrains[i].modifier &= ~2; + if ( (modifier & 10) == 10) { + modifier &= ~2; } // For each tile pixel, without going outside of the terrain ymin=(gIni->level.terrains[i].ypos>=0)?0:-gIni->level.terrains[i].ypos; - ymax=min(tile->clip_rect.h, (*terrain)->clip_rect.h - gIni->level.terrains[i].ypos); + ymax=min(tile->clip_rect.h, gGraph->terrain->clip_rect.h - gIni->level.terrains[i].ypos); xmin=(gIni->level.terrains[i].xpos>=0)?0:-gIni->level.terrains[i].xpos; - xmax=min(tile->clip_rect.w, (*terrain)->clip_rect.w - gIni->level.terrains[i].xpos); + xmax=min(tile->clip_rect.w, gGraph->terrain->clip_rect.w - gIni->level.terrains[i].xpos); SDL_LockSurface(tile); for (y=ymin; ylevel.terrains[i].modifier & 4) == 4 ) { + if (( modifier & 4) == 4 ) { y2=tile->clip_rect.h-1-y; } else { y2=y; @@ -153,10 +154,10 @@ int paintTerrain(gameIni_t *gIni, gameRess_t *gRess, SDL_Surface **terrain, SDL_ if ( ! isTransparent(tile, x, y2) ) { // Always paint pixel, except in one case: // If we are in NO_OVERRIDE mode and there is already a terrain on the current (source) pixel - if ( !( (gIni->level.terrains[i].modifier & 8) == 8 && - getPixel(*stencil, xdst, ydst) == ccc_terrain ) ) { + if ( !( (modifier & 8) == 8 && + getPixel(gGraph->stencil, xdst, ydst) == ccc_terrain ) ) { // If we have REMOVE modifier, dstPixel will be rolled back to bgColor, else, it will be identical to the source pixel. We have to update stencil consistenly. - if ( (gIni->level.terrains[i].modifier & 2) == 2 ) { + if ( (modifier & 2) == 2 ) { dstPixel=gIni->style.bgColor; dstStencil=ccc_nothing; } else { @@ -164,22 +165,23 @@ int paintTerrain(gameIni_t *gIni, gameRess_t *gRess, SDL_Surface **terrain, SDL_ dstStencil=ccc_terrain; } - putPixel(*terrain, xdst, ydst, dstPixel); - putPixel(*terrain, xdst+1, ydst, dstPixel); - putPixel(*terrain, xdst, ydst+1, dstPixel); - putPixel(*terrain, xdst+1, ydst+1, dstPixel); - putPixel(*stencil, xdst, ydst, dstStencil); - putPixel(*stencil, xdst+1, ydst, dstStencil); - putPixel(*stencil, xdst, ydst+1, dstStencil); - putPixel(*stencil, xdst+1, ydst+1, dstStencil); + //FIXME : optimiser le nombre d'appels ici ! + putPixel(gGraph->terrain, xdst, ydst, dstPixel); + putPixel(gGraph->terrain, xdst+1, ydst, dstPixel); + putPixel(gGraph->terrain, xdst, ydst+1, dstPixel); + putPixel(gGraph->terrain, xdst+1, ydst+1, dstPixel); + putPixel(gGraph->stencil, xdst, ydst, dstStencil); + putPixel(gGraph->stencil, xdst+1, ydst, dstStencil); + putPixel(gGraph->stencil, xdst, ydst+1, dstStencil); + putPixel(gGraph->stencil, xdst+1, ydst+1, dstStencil); } } } } SDL_UnlockSurface(tile); } - SDL_UnlockSurface(*stencil); - SDL_UnlockSurface(*terrain); + SDL_UnlockSurface(gGraph->stencil); + SDL_UnlockSurface(gGraph->terrain); return 0; } diff --git a/src/include/data_ini.h b/src/include/data_ini.h index ff1605c..b00d77a 100644 --- a/src/include/data_ini.h +++ b/src/include/data_ini.h @@ -4,6 +4,8 @@ #define LEVEL_WIDTH 1664*2 #define LEVEL_HEIGHT 160*2 +#include "SDL/SDL_stdinc.h" + struct styleObjects { int frames, anim, type, sound; }; diff --git a/src/include/graphic.h b/src/include/graphic.h index e8ce669..2e40301 100644 --- a/src/include/graphic.h +++ b/src/include/graphic.h @@ -4,6 +4,7 @@ #include "SDL/SDL.h" #include "data_ini.h" #include "data_ress.h" +#include "data_localgame.h" Uint32 getPixel(SDL_Surface *s, int x, int y); Uint32 getPixel8BitPalette(SDL_Surface *s, int x, int y); @@ -12,6 +13,6 @@ int isTransparent(SDL_Surface *s, int x, int y); void putPixel(SDL_Surface *s, int x, int y, Uint32 p); SDL_Surface * createSurface(int width, int height); SDL_Surface * loadGif(char *filePath); -int paintTerrain(gameIni_t *gIni, gameRess_t *gRess, SDL_Surface **terrain, SDL_Surface **stencil); +int paintTerrain(gameIni_t *gIni, gameRess_t *gRess, gameGraphics_t *gGraph); #endif /*GRAPHIC_H*/ diff --git a/src/include/loader.h b/src/include/loader.h index 027f15b..c1f08f7 100644 --- a/src/include/loader.h +++ b/src/include/loader.h @@ -5,5 +5,6 @@ #include "data_ress.h" int loadRessources(gameIni_t *gIni, gameRess_t *gRess); +int loadIni(gameIni_t *gIni, char *filepath); #endif /*LOADER_H*/ diff --git a/src/include/netlem_state_machine.h b/src/include/netlem_state_machine.h index 0bc9779..f0c41d4 100644 --- a/src/include/netlem_state_machine.h +++ b/src/include/netlem_state_machine.h @@ -26,7 +26,7 @@ typedef enum { state_t getState(); -state_t changeState(state_t s); -state_t changeStateAndNotify(state_t s, TCPsocket sockClient); +state_t changeState(state_t newState); +state_t changeStateAndNotify(state_t newState, TCPsocket sockClient); #endif /*NETLEM_STATE_MACHINE_H*/ diff --git a/src/include/parser.h b/src/include/parser.h index 9d2d59b..9e1ea59 100644 --- a/src/include/parser.h +++ b/src/include/parser.h @@ -17,6 +17,6 @@ #define STEEL_MAX_WIDTH 256 #define STEEL_MAX_HEIGHT 256 -void parse(gameIni_t *gIni); +int parse(gameIni_t *gIni); #endif /*PARSER_H*/ diff --git a/src/loader.c b/src/loader.c index de28df9..d3cce84 100644 --- a/src/loader.c +++ b/src/loader.c @@ -1,11 +1,16 @@ +#include "loader.h" + #include "SDL/SDL_stdinc.h" #include "SDL/SDL_image.h" -#include "loader.h" + +#include "parser.h" #include "graphic.h" #include "utils.h" #define PATH_STYLE "../styles" +extern FILE *yyin; + int loadRessources(gameIni_t *gIni, gameRess_t *gRess) { int i, filenamelen; char *filepath; @@ -69,3 +74,16 @@ int loadRessources(gameIni_t *gIni, gameRess_t *gRess) { free(filepath); return 0; } + +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; +} diff --git a/src/netlem.c b/src/netlem.c index 52750af..662b2f8 100644 --- a/src/netlem.c +++ b/src/netlem.c @@ -7,6 +7,7 @@ #include "data_localgame.h" #include "netgame.h" +#include "graphic.h" #include "utils.h" #include "game.h" @@ -26,9 +27,11 @@ struct _networkReadProc_args { }; struct _loadLevelProc_args { - serverParams_t *serverParams; + //serverParams_t *serverParams; + char *lvlIniFilePath; gameIni_t *gIni; gameRess_t *gRess; + gameGraphics_t *gGraph; Uint8 *loadProgress; }; @@ -42,10 +45,10 @@ int loadLevelProc(void *a); // Client-specific functions void signals(int signum); -int init(gameConfig_t *conf, gameGraphics_t *graph); +int init(gameConfig_t *conf, gameGraphics_t *gGraph); void loadGameConfig(gameConfig_t *conf); void processLocalEvents(); -int updateGraphics(); +int updateGraphics(gameGraphics_t *gGraph); int main(int argc, char **argv) { @@ -55,11 +58,11 @@ int main(int argc, char **argv) { Uint8 loadProgress=0; client_t client; - serverParams_t serverParams; + //serverParams_t serverParams; gameConfig_t conf; gameIni_t gIni; gameRess_t gRess; - gameGraphics_t graph; + gameGraphics_t gGraph; char logMsg[128]; struct _networkReadProc_args args; @@ -95,7 +98,7 @@ int main(int argc, char **argv) { loadGameConfig(&conf); // Libraries initialization - result=init(&conf, &graph); + result=init(&conf, &gGraph); if(result!=0) { logs(LOG_ERROR,"main(), init()"); return 3; @@ -116,7 +119,7 @@ int main(int argc, char **argv) { } // Worker thread for loading levels asynchronously (the thread begin with a SDL_Wait(semLevelLoadingStart)) - args2.serverParams=&serverParams; + //args2.serverParams=&serverParams; args2.gIni=&gIni; args2.gRess=&gRess; args2.loadProgress=&loadProgress; @@ -172,7 +175,7 @@ int main(int argc, char **argv) { } // Display that new game state to the local user - updateGraphics(); + updateGraphics(&gGraph); // Delay that we have to wait for the next frame (depends on execution time and network time drift) waitForNextTick(timeBefore_ms, drift_ms); @@ -204,7 +207,7 @@ void signals(int signum) { } } -int init(gameConfig_t *conf, gameGraphics_t *graph) { +int init(gameConfig_t *conf, gameGraphics_t *gGraph) { int result; @@ -218,8 +221,8 @@ int init(gameConfig_t *conf, gameGraphics_t *graph) { signal(2,signals); // Screen setup - graph->screen = SDL_SetVideoMode(conf->screen.w, conf->screen.h, SCREEN_BPP, SDL_HWSURFACE | SDL_DOUBLEBUF ); - if( graph->screen == NULL ) { + gGraph->screen = SDL_SetVideoMode(conf->screen.w, conf->screen.h, SCREEN_BPP, SDL_HWSURFACE | SDL_DOUBLEBUF ); + if( gGraph->screen == NULL ) { logs2(LOG_ERROR, "init(), SDL_SetVideoMode()", SDL_GetError()); return 2; } @@ -231,14 +234,14 @@ int init(gameConfig_t *conf, gameGraphics_t *graph) { SDL_ShowCursor(0); // Memory allocation and initialization for all display layers - graph->terrain = SDL_CreateRGBSurface(SDL_HWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, SCREEN_BPP,0,0,0,0); - if( graph->terrain == NULL ) { + gGraph->terrain = SDL_CreateRGBSurface(SDL_HWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, SCREEN_BPP,0,0,0,0); + if( gGraph->terrain == NULL ) { logs2(LOG_ERROR, "init(), SDL_CreateRGBSurface()", SDL_GetError()); return 3; } - graph->stencil = SDL_CreateRGBSurface(SDL_SWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, SCREEN_BPP,0,0,0,0); - if( graph->stencil == NULL ) { + gGraph->stencil = SDL_CreateRGBSurface(SDL_SWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, SCREEN_BPP,0,0,0,0); + if( gGraph->stencil == NULL ) { logs2(LOG_ERROR, "init(), SDL_CreateRGBSurface()", SDL_GetError()); return 3; } @@ -306,28 +309,59 @@ int startLoadLevel() { return result; } - +//FIXME : defines cnetraliser +#define PATH_STYLE "../styles" int loadLevelProc(void *a) { - int result,i; - //char logMsg[128]; + int res, len; + char *filepath; struct _loadLevelProc_args *args = (struct _loadLevelProc_args *)a; logs(LOG_WARN, "loadLevelProc(), beginnng"); while( getState() != eEnd ) { - result=SDL_SemWait(semLoadLevel); - if (result!=0) { + res=SDL_SemWait(semLoadLevel); + if (res!=0) { logs2(LOG_ERROR, "main(), SDL_SemTryWaitTimeout()", SDL_GetError()); - } logs(LOG_WARN, "loadLevelProc(), start load level"); + // Setting default values + memset(args->gIni,0,sizeof(gameIni_t)); + *(args->loadProgress)=1; + + // Loading lvl ini file + //snprintf(filepath, MAX_PATH_LEN, "%s/%s/%s", PATH_LEVEL, argv[1], argv[2]); + res=loadIni(args->gIni, args->lvlIniFilePath); + if (res==0) { + *(args->loadProgress)=10; + + // Check if we found a "style =" line in level ini file + if (args->gIni->level.style==NULL) { + logs(LOG_WARN, "No valid style detected\n"); + } else { + args->gIni->style.name=args->gIni->level.style; + + // Loading style ini file + len=strlen(PATH_STYLE)+2*strlen(args->gIni->level.style)+strlen("//.ini")+1; + filepath=malloc(sizeof(char)*len); + snprintf(filepath, len, "%s/%s/%s.ini", PATH_STYLE, args->gIni->level.style, args->gIni->level.style); + res=loadIni(args->gIni, filepath); + free(filepath); + if (res==0) { + *(args->loadProgress)=20; + res=loadRessources(args->gIni, args->gRess); + if (res==0) { + *(args->loadProgress)=50; + res=paintTerrain(args->gIni, args->gRess, args->gGraph); + if (res==0) { + *(args->loadProgress)=100; + } + } + } + } + } - - - - *(args->loadProgress)=100; logs(LOG_WARN, "loadLevelProc(), end load level"); } @@ -377,15 +411,17 @@ while( SDL_PollEvent( &event ) ) { */ } -int updateGraphics() { +int updateGraphics(gameGraphics_t *gGraph) { //TODO : modifier les calques - - - //Mise à jour de l'écran - - /*if( SDL_Flip(screen) == -1 ) { - return 4; - }*/ + switch(getState()) { + case eMultiWaitLoading: + case eMultiGame: + //TODO : implémenter un système de dirt rectangles + SDL_BlitSurface(gGraph->terrain, &(gGraph->terrain->clip_rect), gGraph->screen, NULL); + break; + default: + break; + } return 0; } diff --git a/src/netlem_state_machine.c b/src/netlem_state_machine.c index b9b7433..f6bb4bc 100644 --- a/src/netlem_state_machine.c +++ b/src/netlem_state_machine.c @@ -10,12 +10,12 @@ extern int startLoadLevel(); -state_t _getOrChangeState(state_t s, TCPsocket sockClient) { +state_t _getOrChangeState(state_t newState, TCPsocket sockClient) { const event_t evReady = {0,0,0,eReady,0,0,NULL,NULL}; static state_t state=eLaunching; int result; - switch(s) { + switch(newState) { case eNull: break; case eMultiLoading: @@ -26,7 +26,8 @@ state_t _getOrChangeState(state_t s, TCPsocket sockClient) { return eNull; } - state=s; + state=newState; + logs2(LOG_INFO, "changing state", "eMultiLoading"); break; case eMultiWaitLoading: //TODO : check current state before switching @@ -35,15 +36,17 @@ state_t _getOrChangeState(state_t s, TCPsocket sockClient) { result=sendEvent(sockClient, &evReady); if (result!=0) return eNull; - state=s; + state=newState; + logs2(LOG_INFO, "changing state", "eMultiWaitLoading"); break; case eMultiGame: //TODO : check current state before switching - logs(LOG_INFO, "Game started !"); - state=s; + state=newState; + logs2(LOG_INFO, "changing state", "eMultiGame"); break; case eEnd: - state=s; + state=newState; + logs2(LOG_INFO, "changing state", "eEnd"); break; default: @@ -58,11 +61,11 @@ state_t getState() { return _getOrChangeState(eNull, NULL); } -state_t changeState(state_t s) { - return _getOrChangeState(s, NULL); +state_t changeState(state_t newState) { + return _getOrChangeState(newState, NULL); } -state_t changeStateAndNotify(state_t s, TCPsocket sockClient) { - return _getOrChangeState(s, sockClient); +state_t changeStateAndNotify(state_t newState, TCPsocket sockClient) { + return _getOrChangeState(newState, sockClient); } diff --git a/src/parser/parse_ini.yy b/src/parser/parse_ini.yy index 4676110..4fb00d8 100644 --- a/src/parser/parse_ini.yy +++ b/src/parser/parse_ini.yy @@ -222,7 +222,9 @@ particles: INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INT $$[0]=$1; $$[1]=$3; $$[2]=$5; $$[3]=$7; $$[4]=$9; $$[5]=$11; $$[6]=$13; $$[7]=$15 ;$$[8]=$17; $$[9]=$19; $$[10]=$21; $$[11]=$23; $$[12]=$25; $$[13]=$27; $$[14]=$29; $$[15]=$31; } %% -void parse(gameIni_t *gIni) { +int parse(gameIni_t *gIni) { + int res=0; + //FIXME : récupérer les valeurs de retour gIni->firstPass=1; yyparse(gIni); @@ -234,6 +236,8 @@ void parse(gameIni_t *gIni) { rewind(yyin); gIni->firstPass=0; yyparse(gIni); + + return res; } void yyassert(int condition, char what[], char why[]){ diff --git a/src/test/testfunc_003_loadress.c b/src/test/testfunc_003_loadress.c index 7c1ed46..cf207cf 100644 --- a/src/test/testfunc_003_loadress.c +++ b/src/test/testfunc_003_loadress.c @@ -10,19 +10,6 @@ #define PATH_LEVEL "../level" #define MAX_PATH_LEN 255 -extern FILE *yyin; - -void load_ini(gameIni_t *gIni, char *filepath) { - yyin=fopen(filepath, "r"); - if (yyin == NULL ) { - fprintf(stderr, "main(), Could not open '%s'\n", filepath); - exit(2); - } -// printf("Parsing '%s'\n", filepath); - parse(gIni); - fclose(yyin); -} - int main(int argc, char **argv) { int res; char filepath[MAX_PATH_LEN]; @@ -41,11 +28,13 @@ int main(int argc, char **argv) { // Loading levelpack.ini snprintf(filepath, MAX_PATH_LEN, "%s/%s/levelpack.ini", PATH_LEVEL, argv[1]); - load_ini(&gIni, filepath); + res=loadIni(&gIni, filepath); + if (res!=0) exit(res); // Loading lvl ini file snprintf(filepath, MAX_PATH_LEN, "%s/%s/%s", PATH_LEVEL, argv[1], argv[2]); - load_ini(&gIni, filepath); + res=loadIni(&gIni, filepath); + if (res!=0) exit(res); // Check if we found a "style =" line in level ini file if (gIni.level.style==NULL) { @@ -56,7 +45,8 @@ int main(int argc, char **argv) { // Loading style ini file snprintf(filepath, MAX_PATH_LEN, "%s/%s/%s.ini", PATH_STYLE, gIni.level.style, gIni.level.style); - load_ini(&gIni, filepath); + res=loadIni(&gIni, filepath); + if (res!=0) exit(res); res=loadRessources(&gIni, &gRess); diff --git a/src/test/testfunc_004_buildterrain.c b/src/test/testfunc_004_buildterrain.c index 882f499..6be0015 100644 --- a/src/test/testfunc_004_buildterrain.c +++ b/src/test/testfunc_004_buildterrain.c @@ -12,25 +12,13 @@ #define PATH_TMP "/tmp" #define MAX_PATH_LEN 255 -extern FILE *yyin; - -void load_ini(gameIni_t *gIni, char *filepath) { - yyin=fopen(filepath, "r"); - if (yyin == NULL ) { - fprintf(stderr, "main(), Could not open '%s'\n", filepath); - exit(2); - } -// printf("Parsing '%s'\n", filepath); - parse(gIni); - fclose(yyin); -} int main(int argc, char **argv) { int res; char filepath[MAX_PATH_LEN]; gameIni_t gIni; gameRess_t gRess; - SDL_Surface *terrain=NULL, *stencil=NULL; + gameGraphics_t gGraph; if (argc != 3) { fprintf(stderr, "Usage %s \n", argv[0]); @@ -44,11 +32,13 @@ int main(int argc, char **argv) { // Loading levelpack.ini snprintf(filepath, MAX_PATH_LEN, "%s/%s/levelpack.ini", PATH_LEVEL, argv[1]); - load_ini(&gIni, filepath); + res=loadIni(&gIni, filepath); + if (res!=0) exit(res); // Loading lvl ini file snprintf(filepath, MAX_PATH_LEN, "%s/%s/%s", PATH_LEVEL, argv[1], argv[2]); - load_ini(&gIni, filepath); + res=loadIni(&gIni, filepath); + if (res!=0) exit(res); // Check if we found a "style =" line in level ini file if (gIni.level.style==NULL) { @@ -59,7 +49,8 @@ int main(int argc, char **argv) { // Loading style ini file snprintf(filepath, MAX_PATH_LEN, "%s/%s/%s.ini", PATH_STYLE, gIni.level.style, gIni.level.style); - load_ini(&gIni, filepath); + res=loadIni(&gIni, filepath); + if (res!=0) exit(res); res=loadRessources(&gIni, &gRess); @@ -75,19 +66,19 @@ int main(int argc, char **argv) { } SDL_UnlockSurface(tile); */ - res=paintTerrain(&gIni, &gRess, &terrain, &stencil); + res=paintTerrain(&gIni, &gRess, &gGraph); if (res!=0) { fprintf(stderr, "Cannot paintTerrain\n"); exit(3); } snprintf(filepath, MAX_PATH_LEN, "%s/%s_%s.bmp", PATH_TMP, argv[1], argv[2]); - res=SDL_SaveBMP(terrain, filepath); + res=SDL_SaveBMP(gGraph.terrain, filepath); if (res!=0) { fprintf(stderr, "Cannot SaveBMP\n"); exit(4); } snprintf(filepath, MAX_PATH_LEN, "%s/%s_%s-stencil.bmp", PATH_TMP, argv[1], argv[2]); - res=SDL_SaveBMP(stencil, filepath); + res=SDL_SaveBMP(gGraph.stencil, filepath); if (res!=0) { fprintf(stderr, "Cannot SaveBMP\n"); exit(4); -- cgit v1.2.3