diff options
author | Thomas Herzog <thomas.herzog@mail.com> | 2017-10-15 13:08:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-15 13:08:23 +0200 |
commit | 066d7c37bcfe074e73cd6f3846be64fff54f3eca (patch) | |
tree | b439cdaefa07819d468883bdd4879d34be2f5375 | |
parent | 6d380b04f27c648b1ebebf6afb0cce261625f205 (diff) | |
parent | c6ce73c68046b3061d753f4bfc5962377236c232 (diff) |
Merge pull request #12105 from BastiaanOlij/arvr_auto_register_gdnative
Couple of small changes so our ARVRInterfaceGDNative gets constructed…
-rw-r--r-- | modules/gdnative/gdnative_api.json | 1 | ||||
-rw-r--r-- | modules/gdnative/include/nativearvr/godot_nativearvr.h | 2 | ||||
-rw-r--r-- | modules/gdnative/nativearvr/arvr_interface_gdnative.cpp | 33 | ||||
-rw-r--r-- | modules/gdnative/nativearvr/arvr_interface_gdnative.h | 6 | ||||
-rw-r--r-- | modules/gdnative/nativearvr/register_types.cpp | 18 |
5 files changed, 12 insertions, 48 deletions
diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index 459ca12ae9..31b021b751 100644 --- a/modules/gdnative/gdnative_api.json +++ b/modules/gdnative/gdnative_api.json @@ -5234,7 +5234,6 @@ "name": "godot_arvr_register_interface", "return_type": "void", "arguments": [ - ["const char *", "p_name"], ["const godot_arvr_interface_gdnative *", "p_interface"] ] }, diff --git a/modules/gdnative/include/nativearvr/godot_nativearvr.h b/modules/gdnative/include/nativearvr/godot_nativearvr.h index ee557843c6..1a8970d396 100644 --- a/modules/gdnative/include/nativearvr/godot_nativearvr.h +++ b/modules/gdnative/include/nativearvr/godot_nativearvr.h @@ -54,7 +54,7 @@ typedef struct { void (*process)(void *); } godot_arvr_interface_gdnative; -void GDAPI godot_arvr_register_interface(const char *p_name, const godot_arvr_interface_gdnative *p_interface); +void GDAPI godot_arvr_register_interface(const godot_arvr_interface_gdnative *p_interface); // helper functions to access ARVRServer data godot_real GDAPI godot_arvr_get_worldscale(); diff --git a/modules/gdnative/nativearvr/arvr_interface_gdnative.cpp b/modules/gdnative/nativearvr/arvr_interface_gdnative.cpp index 2f60339afa..ff8bda162f 100644 --- a/modules/gdnative/nativearvr/arvr_interface_gdnative.cpp +++ b/modules/gdnative/nativearvr/arvr_interface_gdnative.cpp @@ -33,10 +33,6 @@ #include "servers/arvr/arvr_positional_tracker.h" #include "servers/visual/visual_server_global.h" -#include "oa_hash_map.h" - -extern OAHashMap<StringName, godot_arvr_interface_gdnative *> *_registered_interfaces; - ARVRInterfaceGDNative::ARVRInterfaceGDNative() { // testing printf("Construct gdnative interface\n"); @@ -66,23 +62,16 @@ void ARVRInterfaceGDNative::cleanup() { } } -void ARVRInterfaceGDNative::set_interface(StringName p_name) { - - godot_arvr_interface_gdnative *new_interface; - - if (!_registered_interfaces->lookup(p_name, &new_interface)) { - ERR_PRINT((String("ARVR interface \"") + p_name + "\" does not exist.").utf8().get_data()); - return; - } - +void ARVRInterfaceGDNative::set_interface(const godot_arvr_interface_gdnative *p_interface) { + // this should only be called once, just being paranoid.. if (interface) { cleanup(); } - interface = new_interface; + // bind to our interface + interface = p_interface; // Now we do our constructing... - data = interface->constructor((godot_object *)this); } @@ -222,20 +211,16 @@ void ARVRInterfaceGDNative::process() { interface->process(data); } -void ARVRInterfaceGDNative::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_interface", "name"), &ARVRInterfaceGDNative::set_interface); -} - ///////////////////////////////////////////////////////////////////////////////////// // some helper callbacks extern "C" { -void GDAPI godot_arvr_register_interface(const char *p_name, const godot_arvr_interface_gdnative *p_interface) { - // this method is supposed to only be called by GDNative singletons - // which are initialized in a thread safe way, so using a global map is fine here - - _registered_interfaces->set(StringName(p_name), (godot_arvr_interface_gdnative * const)p_interface); +void GDAPI godot_arvr_register_interface(const godot_arvr_interface_gdnative *p_interface) { + Ref<ARVRInterfaceGDNative> new_interface; + new_interface.instance(); + new_interface->set_interface((godot_arvr_interface_gdnative * const)p_interface); + ARVRServer::get_singleton()->add_interface(new_interface); } godot_real GDAPI godot_arvr_get_worldscale() { diff --git a/modules/gdnative/nativearvr/arvr_interface_gdnative.h b/modules/gdnative/nativearvr/arvr_interface_gdnative.h index 04730571b7..e45b51e070 100644 --- a/modules/gdnative/nativearvr/arvr_interface_gdnative.h +++ b/modules/gdnative/nativearvr/arvr_interface_gdnative.h @@ -46,17 +46,15 @@ class ARVRInterfaceGDNative : public ARVRInterface { void cleanup(); protected: - godot_arvr_interface_gdnative *interface; + const godot_arvr_interface_gdnative *interface; void *data; - static void _bind_methods(); - public: /** general interface information **/ ARVRInterfaceGDNative(); ~ARVRInterfaceGDNative(); - void set_interface(StringName p_name); + void set_interface(const godot_arvr_interface_gdnative *p_interface); virtual StringName get_name() const; virtual int get_capabilities() const; diff --git a/modules/gdnative/nativearvr/register_types.cpp b/modules/gdnative/nativearvr/register_types.cpp index 09debe2550..c7d7847a21 100644 --- a/modules/gdnative/nativearvr/register_types.cpp +++ b/modules/gdnative/nativearvr/register_types.cpp @@ -29,29 +29,11 @@ /*************************************************************************/ #include "register_types.h" - #include "arvr_interface_gdnative.h" -#include "core/os/os.h" - -#include "oa_hash_map.h" -#include "ustring.h" - -// what is this?? I can't memnew(OAHashMap<String, godot_arvr_interface_gdnative *>) -// but with this typedef it's working just fine... -// C++ grammar can be a joy. -typedef OAHashMap<StringName, godot_arvr_interface_gdnative *> InterfaceMap; - -InterfaceMap *_registered_interfaces; void register_nativearvr_types() { - - _registered_interfaces = memnew(InterfaceMap); - ClassDB::register_class<ARVRInterfaceGDNative>(); } void unregister_nativearvr_types() { - memdelete(_registered_interfaces); - - _registered_interfaces = NULL; } |