Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit enet;
- interface
- {$MACRO ON}
- {$INLINE ON}
- {$PACKRECORDS C}
- {$DEFINE lenet := cdecl; external 'enet'}
- //===== enet/win32.h and enet/unix.h =====
- {$IFDEF WINDOWS}
- uses
- winsock2;
- type
- ENetSocket = TSocket;
- const
- ENET_SOCKET_NULL = INVALID_SOCKET;
- type
- pENetBuffer = ^ENetBuffer;
- ENetBuffer = record
- dataLength: SizeUint;
- data: pointer;
- end;
- {$ELSE}
- uses
- BaseUnix,
- Sockets;
- type
- ENetSocket = longint;
- const
- ENET_SOCKET_NULL = -1;
- type
- pENetBuffer = ^ENetBuffer;
- ENetBuffer = record
- data: pointer;
- dataLength: SizeUint;
- end;
- {$ENDIF}
- type
- pENetSocketSet = ^ENetSocketSet;
- ENetSocketSet = TFDSet;
- function ENET_HOST_TO_NET_16(const value: word): word; inline;
- function ENET_HOST_TO_NET_32(const value: longword): longword; inline;
- function ENET_NET_TO_HOST_16(const value: word): word; inline;
- function ENET_NET_TO_HOST_32(const value: word): longword; inline;
- procedure ENET_SOCKETSET_EMPTY(var sockset: ENetSocketSet); inline;
- procedure ENET_SOCKETSET_ADD(var sockset: ENetSocketSet;
- socket: ENetSocket); inline;
- procedure ENET_SOCKETSET_REMOVE(var sockset: ENetSocketSet;
- socket: ENetSocket); inline;
- function ENET_SOCKETSET_CHECK(sockset: ENetSocketSet;
- socket: ENetSocket): boolean; inline;
- //===== enet/types.h ====
- type
- penet_uint8 = ^enet_uint8;
- enet_uint8 = byte;
- penet_uint16 = ^enet_uint16;
- enet_uint16 = word;
- penet_uint32 = ^enet_uint32;
- enet_uint32 = longword;
- //===== enet/protocol.h =====
- const
- ENET_PROTOCOL_MINIMUM_MTU = 576;
- ENET_PROTOCOL_MAXIMUM_MTU = 4096;
- ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS = 32;
- ENET_PROTOCOL_MINIMUM_WINDOW_SIZE = 4096;
- ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE = 65536;
- ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT = 1;
- ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255;
- ENET_PROTOCOL_MAXIMUM_PEER_ID = $FFF;
- ENET_PROTOCOL_MAXIMUM_PACKET_SIZE = 1024 * 1024 * 1024;
- ENET_PROTOCOL_MAXIMUM_FRAGMENT_COUNT = 1024 * 1024;
- type
- ENetProtocolCommand = (
- ENET_PROTOCOL_COMMAND_NONE,
- ENET_PROTOCOL_COMMAND_ACKNOWLEDGE,
- ENET_PROTOCOL_COMMAND_CONNECT,
- ENET_PROTOCOL_COMMAND_VERIFY_CONNECT,
- ENET_PROTOCOL_COMMAND_DISCONNECT,
- ENET_PROTOCOL_COMMAND_PING,
- ENET_PROTOCOL_COMMAND_SEND_RELIABLE,
- ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE,
- ENET_PROTOCOL_COMMAND_SEND_FRAGMENT,
- ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED,
- ENET_PROTOCOL_COMMAND_BANDWIDTH_LIMIT,
- ENET_PROTOCOL_COMMAND_THROTTLE_CONFIGURE,
- ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE_FRAGMENT,
- ENET_PROTOCOL_COMMAND_COUNT,
- ENET_PROTOCOL_COMMAND_MASK = $0F);
- const
- //ENetProtocolFlag
- ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE = 1 shl 7;
- ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED = 1 shl 6;
- ENET_PROTOCOL_HEADER_FLAG_COMPRESSED = 1 shl 14;
- ENET_PROTOCOL_HEADER_FLAG_SENT_TIME = 1 shl 15;
- ENET_PROTOCOL_HEADER_FLAG_MASK = ENET_PROTOCOL_HEADER_FLAG_COMPRESSED or
- ENET_PROTOCOL_HEADER_FLAG_SENT_TIME;
- ENET_PROTOCOL_HEADER_SESSION_MASK = 3 shl 12;
- ENET_PROTOCOL_HEADER_SESSION_SHIFT = 12;
- type
- pENetProtocolHeader = ^ENetProtocolHeader;
- ENetProtocolHeader = record
- peerID,
- sentTime: enet_uint16;
- end;
- pENetProtocolCommandHeader = ^ENetProtocolCommandHeader;
- ENetProtocolCommandHeader = record
- command,
- channelID: enet_uint8;
- reliableSequenceNumber: enet_uint16;
- end;
- pENetProtocolAcknowledge = ^ENetProtocolAcknowledge;
- ENetProtocolAcknowledge = record
- header: ENetProtocolCommandHeader;
- receivedReliableSequenceNumber,
- receivedSentTime: enet_uint16;
- end;
- pENetProtocolConnect = ^ENetProtocolConnect;
- ENetProtocolConnect = record
- header: ENetProtocolCommandHeader;
- outgoingPeerID: enet_uint16;
- incomingSessionID,
- outgoingSessionID: enet_uint8;
- mtu,
- windowSize,
- channelCount,
- incomingBandwidth,
- outgoingBandwidth,
- packetThrottleInterval,
- packetThrottleAcceleration,
- packetThrottleDeceleration,
- connectID,
- data: enet_uint32;
- end;
- pENetProtocolVerifyConnect = ^ENetProtocolVerifyConnect;
- ENetProtocolVerifyConnect = record
- header: ENetProtocolCommandHeader;
- outgoingPeerID: enet_uint16;
- incomingSessionID,
- outgoingSessionID: enet_uint8;
- mtu,
- windowSize,
- channelCount,
- incomingBandwidth,
- outgoingBandwidth,
- packetThrottleInterval,
- packetThrottleAcceleration,
- packetThrottleDeceleration,
- connectID: enet_uint32;
- end;
- pENetProtocolBandwidthLimit = ^ENetProtocolBandwidthLimit;
- ENetProtocolBandwidthLimit = record
- header: ENetProtocolCommandHeader;
- incomingBandwidth,
- outgoingBandwidth: enet_uint32;
- end;
- pENetProtocolThrottleConfigure = ^ENetProtocolThrottleConfigure;
- ENetProtocolThrottleConfigure = record
- header: ENetProtocolCommandHeader;
- packetThrottleInterval,
- packetThrottleAcceleration,
- packetThrottleDeceleration: enet_uint32;
- end;
- pENetProtocolDisconnect = ^ENetProtocolDisconnect;
- ENetProtocolDisconnect = record
- header: ENetProtocolCommandHeader;
- data: enet_uint32;
- end;
- pENetProtocolPing = ^ENetProtocolPing;
- ENetProtocolPing = record
- header: ENetProtocolCommandHeader;
- end;
- pENetProtocolSendReliable = ^ENetProtocolSendReliable;
- ENetProtocolSendReliable = record
- header: ENetProtocolCommandHeader;
- dataLength: enet_uint16;
- end;
- pENetProtocolSendUnreliable = ^ENetProtocolSendUnreliable;
- ENetProtocolSendUnreliable = record
- header: ENetProtocolCommandHeader;
- unreliableSequenceNumber,
- dataLength: enet_uint16;
- end;
- pENetProtocolSendUnsequenced = ^ENetProtocolSendUnsequenced;
- ENetProtocolSendUnsequenced = record
- header: ENetProtocolCommandHeader;
- unsequencedGroup,
- dataLength: enet_uint16;
- end;
- pENetProtocolSendFragment = ^ENetProtocolSendFragment;
- ENetProtocolSendFragment = record
- header: ENetProtocolCommandHeader;
- startSequenceNumber,
- dataLength: enet_uint16;
- fragmentCount,
- fragmentNumber,
- totalLength,
- fragmentOffset: enet_uint32;
- end;
- pENetProtocol = ^ENetProtocol;
- ENetProtocol = record
- case byte of
- 0: (header : ENetProtocolCommandHeader);
- 1: (acknowledge : ENetProtocolAcknowledge);
- 2: (connect : ENetProtocolConnect);
- 3: (verifyConnect : ENetProtocolVerifyConnect);
- 4: (disconnect : ENetProtocolDisconnect);
- 5: (ping : ENetProtocolPing);
- 6: (sendReliable : ENetProtocolSendReliable);
- 7: (sendUnreliable : ENetProtocolSendUnreliable);
- 8: (sendUnsequenced : ENetProtocolSendUnsequenced);
- 9: (sendFragment : ENetProtocolSendFragment);
- 10: (bandwidthLimit : ENetProtocolBandwidthLimit);
- 11: (throttleConfigure : ENetProtocolThrottleConfigure);
- end;
- //===== enet/list.h =====
- type
- pENetListNode = ^ENetListNode;
- ENetListNode = record
- next,
- previous: pENetListNode;
- end;
- ENetListIterator = pENetListNode;
- pENetList = ^ENetList;
- ENetList = record
- sentinel: ENetListNode;
- end;
- procedure enet_list_clear(list: pENetList); lenet;
- function enet_list_insert(position: ENetListIterator;
- data: pointer): ENetListIterator; lenet;
- function enet_list_remove(position: ENetListIterator): pointer; lenet;
- function enet_list_move(position: ENetListIterator;
- dataFirst, dataLast: pointer): ENetListIterator; lenet;
- function enet_list_size(list: pENetList): SizeUint; lenet;
- function enet_list_begin(list: pENetList): ENetListIterator; inline;
- function enet_list_end(list: pENetList): ENetListIterator; inline;
- function enet_list_empty(list: pENetList): boolean; inline;
- function enet_list_next(iterator: ENetListIterator): ENetListIterator; inline;
- function enet_list_previous(iterator: ENetListIterator): ENetListIterator; inline;
- function enet_list_front(list: pENetList): pointer; inline;
- function enet_list_back(list: pENetList): pointer; inline;
- //===== enet/callbacks.h =====
- type
- pENetCallbacks = ^ENetCallbacks;
- ENetCallbacks = record
- malloc: function(size: SizeUint): pointer; cdecl;
- free: procedure(memory: pointer); cdecl;
- no_memory: procedure; cdecl;
- end;
- function enet_malloc(size: SizeUint): pointer; lenet;
- procedure enet_free(memory: pointer); lenet;
- //===== enet/enet.h =====
- const
- ENET_VERSION_MAJOR = 1;
- ENET_VERSION_MINOR = 3;
- ENET_VERSION_PATCH = 12;
- type
- ENetVersion = enet_uint32;
- function ENET_VERSION_CREATE(const major, minor, patch: longint): ENetVersion; inline;
- function ENET_VERSION_GET_MAJOR(const version: ENetVersion): longint; inline;
- function ENET_VERSION_GET_MINOR(const version: ENetVersion): longint; inline;
- function ENET_VERSION_GET_PATCH(const version: ENetVersion): longint; inline;
- function ENET_VERSION: ENetVersion; inline;
- type
- ENetSocketType = (
- ENET_SOCKET_TYPE_STREAM = 1,
- ENET_SOCKET_TYPE_DATAGRAM);
- ENetSocketWait = (
- ENET_SOCKET_WAIT_NONE = 0,
- ENET_SOCKET_WAIT_SEND = 1 shl 0,
- ENET_SOCKET_WAIT_RECEIVE = 1 shl 1,
- ENET_SOCKET_WAIT_INTERRUPT = 1 shl 2);
- ENetSocketOption = (
- ENET_SOCKOPT_NONBLOCK = 1,
- ENET_SOCKOPT_BROADCAST,
- ENET_SOCKOPT_RCVBUF,
- ENET_SOCKOPT_SNDBUF,
- ENET_SOCKOPT_REUSEADDR,
- ENET_SOCKOPT_RCVTIMEO,
- ENET_SOCKOPT_SNDTIMEO,
- ENET_SOCKOPT_ERROR,
- ENET_SOCKOPT_NODELAY);
- ENetSocketShutdown = (
- ENET_SOCKET_SHUTDOWN_READ,
- ENET_SOCKET_SHUTDOWN_WRITE,
- ENET_SOCKET_SHUTDOWN_READ_WRITE);
- const
- ENET_HOST_ANY = 0;
- ENET_HOST_BROADCAST_ = $ffffffff;
- ENET_PORT_ANY = 0;
- type
- pENetAddress = ^ENetAddress;
- ENetAddress = record
- host: enet_uint32;
- port: enet_uint16;
- end;
- const
- ENET_PACKET_FLAG_RELIABLE = 1 shl 0;
- ENET_PACKET_FLAG_UNSEQUENCED = 1 shl 1;
- ENET_PACKET_FLAG_NO_ALLOCATE = 1 shl 2;
- ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT = 1 shl 3;
- ENET_PACKET_FLAG_SENT = 1 shl 8;
- type
- pENetPacket = ^ENetPacket;
- ENetPacketFreeCallback = procedure(packet: pENetPacket); cdecl;
- ENetPacket = record
- referenceCount : SizeUint;
- flags : enet_uint32;
- data : ^enet_uint8;
- dataLength : SizeUint;
- freeCallback : ENetPacketFreeCallback;
- userData : pointer;
- end;
- pENetAcknowledgement = ^ENetAcknowledgement;
- ENetAcknowledgement = record
- acknowledgementList : ENetListNode;
- sentTime : enet_uint32;
- command : ENetProtocol;
- end;
- pENetOutgoingCommand = ^ENetOutgoingCommand;
- ENetOutgoingCommand = record
- outgoingCommandList : ENetListNode;
- reliableSequenceNumber,
- unreliableSequenceNumber : enet_uint16;
- sentTime,
- roundTripTimeout,
- roundTripTimeoutLimit,
- fragmentOffset : enet_uint32;
- fragmentLength,
- sendAttempts : enet_uint16;
- command : ENetProtocol;
- packet : pENetPacket;
- end;
- pENetIncomingCommand = ^ENetIncomingCommand;
- ENetIncomingCommand = record
- incomingCommandList : ENetListNode;
- reliableSequenceNumber,
- unreliableSequenceNumber : enet_uint16;
- command : ENetProtocol;
- fragmentCount,
- fragmentsRemaining,
- fragments : ^enet_uint32;
- packet : pENetPacket;
- end;
- ENetPeerState = (
- ENET_PEER_STATE_DISCONNECTED,
- ENET_PEER_STATE_CONNECTING,
- ENET_PEER_STATE_ACKNOWLEDGING_CONNECT,
- ENET_PEER_STATE_CONNECTION_PENDING,
- ENET_PEER_STATE_CONNECTION_SUCCEEDED,
- ENET_PEER_STATE_CONNECTED,
- ENET_PEER_STATE_DISCONNECT_LATER,
- ENET_PEER_STATE_DISCONNECTING,
- ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT,
- ENET_PEER_STATE_ZOMBIE);
- const
- ENET_BUFFER_MAXIMUM = 1 + 2 * ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS;
- ENET_HOST_RECEIVE_BUFFER_SIZE = 256 * 1024;
- ENET_HOST_SEND_BUFFER_SIZE = 256 * 1024;
- ENET_HOST_BANDWIDTH_THROTTLE_INTERVAL = 1000;
- ENET_HOST_DEFAULT_MTU = 1400;
- ENET_PEER_DEFAULT_ROUND_TRIP_TIME = 500;
- ENET_PEER_DEFAULT_PACKET_THROTTLE = 32;
- ENET_PEER_PACKET_THROTTLE_SCALE = 32;
- ENET_PEER_PACKET_THROTTLE_COUNTER = 7;
- ENET_PEER_PACKET_THROTTLE_ACCELERATION = 2;
- ENET_PEER_PACKET_THROTTLE_DECELERATION = 2;
- ENET_PEER_PACKET_THROTTLE_INTERVAL = 5000;
- ENET_PEER_PACKET_LOSS_SCALE = 1 shl 16;
- ENET_PEER_PACKET_LOSS_INTERVAL = 10000;
- ENET_PEER_WINDOW_SIZE_SCALE = 64 * 1024;
- ENET_PEER_TIMEOUT_LIMIT = 32;
- ENET_PEER_TIMEOUT_MINIMUM = 5000;
- ENET_PEER_TIMEOUT_MAXIMUM = 30000;
- ENET_PEER_PING_INTERVAL_ = 500;
- ENET_PEER_UNSEQUENCED_WINDOWS = 64;
- ENET_PEER_UNSEQUENCED_WINDOW_SIZE = 1024;
- ENET_PEER_FREE_UNSEQUENCED_WINDOWS = 32;
- ENET_PEER_RELIABLE_WINDOWS = 16;
- ENET_PEER_RELIABLE_WINDOW_SIZE = $1000;
- ENET_PEER_FREE_RELIABLE_WINDOWS = 8;
- type
- pENetChannel = ^ENetChannel;
- ENetChannel = record
- outgoingReliableSequenceNumber,
- outgoingUnreliableSequenceNumber,
- usedReliableWindows : enet_uint16;
- reliableWindows : array [0..ENET_PEER_RELIABLE_WINDOWS-1] of enet_uint16;
- incomingReliableSequenceNumber,
- incomingUnreliableSequenceNumber : enet_uint16;
- incomingReliableCommands,
- incomingUnreliableCommands : ENetList;
- end;
- pENetHost = ^ENetHost;
- pENetPeer = ^ENetPeer;
- ENetPeer = record
- dispatchList : ENetListNode;
- host : pENetHost;
- outgoingPeerID,
- incomingPeerID : enet_uint16;
- connectID : enet_uint32;
- outgoingSessionID,
- incomingSessionID : enet_uint8;
- address : ENetAddress;
- data : pointer;
- state : ENetPeerState;
- channels : pENetChannel;
- channelCount : SizeUint;
- incomingBandwidth,
- outgoingBandwidth,
- incomingBandwidthThrottleEpoch,
- outgoingBandwidthThrottleEpoch,
- incomingDataTotal,
- outgoingDataTotal,
- lastSendTime,
- lastReceiveTime,
- nextTimeout,
- earliestTimeout,
- packetLossEpoch,
- packetsSent,
- packetsLost,
- packetLoss,
- packetLossVariance,
- packetThrottle,
- packetThrottleLimit,
- packetThrottleCounter,
- packetThrottleEpoch,
- packetThrottleAcceleration,
- packetThrottleDeceleration,
- packetThrottleInterval,
- pingInterval,
- timeoutLimit,
- timeoutMinimum,
- timeoutMaximum,
- lastRoundTripTime,
- lowestRoundTripTime,
- lastRoundTripTimeVariance,
- highestRoundTripTimeVariance,
- roundTripTime,
- roundTripTimeVariance,
- mtu,
- windowSize,
- reliableDataInTransit : enet_uint32;
- outgoingReliableSequenceNumber : enet_uint16;
- acknowledgements,
- sentReliableCommands,
- sentUnreliableCommands,
- outgoingReliableCommands,
- outgoingUnreliableCommands,
- dispatchedCommands : ENetList;
- needsDispatch : longint;
- incomingUnsequencedGroup,
- outgoingUnsequencedGroup : enet_uint16;
- unsequencedWindow : array [0..(ENET_PEER_UNSEQUENCED_WINDOW_SIZE div 32) - 1] of enet_uint32;
- eventData : enet_uint32;
- totalWaitingData : SizeUint;
- end;
- pENetCompressor = ^ENetCompressor;
- ENetCompressor = record
- context: pointer;
- compress: function(context: pointer;
- const inBuffers: pENetBuffer;
- inBufferCount, inLimit: SizeUint;
- outData: penet_uint8;
- outLimit: SizeUInt): SizeUint; cdecl;
- decompress: function(
- context: pointer;
- const inData: penet_uint8;
- inLimit: SizeUint;
- outData: penet_uint8;
- outLimit: SizeUint): SizeUint; cdecl;
- destroy: procedure(context: pointer); cdecl;
- end;
- ENetEventType = (
- ENET_EVENT_TYPE_NONE,
- ENET_EVENT_TYPE_CONNECT,
- ENET_EVENT_TYPE_DISCONNECT,
- ENET_EVENT_TYPE_RECEIVE);
- pENetEvent = ^ENetEvent;
- ENetEvent = record
- type_ : ENetEventType;
- peer : pENetPeer;
- channelID : enet_uint8;
- data : enet_uint32;
- packet : pENetPacket;
- end;
- ENetChecksumCallback = function(const buffers: pENetBuffer;
- bufferCount: SizeUint): enet_uint32; cdecl;
- ENetInterceptCallback = function(host: pENetHost;
- event: pENetEvent): longint; cdecl;
- ENetHost = record
- socket : ENetSocket;
- address : ENetAddress;
- incomingBandwidth,
- outgoingBandwidth,
- bandwidthThrottleEpoch,
- mtu,
- randomSeed : enet_uint32;
- recalculateBandwidthLimits : longint;
- peers : pENetPeer;
- peerCount,
- channelLimit : SizeUint;
- serviceTime : enet_uint32;
- dispatchQueue : ENetList;
- continueSending : longint;
- packetSize : SizeUint;
- headerFlags : enet_uint16;
- commands : array [0..ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS - 1] of ENetProtocol;
- commandCount : SizeUint;
- buffers : array [0..ENET_BUFFER_MAXIMUM - 1] of ENetBuffer;
- bufferCount : SizeUint;
- checksum : ENetChecksumCallback;
- compressor : ENetCompressor;
- packetData : array [0..1, 0..ENET_PROTOCOL_MAXIMUM_MTU - 1] of enet_uint8;
- receivedAddress : ENetAddress;
- receivedData : penet_uint8;
- receivedDataLength : SizeUint;
- totalSentData,
- totalSentPackets,
- totalReceivedData,
- totalReceivedPackets : enet_uint32;
- intercept : ENetInterceptCallback;
- connectedPeers,
- bandwidthLimitedPeers,
- duplicatePeers,
- maximumPacketSize,
- maximumWaitingData : SizeUint;
- end;
- function enet_initialize: longint; lenet;
- function enet_initialize_with_callbacks(version: ENetVersion;
- const inits: pENetCallbacks): longint; lenet;
- procedure enet_deinitialize; lenet;
- function enet_linked_version: ENetVersion; lenet;
- function enet_time_get: enet_uint32; lenet;
- procedure enet_time_set(newTimeBase: enet_uint32); lenet;
- function enet_socket_create(kind: ENetSocketType): ENetSocket; lenet;
- function enet_socket_bind(socket: ENetSocket; const address: pENetAddress): longint; lenet;
- function enet_socket_get_address(socket: ENetSocket; address: pENetAddress): longint; lenet;
- function enet_socket_listen(socket: ENetSocket; backlog: longint): longint; lenet;
- function enet_socket_accept(socket: ENetSocket; address: pENetAddress): ENetSocket; lenet;
- function enet_socket_connect(socket: ENetSocket; const address: pENetAddress): longint; lenet;
- function enet_socket_send(socket: ENetSocket; const address: pENetAddress; const buffers: pENetBuffer; bufferCount: SizeUint): longint; lenet;
- function enet_socket_receive(socket: ENetSocket; address: pENetAddress; buffers: pENetBuffer; bufferCount: SizeUint): longint; lenet;
- function enet_socket_wait(socket: ENetSocket; condition: penet_uint32; timeout: enet_uint32): longint; lenet;
- function enet_socket_set_option(socket: ENetSocket; option: ENetSocketOption; value: longint): longint; lenet;
- function enet_socket_get_option(socket: ENetSocket; option: ENetSocketOption; value: plongint): longint; lenet;
- function enet_socket_shutdown(socket: ENetSocket; how: ENetSocketShutdown): longint; lenet;
- procedure enet_socket_destroy(socket: ENetSocket); lenet;
- function enet_socketset_select(maxSocket: ENetSocket; readSet: pENetSocketSet; writeSet: pENetSocketSet; timeout: enet_uint32): longint; lenet;
- function enet_address_set_host(address: pENetAddress; const hostName: pAnsiChar): longint; lenet;
- function enet_address_get_host_ip(const address: pENetAddress; hostName: pAnsiChar; nameLength: SizeUint): longint; lenet;
- function enet_address_get_host(const address: pENetAddress; hostName: pAnsiChar; nameLength: SizeUint): longint; lenet;
- function enet_packet_create(const data: pointer; dataLength: SizeUint; flags: enet_uint32): pENetPacket; lenet;
- procedure enet_packet_destroy(packet: pENetPacket); lenet;
- function enet_packet_resize(packet: pENetPacket; dataLength: SizeUint): longint; lenet;
- function enet_crc32(const buffers: pENetBuffer; bufferCount: SizeUint): enet_uint32; lenet;
- function enet_host_create(const address: pENetAddress; peerCount, channelLimit: SizeUint; incomingBandwidth, outgoingBandwidth: enet_uint32): pENetHost; lenet;
- procedure enet_host_destroy(host: pENetHost); lenet;
- function enet_host_connect(host: pENetHost; const address: pENetAddress; channelCount: SizeUint; data: enet_uint32): pENetPeer; lenet;
- function enet_host_check_events(host: pENetHost; event: pENetEvent): longint; lenet;
- function enet_host_service(host: pENetHost; event: pENetEvent; timeout: enet_uint32): longint; lenet;
- procedure enet_host_flush(host: pENetHost); lenet;
- procedure enet_host_broadcast(host: pENetHost; channelID: enet_uint8; packet: pENetPacket); lenet;
- procedure enet_host_compress(host: pENetHost; const compressor: pENetCompressor); lenet;
- function enet_host_compress_with_range_coder(host: pENetHost): longint; lenet;
- procedure enet_host_channel_limit(host: pENetHost; channelLimit: SizeUint); lenet;
- procedure enet_host_bandwidth_limit(host: pENetHost; incomingBandwidth, outgoingBandwidth: enet_uint32); lenet;
- procedure enet_host_bandwidth_throttle(host: pENetHost); lenet;
- function enet_host_random_seed: enet_uint32; lenet;
- function enet_peer_send(peer: pENetPeer; channelID: enet_uint8; packet: pENetPacket): longint; lenet;
- function enet_peer_receive(peer: pENetPeer; channelID: penet_uint8): pENetPacket; lenet;
- procedure enet_peer_ping(peer: pENetPeer); lenet;
- procedure enet_peer_ping_interval(peer: pENetPeer; pingInterval: enet_uint32); lenet;
- procedure enet_peer_timeout(peer: pENetPeer; timeoutLimit, timeoutMinimum, timeoutMaximum: enet_uint32); lenet;
- procedure enet_peer_reset(peer: pENetPeer); lenet;
- procedure enet_peer_disconnect(peer: pENetPeer; data: enet_uint32); lenet;
- procedure enet_peer_disconnect_now(peer: pENetPeer; data: enet_uint32); lenet;
- procedure enet_peer_disconnect_later(peer: pENetPeer; data: enet_uint32); lenet;
- procedure enet_peer_throttle_configure(peer: pENetPeer; interval, acceleration, deceleration: enet_uint32); lenet;
- function enet_peer_throttle(peer: pENetPeer; rtt: enet_uint32): longint; lenet;
- procedure enet_peer_reset_queues(peer: pENetPeer); lenet;
- procedure enet_peer_setup_outgoing_command(peer: pENetPeer; outgoingCommand: pENetOutgoingCommand); lenet;
- function enet_peer_queue_outgoing_command(peer: pENetPeer; const command: pENetProtocol; packet: pENetPacket; offset: enet_uint32; length: enet_uint16): pENetOutgoingCommand; lenet;
- function enet_peer_queue_incoming_command(peer: pENetPeer; const command: pENetProtocol; packet: pENetPacket; fragmentCount: enet_uint32): pENetIncomingCommand; lenet;
- function enet_peer_queue_queue_acknowledgement(peer: pENetPeer; const command: pENetProtocol; sentTime: enet_uint16): pENetAcknowledgement; lenet;
- procedure enet_peer_dispatch_incoming_unreliable_commands(peer: pENetPeer; channel: pENetChannel); lenet;
- procedure enet_peer_dispatch_incoming_reliable_commands(peer: pENetPeer; channel: pENetChannel); lenet;
- procedure enet_peer_on_connect(peer: pENetPeer); lenet;
- procedure enet_peer_on_disconnect(peer: pENetPeer); lenet;
- function enet_range_coder_create: pointer; lenet;
- procedure enet_range_coder_destroy(context: pointer); lenet;
- function enet_range_coder_compress(context: pointer; const inBuffers: pENetBuffer; inBufferCount, inLiit: SizeUint; outData: penet_uint8; outLimit: SizeUint): SizeUint; lenet;
- function enet_range_coder_decompress(context: pointer; const inData: penet_uint8; inLimit: SizeUint; outData: penet_uint8; outLimit: SizeUint): SizeUint; lenet;
- function enet_protocol_command_size(commandNumber: enet_uint8): SizeUint; lenet;
- implementation
- //===== enet/win32.h and enet/unix.h =====
- function ENET_HOST_TO_NET_16(const value: word): word; inline;
- begin
- exit(htons(value));
- end;
- function ENET_HOST_TO_NET_32(const value: longword): longword; inline;
- begin
- exit(htonl(value));
- end;
- function ENET_NET_TO_HOST_16(const value: word): word; inline;
- begin
- exit(ntohs(value));
- end;
- function ENET_NET_TO_HOST_32(const value: word): longword; inline;
- begin
- exit(ntohl(value));
- end;
- procedure ENET_SOCKETSET_EMPTY(var sockset: ENetSocketSet); inline;
- begin
- {$IFNDEF WINDOWS}fpFD_ZERO{$ELSE}FD_ZERO{$ENDIF}(sockset);
- end;
- procedure ENET_SOCKETSET_ADD(var sockset: ENetSocketSet;
- socket: ENetSocket); inline;
- begin
- {$IFNDEF WINDOWS}fpFD_SET{$ELSE}FD_SET{$ENDIF}(socket, sockset);
- end;
- procedure ENET_SOCKETSET_REMOVE(var sockset: ENetSocketSet;
- socket: ENetSocket); inline;
- begin
- {$IFNDEF WINDOWS}fpFD_CLR{$ELSE}FD_CLR{$ENDIF}(socket, sockset);
- end;
- function ENET_SOCKETSET_CHECK(sockset: ENetSocketSet;
- socket: ENetSocket): boolean; inline;
- begin
- {$IFNDEF WINDOWS}
- exit(fpFD_ISSET(socket, sockset) <> 0);
- {$ELSE}
- exit(FD_ISSET(socket, sockset));
- {$ENDIF}
- end;
- //===== enet/list.h =====
- function enet_list_begin(list: pENetList): ENetListIterator; inline;
- begin
- exit(list^.sentinel.next);
- end;
- function enet_list_end(list: pENetList): ENetListIterator; inline;
- begin
- exit(@list^.sentinel);
- end;
- function enet_list_empty(list: pENetList): boolean; inline;
- begin
- exit(enet_list_begin(list) = enet_list_end(list));
- end;
- function enet_list_next(iterator: ENetListIterator): ENetListIterator; inline;
- begin
- exit(iterator^.next);
- end;
- function enet_list_previous(iterator: ENetListIterator): ENetListIterator; inline;
- begin
- exit(iterator^.previous);
- end;
- function enet_list_front(list: pENetList): pointer; inline;
- begin
- exit(pointer(list^.sentinel.next));
- end;
- function enet_list_back(list: pENetList): pointer; inline;
- begin
- exit(pointer(list^.sentinel.previous));
- end;
- //===== enet/enet.h =====
- function ENET_VERSION_CREATE(const major, minor, patch: longint): ENetVersion; inline;
- begin
- exit((major shl 16) or (minor shl 16) or patch);
- end;
- function ENET_VERSION_GET_MAJOR(const version: ENetVersion): longint; inline;
- begin
- exit((version shr 16) and $ff);
- end;
- function ENET_VERSION_GET_MINOR(const version: ENetVersion): longint; inline;
- begin
- exit((version shr 8) and $ff);
- end;
- function ENET_VERSION_GET_PATCH(const version: ENetVersion): longint; inline;
- begin
- exit(version and $ff);
- end;
- function ENET_VERSION: ENetVersion; inline;
- begin
- exit(ENET_VERSION_CREATE(
- ENET_VERSION_MAJOR,
- ENET_VERSION_MINOR,
- ENET_VERSION_PATCH));
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement