diff options
Diffstat (limited to 'src/graphic.c')
-rw-r--r-- | src/graphic.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/graphic.c b/src/graphic.c index edbb799..f67613e 100644 --- a/src/graphic.c +++ b/src/graphic.c @@ -75,8 +75,8 @@ SDL_Surface * loadGif(char *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, paint; - Uint32 srcPixel, dstPixel, srcStencil, dstStencil; + int x,y,xmin,xmax,ymin,ymax,y2,xdst, ydst; + Uint32 dstPixel, dstStencil; SDL_Surface *tile; *terrain=createSurface(LEVEL_WIDTH, LEVEL_HEIGHT); @@ -121,9 +121,12 @@ 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é + // 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 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; } @@ -135,8 +138,8 @@ int paintTerrain(gameIni_t *gIni, gameRess_t *gRess, SDL_Surface **terrain, SDL_ xmax=min(tile->clip_rect.w, (*terrain)->clip_rect.w - gIni->level.terrains[i].xpos); SDL_LockSurface(tile); - for (y=ymin; y<ymax; y++) { - for (x=xmin; x<xmax; x++) { + for (y=ymin; y<ymax; y+=2) { + for (x=xmin; x<xmax; x+=2) { // If we have Upside Down modifier, count lines in reverse order if ( (gIni->level.terrains[i].modifier & 4) == 4 ) { y2=tile->clip_rect.h-1-y; @@ -146,30 +149,29 @@ int paintTerrain(gameIni_t *gIni, gameRess_t *gRess, SDL_Surface **terrain, SDL_ ydst=gIni->level.terrains[i].ypos+y; xdst=gIni->level.terrains[i].xpos+x; - // Act only if srcPixel is not transparent + // Act only if current pixel in tile is not transparent if ( ! isTransparent(tile, x, y2) ) { - // Grab current pixel and stencil state (from previous blits) - srcPixel=getPixel8BitPalette(tile, x, y2); - srcStencil=getPixel(*stencil, xdst, ydst); - - if ( (gIni->level.terrains[i].modifier & 8) == 8 ) { - paint=( getPixel(*stencil, xdst, ydst) != ccc_terrain ); - } else { - paint=1; - } - - if ( paint == 1 ) { - // If we have REMOVE modifier, dstPixel will be rolled back to bgColor, else, it will be identical to the source pixel + // 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 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 ) { dstPixel=gIni->style.bgColor; - dstStencil=0; + dstStencil=ccc_nothing; } else { - dstPixel=srcPixel; + dstPixel=getPixel8BitPalette(tile, x, y2); 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); } } } |