summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorludde <ludde@openttd.org>2005-07-15 20:29:06 +0000
committerludde <ludde@openttd.org>2005-07-15 20:29:06 +0000
commit71f9078bddbf26a771c259bc4cde377b90a980ba (patch)
tree4082dbe36cd4d476e1d16f70a88eaa90adb7523f /misc.c
parentc964809d374ef9af63a384a1bd7bc01cdc1bbbf5 (diff)
downloadopenttd-71f9078bddbf26a771c259bc4cde377b90a980ba.tar.xz
(svn r2583) Move OS specific code out of misc.c
Added support for Mersenne Twister random number generator (not implemented in network yet) Wrap player randoms around #ifdef
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c63
1 files changed, 10 insertions, 53 deletions
diff --git a/misc.c b/misc.c
index b4ef52821..0beffba71 100644
--- a/misc.c
+++ b/misc.c
@@ -29,13 +29,14 @@ static inline uint32 ROR(uint32 x, int n)
it completely! -- TrueLight */
#undef PLAYER_SEED_RANDOM
+#ifndef MERSENNE_TWISTER
+
#ifdef RANDOM_DEBUG
#include "network_data.h"
-
uint32 DoRandom(int line, const char *file)
-#else
+#else // RANDOM_DEBUG
uint32 Random(void)
-#endif
+#endif // RANDOM_DEBUG
{
uint32 s;
@@ -66,8 +67,9 @@ uint32 t;
return _random_seeds[0][1] = ROR(s, 3) - 1;
#endif
}
+#endif // MERSENNE_TWISTER
-#ifdef RANDOM_DEBUG
+#if defined(RANDOM_DEBUG) && !defined(MERSENNE_TWISTER)
uint DoRandomRange(uint max, int line, const char *file)
{
return (uint16)DoRandom(line, file) * max >> 16;
@@ -79,6 +81,7 @@ uint RandomRange(uint max)
}
#endif
+
uint32 InteractiveRandom(void)
{
uint32 t = _random_seeds[1][1];
@@ -92,6 +95,8 @@ uint InteractiveRandomRange(uint max)
return (uint16)InteractiveRandom() * max >> 16;
}
+
+#ifdef PLAYER_SEED_RANDOM
void InitPlayerRandoms(void)
{
int i;
@@ -100,6 +105,7 @@ void InitPlayerRandoms(void)
_player_seeds[i][1]=InteractiveRandom();
}
}
+#endif
void SetDate(uint date)
{
@@ -112,55 +118,6 @@ void SetDate(uint date)
#endif /* ENABLE_NETWORK */
}
-
-#ifdef ENABLE_NETWORK
-
-// multi os compatible sleep function
-
-#ifdef __AMIGA__
-// usleep() implementation
-# include <devices/timer.h>
-# include <dos/dos.h>
-
- extern struct Device *TimerBase = NULL;
- extern struct MsgPort *TimerPort = NULL;
- extern struct timerequest *TimerRequest = NULL;
-#endif // __AMIGA__
-
-void CSleep(int milliseconds)
-{
- #if defined(WIN32)
- Sleep(milliseconds);
- #endif
- #if defined(UNIX)
- #if !defined(__BEOS__) && !defined(__AMIGA__)
- usleep(milliseconds * 1000);
- #endif
- #ifdef __BEOS__
- snooze(milliseconds * 1000);
- #endif
- #if defined(__AMIGA__)
- {
- ULONG signals;
- ULONG TimerSigBit = 1 << TimerPort->mp_SigBit;
-
- // send IORequest
- TimerRequest->tr_node.io_Command = TR_ADDREQUEST;
- TimerRequest->tr_time.tv_secs = (milliseconds * 1000) / 1000000;
- TimerRequest->tr_time.tv_micro = (milliseconds * 1000) % 1000000;
- SendIO((struct IORequest *)TimerRequest);
-
- if (!((signals = Wait(TimerSigBit | SIGBREAKF_CTRL_C)) & TimerSigBit) ) {
- AbortIO((struct IORequest *)TimerRequest);
- }
- WaitIO((struct IORequest *)TimerRequest);
- }
- #endif // __AMIGA__
- #endif
-}
-
-#endif /* ENABLE_NETWORK */
-
void InitializeVehicles(void);
void InitializeWaypoints(void);
void InitializeDepot(void);