Mercurial > hg > Members > koba > t_dandy
changeset 43:56ef94618a0e
binary trace move.
author | koba <koba@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 14 Jan 2011 02:17:57 +0900 |
parents | 59b070dd0553 |
children | 2c85322348cf |
files | Character_state.c main.c sgoex.c state_task.cc trace.c trace.h |
diffstat | 6 files changed, 168 insertions(+), 97 deletions(-) [+] |
line wrap: on
line diff
--- a/Character_state.c Wed Jan 12 00:18:16 2011 +0900 +++ b/Character_state.c Fri Jan 14 02:17:57 2011 +0900 @@ -463,7 +463,6 @@ p->vy = rand % 3 -1; p->state = chara_state23; } - printf("x = %f, y = %f, vx = %f, vy = %f\n",p->x, p->y, p->vx, p->vy); return p; } @@ -1212,6 +1211,5 @@ } } asteroidi++; - // printf("x = %f, y = %f, vx = %f, vy = %f\n",p->x, p->y, p->vx, p->vy); return p; }
--- a/main.c Wed Jan 12 00:18:16 2011 +0900 +++ b/main.c Fri Jan 14 02:17:57 2011 +0900 @@ -29,6 +29,7 @@ #include "error.h" + static int gamef = 0; static int use_keybord = 0; static int i; @@ -37,7 +38,11 @@ static int cf = 0; static int cc = 0; +static int runmode; +static TraceBuffPtr first; + static Uint32 background; +static TraceBuffPtr t_buff; static char *pad_trace_file; extern void schedule(); @@ -48,7 +53,7 @@ static void gamesyokika(SDL_Joystick *joy); static void opening(SDL_Joystick *joy); static void pause(SDL_Joystick *joy); -//static char *pad_trace_file; + extern void SDL_GL_Enter2DMode(); extern void SDL_GL_Leave2DMode(); @@ -79,31 +84,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; } @@ -122,11 +133,18 @@ if (get_option(argc, argv)) { print_usage(); - return 1; + return 0; } - 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; } + /* if(myrand_open_file("rand_trace")) { perror("main"); @@ -188,7 +206,7 @@ start_time = SDL_GetTicks(); while (gamef) { - if ((pad[0].l1 != 0) && (pad[0].r1 != 0) && + if ((pad[0].l1 != 0) && (pad[0].r1 != 0) && (pad[0].l2 != 0) && (pad[0].r2 != 0)) { glFlush(); SDL_GL_SwapBuffers( ); @@ -246,13 +264,10 @@ } else { Pad(joy); } - capture_pad(); + t_buff = CapturePad(t_buff, pad); break; case 2: - if (!pad_file_read()) { - printf("can't trace file.\n"); - runmode = 0; - } + t_buff = TracePad(t_buff, pad); break; } @@ -288,7 +303,12 @@ FreeSdlMixer() ; //_______________________________________________ - pad_file_close(); + if (runmode == 1) { + PadfileWrite(first); + PadfileClose(first); + } else if (runmode == 2) { + PadfileClose(first); + } SDL_Quit(); return(0);
--- a/sgoex.c Wed Jan 12 00:18:16 2011 +0900 +++ b/sgoex.c Fri Jan 14 02:17:57 2011 +0900 @@ -32,6 +32,9 @@ //static int padd; +extern int runmode; +extern TraceBuffPtr first; + static const int sgo_tpx[12] = { 0, 64, 128, 192, 256, 320, 0, 64, 128, 192, 256, 320 }; static const int sgo_tpy[12] = { 0, 0, 0, 0, 0, 0, 256, 256, 256, 256, 256, 256 }; @@ -390,12 +393,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]) {
--- a/state_task.cc Wed Jan 12 00:18:16 2011 +0900 +++ b/state_task.cc Fri Jan 14 02:17:57 2011 +0900 @@ -172,7 +172,6 @@ free(obj); CHARACTER *p = (CHARACTER*)chara; -// printf("x = %f, y = %f, vx = %f, vy = %f\n",p->x, p->y, p->vx, p->vy); int num = GetStateNum(p->task); p->state = state_list[num]; @@ -664,8 +663,8 @@ CHARACTER* delete_chara(CHARACTER *p) { - CHARACTER *parent = p; + printf("x = %f, y = %f, vx = %f, vy = %f\n",p->x, p->y, p->vx, p->vy); p->f = FALSE; p->state = noaction; p->collision = noaction;
--- a/trace.c Wed Jan 12 00:18:16 2011 +0900 +++ b/trace.c Fri Jan 14 02:17:57 2011 +0900 @@ -1,79 +1,118 @@ #include <stdio.h> #include "trace.h" -#include "object.h" -#include "sgoex.h" + -#define PAD_BUFSIZ 32 -#define RESET_BUTTON 768 - -FILE *pad_fp; -int runmode; -static char pad_buf[PAD_BUFSIZ]; +static FILE *fileptr; +const char *filename; void pad_trace(unsigned int pad) { - fprintf(pad_fp, "%d\n", pad); + fprintf(fileptr, "%d\n", pad); +} + + +int +PadfileOpen(const char* name) +{ + filename = name; + fileptr = fopen(filename, "rb+"); + + if (!fileptr) { + fileptr = fopen(filename, "wb+"); + if (!fileptr) { + printf("can't open output file.\n"); + return 0; + } + } + + return 1; } void -pad_file_open(char *f) +PadfileRead(TraceBuffPtr buff) { - pad_fp = fopen(f, "r+"); - if (!pad_fp) { -// 本当はerrnoをチェックするのがいいんだろうなぁ - pad_fp = fopen(f, "w+"); - if (!pad_fp) { - printf("can't open output file.\n"); - runmode = 0; - } - // goto dbg_abort(4); + TraceBuffPtr tmp = buff; + fread(buff->cappad, sizeof(SGO_PAD), PAD_BUFSIZE, fileptr); + + while (!feof(fileptr)) { + TraceBuffPtr new_buff = (TraceBuffPtr)malloc(sizeof(TraceBuff)); + tmp->next = new_buff; + new_buff->next = NULL; + tmp = new_buff; + + fread(new_buff->cappad, sizeof(SGO_PAD), PAD_BUFSIZE, fileptr); } } void -capture_pad() +PadfileWrite(TraceBuffPtr buff) { - 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"); + TraceBuffPtr tmp = buff; + fwrite(buff->cappad, sizeof(SGO_PAD), PAD_BUFSIZE, fileptr); + + while (tmp->next != NULL) { + tmp = tmp->next; + fwrite(tmp->cappad, sizeof(SGO_PAD), PAD_BUFSIZE, fileptr); + } } -int -pad_file_read() +TraceBuffPtr +CapturePad(TraceBuffPtr buff, SGO_PAD *pad) { - 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; + static int count; + + if (count !=PAD_BUFSIZE) { + buff->cappad[count] = pad[0]; + ++count; + return buff; + } else { + TraceBuffPtr new_buff = (TraceBuffPtr)malloc(sizeof(TraceBuff)); + new_buff->cappad[0] = pad[0]; + buff->next = new_buff; + new_buff->next = NULL; + + count = 1; + return new_buff; + } +} + + +TraceBuffPtr +TracePad(TraceBuffPtr buff, SGO_PAD *pad) +{ + static int count; + + if (count !=PAD_BUFSIZE) { + pad[0] = buff->cappad[count]; + ++count; + return buff; + } else { + buff = buff->next; + pad[0] = buff->cappad[0]; + + count = 1; + return buff; + } } void -pad_file_close() +PadfileClose(TraceBuffPtr buff) { - if ((runmode ==1)||(runmode == 2)) { - fclose(pad_fp); - } + fclose(fileptr); + + TraceBuffPtr trace = buff; + + while (trace->next != NULL) { + TraceBuffPtr tmp = trace; + trace = trace->next; + free(tmp); + } + free(trace); } #ifdef USE_MYRAND
--- a/trace.h Wed Jan 12 00:18:16 2011 +0900 +++ b/trace.h Fri Jan 14 02:17:57 2011 +0900 @@ -1,8 +1,25 @@ -extern FILE *pad_fp; -extern int runmode; +#ifndef INCLUDE_TRACE_H +#define INCLUDE_TRACE_H + +#include "object.h" +#include "sgoex.h" + +#define PAD_BUFSIZE 5000 + +typedef struct TraceBuff TraceBuff, *TraceBuffPtr; + +struct TraceBuff { + SGO_PAD cappad[PAD_BUFSIZE]; + + TraceBuffPtr next; +}; void pad_trace(int); -void pad_file_open(char *f); -void capture_pad(); -int pad_file_read(); -void pad_file_close(); +int PadfileOpen(const char* filename); +void PadfileRead(TraceBuffPtr buff); +void PadfileWrite(TraceBuffPtr buff); +TraceBuffPtr CapturePad(TraceBuffPtr buff, SGO_PAD *pad); +TraceBuffPtr TracePad(TraceBuffPtr buff, SGO_PAD *pad); +void PadfileClose(TraceBuffPtr buff); + +#endif