summaryrefslogtreecommitdiff
path: root/src/graphic.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphic.c')
-rw-r--r--src/graphic.c45
1 files changed, 24 insertions, 21 deletions
diff --git a/src/graphic.c b/src/graphic.c
index 934e87b..7f25437 100644
--- a/src/graphic.c
+++ b/src/graphic.c
@@ -82,19 +82,21 @@ void my_SDL_init_or_die(char title[], SDL_Rect win_pos, Uint32 init_flags, Uint3
SDL_RenderGetViewport(*rend, viewport);
}
+#define PIXEL32(s,x,y) (((Uint32 *)s->pixels)[y*s->w + x])
+
//FIXME : to be implmented
int paint_terrain(gameIni_t *gIni, gameRess_t *gRess) {
int res, res2, bpp;
-// int i, modifier;
-// int x,y,xmin,xmax,ymin,ymax,y2,xdst,ydst;
-// Uint32 dstPixel, dstStencil;
- Uint32 format, cc_nothing, rmask, gmask, bmask, amask;
-// SDL_Surface *tile;
+ int i, modifier;
+ int x,y,xmin,xmax,ymin,ymax,y2,xdst,ydst;
+ Uint32 srcPixel, dstPixel, dstStencil;
+ Uint32 cc_nothing, cc_terrain, rmask, gmask, bmask, amask;
+ SDL_Surface *tile;
- format=SDL_PIXELFORMAT_ARGB8888;
cc_nothing=0xFF000000; /* Make it portable (big endian) */
+ cc_terrain=0xFFFFAAAA; /* Make it portable (big endian) */
- res=SDL_PixelFormatEnumToMasks(format, &bpp, &rmask, &gmask, &bmask, &amask);
+ res=SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_ARGB8888, &bpp, &rmask, &gmask, &bmask, &amask);
MPL_CHECK(
res==SDL_TRUE,
{ return 1; },
@@ -113,7 +115,7 @@ int paint_terrain(gameIni_t *gIni, gameRess_t *gRess) {
/* Fill the entire surfaces with default color */
- res=SDL_FillRect(gRess->terrain, NULL, gIni->style.bgColor);
+ res =SDL_FillRect(gRess->terrain, NULL, gIni->style.bgColor);
res2=SDL_FillRect(gRess->stencil, NULL, cc_nothing);
MPL_CHECK(
res==0 && res2==0,
@@ -122,9 +124,8 @@ int paint_terrain(gameIni_t *gIni, gameRess_t *gRess) {
"paintTerrain(), SDL_FillRect() failed"
);
-#if 0
- SDL_LockSurface(gRess->terrain); /*XXX Only if RLE encoded. To be removed ? */
- SDL_LockSurface(gRess->stencil);
+ /* SDL_LockSurface(gRess->terrain); //XXX Only if RLE encoded. To be removed ?
+ SDL_LockSurface(gRess->stencil); */
for(i=0 ; i < gIni->level.terrainCount ; i++) {
int tid=gIni->level.terrains[i].id;
MPL_CHECK(
@@ -147,7 +148,7 @@ int paint_terrain(gameIni_t *gIni, gameRess_t *gRess) {
// 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
+ // 8 : NO_OVERRIDE : Don't change pixels that already set on destination
// 4 : Upside Down
// 2 : REMOVE : oublier (rendre transparent) tous les pixels qu'on a déjà plaqué
@@ -164,11 +165,11 @@ int paint_terrain(gameIni_t *gIni, gameRess_t *gRess) {
// 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, gRess->terrain->clip_rect.h - gIni->level.terrains[i].ypos);
+ ymax=SDL_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, gRess->terrain->clip_rect.w - gIni->level.terrains[i].xpos);
+ xmax=SDL_min(tile->clip_rect.w, gRess->terrain->clip_rect.w - gIni->level.terrains[i].xpos);
- SDL_LockSurface(tile);
+ //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
@@ -180,31 +181,33 @@ int paint_terrain(gameIni_t *gIni, gameRess_t *gRess) {
ydst=gIni->level.terrains[i].ypos+y;
xdst=gIni->level.terrains[i].xpos+x;
+ srcPixel = PIXEL32(tile, x, y2);
// Act only if current pixel in tile is not transparent
- if ( ! isTransparent(tile, x, y2) ) {
+ if ( (srcPixel & amask) != 0 ) {
// 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(gRess->stencil, xdst, ydst) == cc_terrain ) ) {
+ PIXEL32(gRess->stencil, xdst, ydst) == cc_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=cc_nothing;
} else {
- dstPixel=getPixel8BitPalette(tile, x, y2);
+ dstPixel=srcPixel;
dstStencil=cc_terrain;
}
- putPixel(gRess->terrain,xdst,ydst,dstPixel);
- putPixel(gRess->stencil,xdst,ydst,dstStencil);
+ PIXEL32(gRess->terrain,xdst,ydst)=dstPixel;
+ PIXEL32(gRess->stencil,xdst,ydst)=dstStencil;
}
}
}
}
SDL_UnlockSurface(tile);
}
+/*
SDL_UnlockSurface(gRess->stencil);
SDL_UnlockSurface(gRess->terrain);
-#endif
+*/
return 0;
}