summaryrefslogtreecommitdiff
path: root/src/graphic.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphic.c')
-rw-r--r--src/graphic.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/graphic.c b/src/graphic.c
index dbdb55c..b1844a3 100644
--- a/src/graphic.c
+++ b/src/graphic.c
@@ -80,3 +80,110 @@ void my_SDL_init_or_die(char title[], SDL_Rect win_pos, Uint32 init_flags, Uint3
SDL_RenderGetViewport(*rend, viewport);
}
+//FIXME : to be implmented
+#if 0
+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;
+
+ 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);
+ 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;
+ }
+
+
+ // Special modifier values :
+ // 15 : Hidden : Lemini hack. Seems to be the same as NO_OVERRIDE
+
+ // Combinable modifier :
+ // 8 : NO_OVERRIDE : marquer les pixels comme indestructibles pour les prochains plaquages
+ // 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 (modifier == 15) {
+ modifier=8;
+ }
+
+ // If both REMOVE and NO_OVERRIDE is enabled, prefer NO_OVERRIDE (turn off REMOVE flag)
+ 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, gGraph->surfaces.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);
+
+ SDL_LockSurface(tile);
+ for (y=ymin; y<ymax; y++) {
+ for (x=xmin; x<xmax; x++) {
+ // If we have Upside Down modifier, count lines in reverse order
+ if (( modifier & 4) == 4 ) {
+ y2=tile->clip_rect.h-1-y;
+ } else {
+ y2=y;
+ }
+ ydst=gIni->level.terrains[i].ypos+y;
+ xdst=gIni->level.terrains[i].xpos+x;
+
+ // Act only if current pixel in tile is not transparent
+ 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 ( !( (modifier & 8) == 8 &&
+ getPixel(gGraph->surfaces.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;
+ dstStencil=ccc_nothing;
+ } else {
+ dstPixel=getPixel8BitPalette(tile, x, y2);
+ dstStencil=ccc_terrain;
+ }
+ putPixel(gGraph->surfaces.terrain,xdst,ydst,dstPixel);
+ putPixel(gGraph->surfaces.stencil,xdst,ydst,dstStencil);
+ }
+ }
+ }
+ }
+ SDL_UnlockSurface(tile);
+ }
+ SDL_UnlockSurface(gGraph->surfaces.stencil);
+ SDL_UnlockSurface(gGraph->surfaces.terrain);
+
+ return 0;
+}
+#endif