diff options
author | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2010-11-21 20:07:04 +0000 |
---|---|---|
committer | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2010-11-21 20:07:04 +0000 |
commit | 0ff965a42f0ad7ab72829b9941bef0b8c20aea45 (patch) | |
tree | aa7fa6df240b6e9795ac589c1f85be77b62b70ee /src | |
parent | 98ddc319bb1eed713fcf92f5d6e9628b41e10ae4 (diff) | |
download | 2010-netlemmings-0ff965a42f0ad7ab72829b9941bef0b8c20aea45.tar.gz 2010-netlemmings-0ff965a42f0ad7ab72829b9941bef0b8c20aea45.tar.bz2 2010-netlemmings-0ff965a42f0ad7ab72829b9941bef0b8c20aea45.zip |
Début de chargement des ressources à partir des infos récupérées dans les fichiers INI. Fichiers .h réorganisés (et quelques dépalcements dans les .c respectifs)
git-svn-id: file:///var/svn/2010-netlemmings/trunk@164 077b3477-7977-48bd-8428-443f22f7bfda
Diffstat (limited to 'src')
-rw-r--r-- | src/events.c | 7 | ||||
-rw-r--r-- | src/game.c | 80 | ||||
-rw-r--r-- | src/include/data_ini.h | 50 | ||||
-rw-r--r-- | src/include/data_lemming.h | 17 | ||||
-rw-r--r-- | src/include/data_localgame.h | 44 | ||||
-rw-r--r-- | src/include/data_network.h | 32 | ||||
-rw-r--r-- | src/include/data_ress.h | 12 | ||||
-rw-r--r-- | src/include/data_types.h | 10 | ||||
-rw-r--r-- | src/include/events.h | 22 | ||||
-rw-r--r-- | src/include/game.h | 67 | ||||
-rw-r--r-- | src/include/loader.h | 9 | ||||
-rw-r--r-- | src/include/netgame.h | 12 | ||||
-rw-r--r-- | src/loader.c | 29 | ||||
-rw-r--r-- | src/loader.h | 7 | ||||
-rw-r--r-- | src/netgame.c | 80 | ||||
-rw-r--r-- | src/netlem.c | 48 | ||||
-rw-r--r-- | src/netlem.h.in | 36 | ||||
-rw-r--r-- | src/netlem_ds.c | 7 | ||||
-rw-r--r-- | src/test/Makefile | 2 | ||||
-rw-r--r-- | src/test/test_load.c | 50 | ||||
-rwxr-xr-x | src/test/test_load.sh | 1 | ||||
-rw-r--r-- | src/utils.c | 5 |
22 files changed, 378 insertions, 249 deletions
diff --git a/src/events.c b/src/events.c index 95be9e9..976199b 100644 --- a/src/events.c +++ b/src/events.c @@ -1,5 +1,4 @@ -#include <stdlib.h> // calloc -#include <string.h> //memcpy +#include "SDL/SDL_stdinc.h" #include "events.h" @@ -10,12 +9,12 @@ inline int eventSerializedSize() { void eventSerialize(const event_t *e, char *buf) { //FIXME : A rendre portable - memcpy(buf,e,sizeof(event_t)); + SDL_memcpy(buf,e,sizeof(event_t)); } int eventUnserialize(event_t *e, char *buf) { //FIXME : A rendre portable et vérifier les champs - memcpy(e,buf,sizeof(event_t)); + SDL_memcpy(e,buf,sizeof(event_t)); return 0; } @@ -1,9 +1,5 @@ -#include <stdlib.h> // calloc -#include <string.h> // memset - #include "game.h" #include "utils.h" -#include "events.h" inline tick_t getGameCurrentTick(Uint32 startTime_ms) { /* char buf[128]; @@ -13,82 +9,6 @@ inline tick_t getGameCurrentTick(Uint32 startTime_ms) { return t/TICK_DURATION_MS; } -int initNetGgame(netGame_t *ng, id_t lemCount) { - memset(ng,0,sizeof(netGame_t)); - - eventListInit(&(ng->elist)); - - ng->lemCount=lemCount; - - ng->local.lems = calloc(lemCount,sizeof(stateLem_t)); - if (ng->local.lems==NULL) { logp(LOG_ERROR, "initNetGame(), calloc()"); return 3; } - - ng->net.lems = calloc(lemCount,sizeof(stateLem_t)); - if (ng->net.lems==NULL) { logp(LOG_ERROR, "initNetGame(), calloc()"); return 4; } - - return 0; -} - -void freeNetGame(netGame_t *ng) { - eventListFree(&(ng->elist)); - free(ng->local.lems); - free(ng->net.lems); -} - -// Serialize en envoi une trame d'évènement sur le réseau -int sendEvent(TCPsocket sockDest, const event_t *e) { - int msgLen, result; - char *buf; - - msgLen=eventSerializedSize(); - buf=malloc(msgLen); - if ( buf==NULL ) { - logp(LOG_ERROR, "sendEvent(), malloc()"); - return 1; - } - eventSerialize(e, buf); - - result=SDLNet_TCP_Send(sockDest,buf,msgLen); - free(buf); - if(result<msgLen) { - logs2(LOG_WARN, "sendEvent(), SDLNet_TCP_Send() error", SDLNet_GetError()); - return 2; - } - - return 0; -} - -// Attends de recevoir une trame d'évènement du réseau pour un client donné et l'envoi dans la file à traiter -int receiveEvent(client_t *c, event_t *e) { - int result, bufLen; - char *buf; - - bufLen=eventSerializedSize(); - buf=malloc(bufLen); - if (buf==NULL) { - logp(LOG_ERROR, "receiveEvent(), malloc()"); - return 1; - } - - // Réception de l'évènement - result=SDLNet_TCP_Recv(c->sockClient,buf,bufLen); // Appel bloquant - if(result<=0) { - logs(LOG_ERROR, "receiveEvent(), SDLNet_TCP_Recv() error"); - free(buf); - return 2; - } - - // Désérialisation de l'évènement - result=eventUnserialize(e,buf); - if ( result!=0 ) { - logs(LOG_WARN, "receiveEvent(), eventUnserialize() error"); - free(buf); - return 4; - } - - free(buf); - return 0; -} void play(int tick) { diff --git a/src/include/data_ini.h b/src/include/data_ini.h new file mode 100644 index 0000000..0efce09 --- /dev/null +++ b/src/include/data_ini.h @@ -0,0 +1,50 @@ +#ifndef DATA_INI_H +#define DATA_INI_H + +struct styleObjects { + int frames, anim, type, sound; +}; + +struct styleIni { + char *name; + uint32_t bgColor, debrisColor; + int tiles, particleColorCount, objectCount; + uint32_t *particleColor; + struct styleObjects *objects; +}; + +struct skills { + int releaseRate, numLemmings, numToRescue, timeLimit; + int numClimbers, numFloaters, numBlockers, numBombers, numBuilders, numBashers, numMiners, numDiggers; +}; + +// Item should be an object, terrain or steel +struct levelItem { + int id, xpos, ypos; // Common to all types (but no id for steel) + int paintMode, ud; // Specific to objects + int modifier; // Specific to terrain + int width, height; // Specific to steels +}; + +struct levelIni { + struct skills initSkills; + int xPos; + char *style, *name; + int superLemming; + int objectCount, terrainCount, steelCount; + struct levelItem *objects, *terrains, *steels; +}; + +struct levelPackIni { + int maxFallDistance; + char *codeSeed; +}; + +typedef struct { + struct styleIni style; + struct levelIni level; + struct levelPackIni levelPack; + int firstPass; +} gameIni_t; + +#endif /*DATA_INI_H*/ diff --git a/src/include/data_lemming.h b/src/include/data_lemming.h new file mode 100644 index 0000000..10f80cf --- /dev/null +++ b/src/include/data_lemming.h @@ -0,0 +1,17 @@ +#ifndef DATA_LEMMING_H +#define DATA_LEMMING_H + +#include "data_types.h" + +typedef struct { + unsigned int dead : 1; + unsigned int side : 1; + unsigned int flotter : 1; + unsigned int climber : 1; + unsigned int remainCount: 4; + unsigned int currRole: 4; + unsigned int animState: 4; + pos_t pos; +} stateLem_t; + +#endif /*DATA_LEMMING_H*/ diff --git a/src/include/data_localgame.h b/src/include/data_localgame.h new file mode 100644 index 0000000..45f7b2c --- /dev/null +++ b/src/include/data_localgame.h @@ -0,0 +1,44 @@ +#ifndef DATA_LOCALGAME_H +#define DATA_LOCALGAME_H + +#include "data_types.h" + +#define SCREEN_BPP 24 + +typedef enum { + eNull, // Pseudo_state for getOrChangeState : do not change state, just return current state + eLaunching, // Initial state, during system objects initialization + eSplash, // State for displaying Game Logo + eMenuMain, // State for main menu (next lines are sub-menus) + eMenuOptions, // State for general options (screen resolution, music...) + eMenuSingle, // State for single player options (level selection...) + eMenuMultiChooseServer, // State for network game server selection + eMenuMultiChooseOptions, // State for network game options selection (level, players, speed...) + eMultiWaitPlayers, // State for + eMultiLoading, // + eMultiWaitLoading, // + eMultiGame, // + eMultiReport, // + eSingleBrief, // State for single player level briefing (number of Lemmings to save...) + eSingleGame, // State for single player game (user is actually playing) + eSingleReport, // State for single player game report (number of saved Lemmings, access code...) + eCredits, // + eEnd // State reached when this program is exiting +} state_t; + +typedef struct { + SDL_Rect screen; + +} gameConfig_t; + +typedef struct { + SDL_Surface *screen, *terrain, *stencil; + pos_t viewport; // Viewport top-left corner coords in screen + +} gameGraphics_t; + +typedef struct { + id_t level; +} serverParams_t; + +#endif /*DATA_LOCALGAME_H*/ diff --git a/src/include/data_network.h b/src/include/data_network.h new file mode 100644 index 0000000..c12e9d2 --- /dev/null +++ b/src/include/data_network.h @@ -0,0 +1,32 @@ +#ifndef DATA_NETWORK_H +#define DATA_NETWORK_H + +#include "SDL/SDL_net.h" + +#include "data_types.h" +#include "data_lemming.h" +#include "events.h" + +#define DEFAULT_LISTEN_PORT 9999 + +enum clientState { clientNew, clientReady }; + +typedef struct _client_t { + int numClient; + enum clientState state; + TCPsocket sockClient; + eventList_t events; + SDL_sem *semEventAvailable; + SDL_sem *semGameStart; + int lastEventSendTime_ms; + //game_t *game; + stateLem_t *lems; +} client_t; + +typedef struct { + id_t lemCount; + eventList_t elist; + client_t local, net; //TODO : reprendre un peu, bcp de champs dupliqués pour rien +} netGame_t; + +#endif /* DATA_NETWORK_H */ diff --git a/src/include/data_ress.h b/src/include/data_ress.h new file mode 100644 index 0000000..7b5e599 --- /dev/null +++ b/src/include/data_ress.h @@ -0,0 +1,12 @@ +#ifndef DATA_RESS_H +#define DATA_RESS_H + +struct styleRess { + SDL_Surface **tiles, **objects, **objectMasks; +}; + +typedef struct { + struct styleRess style; +} gameRess_t; + +#endif /*DATA_RESS_H*/ diff --git a/src/include/data_types.h b/src/include/data_types.h new file mode 100644 index 0000000..20ac937 --- /dev/null +++ b/src/include/data_types.h @@ -0,0 +1,10 @@ +#ifndef DATA_TYPES_H +#define DATA_TYPES_H + +typedef int tick_t; +typedef unsigned int id_t; +typedef struct { + unsigned int x,y; +} pos_t; + +#endif /*DATA_TYPES_H*/ diff --git a/src/include/events.h b/src/include/events.h index 7f9ca50..46b8b30 100644 --- a/src/include/events.h +++ b/src/include/events.h @@ -2,9 +2,29 @@ #define EVENTS_H #include "SDL/SDL.h" -#include "game.h" +#include "data_types.h" #include "utils.h" +enum eventType_t { eReady, eTimeSync, eLemAction }; + +typedef struct _event_t { + id_t playerId; + tick_t eventTick; + tick_t serverTick; + + enum eventType_t type; + + id_t lemId; + unsigned int newRole: 4; + + struct _event_t *prev, *next; +} event_t; + +typedef struct { + event_t *first, *last; + SDL_mutex *lock; +} eventList_t; + int eventSerializedSize(); void eventSerialize(const event_t *e, char *buf); int eventUnserialize(event_t *e, char *buf); diff --git a/src/include/game.h b/src/include/game.h index 6bb1583..bcd902f 100644 --- a/src/include/game.h +++ b/src/include/game.h @@ -1,86 +1,25 @@ #ifndef GAME_H #define GAME_H -#define DEFAULT_LISTEN_PORT 9999 #define TICK_DURATION_MS 30 #define LEVEL_WIDTH 1664*2 #define LEVEL_HEIGHT 160*2 -#include "SDL/SDL_net.h" +#include "SDL/SDL.h" -typedef int tick_t; -typedef unsigned int id_t; -typedef struct { - unsigned int x,y; -} pos_t; - -enum eventType_t { eReady, eTimeSync, eLemAction }; +#include "data_types.h" -typedef struct { - unsigned int dead : 1; - unsigned int side : 1; - unsigned int flotter : 1; - unsigned int climber : 1; - unsigned int remainCount: 4; - unsigned int currRole: 4; - unsigned int animState: 4; - pos_t pos; -} stateLem_t; - enum gameState { gameNew, gameRunning, gameEnded }; typedef struct { enum gameState state; int startTime_ms; int clientCount; - struct _client_t **clients; + struct _client_t **clients; // FIXME: il y a toujours la boucle ? } game_t; -typedef struct _event_t { - id_t playerId; - tick_t eventTick; - tick_t serverTick; - - enum eventType_t type; - - id_t lemId; - unsigned int newRole: 4; - - struct _event_t *prev, *next; -} event_t; - -typedef struct { - event_t *first, *last; - SDL_mutex *lock; -} eventList_t; - -enum clientState { clientNew, clientReady }; - -typedef struct _client_t { - int numClient; - enum clientState state; - TCPsocket sockClient; - eventList_t events; - SDL_sem *semEventAvailable; - SDL_sem *semGameStart; - int lastEventSendTime_ms; - game_t *game; - stateLem_t *lems; -} client_t; - -typedef struct { - id_t lemCount; - eventList_t elist; - client_t local, net; //TODO : reprendre un peu, bcp de champs dupliqué pour rien -} netGame_t; - - tick_t getGameCurrentTick(Uint32 startTime_ms); -int initNetGame(netGame_t *ng, id_t lemCount); -void freeNetGame(netGame_t *ng); -int sendEvent(TCPsocket sockDest, const event_t *e); -int receiveEvent(client_t *c, event_t *e); void play(int tick); diff --git a/src/include/loader.h b/src/include/loader.h new file mode 100644 index 0000000..027f15b --- /dev/null +++ b/src/include/loader.h @@ -0,0 +1,9 @@ +#ifndef LOADER_H +#define LOADER_H + +#include "data_ini.h" +#include "data_ress.h" + +int loadRessources(gameIni_t *gIni, gameRess_t *gRess); + +#endif /*LOADER_H*/ diff --git a/src/include/netgame.h b/src/include/netgame.h new file mode 100644 index 0000000..d9f606b --- /dev/null +++ b/src/include/netgame.h @@ -0,0 +1,12 @@ +#ifndef NETGAME_H +#define NETGAME_H + +#include "data_network.h" +#include "events.h" + +int initNetGame(netGame_t *ng, id_t lemCount); +void freeNetGame(netGame_t *ng); +int sendEvent(TCPsocket sockDest, const event_t *e); +int receiveEvent(client_t *c, event_t *e); + +#endif /*NETGAME_H*/ diff --git a/src/loader.c b/src/loader.c index 6e38809..e744a9e 100644 --- a/src/loader.c +++ b/src/loader.c @@ -1,30 +1,31 @@ -#include <stdio.h> #include "loader.h" +#include "utils.h" #define PATH_STYLE "../styles/" -int loadRessources(struct gameInit *gInit) { + +int loadRessources(gameIni_t *gIni, gameRess_t *gRess) { int i; char *filepath, *kind; - filepath = malloc(sizeof(char)*(strlen(PATH_STYLE)+strlen(gInit->style.name)+strlen("/om_00.gif")+1)); + filepath = malloc(sizeof(char)*(strlen(PATH_STYLE)+strlen(gIni->style.name)+strlen("/om_00.gif")+1)); - gInit->ress.style.tiles=malloc(sizeof(SDL_Surface *)*gInit->style.tiles); + gRess->style.tiles=malloc(sizeof(SDL_Surface *)*gIni->style.tiles); //(if null...) - for(i=0; i < gInit->style.tiles ; ++i) { - sprintf(filepath, "%s/%s_%d.gif", PATH_STYLE, gInit->style.name, i); - gInit->ress.style.tiles[i] = load_image(filepath,ccc_keyGif); + for(i=0; i < gIni->style.tiles ; ++i) { + sprintf(filepath, "%s/%s_%d.gif", PATH_STYLE, gIni->style.name, i); + gRess->style.tiles[i] = load_image(filepath,ccc_keyGif); } - gInit->ress.style.objects=malloc(sizeof(SDL_Surface *)*gInit->style.objectCount); + gRess->style.objects=malloc(sizeof(SDL_Surface *)*gIni->style.objectCount); //(if null...) - gInit->ress.style.objectMasks=malloc(sizeof(SDL_Surface *)*gInit->style.objectCount); + gRess->style.objectMasks=malloc(sizeof(SDL_Surface *)*gIni->style.objectCount); //(if null...) - for(i=0; i < gInit->style.objectCount ; ++i) { - sprintf(filepath, "%s/%so_%d.gif", PATH_STYLE, gInit->style.name, i); - gInit->ress.style.objects[i] = load_image(filepath,ccc_keyGif); - sprintf(filepath, "%s/%som_%d.gif", PATH_STYLE, gInit->style.name, i); - gInit->ress.style.objectMasks[i] = load_image(filepath,ccc_keyGif); + for(i=0; i < gIni->style.objectCount ; ++i) { + sprintf(filepath, "%s/%so_%d.gif", PATH_STYLE, gIni->style.name, i); + gRess->style.objects[i] = load_image(filepath,ccc_keyGif); + sprintf(filepath, "%s/%som_%d.gif", PATH_STYLE, gIni->style.name, i); + gRess->style.objectMasks[i] = load_image(filepath,ccc_keyGif); } } diff --git a/src/loader.h b/src/loader.h deleted file mode 100644 index 7da7ff6..0000000 --- a/src/loader.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef LOADER_H -#define LOADER_H - -#include "parser/ginit.h" -int loadRessources(struct gameInit *gInit); - -#endif /*LOADER_H*/ diff --git a/src/netgame.c b/src/netgame.c new file mode 100644 index 0000000..ac64546 --- /dev/null +++ b/src/netgame.c @@ -0,0 +1,80 @@ +#include "netgame.h" + +#include "utils.h" + +int initNetGame(netGame_t *ng, id_t lemCount) { + memset(ng,0,sizeof(netGame_t)); + + eventListInit(&(ng->elist)); + + ng->lemCount=lemCount; + + ng->local.lems = calloc(lemCount,sizeof(stateLem_t)); + if (ng->local.lems==NULL) { logp(LOG_ERROR, "initNetGame(), calloc()"); return 3; } + + ng->net.lems = calloc(lemCount,sizeof(stateLem_t)); + if (ng->net.lems==NULL) { logp(LOG_ERROR, "initNetGame(), calloc()"); return 4; } + + return 0; +} + +void freeNetGame(netGame_t *ng) { + eventListFree(&(ng->elist)); + free(ng->local.lems); + free(ng->net.lems); +} + +// Serialize en envoi une trame d'évènement sur le réseau +int sendEvent(TCPsocket sockDest, const event_t *e) { + int msgLen, result; + char *buf; + + msgLen=eventSerializedSize(); + buf=malloc(msgLen); + if ( buf==NULL ) { + logp(LOG_ERROR, "sendEvent(), malloc()"); + return 1; + } + eventSerialize(e, buf); + + result=SDLNet_TCP_Send(sockDest,buf,msgLen); + free(buf); + if(result<msgLen) { + logs2(LOG_WARN, "sendEvent(), SDLNet_TCP_Send() error", SDLNet_GetError()); + return 2; + } + + return 0; +} + +// Attends de recevoir une trame d'évènement du réseau pour un client donné et l'envoi dans la file à traiter +int receiveEvent(client_t *c, event_t *e) { + int result, bufLen; + char *buf; + + bufLen=eventSerializedSize(); + buf=malloc(bufLen); + if (buf==NULL) { + logp(LOG_ERROR, "receiveEvent(), malloc()"); + return 1; + } + + // Réception de l'évènement + result=SDLNet_TCP_Recv(c->sockClient,buf,bufLen); // Appel bloquant + if(result<=0) { + logs(LOG_ERROR, "receiveEvent(), SDLNet_TCP_Recv() error"); + free(buf); + return 2; + } + + // Désérialisation de l'évènement + result=eventUnserialize(e,buf); + if ( result!=0 ) { + logs(LOG_WARN, "receiveEvent(), eventUnserialize() error"); + free(buf); + return 4; + } + + free(buf); + return 0; +} diff --git a/src/netlem.c b/src/netlem.c index cedbf93..9985b54 100644 --- a/src/netlem.c +++ b/src/netlem.c @@ -1,24 +1,20 @@ -#include <stdlib.h> -#include <stdio.h> -#include <signal.h> #include "SDL/SDL.h" #include "SDL/SDL_net.h" #include "SDL/SDL_thread.h" -#include "game.h" -#include "events.h" +#include "data_localgame.h" + +#include "netgame.h" #include "utils.h" +#include "game.h" +//#include "events.h" +#include "loader.h" + // Application version number #include "netlem.h" -//TODO : Trucs brouillons à déplacer à terme -typedef struct { - int todo; -} gameInit_t; -// Fin trucs brouillon - // Thread arguments structures struct _networkReadProc_args { client_t *client; @@ -28,7 +24,8 @@ struct _networkReadProc_args { struct _loadLevelProc_args { serverParams_t *serverParams; - gameInit_t *gInit; + gameIni_t *gIni; + gameRess_t *gRess; Uint8 *loadProgress; }; @@ -49,7 +46,6 @@ void processLocalEvents(); int updateGraphics(); - int main(int argc, char **argv) { int drift_ms=0,result; @@ -59,7 +55,8 @@ int main(int argc, char **argv) { client_t client; serverParams_t serverParams; gameConfig_t conf; - gameInit_t gInit; + gameIni_t gIni; + gameRess_t gRess; gameGraphics_t graph; char logMsg[128]; @@ -117,7 +114,8 @@ int main(int argc, char **argv) { // Worker thread for loading levels asynchronously (the thread begin with a SDL_Wait(semLevelLoadingStart)) args2.serverParams=&serverParams; - args2.gInit=&gInit; + args2.gIni=&gIni; + args2.gRess=&gRess; args2.loadProgress=&loadProgress; SDL_Thread *loadLevelThread = SDL_CreateThread(loadLevelProc, &args2); if(!loadLevelThread) { @@ -271,26 +269,14 @@ int init(gameConfig_t *conf, gameGraphics_t *graph) { //Désactiver le pointeur de la souris SDL_ShowCursor(0); // Allocation et initialisation des différents calques d'affichage et de collision - graph->pTerrain = SDL_CreateRGBSurface(SDL_HWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, SCREEN_BPP,0,0,0,0); - if( graph->pTerrain == NULL ) { - logs2(LOG_ERROR, "init(), SDL_CreateRGBSurface()", SDL_GetError()); - return 3; - } - - graph->pSpr_Lem = SDL_CreateRGBSurface(SDL_HWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT,SCREEN_BPP,0,0,0,0); - if( graph->pSpr_Lem == NULL ) { - logs2(LOG_ERROR, "init(), SDL_CreateRGBSurface()", SDL_GetError()); - return 3; - } - - graph->pStencil = SDL_CreateRGBSurface(SDL_SWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, SCREEN_BPP,0,0,0,0); - if( graph->pStencil == NULL ) { + graph->terrain = SDL_CreateRGBSurface(SDL_HWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, SCREEN_BPP,0,0,0,0); + if( graph->terrain == NULL ) { logs2(LOG_ERROR, "init(), SDL_CreateRGBSurface()", SDL_GetError()); return 3; } - graph->pStencilFixe = SDL_CreateRGBSurface(SDL_SWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, SCREEN_BPP,0,0,0,0); - if( graph->pStencilFixe == NULL ) { + graph->stencil = SDL_CreateRGBSurface(SDL_SWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, SCREEN_BPP,0,0,0,0); + if( graph->stencil == NULL ) { logs2(LOG_ERROR, "init(), SDL_CreateRGBSurface()", SDL_GetError()); return 3; } diff --git a/src/netlem.h.in b/src/netlem.h.in index 512746e..6f86000 100644 --- a/src/netlem.h.in +++ b/src/netlem.h.in @@ -5,42 +5,6 @@ #define NetLemmings_VERSION_MAJOR @NetLemmings_VERSION_MAJOR@ #define NetLemmings_VERSION_MINOR @NetLemmings_VERSION_MINOR@ -#define SCREEN_BPP 24 #define WIN_CAPTION "NetLemmings v@NetLemmings_VERSION_MAJOR@.@NetLemmings_VERSION_MINOR@" -typedef enum { - eNull, // Pseudo_state for getOrChangeState : do not change state, just return current state - eLaunching, // Initial state, during system objects initialization - eSplash, // State for displaying Game Logo - eMenuMain, // State for main menu (next lines are sub-menus) - eMenuOptions, // State for general options (screen resolution, music...) - eMenuSingle, // State for single player options (level selection...) - eMenuMultiChooseServer, // State for network game server selection - eMenuMultiChooseOptions, // State for network game options selection (level, players, speed...) - eMultiWaitPlayers, // State for - eMultiLoading, // - eMultiWaitLoading, // - eMultiGame, // - eMultiReport, // - eSingleBrief, // State for single player level briefing (number of Lemmings to save...) - eSingleGame, // State for single player game (user is actually playing) - eSingleReport, // State for single player game report (number of saved Lemmings, access code...) - eCredits, // - eEnd // State reached when this program is exiting -} state_t; - -typedef struct { - SDL_Rect screen; - -} gameConfig_t; - -typedef struct { - SDL_Surface *screen, *pTerrain, *pSpr_Lem, *pStencil, *pStencilFixe; - -} gameGraphics_t; - -typedef struct { - id_t level; -} serverParams_t; - #endif /*NETLEM_H*/ diff --git a/src/netlem_ds.c b/src/netlem_ds.c index e4bf007..fc4123c 100644 --- a/src/netlem_ds.c +++ b/src/netlem_ds.c @@ -1,13 +1,8 @@ -#include <stdlib.h> -#include <stdio.h> -#include <signal.h> - #include "SDL/SDL.h" #include "SDL/SDL_net.h" #include "SDL/SDL_thread.h" -#include "game.h" -#include "events.h" +#include "netgame.h" #include "utils.h" // Application version number and some constants diff --git a/src/test/Makefile b/src/test/Makefile index 88c7432..bf08627 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -6,7 +6,7 @@ test_lex: test_lex.c ../parser/lex.yy.c test_parse: test_parse.c ../parser/y.tab.c ../parser/lex.yy.c gcc -Wall --std=c99 -D_POSIX_SOURCE -g -o $@ $^ -test_load: test_load.c ../parser/y.tab.c ../parser/lex.yy.c +test_load: test_load.c ../parser/y.tab.c ../parser/lex.yy.c ../loader.c gcc -Wall --std=c99 -D_POSIX_SOURCE -g -o $@ $^ clean: -rm test_lex test_parse test_load diff --git a/src/test/test_load.c b/src/test/test_load.c new file mode 100644 index 0000000..91be214 --- /dev/null +++ b/src/test/test_load.c @@ -0,0 +1,50 @@ +#include <stdio.h> +#include <string.h> +#include "SDL/SDL.h" +#include "../parser/y.tab.h" +#include "../parser/ginit.h" +#include "../loader.h" + +#define PATH_STYLE "../styles" + +extern FILE *yyin; + +int main(int argc, char **argv) { + char *filepath=NULL; + struct gameInit gInit; + + if (argc<2) { + fprintf(stderr, "Usage %s <level_subfolder/ini_file>\n", argv[0]); + return 1; + } + filepath=argv[1]; + + yyin=fopen(filepath, "r"); + if (yyin == NULL ) { + fprintf(stderr, "main(), Could not open '%s'\n", filepath); + return 2; + } + memset(&gInit,0,sizeof(gInit)); + printf("Parsing '%s'\n", filepath); + parse(&gInit); + fclose(yyin); + + if (gInit.level.style==NULL) { + fprintf(stderr, "No valid style detected\n"); + exit(1); + } + filepath=malloc(sizeof(char)*(strlen(gInit.level.style)*2+strlen(PATH_STYLE)+5)); + sprintf(filepath, "%s/%s/%s.ini", PATH_STYLE, gInit.level.style, gInit.level.style); + + yyin=fopen(filepath, "r"); + if (yyin == NULL ) { + fprintf(stderr, "main(), Could not open '%s'\n", filepath); + return 2; + } + memset(&gInit,0,sizeof(gInit)); + printf("Parsing '%s'\n", filepath); + parse(&gInit); + fclose(yyin); + + return loadRessources(&gInit); +} diff --git a/src/test/test_load.sh b/src/test/test_load.sh new file mode 100755 index 0000000..0b744f9 --- /dev/null +++ b/src/test/test_load.sh @@ -0,0 +1 @@ +(cd ../parser/ && make) && make && cd ../../level && find -name 'lvl*.ini' -exec ../src/test/test_load {} \; 2>&1 | less diff --git a/src/utils.c b/src/utils.c index 0cbe483..635b325 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,8 +1,3 @@ -#include <stdlib.h> // exit() -#include <stdio.h> // FILE * -#include <string.h> // strerror() -#include <errno.h> - #include "utils.h" static FILE *fdLog=NULL; |