# HG changeset patch # User koba # Date 1294756771 -32400 # Node ID 5484b8606e8e6d32bcc729702d60a65bf11f71ae # Parent 6626e451a09d954fdb0fb8d75e0806669d1c04a5 add trace mode to tree_dandy2(GL). diff -r 6626e451a09d -r 5484b8606e8e TaskDandy.cc --- a/TaskDandy.cc Tue Jan 11 16:27:01 2011 +0900 +++ b/TaskDandy.cc Tue Jan 11 23:39:31 2011 +0900 @@ -97,7 +97,7 @@ return new Dandy(); } - +static void get_input(int argc, char *argv[]); static int opening(int gamef); static int dandy_closing(int gamef); static int dandy_main_loop(int gamef); @@ -132,6 +132,7 @@ task_init(); task_initialize(); manager->set_TMend(TMend); + get_input(argc, argv); return init(manager,argc, argv); } diff -r 6626e451a09d -r 5484b8606e8e main.c --- a/main.c Tue Jan 11 16:27:01 2011 +0900 +++ b/main.c Tue Jan 11 23:39:31 2011 +0900 @@ -38,7 +38,7 @@ static int cc = 0; static Uint32 background; -// static char *pad_trace_file; +static char *pad_trace_file; extern void schedule(); extern void tokuten(); @@ -63,35 +63,38 @@ * by capture-mode */ -#ifdef ENABLE_TRACEMODE + #define SCMP_SIZ 8 -void print_usage() +static void +print_usage() { - dbg_printf("usage: %s [-h|-help|--help][--capture filename][--trace filename]\n",PROGRAM_NAME); + printf("usage: exe_file [-h|-help|--help][-capture filename][-trace filename]\n"); } - -int get_option(int argc, char *argv[]) +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 (!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)) { + } 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; @@ -103,7 +106,6 @@ } return 1; } -#endif //ENABLE_TRACEMODE int main(int argc, char *argv[]) @@ -118,19 +120,19 @@ int frames = 0; int start_time = 0, stop_time = 0; -#ifdef ENABLE_TRACEMODE if (get_option(argc, argv)) { - print_usage(); - return (1); + print_usage(); + return 1; } - if (pad_trace_file) { + if ((runmode == 1)||(runmode == 2)) { pad_file_open(pad_trace_file); } - if(myrand_open_file("rand_trace")) { - perror("main"); - retun 1; + /* + if(myrand_open_file("rand_trace")) { + perror("main"); + retun 1; } -#endif //ENABLE_TRACEMODE + */ //SDL_Joystick *joy=SDL_JoystickOpen(0); @@ -230,10 +232,28 @@ obj_draw(); pause(joy); - if (use_keybord) { + switch (runmode) { + case 0: + if (use_keybord) { + keybord(); + } else { + Pad(joy); + } + break; + case 1: + if (use_keybord) { keybord(); - } else { + } else { Pad(joy); + } + capture_pad(); + break; + case 2: + if (!pad_file_read()) { + printf("can't trace file.\n"); + runmode = 0; + } + break; } glFlush(); @@ -268,6 +288,7 @@ FreeSdlMixer() ; //_______________________________________________ + pad_file_close(); SDL_Quit(); return(0); diff -r 6626e451a09d -r 5484b8606e8e sgoex.c --- a/sgoex.c Tue Jan 11 16:27:01 2011 +0900 +++ b/sgoex.c Tue Jan 11 23:39:31 2011 +0900 @@ -190,13 +190,8 @@ // SDL_GL_SwapBuffers(); } - - struct SGO_PAD pad[2]; -#ifdef ENABLE_TRACEMODE -extern int runmode; -#endif //ENABLE_TRACEMODE /* コントローラ状態の読み込み */ void Pad(SDL_Joystick *joy) @@ -395,10 +390,12 @@ } if (keys[SDLK_ESCAPE]) { - SDL_Quit(); - exit(1); - //pad[0].st = 1; - //pad[0].se = 1; + pad_file_close(); + + SDL_Quit(); + exit(1); + //pad[0].st = 1; + //pad[0].se = 1; } if (keys[SDLK_0]) { @@ -408,3 +405,23 @@ } } + +void +capture_pad() +{ + fprintf(pad_fp, "%hd ", pad[0].up); + fprintf(pad_fp, "%hd ", pad[0].down); + fprintf(pad_fp, "%hd ", pad[0].right); + fprintf(pad_fp, "%hd ", pad[0].left); + fprintf(pad_fp, "%hd ", pad[0].k0); + fprintf(pad_fp, "%hd ", pad[0].k1); + fprintf(pad_fp, "%hd ", pad[0].k3); + fprintf(pad_fp, "%hd ", pad[0].k4); + fprintf(pad_fp, "%hd ", pad[0].r1); + fprintf(pad_fp, "%hd ", pad[0].r2); + fprintf(pad_fp, "%hd ", pad[0].l1); + fprintf(pad_fp, "%hd ", pad[0].st); + fprintf(pad_fp, "%hd ", pad[0].se); + + fprintf(pad_fp, "\n"); +} diff -r 6626e451a09d -r 5484b8606e8e sgoex.h --- a/sgoex.h Tue Jan 11 16:27:01 2011 +0900 +++ b/sgoex.h Tue Jan 11 23:39:31 2011 +0900 @@ -93,7 +93,7 @@ void DefSprite(int number, const char *name, float w, float h, int color, OBJECT *obj); void DefSpriteEx(int number, short middlex, short middley); void PutSpriteEx(int number, int x, int y, float scalex, float scaley, float angle); - +void capture_pad(); /* Joypad - Below member are implemented in sgoex_ps2.c */ extern SGO_PAD pad[2]; diff -r 6626e451a09d -r 5484b8606e8e trace.c --- a/trace.c Tue Jan 11 16:27:01 2011 +0900 +++ b/trace.c Tue Jan 11 23:39:31 2011 +0900 @@ -1,43 +1,59 @@ -#include +#include +#include "trace.h" +#include "object.h" +#include "sgoex.h" #define PAD_BUFSIZ 32 #define RESET_BUTTON 768 -#ifdef ENABLE_TRACEMODE - -static FILE *pad_fp; +FILE *pad_fp; +int runmode; static char pad_buf[PAD_BUFSIZ]; -void pad_trace(unsigned int pad) +void +pad_trace(unsigned int pad) { fprintf(pad_fp, "%d\n", pad); } -int pad_file_open(char *f) + +void +pad_file_open(char *f) { pad_fp = fopen(f, "r+"); if (!pad_fp) { // 本当はerrnoをチェックするのがいいんだろうなぁ pad_fp = fopen(f, "w+"); - if (pad_fp) { - return 0; + if (!pad_fp) { + printf("can't open output file.\n"); + runmode = 0; } -// goto dbg_abort(4); - return 1; + // goto dbg_abort(4); } - return 0; } -int pad_file_read() + +int +pad_file_read() { - int padd; - if (fgets(pad_buf, PAD_BUFSIZ, pad_fp)) { - sscanf(pad_buf, "%d", &padd); - return padd; - } - return RESET_BUTTON; + if (fgets(pad_buf, PAD_BUFSIZ, pad_fp)) { + sscanf(pad_buf, "%hd %hd %hd %hd %hd %hd %hd %hd %hd %hd %hd %hd %hd ", + &pad[0].up, &pad[0].down, &pad[0].right, &pad[0].left, + &pad[0].k0, &pad[0].k1, &pad[0].k3, &pad[0].k4, + &pad[0].r1, &pad[0].r2, &pad[0].l1, &pad[0].st, &pad[0].se); + return 1; + } + return 0; } -#endif //ENABLE_TRACEMODE + + +void +pad_file_close() +{ + if ((runmode ==1)||(runmode == 2)) { + fclose(pad_fp); + } +} #ifdef USE_MYRAND static FILE *myrand_fp; diff -r 6626e451a09d -r 5484b8606e8e trace.h --- a/trace.h Tue Jan 11 16:27:01 2011 +0900 +++ b/trace.h Tue Jan 11 23:39:31 2011 +0900 @@ -1,3 +1,7 @@ -extern void pad_trace(int); -extern void pad_file_open(char *f); -extern int pad_file_read(); +extern FILE *pad_fp; +extern int runmode; + +void pad_trace(int); +void pad_file_open(char *f); +int pad_file_read(); +void pad_file_close();