changeset 41:6974c3834700

all trace mode moving.
author koba <koba@cr.ie.u-ryukyu.ac.jp>
date Wed, 12 Jan 2011 00:17:27 +0900
parents cbe5bb9068c3
children 59b070dd0553
files TaskDandy.cc
diffstat 1 files changed, 79 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/TaskDandy.cc	Wed Jan 12 00:01:02 2011 +0900
+++ b/TaskDandy.cc	Wed Jan 12 00:17:27 2011 +0900
@@ -52,7 +52,8 @@
 static int game_pause(int);
 
 extern void task_init();
-//static char *pad_trace_file;
+
+static char *pad_trace_file;
 
 /**
  * runmode:
@@ -64,10 +65,10 @@
  *     program will run with a trace file which is generated           
  *     by capture-mode
  */
-int runmode;
 
 SDL_Joystick *joy;
 
+#define SCMP_SIZ 8
 
 const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\
   -length  Number of data (default DATA_NUM (Func.h))\n\
@@ -97,7 +98,8 @@
     return new Dandy();
 }
 
-static void get_input(int argc, char *argv[]);
+static void print_usage();
+static int get_option(int argc, char *argv[]);
 static int opening(int gamef);
 static int dandy_closing(int gamef);
 static int dandy_main_loop(int gamef);
@@ -132,7 +134,9 @@
     task_init();
     task_initialize();
     manager->set_TMend(TMend);
-    get_input(argc, argv);
+    if (get_option(argc, argv)) {
+	print_usage();
+    }
 
     return init(manager,argc, argv);
 }
@@ -163,6 +167,47 @@
 }
 
 
+static void
+print_usage()
+{
+  printf("usage: exe_file [-h|-help|--help][-capture filename][-trace filename]\n");
+}
+
+
+static int
+get_option(int argc, char *argv[])
+{
+    int i;
+    if (argc < 2) {
+	return 0;
+    }
+    for (i = 0; i < argc; i++) {
+	if (!strncmp(argv[i], "-capture", SCMP_SIZ)) {
+	    if (++i >= argc) {
+		return 1;
+	    }
+	    printf("Start capture mode.\n");
+	    pad_trace_file = argv[i];
+	    runmode = 1;
+	    return 0;
+	} else if (!strncmp(argv[i], "-trace", SCMP_SIZ)) {
+	    if (++i >= argc) {
+		return 1;
+	    }
+	    printf("Start trace mode.\n");
+	    pad_trace_file = argv[i];
+	    runmode = 2;
+	    return 0;
+	} else if (!strncmp(argv[i], "--help", SCMP_SIZ) ||
+		   !strncmp(argv[i], "-help", SCMP_SIZ) ||
+		   !strncmp(argv[i], "-h", SCMP_SIZ)) {
+	    return 1;
+	}
+    }
+    return 1;
+}
+
+
 static int 
 dandy_main_init(int gamef)
 {
@@ -173,6 +218,9 @@
     /**
      * timeprof があるんだけどね
      */
+    if ((runmode == 1)||(runmode == 2)) {
+	pad_file_open(pad_trace_file);
+    }
 
     sgroot->createFromXMLfile("xml/character.xml");
     sgroot->createFromXMLfile("xml/font.xml");
@@ -301,11 +349,30 @@
 	obj_draw();
 	gamef = game_pause(gamef);
 
-	if (use_keybord) {
-	    keybord();
-	} else {
-	    Pad(joy);
+	switch (runmode) {
+	case 0:
+	    if (use_keybord) {
+		keybord();
+	    } else {
+		Pad(joy);
+	    }
+	    break;
+	case 1:
+	    if (use_keybord) {
+		keybord();
+	    } else {
+		Pad(joy);
+	    }
+	    capture_pad();
+	    break;
+	case 2:
+	    if (!pad_file_read()) {
+		printf("can't trace file.\n");
+		runmode = 0;
+	    }
+	    break;
 	}
+
 	filpcount++;
 	count = 0;
 
@@ -315,6 +382,7 @@
 static int
 dandy_closing(int gamef)
 {
+    pad_file_close();
 
     //_______________________________________________
     // SDL_mixerの後始末
@@ -335,7 +403,7 @@
 	tlv3[i].y = -1;
     }
     filpcount = 0;
-    stage = 4;
+    stage = 0;
     //for (i = 0; i < 300; i++)
     //enemy[i].f = FALSE;
     jiki.zanki = 3;
@@ -785,6 +853,8 @@
     }
 
     if (keys[SDLK_ESCAPE]) {
+	pad_file_close();
+
 	SDL_Quit();
 	exit(1);
 	//pad[0].st = 1;