DEADSOFTWARE

Added stubs for gl, enet and sdl2
[d2df-sdl.git] / src / wrappers / enet / enet.pas
1 {$INCLUDE ../shared/a_modes.inc}
2 {$SCOPEDENUMS OFF}
3 unit ENet;
5 {$DEFINE libraryLibENetDecl := cdecl}
6 {$DEFINE libraryLibENetImp := cdecl}
7 {$DEFINE libraryLibENetVar := cvar}
9 interface
11 uses ctypes;
13 ////////////////////////////////////////////////////////////////////////////////
14 // types.h
15 ////////////////////////////////////////////////////////////////////////////////
17 type
18 enet_uint8 = cuchar;
19 penet_uint8 = ^enet_uint8;
21 enet_uint16 = cushort;
22 penet_uint16 = ^enet_uint16;
24 enet_uint32 = cuint; // TODO: why 'int' instead of 'long'?
25 penet_uint32 = ^enet_uint32;
27 enet_size_t = NativeUInt;
28 penet_size_t = ^enet_size_t;
30 ////////////////////////////////////////////////////////////////////////////////
31 // callbacks.h
32 ////////////////////////////////////////////////////////////////////////////////
34 type
35 pENetCallbacks = ^TENetCallbacks;
36 TENetCallbacks = record
37 malloc : function( size: csize_t ): Pointer; cdecl;
38 free : procedure( memory: Pointer ); cdecl;
39 no_memory : procedure(); cdecl;
40 end;
42 ////////////////////////////////////////////////////////////////////////////////
43 // protocol.h
44 ////////////////////////////////////////////////////////////////////////////////
46 const
47 { unnamed enums }
48 ENET_PROTOCOL_MINIMUM_MTU = 576;
49 ENET_PROTOCOL_MAXIMUM_MTU = 4096;
50 ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS = 32;
51 ENET_PROTOCOL_MINIMUM_WINDOW_SIZE = 4096;
52 ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE = 65536;
53 ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT = 1;
54 ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255;
55 ENET_PROTOCOL_MAXIMUM_PEER_ID = $FFF;
56 ENET_PROTOCOL_MAXIMUM_FRAGMENT_COUNT = 1024 * 1024;
58 { enum ENetProtocolFlag }
59 ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE = 1 shl 7;
60 ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED = 1 shl 6;
61 ENET_PROTOCOL_HEADER_FLAG_COMPRESSED = 1 shl 14;
62 ENET_PROTOCOL_HEADER_FLAG_SENT_TIME = 1 shl 15;
63 ENET_PROTOCOL_HEADER_FLAG_MASK = ENET_PROTOCOL_HEADER_FLAG_COMPRESSED or
64 ENET_PROTOCOL_HEADER_FLAG_SENT_TIME;
65 ENET_PROTOCOL_HEADER_SESSION_MASK = 3 shl 12;
66 ENET_PROTOCOL_HEADER_SESSION_SHIFT = 12;
68 type
69 { enums }
70 ENetProtocolCommand = ( ENET_PROTOCOL_COMMAND_NONE,
71 ENET_PROTOCOL_COMMAND_ACKNOWLEDGE,
72 ENET_PROTOCOL_COMMAND_CONNECT,
73 ENET_PROTOCOL_COMMAND_VERIFY_CONNECT,
74 ENET_PROTOCOL_COMMAND_DISCONNECT,
75 ENET_PROTOCOL_COMMAND_PING,
76 ENET_PROTOCOL_COMMAND_SEND_RELIABLE,
77 ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE,
78 ENET_PROTOCOL_COMMAND_SEND_FRAGMENT,
79 ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED,
80 ENET_PROTOCOL_COMMAND_BANDWIDTH_LIMIT,
81 ENET_PROTOCOL_COMMAND_THROTTLE_CONFIGURE,
82 ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE_FRAGMENT,
83 ENET_PROTOCOL_COMMAND_COUNT,
84 ENET_PROTOCOL_COMMAND_MASK = $0F );
86 { structs / unions }
87 pENetProtocolHeader = ^ENetProtocolHeader;
88 ENetProtocolHeader = packed record
89 peerID : enet_uint16;
90 sentTime : enet_uint16;
91 end;
93 pENetProtocolCommandHeader = ^ENetProtocolCommandHeader;
94 ENetProtocolCommandHeader = packed record
95 command : enet_uint8;
96 channelID : enet_uint8;
97 reliableSequenceNumber : enet_uint16;
98 end;
100 pENetProtocolAcknowledge = ^ENetProtocolAcknowledge;
101 ENetProtocolAcknowledge = packed record
102 header : ENetProtocolCommandHeader;
103 receivedReliableSequenceNumber : enet_uint16;
104 receivedSentTime : enet_uint16;
105 end;
107 pENetProtocolConnect = ^ENetProtocolConnect;
108 ENetProtocolConnect = packed record
109 header : ENetProtocolCommandHeader;
110 outgoingPeerID : enet_uint16;
111 incomingSessionID : enet_uint8;
112 outgoingSessionID : enet_uint8;
113 mtu : enet_uint32;
114 windowSize : enet_uint32;
115 channelCount : enet_uint32;
116 incomingBandwidth : enet_uint32;
117 outgoingBandwidth : enet_uint32;
118 packetThrottleInterval : enet_uint32;
119 packetThrottleAcceleration : enet_uint32;
120 packetThrottleDeceleration : enet_uint32;
121 connectID : enet_uint32;
122 data : enet_uint32;
123 end;
125 pENetProtocolVerifyConnect = ^ENetProtocolVerifyConnect;
126 ENetProtocolVerifyConnect = packed record
127 header : ENetProtocolCommandHeader;
128 outgoingPeerID : enet_uint16;
129 incomingSessionID : enet_uint8;
130 outgoingSessionID : enet_uint8;
131 mtu : enet_uint32;
132 windowSize : enet_uint32;
133 channelCount : enet_uint32;
134 incomingBandwidth : enet_uint32;
135 outgoingBandwidth : enet_uint32;
136 packetThrottleInterval : enet_uint32;
137 packetThrottleAcceleration : enet_uint32;
138 packetThrottleDeceleration : enet_uint32;
139 connectID : enet_uint32;
140 end;
142 pENetProtocolBandwidthLimit = ^ENetProtocolBandwidthLimit;
143 ENetProtocolBandwidthLimit = packed record
144 header : ENetProtocolCommandHeader;
145 incomingBandwidth : enet_uint32;
146 outgoingBandwidth : enet_uint32;
147 end;
149 pENetProtocolThrottleConfigure = ^ENetProtocolThrottleConfigure;
150 ENetProtocolThrottleConfigure = packed record
151 header : ENetProtocolCommandHeader;
152 packetThrottleInterval : enet_uint32;
153 packetThrottleAcceleration : enet_uint32;
154 packetThrottleDeceleration : enet_uint32;
155 end;
157 pENetProtocolDisconnect = ^ENetProtocolDisconnect;
158 ENetProtocolDisconnect = packed record
159 header : ENetProtocolCommandHeader;
160 data : enet_uint32;
161 end;
163 pENetProtocolPing = ^ENetProtocolPing;
164 ENetProtocolPing = packed record
165 header : ENetProtocolCommandHeader;
166 end;
168 pENetProtocolSendReliable = ^ENetProtocolSendReliable;
169 ENetProtocolSendReliable = packed record
170 header : ENetProtocolCommandHeader;
171 dataLength : enet_uint16;
172 end;
174 pENetProtocolSendUnreliable = ^ENetProtocolSendUnreliable;
175 ENetProtocolSendUnreliable = packed record
176 header : ENetProtocolCommandHeader;
177 unreliableSequenceNumber : enet_uint16;
178 dataLength : enet_uint16;
179 end;
181 pENetProtocolSendUnsequenced = ^ENetProtocolSendUnsequenced;
182 ENetProtocolSendUnsequenced = packed record
183 header : ENetProtocolCommandHeader;
184 unsequencedGroup : enet_uint16;
185 dataLength : enet_uint16;
186 end;
188 pENetProtocolSendFragment = ^ENetProtocolSendFragment;
189 ENetProtocolSendFragment = packed record
190 header : ENetProtocolCommandHeader;
191 startSequenceNumber : enet_uint16;
192 dataLength : enet_uint16;
193 fragmentCount : enet_uint32;
194 fragmentNumber : enet_uint32;
195 totalLength : enet_uint32;
196 fragmentOffset : enet_uint32;
197 end;
199 pENetProtocol = ^TENetProtocol;
200 TENetProtocol = packed record //union
201 case Byte of
202 0 : (header : ENetProtocolCommandHeader);
203 1 : (acknowledge : ENetProtocolAcknowledge);
204 2 : (connect : ENetProtocolConnect);
205 3 : (verifyConnect : ENetProtocolVerifyConnect);
206 4 : (disconnect : ENetProtocolDisconnect);
207 5 : (ping : ENetProtocolPing);
208 6 : (sendReliable : ENetProtocolSendReliable);
209 7 : (sendUnreliable : ENetProtocolSendUnreliable);
210 8 : (sendUnsequenced : ENetProtocolSendUnsequenced);
211 9 : (sendFragment : ENetProtocolSendFragment);
212 10: (bandwidthLimit : ENetProtocolBandwidthLimit);
213 11: (throttleConfigure : ENetProtocolThrottleConfigure);
214 end;
216 ////////////////////////////////////////////////////////////////////////////////
217 // win32.h / unix.h
218 ////////////////////////////////////////////////////////////////////////////////
220 const
221 ENET_SOCKET_NULL = -1;
223 type
224 ENetSocket = cint;
226 //ENetSocketSet = TFDSet;
227 ENetSocketSet = record end;
228 pENetSocketSet = ^ENetSocketSet;
230 pENetBuffer = ^ENetBuffer;
231 ENetBuffer = record
232 data : Pointer;
233 dataLength : csize_t;
234 end;
236 { inline macros }
238 function ENET_HOST_TO_NET_16( value: cuint16 ): cuint16; inline;
239 function ENET_HOST_TO_NET_32( value: cuint32 ): cuint32; inline;
241 function ENET_NET_TO_HOST_16( value: cuint16 ): cuint16; inline;
242 function ENET_NET_TO_HOST_32( value: cuint32 ): cuint32; inline;
244 procedure ENET_SOCKETSET_EMPTY( var sockset: ENetSocketSet ); inline;
245 procedure ENET_SOCKETSET_ADD( var sockset: ENetSocketSet; socket: ENetSocket ); inline;
246 procedure ENET_SOCKETSET_REMOVE( var sockset: ENetSocketSet; socket: ENetSocket ); inline;
247 function ENET_SOCKETSET_CHECK( var sockset: ENetSocketSet; socket: ENetSocket ): cbool; inline;
249 ////////////////////////////////////////////////////////////////////////////////
250 // list.h
251 ////////////////////////////////////////////////////////////////////////////////
253 type
254 pENetListNode = ^ENetListNode;
255 ENetListNode = record
256 next : pENetListNode;
257 previous : pENetListNode;
258 end;
260 pENetList = ^TENetList;
261 TENetList = record
262 sentinel : ENetListNode;
263 end;
265 ENetListIterator = pENetListNode;
267 { inline macros }
268 function enet_list_begin( list: pENetList ): ENetListIterator; inline;
269 function enet_list_end( list: pENetList ): ENetListIterator; inline;
271 function enet_list_empty( list: pENetList ): Boolean; inline;
273 function enet_list_next( iterator: ENetListIterator ): ENetListIterator; inline;
274 function enet_list_previous( iterator: ENetListIterator ): ENetListIterator; inline;
276 function enet_list_front( list: pENetList ): Pointer; inline;
277 function enet_list_back( list: pENetList ): Pointer; inline;
279 ////////////////////////////////////////////////////////////////////////////////
280 // time.h
281 ////////////////////////////////////////////////////////////////////////////////
283 const
284 ENET_TIME_OVERFLOW = 86400000;
286 { inline macros }
287 function ENET_TIME_LESS( const a, b: cint ): cbool; inline;
288 function ENET_TIME_GREATER( const a, b: cint ): cbool; inline;
290 function ENET_TIME_LESS_EQUAL( const a, b: cint ): cbool; inline;
291 function ENET_TIME_GREATER_EQUAL( const a, b: cint ): cbool; inline;
293 function ENET_TIME_DIFFERENCE( const a, b: cint ): cint; inline;
295 ////////////////////////////////////////////////////////////////////////////////
296 // enet.h
297 ////////////////////////////////////////////////////////////////////////////////
299 const
300 { defines }
301 ENET_VERSION_MAJOR = 1;
302 ENET_VERSION_MINOR = 3;
303 ENET_VERSION_PATCH = 13;
305 ENET_HOST_ANY = 0;
306 ENET_HOST_BROADCAST_ = $FFFFFFFF; // "_" due to name conflict
307 ENET_PORT_ANY = 0;
309 ENET_BUFFER_MAXIMUM = 1 + 2 * ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS;
311 { unnamed enums }
312 ENET_HOST_RECEIVE_BUFFER_SIZE = 256 * 1024;
313 ENET_HOST_SEND_BUFFER_SIZE = 256 * 1024;
314 ENET_HOST_BANDWIDTH_THROTTLE_INTERVAL = 1000;
315 ENET_HOST_DEFAULT_MTU = 1400;
316 ENET_HOST_DEFAULT_MAXIMUM_PACKET_SIZE = 32 * 1024 * 1024;
317 ENET_HOST_DEFAULT_MAXIMUM_WAITING_DATA = 32 * 1024 * 1024;
319 ENET_PEER_DEFAULT_ROUND_TRIP_TIME = 500;
320 ENET_PEER_DEFAULT_PACKET_THROTTLE = 32;
321 ENET_PEER_PACKET_THROTTLE_SCALE = 32;
322 ENET_PEER_PACKET_THROTTLE_COUNTER = 7;
323 ENET_PEER_PACKET_THROTTLE_ACCELERATION = 2;
324 ENET_PEER_PACKET_THROTTLE_DECELERATION = 2;
325 ENET_PEER_PACKET_THROTTLE_INTERVAL = 5000;
326 ENET_PEER_PACKET_LOSS_SCALE = 1 shl 16;
327 ENET_PEER_PACKET_LOSS_INTERVAL = 10000;
328 ENET_PEER_WINDOW_SIZE_SCALE = 64 * 1024;
329 ENET_PEER_TIMEOUT_LIMIT = 32;
330 ENET_PEER_TIMEOUT_MINIMUM = 5000;
331 ENET_PEER_TIMEOUT_MAXIMUM = 30000;
332 ENET_PEER_PING_INTERVAL_ = 500; // "_" due to name conflict
333 ENET_PEER_UNSEQUENCED_WINDOWS = 64;
334 ENET_PEER_UNSEQUENCED_WINDOW_SIZE = 1024;
335 ENET_PEER_FREE_UNSEQUENCED_WINDOWS = 32;
336 ENET_PEER_RELIABLE_WINDOWS = 16;
337 ENET_PEER_RELIABLE_WINDOW_SIZE = $1000;
338 ENET_PEER_FREE_RELIABLE_WINDOWS = 8;
340 { enum ENetSocketWait }
341 ENET_SOCKET_WAIT_NONE = 0;
342 ENET_SOCKET_WAIT_SEND = 1 shl 0;
343 ENET_SOCKET_WAIT_RECEIVE = 1 shl 1;
344 ENET_SOCKET_WAIT_INTERRUPT = 1 shl 2;
346 { enum ENetPacketFlag }
347 ENET_PACKET_FLAG_RELIABLE = 1 shl 0;
348 ENET_PACKET_FLAG_UNSEQUENCED = 1 shl 1;
349 ENET_PACKET_FLAG_NO_ALLOCATE = 1 shl 2;
350 ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT = 1 shl 3;
351 ENET_PACKET_FLAG_SENT = 1 shl 8;
353 type
354 { enums }
355 ENetSocketType = ( ENET_SOCKET_TYPE_STREAM = 1,
356 ENET_SOCKET_TYPE_DATAGRAM = 2 );
358 ENetSocketOption = ( ENET_SOCKOPT_NONBLOCK = 1,
359 ENET_SOCKOPT_BROADCAST = 2,
360 ENET_SOCKOPT_RCVBUF = 3,
361 ENET_SOCKOPT_SNDBUF = 4,
362 ENET_SOCKOPT_REUSEADDR = 5,
363 ENET_SOCKOPT_RCVTIMEO = 6,
364 ENET_SOCKOPT_SNDTIMEO = 7,
365 ENET_SOCKOPT_ERROR = 8,
366 ENET_SOCKOPT_NODELAY = 9 );
368 ENetSocketShutdown = ( ENET_SOCKET_SHUTDOWN_READ,
369 ENET_SOCKET_SHUTDOWN_WRITE,
370 ENET_SOCKET_SHUTDOWN_READ_WRITE );
372 ENetPeerState = ( ENET_PEER_STATE_DISCONNECTED,
373 ENET_PEER_STATE_CONNECTING,
374 ENET_PEER_STATE_ACKNOWLEDGING_CONNECT,
375 ENET_PEER_STATE_CONNECTION_PENDING,
376 ENET_PEER_STATE_CONNECTION_SUCCEEDED,
377 ENET_PEER_STATE_CONNECTED,
378 ENET_PEER_STATE_DISCONNECT_LATER,
379 ENET_PEER_STATE_DISCONNECTING,
380 ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT,
381 ENET_PEER_STATE_ZOMBIE );
383 ENetEventType = ( ENET_EVENT_TYPE_NONE,
384 ENET_EVENT_TYPE_CONNECT,
385 ENET_EVENT_TYPE_DISCONNECT,
386 ENET_EVENT_TYPE_RECEIVE );
388 { typedefs }
389 ENetVersion = enet_uint32;
391 { pointers to structs }
392 pENetAddress = ^ENetAddress;
393 pENetPacket = ^ENetPacket;
394 pENetChannel = ^ENetChannel;
395 pENetPeer = ^ENetPeer;
396 pENetCompressor = ^ENetCompressor;
397 pENetHost = ^ENetHost;
398 pENetEvent = ^ENetEvent;
400 { callbacks }
401 ENetPacketFreeCallback = procedure( packet: pENetPacket ); cdecl;
402 ENetChecksumCallback = function( const buffers: pENetBuffer;
403 bufferCount: csize_t ): enet_uint32; cdecl;
404 ENetInterceptCallback = function( host: pENetHost;
405 event: pENetEvent ): cint; cdecl;
407 { structs }
408 ENetAddress = record
409 host : enet_uint32;
410 port : enet_uint16;
411 end;
412 ENetPacket = record
413 referenceCount : csize_t;
414 flags : enet_uint32;
415 data : penet_uint8;
416 dataLength : csize_t;
417 freeCallback : ENetPacketFreeCallback;
418 userData : Pointer;
419 end;
420 ENetChannel = record
421 outgoingReliableSequenceNumber : enet_uint16;
422 outgoingUnreliableSequenceNumber : enet_uint16;
423 usedReliableWindows : enet_uint16;
424 reliableWindows : array[ 0..ENET_PEER_RELIABLE_WINDOWS-1 ] of enet_uint16;
425 incomingReliableSequenceNumber : enet_uint16;
426 incomingUnreliableSequenceNumber : enet_uint16;
427 incomingReliableCommands : TENetList;
428 incomingUnreliableCommands : TENetList;
429 end;
430 ENetPeer = record
431 dispatchList : ENetListNode;
432 host : pENetHost;
433 outgoingPeerID : enet_uint16;
434 incomingPeerID : enet_uint16;
435 connectID : enet_uint32;
436 outgoingSessionID : enet_uint8;
437 incomingSessionID : enet_uint8;
438 address : ENetAddress;
439 data : Pointer;
440 state : ENetPeerState;
441 channels : pENetChannel;
442 channelCount : csize_t;
443 incomingBandwidth : enet_uint32;
444 outgoingBandwidth : enet_uint32;
445 incomingBandwidthThrottleEpoch : enet_uint32;
446 outgoingBandwidthThrottleEpoch : enet_uint32;
447 incomingDataTotal : enet_uint32;
448 outgoingDataTotal : enet_uint32;
449 lastSendTime : enet_uint32;
450 lastReceiveTime : enet_uint32;
451 nextTimeout : enet_uint32;
452 earliestTimeout : enet_uint32;
453 packetLossEpoch : enet_uint32;
454 packetsSent : enet_uint32;
455 packetsLost : enet_uint32;
456 packetLoss : enet_uint32;
457 packetLossVariance : enet_uint32;
458 packetThrottle : enet_uint32;
459 packetThrottleLimit : enet_uint32;
460 packetThrottleCounter : enet_uint32;
461 packetThrottleEpoch : enet_uint32;
462 packetThrottleAcceleration : enet_uint32;
463 packetThrottleDeceleration : enet_uint32;
464 packetThrottleInterval : enet_uint32;
465 pingInterval : enet_uint32;
466 timeoutLimit : enet_uint32;
467 timeoutMinimum : enet_uint32;
468 timeoutMaximum : enet_uint32;
469 lastRoundTripTime : enet_uint32;
470 lowestRoundTripTime : enet_uint32;
471 lastRoundTripTimeVariance : enet_uint32;
472 highestRoundTripTimeVariance : enet_uint32;
473 roundTripTime : enet_uint32;
474 roundTripTimeVariance : enet_uint32;
475 mtu : enet_uint32;
476 windowSize : enet_uint32;
477 reliableDataInTransit : enet_uint32;
478 outgoingReliableSequenceNumber : enet_uint16;
479 acknowledgements : TENetList;
480 sentReliableCommands : TENetList;
481 sentUnreliableCommands : TENetList;
482 outgoingReliableCommands : TENetList;
483 outgoingUnreliableCommands : TENetList;
484 dispatchedCommands : TENetList;
485 needsDispatch : cint;
486 incomingUnsequencedGroup : enet_uint16;
487 outgoingUnsequencedGroup : enet_uint16;
488 unsequencedWindow : array[ 0..(ENET_PEER_UNSEQUENCED_WINDOW_SIZE div 32)-1 ] of enet_uint32;
489 eventData : enet_uint32;
490 totalWaitingData : csize_t;
491 end;
492 ENetCompressor = record
493 context : Pointer;
494 compress : function( context: Pointer; const inBuffers: pENetBuffer; inBufferCount, inLimit: csize_t; outData: penet_uint8; outLimit: csize_t ): csize_t; cdecl;
495 decompress : function( context: Pointer; const inData: penet_uint8; inLimit: csize_t; outData: penet_uint8; outLimit: csize_t ): csize_t; cdecl;
496 destroy : procedure( context: Pointer ); cdecl;
497 end;
498 ENetHost = record
499 socket : ENetSocket;
500 address : ENetAddress;
501 incomingBandwidth : enet_uint32;
502 outgoingBandwidth : enet_uint32;
503 bandwidthThrottleEpoch : enet_uint32;
504 mtu : enet_uint32;
505 randomSeed : enet_uint32;
506 recalculateBandwidthLimits : cint;
507 peers : pENetPeer;
508 peerCount : csize_t;
509 channelLimit : csize_t;
510 serviceTime : enet_uint32;
511 dispatchQueue : TENetList;
512 continueSending : cint;
513 packetSize : csize_t;
514 headerFlags : enet_uint16;
515 commands : array[ 0..ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS-1 ] of TENetProtocol;
516 commandCount : csize_t;
517 buffers : array[ 0..ENET_BUFFER_MAXIMUM-1 ] of ENetBuffer;
518 bufferCount : csize_t;
519 checksum : ENetChecksumCallback;
520 compressor : ENetCompressor;
521 packetData : array[ 0..1, 0..ENET_PROTOCOL_MAXIMUM_MTU-1 ] of enet_uint8;
522 receivedAddress : ENetAddress;
523 receivedData : penet_uint8;
524 receivedDataLength : csize_t;
525 totalSentData : enet_uint32;
526 totalSentPackets : enet_uint32;
527 totalReceivedData : enet_uint32;
528 totalReceivedPackets : enet_uint32;
529 intercept : ENetInterceptCallback;
530 connectedPeers : csize_t;
531 bandwidthLimitedPeers : csize_t;
532 duplicatePeers : csize_t;
533 maximumPacketSize : csize_t;
534 maximumWaitingData : csize_t;
535 end;
536 ENetEvent = record
537 kind : ENetEventType; //originally "type", which conflicts
538 peer : pENetPeer;
539 channelID : enet_uint8;
540 data : enet_uint32;
541 packet : pENetPacket;
542 end;
544 { inline macros }
545 function ENET_VERSION_CREATE( const major, minor, patch: cint ): ENetVersion; inline;
546 function ENET_VERSION_GET_MAJOR( const version: ENetVersion ): cint; inline;
547 function ENET_VERSION_GET_MINOR( const version: ENetVersion ): cint; inline;
548 function ENET_VERSION_GET_PATCH( const version: ENetVersion ): cint; inline;
549 function ENET_VERSION(): ENetVersion; inline;
551 { library functions }
552 function enet_initialize(): cint;
553 //function enet_initialize_with_callbacks( version: ENetVersion; const inits: pENetCallbacks ): cint; libraryLibENetImp;
554 procedure enet_deinitialize();
555 //function enet_linked_version(): ENetVersion; libraryLibENetImp;
557 //function enet_time_get(): enet_uint32; libraryLibENetImp;
558 //procedure enet_time_set( newTimeBase: enet_uint32 ); libraryLibENetImp;
560 function enet_socket_create( kind: ENetSocketType ): ENetSocket;
561 function enet_socket_bind( socket: ENetSocket; const address: pENetAddress ): cint;
562 //function enet_socket_get_address( socket: ENetSocket; address: pENetAddress ): cint; libraryLibENetImp;
563 //function enet_socket_listen( socket: ENetSocket; backlog: cint ): cint; libraryLibENetImp;
564 //function enet_socket_accept( socket: ENetSocket; address: pENetAddress ): ENetSocket; libraryLibENetImp;
565 //function enet_socket_connect( socket: ENetSocket; const address: pENetAddress ): cint; libraryLibENetImp;
566 function enet_socket_send( socket: ENetSocket; const address: pENetAddress; const buffers: pENetBuffer; bufferCount: csize_t ): cint;
567 function enet_socket_receive( socket: ENetSocket; address: pENetAddress; buffers: pENetBuffer; bufferCount: csize_t ): cint;
568 //function enet_socket_wait( socket: ENetSocket; condition: penet_uint32; timeout: enet_uint32 ): cint;
569 function enet_socket_set_option( socket: ENetSocket; option: ENetSocketOption; value: cint ): cint;
570 //function enet_socket_get_option( socket: ENetSocket; option: ENetSocketOption; value: pcint ): cint; libraryLibENetImp;
571 //function enet_socket_shutdown( socket: ENetSocket; how: ENetSocketShutdown ): cint; libraryLibENetImp;
572 procedure enet_socket_destroy( socket: ENetSocket );
573 //function enet_socketset_select( maxSocket: ENetSocket; readSet: pENetSocketSet; writeSet: pENetSocketSet; timeout: enet_uint32 ): cint; libraryLibENetImp;
575 function enet_address_set_host( address: pENetAddress; const hostName: PChar ): cint;
576 //function enet_address_get_host_ip( const address: pENetAddress; hostName: PChar; nameLength: csize_t ): cint; libraryLibENetImp;
577 //function enet_address_get_host( const address: pENetAddress; hostName: PChar; nameLength: csize_t ): cint; libraryLibENetImp;
579 function enet_packet_create( const data: Pointer; dataLength: csize_t; flags: enet_uint32 ): pENetPacket;
580 procedure enet_packet_destroy( packet: pENetPacket );
581 //function enet_packet_resize( packet: pENetPacket; dataLength: csize_t ): cint; libraryLibENetImp;
582 //function enet_crc32( const buffers: pENetBuffer; bufferCount: csize_t ): enet_uint32; libraryLibENetImp;
584 function enet_host_create( const address: pENetAddress; peerCount, channelLimit: csize_t; incomingBandwidth, outgoingBandwidth: enet_uint32 ): pENetHost;
585 procedure enet_host_destroy( host: pENetHost );
586 function enet_host_connect( host: pENetHost; const address: pENetAddress; channelCount: csize_t; data: enet_uint32 ): pENetPeer;
587 //function enet_host_check_events( host: pENetHost; event: pENetEvent ): cint; libraryLibENetImp;
588 function enet_host_service( host: pENetHost; event: pENetEvent; timeout: enet_uint32 ): cint;
589 procedure enet_host_flush( host: pENetHost );
590 procedure enet_host_broadcast( host: pENetHost; channelID: enet_uint8; packet: pENetPacket );
591 //procedure enet_host_compress( host: pENetHost; const compressor: pENetCompressor ); libraryLibENetImp;
592 //function enet_host_compress_with_range_coder( host: pENetHost ): cint; libraryLibENetImp;
593 //procedure enet_host_channel_limit( host: pENetHost; channelLimit: csize_t ); libraryLibENetImp;
594 //procedure enet_host_bandwidth_limit( host: pENetHost; incomingBandwidth, outgoingBandwidth: enet_uint32 ); libraryLibENetImp;
596 function enet_peer_send( peer: pENetPeer; channelID: enet_uint8; packet: pENetPacket ): cint;
597 //function enet_peer_receive( peer: pENetPeer; channelID: penet_uint8 ): pENetPacket; libraryLibENetImp;
598 //procedure enet_peer_ping( peer: pENetPeer ); libraryLibENetImp;
599 //procedure enet_peer_ping_interval( peer: pENetPeer; pingInterval: enet_uint32 ); libraryLibENetImp;
600 procedure enet_peer_timeout( peer: pENetPeer; timeoutLimit, timeoutMinimum, timeoutMaximum: enet_uint32 );
601 procedure enet_peer_reset( peer: pENetPeer );
602 procedure enet_peer_disconnect( peer: pENetPeer; data: enet_uint32 );
603 //procedure enet_peer_disconnect_now( peer: pENetPeer; data: enet_uint32 ); libraryLibENetImp;
604 //procedure enet_peer_disconnect_later( peer: pENetPeer; data: enet_uint32 ); libraryLibENetImp;
605 //procedure enet_peer_throttle_configure( peer: pENetPeer; interval, acceleration, deceleration: enet_uint32 ); libraryLibENetImp;
607 //function enet_range_coder_create(): Pointer; libraryLibENetImp;
608 //procedure enet_range_coder_destroy( context: Pointer ); libraryLibENetImp;
609 //function enet_range_coder_compress( context: Pointer; const inBuffers: pENetBuffer; inBufferCount, inLiit: csize_t; outData: penet_uint8; outLimit: csize_t ): csize_t; libraryLibENetImp;
610 //function enet_range_coder_decompress( context: Pointer; const inData: penet_uint8; inLimit: csize_t; outData: penet_uint8; outLimit: csize_t ): csize_t; libraryLibENetImp;
612 implementation
614 ////////////////////////////////////////////////////////////////////////////////
615 // win32.h / unix.h
616 ////////////////////////////////////////////////////////////////////////////////
618 function ENET_HOST_TO_NET_16( value: cuint16 ): cuint16;
619 begin
620 // Result := htons(value);
621 Result := value;
622 end;
624 function ENET_HOST_TO_NET_32( value: cuint32 ): cuint32;
625 begin
626 // Result := htonl(value);
627 Result := value;
628 end;
630 function ENET_NET_TO_HOST_16( value: cuint16 ): cuint16;
631 begin
632 // Result := ntohs(value);
633 Result := value;
634 end;
636 function ENET_NET_TO_HOST_32( value: cuint32 ): cuint32;
637 begin
638 // Result := ntohl(value);
639 Result := value;
640 end;
642 procedure ENET_SOCKETSET_EMPTY( var sockset: ENetSocketSet );
643 begin
644 // fpFD_ZERO( sockset );
645 end;
647 procedure ENET_SOCKETSET_ADD( var sockset: ENetSocketSet; socket: ENetSocket );
648 begin
649 // fpFD_SET( socket, sockset );
650 end;
652 procedure ENET_SOCKETSET_REMOVE( var sockset: ENetSocketSet; socket: ENetSocket );
653 begin
654 // fpFD_CLR( socket, sockset );
655 end;
657 function ENET_SOCKETSET_CHECK( var sockset: ENetSocketSet; socket: ENetSocket ): cbool;
658 begin
659 // Result := fpFD_ISSET( socket, sockset ) = 1;
660 Result := false;
661 end;
663 ////////////////////////////////////////////////////////////////////////////////
664 // list.h
665 ////////////////////////////////////////////////////////////////////////////////
667 function enet_list_begin( list: pENetList ): ENetListIterator;
668 begin
669 Result := list^.sentinel.next;
670 end;
672 function enet_list_end( list: pENetList ): ENetListIterator;
673 begin
674 Result := @( list^.sentinel );
675 end;
677 function enet_list_empty( list: pENetList ): Boolean;
678 begin
679 Result := enet_list_begin(list) = enet_list_end(list);
680 end;
682 function enet_list_next( iterator: ENetListIterator ): ENetListIterator;
683 begin
684 Result := iterator^.next;
685 end;
687 function enet_list_previous( iterator: ENetListIterator ): ENetListIterator;
688 begin
689 Result := iterator^.previous;
690 end;
692 function enet_list_front( list: pENetList ): Pointer;
693 begin
694 Result := Pointer( list^.sentinel.next );
695 end;
697 function enet_list_back( list: pENetList ): Pointer;
698 begin
699 Result := Pointer( list^.sentinel.previous );
700 end;
702 ////////////////////////////////////////////////////////////////////////////////
703 // time.h
704 ////////////////////////////////////////////////////////////////////////////////
706 function ENET_TIME_LESS( const a, b: cint ): cbool;
707 begin
708 Result := (a - b) >= ENET_TIME_OVERFLOW;
709 end;
711 function ENET_TIME_GREATER( const a, b: cint ): cbool;
712 begin
713 Result := (b - a) >= ENET_TIME_OVERFLOW;
714 end;
716 function ENET_TIME_LESS_EQUAL( const a, b: cint ): cbool;
717 begin
718 Result := not ENET_TIME_GREATER(a, b);
719 end;
721 function ENET_TIME_GREATER_EQUAL( const a, b: cint ): cbool;
722 begin
723 Result := not ENET_TIME_LESS(a, b);
724 end;
726 function ENET_TIME_DIFFERENCE( const a, b: cint ): cint;
727 begin
728 if (a - b) >= ENET_TIME_OVERFLOW then
729 Result := b - a
730 else
731 Result := a - b;
732 end;
734 ////////////////////////////////////////////////////////////////////////////////
735 // enet.h
736 ////////////////////////////////////////////////////////////////////////////////
738 function ENET_VERSION_CREATE( const major, minor, patch: cint ): ENetVersion;
739 begin
740 Result := (major shl 16) or (minor shl 8) or patch;
741 end;
743 function ENET_VERSION_GET_MAJOR( const version: ENetVersion ): cint;
744 begin
745 Result := (version shr 16) and $FF;
746 end;
748 function ENET_VERSION_GET_MINOR( const version: ENetVersion ): cint;
749 begin
750 Result := (version shr 8) and $FF;
751 end;
753 function ENET_VERSION_GET_PATCH( const version: ENetVersion ): cint;
754 begin
755 Result := version and $FF;
756 end;
758 function ENET_VERSION(): ENetVersion;
759 begin
760 Result := ENET_VERSION_CREATE( ENET_VERSION_MAJOR, ENET_VERSION_MINOR, ENET_VERSION_PATCH );
761 end;
770 function enet_initialize(): cint;
771 begin
772 result := 0;
773 end;
775 procedure enet_deinitialize;
776 begin
777 end;
779 function enet_socket_create( kind: ENetSocketType ): ENetSocket;
780 begin
781 result := 0
782 end;
784 function enet_socket_bind( socket: ENetSocket; const address: pENetAddress ): cint;
785 begin
786 result := 0
787 end;
789 function enet_socket_send( socket: ENetSocket; const address: pENetAddress; const buffers: pENetBuffer; bufferCount: csize_t ): cint;
790 begin
791 result := 0
792 end;
794 function enet_socket_receive( socket: ENetSocket; address: pENetAddress; buffers: pENetBuffer; bufferCount: csize_t ): cint;
795 begin
796 result := 0
797 end;
799 function enet_socket_set_option( socket: ENetSocket; option: ENetSocketOption; value: cint ): cint;
800 begin
801 result := 0
802 end;
804 procedure enet_socket_destroy( socket: ENetSocket );
805 begin
806 end;
808 function enet_address_set_host( address: pENetAddress; const hostName: PChar ): cint;
809 begin
810 result := 0
811 end;
813 function enet_packet_create( const data: Pointer; dataLength: csize_t; flags: enet_uint32 ): pENetPacket;
814 begin
815 result := nil
816 end;
818 procedure enet_packet_destroy( packet: pENetPacket );
819 begin
820 end;
822 function enet_host_create( const address: pENetAddress; peerCount, channelLimit: csize_t; incomingBandwidth, outgoingBandwidth: enet_uint32 ): pENetHost;
823 begin
824 result := nil
825 end;
827 procedure enet_host_destroy( host: pENetHost );
828 begin
829 end;
831 function enet_host_connect( host: pENetHost; const address: pENetAddress; channelCount: csize_t; data: enet_uint32 ): pENetPeer;
832 begin
833 result := nil
834 end;
836 function enet_host_service( host: pENetHost; event: pENetEvent; timeout: enet_uint32 ): cint;
837 begin
838 result := 0
839 end;
841 procedure enet_host_flush( host: pENetHost );
842 begin
843 end;
845 procedure enet_host_broadcast( host: pENetHost; channelID: enet_uint8; packet: pENetPacket );
846 begin
847 end;
849 function enet_peer_send( peer: pENetPeer; channelID: enet_uint8; packet: pENetPacket ): cint;
850 begin
851 result := 0
852 end;
854 procedure enet_peer_timeout( peer: pENetPeer; timeoutLimit, timeoutMinimum, timeoutMaximum: enet_uint32 );
855 begin
856 end;
858 procedure enet_peer_reset( peer: pENetPeer );
859 begin
860 end;
862 procedure enet_peer_disconnect( peer: pENetPeer; data: enet_uint32 );
863 begin
864 end;
870 end.