1 | /* |
1 | /* |
2 | * static char *rcsid_main_c = |
2 | * static char *rcsid_main_c = |
3 | * "$Id: main.C,v 1.1 2006/08/13 17:16:04 elmex Exp $"; |
3 | * "$Id: main.C,v 1.2 2006/08/15 18:07:25 root Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
1316 | |
1316 | |
1317 | if (!(pticks % 12503)) |
1317 | if (!(pticks % 12503)) |
1318 | fix_luck(); |
1318 | fix_luck(); |
1319 | } |
1319 | } |
1320 | |
1320 | |
|
|
1321 | /* |
|
|
1322 | * sleep_delta checks how much time has elapsed since last tick. |
|
|
1323 | * If it is less than max_time, the remaining time is slept with select(). |
|
|
1324 | */ |
|
|
1325 | |
|
|
1326 | void |
|
|
1327 | sleep_delta(void) |
|
|
1328 | { |
|
|
1329 | extern long max_time; |
|
|
1330 | extern struct timeval last_time; |
|
|
1331 | extern long process_utime_long_count; |
|
|
1332 | extern void cfperl_sleep (double delta); |
|
|
1333 | |
|
|
1334 | struct timeval new_time; |
|
|
1335 | GETTIMEOFDAY (&new_time); |
|
|
1336 | |
|
|
1337 | long sleep_sec = last_time.tv_sec - new_time.tv_sec; |
|
|
1338 | long sleep_usec = max_time - (new_time.tv_usec - last_time.tv_usec); |
|
|
1339 | |
|
|
1340 | /* This is very ugly, but probably the fastest for our use: */ |
|
|
1341 | while (sleep_usec < 0) { |
|
|
1342 | sleep_usec += 1000000; |
|
|
1343 | sleep_sec -= 1; |
|
|
1344 | } |
|
|
1345 | while (sleep_usec > 1000000) { |
|
|
1346 | sleep_usec -= 1000000; |
|
|
1347 | sleep_sec += 1; |
|
|
1348 | } |
|
|
1349 | |
|
|
1350 | log_time((new_time.tv_sec - last_time.tv_sec)*1000000 |
|
|
1351 | + new_time.tv_usec - last_time.tv_usec); |
|
|
1352 | |
|
|
1353 | /* |
|
|
1354 | * Set last_time to when we're expected to wake up: |
|
|
1355 | */ |
|
|
1356 | last_time.tv_usec += max_time; |
|
|
1357 | while (last_time.tv_usec > 1000000) { |
|
|
1358 | last_time.tv_usec -= 1000000; |
|
|
1359 | last_time.tv_sec++; |
|
|
1360 | } |
|
|
1361 | |
|
|
1362 | /* |
|
|
1363 | * Don't do too much catching up: |
|
|
1364 | * (Things can still get jerky on a slow/loaded computer) |
|
|
1365 | */ |
|
|
1366 | if (last_time.tv_sec * 1000000 + last_time.tv_usec < |
|
|
1367 | new_time.tv_sec * 1000000 + new_time.tv_usec) |
|
|
1368 | { |
|
|
1369 | last_time.tv_sec = new_time.tv_sec; |
|
|
1370 | last_time.tv_usec = new_time.tv_usec; |
|
|
1371 | } |
|
|
1372 | |
|
|
1373 | if (sleep_sec >= 0 && sleep_usec > 0) |
|
|
1374 | cfperl_sleep (sleep_sec + sleep_usec * 1e-6); |
|
|
1375 | else |
|
|
1376 | process_utime_long_count++; |
|
|
1377 | } |
|
|
1378 | |
1321 | int main(int argc, char **argv) |
1379 | int main(int argc, char **argv) |
1322 | { |
1380 | { |
1323 | #ifdef WIN32 /* ---win32 this sets the win32 from 0d0a to 0a handling */ |
1381 | #ifdef WIN32 /* ---win32 this sets the win32 from 0d0a to 0a handling */ |
1324 | _fmode = _O_BINARY ; |
1382 | _fmode = _O_BINARY ; |
1325 | bRunning = 1; |
1383 | bRunning = 1; |