summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2018-08-12 16:31:44 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2018-08-12 16:59:59 +0200
commit662ceddd518faab8137d922e29030dc3fa1e34e2 (patch)
treea9c7a17b4a14f83f67bb02a82237558633ce7c77
parent1885036052b24cbe804bb829a32ba2617eac3fe4 (diff)
downloadfork-godot-webrtc-native-662ceddd518faab8137d922e29030dc3fa1e34e2.tar.gz
fork-godot-webrtc-native-662ceddd518faab8137d922e29030dc3fa1e34e2.tar.bz2
fork-godot-webrtc-native-662ceddd518faab8137d922e29030dc3fa1e34e2.zip
Fix interface binding
-rw-r--r--src/WebRTCPeer.cpp4
-rw-r--r--src/init.cpp9
-rw-r--r--src/net/WebRTCPeerNative.cpp11
-rw-r--r--src/net/WebRTCPeerNative.hpp2
4 files changed, 22 insertions, 4 deletions
diff --git a/src/WebRTCPeer.cpp b/src/WebRTCPeer.cpp
index 5eada1f..38303e1 100644
--- a/src/WebRTCPeer.cpp
+++ b/src/WebRTCPeer.cpp
@@ -61,12 +61,12 @@ void WebRTCPeer::_register_methods() { }
void WebRTCPeer::_init() {
printf("Binding PacketPeer interface");
- godot_net_bind_webrtc_peer(_owner, &interface);
+ register_interface(&interface);
}
WebRTCPeer::~WebRTCPeer() {
if (_owner) {
printf("Unbinding PacketPeer interface");
- godot_net_bind_webrtc_peer(_owner, NULL);
+ register_interface(NULL);
}
}
diff --git a/src/init.cpp b/src/init.cpp
index 601ac2a..544bfa2 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1,7 +1,16 @@
+#include <gdnative_api_struct.gen.h>
+#include "net/WebRTCPeerNative.hpp"
#include "WebRTCPeer.hpp"
/* Godot export stuff */
extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o) {
+ const godot_gdnative_core_api_struct *api = o->api_struct;
+ for (int i = 0; i < api->num_extensions; i++) {
+ if (api->extensions[i]->type == GDNATIVE_EXT_NET) {
+ WebRTCPeerNative::_net_api = (godot_gdnative_ext_net_api_struct *)api->extensions[i];
+ }
+ }
+
godot::Godot::gdnative_init(o);
}
diff --git a/src/net/WebRTCPeerNative.cpp b/src/net/WebRTCPeerNative.cpp
index 0e32d61..be9040c 100644
--- a/src/net/WebRTCPeerNative.cpp
+++ b/src/net/WebRTCPeerNative.cpp
@@ -1,16 +1,23 @@
#include "WebRTCPeerNative.hpp"
+const godot_gdnative_ext_net_api_struct *WebRTCPeerNative::_net_api = NULL;
+
+void WebRTCPeerNative::register_interface(const godot_net_webrtc_peer *p_interface) {
+ ERR_FAIL_COND(!_net_api);
+ _net_api->godot_net_bind_webrtc_peer(_owner, p_interface);
+}
+
void WebRTCPeerNative::_register_methods() { }
void WebRTCPeerNative::_init() {
printf("Binding PacketPeer interface");
- godot_net_bind_webrtc_peer(_owner, &interface);
+ register_interface(&interface);
}
WebRTCPeerNative::~WebRTCPeerNative() {
if (_owner) {
printf("Unbinding PacketPeer interface");
- godot_net_bind_webrtc_peer(_owner, NULL);
+ register_interface(NULL);
}
}
diff --git a/src/net/WebRTCPeerNative.hpp b/src/net/WebRTCPeerNative.hpp
index 6387cb1..603ba34 100644
--- a/src/net/WebRTCPeerNative.hpp
+++ b/src/net/WebRTCPeerNative.hpp
@@ -52,8 +52,10 @@ protected:
public:
static void _register_methods();
+ static const godot_gdnative_ext_net_api_struct *_net_api;
void _init();
+ void register_interface(const godot_net_webrtc_peer *interface);
virtual void set_write_mode(godot_int mode) = 0;
virtual godot_int get_write_mode() const = 0;