enet.bmx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. SuperStrict
  2. Module Pub.Enet
  3. ModuleInfo "Version: 1.02"
  4. ModuleInfo "Author: Lee Salzman, Vladyslav Hrytsenko, Dominik Madarasz"
  5. ModuleInfo "History: 1.02"
  6. ModuleInfo "History: Made SuperStrict"
  7. ModuleInfo "History: Ported to zpl-c enet : https://github.com/zpl-c/enet"
  8. ModuleInfo "History: 1.01 Release"
  9. Import Pub.StdC
  10. ?win32x86
  11. Import "-lWs2_32"
  12. ?
  13. Import "enet/include/*.h"
  14. Import "glue.c"
  15. Function enet_address_create:Byte Ptr( host_ip:Int,host_port:Int )
  16. ?BigEndian
  17. Return bmx_enet_address_create_ipv4(host_ip, host_port)
  18. ?LittleEndian
  19. Return bmx_enet_address_create_ipv4((host_ip Shr 24) | (host_ip Shr 8 & $ff00) | (host_ip Shl 8 & $ff0000) | (host_ip Shl 24), host_port)
  20. ?
  21. End Function
  22. Function enet_address_create:Byte Ptr( host_ip:String,host_port:Int )
  23. If host_ip = ENET_HOST_ANY Then
  24. Return bmx_enet_address_create_any(host_port)
  25. Else
  26. Return bmx_enet_address_create_ipv6(host_ip, host_port, host_ip.Find(".") < 0)
  27. End If
  28. End Function
  29. Function enet_address_destroy( address:Byte Ptr )
  30. bmx_enet_address_destroy(address)
  31. End Function
  32. Type ENetEvent
  33. Field eventPtr:Byte Ptr
  34. Method New()
  35. eventPtr = bmx_enet_enetevent_new()
  36. End Method
  37. Method Delete()
  38. bmx_enet_enetevent_free(eventPtr)
  39. End Method
  40. Method channelID:Byte()
  41. Return bmx_enet_enetevent_channelid(eventPtr)
  42. End Method
  43. Method data:UInt()
  44. Return bmx_enet_enetevent_data(eventPtr)
  45. End Method
  46. Method event:Int()
  47. Return bmx_enet_enetevent_event(eventPtr)
  48. End Method
  49. Method peer:Byte Ptr()
  50. Return bmx_enet_enetevent_peer(eventPtr)
  51. End Method
  52. Method packet:Byte Ptr()
  53. Return bmx_enet_enetevent_packet(eventPtr)
  54. End Method
  55. End Type
  56. Extern
  57. Function bmx_enet_address_create_ipv4:Byte Ptr(host_ip:Int, host_port:Int)
  58. Function bmx_enet_address_create_any:Byte Ptr(host_port:Int)
  59. Function bmx_enet_address_create_ipv6:Byte Ptr(host_ip:String, host_port:Int, ipv6:Int)
  60. Function bmx_enet_address_destroy(address:Byte Ptr)
  61. Function bmx_enet_enetevent_new:Byte Ptr()
  62. Function bmx_enet_enetevent_free(event:Byte Ptr)
  63. Function bmx_enet_enetevent_peer:Byte Ptr(event:Byte Ptr)
  64. Function bmx_enet_enetevent_event:Int(event:Byte Ptr)
  65. Function bmx_enet_enetevent_packet:Byte Ptr(event:Byte Ptr)
  66. Function bmx_enet_enetevent_channelid:Byte(event:Byte Ptr)
  67. Function bmx_enet_enetevent_data:UInt(event:Byte Ptr)
  68. Function enet_initialize:Int()
  69. Function enet_deinitialize()
  70. Function enet_peer_disconnect(peer:Byte Ptr, data:UInt)
  71. Function enet_peer_send:Int(peer:Byte Ptr, channelID:Byte, packet:Byte Ptr)
  72. Function enet_host_create:Byte Ptr(address:Byte Ptr, peerCount:Size_T , channelLimit:Size_T , incomingBandwidth:UInt, outgoingBandwidth:UInt)
  73. Function enet_host_connect:Byte Ptr(host:Byte Ptr, address:Byte Ptr, channelCount:Size_T, data:UInt)
  74. Function enet_host_service:Int( host:Byte Ptr, event:Byte Ptr,timeout_ms:UInt )
  75. Function enet_host_destroy(host:Byte Ptr)
  76. Function enet_host_flush(host:Byte Ptr)
  77. Function enet_packet_create:Byte Ptr(data:Byte Ptr, dataLength:Size_T, flags:UInt)
  78. Function enet_packet_destroy(packet:Byte Ptr)
  79. Function bmx_enet_packet_data:Byte Ptr(packet:Byte Ptr)
  80. Function bmx_enet_packet_size:Size_T(packet:Byte Ptr)
  81. End Extern
  82. Const ENET_HOST_ANY:String = "ENET_HOST_ANY"
  83. Const ENET_EVENT_TYPE_NONE:Int = 0
  84. Const ENET_EVENT_TYPE_CONNECT:Int = 1
  85. Const ENET_EVENT_TYPE_DISCONNECT:Int = 2
  86. Const ENET_EVENT_TYPE_RECEIVE:Int = 3
  87. Const ENET_EVENT_TYPE_DISCONNECT_TIMEOUT:Int = 4
  88. Const ENET_PACKET_FLAG_RELIABLE:Int = 1 Shl 0
  89. Const ENET_PACKET_FLAG_UNSEQUENCED:Int = 1 Shl 1
  90. Const ENET_PACKET_FLAG_NO_ALLOCATE:Int = 1 Shl 2
  91. Const ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT:Int = 1 Shl 3
  92. Const ENET_PACKET_FLAG_SENT:Int = 1 Shl 8
  93. enet_initialize
  94. atexit_ enet_deinitialize