Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2004:
[Freeciv-Dev] (PR#7461) move nuke animation into mapview_common
Home

[Freeciv-Dev] (PR#7461) move nuke animation into mapview_common

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#7461) move nuke animation into mapview_common
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 21 Feb 2004 15:43:06 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=7461 >

This patch accomplishes a few things.

The main goal is to move the nuke animation (put_nuke_mushroom_pixmaps) 
into mapview_common.  (Currently the "animation" is just a single sprite 
left on the screen for 1 second.  However I think Arnstein and Rafal 
were working on real animation.)

To do this properly two new GUI functions were needed: 
get_sprite_dimensions() and gui_flush().  The former just gives the 
width and height of the sprite (encoded in the sprite structure but not 
available to the common code).  The latter calls gdk_flush() or whatever 
other hardware-flush function is available.

At the same time I changed the non-iso nuke drawing to be the same as 
the iso-view drawing.  This is easy to do and obviously better (it fits 
a fixme comment already in place).  It cuts down on code and avoids bugs 
in the old method (flickering and misplaced nuke images).

The logic of the function is slightly changed becase we have to copy to 
the canvas store, then flush to the screen.  This is probably a good 
thing.  However it means we have to do a full update_map_canvas_visible 
at the end to restore the original screen (this was being done already, 
but it was unnecessary).  If we had a second backing store (the same 
size as the nuke sprite) we could make a backup copy and avoid this 
update.  But this is unnecessary (a full update is trivial compared to a 
1-second wait).

Support is included for gtk2, gtk, xaw, and win32 clients.  I've tested 
the gtk2 client in iso and non-iso views.  The others I've compiled but 
not tested.

jason

? foo-game.gz
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.79
diff -u -r1.79 mapview_common.c
--- client/mapview_common.c     2004/02/21 22:15:03     1.79
+++ client/mapview_common.c     2004/02/21 23:25:21
@@ -697,6 +697,32 @@
   }
 }
 
+/****************************************************************************
+  Animate the nuke explosion at map(x, y).
+****************************************************************************/
+void put_nuke_mushroom_pixmaps(int map_x, int map_y)
+{
+  int canvas_x, canvas_y;
+  struct Sprite *mysprite = sprites.explode.nuke;
+  int width, height;
+
+  /* We can't count on the return value of map_to_canvas_pos since the
+   * sprite may span multiple tiles. */
+  (void) map_to_canvas_pos(&canvas_x, &canvas_y, map_x, map_y);
+  get_sprite_dimensions(mysprite, &width, &height);
+
+  canvas_x += (NORMAL_TILE_WIDTH - width) / 2;
+  canvas_y += (NORMAL_TILE_HEIGHT - height) / 2;
+
+  gui_put_sprite_full(mapview_canvas.store, canvas_x, canvas_y, mysprite);
+  flush_mapcanvas(canvas_x, canvas_y, width, height);
+  gui_flush();
+
+  myusleep(1000000);
+
+  update_map_canvas_visible();
+}
+
 /**************************************************************************
    Draw the borders of the given map tile at the given canvas position
    in non-isometric view.
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.44
diff -u -r1.44 mapview_common.h
--- client/mapview_common.h     2004/02/21 22:15:03     1.44
+++ client/mapview_common.h     2004/02/21 23:25:21
@@ -168,6 +168,7 @@
 void put_unit_city_overlays(struct unit *punit,
                            struct canvas_store *pcanvas_store,
                            int canvas_x, int canvas_y);
+void put_nuke_mushroom_pixmaps(int map_x, int map_y);
 
 void put_one_tile(struct canvas_store *pcanvas_store, int map_x, int map_y,
                  int canvas_x, int canvas_y, bool citymode);
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.141
diff -u -r1.141 tilespec.c
--- client/tilespec.c   2004/02/20 15:57:18     1.141
+++ client/tilespec.c   2004/02/21 23:25:22
@@ -921,16 +921,7 @@
   SET_SPRITE_OPT(road.corner[DIR8_SOUTHWEST], "r.c_road_sw");
   SET_SPRITE_OPT(road.corner[DIR8_SOUTHEAST], "r.c_road_se");
 
-  if (is_isometric) {
-    SET_SPRITE(explode.iso_nuke, "explode.iso_nuke");
-  } else {
-    for(i=0; i<3; i++) {
-      for(j=0; j<3; j++) {
-       my_snprintf(buffer, sizeof(buffer), "explode.nuke_%d%d", i, j);
-       SET_SPRITE(explode.nuke[i][j], buffer);
-      }
-    }
-  }
+  SET_SPRITE(explode.nuke, "explode.nuke");
 
   num_tiles_explode_unit = 0;
   do {
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.53
diff -u -r1.53 tilespec.h
--- client/tilespec.h   2004/02/20 15:57:18     1.53
+++ client/tilespec.h   2004/02/21 23:25:22
@@ -148,9 +148,8 @@
       *corner[NUM_DIRECTION_NSEW]; /* only diagonal directions used */
   } road, rail;
   struct {
-    struct Sprite *nuke[3][3];          /* row, column, from top-left */
     struct Sprite **unit;
-    struct Sprite *iso_nuke;
+    struct Sprite *nuke;
   } explode;
   struct {
     struct Sprite
Index: client/gui-gtk/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/graphics.c,v
retrieving revision 1.51
diff -u -r1.51 graphics.c
--- client/gui-gtk/graphics.c   2003/07/15 01:04:54     1.51
+++ client/gui-gtk/graphics.c   2004/02/21 23:25:22
@@ -187,6 +187,14 @@
   return ctor_sprite_mask(mypixmap, mask, width, height);
 }
 
+/****************************************************************************
+  Find the dimensions of the sprite.
+****************************************************************************/
+void get_sprite_dimensions(struct Sprite *sprite, int *w, int *h)
+{
+  *w = sprite->width;
+  *h = sprite->height;
+}
 
 /***************************************************************************
 ...
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.196
diff -u -r1.196 mapview.c
--- client/gui-gtk/mapview.c    2004/02/21 22:15:03     1.196
+++ client/gui-gtk/mapview.c    2004/02/21 23:25:23
@@ -618,6 +618,14 @@
   num_dirty_rects = 0;
 }
 
+/****************************************************************************
+  Do any necessary flushes to make sure the screen is up-to-date.
+****************************************************************************/
+void gui_flush(void)
+{
+  gdk_flush();
+}
+
 /**************************************************************************
  Update display of descriptions associated with cities on the main map.
 **************************************************************************/
@@ -731,55 +739,6 @@
   struct canvas_store store = {NULL, p};
 
   put_unit_city_overlays(punit, &store, 0, NORMAL_TILE_HEIGHT);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void put_nuke_mushroom_pixmaps(int x, int y)
-{
-  if (is_isometric) {
-    int canvas_x, canvas_y;
-    struct Sprite *mysprite = sprites.explode.iso_nuke;
-
-    (void) map_to_canvas_pos(&canvas_x, &canvas_y, x, y);
-    canvas_x += NORMAL_TILE_WIDTH/2 - mysprite->width/2;
-    canvas_y += NORMAL_TILE_HEIGHT/2 - mysprite->height/2;
-
-    pixmap_put_overlay_tile(map_canvas->window, canvas_x, canvas_y,
-                           mysprite);
-
-    gdk_flush();
-    myusleep(1000000);
-
-    update_map_canvas_visible();
-  } else {
-    int x_itr, y_itr;
-    int canvas_x, canvas_y;
-
-    for (y_itr=0; y_itr<3; y_itr++) {
-      for (x_itr=0; x_itr<3; x_itr++) {
-       struct Sprite *mysprite = sprites.explode.nuke[y_itr][x_itr];
-       if (!map_to_canvas_pos(&canvas_x, &canvas_y,
-                              x + x_itr - 1, y + y_itr - 1)) {
-         continue;
-       }
-
-       gdk_draw_pixmap(single_tile_pixmap, civ_gc, map_canvas_store,
-                       canvas_x, canvas_y, 0, 0,
-                       NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT);
-       pixmap_put_overlay_tile(single_tile_pixmap, 0, 0, mysprite);
-       gdk_draw_pixmap(map_canvas->window, civ_gc, single_tile_pixmap,
-                       0, 0, canvas_x, canvas_y,
-                       NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT);
-      }
-    }
-
-    gdk_flush();
-    myusleep(1000000);
-
-    update_map_canvas(x-1, y-1, 3, 3, TRUE);
-  }
 }
 
 /**************************************************************************
Index: client/gui-gtk-2.0/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/graphics.c,v
retrieving revision 1.22
diff -u -r1.22 graphics.c
--- client/gui-gtk-2.0/graphics.c       2003/11/10 02:53:53     1.22
+++ client/gui-gtk-2.0/graphics.c       2004/02/21 23:25:23
@@ -188,6 +188,14 @@
   return ctor_sprite_mask(mypixmap, mask, width, height);
 }
 
+/****************************************************************************
+  Find the dimensions of the sprite.
+****************************************************************************/
+void get_sprite_dimensions(struct Sprite *sprite, int *w, int *h)
+{
+  *w = sprite->width;
+  *h = sprite->height;
+}
 
 /***************************************************************************
 ...
Index: client/gui-gtk-2.0/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapview.c,v
retrieving revision 1.96
diff -u -r1.96 mapview.c
--- client/gui-gtk-2.0/mapview.c        2004/02/21 22:15:03     1.96
+++ client/gui-gtk-2.0/mapview.c        2004/02/21 23:25:23
@@ -646,6 +646,14 @@
   gdk_window_process_updates(map_canvas->window, FALSE);
 }
 
+/****************************************************************************
+  Do any necessary flushes to make sure the screen is up-to-date.
+****************************************************************************/
+void gui_flush(void)
+{
+  gdk_flush();
+}
+
 /**************************************************************************
  Update display of descriptions associated with cities on the main map.
 **************************************************************************/
@@ -801,58 +809,6 @@
   put_unit_city_overlays(punit, &store, 0, NORMAL_TILE_HEIGHT);
 
   gtk_pixcomm_thaw(p);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void put_nuke_mushroom_pixmaps(int x, int y)
-{
-  if (is_isometric) {
-    int canvas_x, canvas_y;
-    struct Sprite *mysprite = sprites.explode.iso_nuke;
-
-    /* We can't count on the return value of map_to_canvas_pos since the
-     * sprite may span multiple tiles. */
-    (void) map_to_canvas_pos(&canvas_x, &canvas_y, x, y);
-
-    canvas_x += NORMAL_TILE_WIDTH/2 - mysprite->width/2;
-    canvas_y += NORMAL_TILE_HEIGHT/2 - mysprite->height/2;
-
-    pixmap_put_overlay_tile(map_canvas->window, canvas_x, canvas_y,
-                           mysprite);
-
-    gdk_flush();
-    myusleep(1000000);
-
-    update_map_canvas_visible();
-  } else {
-    int x_itr, y_itr;
-    int canvas_x, canvas_y;
-
-    for (y_itr=0; y_itr<3; y_itr++) {
-      for (x_itr=0; x_itr<3; x_itr++) {
-       struct Sprite *mysprite = sprites.explode.nuke[y_itr][x_itr];
-       if (!map_to_canvas_pos(&canvas_x, &canvas_y,
-                              x + x_itr - 1, y + y_itr - 1)) {
-         continue;
-       }
-
-       gdk_draw_drawable(single_tile_pixmap, civ_gc, map_canvas_store,
-                         canvas_x, canvas_y, 0, 0,
-                         NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT);
-       pixmap_put_overlay_tile(single_tile_pixmap, 0, 0, mysprite);
-       gdk_draw_drawable(map_canvas->window, civ_gc, single_tile_pixmap,
-                         0, 0, canvas_x, canvas_y,
-                         NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT);
-      }
-    }
-
-    gdk_flush();
-    myusleep(1000000);
-
-    update_map_canvas(x-1, y-1, 3, 3, TRUE);
-  }
 }
 
 /**************************************************************************
Index: client/gui-win32/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/graphics.c,v
retrieving revision 1.15
diff -u -r1.15 graphics.c
--- client/gui-win32/graphics.c 2003/11/09 12:09:52     1.15
+++ client/gui-win32/graphics.c 2004/02/21 23:25:23
@@ -240,6 +240,14 @@
   return mysprite;
 }
 
+/****************************************************************************
+  Find the dimensions of the sprite.
+****************************************************************************/
+void get_sprite_dimensions(struct Sprite *sprite, int *w, int *h)
+{
+  *w = sprite->width;
+  *h = sprite->height;
+}
 
 /**************************************************************************
 
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.91
diff -u -r1.91 mapview.c
--- client/gui-win32/mapview.c  2004/02/21 22:15:03     1.91
+++ client/gui-win32/mapview.c  2004/02/21 23:25:24
@@ -559,6 +559,14 @@
   num_dirty_rects = 0;
 }
 
+/****************************************************************************
+  Do any necessary flushes to make sure the screen is up-to-date.
+****************************************************************************/
+void gui_flush(void)
+{
+  GdiFlush();
+}
+
 /**************************************************************************
 
 **************************************************************************/
@@ -819,45 +827,6 @@
   refresh_tile_mapcanvas(punit1->x, punit1->y, TRUE);
   
 }
-
-/**************************************************************************
-
-**************************************************************************/
-void
-put_nuke_mushroom_pixmaps(int x, int y)
-{
-  
-  HDC hdc;
-  hdc=GetDC(map_window);
-  if (is_isometric) {
-    int canvas_x, canvas_y;
-    struct Sprite *mysprite = sprites.explode.iso_nuke;  
-    get_canvas_xy(x, y, &canvas_x, &canvas_y);
-    canvas_x += NORMAL_TILE_WIDTH/2 - mysprite->width/2;
-    canvas_y += NORMAL_TILE_HEIGHT/2 - mysprite->height/2;
-    draw_sprite(mysprite,hdc,canvas_x,canvas_y);
-    GdiFlush();
-    ReleaseDC(map_window,hdc);
-    Sleep(1000);
-    update_map_canvas_visible();
-  } else {
-    int x_itr, y_itr;
-    int canvas_x, canvas_y;
-    
-    for (y_itr=0; y_itr<3; y_itr++) {
-      for (x_itr=0; x_itr<3; x_itr++) {
-        struct Sprite *mysprite = sprites.explode.nuke[y_itr][x_itr];
-        get_canvas_xy(x + x_itr - 1, y + y_itr - 1, &canvas_x, &canvas_y);
-       draw_sprite(mysprite,hdc,canvas_x,canvas_y);
-      }
-    }
-    GdiFlush();
-    ReleaseDC(map_window,hdc);
-    Sleep(1000); 
-    update_map_canvas(x-1, y-1, 3, 3, TRUE);
-  }
-}
-
 
 /**************************************************************************
 
Index: client/gui-xaw/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/graphics.c,v
retrieving revision 1.50
diff -u -r1.50 graphics.c
--- client/gui-xaw/graphics.c   2003/08/06 07:34:38     1.50
+++ client/gui-xaw/graphics.c   2004/02/21 23:25:24
@@ -190,6 +190,15 @@
   }
 }
 
+/****************************************************************************
+  Find the dimensions of the sprite.
+****************************************************************************/
+void get_sprite_dimensions(struct Sprite *sprite, int *w, int *h)
+{
+  *w = sprite->width;
+  *h = sprite->height;
+}
+
 /***************************************************************************
 ...
 ***************************************************************************/
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.159
diff -u -r1.159 mapview.c
--- client/gui-xaw/mapview.c    2004/02/21 22:15:04     1.159
+++ client/gui-xaw/mapview.c    2004/02/21 23:25:24
@@ -638,6 +638,14 @@
   num_dirty_rects = 0;
 }
 
+/****************************************************************************
+  Do any necessary flushes to make sure the screen is up-to-date.
+****************************************************************************/
+void gui_flush(void)
+{
+  XSync(display, 0);
+}
+
 /**************************************************************************
 ...
 **************************************************************************/
@@ -781,40 +789,6 @@
                 NORMAL_TILE_HEIGHT, NORMAL_TILE_HEIGHT+SMALL_TILE_HEIGHT);
 
   put_unit_city_overlays(punit, &store, 0, NORMAL_TILE_HEIGHT);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void put_nuke_mushroom_pixmaps(int x, int y)
-{
-  int x_itr, y_itr;
-
-  for (x_itr = 0; x_itr<3; x_itr++) {
-    for (y_itr = 0; y_itr<3; y_itr++) {
-      int x1 = x + x_itr -1;
-      int y1 = y + y_itr -1;
-      if (normalize_map_pos(&x1, &y1)) {
-       int canvas_x, canvas_y;
-       struct Sprite *mysprite = sprites.explode.nuke[y_itr][x_itr];
-
-       if (!map_to_canvas_pos(&canvas_x, &canvas_y, x1, y1)) {
-         continue;
-       }
-       XCopyArea(display, map_canvas_store, single_tile_pixmap, civ_gc,
-                 canvas_x, canvas_y, NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT,
-                 0, 0);
-       pixmap_put_overlay_tile(single_tile_pixmap, 0, 0, mysprite);
-       XCopyArea(display, single_tile_pixmap, XtWindow(map_canvas), civ_gc,
-                 0, 0, NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT,
-                 canvas_x, canvas_y);
-      }
-    }
-  }
-  XSync(display, 0);
-  myusleep(1000000);
-
-  update_map_canvas(x-1, y-1, 3, 3, TRUE);
 }
 
 /**************************************************************************
Index: client/include/graphics_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/graphics_g.h,v
retrieving revision 1.8
diff -u -r1.8 graphics_g.h
--- client/include/graphics_g.h 2002/11/07 16:04:53     1.8
+++ client/include/graphics_g.h 2004/02/21 23:25:24
@@ -30,6 +30,7 @@
 struct Sprite *load_gfxfile(const char *filename);
 struct Sprite *crop_sprite(struct Sprite *source,
                           int x, int y, int width, int height);
+void get_sprite_dimensions(struct Sprite *sprite, int *w, int *h);
 void free_sprite(struct Sprite *s);
 
 #endif  /* FC__GRAPHICS_G_H */
Index: client/include/mapview_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/mapview_g.h,v
retrieving revision 1.43
diff -u -r1.43 mapview_g.h
--- client/include/mapview_g.h  2004/02/18 02:20:52     1.43
+++ client/include/mapview_g.h  2004/02/21 23:25:24
@@ -64,6 +64,7 @@
                int pixel_width, int pixel_height);
 void dirty_all(void);
 void flush_dirty(void);
+void gui_flush(void);
 
 void update_map_canvas_scrollbars(void);
 void update_map_canvas_scrollbars_size(void);
@@ -77,7 +78,6 @@
                               int new_canvas_x, int new_canvas_y);
 void decrease_unit_hp_smooth(struct unit *punit0, int hp0, 
                             struct unit *punit1, int hp1);
-void put_nuke_mushroom_pixmaps(int x, int y);
 
 void draw_segment(int src_x, int src_y, int dir);
 void draw_selection_rectangle(int canvas_x, int canvas_y, int w, int h);
Index: data/isotrident/nuke.spec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/isotrident/nuke.spec,v
retrieving revision 1.1
diff -u -r1.1 nuke.spec
--- data/isotrident/nuke.spec   2002/05/02 05:46:57     1.1
+++ data/isotrident/nuke.spec   2004/02/21 23:25:25
@@ -22,5 +22,5 @@
 is_pixel_border = 0
 
 tiles = { "row", "column", "tag"
- 0, 0, "explode.iso_nuke"
+ 0, 0, "explode.nuke"
 }
Index: data/trident/tiles.spec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/trident/tiles.spec,v
retrieving revision 1.14
diff -u -r1.14 tiles.spec
--- data/trident/tiles.spec     2004/02/03 20:21:15     1.14
+++ data/trident/tiles.spec     2004/02/21 23:25:25
@@ -501,21 +501,19 @@
  16, 18, "upkeep.unhappy2"
  16, 19, "upkeep.shield"
 
-; Nuclear explosion: this could maybe now be handled as one 
-; big graphic (?), but for now is done old way as 3 by 3:
-
-  1, 17, "explode.nuke_00"
-  1, 18, "explode.nuke_01"
-  1, 19, "explode.nuke_02"
-  2, 17, "explode.nuke_10"
-  2, 18, "explode.nuke_11"
-  2, 19, "explode.nuke_12"
-  3, 17, "explode.nuke_20"
-  3, 18, "explode.nuke_21"
-  3, 19, "explode.nuke_22"
-
 ; Misc:
 
   9, 17, "user.attention"      ; Variously crosshair/red-square/arrows
 
+}
+
+[grid_nuke]
+
+x_top_left = 510
+y_top_left = 30
+dx = 90
+dy = 90
+
+tiles = { "row", "column", "tag"
+  0, 0, "explode.nuke"
 }

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#7461) move nuke animation into mapview_common, Jason Short <=