mirror of
https://github.com/lsalzman/enet
synced 2024-11-21 06:25:59 -07:00
implement mulberry32 for PRNG
This commit is contained in:
parent
2cc0e7c780
commit
e3ada4ed75
2 changed files with 12 additions and 1 deletions
12
host.c
12
host.c
|
@ -160,6 +160,16 @@ enet_host_destroy (ENetHost * host)
|
||||||
enet_free (host);
|
enet_free (host);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enet_uint32
|
||||||
|
enet_host_random (ENetHost * host)
|
||||||
|
{
|
||||||
|
/* Mulberry32 by Tommy Ettinger */
|
||||||
|
enet_uint32 n = (host -> randomSeed += 0x6D2B79F5U);
|
||||||
|
n = (n ^ (n >> 15)) * (n | 1U);
|
||||||
|
n ^= n + (n ^ (n >> 7)) * (n | 61U);
|
||||||
|
return n ^ (n >> 14);
|
||||||
|
}
|
||||||
|
|
||||||
/** Initiates a connection to a foreign host.
|
/** Initiates a connection to a foreign host.
|
||||||
@param host host seeking the connection
|
@param host host seeking the connection
|
||||||
@param address destination for the connection
|
@param address destination for the connection
|
||||||
|
@ -199,7 +209,7 @@ enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelC
|
||||||
currentPeer -> channelCount = channelCount;
|
currentPeer -> channelCount = channelCount;
|
||||||
currentPeer -> state = ENET_PEER_STATE_CONNECTING;
|
currentPeer -> state = ENET_PEER_STATE_CONNECTING;
|
||||||
currentPeer -> address = * address;
|
currentPeer -> address = * address;
|
||||||
currentPeer -> connectID = ++ host -> randomSeed;
|
currentPeer -> connectID = enet_host_random (host);
|
||||||
|
|
||||||
if (host -> outgoingBandwidth == 0)
|
if (host -> outgoingBandwidth == 0)
|
||||||
currentPeer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE;
|
currentPeer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE;
|
||||||
|
|
|
@ -575,6 +575,7 @@ ENET_API void enet_host_channel_limit (ENetHost *, size_t);
|
||||||
ENET_API void enet_host_bandwidth_limit (ENetHost *, enet_uint32, enet_uint32);
|
ENET_API void enet_host_bandwidth_limit (ENetHost *, enet_uint32, enet_uint32);
|
||||||
extern void enet_host_bandwidth_throttle (ENetHost *);
|
extern void enet_host_bandwidth_throttle (ENetHost *);
|
||||||
extern enet_uint32 enet_host_random_seed (void);
|
extern enet_uint32 enet_host_random_seed (void);
|
||||||
|
extern enet_uint32 enet_host_random (ENetHost *);
|
||||||
|
|
||||||
ENET_API int enet_peer_send (ENetPeer *, enet_uint8, ENetPacket *);
|
ENET_API int enet_peer_send (ENetPeer *, enet_uint8, ENetPacket *);
|
||||||
ENET_API ENetPacket * enet_peer_receive (ENetPeer *, enet_uint8 * channelID);
|
ENET_API ENetPacket * enet_peer_receive (ENetPeer *, enet_uint8 * channelID);
|
||||||
|
|
Loading…
Reference in a new issue