changeset 11:5d2d9369052a

minor fix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 08 Dec 2010 02:04:07 +0900
parents a6dc38328741
children 4c9c5cbd47c5
files Dandy.cc Makefile
diffstat 2 files changed, 151 insertions(+), 149 deletions(-) [+]
line wrap: on
line diff
--- a/Dandy.cc	Wed Dec 08 00:07:08 2010 +0900
+++ b/Dandy.cc	Wed Dec 08 02:04:07 2010 +0900
@@ -1,80 +1,4 @@
 #include "Dandy.h"
-
-
-const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\
-  -length  Number of data (default DATA_NUM (Func.h))\n\
-  -count   Number of task (default 1)\n";
-
-static Viewer *sgroot;
-
-static    int screen_w;
-static    int screen_h;
-
-MainLoopPtr
-Dandy::init(Viewer *sgroot_, int w, int h)
-{
-    screen_w = w;
-    screen_h = h;
-    sgroot = sgroot_;
-    return sgroot;
-}
-
-Application *
-application() {
-    return new Dandy();
-}
-
-
-static int dandy_closing(int gamef);
-static int dandy_main_loop(int gamef);
-static int dandy_main_init(int gamef);
-
-bool 
-Dandy::app_loop(Viewer *viewer){
-    // don't use allExecute
-    return 0;
-};
-
-HTaskPtr 
-Dandy::application_task(HTaskPtr next, Viewer* viewer){
-    int gamef = 0;
-
-    switch (gamef) {
-    case 0:    gamef= dandy_main_init(gamef); break;
-    case 1:    gamef= dandy_main_loop(gamef); break;
-    case 2:    gamef= dandy_closing(gamef); break;
-    }
-    return next;
-}; 
-
-
-
-extern int init(TaskManager *manager, int argc, char *argv[]);
-extern void task_initialize();
-static void TMend(TaskManager *manager);
-
-static void
-task_init() 
-{
-}
-
-int
-TMmain(TaskManager *manager,int argc, char *argv[])
-{
-    task_init();
-    task_initialize();
-    manager->set_TMend(TMend);
-
-    return init(manager,argc, argv);
-}
-
-void
-TMend(TaskManager *manager)
-{
-    printf("game end\n");
-}
-
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -106,7 +30,6 @@
 #include "Character.h"
 #include "Character_state.h"
 
-int gamef = 0;
 int use_keybord = 0;
 int cdp[20] = { 16, 16, 16, 17, 18, 0 };
 int d, i;
@@ -116,16 +39,15 @@
 int cc = 0;
 
 //static SDL_Surface *screen;
-static Uint32 background;
+// static Uint32 background;
 // static char *pad_trace_file;
 
 extern void schedule();
 extern void tokuten();
 extern void Pad();
 extern void keybord();
-static void gamesyokika(SDL_Joystick *joy);
-static void opening(SDL_Joystick *joy);
-static void game_pause(SDL_Joystick *joy);
+static int gamesyokika(int gamef);
+static int game_pause(int);
 //static char *pad_trace_file;
 
 /**
@@ -142,6 +64,86 @@
 
 SDL_Joystick *joy;
 
+
+
+const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\
+  -length  Number of data (default DATA_NUM (Func.h))\n\
+  -count   Number of task (default 1)\n";
+
+static Viewer *sgroot;
+
+static    int screen_w;
+static    int screen_h;
+
+MainLoopPtr
+Dandy::init(Viewer *sgroot_, int w, int h)
+{
+    screen_w = w;
+    screen_h = h;
+    sgroot = sgroot_;
+    return sgroot;
+}
+
+Application *
+application() {
+    return new Dandy();
+}
+
+
+static int opening(int gamef);
+static int dandy_closing(int gamef);
+static int dandy_main_loop(int gamef);
+static int dandy_main_init(int gamef);
+extern int init(TaskManager *manager, int argc, char *argv[]);
+extern void task_initialize();
+static void TMend(TaskManager *manager);
+
+bool 
+Dandy::app_loop(Viewer *viewer){
+    // don't use allExecute
+    return 0;
+};
+
+static int gamef = 0;
+
+HTaskPtr 
+Dandy::application_task(HTaskPtr next, Viewer* viewer){
+printf("gamef = %d\n",gamef);
+    switch (gamef) {
+    case 0:    gamef= dandy_main_init(gamef); break;
+    case 1:    gamef= gamesyokika(gamef); break;
+    case 2:    gamef= opening(gamef); break;
+    case 3:    gamef= dandy_main_loop(gamef); break;
+    case 4:    gamef= dandy_closing(gamef); break;
+    }
+    return next;
+}; 
+
+
+
+
+static void
+task_init() 
+{
+}
+
+int
+TMmain(TaskManager *manager,int argc, char *argv[])
+{
+    task_init();
+    task_initialize();
+    manager->set_TMend(TMend);
+
+    return init(manager,argc, argv);
+}
+
+void
+TMend(TaskManager *manager)
+{
+    printf("game end\n");
+}
+
+
 static int 
 dandy_main_init(int gamef)
 {
@@ -168,10 +170,6 @@
 	use_keybord = 1;
     }
 
-    opening(joy);
-
-    __debug("openingがよびだされました\n");
-
     /**
      * sound.c に移しました
      * 代わりに InitSdlMixer(void); を使います。
@@ -209,24 +207,31 @@
     return 1;
 }
 
+static void
+flip()
+{
+    sgroot->sgroot->sg_exec_tree = sgroot->sgroot->sg_available_list;
+    sgroot->sgroot->flip();
+    sgroot->sgroot->lightCalc();
+}
+
+
 static int
 dandy_main_loop(int gamef)
 {
-	sgroot->sgroot->flip();
-	sgroot->sgroot->lightCalc();
 	
 
 	if ((pad[0].l1 != 0) && (pad[0].r1 != 0) &&
 	    (pad[0].l2 != 0) && (pad[0].r2 != 0)) {
-	    gamesyokika(joy);
+	    gamef = gamesyokika(gamef);
 	}
 
 	if (pad[0].quit != 0) {
-	    gamef = 2;
+	    gamef = 4;
 	}
+	flip();
 
 	//SDL_FillRect(screen, NULL, background);
-	glClear( GL_COLOR_BUFFER_BIT);		
     
 	schedule();
 	enemyfaste = count;
@@ -257,7 +262,7 @@
 	//PutSprite(count, 0, 0, 48);
 
 	obj_draw();
-	game_pause(joy);
+	gamef = game_pause(gamef);
 
 	if (use_keybord) {
 	    keybord();
@@ -283,8 +288,8 @@
 }
 
 
-static void
-gamesyokika(SDL_Joystick *joy)
+static int
+gamesyokika(int gamef)
 {
     laser_lv3[0].r = 62;
     laser_lv3[0].r = 62;
@@ -317,61 +322,55 @@
     pad[0].left=0;
     pad[0].st=0;
     pad[0].se=0;
-    opening(joy);
-}
-
-static void
-opening(SDL_Joystick *joy)
-{
-    //for (i = 0; i < 300; i++) {
-    //};
 
     SoundStop();
     SoundPlay(7);
-
-    while (1) {
-	if(use_keybord == 1) {
-	    keybord();
-	} else {
-	    Pad(joy);
-	}
-
-	count = 1;
-
-	PutSprite(count, 700, 480, 53); //  put `push start' string on screen.  
-	count++;
-	PutSprite(count, 224, 776, 119); //  put `super dandy'                   
-	count++;
-	//    PutSprite(count, 200, 64, 190);
-	//    PutSpriteEx(count, 8192, 8192, 0);
-        PutSpriteEx(190, 800, 264, 2, 2, 5);
-	count++;
-	PutSprite(count, 396, 432, 191);
-	//PutSpriteEx(count, 8192, 8192, 0);
-	count++;
-	PutSprite(count, 640, 640, 192);
-	//PutSpriteEx(count, 8192, 8192, 0);
-
-	if (pad[0].st > 1) {
-	    jiki.bf = TRUE;
-	    
-	    //CdPlay(1,&cdp[0],0);                                          
-	    SoundStop();
-	    SoundPlay(0);
-
-	    gamef = 1;
-	    pad[0].st = 1;
-	    return;
-	}
-	if ((pad[0].se > 0) && (pad[0].st > 0)) {
-	    gamef = 0;
-	    break;
-	}
-    }
+    gamef =  2;
+    return gamef;
 }
 
-static void
-game_pause(SDL_Joystick *joy)
+static int
+opening(int gamef)
+{
+    if(use_keybord == 1) {
+	keybord();
+    } else {
+	Pad(joy);
+    }
+
+    count = 1;
+
+    PutSprite(count, 700, 480, 53); //  put `push start' string on screen.  
+    count++;
+    PutSprite(count, 224, 776, 119); //  put `super dandy'                   
+    count++;
+    //    PutSprite(count, 200, 64, 190);
+    //    PutSpriteEx(count, 8192, 8192, 0);
+    PutSpriteEx(190, 800, 264, 2, 2, 5);
+    count++;
+    PutSprite(count, 396, 432, 191);
+    //PutSpriteEx(count, 8192, 8192, 0);
+    count++;
+    PutSprite(count, 640, 640, 192);
+    //PutSpriteEx(count, 8192, 8192, 0);
+
+    if (pad[0].st > 1) {
+	jiki.bf = TRUE;
+	
+	//CdPlay(1,&cdp[0],0);                                          
+	SoundStop();
+	SoundPlay(0);
+
+	gamef = 3;
+	pad[0].st = 1;
+    } else if ((pad[0].se > 0) && (pad[0].st > 0)) {
+	gamef = 2;
+    }
+    return gamef;
+}
+
+static int
+game_pause(int gamef)
 {
     if (jiki.zanki != 0 && jiki.bf != FALSE) {
 	if (pad[0].se == 1) {
@@ -431,25 +430,25 @@
 		//      	PutSpriteEx(1, 409 * ((cc % 60) + 1), 409 * ((cc % 60) + 1), 0);
 
 		Pad(joy);
-		SDL_GL_SwapBuffers( );
+		flip();  // this is not correct
 	    }
 	}
 	if (rswait > 60 * 6) {
 	    cf = 0;
 	    rswait = 0;
-	    gamesyokika(joy);
+	    gamef = gamesyokika(gamef);
 	}
 	rswait++;
 	count++;
 	//cgcg(1);
 	PutSprite(1, 480, 480, 19);
-	return;
+	return gamef;
     }
     if (jiki.bf == FALSE) {
     f:
 	if (rswait < 80) {
 	    rswait++;
-	    return;
+	    return gamef;
 	} else {
 	    rswait = 0;
 	    jiki.x = 60;
@@ -462,10 +461,11 @@
 	    laser_lv3[0].r = 62;
 	    tlv3[0].r = 0;
 	    tlv3[0].y = -1;
-	    return;
+	    return gamef;
 	    // sb_size = -1;                                                    
 	}
     }
+    return gamef;
 }
 
 
@@ -505,6 +505,7 @@
 {
     SpriteTable *m = &sptable[number];
     char *name = (char *) m->texture;
+if (!name) return;
     SceneGraphPtr object = sgroot->createSceneGraph(name);
     object->xyz[0] = x + screen_w /2;
     object->xyz[1] = y + screen_h /2;
@@ -516,6 +517,7 @@
 {
     SpriteTable *m = &sptable[number];
     char *name = (char *) m->texture;
+if (!name) return;
     SceneGraphPtr object = sgroot->createSceneGraph(name);
     object->xyz[0] = x + screen_w /2;
     object->xyz[1] = y + screen_h /2;
--- a/Makefile	Wed Dec 08 00:07:08 2010 +0900
+++ b/Makefile	Wed Dec 08 02:04:07 2010 +0900
@@ -16,7 +16,7 @@
 test: $(TARGET)
 	./demo  -test
 
-demo: $(OBJS) sgoex.o
+demo: $(OBJS) sgoex.o main.o
 	$(CC) $(ABI) -o $@ main.o sgoex.o $(OBJS) $(LIBS)
 
 dandy: $(OBJS) Dandy.o