summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Pouzenc <lpouzenc@gmail.com>2013-07-18 00:15:47 +0200
committerLudovic Pouzenc <lpouzenc@gmail.com>2013-07-18 00:15:47 +0200
commitf02db00ad4f41b4d098557a63461f6c5766c3273 (patch)
tree62a47e261960c441aef792931aa290f760606574
parent009f277764f45dd88ba0bb2b87bae0b024bf900e (diff)
downloadmplemmings-f02db00ad4f41b4d098557a63461f6c5766c3273.tar.gz
mplemmings-f02db00ad4f41b4d098557a63461f6c5766c3273.tar.bz2
mplemmings-f02db00ad4f41b4d098557a63461f6c5766c3273.zip
Debut paintTerrain() import depuis code de 2010
-rw-r--r--src/graphic.c107
-rw-r--r--src/include/graphic.h6
2 files changed, 112 insertions, 1 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
diff --git a/src/include/graphic.h b/src/include/graphic.h
index c1b2a42..6188af3 100644
--- a/src/include/graphic.h
+++ b/src/include/graphic.h
@@ -1,8 +1,12 @@
#ifndef GRAPHIC_H
#define GRAPHIC_H
-
#include <SDL.h>
+#include "data_ini.h"
+#include "data_ress.h"
+
void my_SDL_init_or_die(char title[], SDL_Rect win_pos, Uint32 init_flags, Uint32 win_flags, Uint32 rend_flags, SDL_Window **win, SDL_Renderer **rend, SDL_RendererInfo *rend_info, SDL_Rect *viewport);
+int paintTerrain(gameIni_t *gIni, gameRess_t *gRess, gameGraphics_t *gGraph);
+
#endif /*GRAPHIC_H*/