diff Dandy.cc @ 44:2c85322348cf

add print log.
author koba <koba@cr.ie.u-ryukyu.ac.jp>
date Fri, 14 Jan 2011 23:49:23 +0900
parents cbe5bb9068c3
children e01948ce859a
line wrap: on
line diff
--- a/Dandy.cc	Fri Jan 14 02:17:57 2011 +0900
+++ b/Dandy.cc	Fri Jan 14 23:49:23 2011 +0900
@@ -30,13 +30,13 @@
 #include "Character.h"
 #include "Character_state.h"
 
-int use_keybord = 0;
-int cdp[20] = { 16, 16, 16, 17, 18, 0 };
-int d, i;
+static int use_keybord = 0;
+static int cdp[20] = { 16, 16, 16, 17, 18, 0 };
+static int d, i;
 
-int rswait = 0;
-int cf = 0;
-int cc = 0;
+static int rswait = 0;
+static int cf = 0;
+static int cc = 0;
 
 //static SDL_Surface *screen;
 // static Uint32 background;
@@ -48,7 +48,11 @@
 extern void keybord();
 static int gamesyokika(int gamef);
 static int game_pause(int);
+static void KeyAssign(int runmode, TraceBuffPtr buff, SDL_Joystick *joy, SGO_PAD *pad);
 
+static int runmode = 0;
+static TraceBuffPtr t_buff;
+static TraceBuffPtr first;
 static char *pad_trace_file;
 
 /**
@@ -62,7 +66,7 @@
  *     by capture-mode
  */
 
-SDL_Joystick *joy;
+static SDL_Joystick *joy;
 
 #define SCMP_SIZ 8
 
@@ -171,7 +175,7 @@
 static void
 print_usage()
 {
-  printf("usage: exe_file [-h|-help|--help][-capture filename][-trace filename]\n");
+  printf("usage: ./exe_file [-h|-help|--help][-capture filename][-trace filename]\n");
 }
 
 
@@ -180,31 +184,37 @@
 {
     int i;
     if (argc < 2) {
-	return 0;
+      runmode = 0;
+      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;
+      if (!strncmp(argv[i], "-capture", SCMP_SIZ)) {
+	if (++i >= argc) {
+	  return 1;
+	}
+	printf("Start Capture mode.\n");
+	t_buff = (TraceBuffPtr)malloc(sizeof(TraceBuff));
+	t_buff->next = NULL;
+	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");
+	t_buff = (TraceBuffPtr)malloc(sizeof(TraceBuff));
+	t_buff->next = NULL;
+	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;
 }
 
@@ -219,8 +229,13 @@
     /**
      * timeprof があるんだけどね
      */
-    if ((runmode == 1)||(runmode == 2)) {
-	pad_file_open(pad_trace_file);
+    if ((runmode == 1)||(runmode ==2)) {
+	if (!PadfileOpen(pad_trace_file)) {
+	    runmode = 0;
+	} else if(runmode == 2) {
+	    PadfileRead(t_buff);
+	}
+	first = t_buff;
     }
 
     sgroot->createFromXMLfile("xml/character.xml");
@@ -348,29 +363,7 @@
 	obj_draw();
 	gamef = game_pause(gamef);
 
-	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;
-	}
+	KeyAssign(runmode, t_buff, joy, pad);
 	
 	filpcount++;
 	count = 0;
@@ -381,7 +374,12 @@
 static int
 dandy_closing(int gamef)
 {
-    pad_file_close();
+    if (runmode == 1) {
+	PadfileWrite(first);
+	PadfileClose(first);
+    } else if (runmode == 2) {
+	PadfileClose(first);
+    }
 
     //_______________________________________________
     // SDL_mixerの後始末
@@ -855,12 +853,7 @@
     }
 
     if (keys[SDLK_ESCAPE]) {
-	pad_file_close();
-
-	SDL_Quit();
-	exit(1);
-	//pad[0].st = 1;
-	//pad[0].se = 1;
+      	pad[0].quit = 1;
     }
 
     if (keys[SDLK_0]) {
@@ -871,4 +864,29 @@
 }
 
 
+static void
+KeyAssign(int runmode, TraceBuffPtr buff, SDL_Joystick *joy, SGO_PAD *pad)
+{
+    switch (runmode) {
+    case 0:
+      if (use_keybord) {
+	keybord();
+      } else {
+	Pad(joy);
+      }
+      break;
+    case 1:
+      if (use_keybord) {
+	keybord();
+      } else {
+	Pad(joy);
+      }
+      t_buff = CapturePad(t_buff, pad);
+      break;
+    case 2:
+      t_buff = TracePad(t_buff, pad);
+      break;
+    }
+}
+
 /* end */