diff options
Diffstat (limited to 'src/netlem.c')
-rw-r--r-- | src/netlem.c | 102 |
1 files changed, 69 insertions, 33 deletions
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; } |