diff options
author | Ludovic Pouzenc <lpouzenc@gmail.com> | 2013-07-19 21:44:09 +0200 |
---|---|---|
committer | Ludovic Pouzenc <lpouzenc@gmail.com> | 2013-07-19 21:44:09 +0200 |
commit | 2dc612b3115e7391582a526be524971e19078425 (patch) | |
tree | 53dd65b5f0b3bb4e3f6345cbaa1599ab38cacad8 /src/graphic.c | |
parent | 9deb747bd914741a5a6f794568dfc9e53d8ec924 (diff) | |
download | mplemmings-2dc612b3115e7391582a526be524971e19078425.tar.gz mplemmings-2dc612b3115e7391582a526be524971e19078425.tar.bz2 mplemmings-2dc612b3115e7391582a526be524971e19078425.zip |
Debut adaptation paint_terrain(). Modif des tiles de texture vers
surfaces car blitting custom manuel.
Diffstat (limited to 'src/graphic.c')
-rw-r--r-- | src/graphic.c | 105 |
1 files changed, 61 insertions, 44 deletions
diff --git a/src/graphic.c b/src/graphic.c index 58d38f1..1a3fa1f 100644 --- a/src/graphic.c +++ b/src/graphic.c @@ -83,45 +83,63 @@ void my_SDL_init_or_die(char title[], SDL_Rect win_pos, Uint32 init_flags, Uint3 } //FIXME : to be implmented -#if 0 -int paint_terrain(gameIni_t *gIni, gameRess_t *gRess, gameGraphics_t *gGraph) { - int res, i, modifier; +int paint_terrain(gameIni_t *gIni, gameRess_t *gRess) { + int res, res2, i, modifier; int x,y,xmin,xmax,ymin,ymax,y2,xdst,ydst; - Uint32 dstPixel, dstStencil; + Uint32 dstPixel, dstStencil, rmask, gmask, bmask, amask; SDL_Surface *tile; - - gGraph->surfaces.terrain=createSurface(LEVEL_WIDTH, LEVEL_HEIGHT); - if (gGraph->surfaces.terrain==NULL) { - logs(LOG_ERROR, "paintTerrain(), SDL_CreateRGBSurface() returns NULL"); - return 1; - } - gGraph->surfaces.stencil=createSurface(LEVEL_WIDTH, LEVEL_HEIGHT); - if (gGraph->surfaces.stencil==NULL) { - logs(LOG_ERROR, "paintTerrain(), SDL_CreateRGBSurface() returns NULL"); - return 2; - } - - res=SDL_FillRect(gGraph->surfaces.terrain, &(gGraph->surfaces.terrain->clip_rect), gIni->style.bgColor); - if (res!=0) { - logs(LOG_WARN, "paintTerrain(), SDL_FillRect() failed"); - return 3; - } - - res=SDL_FillRect(gGraph->surfaces.stencil, &(gGraph->surfaces.stencil->clip_rect), ccc_nothing); - if (res!=0) { - logs(LOG_WARN, "paintTerrain(), SDL_FillRect() failed"); - return 4; - } - - SDL_LockSurface(gGraph->surfaces.terrain); - SDL_LockSurface(gGraph->surfaces.stencil); +/* Is necessary ? +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + rmask = 0xff000000; + gmask = 0x00ff0000; + bmask = 0x0000ff00; + amask = 0x000000ff; +#else + rmask = 0x000000ff; + gmask = 0x0000ff00; + bmask = 0x00ff0000; + amask = 0xff000000; +#endif +*/ + rmask = gmask = bmask = amask = 0; // Use default masks + gRess->terrain=SDL_CreateRGBSurface(0, LEVEL_WIDTH, LEVEL_HEIGHT, 32, rmask, gmask, bmask, amask); + gRess->stencil=SDL_CreateRGBSurface(0, LEVEL_WIDTH, LEVEL_HEIGHT, 32, rmask, gmask, bmask, amask); + + MPL_CHECK( + gRess->terrain && gRess->stencil, + { return 1; }, + SDL_LOG_PRIORITY_CRITICAL, + "paintTerrain(), SDL_CreateRGBSurface() failed" + ); + + /* Fill the entire surfaces with default color */ + res=SDL_FillRect(gRess->terrain, NULL, gIni->style.bgColor); + res2=SDL_FillRect(gRess->stencil, NULL, ccc_nothing); + MPL_CHECK( + res==0 && res2==0, + { return 2; }, + SDL_LOG_PRIORITY_CRITICAL, + "paintTerrain(), SDL_FillRect() failed" + ); + + SDL_LockSurface(gRess->terrain); + SDL_LockSurface(gRess->stencil); for(i=0 ; i < gIni->level.terrainCount ; i++) { - //FIXME : check sanity for id value - tile=gRess->style.tiles[gIni->level.terrains[i].id]; - if (tile==NULL) { - logs(LOG_ERROR, "paintTerrain(), tile==NULL"); - return 5; - } + int tid=gIni->level.terrains[i].id; + MPL_CHECK( + tid > 0 && tid < MAX_TILES_COUNT, + { return 3; }, + SDL_LOG_PRIORITY_CRITICAL, + "paintTerrain(), gIni->level.terrains[%].id == %i and it's out of range", i, tid + ); + + tile=gRess->tiles[tid]; + MPL_CHECK( + tile, + { return 4; }, + SDL_LOG_PRIORITY_CRITICAL, + "paintTerrain(), tile %i was not loaded", tid + ); // Special modifier values : @@ -145,9 +163,9 @@ int paint_terrain(gameIni_t *gIni, gameRess_t *gRess, gameGraphics_t *gGraph) { // 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, gGraph->surfaces.terrain->clip_rect.h - gIni->level.terrains[i].ypos); + ymax=min(tile->clip_rect.h, gRess->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, gGraph->surfaces.terrain->clip_rect.w - gIni->level.terrains[i].xpos); + xmax=min(tile->clip_rect.w, gRess->terrain->clip_rect.w - gIni->level.terrains[i].xpos); SDL_LockSurface(tile); for (y=ymin; y<ymax; y++) { @@ -166,7 +184,7 @@ int paint_terrain(gameIni_t *gIni, gameRess_t *gRess, gameGraphics_t *gGraph) { // 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 ( !( (modifier & 8) == 8 && - getPixel(gGraph->surfaces.stencil, xdst, ydst) == ccc_terrain ) ) { + getPixel(gRess->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 ( (modifier & 2) == 2 ) { dstPixel=gIni->style.bgColor; @@ -175,20 +193,19 @@ int paint_terrain(gameIni_t *gIni, gameRess_t *gRess, gameGraphics_t *gGraph) { dstPixel=getPixel8BitPalette(tile, x, y2); dstStencil=ccc_terrain; } - putPixel(gGraph->surfaces.terrain,xdst,ydst,dstPixel); - putPixel(gGraph->surfaces.stencil,xdst,ydst,dstStencil); + putPixel(gRess->terrain,xdst,ydst,dstPixel); + putPixel(gRess->stencil,xdst,ydst,dstStencil); } } } } SDL_UnlockSurface(tile); } - SDL_UnlockSurface(gGraph->surfaces.stencil); - SDL_UnlockSurface(gGraph->surfaces.terrain); + SDL_UnlockSurface(gRess->stencil); + SDL_UnlockSurface(gRess->terrain); return 0; } -#endif void render_all(SDL_Renderer *rend, render_item_t render_list[], int list_size) { int i, res; |