Mercurial > hg > Members > koba > t_dandy
comparison 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 |
comparison
equal
deleted
inserted
replaced
43:56ef94618a0e | 44:2c85322348cf |
---|---|
28 #include "error.h" | 28 #include "error.h" |
29 #include "matrix_calc.h" | 29 #include "matrix_calc.h" |
30 #include "Character.h" | 30 #include "Character.h" |
31 #include "Character_state.h" | 31 #include "Character_state.h" |
32 | 32 |
33 int use_keybord = 0; | 33 static int use_keybord = 0; |
34 int cdp[20] = { 16, 16, 16, 17, 18, 0 }; | 34 static int cdp[20] = { 16, 16, 16, 17, 18, 0 }; |
35 int d, i; | 35 static int d, i; |
36 | 36 |
37 int rswait = 0; | 37 static int rswait = 0; |
38 int cf = 0; | 38 static int cf = 0; |
39 int cc = 0; | 39 static int cc = 0; |
40 | 40 |
41 //static SDL_Surface *screen; | 41 //static SDL_Surface *screen; |
42 // static Uint32 background; | 42 // static Uint32 background; |
43 // static char *pad_trace_file; | 43 // static char *pad_trace_file; |
44 | 44 |
46 extern void tokuten(); | 46 extern void tokuten(); |
47 extern void Pad(); | 47 extern void Pad(); |
48 extern void keybord(); | 48 extern void keybord(); |
49 static int gamesyokika(int gamef); | 49 static int gamesyokika(int gamef); |
50 static int game_pause(int); | 50 static int game_pause(int); |
51 | 51 static void KeyAssign(int runmode, TraceBuffPtr buff, SDL_Joystick *joy, SGO_PAD *pad); |
52 | |
53 static int runmode = 0; | |
54 static TraceBuffPtr t_buff; | |
55 static TraceBuffPtr first; | |
52 static char *pad_trace_file; | 56 static char *pad_trace_file; |
53 | 57 |
54 /** | 58 /** |
55 * runmode: | 59 * runmode: |
56 * 0 - normal game | 60 * 0 - normal game |
60 * 2 - trace mode | 64 * 2 - trace mode |
61 * program will run with a trace file which is generated | 65 * program will run with a trace file which is generated |
62 * by capture-mode | 66 * by capture-mode |
63 */ | 67 */ |
64 | 68 |
65 SDL_Joystick *joy; | 69 static SDL_Joystick *joy; |
66 | 70 |
67 #define SCMP_SIZ 8 | 71 #define SCMP_SIZ 8 |
68 | 72 |
69 const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\ | 73 const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\ |
70 -length Number of data (default DATA_NUM (Func.h))\n\ | 74 -length Number of data (default DATA_NUM (Func.h))\n\ |
169 | 173 |
170 | 174 |
171 static void | 175 static void |
172 print_usage() | 176 print_usage() |
173 { | 177 { |
174 printf("usage: exe_file [-h|-help|--help][-capture filename][-trace filename]\n"); | 178 printf("usage: ./exe_file [-h|-help|--help][-capture filename][-trace filename]\n"); |
175 } | 179 } |
176 | 180 |
177 | 181 |
178 static int | 182 static int |
179 get_option(int argc, char *argv[]) | 183 get_option(int argc, char *argv[]) |
180 { | 184 { |
181 int i; | 185 int i; |
182 if (argc < 2) { | 186 if (argc < 2) { |
187 runmode = 0; | |
188 return 0; | |
189 } | |
190 for (i = 0; i < argc; i++) { | |
191 if (!strncmp(argv[i], "-capture", SCMP_SIZ)) { | |
192 if (++i >= argc) { | |
193 return 1; | |
194 } | |
195 printf("Start Capture mode.\n"); | |
196 t_buff = (TraceBuffPtr)malloc(sizeof(TraceBuff)); | |
197 t_buff->next = NULL; | |
198 pad_trace_file = argv[i]; | |
199 runmode = 1; | |
183 return 0; | 200 return 0; |
184 } | 201 } else if (!strncmp(argv[i], "-trace", SCMP_SIZ)) { |
185 for (i = 0; i < argc; i++) { | 202 if (++i >= argc) { |
186 if (!strncmp(argv[i], "-capture", SCMP_SIZ)) { | 203 return 1; |
187 if (++i >= argc) { | 204 } |
188 return 1; | 205 printf("Start Trace mode.\n"); |
189 } | 206 t_buff = (TraceBuffPtr)malloc(sizeof(TraceBuff)); |
190 printf("Start capture mode.\n"); | 207 t_buff->next = NULL; |
191 pad_trace_file = argv[i]; | 208 pad_trace_file = argv[i]; |
192 runmode = 1; | 209 runmode = 2; |
193 return 0; | 210 return 0; |
194 } else if (!strncmp(argv[i], "-trace", SCMP_SIZ)) { | 211 } else if (!strncmp(argv[i], "--help", SCMP_SIZ) || |
195 if (++i >= argc) { | 212 !strncmp(argv[i], "-help", SCMP_SIZ) || |
196 return 1; | 213 !strncmp(argv[i], "-h", SCMP_SIZ)) { |
197 } | 214 return 1; |
198 printf("Start trace mode.\n"); | 215 } |
199 pad_trace_file = argv[i]; | 216 } |
200 runmode = 2; | 217 |
201 return 0; | |
202 } else if (!strncmp(argv[i], "--help", SCMP_SIZ) || | |
203 !strncmp(argv[i], "-help", SCMP_SIZ) || | |
204 !strncmp(argv[i], "-h", SCMP_SIZ)) { | |
205 return 1; | |
206 } | |
207 } | |
208 return 1; | 218 return 1; |
209 } | 219 } |
210 | 220 |
211 | 221 |
212 static int | 222 static int |
217 dbg_init("/dev/stdout"); | 227 dbg_init("/dev/stdout"); |
218 | 228 |
219 /** | 229 /** |
220 * timeprof があるんだけどね | 230 * timeprof があるんだけどね |
221 */ | 231 */ |
222 if ((runmode == 1)||(runmode == 2)) { | 232 if ((runmode == 1)||(runmode ==2)) { |
223 pad_file_open(pad_trace_file); | 233 if (!PadfileOpen(pad_trace_file)) { |
234 runmode = 0; | |
235 } else if(runmode == 2) { | |
236 PadfileRead(t_buff); | |
237 } | |
238 first = t_buff; | |
224 } | 239 } |
225 | 240 |
226 sgroot->createFromXMLfile("xml/character.xml"); | 241 sgroot->createFromXMLfile("xml/character.xml"); |
227 sgroot->createFromXMLfile("xml/font.xml"); | 242 sgroot->createFromXMLfile("xml/font.xml"); |
228 sgroot->createFromXMLfile("xml/effect.xml"); | 243 sgroot->createFromXMLfile("xml/effect.xml"); |
346 //PutSprite(count, 0, 0, 48); | 361 //PutSprite(count, 0, 0, 48); |
347 | 362 |
348 obj_draw(); | 363 obj_draw(); |
349 gamef = game_pause(gamef); | 364 gamef = game_pause(gamef); |
350 | 365 |
351 switch (runmode) { | 366 KeyAssign(runmode, t_buff, joy, pad); |
352 case 0: | |
353 if (use_keybord) { | |
354 keybord(); | |
355 } else { | |
356 Pad(joy); | |
357 } | |
358 break; | |
359 case 1: | |
360 if (use_keybord) { | |
361 keybord(); | |
362 } else { | |
363 Pad(joy); | |
364 } | |
365 capture_pad(); | |
366 break; | |
367 case 2: | |
368 if (!pad_file_read()) { | |
369 printf("can't trace file.\n"); | |
370 runmode = 0; | |
371 } | |
372 break; | |
373 } | |
374 | 367 |
375 filpcount++; | 368 filpcount++; |
376 count = 0; | 369 count = 0; |
377 | 370 |
378 return gamef; | 371 return gamef; |
379 } | 372 } |
380 | 373 |
381 static int | 374 static int |
382 dandy_closing(int gamef) | 375 dandy_closing(int gamef) |
383 { | 376 { |
384 pad_file_close(); | 377 if (runmode == 1) { |
378 PadfileWrite(first); | |
379 PadfileClose(first); | |
380 } else if (runmode == 2) { | |
381 PadfileClose(first); | |
382 } | |
385 | 383 |
386 //_______________________________________________ | 384 //_______________________________________________ |
387 // SDL_mixerの後始末 | 385 // SDL_mixerの後始末 |
388 Mix_CloseAudio(); | 386 Mix_CloseAudio(); |
389 Mix_HaltMusic(); | 387 Mix_HaltMusic(); |
853 } else { | 851 } else { |
854 pad[0].se = 0; | 852 pad[0].se = 0; |
855 } | 853 } |
856 | 854 |
857 if (keys[SDLK_ESCAPE]) { | 855 if (keys[SDLK_ESCAPE]) { |
858 pad_file_close(); | 856 pad[0].quit = 1; |
859 | |
860 SDL_Quit(); | |
861 exit(1); | |
862 //pad[0].st = 1; | |
863 //pad[0].se = 1; | |
864 } | 857 } |
865 | 858 |
866 if (keys[SDLK_0]) { | 859 if (keys[SDLK_0]) { |
867 pad[0].quit = 1; | 860 pad[0].quit = 1; |
868 } else { | 861 } else { |
869 pad[0].quit = 0; | 862 pad[0].quit = 0; |
870 } | 863 } |
871 } | 864 } |
872 | 865 |
873 | 866 |
867 static void | |
868 KeyAssign(int runmode, TraceBuffPtr buff, SDL_Joystick *joy, SGO_PAD *pad) | |
869 { | |
870 switch (runmode) { | |
871 case 0: | |
872 if (use_keybord) { | |
873 keybord(); | |
874 } else { | |
875 Pad(joy); | |
876 } | |
877 break; | |
878 case 1: | |
879 if (use_keybord) { | |
880 keybord(); | |
881 } else { | |
882 Pad(joy); | |
883 } | |
884 t_buff = CapturePad(t_buff, pad); | |
885 break; | |
886 case 2: | |
887 t_buff = TracePad(t_buff, pad); | |
888 break; | |
889 } | |
890 } | |
891 | |
874 /* end */ | 892 /* end */ |