multiplayer_peer_gdnative.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*************************************************************************/
  2. /* multiplayer_peer_gdnative.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "multiplayer_peer_gdnative.h"
  31. MultiplayerPeerGDNative::MultiplayerPeerGDNative() {
  32. interface = NULL;
  33. }
  34. MultiplayerPeerGDNative::~MultiplayerPeerGDNative() {
  35. }
  36. void MultiplayerPeerGDNative::set_native_multiplayer_peer(const godot_net_multiplayer_peer *p_interface) {
  37. interface = p_interface;
  38. }
  39. Error MultiplayerPeerGDNative::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
  40. ERR_FAIL_COND_V(interface == NULL, ERR_UNCONFIGURED);
  41. return (Error)interface->get_packet(interface->data, r_buffer, r_buffer_size);
  42. }
  43. Error MultiplayerPeerGDNative::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
  44. ERR_FAIL_COND_V(interface == NULL, ERR_UNCONFIGURED);
  45. return (Error)interface->put_packet(interface->data, p_buffer, p_buffer_size);
  46. }
  47. int MultiplayerPeerGDNative::get_max_packet_size() const {
  48. ERR_FAIL_COND_V(interface == NULL, 0);
  49. return interface->get_max_packet_size(interface->data);
  50. }
  51. int MultiplayerPeerGDNative::get_available_packet_count() const {
  52. ERR_FAIL_COND_V(interface == NULL, 0);
  53. return interface->get_available_packet_count(interface->data);
  54. }
  55. /* NetworkedMultiplayerPeer */
  56. void MultiplayerPeerGDNative::set_transfer_mode(TransferMode p_mode) {
  57. ERR_FAIL_COND(interface == NULL);
  58. interface->set_transfer_mode(interface->data, (godot_int)p_mode);
  59. }
  60. NetworkedMultiplayerPeer::TransferMode MultiplayerPeerGDNative::get_transfer_mode() const {
  61. ERR_FAIL_COND_V(interface == NULL, TRANSFER_MODE_UNRELIABLE);
  62. return (TransferMode)interface->get_transfer_mode(interface->data);
  63. }
  64. void MultiplayerPeerGDNative::set_target_peer(int p_peer_id) {
  65. ERR_FAIL_COND(interface == NULL);
  66. interface->set_target_peer(interface->data, p_peer_id);
  67. }
  68. int MultiplayerPeerGDNative::get_packet_peer() const {
  69. ERR_FAIL_COND_V(interface == NULL, 0);
  70. return interface->get_packet_peer(interface->data);
  71. }
  72. bool MultiplayerPeerGDNative::is_server() const {
  73. ERR_FAIL_COND_V(interface == NULL, false);
  74. return interface->is_server(interface->data);
  75. }
  76. void MultiplayerPeerGDNative::poll() {
  77. ERR_FAIL_COND(interface == NULL);
  78. interface->poll(interface->data);
  79. }
  80. int MultiplayerPeerGDNative::get_unique_id() const {
  81. ERR_FAIL_COND_V(interface == NULL, 0);
  82. return interface->get_unique_id(interface->data);
  83. }
  84. void MultiplayerPeerGDNative::set_refuse_new_connections(bool p_enable) {
  85. ERR_FAIL_COND(interface == NULL);
  86. interface->set_refuse_new_connections(interface->data, p_enable);
  87. }
  88. bool MultiplayerPeerGDNative::is_refusing_new_connections() const {
  89. ERR_FAIL_COND_V(interface == NULL, true);
  90. return interface->is_refusing_new_connections(interface->data);
  91. }
  92. NetworkedMultiplayerPeer::ConnectionStatus MultiplayerPeerGDNative::get_connection_status() const {
  93. ERR_FAIL_COND_V(interface == NULL, CONNECTION_DISCONNECTED);
  94. return (ConnectionStatus)interface->get_connection_status(interface->data);
  95. }
  96. void MultiplayerPeerGDNative::_bind_methods() {
  97. }
  98. extern "C" {
  99. void GDAPI godot_net_bind_multiplayer_peer(godot_object *p_obj, const godot_net_multiplayer_peer *p_impl) {
  100. ((MultiplayerPeerGDNative *)p_obj)->set_native_multiplayer_peer(p_impl);
  101. }
  102. }