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 src/map/minimap.c s...


From: Nehal Mistry
Subject: [Stratagus-CVS] stratagus src/map/map_fog.c src/map/minimap.c s...
Date: Fri, 21 Nov 2003 22:00:28 -0500

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Nehal Mistry <address@hidden>   03/11/21 22:00:26

Modified files:
        src/map        : map_fog.c minimap.c 
        src/video      : linedraw.c png.c 
        tools          : wartool.c 

Log message:
        fix up fog of war on USE_SDL_SURFACE

Patches:
Index: stratagus/src/map/map_fog.c
diff -u stratagus/src/map/map_fog.c:1.117 stratagus/src/map/map_fog.c:1.118
--- stratagus/src/map/map_fog.c:1.117   Thu Nov 20 15:35:46 2003
+++ stratagus/src/map/map_fog.c Fri Nov 21 22:00:19 2003
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: map_fog.c,v 1.117 2003/11/20 20:35:46 n0body Exp $
+//     $Id: map_fog.c,v 1.118 2003/11/22 03:00:19 nehalmistry Exp $
 
 //@{
 
@@ -606,6 +606,29 @@
 
     SDL_BlitSurface(TheMap.TileGraphic->Surface, &srect, TheScreen, &drect);
 }
+
+global void VideoDrawFogAlpha(const int tile, int x, int y)
+{
+    int tilepitch;
+    int alpha;
+    SDL_Rect srect;
+    SDL_Rect drect;
+
+    tilepitch = TheMap.TileGraphic->Width / TileSizeX;
+
+    srect.x = TileSizeX * (tile % tilepitch);
+    srect.y = TileSizeY * (tile / tilepitch);
+    srect.w = TileSizeX;
+    srect.h = TileSizeY;
+
+    drect.x = x;
+    drect.y = y;
+
+    alpha = TheMap.TileGraphic->Surface->format->alpha;
+    SDL_SetAlpha(TheMap.TileGraphic->Surface, SDL_SRCALPHA, 128);
+    SDL_BlitSurface(TheMap.TileGraphic->Surface, &srect, TheScreen, &drect);
+    SDL_SetAlpha(TheMap.TileGraphic->Surface, SDL_SRCALPHA, alpha);
+}
 #else
 // Routines for 8 bit displays .. --------------------------------------------
 
@@ -1613,27 +1636,7 @@
 --     Draw real fog :-)
 ----------------------------------------------------------------------------*/
 
-#ifdef USE_SDL_SURFACE
-global void VideoDrawFogAlpha(const int tile, int x, int y)
-{
-    int tilepitch;
-    SDL_Rect srect;
-    SDL_Rect drect;
-
-    tilepitch = TheMap.TileGraphic->Width / TileSizeX;
-
-    srect.x = TileSizeX * (tile % tilepitch);
-    srect.y = TileSizeY * (tile / tilepitch);
-    srect.w = TileSizeX;
-    srect.y = TileSizeY;
-
-    drect.x = x;
-    drect.y = y;
-
-    SDL_BlitSurface(TheMap.TileGraphic->Surface, &srect, TheScreen, &drect);
-}
-
-#else
+#ifndef USE_SDL_SURFACE
 // Routines for 8 bit displays .. --------------------------------------------
 
 /**
@@ -2759,7 +2762,8 @@
        }
     } else {
 #ifdef USE_SDL_SURFACE
-       VideoDrawOnlyFog(UNEXPLORED_TILE, dx, dy);
+       // Tile is fully FOW
+       VideoFillTransRectangleClip(ColorBlack, dx, dy, TileSizeX, TileSizeY, 
128);
 #else
        VideoDrawOnlyFog(TheMap.Tiles[UNEXPLORED_TILE], dx, dy);
 #endif
@@ -2833,7 +2837,7 @@
                        MapDrawTile(UNEXPLORED_TILE, dx, dy);
 #else
 #ifdef USE_SDL_SURFACE
-                       VideoDrawTile(UNEXPLORED_TILE, dx, dy);
+                       VideoFillRectangleClip(ColorBlack, dx, dy, TileSizeX, 
TileSizeY);
 #else
                        VideoDrawTile(TheMap.Tiles[UNEXPLORED_TILE], dx, dy);
 #endif
Index: stratagus/src/map/minimap.c
diff -u stratagus/src/map/minimap.c:1.75 stratagus/src/map/minimap.c:1.76
--- stratagus/src/map/minimap.c:1.75    Thu Nov 20 15:35:47 2003
+++ stratagus/src/map/minimap.c Fri Nov 21 22:00:21 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: minimap.c,v 1.75 2003/11/20 20:35:47 n0body Exp $
+//     $Id: minimap.c,v 1.76 2003/11/22 03:00:21 nehalmistry Exp $
 
 //@{
 
@@ -142,7 +142,15 @@
            tile = TheMap.Fields[x + y].Tile;
 
 #ifdef USE_SDL_SURFACE
-           // FIXME: todod
+           // FIXME: todo
+           int xofs;
+           int yofs;
+           xofs = TileSizeX * (tile % TheMap.TileGraphic->Surface->w);
+           yofs = TileSizeY * (tile / TheMap.TileGraphic->Surface->w);
+           SDL_LockSurface(MinimapTerrainGraphic->Surface);
+           ((unsigned char*)MinimapTerrainGraphic->Surface->pixels)[mx + my * 
TheUI.MinimapW] =
+               ((unsigned char*)TheMap.TileGraphic->Surface->pixels)[7 + (mx % 
scalex) * 8 + (6 + (my % scaley) * 8) * TileSizeX];
+           SDL_UnlockSurface(MinimapTerrainGraphic->Surface);
 #else
            ((unsigned char*)MinimapTerrainGraphic->Frames)[mx + my * 
TheUI.MinimapW] =
                TheMap.Tiles[tile][7 + (mx % scalex) * 8 + (6 + (my % scaley) * 
8) * TileSizeX];
@@ -243,23 +251,8 @@
     MinimapTerrainGraphic = NewGraphic(8, TheUI.MinimapW, TheUI.MinimapH);
 
 #ifdef USE_SDL_SURFACE
-    Uint32 rmask, gmask, bmask, amask;
-// FIXME: use defines for this?
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-    rmask = 0xff000000;
-    gmask = 0x00ff0000;
-    bmask = 0x0000ff00;
-    amask = 0x000000ff;
-#else
-    rmask = 0x000000ff;
-    gmask = 0x0000ff00;
-    bmask = 0x00ff0000;
-    amask = 0xff000000;
-#endif
-    // FIXME: does NewGraphic do this for MinimapTerrainGraphic??
-    // FIXME: what depth?
     MinimapGraphic = SDL_CreateRGBSurface(SDL_SWSURFACE, TheUI.MinimapW,
-       TheUI.MinimapH, 8, rmask, gmask, bmask, amask);
+       TheUI.MinimapH, 8, RMASK, GMASK, BMASK, AMASK);
 #else
     memset(MinimapTerrainGraphic->Frames, 0, TheUI.MinimapW * TheUI.MinimapH);
     MinimapGraphic = calloc(TheUI.MinimapW * TheUI.MinimapH, sizeof(VMemType));
@@ -300,7 +293,7 @@
            for (x = MinimapX; x < TheUI.MinimapW - MinimapX; ++x) {
 #ifdef USE_SDL_SURFACE
                // FIXME: todo
-//             ((char*)MinimapGraphic->pixels)[x + y * TheUI.MinimapW] = 
ColorBlack;
+               VideoDrawPixel(ColorBlack, x, y);
 #else
                MinimapGraphic[x + y * TheUI.MinimapW] = ColorBlack;
 #endif
Index: stratagus/src/video/linedraw.c
diff -u stratagus/src/video/linedraw.c:1.46 stratagus/src/video/linedraw.c:1.47
--- stratagus/src/video/linedraw.c:1.46 Thu Nov 20 21:10:50 2003
+++ stratagus/src/video/linedraw.c      Fri Nov 21 22:00:22 2003
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: linedraw.c,v 1.46 2003/11/21 02:10:50 nehalmistry Exp $
+//     $Id: linedraw.c,v 1.47 2003/11/22 03:00:22 nehalmistry Exp $
 
 //@{
 
@@ -748,36 +748,43 @@
     SDL_FillRect(TheScreen, &drect, c);
 }
 
+global void VideoFillRectangleClip(SDL_Color color, int x, int y,
+    int w, int h)
+{
+    CLIP_RECTANGLE(x, y, w, h);
+    VideoFillRectangle(color, x, y, w, h);
+}
+
 global void VideoFillTransRectangle(SDL_Color color, int x, int y,
     int w, int h, unsigned char alpha)
 {
-    // FIXME: alpha
-    // FIXME: do clipping
-
     SDL_Rect drect;
-    Uint32 c = SDL_MapRGB(TheScreen->format, color.r, color.g, color.b);
+    SDL_Surface* s;
 
-    drect.x = x;
-    drect.y = y;
+    s = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA, w, h, 
+       32, RMASK, GMASK, BMASK, AMASK);
+
+    Uint32 c = SDL_MapRGBA(s->format, color.r, color.g, color.b, alpha);
+
+    drect.x = 0;
+    drect.y = 0;
     drect.w = w;
     drect.h = h;
 
-    SDL_FillRect(TheScreen, &drect, c);
-}
+    SDL_FillRect(s, &drect, c);
 
-global void VideoFillRectangleClip(SDL_Color color, int x, int y,
-    int w, int h)
-{
-    CLIP_RECTANGLE(x, y, w, h);
-    VideoFillRectangle(color, x, y, w, h);
+    drect.x = x;
+    drect.y = y;
+
+    SDL_BlitSurface(s, NULL, TheScreen, &drect);
+    SDL_FreeSurface(s);
 }
 
 global void VideoFillTransRectangleClip(SDL_Color color, int x, int y,
     int w, int h, unsigned char alpha)
 {
-    // FIXME: trans
     CLIP_RECTANGLE(x, y, w, h);
-    VideoFillRectangle(color, x, y, w, h);
+    VideoFillTransRectangle(color, x, y, w, h, alpha);
 }
 
 global void VideoDrawCircle(SDL_Color color, int x, int y, int r)
Index: stratagus/src/video/png.c
diff -u stratagus/src/video/png.c:1.27 stratagus/src/video/png.c:1.28
--- stratagus/src/video/png.c:1.27      Fri Nov 21 00:34:56 2003
+++ stratagus/src/video/png.c   Fri Nov 21 22:00:23 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: png.c,v 1.27 2003/11/21 05:34:56 nehalmistry Exp $
+//     $Id: png.c,v 1.28 2003/11/22 03:00:23 nehalmistry Exp $
 
 //@{
 
@@ -234,9 +234,7 @@
     graphic = MakeGraphic(8, w, h, data, w * h);       // data freed by make 
graphic
 #ifdef USE_SDL_SURFACE
     SDL_SetPalette(graphic->Surface, SDL_LOGPAL|SDL_PHYSPAL, palettecolors, 0, 
256);
-    SDL_SetColorKey(graphic->Surface, SDL_SRCCOLORKEY|SDL_RLEACCEL, 
-       SDL_MapRGB(graphic->Surface->format, palettecolors[255].r, 
-       palettecolors[255].g, palettecolors[255].b));
+    SDL_SetColorKey(graphic->Surface, SDL_SRCCOLORKEY|SDL_RLEACCEL, 255);
 #else
     graphic->Palette = palette;  //FIXME: should this be part of MakeGraphic
 #endif
Index: stratagus/tools/wartool.c
diff -u stratagus/tools/wartool.c:1.109 stratagus/tools/wartool.c:1.110
--- stratagus/tools/wartool.c:1.109     Fri Nov 14 18:55:22 2003
+++ stratagus/tools/wartool.c   Fri Nov 21 22:00:25 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: wartool.c,v 1.109 2003/11/14 23:55:22 mr-russ Exp $
+//     $Id: wartool.c,v 1.110 2003/11/22 03:00:25 nehalmistry Exp $
 
 //@{
 
@@ -1609,6 +1609,9 @@
     png_infop info_ptr;
     unsigned char** lines;
     int i;
+#ifdef USE_SDL_SURFACE
+    int j;
+#endif
 
     if( !(fp=fopen(name,"wb")) ) {
        printf("%s:",name);
@@ -1662,6 +1665,17 @@
        fclose(fp);
        return 1;
     }
+
+#ifdef USE_SDL_SURFACE
+    // So the engine doesn't need to support 2 transparent indexes
+    for (i = 0; i < h; ++i) {
+       for (j = 0; j < w; ++j) {
+           if (!image[j + i * w]) {
+               image[j + i * w] = 255;
+           }
+       }
+    }
+#endif
 
     for( i=0; i<h; ++i ) {
        lines[i]=image+i*w;




reply via email to

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