From 3f4026dd46e0eba4c6f60e78e58069c58cb1cb5c Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Wed, 17 Jul 2013 18:10:43 +0200 Subject: Debut implementataion loader mais début d'orage aussi MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/include/loader.h | 2 +- src/loader.c | 20 +++++++++++++++++++- src/parser.c | 6 +++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/include/loader.h b/src/include/loader.h index adf8777..81c39cb 100644 --- a/src/include/loader.h +++ b/src/include/loader.h @@ -5,6 +5,6 @@ #include "data_ress.h" // Load all textures needed for style and level from gIni -int loadRessources(gameIni_t *gIni, char databasepath[], gameRess_t *gRess); +int loadRessources(gameIni_t *gIni, char data_basepath[], gameRess_t *gRess); #endif /*LOADER_H*/ diff --git a/src/loader.c b/src/loader.c index 7a3d328..6e53298 100644 --- a/src/loader.c +++ b/src/loader.c @@ -1,6 +1,7 @@ #include "loader.h" #include "utils.h" /* mpl_check */ +#include #include #if ! SDL_VERSION_ATLEAST(2,0,0) #error "This code is only for SDL 2+. No backward compatibility with previous SDL versions, sorry." @@ -8,7 +9,24 @@ SDL_Texture * my_sdl_load_texture(SDL_Renderer *rend, char *giffilepath, SDL_Rect *size); -int loadRessources(gameIni_t *gIni, char databasepath[], gameRess_t *gRess) { +int loadRessources(gameIni_t *gIni, char data_basepath[], gameRess_t *gRess) { + int i, res, maxlen; + char *filepath; + + /* This is the lenght of the longest filepath we need in this proc */ + maxlen = strlen(databasepath) + 2*strlen(gIni->style.name) + sizeof("/style//om_00.gif"); + filepath = SDL_malloc(maxlen+1); + + for(i=0; i < gIni->style.tiles ; ++i) { + (void) SDL_snprintf(filepath, maxlen, "%s/style/%s/%s_%d.gif", data_basepath, gIni->style.name, gIni->style.name, i); + gRess->style.tiles[i] = loadGif(filepath); + if(gRess->style.tiles[i]==NULL) { + logs2(LOG_WARN, "loadRessources(), loadGif() error for ", filepath); + return 2; + } + } + + SDL_free(filepath); return 1; //FIXME } diff --git a/src/parser.c b/src/parser.c index 0720881..d34197d 100644 --- a/src/parser.c +++ b/src/parser.c @@ -61,9 +61,9 @@ } \ } while(0) -int callback_ini_style (const mTCHAR *section, const mTCHAR *key, const mTCHAR *value, const void *userData); -int callback_ini_levelpack (const mTCHAR *section, const mTCHAR *key, const mTCHAR *value, const void *userData); -int callback_ini_level(const mTCHAR *section, const mTCHAR *key, const mTCHAR *value, const void *userData); +int callback_ini_style (const mTCHAR *section, const mTCHAR *key, const mTCHAR *value, const void *userData); +int callback_ini_levelpack(const mTCHAR *section, const mTCHAR *key, const mTCHAR *value, const void *userData); +int callback_ini_level (const mTCHAR *section, const mTCHAR *key, const mTCHAR *value, const void *userData); // struct for void *UserData pointer (app context passed to each callback func) #define MAX_LINELEN 256 -- cgit v1.2.3