Nativescript 1.1

implemented instance binding data usage

This commit changes the way C++ wrapper classes work.
Previously, wrapper classes were merely wrapper *interfaces*.
They used the `this` pointer to store the actual foreign Godot
Object.

With the NativeScript 1.1 extension it is now possible to have
low-overhead language binding data attached to Objects.

The C++ bindings use that feature to implement *proper* wrappers
and enable regular C++ inheritance usage that way.

Some things might still be buggy and untested, but the C++
SimpleDemo works with those changes.

new and free change, custom free will crash engine, be wary

fix exporting of non-object types

fix free() crash with custom resources

added type tags and safe object casting

fix global type registration order

fix cast_to

changed build system to be more self contained

updated .gitignore

use typeid() for type tags now

fix indentation in bindings generator

remove accidentally added files

fix gitignore

Fixed up registering tool and updated godot_headers

Fix crash when calling String::split/split_floats

Was casting to the wrong object type.
Also adds parse_ints function to String with the same logic

Better warning/error macros

Change gitignore so we get our gen folders

New documentation based on nativescript 1.1

Fixed GODOT_SUBCLASS macro

Preventing crash when function returned null ptr

Adds needed include <typeinfo>

 Solves this issue #168 due to not having the include of typeinfo

Fix compile error of 'WARN_PRINT' and 'ERR_PRINT'.

cannot pass non-trivial object of type 'godot::String' to variadic function; expected type from format string was 'char *' [-Wnon-pod-varargs]

update vector3::distance_to

Remove godot_api.json as its now in the godot_headers submodule (api.json)
This commit is contained in:
karroffel
2018-02-11 15:50:01 +01:00
committed by Bastiaan Olij
parent 13f4f0e8f8
commit 200bf226bf
23 changed files with 547 additions and 140919 deletions

View File

@@ -2,11 +2,35 @@
#include "String.hpp"
#include "Wrapped.hpp"
static GDCALLINGCONV void *wrapper_create(void *data, const void *type_tag, godot_object *instance)
{
godot::_Wrapped *wrapper_memory = (godot::_Wrapped *) godot::api->godot_alloc(sizeof(godot::_Wrapped));
if (!wrapper_memory)
return NULL;
wrapper_memory->_owner = instance;
wrapper_memory->_type_tag = (size_t) type_tag;
return (void *) wrapper_memory;
}
static GDCALLINGCONV void wrapper_destroy(void *data, void *wrapper)
{
if (wrapper)
godot::api->godot_free(wrapper);
}
namespace godot {
void *_RegisterState::nativescript_handle;
int _RegisterState::language_index;
const godot_gdnative_core_api_struct *api = nullptr;
const godot_gdnative_ext_nativescript_api_struct *nativescript_api = nullptr;
const godot_gdnative_ext_nativescript_1_1_api_struct *nativescript_1_1_api = nullptr;
const void *gdnlib = NULL;
void Godot::print(const String& message)
{
@@ -47,19 +71,33 @@ void Godot::print_error(const String& description, const String& function, const
if (c_file != nullptr) godot::api->godot_free(c_file);
}
void ___register_types();
void Godot::gdnative_init(godot_gdnative_init_options *options)
{
godot::api = options->api_struct;
godot::gdnlib = options->gd_native_library;
// now find our extensions
for (int i = 0; i < godot::api->num_extensions; i++) {
switch (godot::api->extensions[i]->type) {
case GDNATIVE_EXT_NATIVESCRIPT: {
godot::nativescript_api = (godot_gdnative_ext_nativescript_api_struct *)godot::api->extensions[i];
}; break;
case GDNATIVE_EXT_NATIVESCRIPT: {
godot::nativescript_api = (const godot_gdnative_ext_nativescript_api_struct *)godot::api->extensions[i];
const godot_gdnative_api_struct *extension = godot::nativescript_api->next;
while (extension) {
if (extension->version.major == 1 && extension->version.minor == 1) {
godot::nativescript_1_1_api = (const godot_gdnative_ext_nativescript_1_1_api_struct *) extension;
}
extension = extension->next;
}
} break;
default: break;
};
};
}
}
}
void Godot::gdnative_terminate(godot_gdnative_terminate_options *options)
@@ -70,6 +108,19 @@ void Godot::gdnative_terminate(godot_gdnative_terminate_options *options)
void Godot::nativescript_init(void *handle)
{
godot::_RegisterState::nativescript_handle = handle;
godot_instance_binding_functions binding_funcs = {};
binding_funcs.alloc_instance_binding_data = wrapper_create;
binding_funcs.free_instance_binding_data = wrapper_destroy;
godot::_RegisterState::language_index = godot::nativescript_1_1_api->godot_nativescript_register_instance_binding_data_functions(binding_funcs);
___register_types();
}
};
void Godot::nativescript_terminate(void *handle)
{
godot::nativescript_1_1_api->godot_nativescript_unregister_instance_binding_data_functions(godot::_RegisterState::language_index);
}
}