stratagus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Stratagus-CVS] stratagus/src/map map_fog.c


From: Nehal Mistry
Subject: [Stratagus-CVS] stratagus/src/map map_fog.c
Date: Sat, 29 Nov 2003 19:47:08 -0500

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Nehal Mistry <address@hidden>   03/11/29 19:47:08

Modified files:
        src/map        : map_fog.c 

Log message:
        implement fow brightness

Patches:
Index: stratagus/src/map/map_fog.c
diff -u stratagus/src/map/map_fog.c:1.121 stratagus/src/map/map_fog.c:1.122
--- stratagus/src/map/map_fog.c:1.121   Fri Nov 28 20:35:34 2003
+++ stratagus/src/map/map_fog.c Sat Nov 29 19:47:08 2003
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: map_fog.c,v 1.121 2003/11/29 01:35:34 nehalmistry Exp $
+//     $Id: map_fog.c,v 1.122 2003/11/30 00:47:08 nehalmistry Exp $
 
 //@{
 
@@ -126,7 +126,7 @@
 
 local void (*VideoDrawUnexplored)(const int, int, int);
 local void (*VideoDrawFog)(const int, int, int);
-local void (*VideoDrawOnlyFog)(const int, int x, int y);
+local void (*VideoDrawOnlyFog)(int x, int y);
 #else
 /**
 **     Draw unexplored area function pointer. (display and video mode independ)
@@ -548,8 +548,10 @@
     SDL_BlitSurface(TheMap.TileGraphic->Surface, &srect, TheScreen, &drect);
 }
 
-global void VideoDrawOnlyFogSolid(const int tile, int x, int y)
+global void VideoDrawOnlyFogSolid(int x, int y)
 {
+    // FIXME:
+/*
     int tilepitch;
     SDL_Rect srect;
     SDL_Rect drect;
@@ -565,30 +567,45 @@
     drect.y = y;
 
     SDL_BlitSurface(TheMap.TileGraphic->Surface, &srect, TheScreen, &drect);
+*/
 }
 
-global void VideoDrawOnlyFogAlpha(const int tile, int x, int y)
+// FIXME: VERY MESSY | Looks different from old video code
+global void VideoDrawOnlyFogAlpha(int x, int y)
 {
-    int tilepitch;
-    int alpha;
-    SDL_Rect srect;
+    int i;
+    int j;
+    Uint16* p;
     SDL_Rect drect;
-
-    tilepitch = TheMap.TileGraphic->Width / TileSizeX;
-
-    srect.x = TileSizeX * (tile % tilepitch);
-    srect.y = TileSizeY * (tile / tilepitch);
-    srect.w = TileSizeX;
-    srect.h = TileSizeY;
+    SDL_Color csrc;
+    SDL_Color cdest;
+    unsigned char alpha;
 
     drect.x = x;
     drect.y = y;
 
-    alpha = TheMap.TileGraphic->Surface->format->alpha;
-    SDL_SetAlpha(TheMap.TileGraphic->Surface, SDL_SRCALPHA,
-       (100 - FogOfWarContrast) * 255 / 100);
-    SDL_BlitSurface(TheMap.TileGraphic->Surface, &srect, TheScreen, &drect);
-    SDL_SetAlpha(TheMap.TileGraphic->Surface, SDL_SRCALPHA, alpha);
+    SDL_BlitSurface(SolidFog, NULL, TheScreen, &drect);
+
+    csrc.r = 255;
+    csrc.g = 255;
+    csrc.b = 255;
+
+    alpha = (255 - FogOfWarBrightness * 255 / 100);
+
+    SDL_LockSurface(TheScreen);
+    for (i = y; i < y + TileSizeY; ++i) {
+       for (j = x; j < x + TileSizeX; ++j) {
+           p = &((Uint16*)TheScreen->pixels)[j + i * VideoWidth];
+           if (*p) {
+               SDL_GetRGB(*p, TheScreen->format, &cdest.r, &cdest.g, &cdest.b);
+               cdest.r = ((cdest.r * alpha) + (csrc.r * (255 - alpha))) >> 8;
+               cdest.g = ((cdest.g * alpha) + (csrc.g * (255 - alpha))) >> 8;
+               cdest.b = ((cdest.b * alpha) + (csrc.b * (255 - alpha))) >> 8;
+               *p = SDL_MapRGB(TheScreen->format, cdest.r, cdest.g, cdest.b);
+           }
+       }
+    }
+    SDL_UnlockSurface(TheScreen);
 }
 
 global void VideoDrawUnexploredSolid(const int tile, int x, int y)
@@ -610,12 +627,19 @@
     SDL_BlitSurface(TheMap.TileGraphic->Surface, &srect, TheScreen, &drect);
 }
 
+// FIXME: VERY MESSY
 global void VideoDrawFogAlpha(const int tile, int x, int y)
 {
+    int i;
+    int j;
+    Uint16* p;
+    Uint8* ptile;
     int tilepitch;
-    int alpha;
     SDL_Rect srect;
     SDL_Rect drect;
+    SDL_Color csrc;
+    SDL_Color cdest;
+    unsigned char alpha;
 
     tilepitch = TheMap.TileGraphic->Width / TileSizeX;
 
@@ -632,6 +656,31 @@
        (100 - FogOfWarContrast) * 255 / 100);
     SDL_BlitSurface(TheMap.TileGraphic->Surface, &srect, TheScreen, &drect);
     SDL_SetAlpha(TheMap.TileGraphic->Surface, SDL_SRCALPHA, alpha);
+
+    csrc.r = 255;
+    csrc.g = 255;
+    csrc.b = 255;
+
+    alpha = (255 - FogOfWarBrightness * 255 / 100);
+
+    SDL_LockSurface(TheScreen);
+    for (i = y; i < y + TileSizeY; ++i) {
+       for (j = x; j < x + TileSizeX; ++j) {
+           p = &((Uint16*)TheScreen->pixels)[j + i * VideoWidth];
+           ptile = &((Uint8*)TheMap.TileGraphic->Surface->pixels)[srect.x + j 
- x 
+               + srect.y + (i - y) * TheMap.TileGraphic->Surface->w];
+           SDL_GetRGB(*ptile, TheMap.TileGraphic->Surface->format, 
+               &cdest.r, &cdest.g, &cdest.b);
+           if (!(cdest.r | cdest.g | cdest.b) && *p) {
+               SDL_GetRGB(*p, TheScreen->format, &cdest.r, &cdest.g, &cdest.b);
+               cdest.r = ((cdest.r * alpha) + (csrc.r * (255 - alpha))) >> 8;
+               cdest.g = ((cdest.g * alpha) + (csrc.g * (255 - alpha))) >> 8;
+               cdest.b = ((cdest.b * alpha) + (csrc.b * (255 - alpha))) >> 8;
+               *p = SDL_MapRGB(TheScreen->format, cdest.r, cdest.g, cdest.b);
+           }
+       }
+    }
+    SDL_UnlockSurface(TheScreen);
 }
 #else
 // Routines for 8 bit displays .. --------------------------------------------
@@ -2766,11 +2815,7 @@
        }
     } else {
 #ifdef USE_SDL_SURFACE
-       SDL_Rect drect;
-       drect.x = dx;
-       drect.y = dy;
-       // Tile is fully FOW
-       SDL_BlitSurface(SolidFog, NULL, TheScreen, &drect);
+       VideoDrawOnlyFog(dx, dy);
 #else
        VideoDrawOnlyFog(TheMap.Tiles[UNEXPLORED_TILE], dx, dy);
 #endif




reply via email to

[Prev in Thread] Current Thread [Next in Thread]