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:
@@ -269,7 +269,7 @@ Color Color::html(const String& p_color)
|
||||
} else if (color.length()==6) {
|
||||
alpha=false;
|
||||
} else {
|
||||
ERR_PRINT(String("Invalid Color Code: ") + p_color);
|
||||
ERR_PRINTS(String("Invalid Color Code: ") + p_color);
|
||||
ERR_FAIL_V(Color());
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ Color Color::html(const String& p_color)
|
||||
if (alpha) {
|
||||
a=_parse_col(color,0);
|
||||
if (a<0) {
|
||||
ERR_PRINT("Invalid Color Code: "+p_color);
|
||||
ERR_PRINTS(String("Invalid Color Code: ") + p_color);
|
||||
ERR_FAIL_V(Color());
|
||||
}
|
||||
}
|
||||
@@ -286,17 +286,17 @@ Color Color::html(const String& p_color)
|
||||
|
||||
int r=_parse_col(color,from+0);
|
||||
if (r<0) {
|
||||
ERR_PRINT("Invalid Color Code: "+p_color);
|
||||
ERR_PRINTS(String("Invalid Color Code: ") + p_color);
|
||||
ERR_FAIL_V(Color());
|
||||
}
|
||||
int g=_parse_col(color,from+2);
|
||||
if (g<0) {
|
||||
ERR_PRINT("Invalid Color Code: "+p_color);
|
||||
ERR_PRINTS(String("Invalid Color Code: ") + p_color);
|
||||
ERR_FAIL_V(Color());
|
||||
}
|
||||
int b=_parse_col(color,from+4);
|
||||
if (b<0) {
|
||||
ERR_PRINT("Invalid Color Code: "+p_color);
|
||||
ERR_PRINTS(String("Invalid Color Code: ") + p_color);
|
||||
ERR_FAIL_V(Color());
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ bool String::begins_with_char_array(const char *p_char_array) const {
|
||||
PoolStringArray String::bigrams() const {
|
||||
godot_array arr = godot::api->godot_string_bigrams(&_godot_string);
|
||||
|
||||
return *(PoolStringArray *)&arr;
|
||||
return *(Array *)&arr;
|
||||
}
|
||||
|
||||
String String::c_escape() const {
|
||||
@@ -479,13 +479,19 @@ float String::similarity(String text) const {
|
||||
PoolStringArray String::split(String divisor, bool allow_empty) const {
|
||||
godot_array arr = godot::api->godot_string_split(&_godot_string, &divisor._godot_string);
|
||||
|
||||
return *(PoolStringArray *)&arr;
|
||||
return *(Array *)&arr;
|
||||
}
|
||||
|
||||
PoolIntArray String::split_ints(String divisor, bool allow_empty) const {
|
||||
godot_array arr = godot::api->godot_string_split_floats(&_godot_string, &divisor._godot_string);
|
||||
|
||||
return *(Array *)&arr;
|
||||
}
|
||||
|
||||
PoolRealArray String::split_floats(String divisor, bool allow_empty) const {
|
||||
godot_array arr = godot::api->godot_string_split_floats(&_godot_string, &divisor._godot_string);
|
||||
|
||||
return *(PoolRealArray *)&arr;
|
||||
return *(Array *)&arr;
|
||||
}
|
||||
|
||||
String String::strip_edges(bool left, bool right) const {
|
||||
|
||||
55
src/core/TagDB.cpp
Normal file
55
src/core/TagDB.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include "TagDB.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include <GodotGlobal.hpp>
|
||||
|
||||
namespace godot {
|
||||
|
||||
namespace _TagDB {
|
||||
|
||||
std::unordered_map<size_t, size_t> parent_to;
|
||||
|
||||
void register_type(size_t type_tag, size_t base_type_tag)
|
||||
{
|
||||
if (type_tag == base_type_tag) {
|
||||
return;
|
||||
}
|
||||
parent_to[type_tag] = base_type_tag;
|
||||
}
|
||||
|
||||
bool is_type_known(size_t type_tag)
|
||||
{
|
||||
return parent_to.find(type_tag) != parent_to.end();
|
||||
}
|
||||
|
||||
void register_global_type(const char *name, size_t type_tag, size_t base_type_tag)
|
||||
{
|
||||
|
||||
godot::nativescript_1_1_api->godot_nativescript_set_global_type_tag(godot::_RegisterState::language_index, name, (const void *) type_tag);
|
||||
|
||||
register_type(type_tag, base_type_tag);
|
||||
}
|
||||
|
||||
bool is_type_compatible(size_t ask_tag, size_t have_tag)
|
||||
{
|
||||
|
||||
if (have_tag == 0)
|
||||
return false;
|
||||
|
||||
size_t tag = have_tag;
|
||||
|
||||
while (tag != 0) {
|
||||
if (tag == ask_tag)
|
||||
return true;
|
||||
|
||||
tag = parent_to[tag];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "Defs.hpp"
|
||||
#include "CoreTypes.hpp"
|
||||
#include "GodotGlobal.hpp"
|
||||
#include "Object.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -141,7 +142,7 @@ Variant::Variant(const RID& p_rid)
|
||||
|
||||
Variant::Variant(const Object* p_object)
|
||||
{
|
||||
godot::api->godot_variant_new_object(&_godot_variant, (godot_object *) p_object);
|
||||
godot::api->godot_variant_new_object(&_godot_variant, p_object->_owner);
|
||||
}
|
||||
|
||||
Variant::Variant(const Dictionary& p_dictionary)
|
||||
@@ -363,9 +364,8 @@ Variant::operator PoolColorArray() const
|
||||
godot_pool_color_array s = godot::api->godot_variant_as_pool_color_array(&_godot_variant);
|
||||
return *(PoolColorArray *) &s;
|
||||
}
|
||||
Variant::operator Object*() const {
|
||||
godot_object *o = godot::api->godot_variant_as_object(&_godot_variant);
|
||||
return (Object *) o;
|
||||
Variant::operator godot_object*() const {
|
||||
return godot::api->godot_variant_as_object(&_godot_variant);
|
||||
}
|
||||
|
||||
Variant::Type Variant::get_type() const
|
||||
|
||||
@@ -229,12 +229,12 @@ real_t Vector3::length_squared() const
|
||||
|
||||
real_t Vector3::distance_squared_to(const Vector3& b) const
|
||||
{
|
||||
return (b-*this).length();
|
||||
return (b-*this).length_squared();
|
||||
}
|
||||
|
||||
real_t Vector3::distance_to(const Vector3& b) const
|
||||
{
|
||||
return (b-*this).length_squared();
|
||||
return (b-*this).length();
|
||||
}
|
||||
|
||||
real_t Vector3::dot(const Vector3& b) const
|
||||
|
||||
2
src/gen/.gitignore
vendored
Normal file
2
src/gen/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
Reference in New Issue
Block a user