forked from librae8226/gmsv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handletime.c
381 lines (328 loc) · 9.19 KB
/
handletime.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#define __HANDLETIME_C__
#include "version.h"
#include <time.h>
#include <sys/time.h>
#include "common.h"
#include "handletime.h"
#define LSTIME_SECONDS_PER_DAY 5400 /* LSTIME域 少氏及蜇 及 醒 */
/*
LSTIME_SECONDS_PER_DAY 毛 尹月午}凛棉及褡心填宁毛 尹月仇午互匹五月[
袄 LS凛棉匹域 丐凶曰及蜇 及凛棉醒
9000 ( 赏) 2.5 [hour]
900 0.25[hour] = 15[min]
90 0.025[hour] = 1.5[min] = 90[sec]
9 9[sec]
*/
#define LSTIME_HOURS_PER_DAY 1024 /* LSTIME域 少氏及LSTIME及凛棉醒 */
#define LSTIME_DAYS_PER_YEAR 100 /* LSTIME域 少氏及LSTIME及 醒 */
// WON REM
/*
// Nuke 0701: localtime
struct timeval NowTime;
#ifdef localtime
#undef localtime
#endif
struct tm *localtime(const time_t *timep)
{
static struct tm lt;
memset(<,0,sizeof(lt));
lt.tm_sec=*timep %60;
lt.tm_min=(*timep %3600) / 60;
lt.tm_hour=(*timep % 86400) / 3600;
return <
}
*/
/*------------------------------------------------------------
* 域伙□皿卞域荚裟壬木化}凛棉毛褡户月[
* 娄醒
* 卅仄
* 忒曰袄
* 岳 TRUE(1)
* 撩 FALSE(0)
------------------------------------------------------------*/
BOOL setNewTime( void )
{
if( gettimeofday( &NowTime, (struct timezone*)NULL) != 0 ) {
NowTime.tv_sec = time(0);
// Nuke 0701: Localtime down
print("\n time err !! \n");
return FALSE;
}
NowTime.tv_sec += DEBUG_ADJUSTTIME;
return TRUE;
}
/*******************************************************************
漆葭绎卞仄凶[byHiO 1998/12/4 18:37
*******************************************************************/
static long era = (long)912766409 + 5400;
/* SA及啃卞内日仄凶 */
/* LS葭 毛烂聒允月化五午□卅醒袄[
弁仿奶失件玄午 元元扎卅中午分户[*/
/*******************************************************************
穴扑件凛棉井日LS凛棉卞允月
long t : time匹请月
LSTIME *lstime : LSTIME厌瞻 尺及禾奶件正
*******************************************************************/
void RealTimeToLSTime(long t , LSTIME *lstime)
{
long lsseconds = t - era; /* LS葭 井日及 醒 */
long lsdays; /* LS葭 井日及 醒 */
/* 葭 井日及 醒毛1 癫曰及 醒匹喃月午} 卞卅月 */
lstime->year = (int)( lsseconds/(LSTIME_SECONDS_PER_DAY*LSTIME_DAYS_PER_YEAR) );
lsdays = lsseconds/LSTIME_SECONDS_PER_DAY;/* 引内葭 井日及 醒毛煌遥仄化 */
lstime->day = lsdays % LSTIME_DAYS_PER_YEAR;/* 癫凶曰及 醒匹喃匀凶丐引曰互 */
/*(450*12) 匹1 */
lstime->hour = (int)(lsseconds % LSTIME_SECONDS_PER_DAY )
/* 仇仇引匹匹}域 互铵引匀化井日窒 凶匀凶井[ */
* LSTIME_HOURS_PER_DAY / LSTIME_SECONDS_PER_DAY;
/* 域 丐凶曰及 醒匹喃匀化井日域 丐凶曰及凛棉醒毛井仃月午蜇箕窒凛
卅及井互歹井月[*/
return;
}
/*******************************************************************
LS凛棉井日穴扑件凛棉卞允月
LSTIME *lstime : LSTIME厌瞻 尺及禾奶件正
long *t : 凛棉尺及禾奶件正
*******************************************************************/
void LSTimeToRealTime( LSTIME *lstime, long *t)
{
*t=(long)(
( lstime->hour*LSTIME_DAYS_PER_YEAR+lstime->day) /* 凛棉 */
*LSTIME_HOURS_PER_DAY
+ lstime->year)
/*仇及楮醒反壬什匀化中月方丹卞苇尹月[nakamura */
*450;
return;
}
/*******************************************************************
LS凛棉匹漆及凛棉嗉坌毛 月
曰袄 int : 0}苹1}镞2} 3
LSTIME *lstime : LSTIME厌瞻 尺及禾奶件正
*******************************************************************/
LSTIME_SECTION getLSTime (LSTIME *lstime)
{
if (NIGHT_TO_MORNING < lstime->hour
&& lstime->hour <= MORNING_TO_NOON)
return LS_MORNING;
else if(NOON_TO_EVENING < lstime->hour
&& lstime->hour <= EVENING_TO_NIGHT)
return LS_EVENING;
else if(EVENING_TO_NIGHT < lstime->hour
&& lstime->hour <= NIGHT_TO_MORNING)
return LS_NIGHT;
else
return LS_NOON;
}
#ifdef _ASSESS_SYSEFFICACY
static clock_t TotalClock = 0;
static clock_t StartClock = 0;
//static int EndClock = 0;
//static float SysTime=0.0;
static clock_t EndClock = 0;
static double SysTime=0.0;
static int Cnum = 0;
#ifdef _ASSESS_SYSEFFICACY_SUB
static clock_t Net_TotalClock = 0;
static clock_t NPCGEN_TotalClock = 0;
static clock_t Battle_TotalClock = 0;
static clock_t Char_TotalClock = 0;
static clock_t Petmail_TotalClock = 0;
static clock_t Family_TotalClock = 0;
static clock_t SaveCheck_TotalClock = 0;
static clock_t GMBroadCast_TotalClock = 0;
static double Net_SysTime=0.0;
static double NPCGEN_SysTime=0.0;
static double Battle_SysTime=0.0;
static double Char_SysTime=0.0;
static double Petmail_SysTime=0.0;
static double Family_SysTime=0.0;
static double SaveCheck_SysTime=0.0;
static double GMBroadCast_SysTime=0.0;
static clock_t SubStartClock = 0;
#endif
void Assess_InitSysEfficacy()
{
TotalClock = 0;
StartClock = 0;
EndClock = 0;
#ifdef _ASSESS_SYSEFFICACY_SUB
Net_TotalClock = 0;
NPCGEN_TotalClock = 0;
Battle_TotalClock = 0;
Char_TotalClock = 0;
Petmail_TotalClock = 0;
Family_TotalClock = 0;
SaveCheck_TotalClock = 0;
GMBroadCast_TotalClock = 0;
SubStartClock = 0;
#endif
}
void Assess_SysEfficacy( int flg)
{
if( flg == 0 ){
StartClock=clock();
}else if( flg == 1 ){
EndClock = clock();
if( EndClock < StartClock ) return;
TotalClock += (int)(EndClock-StartClock);
Cnum++;
if( Cnum%500 == 0 ){
SysTime = (float)(TotalClock/Cnum)/CLOCKS_PER_SEC;
TotalClock = 0;
#ifdef _ASSESS_SYSEFFICACY_SUB
Net_SysTime = (float)(Net_TotalClock/Cnum)/CLOCKS_PER_SEC;
Net_TotalClock = 0;
NPCGEN_SysTime = (float)(NPCGEN_TotalClock/Cnum)/CLOCKS_PER_SEC;
NPCGEN_TotalClock = 0;
Battle_SysTime = (float)(Battle_TotalClock/Cnum)/CLOCKS_PER_SEC;
Battle_TotalClock = 0;
Char_SysTime = (float)(Char_TotalClock/Cnum)/CLOCKS_PER_SEC;
Char_TotalClock = 0;
Petmail_SysTime = (float)(Petmail_TotalClock/Cnum)/CLOCKS_PER_SEC;
Petmail_TotalClock = 0;
Family_SysTime = (float)(Family_TotalClock/Cnum)/CLOCKS_PER_SEC;
Family_TotalClock = 0;
SaveCheck_SysTime = (float)(SaveCheck_TotalClock/Cnum)/CLOCKS_PER_SEC;
SaveCheck_TotalClock = 0;
GMBroadCast_SysTime = (float)(GMBroadCast_TotalClock/Cnum)/CLOCKS_PER_SEC;
GMBroadCast_TotalClock = 0;
#endif
Cnum = 0;
}
}
/*
EndClock = clock();
if( StartClock != 0 ){
if( EndClock < StartClock ) return;
TotalClock += (int)(EndClock-StartClock);
Cnum++;
if( Cnum%500 == 0 ){
SysTime = (float)TotalClock/Cnum;
TotalClock = 0;
}
}
StartClock = EndClock;
*/
}
void ASSESS_getSysEfficacy( float *TVsec)
{
*TVsec = SysTime;
}
#ifdef _ASSESS_SYSEFFICACY_SUB
void Assess_SysEfficacy_sub( int flg, int loop)
{
if( flg == 0 ){
SubStartClock = clock();
}else if( flg == 1 ){
EndClock = clock();
if( EndClock < SubStartClock ) return;
switch( loop) {
case 1: // Net_TotalClock
Net_TotalClock += (int)(EndClock-SubStartClock);
break;
case 2: // NPCGEN_TotalClock
NPCGEN_TotalClock += (int)(EndClock-SubStartClock);
break;
case 3: // Battle_TotalClock
Battle_TotalClock += (int)(EndClock-SubStartClock);
break;
case 4: // Char_TotalClock
Char_TotalClock += (int)(EndClock-SubStartClock);
break;
case 5: // Petmail_TotalClock
Petmail_TotalClock += (int)(EndClock-SubStartClock);
break;
case 6: // Family_TotalClock
Family_TotalClock += (int)(EndClock-SubStartClock);
break;
case 7: // SaveCheck_TotalClock
SaveCheck_TotalClock += (int)(EndClock-SubStartClock);
break;
case 8: // GMBroadCast_TotalClock
GMBroadCast_TotalClock += (int)(EndClock-SubStartClock);
break;
}
}
}
void ASSESS_getSysEfficacy_sub( float *TVsec, int loop_index)
{
switch( loop_index) {
case 1:
*TVsec = Net_SysTime;
break;
case 2:
*TVsec = NPCGEN_SysTime;
break;
case 3:
*TVsec = Battle_SysTime;
break;
case 4:
*TVsec = Char_SysTime;
break;
case 5:
*TVsec = Petmail_SysTime;
break;
case 6:
*TVsec = Family_SysTime;
break;
case 7:
*TVsec = SaveCheck_SysTime;
break;
case 8:
*TVsec = GMBroadCast_SysTime;
break;
}
}
#endif
#endif
#ifdef _CHECK_BATTLETIME
#include "battle.h"
static clock_t battleComClock = 0;
double battleComTotalTime[BATTLE_COM_END];
long battleComTotalUse[BATTLE_COM_END];
void check_battle_com_init( void)
{
print("\n check_battle_com_init... ");
print("\n BATTLE_COM_END = %d ", BATTLE_COM_END);
memset( battleComTotalTime, 0, sizeof(double)*BATTLE_COM_END);
memset( battleComTotalUse, 0, sizeof(long)*BATTLE_COM_END);
}
void check_battle_com_begin( void)
{
//print(" bi ");
battleComClock = clock();
}
void check_battle_com_end( int b_com)
{
clock_t endClock;
double usedClock;
endClock = clock();
usedClock = (double)(endClock - battleComClock)/CLOCKS_PER_SEC;
print(" BC[%d,%0.10f] ", b_com, usedClock);
battleComTotalTime[b_com] += usedClock;
battleComTotalUse[b_com] ++;
//print(" bo ");
}
void check_battle_com_show( void)
{
FILE *outfile;
int i;
char outstr[1024];
outfile = fopen( "battle_com_time.txt", "w");
if( !outfile)
{
print("\n OPEN battle_com_time.txt ERROR!!! \n");
return;
}
for( i =0; i <BATTLE_COM_END; i++)
{
sprintf( outstr, "%d\t=\t%0.10f\t*\t%d\n",
i,
(double)(battleComTotalTime[i]/battleComTotalUse[i]),
battleComTotalUse[i] );
fputs( outstr, outfile);
}
fclose( outfile);
print("\n RECORD battle_com_time.txt COMPLETE \n");
}
#endif