0
|
1 /**
|
|
2 * 2006/07/31(MON) Nobutaka OSHIRO
|
|
3 */
|
|
4 #include "game_time.h"
|
|
5
|
|
6 int game_time_get_msec() {
|
|
7
|
|
8 struct timeval now;
|
|
9 int time_msec;
|
|
10
|
|
11 /**
|
|
12 * *** man timeval ***
|
|
13 * struct timeval {
|
|
14 * time_t tv_sec // second
|
|
15 * suseconds_t tv_usec; // micro sec
|
|
16 * };
|
|
17 **/
|
|
18
|
|
19 // get time micro second ( micro second = 1 / 1000,000 second)
|
|
20 gettimeofday(&now, NULL);
|
|
21
|
|
22 // evaluation milli second ( milli second = 1 / 1000 second )
|
|
23 time_msec = now.tv_sec * 1000 + now.tv_usec / 1000;
|
|
24
|
|
25 return time_msec;
|
|
26 }
|
|
27
|
|
28
|
|
29 int game_time_conv_ms2cs (int msec)
|
|
30 {
|
|
31 return msec / 10 % 100; /** 1/100 sec **/
|
|
32 }
|
|
33
|
|
34 int game_time_conv_ms2sec (int msec)
|
|
35 {
|
|
36 return msec / 1000 % 60;
|
|
37 }
|
|
38
|
|
39 int game_time_conv_ms2minute (int msec)
|
|
40 {
|
|
41 return msec / 60000 % 60;
|
|
42 }
|
|
43
|
|
44
|
|
45 /**
|
|
46 * NAME:
|
|
47 * game_time_set_raptime - Return RAP TIME ("XXX:XX:XX")
|
|
48 *
|
|
49 * DESCRIPTION:
|
|
50 * 1. convert (int --> string)
|
|
51 * (int) argument2 (milli second) --> "XXX:XX:XX"
|
|
52 *
|
|
53 * 2. set ( string --> char * )
|
|
54 * "XXX:XX:XX" --> char *argument1
|
|
55 **/
|
|
56 void game_time_set_raptime (char *s,int msec)
|
|
57 {
|
|
58 char chminute[3];
|
|
59 char chsec[2];
|
|
60 char chcsec[2];
|
|
61 char raptime[10];
|
|
62 int minute = game_time_conv_ms2minute (msec);
|
|
63 int sec = game_time_conv_ms2sec (msec);
|
|
64 int csec = game_time_conv_ms2cs (msec);
|
|
65 int i;
|
|
66
|
|
67
|
|
68 if (minute < 10 ){
|
|
69 chminute[0] = ' ';
|
|
70 chminute[1] = '0';
|
|
71 chminute[2] = minute + 48;
|
|
72 } else if (minute < 100 ) {
|
|
73 chminute[0] = ' ';
|
|
74 chminute[1] = (minute / 10) + 48;
|
|
75 chminute[2] = (minute % 10) + 48;
|
|
76 } else {
|
|
77 chminute[0] = (minute / 100) + 48;
|
|
78 chminute[1] = (minute / 10) + 48;
|
|
79 chminute[2] = (minute % 10) + 48;
|
|
80 }
|
|
81 if (sec < 10 ){
|
|
82 chsec[0] = '0';
|
|
83 chsec[1] = sec + 48;
|
|
84 } else {
|
|
85 chsec[0] = (sec / 10) + 48;
|
|
86 chsec[1] = (sec % 10) + 48;
|
|
87 }
|
|
88
|
|
89 if (csec < 10 ){
|
|
90 chcsec[0] = '0';
|
|
91 chcsec[1] = csec + 48;
|
|
92 } else {
|
|
93 chcsec[0] = (csec / 10) + 48;
|
|
94 chcsec[1] = (csec % 10) + 48;
|
|
95 }
|
|
96
|
|
97
|
|
98 /** raptime[0-9] == "XXX:XX:XX\0" **/
|
|
99 raptime[0] = chminute[0];
|
|
100 raptime[1] = chminute[1];
|
|
101 raptime[2] = chminute[2];
|
|
102 raptime[3] = ':';
|
|
103 raptime[4] = chsec[0];
|
|
104 raptime[5] = chsec[1];
|
|
105 raptime[6] = ':';
|
|
106 raptime[7] = chcsec[0];
|
|
107 raptime[8] = chcsec[1];
|
|
108 raptime[9] = '\0'; // NULL
|
|
109
|
|
110
|
|
111 for (i = 0; raptime[i] != '\0'; i++) {
|
|
112 s[i] = raptime[i];
|
|
113 }
|
|
114 }
|