[cairo-commit] cairo-demo/svgspacewar ChangeLog, 1.7, 1.8 Makefile, 1.2, 1.3 svgspacewar.c, 1.6, 1.7

Behdad Esfahbod commit at pdx.freedesktop.org
Thu Aug 11 21:57:29 PDT 2005


Committed by: behdad

Update of /cvs/cairo/cairo-demo/svgspacewar
In directory gabe:/tmp/cvs-serv16600

Modified Files:
	ChangeLog Makefile svgspacewar.c 
Log Message:
2005-08-12  Behdad Esfahbod  <behdad at behdad.org>

        * svgspacewar.c: Misc changes to shut gcc warning up.



Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-demo/svgspacewar/ChangeLog,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- ChangeLog	29 Jul 2005 04:36:07 -0000	1.7
+++ ChangeLog	12 Aug 2005 04:57:27 -0000	1.8
@@ -1,4 +1,8 @@
-2005-06-29  Behdad Esfahbod  <behdad at behdad.org>
+2005-08-12  Behdad Esfahbod  <behdad at behdad.org>
+
+	* svgspacewar.c: Misc changes to shut gcc warning up.
+
+2005-07-29  Behdad Esfahbod  <behdad at behdad.org>
 
 	* svgspacewar.c: Use M_PI instead of handcoding $\pi$.
 
@@ -41,4 +45,3 @@
 
 	Initial import into CVS.
 
-/* vim: set ts=4 noet : */

Index: Makefile
===================================================================
RCS file: /cvs/cairo/cairo-demo/svgspacewar/Makefile,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Makefile	21 Jun 2005 15:28:23 -0000	1.2
+++ Makefile	12 Aug 2005 04:57:27 -0000	1.3
@@ -1,7 +1,4 @@
-CC = gcc
-
-APPS =				\
-	svgspacewar
+APPS = svgspacewar
 
 CFLAGS  = -g -Wall
 
@@ -11,4 +8,4 @@
 all: $(APPS)
 
 clean:
-	rm -f *.o $(APPS)
+	$(RM) $(APPS)

Index: svgspacewar.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/svgspacewar/svgspacewar.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- svgspacewar.c	29 Jul 2005 04:36:07 -0000	1.6
+++ svgspacewar.c	12 Aug 2005 04:57:27 -0000	1.7
@@ -193,7 +193,7 @@
 static int number_of_frames = 0;
 static long millis_taken_for_frames = 0;
 static float debug_scale_factor = 1.0f;
-static char *game_over_message = NULL;
+static const char *game_over_message = NULL;
 
 //------------------------------------------------------------------------------
 
@@ -226,13 +226,13 @@
 gint
 main (gint argc, gchar ** argv)
 {
+  GtkWidget *window;
+
   srand ((unsigned int) time (NULL));
 
   init_trigonometric_tables ();
   reset ();
 
-  GtkWidget *window;
-
   gtk_init (&argc, &argv);
 
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
@@ -272,7 +272,7 @@
 {
   cairo_t *cr = gdk_cairo_create (widget->window);
   int i;
-  long start_time;
+  long start_time = 0;
   if (show_fps)
     {
       start_time = get_time_millis ();
@@ -423,14 +423,14 @@
 static void
 draw_energy_bar (cairo_t * cr, player_t * p)
 {
+  cairo_pattern_t *pat;
   double alpha = 0.6;
 
   cairo_save (cr);
 
   cairo_rectangle (cr, 0, -5, p->energy / 5, 10);
 
-  cairo_pattern_t *pat =
-    cairo_pattern_create_linear (0, 0, SHIP_MAX_ENERGY / 5, 0);
+  pat = cairo_pattern_create_linear (0, 0, SHIP_MAX_ENERGY / 5, 0);
   cairo_pattern_add_color_stop_rgba (pat, 0,
 				     p->secondary_color.r,
 				     p->secondary_color.g,
@@ -453,6 +453,8 @@
 static void
 draw_ship_body (cairo_t * cr, player_t * p)
 {
+  cairo_pattern_t *pat;
+
   if (p->is_hit)
     {
       cairo_set_source_rgba (cr, p->primary_color.r, p->primary_color.g,
@@ -498,8 +500,7 @@
   cairo_curve_to (cr, -6, 15, -8, -10, -4, -35);
   cairo_curve_to (cr, -3, -34, -2, -33, 0, -33);
 
-  cairo_pattern_t *pat =
-    cairo_pattern_create_linear (-30.0, -30.0, 30.0, 30.0);
+  pat = cairo_pattern_create_linear (-30.0, -30.0, 30.0, 30.0);
   cairo_pattern_add_color_stop_rgba (pat, 0,
 				     p->primary_color.r, p->primary_color.g,
 				     p->primary_color.b, 1);
@@ -521,9 +522,11 @@
 static void
 draw_flare (cairo_t * cr, RGB_t color)
 {
+  cairo_pattern_t *pat;
+
   cairo_save (cr);
   cairo_translate (cr, 0, 22);
-  cairo_pattern_t *pat = cairo_pattern_create_radial (0, 0, 2, 0, 5, 12);
+  pat = cairo_pattern_create_radial (0, 0, 2, 0, 5, 12);
 
   cairo_pattern_add_color_stop_rgba (pat, 0.0, color.r, color.g, color.b, 1);
   cairo_pattern_add_color_stop_rgba (pat, 0.3, 1, 1, 1, 1);
@@ -540,8 +543,10 @@
 static void
 draw_turning_flare (cairo_t * cr, RGB_t color, int right_hand_side)
 {
+  cairo_pattern_t *pat;
+
   cairo_save (cr);
-  cairo_pattern_t *pat = cairo_pattern_create_radial (0, 0, 1, 0, 0, 7);
+  pat = cairo_pattern_create_radial (0, 0, 1, 0, 0, 7);
 
   cairo_pattern_add_color_stop_rgba (pat, 0.0, 1, 1, 1, 1);
   cairo_pattern_add_color_stop_rgba (pat, 1.0, color.r, color.g, color.b, 0);
@@ -629,13 +634,13 @@
 static void
 draw_exploded_missile (cairo_t * cr, missile_t * m)
 {
+  double alpha;
+  cairo_pattern_t *pat;
+
   cairo_save (cr);
   cairo_scale (cr, GLOBAL_SHIP_SCALE_FACTOR, GLOBAL_SHIP_SCALE_FACTOR);
 
-  cairo_pattern_t *pat;
-
-  double alpha =
-    ((double) m->ticks_to_live) / MISSILE_EXPLOSION_TICKS_TO_LIVE;
+  alpha = ((double) m->ticks_to_live) / MISSILE_EXPLOSION_TICKS_TO_LIVE;
   alpha = 1.0 - (1.0 - alpha) * (1.0 - alpha);
 
   cairo_arc (cr, 0, 0, 30, 0, TWO_PI);
@@ -663,29 +668,25 @@
   int a = NUMBER_OF_ROTATION_ANGLES / 10;
   float r1 = 5.0;
   float r2 = 2.0;
+  float c;
+  int i;
 
-  cairo_move_to (cr, r1 * cos_table[0 * a] / FIXED_POINT_SCALE_FACTOR,
-		 r1 * sin_table[0 * a] / FIXED_POINT_SCALE_FACTOR);
-  cairo_line_to (cr, r2 * cos_table[1 * a] / FIXED_POINT_SCALE_FACTOR,
-		 r2 * sin_table[1 * a] / FIXED_POINT_SCALE_FACTOR);
-  cairo_line_to (cr, r1 * cos_table[2 * a] / FIXED_POINT_SCALE_FACTOR,
-		 r1 * sin_table[2 * a] / FIXED_POINT_SCALE_FACTOR);
-  cairo_line_to (cr, r2 * cos_table[3 * a] / FIXED_POINT_SCALE_FACTOR,
-		 r2 * sin_table[3 * a] / FIXED_POINT_SCALE_FACTOR);
-  cairo_line_to (cr, r1 * cos_table[4 * a] / FIXED_POINT_SCALE_FACTOR,
-		 r1 * sin_table[4 * a] / FIXED_POINT_SCALE_FACTOR);
-  cairo_line_to (cr, r2 * cos_table[5 * a] / FIXED_POINT_SCALE_FACTOR,
-		 r2 * sin_table[5 * a] / FIXED_POINT_SCALE_FACTOR);
-  cairo_line_to (cr, r1 * cos_table[6 * a] / FIXED_POINT_SCALE_FACTOR,
-		 r1 * sin_table[6 * a] / FIXED_POINT_SCALE_FACTOR);
-  cairo_line_to (cr, r2 * cos_table[7 * a] / FIXED_POINT_SCALE_FACTOR,
-		 r2 * sin_table[7 * a] / FIXED_POINT_SCALE_FACTOR);
-  cairo_line_to (cr, r1 * cos_table[8 * a] / FIXED_POINT_SCALE_FACTOR,
-		 r1 * sin_table[8 * a] / FIXED_POINT_SCALE_FACTOR);
-  cairo_line_to (cr, r2 * cos_table[9 * a] / FIXED_POINT_SCALE_FACTOR,
-		 r2 * sin_table[9 * a] / FIXED_POINT_SCALE_FACTOR);
+  cairo_save (cr);
+  cairo_move_to (cr, r1 * cos_table[0] / FIXED_POINT_SCALE_FACTOR,
+		 r1 * sin_table[0] / FIXED_POINT_SCALE_FACTOR);
 
-  float c = 0.5;
+  for (i = 0; i < 5; i++) {
+    cairo_line_to (cr, r1 * cos_table[0] / FIXED_POINT_SCALE_FACTOR,
+		   r1 * sin_table[0] / FIXED_POINT_SCALE_FACTOR);
+    cairo_line_to (cr, r2 * cos_table[a] / FIXED_POINT_SCALE_FACTOR,
+		   r2 * sin_table[a] / FIXED_POINT_SCALE_FACTOR);
+    cairo_rotate (cr, 4*a*PI/NUMBER_OF_ROTATION_ANGLES);
+  }
+
+  cairo_close_path (cr);
+  cairo_restore (cr);
+
+  c = 0.5;
   cairo_set_source_rgb (cr, c, c, c);
   cairo_fill (cr);
 }
@@ -705,17 +706,27 @@
 
   if (check_for_collision (&(player1.p), &(player2.p)))
     {
+      int p1vx;
+      int p1vy;
+      int p2vx;
+      int p2vy;
+
+      int dvx;
+      int dvy;
+      int dv2;
+      int damage;
+
       enforce_minimum_distance (&(player1.p), &(player2.p));
 
-      int p1vx = player1.p.vx;
-      int p1vy = player1.p.vy;
-      int p2vx = player2.p.vx;
-      int p2vy = player2.p.vy;
+      p1vx = player1.p.vx;
+      p1vy = player1.p.vy;
+      p2vx = player2.p.vx;
+      p2vy = player2.p.vy;
 
-      int dvx = (p1vx - p2vx) / FIXED_POINT_HALF_SCALE_FACTOR;
-      int dvy = (p1vy - p2vy) / FIXED_POINT_HALF_SCALE_FACTOR;
-      int dv2 = (dvx * dvx) + (dvy * dvy);
-      int damage = ((int) sqrt (dv2)) / DAMAGE_PER_SHIP_BOUNCE_DIVISOR;
+      dvx = (p1vx - p2vx) / FIXED_POINT_HALF_SCALE_FACTOR;
+      dvy = (p1vy - p2vy) / FIXED_POINT_HALF_SCALE_FACTOR;
+      dv2 = (dvx * dvx) + (dvy * dvy);
+      damage = ((int)(sqrt (dv2))) / DAMAGE_PER_SHIP_BOUNCE_DIVISOR;
 
       player1.energy -= damage;
       player2.energy -= damage;
@@ -784,6 +795,7 @@
 static void
 apply_physics_to_player (player_t * player)
 {
+  int v2, m2;
   physics_t *p = &(player->p);
 
   if (!player->is_dead)
@@ -816,8 +828,8 @@
 	}
 
       // apply velocity upper bound
-      int v2 = ((p->vx) * (p->vx)) + ((p->vy) * (p->vy));
-      int m2 = SHIP_MAX_VELOCITY * SHIP_MAX_VELOCITY;
+      v2 = ((p->vx) * (p->vx)) + ((p->vy) * (p->vy));
+      m2 = SHIP_MAX_VELOCITY * SHIP_MAX_VELOCITY;
       if (v2 > m2)
 	{
 	  p->vx = (int) (((double) (p->vx) * m2) / v2);
@@ -829,12 +841,13 @@
 	{
 	  if ((player->is_firing) && (player->energy > ENERGY_PER_MISSILE))
 	    {
-	      player->energy -= ENERGY_PER_MISSILE;
-
 	      int xx = cos_table[p->rotation];
 	      int yy = sin_table[p->rotation];
 
 	      missile_t *m = &(missiles[next_missile_index++]);
+
+	      player->energy -= ENERGY_PER_MISSILE;
+
 	      if (next_missile_index == MAX_NUMBER_OF_MISSILES)
 		{
 		  next_missile_index = 0;
@@ -952,16 +965,18 @@
 static void
 show_text_message (cairo_t * cr, int font_size, int dy, const char *message)
 {
-  cairo_save (cr);
+  double x, y;
   cairo_text_extents_t extents;
 
+  cairo_save (cr);
+
   cairo_select_font_face (cr, "Serif",
 			  CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
 
   cairo_set_font_size (cr, font_size);
   cairo_text_extents (cr, message, &extents);
-  double x = (WIDTH / 2) - (extents.width / 2 + extents.x_bearing);
-  double y = (HEIGHT / 2) - (extents.height / 2 + extents.y_bearing);
+  x = (WIDTH / 2) - (extents.width / 2 + extents.x_bearing);
+  y = (HEIGHT / 2) - (extents.height / 2 + extents.y_bearing);
 
   cairo_set_source_rgba (cr, 1, 1, 1, 1);
   cairo_move_to (cr, x, y + dy);




More information about the cairo-commit mailing list