[xiph-commits] r10094 - trunk/planarity

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Thu Sep 29 04:02:29 PDT 2005


Author: xiphmont
Date: 2005-09-29 04:02:25 -0700 (Thu, 29 Sep 2005)
New Revision: 10094

Added:
   trunk/planarity/gameboard_logic_fade.c
Modified:
   trunk/planarity/Makefile
   trunk/planarity/dialog_level_icons.c
   trunk/planarity/gameboard.h
   trunk/planarity/gameboard_draw_main.c
   trunk/planarity/gameboard_draw_vertex.c
   trunk/planarity/gameboard_logic.c
   trunk/planarity/gameboard_logic_button.c
   trunk/planarity/gameboard_logic_buttonbar.c
   trunk/planarity/gameboard_logic_mouse.c
   trunk/planarity/version.h
Log:
Add slow post-release vertex fade from red to blue.



Modified: trunk/planarity/Makefile
===================================================================
--- trunk/planarity/Makefile	2005-09-29 09:53:26 UTC (rev 10093)
+++ trunk/planarity/Makefile	2005-09-29 11:02:25 UTC (rev 10094)
@@ -24,7 +24,8 @@
 	gameboard_draw_intersection.c graph_generate_mesh1.c gameboard_draw_main.c\
 	gameboard_draw_score.c main.c gameboard_draw_selection.c\
 	timer.c gameboard_draw_vertex.c levelstate.c dialog_level.c\
-	dialog_level_icons.c gameboard_draw_text.c random.c graph_generate_data.c
+	dialog_level_icons.c gameboard_draw_text.c random.c graph_generate_data.c\
+	gameboard_logic_fade.c
 OBJ  = dialog_finish.o gameboard_logic.o dialog_pause.o gameboard_logic_button.o\
 	gameboard.o gameboard_logic_buttonbar.o gameboard_draw_box.o\
 	gameboard_logic_mouse.o gameboard_draw_button.o gameboard_logic_push.o\
@@ -33,7 +34,8 @@
 	gameboard_draw_intersection.o graph_generate_mesh1.o gameboard_draw_main.o\
 	gameboard_draw_score.o main.o gameboard_draw_selection.o\
 	timer.o gameboard_draw_vertex.o levelstate.o dialog_level.o\
-	dialog_level_icons.o gameboard_draw_text.o random.o graph_generate_data.o
+	dialog_level_icons.o gameboard_draw_text.o random.o graph_generate_data.o\
+	gameboard_logic_fade.o
 GCF  = `pkg-config --static --cflags "gtk+-2.0 >= 2.7.2"`
 
 # uncomment below for a normal dynamic build
@@ -70,7 +72,7 @@
 	$(STRIP) $(TARGET)
 
 debug:
-	$(MAKE) debug-target CFLAGS="-g -Wall -W -Wno-unused-parameter -D__NO_MATH_INLINES $(GCF) $(ADD_DEF)"
+	$(MAKE) target CFLAGS="-g -Wall -W -Wno-unused-parameter -D__NO_MATH_INLINES $(GCF) $(ADD_DEF)"
 
 profile:
 	$(MAKE) target CFLAGS="-pg -g -O2 -ffast-math $(GCF) $(ADD_DEF)" LIBS="$(LIBS) -lgprof-helper "
@@ -88,14 +90,14 @@
 include $(SRC:.c=.d)
 endif
 
+ifeq ($(MAKECMDGOALS),static-target)
+include $(SRC:.c=.d)
+endif
+
 target:  $(OBJ) 
 	./touch-version
 	$(LD) $(OBJ) $(CFLAGS) -o $(TARGET) $(LIBS) $(LDF)
 
-debug-target:  $(OBJ) 
-	./touch-version
-	$(LD) $(OBJ) $(CFLAGS) -o $(TARGET) $(LIBS) $(LDF)
-
 static-target: $(OBJ)
 	./touch-version
 	$(LD) $(OBJ) $(CFLAGS) -o $(TARGET) $(SLIBS) $(SLDF) 

Modified: trunk/planarity/dialog_level_icons.c
===================================================================
--- trunk/planarity/dialog_level_icons.c	2005-09-29 09:53:26 UTC (rev 10093)
+++ trunk/planarity/dialog_level_icons.c	2005-09-29 11:02:25 UTC (rev 10094)
@@ -131,17 +131,13 @@
     states[2].y_target = states[2].y_active;
    
     g->d.reset_deployed=1;
+    
+    if(g->b.buttons_ready){
+      if(g->button_timer!=0)
+	g_source_remove(g->button_timer);
+      g->button_timer = g_timeout_add(BUTTON_ANIM_INTERVAL, animate_button_frame, (gpointer)g);
+    }
   }
-  
-  // even if the button is already 'deployed', the animation may
-  // have been interrupted.  Retrigger.
-
-  if(g->b.buttons_ready){
-    if(g->gtk_timer!=0)
-      g_source_remove(g->gtk_timer);
-    g->gtk_timer = g_timeout_add(BUTTON_ANIM_INTERVAL, animate_button_frame, (gpointer)g);
-  }
-
 }
 
 static void undeploy_reset_button(Gameboard *g){
@@ -153,15 +149,13 @@
     states[2].y_target = states[2].y_inactive;
     
     g->d.reset_deployed=0;
-  }
 
-  // even if the button is already 'undeployed', the animation may
-  // have been interrupted.  Retrigger.
-  if(g->b.buttons_ready){
-    if(g->gtk_timer!=0)
-      g_source_remove(g->gtk_timer);
-    g->gtk_timer = g_timeout_add(BUTTON_ANIM_INTERVAL, animate_button_frame, (gpointer)g);
-  } 
+    if(g->b.buttons_ready){
+      if(g->button_timer!=0)
+	g_source_remove(g->button_timer);
+      g->button_timer = g_timeout_add(BUTTON_ANIM_INTERVAL, animate_button_frame, (gpointer)g);
+    } 
+  }
 }
 
 static void alpha_update(Gameboard *g,dialog_level_oneicon *l){
@@ -316,13 +310,11 @@
   int i;
 
   if(g->d.center_x == 0){
-    g_source_remove(g->gtk_timer);
-    g->gtk_timer=0;
+    g_source_remove(g->d.icon_timer);
+    g->d.icon_timer=0;
 
     if(levelstate_in_progress())
       deploy_reset_button(g);
-    else
-      undeploy_reset_button(g);
     
     expose_full(g);
     return 0;
@@ -398,6 +390,10 @@
 
   if(g->d.level_lit == 1){
     if(levelstate_prev()){
+
+    if(!levelstate_in_progress())
+      undeploy_reset_button(g);
+
       if(g->d.level_icons[4].icon)
 	cairo_surface_destroy(g->d.level_icons[4].icon);
       for(i=4;i>=1;i--){
@@ -415,6 +411,9 @@
   
   if(g->d.level_lit == 3){
     if(levelstate_next()){
+
+      if(!levelstate_in_progress())
+	undeploy_reset_button(g);
       
       if(g->d.level_icons[0].icon)
 	cairo_surface_destroy(g->d.level_icons[0].icon);
@@ -433,9 +432,9 @@
   }
 
   if(g->d.center_x){
-    if(g->gtk_timer)
-      g_source_remove(g->gtk_timer);
-    g->gtk_timer = g_timeout_add(BUTTON_ANIM_INTERVAL, animate_level_frame, (gpointer)g);
+    if(g->d.icon_timer)
+      g_source_remove(g->d.icon_timer);
+    g->d.icon_timer = g_timeout_add(BUTTON_ANIM_INTERVAL, animate_level_frame, (gpointer)g);
   }
 
 }

Modified: trunk/planarity/gameboard.h
===================================================================
--- trunk/planarity/gameboard.h	2005-09-29 09:53:26 UTC (rev 10093)
+++ trunk/planarity/gameboard.h	2005-09-29 11:02:25 UTC (rev 10094)
@@ -61,6 +61,9 @@
 #define ICON_WIDTH  160
 #define ICON_HEIGHT 120
 
+#define FADE_FRAMES 50
+#define FADE_ANIM_INTERVAL 100
+
 G_BEGIN_DECLS
 
 #define GAMEBOARD_TYPE            (gameboard_get_type ())
@@ -72,6 +75,17 @@
 typedef struct _Gameboard       Gameboard;
 typedef struct _GameboardClass  GameboardClass;
 
+typedef struct fade_list{
+  vertex *v;
+  struct fade_list *next;
+} fade_list;
+
+typedef struct {
+  fade_list *head;
+  int count;
+  gint fade_timer;
+} fade_state;
+
 #define NUMBUTTONS 11
 
 typedef struct {
@@ -137,6 +151,7 @@
   GdkRectangle text3;
   GdkRectangle text4;
 
+  gint icon_timer; // used for buttons and icons
 } dialog_level_state;
 
 struct _Gameboard{
@@ -172,6 +187,7 @@
 
   buttongroup b;
   dialog_level_state d;
+  fade_state fade;
 
   vertex *grabbed_vertex;
   vertex *lit_vertex;
@@ -195,7 +211,7 @@
   int checkbutton_deployed;
   int buttonbar_sweeper;
   
-  gint gtk_timer;
+  gint button_timer; // used for buttons and icons
   void (*button_callback)(Gameboard *);
 
 };
@@ -266,6 +282,7 @@
 extern void update_score(Gameboard *g);
 
 extern void draw_vertex(cairo_t *c,vertex *v,cairo_surface_t *s);
+extern void draw_vertex_with_alpha(cairo_t *c,vertex *v,cairo_surface_t *s,float alpha);
 extern cairo_surface_t *cache_vertex(Gameboard *g);
 extern cairo_surface_t *cache_vertex_sel(Gameboard *g);
 extern cairo_surface_t *cache_vertex_grabbed(Gameboard *g);
@@ -307,3 +324,7 @@
 
 extern void gameboard_size_allocate (GtkWidget     *widget,
 				     GtkAllocation *allocation);
+
+extern void fade_cancel(Gameboard *g);
+extern void fade_attached(Gameboard *g,vertex *v);
+

Modified: trunk/planarity/gameboard_draw_main.c
===================================================================
--- trunk/planarity/gameboard_draw_main.c	2005-09-29 09:53:26 UTC (rev 10093)
+++ trunk/planarity/gameboard_draw_main.c	2005-09-29 11:02:25 UTC (rev 10094)
@@ -73,6 +73,9 @@
   /* verticies drawn over the edges */
   {
     vertex *v = g->g.verticies;
+    fade_list *f = g->fade.head;
+    float alpha = 1.*g->fade.count/FADE_FRAMES;
+
     int clipx = x-V_RADIUS;
     int clipw = x+w+V_RADIUS;
     int clipy = y-V_RADIUS;
@@ -98,6 +101,25 @@
       
       v=v->next;
     }
+
+    while(f){
+      v=f->v;
+
+      /* is the vertex in the expose rectangle? */
+      if(v->x>=clipx && v->x<=clipw &&
+	 v->y>=clipy && v->y<=cliph){
+
+	/* only fade if not specially lit */
+	if(!(v == g->grabbed_vertex && !g->group_drag) &&
+	   !(v->selected) &&
+	   !(v==g->lit_vertex) &&
+	   !(v->attached_to_grabbed && !g->group_drag))
+     
+	  draw_vertex_with_alpha(c,v,g->vertex_attached,alpha);
+
+      }
+      f=f->next;
+    }
   }
 }
 

Modified: trunk/planarity/gameboard_draw_vertex.c
===================================================================
--- trunk/planarity/gameboard_draw_vertex.c	2005-09-29 09:53:26 UTC (rev 10093)
+++ trunk/planarity/gameboard_draw_vertex.c	2005-09-29 11:02:25 UTC (rev 10094)
@@ -47,6 +47,14 @@
   cairo_paint(c);
 }      
 
+void draw_vertex_with_alpha(cairo_t *c,vertex *v,cairo_surface_t *s,float alpha){
+  cairo_set_source_surface(c,
+			   s,
+			   v->x-V_LINE-V_RADIUS,
+			   v->y-V_LINE-V_RADIUS);
+  cairo_paint_with_alpha(c,alpha);
+}      
+
 // normal unlit vertex
 cairo_surface_t *cache_vertex(Gameboard *g){
   cairo_surface_t *ret=

Modified: trunk/planarity/gameboard_logic.c
===================================================================
--- trunk/planarity/gameboard_logic.c	2005-09-29 09:53:26 UTC (rev 10093)
+++ trunk/planarity/gameboard_logic.c	2005-09-29 11:02:25 UTC (rev 10094)
@@ -124,13 +124,20 @@
 }
 
 static void gtk_main_quit_wrapper(Gameboard *g){
+  fade_cancel(g);
   gtk_main_quit();
 }
 
 static void level_wrapper(Gameboard *g){
+  fade_cancel(g);
   level_dialog(g,0);
 }
 
+static void finish_wrapper(Gameboard *g){
+  fade_cancel(g);
+  finish_level_dialog(g);
+}
+
 /* toplevel main gameboard action entry points; when a button is
    clicked and decoded to a specific action or a game state change
    triggers an action, one of the below functions is the entry
@@ -150,7 +157,7 @@
   if(g->g.active_intersections<=g->g.original_intersections){
     pause_timer();
     levelstate_finish();
-    undeploy_buttons(g,finish_level_dialog);
+    undeploy_buttons(g,finish_wrapper);
   }
 }
 

Modified: trunk/planarity/gameboard_logic_button.c
===================================================================
--- trunk/planarity/gameboard_logic_button.c	2005-09-29 09:53:26 UTC (rev 10093)
+++ trunk/planarity/gameboard_logic_button.c	2005-09-29 11:02:25 UTC (rev 10094)
@@ -26,6 +26,7 @@
 
 #include <math.h>
 #include <string.h>
+#include <stdlib.h>
 #include <gtk/gtk.h>
 #include <gdk/gdk.h>
 
@@ -488,9 +489,9 @@
 
   if(!ret)g->b.sweeperd = 0;
 
-  if(!ret && g->gtk_timer!=0){
-    g_source_remove(g->gtk_timer);
-    g->gtk_timer=0;
+  if(!ret && g->button_timer!=0){
+    g_source_remove(g->button_timer);
+    g->button_timer=0;
   }
 
   if(!ret && g->button_callback)
@@ -617,9 +618,9 @@
     g->b.sweeperd = 1;
 
     g->button_callback = callback;
-    if(g->gtk_timer!=0)
-      g_source_remove(g->gtk_timer);
-    g->gtk_timer = g_timeout_add(BUTTON_ANIM_INTERVAL, animate_button_frame, (gpointer)g);
+    if(g->button_timer!=0)
+      g_source_remove(g->button_timer);
+    g->button_timer = g_timeout_add(BUTTON_ANIM_INTERVAL, animate_button_frame, (gpointer)g);
     g->b.buttons_ready=1;
   }
 
@@ -640,9 +641,9 @@
     g->b.sweeperd = -1;
 
     g->button_callback = callback;
-    if(g->gtk_timer!=0)
-      g_source_remove(g->gtk_timer);
-    g->gtk_timer = g_timeout_add(BUTTON_ANIM_INTERVAL, animate_button_frame, (gpointer)g);
+    if(g->button_timer!=0)
+      g_source_remove(g->button_timer);
+    g->button_timer = g_timeout_add(BUTTON_ANIM_INTERVAL, animate_button_frame, (gpointer)g);
   }else
     callback(g);
 

Modified: trunk/planarity/gameboard_logic_buttonbar.c
===================================================================
--- trunk/planarity/gameboard_logic_buttonbar.c	2005-09-29 09:53:26 UTC (rev 10093)
+++ trunk/planarity/gameboard_logic_buttonbar.c	2005-09-29 11:02:25 UTC (rev 10094)
@@ -149,9 +149,9 @@
     states[9].y_target = states[9].y_active;
     states[i].sweepdeploy = 0;
 
-    if(g->gtk_timer!=0)
-      g_source_remove(g->gtk_timer);
-    g->gtk_timer = g_timeout_add(BUTTON_ANIM_INTERVAL, animate_button_frame, (gpointer)g);
+    if(g->button_timer!=0)
+      g_source_remove(g->button_timer);
+    g->button_timer = g_timeout_add(BUTTON_ANIM_INTERVAL, animate_button_frame, (gpointer)g);
     g->checkbutton_deployed=1;
   }
 }
@@ -167,9 +167,9 @@
     }
     states[9].y_target=states[9].y_inactive;
 
-    if(g->gtk_timer!=0)
-      g_source_remove(g->gtk_timer);
-    g->gtk_timer = g_timeout_add(BUTTON_ANIM_INTERVAL, animate_button_frame, (gpointer)g);
+    if(g->button_timer!=0)
+      g_source_remove(g->button_timer);
+    g->button_timer = g_timeout_add(BUTTON_ANIM_INTERVAL, animate_button_frame, (gpointer)g);
     g->checkbutton_deployed=0;
   }
 }

Added: trunk/planarity/gameboard_logic_fade.c
===================================================================
--- trunk/planarity/gameboard_logic_fade.c	2005-09-29 09:53:26 UTC (rev 10093)
+++ trunk/planarity/gameboard_logic_fade.c	2005-09-29 11:02:25 UTC (rev 10094)
@@ -0,0 +1,117 @@
+/*
+ *
+ *  gPlanarity: 
+ *     The geeky little puzzle game with a big noodly crunch!
+ *    
+ *     gPlanarity copyright (C) 2005 Monty <monty at xiph.org>
+ *     Original Flash game by John Tantalo <john.tantalo at case.edu>
+ *     Original game concept by Mary Radcliffe
+ *
+ *  gPlanarity is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *   
+ *  gPlanarity is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *   
+ *  You should have received a copy of the GNU General Public License
+ *  along with Postfish; see the file COPYING.  If not, write to the
+ *  Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * 
+ */
+
+#include <stdlib.h>
+#include "graph.h"
+#include "gameboard.h"
+
+static fade_list *pool=0;
+
+#define CHUNK 32
+static void fade_add_vertex(fade_state *f,vertex *v){
+  fade_list *ret;
+
+  if(pool==0){
+    int i;
+    pool = calloc(CHUNK,sizeof(*pool));
+    for(i=0;i<CHUNK-1;i++) /* last addition's next points to nothing */
+      pool[i].next=pool+i+1;
+  }
+
+  ret=pool;
+  pool=ret->next;
+
+  ret->v=v;
+
+  ret->next = f->head;
+  f->head = ret;
+}
+
+static gint animate_fade(gpointer ptr){
+  Gameboard *g = (Gameboard *)ptr;
+  fade_state *f = &g->fade;
+  
+  f->count--;
+  if(f->count>0){
+    fade_list *l = f->head;
+  
+    while(l){
+      invalidate_vertex(g,l->v);
+      l=l->next;
+    } 
+    
+    return 1;
+  }
+  
+  fade_cancel(g);
+  return 0;
+}
+
+void fade_cancel(Gameboard *g){
+  fade_state *f = &g->fade;
+  fade_list *l = f->head;
+  
+  while(l){
+    fade_list *n = l->next;
+
+    /* invalidate the vertex */
+    invalidate_vertex(g,l->v);
+
+    l->next=pool;
+    pool=l;
+    l=n;
+  }
+  f->head = 0;
+  f->count = 0;
+
+  if(f->fade_timer)
+    g_source_remove(f->fade_timer);
+  f->fade_timer=0;
+}
+
+void fade_attached(Gameboard *g,vertex *v){
+  fade_state *f = &g->fade;
+  edge_list *el=v->edges;
+
+  /* If a fade is already in progress, cancel it */
+  fade_cancel(g);
+
+  while(el){
+    edge *e=el->edge;
+
+    if(v == e->A){
+      fade_add_vertex(f,e->B);
+    }else{
+      fade_add_vertex(f,e->A);
+    }
+    el=el->next;
+  }
+
+  f->count = FADE_FRAMES;
+
+  f->fade_timer = g_timeout_add(FADE_ANIM_INTERVAL, animate_fade, (gpointer)g);
+}
+

Modified: trunk/planarity/gameboard_logic_mouse.c
===================================================================
--- trunk/planarity/gameboard_logic_mouse.c	2005-09-29 09:53:26 UTC (rev 10093)
+++ trunk/planarity/gameboard_logic_mouse.c	2005-09-29 11:02:25 UTC (rev 10094)
@@ -239,7 +239,7 @@
 	grab_vertex(&g->g,g->grabbed_vertex);
 	invalidate_attached(widget,g->grabbed_vertex);
 	invalidate_edges(widget,g->grabbed_vertex);
-	
+	fade_cancel(g);
 	// highlight vertex immediately; update the background after the
 	// vertex change
 	update_full_delayed(g);
@@ -299,6 +299,7 @@
     if(g->grabbed_vertex){
       ungrab_vertex(&g->g,g->grabbed_vertex);
       update_add_vertex(g,g->grabbed_vertex);
+      fade_attached(g,g->grabbed_vertex);
       update_score(g);
       g->grabbed_vertex = 0;
 

Modified: trunk/planarity/version.h
===================================================================
--- trunk/planarity/version.h	2005-09-29 09:53:26 UTC (rev 10093)
+++ trunk/planarity/version.h	2005-09-29 11:02:25 UTC (rev 10094)
@@ -1,2 +1,2 @@
 #define VERSION "$Id$ "
-/* DO NOT EDIT: Automated versioning hack [Mon Sep 26 06:29:46 EDT 2005] */
+/* DO NOT EDIT: Automated versioning hack [Thu Sep 29 06:57:55 EDT 2005] */



More information about the commits mailing list