summaryrefslogtreecommitdiff
path: root/src/graphic.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphic.c')
-rw-r--r--src/graphic.c64
1 files changed, 33 insertions, 31 deletions
diff --git a/src/graphic.c b/src/graphic.c
index f67613e..a0587bc 100644
--- a/src/graphic.c
+++ b/src/graphic.c
@@ -73,37 +73,37 @@ SDL_Surface * loadGif(char *filePath) {
return IMG_Load(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;
+int paintTerrain(gameIni_t *gIni, gameRess_t *gRess, gameGraphics_t *gGraph) {
+ int res, i, modifier;
+ int x,y,xmin,xmax,ymin,ymax,y2,xdst,ydst;
Uint32 dstPixel, dstStencil;
SDL_Surface *tile;
- *terrain=createSurface(LEVEL_WIDTH, LEVEL_HEIGHT);
- if (*terrain==NULL) {
+ gGraph->terrain=createSurface(LEVEL_WIDTH, LEVEL_HEIGHT);
+ if (gGraph->terrain==NULL) {
logs(LOG_ERROR, "paintTerrain(), SDL_CreateRGBSurface() returns NULL");
return 1;
}
- *stencil=createSurface(LEVEL_WIDTH, LEVEL_HEIGHT);
- if (*stencil==NULL) {
+ gGraph->stencil=createSurface(LEVEL_WIDTH, LEVEL_HEIGHT);
+ if (gGraph->stencil==NULL) {
logs(LOG_ERROR, "paintTerrain(), SDL_CreateRGBSurface() returns NULL");
return 2;
}
- res=SDL_FillRect(*terrain, &((*terrain)->clip_rect), gIni->style.bgColor);
+ res=SDL_FillRect(gGraph->terrain, &(gGraph->terrain->clip_rect), gIni->style.bgColor);
if (res!=0) {
logs(LOG_WARN, "paintTerrain(), SDL_FillRect() failed");
return 3;
}
- res=SDL_FillRect(*stencil, &((*stencil)->clip_rect), ccc_nothing);
+ res=SDL_FillRect(gGraph->stencil, &(gGraph->stencil->clip_rect), ccc_nothing);
if (res!=0) {
logs(LOG_WARN, "paintTerrain(), SDL_FillRect() failed");
return 4;
}
- SDL_LockSurface(*terrain);
- SDL_LockSurface(*stencil);
+ SDL_LockSurface(gGraph->terrain);
+ SDL_LockSurface(gGraph->stencil);
for(i=0 ; i < gIni->level.terrainCount ; i++) {
//FIXME : check sanity for id value
tile=gRess->style.tiles[gIni->level.terrains[i].id];
@@ -121,27 +121,28 @@ 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é
+ modifier=gIni->level.terrains[i].modifier;
// 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 (modifier == 15) {
+ 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;
+ if ( (modifier & 10) == 10) {
+ modifier &= ~2;
}
// 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, (*terrain)->clip_rect.h - gIni->level.terrains[i].ypos);
+ ymax=min(tile->clip_rect.h, gGraph->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, (*terrain)->clip_rect.w - gIni->level.terrains[i].xpos);
+ xmax=min(tile->clip_rect.w, gGraph->terrain->clip_rect.w - gIni->level.terrains[i].xpos);
SDL_LockSurface(tile);
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 ) {
+ if (( modifier & 4) == 4 ) {
y2=tile->clip_rect.h-1-y;
} else {
y2=y;
@@ -153,10 +154,10 @@ int paintTerrain(gameIni_t *gIni, gameRess_t *gRess, SDL_Surface **terrain, SDL_
if ( ! isTransparent(tile, x, y2) ) {
// 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 ( !( (modifier & 8) == 8 &&
+ getPixel(gGraph->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 ) {
+ if ( (modifier & 2) == 2 ) {
dstPixel=gIni->style.bgColor;
dstStencil=ccc_nothing;
} else {
@@ -164,22 +165,23 @@ int paintTerrain(gameIni_t *gIni, gameRess_t *gRess, SDL_Surface **terrain, SDL_
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);
+ //FIXME : optimiser le nombre d'appels ici !
+ putPixel(gGraph->terrain, xdst, ydst, dstPixel);
+ putPixel(gGraph->terrain, xdst+1, ydst, dstPixel);
+ putPixel(gGraph->terrain, xdst, ydst+1, dstPixel);
+ putPixel(gGraph->terrain, xdst+1, ydst+1, dstPixel);
+ putPixel(gGraph->stencil, xdst, ydst, dstStencil);
+ putPixel(gGraph->stencil, xdst+1, ydst, dstStencil);
+ putPixel(gGraph->stencil, xdst, ydst+1, dstStencil);
+ putPixel(gGraph->stencil, xdst+1, ydst+1, dstStencil);
}
}
}
}
SDL_UnlockSurface(tile);
}
- SDL_UnlockSurface(*stencil);
- SDL_UnlockSurface(*terrain);
+ SDL_UnlockSurface(gGraph->stencil);
+ SDL_UnlockSurface(gGraph->terrain);
return 0;
}