changeset 153:9870b049b7f6

Make mb_progm_abort() work.
author Thinker K.F. Li <thinker@branda.to>
date Sat, 27 Sep 2008 02:40:42 +0800
parents 2b316b5d65f9
children 6ce68c1f7405
files examples/tank/tank_main.c src/animate.c src/animate.h
diffstat 3 files changed, 18 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/examples/tank/tank_main.c	Fri Sep 26 17:56:08 2008 +0800
+++ b/examples/tank/tank_main.c	Sat Sep 27 02:40:42 2008 +0800
@@ -108,7 +108,7 @@
 
     if(tank->progm) {
 	tman = X_MB_tman(xmb_rt);
-	mb_progm_abort(tank->progm, tman);
+	mb_progm_abort(tank->progm);
     }
     free(tank);
 }
@@ -252,27 +252,31 @@
     switch(xkey->sym) {
     case 0xff51:		/* left */
 	direction = TD_LEFT;
+	tank_move(tank_rt->tank1, direction, tank_rt);
 	break;
 
     case 0xff52:		/* up */
 	direction = TD_UP;
+	tank_move(tank_rt->tank1, direction, tank_rt);
 	break;
 
     case 0xff53:		/* right */
 	direction = TD_RIGHT;
+	tank_move(tank_rt->tank1, direction, tank_rt);
 	break;
 
     case 0xff54:		/* down */
 	direction = TD_DOWN;
+	tank_move(tank_rt->tank1, direction, tank_rt);
 	break;
 
     case 0x20:			/* space */
+	break;
     case 0xff0d:		/* enter */
     default:
 	return;
     }
 
-    tank_move(tank_rt->tank1, direction, tank_rt);
 }
 
 static void init_keyboard(tank_rt_t *tank_rt) {
--- a/src/animate.c	Fri Sep 26 17:56:08 2008 +0800
+++ b/src/animate.c	Sat Sep 27 02:40:42 2008 +0800
@@ -98,6 +98,7 @@
     int first_playing;		/*!< first playing word. */
     mb_tman_t *tman;
     subject_t *complete;	/*!< notify when a program is completed. */
+    mb_timer_t *cur_timer;
 
     int n_words;
     int max_words;
@@ -290,6 +291,7 @@
 	timer = mb_tman_timeout(progm->tman, &next_tmo,
 				mb_progm_step, progm);	
     } else {
+	/* Make program to complete. */
 #ifndef UNITTEST
 	factory = rdman_get_ob_factory(progm->rdman);
 	comp_evt.event.type = EVT_PROGM_COMPLETE;
@@ -297,6 +299,7 @@
 	comp_evt.progm = progm;
 	subject_notify(factory, progm->complete, &comp_evt.event);
 #endif /* UNITTEST */
+	progm->cur_timer = NULL;
     }
 }
 
@@ -329,10 +332,17 @@
     timer = mb_tman_timeout(tman, &progm->words[0].abs_start,
 			    mb_progm_step, progm);
     ASSERT(timer != NULL);
+
+    /* We need timer to abort it. */
+    progm->cur_timer = timer;
 }
 
-void mb_progm_abort(mb_progm_t *progm, mb_tman_t *tman) {
+void mb_progm_abort(mb_progm_t *progm) {
     /*! \todo Make sure abort release resources. */
+    if(progm->cur_timer) {
+	mb_tman_remove(progm->tman, progm->cur_timer);
+	progm->cur_timer = NULL;
+    }
 }
 
 /*! \brief Return event subject for completion of a program.
--- a/src/animate.h	Fri Sep 26 17:56:08 2008 +0800
+++ b/src/animate.h	Sat Sep 27 02:40:42 2008 +0800
@@ -42,7 +42,7 @@
 				     const mb_timeval_t *playing);
 extern void mb_progm_start(mb_progm_t *progm, mb_tman_t *tman,
 			   mb_timeval_t *now);
-extern void mb_progm_abort(mb_progm_t *progm, mb_tman_t *tman);
+extern void mb_progm_abort(mb_progm_t *progm);
 extern subject_t *mb_progm_get_complete(mb_progm_t *progm);
 
 /*! \defgroup ani_actions Animation Actions