enet.bmx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. Strict
  2. Module Pub.ENet
  3. ModuleInfo "Version: 1.01"
  4. ModuleInfo "Author: Lee Salzman"
  5. ModuleInfo "Modserver: BRL"
  6. ModuleInfo "Credit: Adapted for BlitzMax by Mark Sibly"
  7. ModuleInfo "History: 1.01 Release"
  8. Import Pub.StdC
  9. Import "include/*.h"
  10. Import "host.c"
  11. Import "list.c"
  12. Import "memory.c"
  13. Import "packet.c"
  14. Import "peer.c"
  15. Import "protocol.c"
  16. ?Win32
  17. Import "win32.c"
  18. Import "-lws2_32"
  19. ?MacOS
  20. Import "unix.c"
  21. ?Linux
  22. Import "unix.c"
  23. ?
  24. Type ENetEvent
  25. Field event
  26. Field peer:Byte Ptr
  27. Field channel
  28. Field packet:Byte Ptr
  29. End Type
  30. Extern "C"
  31. Const ENET_HOST_ANY=0
  32. Const ENET_EVENT_TYPE_NONE=0
  33. Const ENET_EVENT_TYPE_CONNECT=1
  34. Const ENET_EVENT_TYPE_DISCONNECT=2
  35. Const ENET_EVENT_TYPE_RECEIVE=3
  36. Const ENET_PACKET_FLAG_RELIABLE=1
  37. Function enet_initialize()
  38. Function enet_deinitialize()
  39. Function enet_address_set_host( address:Byte Ptr,name$z )
  40. Function enet_time_get()
  41. Function enet_time_set( walltime_ms )
  42. Function enet_packet_create:Byte Ptr( data:Byte Ptr,size,flags )
  43. Function enet_packet_destroy( packet:Byte Ptr )
  44. Function enet_host_create:Byte Ptr( address:Byte Ptr,peerCount,incomingBandwidth,outgoingBandwidth )
  45. Function enet_host_destroy( host:Byte Ptr )
  46. Function enet_host_connect:Byte Ptr( host:Byte Ptr,address:Byte Ptr,channelCount )
  47. Function enet_host_flush( host:Byte Ptr )
  48. Function enet_host_service( host:Byte Ptr,event:Byte Ptr,timeout_ms )
  49. Function enet_host_broadcast( host:Byte Ptr,channel,packet:Byte Ptr )
  50. Function enet_host_bandwidth_limit( host:Byte Ptr,incomingBandwidth,outgoingBandwidth )
  51. Function enet_peer_send( peer:Byte Ptr,channel,packet:Byte Ptr )
  52. Function enet_peer_receive( peer:Byte Ptr,channel )
  53. Function enet_peer_ping( peer:Byte Ptr )
  54. Function enet_peer_reset( peer:Byte Ptr )
  55. Function enet_peer_disconnect( peer:Byte Ptr )
  56. Function enet_peer_throttle_configure( peer:Byte Ptr,interval,acceleration,deceleration )
  57. End Extern
  58. Function enet_peer_address( peer:Byte Ptr,host_ip Var,host_port Var )
  59. Local ip=(Int Ptr peer)[3]
  60. Local port=(Short Ptr peer)[8]
  61. ?LittleEndian
  62. ip=(ip Shr 24) | (ip Shr 8 & $ff00) | (ip Shl 8 & $ff0000) | (ip Shl 24)
  63. ?
  64. host_ip=ip
  65. host_port=port
  66. End Function
  67. Function enet_packet_data:Byte Ptr( packet:Byte Ptr )
  68. Return Byte Ptr( (Int Ptr packet)[2] )
  69. End Function
  70. Function enet_packet_size( packet:Byte Ptr )
  71. Return (Int Ptr packet)[3]
  72. End Function
  73. Function enet_address_create:Byte Ptr( host_ip,host_port )
  74. Local t:Byte Ptr=MemAlloc( 6 )
  75. ?BigEndian
  76. (Int Ptr t)[0]=host_ip
  77. ?LittleEndian
  78. (Int Ptr t)[0]=(host_ip Shr 24) | (host_ip Shr 8 & $ff00) | (host_ip Shl 8 & $ff0000) | (host_ip Shl 24)
  79. ?
  80. (Short Ptr t)[2]=host_port
  81. Return t
  82. End Function
  83. Function enet_address_destroy( address:Byte Ptr )
  84. MemFree address
  85. End Function
  86. enet_initialize
  87. atexit_ enet_deinitialize