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

[Freeciv-Dev] Re: (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] Re: (PR#7461) move nuke animation into mapview_common
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 22 Feb 2004 19:14:32 -0800
Reply-to: rt@xxxxxxxxxxx

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

Raimar Falke wrote:

> Good idea. Two issues: can we please use "width" and "height" as the
> parameter names?

Done.

> The second: It would be good to define in more detail what canvas
> store, window and screen are. And that gui_flush() copies the window
> to the screen.

I've given a more full function comment to gui_flush().  We should write 
more in doc/HACKING about this.  However I'm not sure if the design is 
really mature.

Also in this patch I changed the nuke drawing to call flush_dirty.  This 
way if there are unflushed rects when we enter the function they'll be 
flushed before the 1-second delay.

jason

? diff
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/23 03:12:44
@@ -22,15 +22,16 @@
 #include "support.h"
 #include "timing.h"
 
+#include "graphics_g.h"
+#include "mapctrl_g.h"
+#include "mapview_g.h"
+
 #include "civclient.h"
 #include "climap.h"
 #include "control.h"
 #include "goto.h"
-#include "mapctrl_g.h"
-#include "mapview_g.h"
-#include "tilespec.h"
-
 #include "mapview_common.h"
+#include "tilespec.h"
 
 struct canvas mapview_canvas;
 struct overview overview;
@@ -695,6 +696,35 @@
     gui_put_sprite_full(pcanvas_store, canvas_x, canvas_y,
                        sprites.upkeep.unhappy[unhappy - 1]);
   }
+}
+
+/****************************************************************************
+  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);
+  dirty_rect(canvas_x, canvas_y, width, height);
+
+  /* Make sure everything is flushed and synced before proceeding. */
+  flush_dirty();
+  gui_flush();
+
+  myusleep(1000000);
+
+  update_map_canvas_visible();
 }
 
 /**************************************************************************
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/23 03:12:44
@@ -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.142
diff -u -r1.142 tilespec.c
--- client/tilespec.c   2004/02/22 19:24:58     1.142
+++ client/tilespec.c   2004/02/23 03:12:45
@@ -927,16 +927,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/23 03:12:45
@@ -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/23 03:12:45
@@ -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 *width, int *height)
+{
+  *width = sprite->width;
+  *height = 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/23 03:12:46
@@ -618,6 +618,16 @@
   num_dirty_rects = 0;
 }
 
+/****************************************************************************
+  Do any necessary synchronization to make sure the screen is up-to-date.
+  The canvas should have already been flushed to screen via flush_dirty -
+  all this function does is make sure the hardware has caught up.
+****************************************************************************/
+void gui_flush(void)
+{
+  gdk_flush();
+}
+
 /**************************************************************************
  Update display of descriptions associated with cities on the main map.
 **************************************************************************/
@@ -731,55 +741,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/23 03:12:46
@@ -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 *width, int *height)
+{
+  *width = sprite->width;
+  *height = 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/23 03:12:46
@@ -646,6 +646,16 @@
   gdk_window_process_updates(map_canvas->window, FALSE);
 }
 
+/****************************************************************************
+  Do any necessary synchronization to make sure the screen is up-to-date.
+  The canvas should have already been flushed to screen via flush_dirty -
+  all this function does is make sure the hardware has caught up.
+****************************************************************************/
+void gui_flush(void)
+{
+  gdk_flush();
+}
+
 /**************************************************************************
  Update display of descriptions associated with cities on the main map.
 **************************************************************************/
@@ -801,58 +811,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/23 03:12:47
@@ -240,6 +240,14 @@
   return mysprite;
 }
 
+/****************************************************************************
+  Find the dimensions of the sprite.
+****************************************************************************/
+void get_sprite_dimensions(struct Sprite *sprite, int *width, int *height)
+{
+  *width = sprite->width;
+  *height = sprite->height;
+}
 
 /**************************************************************************
 
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.92
diff -u -r1.92 mapview.c
--- client/gui-win32/mapview.c  2004/02/22 07:31:30     1.92
+++ client/gui-win32/mapview.c  2004/02/23 03:12:47
@@ -559,6 +559,16 @@
   num_dirty_rects = 0;
 }
 
+/****************************************************************************
+  Do any necessary synchronization to make sure the screen is up-to-date.
+  The canvas should have already been flushed to screen via flush_dirty -
+  all this function does is make sure the hardware has caught up.
+****************************************************************************/
+void gui_flush(void)
+{
+  GdiFlush();
+}
+
 /**************************************************************************
 
 **************************************************************************/
@@ -819,45 +829,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/23 03:12:47
@@ -190,6 +190,15 @@
   }
 }
 
+/****************************************************************************
+  Find the dimensions of the sprite.
+****************************************************************************/
+void get_sprite_dimensions(struct Sprite *sprite, int *width, int *height)
+{
+  *width = sprite->width;
+  *height = 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/23 03:12:48
@@ -638,6 +638,16 @@
   num_dirty_rects = 0;
 }
 
+/****************************************************************************
+  Do any necessary synchronization to make sure the screen is up-to-date.
+  The canvas should have already been flushed to screen via flush_dirty -
+  all this function does is make sure the hardware has caught up.
+****************************************************************************/
+void gui_flush(void)
+{
+  XSync(display, 0);
+}
+
 /**************************************************************************
 ...
 **************************************************************************/
@@ -781,40 +791,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/23 03:12:48
@@ -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 *width, int *height);
 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/23 03:12:48
@@ -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/23 03:12:49
@@ -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/23 03:12:49
@@ -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]