Skip to content

Commit

Permalink
Added versioning info and checks for Godot 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
BastiaanOlij committed Aug 26, 2018
1 parent e3a2cba commit daff43f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 34 deletions.
1 change: 1 addition & 0 deletions src/ARVRInterface.cpp
Expand Up @@ -660,6 +660,7 @@ void godot_arvr_destructor(void *p_data) {
};

const godot_arvr_interface_gdnative interface_struct = {
GODOTVR_API_MAJOR, GODOTVR_API_MINOR,
godot_arvr_constructor,
godot_arvr_destructor,
godot_arvr_get_name,
Expand Down
38 changes: 38 additions & 0 deletions src/GodotCalls.cpp
Expand Up @@ -7,11 +7,49 @@
// and openvr uses pesky things such as namespaces

#include "GodotCalls.h"
#include <glad/glad.h>

const godot_gdnative_core_api_struct *api = NULL;
const godot_gdnative_ext_arvr_api_struct *arvr_api = NULL;
const godot_gdnative_ext_nativescript_api_struct *nativescript_api = NULL;

void GDN_EXPORT godot_oculus_gdnative_init(godot_gdnative_init_options *p_options) {
// get our main API struct
api = p_options->api_struct;

// now find our arvr extension
for (int i = 0; i < api->num_extensions; i++) {
// todo: add version checks
switch (api->extensions[i]->type) {
case GDNATIVE_EXT_ARVR: {
if (api->extensions[i]->version.major > 1 || (api->extensions[i]->version.major == 1 && api->extensions[i]->version.minor >= 1)) {
arvr_api = (godot_gdnative_ext_arvr_api_struct *)api->extensions[i];
} else {
printf("ARVR API version %i.%i isn't supported, need version 1.1 or higher\n", api->extensions[i]->version.major, api->extensions[i]->version.minor);
}
}; break;
case GDNATIVE_EXT_NATIVESCRIPT: {
if (api->extensions[i]->version.major > 1 || (api->extensions[i]->version.major == 1 && api->extensions[i]->version.minor >= 0)) {
nativescript_api = (godot_gdnative_ext_nativescript_api_struct *)api->extensions[i];
} else {
printf("Native script API version %i.%i isn't supported, need version 1.1 or higher\n", api->extensions[i]->version.major, api->extensions[i]->version.minor);
}
}; break;
default: break;
};
};

if (!gladLoadGL()) {
printf("Error initializing GLAD\n");
}
}

void GDN_EXPORT godot_oculus_gdnative_terminate(godot_gdnative_terminate_options *p_options) {
api = NULL;
nativescript_api = NULL;
arvr_api = NULL;
}

int64_t ___godot_icall_int(godot_method_bind *mb, godot_object *inst) {
int64_t ret;
const void *args[1] = {
Expand Down
3 changes: 3 additions & 0 deletions src/GodotCalls.h
Expand Up @@ -53,6 +53,9 @@ extern const godot_gdnative_ext_nativescript_api_struct *nativescript_api;
extern "C" {
#endif

void GDN_EXPORT godot_oculus_gdnative_init(godot_gdnative_init_options *p_options);
void GDN_EXPORT godot_oculus_gdnative_terminate(godot_gdnative_terminate_options *p_options);

int64_t ___godot_icall_int(godot_method_bind *mb, godot_object *inst);
void ___godot_icall_void_int(godot_method_bind *mb, godot_object *inst, const int arg0);
void ___godot_icall_void_int_Array_Array_int(godot_method_bind *mb, godot_object *inst, const int arg0, const godot_array& arg1, const godot_array& arg2, const int arg3);
Expand Down
34 changes: 3 additions & 31 deletions src/godot_oculus.cpp
Expand Up @@ -10,38 +10,10 @@

#include "godot_oculus.h"

////////////////////////////////////////////////////////////////////////
// gdnative init

void GDN_EXPORT godot_oculus_gdnative_init(godot_gdnative_init_options *p_options) {
// get our main API struct
api = p_options->api_struct;

// now find our arvr extension
for (int i = 0; i < api->num_extensions; i++) {
// todo: add version checks
switch (api->extensions[i]->type) {
case GDNATIVE_EXT_ARVR: {
arvr_api = (godot_gdnative_ext_arvr_api_struct *)api->extensions[i];
}; break;
case GDNATIVE_EXT_NATIVESCRIPT: {
nativescript_api = (godot_gdnative_ext_nativescript_api_struct *)api->extensions[i];
}; break;
default: break;
};
};

if (!gladLoadGL()) {
printf("Error initializing GLAD\n");
}
}

void GDN_EXPORT godot_oculus_gdnative_terminate(godot_gdnative_terminate_options *p_options) {
api = NULL;
}

void GDN_EXPORT godot_oculus_gdnative_singleton() {
arvr_api->godot_arvr_register_interface(&interface_struct);
if (arvr_api != NULL) {
arvr_api->godot_arvr_register_interface(&interface_struct);
}
}

void GDN_EXPORT godot_oculus_nativescript_init(void *p_handle) {
Expand Down
3 changes: 0 additions & 3 deletions src/godot_oculus.h
Expand Up @@ -8,16 +8,13 @@
#define GODOT_OCULUS_H

#include "GodotCalls.h"

#include "ARVRInterface.h"

// declare our public functions for our ARVR Interface
#ifdef __cplusplus
extern "C" {
#endif

void GDN_EXPORT godot_oculus_gdnative_init(godot_gdnative_init_options *p_options);
void GDN_EXPORT godot_oculus_gdnative_terminate(godot_gdnative_terminate_options *p_options);
void GDN_EXPORT godot_oculus_gdnative_singleton();
void GDN_EXPORT godot_oculus_nativescript_init(void *p_handle);

Expand Down

0 comments on commit daff43f

Please sign in to comment.