Added godot's gdnative module.

This commit is contained in:
Relintai 2023-05-23 18:02:01 +02:00
commit bd9e05126e
111 changed files with 27013 additions and 0 deletions

21
LICENSE.txt Normal file
View File

@ -0,0 +1,21 @@
Copyright (c) 2023-present Péter Magyar.
Copyright (c) 2014-2023 Godot Engine contributors (cf. AUTHORS.md).
Copyright (c) 2007-2023 Juan Linietsky, Ariel Manzur.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

60
SCsub Normal file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env python
Import("env")
Import("env_modules")
env_gdnative = env_modules.Clone()
env_gdnative.add_source_files(env.modules_sources, "gdnative.cpp")
env_gdnative.add_source_files(env.modules_sources, "register_types.cpp")
env_gdnative.add_source_files(env.modules_sources, "android/*.cpp")
env_gdnative.add_source_files(env.modules_sources, "gdnative/*.cpp")
env_gdnative.add_source_files(env.modules_sources, "nativescript/*.cpp")
env_gdnative.add_source_files(env.modules_sources, "gdnative_library_singleton_editor.cpp")
env_gdnative.add_source_files(env.modules_sources, "gdnative_library_editor_plugin.cpp")
env_gdnative.Prepend(CPPPATH=["#modules/gdnative/include/"])
Export("env_gdnative")
SConscript("net/SCsub")
SConscript("arvr/SCsub")
SConscript("pluginscript/SCsub")
SConscript("videodecoder/SCsub")
from methods import get_cmdline_bool
from platform_methods import run_in_subprocess
import gdnative_builders
_, gensource = env_gdnative.CommandNoCache(
["include/gdnative_api_struct.gen.h", "gdnative_api_struct.gen.cpp"],
"gdnative_api.json",
run_in_subprocess(gdnative_builders.build_gdnative_api_struct),
)
env_gdnative.add_source_files(env.modules_sources, [gensource])
env.use_ptrcall = True
if get_cmdline_bool("gdnative_wrapper", False):
(gensource,) = env_gdnative.CommandNoCache(
"gdnative_wrapper_code.gen.cpp",
"gdnative_api.json",
run_in_subprocess(gdnative_builders.build_gdnative_wrapper_code),
)
gd_wrapper_env = env.Clone()
gd_wrapper_env.Prepend(CPPPATH=["#modules/gdnative/include/"])
if gd_wrapper_env["use_lto"]:
if not env.msvc:
gd_wrapper_env.Append(CCFLAGS=["-fno-lto"])
gd_wrapper_env.Append(LINKFLAGS=["-fno-lto"])
else:
gd_wrapper_env.Append(CCFLAGS=["/GL-"])
gd_wrapper_env.Append(LINKFLAGS=["/LTCG:OFF"])
if not env.msvc:
gd_wrapper_env.Append(CCFLAGS=["-fPIC"])
lib = gd_wrapper_env.add_library("#bin/gdnative_wrapper_code", [gensource])

86
android/android_gdn.cpp Normal file
View File

@ -0,0 +1,86 @@
/**************************************************************************/
/* android_gdn.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "modules/gdnative/gdnative.h"
// Code by Paritosh97 with minor tweaks by Mux213
// These entry points are only for the android platform and are simple stubs in all others.
#ifdef __ANDROID__
#include "platform/android/java_godot_wrapper.h"
#include "platform/android/os_android.h"
#include "platform/android/thread_jandroid.h"
#else
#define JNIEnv void
#define jobject void *
#endif
#ifdef __cplusplus
extern "C" {
#endif
JNIEnv *GDAPI godot_android_get_env() {
#ifdef __ANDROID__
return get_jni_env();
#else
return nullptr;
#endif
}
jobject GDAPI godot_android_get_activity() {
#ifdef __ANDROID__
OS_Android *os_android = (OS_Android *)OS::get_singleton();
return os_android->get_godot_java()->get_activity();
#else
return nullptr;
#endif
}
jobject GDAPI godot_android_get_surface() {
#ifdef __ANDROID__
OS_Android *os_android = (OS_Android *)OS::get_singleton();
return os_android->get_godot_java()->get_surface();
#else
return nullptr;
#endif
}
bool GDAPI godot_android_is_activity_resumed() {
#ifdef __ANDROID__
OS_Android *os_android = (OS_Android *)OS::get_singleton();
return os_android->get_godot_java()->is_activity_resumed();
#else
return false;
#endif
}
#ifdef __cplusplus
}
#endif

6
arvr/SCsub Normal file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env python
Import("env")
Import("env_gdnative")
env_gdnative.add_source_files(env.modules_sources, "*.cpp")

View File

@ -0,0 +1,450 @@
/**************************************************************************/
/* arvr_interface_gdnative.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "arvr_interface_gdnative.h"
#include "main/input_default.h"
#include "servers/arvr/arvr_positional_tracker.h"
#include "servers/visual/visual_server_globals.h"
void ARVRInterfaceGDNative::_bind_methods() {
ADD_PROPERTY_DEFAULT("interface_is_initialized", false);
ADD_PROPERTY_DEFAULT("ar_is_anchor_detection_enabled", false);
}
ARVRInterfaceGDNative::ARVRInterfaceGDNative() {
print_verbose("Construct gdnative interface\n");
// we won't have our data pointer until our library gets set
data = nullptr;
interface = nullptr;
}
ARVRInterfaceGDNative::~ARVRInterfaceGDNative() {
print_verbose("Destruct gdnative interface\n");
if (interface != nullptr && is_initialized()) {
uninitialize();
};
// cleanup after ourselves
cleanup();
}
void ARVRInterfaceGDNative::cleanup() {
if (interface != nullptr) {
interface->destructor(data);
data = nullptr;
interface = nullptr;
}
}
void ARVRInterfaceGDNative::set_interface(const godot_arvr_interface_gdnative *p_interface) {
// this should only be called once, just being paranoid..
if (interface) {
cleanup();
}
// bind to our interface
interface = p_interface;
// Now we do our constructing...
data = interface->constructor((godot_object *)this);
}
StringName ARVRInterfaceGDNative::get_name() const {
ERR_FAIL_COND_V(interface == nullptr, StringName());
godot_string result = interface->get_name(data);
StringName name = *(String *)&result;
godot_string_destroy(&result);
return name;
}
int ARVRInterfaceGDNative::get_capabilities() const {
int capabilities;
ERR_FAIL_COND_V(interface == nullptr, 0); // 0 = None
capabilities = interface->get_capabilities(data);
return capabilities;
}
bool ARVRInterfaceGDNative::get_anchor_detection_is_enabled() const {
ERR_FAIL_COND_V(interface == nullptr, false);
return interface->get_anchor_detection_is_enabled(data);
}
void ARVRInterfaceGDNative::set_anchor_detection_is_enabled(bool p_enable) {
ERR_FAIL_COND(interface == nullptr);
interface->set_anchor_detection_is_enabled(data, p_enable);
}
int ARVRInterfaceGDNative::get_camera_feed_id() {
ERR_FAIL_COND_V(interface == nullptr, 0);
if ((interface->version.major > 1) || ((interface->version.major) == 1 && (interface->version.minor >= 1))) {
return (unsigned int)interface->get_camera_feed_id(data);
} else {
return 0;
}
}
bool ARVRInterfaceGDNative::is_stereo() {
bool stereo;
ERR_FAIL_COND_V(interface == nullptr, false);
stereo = interface->is_stereo(data);
return stereo;
}
bool ARVRInterfaceGDNative::is_initialized() const {
ERR_FAIL_COND_V(interface == nullptr, false);
return interface->is_initialized(data);
}
bool ARVRInterfaceGDNative::initialize() {
ERR_FAIL_COND_V(interface == nullptr, false);
bool initialized = interface->initialize(data);
if (initialized) {
// if we successfully initialize our interface and we don't have a primary interface yet, this becomes our primary interface
ARVRServer *arvr_server = ARVRServer::get_singleton();
if ((arvr_server != nullptr) && (arvr_server->get_primary_interface() == nullptr)) {
arvr_server->set_primary_interface(this);
};
};
return initialized;
}
void ARVRInterfaceGDNative::uninitialize() {
ERR_FAIL_COND(interface == nullptr);
ARVRServer *arvr_server = ARVRServer::get_singleton();
if (arvr_server != nullptr) {
// Whatever happens, make sure this is no longer our primary interface
arvr_server->clear_primary_interface_if(this);
}
interface->uninitialize(data);
}
Size2 ARVRInterfaceGDNative::get_render_targetsize() {
ERR_FAIL_COND_V(interface == nullptr, Size2());
godot_vector2 result = interface->get_render_targetsize(data);
Vector2 *vec = (Vector2 *)&result;
return *vec;
}
Transform ARVRInterfaceGDNative::get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform) {
Transform *ret;
ERR_FAIL_COND_V(interface == nullptr, Transform());
godot_transform t = interface->get_transform_for_eye(data, (int)p_eye, (godot_transform *)&p_cam_transform);
ret = (Transform *)&t;
return *ret;
}
CameraMatrix ARVRInterfaceGDNative::get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) {
CameraMatrix cm;
ERR_FAIL_COND_V(interface == nullptr, CameraMatrix());
interface->fill_projection_for_eye(data, (godot_real *)cm.matrix, (godot_int)p_eye, p_aspect, p_z_near, p_z_far);
return cm;
}
unsigned int ARVRInterfaceGDNative::get_external_texture_for_eye(ARVRInterface::Eyes p_eye) {
ERR_FAIL_COND_V(interface == nullptr, 0);
if ((interface->version.major > 1) || ((interface->version.major) == 1 && (interface->version.minor >= 1))) {
return (unsigned int)interface->get_external_texture_for_eye(data, (godot_int)p_eye);
} else {
return 0;
}
}
unsigned int ARVRInterfaceGDNative::get_external_depth_for_eye(ARVRInterface::Eyes p_eye) {
ERR_FAIL_COND_V(interface == nullptr, 0);
if ((interface->version.major > 1) || ((interface->version.major) == 1 && (interface->version.minor >= 2))) {
return (unsigned int)interface->get_external_depth_for_eye(data, (godot_int)p_eye);
} else {
return 0;
}
}
void ARVRInterfaceGDNative::commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) {
ERR_FAIL_COND(interface == nullptr);
interface->commit_for_eye(data, (godot_int)p_eye, (godot_rid *)&p_render_target, (godot_rect2 *)&p_screen_rect);
}
void ARVRInterfaceGDNative::process() {
ERR_FAIL_COND(interface == nullptr);
interface->process(data);
}
void ARVRInterfaceGDNative::notification(int p_what) {
ERR_FAIL_COND(interface == nullptr);
// this is only available in interfaces that implement 1.1 or later
if ((interface->version.major > 1) || ((interface->version.major == 1) && (interface->version.minor > 0))) {
interface->notification(data, p_what);
}
}
/////////////////////////////////////////////////////////////////////////////////////
// some helper callbacks
extern "C" {
void GDAPI godot_arvr_register_interface(const godot_arvr_interface_gdnative *p_interface) {
// If our major version is 0 or bigger then 10, we're likely looking at our constructor pointer from an older plugin
ERR_FAIL_COND_MSG((p_interface->version.major == 0) || (p_interface->version.major > 10), "GDNative ARVR interfaces build for Godot 3.0 are not supported.");
Ref<ARVRInterfaceGDNative> new_interface;
new_interface.instance();
new_interface->set_interface((const godot_arvr_interface_gdnative *)p_interface);
ARVRServer::get_singleton()->add_interface(new_interface);
}
godot_real GDAPI godot_arvr_get_worldscale() {
ARVRServer *arvr_server = ARVRServer::get_singleton();
ERR_FAIL_NULL_V(arvr_server, 1.0);
return arvr_server->get_world_scale();
}
godot_transform GDAPI godot_arvr_get_reference_frame() {
godot_transform reference_frame;
Transform *reference_frame_ptr = (Transform *)&reference_frame;
ARVRServer *arvr_server = ARVRServer::get_singleton();
if (arvr_server != nullptr) {
*reference_frame_ptr = arvr_server->get_reference_frame();
} else {
godot_transform_new_identity(&reference_frame);
}
return reference_frame;
}
void GDAPI godot_arvr_blit(godot_int p_eye, godot_rid *p_render_target, godot_rect2 *p_rect) {
// blits out our texture as is, handy for preview display of one of the eyes that is already rendered with lens distortion on an external HMD
ARVRInterface::Eyes eye = (ARVRInterface::Eyes)p_eye;
RID *render_target = (RID *)p_render_target;
Rect2 screen_rect = *(Rect2 *)p_rect;
if (eye == ARVRInterface::EYE_LEFT) {
screen_rect.size.x /= 2.0;
} else if (p_eye == ARVRInterface::EYE_RIGHT) {
screen_rect.size.x /= 2.0;
screen_rect.position.x += screen_rect.size.x;
}
VSG::rasterizer->set_current_render_target(RID());
VSG::rasterizer->blit_render_target_to_screen(*render_target, screen_rect, 0);
}
godot_int GDAPI godot_arvr_get_texid(godot_rid *p_render_target) {
// In order to send off our textures to display on our hardware we need the opengl texture ID instead of the render target RID
// This is a handy function to expose that.
RID *render_target = (RID *)p_render_target;
RID eye_texture = VSG::storage->render_target_get_texture(*render_target);
uint32_t texid = VS::get_singleton()->texture_get_texid(eye_texture);
return texid;
}
godot_int GDAPI godot_arvr_add_controller(char *p_device_name, godot_int p_hand, godot_bool p_tracks_orientation, godot_bool p_tracks_position) {
ARVRServer *arvr_server = ARVRServer::get_singleton();
ERR_FAIL_NULL_V(arvr_server, 0);
InputDefault *input = (InputDefault *)Input::get_singleton();
ERR_FAIL_NULL_V(input, 0);
Ref<ARVRPositionalTracker> new_tracker;
new_tracker.instance();
new_tracker->set_name(p_device_name);
new_tracker->set_type(ARVRServer::TRACKER_CONTROLLER);
if (p_hand == 1) {
new_tracker->set_hand(ARVRPositionalTracker::TRACKER_LEFT_HAND);
} else if (p_hand == 2) {
new_tracker->set_hand(ARVRPositionalTracker::TRACKER_RIGHT_HAND);
}
// also register as joystick...
int joyid = input->get_unused_joy_id();
if (joyid != -1) {
new_tracker->set_joy_id(joyid);
input->joy_connection_changed(joyid, true, p_device_name, "");
}
if (p_tracks_orientation) {
Basis orientation;
new_tracker->set_orientation(orientation);
}
if (p_tracks_position) {
Vector3 position;
new_tracker->set_position(position);
}
// add our tracker to our server and remember its pointer
arvr_server->add_tracker(new_tracker);
// note, this ID is only unique within controllers!
return new_tracker->get_tracker_id();
}
void GDAPI godot_arvr_remove_controller(godot_int p_controller_id) {
ARVRServer *arvr_server = ARVRServer::get_singleton();
ERR_FAIL_NULL(arvr_server);
InputDefault *input = (InputDefault *)Input::get_singleton();
ERR_FAIL_NULL(input);
Ref<ARVRPositionalTracker> remove_tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id);
if (remove_tracker.is_valid()) {
// unset our joystick if applicable
int joyid = remove_tracker->get_joy_id();
if (joyid != -1) {
input->joy_connection_changed(joyid, false, "", "");
remove_tracker->set_joy_id(-1);
}
// remove our tracker from our server
arvr_server->remove_tracker(remove_tracker);
remove_tracker.unref();
}
}
void GDAPI godot_arvr_set_controller_transform(godot_int p_controller_id, godot_transform *p_transform, godot_bool p_tracks_orientation, godot_bool p_tracks_position) {
ARVRServer *arvr_server = ARVRServer::get_singleton();
ERR_FAIL_NULL(arvr_server);
Ref<ARVRPositionalTracker> tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id);
if (tracker.is_valid()) {
Transform *transform = (Transform *)p_transform;
if (p_tracks_orientation) {
tracker->set_orientation(transform->basis);
}
if (p_tracks_position) {
tracker->set_rw_position(transform->origin);
}
}
}
void GDAPI godot_arvr_set_controller_button(godot_int p_controller_id, godot_int p_button, godot_bool p_is_pressed) {
ARVRServer *arvr_server = ARVRServer::get_singleton();
ERR_FAIL_NULL(arvr_server);
InputDefault *input = (InputDefault *)Input::get_singleton();
ERR_FAIL_NULL(input);
Ref<ARVRPositionalTracker> tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id);
if (tracker.is_valid()) {
int joyid = tracker->get_joy_id();
if (joyid != -1) {
input->joy_button(joyid, p_button, p_is_pressed);
}
}
}
void GDAPI godot_arvr_set_controller_axis(godot_int p_controller_id, godot_int p_axis, godot_real p_value, godot_bool p_can_be_negative) {
ARVRServer *arvr_server = ARVRServer::get_singleton();
ERR_FAIL_NULL(arvr_server);
InputDefault *input = (InputDefault *)Input::get_singleton();
ERR_FAIL_NULL(input);
Ref<ARVRPositionalTracker> tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id);
if (tracker.is_valid()) {
int joyid = tracker->get_joy_id();
if (joyid != -1) {
float value = p_value;
if (!p_can_be_negative) {
// Convert to a value between -1.0f and 1.0f.
value = p_value * 2.0f - 1.0f;
}
input->joy_axis(joyid, p_axis, value);
}
}
}
godot_real GDAPI godot_arvr_get_controller_rumble(godot_int p_controller_id) {
ARVRServer *arvr_server = ARVRServer::get_singleton();
ERR_FAIL_NULL_V(arvr_server, 0.0);
Ref<ARVRPositionalTracker> tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id);
if (tracker.is_valid()) {
return tracker->get_rumble();
}
return 0.0;
}
void GDAPI godot_arvr_set_interface(godot_object *p_arvr_interface, const godot_arvr_interface_gdnative *p_gdn_interface) {
// If our major version is 0 or bigger then 10, we're likely looking at our constructor pointer from an older plugin
ERR_FAIL_COND_MSG((p_gdn_interface->version.major == 0) || (p_gdn_interface->version.major > 10), "GDNative ARVR interfaces build for Godot 3.0 are not supported.");
ARVRInterfaceGDNative *interface = (ARVRInterfaceGDNative *)p_arvr_interface;
interface->set_interface((const godot_arvr_interface_gdnative *)p_gdn_interface);
}
godot_int GDAPI godot_arvr_get_depthid(godot_rid *p_render_target) {
// We also need to access our depth texture for reprojection.
RID *render_target = (RID *)p_render_target;
uint32_t texid = VSG::storage->render_target_get_depth_texture_id(*render_target);
return texid;
}
}

View File

@ -0,0 +1,89 @@
/**************************************************************************/
/* arvr_interface_gdnative.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef ARVR_INTERFACE_GDNATIVE_H
#define ARVR_INTERFACE_GDNATIVE_H
#include "modules/gdnative/gdnative.h"
#include "servers/arvr/arvr_interface.h"
/**
@authors Hinsbart & Karroffel & Mux213
This subclass of our AR/VR interface forms a bridge to GDNative.
*/
class ARVRInterfaceGDNative : public ARVRInterface {
GDCLASS(ARVRInterfaceGDNative, ARVRInterface);
void cleanup();
protected:
const godot_arvr_interface_gdnative *interface;
void *data;
static void _bind_methods();
public:
/** general interface information **/
ARVRInterfaceGDNative();
~ARVRInterfaceGDNative();
void set_interface(const godot_arvr_interface_gdnative *p_interface);
virtual StringName get_name() const;
virtual int get_capabilities() const;
virtual bool is_initialized() const;
virtual bool initialize();
virtual void uninitialize();
/** specific to AR **/
virtual bool get_anchor_detection_is_enabled() const;
virtual void set_anchor_detection_is_enabled(bool p_enable);
virtual int get_camera_feed_id();
/** rendering and internal **/
virtual Size2 get_render_targetsize();
virtual bool is_stereo();
virtual Transform get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform);
// and a CameraMatrix version to ARVRServer
virtual CameraMatrix get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far);
virtual unsigned int get_external_texture_for_eye(ARVRInterface::Eyes p_eye);
virtual unsigned int get_external_depth_for_eye(ARVRInterface::Eyes p_eye);
virtual void commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect);
virtual void process();
virtual void notification(int p_what);
};
#endif // ARVR_INTERFACE_GDNATIVE_H

39
arvr/register_types.cpp Normal file
View File

@ -0,0 +1,39 @@
/**************************************************************************/
/* register_types.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "register_types.h"
#include "arvr_interface_gdnative.h"
void register_arvr_types() {
ClassDB::register_class<ARVRInterfaceGDNative>();
}
void unregister_arvr_types() {
}

37
arvr/register_types.h Normal file
View File

@ -0,0 +1,37 @@
/**************************************************************************/
/* register_types.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef ARVR_REGISTER_TYPES_H
#define ARVR_REGISTER_TYPES_H
void register_arvr_types();
void unregister_arvr_types();
#endif // ARVR_REGISTER_TYPES_H

26
config.py Normal file
View File

@ -0,0 +1,26 @@
def can_build(env, platform):
return True
def configure(env):
env.use_ptrcall = True
def get_doc_classes():
return [
"ARVRInterfaceGDNative",
"GDNative",
"GDNativeLibrary",
"MultiplayerPeerGDNative",
"NativeScript",
"PacketPeerGDNative",
"PluginScript",
"StreamPeerGDNative",
"VideoStreamGDNative",
"WebRTCPeerConnectionGDNative",
"WebRTCDataChannelGDNative",
]
def get_doc_path():
return "doc_classes"

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="ARVRInterfaceGDNative" inherits="ARVRInterface" version="3.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
GDNative wrapper for an ARVR interface.
</brief_description>
<description>
This is a wrapper class for GDNative implementations of the ARVR interface. To use a GDNative ARVR interface, simply instantiate this object and set your GDNative library containing the ARVR interface implementation.
</description>
<tutorials>
</tutorials>
<methods>
</methods>
<constants>
</constants>
</class>

35
doc_classes/GDNative.xml Normal file
View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="GDNative" inherits="Reference" version="3.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<methods>
<method name="call_native">
<return type="Variant" />
<argument index="0" name="calling_type" type="String" />
<argument index="1" name="procedure_name" type="String" />
<argument index="2" name="arguments" type="Array" />
<description>
</description>
</method>
<method name="initialize">
<return type="bool" />
<description>
</description>
</method>
<method name="terminate">
<return type="bool" />
<description>
</description>
</method>
</methods>
<members>
<member name="library" type="GDNativeLibrary" setter="set_library" getter="get_library">
</member>
</members>
<constants>
</constants>
</class>

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="GDNativeLibrary" inherits="Resource" version="3.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
An external library containing functions or script classes to use in Godot.
</brief_description>
<description>
A GDNative library can implement [NativeScript]s, global functions to call with the [GDNative] class, or low-level engine extensions through interfaces such as [ARVRInterfaceGDNative]. The library must be compiled for each platform and architecture that the project will run on.
</description>
<tutorials>
<link>$DOCS_URL/tutorials/scripting/gdnative/gdnative_c_example.html</link>
<link>$DOCS_URL/tutorials/scripting/gdnative/gdnative_cpp_example.html</link>
</tutorials>
<methods>
<method name="get_current_dependencies" qualifiers="const">
<return type="PoolStringArray" />
<description>
Returns paths to all dependency libraries for the current platform and architecture.
</description>
</method>
<method name="get_current_library_path" qualifiers="const">
<return type="String" />
<description>
Returns the path to the dynamic library file for the current platform and architecture.
</description>
</method>
</methods>
<members>
<member name="config_file" type="ConfigFile" setter="set_config_file" getter="get_config_file">
This resource in INI-style [ConfigFile] format, as in [code].gdnlib[/code] files.
</member>
<member name="load_once" type="bool" setter="set_load_once" getter="should_load_once" default="true">
If [code]true[/code], Godot loads only one copy of the library and each script that references the library will share static data like static or global variables.
If [code]false[/code], Godot loads a separate copy of the library into memory for each script that references it.
</member>
<member name="reloadable" type="bool" setter="set_reloadable" getter="is_reloadable" default="true">
If [code]true[/code], the editor will temporarily unload the library whenever the user switches away from the editor window, allowing the user to recompile the library without restarting Godot.
[b]Note:[/b] If the library defines tool scripts that run inside the editor, [code]reloadable[/code] must be [code]false[/code]. Otherwise, the editor will attempt to unload the tool scripts while they're in use and crash.
</member>
<member name="singleton" type="bool" setter="set_singleton" getter="is_singleton" default="false">
If [code]true[/code], Godot loads the library at startup rather than the first time a script uses the library, calling [code]{prefix}gdnative_singleton[/code] after initializing the library (where [code]{prefix}[/code] is the value of [member symbol_prefix]). The library remains loaded as long as Godot is running.
[b]Note:[/b] A singleton library cannot be [member reloadable].
</member>
<member name="symbol_prefix" type="String" setter="set_symbol_prefix" getter="get_symbol_prefix" default="&quot;godot_&quot;">
The prefix this library's entry point functions begin with. For example, a GDNativeLibrary would declare its [code]gdnative_init[/code] function as [code]godot_gdnative_init[/code] by default.
On platforms that require statically linking libraries (currently only iOS), each library must have a different [code]symbol_prefix[/code].
</member>
</members>
<constants>
</constants>
</class>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="MultiplayerPeerGDNative" inherits="NetworkedMultiplayerPeer" version="3.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<methods>
</methods>
<members>
<member name="refuse_new_connections" type="bool" setter="set_refuse_new_connections" getter="is_refusing_new_connections" overrides="NetworkedMultiplayerPeer" default="true" />
<member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" overrides="NetworkedMultiplayerPeer" enum="NetworkedMultiplayerPeer.TransferMode" default="0" />
</members>
<constants>
</constants>
</class>

View File

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="NativeScript" inherits="Script" version="3.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<methods>
<method name="get_class_documentation" qualifiers="const">
<return type="String" />
<description>
Returns the documentation string that was previously set with [code]godot_nativescript_set_class_documentation[/code].
</description>
</method>
<method name="get_method_documentation" qualifiers="const">
<return type="String" />
<argument index="0" name="method" type="String" />
<description>
Returns the documentation string that was previously set with [code]godot_nativescript_set_method_documentation[/code].
</description>
</method>
<method name="get_property_documentation" qualifiers="const">
<return type="String" />
<argument index="0" name="path" type="String" />
<description>
Returns the documentation string that was previously set with [code]godot_nativescript_set_property_documentation[/code].
</description>
</method>
<method name="get_signal_documentation" qualifiers="const">
<return type="String" />
<argument index="0" name="signal_name" type="String" />
<description>
Returns the documentation string that was previously set with [code]godot_nativescript_set_signal_documentation[/code].
</description>
</method>
<method name="new" qualifiers="vararg">
<return type="Variant" />
<description>
Constructs a new object of the base type with a script of this type already attached.
[b]Note:[/b] Any arguments passed to this function will be ignored and not passed to the native constructor function. This will change with in a future API extension.
</description>
</method>
</methods>
<members>
<member name="class_name" type="String" setter="set_class_name" getter="get_class_name" default="&quot;&quot;">
</member>
<member name="library" type="GDNativeLibrary" setter="set_library" getter="get_library">
</member>
<member name="script_class_icon_path" type="String" setter="set_script_class_icon_path" getter="get_script_class_icon_path" default="&quot;&quot;">
</member>
<member name="script_class_name" type="String" setter="set_script_class_name" getter="get_script_class_name" default="&quot;&quot;">
</member>
</members>
<constants>
</constants>
</class>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="PacketPeerGDNative" inherits="PacketPeer" version="3.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<methods>
</methods>
<constants>
</constants>
</class>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="PluginScript" inherits="Script" version="3.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<methods>
<method name="new" qualifiers="vararg">
<return type="Variant" />
<description>
Returns a new instance of the script.
</description>
</method>
</methods>
<constants>
</constants>
</class>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="StreamPeerGDNative" inherits="StreamPeer" version="3.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<methods>
</methods>
<constants>
</constants>
</class>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="VideoStreamGDNative" inherits="VideoStream" version="3.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
[VideoStream] resource for video formats implemented via GDNative.
</brief_description>
<description>
[VideoStream] resource for video formats implemented via GDNative.
It can be used via [url=https://github.com/KidRigger/godot-videodecoder]godot-videodecoder[/url] which uses the [url=https://ffmpeg.org]FFmpeg[/url] library.
</description>
<tutorials>
</tutorials>
<methods>
<method name="get_file">
<return type="String" />
<description>
Returns the video file handled by this [VideoStreamGDNative].
</description>
</method>
<method name="set_file">
<return type="void" />
<argument index="0" name="file" type="String" />
<description>
Sets the video file that this [VideoStreamGDNative] resource handles. The supported extensions depend on the GDNative plugins used to expose video formats.
</description>
</method>
</methods>
<constants>
</constants>
</class>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="WebRTCDataChannelGDNative" inherits="WebRTCDataChannel" version="3.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<methods>
</methods>
<constants>
</constants>
</class>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="WebRTCPeerConnectionGDNative" inherits="WebRTCPeerConnection" version="3.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<methods>
</methods>
<constants>
</constants>
</class>

581
gdnative.cpp Normal file
View File

@ -0,0 +1,581 @@
/**************************************************************************/
/* gdnative.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "gdnative.h"
#include "core/global_constants.h"
#include "core/io/file_access_encrypted.h"
#include "core/os/dir_access.h"
#include "core/os/file_access.h"
#include "core/os/os.h"
#include "core/project_settings.h"
#include "scene/main/scene_tree.h"
static const String init_symbol = "gdnative_init";
static const String terminate_symbol = "gdnative_terminate";
static const String default_symbol_prefix = "godot_";
static const bool default_singleton = false;
static const bool default_load_once = true;
static const bool default_reloadable = true;
// Defined in gdnative_api_struct.gen.cpp
extern const godot_gdnative_core_api_struct api_struct;
Map<String, Vector<Ref<GDNative>>> GDNativeLibrary::loaded_libraries;
GDNativeLibrary::GDNativeLibrary() {
config_file.instance();
symbol_prefix = default_symbol_prefix;
load_once = default_load_once;
singleton = default_singleton;
reloadable = default_reloadable;
}
GDNativeLibrary::~GDNativeLibrary() {
}
bool GDNativeLibrary::_set(const StringName &p_name, const Variant &p_property) {
String name = p_name;
if (name.begins_with("entry/")) {
String key = name.substr(6, name.length() - 6);
config_file->set_value("entry", key, p_property);
set_config_file(config_file);
return true;
}
if (name.begins_with("dependency/")) {
String key = name.substr(11, name.length() - 11);
config_file->set_value("dependencies", key, p_property);
set_config_file(config_file);
return true;
}
return false;
}
bool GDNativeLibrary::_get(const StringName &p_name, Variant &r_property) const {
String name = p_name;
if (name.begins_with("entry/")) {
String key = name.substr(6, name.length() - 6);
r_property = config_file->get_value("entry", key);
return true;
}
if (name.begins_with("dependency/")) {
String key = name.substr(11, name.length() - 11);
r_property = config_file->get_value("dependencies", key);
return true;
}
return false;
}
void GDNativeLibrary::_get_property_list(List<PropertyInfo> *p_list) const {
// set entries
List<String> entry_key_list;
if (config_file->has_section("entry")) {
config_file->get_section_keys("entry", &entry_key_list);
}
for (List<String>::Element *E = entry_key_list.front(); E; E = E->next()) {
String key = E->get();
PropertyInfo prop;
prop.type = Variant::STRING;
prop.name = "entry/" + key;
p_list->push_back(prop);
}
// set dependencies
List<String> dependency_key_list;
if (config_file->has_section("dependencies")) {
config_file->get_section_keys("dependencies", &dependency_key_list);
}
for (List<String>::Element *E = dependency_key_list.front(); E; E = E->next()) {
String key = E->get();
PropertyInfo prop;
prop.type = Variant::STRING;
prop.name = "dependency/" + key;
p_list->push_back(prop);
}
}
void GDNativeLibrary::set_config_file(Ref<ConfigFile> p_config_file) {
ERR_FAIL_COND(p_config_file.is_null());
set_singleton(p_config_file->get_value("general", "singleton", default_singleton));
set_load_once(p_config_file->get_value("general", "load_once", default_load_once));
set_symbol_prefix(p_config_file->get_value("general", "symbol_prefix", default_symbol_prefix));
set_reloadable(p_config_file->get_value("general", "reloadable", default_reloadable));
String entry_lib_path;
{
List<String> entry_keys;
if (p_config_file->has_section("entry")) {
p_config_file->get_section_keys("entry", &entry_keys);
}
for (List<String>::Element *E = entry_keys.front(); E; E = E->next()) {
String key = E->get();
Vector<String> tags = key.split(".");
bool skip = false;
for (int i = 0; i < tags.size(); i++) {
bool has_feature = OS::get_singleton()->has_feature(tags[i]);
if (!has_feature) {
skip = true;
break;
}
}
if (skip) {
continue;
}
entry_lib_path = p_config_file->get_value("entry", key);
break;
}
}
Vector<String> dependency_paths;
{
List<String> dependency_keys;
if (p_config_file->has_section("dependencies")) {
p_config_file->get_section_keys("dependencies", &dependency_keys);
}
for (List<String>::Element *E = dependency_keys.front(); E; E = E->next()) {
String key = E->get();
Vector<String> tags = key.split(".");
bool skip = false;
for (int i = 0; i < tags.size(); i++) {
bool has_feature = OS::get_singleton()->has_feature(tags[i]);
if (!has_feature) {
skip = true;
break;
}
}
if (skip) {
continue;
}
dependency_paths = p_config_file->get_value("dependencies", key);
break;
}
}
current_library_path = entry_lib_path;
current_dependencies = dependency_paths;
}
void GDNativeLibrary::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_config_file"), &GDNativeLibrary::get_config_file);
ClassDB::bind_method(D_METHOD("set_config_file", "config_file"), &GDNativeLibrary::set_config_file);
ClassDB::bind_method(D_METHOD("get_current_library_path"), &GDNativeLibrary::get_current_library_path);
ClassDB::bind_method(D_METHOD("get_current_dependencies"), &GDNativeLibrary::get_current_dependencies);
ClassDB::bind_method(D_METHOD("should_load_once"), &GDNativeLibrary::should_load_once);
ClassDB::bind_method(D_METHOD("is_singleton"), &GDNativeLibrary::is_singleton);
ClassDB::bind_method(D_METHOD("get_symbol_prefix"), &GDNativeLibrary::get_symbol_prefix);
ClassDB::bind_method(D_METHOD("is_reloadable"), &GDNativeLibrary::is_reloadable);
ClassDB::bind_method(D_METHOD("set_load_once", "load_once"), &GDNativeLibrary::set_load_once);
ClassDB::bind_method(D_METHOD("set_singleton", "singleton"), &GDNativeLibrary::set_singleton);
ClassDB::bind_method(D_METHOD("set_symbol_prefix", "symbol_prefix"), &GDNativeLibrary::set_symbol_prefix);
ClassDB::bind_method(D_METHOD("set_reloadable", "reloadable"), &GDNativeLibrary::set_reloadable);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "config_file", PROPERTY_HINT_RESOURCE_TYPE, "ConfigFile", 0), "set_config_file", "get_config_file");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "load_once"), "set_load_once", "should_load_once");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "singleton"), "set_singleton", "is_singleton");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "symbol_prefix"), "set_symbol_prefix", "get_symbol_prefix");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "reloadable"), "set_reloadable", "is_reloadable");
}
GDNative::GDNative() {
native_handle = nullptr;
initialized = false;
}
GDNative::~GDNative() {
}
void GDNative::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_library", "library"), &GDNative::set_library);
ClassDB::bind_method(D_METHOD("get_library"), &GDNative::get_library);
ClassDB::bind_method(D_METHOD("initialize"), &GDNative::initialize);
ClassDB::bind_method(D_METHOD("terminate"), &GDNative::terminate);
ClassDB::bind_method(D_METHOD("call_native", "calling_type", "procedure_name", "arguments"), &GDNative::call_native);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "GDNativeLibrary"), "set_library", "get_library");
}
void GDNative::set_library(Ref<GDNativeLibrary> p_library) {
ERR_FAIL_COND_MSG(library.is_valid(), "Tried to change library of GDNative when it is already set.");
library = p_library;
}
Ref<GDNativeLibrary> GDNative::get_library() const {
return library;
}
extern "C" void _gdnative_report_version_mismatch(const godot_object *p_library, const char *p_ext, godot_gdnative_api_version p_want, godot_gdnative_api_version p_have);
extern "C" void _gdnative_report_loading_error(const godot_object *p_library, const char *p_what);
bool GDNative::initialize() {
if (library.is_null()) {
ERR_PRINT("No library set, can't initialize GDNative object");
return false;
}
String lib_path = library->get_current_library_path();
if (lib_path.empty()) {
ERR_PRINT("No library set for this platform");
return false;
}
#ifdef IPHONE_ENABLED
// On iOS we use static linking by default.
String path = "";
// On iOS dylibs is not allowed, but can be replaced with .framework or .xcframework.
// If they are used, we can run dlopen on them.
// They should be located under Frameworks directory, so we need to replace library path.
if (!lib_path.ends_with(".a")) {
path = ProjectSettings::get_singleton()->globalize_path(lib_path);
if (!FileAccess::exists(path)) {
String lib_name = lib_path.get_basename().get_file();
String framework_path_format = "Frameworks/$name.framework/$name";
Dictionary format_dict;
format_dict["name"] = lib_name;
String framework_path = framework_path_format.format(format_dict, "$_");
path = OS::get_singleton()->get_executable_path().get_base_dir().plus_file(framework_path);
}
}
#elif defined(ANDROID_ENABLED)
// On Android dynamic libraries are located separately from resource assets,
// we should pass library name to dlopen(). The library name is flattened
// during export.
String path = lib_path.get_file();
#elif defined(UWP_ENABLED)
// On UWP we use a relative path from the app
String path = lib_path.replace("res://", "");
#elif defined(OSX_ENABLED)
// On OSX the exported libraries are located under the Frameworks directory.
// So we need to replace the library path.
String path = ProjectSettings::get_singleton()->globalize_path(lib_path);
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
if (!da->file_exists(path) && !da->dir_exists(path)) {
path = OS::get_singleton()->get_executable_path().get_base_dir().plus_file("../Frameworks").plus_file(lib_path.get_file());
}
if (da->dir_exists(path)) { // Target library is a ".framework", add library base name to the path.
path = path.plus_file(path.get_file().get_basename());
}
memdelete(da);
#else
String path = ProjectSettings::get_singleton()->globalize_path(lib_path);
#endif
if (library->should_load_once()) {
if (GDNativeLibrary::loaded_libraries.has(lib_path)) {
// already loaded. Don't load again.
// copy some of the stuff instead
this->native_handle = GDNativeLibrary::loaded_libraries[lib_path][0]->native_handle;
initialized = true;
return true;
}
}
Error err = OS::get_singleton()->open_dynamic_library(path, native_handle, true);
if (err != OK) {
return false;
}
void *library_init;
// we cheat here a little bit. you saw nothing
initialized = true;
err = get_symbol(library->get_symbol_prefix() + init_symbol, library_init, false);
initialized = false;
if (err || !library_init) {
OS::get_singleton()->close_dynamic_library(native_handle);
native_handle = nullptr;
ERR_PRINT("Failed to obtain " + library->get_symbol_prefix() + "gdnative_init symbol");
return false;
}
godot_gdnative_init_fn library_init_fpointer;
library_init_fpointer = (godot_gdnative_init_fn)library_init;
static uint64_t core_api_hash = 0;
static uint64_t editor_api_hash = 0;
static uint64_t no_api_hash = 0;
if (!(core_api_hash || editor_api_hash || no_api_hash)) {
core_api_hash = ClassDB::get_api_hash(ClassDB::API_CORE);
editor_api_hash = ClassDB::get_api_hash(ClassDB::API_EDITOR);
no_api_hash = ClassDB::get_api_hash(ClassDB::API_NONE);
}
godot_gdnative_init_options options;
options.api_struct = &api_struct;
options.in_editor = Engine::get_singleton()->is_editor_hint();
options.core_api_hash = core_api_hash;
options.editor_api_hash = editor_api_hash;
options.no_api_hash = no_api_hash;
options.report_version_mismatch = &_gdnative_report_version_mismatch;
options.report_loading_error = &_gdnative_report_loading_error;
options.gd_native_library = (godot_object *)(get_library().ptr());
options.active_library_path = (godot_string *)&path;
library_init_fpointer(&options);
initialized = true;
if (library->should_load_once() && !GDNativeLibrary::loaded_libraries.has(lib_path)) {
Vector<Ref<GDNative>> gdnatives;
gdnatives.resize(1);
gdnatives.write[0] = Ref<GDNative>(this);
GDNativeLibrary::loaded_libraries.insert(lib_path, gdnatives);
}
return true;
}
bool GDNative::terminate() {
if (!initialized) {
ERR_PRINT("No valid library handle, can't terminate GDNative object");
return false;
}
if (library->should_load_once()) {
Vector<Ref<GDNative>> *gdnatives = &GDNativeLibrary::loaded_libraries[library->get_current_library_path()];
if (gdnatives->size() > 1) {
// there are other GDNative's still using this library, so we actually don't terminate
gdnatives->erase(Ref<GDNative>(this));
initialized = false;
return true;
} else if (gdnatives->size() == 1) {
// we're the last one, terminate!
gdnatives->clear();
// whew this looks scary, but all it does is remove the entry completely
GDNativeLibrary::loaded_libraries.erase(GDNativeLibrary::loaded_libraries.find(library->get_current_library_path()));
}
}
void *library_terminate;
Error error = get_symbol(library->get_symbol_prefix() + terminate_symbol, library_terminate);
if (error || !library_terminate) {
OS::get_singleton()->close_dynamic_library(native_handle);
native_handle = nullptr;
initialized = false;
return true;
}
godot_gdnative_terminate_fn library_terminate_pointer;
library_terminate_pointer = (godot_gdnative_terminate_fn)library_terminate;
godot_gdnative_terminate_options options;
options.in_editor = Engine::get_singleton()->is_editor_hint();
library_terminate_pointer(&options);
initialized = false;
// GDNativeScriptLanguage::get_singleton()->initialized_libraries.erase(p_native_lib->path);
OS::get_singleton()->close_dynamic_library(native_handle);
native_handle = nullptr;
return true;
}
bool GDNative::is_initialized() const {
return initialized;
}
void GDNativeCallRegistry::register_native_call_type(StringName p_call_type, native_call_cb p_callback) {
native_calls.insert(p_call_type, p_callback);
}
Vector<StringName> GDNativeCallRegistry::get_native_call_types() {
Vector<StringName> call_types;
call_types.resize(native_calls.size());
size_t idx = 0;
for (Map<StringName, native_call_cb>::Element *E = native_calls.front(); E; E = E->next(), idx++) {
call_types.write[idx] = E->key();
}
return call_types;
}
Variant GDNative::call_native(StringName p_native_call_type, StringName p_procedure_name, Array p_arguments) {
Map<StringName, native_call_cb>::Element *E = GDNativeCallRegistry::singleton->native_calls.find(p_native_call_type);
if (!E) {
ERR_PRINT((String("No handler for native call type \"" + p_native_call_type) + "\" found").utf8().get_data());
return Variant();
}
void *procedure_handle;
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
native_handle,
p_procedure_name,
procedure_handle);
if (err != OK || procedure_handle == nullptr) {
return Variant();
}
godot_variant result = E->get()(procedure_handle, (godot_array *)&p_arguments);
Variant res = *(Variant *)&result;
godot_variant_destroy(&result);
return res;
}
Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle, bool p_optional) const {
if (!initialized) {
ERR_PRINT("No valid library handle, can't get symbol from GDNative object");
return ERR_CANT_OPEN;
}
Error result = OS::get_singleton()->get_dynamic_library_symbol_handle(
native_handle,
p_procedure_name,
r_handle,
p_optional);
return result;
}
RES GDNativeLibraryResourceLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
Ref<GDNativeLibrary> lib;
lib.instance();
Ref<ConfigFile> config = lib->get_config_file();
Error err = config->load(p_path);
if (r_error) {
*r_error = err;
}
lib->set_config_file(config);
return lib;
}
void GDNativeLibraryResourceLoader::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("gdnlib");
}
bool GDNativeLibraryResourceLoader::handles_type(const String &p_type) const {
return p_type == "GDNativeLibrary";
}
String GDNativeLibraryResourceLoader::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
if (el == "gdnlib") {
return "GDNativeLibrary";
}
return "";
}
Error GDNativeLibraryResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
Ref<GDNativeLibrary> lib = p_resource;
if (lib.is_null()) {
return ERR_INVALID_DATA;
}
Ref<ConfigFile> config = lib->get_config_file();
config->set_value("general", "singleton", lib->is_singleton());
config->set_value("general", "load_once", lib->should_load_once());
config->set_value("general", "symbol_prefix", lib->get_symbol_prefix());
config->set_value("general", "reloadable", lib->is_reloadable());
return config->save(p_path);
}
bool GDNativeLibraryResourceSaver::recognize(const RES &p_resource) const {
return Object::cast_to<GDNativeLibrary>(*p_resource) != nullptr;
}
void GDNativeLibraryResourceSaver::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
if (Object::cast_to<GDNativeLibrary>(*p_resource) != nullptr) {
p_extensions->push_back("gdnlib");
}
}

182
gdnative.h Normal file
View File

@ -0,0 +1,182 @@
/**************************************************************************/
/* gdnative.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_H
#define GDNATIVE_H
#include "core/io/resource_loader.h"
#include "core/io/resource_saver.h"
#include "core/os/thread_safe.h"
#include "core/resource.h"
#include "gdnative/gdnative.h"
#include "gdnative_api_struct.gen.h"
#include "core/io/config_file.h"
class GDNativeLibraryResourceLoader;
class GDNative;
class GDNativeLibrary : public Resource {
GDCLASS(GDNativeLibrary, Resource);
static Map<String, Vector<Ref<GDNative>>> loaded_libraries;
friend class GDNativeLibraryResourceLoader;
friend class GDNative;
Ref<ConfigFile> config_file;
String current_library_path;
Vector<String> current_dependencies;
bool singleton;
bool load_once;
String symbol_prefix;
bool reloadable;
public:
GDNativeLibrary();
~GDNativeLibrary();
virtual bool _set(const StringName &p_name, const Variant &p_property);
virtual bool _get(const StringName &p_name, Variant &r_property) const;
virtual void _get_property_list(List<PropertyInfo> *p_list) const;
_FORCE_INLINE_ Ref<ConfigFile> get_config_file() { return config_file; }
void set_config_file(Ref<ConfigFile> p_config_file);
// things that change per-platform
// so there are no setters for this
_FORCE_INLINE_ const String &get_current_library_path() const {
return current_library_path;
}
_FORCE_INLINE_ Vector<String> get_current_dependencies() const {
return current_dependencies;
}
// things that are a property of the library itself, not platform specific
_FORCE_INLINE_ bool should_load_once() const {
return load_once;
}
_FORCE_INLINE_ bool is_singleton() const {
return singleton;
}
_FORCE_INLINE_ String get_symbol_prefix() const {
return symbol_prefix;
}
_FORCE_INLINE_ bool is_reloadable() const {
return reloadable;
}
_FORCE_INLINE_ void set_load_once(bool p_load_once) {
config_file->set_value("general", "load_once", p_load_once);
load_once = p_load_once;
}
_FORCE_INLINE_ void set_singleton(bool p_singleton) {
config_file->set_value("general", "singleton", p_singleton);
singleton = p_singleton;
}
_FORCE_INLINE_ void set_symbol_prefix(String p_symbol_prefix) {
config_file->set_value("general", "symbol_prefix", p_symbol_prefix);
symbol_prefix = p_symbol_prefix;
}
_FORCE_INLINE_ void set_reloadable(bool p_reloadable) {
config_file->set_value("general", "reloadable", p_reloadable);
reloadable = p_reloadable;
}
static void _bind_methods();
};
struct GDNativeCallRegistry {
static GDNativeCallRegistry *singleton;
inline static GDNativeCallRegistry *get_singleton() {
return singleton;
}
inline GDNativeCallRegistry() :
native_calls() {}
Map<StringName, native_call_cb> native_calls;
void register_native_call_type(StringName p_call_type, native_call_cb p_callback);
Vector<StringName> get_native_call_types();
};
class GDNative : public Reference {
GDCLASS(GDNative, Reference);
Ref<GDNativeLibrary> library;
void *native_handle;
bool initialized;
public:
GDNative();
~GDNative();
static void _bind_methods();
void set_library(Ref<GDNativeLibrary> p_library);
Ref<GDNativeLibrary> get_library() const;
bool is_initialized() const;
bool initialize();
bool terminate();
Variant call_native(StringName p_native_call_type, StringName p_procedure_name, Array p_arguments = Array());
Error get_symbol(StringName p_procedure_name, void *&r_handle, bool p_optional = true) const;
};
class GDNativeLibraryResourceLoader : public ResourceFormatLoader {
public:
virtual RES load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
};
class GDNativeLibraryResourceSaver : public ResourceFormatSaver {
public:
virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags);
virtual bool recognize(const RES &p_resource) const;
virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const;
};
#endif // GDNATIVE_H

220
gdnative/aabb.cpp Normal file
View File

@ -0,0 +1,220 @@
/**************************************************************************/
/* aabb.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "gdnative/aabb.h"
#include "core/math/aabb.h"
#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
#endif
static_assert(sizeof(godot_aabb) == sizeof(AABB), "AABB size mismatch");
void GDAPI godot_aabb_new(godot_aabb *r_dest, const godot_vector3 *p_pos, const godot_vector3 *p_size) {
const Vector3 *pos = (const Vector3 *)p_pos;
const Vector3 *size = (const Vector3 *)p_size;
AABB *dest = (AABB *)r_dest;
*dest = AABB(*pos, *size);
}
godot_vector3 GDAPI godot_aabb_get_position(const godot_aabb *p_self) {
godot_vector3 raw_ret;
const AABB *self = (const AABB *)p_self;
Vector3 *ret = (Vector3 *)&raw_ret;
*ret = self->position;
return raw_ret;
}
void GDAPI godot_aabb_set_position(const godot_aabb *p_self, const godot_vector3 *p_v) {
AABB *self = (AABB *)p_self;
const Vector3 *v = (const Vector3 *)p_v;
self->position = *v;
}
godot_vector3 GDAPI godot_aabb_get_size(const godot_aabb *p_self) {
godot_vector3 raw_ret;
const AABB *self = (const AABB *)p_self;
Vector3 *ret = (Vector3 *)&raw_ret;
*ret = self->size;
return raw_ret;
}
void GDAPI godot_aabb_set_size(const godot_aabb *p_self, const godot_vector3 *p_v) {
AABB *self = (AABB *)p_self;
const Vector3 *v = (const Vector3 *)p_v;
self->size = *v;
}
godot_string GDAPI godot_aabb_as_string(const godot_aabb *p_self) {
godot_string ret;
const AABB *self = (const AABB *)p_self;
memnew_placement(&ret, String(*self));
return ret;
}
godot_real GDAPI godot_aabb_get_area(const godot_aabb *p_self) {
const AABB *self = (const AABB *)p_self;
return self->get_area();
}
godot_bool GDAPI godot_aabb_has_no_area(const godot_aabb *p_self) {
const AABB *self = (const AABB *)p_self;
return self->has_no_area();
}
godot_bool GDAPI godot_aabb_has_no_surface(const godot_aabb *p_self) {
const AABB *self = (const AABB *)p_self;
return self->has_no_surface();
}
godot_bool GDAPI godot_aabb_intersects(const godot_aabb *p_self, const godot_aabb *p_with) {
const AABB *self = (const AABB *)p_self;
const AABB *with = (const AABB *)p_with;
return self->intersects(*with);
}
godot_bool GDAPI godot_aabb_encloses(const godot_aabb *p_self, const godot_aabb *p_with) {
const AABB *self = (const AABB *)p_self;
const AABB *with = (const AABB *)p_with;
return self->encloses(*with);
}
godot_aabb GDAPI godot_aabb_merge(const godot_aabb *p_self, const godot_aabb *p_with) {
godot_aabb dest;
const AABB *self = (const AABB *)p_self;
const AABB *with = (const AABB *)p_with;
*((AABB *)&dest) = self->merge(*with);
return dest;
}
godot_aabb GDAPI godot_aabb_intersection(const godot_aabb *p_self, const godot_aabb *p_with) {
godot_aabb dest;
const AABB *self = (const AABB *)p_self;
const AABB *with = (const AABB *)p_with;
*((AABB *)&dest) = self->intersection(*with);
return dest;
}
godot_bool GDAPI godot_aabb_intersects_plane(const godot_aabb *p_self, const godot_plane *p_plane) {
const AABB *self = (const AABB *)p_self;
const Plane *plane = (const Plane *)p_plane;
return self->intersects_plane(*plane);
}
godot_bool GDAPI godot_aabb_intersects_segment(const godot_aabb *p_self, const godot_vector3 *p_from, const godot_vector3 *p_to) {
const AABB *self = (const AABB *)p_self;
const Vector3 *from = (const Vector3 *)p_from;
const Vector3 *to = (const Vector3 *)p_to;
return self->intersects_segment(*from, *to);
}
godot_bool GDAPI godot_aabb_has_point(const godot_aabb *p_self, const godot_vector3 *p_point) {
const AABB *self = (const AABB *)p_self;
const Vector3 *point = (const Vector3 *)p_point;
return self->has_point(*point);
}
godot_vector3 GDAPI godot_aabb_get_support(const godot_aabb *p_self, const godot_vector3 *p_dir) {
godot_vector3 dest;
const AABB *self = (const AABB *)p_self;
const Vector3 *dir = (const Vector3 *)p_dir;
*((Vector3 *)&dest) = self->get_support(*dir);
return dest;
}
godot_vector3 GDAPI godot_aabb_get_longest_axis(const godot_aabb *p_self) {
godot_vector3 dest;
const AABB *self = (const AABB *)p_self;
*((Vector3 *)&dest) = self->get_longest_axis();
return dest;
}
godot_int GDAPI godot_aabb_get_longest_axis_index(const godot_aabb *p_self) {
const AABB *self = (const AABB *)p_self;
return self->get_longest_axis_index();
}
godot_real GDAPI godot_aabb_get_longest_axis_size(const godot_aabb *p_self) {
const AABB *self = (const AABB *)p_self;
return self->get_longest_axis_size();
}
godot_vector3 GDAPI godot_aabb_get_shortest_axis(const godot_aabb *p_self) {
godot_vector3 dest;
const AABB *self = (const AABB *)p_self;
*((Vector3 *)&dest) = self->get_shortest_axis();
return dest;
}
godot_int GDAPI godot_aabb_get_shortest_axis_index(const godot_aabb *p_self) {
const AABB *self = (const AABB *)p_self;
return self->get_shortest_axis_index();
}
godot_real GDAPI godot_aabb_get_shortest_axis_size(const godot_aabb *p_self) {
const AABB *self = (const AABB *)p_self;
return self->get_shortest_axis_size();
}
godot_aabb GDAPI godot_aabb_expand(const godot_aabb *p_self, const godot_vector3 *p_to_point) {
godot_aabb dest;
const AABB *self = (const AABB *)p_self;
const Vector3 *to_point = (const Vector3 *)p_to_point;
*((AABB *)&dest) = self->expand(*to_point);
return dest;
}
godot_aabb GDAPI godot_aabb_grow(const godot_aabb *p_self, const godot_real p_by) {
godot_aabb dest;
const AABB *self = (const AABB *)p_self;
*((AABB *)&dest) = self->grow(p_by);
return dest;
}
godot_vector3 GDAPI godot_aabb_get_endpoint(const godot_aabb *p_self, const godot_int p_idx) {
godot_vector3 dest;
const AABB *self = (const AABB *)p_self;
*((Vector3 *)&dest) = self->get_endpoint(p_idx);
return dest;
}
godot_bool GDAPI godot_aabb_operator_equal(const godot_aabb *p_self, const godot_aabb *p_b) {
const AABB *self = (const AABB *)p_self;
const AABB *b = (const AABB *)p_b;
return *self == *b;
}
#ifdef __cplusplus
}
#endif

366
gdnative/array.cpp Normal file
View File

@ -0,0 +1,366 @@
/**************************************************************************/
/* array.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "gdnative/array.h"
#include "core/array.h"
#include "core/os/memory.h"
#include "core/color.h"
#include "core/pool_vector.h"
#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
#endif
static_assert(sizeof(godot_array) == sizeof(Array), "Array size mismatch");
void GDAPI godot_array_new(godot_array *r_dest) {
Array *dest = (Array *)r_dest;
memnew_placement(dest, Array);
}
void GDAPI godot_array_new_copy(godot_array *r_dest, const godot_array *p_src) {
Array *dest = (Array *)r_dest;
const Array *src = (const Array *)p_src;
memnew_placement(dest, Array(*src));
}
void GDAPI godot_array_new_pool_color_array(godot_array *r_dest, const godot_pool_color_array *p_pca) {
Array *dest = (Array *)r_dest;
PoolVector<Color> *pca = (PoolVector<Color> *)p_pca;
memnew_placement(dest, Array);
dest->resize(pca->size());
for (int i = 0; i < dest->size(); i++) {
Variant v = pca->operator[](i);
dest->operator[](i) = v;
}
}
void GDAPI godot_array_new_pool_vector3_array(godot_array *r_dest, const godot_pool_vector3_array *p_pv3a) {
Array *dest = (Array *)r_dest;
PoolVector<Vector3> *pca = (PoolVector<Vector3> *)p_pv3a;
memnew_placement(dest, Array);
dest->resize(pca->size());
for (int i = 0; i < dest->size(); i++) {
Variant v = pca->operator[](i);
dest->operator[](i) = v;
}
}
void GDAPI godot_array_new_pool_vector2_array(godot_array *r_dest, const godot_pool_vector2_array *p_pv2a) {
Array *dest = (Array *)r_dest;
PoolVector<Vector2> *pca = (PoolVector<Vector2> *)p_pv2a;
memnew_placement(dest, Array);
dest->resize(pca->size());
for (int i = 0; i < dest->size(); i++) {
Variant v = pca->operator[](i);
dest->operator[](i) = v;
}
}
void GDAPI godot_array_new_pool_string_array(godot_array *r_dest, const godot_pool_string_array *p_psa) {
Array *dest = (Array *)r_dest;
PoolVector<String> *pca = (PoolVector<String> *)p_psa;
memnew_placement(dest, Array);
dest->resize(pca->size());
for (int i = 0; i < dest->size(); i++) {
Variant v = pca->operator[](i);
dest->operator[](i) = v;
}
}
void GDAPI godot_array_new_pool_real_array(godot_array *r_dest, const godot_pool_real_array *p_pra) {
Array *dest = (Array *)r_dest;
PoolVector<godot_real> *pca = (PoolVector<godot_real> *)p_pra;
memnew_placement(dest, Array);
dest->resize(pca->size());
for (int i = 0; i < dest->size(); i++) {
Variant v = pca->operator[](i);
dest->operator[](i) = v;
}
}
void GDAPI godot_array_new_pool_int_array(godot_array *r_dest, const godot_pool_int_array *p_pia) {
Array *dest = (Array *)r_dest;
PoolVector<godot_int> *pca = (PoolVector<godot_int> *)p_pia;
memnew_placement(dest, Array);
dest->resize(pca->size());
for (int i = 0; i < dest->size(); i++) {
Variant v = pca->operator[](i);
dest->operator[](i) = v;
}
}
void GDAPI godot_array_new_pool_byte_array(godot_array *r_dest, const godot_pool_byte_array *p_pba) {
Array *dest = (Array *)r_dest;
PoolVector<uint8_t> *pca = (PoolVector<uint8_t> *)p_pba;
memnew_placement(dest, Array);
dest->resize(pca->size());
for (int i = 0; i < dest->size(); i++) {
Variant v = pca->operator[](i);
dest->operator[](i) = v;
}
}
void GDAPI godot_array_set(godot_array *p_self, const godot_int p_idx, const godot_variant *p_value) {
Array *self = (Array *)p_self;
Variant *val = (Variant *)p_value;
self->operator[](p_idx) = *val;
}
godot_variant GDAPI godot_array_get(const godot_array *p_self, const godot_int p_idx) {
godot_variant raw_dest;
Variant *dest = (Variant *)&raw_dest;
const Array *self = (const Array *)p_self;
memnew_placement(dest, Variant(self->operator[](p_idx)));
return raw_dest;
}
godot_variant GDAPI *godot_array_operator_index(godot_array *p_self, const godot_int p_idx) {
Array *self = (Array *)p_self;
return (godot_variant *)&self->operator[](p_idx);
}
const godot_variant GDAPI *godot_array_operator_index_const(const godot_array *p_self, const godot_int p_idx) {
const Array *self = (const Array *)p_self;
return (const godot_variant *)&self->operator[](p_idx);
}
void GDAPI godot_array_append(godot_array *p_self, const godot_variant *p_value) {
Array *self = (Array *)p_self;
Variant *val = (Variant *)p_value;
self->append(*val);
}
void GDAPI godot_array_clear(godot_array *p_self) {
Array *self = (Array *)p_self;
self->clear();
}
godot_int GDAPI godot_array_count(const godot_array *p_self, const godot_variant *p_value) {
const Array *self = (const Array *)p_self;
const Variant *val = (const Variant *)p_value;
return self->count(*val);
}
godot_bool GDAPI godot_array_empty(const godot_array *p_self) {
const Array *self = (const Array *)p_self;
return self->empty();
}
void GDAPI godot_array_erase(godot_array *p_self, const godot_variant *p_value) {
Array *self = (Array *)p_self;
const Variant *val = (const Variant *)p_value;
self->erase(*val);
}
godot_variant GDAPI godot_array_front(const godot_array *p_self) {
const Array *self = (const Array *)p_self;
godot_variant v;
Variant *val = (Variant *)&v;
memnew_placement(val, Variant);
*val = self->front();
return v;
}
godot_variant GDAPI godot_array_back(const godot_array *p_self) {
const Array *self = (const Array *)p_self;
godot_variant v;
Variant *val = (Variant *)&v;
memnew_placement(val, Variant);
*val = self->back();
return v;
}
godot_int GDAPI godot_array_find(const godot_array *p_self, const godot_variant *p_what, const godot_int p_from) {
const Array *self = (const Array *)p_self;
const Variant *val = (const Variant *)p_what;
return self->find(*val, p_from);
}
godot_int GDAPI godot_array_find_last(const godot_array *p_self, const godot_variant *p_what) {
const Array *self = (const Array *)p_self;
const Variant *val = (const Variant *)p_what;
return self->find_last(*val);
}
godot_bool GDAPI godot_array_has(const godot_array *p_self, const godot_variant *p_value) {
const Array *self = (const Array *)p_self;
const Variant *val = (const Variant *)p_value;
return self->has(*val);
}
godot_int GDAPI godot_array_hash(const godot_array *p_self) {
const Array *self = (const Array *)p_self;
return self->hash();
}
void GDAPI godot_array_insert(godot_array *p_self, const godot_int p_pos, const godot_variant *p_value) {
Array *self = (Array *)p_self;
const Variant *val = (const Variant *)p_value;
self->insert(p_pos, *val);
}
void GDAPI godot_array_invert(godot_array *p_self) {
Array *self = (Array *)p_self;
self->invert();
}
godot_variant GDAPI godot_array_pop_back(godot_array *p_self) {
Array *self = (Array *)p_self;
godot_variant v;
Variant *val = (Variant *)&v;
memnew_placement(val, Variant);
*val = self->pop_back();
return v;
}
godot_variant GDAPI godot_array_pop_front(godot_array *p_self) {
Array *self = (Array *)p_self;
godot_variant v;
Variant *val = (Variant *)&v;
memnew_placement(val, Variant);
*val = self->pop_front();
return v;
}
void GDAPI godot_array_push_back(godot_array *p_self, const godot_variant *p_value) {
Array *self = (Array *)p_self;
const Variant *val = (const Variant *)p_value;
self->push_back(*val);
}
void GDAPI godot_array_push_front(godot_array *p_self, const godot_variant *p_value) {
Array *self = (Array *)p_self;
const Variant *val = (const Variant *)p_value;
self->push_front(*val);
}
void GDAPI godot_array_remove(godot_array *p_self, const godot_int p_idx) {
Array *self = (Array *)p_self;
self->remove(p_idx);
}
void GDAPI godot_array_resize(godot_array *p_self, const godot_int p_size) {
Array *self = (Array *)p_self;
self->resize(p_size);
}
godot_int GDAPI godot_array_rfind(const godot_array *p_self, const godot_variant *p_what, const godot_int p_from) {
const Array *self = (const Array *)p_self;
const Variant *val = (const Variant *)p_what;
return self->rfind(*val, p_from);
}
godot_int GDAPI godot_array_size(const godot_array *p_self) {
const Array *self = (const Array *)p_self;
return self->size();
}
void GDAPI godot_array_sort(godot_array *p_self) {
Array *self = (Array *)p_self;
self->sort();
}
void GDAPI godot_array_sort_custom(godot_array *p_self, godot_object *p_obj, const godot_string *p_func) {
Array *self = (Array *)p_self;
const String *func = (const String *)p_func;
self->sort_custom((Object *)p_obj, *func);
}
godot_int GDAPI godot_array_bsearch(godot_array *p_self, const godot_variant *p_value, const godot_bool p_before) {
Array *self = (Array *)p_self;
return self->bsearch(*(const Variant *)p_value, p_before);
}
godot_int GDAPI godot_array_bsearch_custom(godot_array *p_self, const godot_variant *p_value, godot_object *p_obj, const godot_string *p_func, const godot_bool p_before) {
Array *self = (Array *)p_self;
const String *func = (const String *)p_func;
return self->bsearch_custom(*(const Variant *)p_value, (Object *)p_obj, *func, p_before);
}
void GDAPI godot_array_destroy(godot_array *p_self) {
((Array *)p_self)->~Array();
}
godot_array GDAPI godot_array_duplicate(const godot_array *p_self, const godot_bool p_deep) {
const Array *self = (const Array *)p_self;
godot_array res;
Array *val = (Array *)&res;
memnew_placement(val, Array);
*val = self->duplicate(p_deep);
return res;
}
godot_array GDAPI godot_array_slice(const godot_array *p_self, const godot_int p_begin, const godot_int p_end, const godot_int p_step, const godot_bool p_deep) {
const Array *self = (const Array *)p_self;
godot_array res;
Array *val = (Array *)&res;
memnew_placement(val, Array);
*val = self->slice(p_begin, p_end, p_step, p_deep);
return res;
}
godot_variant GDAPI godot_array_max(const godot_array *p_self) {
const Array *self = (const Array *)p_self;
godot_variant v;
Variant *val = (Variant *)&v;
memnew_placement(val, Variant);
*val = self->max();
return v;
}
godot_variant GDAPI godot_array_min(const godot_array *p_self) {
const Array *self = (const Array *)p_self;
godot_variant v;
Variant *val = (Variant *)&v;
memnew_placement(val, Variant);
*val = self->min();
return v;
}
void GDAPI godot_array_shuffle(godot_array *p_self) {
Array *self = (Array *)p_self;
self->shuffle();
}
#ifdef __cplusplus
}
#endif

298
gdnative/basis.cpp Normal file
View File

@ -0,0 +1,298 @@
/**************************************************************************/
/* basis.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "gdnative/basis.h"
#include "core/math/basis.h"
#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
#endif
static_assert(sizeof(godot_basis) == sizeof(Basis), "Basis size mismatch");
void GDAPI godot_basis_new_with_rows(godot_basis *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis) {
const Vector3 *x_axis = (const Vector3 *)p_x_axis;
const Vector3 *y_axis = (const Vector3 *)p_y_axis;
const Vector3 *z_axis = (const Vector3 *)p_z_axis;
Basis *dest = (Basis *)r_dest;
*dest = Basis(*x_axis, *y_axis, *z_axis);
}
void GDAPI godot_basis_new_with_axis_and_angle(godot_basis *r_dest, const godot_vector3 *p_axis, const godot_real p_phi) {
const Vector3 *axis = (const Vector3 *)p_axis;
Basis *dest = (Basis *)r_dest;
*dest = Basis(*axis, p_phi);
}
void GDAPI godot_basis_new_with_euler(godot_basis *r_dest, const godot_vector3 *p_euler) {
const Vector3 *euler = (const Vector3 *)p_euler;
Basis *dest = (Basis *)r_dest;
*dest = Basis(*euler);
}
godot_string GDAPI godot_basis_as_string(const godot_basis *p_self) {
godot_string ret;
const Basis *self = (const Basis *)p_self;
memnew_placement(&ret, String(*self));
return ret;
}
godot_basis GDAPI godot_basis_inverse(const godot_basis *p_self) {
godot_basis dest;
const Basis *self = (const Basis *)p_self;
*((Basis *)&dest) = self->inverse();
return dest;
}
godot_basis GDAPI godot_basis_transposed(const godot_basis *p_self) {
godot_basis dest;
const Basis *self = (const Basis *)p_self;
*((Basis *)&dest) = self->transposed();
return dest;
}
godot_basis GDAPI godot_basis_orthonormalized(const godot_basis *p_self) {
godot_basis dest;
const Basis *self = (const Basis *)p_self;
*((Basis *)&dest) = self->orthonormalized();
return dest;
}
godot_real GDAPI godot_basis_determinant(const godot_basis *p_self) {
const Basis *self = (const Basis *)p_self;
return self->determinant();
}
godot_basis GDAPI godot_basis_rotated(const godot_basis *p_self, const godot_vector3 *p_axis, const godot_real p_phi) {
godot_basis dest;
const Basis *self = (const Basis *)p_self;
const Vector3 *axis = (const Vector3 *)p_axis;
*((Basis *)&dest) = self->rotated(*axis, p_phi);
return dest;
}
godot_basis GDAPI godot_basis_scaled(const godot_basis *p_self, const godot_vector3 *p_scale) {
godot_basis dest;
const Basis *self = (const Basis *)p_self;
const Vector3 *scale = (const Vector3 *)p_scale;
*((Basis *)&dest) = self->scaled(*scale);
return dest;
}
godot_vector3 GDAPI godot_basis_get_scale(const godot_basis *p_self) {
godot_vector3 dest;
const Basis *self = (const Basis *)p_self;
*((Vector3 *)&dest) = self->get_scale();
return dest;
}
godot_quat GDAPI godot_basis_get_quat(const godot_basis *p_self) {
godot_quat dest;
const Basis *self = (const Basis *)p_self;
*((Quat *)&dest) = self->get_quat();
return dest;
}
void GDAPI godot_basis_set_quat(godot_basis *p_self, const godot_quat *p_quat) {
Basis *self = (Basis *)p_self;
const Quat *quat = (const Quat *)p_quat;
self->set_quat(*quat);
}
void GDAPI godot_basis_set_axis_angle_scale(godot_basis *p_self, const godot_vector3 *p_axis, godot_real p_phi, const godot_vector3 *p_scale) {
Basis *self = (Basis *)p_self;
const Vector3 *axis = (const Vector3 *)p_axis;
const Vector3 *scale = (const Vector3 *)p_scale;
self->set_axis_angle_scale(*axis, p_phi, *scale);
}
void GDAPI godot_basis_set_euler_scale(godot_basis *p_self, const godot_vector3 *p_euler, const godot_vector3 *p_scale) {
Basis *self = (Basis *)p_self;
const Vector3 *euler = (const Vector3 *)p_euler;
const Vector3 *scale = (const Vector3 *)p_scale;
self->set_euler_scale(*euler, *scale);
}
void GDAPI godot_basis_set_quat_scale(godot_basis *p_self, const godot_quat *p_quat, const godot_vector3 *p_scale) {
Basis *self = (Basis *)p_self;
const Quat *quat = (const Quat *)p_quat;
const Vector3 *scale = (const Vector3 *)p_scale;
self->set_quat_scale(*quat, *scale);
}
godot_vector3 GDAPI godot_basis_get_euler(const godot_basis *p_self) {
godot_vector3 dest;
const Basis *self = (const Basis *)p_self;
*((Vector3 *)&dest) = self->get_euler();
return dest;
}
godot_real GDAPI godot_basis_tdotx(const godot_basis *p_self, const godot_vector3 *p_with) {
const Basis *self = (const Basis *)p_self;
const Vector3 *with = (const Vector3 *)p_with;
return self->tdotx(*with);
}
godot_real GDAPI godot_basis_tdoty(const godot_basis *p_self, const godot_vector3 *p_with) {
const Basis *self = (const Basis *)p_self;
const Vector3 *with = (const Vector3 *)p_with;
return self->tdoty(*with);
}
godot_real GDAPI godot_basis_tdotz(const godot_basis *p_self, const godot_vector3 *p_with) {
const Basis *self = (const Basis *)p_self;
const Vector3 *with = (const Vector3 *)p_with;
return self->tdotz(*with);
}
godot_vector3 GDAPI godot_basis_xform(const godot_basis *p_self, const godot_vector3 *p_v) {
godot_vector3 dest;
const Basis *self = (const Basis *)p_self;
const Vector3 *v = (const Vector3 *)p_v;
*((Vector3 *)&dest) = self->xform(*v);
return dest;
}
godot_vector3 GDAPI godot_basis_xform_inv(const godot_basis *p_self, const godot_vector3 *p_v) {
godot_vector3 dest;
const Basis *self = (const Basis *)p_self;
const Vector3 *v = (const Vector3 *)p_v;
*((Vector3 *)&dest) = self->xform_inv(*v);
return dest;
}
godot_int GDAPI godot_basis_get_orthogonal_index(const godot_basis *p_self) {
const Basis *self = (const Basis *)p_self;
return self->get_orthogonal_index();
}
void GDAPI godot_basis_new(godot_basis *r_dest) {
Basis *dest = (Basis *)r_dest;
*dest = Basis();
}
void GDAPI godot_basis_new_with_euler_quat(godot_basis *r_dest, const godot_quat *p_euler) {
Basis *dest = (Basis *)r_dest;
const Quat *euler = (const Quat *)p_euler;
*dest = Basis(*euler);
}
// p_elements is a pointer to an array of 3 (!!) vector3
void GDAPI godot_basis_get_elements(const godot_basis *p_self, godot_vector3 *p_elements) {
const Basis *self = (const Basis *)p_self;
Vector3 *elements = (Vector3 *)p_elements;
elements[0] = self->elements[0];
elements[1] = self->elements[1];
elements[2] = self->elements[2];
}
godot_vector3 GDAPI godot_basis_get_axis(const godot_basis *p_self, const godot_int p_axis) {
godot_vector3 dest;
Vector3 *d = (Vector3 *)&dest;
const Basis *self = (const Basis *)p_self;
*d = self->get_axis(p_axis);
return dest;
}
void GDAPI godot_basis_set_axis(godot_basis *p_self, const godot_int p_axis, const godot_vector3 *p_value) {
Basis *self = (Basis *)p_self;
const Vector3 *value = (const Vector3 *)p_value;
self->set_axis(p_axis, *value);
}
godot_vector3 GDAPI godot_basis_get_row(const godot_basis *p_self, const godot_int p_row) {
godot_vector3 dest;
Vector3 *d = (Vector3 *)&dest;
const Basis *self = (const Basis *)p_self;
*d = self->get_row(p_row);
return dest;
}
void GDAPI godot_basis_set_row(godot_basis *p_self, const godot_int p_row, const godot_vector3 *p_value) {
Basis *self = (Basis *)p_self;
const Vector3 *value = (const Vector3 *)p_value;
self->set_row(p_row, *value);
}
godot_bool GDAPI godot_basis_operator_equal(const godot_basis *p_self, const godot_basis *p_b) {
const Basis *self = (const Basis *)p_self;
const Basis *b = (const Basis *)p_b;
return *self == *b;
}
godot_basis GDAPI godot_basis_operator_add(const godot_basis *p_self, const godot_basis *p_b) {
godot_basis raw_dest;
Basis *dest = (Basis *)&raw_dest;
const Basis *self = (const Basis *)p_self;
const Basis *b = (const Basis *)p_b;
*dest = *self + *b;
return raw_dest;
}
godot_basis GDAPI godot_basis_operator_subtract(const godot_basis *p_self, const godot_basis *p_b) {
godot_basis raw_dest;
Basis *dest = (Basis *)&raw_dest;
const Basis *self = (const Basis *)p_self;
const Basis *b = (const Basis *)p_b;
*dest = *self - *b;
return raw_dest;
}
godot_basis GDAPI godot_basis_operator_multiply_vector(const godot_basis *p_self, const godot_basis *p_b) {
godot_basis raw_dest;
Basis *dest = (Basis *)&raw_dest;
const Basis *self = (const Basis *)p_self;
const Basis *b = (const Basis *)p_b;
*dest = *self * *b;
return raw_dest;
}
godot_basis GDAPI godot_basis_operator_multiply_scalar(const godot_basis *p_self, const godot_real p_b) {
godot_basis raw_dest;
Basis *dest = (Basis *)&raw_dest;
const Basis *self = (const Basis *)p_self;
*dest = *self * p_b;
return raw_dest;
}
godot_basis GDAPI godot_basis_slerp(const godot_basis *p_self, const godot_basis *p_b, const godot_real p_t) {
godot_basis raw_dest;
Basis *dest = (Basis *)&raw_dest;
const Basis *self = (const Basis *)p_self;
const Basis *b = (const Basis *)p_b;
*dest = self->slerp(*b, p_t);
return raw_dest;
}
#ifdef __cplusplus
}
#endif

222
gdnative/color.cpp Normal file
View File

@ -0,0 +1,222 @@
/**************************************************************************/
/* color.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "gdnative/color.h"
#include "core/color.h"
#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
#endif
static_assert(sizeof(godot_color) == sizeof(Color), "Color size mismatch");
void GDAPI godot_color_new_rgba(godot_color *r_dest, const godot_real p_r, const godot_real p_g, const godot_real p_b, const godot_real p_a) {
Color *dest = (Color *)r_dest;
*dest = Color(p_r, p_g, p_b, p_a);
}
void GDAPI godot_color_new_rgb(godot_color *r_dest, const godot_real p_r, const godot_real p_g, const godot_real p_b) {
Color *dest = (Color *)r_dest;
*dest = Color(p_r, p_g, p_b);
}
godot_real godot_color_get_r(const godot_color *p_self) {
const Color *self = (const Color *)p_self;
return self->r;
}
void godot_color_set_r(godot_color *p_self, const godot_real val) {
Color *self = (Color *)p_self;
self->r = val;
}
godot_real godot_color_get_g(const godot_color *p_self) {
const Color *self = (const Color *)p_self;
return self->g;
}
void godot_color_set_g(godot_color *p_self, const godot_real val) {
Color *self = (Color *)p_self;
self->g = val;
}
godot_real godot_color_get_b(const godot_color *p_self) {
const Color *self = (const Color *)p_self;
return self->b;
}
void godot_color_set_b(godot_color *p_self, const godot_real val) {
Color *self = (Color *)p_self;
self->b = val;
}
godot_real godot_color_get_a(const godot_color *p_self) {
const Color *self = (const Color *)p_self;
return self->a;
}
void godot_color_set_a(godot_color *p_self, const godot_real val) {
Color *self = (Color *)p_self;
self->a = val;
}
godot_real godot_color_get_h(const godot_color *p_self) {
const Color *self = (const Color *)p_self;
return self->get_h();
}
godot_real godot_color_get_s(const godot_color *p_self) {
const Color *self = (const Color *)p_self;
return self->get_s();
}
godot_real godot_color_get_v(const godot_color *p_self) {
const Color *self = (const Color *)p_self;
return self->get_v();
}
godot_string GDAPI godot_color_as_string(const godot_color *p_self) {
godot_string ret;
const Color *self = (const Color *)p_self;
memnew_placement(&ret, String(*self));
return ret;
}
godot_int GDAPI godot_color_to_rgba32(const godot_color *p_self) {
const Color *self = (const Color *)p_self;
return self->to_rgba32();
}
godot_int GDAPI godot_color_to_abgr32(const godot_color *p_self) {
const Color *self = (const Color *)p_self;
return self->to_abgr32();
}
godot_int GDAPI godot_color_to_abgr64(const godot_color *p_self) {
const Color *self = (const Color *)p_self;
return self->to_abgr64();
}
godot_int GDAPI godot_color_to_argb64(const godot_color *p_self) {
const Color *self = (const Color *)p_self;
return self->to_argb64();
}
godot_int GDAPI godot_color_to_rgba64(const godot_color *p_self) {
const Color *self = (const Color *)p_self;
return self->to_rgba64();
}
godot_int GDAPI godot_color_to_argb32(const godot_color *p_self) {
const Color *self = (const Color *)p_self;
return self->to_argb32();
}
godot_real GDAPI godot_color_gray(const godot_color *p_self) {
const Color *self = (const Color *)p_self;
return self->gray();
}
godot_color GDAPI godot_color_inverted(const godot_color *p_self) {
godot_color dest;
const Color *self = (const Color *)p_self;
*((Color *)&dest) = self->inverted();
return dest;
}
godot_color GDAPI godot_color_contrasted(const godot_color *p_self) {
godot_color dest;
const Color *self = (const Color *)p_self;
*((Color *)&dest) = self->contrasted();
return dest;
}
godot_color GDAPI godot_color_linear_interpolate(const godot_color *p_self, const godot_color *p_b, const godot_real p_t) {
godot_color dest;
const Color *self = (const Color *)p_self;
const Color *b = (const Color *)p_b;
*((Color *)&dest) = self->linear_interpolate(*b, p_t);
return dest;
}
godot_color GDAPI godot_color_blend(const godot_color *p_self, const godot_color *p_over) {
godot_color dest;
const Color *self = (const Color *)p_self;
const Color *over = (const Color *)p_over;
*((Color *)&dest) = self->blend(*over);
return dest;
}
godot_color GDAPI godot_color_darkened(const godot_color *p_self, const godot_real p_amount) {
godot_color dest;
const Color *self = (const Color *)p_self;
*((Color *)&dest) = self->darkened(p_amount);
return dest;
}
godot_color GDAPI godot_color_from_hsv(const godot_color *p_self, const godot_real p_h, const godot_real p_s, const godot_real p_v, const godot_real p_a) {
godot_color dest;
const Color *self = (const Color *)p_self;
*((Color *)&dest) = self->from_hsv(p_h, p_s, p_v, p_a);
return dest;
}
godot_color GDAPI godot_color_lightened(const godot_color *p_self, const godot_real p_amount) {
godot_color dest;
const Color *self = (const Color *)p_self;
*((Color *)&dest) = self->lightened(p_amount);
return dest;
}
godot_string GDAPI godot_color_to_html(const godot_color *p_self, const godot_bool p_with_alpha) {
godot_string dest;
const Color *self = (const Color *)p_self;
memnew_placement(&dest, String(self->to_html(p_with_alpha)));
return dest;
}
godot_bool GDAPI godot_color_operator_equal(const godot_color *p_self, const godot_color *p_b) {
const Color *self = (const Color *)p_self;
const Color *b = (const Color *)p_b;
return *self == *b;
}
godot_bool GDAPI godot_color_operator_less(const godot_color *p_self, const godot_color *p_b) {
const Color *self = (const Color *)p_self;
const Color *b = (const Color *)p_b;
return *self < *b;
}
#ifdef __cplusplus
}
#endif

199
gdnative/dictionary.cpp Normal file
View File

@ -0,0 +1,199 @@
/**************************************************************************/
/* dictionary.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "gdnative/dictionary.h"
#include "core/variant.h"
// core/variant.h before to avoid compile errors with MSVC
#include "core/dictionary.h"
#include "core/io/json.h"
#ifdef __cplusplus
extern "C" {
#endif
static_assert(sizeof(godot_dictionary) == sizeof(Dictionary), "Dictionary size mismatch");
void GDAPI godot_dictionary_new(godot_dictionary *r_dest) {
Dictionary *dest = (Dictionary *)r_dest;
memnew_placement(dest, Dictionary);
}
void GDAPI godot_dictionary_new_copy(godot_dictionary *r_dest, const godot_dictionary *p_src) {
Dictionary *dest = (Dictionary *)r_dest;
const Dictionary *src = (const Dictionary *)p_src;
memnew_placement(dest, Dictionary(*src));
}
void GDAPI godot_dictionary_destroy(godot_dictionary *p_self) {
Dictionary *self = (Dictionary *)p_self;
self->~Dictionary();
}
godot_dictionary GDAPI godot_dictionary_duplicate(const godot_dictionary *p_self, const godot_bool p_deep) {
const Dictionary *self = (const Dictionary *)p_self;
godot_dictionary res;
Dictionary *val = (Dictionary *)&res;
memnew_placement(val, Dictionary);
*val = self->duplicate(p_deep);
return res;
}
godot_int GDAPI godot_dictionary_size(const godot_dictionary *p_self) {
const Dictionary *self = (const Dictionary *)p_self;
return self->size();
}
godot_bool GDAPI godot_dictionary_empty(const godot_dictionary *p_self) {
const Dictionary *self = (const Dictionary *)p_self;
return self->empty();
}
void GDAPI godot_dictionary_clear(godot_dictionary *p_self) {
Dictionary *self = (Dictionary *)p_self;
self->clear();
}
godot_bool GDAPI godot_dictionary_has(const godot_dictionary *p_self, const godot_variant *p_key) {
const Dictionary *self = (const Dictionary *)p_self;
const Variant *key = (const Variant *)p_key;
return self->has(*key);
}
godot_bool GDAPI godot_dictionary_has_all(const godot_dictionary *p_self, const godot_array *p_keys) {
const Dictionary *self = (const Dictionary *)p_self;
const Array *keys = (const Array *)p_keys;
return self->has_all(*keys);
}
void GDAPI godot_dictionary_erase(godot_dictionary *p_self, const godot_variant *p_key) {
Dictionary *self = (Dictionary *)p_self;
const Variant *key = (const Variant *)p_key;
self->erase(*key);
}
godot_int GDAPI godot_dictionary_hash(const godot_dictionary *p_self) {
const Dictionary *self = (const Dictionary *)p_self;
return self->hash();
}
godot_array GDAPI godot_dictionary_keys(const godot_dictionary *p_self) {
godot_array dest;
const Dictionary *self = (const Dictionary *)p_self;
memnew_placement(&dest, Array(self->keys()));
return dest;
}
godot_array GDAPI godot_dictionary_values(const godot_dictionary *p_self) {
godot_array dest;
const Dictionary *self = (const Dictionary *)p_self;
memnew_placement(&dest, Array(self->values()));
return dest;
}
godot_variant GDAPI godot_dictionary_get(const godot_dictionary *p_self, const godot_variant *p_key) {
godot_variant raw_dest;
Variant *dest = (Variant *)&raw_dest;
const Dictionary *self = (const Dictionary *)p_self;
const Variant *key = (const Variant *)p_key;
memnew_placement(dest, Variant(self->operator[](*key)));
return raw_dest;
}
void GDAPI godot_dictionary_set(godot_dictionary *p_self, const godot_variant *p_key, const godot_variant *p_value) {
Dictionary *self = (Dictionary *)p_self;
const Variant *key = (const Variant *)p_key;
const Variant *value = (const Variant *)p_value;
self->operator[](*key) = *value;
}
godot_variant GDAPI *godot_dictionary_operator_index(godot_dictionary *p_self, const godot_variant *p_key) {
Dictionary *self = (Dictionary *)p_self;
const Variant *key = (const Variant *)p_key;
return (godot_variant *)&self->operator[](*key);
}
const godot_variant GDAPI *godot_dictionary_operator_index_const(const godot_dictionary *p_self, const godot_variant *p_key) {
const Dictionary *self = (const Dictionary *)p_self;
const Variant *key = (const Variant *)p_key;
return (const godot_variant *)&self->operator[](*key);
}
godot_variant GDAPI *godot_dictionary_next(const godot_dictionary *p_self, const godot_variant *p_key) {
Dictionary *self = (Dictionary *)p_self;
const Variant *key = (const Variant *)p_key;
return (godot_variant *)self->next(key);
}
godot_bool GDAPI godot_dictionary_operator_equal(const godot_dictionary *p_self, const godot_dictionary *p_b) {
const Dictionary *self = (const Dictionary *)p_self;
const Dictionary *b = (const Dictionary *)p_b;
return *self == *b;
}
godot_string GDAPI godot_dictionary_to_json(const godot_dictionary *p_self) {
godot_string raw_dest;
String *dest = (String *)&raw_dest;
const Dictionary *self = (const Dictionary *)p_self;
memnew_placement(dest, String(JSON::print(Variant(*self))));
return raw_dest;
}
// GDNative core 1.1
godot_bool GDAPI godot_dictionary_erase_with_return(godot_dictionary *p_self, const godot_variant *p_key) {
Dictionary *self = (Dictionary *)p_self;
const Variant *key = (const Variant *)p_key;
return self->erase(*key);
}
godot_variant GDAPI godot_dictionary_get_with_default(const godot_dictionary *p_self, const godot_variant *p_key, const godot_variant *p_default) {
const Dictionary *self = (const Dictionary *)p_self;
const Variant *key = (const Variant *)p_key;
const Variant *def = (const Variant *)p_default;
godot_variant raw_dest;
Variant *dest = (Variant *)&raw_dest;
memnew_placement(dest, Variant(self->get(*key, *def)));
return raw_dest;
}
// GDNative core 1.3
void GDAPI godot_dictionary_merge(godot_dictionary *p_self, const godot_dictionary *p_dictionary, const godot_bool p_overwrite) {
Dictionary *self = (Dictionary *)p_self;
const Dictionary *dictionary = (const Dictionary *)p_dictionary;
self->merge(*dictionary, p_overwrite);
}
#ifdef __cplusplus
}
#endif

193
gdnative/gdnative.cpp Normal file
View File

@ -0,0 +1,193 @@
/**************************************************************************/
/* gdnative.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "gdnative/gdnative.h"
#include "core/class_db.h"
#include "core/engine.h"
#include "core/error_macros.h"
#include "core/global_constants.h"
#include "core/os/os.h"
#include "core/variant.h"
#include "modules/gdnative/gdnative.h"
#ifdef __cplusplus
extern "C" {
#endif
void GDAPI godot_object_destroy(godot_object *p_o) {
memdelete((Object *)p_o);
}
// Singleton API
godot_object GDAPI *godot_global_get_singleton(char *p_name) {
return (godot_object *)Engine::get_singleton()->get_singleton_object(String(p_name));
} // result shouldn't be freed
// MethodBind API
godot_method_bind GDAPI *godot_method_bind_get_method(const char *p_classname, const char *p_methodname) {
MethodBind *mb = ClassDB::get_method(StringName(p_classname), StringName(p_methodname));
// MethodBind *mb = ClassDB::get_method("Node", "get_name");
return (godot_method_bind *)mb;
}
void GDAPI godot_method_bind_ptrcall(godot_method_bind *p_method_bind, godot_object *p_instance, const void **p_args, void *p_ret) {
MethodBind *mb = (MethodBind *)p_method_bind;
Object *o = (Object *)p_instance;
mb->ptrcall(o, p_args, p_ret);
}
godot_variant GDAPI godot_method_bind_call(godot_method_bind *p_method_bind, godot_object *p_instance, const godot_variant **p_args, const int p_arg_count, godot_variant_call_error *p_call_error) {
MethodBind *mb = (MethodBind *)p_method_bind;
Object *o = (Object *)p_instance;
const Variant **args = (const Variant **)p_args;
godot_variant ret;
godot_variant_new_nil(&ret);
Variant *ret_val = (Variant *)&ret;
Variant::CallError r_error;
*ret_val = mb->call(o, args, p_arg_count, r_error);
if (p_call_error) {
p_call_error->error = (godot_variant_call_error_error)r_error.error;
p_call_error->argument = r_error.argument;
p_call_error->expected = (godot_variant_type)r_error.expected;
}
return ret;
}
godot_class_constructor GDAPI godot_get_class_constructor(const char *p_classname) {
ClassDB::ClassInfo *class_info = ClassDB::classes.getptr(StringName(p_classname));
if (class_info) {
return (godot_class_constructor)class_info->creation_func;
}
return nullptr;
}
godot_dictionary GDAPI godot_get_global_constants() {
godot_dictionary constants;
godot_dictionary_new(&constants);
Dictionary *p_constants = (Dictionary *)&constants;
const int constants_count = GlobalConstants::get_global_constant_count();
for (int i = 0; i < constants_count; ++i) {
const char *name = GlobalConstants::get_global_constant_name(i);
int value = GlobalConstants::get_global_constant_value(i);
(*p_constants)[name] = value;
}
return constants;
}
// System functions
void GDAPI godot_register_native_call_type(const char *p_call_type, native_call_cb p_callback) {
GDNativeCallRegistry::get_singleton()->register_native_call_type(StringName(p_call_type), p_callback);
}
void GDAPI *godot_alloc(int p_bytes) {
return memalloc(p_bytes);
}
void GDAPI *godot_realloc(void *p_ptr, int p_bytes) {
return memrealloc(p_ptr, p_bytes);
}
void GDAPI godot_free(void *p_ptr) {
memfree(p_ptr);
}
void GDAPI godot_print_error(const char *p_description, const char *p_function, const char *p_file, int p_line) {
_err_print_error(p_function, p_file, p_line, p_description, ERR_HANDLER_ERROR);
}
void GDAPI godot_print_warning(const char *p_description, const char *p_function, const char *p_file, int p_line) {
_err_print_error(p_function, p_file, p_line, p_description, ERR_HANDLER_WARNING);
}
void GDAPI godot_print(const godot_string *p_message) {
print_line(*(String *)p_message);
}
void _gdnative_report_version_mismatch(const godot_object *p_library, const char *p_ext, godot_gdnative_api_version p_want, godot_gdnative_api_version p_have) {
String message = "Error loading GDNative file ";
GDNativeLibrary *library = (GDNativeLibrary *)p_library;
message += library->get_current_library_path() + ": Extension \"" + p_ext + "\" can't be loaded.\n";
Dictionary versions;
versions["have_major"] = p_have.major;
versions["have_minor"] = p_have.minor;
versions["want_major"] = p_want.major;
versions["want_minor"] = p_want.minor;
message += String("Got version {have_major}.{have_minor} but needs {want_major}.{want_minor}!").format(versions);
_err_print_error("gdnative_init", library->get_current_library_path().utf8().ptr(), 0, message.utf8().ptr());
}
void _gdnative_report_loading_error(const godot_object *p_library, const char *p_what) {
String message = "Error loading GDNative file ";
GDNativeLibrary *library = (GDNativeLibrary *)p_library;
message += library->get_current_library_path() + ": " + p_what;
_err_print_error("gdnative_init", library->get_current_library_path().utf8().ptr(), 0, message.utf8().ptr());
}
bool GDAPI godot_is_instance_valid(const godot_object *p_object) {
return ObjectDB::instance_validate((Object *)p_object);
}
godot_object GDAPI *godot_instance_from_id(godot_int p_instance_id) {
return (godot_object *)ObjectDB::get_instance((ObjectID)p_instance_id);
}
void *godot_get_class_tag(const godot_string_name *p_class) {
StringName class_name = *(StringName *)p_class;
ClassDB::ClassInfo *class_info = ClassDB::classes.getptr(class_name);
return class_info ? class_info->class_ptr : nullptr;
}
godot_object *godot_object_cast_to(const godot_object *p_object, void *p_class_tag) {
if (!p_object) {
return nullptr;
}
Object *o = (Object *)p_object;
return o->is_class_ptr(p_class_tag) ? (godot_object *)o : nullptr;
}
#ifdef __cplusplus
}
#endif

126
gdnative/node_path.cpp Normal file
View File

@ -0,0 +1,126 @@
/**************************************************************************/
/* node_path.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "gdnative/node_path.h"
#include "core/node_path.h"
#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
#endif
static_assert(sizeof(godot_node_path) == sizeof(NodePath), "NodePath size mismatch");
void GDAPI godot_node_path_new(godot_node_path *r_dest, const godot_string *p_from) {
NodePath *dest = (NodePath *)r_dest;
const String *from = (const String *)p_from;
memnew_placement(dest, NodePath(*from));
}
void GDAPI godot_node_path_new_copy(godot_node_path *r_dest, const godot_node_path *p_src) {
NodePath *dest = (NodePath *)r_dest;
const NodePath *src = (const NodePath *)p_src;
memnew_placement(dest, NodePath(*src));
}
void GDAPI godot_node_path_destroy(godot_node_path *p_self) {
NodePath *self = (NodePath *)p_self;
self->~NodePath();
}
godot_string GDAPI godot_node_path_as_string(const godot_node_path *p_self) {
godot_string ret;
const NodePath *self = (const NodePath *)p_self;
memnew_placement(&ret, String(*self));
return ret;
}
godot_bool GDAPI godot_node_path_is_absolute(const godot_node_path *p_self) {
const NodePath *self = (const NodePath *)p_self;
return self->is_absolute();
}
godot_int GDAPI godot_node_path_get_name_count(const godot_node_path *p_self) {
const NodePath *self = (const NodePath *)p_self;
return self->get_name_count();
}
godot_string GDAPI godot_node_path_get_name(const godot_node_path *p_self, const godot_int p_idx) {
godot_string dest;
const NodePath *self = (const NodePath *)p_self;
memnew_placement(&dest, String(self->get_name(p_idx)));
return dest;
}
godot_int GDAPI godot_node_path_get_subname_count(const godot_node_path *p_self) {
const NodePath *self = (const NodePath *)p_self;
return self->get_subname_count();
}
godot_string GDAPI godot_node_path_get_subname(const godot_node_path *p_self, const godot_int p_idx) {
godot_string dest;
const NodePath *self = (const NodePath *)p_self;
memnew_placement(&dest, String(self->get_subname(p_idx)));
return dest;
}
godot_string GDAPI godot_node_path_get_concatenated_subnames(const godot_node_path *p_self) {
godot_string dest;
const NodePath *self = (const NodePath *)p_self;
memnew_placement(&dest, String(self->get_concatenated_subnames()));
return dest;
}
godot_bool GDAPI godot_node_path_is_empty(const godot_node_path *p_self) {
const NodePath *self = (const NodePath *)p_self;
return self->is_empty();
}
godot_bool GDAPI godot_node_path_operator_equal(const godot_node_path *p_self, const godot_node_path *p_b) {
const NodePath *self = (const NodePath *)p_self;
const NodePath *b = (const NodePath *)p_b;
return *self == *b;
}
godot_node_path godot_node_path_get_as_property_path(const godot_node_path *p_self) {
const NodePath *self = (const NodePath *)p_self;
godot_node_path res;
NodePath *val = (NodePath *)&res;
memnew_placement(val, NodePath);
*val = self->get_as_property_path();
return res;
}
#ifdef __cplusplus
}
#endif

178
gdnative/plane.cpp Normal file
View File

@ -0,0 +1,178 @@
/**************************************************************************/
/* plane.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "gdnative/plane.h"
#include "core/math/plane.h"
#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
#endif
static_assert(sizeof(godot_plane) == sizeof(Plane), "Plane size mismatch");
void GDAPI godot_plane_new_with_reals(godot_plane *r_dest, const godot_real p_a, const godot_real p_b, const godot_real p_c, const godot_real p_d) {
Plane *dest = (Plane *)r_dest;
*dest = Plane(p_a, p_b, p_c, p_d);
}
void GDAPI godot_plane_new_with_vectors(godot_plane *r_dest, const godot_vector3 *p_v1, const godot_vector3 *p_v2, const godot_vector3 *p_v3) {
const Vector3 *v1 = (const Vector3 *)p_v1;
const Vector3 *v2 = (const Vector3 *)p_v2;
const Vector3 *v3 = (const Vector3 *)p_v3;
Plane *dest = (Plane *)r_dest;
*dest = Plane(*v1, *v2, *v3);
}
void GDAPI godot_plane_new_with_normal(godot_plane *r_dest, const godot_vector3 *p_normal, const godot_real p_d) {
const Vector3 *normal = (const Vector3 *)p_normal;
Plane *dest = (Plane *)r_dest;
*dest = Plane(*normal, p_d);
}
godot_string GDAPI godot_plane_as_string(const godot_plane *p_self) {
godot_string ret;
const Plane *self = (const Plane *)p_self;
memnew_placement(&ret, String(*self));
return ret;
}
godot_plane GDAPI godot_plane_normalized(const godot_plane *p_self) {
godot_plane dest;
const Plane *self = (const Plane *)p_self;
*((Plane *)&dest) = self->normalized();
return dest;
}
godot_vector3 GDAPI godot_plane_center(const godot_plane *p_self) {
godot_vector3 dest;
const Plane *self = (const Plane *)p_self;
*((Vector3 *)&dest) = self->center();
return dest;
}
godot_vector3 GDAPI godot_plane_get_any_point(const godot_plane *p_self) {
godot_vector3 dest;
const Plane *self = (const Plane *)p_self;
*((Vector3 *)&dest) = self->get_any_point();
return dest;
}
godot_bool GDAPI godot_plane_is_point_over(const godot_plane *p_self, const godot_vector3 *p_point) {
const Plane *self = (const Plane *)p_self;
const Vector3 *point = (const Vector3 *)p_point;
return self->is_point_over(*point);
}
godot_real GDAPI godot_plane_distance_to(const godot_plane *p_self, const godot_vector3 *p_point) {
const Plane *self = (const Plane *)p_self;
const Vector3 *point = (const Vector3 *)p_point;
return self->distance_to(*point);
}
godot_bool GDAPI godot_plane_has_point(const godot_plane *p_self, const godot_vector3 *p_point, const godot_real p_epsilon) {
const Plane *self = (const Plane *)p_self;
const Vector3 *point = (const Vector3 *)p_point;
return self->has_point(*point, p_epsilon);
}
godot_vector3 GDAPI godot_plane_project(const godot_plane *p_self, const godot_vector3 *p_point) {
godot_vector3 dest;
const Plane *self = (const Plane *)p_self;
const Vector3 *point = (const Vector3 *)p_point;
*((Vector3 *)&dest) = self->project(*point);
return dest;
}
godot_bool GDAPI godot_plane_intersect_3(const godot_plane *p_self, godot_vector3 *r_dest, const godot_plane *p_b, const godot_plane *p_c) {
const Plane *self = (const Plane *)p_self;
const Plane *b = (const Plane *)p_b;
const Plane *c = (const Plane *)p_c;
Vector3 *dest = (Vector3 *)r_dest;
return self->intersect_3(*b, *c, dest);
}
godot_bool GDAPI godot_plane_intersects_ray(const godot_plane *p_self, godot_vector3 *r_dest, const godot_vector3 *p_from, const godot_vector3 *p_dir) {
const Plane *self = (const Plane *)p_self;
const Vector3 *from = (const Vector3 *)p_from;
const Vector3 *dir = (const Vector3 *)p_dir;
Vector3 *dest = (Vector3 *)r_dest;
return self->intersects_ray(*from, *dir, dest);
}
godot_bool GDAPI godot_plane_intersects_segment(const godot_plane *p_self, godot_vector3 *r_dest, const godot_vector3 *p_begin, const godot_vector3 *p_end) {
const Plane *self = (const Plane *)p_self;
const Vector3 *begin = (const Vector3 *)p_begin;
const Vector3 *end = (const Vector3 *)p_end;
Vector3 *dest = (Vector3 *)r_dest;
return self->intersects_segment(*begin, *end, dest);
}
godot_plane GDAPI godot_plane_operator_neg(const godot_plane *p_self) {
godot_plane raw_dest;
Plane *dest = (Plane *)&raw_dest;
const Plane *self = (const Plane *)p_self;
*dest = -(*self);
return raw_dest;
}
godot_bool GDAPI godot_plane_operator_equal(const godot_plane *p_self, const godot_plane *p_b) {
const Plane *self = (const Plane *)p_self;
const Plane *b = (const Plane *)p_b;
return *self == *b;
}
void GDAPI godot_plane_set_normal(godot_plane *p_self, const godot_vector3 *p_normal) {
Plane *self = (Plane *)p_self;
const Vector3 *normal = (const Vector3 *)p_normal;
self->set_normal(*normal);
}
godot_vector3 GDAPI godot_plane_get_normal(const godot_plane *p_self) {
const Plane *self = (const Plane *)p_self;
const Vector3 normal = self->get_normal();
godot_vector3 *v3 = (godot_vector3 *)&normal;
return *v3;
}
godot_real GDAPI godot_plane_get_d(const godot_plane *p_self) {
const Plane *self = (const Plane *)p_self;
return self->d;
}
void GDAPI godot_plane_set_d(godot_plane *p_self, const godot_real p_d) {
Plane *self = (Plane *)p_self;
self->d = p_d;
}
#ifdef __cplusplus
}
#endif

1075
gdnative/pool_arrays.cpp Normal file

File diff suppressed because it is too large Load Diff

237
gdnative/quat.cpp Normal file
View File

@ -0,0 +1,237 @@
/**************************************************************************/
/* quat.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "gdnative/quat.h"
#include "core/math/quat.h"
#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
#endif
static_assert(sizeof(godot_quat) == sizeof(Quat), "Quat size mismatch");
void GDAPI godot_quat_new(godot_quat *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z, const godot_real p_w) {
Quat *dest = (Quat *)r_dest;
*dest = Quat(p_x, p_y, p_z, p_w);
}
void GDAPI godot_quat_new_with_axis_angle(godot_quat *r_dest, const godot_vector3 *p_axis, const godot_real p_angle) {
const Vector3 *axis = (const Vector3 *)p_axis;
Quat *dest = (Quat *)r_dest;
*dest = Quat(*axis, p_angle);
}
void GDAPI godot_quat_new_with_basis(godot_quat *r_dest, const godot_basis *p_basis) {
const Basis *basis = (const Basis *)p_basis;
Quat *dest = (Quat *)r_dest;
*dest = Quat(*basis);
}
void GDAPI godot_quat_new_with_euler(godot_quat *r_dest, const godot_vector3 *p_euler) {
const Vector3 *euler = (const Vector3 *)p_euler;
Quat *dest = (Quat *)r_dest;
*dest = Quat(*euler);
}
godot_real GDAPI godot_quat_get_x(const godot_quat *p_self) {
const Quat *self = (const Quat *)p_self;
return self->x;
}
void GDAPI godot_quat_set_x(godot_quat *p_self, const godot_real val) {
Quat *self = (Quat *)p_self;
self->x = val;
}
godot_real GDAPI godot_quat_get_y(const godot_quat *p_self) {
const Quat *self = (const Quat *)p_self;
return self->y;
}
void GDAPI godot_quat_set_y(godot_quat *p_self, const godot_real val) {
Quat *self = (Quat *)p_self;
self->y = val;
}
godot_real GDAPI godot_quat_get_z(const godot_quat *p_self) {
const Quat *self = (const Quat *)p_self;
return self->z;
}
void GDAPI godot_quat_set_z(godot_quat *p_self, const godot_real val) {
Quat *self = (Quat *)p_self;
self->z = val;
}
godot_real GDAPI godot_quat_get_w(const godot_quat *p_self) {
const Quat *self = (const Quat *)p_self;
return self->w;
}
void GDAPI godot_quat_set_w(godot_quat *p_self, const godot_real val) {
Quat *self = (Quat *)p_self;
self->w = val;
}
godot_string GDAPI godot_quat_as_string(const godot_quat *p_self) {
godot_string ret;
const Quat *self = (const Quat *)p_self;
memnew_placement(&ret, String(*self));
return ret;
}
godot_real GDAPI godot_quat_length(const godot_quat *p_self) {
const Quat *self = (const Quat *)p_self;
return self->length();
}
godot_real GDAPI godot_quat_length_squared(const godot_quat *p_self) {
const Quat *self = (const Quat *)p_self;
return self->length_squared();
}
godot_quat GDAPI godot_quat_normalized(const godot_quat *p_self) {
godot_quat dest;
const Quat *self = (const Quat *)p_self;
*((Quat *)&dest) = self->normalized();
return dest;
}
godot_bool GDAPI godot_quat_is_normalized(const godot_quat *p_self) {
const Quat *self = (const Quat *)p_self;
return self->is_normalized();
}
godot_quat GDAPI godot_quat_inverse(const godot_quat *p_self) {
godot_quat dest;
const Quat *self = (const Quat *)p_self;
*((Quat *)&dest) = self->inverse();
return dest;
}
godot_real GDAPI godot_quat_dot(const godot_quat *p_self, const godot_quat *p_b) {
const Quat *self = (const Quat *)p_self;
const Quat *b = (const Quat *)p_b;
return self->dot(*b);
}
godot_vector3 GDAPI godot_quat_xform(const godot_quat *p_self, const godot_vector3 *p_v) {
godot_vector3 dest;
const Quat *self = (const Quat *)p_self;
const Vector3 *v = (const Vector3 *)p_v;
*((Vector3 *)&dest) = self->xform(*v);
return dest;
}
godot_quat GDAPI godot_quat_slerp(const godot_quat *p_self, const godot_quat *p_b, const godot_real p_t) {
godot_quat dest;
const Quat *self = (const Quat *)p_self;
const Quat *b = (const Quat *)p_b;
*((Quat *)&dest) = self->slerp(*b, p_t);
return dest;
}
godot_quat GDAPI godot_quat_slerpni(const godot_quat *p_self, const godot_quat *p_b, const godot_real p_t) {
godot_quat dest;
const Quat *self = (const Quat *)p_self;
const Quat *b = (const Quat *)p_b;
*((Quat *)&dest) = self->slerpni(*b, p_t);
return dest;
}
godot_quat GDAPI godot_quat_cubic_slerp(const godot_quat *p_self, const godot_quat *p_b, const godot_quat *p_pre_a, const godot_quat *p_post_b, const godot_real p_t) {
godot_quat dest;
const Quat *self = (const Quat *)p_self;
const Quat *b = (const Quat *)p_b;
const Quat *pre_a = (const Quat *)p_pre_a;
const Quat *post_b = (const Quat *)p_post_b;
*((Quat *)&dest) = self->cubic_slerp(*b, *pre_a, *post_b, p_t);
return dest;
}
godot_quat GDAPI godot_quat_operator_multiply(const godot_quat *p_self, const godot_real p_b) {
godot_quat raw_dest;
Quat *dest = (Quat *)&raw_dest;
const Quat *self = (const Quat *)p_self;
*dest = *self * p_b;
return raw_dest;
}
godot_quat GDAPI godot_quat_operator_add(const godot_quat *p_self, const godot_quat *p_b) {
godot_quat raw_dest;
Quat *dest = (Quat *)&raw_dest;
const Quat *self = (const Quat *)p_self;
const Quat *b = (const Quat *)p_b;
*dest = *self + *b;
return raw_dest;
}
godot_quat GDAPI godot_quat_operator_subtract(const godot_quat *p_self, const godot_quat *p_b) {
godot_quat raw_dest;
Quat *dest = (Quat *)&raw_dest;
const Quat *self = (const Quat *)p_self;
const Quat *b = (const Quat *)p_b;
*dest = *self - *b;
return raw_dest;
}
godot_quat GDAPI godot_quat_operator_divide(const godot_quat *p_self, const godot_real p_b) {
godot_quat raw_dest;
Quat *dest = (Quat *)&raw_dest;
const Quat *self = (const Quat *)p_self;
*dest = *self / p_b;
return raw_dest;
}
godot_bool GDAPI godot_quat_operator_equal(const godot_quat *p_self, const godot_quat *p_b) {
const Quat *self = (const Quat *)p_self;
const Quat *b = (const Quat *)p_b;
return *self == *b;
}
godot_quat GDAPI godot_quat_operator_neg(const godot_quat *p_self) {
godot_quat raw_dest;
Quat *dest = (Quat *)&raw_dest;
const Quat *self = (const Quat *)p_self;
*dest = -(*self);
return raw_dest;
}
void GDAPI godot_quat_set_axis_angle(godot_quat *p_self, const godot_vector3 *p_axis, const godot_real p_angle) {
Quat *self = (Quat *)p_self;
const Vector3 *axis = (const Vector3 *)p_axis;
self->set_axis_angle(*axis, p_angle);
}
#ifdef __cplusplus
}
#endif

178
gdnative/rect2.cpp Normal file
View File

@ -0,0 +1,178 @@
/**************************************************************************/
/* rect2.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "gdnative/rect2.h"
#include "core/math/transform_2d.h"
#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
#endif
static_assert(sizeof(godot_rect2) == sizeof(Rect2), "Rect2 size mismatch");
void GDAPI godot_rect2_new_with_position_and_size(godot_rect2 *r_dest, const godot_vector2 *p_pos, const godot_vector2 *p_size) {
const Vector2 *position = (const Vector2 *)p_pos;
const Vector2 *size = (const Vector2 *)p_size;
Rect2 *dest = (Rect2 *)r_dest;
*dest = Rect2(*position, *size);
}
void GDAPI godot_rect2_new(godot_rect2 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_width, const godot_real p_height) {
Rect2 *dest = (Rect2 *)r_dest;
*dest = Rect2(p_x, p_y, p_width, p_height);
}
godot_string GDAPI godot_rect2_as_string(const godot_rect2 *p_self) {
godot_string ret;
const Rect2 *self = (const Rect2 *)p_self;
memnew_placement(&ret, String(*self));
return ret;
}
godot_real GDAPI godot_rect2_get_area(const godot_rect2 *p_self) {
const Rect2 *self = (const Rect2 *)p_self;
return self->get_area();
}
godot_bool GDAPI godot_rect2_intersects(const godot_rect2 *p_self, const godot_rect2 *p_b) {
const Rect2 *self = (const Rect2 *)p_self;
const Rect2 *b = (const Rect2 *)p_b;
return self->intersects(*b);
}
godot_bool GDAPI godot_rect2_encloses(const godot_rect2 *p_self, const godot_rect2 *p_b) {
const Rect2 *self = (const Rect2 *)p_self;
const Rect2 *b = (const Rect2 *)p_b;
return self->encloses(*b);
}
godot_bool GDAPI godot_rect2_has_no_area(const godot_rect2 *p_self) {
const Rect2 *self = (const Rect2 *)p_self;
return self->has_no_area();
}
godot_rect2 GDAPI godot_rect2_clip(const godot_rect2 *p_self, const godot_rect2 *p_b) {
godot_rect2 dest;
const Rect2 *self = (const Rect2 *)p_self;
const Rect2 *b = (const Rect2 *)p_b;
*((Rect2 *)&dest) = self->clip(*b);
return dest;
}
godot_rect2 GDAPI godot_rect2_merge(const godot_rect2 *p_self, const godot_rect2 *p_b) {
godot_rect2 dest;
const Rect2 *self = (const Rect2 *)p_self;
const Rect2 *b = (const Rect2 *)p_b;
*((Rect2 *)&dest) = self->merge(*b);
return dest;
}
godot_bool GDAPI godot_rect2_has_point(const godot_rect2 *p_self, const godot_vector2 *p_point) {
const Rect2 *self = (const Rect2 *)p_self;
const Vector2 *point = (const Vector2 *)p_point;
return self->has_point(*point);
}
godot_rect2 GDAPI godot_rect2_grow(const godot_rect2 *p_self, const godot_real p_by) {
godot_rect2 dest;
const Rect2 *self = (const Rect2 *)p_self;
*((Rect2 *)&dest) = self->grow(p_by);
return dest;
}
godot_rect2 GDAPI godot_rect2_grow_individual(const godot_rect2 *p_self, const godot_real p_left, const godot_real p_top, const godot_real p_right, const godot_real p_bottom) {
godot_rect2 dest;
const Rect2 *self = (const Rect2 *)p_self;
*((Rect2 *)&dest) = self->grow_individual(p_left, p_top, p_right, p_bottom);
return dest;
}
godot_rect2 GDAPI godot_rect2_grow_margin(const godot_rect2 *p_self, const godot_int p_margin, const godot_real p_by) {
godot_rect2 dest;
const Rect2 *self = (const Rect2 *)p_self;
*((Rect2 *)&dest) = self->grow_margin((Margin)p_margin, p_by);
return dest;
}
godot_rect2 GDAPI godot_rect2_abs(const godot_rect2 *p_self) {
godot_rect2 dest;
const Rect2 *self = (const Rect2 *)p_self;
*((Rect2 *)&dest) = self->abs();
return dest;
}
godot_rect2 GDAPI godot_rect2_expand(const godot_rect2 *p_self, const godot_vector2 *p_to) {
godot_rect2 dest;
const Rect2 *self = (const Rect2 *)p_self;
const Vector2 *to = (const Vector2 *)p_to;
*((Rect2 *)&dest) = self->expand(*to);
return dest;
}
godot_bool GDAPI godot_rect2_operator_equal(const godot_rect2 *p_self, const godot_rect2 *p_b) {
const Rect2 *self = (const Rect2 *)p_self;
const Rect2 *b = (const Rect2 *)p_b;
return *self == *b;
}
godot_vector2 GDAPI godot_rect2_get_position(const godot_rect2 *p_self) {
godot_vector2 dest;
Vector2 *d = (Vector2 *)&dest;
const Rect2 *self = (const Rect2 *)p_self;
*d = self->get_position();
return dest;
}
godot_vector2 GDAPI godot_rect2_get_size(const godot_rect2 *p_self) {
godot_vector2 dest;
Vector2 *d = (Vector2 *)&dest;
const Rect2 *self = (const Rect2 *)p_self;
*d = self->get_size();
return dest;
}
void GDAPI godot_rect2_set_position(godot_rect2 *p_self, const godot_vector2 *p_pos) {
Rect2 *self = (Rect2 *)p_self;
const Vector2 *position = (const Vector2 *)p_pos;
self->set_position(*position);
}
void GDAPI godot_rect2_set_size(godot_rect2 *p_self, const godot_vector2 *p_size) {
Rect2 *self = (Rect2 *)p_self;
const Vector2 *size = (const Vector2 *)p_size;
self->set_size(*size);
}
#ifdef __cplusplus
}
#endif

76
gdnative/rid.cpp Normal file
View File

@ -0,0 +1,76 @@
/**************************************************************************/
/* rid.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "gdnative/rid.h"
#include "core/resource.h"
#include "core/rid.h"
#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
#endif
static_assert(sizeof(godot_rid) == sizeof(RID), "RID size mismatch");
void GDAPI godot_rid_new(godot_rid *r_dest) {
RID *dest = (RID *)r_dest;
memnew_placement(dest, RID);
}
godot_int GDAPI godot_rid_get_id(const godot_rid *p_self) {
const RID *self = (const RID *)p_self;
return self->get_id();
}
void GDAPI godot_rid_new_with_resource(godot_rid *r_dest, const godot_object *p_from) {
const Resource *res_from = Object::cast_to<Resource>((Object *)p_from);
godot_rid_new(r_dest);
if (res_from) {
RID *dest = (RID *)r_dest;
*dest = RID(res_from->get_rid());
}
}
godot_bool GDAPI godot_rid_operator_equal(const godot_rid *p_self, const godot_rid *p_b) {
const RID *self = (const RID *)p_self;
const RID *b = (const RID *)p_b;
return *self == *b;
}
godot_bool GDAPI godot_rid_operator_less(const godot_rid *p_self, const godot_rid *p_b) {
const RID *self = (const RID *)p_self;
const RID *b = (const RID *)p_b;
return *self < *b;
}
#ifdef __cplusplus
}
#endif

1397
gdnative/string.cpp Normal file

File diff suppressed because it is too large Load Diff

91
gdnative/string_name.cpp Normal file
View File

@ -0,0 +1,91 @@
/**************************************************************************/
/* string_name.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "gdnative/string_name.h"
#include "core/string_name.h"
#include "core/ustring.h"
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
static_assert(sizeof(godot_string_name) == sizeof(StringName), "StringName size mismatch");
void GDAPI godot_string_name_new(godot_string_name *r_dest, const godot_string *p_name) {
StringName *dest = (StringName *)r_dest;
const String *name = (const String *)p_name;
memnew_placement(dest, StringName(*name));
}
void GDAPI godot_string_name_new_data(godot_string_name *r_dest, const char *p_name) {
StringName *dest = (StringName *)r_dest;
memnew_placement(dest, StringName(p_name));
}
godot_string GDAPI godot_string_name_get_name(const godot_string_name *p_self) {
godot_string ret;
const StringName *self = (const StringName *)p_self;
memnew_placement(&ret, String(*self));
return ret;
}
uint32_t GDAPI godot_string_name_get_hash(const godot_string_name *p_self) {
const StringName *self = (const StringName *)p_self;
return self->hash();
}
const void GDAPI *godot_string_name_get_data_unique_pointer(const godot_string_name *p_self) {
const StringName *self = (const StringName *)p_self;
return self->data_unique_pointer();
}
godot_bool GDAPI godot_string_name_operator_equal(const godot_string_name *p_self, const godot_string_name *p_other) {
const StringName *self = (const StringName *)p_self;
const StringName *other = (const StringName *)p_other;
return *self == *other;
}
godot_bool GDAPI godot_string_name_operator_less(const godot_string_name *p_self, const godot_string_name *p_other) {
const StringName *self = (const StringName *)p_self;
const StringName *other = (const StringName *)p_other;
return *self < *other;
}
void GDAPI godot_string_name_destroy(godot_string_name *p_self) {
StringName *self = (StringName *)p_self;
self->~StringName();
}
#ifdef __cplusplus
}
#endif

230
gdnative/transform.cpp Normal file
View File

@ -0,0 +1,230 @@
/**************************************************************************/
/* transform.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "gdnative/transform.h"
#include "core/math/transform.h"
#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
#endif
static_assert(sizeof(godot_transform) == sizeof(Transform), "Transform size mismatch");
void GDAPI godot_transform_new_with_axis_origin(godot_transform *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis, const godot_vector3 *p_origin) {
const Vector3 *x_axis = (const Vector3 *)p_x_axis;
const Vector3 *y_axis = (const Vector3 *)p_y_axis;
const Vector3 *z_axis = (const Vector3 *)p_z_axis;
const Vector3 *origin = (const Vector3 *)p_origin;
Transform *dest = (Transform *)r_dest;
dest->basis.set_axis(0, *x_axis);
dest->basis.set_axis(1, *y_axis);
dest->basis.set_axis(2, *z_axis);
dest->origin = *origin;
}
void GDAPI godot_transform_new(godot_transform *r_dest, const godot_basis *p_basis, const godot_vector3 *p_origin) {
const Basis *basis = (const Basis *)p_basis;
const Vector3 *origin = (const Vector3 *)p_origin;
Transform *dest = (Transform *)r_dest;
*dest = Transform(*basis, *origin);
}
void GDAPI godot_transform_new_with_quat(godot_transform *r_dest, const godot_quat *p_quat) {
const Quat *quat = (const Quat *)p_quat;
Transform *dest = (Transform *)r_dest;
*dest = Transform(*quat);
}
godot_basis GDAPI godot_transform_get_basis(const godot_transform *p_self) {
godot_basis dest;
const Transform *self = (const Transform *)p_self;
*((Basis *)&dest) = self->basis;
return dest;
}
void GDAPI godot_transform_set_basis(godot_transform *p_self, const godot_basis *p_v) {
Transform *self = (Transform *)p_self;
const Basis *v = (const Basis *)p_v;
self->basis = *v;
}
godot_vector3 GDAPI godot_transform_get_origin(const godot_transform *p_self) {
godot_vector3 dest;
const Transform *self = (const Transform *)p_self;
*((Vector3 *)&dest) = self->origin;
return dest;
}
void GDAPI godot_transform_set_origin(godot_transform *p_self, const godot_vector3 *p_v) {
Transform *self = (Transform *)p_self;
const Vector3 *v = (const Vector3 *)p_v;
self->origin = *v;
}
godot_string GDAPI godot_transform_as_string(const godot_transform *p_self) {
godot_string ret;
const Transform *self = (const Transform *)p_self;
memnew_placement(&ret, String(*self));
return ret;
}
godot_transform GDAPI godot_transform_inverse(const godot_transform *p_self) {
godot_transform dest;
const Transform *self = (const Transform *)p_self;
*((Transform *)&dest) = self->inverse();
return dest;
}
godot_transform GDAPI godot_transform_affine_inverse(const godot_transform *p_self) {
godot_transform dest;
const Transform *self = (const Transform *)p_self;
*((Transform *)&dest) = self->affine_inverse();
return dest;
}
godot_transform GDAPI godot_transform_orthonormalized(const godot_transform *p_self) {
godot_transform dest;
const Transform *self = (const Transform *)p_self;
*((Transform *)&dest) = self->orthonormalized();
return dest;
}
godot_transform GDAPI godot_transform_rotated(const godot_transform *p_self, const godot_vector3 *p_axis, const godot_real p_phi) {
godot_transform dest;
const Transform *self = (const Transform *)p_self;
const Vector3 *axis = (const Vector3 *)p_axis;
*((Transform *)&dest) = self->rotated(*axis, p_phi);
return dest;
}
godot_transform GDAPI godot_transform_scaled(const godot_transform *p_self, const godot_vector3 *p_scale) {
godot_transform dest;
const Transform *self = (const Transform *)p_self;
const Vector3 *scale = (const Vector3 *)p_scale;
*((Transform *)&dest) = self->scaled(*scale);
return dest;
}
godot_transform GDAPI godot_transform_translated(const godot_transform *p_self, const godot_vector3 *p_ofs) {
godot_transform dest;
const Transform *self = (const Transform *)p_self;
const Vector3 *ofs = (const Vector3 *)p_ofs;
*((Transform *)&dest) = self->translated(*ofs);
return dest;
}
godot_transform GDAPI godot_transform_looking_at(const godot_transform *p_self, const godot_vector3 *p_target, const godot_vector3 *p_up) {
godot_transform dest;
const Transform *self = (const Transform *)p_self;
const Vector3 *target = (const Vector3 *)p_target;
const Vector3 *up = (const Vector3 *)p_up;
*((Transform *)&dest) = self->looking_at(*target, *up);
return dest;
}
godot_plane GDAPI godot_transform_xform_plane(const godot_transform *p_self, const godot_plane *p_v) {
godot_plane raw_dest;
Plane *dest = (Plane *)&raw_dest;
const Transform *self = (const Transform *)p_self;
const Plane *v = (const Plane *)p_v;
*dest = self->xform(*v);
return raw_dest;
}
godot_plane GDAPI godot_transform_xform_inv_plane(const godot_transform *p_self, const godot_plane *p_v) {
godot_plane raw_dest;
Plane *dest = (Plane *)&raw_dest;
const Transform *self = (const Transform *)p_self;
const Plane *v = (const Plane *)p_v;
*dest = self->xform_inv(*v);
return raw_dest;
}
void GDAPI godot_transform_new_identity(godot_transform *r_dest) {
Transform *dest = (Transform *)r_dest;
*dest = Transform();
}
godot_bool GDAPI godot_transform_operator_equal(const godot_transform *p_self, const godot_transform *p_b) {
const Transform *self = (const Transform *)p_self;
const Transform *b = (const Transform *)p_b;
return *self == *b;
}
godot_transform GDAPI godot_transform_operator_multiply(const godot_transform *p_self, const godot_transform *p_b) {
godot_transform raw_dest;
Transform *dest = (Transform *)&raw_dest;
const Transform *self = (const Transform *)p_self;
const Transform *b = (const Transform *)p_b;
*dest = *self * *b;
return raw_dest;
}
godot_vector3 GDAPI godot_transform_xform_vector3(const godot_transform *p_self, const godot_vector3 *p_v) {
godot_vector3 raw_dest;
Vector3 *dest = (Vector3 *)&raw_dest;
const Transform *self = (const Transform *)p_self;
const Vector3 *v = (const Vector3 *)p_v;
*dest = self->xform(*v);
return raw_dest;
}
godot_vector3 GDAPI godot_transform_xform_inv_vector3(const godot_transform *p_self, const godot_vector3 *p_v) {
godot_vector3 raw_dest;
Vector3 *dest = (Vector3 *)&raw_dest;
const Transform *self = (const Transform *)p_self;
const Vector3 *v = (const Vector3 *)p_v;
*dest = self->xform_inv(*v);
return raw_dest;
}
godot_aabb GDAPI godot_transform_xform_aabb(const godot_transform *p_self, const godot_aabb *p_v) {
godot_aabb raw_dest;
AABB *dest = (AABB *)&raw_dest;
const Transform *self = (const Transform *)p_self;
const AABB *v = (const AABB *)p_v;
*dest = self->xform(*v);
return raw_dest;
}
godot_aabb GDAPI godot_transform_xform_inv_aabb(const godot_transform *p_self, const godot_aabb *p_v) {
godot_aabb raw_dest;
AABB *dest = (AABB *)&raw_dest;
const Transform *self = (const Transform *)p_self;
const AABB *v = (const AABB *)p_v;
*dest = self->xform_inv(*v);
return raw_dest;
}
#ifdef __cplusplus
}
#endif

216
gdnative/transform2d.cpp Normal file
View File

@ -0,0 +1,216 @@
/**************************************************************************/
/* transform2d.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "gdnative/transform2d.h"
#include "core/math/transform_2d.h"
#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
#endif
static_assert(sizeof(godot_transform2d) == sizeof(Transform2D), "Transform2D size mismatch");
void GDAPI godot_transform2d_new(godot_transform2d *r_dest, const godot_real p_rot, const godot_vector2 *p_pos) {
const Vector2 *pos = (const Vector2 *)p_pos;
Transform2D *dest = (Transform2D *)r_dest;
*dest = Transform2D(p_rot, *pos);
}
void GDAPI godot_transform2d_new_axis_origin(godot_transform2d *r_dest, const godot_vector2 *p_x_axis, const godot_vector2 *p_y_axis, const godot_vector2 *p_origin) {
const Vector2 *x_axis = (const Vector2 *)p_x_axis;
const Vector2 *y_axis = (const Vector2 *)p_y_axis;
const Vector2 *origin = (const Vector2 *)p_origin;
Transform2D *dest = (Transform2D *)r_dest;
*dest = Transform2D(x_axis->x, x_axis->y, y_axis->x, y_axis->y, origin->x, origin->y);
}
godot_string GDAPI godot_transform2d_as_string(const godot_transform2d *p_self) {
godot_string ret;
const Transform2D *self = (const Transform2D *)p_self;
memnew_placement(&ret, String(*self));
return ret;
}
godot_transform2d GDAPI godot_transform2d_inverse(const godot_transform2d *p_self) {
godot_transform2d dest;
const Transform2D *self = (const Transform2D *)p_self;
*((Transform2D *)&dest) = self->inverse();
return dest;
}
godot_transform2d GDAPI godot_transform2d_affine_inverse(const godot_transform2d *p_self) {
godot_transform2d dest;
const Transform2D *self = (const Transform2D *)p_self;
*((Transform2D *)&dest) = self->affine_inverse();
return dest;
}
godot_real GDAPI godot_transform2d_get_rotation(const godot_transform2d *p_self) {
const Transform2D *self = (const Transform2D *)p_self;
return self->get_rotation();
}
godot_vector2 GDAPI godot_transform2d_get_origin(const godot_transform2d *p_self) {
godot_vector2 dest;
const Transform2D *self = (const Transform2D *)p_self;
*((Vector2 *)&dest) = self->get_origin();
return dest;
}
godot_vector2 GDAPI godot_transform2d_get_scale(const godot_transform2d *p_self) {
godot_vector2 dest;
const Transform2D *self = (const Transform2D *)p_self;
*((Vector2 *)&dest) = self->get_scale();
return dest;
}
godot_real GDAPI godot_transform2d_determinant(const godot_transform2d *p_self) {
const Transform2D *self = (const Transform2D *)p_self;
return self->determinant();
}
godot_transform2d GDAPI godot_transform2d_orthonormalized(const godot_transform2d *p_self) {
godot_transform2d dest;
const Transform2D *self = (const Transform2D *)p_self;
*((Transform2D *)&dest) = self->orthonormalized();
return dest;
}
godot_transform2d GDAPI godot_transform2d_rotated(const godot_transform2d *p_self, const godot_real p_phi) {
godot_transform2d dest;
const Transform2D *self = (const Transform2D *)p_self;
*((Transform2D *)&dest) = self->rotated(p_phi);
return dest;
}
godot_transform2d GDAPI godot_transform2d_scaled(const godot_transform2d *p_self, const godot_vector2 *p_scale) {
godot_transform2d dest;
const Transform2D *self = (const Transform2D *)p_self;
const Vector2 *scale = (const Vector2 *)p_scale;
*((Transform2D *)&dest) = self->scaled(*scale);
return dest;
}
godot_transform2d GDAPI godot_transform2d_translated(const godot_transform2d *p_self, const godot_vector2 *p_offset) {
godot_transform2d dest;
const Transform2D *self = (const Transform2D *)p_self;
const Vector2 *offset = (const Vector2 *)p_offset;
*((Transform2D *)&dest) = self->translated(*offset);
return dest;
}
godot_vector2 GDAPI godot_transform2d_xform_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v) {
godot_vector2 raw_dest;
Vector2 *dest = (Vector2 *)&raw_dest;
const Transform2D *self = (const Transform2D *)p_self;
const Vector2 *v = (const Vector2 *)p_v;
*dest = self->xform(*v);
return raw_dest;
}
godot_vector2 GDAPI godot_transform2d_xform_inv_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v) {
godot_vector2 raw_dest;
Vector2 *dest = (Vector2 *)&raw_dest;
const Transform2D *self = (const Transform2D *)p_self;
const Vector2 *v = (const Vector2 *)p_v;
*dest = self->xform_inv(*v);
return raw_dest;
}
godot_vector2 GDAPI godot_transform2d_basis_xform_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v) {
godot_vector2 raw_dest;
Vector2 *dest = (Vector2 *)&raw_dest;
const Transform2D *self = (const Transform2D *)p_self;
const Vector2 *v = (const Vector2 *)p_v;
*dest = self->basis_xform(*v);
return raw_dest;
}
godot_vector2 GDAPI godot_transform2d_basis_xform_inv_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v) {
godot_vector2 raw_dest;
Vector2 *dest = (Vector2 *)&raw_dest;
const Transform2D *self = (const Transform2D *)p_self;
const Vector2 *v = (const Vector2 *)p_v;
*dest = self->basis_xform_inv(*v);
return raw_dest;
}
godot_transform2d GDAPI godot_transform2d_interpolate_with(const godot_transform2d *p_self, const godot_transform2d *p_m, const godot_real p_c) {
godot_transform2d dest;
const Transform2D *self = (const Transform2D *)p_self;
const Transform2D *m = (const Transform2D *)p_m;
*((Transform2D *)&dest) = self->interpolate_with(*m, p_c);
return dest;
}
godot_bool GDAPI godot_transform2d_operator_equal(const godot_transform2d *p_self, const godot_transform2d *p_b) {
const Transform2D *self = (const Transform2D *)p_self;
const Transform2D *b = (const Transform2D *)p_b;
return *self == *b;
}
godot_transform2d GDAPI godot_transform2d_operator_multiply(const godot_transform2d *p_self, const godot_transform2d *p_b) {
godot_transform2d raw_dest;
Transform2D *dest = (Transform2D *)&raw_dest;
const Transform2D *self = (const Transform2D *)p_self;
const Transform2D *b = (const Transform2D *)p_b;
*dest = *self * *b;
return raw_dest;
}
void GDAPI godot_transform2d_new_identity(godot_transform2d *r_dest) {
Transform2D *dest = (Transform2D *)r_dest;
*dest = Transform2D();
}
godot_rect2 GDAPI godot_transform2d_xform_rect2(const godot_transform2d *p_self, const godot_rect2 *p_v) {
godot_rect2 raw_dest;
Rect2 *dest = (Rect2 *)&raw_dest;
const Transform2D *self = (const Transform2D *)p_self;
const Rect2 *v = (const Rect2 *)p_v;
*dest = self->xform(*v);
return raw_dest;
}
godot_rect2 GDAPI godot_transform2d_xform_inv_rect2(const godot_transform2d *p_self, const godot_rect2 *p_v) {
godot_rect2 raw_dest;
Rect2 *dest = (Rect2 *)&raw_dest;
const Transform2D *self = (const Transform2D *)p_self;
const Rect2 *v = (const Rect2 *)p_v;
*dest = self->xform_inv(*v);
return raw_dest;
}
#ifdef __cplusplus
}
#endif

528
gdnative/variant.cpp Normal file
View File

@ -0,0 +1,528 @@
/**************************************************************************/
/* variant.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "gdnative/variant.h"
#include "core/reference.h"
#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
#endif
static_assert(sizeof(godot_variant) == sizeof(Variant), "Variant size mismatch");
// Workaround GCC ICE on armv7hl which was affected GCC 6.0 up to 8.0 (GH-16100).
// It was fixed upstream in 8.1, and a fix was backported to 7.4.
// This can be removed once no supported distro ships with versions older than 7.4.
#if defined(__arm__) && defined(__GNUC__) && !defined(__clang__) && \
(__GNUC__ == 6 || (__GNUC__ == 7 && __GNUC_MINOR__ < 4) || (__GNUC__ == 8 && __GNUC_MINOR__ < 1))
#pragma GCC push_options
#pragma GCC optimize("-O0")
#endif
#define memnew_placement_custom(m_placement, m_class, m_constr) _post_initialize(new (m_placement, sizeof(m_class), "") m_constr)
#if defined(__arm__) && defined(__GNUC__) && !defined(__clang__) && \
(__GNUC__ == 6 || (__GNUC__ == 7 && __GNUC_MINOR__ < 4) || (__GNUC__ == 8 && __GNUC_MINOR__ < 1))
#pragma GCC pop_options
#endif
// Constructors
godot_variant_type GDAPI godot_variant_get_type(const godot_variant *p_self) {
const Variant *self = (const Variant *)p_self;
return (godot_variant_type)self->get_type();
}
void GDAPI godot_variant_new_copy(godot_variant *p_dest, const godot_variant *p_src) {
Variant *dest = (Variant *)p_dest;
Variant *src = (Variant *)p_src;
memnew_placement(dest, Variant(*src));
}
void GDAPI godot_variant_new_nil(godot_variant *r_dest) {
Variant *dest = (Variant *)r_dest;
memnew_placement(dest, Variant);
}
void GDAPI godot_variant_new_bool(godot_variant *r_dest, const godot_bool p_b) {
Variant *dest = (Variant *)r_dest;
memnew_placement_custom(dest, Variant, Variant(p_b));
}
void GDAPI godot_variant_new_uint(godot_variant *r_dest, const uint64_t p_i) {
Variant *dest = (Variant *)r_dest;
memnew_placement_custom(dest, Variant, Variant(p_i));
}
void GDAPI godot_variant_new_int(godot_variant *r_dest, const int64_t p_i) {
Variant *dest = (Variant *)r_dest;
memnew_placement_custom(dest, Variant, Variant(p_i));
}
void GDAPI godot_variant_new_real(godot_variant *r_dest, const double p_r) {
Variant *dest = (Variant *)r_dest;
memnew_placement_custom(dest, Variant, Variant(p_r));
}
void GDAPI godot_variant_new_string(godot_variant *r_dest, const godot_string *p_s) {
Variant *dest = (Variant *)r_dest;
String *s = (String *)p_s;
memnew_placement_custom(dest, Variant, Variant(*s));
}
void GDAPI godot_variant_new_vector2(godot_variant *r_dest, const godot_vector2 *p_v2) {
Variant *dest = (Variant *)r_dest;
Vector2 *v2 = (Vector2 *)p_v2;
memnew_placement_custom(dest, Variant, Variant(*v2));
}
void GDAPI godot_variant_new_rect2(godot_variant *r_dest, const godot_rect2 *p_rect2) {
Variant *dest = (Variant *)r_dest;
Rect2 *rect2 = (Rect2 *)p_rect2;
memnew_placement_custom(dest, Variant, Variant(*rect2));
}
void GDAPI godot_variant_new_vector3(godot_variant *r_dest, const godot_vector3 *p_v3) {
Variant *dest = (Variant *)r_dest;
Vector3 *v3 = (Vector3 *)p_v3;
memnew_placement_custom(dest, Variant, Variant(*v3));
}
void GDAPI godot_variant_new_transform2d(godot_variant *r_dest, const godot_transform2d *p_t2d) {
Variant *dest = (Variant *)r_dest;
Transform2D *t2d = (Transform2D *)p_t2d;
memnew_placement_custom(dest, Variant, Variant(*t2d));
}
void GDAPI godot_variant_new_plane(godot_variant *r_dest, const godot_plane *p_plane) {
Variant *dest = (Variant *)r_dest;
Plane *plane = (Plane *)p_plane;
memnew_placement_custom(dest, Variant, Variant(*plane));
}
void GDAPI godot_variant_new_quat(godot_variant *r_dest, const godot_quat *p_quat) {
Variant *dest = (Variant *)r_dest;
Quat *quat = (Quat *)p_quat;
memnew_placement_custom(dest, Variant, Variant(*quat));
}
void GDAPI godot_variant_new_aabb(godot_variant *r_dest, const godot_aabb *p_aabb) {
Variant *dest = (Variant *)r_dest;
AABB *aabb = (AABB *)p_aabb;
memnew_placement_custom(dest, Variant, Variant(*aabb));
}
void GDAPI godot_variant_new_basis(godot_variant *r_dest, const godot_basis *p_basis) {
Variant *dest = (Variant *)r_dest;
Basis *basis = (Basis *)p_basis;
memnew_placement_custom(dest, Variant, Variant(*basis));
}
void GDAPI godot_variant_new_transform(godot_variant *r_dest, const godot_transform *p_trans) {
Variant *dest = (Variant *)r_dest;
Transform *trans = (Transform *)p_trans;
memnew_placement_custom(dest, Variant, Variant(*trans));
}
void GDAPI godot_variant_new_color(godot_variant *r_dest, const godot_color *p_color) {
Variant *dest = (Variant *)r_dest;
Color *color = (Color *)p_color;
memnew_placement_custom(dest, Variant, Variant(*color));
}
void GDAPI godot_variant_new_node_path(godot_variant *r_dest, const godot_node_path *p_np) {
Variant *dest = (Variant *)r_dest;
NodePath *np = (NodePath *)p_np;
memnew_placement_custom(dest, Variant, Variant(*np));
}
void GDAPI godot_variant_new_rid(godot_variant *r_dest, const godot_rid *p_rid) {
Variant *dest = (Variant *)r_dest;
RID *rid = (RID *)p_rid;
memnew_placement_custom(dest, Variant, Variant(*rid));
}
void GDAPI godot_variant_new_object(godot_variant *r_dest, const godot_object *p_obj) {
Variant *dest = (Variant *)r_dest;
Object *obj = (Object *)p_obj;
Reference *reference = Object::cast_to<Reference>(obj);
REF ref;
if (reference) {
ref = REF(reference);
}
if (!ref.is_null()) {
memnew_placement_custom(dest, Variant, Variant(ref.get_ref_ptr()));
} else {
#if defined(DEBUG_METHODS_ENABLED)
if (reference) {
ERR_PRINT("Reference object has 0 refcount in godot_variant_new_object - you lost it somewhere.");
}
#endif
memnew_placement_custom(dest, Variant, Variant(obj));
}
}
void GDAPI godot_variant_new_dictionary(godot_variant *r_dest, const godot_dictionary *p_dict) {
Variant *dest = (Variant *)r_dest;
Dictionary *dict = (Dictionary *)p_dict;
memnew_placement_custom(dest, Variant, Variant(*dict));
}
void GDAPI godot_variant_new_array(godot_variant *r_dest, const godot_array *p_arr) {
Variant *dest = (Variant *)r_dest;
Array *arr = (Array *)p_arr;
memnew_placement_custom(dest, Variant, Variant(*arr));
}
void GDAPI godot_variant_new_pool_byte_array(godot_variant *r_dest, const godot_pool_byte_array *p_pba) {
Variant *dest = (Variant *)r_dest;
PoolByteArray *pba = (PoolByteArray *)p_pba;
memnew_placement_custom(dest, Variant, Variant(*pba));
}
void GDAPI godot_variant_new_pool_int_array(godot_variant *r_dest, const godot_pool_int_array *p_pia) {
Variant *dest = (Variant *)r_dest;
PoolIntArray *pia = (PoolIntArray *)p_pia;
memnew_placement_custom(dest, Variant, Variant(*pia));
}
void GDAPI godot_variant_new_pool_real_array(godot_variant *r_dest, const godot_pool_real_array *p_pra) {
Variant *dest = (Variant *)r_dest;
PoolRealArray *pra = (PoolRealArray *)p_pra;
memnew_placement_custom(dest, Variant, Variant(*pra));
}
void GDAPI godot_variant_new_pool_string_array(godot_variant *r_dest, const godot_pool_string_array *p_psa) {
Variant *dest = (Variant *)r_dest;
PoolStringArray *psa = (PoolStringArray *)p_psa;
memnew_placement_custom(dest, Variant, Variant(*psa));
}
void GDAPI godot_variant_new_pool_vector2_array(godot_variant *r_dest, const godot_pool_vector2_array *p_pv2a) {
Variant *dest = (Variant *)r_dest;
PoolVector2Array *pv2a = (PoolVector2Array *)p_pv2a;
memnew_placement_custom(dest, Variant, Variant(*pv2a));
}
void GDAPI godot_variant_new_pool_vector3_array(godot_variant *r_dest, const godot_pool_vector3_array *p_pv3a) {
Variant *dest = (Variant *)r_dest;
PoolVector3Array *pv3a = (PoolVector3Array *)p_pv3a;
memnew_placement_custom(dest, Variant, Variant(*pv3a));
}
void GDAPI godot_variant_new_pool_color_array(godot_variant *r_dest, const godot_pool_color_array *p_pca) {
Variant *dest = (Variant *)r_dest;
PoolColorArray *pca = (PoolColorArray *)p_pca;
memnew_placement_custom(dest, Variant, Variant(*pca));
}
godot_bool GDAPI godot_variant_as_bool(const godot_variant *p_self) {
const Variant *self = (const Variant *)p_self;
return self->operator bool();
}
uint64_t GDAPI godot_variant_as_uint(const godot_variant *p_self) {
const Variant *self = (const Variant *)p_self;
return self->operator uint64_t();
}
int64_t GDAPI godot_variant_as_int(const godot_variant *p_self) {
const Variant *self = (const Variant *)p_self;
return self->operator int64_t();
}
double GDAPI godot_variant_as_real(const godot_variant *p_self) {
const Variant *self = (const Variant *)p_self;
return self->operator double();
}
godot_string GDAPI godot_variant_as_string(const godot_variant *p_self) {
godot_string raw_dest;
const Variant *self = (const Variant *)p_self;
String *dest = (String *)&raw_dest;
memnew_placement(dest, String(self->operator String())); // operator = is overloaded by String
return raw_dest;
}
godot_vector2 GDAPI godot_variant_as_vector2(const godot_variant *p_self) {
godot_vector2 raw_dest;
const Variant *self = (const Variant *)p_self;
Vector2 *dest = (Vector2 *)&raw_dest;
*dest = *self;
return raw_dest;
}
godot_rect2 GDAPI godot_variant_as_rect2(const godot_variant *p_self) {
godot_rect2 raw_dest;
const Variant *self = (const Variant *)p_self;
Rect2 *dest = (Rect2 *)&raw_dest;
*dest = *self;
return raw_dest;
}
godot_vector3 GDAPI godot_variant_as_vector3(const godot_variant *p_self) {
godot_vector3 raw_dest;
const Variant *self = (const Variant *)p_self;
Vector3 *dest = (Vector3 *)&raw_dest;
*dest = *self;
return raw_dest;
}
godot_transform2d GDAPI godot_variant_as_transform2d(const godot_variant *p_self) {
godot_transform2d raw_dest;
const Variant *self = (const Variant *)p_self;
Transform2D *dest = (Transform2D *)&raw_dest;
*dest = *self;
return raw_dest;
}
godot_plane GDAPI godot_variant_as_plane(const godot_variant *p_self) {
godot_plane raw_dest;
const Variant *self = (const Variant *)p_self;
Plane *dest = (Plane *)&raw_dest;
*dest = *self;
return raw_dest;
}
godot_quat GDAPI godot_variant_as_quat(const godot_variant *p_self) {
godot_quat raw_dest;
const Variant *self = (const Variant *)p_self;
Quat *dest = (Quat *)&raw_dest;
*dest = *self;
return raw_dest;
}
godot_aabb GDAPI godot_variant_as_aabb(const godot_variant *p_self) {
godot_aabb raw_dest;
const Variant *self = (const Variant *)p_self;
AABB *dest = (AABB *)&raw_dest;
*dest = *self;
return raw_dest;
}
godot_basis GDAPI godot_variant_as_basis(const godot_variant *p_self) {
godot_basis raw_dest;
const Variant *self = (const Variant *)p_self;
Basis *dest = (Basis *)&raw_dest;
*dest = *self;
return raw_dest;
}
godot_transform GDAPI godot_variant_as_transform(const godot_variant *p_self) {
godot_transform raw_dest;
const Variant *self = (const Variant *)p_self;
Transform *dest = (Transform *)&raw_dest;
*dest = *self;
return raw_dest;
}
godot_color GDAPI godot_variant_as_color(const godot_variant *p_self) {
godot_color raw_dest;
const Variant *self = (const Variant *)p_self;
Color *dest = (Color *)&raw_dest;
*dest = *self;
return raw_dest;
}
godot_node_path GDAPI godot_variant_as_node_path(const godot_variant *p_self) {
godot_node_path raw_dest;
const Variant *self = (const Variant *)p_self;
NodePath *dest = (NodePath *)&raw_dest;
memnew_placement(dest, NodePath(self->operator NodePath())); // operator = is overloaded by NodePath
return raw_dest;
}
godot_rid GDAPI godot_variant_as_rid(const godot_variant *p_self) {
godot_rid raw_dest;
const Variant *self = (const Variant *)p_self;
RID *dest = (RID *)&raw_dest;
*dest = *self;
return raw_dest;
}
godot_object GDAPI *godot_variant_as_object(const godot_variant *p_self) {
const Variant *self = (const Variant *)p_self;
Object *dest;
dest = *self;
return (godot_object *)dest;
}
godot_dictionary GDAPI godot_variant_as_dictionary(const godot_variant *p_self) {
godot_dictionary raw_dest;
const Variant *self = (const Variant *)p_self;
Dictionary *dest = (Dictionary *)&raw_dest;
memnew_placement(dest, Dictionary(self->operator Dictionary())); // operator = is overloaded by Dictionary
return raw_dest;
}
godot_array GDAPI godot_variant_as_array(const godot_variant *p_self) {
godot_array raw_dest;
const Variant *self = (const Variant *)p_self;
Array *dest = (Array *)&raw_dest;
memnew_placement(dest, Array(self->operator Array())); // operator = is overloaded by Array
return raw_dest;
}
godot_pool_byte_array GDAPI godot_variant_as_pool_byte_array(const godot_variant *p_self) {
godot_pool_byte_array raw_dest;
const Variant *self = (const Variant *)p_self;
PoolByteArray *dest = (PoolByteArray *)&raw_dest;
memnew_placement(dest, PoolByteArray(self->operator PoolByteArray())); // operator = is overloaded by PoolByteArray
*dest = *self;
return raw_dest;
}
godot_pool_int_array GDAPI godot_variant_as_pool_int_array(const godot_variant *p_self) {
godot_pool_int_array raw_dest;
const Variant *self = (const Variant *)p_self;
PoolIntArray *dest = (PoolIntArray *)&raw_dest;
memnew_placement(dest, PoolIntArray(self->operator PoolIntArray())); // operator = is overloaded by PoolIntArray
*dest = *self;
return raw_dest;
}
godot_pool_real_array GDAPI godot_variant_as_pool_real_array(const godot_variant *p_self) {
godot_pool_real_array raw_dest;
const Variant *self = (const Variant *)p_self;
PoolRealArray *dest = (PoolRealArray *)&raw_dest;
memnew_placement(dest, PoolRealArray(self->operator PoolRealArray())); // operator = is overloaded by PoolRealArray
*dest = *self;
return raw_dest;
}
godot_pool_string_array GDAPI godot_variant_as_pool_string_array(const godot_variant *p_self) {
godot_pool_string_array raw_dest;
const Variant *self = (const Variant *)p_self;
PoolStringArray *dest = (PoolStringArray *)&raw_dest;
memnew_placement(dest, PoolStringArray(self->operator PoolStringArray())); // operator = is overloaded by PoolStringArray
*dest = *self;
return raw_dest;
}
godot_pool_vector2_array GDAPI godot_variant_as_pool_vector2_array(const godot_variant *p_self) {
godot_pool_vector2_array raw_dest;
const Variant *self = (const Variant *)p_self;
PoolVector2Array *dest = (PoolVector2Array *)&raw_dest;
memnew_placement(dest, PoolVector2Array(self->operator PoolVector2Array())); // operator = is overloaded by PoolVector2Array
*dest = *self;
return raw_dest;
}
godot_pool_vector3_array GDAPI godot_variant_as_pool_vector3_array(const godot_variant *p_self) {
godot_pool_vector3_array raw_dest;
const Variant *self = (const Variant *)p_self;
PoolVector3Array *dest = (PoolVector3Array *)&raw_dest;
memnew_placement(dest, PoolVector3Array(self->operator PoolVector3Array())); // operator = is overloaded by PoolVector3Array
*dest = *self;
return raw_dest;
}
godot_pool_color_array GDAPI godot_variant_as_pool_color_array(const godot_variant *p_self) {
godot_pool_color_array raw_dest;
const Variant *self = (const Variant *)p_self;
PoolColorArray *dest = (PoolColorArray *)&raw_dest;
memnew_placement(dest, PoolColorArray(self->operator PoolColorArray())); // operator = is overloaded by PoolColorArray
*dest = *self;
return raw_dest;
}
godot_variant GDAPI godot_variant_call(godot_variant *p_self, const godot_string *p_method, const godot_variant **p_args, const godot_int p_argcount, godot_variant_call_error *r_error) {
Variant *self = (Variant *)p_self;
String *method = (String *)p_method;
const Variant **args = (const Variant **)p_args;
godot_variant raw_dest;
Variant *dest = (Variant *)&raw_dest;
Variant::CallError error;
memnew_placement_custom(dest, Variant, Variant(self->call(*method, args, p_argcount, error)));
if (r_error) {
r_error->error = (godot_variant_call_error_error)error.error;
r_error->argument = error.argument;
r_error->expected = (godot_variant_type)error.expected;
}
return raw_dest;
}
godot_bool GDAPI godot_variant_has_method(const godot_variant *p_self, const godot_string *p_method) {
const Variant *self = (const Variant *)p_self;
const String *method = (const String *)p_method;
return self->has_method(*method);
}
godot_bool GDAPI godot_variant_operator_equal(const godot_variant *p_self, const godot_variant *p_other) {
const Variant *self = (const Variant *)p_self;
const Variant *other = (const Variant *)p_other;
return self->operator==(*other);
}
godot_bool GDAPI godot_variant_operator_less(const godot_variant *p_self, const godot_variant *p_other) {
const Variant *self = (const Variant *)p_self;
const Variant *other = (const Variant *)p_other;
return self->operator<(*other);
}
godot_bool GDAPI godot_variant_hash_compare(const godot_variant *p_self, const godot_variant *p_other) {
const Variant *self = (const Variant *)p_self;
const Variant *other = (const Variant *)p_other;
return self->hash_compare(*other);
}
godot_bool GDAPI godot_variant_booleanize(const godot_variant *p_self) {
const Variant *self = (const Variant *)p_self;
return self->booleanize();
}
void GDAPI godot_variant_destroy(godot_variant *p_self) {
Variant *self = (Variant *)p_self;
self->~Variant();
}
// GDNative core 1.1
godot_string GDAPI godot_variant_get_operator_name(godot_variant_operator p_op) {
Variant::Operator op = (Variant::Operator)p_op;
godot_string raw_dest;
String *dest = (String *)&raw_dest;
memnew_placement(dest, String(Variant::get_operator_name(op))); // operator = is overloaded by String
return raw_dest;
}
void GDAPI godot_variant_evaluate(godot_variant_operator p_op, const godot_variant *p_a, const godot_variant *p_b, godot_variant *r_ret, godot_bool *r_valid) {
Variant::Operator op = (Variant::Operator)p_op;
const Variant *a = (const Variant *)p_a;
const Variant *b = (const Variant *)p_b;
Variant *ret = (Variant *)r_ret;
Variant::evaluate(op, *a, *b, *ret, *r_valid);
}
#ifdef __cplusplus
}
#endif

313
gdnative/vector2.cpp Normal file
View File

@ -0,0 +1,313 @@
/**************************************************************************/
/* vector2.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "gdnative/vector2.h"
#include "core/math/vector2.h"
#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
#endif
static_assert(sizeof(godot_vector2) == sizeof(Vector2), "Vector2 size mismatch");
void GDAPI godot_vector2_new(godot_vector2 *r_dest, const godot_real p_x, const godot_real p_y) {
Vector2 *dest = (Vector2 *)r_dest;
*dest = Vector2(p_x, p_y);
}
godot_string GDAPI godot_vector2_as_string(const godot_vector2 *p_self) {
godot_string ret;
const Vector2 *self = (const Vector2 *)p_self;
memnew_placement(&ret, String(*self));
return ret;
}
godot_vector2 GDAPI godot_vector2_normalized(const godot_vector2 *p_self) {
godot_vector2 dest;
const Vector2 *self = (const Vector2 *)p_self;
*((Vector2 *)&dest) = self->normalized();
return dest;
}
godot_real GDAPI godot_vector2_length(const godot_vector2 *p_self) {
const Vector2 *self = (const Vector2 *)p_self;
return self->length();
}
godot_real GDAPI godot_vector2_angle(const godot_vector2 *p_self) {
const Vector2 *self = (const Vector2 *)p_self;
return self->angle();
}
godot_real GDAPI godot_vector2_length_squared(const godot_vector2 *p_self) {
const Vector2 *self = (const Vector2 *)p_self;
return self->length_squared();
}
godot_bool GDAPI godot_vector2_is_normalized(const godot_vector2 *p_self) {
const Vector2 *self = (const Vector2 *)p_self;
return self->is_normalized();
}
godot_vector2 GDAPI godot_vector2_direction_to(const godot_vector2 *p_self, const godot_vector2 *p_to) {
godot_vector2 dest;
const Vector2 *self = (const Vector2 *)p_self;
const Vector2 *to = (const Vector2 *)p_to;
*((Vector2 *)&dest) = self->direction_to(*to);
return dest;
}
godot_real GDAPI godot_vector2_distance_to(const godot_vector2 *p_self, const godot_vector2 *p_to) {
const Vector2 *self = (const Vector2 *)p_self;
const Vector2 *to = (const Vector2 *)p_to;
return self->distance_to(*to);
}
godot_real GDAPI godot_vector2_distance_squared_to(const godot_vector2 *p_self, const godot_vector2 *p_to) {
const Vector2 *self = (const Vector2 *)p_self;
const Vector2 *to = (const Vector2 *)p_to;
return self->distance_squared_to(*to);
}
godot_real GDAPI godot_vector2_angle_to(const godot_vector2 *p_self, const godot_vector2 *p_to) {
const Vector2 *self = (const Vector2 *)p_self;
const Vector2 *to = (const Vector2 *)p_to;
return self->angle_to(*to);
}
godot_real GDAPI godot_vector2_angle_to_point(const godot_vector2 *p_self, const godot_vector2 *p_to) {
const Vector2 *self = (const Vector2 *)p_self;
const Vector2 *to = (const Vector2 *)p_to;
return self->angle_to_point(*to);
}
godot_vector2 GDAPI godot_vector2_linear_interpolate(const godot_vector2 *p_self, const godot_vector2 *p_b, const godot_real p_t) {
godot_vector2 dest;
const Vector2 *self = (const Vector2 *)p_self;
const Vector2 *b = (const Vector2 *)p_b;
*((Vector2 *)&dest) = self->linear_interpolate(*b, p_t);
return dest;
}
godot_vector2 GDAPI godot_vector2_cubic_interpolate(const godot_vector2 *p_self, const godot_vector2 *p_b, const godot_vector2 *p_pre_a, const godot_vector2 *p_post_b, const godot_real p_t) {
godot_vector2 dest;
const Vector2 *self = (const Vector2 *)p_self;
const Vector2 *b = (const Vector2 *)p_b;
const Vector2 *pre_a = (const Vector2 *)p_pre_a;
const Vector2 *post_b = (const Vector2 *)p_post_b;
*((Vector2 *)&dest) = self->cubic_interpolate(*b, *pre_a, *post_b, p_t);
return dest;
}
godot_vector2 GDAPI godot_vector2_move_toward(const godot_vector2 *p_self, const godot_vector2 *p_to, const godot_real p_delta) {
godot_vector2 dest;
const Vector2 *self = (const Vector2 *)p_self;
const Vector2 *to = (const Vector2 *)p_to;
*((Vector2 *)&dest) = self->move_toward(*to, p_delta);
return dest;
}
godot_vector2 GDAPI godot_vector2_rotated(const godot_vector2 *p_self, const godot_real p_phi) {
godot_vector2 dest;
const Vector2 *self = (const Vector2 *)p_self;
*((Vector2 *)&dest) = self->rotated(p_phi);
return dest;
}
godot_vector2 GDAPI godot_vector2_tangent(const godot_vector2 *p_self) {
godot_vector2 dest;
const Vector2 *self = (const Vector2 *)p_self;
*((Vector2 *)&dest) = self->tangent();
return dest;
}
godot_vector2 GDAPI godot_vector2_floor(const godot_vector2 *p_self) {
godot_vector2 dest;
const Vector2 *self = (const Vector2 *)p_self;
*((Vector2 *)&dest) = self->floor();
return dest;
}
godot_vector2 GDAPI godot_vector2_snapped(const godot_vector2 *p_self, const godot_vector2 *p_by) {
godot_vector2 dest;
const Vector2 *self = (const Vector2 *)p_self;
const Vector2 *by = (const Vector2 *)p_by;
*((Vector2 *)&dest) = self->snapped(*by);
return dest;
}
godot_real GDAPI godot_vector2_aspect(const godot_vector2 *p_self) {
const Vector2 *self = (const Vector2 *)p_self;
return self->aspect();
}
godot_real GDAPI godot_vector2_dot(const godot_vector2 *p_self, const godot_vector2 *p_with) {
const Vector2 *self = (const Vector2 *)p_self;
const Vector2 *with = (const Vector2 *)p_with;
return self->dot(*with);
}
godot_vector2 GDAPI godot_vector2_slide(const godot_vector2 *p_self, const godot_vector2 *p_n) {
godot_vector2 dest;
const Vector2 *self = (const Vector2 *)p_self;
const Vector2 *n = (const Vector2 *)p_n;
*((Vector2 *)&dest) = self->slide(*n);
return dest;
}
godot_vector2 GDAPI godot_vector2_bounce(const godot_vector2 *p_self, const godot_vector2 *p_n) {
godot_vector2 dest;
const Vector2 *self = (const Vector2 *)p_self;
const Vector2 *n = (const Vector2 *)p_n;
*((Vector2 *)&dest) = self->bounce(*n);
return dest;
}
godot_vector2 GDAPI godot_vector2_reflect(const godot_vector2 *p_self, const godot_vector2 *p_n) {
godot_vector2 dest;
const Vector2 *self = (const Vector2 *)p_self;
const Vector2 *n = (const Vector2 *)p_n;
*((Vector2 *)&dest) = self->reflect(*n);
return dest;
}
godot_vector2 GDAPI godot_vector2_abs(const godot_vector2 *p_self) {
godot_vector2 dest;
const Vector2 *self = (const Vector2 *)p_self;
*((Vector2 *)&dest) = self->abs();
return dest;
}
godot_vector2 GDAPI godot_vector2_clamped(const godot_vector2 *p_self, const godot_real p_length) {
godot_vector2 dest;
const Vector2 *self = (const Vector2 *)p_self;
*((Vector2 *)&dest) = self->limit_length(p_length);
return dest;
}
godot_vector2 GDAPI godot_vector2_operator_add(const godot_vector2 *p_self, const godot_vector2 *p_b) {
godot_vector2 raw_dest;
Vector2 *dest = (Vector2 *)&raw_dest;
const Vector2 *self = (const Vector2 *)p_self;
const Vector2 *b = (const Vector2 *)p_b;
*dest = *self + *b;
return raw_dest;
}
godot_vector2 GDAPI godot_vector2_operator_subtract(const godot_vector2 *p_self, const godot_vector2 *p_b) {
godot_vector2 raw_dest;
Vector2 *dest = (Vector2 *)&raw_dest;
const Vector2 *self = (const Vector2 *)p_self;
const Vector2 *b = (const Vector2 *)p_b;
*dest = *self - *b;
return raw_dest;
}
godot_vector2 GDAPI godot_vector2_operator_multiply_vector(const godot_vector2 *p_self, const godot_vector2 *p_b) {
godot_vector2 raw_dest;
Vector2 *dest = (Vector2 *)&raw_dest;
const Vector2 *self = (const Vector2 *)p_self;
const Vector2 *b = (const Vector2 *)p_b;
*dest = *self * *b;
return raw_dest;
}
godot_vector2 GDAPI godot_vector2_operator_multiply_scalar(const godot_vector2 *p_self, const godot_real p_b) {
godot_vector2 raw_dest;
Vector2 *dest = (Vector2 *)&raw_dest;
const Vector2 *self = (const Vector2 *)p_self;
*dest = *self * p_b;
return raw_dest;
}
godot_vector2 GDAPI godot_vector2_operator_divide_vector(const godot_vector2 *p_self, const godot_vector2 *p_b) {
godot_vector2 raw_dest;
Vector2 *dest = (Vector2 *)&raw_dest;
const Vector2 *self = (const Vector2 *)p_self;
const Vector2 *b = (const Vector2 *)p_b;
*dest = *self / *b;
return raw_dest;
}
godot_vector2 GDAPI godot_vector2_operator_divide_scalar(const godot_vector2 *p_self, const godot_real p_b) {
godot_vector2 raw_dest;
Vector2 *dest = (Vector2 *)&raw_dest;
const Vector2 *self = (const Vector2 *)p_self;
*dest = *self / p_b;
return raw_dest;
}
godot_bool GDAPI godot_vector2_operator_equal(const godot_vector2 *p_self, const godot_vector2 *p_b) {
const Vector2 *self = (const Vector2 *)p_self;
const Vector2 *b = (const Vector2 *)p_b;
return *self == *b;
}
godot_bool GDAPI godot_vector2_operator_less(const godot_vector2 *p_self, const godot_vector2 *p_b) {
const Vector2 *self = (const Vector2 *)p_self;
const Vector2 *b = (const Vector2 *)p_b;
return *self < *b;
}
godot_vector2 GDAPI godot_vector2_operator_neg(const godot_vector2 *p_self) {
godot_vector2 raw_dest;
Vector2 *dest = (Vector2 *)&raw_dest;
const Vector2 *self = (const Vector2 *)p_self;
*dest = -(*self);
return raw_dest;
}
void GDAPI godot_vector2_set_x(godot_vector2 *p_self, const godot_real p_x) {
Vector2 *self = (Vector2 *)p_self;
self->x = p_x;
}
void GDAPI godot_vector2_set_y(godot_vector2 *p_self, const godot_real p_y) {
Vector2 *self = (Vector2 *)p_self;
self->y = p_y;
}
godot_real GDAPI godot_vector2_get_x(const godot_vector2 *p_self) {
const Vector2 *self = (const Vector2 *)p_self;
return self->x;
}
godot_real GDAPI godot_vector2_get_y(const godot_vector2 *p_self) {
const Vector2 *self = (const Vector2 *)p_self;
return self->y;
}
#ifdef __cplusplus
}
#endif

320
gdnative/vector3.cpp Normal file
View File

@ -0,0 +1,320 @@
/**************************************************************************/
/* vector3.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "gdnative/vector3.h"
#include "core/variant.h"
#include "core/vector.h"
#ifdef __cplusplus
extern "C" {
#endif
static_assert(sizeof(godot_vector3) == sizeof(Vector3), "Vector3 size mismatch");
void GDAPI godot_vector3_new(godot_vector3 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z) {
Vector3 *dest = (Vector3 *)r_dest;
*dest = Vector3(p_x, p_y, p_z);
}
godot_string GDAPI godot_vector3_as_string(const godot_vector3 *p_self) {
godot_string ret;
const Vector3 *self = (const Vector3 *)p_self;
memnew_placement(&ret, String(*self));
return ret;
}
godot_int GDAPI godot_vector3_min_axis(const godot_vector3 *p_self) {
const Vector3 *self = (const Vector3 *)p_self;
return self->min_axis();
}
godot_int GDAPI godot_vector3_max_axis(const godot_vector3 *p_self) {
const Vector3 *self = (const Vector3 *)p_self;
return self->max_axis();
}
godot_real GDAPI godot_vector3_length(const godot_vector3 *p_self) {
const Vector3 *self = (const Vector3 *)p_self;
return self->length();
}
godot_real GDAPI godot_vector3_length_squared(const godot_vector3 *p_self) {
const Vector3 *self = (const Vector3 *)p_self;
return self->length_squared();
}
godot_bool GDAPI godot_vector3_is_normalized(const godot_vector3 *p_self) {
const Vector3 *self = (const Vector3 *)p_self;
return self->is_normalized();
}
godot_vector3 GDAPI godot_vector3_normalized(const godot_vector3 *p_self) {
godot_vector3 dest;
const Vector3 *self = (const Vector3 *)p_self;
*((Vector3 *)&dest) = self->normalized();
return dest;
}
godot_vector3 GDAPI godot_vector3_inverse(const godot_vector3 *p_self) {
godot_vector3 dest;
const Vector3 *self = (const Vector3 *)p_self;
*((Vector3 *)&dest) = self->inverse();
return dest;
}
godot_vector3 GDAPI godot_vector3_snapped(const godot_vector3 *p_self, const godot_vector3 *p_by) {
godot_vector3 dest;
const Vector3 *self = (const Vector3 *)p_self;
const Vector3 *snap_axis = (const Vector3 *)p_by;
*((Vector3 *)&dest) = self->snapped(*snap_axis);
return dest;
}
godot_vector3 GDAPI godot_vector3_rotated(const godot_vector3 *p_self, const godot_vector3 *p_axis, const godot_real p_phi) {
godot_vector3 dest;
const Vector3 *self = (const Vector3 *)p_self;
const Vector3 *axis = (const Vector3 *)p_axis;
*((Vector3 *)&dest) = self->rotated(*axis, p_phi);
return dest;
}
godot_vector3 GDAPI godot_vector3_linear_interpolate(const godot_vector3 *p_self, const godot_vector3 *p_b, const godot_real p_t) {
godot_vector3 dest;
const Vector3 *self = (const Vector3 *)p_self;
const Vector3 *b = (const Vector3 *)p_b;
*((Vector3 *)&dest) = self->linear_interpolate(*b, p_t);
return dest;
}
godot_vector3 GDAPI godot_vector3_cubic_interpolate(const godot_vector3 *p_self, const godot_vector3 *p_b, const godot_vector3 *p_pre_a, const godot_vector3 *p_post_b, const godot_real p_t) {
godot_vector3 dest;
const Vector3 *self = (const Vector3 *)p_self;
const Vector3 *b = (const Vector3 *)p_b;
const Vector3 *pre_a = (const Vector3 *)p_pre_a;
const Vector3 *post_b = (const Vector3 *)p_post_b;
*((Vector3 *)&dest) = self->cubic_interpolate(*b, *pre_a, *post_b, p_t);
return dest;
}
godot_vector3 GDAPI godot_vector3_move_toward(const godot_vector3 *p_self, const godot_vector3 *p_to, const godot_real p_delta) {
godot_vector3 dest;
const Vector3 *self = (const Vector3 *)p_self;
const Vector3 *to = (const Vector3 *)p_to;
*((Vector3 *)&dest) = self->move_toward(*to, p_delta);
return dest;
}
godot_real GDAPI godot_vector3_dot(const godot_vector3 *p_self, const godot_vector3 *p_b) {
const Vector3 *self = (const Vector3 *)p_self;
const Vector3 *b = (const Vector3 *)p_b;
return self->dot(*b);
}
godot_vector3 GDAPI godot_vector3_cross(const godot_vector3 *p_self, const godot_vector3 *p_b) {
godot_vector3 dest;
const Vector3 *self = (const Vector3 *)p_self;
const Vector3 *b = (const Vector3 *)p_b;
*((Vector3 *)&dest) = self->cross(*b);
return dest;
}
godot_basis GDAPI godot_vector3_outer(const godot_vector3 *p_self, const godot_vector3 *p_b) {
godot_basis dest;
const Vector3 *self = (const Vector3 *)p_self;
const Vector3 *b = (const Vector3 *)p_b;
*((Basis *)&dest) = self->outer(*b);
return dest;
}
godot_basis GDAPI godot_vector3_to_diagonal_matrix(const godot_vector3 *p_self) {
godot_basis dest;
const Vector3 *self = (const Vector3 *)p_self;
*((Basis *)&dest) = self->to_diagonal_matrix();
return dest;
}
godot_vector3 GDAPI godot_vector3_abs(const godot_vector3 *p_self) {
godot_vector3 dest;
const Vector3 *self = (const Vector3 *)p_self;
*((Vector3 *)&dest) = self->abs();
return dest;
}
godot_vector3 GDAPI godot_vector3_floor(const godot_vector3 *p_self) {
godot_vector3 dest;
const Vector3 *self = (const Vector3 *)p_self;
*((Vector3 *)&dest) = self->floor();
return dest;
}
godot_vector3 GDAPI godot_vector3_ceil(const godot_vector3 *p_self) {
godot_vector3 dest;
const Vector3 *self = (const Vector3 *)p_self;
*((Vector3 *)&dest) = self->ceil();
return dest;
}
godot_vector3 GDAPI godot_vector3_direction_to(const godot_vector3 *p_self, const godot_vector3 *p_to) {
godot_vector3 dest;
const Vector3 *self = (const Vector3 *)p_self;
const Vector3 *to = (const Vector3 *)p_to;
*((Vector3 *)&dest) = self->direction_to(*to);
return dest;
}
godot_real GDAPI godot_vector3_distance_to(const godot_vector3 *p_self, const godot_vector3 *p_b) {
const Vector3 *self = (const Vector3 *)p_self;
const Vector3 *b = (const Vector3 *)p_b;
return self->distance_to(*b);
}
godot_real GDAPI godot_vector3_distance_squared_to(const godot_vector3 *p_self, const godot_vector3 *p_b) {
const Vector3 *self = (const Vector3 *)p_self;
const Vector3 *b = (const Vector3 *)p_b;
return self->distance_squared_to(*b);
}
godot_real GDAPI godot_vector3_angle_to(const godot_vector3 *p_self, const godot_vector3 *p_to) {
const Vector3 *self = (const Vector3 *)p_self;
const Vector3 *to = (const Vector3 *)p_to;
return self->angle_to(*to);
}
godot_vector3 GDAPI godot_vector3_slide(const godot_vector3 *p_self, const godot_vector3 *p_n) {
godot_vector3 dest;
const Vector3 *self = (const Vector3 *)p_self;
const Vector3 *n = (const Vector3 *)p_n;
*((Vector3 *)&dest) = self->slide(*n);
return dest;
}
godot_vector3 GDAPI godot_vector3_bounce(const godot_vector3 *p_self, const godot_vector3 *p_n) {
godot_vector3 dest;
const Vector3 *self = (const Vector3 *)p_self;
const Vector3 *n = (const Vector3 *)p_n;
*((Vector3 *)&dest) = self->bounce(*n);
return dest;
}
godot_vector3 GDAPI godot_vector3_reflect(const godot_vector3 *p_self, const godot_vector3 *p_n) {
godot_vector3 dest;
const Vector3 *self = (const Vector3 *)p_self;
const Vector3 *n = (const Vector3 *)p_n;
*((Vector3 *)&dest) = self->reflect(*n);
return dest;
}
godot_vector3 GDAPI godot_vector3_operator_add(const godot_vector3 *p_self, const godot_vector3 *p_b) {
godot_vector3 raw_dest;
Vector3 *dest = (Vector3 *)&raw_dest;
Vector3 *self = (Vector3 *)p_self;
const Vector3 *b = (const Vector3 *)p_b;
*dest = *self + *b;
return raw_dest;
}
godot_vector3 GDAPI godot_vector3_operator_subtract(const godot_vector3 *p_self, const godot_vector3 *p_b) {
godot_vector3 raw_dest;
Vector3 *dest = (Vector3 *)&raw_dest;
Vector3 *self = (Vector3 *)p_self;
const Vector3 *b = (const Vector3 *)p_b;
*dest = *self - *b;
return raw_dest;
}
godot_vector3 GDAPI godot_vector3_operator_multiply_vector(const godot_vector3 *p_self, const godot_vector3 *p_b) {
godot_vector3 raw_dest;
Vector3 *dest = (Vector3 *)&raw_dest;
Vector3 *self = (Vector3 *)p_self;
const Vector3 *b = (const Vector3 *)p_b;
*dest = *self * *b;
return raw_dest;
}
godot_vector3 GDAPI godot_vector3_operator_multiply_scalar(const godot_vector3 *p_self, const godot_real p_b) {
godot_vector3 raw_dest;
Vector3 *dest = (Vector3 *)&raw_dest;
Vector3 *self = (Vector3 *)p_self;
*dest = *self * p_b;
return raw_dest;
}
godot_vector3 GDAPI godot_vector3_operator_divide_vector(const godot_vector3 *p_self, const godot_vector3 *p_b) {
godot_vector3 raw_dest;
Vector3 *dest = (Vector3 *)&raw_dest;
Vector3 *self = (Vector3 *)p_self;
const Vector3 *b = (const Vector3 *)p_b;
*dest = *self / *b;
return raw_dest;
}
godot_vector3 GDAPI godot_vector3_operator_divide_scalar(const godot_vector3 *p_self, const godot_real p_b) {
godot_vector3 raw_dest;
Vector3 *dest = (Vector3 *)&raw_dest;
Vector3 *self = (Vector3 *)p_self;
*dest = *self / p_b;
return raw_dest;
}
godot_bool GDAPI godot_vector3_operator_equal(const godot_vector3 *p_self, const godot_vector3 *p_b) {
Vector3 *self = (Vector3 *)p_self;
const Vector3 *b = (const Vector3 *)p_b;
return *self == *b;
}
godot_bool GDAPI godot_vector3_operator_less(const godot_vector3 *p_self, const godot_vector3 *p_b) {
Vector3 *self = (Vector3 *)p_self;
const Vector3 *b = (const Vector3 *)p_b;
return *self < *b;
}
godot_vector3 GDAPI godot_vector3_operator_neg(const godot_vector3 *p_self) {
godot_vector3 raw_dest;
Vector3 *dest = (Vector3 *)&raw_dest;
const Vector3 *self = (const Vector3 *)p_self;
*dest = -(*self);
return raw_dest;
}
void GDAPI godot_vector3_set_axis(godot_vector3 *p_self, const godot_vector3_axis p_axis, const godot_real p_val) {
Vector3 *self = (Vector3 *)p_self;
self->set_axis(p_axis, p_val);
}
godot_real GDAPI godot_vector3_get_axis(const godot_vector3 *p_self, const godot_vector3_axis p_axis) {
const Vector3 *self = (const Vector3 *)p_self;
return self->get_axis(p_axis);
}
#ifdef __cplusplus
}
#endif

6844
gdnative_api.json Normal file

File diff suppressed because it is too large Load Diff

350
gdnative_builders.py Normal file
View File

@ -0,0 +1,350 @@
"""Functions used to generate source files during build time
All such functions are invoked in a subprocess on Windows to prevent build flakiness.
"""
import json
from platform_methods import subprocess_main
def _spaced(e):
return e if e[-1] == "*" else e + " "
def _build_gdnative_api_struct_header(api):
gdnative_api_init_macro = ["\textern const godot_gdnative_core_api_struct *_gdnative_wrapper_api_struct;"]
for ext in api["extensions"]:
name = ext["name"]
gdnative_api_init_macro.append(
"\textern const godot_gdnative_ext_{0}_api_struct *_gdnative_wrapper_{0}_api_struct;".format(name)
)
gdnative_api_init_macro.append("\t_gdnative_wrapper_api_struct = options->api_struct;")
gdnative_api_init_macro.append(
"\tfor (unsigned int i = 0; i < _gdnative_wrapper_api_struct->num_extensions; i++) { "
)
gdnative_api_init_macro.append("\t\tswitch (_gdnative_wrapper_api_struct->extensions[i]->type) {")
for ext in api["extensions"]:
name = ext["name"]
gdnative_api_init_macro.append("\t\t\tcase GDNATIVE_EXT_%s:" % ext["type"])
gdnative_api_init_macro.append(
"\t\t\t\t_gdnative_wrapper_{0}_api_struct = (godot_gdnative_ext_{0}_api_struct *)"
" _gdnative_wrapper_api_struct->extensions[i];".format(name)
)
gdnative_api_init_macro.append("\t\t\t\tbreak;")
gdnative_api_init_macro.append("\t\t}")
gdnative_api_init_macro.append("\t}")
out = [
"/* THIS FILE IS GENERATED DO NOT EDIT */",
"#ifndef GODOT_GDNATIVE_API_STRUCT_H",
"#define GODOT_GDNATIVE_API_STRUCT_H",
"",
"#include <gdnative/gdnative.h>",
"#include <android/godot_android.h>",
"#include <arvr/godot_arvr.h>",
"#include <nativescript/godot_nativescript.h>",
"#include <net/godot_net.h>",
"#include <pluginscript/godot_pluginscript.h>",
"#include <videodecoder/godot_videodecoder.h>",
"",
"#define GDNATIVE_API_INIT(options) do { \\\n" + " \\\n".join(gdnative_api_init_macro) + " \\\n } while (0)",
"",
"#ifdef __cplusplus",
'extern "C" {',
"#endif",
"",
"enum GDNATIVE_API_TYPES {",
"\tGDNATIVE_" + api["core"]["type"] + ",",
]
for ext in api["extensions"]:
out += ["\tGDNATIVE_EXT_" + ext["type"] + ","]
out += ["};", ""]
def generate_extension_struct(name, ext, include_version=True):
ret_val = []
if ext["next"]:
ret_val += generate_extension_struct(name, ext["next"])
ret_val += [
"typedef struct godot_gdnative_ext_"
+ name
+ ("" if not include_version else ("_{0}_{1}".format(ext["version"]["major"], ext["version"]["minor"])))
+ "_api_struct {",
"\tunsigned int type;",
"\tgodot_gdnative_api_version version;",
"\tconst godot_gdnative_api_struct *next;",
]
for funcdef in ext["api"]:
args = ", ".join(["%s%s" % (_spaced(t), n) for t, n in funcdef["arguments"]])
ret_val.append("\t%s(*%s)(%s);" % (_spaced(funcdef["return_type"]), funcdef["name"], args))
ret_val += [
"} godot_gdnative_ext_"
+ name
+ ("" if not include_version else ("_{0}_{1}".format(ext["version"]["major"], ext["version"]["minor"])))
+ "_api_struct;",
"",
]
return ret_val
def generate_core_extension_struct(core):
ret_val = []
if core["next"]:
ret_val += generate_core_extension_struct(core["next"])
ret_val += [
"typedef struct godot_gdnative_core_"
+ ("{0}_{1}".format(core["version"]["major"], core["version"]["minor"]))
+ "_api_struct {",
"\tunsigned int type;",
"\tgodot_gdnative_api_version version;",
"\tconst godot_gdnative_api_struct *next;",
]
for funcdef in core["api"]:
args = ", ".join(["%s%s" % (_spaced(t), n) for t, n in funcdef["arguments"]])
ret_val.append("\t%s(*%s)(%s);" % (_spaced(funcdef["return_type"]), funcdef["name"], args))
ret_val += [
"} godot_gdnative_core_"
+ "{0}_{1}".format(core["version"]["major"], core["version"]["minor"])
+ "_api_struct;",
"",
]
return ret_val
for ext in api["extensions"]:
name = ext["name"]
out += generate_extension_struct(name, ext, False)
if api["core"]["next"]:
out += generate_core_extension_struct(api["core"]["next"])
out += [
"typedef struct godot_gdnative_core_api_struct {",
"\tunsigned int type;",
"\tgodot_gdnative_api_version version;",
"\tconst godot_gdnative_api_struct *next;",
"\tunsigned int num_extensions;",
"\tconst godot_gdnative_api_struct **extensions;",
]
for funcdef in api["core"]["api"]:
args = ", ".join(["%s%s" % (_spaced(t), n) for t, n in funcdef["arguments"]])
out.append("\t%s(*%s)(%s);" % (_spaced(funcdef["return_type"]), funcdef["name"], args))
out += [
"} godot_gdnative_core_api_struct;",
"",
"#ifdef __cplusplus",
"}",
"#endif",
"",
"#endif // GODOT_GDNATIVE_API_STRUCT_H",
"",
]
return "\n".join(out)
def _build_gdnative_api_struct_source(api):
out = ["/* THIS FILE IS GENERATED DO NOT EDIT */", "", "#include <gdnative_api_struct.gen.h>", ""]
def get_extension_struct_name(name, ext, include_version=True):
return (
"godot_gdnative_ext_"
+ name
+ ("" if not include_version else ("_{0}_{1}".format(ext["version"]["major"], ext["version"]["minor"])))
+ "_api_struct"
)
def get_extension_struct_instance_name(name, ext, include_version=True):
return (
"api_extension_"
+ name
+ ("" if not include_version else ("_{0}_{1}".format(ext["version"]["major"], ext["version"]["minor"])))
+ "_struct"
)
def get_extension_struct_definition(name, ext, include_version=True):
ret_val = []
if ext["next"]:
ret_val += get_extension_struct_definition(name, ext["next"])
ret_val += [
"extern const "
+ get_extension_struct_name(name, ext, include_version)
+ " "
+ get_extension_struct_instance_name(name, ext, include_version)
+ " = {",
"\tGDNATIVE_EXT_" + ext["type"] + ",",
"\t{" + str(ext["version"]["major"]) + ", " + str(ext["version"]["minor"]) + "},",
"\t"
+ (
"NULL"
if not ext["next"]
else ("(const godot_gdnative_api_struct *)&" + get_extension_struct_instance_name(name, ext["next"]))
)
+ ",",
]
for funcdef in ext["api"]:
ret_val.append("\t%s," % funcdef["name"])
ret_val += ["};\n"]
return ret_val
def get_core_struct_definition(core):
ret_val = []
if core["next"]:
ret_val += get_core_struct_definition(core["next"])
ret_val += [
"extern const godot_gdnative_core_"
+ ("{0}_{1}_api_struct api_{0}_{1}".format(core["version"]["major"], core["version"]["minor"]))
+ " = {",
"\tGDNATIVE_" + core["type"] + ",",
"\t{" + str(core["version"]["major"]) + ", " + str(core["version"]["minor"]) + "},",
"\t"
+ (
"NULL"
if not core["next"]
else (
"(const godot_gdnative_api_struct *)& api_{0}_{1}".format(
core["next"]["version"]["major"], core["next"]["version"]["minor"]
)
)
)
+ ",",
]
for funcdef in core["api"]:
ret_val.append("\t%s," % funcdef["name"])
ret_val += ["};\n"]
return ret_val
for ext in api["extensions"]:
name = ext["name"]
out += get_extension_struct_definition(name, ext, False)
out += ["", "const godot_gdnative_api_struct *gdnative_extensions_pointers[] = {"]
for ext in api["extensions"]:
name = ext["name"]
out += ["\t(godot_gdnative_api_struct *)&api_extension_" + name + "_struct,"]
out += ["};\n"]
if api["core"]["next"]:
out += get_core_struct_definition(api["core"]["next"])
out += [
"extern const godot_gdnative_core_api_struct api_struct = {",
"\tGDNATIVE_" + api["core"]["type"] + ",",
"\t{" + str(api["core"]["version"]["major"]) + ", " + str(api["core"]["version"]["minor"]) + "},",
"\t(const godot_gdnative_api_struct *)&api_1_1,",
"\t" + str(len(api["extensions"])) + ",",
"\tgdnative_extensions_pointers,",
]
for funcdef in api["core"]["api"]:
out.append("\t%s," % funcdef["name"])
out.append("};\n")
return "\n".join(out)
def build_gdnative_api_struct(target, source, env):
with open(source[0], "r") as fd:
api = json.load(fd)
header, source = target
with open(header, "w") as fd:
fd.write(_build_gdnative_api_struct_header(api))
with open(source, "w") as fd:
fd.write(_build_gdnative_api_struct_source(api))
def _build_gdnative_wrapper_code(api):
out = [
"/* THIS FILE IS GENERATED DO NOT EDIT */",
"",
"#include <gdnative/gdnative.h>",
"#include <nativescript/godot_nativescript.h>",
"#include <pluginscript/godot_pluginscript.h>",
"#include <arvr/godot_arvr.h>",
"#include <videodecoder/godot_videodecoder.h>",
"",
"#include <gdnative_api_struct.gen.h>",
"",
"#ifdef __cplusplus",
'extern "C" {',
"#endif",
"",
"godot_gdnative_core_api_struct *_gdnative_wrapper_api_struct = 0;",
]
for ext in api["extensions"]:
name = ext["name"]
out.append("godot_gdnative_ext_" + name + "_api_struct *_gdnative_wrapper_" + name + "_api_struct = 0;")
out += [""]
for funcdef in api["core"]["api"]:
args = ", ".join(["%s%s" % (_spaced(t), n) for t, n in funcdef["arguments"]])
out.append("%s%s(%s) {" % (_spaced(funcdef["return_type"]), funcdef["name"], args))
args = ", ".join(["%s" % n for t, n in funcdef["arguments"]])
return_line = "\treturn " if funcdef["return_type"] != "void" else "\t"
return_line += "_gdnative_wrapper_api_struct->" + funcdef["name"] + "(" + args + ");"
out.append(return_line)
out.append("}")
out.append("")
for ext in api["extensions"]:
name = ext["name"]
for funcdef in ext["api"]:
args = ", ".join(["%s%s" % (_spaced(t), n) for t, n in funcdef["arguments"]])
out.append("%s%s(%s) {" % (_spaced(funcdef["return_type"]), funcdef["name"], args))
args = ", ".join(["%s" % n for t, n in funcdef["arguments"]])
return_line = "\treturn " if funcdef["return_type"] != "void" else "\t"
return_line += "_gdnative_wrapper_" + name + "_api_struct->" + funcdef["name"] + "(" + args + ");"
out.append(return_line)
out.append("}")
out.append("")
out += ["#ifdef __cplusplus", "}", "#endif"]
return "\n".join(out)
def build_gdnative_wrapper_code(target, source, env):
with open(source[0], "r") as fd:
api = json.load(fd)
wrapper_file = target[0]
with open(wrapper_file, "w") as fd:
fd.write(_build_gdnative_wrapper_code(api))
if __name__ == "__main__":
subprocess_main(globals())

View File

@ -0,0 +1,426 @@
/**************************************************************************/
/* gdnative_library_editor_plugin.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifdef TOOLS_ENABLED
#include "gdnative_library_editor_plugin.h"
#include "gdnative.h"
#include "editor/editor_scale.h"
void GDNativeLibraryEditor::edit(Ref<GDNativeLibrary> p_library) {
library = p_library;
Ref<ConfigFile> config = p_library->get_config_file();
for (Map<String, NativePlatformConfig>::Element *E = platforms.front(); E; E = E->next()) {
for (List<String>::Element *it = E->value().entries.front(); it; it = it->next()) {
String target = E->key() + "." + it->get();
TargetConfig ecfg;
ecfg.library = config->get_value("entry", target, "");
ecfg.dependencies = config->get_value("dependencies", target, Array());
entry_configs[target] = ecfg;
}
}
_update_tree();
}
void GDNativeLibraryEditor::_bind_methods() {
ClassDB::bind_method("_on_item_button", &GDNativeLibraryEditor::_on_item_button);
ClassDB::bind_method("_on_library_selected", &GDNativeLibraryEditor::_on_library_selected);
ClassDB::bind_method("_on_dependencies_selected", &GDNativeLibraryEditor::_on_dependencies_selected);
ClassDB::bind_method("_on_filter_selected", &GDNativeLibraryEditor::_on_filter_selected);
ClassDB::bind_method("_on_item_collapsed", &GDNativeLibraryEditor::_on_item_collapsed);
ClassDB::bind_method("_on_item_activated", &GDNativeLibraryEditor::_on_item_activated);
ClassDB::bind_method("_on_create_new_entry", &GDNativeLibraryEditor::_on_create_new_entry);
}
void GDNativeLibraryEditor::_update_tree() {
tree->clear();
TreeItem *root = tree->create_item();
PopupMenu *filter_list = filter->get_popup();
String text = "";
for (int i = 0; i < filter_list->get_item_count(); i++) {
if (!filter_list->is_item_checked(i)) {
continue;
}
Map<String, NativePlatformConfig>::Element *E = platforms.find(filter_list->get_item_metadata(i));
if (!text.empty()) {
text += ", ";
}
text += E->get().name;
TreeItem *platform = tree->create_item(root);
platform->set_text(0, E->get().name);
platform->set_metadata(0, E->get().library_extension);
platform->set_custom_bg_color(0, get_color("prop_category", "Editor"));
platform->set_custom_bg_color(1, get_color("prop_category", "Editor"));
platform->set_custom_bg_color(2, get_color("prop_category", "Editor"));
platform->set_selectable(0, false);
platform->set_expand_right(0, true);
for (List<String>::Element *it = E->value().entries.front(); it; it = it->next()) {
String target = E->key() + "." + it->get();
TreeItem *bit = tree->create_item(platform);
bit->set_text(0, it->get());
bit->set_metadata(0, target);
bit->set_selectable(0, false);
bit->set_custom_bg_color(0, get_color("prop_subsection", "Editor"));
bit->add_button(1, get_icon("Folder", "EditorIcons"), BUTTON_SELECT_LIBRARY, false, TTR("Select the dynamic library for this entry"));
String file = entry_configs[target].library;
if (!file.empty()) {
bit->add_button(1, get_icon("Clear", "EditorIcons"), BUTTON_CLEAR_LIBRARY, false, TTR("Clear"));
}
bit->set_text(1, file);
bit->add_button(2, get_icon("Folder", "EditorIcons"), BUTTON_SELECT_DEPENDENCES, false, TTR("Select dependencies of the library for this entry"));
Array files = entry_configs[target].dependencies;
if (files.size()) {
bit->add_button(2, get_icon("Clear", "EditorIcons"), BUTTON_CLEAR_DEPENDENCES, false, TTR("Clear"));
}
bit->set_text(2, Variant(files));
bit->add_button(3, get_icon("MoveUp", "EditorIcons"), BUTTON_MOVE_UP, false, TTR("Move Up"));
bit->add_button(3, get_icon("MoveDown", "EditorIcons"), BUTTON_MOVE_DOWN, false, TTR("Move Down"));
bit->add_button(3, get_icon("Remove", "EditorIcons"), BUTTON_ERASE_ENTRY, false, TTR("Remove current entry"));
}
TreeItem *new_arch = tree->create_item(platform);
new_arch->set_text(0, TTR("Double click to create a new entry"));
new_arch->set_text_align(0, TreeItem::ALIGN_CENTER);
new_arch->set_custom_color(0, get_color("accent_color", "Editor"));
new_arch->set_expand_right(0, true);
new_arch->set_metadata(1, E->key());
platform->set_collapsed(collapsed_items.find(E->get().name) != nullptr);
}
filter->set_text(text);
}
void GDNativeLibraryEditor::_on_item_button(Object *item, int column, int id) {
String target = Object::cast_to<TreeItem>(item)->get_metadata(0);
String platform = target.substr(0, target.find("."));
String entry = target.substr(platform.length() + 1, target.length());
String section = (id == BUTTON_SELECT_DEPENDENCES || id == BUTTON_CLEAR_DEPENDENCES) ? "dependencies" : "entry";
if (id == BUTTON_SELECT_LIBRARY || id == BUTTON_SELECT_DEPENDENCES) {
TreeItem *treeItem = Object::cast_to<TreeItem>(item)->get_parent();
EditorFileDialog::Mode mode = EditorFileDialog::MODE_OPEN_FILE;
if (id == BUTTON_SELECT_DEPENDENCES) {
mode = EditorFileDialog::MODE_OPEN_FILES;
} else if (treeItem->get_text(0) == "iOS" || treeItem->get_text(0) == "macOS") {
mode = EditorFileDialog::MODE_OPEN_ANY;
}
file_dialog->set_meta("target", target);
file_dialog->set_meta("section", section);
file_dialog->clear_filters();
String filter_string = treeItem->get_metadata(0);
Vector<String> filters = filter_string.split(",", false, 0);
for (int i = 0; i < filters.size(); i++) {
file_dialog->add_filter(filters[i]);
}
file_dialog->set_mode(mode);
file_dialog->popup_centered_ratio();
} else if (id == BUTTON_CLEAR_LIBRARY) {
_set_target_value(section, target, "");
} else if (id == BUTTON_CLEAR_DEPENDENCES) {
_set_target_value(section, target, Array());
} else if (id == BUTTON_ERASE_ENTRY) {
_erase_entry(platform, entry);
} else if (id == BUTTON_MOVE_UP || id == BUTTON_MOVE_DOWN) {
_move_entry(platform, entry, id);
}
}
void GDNativeLibraryEditor::_on_library_selected(const String &file) {
_set_target_value(file_dialog->get_meta("section"), file_dialog->get_meta("target"), file);
}
void GDNativeLibraryEditor::_on_dependencies_selected(const PoolStringArray &files) {
_set_target_value(file_dialog->get_meta("section"), file_dialog->get_meta("target"), files);
}
void GDNativeLibraryEditor::_on_filter_selected(int index) {
PopupMenu *filter_list = filter->get_popup();
filter_list->set_item_checked(index, !filter_list->is_item_checked(index));
_update_tree();
}
void GDNativeLibraryEditor::_on_item_collapsed(Object *p_item) {
TreeItem *item = Object::cast_to<TreeItem>(p_item);
String name = item->get_text(0);
if (item->is_collapsed()) {
collapsed_items.insert(name);
} else if (Set<String>::Element *e = collapsed_items.find(name)) {
collapsed_items.erase(e);
}
}
void GDNativeLibraryEditor::_on_item_activated() {
TreeItem *item = tree->get_selected();
if (item && tree->get_selected_column() == 0 && item->get_metadata(0).get_type() == Variant::NIL) {
new_architecture_dialog->set_meta("platform", item->get_metadata(1));
new_architecture_dialog->popup_centered();
}
}
void GDNativeLibraryEditor::_on_create_new_entry() {
String platform = new_architecture_dialog->get_meta("platform");
String entry = new_architecture_input->get_text().strip_edges();
if (!entry.empty()) {
platforms[platform].entries.push_back(entry);
_update_tree();
}
}
void GDNativeLibraryEditor::_set_target_value(const String &section, const String &target, Variant file) {
if (section == "entry") {
entry_configs[target].library = file;
} else if (section == "dependencies") {
entry_configs[target].dependencies = file;
}
_translate_to_config_file();
_update_tree();
}
void GDNativeLibraryEditor::_erase_entry(const String &platform, const String &entry) {
if (platforms.has(platform)) {
if (List<String>::Element *E = platforms[platform].entries.find(entry)) {
String target = platform + "." + entry;
platforms[platform].entries.erase(E);
_set_target_value("entry", target, "");
_set_target_value("dependencies", target, Array());
_translate_to_config_file();
_update_tree();
}
}
}
void GDNativeLibraryEditor::_move_entry(const String &platform, const String &entry, int dir) {
if (List<String>::Element *E = platforms[platform].entries.find(entry)) {
if (E->prev() && dir == BUTTON_MOVE_UP) {
platforms[platform].entries.insert_before(E->prev(), E->get());
platforms[platform].entries.erase(E);
} else if (E->next() && dir == BUTTON_MOVE_DOWN) {
platforms[platform].entries.insert_after(E->next(), E->get());
platforms[platform].entries.erase(E);
}
_translate_to_config_file();
_update_tree();
}
}
void GDNativeLibraryEditor::_translate_to_config_file() {
if (!library.is_null()) {
Ref<ConfigFile> config = library->get_config_file();
config->erase_section("entry");
config->erase_section("dependencies");
for (Map<String, NativePlatformConfig>::Element *E = platforms.front(); E; E = E->next()) {
for (List<String>::Element *it = E->value().entries.front(); it; it = it->next()) {
String target = E->key() + "." + it->get();
if (entry_configs[target].library.empty() && entry_configs[target].dependencies.empty()) {
continue;
}
config->set_value("entry", target, entry_configs[target].library);
config->set_value("dependencies", target, entry_configs[target].dependencies);
}
}
library->_change_notify();
}
}
GDNativeLibraryEditor::GDNativeLibraryEditor() {
{ // Define platforms
NativePlatformConfig platform_windows;
platform_windows.name = "Windows";
platform_windows.entries.push_back("64");
platform_windows.entries.push_back("32");
platform_windows.library_extension = "*.dll";
platforms["Windows"] = platform_windows;
NativePlatformConfig platform_linux;
platform_linux.name = "Linux/X11";
platform_linux.entries.push_back("64");
platform_linux.entries.push_back("32");
platform_linux.library_extension = "*.so";
platforms["X11"] = platform_linux;
NativePlatformConfig platform_osx;
platform_osx.name = "macOS";
platform_osx.entries.push_back("64");
platform_osx.library_extension = "*.framework; Framework, *.dylib; Dynamic Library";
platforms["OSX"] = platform_osx;
NativePlatformConfig platform_haiku;
platform_haiku.name = "Haiku";
platform_haiku.entries.push_back("64");
platform_haiku.entries.push_back("32");
platform_haiku.library_extension = "*.so";
platforms["Haiku"] = platform_haiku;
NativePlatformConfig platform_uwp;
platform_uwp.name = "UWP";
platform_uwp.entries.push_back("arm");
platform_uwp.entries.push_back("32");
platform_uwp.entries.push_back("64");
platform_uwp.library_extension = "*.dll";
platforms["UWP"] = platform_uwp;
NativePlatformConfig platform_android;
platform_android.name = "Android";
platform_android.entries.push_back("armeabi-v7a");
platform_android.entries.push_back("arm64-v8a");
platform_android.entries.push_back("x86");
platform_android.entries.push_back("x86_64");
platform_android.library_extension = "*.so";
platforms["Android"] = platform_android;
NativePlatformConfig platform_html5;
platform_html5.name = "HTML5";
platform_html5.entries.push_back("wasm32");
platform_html5.library_extension = "*.wasm";
platforms["HTML5"] = platform_html5;
NativePlatformConfig platform_ios;
platform_ios.name = "iOS";
platform_ios.entries.push_back("armv7");
platform_ios.entries.push_back("arm64");
platform_ios.entries.push_back("x86_64");
// iOS can use both Static and Dynamic libraries.
// Frameworks is actually a folder with files.
platform_ios.library_extension = "*.framework; Framework, *.xcframework; Binary Framework, *.a; Static Library, *.dylib; Dynamic Library";
platforms["iOS"] = platform_ios;
}
VBoxContainer *container = memnew(VBoxContainer);
add_child(container);
container->set_anchors_and_margins_preset(PRESET_WIDE);
HBoxContainer *hbox = memnew(HBoxContainer);
container->add_child(hbox);
Label *label = memnew(Label);
label->set_text(TTR("Platform:"));
hbox->add_child(label);
filter = memnew(MenuButton);
filter->set_h_size_flags(SIZE_EXPAND_FILL);
filter->set_text_align(filter->ALIGN_LEFT);
hbox->add_child(filter);
PopupMenu *filter_list = filter->get_popup();
filter_list->set_hide_on_checkable_item_selection(false);
int idx = 0;
for (Map<String, NativePlatformConfig>::Element *E = platforms.front(); E; E = E->next()) {
filter_list->add_check_item(E->get().name, idx);
filter_list->set_item_metadata(idx, E->key());
filter_list->set_item_checked(idx, true);
idx += 1;
}
filter_list->connect("index_pressed", this, "_on_filter_selected");
tree = memnew(Tree);
container->add_child(tree);
tree->set_v_size_flags(SIZE_EXPAND_FILL);
tree->set_hide_root(true);
tree->set_column_titles_visible(true);
tree->set_columns(4);
tree->set_column_expand(0, false);
tree->set_column_min_width(0, int(200 * EDSCALE));
tree->set_column_title(0, TTR("Platform"));
tree->set_column_title(1, TTR("Dynamic Library"));
tree->set_column_title(2, TTR("Dependencies"));
tree->set_column_expand(3, false);
tree->set_column_min_width(3, int(110 * EDSCALE));
tree->connect("button_pressed", this, "_on_item_button");
tree->connect("item_collapsed", this, "_on_item_collapsed");
tree->connect("item_activated", this, "_on_item_activated");
file_dialog = memnew(EditorFileDialog);
file_dialog->set_access(EditorFileDialog::ACCESS_RESOURCES);
file_dialog->set_resizable(true);
add_child(file_dialog);
file_dialog->connect("file_selected", this, "_on_library_selected");
file_dialog->connect("dir_selected", this, "_on_library_selected");
file_dialog->connect("files_selected", this, "_on_dependencies_selected");
new_architecture_dialog = memnew(ConfirmationDialog);
add_child(new_architecture_dialog);
new_architecture_dialog->set_title(TTR("Add an architecture entry"));
new_architecture_input = memnew(LineEdit);
new_architecture_dialog->add_child(new_architecture_input);
new_architecture_dialog->set_custom_minimum_size(Vector2(300, 80) * EDSCALE);
new_architecture_input->set_anchors_and_margins_preset(PRESET_HCENTER_WIDE, PRESET_MODE_MINSIZE, 5 * EDSCALE);
new_architecture_dialog->get_ok()->connect("pressed", this, "_on_create_new_entry");
}
void GDNativeLibraryEditorPlugin::edit(Object *p_node) {
Ref<GDNativeLibrary> new_library = Object::cast_to<GDNativeLibrary>(p_node);
if (new_library.is_valid()) {
library_editor->edit(new_library);
}
}
bool GDNativeLibraryEditorPlugin::handles(Object *p_node) const {
return p_node->is_class("GDNativeLibrary");
}
void GDNativeLibraryEditorPlugin::make_visible(bool p_visible) {
if (p_visible) {
button->show();
EditorNode::get_singleton()->make_bottom_panel_item_visible(library_editor);
} else {
if (library_editor->is_visible_in_tree()) {
EditorNode::get_singleton()->hide_bottom_panel();
}
button->hide();
}
}
GDNativeLibraryEditorPlugin::GDNativeLibraryEditorPlugin(EditorNode *p_node) {
library_editor = memnew(GDNativeLibraryEditor);
library_editor->set_custom_minimum_size(Size2(0, 250 * EDSCALE));
button = p_node->add_bottom_panel_item(TTR("GDNativeLibrary"), library_editor);
button->hide();
}
#endif

View File

@ -0,0 +1,113 @@
/**************************************************************************/
/* gdnative_library_editor_plugin.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_LIBRARY_EDITOR_PLUGIN_H
#define GDNATIVE_LIBRARY_EDITOR_PLUGIN_H
#ifdef TOOLS_ENABLED
#include "editor/editor_node.h"
#include "gdnative.h"
class GDNativeLibraryEditor : public Control {
GDCLASS(GDNativeLibraryEditor, Control);
struct NativePlatformConfig {
String name;
String library_extension;
List<String> entries;
};
struct TargetConfig {
String library;
Array dependencies;
};
enum ItemButton {
BUTTON_SELECT_LIBRARY,
BUTTON_CLEAR_LIBRARY,
BUTTON_SELECT_DEPENDENCES,
BUTTON_CLEAR_DEPENDENCES,
BUTTON_ERASE_ENTRY,
BUTTON_MOVE_UP,
BUTTON_MOVE_DOWN,
};
Tree *tree;
MenuButton *filter;
EditorFileDialog *file_dialog;
ConfirmationDialog *new_architecture_dialog;
LineEdit *new_architecture_input;
Set<String> collapsed_items;
String showing_platform;
Ref<GDNativeLibrary> library;
Map<String, NativePlatformConfig> platforms;
Map<String, TargetConfig> entry_configs;
protected:
static void _bind_methods();
void _update_tree();
void _on_item_button(Object *item, int column, int id);
void _on_library_selected(const String &file);
void _on_dependencies_selected(const PoolStringArray &files);
void _on_filter_selected(int id);
void _on_item_collapsed(Object *p_item);
void _on_item_activated();
void _on_create_new_entry();
void _set_target_value(const String &section, const String &target, Variant file);
void _erase_entry(const String &platform, const String &entry);
void _move_entry(const String &platform, const String &entry, int dir);
void _translate_to_config_file();
public:
void edit(Ref<GDNativeLibrary> p_library);
GDNativeLibraryEditor();
};
class GDNativeLibraryEditorPlugin : public EditorPlugin {
GDCLASS(GDNativeLibraryEditorPlugin, EditorPlugin);
GDNativeLibraryEditor *library_editor;
EditorNode *editor;
Button *button;
public:
virtual String get_name() const { return "GDNativeLibrary"; }
bool has_main_screen() const { return false; }
virtual void edit(Object *p_node);
virtual bool handles(Object *p_node) const;
virtual void make_visible(bool p_visible);
GDNativeLibraryEditorPlugin(EditorNode *p_node);
};
#endif
#endif // GDNATIVE_LIBRARY_EDITOR_PLUGIN_H

View File

@ -0,0 +1,212 @@
/**************************************************************************/
/* gdnative_library_singleton_editor.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifdef TOOLS_ENABLED
#include "gdnative_library_singleton_editor.h"
#include "gdnative.h"
#include "editor/editor_node.h"
Set<String> GDNativeLibrarySingletonEditor::_find_singletons_recursive(EditorFileSystemDirectory *p_dir) {
Set<String> file_paths;
// check children
for (int i = 0; i < p_dir->get_file_count(); i++) {
String file_name = p_dir->get_file(i);
String file_type = p_dir->get_file_type(i);
if (file_type != "GDNativeLibrary") {
continue;
}
Ref<GDNativeLibrary> lib = ResourceLoader::load(p_dir->get_file_path(i));
if (lib.is_valid() && lib->is_singleton()) {
file_paths.insert(p_dir->get_file_path(i));
}
}
// check subdirectories
for (int i = 0; i < p_dir->get_subdir_count(); i++) {
Set<String> paths = _find_singletons_recursive(p_dir->get_subdir(i));
for (Set<String>::Element *E = paths.front(); E; E = E->next()) {
file_paths.insert(E->get());
}
}
return file_paths;
}
void GDNativeLibrarySingletonEditor::_discover_singletons() {
EditorFileSystemDirectory *dir = EditorFileSystem::get_singleton()->get_filesystem();
Set<String> file_paths = _find_singletons_recursive(dir);
bool changed = false;
Array current_files;
if (ProjectSettings::get_singleton()->has_setting("gdnative/singletons")) {
current_files = ProjectSettings::get_singleton()->get("gdnative/singletons");
}
Array files;
for (Set<String>::Element *E = file_paths.front(); E; E = E->next()) {
if (!current_files.has(E->get())) {
changed = true;
}
files.append(E->get());
}
// Check for removed files
if (!changed) {
// Removed singleton
for (int j = 0; j < current_files.size(); j++) {
if (!files.has(current_files[j])) {
changed = true;
break;
}
}
}
if (changed) {
ProjectSettings::get_singleton()->set("gdnative/singletons", files);
_update_libraries(); // So singleton options (i.e. disabled) updates too
ProjectSettings::get_singleton()->save();
}
}
void GDNativeLibrarySingletonEditor::_update_libraries() {
updating = true;
libraries->clear();
libraries->create_item(); // root item
Array singletons;
if (ProjectSettings::get_singleton()->has_setting("gdnative/singletons")) {
singletons = ProjectSettings::get_singleton()->get("gdnative/singletons");
}
Array singletons_disabled;
if (ProjectSettings::get_singleton()->has_setting("gdnative/singletons_disabled")) {
singletons_disabled = ProjectSettings::get_singleton()->get("gdnative/singletons_disabled");
}
Array updated_disabled;
for (int i = 0; i < singletons.size(); i++) {
bool enabled = true;
String path = singletons[i];
if (singletons_disabled.has(path)) {
enabled = false;
updated_disabled.push_back(path);
}
TreeItem *ti = libraries->create_item(libraries->get_root());
ti->set_text(0, path.get_file());
ti->set_tooltip(0, path);
ti->set_metadata(0, path);
ti->set_cell_mode(1, TreeItem::CELL_MODE_RANGE);
ti->set_text(1, "Disabled,Enabled");
ti->set_range(1, enabled ? 1 : 0);
ti->set_custom_color(1, enabled ? Color(0, 1, 0) : Color(1, 0, 0));
ti->set_editable(1, true);
}
// The singletons list changed, we must update the settings
if (updated_disabled.size() != singletons_disabled.size()) {
ProjectSettings::get_singleton()->set("gdnative/singletons_disabled", updated_disabled);
}
updating = false;
}
void GDNativeLibrarySingletonEditor::_item_edited() {
if (updating) {
return;
}
TreeItem *item = libraries->get_edited();
if (!item) {
return;
}
bool enabled = item->get_range(1);
String path = item->get_metadata(0);
Array disabled_paths;
Array undo_paths;
if (ProjectSettings::get_singleton()->has_setting("gdnative/singletons_disabled")) {
disabled_paths = ProjectSettings::get_singleton()->get("gdnative/singletons_disabled");
// Duplicate so redo works (not a reference)
disabled_paths = disabled_paths.duplicate();
// For undo, so we can reset the property.
undo_paths = disabled_paths.duplicate();
}
if (enabled) {
disabled_paths.erase(path);
} else {
if (disabled_paths.find(path) == -1) {
disabled_paths.push_back(path);
}
}
undo_redo->create_action(enabled ? TTR("Enabled GDNative Singleton") : TTR("Disabled GDNative Singleton"));
undo_redo->add_do_property(ProjectSettings::get_singleton(), "gdnative/singletons_disabled", disabled_paths);
undo_redo->add_do_method(this, "_update_libraries");
undo_redo->add_undo_property(ProjectSettings::get_singleton(), "gdnative/singletons_disabled", undo_paths);
undo_redo->add_undo_method(this, "_update_libraries");
undo_redo->commit_action();
}
void GDNativeLibrarySingletonEditor::_notification(int p_what) {
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
if (is_visible_in_tree()) {
_update_libraries();
}
}
}
void GDNativeLibrarySingletonEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_item_edited"), &GDNativeLibrarySingletonEditor::_item_edited);
ClassDB::bind_method(D_METHOD("_discover_singletons"), &GDNativeLibrarySingletonEditor::_discover_singletons);
ClassDB::bind_method(D_METHOD("_update_libraries"), &GDNativeLibrarySingletonEditor::_update_libraries);
}
GDNativeLibrarySingletonEditor::GDNativeLibrarySingletonEditor() {
undo_redo = EditorNode::get_singleton()->get_undo_redo();
libraries = memnew(Tree);
libraries->set_columns(2);
libraries->set_column_titles_visible(true);
libraries->set_column_title(0, TTR("Library"));
libraries->set_column_title(1, TTR("Status"));
libraries->set_hide_root(true);
add_margin_child(TTR("Libraries:"), libraries, true);
updating = false;
libraries->connect("item_edited", this, "_item_edited");
EditorFileSystem::get_singleton()->connect("filesystem_changed", this, "_discover_singletons");
}
#endif // TOOLS_ENABLED

View File

@ -0,0 +1,63 @@
/**************************************************************************/
/* gdnative_library_singleton_editor.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_LIBRARY_SINGLETON_EDITOR_H
#define GDNATIVE_LIBRARY_SINGLETON_EDITOR_H
#ifdef TOOLS_ENABLED
#include "editor/editor_file_system.h"
#include "editor/project_settings_editor.h"
class GDNativeLibrarySingletonEditor : public VBoxContainer {
GDCLASS(GDNativeLibrarySingletonEditor, VBoxContainer);
private:
Tree *libraries;
UndoRedo *undo_redo;
bool updating;
static Set<String> _find_singletons_recursive(EditorFileSystemDirectory *p_dir);
protected:
void _notification(int p_what);
static void _bind_methods();
void _discover_singletons();
void _item_edited();
void _update_libraries();
public:
GDNativeLibrarySingletonEditor();
};
#endif
#endif // GDNATIVE_LIBRARY_SINGLETON_EDITOR_H

View File

@ -0,0 +1,5 @@
<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<g transform="translate(0 -1036.4)">
<path transform="translate(0 1036.4)" d="m7 1l-0.56445 2.2578a5 5 0 0 0 -0.68945 0.2793l-1.9883-1.1934-1.4141 1.4141 1.1953 1.9941a5 5 0 0 0 -0.28516 0.68555l-2.2539 0.5625v2l2.2578 0.56445a5 5 0 0 0 0.2793 0.6875l-1.1934 1.9902 1.4141 1.4141 1.9941-1.1953a5 5 0 0 0 0.68555 0.28516l0.5625 2.2539v-5.2695a2 2 0 0 1 -1 -1.7305 2 2 0 0 1 1 -1.7285v-0.27148h1 4.5762a5 5 0 0 0 -0.11328 -0.25195l1.1934-1.9902-1.4141-1.4141-1.9941 1.1953a5 5 0 0 0 -0.68555 -0.28516l-0.5625-2.2539h-2zm2 7v1 5 1h5c0.55228 0 1-0.4477 1-1v-5c0-0.5523-0.44772-1-1-1v4l-1-1-1 1v-4h-3z" fill="#e0e0e0"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 725 B

View File

@ -0,0 +1,5 @@
<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<g transform="translate(0 -1036.4)">
<path transform="translate(0 1036.4)" d="m7 1l-0.56445 2.2578a5 5 0 0 0 -0.68945 0.2793l-1.9883-1.1934-1.4141 1.4141 1.1953 1.9941a5 5 0 0 0 -0.28516 0.68555l-2.2539 0.5625h3v1 1h2v-0.95117a2 2 0 0 1 0 -0.048828 2 2 0 0 1 2 -2 2 2 0 0 1 2 2v1h5v-2l-2.2578-0.56445a5 5 0 0 0 -0.2793 -0.6875l1.1934-1.9902-1.4141-1.4141-1.9941 1.1953a5 5 0 0 0 -0.68555 -0.28516l-0.5625-2.2539h-2zm-6 7v4 4h2a3 3 0 0 0 3 -3 3 3 0 0 0 -3 -3v-2h-2zm6 0v2h2v-2h-2zm3 2v6h2v-4a1 1 0 0 1 1 1v3h2v-3a3 3 0 0 0 -3 -3h-2zm-7 2a1 1 0 0 1 1 1 1 1 0 0 1 -1 1v-2zm4 0v4h2v-4h-2z" fill="#e0e0e0"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 713 B

View File

@ -0,0 +1,56 @@
/**************************************************************************/
/* godot_android.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GODOT_ANDROID_H
#define GODOT_ANDROID_H
#include <gdnative/gdnative.h>
#ifdef __ANDROID__
#include <jni.h>
#else
#define JNIEnv void
#define jobject void *
#endif
#ifdef __cplusplus
extern "C" {
#endif
JNIEnv *GDAPI godot_android_get_env();
jobject GDAPI godot_android_get_activity();
jobject GDAPI godot_android_get_surface();
bool GDAPI godot_android_is_activity_resumed();
#ifdef __cplusplus
}
#endif
#endif // GODOT_ANDROID_H

98
include/arvr/godot_arvr.h Normal file
View File

@ -0,0 +1,98 @@
/**************************************************************************/
/* godot_arvr.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GODOT_ARVR_H
#define GODOT_ARVR_H
#include <gdnative/gdnative.h>
#ifdef __cplusplus
extern "C" {
#endif
// For future versions of the API we should only add new functions at the end of the structure and use the
// version info to detect whether a call is available
// Use these to populate version in your plugin
#define GODOTVR_API_MAJOR 1
#define GODOTVR_API_MINOR 2
typedef struct {
godot_gdnative_api_version version; /* version of our API */
void *(*constructor)(godot_object *);
void (*destructor)(void *);
godot_string (*get_name)(const void *);
godot_int (*get_capabilities)(const void *);
godot_bool (*get_anchor_detection_is_enabled)(const void *);
void (*set_anchor_detection_is_enabled)(void *, godot_bool);
godot_bool (*is_stereo)(const void *);
godot_bool (*is_initialized)(const void *);
godot_bool (*initialize)(void *);
void (*uninitialize)(void *);
godot_vector2 (*get_render_targetsize)(const void *);
godot_transform (*get_transform_for_eye)(void *, godot_int, godot_transform *);
void (*fill_projection_for_eye)(void *, godot_real *, godot_int, godot_real, godot_real, godot_real);
void (*commit_for_eye)(void *, godot_int, godot_rid *, godot_rect2 *);
void (*process)(void *);
// only in 1.1 onwards
godot_int (*get_external_texture_for_eye)(void *, godot_int);
void (*notification)(void *, godot_int);
godot_int (*get_camera_feed_id)(void *);
// only in 1.2 onwards
godot_int (*get_external_depth_for_eye)(void *, godot_int);
} godot_arvr_interface_gdnative;
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();
godot_transform GDAPI godot_arvr_get_reference_frame();
// helper functions for rendering
void GDAPI godot_arvr_blit(godot_int p_eye, godot_rid *p_render_target, godot_rect2 *p_rect);
godot_int GDAPI godot_arvr_get_texid(godot_rid *p_render_target);
// helper functions for updating ARVR controllers
godot_int GDAPI godot_arvr_add_controller(char *p_device_name, godot_int p_hand, godot_bool p_tracks_orientation, godot_bool p_tracks_position);
void GDAPI godot_arvr_remove_controller(godot_int p_controller_id);
void GDAPI godot_arvr_set_controller_transform(godot_int p_controller_id, godot_transform *p_transform, godot_bool p_tracks_orientation, godot_bool p_tracks_position);
void GDAPI godot_arvr_set_controller_button(godot_int p_controller_id, godot_int p_button, godot_bool p_is_pressed);
void GDAPI godot_arvr_set_controller_axis(godot_int p_controller_id, godot_int p_axis, godot_real p_value, godot_bool p_can_be_negative);
godot_real GDAPI godot_arvr_get_controller_rumble(godot_int p_controller_id);
// ARVR 1.2 functions
void GDAPI godot_arvr_set_interface(godot_object *p_arvr_interface, const godot_arvr_interface_gdnative *p_gdn_interface);
godot_int GDAPI godot_arvr_get_depthid(godot_rid *p_render_target);
#ifdef __cplusplus
}
#endif
#endif // GODOT_ARVR_H

118
include/gdnative/aabb.h Normal file
View File

@ -0,0 +1,118 @@
/**************************************************************************/
/* aabb.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_AABB_H
#define GDNATIVE_AABB_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#define GODOT_AABB_SIZE 24
#ifndef GODOT_CORE_API_GODOT_AABB_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_AABB_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_AABB_SIZE];
} godot_aabb;
#endif
// reduce extern "C" nesting for VS2013
#ifdef __cplusplus
}
#endif
#include <gdnative/gdnative.h>
#include <gdnative/plane.h>
#include <gdnative/vector3.h>
#ifdef __cplusplus
extern "C" {
#endif
void GDAPI godot_aabb_new(godot_aabb *r_dest, const godot_vector3 *p_pos, const godot_vector3 *p_size);
godot_vector3 GDAPI godot_aabb_get_position(const godot_aabb *p_self);
void GDAPI godot_aabb_set_position(const godot_aabb *p_self, const godot_vector3 *p_v);
godot_vector3 GDAPI godot_aabb_get_size(const godot_aabb *p_self);
void GDAPI godot_aabb_set_size(const godot_aabb *p_self, const godot_vector3 *p_v);
godot_string GDAPI godot_aabb_as_string(const godot_aabb *p_self);
godot_real GDAPI godot_aabb_get_area(const godot_aabb *p_self);
godot_bool GDAPI godot_aabb_has_no_area(const godot_aabb *p_self);
godot_bool GDAPI godot_aabb_has_no_surface(const godot_aabb *p_self);
godot_bool GDAPI godot_aabb_intersects(const godot_aabb *p_self, const godot_aabb *p_with);
godot_bool GDAPI godot_aabb_encloses(const godot_aabb *p_self, const godot_aabb *p_with);
godot_aabb GDAPI godot_aabb_merge(const godot_aabb *p_self, const godot_aabb *p_with);
godot_aabb GDAPI godot_aabb_intersection(const godot_aabb *p_self, const godot_aabb *p_with);
godot_bool GDAPI godot_aabb_intersects_plane(const godot_aabb *p_self, const godot_plane *p_plane);
godot_bool GDAPI godot_aabb_intersects_segment(const godot_aabb *p_self, const godot_vector3 *p_from, const godot_vector3 *p_to);
godot_bool GDAPI godot_aabb_has_point(const godot_aabb *p_self, const godot_vector3 *p_point);
godot_vector3 GDAPI godot_aabb_get_support(const godot_aabb *p_self, const godot_vector3 *p_dir);
godot_vector3 GDAPI godot_aabb_get_longest_axis(const godot_aabb *p_self);
godot_int GDAPI godot_aabb_get_longest_axis_index(const godot_aabb *p_self);
godot_real GDAPI godot_aabb_get_longest_axis_size(const godot_aabb *p_self);
godot_vector3 GDAPI godot_aabb_get_shortest_axis(const godot_aabb *p_self);
godot_int GDAPI godot_aabb_get_shortest_axis_index(const godot_aabb *p_self);
godot_real GDAPI godot_aabb_get_shortest_axis_size(const godot_aabb *p_self);
godot_aabb GDAPI godot_aabb_expand(const godot_aabb *p_self, const godot_vector3 *p_to_point);
godot_aabb GDAPI godot_aabb_grow(const godot_aabb *p_self, const godot_real p_by);
godot_vector3 GDAPI godot_aabb_get_endpoint(const godot_aabb *p_self, const godot_int p_idx);
godot_bool GDAPI godot_aabb_operator_equal(const godot_aabb *p_self, const godot_aabb *p_b);
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_AABB_H

147
include/gdnative/array.h Normal file
View File

@ -0,0 +1,147 @@
/**************************************************************************/
/* array.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_ARRAY_H
#define GDNATIVE_ARRAY_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#define GODOT_ARRAY_SIZE sizeof(void *)
#ifndef GODOT_CORE_API_GODOT_ARRAY_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_ARRAY_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_ARRAY_SIZE];
} godot_array;
#endif
// reduce extern "C" nesting for VS2013
#ifdef __cplusplus
}
#endif
#include <gdnative/pool_arrays.h>
#include <gdnative/variant.h>
#include <gdnative/gdnative.h>
#ifdef __cplusplus
extern "C" {
#endif
void GDAPI godot_array_new(godot_array *r_dest);
void GDAPI godot_array_new_copy(godot_array *r_dest, const godot_array *p_src);
void GDAPI godot_array_new_pool_color_array(godot_array *r_dest, const godot_pool_color_array *p_pca);
void GDAPI godot_array_new_pool_vector3_array(godot_array *r_dest, const godot_pool_vector3_array *p_pv3a);
void GDAPI godot_array_new_pool_vector2_array(godot_array *r_dest, const godot_pool_vector2_array *p_pv2a);
void GDAPI godot_array_new_pool_string_array(godot_array *r_dest, const godot_pool_string_array *p_psa);
void GDAPI godot_array_new_pool_real_array(godot_array *r_dest, const godot_pool_real_array *p_pra);
void GDAPI godot_array_new_pool_int_array(godot_array *r_dest, const godot_pool_int_array *p_pia);
void GDAPI godot_array_new_pool_byte_array(godot_array *r_dest, const godot_pool_byte_array *p_pba);
void GDAPI godot_array_set(godot_array *p_self, const godot_int p_idx, const godot_variant *p_value);
godot_variant GDAPI godot_array_get(const godot_array *p_self, const godot_int p_idx);
godot_variant GDAPI *godot_array_operator_index(godot_array *p_self, const godot_int p_idx);
const godot_variant GDAPI *godot_array_operator_index_const(const godot_array *p_self, const godot_int p_idx);
void GDAPI godot_array_append(godot_array *p_self, const godot_variant *p_value);
void GDAPI godot_array_clear(godot_array *p_self);
godot_int GDAPI godot_array_count(const godot_array *p_self, const godot_variant *p_value);
godot_bool GDAPI godot_array_empty(const godot_array *p_self);
void GDAPI godot_array_erase(godot_array *p_self, const godot_variant *p_value);
godot_variant GDAPI godot_array_front(const godot_array *p_self);
godot_variant GDAPI godot_array_back(const godot_array *p_self);
godot_int GDAPI godot_array_find(const godot_array *p_self, const godot_variant *p_what, const godot_int p_from);
godot_int GDAPI godot_array_find_last(const godot_array *p_self, const godot_variant *p_what);
godot_bool GDAPI godot_array_has(const godot_array *p_self, const godot_variant *p_value);
godot_int GDAPI godot_array_hash(const godot_array *p_self);
void GDAPI godot_array_insert(godot_array *p_self, const godot_int p_pos, const godot_variant *p_value);
void GDAPI godot_array_invert(godot_array *p_self);
godot_variant GDAPI godot_array_pop_back(godot_array *p_self);
godot_variant GDAPI godot_array_pop_front(godot_array *p_self);
void GDAPI godot_array_push_back(godot_array *p_self, const godot_variant *p_value);
void GDAPI godot_array_push_front(godot_array *p_self, const godot_variant *p_value);
void GDAPI godot_array_remove(godot_array *p_self, const godot_int p_idx);
void GDAPI godot_array_resize(godot_array *p_self, const godot_int p_size);
godot_int GDAPI godot_array_rfind(const godot_array *p_self, const godot_variant *p_what, const godot_int p_from);
godot_int GDAPI godot_array_size(const godot_array *p_self);
void GDAPI godot_array_sort(godot_array *p_self);
void GDAPI godot_array_sort_custom(godot_array *p_self, godot_object *p_obj, const godot_string *p_func);
godot_int GDAPI godot_array_bsearch(godot_array *p_self, const godot_variant *p_value, const godot_bool p_before);
godot_int GDAPI godot_array_bsearch_custom(godot_array *p_self, const godot_variant *p_value, godot_object *p_obj, const godot_string *p_func, const godot_bool p_before);
void GDAPI godot_array_destroy(godot_array *p_self);
godot_array GDAPI godot_array_duplicate(const godot_array *p_self, const godot_bool p_deep);
godot_array GDAPI godot_array_slice(const godot_array *p_self, const godot_int p_begin, const godot_int p_end, const godot_int p_step, const godot_bool p_deep);
godot_variant GDAPI godot_array_max(const godot_array *p_self);
godot_variant GDAPI godot_array_min(const godot_array *p_self);
void GDAPI godot_array_shuffle(godot_array *p_self);
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_ARRAY_H

136
include/gdnative/basis.h Normal file
View File

@ -0,0 +1,136 @@
/**************************************************************************/
/* basis.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_BASIS_H
#define GDNATIVE_BASIS_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#define GODOT_BASIS_SIZE 36
#ifndef GODOT_CORE_API_GODOT_BASIS_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_BASIS_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_BASIS_SIZE];
} godot_basis;
#endif
// reduce extern "C" nesting for VS2013
#ifdef __cplusplus
}
#endif
#include <gdnative/gdnative.h>
#include <gdnative/quat.h>
#include <gdnative/vector3.h>
#ifdef __cplusplus
extern "C" {
#endif
void GDAPI godot_basis_new_with_rows(godot_basis *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis);
void GDAPI godot_basis_new_with_axis_and_angle(godot_basis *r_dest, const godot_vector3 *p_axis, const godot_real p_phi);
void GDAPI godot_basis_new_with_euler(godot_basis *r_dest, const godot_vector3 *p_euler);
void GDAPI godot_basis_new_with_euler_quat(godot_basis *r_dest, const godot_quat *p_euler);
godot_string GDAPI godot_basis_as_string(const godot_basis *p_self);
godot_basis GDAPI godot_basis_inverse(const godot_basis *p_self);
godot_basis GDAPI godot_basis_transposed(const godot_basis *p_self);
godot_basis GDAPI godot_basis_orthonormalized(const godot_basis *p_self);
godot_real GDAPI godot_basis_determinant(const godot_basis *p_self);
godot_basis GDAPI godot_basis_rotated(const godot_basis *p_self, const godot_vector3 *p_axis, const godot_real p_phi);
godot_basis GDAPI godot_basis_scaled(const godot_basis *p_self, const godot_vector3 *p_scale);
godot_vector3 GDAPI godot_basis_get_scale(const godot_basis *p_self);
godot_vector3 GDAPI godot_basis_get_euler(const godot_basis *p_self);
godot_quat GDAPI godot_basis_get_quat(const godot_basis *p_self);
void GDAPI godot_basis_set_quat(godot_basis *p_self, const godot_quat *p_quat);
void GDAPI godot_basis_set_axis_angle_scale(godot_basis *p_self, const godot_vector3 *p_axis, godot_real p_phi, const godot_vector3 *p_scale);
void GDAPI godot_basis_set_euler_scale(godot_basis *p_self, const godot_vector3 *p_euler, const godot_vector3 *p_scale);
void GDAPI godot_basis_set_quat_scale(godot_basis *p_self, const godot_quat *p_quat, const godot_vector3 *p_scale);
godot_real GDAPI godot_basis_tdotx(const godot_basis *p_self, const godot_vector3 *p_with);
godot_real GDAPI godot_basis_tdoty(const godot_basis *p_self, const godot_vector3 *p_with);
godot_real GDAPI godot_basis_tdotz(const godot_basis *p_self, const godot_vector3 *p_with);
godot_vector3 GDAPI godot_basis_xform(const godot_basis *p_self, const godot_vector3 *p_v);
godot_vector3 GDAPI godot_basis_xform_inv(const godot_basis *p_self, const godot_vector3 *p_v);
godot_int GDAPI godot_basis_get_orthogonal_index(const godot_basis *p_self);
void GDAPI godot_basis_new(godot_basis *r_dest);
// p_elements is a pointer to an array of 3 (!!) vector3
void GDAPI godot_basis_get_elements(const godot_basis *p_self, godot_vector3 *p_elements);
godot_vector3 GDAPI godot_basis_get_axis(const godot_basis *p_self, const godot_int p_axis);
void GDAPI godot_basis_set_axis(godot_basis *p_self, const godot_int p_axis, const godot_vector3 *p_value);
godot_vector3 GDAPI godot_basis_get_row(const godot_basis *p_self, const godot_int p_row);
void GDAPI godot_basis_set_row(godot_basis *p_self, const godot_int p_row, const godot_vector3 *p_value);
godot_bool GDAPI godot_basis_operator_equal(const godot_basis *p_self, const godot_basis *p_b);
godot_basis GDAPI godot_basis_operator_add(const godot_basis *p_self, const godot_basis *p_b);
godot_basis GDAPI godot_basis_operator_subtract(const godot_basis *p_self, const godot_basis *p_b);
godot_basis GDAPI godot_basis_operator_multiply_vector(const godot_basis *p_self, const godot_basis *p_b);
godot_basis GDAPI godot_basis_operator_multiply_scalar(const godot_basis *p_self, const godot_real p_b);
godot_basis GDAPI godot_basis_slerp(const godot_basis *p_self, const godot_basis *p_b, const godot_real p_t);
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_BASIS_H

120
include/gdnative/color.h Normal file
View File

@ -0,0 +1,120 @@
/**************************************************************************/
/* color.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_COLOR_H
#define GDNATIVE_COLOR_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#define GODOT_COLOR_SIZE 16
#ifndef GODOT_CORE_API_GODOT_COLOR_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_COLOR_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_COLOR_SIZE];
} godot_color;
#endif
// reduce extern "C" nesting for VS2013
#ifdef __cplusplus
}
#endif
#include <gdnative/gdnative.h>
#include <gdnative/string.h>
#ifdef __cplusplus
extern "C" {
#endif
void GDAPI godot_color_new_rgba(godot_color *r_dest, const godot_real p_r, const godot_real p_g, const godot_real p_b, const godot_real p_a);
void GDAPI godot_color_new_rgb(godot_color *r_dest, const godot_real p_r, const godot_real p_g, const godot_real p_b);
godot_real godot_color_get_r(const godot_color *p_self);
void godot_color_set_r(godot_color *p_self, const godot_real r);
godot_real godot_color_get_g(const godot_color *p_self);
void godot_color_set_g(godot_color *p_self, const godot_real g);
godot_real godot_color_get_b(const godot_color *p_self);
void godot_color_set_b(godot_color *p_self, const godot_real b);
godot_real godot_color_get_a(const godot_color *p_self);
void godot_color_set_a(godot_color *p_self, const godot_real a);
godot_real godot_color_get_h(const godot_color *p_self);
godot_real godot_color_get_s(const godot_color *p_self);
godot_real godot_color_get_v(const godot_color *p_self);
godot_string GDAPI godot_color_as_string(const godot_color *p_self);
godot_int GDAPI godot_color_to_rgba32(const godot_color *p_self);
godot_int GDAPI godot_color_to_abgr32(const godot_color *p_self);
godot_int GDAPI godot_color_to_abgr64(const godot_color *p_self);
godot_int GDAPI godot_color_to_argb64(const godot_color *p_self);
godot_int GDAPI godot_color_to_rgba64(const godot_color *p_self);
godot_int GDAPI godot_color_to_argb32(const godot_color *p_self);
godot_real GDAPI godot_color_gray(const godot_color *p_self);
godot_color GDAPI godot_color_inverted(const godot_color *p_self);
godot_color GDAPI godot_color_contrasted(const godot_color *p_self);
godot_color GDAPI godot_color_linear_interpolate(const godot_color *p_self, const godot_color *p_b, const godot_real p_t);
godot_color GDAPI godot_color_blend(const godot_color *p_self, const godot_color *p_over);
godot_color GDAPI godot_color_darkened(const godot_color *p_self, const godot_real p_amount);
godot_color GDAPI godot_color_from_hsv(const godot_color *p_self, const godot_real p_h, const godot_real p_s, const godot_real p_v, const godot_real p_a);
godot_color GDAPI godot_color_lightened(const godot_color *p_self, const godot_real p_amount);
godot_string GDAPI godot_color_to_html(const godot_color *p_self, const godot_bool p_with_alpha);
godot_bool GDAPI godot_color_operator_equal(const godot_color *p_self, const godot_color *p_b);
godot_bool GDAPI godot_color_operator_less(const godot_color *p_self, const godot_color *p_b);
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_COLOR_H

View File

@ -0,0 +1,113 @@
/**************************************************************************/
/* dictionary.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_DICTIONARY_H
#define GDNATIVE_DICTIONARY_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#define GODOT_DICTIONARY_SIZE sizeof(void *)
#ifndef GODOT_CORE_API_GODOT_DICTIONARY_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_DICTIONARY_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_DICTIONARY_SIZE];
} godot_dictionary;
#endif
// reduce extern "C" nesting for VS2013
#ifdef __cplusplus
}
#endif
#include <gdnative/array.h>
#include <gdnative/gdnative.h>
#include <gdnative/variant.h>
#ifdef __cplusplus
extern "C" {
#endif
void GDAPI godot_dictionary_new(godot_dictionary *r_dest);
void GDAPI godot_dictionary_new_copy(godot_dictionary *r_dest, const godot_dictionary *p_src);
void GDAPI godot_dictionary_destroy(godot_dictionary *p_self);
godot_dictionary GDAPI godot_dictionary_duplicate(const godot_dictionary *p_self, const godot_bool p_deep);
godot_int GDAPI godot_dictionary_size(const godot_dictionary *p_self);
godot_bool GDAPI godot_dictionary_empty(const godot_dictionary *p_self);
void GDAPI godot_dictionary_clear(godot_dictionary *p_self);
godot_bool GDAPI godot_dictionary_has(const godot_dictionary *p_self, const godot_variant *p_key);
godot_bool GDAPI godot_dictionary_has_all(const godot_dictionary *p_self, const godot_array *p_keys);
void GDAPI godot_dictionary_erase(godot_dictionary *p_self, const godot_variant *p_key);
godot_int GDAPI godot_dictionary_hash(const godot_dictionary *p_self);
godot_array GDAPI godot_dictionary_keys(const godot_dictionary *p_self);
godot_array GDAPI godot_dictionary_values(const godot_dictionary *p_self);
godot_variant GDAPI godot_dictionary_get(const godot_dictionary *p_self, const godot_variant *p_key);
void GDAPI godot_dictionary_set(godot_dictionary *p_self, const godot_variant *p_key, const godot_variant *p_value);
godot_variant GDAPI *godot_dictionary_operator_index(godot_dictionary *p_self, const godot_variant *p_key);
const godot_variant GDAPI *godot_dictionary_operator_index_const(const godot_dictionary *p_self, const godot_variant *p_key);
godot_variant GDAPI *godot_dictionary_next(const godot_dictionary *p_self, const godot_variant *p_key);
godot_bool GDAPI godot_dictionary_operator_equal(const godot_dictionary *p_self, const godot_dictionary *p_b);
godot_string GDAPI godot_dictionary_to_json(const godot_dictionary *p_self);
// GDNative core 1.1
godot_bool GDAPI godot_dictionary_erase_with_return(godot_dictionary *p_self, const godot_variant *p_key);
godot_variant GDAPI godot_dictionary_get_with_default(const godot_dictionary *p_self, const godot_variant *p_key, const godot_variant *p_default);
// GDNative core 1.3
void GDAPI godot_dictionary_merge(godot_dictionary *p_self, const godot_dictionary *p_dictionary, const godot_bool p_overwrite);
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_DICTIONARY_H

304
include/gdnative/gdnative.h Normal file
View File

@ -0,0 +1,304 @@
/**************************************************************************/
/* gdnative.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_GDNATIVE_H
#define GDNATIVE_GDNATIVE_H
#ifdef __cplusplus
extern "C" {
#endif
#if defined(_WIN32) || defined(__ANDROID__)
#define GDCALLINGCONV
#define GDAPI GDCALLINGCONV
#elif defined(__APPLE__)
#include "TargetConditionals.h"
#if TARGET_OS_IPHONE
#define GDCALLINGCONV __attribute__((visibility("default")))
#define GDAPI GDCALLINGCONV
#elif TARGET_OS_MAC
#define GDCALLINGCONV __attribute__((sysv_abi))
#define GDAPI GDCALLINGCONV
#endif
#else // !_WIN32 && !__APPLE__
#define GDCALLINGCONV __attribute__((sysv_abi))
#define GDAPI GDCALLINGCONV
#endif
// This is for libraries *using* the header, NOT GODOT EXPOSING STUFF!!
#if !defined(GDN_EXPORT)
#if defined(_WIN32)
#define GDN_EXPORT __declspec(dllexport)
#elif defined(__GNUC__)
#define GDN_EXPORT __attribute__((visibility("default")))
#else
#define GDN_EXPORT
#endif
#endif
#include <stdbool.h>
#include <stdint.h>
#define GODOT_API_VERSION 1
////// Error
typedef enum {
GODOT_OK, // (0)
GODOT_FAILED, ///< Generic fail error
GODOT_ERR_UNAVAILABLE, ///< What is requested is unsupported/unavailable
GODOT_ERR_UNCONFIGURED, ///< The object being used hasn't been properly set up yet
GODOT_ERR_UNAUTHORIZED, ///< Missing credentials for requested resource
GODOT_ERR_PARAMETER_RANGE_ERROR, ///< Parameter given out of range (5)
GODOT_ERR_OUT_OF_MEMORY, ///< Out of memory
GODOT_ERR_FILE_NOT_FOUND,
GODOT_ERR_FILE_BAD_DRIVE,
GODOT_ERR_FILE_BAD_PATH,
GODOT_ERR_FILE_NO_PERMISSION, // (10)
GODOT_ERR_FILE_ALREADY_IN_USE,
GODOT_ERR_FILE_CANT_OPEN,
GODOT_ERR_FILE_CANT_WRITE,
GODOT_ERR_FILE_CANT_READ,
GODOT_ERR_FILE_UNRECOGNIZED, // (15)
GODOT_ERR_FILE_CORRUPT,
GODOT_ERR_FILE_MISSING_DEPENDENCIES,
GODOT_ERR_FILE_EOF,
GODOT_ERR_CANT_OPEN, ///< Can't open a resource/socket/file
GODOT_ERR_CANT_CREATE, // (20)
GODOT_ERR_QUERY_FAILED,
GODOT_ERR_ALREADY_IN_USE,
GODOT_ERR_LOCKED, ///< resource is locked
GODOT_ERR_TIMEOUT,
GODOT_ERR_CANT_CONNECT, // (25)
GODOT_ERR_CANT_RESOLVE,
GODOT_ERR_CONNECTION_ERROR,
GODOT_ERR_CANT_ACQUIRE_RESOURCE,
GODOT_ERR_CANT_FORK,
GODOT_ERR_INVALID_DATA, ///< Data passed is invalid (30)
GODOT_ERR_INVALID_PARAMETER, ///< Parameter passed is invalid
GODOT_ERR_ALREADY_EXISTS, ///< When adding, item already exists
GODOT_ERR_DOES_NOT_EXIST, ///< When retrieving/erasing, it item does not exist
GODOT_ERR_DATABASE_CANT_READ, ///< database is full
GODOT_ERR_DATABASE_CANT_WRITE, ///< database is full (35)
GODOT_ERR_COMPILATION_FAILED,
GODOT_ERR_METHOD_NOT_FOUND,
GODOT_ERR_LINK_FAILED,
GODOT_ERR_SCRIPT_FAILED,
GODOT_ERR_CYCLIC_LINK, // (40)
GODOT_ERR_INVALID_DECLARATION,
GODOT_ERR_DUPLICATE_SYMBOL,
GODOT_ERR_PARSE_ERROR,
GODOT_ERR_BUSY,
GODOT_ERR_SKIP, // (45)
GODOT_ERR_HELP, ///< user requested help!!
GODOT_ERR_BUG, ///< a bug in the software certainly happened, due to a double check failing or unexpected behavior.
GODOT_ERR_PRINTER_ON_FIRE, /// the parallel port printer is engulfed in flames
} godot_error;
////// bool
typedef bool godot_bool;
#define GODOT_TRUE 1
#define GODOT_FALSE 0
/////// int
typedef int godot_int;
/////// real
typedef float godot_real;
/////// Object (forward declared)
typedef void godot_object;
/////// String
#include <gdnative/string.h>
/////// String name
#include <gdnative/string_name.h>
////// Vector2
#include <gdnative/vector2.h>
////// Rect2
#include <gdnative/rect2.h>
////// Vector3
#include <gdnative/vector3.h>
////// Transform2D
#include <gdnative/transform2d.h>
/////// Plane
#include <gdnative/plane.h>
/////// Quat
#include <gdnative/quat.h>
/////// AABB
#include <gdnative/aabb.h>
/////// Basis
#include <gdnative/basis.h>
/////// Transform
#include <gdnative/transform.h>
/////// Color
#include <gdnative/color.h>
/////// NodePath
#include <gdnative/node_path.h>
/////// RID
#include <gdnative/rid.h>
/////// Dictionary
#include <gdnative/dictionary.h>
/////// Array
#include <gdnative/array.h>
// single API file for Pool*Array
#include <gdnative/pool_arrays.h>
void GDAPI godot_object_destroy(godot_object *p_o);
////// Variant
#include <gdnative/variant.h>
////// Singleton API
godot_object GDAPI *godot_global_get_singleton(char *p_name); // result shouldn't be freed
////// MethodBind API
typedef struct {
uint8_t _dont_touch_that[1]; // TODO
} godot_method_bind;
godot_method_bind GDAPI *godot_method_bind_get_method(const char *p_classname, const char *p_methodname);
void GDAPI godot_method_bind_ptrcall(godot_method_bind *p_method_bind, godot_object *p_instance, const void **p_args, void *p_ret);
godot_variant GDAPI godot_method_bind_call(godot_method_bind *p_method_bind, godot_object *p_instance, const godot_variant **p_args, const int p_arg_count, godot_variant_call_error *p_call_error);
////// Script API
typedef struct godot_gdnative_api_version {
unsigned int major;
unsigned int minor;
} godot_gdnative_api_version;
typedef struct godot_gdnative_api_struct godot_gdnative_api_struct;
struct godot_gdnative_api_struct {
unsigned int type;
godot_gdnative_api_version version;
const godot_gdnative_api_struct *next;
};
#define GDNATIVE_VERSION_COMPATIBLE(want, have) (want.major == have.major && want.minor <= have.minor)
typedef struct {
godot_bool in_editor;
uint64_t core_api_hash;
uint64_t editor_api_hash;
uint64_t no_api_hash;
void (*report_version_mismatch)(const godot_object *p_library, const char *p_what, godot_gdnative_api_version p_want, godot_gdnative_api_version p_have);
void (*report_loading_error)(const godot_object *p_library, const char *p_what);
godot_object *gd_native_library; // pointer to GDNativeLibrary that is being initialized
const struct godot_gdnative_core_api_struct *api_struct;
const godot_string *active_library_path;
} godot_gdnative_init_options;
typedef struct {
godot_bool in_editor;
} godot_gdnative_terminate_options;
// Calling convention?
typedef godot_object *(*godot_class_constructor)();
godot_class_constructor GDAPI godot_get_class_constructor(const char *p_classname);
godot_dictionary GDAPI godot_get_global_constants();
////// GDNative procedure types
typedef void (*godot_gdnative_init_fn)(godot_gdnative_init_options *);
typedef void (*godot_gdnative_terminate_fn)(godot_gdnative_terminate_options *);
typedef godot_variant (*godot_gdnative_procedure_fn)(godot_array *);
////// System Functions
typedef godot_variant (*native_call_cb)(void *, godot_array *);
void GDAPI godot_register_native_call_type(const char *p_call_type, native_call_cb p_callback);
//using these will help Godot track how much memory is in use in debug mode
void GDAPI *godot_alloc(int p_bytes);
void GDAPI *godot_realloc(void *p_ptr, int p_bytes);
void GDAPI godot_free(void *p_ptr);
//print using Godot's error handler list
void GDAPI godot_print_error(const char *p_description, const char *p_function, const char *p_file, int p_line);
void GDAPI godot_print_warning(const char *p_description, const char *p_function, const char *p_file, int p_line);
void GDAPI godot_print(const godot_string *p_message);
// GDNATIVE CORE 1.0.1
bool GDAPI godot_is_instance_valid(const godot_object *p_object);
//tags used for safe dynamic casting
void GDAPI *godot_get_class_tag(const godot_string_name *p_class);
godot_object GDAPI *godot_object_cast_to(const godot_object *p_object, void *p_class_tag);
// equivalent of GDScript's instance_from_id
godot_object GDAPI *godot_instance_from_id(godot_int p_instance_id);
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_GDNATIVE_H

View File

@ -0,0 +1,89 @@
/**************************************************************************/
/* node_path.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_NODE_PATH_H
#define GDNATIVE_NODE_PATH_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#define GODOT_NODE_PATH_SIZE sizeof(void *)
#ifndef GODOT_CORE_API_GODOT_NODE_PATH_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_NODE_PATH_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_NODE_PATH_SIZE];
} godot_node_path;
#endif
// reduce extern "C" nesting for VS2013
#ifdef __cplusplus
}
#endif
#include <gdnative/gdnative.h>
#include <gdnative/string.h>
#ifdef __cplusplus
extern "C" {
#endif
void GDAPI godot_node_path_new(godot_node_path *r_dest, const godot_string *p_from);
void GDAPI godot_node_path_new_copy(godot_node_path *r_dest, const godot_node_path *p_src);
void GDAPI godot_node_path_destroy(godot_node_path *p_self);
godot_string GDAPI godot_node_path_as_string(const godot_node_path *p_self);
godot_bool GDAPI godot_node_path_is_absolute(const godot_node_path *p_self);
godot_int GDAPI godot_node_path_get_name_count(const godot_node_path *p_self);
godot_string GDAPI godot_node_path_get_name(const godot_node_path *p_self, const godot_int p_idx);
godot_int GDAPI godot_node_path_get_subname_count(const godot_node_path *p_self);
godot_string GDAPI godot_node_path_get_subname(const godot_node_path *p_self, const godot_int p_idx);
godot_string GDAPI godot_node_path_get_concatenated_subnames(const godot_node_path *p_self);
godot_bool GDAPI godot_node_path_is_empty(const godot_node_path *p_self);
godot_bool GDAPI godot_node_path_operator_equal(const godot_node_path *p_self, const godot_node_path *p_b);
godot_node_path godot_node_path_get_as_property_path(const godot_node_path *p_self);
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_NODE_PATH_H

103
include/gdnative/plane.h Normal file
View File

@ -0,0 +1,103 @@
/**************************************************************************/
/* plane.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_PLANE_H
#define GDNATIVE_PLANE_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#define GODOT_PLANE_SIZE 16
#ifndef GODOT_CORE_API_GODOT_PLANE_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_PLANE_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_PLANE_SIZE];
} godot_plane;
#endif
// reduce extern "C" nesting for VS2013
#ifdef __cplusplus
}
#endif
#include <gdnative/gdnative.h>
#include <gdnative/vector3.h>
#ifdef __cplusplus
extern "C" {
#endif
void GDAPI godot_plane_new_with_reals(godot_plane *r_dest, const godot_real p_a, const godot_real p_b, const godot_real p_c, const godot_real p_d);
void GDAPI godot_plane_new_with_vectors(godot_plane *r_dest, const godot_vector3 *p_v1, const godot_vector3 *p_v2, const godot_vector3 *p_v3);
void GDAPI godot_plane_new_with_normal(godot_plane *r_dest, const godot_vector3 *p_normal, const godot_real p_d);
godot_string GDAPI godot_plane_as_string(const godot_plane *p_self);
godot_plane GDAPI godot_plane_normalized(const godot_plane *p_self);
godot_vector3 GDAPI godot_plane_center(const godot_plane *p_self);
godot_vector3 GDAPI godot_plane_get_any_point(const godot_plane *p_self);
godot_bool GDAPI godot_plane_is_point_over(const godot_plane *p_self, const godot_vector3 *p_point);
godot_real GDAPI godot_plane_distance_to(const godot_plane *p_self, const godot_vector3 *p_point);
godot_bool GDAPI godot_plane_has_point(const godot_plane *p_self, const godot_vector3 *p_point, const godot_real p_epsilon);
godot_vector3 GDAPI godot_plane_project(const godot_plane *p_self, const godot_vector3 *p_point);
godot_bool GDAPI godot_plane_intersect_3(const godot_plane *p_self, godot_vector3 *r_dest, const godot_plane *p_b, const godot_plane *p_c);
godot_bool GDAPI godot_plane_intersects_ray(const godot_plane *p_self, godot_vector3 *r_dest, const godot_vector3 *p_from, const godot_vector3 *p_dir);
godot_bool GDAPI godot_plane_intersects_segment(const godot_plane *p_self, godot_vector3 *r_dest, const godot_vector3 *p_begin, const godot_vector3 *p_end);
godot_plane GDAPI godot_plane_operator_neg(const godot_plane *p_self);
godot_bool GDAPI godot_plane_operator_equal(const godot_plane *p_self, const godot_plane *p_b);
void GDAPI godot_plane_set_normal(godot_plane *p_self, const godot_vector3 *p_normal);
godot_vector3 GDAPI godot_plane_get_normal(const godot_plane *p_self);
godot_real GDAPI godot_plane_get_d(const godot_plane *p_self);
void GDAPI godot_plane_set_d(godot_plane *p_self, const godot_real p_d);
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_PLANE_H

View File

@ -0,0 +1,508 @@
/**************************************************************************/
/* pool_arrays.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_POOL_ARRAYS_H
#define GDNATIVE_POOL_ARRAYS_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/////// Read Access
#define GODOT_POOL_ARRAY_READ_ACCESS_SIZE 1
typedef struct {
uint8_t _dont_touch_that[GODOT_POOL_ARRAY_READ_ACCESS_SIZE];
} godot_pool_array_read_access;
typedef godot_pool_array_read_access godot_pool_byte_array_read_access;
typedef godot_pool_array_read_access godot_pool_int_array_read_access;
typedef godot_pool_array_read_access godot_pool_real_array_read_access;
typedef godot_pool_array_read_access godot_pool_string_array_read_access;
typedef godot_pool_array_read_access godot_pool_vector2_array_read_access;
typedef godot_pool_array_read_access godot_pool_vector3_array_read_access;
typedef godot_pool_array_read_access godot_pool_color_array_read_access;
/////// Write Access
#define GODOT_POOL_ARRAY_WRITE_ACCESS_SIZE 1
typedef struct {
uint8_t _dont_touch_that[GODOT_POOL_ARRAY_WRITE_ACCESS_SIZE];
} godot_pool_array_write_access;
typedef godot_pool_array_write_access godot_pool_byte_array_write_access;
typedef godot_pool_array_write_access godot_pool_int_array_write_access;
typedef godot_pool_array_write_access godot_pool_real_array_write_access;
typedef godot_pool_array_write_access godot_pool_string_array_write_access;
typedef godot_pool_array_write_access godot_pool_vector2_array_write_access;
typedef godot_pool_array_write_access godot_pool_vector3_array_write_access;
typedef godot_pool_array_write_access godot_pool_color_array_write_access;
/////// PoolByteArray
#define GODOT_POOL_BYTE_ARRAY_SIZE sizeof(void *)
#ifndef GODOT_CORE_API_GODOT_POOL_BYTE_ARRAY_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_POOL_BYTE_ARRAY_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_POOL_BYTE_ARRAY_SIZE];
} godot_pool_byte_array;
#endif
/////// PoolIntArray
#define GODOT_POOL_INT_ARRAY_SIZE sizeof(void *)
#ifndef GODOT_CORE_API_GODOT_POOL_INT_ARRAY_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_POOL_INT_ARRAY_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_POOL_INT_ARRAY_SIZE];
} godot_pool_int_array;
#endif
/////// PoolRealArray
#define GODOT_POOL_REAL_ARRAY_SIZE sizeof(void *)
#ifndef GODOT_CORE_API_GODOT_POOL_REAL_ARRAY_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_POOL_REAL_ARRAY_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_POOL_REAL_ARRAY_SIZE];
} godot_pool_real_array;
#endif
/////// PoolStringArray
#define GODOT_POOL_STRING_ARRAY_SIZE sizeof(void *)
#ifndef GODOT_CORE_API_GODOT_POOL_STRING_ARRAY_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_POOL_STRING_ARRAY_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_POOL_STRING_ARRAY_SIZE];
} godot_pool_string_array;
#endif
/////// PoolVector2Array
#define GODOT_POOL_VECTOR2_ARRAY_SIZE sizeof(void *)
#ifndef GODOT_CORE_API_GODOT_POOL_VECTOR2_ARRAY_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_POOL_VECTOR2_ARRAY_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_POOL_VECTOR2_ARRAY_SIZE];
} godot_pool_vector2_array;
#endif
/////// PoolVector3Array
#define GODOT_POOL_VECTOR3_ARRAY_SIZE sizeof(void *)
#ifndef GODOT_CORE_API_GODOT_POOL_VECTOR3_ARRAY_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_POOL_VECTOR3_ARRAY_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_POOL_VECTOR3_ARRAY_SIZE];
} godot_pool_vector3_array;
#endif
/////// PoolColorArray
#define GODOT_POOL_COLOR_ARRAY_SIZE sizeof(void *)
#ifndef GODOT_CORE_API_GODOT_POOL_COLOR_ARRAY_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_POOL_COLOR_ARRAY_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_POOL_COLOR_ARRAY_SIZE];
} godot_pool_color_array;
#endif
// reduce extern "C" nesting for VS2013
#ifdef __cplusplus
}
#endif
#include <gdnative/array.h>
#include <gdnative/color.h>
#include <gdnative/vector2.h>
#include <gdnative/vector3.h>
#include <gdnative/gdnative.h>
#ifdef __cplusplus
extern "C" {
#endif
// byte
void GDAPI godot_pool_byte_array_new(godot_pool_byte_array *r_dest);
void GDAPI godot_pool_byte_array_new_copy(godot_pool_byte_array *r_dest, const godot_pool_byte_array *p_src);
void GDAPI godot_pool_byte_array_new_with_array(godot_pool_byte_array *r_dest, const godot_array *p_a);
void GDAPI godot_pool_byte_array_append(godot_pool_byte_array *p_self, const uint8_t p_data);
void GDAPI godot_pool_byte_array_append_array(godot_pool_byte_array *p_self, const godot_pool_byte_array *p_array);
godot_error GDAPI godot_pool_byte_array_insert(godot_pool_byte_array *p_self, const godot_int p_idx, const uint8_t p_data);
void GDAPI godot_pool_byte_array_invert(godot_pool_byte_array *p_self);
void GDAPI godot_pool_byte_array_push_back(godot_pool_byte_array *p_self, const uint8_t p_data);
void GDAPI godot_pool_byte_array_remove(godot_pool_byte_array *p_self, const godot_int p_idx);
void GDAPI godot_pool_byte_array_resize(godot_pool_byte_array *p_self, const godot_int p_size);
void GDAPI godot_pool_byte_array_sort(godot_pool_byte_array *p_self);
godot_pool_byte_array_read_access GDAPI *godot_pool_byte_array_read(const godot_pool_byte_array *p_self);
godot_pool_byte_array_write_access GDAPI *godot_pool_byte_array_write(godot_pool_byte_array *p_self);
void GDAPI godot_pool_byte_array_set(godot_pool_byte_array *p_self, const godot_int p_idx, const uint8_t p_data);
uint8_t GDAPI godot_pool_byte_array_get(const godot_pool_byte_array *p_self, const godot_int p_idx);
godot_int GDAPI godot_pool_byte_array_size(const godot_pool_byte_array *p_self);
godot_bool GDAPI godot_pool_byte_array_empty(const godot_pool_byte_array *p_self);
godot_bool GDAPI godot_pool_byte_array_has(const godot_pool_byte_array *p_self, const uint8_t p_data);
void GDAPI godot_pool_byte_array_destroy(godot_pool_byte_array *p_self);
// int
void GDAPI godot_pool_int_array_new(godot_pool_int_array *r_dest);
void GDAPI godot_pool_int_array_new_copy(godot_pool_int_array *r_dest, const godot_pool_int_array *p_src);
void GDAPI godot_pool_int_array_new_with_array(godot_pool_int_array *r_dest, const godot_array *p_a);
void GDAPI godot_pool_int_array_append(godot_pool_int_array *p_self, const godot_int p_data);
void GDAPI godot_pool_int_array_append_array(godot_pool_int_array *p_self, const godot_pool_int_array *p_array);
godot_error GDAPI godot_pool_int_array_insert(godot_pool_int_array *p_self, const godot_int p_idx, const godot_int p_data);
void GDAPI godot_pool_int_array_invert(godot_pool_int_array *p_self);
void GDAPI godot_pool_int_array_push_back(godot_pool_int_array *p_self, const godot_int p_data);
void GDAPI godot_pool_int_array_remove(godot_pool_int_array *p_self, const godot_int p_idx);
void GDAPI godot_pool_int_array_resize(godot_pool_int_array *p_self, const godot_int p_size);
void GDAPI godot_pool_int_array_sort(godot_pool_int_array *p_self);
godot_pool_int_array_read_access GDAPI *godot_pool_int_array_read(const godot_pool_int_array *p_self);
godot_pool_int_array_write_access GDAPI *godot_pool_int_array_write(godot_pool_int_array *p_self);
void GDAPI godot_pool_int_array_set(godot_pool_int_array *p_self, const godot_int p_idx, const godot_int p_data);
godot_int GDAPI godot_pool_int_array_get(const godot_pool_int_array *p_self, const godot_int p_idx);
godot_int GDAPI godot_pool_int_array_size(const godot_pool_int_array *p_self);
godot_bool GDAPI godot_pool_int_array_empty(const godot_pool_int_array *p_self);
godot_bool GDAPI godot_pool_int_array_has(const godot_pool_int_array *p_self, const godot_int p_data);
void GDAPI godot_pool_int_array_destroy(godot_pool_int_array *p_self);
// real
void GDAPI godot_pool_real_array_new(godot_pool_real_array *r_dest);
void GDAPI godot_pool_real_array_new_copy(godot_pool_real_array *r_dest, const godot_pool_real_array *p_src);
void GDAPI godot_pool_real_array_new_with_array(godot_pool_real_array *r_dest, const godot_array *p_a);
void GDAPI godot_pool_real_array_append(godot_pool_real_array *p_self, const godot_real p_data);
void GDAPI godot_pool_real_array_append_array(godot_pool_real_array *p_self, const godot_pool_real_array *p_array);
godot_error GDAPI godot_pool_real_array_insert(godot_pool_real_array *p_self, const godot_int p_idx, const godot_real p_data);
void GDAPI godot_pool_real_array_invert(godot_pool_real_array *p_self);
void GDAPI godot_pool_real_array_push_back(godot_pool_real_array *p_self, const godot_real p_data);
void GDAPI godot_pool_real_array_remove(godot_pool_real_array *p_self, const godot_int p_idx);
void GDAPI godot_pool_real_array_resize(godot_pool_real_array *p_self, const godot_int p_size);
void GDAPI godot_pool_real_array_sort(godot_pool_real_array *p_self);
godot_pool_real_array_read_access GDAPI *godot_pool_real_array_read(const godot_pool_real_array *p_self);
godot_pool_real_array_write_access GDAPI *godot_pool_real_array_write(godot_pool_real_array *p_self);
void GDAPI godot_pool_real_array_set(godot_pool_real_array *p_self, const godot_int p_idx, const godot_real p_data);
godot_real GDAPI godot_pool_real_array_get(const godot_pool_real_array *p_self, const godot_int p_idx);
godot_int GDAPI godot_pool_real_array_size(const godot_pool_real_array *p_self);
godot_bool GDAPI godot_pool_real_array_empty(const godot_pool_real_array *p_self);
godot_bool GDAPI godot_pool_real_array_has(const godot_pool_real_array *p_self, const godot_real p_data);
void GDAPI godot_pool_real_array_destroy(godot_pool_real_array *p_self);
// string
void GDAPI godot_pool_string_array_new(godot_pool_string_array *r_dest);
void GDAPI godot_pool_string_array_new_copy(godot_pool_string_array *r_dest, const godot_pool_string_array *p_src);
void GDAPI godot_pool_string_array_new_with_array(godot_pool_string_array *r_dest, const godot_array *p_a);
void GDAPI godot_pool_string_array_append(godot_pool_string_array *p_self, const godot_string *p_data);
void GDAPI godot_pool_string_array_append_array(godot_pool_string_array *p_self, const godot_pool_string_array *p_array);
godot_error GDAPI godot_pool_string_array_insert(godot_pool_string_array *p_self, const godot_int p_idx, const godot_string *p_data);
void GDAPI godot_pool_string_array_invert(godot_pool_string_array *p_self);
godot_string GDAPI godot_pool_string_array_join(const godot_pool_string_array *p_self, const godot_string *p_delimiter);
void GDAPI godot_pool_string_array_push_back(godot_pool_string_array *p_self, const godot_string *p_data);
void GDAPI godot_pool_string_array_remove(godot_pool_string_array *p_self, const godot_int p_idx);
void GDAPI godot_pool_string_array_resize(godot_pool_string_array *p_self, const godot_int p_size);
void GDAPI godot_pool_string_array_sort(godot_pool_string_array *p_self);
godot_pool_string_array_read_access GDAPI *godot_pool_string_array_read(const godot_pool_string_array *p_self);
godot_pool_string_array_write_access GDAPI *godot_pool_string_array_write(godot_pool_string_array *p_self);
void GDAPI godot_pool_string_array_set(godot_pool_string_array *p_self, const godot_int p_idx, const godot_string *p_data);
godot_string GDAPI godot_pool_string_array_get(const godot_pool_string_array *p_self, const godot_int p_idx);
godot_int GDAPI godot_pool_string_array_size(const godot_pool_string_array *p_self);
godot_bool GDAPI godot_pool_string_array_empty(const godot_pool_string_array *p_self);
godot_bool GDAPI godot_pool_string_array_has(const godot_pool_string_array *p_self, const godot_string *p_data);
void GDAPI godot_pool_string_array_destroy(godot_pool_string_array *p_self);
// vector2
void GDAPI godot_pool_vector2_array_new(godot_pool_vector2_array *r_dest);
void GDAPI godot_pool_vector2_array_new_copy(godot_pool_vector2_array *r_dest, const godot_pool_vector2_array *p_src);
void GDAPI godot_pool_vector2_array_new_with_array(godot_pool_vector2_array *r_dest, const godot_array *p_a);
void GDAPI godot_pool_vector2_array_append(godot_pool_vector2_array *p_self, const godot_vector2 *p_data);
void GDAPI godot_pool_vector2_array_append_array(godot_pool_vector2_array *p_self, const godot_pool_vector2_array *p_array);
godot_error GDAPI godot_pool_vector2_array_insert(godot_pool_vector2_array *p_self, const godot_int p_idx, const godot_vector2 *p_data);
void GDAPI godot_pool_vector2_array_invert(godot_pool_vector2_array *p_self);
void GDAPI godot_pool_vector2_array_push_back(godot_pool_vector2_array *p_self, const godot_vector2 *p_data);
void GDAPI godot_pool_vector2_array_remove(godot_pool_vector2_array *p_self, const godot_int p_idx);
void GDAPI godot_pool_vector2_array_resize(godot_pool_vector2_array *p_self, const godot_int p_size);
void GDAPI godot_pool_vector2_array_sort(godot_pool_vector2_array *p_self);
godot_pool_vector2_array_read_access GDAPI *godot_pool_vector2_array_read(const godot_pool_vector2_array *p_self);
godot_pool_vector2_array_write_access GDAPI *godot_pool_vector2_array_write(godot_pool_vector2_array *p_self);
void GDAPI godot_pool_vector2_array_set(godot_pool_vector2_array *p_self, const godot_int p_idx, const godot_vector2 *p_data);
godot_vector2 GDAPI godot_pool_vector2_array_get(const godot_pool_vector2_array *p_self, const godot_int p_idx);
godot_int GDAPI godot_pool_vector2_array_size(const godot_pool_vector2_array *p_self);
godot_bool GDAPI godot_pool_vector2_array_empty(const godot_pool_vector2_array *p_self);
godot_bool GDAPI godot_pool_vector2_array_has(const godot_pool_vector2_array *p_self, const godot_vector2 *p_data);
void GDAPI godot_pool_vector2_array_destroy(godot_pool_vector2_array *p_self);
// vector3
void GDAPI godot_pool_vector3_array_new(godot_pool_vector3_array *r_dest);
void GDAPI godot_pool_vector3_array_new_copy(godot_pool_vector3_array *r_dest, const godot_pool_vector3_array *p_src);
void GDAPI godot_pool_vector3_array_new_with_array(godot_pool_vector3_array *r_dest, const godot_array *p_a);
void GDAPI godot_pool_vector3_array_append(godot_pool_vector3_array *p_self, const godot_vector3 *p_data);
void GDAPI godot_pool_vector3_array_append_array(godot_pool_vector3_array *p_self, const godot_pool_vector3_array *p_array);
godot_error GDAPI godot_pool_vector3_array_insert(godot_pool_vector3_array *p_self, const godot_int p_idx, const godot_vector3 *p_data);
void GDAPI godot_pool_vector3_array_invert(godot_pool_vector3_array *p_self);
void GDAPI godot_pool_vector3_array_push_back(godot_pool_vector3_array *p_self, const godot_vector3 *p_data);
void GDAPI godot_pool_vector3_array_remove(godot_pool_vector3_array *p_self, const godot_int p_idx);
void GDAPI godot_pool_vector3_array_resize(godot_pool_vector3_array *p_self, const godot_int p_size);
void GDAPI godot_pool_vector3_array_sort(godot_pool_vector3_array *p_self);
godot_pool_vector3_array_read_access GDAPI *godot_pool_vector3_array_read(const godot_pool_vector3_array *p_self);
godot_pool_vector3_array_write_access GDAPI *godot_pool_vector3_array_write(godot_pool_vector3_array *p_self);
void GDAPI godot_pool_vector3_array_set(godot_pool_vector3_array *p_self, const godot_int p_idx, const godot_vector3 *p_data);
godot_vector3 GDAPI godot_pool_vector3_array_get(const godot_pool_vector3_array *p_self, const godot_int p_idx);
godot_int GDAPI godot_pool_vector3_array_size(const godot_pool_vector3_array *p_self);
godot_bool GDAPI godot_pool_vector3_array_empty(const godot_pool_vector3_array *p_self);
godot_bool GDAPI godot_pool_vector3_array_has(const godot_pool_vector3_array *p_self, const godot_vector3 *p_data);
void GDAPI godot_pool_vector3_array_destroy(godot_pool_vector3_array *p_self);
// color
void GDAPI godot_pool_color_array_new(godot_pool_color_array *r_dest);
void GDAPI godot_pool_color_array_new_copy(godot_pool_color_array *r_dest, const godot_pool_color_array *p_src);
void GDAPI godot_pool_color_array_new_with_array(godot_pool_color_array *r_dest, const godot_array *p_a);
void GDAPI godot_pool_color_array_append(godot_pool_color_array *p_self, const godot_color *p_data);
void GDAPI godot_pool_color_array_append_array(godot_pool_color_array *p_self, const godot_pool_color_array *p_array);
godot_error GDAPI godot_pool_color_array_insert(godot_pool_color_array *p_self, const godot_int p_idx, const godot_color *p_data);
void GDAPI godot_pool_color_array_invert(godot_pool_color_array *p_self);
void GDAPI godot_pool_color_array_push_back(godot_pool_color_array *p_self, const godot_color *p_data);
void GDAPI godot_pool_color_array_remove(godot_pool_color_array *p_self, const godot_int p_idx);
void GDAPI godot_pool_color_array_resize(godot_pool_color_array *p_self, const godot_int p_size);
void GDAPI godot_pool_color_array_sort(godot_pool_color_array *p_self);
godot_pool_color_array_read_access GDAPI *godot_pool_color_array_read(const godot_pool_color_array *p_self);
godot_pool_color_array_write_access GDAPI *godot_pool_color_array_write(godot_pool_color_array *p_self);
void GDAPI godot_pool_color_array_set(godot_pool_color_array *p_self, const godot_int p_idx, const godot_color *p_data);
godot_color GDAPI godot_pool_color_array_get(const godot_pool_color_array *p_self, const godot_int p_idx);
godot_int GDAPI godot_pool_color_array_size(const godot_pool_color_array *p_self);
godot_bool GDAPI godot_pool_color_array_empty(const godot_pool_color_array *p_self);
godot_bool GDAPI godot_pool_color_array_has(const godot_pool_color_array *p_self, const godot_color *p_data);
void GDAPI godot_pool_color_array_destroy(godot_pool_color_array *p_self);
//
// read accessor functions
//
godot_pool_byte_array_read_access GDAPI *godot_pool_byte_array_read_access_copy(const godot_pool_byte_array_read_access *p_other);
const uint8_t GDAPI *godot_pool_byte_array_read_access_ptr(const godot_pool_byte_array_read_access *p_read);
void GDAPI godot_pool_byte_array_read_access_operator_assign(godot_pool_byte_array_read_access *p_read, godot_pool_byte_array_read_access *p_other);
void GDAPI godot_pool_byte_array_read_access_destroy(godot_pool_byte_array_read_access *p_read);
godot_pool_int_array_read_access GDAPI *godot_pool_int_array_read_access_copy(const godot_pool_int_array_read_access *p_other);
const godot_int GDAPI *godot_pool_int_array_read_access_ptr(const godot_pool_int_array_read_access *p_read);
void GDAPI godot_pool_int_array_read_access_operator_assign(godot_pool_int_array_read_access *p_read, godot_pool_int_array_read_access *p_other);
void GDAPI godot_pool_int_array_read_access_destroy(godot_pool_int_array_read_access *p_read);
godot_pool_real_array_read_access GDAPI *godot_pool_real_array_read_access_copy(const godot_pool_real_array_read_access *p_other);
const godot_real GDAPI *godot_pool_real_array_read_access_ptr(const godot_pool_real_array_read_access *p_read);
void GDAPI godot_pool_real_array_read_access_operator_assign(godot_pool_real_array_read_access *p_read, godot_pool_real_array_read_access *p_other);
void GDAPI godot_pool_real_array_read_access_destroy(godot_pool_real_array_read_access *p_read);
godot_pool_string_array_read_access GDAPI *godot_pool_string_array_read_access_copy(const godot_pool_string_array_read_access *p_other);
const godot_string GDAPI *godot_pool_string_array_read_access_ptr(const godot_pool_string_array_read_access *p_read);
void GDAPI godot_pool_string_array_read_access_operator_assign(godot_pool_string_array_read_access *p_read, godot_pool_string_array_read_access *p_other);
void GDAPI godot_pool_string_array_read_access_destroy(godot_pool_string_array_read_access *p_read);
godot_pool_vector2_array_read_access GDAPI *godot_pool_vector2_array_read_access_copy(const godot_pool_vector2_array_read_access *p_other);
const godot_vector2 GDAPI *godot_pool_vector2_array_read_access_ptr(const godot_pool_vector2_array_read_access *p_read);
void GDAPI godot_pool_vector2_array_read_access_operator_assign(godot_pool_vector2_array_read_access *p_read, godot_pool_vector2_array_read_access *p_other);
void GDAPI godot_pool_vector2_array_read_access_destroy(godot_pool_vector2_array_read_access *p_read);
godot_pool_vector3_array_read_access GDAPI *godot_pool_vector3_array_read_access_copy(const godot_pool_vector3_array_read_access *p_other);
const godot_vector3 GDAPI *godot_pool_vector3_array_read_access_ptr(const godot_pool_vector3_array_read_access *p_read);
void GDAPI godot_pool_vector3_array_read_access_operator_assign(godot_pool_vector3_array_read_access *p_read, godot_pool_vector3_array_read_access *p_other);
void GDAPI godot_pool_vector3_array_read_access_destroy(godot_pool_vector3_array_read_access *p_read);
godot_pool_color_array_read_access GDAPI *godot_pool_color_array_read_access_copy(const godot_pool_color_array_read_access *p_other);
const godot_color GDAPI *godot_pool_color_array_read_access_ptr(const godot_pool_color_array_read_access *p_read);
void GDAPI godot_pool_color_array_read_access_operator_assign(godot_pool_color_array_read_access *p_read, godot_pool_color_array_read_access *p_other);
void GDAPI godot_pool_color_array_read_access_destroy(godot_pool_color_array_read_access *p_read);
//
// write accessor functions
//
godot_pool_byte_array_write_access GDAPI *godot_pool_byte_array_write_access_copy(const godot_pool_byte_array_write_access *p_other);
uint8_t GDAPI *godot_pool_byte_array_write_access_ptr(const godot_pool_byte_array_write_access *p_write);
void GDAPI godot_pool_byte_array_write_access_operator_assign(godot_pool_byte_array_write_access *p_write, godot_pool_byte_array_write_access *p_other);
void GDAPI godot_pool_byte_array_write_access_destroy(godot_pool_byte_array_write_access *p_write);
godot_pool_int_array_write_access GDAPI *godot_pool_int_array_write_access_copy(const godot_pool_int_array_write_access *p_other);
godot_int GDAPI *godot_pool_int_array_write_access_ptr(const godot_pool_int_array_write_access *p_write);
void GDAPI godot_pool_int_array_write_access_operator_assign(godot_pool_int_array_write_access *p_write, godot_pool_int_array_write_access *p_other);
void GDAPI godot_pool_int_array_write_access_destroy(godot_pool_int_array_write_access *p_write);
godot_pool_real_array_write_access GDAPI *godot_pool_real_array_write_access_copy(const godot_pool_real_array_write_access *p_other);
godot_real GDAPI *godot_pool_real_array_write_access_ptr(const godot_pool_real_array_write_access *p_write);
void GDAPI godot_pool_real_array_write_access_operator_assign(godot_pool_real_array_write_access *p_write, godot_pool_real_array_write_access *p_other);
void GDAPI godot_pool_real_array_write_access_destroy(godot_pool_real_array_write_access *p_write);
godot_pool_string_array_write_access GDAPI *godot_pool_string_array_write_access_copy(const godot_pool_string_array_write_access *p_other);
godot_string GDAPI *godot_pool_string_array_write_access_ptr(const godot_pool_string_array_write_access *p_write);
void GDAPI godot_pool_string_array_write_access_operator_assign(godot_pool_string_array_write_access *p_write, godot_pool_string_array_write_access *p_other);
void GDAPI godot_pool_string_array_write_access_destroy(godot_pool_string_array_write_access *p_write);
godot_pool_vector2_array_write_access GDAPI *godot_pool_vector2_array_write_access_copy(const godot_pool_vector2_array_write_access *p_other);
godot_vector2 GDAPI *godot_pool_vector2_array_write_access_ptr(const godot_pool_vector2_array_write_access *p_write);
void GDAPI godot_pool_vector2_array_write_access_operator_assign(godot_pool_vector2_array_write_access *p_write, godot_pool_vector2_array_write_access *p_other);
void GDAPI godot_pool_vector2_array_write_access_destroy(godot_pool_vector2_array_write_access *p_write);
godot_pool_vector3_array_write_access GDAPI *godot_pool_vector3_array_write_access_copy(const godot_pool_vector3_array_write_access *p_other);
godot_vector3 GDAPI *godot_pool_vector3_array_write_access_ptr(const godot_pool_vector3_array_write_access *p_write);
void GDAPI godot_pool_vector3_array_write_access_operator_assign(godot_pool_vector3_array_write_access *p_write, godot_pool_vector3_array_write_access *p_other);
void GDAPI godot_pool_vector3_array_write_access_destroy(godot_pool_vector3_array_write_access *p_write);
godot_pool_color_array_write_access GDAPI *godot_pool_color_array_write_access_copy(const godot_pool_color_array_write_access *p_other);
godot_color GDAPI *godot_pool_color_array_write_access_ptr(const godot_pool_color_array_write_access *p_write);
void GDAPI godot_pool_color_array_write_access_operator_assign(godot_pool_color_array_write_access *p_write, godot_pool_color_array_write_access *p_other);
void GDAPI godot_pool_color_array_write_access_destroy(godot_pool_color_array_write_access *p_write);
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_POOL_ARRAYS_H

118
include/gdnative/quat.h Normal file
View File

@ -0,0 +1,118 @@
/**************************************************************************/
/* quat.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_QUAT_H
#define GDNATIVE_QUAT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#define GODOT_QUAT_SIZE 16
#ifndef GODOT_CORE_API_GODOT_QUAT_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_QUAT_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_QUAT_SIZE];
} godot_quat;
#endif
// reduce extern "C" nesting for VS2013
#ifdef __cplusplus
}
#endif
#include <gdnative/gdnative.h>
#include <gdnative/vector3.h>
#ifdef __cplusplus
extern "C" {
#endif
void GDAPI godot_quat_new(godot_quat *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z, const godot_real p_w);
void GDAPI godot_quat_new_with_axis_angle(godot_quat *r_dest, const godot_vector3 *p_axis, const godot_real p_angle);
void GDAPI godot_quat_new_with_basis(godot_quat *r_dest, const godot_basis *p_basis);
void GDAPI godot_quat_new_with_euler(godot_quat *r_dest, const godot_vector3 *p_euler);
godot_real GDAPI godot_quat_get_x(const godot_quat *p_self);
void GDAPI godot_quat_set_x(godot_quat *p_self, const godot_real val);
godot_real GDAPI godot_quat_get_y(const godot_quat *p_self);
void GDAPI godot_quat_set_y(godot_quat *p_self, const godot_real val);
godot_real GDAPI godot_quat_get_z(const godot_quat *p_self);
void GDAPI godot_quat_set_z(godot_quat *p_self, const godot_real val);
godot_real GDAPI godot_quat_get_w(const godot_quat *p_self);
void GDAPI godot_quat_set_w(godot_quat *p_self, const godot_real val);
godot_string GDAPI godot_quat_as_string(const godot_quat *p_self);
godot_real GDAPI godot_quat_length(const godot_quat *p_self);
godot_real GDAPI godot_quat_length_squared(const godot_quat *p_self);
godot_quat GDAPI godot_quat_normalized(const godot_quat *p_self);
godot_bool GDAPI godot_quat_is_normalized(const godot_quat *p_self);
godot_quat GDAPI godot_quat_inverse(const godot_quat *p_self);
godot_real GDAPI godot_quat_dot(const godot_quat *p_self, const godot_quat *p_b);
godot_vector3 GDAPI godot_quat_xform(const godot_quat *p_self, const godot_vector3 *p_v);
godot_quat GDAPI godot_quat_slerp(const godot_quat *p_self, const godot_quat *p_b, const godot_real p_t);
godot_quat GDAPI godot_quat_slerpni(const godot_quat *p_self, const godot_quat *p_b, const godot_real p_t);
godot_quat GDAPI godot_quat_cubic_slerp(const godot_quat *p_self, const godot_quat *p_b, const godot_quat *p_pre_a, const godot_quat *p_post_b, const godot_real p_t);
godot_quat GDAPI godot_quat_operator_multiply(const godot_quat *p_self, const godot_real p_b);
godot_quat GDAPI godot_quat_operator_add(const godot_quat *p_self, const godot_quat *p_b);
godot_quat GDAPI godot_quat_operator_subtract(const godot_quat *p_self, const godot_quat *p_b);
godot_quat GDAPI godot_quat_operator_divide(const godot_quat *p_self, const godot_real p_b);
godot_bool GDAPI godot_quat_operator_equal(const godot_quat *p_self, const godot_quat *p_b);
godot_quat GDAPI godot_quat_operator_neg(const godot_quat *p_self);
void GDAPI godot_quat_set_axis_angle(godot_quat *p_self, const godot_vector3 *p_axis, const godot_real p_angle);
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_QUAT_H

102
include/gdnative/rect2.h Normal file
View File

@ -0,0 +1,102 @@
/**************************************************************************/
/* rect2.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_RECT2_H
#define GDNATIVE_RECT2_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#ifndef GODOT_CORE_API_GODOT_RECT2_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_RECT2_TYPE_DEFINED
typedef struct godot_rect2 {
uint8_t _dont_touch_that[16];
} godot_rect2;
#endif
// reduce extern "C" nesting for VS2013
#ifdef __cplusplus
}
#endif
#include <gdnative/gdnative.h>
#include <gdnative/vector2.h>
#ifdef __cplusplus
extern "C" {
#endif
void GDAPI godot_rect2_new_with_position_and_size(godot_rect2 *r_dest, const godot_vector2 *p_pos, const godot_vector2 *p_size);
void GDAPI godot_rect2_new(godot_rect2 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_width, const godot_real p_height);
godot_string GDAPI godot_rect2_as_string(const godot_rect2 *p_self);
godot_real GDAPI godot_rect2_get_area(const godot_rect2 *p_self);
godot_bool GDAPI godot_rect2_intersects(const godot_rect2 *p_self, const godot_rect2 *p_b);
godot_bool GDAPI godot_rect2_encloses(const godot_rect2 *p_self, const godot_rect2 *p_b);
godot_bool GDAPI godot_rect2_has_no_area(const godot_rect2 *p_self);
godot_rect2 GDAPI godot_rect2_clip(const godot_rect2 *p_self, const godot_rect2 *p_b);
godot_rect2 GDAPI godot_rect2_merge(const godot_rect2 *p_self, const godot_rect2 *p_b);
godot_bool GDAPI godot_rect2_has_point(const godot_rect2 *p_self, const godot_vector2 *p_point);
godot_rect2 GDAPI godot_rect2_grow(const godot_rect2 *p_self, const godot_real p_by);
godot_rect2 GDAPI godot_rect2_grow_individual(const godot_rect2 *p_self, const godot_real p_left, const godot_real p_top, const godot_real p_right, const godot_real p_bottom);
godot_rect2 GDAPI godot_rect2_grow_margin(const godot_rect2 *p_self, const godot_int p_margin, const godot_real p_by);
godot_rect2 GDAPI godot_rect2_abs(const godot_rect2 *p_self);
godot_rect2 GDAPI godot_rect2_expand(const godot_rect2 *p_self, const godot_vector2 *p_to);
godot_bool GDAPI godot_rect2_operator_equal(const godot_rect2 *p_self, const godot_rect2 *p_b);
godot_vector2 GDAPI godot_rect2_get_position(const godot_rect2 *p_self);
godot_vector2 GDAPI godot_rect2_get_size(const godot_rect2 *p_self);
void GDAPI godot_rect2_set_position(godot_rect2 *p_self, const godot_vector2 *p_pos);
void GDAPI godot_rect2_set_size(godot_rect2 *p_self, const godot_vector2 *p_size);
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_RECT2_H

74
include/gdnative/rid.h Normal file
View File

@ -0,0 +1,74 @@
/**************************************************************************/
/* rid.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_RID_H
#define GDNATIVE_RID_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#define GODOT_RID_SIZE sizeof(void *)
#ifndef GODOT_CORE_API_GODOT_RID_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_RID_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_RID_SIZE];
} godot_rid;
#endif
// reduce extern "C" nesting for VS2013
#ifdef __cplusplus
}
#endif
#include <gdnative/gdnative.h>
#ifdef __cplusplus
extern "C" {
#endif
void GDAPI godot_rid_new(godot_rid *r_dest);
godot_int GDAPI godot_rid_get_id(const godot_rid *p_self);
void GDAPI godot_rid_new_with_resource(godot_rid *r_dest, const godot_object *p_from);
godot_bool GDAPI godot_rid_operator_equal(const godot_rid *p_self, const godot_rid *p_b);
godot_bool GDAPI godot_rid_operator_less(const godot_rid *p_self, const godot_rid *p_b);
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_RID_H

267
include/gdnative/string.h Normal file
View File

@ -0,0 +1,267 @@
/**************************************************************************/
/* string.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_STRING_H
#define GDNATIVE_STRING_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <wchar.h>
typedef wchar_t godot_char_type;
#define GODOT_STRING_SIZE sizeof(void *)
#define GODOT_CHAR_STRING_SIZE sizeof(void *)
#ifndef GODOT_CORE_API_GODOT_STRING_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_STRING_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_STRING_SIZE];
} godot_string;
#endif
#ifndef GODOT_CORE_API_GODOT_CHAR_STRING_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_CHAR_STRING_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_CHAR_STRING_SIZE];
} godot_char_string;
#endif
// reduce extern "C" nesting for VS2013
#ifdef __cplusplus
}
#endif
#include <gdnative/array.h>
#include <gdnative/gdnative.h>
#include <gdnative/variant.h>
#ifdef __cplusplus
extern "C" {
#endif
godot_int GDAPI godot_char_string_length(const godot_char_string *p_cs);
const char GDAPI *godot_char_string_get_data(const godot_char_string *p_cs);
void GDAPI godot_char_string_destroy(godot_char_string *p_cs);
void GDAPI godot_string_new(godot_string *r_dest);
void GDAPI godot_string_new_copy(godot_string *r_dest, const godot_string *p_src);
void GDAPI godot_string_new_with_wide_string(godot_string *r_dest, const wchar_t *p_contents, const int p_size);
const wchar_t GDAPI *godot_string_operator_index(godot_string *p_self, const godot_int p_idx);
wchar_t GDAPI godot_string_operator_index_const(const godot_string *p_self, const godot_int p_idx);
const wchar_t GDAPI *godot_string_wide_str(const godot_string *p_self);
godot_bool GDAPI godot_string_operator_equal(const godot_string *p_self, const godot_string *p_b);
godot_bool GDAPI godot_string_operator_less(const godot_string *p_self, const godot_string *p_b);
godot_string GDAPI godot_string_operator_plus(const godot_string *p_self, const godot_string *p_b);
/* Standard size stuff */
godot_int GDAPI godot_string_length(const godot_string *p_self);
/* Helpers */
signed char GDAPI godot_string_casecmp_to(const godot_string *p_self, const godot_string *p_str);
signed char GDAPI godot_string_nocasecmp_to(const godot_string *p_self, const godot_string *p_str);
signed char GDAPI godot_string_naturalnocasecmp_to(const godot_string *p_self, const godot_string *p_str);
godot_bool GDAPI godot_string_begins_with(const godot_string *p_self, const godot_string *p_string);
godot_bool GDAPI godot_string_begins_with_char_array(const godot_string *p_self, const char *p_char_array);
godot_array GDAPI godot_string_bigrams(const godot_string *p_self);
godot_string GDAPI godot_string_chr(wchar_t p_character);
godot_bool GDAPI godot_string_ends_with(const godot_string *p_self, const godot_string *p_string);
godot_int GDAPI godot_string_count(const godot_string *p_self, godot_string p_what, godot_int p_from, godot_int p_to);
godot_int GDAPI godot_string_countn(const godot_string *p_self, godot_string p_what, godot_int p_from, godot_int p_to);
godot_int GDAPI godot_string_find(const godot_string *p_self, godot_string p_what);
godot_int GDAPI godot_string_find_from(const godot_string *p_self, godot_string p_what, godot_int p_from);
godot_int GDAPI godot_string_findmk(const godot_string *p_self, const godot_array *p_keys);
godot_int GDAPI godot_string_findmk_from(const godot_string *p_self, const godot_array *p_keys, godot_int p_from);
godot_int GDAPI godot_string_findmk_from_in_place(const godot_string *p_self, const godot_array *p_keys, godot_int p_from, godot_int *r_key);
godot_int GDAPI godot_string_findn(const godot_string *p_self, godot_string p_what);
godot_int GDAPI godot_string_findn_from(const godot_string *p_self, godot_string p_what, godot_int p_from);
godot_int GDAPI godot_string_find_last(const godot_string *p_self, godot_string p_what);
godot_string GDAPI godot_string_format(const godot_string *p_self, const godot_variant *p_values);
godot_string GDAPI godot_string_format_with_custom_placeholder(const godot_string *p_self, const godot_variant *p_values, const char *p_placeholder);
godot_string GDAPI godot_string_hex_encode_buffer(const uint8_t *p_buffer, godot_int p_len);
godot_int GDAPI godot_string_hex_to_int(const godot_string *p_self);
godot_int GDAPI godot_string_hex_to_int_without_prefix(const godot_string *p_self);
godot_string GDAPI godot_string_insert(const godot_string *p_self, godot_int p_at_pos, godot_string p_string);
godot_bool GDAPI godot_string_is_numeric(const godot_string *p_self);
godot_bool GDAPI godot_string_is_subsequence_of(const godot_string *p_self, const godot_string *p_string);
godot_bool GDAPI godot_string_is_subsequence_ofi(const godot_string *p_self, const godot_string *p_string);
godot_string GDAPI godot_string_lpad(const godot_string *p_self, godot_int p_min_length);
godot_string GDAPI godot_string_lpad_with_custom_character(const godot_string *p_self, godot_int p_min_length, const godot_string *p_character);
godot_bool GDAPI godot_string_match(const godot_string *p_self, const godot_string *p_wildcard);
godot_bool GDAPI godot_string_matchn(const godot_string *p_self, const godot_string *p_wildcard);
godot_string GDAPI godot_string_md5(const uint8_t *p_md5);
godot_string GDAPI godot_string_num(double p_num);
godot_string GDAPI godot_string_num_int64(int64_t p_num, godot_int p_base);
godot_string GDAPI godot_string_num_int64_capitalized(int64_t p_num, godot_int p_base, godot_bool p_capitalize_hex);
godot_string GDAPI godot_string_num_uint64(uint64_t p_num, godot_int p_base);
godot_string GDAPI godot_string_num_uint64_capitalized(uint64_t p_num, godot_int p_base, godot_bool p_capitalize_hex);
godot_string GDAPI godot_string_num_real(double p_num);
godot_string GDAPI godot_string_num_scientific(double p_num);
godot_string GDAPI godot_string_num_with_decimals(double p_num, godot_int p_decimals);
godot_string GDAPI godot_string_pad_decimals(const godot_string *p_self, godot_int p_digits);
godot_string GDAPI godot_string_pad_zeros(const godot_string *p_self, godot_int p_digits);
godot_string GDAPI godot_string_replace_first(const godot_string *p_self, godot_string p_key, godot_string p_with);
godot_string GDAPI godot_string_replace(const godot_string *p_self, godot_string p_key, godot_string p_with);
godot_string GDAPI godot_string_replacen(const godot_string *p_self, godot_string p_key, godot_string p_with);
godot_int GDAPI godot_string_rfind(const godot_string *p_self, godot_string p_what);
godot_int GDAPI godot_string_rfindn(const godot_string *p_self, godot_string p_what);
godot_int GDAPI godot_string_rfind_from(const godot_string *p_self, godot_string p_what, godot_int p_from);
godot_int GDAPI godot_string_rfindn_from(const godot_string *p_self, godot_string p_what, godot_int p_from);
godot_string GDAPI godot_string_rpad(const godot_string *p_self, godot_int p_min_length);
godot_string GDAPI godot_string_rpad_with_custom_character(const godot_string *p_self, godot_int p_min_length, const godot_string *p_character);
godot_real GDAPI godot_string_similarity(const godot_string *p_self, const godot_string *p_string);
godot_string GDAPI godot_string_sprintf(const godot_string *p_self, const godot_array *p_values, godot_bool *p_error);
godot_string GDAPI godot_string_substr(const godot_string *p_self, godot_int p_from, godot_int p_chars);
double GDAPI godot_string_to_double(const godot_string *p_self);
godot_real GDAPI godot_string_to_float(const godot_string *p_self);
godot_int GDAPI godot_string_to_int(const godot_string *p_self);
godot_string GDAPI godot_string_camelcase_to_underscore(const godot_string *p_self);
godot_string GDAPI godot_string_camelcase_to_underscore_lowercased(const godot_string *p_self);
godot_string GDAPI godot_string_capitalize(const godot_string *p_self);
double GDAPI godot_string_char_to_double(const char *p_what);
godot_int GDAPI godot_string_char_to_int(const char *p_what);
int64_t GDAPI godot_string_wchar_to_int(const wchar_t *p_str);
godot_int GDAPI godot_string_char_to_int_with_len(const char *p_what, godot_int p_len);
int64_t GDAPI godot_string_char_to_int64_with_len(const wchar_t *p_str, int p_len);
int64_t GDAPI godot_string_hex_to_int64(const godot_string *p_self);
int64_t GDAPI godot_string_hex_to_int64_with_prefix(const godot_string *p_self);
int64_t GDAPI godot_string_to_int64(const godot_string *p_self);
double GDAPI godot_string_unicode_char_to_double(const wchar_t *p_str, const wchar_t **r_end);
godot_int GDAPI godot_string_get_slice_count(const godot_string *p_self, godot_string p_splitter);
godot_string GDAPI godot_string_get_slice(const godot_string *p_self, godot_string p_splitter, godot_int p_slice);
godot_string GDAPI godot_string_get_slicec(const godot_string *p_self, wchar_t p_splitter, godot_int p_slice);
godot_array GDAPI godot_string_split(const godot_string *p_self, const godot_string *p_splitter);
godot_array GDAPI godot_string_split_allow_empty(const godot_string *p_self, const godot_string *p_splitter);
godot_array GDAPI godot_string_split_floats(const godot_string *p_self, const godot_string *p_splitter);
godot_array GDAPI godot_string_split_floats_allows_empty(const godot_string *p_self, const godot_string *p_splitter);
godot_array GDAPI godot_string_split_floats_mk(const godot_string *p_self, const godot_array *p_splitters);
godot_array GDAPI godot_string_split_floats_mk_allows_empty(const godot_string *p_self, const godot_array *p_splitters);
godot_array GDAPI godot_string_split_ints(const godot_string *p_self, const godot_string *p_splitter);
godot_array GDAPI godot_string_split_ints_allows_empty(const godot_string *p_self, const godot_string *p_splitter);
godot_array GDAPI godot_string_split_ints_mk(const godot_string *p_self, const godot_array *p_splitters);
godot_array GDAPI godot_string_split_ints_mk_allows_empty(const godot_string *p_self, const godot_array *p_splitters);
godot_array GDAPI godot_string_split_spaces(const godot_string *p_self);
godot_string GDAPI godot_string_join(const godot_string *p_self, const godot_array *p_parts);
wchar_t GDAPI godot_string_char_lowercase(wchar_t p_char);
wchar_t GDAPI godot_string_char_uppercase(wchar_t p_char);
godot_string GDAPI godot_string_to_lower(const godot_string *p_self);
godot_string GDAPI godot_string_to_upper(const godot_string *p_self);
godot_string GDAPI godot_string_get_basename(const godot_string *p_self);
godot_string GDAPI godot_string_get_extension(const godot_string *p_self);
godot_string GDAPI godot_string_left(const godot_string *p_self, godot_int p_pos);
wchar_t GDAPI godot_string_ord_at(const godot_string *p_self, godot_int p_idx);
godot_string GDAPI godot_string_plus_file(const godot_string *p_self, const godot_string *p_file);
godot_string GDAPI godot_string_right(const godot_string *p_self, godot_int p_pos);
godot_string GDAPI godot_string_strip_edges(const godot_string *p_self, godot_bool p_left, godot_bool p_right);
godot_string GDAPI godot_string_strip_escapes(const godot_string *p_self);
void GDAPI godot_string_erase(godot_string *p_self, godot_int p_pos, godot_int p_chars);
godot_char_string GDAPI godot_string_ascii(const godot_string *p_self);
godot_char_string GDAPI godot_string_ascii_extended(const godot_string *p_self);
godot_char_string GDAPI godot_string_utf8(const godot_string *p_self);
godot_bool GDAPI godot_string_parse_utf8(godot_string *p_self, const char *p_utf8);
godot_bool GDAPI godot_string_parse_utf8_with_len(godot_string *p_self, const char *p_utf8, godot_int p_len);
godot_string GDAPI godot_string_chars_to_utf8(const char *p_utf8);
godot_string GDAPI godot_string_chars_to_utf8_with_len(const char *p_utf8, godot_int p_len);
uint32_t GDAPI godot_string_hash(const godot_string *p_self);
uint64_t GDAPI godot_string_hash64(const godot_string *p_self);
uint32_t GDAPI godot_string_hash_chars(const char *p_cstr);
uint32_t GDAPI godot_string_hash_chars_with_len(const char *p_cstr, godot_int p_len);
uint32_t GDAPI godot_string_hash_utf8_chars(const wchar_t *p_str);
uint32_t GDAPI godot_string_hash_utf8_chars_with_len(const wchar_t *p_str, godot_int p_len);
godot_pool_byte_array GDAPI godot_string_md5_buffer(const godot_string *p_self);
godot_string GDAPI godot_string_md5_text(const godot_string *p_self);
godot_pool_byte_array GDAPI godot_string_sha256_buffer(const godot_string *p_self);
godot_string GDAPI godot_string_sha256_text(const godot_string *p_self);
godot_bool godot_string_empty(const godot_string *p_self);
// path functions
godot_string GDAPI godot_string_get_base_dir(const godot_string *p_self);
godot_string GDAPI godot_string_get_file(const godot_string *p_self);
godot_string GDAPI godot_string_humanize_size(uint64_t p_size);
godot_bool GDAPI godot_string_is_abs_path(const godot_string *p_self);
godot_bool GDAPI godot_string_is_rel_path(const godot_string *p_self);
godot_bool GDAPI godot_string_is_resource_file(const godot_string *p_self);
godot_string GDAPI godot_string_path_to(const godot_string *p_self, const godot_string *p_path);
godot_string GDAPI godot_string_path_to_file(const godot_string *p_self, const godot_string *p_path);
godot_string GDAPI godot_string_simplify_path(const godot_string *p_self);
godot_string GDAPI godot_string_c_escape(const godot_string *p_self);
godot_string GDAPI godot_string_c_escape_multiline(const godot_string *p_self);
godot_string GDAPI godot_string_c_unescape(const godot_string *p_self);
godot_string GDAPI godot_string_http_escape(const godot_string *p_self);
godot_string GDAPI godot_string_http_unescape(const godot_string *p_self);
godot_string GDAPI godot_string_json_escape(const godot_string *p_self);
godot_string GDAPI godot_string_word_wrap(const godot_string *p_self, godot_int p_chars_per_line);
godot_string GDAPI godot_string_xml_escape(const godot_string *p_self);
godot_string GDAPI godot_string_xml_escape_with_quotes(const godot_string *p_self);
godot_string GDAPI godot_string_xml_unescape(const godot_string *p_self);
godot_string GDAPI godot_string_percent_decode(const godot_string *p_self);
godot_string GDAPI godot_string_percent_encode(const godot_string *p_self);
godot_bool GDAPI godot_string_is_valid_float(const godot_string *p_self);
godot_bool GDAPI godot_string_is_valid_hex_number(const godot_string *p_self, godot_bool p_with_prefix);
godot_bool GDAPI godot_string_is_valid_html_color(const godot_string *p_self);
godot_bool GDAPI godot_string_is_valid_identifier(const godot_string *p_self);
godot_bool GDAPI godot_string_is_valid_integer(const godot_string *p_self);
godot_bool GDAPI godot_string_is_valid_ip_address(const godot_string *p_self);
godot_string GDAPI godot_string_dedent(const godot_string *p_self);
godot_string GDAPI godot_string_trim_prefix(const godot_string *p_self, const godot_string *p_prefix);
godot_string GDAPI godot_string_trim_suffix(const godot_string *p_self, const godot_string *p_suffix);
godot_string GDAPI godot_string_rstrip(const godot_string *p_self, const godot_string *p_chars);
godot_pool_string_array GDAPI godot_string_rsplit(const godot_string *p_self, const godot_string *p_divisor, const godot_bool p_allow_empty, const godot_int p_maxsplit);
void GDAPI godot_string_destroy(godot_string *p_self);
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_STRING_H

View File

@ -0,0 +1,78 @@
/**************************************************************************/
/* string_name.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_STRING_NAME_H
#define GDNATIVE_STRING_NAME_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <wchar.h>
#define GODOT_STRING_NAME_SIZE sizeof(void *)
#ifndef GODOT_CORE_API_GODOT_STRING_NAME_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_STRING_NAME_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_STRING_NAME_SIZE];
} godot_string_name;
#endif
// reduce extern "C" nesting for VS2013
#ifdef __cplusplus
}
#endif
#include <gdnative/gdnative.h>
#ifdef __cplusplus
extern "C" {
#endif
void GDAPI godot_string_name_new(godot_string_name *r_dest, const godot_string *p_name);
void GDAPI godot_string_name_new_data(godot_string_name *r_dest, const char *p_name);
godot_string GDAPI godot_string_name_get_name(const godot_string_name *p_self);
uint32_t GDAPI godot_string_name_get_hash(const godot_string_name *p_self);
const void GDAPI *godot_string_name_get_data_unique_pointer(const godot_string_name *p_self);
godot_bool GDAPI godot_string_name_operator_equal(const godot_string_name *p_self, const godot_string_name *p_other);
godot_bool GDAPI godot_string_name_operator_less(const godot_string_name *p_self, const godot_string_name *p_other);
void GDAPI godot_string_name_destroy(godot_string_name *p_self);
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_STRING_NAME_H

View File

@ -0,0 +1,111 @@
/**************************************************************************/
/* transform.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_TRANSFORM_H
#define GDNATIVE_TRANSFORM_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#define GODOT_TRANSFORM_SIZE 48
#ifndef GODOT_CORE_API_GODOT_TRANSFORM_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_TRANSFORM_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_TRANSFORM_SIZE];
} godot_transform;
#endif
// reduce extern "C" nesting for VS2013
#ifdef __cplusplus
}
#endif
#include <gdnative/basis.h>
#include <gdnative/gdnative.h>
#include <gdnative/variant.h>
#include <gdnative/vector3.h>
#ifdef __cplusplus
extern "C" {
#endif
void GDAPI godot_transform_new_with_axis_origin(godot_transform *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis, const godot_vector3 *p_origin);
void GDAPI godot_transform_new(godot_transform *r_dest, const godot_basis *p_basis, const godot_vector3 *p_origin);
void GDAPI godot_transform_new_with_quat(godot_transform *r_dest, const godot_quat *p_quat);
godot_basis GDAPI godot_transform_get_basis(const godot_transform *p_self);
void GDAPI godot_transform_set_basis(godot_transform *p_self, const godot_basis *p_v);
godot_vector3 GDAPI godot_transform_get_origin(const godot_transform *p_self);
void GDAPI godot_transform_set_origin(godot_transform *p_self, const godot_vector3 *p_v);
godot_string GDAPI godot_transform_as_string(const godot_transform *p_self);
godot_transform GDAPI godot_transform_inverse(const godot_transform *p_self);
godot_transform GDAPI godot_transform_affine_inverse(const godot_transform *p_self);
godot_transform GDAPI godot_transform_orthonormalized(const godot_transform *p_self);
godot_transform GDAPI godot_transform_rotated(const godot_transform *p_self, const godot_vector3 *p_axis, const godot_real p_phi);
godot_transform GDAPI godot_transform_scaled(const godot_transform *p_self, const godot_vector3 *p_scale);
godot_transform GDAPI godot_transform_translated(const godot_transform *p_self, const godot_vector3 *p_ofs);
godot_transform GDAPI godot_transform_looking_at(const godot_transform *p_self, const godot_vector3 *p_target, const godot_vector3 *p_up);
godot_plane GDAPI godot_transform_xform_plane(const godot_transform *p_self, const godot_plane *p_v);
godot_plane GDAPI godot_transform_xform_inv_plane(const godot_transform *p_self, const godot_plane *p_v);
void GDAPI godot_transform_new_identity(godot_transform *r_dest);
godot_bool GDAPI godot_transform_operator_equal(const godot_transform *p_self, const godot_transform *p_b);
godot_transform GDAPI godot_transform_operator_multiply(const godot_transform *p_self, const godot_transform *p_b);
godot_vector3 GDAPI godot_transform_xform_vector3(const godot_transform *p_self, const godot_vector3 *p_v);
godot_vector3 GDAPI godot_transform_xform_inv_vector3(const godot_transform *p_self, const godot_vector3 *p_v);
godot_aabb GDAPI godot_transform_xform_aabb(const godot_transform *p_self, const godot_aabb *p_v);
godot_aabb GDAPI godot_transform_xform_inv_aabb(const godot_transform *p_self, const godot_aabb *p_v);
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_TRANSFORM_H

View File

@ -0,0 +1,111 @@
/**************************************************************************/
/* transform2d.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_TRANSFORM2D_H
#define GDNATIVE_TRANSFORM2D_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#define GODOT_TRANSFORM2D_SIZE 24
#ifndef GODOT_CORE_API_GODOT_TRANSFORM2D_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_TRANSFORM2D_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_TRANSFORM2D_SIZE];
} godot_transform2d;
#endif
// reduce extern "C" nesting for VS2013
#ifdef __cplusplus
}
#endif
#include <gdnative/gdnative.h>
#include <gdnative/variant.h>
#include <gdnative/vector2.h>
#ifdef __cplusplus
extern "C" {
#endif
void GDAPI godot_transform2d_new(godot_transform2d *r_dest, const godot_real p_rot, const godot_vector2 *p_pos);
void GDAPI godot_transform2d_new_axis_origin(godot_transform2d *r_dest, const godot_vector2 *p_x_axis, const godot_vector2 *p_y_axis, const godot_vector2 *p_origin);
godot_string GDAPI godot_transform2d_as_string(const godot_transform2d *p_self);
godot_transform2d GDAPI godot_transform2d_inverse(const godot_transform2d *p_self);
godot_transform2d GDAPI godot_transform2d_affine_inverse(const godot_transform2d *p_self);
godot_real GDAPI godot_transform2d_get_rotation(const godot_transform2d *p_self);
godot_vector2 GDAPI godot_transform2d_get_origin(const godot_transform2d *p_self);
godot_vector2 GDAPI godot_transform2d_get_scale(const godot_transform2d *p_self);
godot_real GDAPI godot_transform2d_determinant(const godot_transform2d *p_self);
godot_transform2d GDAPI godot_transform2d_orthonormalized(const godot_transform2d *p_self);
godot_transform2d GDAPI godot_transform2d_rotated(const godot_transform2d *p_self, const godot_real p_phi);
godot_transform2d GDAPI godot_transform2d_scaled(const godot_transform2d *p_self, const godot_vector2 *p_scale);
godot_transform2d GDAPI godot_transform2d_translated(const godot_transform2d *p_self, const godot_vector2 *p_offset);
godot_vector2 GDAPI godot_transform2d_xform_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v);
godot_vector2 GDAPI godot_transform2d_xform_inv_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v);
godot_vector2 GDAPI godot_transform2d_basis_xform_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v);
godot_vector2 GDAPI godot_transform2d_basis_xform_inv_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v);
godot_transform2d GDAPI godot_transform2d_interpolate_with(const godot_transform2d *p_self, const godot_transform2d *p_m, const godot_real p_c);
godot_bool GDAPI godot_transform2d_operator_equal(const godot_transform2d *p_self, const godot_transform2d *p_b);
godot_transform2d GDAPI godot_transform2d_operator_multiply(const godot_transform2d *p_self, const godot_transform2d *p_b);
void GDAPI godot_transform2d_new_identity(godot_transform2d *r_dest);
godot_rect2 GDAPI godot_transform2d_xform_rect2(const godot_transform2d *p_self, const godot_rect2 *p_v);
godot_rect2 GDAPI godot_transform2d_xform_inv_rect2(const godot_transform2d *p_self, const godot_rect2 *p_v);
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_TRANSFORM2D_H

255
include/gdnative/variant.h Normal file
View File

@ -0,0 +1,255 @@
/**************************************************************************/
/* variant.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_VARIANT_H
#define GDNATIVE_VARIANT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#define GODOT_VARIANT_SIZE (16 + sizeof(int64_t))
#ifndef GODOT_CORE_API_GODOT_VARIANT_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_VARIANT_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_VARIANT_SIZE];
} godot_variant;
#endif
typedef enum godot_variant_type {
GODOT_VARIANT_TYPE_NIL,
// atomic types
GODOT_VARIANT_TYPE_BOOL,
GODOT_VARIANT_TYPE_INT,
GODOT_VARIANT_TYPE_REAL,
GODOT_VARIANT_TYPE_STRING,
// math types
GODOT_VARIANT_TYPE_VECTOR2, // 5
GODOT_VARIANT_TYPE_RECT2,
GODOT_VARIANT_TYPE_VECTOR3,
GODOT_VARIANT_TYPE_TRANSFORM2D,
GODOT_VARIANT_TYPE_PLANE,
GODOT_VARIANT_TYPE_QUAT, // 10
GODOT_VARIANT_TYPE_AABB,
GODOT_VARIANT_TYPE_BASIS,
GODOT_VARIANT_TYPE_TRANSFORM,
// misc types
GODOT_VARIANT_TYPE_COLOR,
GODOT_VARIANT_TYPE_NODE_PATH, // 15
GODOT_VARIANT_TYPE_RID,
GODOT_VARIANT_TYPE_OBJECT,
GODOT_VARIANT_TYPE_DICTIONARY,
GODOT_VARIANT_TYPE_ARRAY, // 20
// arrays
GODOT_VARIANT_TYPE_POOL_BYTE_ARRAY,
GODOT_VARIANT_TYPE_POOL_INT_ARRAY,
GODOT_VARIANT_TYPE_POOL_REAL_ARRAY,
GODOT_VARIANT_TYPE_POOL_STRING_ARRAY,
GODOT_VARIANT_TYPE_POOL_VECTOR2_ARRAY, // 25
GODOT_VARIANT_TYPE_POOL_VECTOR3_ARRAY,
GODOT_VARIANT_TYPE_POOL_COLOR_ARRAY,
} godot_variant_type;
typedef enum godot_variant_call_error_error {
GODOT_CALL_ERROR_CALL_OK,
GODOT_CALL_ERROR_CALL_ERROR_INVALID_METHOD,
GODOT_CALL_ERROR_CALL_ERROR_INVALID_ARGUMENT,
GODOT_CALL_ERROR_CALL_ERROR_TOO_MANY_ARGUMENTS,
GODOT_CALL_ERROR_CALL_ERROR_TOO_FEW_ARGUMENTS,
GODOT_CALL_ERROR_CALL_ERROR_INSTANCE_IS_NULL,
} godot_variant_call_error_error;
typedef struct godot_variant_call_error {
godot_variant_call_error_error error;
int argument;
godot_variant_type expected;
} godot_variant_call_error;
typedef enum godot_variant_operator {
// comparison
GODOT_VARIANT_OP_EQUAL,
GODOT_VARIANT_OP_NOT_EQUAL,
GODOT_VARIANT_OP_LESS,
GODOT_VARIANT_OP_LESS_EQUAL,
GODOT_VARIANT_OP_GREATER,
GODOT_VARIANT_OP_GREATER_EQUAL,
// mathematic
GODOT_VARIANT_OP_ADD,
GODOT_VARIANT_OP_SUBTRACT,
GODOT_VARIANT_OP_MULTIPLY,
GODOT_VARIANT_OP_DIVIDE,
GODOT_VARIANT_OP_NEGATE,
GODOT_VARIANT_OP_POSITIVE,
GODOT_VARIANT_OP_MODULE,
GODOT_VARIANT_OP_STRING_CONCAT,
// bitwise
GODOT_VARIANT_OP_SHIFT_LEFT,
GODOT_VARIANT_OP_SHIFT_RIGHT,
GODOT_VARIANT_OP_BIT_AND,
GODOT_VARIANT_OP_BIT_OR,
GODOT_VARIANT_OP_BIT_XOR,
GODOT_VARIANT_OP_BIT_NEGATE,
// logic
GODOT_VARIANT_OP_AND,
GODOT_VARIANT_OP_OR,
GODOT_VARIANT_OP_XOR,
GODOT_VARIANT_OP_NOT,
// containment
GODOT_VARIANT_OP_IN,
GODOT_VARIANT_OP_MAX,
} godot_variant_operator;
// reduce extern "C" nesting for VS2013
#ifdef __cplusplus
}
#endif
#include <gdnative/aabb.h>
#include <gdnative/array.h>
#include <gdnative/basis.h>
#include <gdnative/color.h>
#include <gdnative/dictionary.h>
#include <gdnative/node_path.h>
#include <gdnative/plane.h>
#include <gdnative/pool_arrays.h>
#include <gdnative/quat.h>
#include <gdnative/rect2.h>
#include <gdnative/rid.h>
#include <gdnative/string.h>
#include <gdnative/transform.h>
#include <gdnative/transform2d.h>
#include <gdnative/variant.h>
#include <gdnative/vector2.h>
#include <gdnative/vector3.h>
#include <gdnative/gdnative.h>
#ifdef __cplusplus
extern "C" {
#endif
godot_variant_type GDAPI godot_variant_get_type(const godot_variant *p_v);
void GDAPI godot_variant_new_copy(godot_variant *r_dest, const godot_variant *p_src);
void GDAPI godot_variant_new_nil(godot_variant *r_dest);
void GDAPI godot_variant_new_bool(godot_variant *r_dest, const godot_bool p_b);
void GDAPI godot_variant_new_uint(godot_variant *r_dest, const uint64_t p_i);
void GDAPI godot_variant_new_int(godot_variant *r_dest, const int64_t p_i);
void GDAPI godot_variant_new_real(godot_variant *r_dest, const double p_r);
void GDAPI godot_variant_new_string(godot_variant *r_dest, const godot_string *p_s);
void GDAPI godot_variant_new_vector2(godot_variant *r_dest, const godot_vector2 *p_v2);
void GDAPI godot_variant_new_rect2(godot_variant *r_dest, const godot_rect2 *p_rect2);
void GDAPI godot_variant_new_vector3(godot_variant *r_dest, const godot_vector3 *p_v3);
void GDAPI godot_variant_new_transform2d(godot_variant *r_dest, const godot_transform2d *p_t2d);
void GDAPI godot_variant_new_plane(godot_variant *r_dest, const godot_plane *p_plane);
void GDAPI godot_variant_new_quat(godot_variant *r_dest, const godot_quat *p_quat);
void GDAPI godot_variant_new_aabb(godot_variant *r_dest, const godot_aabb *p_aabb);
void GDAPI godot_variant_new_basis(godot_variant *r_dest, const godot_basis *p_basis);
void GDAPI godot_variant_new_transform(godot_variant *r_dest, const godot_transform *p_trans);
void GDAPI godot_variant_new_color(godot_variant *r_dest, const godot_color *p_color);
void GDAPI godot_variant_new_node_path(godot_variant *r_dest, const godot_node_path *p_np);
void GDAPI godot_variant_new_rid(godot_variant *r_dest, const godot_rid *p_rid);
void GDAPI godot_variant_new_object(godot_variant *r_dest, const godot_object *p_obj);
void GDAPI godot_variant_new_dictionary(godot_variant *r_dest, const godot_dictionary *p_dict);
void GDAPI godot_variant_new_array(godot_variant *r_dest, const godot_array *p_arr);
void GDAPI godot_variant_new_pool_byte_array(godot_variant *r_dest, const godot_pool_byte_array *p_pba);
void GDAPI godot_variant_new_pool_int_array(godot_variant *r_dest, const godot_pool_int_array *p_pia);
void GDAPI godot_variant_new_pool_real_array(godot_variant *r_dest, const godot_pool_real_array *p_pra);
void GDAPI godot_variant_new_pool_string_array(godot_variant *r_dest, const godot_pool_string_array *p_psa);
void GDAPI godot_variant_new_pool_vector2_array(godot_variant *r_dest, const godot_pool_vector2_array *p_pv2a);
void GDAPI godot_variant_new_pool_vector3_array(godot_variant *r_dest, const godot_pool_vector3_array *p_pv3a);
void GDAPI godot_variant_new_pool_color_array(godot_variant *r_dest, const godot_pool_color_array *p_pca);
godot_bool GDAPI godot_variant_as_bool(const godot_variant *p_self);
uint64_t GDAPI godot_variant_as_uint(const godot_variant *p_self);
int64_t GDAPI godot_variant_as_int(const godot_variant *p_self);
double GDAPI godot_variant_as_real(const godot_variant *p_self);
godot_string GDAPI godot_variant_as_string(const godot_variant *p_self);
godot_vector2 GDAPI godot_variant_as_vector2(const godot_variant *p_self);
godot_rect2 GDAPI godot_variant_as_rect2(const godot_variant *p_self);
godot_vector3 GDAPI godot_variant_as_vector3(const godot_variant *p_self);
godot_transform2d GDAPI godot_variant_as_transform2d(const godot_variant *p_self);
godot_plane GDAPI godot_variant_as_plane(const godot_variant *p_self);
godot_quat GDAPI godot_variant_as_quat(const godot_variant *p_self);
godot_aabb GDAPI godot_variant_as_aabb(const godot_variant *p_self);
godot_basis GDAPI godot_variant_as_basis(const godot_variant *p_self);
godot_transform GDAPI godot_variant_as_transform(const godot_variant *p_self);
godot_color GDAPI godot_variant_as_color(const godot_variant *p_self);
godot_node_path GDAPI godot_variant_as_node_path(const godot_variant *p_self);
godot_rid GDAPI godot_variant_as_rid(const godot_variant *p_self);
godot_object GDAPI *godot_variant_as_object(const godot_variant *p_self);
godot_dictionary GDAPI godot_variant_as_dictionary(const godot_variant *p_self);
godot_array GDAPI godot_variant_as_array(const godot_variant *p_self);
godot_pool_byte_array GDAPI godot_variant_as_pool_byte_array(const godot_variant *p_self);
godot_pool_int_array GDAPI godot_variant_as_pool_int_array(const godot_variant *p_self);
godot_pool_real_array GDAPI godot_variant_as_pool_real_array(const godot_variant *p_self);
godot_pool_string_array GDAPI godot_variant_as_pool_string_array(const godot_variant *p_self);
godot_pool_vector2_array GDAPI godot_variant_as_pool_vector2_array(const godot_variant *p_self);
godot_pool_vector3_array GDAPI godot_variant_as_pool_vector3_array(const godot_variant *p_self);
godot_pool_color_array GDAPI godot_variant_as_pool_color_array(const godot_variant *p_self);
godot_variant GDAPI godot_variant_call(godot_variant *p_self, const godot_string *p_method, const godot_variant **p_args, const godot_int p_argcount, godot_variant_call_error *r_error);
godot_bool GDAPI godot_variant_has_method(const godot_variant *p_self, const godot_string *p_method);
godot_bool GDAPI godot_variant_operator_equal(const godot_variant *p_self, const godot_variant *p_other);
godot_bool GDAPI godot_variant_operator_less(const godot_variant *p_self, const godot_variant *p_other);
godot_bool GDAPI godot_variant_hash_compare(const godot_variant *p_self, const godot_variant *p_other);
godot_bool GDAPI godot_variant_booleanize(const godot_variant *p_self);
void GDAPI godot_variant_destroy(godot_variant *p_self);
// GDNative core 1.1
godot_string GDAPI godot_variant_get_operator_name(godot_variant_operator p_op);
void GDAPI godot_variant_evaluate(godot_variant_operator p_op, const godot_variant *p_a, const godot_variant *p_b, godot_variant *r_ret, godot_bool *r_valid);
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_VARIANT_H

142
include/gdnative/vector2.h Normal file
View File

@ -0,0 +1,142 @@
/**************************************************************************/
/* vector2.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_VECTOR2_H
#define GDNATIVE_VECTOR2_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#define GODOT_VECTOR2_SIZE 8
#ifndef GODOT_CORE_API_GODOT_VECTOR2_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_VECTOR2_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_VECTOR2_SIZE];
} godot_vector2;
#endif
// reduce extern "C" nesting for VS2013
#ifdef __cplusplus
}
#endif
#include <gdnative/gdnative.h>
#ifdef __cplusplus
extern "C" {
#endif
void GDAPI godot_vector2_new(godot_vector2 *r_dest, const godot_real p_x, const godot_real p_y);
godot_string GDAPI godot_vector2_as_string(const godot_vector2 *p_self);
godot_vector2 GDAPI godot_vector2_normalized(const godot_vector2 *p_self);
godot_real GDAPI godot_vector2_length(const godot_vector2 *p_self);
godot_real GDAPI godot_vector2_angle(const godot_vector2 *p_self);
godot_real GDAPI godot_vector2_length_squared(const godot_vector2 *p_self);
godot_bool GDAPI godot_vector2_is_normalized(const godot_vector2 *p_self);
godot_vector2 GDAPI godot_vector2_direction_to(const godot_vector2 *p_self, const godot_vector2 *p_b);
godot_real GDAPI godot_vector2_distance_to(const godot_vector2 *p_self, const godot_vector2 *p_to);
godot_real GDAPI godot_vector2_distance_squared_to(const godot_vector2 *p_self, const godot_vector2 *p_to);
godot_real GDAPI godot_vector2_angle_to(const godot_vector2 *p_self, const godot_vector2 *p_to);
godot_real GDAPI godot_vector2_angle_to_point(const godot_vector2 *p_self, const godot_vector2 *p_to);
godot_vector2 GDAPI godot_vector2_linear_interpolate(const godot_vector2 *p_self, const godot_vector2 *p_b, const godot_real p_t);
godot_vector2 GDAPI godot_vector2_cubic_interpolate(const godot_vector2 *p_self, const godot_vector2 *p_b, const godot_vector2 *p_pre_a, const godot_vector2 *p_post_b, const godot_real p_t);
godot_vector2 GDAPI godot_vector2_move_toward(const godot_vector2 *p_self, const godot_vector2 *p_to, const godot_real p_delta);
godot_vector2 GDAPI godot_vector2_rotated(const godot_vector2 *p_self, const godot_real p_phi);
godot_vector2 GDAPI godot_vector2_tangent(const godot_vector2 *p_self);
godot_vector2 GDAPI godot_vector2_floor(const godot_vector2 *p_self);
godot_vector2 GDAPI godot_vector2_snapped(const godot_vector2 *p_self, const godot_vector2 *p_by);
godot_real GDAPI godot_vector2_aspect(const godot_vector2 *p_self);
godot_real GDAPI godot_vector2_dot(const godot_vector2 *p_self, const godot_vector2 *p_with);
godot_vector2 GDAPI godot_vector2_slide(const godot_vector2 *p_self, const godot_vector2 *p_n);
godot_vector2 GDAPI godot_vector2_bounce(const godot_vector2 *p_self, const godot_vector2 *p_n);
godot_vector2 GDAPI godot_vector2_reflect(const godot_vector2 *p_self, const godot_vector2 *p_n);
godot_vector2 GDAPI godot_vector2_abs(const godot_vector2 *p_self);
godot_vector2 GDAPI godot_vector2_clamped(const godot_vector2 *p_self, const godot_real p_length);
godot_vector2 GDAPI godot_vector2_operator_add(const godot_vector2 *p_self, const godot_vector2 *p_b);
godot_vector2 GDAPI godot_vector2_operator_subtract(const godot_vector2 *p_self, const godot_vector2 *p_b);
godot_vector2 GDAPI godot_vector2_operator_multiply_vector(const godot_vector2 *p_self, const godot_vector2 *p_b);
godot_vector2 GDAPI godot_vector2_operator_multiply_scalar(const godot_vector2 *p_self, const godot_real p_b);
godot_vector2 GDAPI godot_vector2_operator_divide_vector(const godot_vector2 *p_self, const godot_vector2 *p_b);
godot_vector2 GDAPI godot_vector2_operator_divide_scalar(const godot_vector2 *p_self, const godot_real p_b);
godot_bool GDAPI godot_vector2_operator_equal(const godot_vector2 *p_self, const godot_vector2 *p_b);
godot_bool GDAPI godot_vector2_operator_less(const godot_vector2 *p_self, const godot_vector2 *p_b);
godot_vector2 GDAPI godot_vector2_operator_neg(const godot_vector2 *p_self);
void GDAPI godot_vector2_set_x(godot_vector2 *p_self, const godot_real p_x);
void GDAPI godot_vector2_set_y(godot_vector2 *p_self, const godot_real p_y);
godot_real GDAPI godot_vector2_get_x(const godot_vector2 *p_self);
godot_real GDAPI godot_vector2_get_y(const godot_vector2 *p_self);
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_VECTOR2_H

149
include/gdnative/vector3.h Normal file
View File

@ -0,0 +1,149 @@
/**************************************************************************/
/* vector3.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_VECTOR3_H
#define GDNATIVE_VECTOR3_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#define GODOT_VECTOR3_SIZE 12
#ifndef GODOT_CORE_API_GODOT_VECTOR3_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_VECTOR3_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_VECTOR3_SIZE];
} godot_vector3;
#endif
// reduce extern "C" nesting for VS2013
#ifdef __cplusplus
}
#endif
#include <gdnative/basis.h>
#include <gdnative/gdnative.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
GODOT_VECTOR3_AXIS_X,
GODOT_VECTOR3_AXIS_Y,
GODOT_VECTOR3_AXIS_Z,
} godot_vector3_axis;
void GDAPI godot_vector3_new(godot_vector3 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z);
godot_string GDAPI godot_vector3_as_string(const godot_vector3 *p_self);
godot_int GDAPI godot_vector3_min_axis(const godot_vector3 *p_self);
godot_int GDAPI godot_vector3_max_axis(const godot_vector3 *p_self);
godot_real GDAPI godot_vector3_length(const godot_vector3 *p_self);
godot_real GDAPI godot_vector3_length_squared(const godot_vector3 *p_self);
godot_bool GDAPI godot_vector3_is_normalized(const godot_vector3 *p_self);
godot_vector3 GDAPI godot_vector3_normalized(const godot_vector3 *p_self);
godot_vector3 GDAPI godot_vector3_inverse(const godot_vector3 *p_self);
godot_vector3 GDAPI godot_vector3_snapped(const godot_vector3 *p_self, const godot_vector3 *p_by);
godot_vector3 GDAPI godot_vector3_rotated(const godot_vector3 *p_self, const godot_vector3 *p_axis, const godot_real p_phi);
godot_vector3 GDAPI godot_vector3_linear_interpolate(const godot_vector3 *p_self, const godot_vector3 *p_b, const godot_real p_t);
godot_vector3 GDAPI godot_vector3_cubic_interpolate(const godot_vector3 *p_self, const godot_vector3 *p_b, const godot_vector3 *p_pre_a, const godot_vector3 *p_post_b, const godot_real p_t);
godot_vector3 GDAPI godot_vector3_move_toward(const godot_vector3 *p_self, const godot_vector3 *p_to, const godot_real p_delta);
godot_real GDAPI godot_vector3_dot(const godot_vector3 *p_self, const godot_vector3 *p_b);
godot_vector3 GDAPI godot_vector3_cross(const godot_vector3 *p_self, const godot_vector3 *p_b);
godot_basis GDAPI godot_vector3_outer(const godot_vector3 *p_self, const godot_vector3 *p_b);
godot_basis GDAPI godot_vector3_to_diagonal_matrix(const godot_vector3 *p_self);
godot_vector3 GDAPI godot_vector3_abs(const godot_vector3 *p_self);
godot_vector3 GDAPI godot_vector3_floor(const godot_vector3 *p_self);
godot_vector3 GDAPI godot_vector3_ceil(const godot_vector3 *p_self);
godot_vector3 GDAPI godot_vector3_direction_to(const godot_vector3 *p_self, const godot_vector3 *p_b);
godot_real GDAPI godot_vector3_distance_to(const godot_vector3 *p_self, const godot_vector3 *p_b);
godot_real GDAPI godot_vector3_distance_squared_to(const godot_vector3 *p_self, const godot_vector3 *p_b);
godot_real GDAPI godot_vector3_angle_to(const godot_vector3 *p_self, const godot_vector3 *p_to);
godot_vector3 GDAPI godot_vector3_slide(const godot_vector3 *p_self, const godot_vector3 *p_n);
godot_vector3 GDAPI godot_vector3_bounce(const godot_vector3 *p_self, const godot_vector3 *p_n);
godot_vector3 GDAPI godot_vector3_reflect(const godot_vector3 *p_self, const godot_vector3 *p_n);
godot_vector3 GDAPI godot_vector3_operator_add(const godot_vector3 *p_self, const godot_vector3 *p_b);
godot_vector3 GDAPI godot_vector3_operator_subtract(const godot_vector3 *p_self, const godot_vector3 *p_b);
godot_vector3 GDAPI godot_vector3_operator_multiply_vector(const godot_vector3 *p_self, const godot_vector3 *p_b);
godot_vector3 GDAPI godot_vector3_operator_multiply_scalar(const godot_vector3 *p_self, const godot_real p_b);
godot_vector3 GDAPI godot_vector3_operator_divide_vector(const godot_vector3 *p_self, const godot_vector3 *p_b);
godot_vector3 GDAPI godot_vector3_operator_divide_scalar(const godot_vector3 *p_self, const godot_real p_b);
godot_bool GDAPI godot_vector3_operator_equal(const godot_vector3 *p_self, const godot_vector3 *p_b);
godot_bool GDAPI godot_vector3_operator_less(const godot_vector3 *p_self, const godot_vector3 *p_b);
godot_vector3 GDAPI godot_vector3_operator_neg(const godot_vector3 *p_self);
void GDAPI godot_vector3_set_axis(godot_vector3 *p_self, const godot_vector3_axis p_axis, const godot_real p_val);
godot_real GDAPI godot_vector3_get_axis(const godot_vector3 *p_self, const godot_vector3_axis p_axis);
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_VECTOR3_H

View File

@ -0,0 +1,257 @@
/**************************************************************************/
/* godot_nativescript.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GODOT_NATIVESCRIPT_H
#define GODOT_NATIVESCRIPT_H
#include <gdnative/gdnative.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
GODOT_METHOD_RPC_MODE_DISABLED,
GODOT_METHOD_RPC_MODE_REMOTE,
GODOT_METHOD_RPC_MODE_MASTER,
GODOT_METHOD_RPC_MODE_PUPPET,
GODOT_METHOD_RPC_MODE_SLAVE = GODOT_METHOD_RPC_MODE_PUPPET,
GODOT_METHOD_RPC_MODE_REMOTESYNC,
GODOT_METHOD_RPC_MODE_SYNC = GODOT_METHOD_RPC_MODE_REMOTESYNC,
GODOT_METHOD_RPC_MODE_MASTERSYNC,
GODOT_METHOD_RPC_MODE_PUPPETSYNC,
} godot_method_rpc_mode;
typedef enum {
GODOT_PROPERTY_HINT_NONE, ///< no hint provided.
GODOT_PROPERTY_HINT_RANGE, ///< hint_text = "min,max,step,slider; //slider is optional"
GODOT_PROPERTY_HINT_EXP_RANGE, ///< hint_text = "min,max,step", exponential edit
GODOT_PROPERTY_HINT_ENUM, ///< hint_text= "val1,val2,val3,etc"
GODOT_PROPERTY_HINT_EXP_EASING, /// exponential easing function (Math::ease)
GODOT_PROPERTY_HINT_LENGTH, ///< hint_text= "length" (as integer)
GODOT_PROPERTY_HINT_SPRITE_FRAME, // FIXME: Obsolete: drop whenever we can break compat
GODOT_PROPERTY_HINT_KEY_ACCEL, ///< hint_text= "length" (as integer)
GODOT_PROPERTY_HINT_FLAGS, ///< hint_text= "flag1,flag2,etc" (as bit flags)
GODOT_PROPERTY_HINT_LAYERS_2D_RENDER,
GODOT_PROPERTY_HINT_LAYERS_2D_PHYSICS,
GODOT_PROPERTY_HINT_LAYERS_2D_NAVIGATION,
GODOT_PROPERTY_HINT_LAYERS_3D_RENDER,
GODOT_PROPERTY_HINT_LAYERS_3D_PHYSICS,
GODOT_PROPERTY_HINT_LAYERS_3D_NAVIGATION,
GODOT_PROPERTY_HINT_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,"
GODOT_PROPERTY_HINT_DIR, ///< a directory path must be passed
GODOT_PROPERTY_HINT_GLOBAL_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,"
GODOT_PROPERTY_HINT_GLOBAL_DIR, ///< a directory path must be passed
GODOT_PROPERTY_HINT_RESOURCE_TYPE, ///< a resource object type
GODOT_PROPERTY_HINT_MULTILINE_TEXT, ///< used for string properties that can contain multiple lines
GODOT_PROPERTY_HINT_PLACEHOLDER_TEXT, ///< used to set a placeholder text for string properties
GODOT_PROPERTY_HINT_COLOR_NO_ALPHA, ///< used for ignoring alpha component when editing a color
GODOT_PROPERTY_HINT_IMAGE_COMPRESS_LOSSY,
GODOT_PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS,
GODOT_PROPERTY_HINT_OBJECT_ID,
GODOT_PROPERTY_HINT_TYPE_STRING, ///< a type string, the hint is the base type to choose
GODOT_PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE, ///< so something else can provide this (used in scripts)
GODOT_PROPERTY_HINT_METHOD_OF_VARIANT_TYPE, ///< a method of a type
GODOT_PROPERTY_HINT_METHOD_OF_BASE_TYPE, ///< a method of a base type
GODOT_PROPERTY_HINT_METHOD_OF_INSTANCE, ///< a method of an instance
GODOT_PROPERTY_HINT_METHOD_OF_SCRIPT, ///< a method of a script & base
GODOT_PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE, ///< a property of a type
GODOT_PROPERTY_HINT_PROPERTY_OF_BASE_TYPE, ///< a property of a base type
GODOT_PROPERTY_HINT_PROPERTY_OF_INSTANCE, ///< a property of an instance
GODOT_PROPERTY_HINT_PROPERTY_OF_SCRIPT, ///< a property of a script & base
GODOT_PROPERTY_HINT_OBJECT_TOO_BIG, ///< object is too big to send
GODOT_PROPERTY_HINT_NODE_PATH_VALID_TYPES,
GODOT_PROPERTY_HINT_SAVE_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,". This opens a save dialog
GODOT_PROPERTY_HINT_ENUM_SUGGESTION, ///< hint_text= "val1,val2,val3,etc"
GODOT_PROPERTY_HINT_LOCALE_ID,
GODOT_PROPERTY_HINT_MAX,
} godot_property_hint;
typedef enum {
GODOT_PROPERTY_USAGE_STORAGE = 1,
GODOT_PROPERTY_USAGE_EDITOR = 2,
GODOT_PROPERTY_USAGE_NETWORK = 4,
GODOT_PROPERTY_USAGE_EDITOR_HELPER = 8,
GODOT_PROPERTY_USAGE_CHECKABLE = 16, //used for editing global variables
GODOT_PROPERTY_USAGE_CHECKED = 32, //used for editing global variables
GODOT_PROPERTY_USAGE_INTERNATIONALIZED = 64, //hint for internationalized strings
GODOT_PROPERTY_USAGE_GROUP = 128, //used for grouping props in the editor
GODOT_PROPERTY_USAGE_CATEGORY = 256,
GODOT_PROPERTY_USAGE_STORE_IF_NONZERO = 512, // FIXME: Obsolete: drop whenever we can break compat
GODOT_PROPERTY_USAGE_STORE_IF_NONONE = 1024, // FIXME: Obsolete: drop whenever we can break compat
GODOT_PROPERTY_USAGE_NO_INSTANCE_STATE = 2048,
GODOT_PROPERTY_USAGE_RESTART_IF_CHANGED = 4096,
GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE = 8192,
GODOT_PROPERTY_USAGE_STORE_IF_NULL = 16384,
GODOT_PROPERTY_USAGE_ANIMATE_AS_TRIGGER = 32768,
GODOT_PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED = 65536,
GODOT_PROPERTY_USAGE_DEFAULT = GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_EDITOR | GODOT_PROPERTY_USAGE_NETWORK,
GODOT_PROPERTY_USAGE_DEFAULT_INTL = GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_EDITOR | GODOT_PROPERTY_USAGE_NETWORK | GODOT_PROPERTY_USAGE_INTERNATIONALIZED,
GODOT_PROPERTY_USAGE_NOEDITOR = GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_NETWORK,
} godot_property_usage_flags;
typedef struct {
godot_method_rpc_mode rset_type;
godot_int type;
godot_property_hint hint;
godot_string hint_string;
godot_property_usage_flags usage;
godot_variant default_value;
} godot_property_attributes;
typedef struct {
// instance pointer, method_data - return user data
GDCALLINGCONV void *(*create_func)(godot_object *, void *);
void *method_data;
GDCALLINGCONV void (*free_func)(void *);
} godot_instance_create_func;
typedef struct {
// instance pointer, method data, user data
GDCALLINGCONV void (*destroy_func)(godot_object *, void *, void *);
void *method_data;
GDCALLINGCONV void (*free_func)(void *);
} godot_instance_destroy_func;
void GDAPI godot_nativescript_register_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func);
void GDAPI godot_nativescript_register_tool_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func);
typedef struct {
godot_method_rpc_mode rpc_type;
} godot_method_attributes;
typedef struct {
// instance pointer, method data, user data, num args, args - return result as variant
GDCALLINGCONV godot_variant (*method)(godot_object *, void *, void *, int, godot_variant **);
void *method_data;
GDCALLINGCONV void (*free_func)(void *);
} godot_instance_method;
void GDAPI godot_nativescript_register_method(void *p_gdnative_handle, const char *p_name, const char *p_function_name, godot_method_attributes p_attr, godot_instance_method p_method);
typedef struct {
// instance pointer, method data, user data, value
GDCALLINGCONV void (*set_func)(godot_object *, void *, void *, godot_variant *);
void *method_data;
GDCALLINGCONV void (*free_func)(void *);
} godot_property_set_func;
typedef struct {
// instance pointer, method data, user data, value
GDCALLINGCONV godot_variant (*get_func)(godot_object *, void *, void *);
void *method_data;
GDCALLINGCONV void (*free_func)(void *);
} godot_property_get_func;
void GDAPI godot_nativescript_register_property(void *p_gdnative_handle, const char *p_name, const char *p_path, godot_property_attributes *p_attr, godot_property_set_func p_set_func, godot_property_get_func p_get_func);
typedef struct {
godot_string name;
godot_int type;
godot_property_hint hint;
godot_string hint_string;
godot_property_usage_flags usage;
godot_variant default_value;
} godot_signal_argument;
typedef struct {
godot_string name;
int num_args;
godot_signal_argument *args;
int num_default_args;
godot_variant *default_args;
} godot_signal;
void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const char *p_name, const godot_signal *p_signal);
void GDAPI *godot_nativescript_get_userdata(godot_object *p_instance);
/*
*
*
* NativeScript 1.1
*
*
*/
// method registering with argument names
typedef struct {
godot_string name;
godot_variant_type type;
godot_property_hint hint;
godot_string hint_string;
} godot_method_arg;
void GDAPI godot_nativescript_set_method_argument_information(void *p_gdnative_handle, const char *p_name, const char *p_function_name, int p_num_args, const godot_method_arg *p_args);
// documentation
void GDAPI godot_nativescript_set_class_documentation(void *p_gdnative_handle, const char *p_name, godot_string p_documentation);
void GDAPI godot_nativescript_set_method_documentation(void *p_gdnative_handle, const char *p_name, const char *p_function_name, godot_string p_documentation);
void GDAPI godot_nativescript_set_property_documentation(void *p_gdnative_handle, const char *p_name, const char *p_path, godot_string p_documentation);
void GDAPI godot_nativescript_set_signal_documentation(void *p_gdnative_handle, const char *p_name, const char *p_signal_name, godot_string p_documentation);
// type tag API
void GDAPI godot_nativescript_set_global_type_tag(int p_idx, const char *p_name, const void *p_type_tag);
const void GDAPI *godot_nativescript_get_global_type_tag(int p_idx, const char *p_name);
void GDAPI godot_nativescript_set_type_tag(void *p_gdnative_handle, const char *p_name, const void *p_type_tag);
const void GDAPI *godot_nativescript_get_type_tag(const godot_object *p_object);
// instance binding API
typedef struct {
GDCALLINGCONV void *(*alloc_instance_binding_data)(void *, const void *, godot_object *);
GDCALLINGCONV void (*free_instance_binding_data)(void *, void *);
GDCALLINGCONV void (*refcount_incremented_instance_binding)(void *, godot_object *);
GDCALLINGCONV bool (*refcount_decremented_instance_binding)(void *, godot_object *);
void *data;
GDCALLINGCONV void (*free_func)(void *);
} godot_instance_binding_functions;
int GDAPI godot_nativescript_register_instance_binding_data_functions(godot_instance_binding_functions p_binding_functions);
void GDAPI godot_nativescript_unregister_instance_binding_data_functions(int p_idx);
void GDAPI *godot_nativescript_get_instance_binding_data(int p_idx, godot_object *p_object);
void GDAPI godot_nativescript_profiling_add_data(const char *p_signature, uint64_t p_time);
#ifdef __cplusplus
}
#endif
#endif // GODOT_NATIVESCRIPT_H

120
include/net/godot_net.h Normal file
View File

@ -0,0 +1,120 @@
/**************************************************************************/
/* godot_net.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GODOT_NET_H
#define GODOT_NET_H
#include <gdnative/gdnative.h>
#ifdef __cplusplus
extern "C" {
#endif
// For future versions of the API we should only add new functions at the end of the structure and use the
// version info to detect whether a call is available
// Use these to populate version in your plugin
#define GODOT_NET_API_MAJOR 3
#define GODOT_NET_API_MINOR 1
typedef struct {
godot_gdnative_api_version version; /* version of our API */
godot_object *data; /* User reference */
/* This is StreamPeer */
godot_error (*get_data)(void *user, uint8_t *p_buffer, int p_bytes);
godot_error (*get_partial_data)(void *user, uint8_t *p_buffer, int p_bytes, int *r_received);
godot_error (*put_data)(void *user, const uint8_t *p_data, int p_bytes);
godot_error (*put_partial_data)(void *user, const uint8_t *p_data, int p_bytes, int *r_sent);
int (*get_available_bytes)(const void *user);
void *next; /* For extension? */
} godot_net_stream_peer;
/* Binds a StreamPeerGDNative to the provided interface */
void godot_net_bind_stream_peer(godot_object *p_obj, const godot_net_stream_peer *p_interface);
typedef struct {
godot_gdnative_api_version version; /* version of our API */
godot_object *data; /* User reference */
/* This is PacketPeer */
godot_error (*get_packet)(void *, const uint8_t **, int *);
godot_error (*put_packet)(void *, const uint8_t *, int);
godot_int (*get_available_packet_count)(const void *);
godot_int (*get_max_packet_size)(const void *);
void *next; /* For extension? */
} godot_net_packet_peer;
/* Binds a PacketPeerGDNative to the provided interface */
void GDAPI godot_net_bind_packet_peer(godot_object *p_obj, const godot_net_packet_peer *);
typedef struct {
godot_gdnative_api_version version; /* version of our API */
godot_object *data; /* User reference */
/* This is PacketPeer */
godot_error (*get_packet)(void *, const uint8_t **, int *);
godot_error (*put_packet)(void *, const uint8_t *, int);
godot_int (*get_available_packet_count)(const void *);
godot_int (*get_max_packet_size)(const void *);
/* This is NetworkedMultiplayerPeer */
void (*set_transfer_mode)(void *, godot_int);
godot_int (*get_transfer_mode)(const void *);
// 0 = broadcast, 1 = server, <0 = all but abs(value)
void (*set_target_peer)(void *, godot_int);
godot_int (*get_packet_peer)(const void *);
godot_bool (*is_server)(const void *);
void (*poll)(void *);
// Must be > 0, 1 is for server
int32_t (*get_unique_id)(const void *);
void (*set_refuse_new_connections)(void *, godot_bool);
godot_bool (*is_refusing_new_connections)(const void *);
godot_int (*get_connection_status)(const void *);
void *next; /* For extension? Or maybe not... */
} godot_net_multiplayer_peer;
/* Binds a MultiplayerPeerGDNative to the provided interface */
void GDAPI godot_net_bind_multiplayer_peer(godot_object *p_obj, const godot_net_multiplayer_peer *);
#ifdef __cplusplus
}
#endif
// WebRTC Bindings
#include "net/godot_webrtc.h"
#endif // GODOT_NET_H

129
include/net/godot_webrtc.h Normal file
View File

@ -0,0 +1,129 @@
/**************************************************************************/
/* godot_webrtc.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GODOT_WEBRTC_H
#define GODOT_WEBRTC_H
#include <gdnative/gdnative.h>
#ifdef __cplusplus
extern "C" {
#endif
#define GODOT_NET_WEBRTC_API_MAJOR 3
#define GODOT_NET_WEBRTC_API_MINOR 4
/* Library Interface (used to set default GDNative WebRTC implementation */
typedef struct {
godot_gdnative_api_version version; /* version of our API */
/* Called when the library is unset as default interface via godot_net_set_webrtc_library */
void (*unregistered)();
/* Used by WebRTCPeerConnection create when GDNative is the default implementation. */
/* Takes a pointer to WebRTCPeerConnectionGDNative, should bind and return OK, failure if binding was unsuccessful. */
godot_error (*create_peer_connection)(godot_object *);
void *next; /* For extension */
} godot_net_webrtc_library;
/* WebRTCPeerConnection interface */
typedef struct {
godot_gdnative_api_version version; /* version of our API */
godot_object *data; /* User reference */
/* This is WebRTCPeerConnection */
godot_int (*get_connection_state)(const void *);
godot_error (*initialize)(void *, const godot_dictionary *);
godot_object *(*create_data_channel)(void *, const char *p_channel_name, const godot_dictionary *);
godot_error (*create_offer)(void *);
godot_error (*create_answer)(void *); /* unused for now, should be done automatically on set_local_description */
godot_error (*set_remote_description)(void *, const char *, const char *);
godot_error (*set_local_description)(void *, const char *, const char *);
godot_error (*add_ice_candidate)(void *, const char *, int, const char *);
godot_error (*poll)(void *);
void (*close)(void *);
void *next; /* For extension? */
} godot_net_webrtc_peer_connection;
/* WebRTCDataChannel interface */
typedef struct {
godot_gdnative_api_version version; /* version of our API */
godot_object *data; /* User reference */
/* This is PacketPeer */
godot_error (*get_packet)(void *, const uint8_t **, int *);
godot_error (*put_packet)(void *, const uint8_t *, int);
godot_int (*get_available_packet_count)(const void *);
godot_int (*get_max_packet_size)(const void *);
/* This is WebRTCDataChannel */
void (*set_write_mode)(void *, godot_int);
godot_int (*get_write_mode)(const void *);
bool (*was_string_packet)(const void *);
godot_int (*get_ready_state)(const void *);
const char *(*get_label)(const void *);
bool (*is_ordered)(const void *);
int (*get_id)(const void *);
int (*get_max_packet_life_time)(const void *);
int (*get_max_retransmits)(const void *);
const char *(*get_protocol)(const void *);
bool (*is_negotiated)(const void *);
godot_error (*poll)(void *);
void (*close)(void *);
void *next; /* For extension? */
} godot_net_webrtc_data_channel;
/* Extensions to WebRTCDataChannel */
typedef struct {
int (*get_buffered_amount)(const void *);
void *next; /* For extension? */
} godot_net_webrtc_data_channel_ext;
/* Set the default GDNative library */
godot_error GDAPI godot_net_set_webrtc_library(const godot_net_webrtc_library *);
/* Binds a WebRTCPeerConnectionGDNative to the provided interface */
void GDAPI godot_net_bind_webrtc_peer_connection(godot_object *p_obj, const godot_net_webrtc_peer_connection *);
/* Binds a WebRTCDataChannelGDNative to the provided interface */
void GDAPI godot_net_bind_webrtc_data_channel(godot_object *p_obj, const godot_net_webrtc_data_channel *);
#ifdef __cplusplus
}
#endif
#endif // GODOT_WEBRTC_H

View File

@ -0,0 +1,172 @@
/**************************************************************************/
/* godot_pluginscript.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GODOT_PLUGINSCRIPT_H
#define GODOT_PLUGINSCRIPT_H
#include <gdnative/gdnative.h>
#include <nativescript/godot_nativescript.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef void godot_pluginscript_instance_data;
typedef void godot_pluginscript_script_data;
typedef void godot_pluginscript_language_data;
// --- Instance ---
// TODO: use godot_string_name for faster lookup ?
typedef struct {
godot_pluginscript_instance_data *(*init)(godot_pluginscript_script_data *p_data, godot_object *p_owner);
void (*finish)(godot_pluginscript_instance_data *p_data);
godot_bool (*set_prop)(godot_pluginscript_instance_data *p_data, const godot_string *p_name, const godot_variant *p_value);
godot_bool (*get_prop)(godot_pluginscript_instance_data *p_data, const godot_string *p_name, godot_variant *r_ret);
godot_variant (*call_method)(godot_pluginscript_instance_data *p_data,
const godot_string_name *p_method, const godot_variant **p_args,
int p_argcount, godot_variant_call_error *r_error);
void (*notification)(godot_pluginscript_instance_data *p_data, int p_notification);
// TODO: could this rpc mode stuff be moved to the godot_pluginscript_script_manifest ?
godot_method_rpc_mode (*get_rpc_mode)(godot_pluginscript_instance_data *p_data, const godot_string *p_method);
godot_method_rpc_mode (*get_rset_mode)(godot_pluginscript_instance_data *p_data, const godot_string *p_variable);
//this is used by script languages that keep a reference counter of their own
//you can make make Ref<> not die when it reaches zero, so deleting the reference
//depends entirely from the script.
// Note: You can set those function pointer to NULL if not needed.
void (*refcount_incremented)(godot_pluginscript_instance_data *p_data);
bool (*refcount_decremented)(godot_pluginscript_instance_data *p_data); // return true if it can die
} godot_pluginscript_instance_desc;
// --- Script ---
typedef struct {
godot_pluginscript_script_data *data;
godot_string_name name;
godot_bool is_tool;
godot_string_name base;
// Member lines format: {<string>: <int>}
godot_dictionary member_lines;
// Method info dictionary format
// {
// name: <string>
// args: [<dict:property>]
// default_args: [<variant>]
// return: <dict:property>
// flags: <int>
// rpc_mode: <int:godot_method_rpc_mode>
// }
godot_array methods;
// Same format than for methods
godot_array signals;
// Property info dictionary format
// {
// name: <string>
// type: <int:godot_variant_type>
// hint: <int:godot_property_hint>
// hint_string: <string>
// usage: <int:godot_property_usage_flags>
// default_value: <variant>
// rset_mode: <int:godot_method_rpc_mode>
// }
godot_array properties;
} godot_pluginscript_script_manifest;
typedef struct {
godot_pluginscript_script_manifest (*init)(godot_pluginscript_language_data *p_data, const godot_string *p_path, const godot_string *p_source, godot_error *r_error);
void (*finish)(godot_pluginscript_script_data *p_data);
godot_pluginscript_instance_desc instance_desc;
} godot_pluginscript_script_desc;
// --- Language ---
typedef struct {
godot_string_name signature;
godot_int call_count;
godot_int total_time; // In microseconds
godot_int self_time; // In microseconds
} godot_pluginscript_profiling_data;
typedef struct {
const char *name;
const char *type;
const char *extension;
const char **recognized_extensions; // NULL terminated array
godot_pluginscript_language_data *(*init)();
void (*finish)(godot_pluginscript_language_data *p_data);
const char **reserved_words; // NULL terminated array
const char **comment_delimiters; // NULL terminated array
const char **string_delimiters; // NULL terminated array
godot_bool has_named_classes;
godot_bool supports_builtin_mode;
godot_string (*get_template_source_code)(godot_pluginscript_language_data *p_data, const godot_string *p_class_name, const godot_string *p_base_class_name);
godot_bool (*validate)(godot_pluginscript_language_data *p_data, const godot_string *p_script, int *r_line_error, int *r_col_error, godot_string *r_test_error, const godot_string *p_path, godot_pool_string_array *r_functions);
int (*find_function)(godot_pluginscript_language_data *p_data, const godot_string *p_function, const godot_string *p_code); // Can be NULL
godot_string (*make_function)(godot_pluginscript_language_data *p_data, const godot_string *p_class, const godot_string *p_name, const godot_pool_string_array *p_args);
godot_error (*complete_code)(godot_pluginscript_language_data *p_data, const godot_string *p_code, const godot_string *p_path, godot_object *p_owner, godot_array *r_options, godot_bool *r_force, godot_string *r_call_hint);
void (*auto_indent_code)(godot_pluginscript_language_data *p_data, godot_string *p_code, int p_from_line, int p_to_line);
void (*add_global_constant)(godot_pluginscript_language_data *p_data, const godot_string *p_variable, const godot_variant *p_value);
godot_string (*debug_get_error)(godot_pluginscript_language_data *p_data);
int (*debug_get_stack_level_count)(godot_pluginscript_language_data *p_data);
int (*debug_get_stack_level_line)(godot_pluginscript_language_data *p_data, int p_level);
godot_string (*debug_get_stack_level_function)(godot_pluginscript_language_data *p_data, int p_level);
godot_string (*debug_get_stack_level_source)(godot_pluginscript_language_data *p_data, int p_level);
void (*debug_get_stack_level_locals)(godot_pluginscript_language_data *p_data, int p_level, godot_pool_string_array *p_locals, godot_array *p_values, int p_max_subitems, int p_max_depth);
void (*debug_get_stack_level_members)(godot_pluginscript_language_data *p_data, int p_level, godot_pool_string_array *p_members, godot_array *p_values, int p_max_subitems, int p_max_depth);
void (*debug_get_globals)(godot_pluginscript_language_data *p_data, godot_pool_string_array *p_locals, godot_array *p_values, int p_max_subitems, int p_max_depth);
godot_string (*debug_parse_stack_level_expression)(godot_pluginscript_language_data *p_data, int p_level, const godot_string *p_expression, int p_max_subitems, int p_max_depth);
// TODO: could this stuff be moved to the godot_pluginscript_language_desc ?
void (*get_public_functions)(godot_pluginscript_language_data *p_data, godot_array *r_functions);
void (*get_public_constants)(godot_pluginscript_language_data *p_data, godot_dictionary *r_constants);
void (*profiling_start)(godot_pluginscript_language_data *p_data);
void (*profiling_stop)(godot_pluginscript_language_data *p_data);
int (*profiling_get_accumulated_data)(godot_pluginscript_language_data *p_data, godot_pluginscript_profiling_data *r_info, int p_info_max);
int (*profiling_get_frame_data)(godot_pluginscript_language_data *p_data, godot_pluginscript_profiling_data *r_info, int p_info_max);
void (*profiling_frame)(godot_pluginscript_language_data *p_data);
godot_pluginscript_script_desc script_desc;
} godot_pluginscript_language_desc;
void GDAPI godot_pluginscript_register_language(const godot_pluginscript_language_desc *language_desc);
#ifdef __cplusplus
}
#endif
#endif // GODOT_PLUGINSCRIPT_H

View File

@ -0,0 +1,75 @@
/**************************************************************************/
/* godot_videodecoder.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GODOT_VIDEODECODER_H
#define GODOT_VIDEODECODER_H
#include <gdnative/gdnative.h>
#ifdef __cplusplus
extern "C" {
#endif
#define GODOTAV_API_MAJOR 0
#define GODOTAV_API_MINOR 1
typedef struct
{
godot_gdnative_api_version version;
void *next;
void *(*constructor)(godot_object *);
void (*destructor)(void *);
const char *(*get_plugin_name)();
const char **(*get_supported_extensions)(int *count);
godot_bool (*open_file)(void *, void *); // data struct, and a FileAccess pointer
godot_real (*get_length)(const void *);
godot_real (*get_playback_position)(const void *);
void (*seek)(void *, godot_real);
void (*set_audio_track)(void *, godot_int);
void (*update)(void *, godot_real);
godot_pool_byte_array *(*get_videoframe)(void *);
godot_int (*get_audioframe)(void *, float *, int);
godot_int (*get_channels)(const void *);
godot_int (*get_mix_rate)(const void *);
godot_vector2 (*get_texture_size)(const void *);
} godot_videodecoder_interface_gdnative;
typedef int (*GDNativeAudioMixCallback)(void *, const float *, int);
// FileAccess wrappers for custom FFmpeg IO
godot_int GDAPI godot_videodecoder_file_read(void *file_ptr, uint8_t *buf, int buf_size);
int64_t GDAPI godot_videodecoder_file_seek(void *file_ptr, int64_t pos, int whence);
void GDAPI godot_videodecoder_register_decoder(const godot_videodecoder_interface_gdnative *p_interface);
#ifdef __cplusplus
}
#endif
#endif // GODOT_VIDEODECODER_H

9
nativescript/SCsub Normal file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env python
Import("env")
Import("env_gdnative")
env_gdnative.add_source_files(env.modules_sources, "*.cpp")
if "platform" in env and env["platform"] in ["x11", "iphone"]:
env.Append(LINKFLAGS=["-rdynamic"])

View File

@ -0,0 +1,528 @@
/**************************************************************************/
/* api_generator.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "api_generator.h"
#ifdef TOOLS_ENABLED
#include "core/class_db.h"
#include "core/engine.h"
#include "core/global_constants.h"
#include "core/os/file_access.h"
#include "core/pair.h"
// helper stuff
static Error save_file(const String &p_path, const List<String> &p_content) {
FileAccessRef file = FileAccess::open(p_path, FileAccess::WRITE);
ERR_FAIL_COND_V(!file, ERR_FILE_CANT_WRITE);
for (const List<String>::Element *e = p_content.front(); e != nullptr; e = e->next()) {
file->store_string(e->get());
}
file->close();
return OK;
}
// helper stuff end
struct MethodAPI {
String method_name;
String return_type;
List<String> argument_types;
List<String> argument_names;
Map<int, Variant> default_arguments;
int argument_count;
bool has_varargs;
bool is_editor;
bool is_noscript;
bool is_const;
bool is_reverse;
bool is_virtual;
bool is_from_script;
};
struct PropertyAPI {
String name;
String getter;
String setter;
String type;
int index;
};
struct ConstantAPI {
String constant_name;
int constant_value;
};
struct SignalAPI {
String name;
List<String> argument_types;
List<String> argument_names;
Map<int, Variant> default_arguments;
};
struct EnumAPI {
String name;
List<Pair<int, String>> values;
};
struct ClassAPI {
String class_name;
String super_class_name;
ClassDB::APIType api_type;
bool is_singleton;
String singleton_name;
bool is_instanciable;
// @Unclear
bool is_reference;
List<MethodAPI> methods;
List<PropertyAPI> properties;
List<ConstantAPI> constants;
List<SignalAPI> signals_;
List<EnumAPI> enums;
};
static String get_type_name(const PropertyInfo &info) {
if (info.type == Variant::INT && (info.usage & PROPERTY_USAGE_CLASS_IS_ENUM)) {
return String("enum.") + String(info.class_name).replace(".", "::");
}
if (info.class_name != StringName()) {
return info.class_name;
}
if (info.hint == PROPERTY_HINT_RESOURCE_TYPE) {
return info.hint_string;
}
if (info.type == Variant::NIL && (info.usage & PROPERTY_USAGE_NIL_IS_VARIANT)) {
return "Variant";
}
if (info.type == Variant::NIL) {
return "void";
}
return Variant::get_type_name(info.type);
}
/*
* Some comparison helper functions we need
*/
struct MethodInfoComparator {
StringName::AlphCompare compare;
bool operator()(const MethodInfo &p_a, const MethodInfo &p_b) const {
return compare(p_a.name, p_b.name);
}
};
struct PropertyInfoComparator {
StringName::AlphCompare compare;
bool operator()(const PropertyInfo &p_a, const PropertyInfo &p_b) const {
return compare(p_a.name, p_b.name);
}
};
struct ConstantAPIComparator {
NoCaseComparator compare;
bool operator()(const ConstantAPI &p_a, const ConstantAPI &p_b) const {
return compare(p_a.constant_name, p_b.constant_name);
}
};
/*
* Reads the entire Godot API to a list
*/
List<ClassAPI> generate_c_api_classes() {
List<ClassAPI> api;
List<StringName> classes;
ClassDB::get_class_list(&classes);
classes.sort_custom<StringName::AlphCompare>();
// Register global constants as a fake GlobalConstants singleton class
{
ClassAPI global_constants_api;
global_constants_api.class_name = L"GlobalConstants";
global_constants_api.api_type = ClassDB::API_CORE;
global_constants_api.is_singleton = true;
global_constants_api.singleton_name = L"GlobalConstants";
global_constants_api.is_instanciable = false;
const int constants_count = GlobalConstants::get_global_constant_count();
for (int i = 0; i < constants_count; ++i) {
ConstantAPI constant_api;
constant_api.constant_name = GlobalConstants::get_global_constant_name(i);
constant_api.constant_value = GlobalConstants::get_global_constant_value(i);
global_constants_api.constants.push_back(constant_api);
}
global_constants_api.constants.sort_custom<ConstantAPIComparator>();
api.push_back(global_constants_api);
}
for (List<StringName>::Element *e = classes.front(); e != nullptr; e = e->next()) {
StringName class_name = e->get();
ClassAPI class_api;
class_api.api_type = ClassDB::get_api_type(e->get());
class_api.class_name = class_name;
class_api.super_class_name = ClassDB::get_parent_class(class_name);
{
String name = class_name;
if (name.begins_with("_")) {
name.remove(0);
}
class_api.is_singleton = Engine::get_singleton()->has_singleton(name);
if (class_api.is_singleton) {
class_api.singleton_name = name;
}
}
class_api.is_instanciable = !class_api.is_singleton && ClassDB::can_instance(class_name);
{
List<StringName> inheriters;
ClassDB::get_inheriters_from_class("Reference", &inheriters);
bool is_reference = !!inheriters.find(class_name) || class_name == "Reference";
// @Unclear
class_api.is_reference = !class_api.is_singleton && is_reference;
}
// constants
{
List<String> constant;
ClassDB::get_integer_constant_list(class_name, &constant, true);
constant.sort_custom<NoCaseComparator>();
for (List<String>::Element *c = constant.front(); c != nullptr; c = c->next()) {
ConstantAPI constant_api;
constant_api.constant_name = c->get();
constant_api.constant_value = ClassDB::get_integer_constant(class_name, c->get());
class_api.constants.push_back(constant_api);
}
}
// signals
{
List<MethodInfo> signals_;
ClassDB::get_signal_list(class_name, &signals_, true);
signals_.sort_custom<MethodInfoComparator>();
for (int i = 0; i < signals_.size(); i++) {
SignalAPI signal;
MethodInfo method_info = signals_[i];
signal.name = method_info.name;
for (int j = 0; j < method_info.arguments.size(); j++) {
PropertyInfo argument = method_info.arguments[j];
String type;
String name = argument.name;
if (argument.name.find(":") != -1) {
type = argument.name.get_slice(":", 1);
name = argument.name.get_slice(":", 0);
} else {
type = get_type_name(argument);
}
signal.argument_names.push_back(name);
signal.argument_types.push_back(type);
}
Vector<Variant> default_arguments = method_info.default_arguments;
int default_start = signal.argument_names.size() - default_arguments.size();
for (int j = 0; j < default_arguments.size(); j++) {
signal.default_arguments[default_start + j] = default_arguments[j];
}
class_api.signals_.push_back(signal);
}
}
//properties
{
List<PropertyInfo> properties;
ClassDB::get_property_list(class_name, &properties, true);
properties.sort_custom<PropertyInfoComparator>();
for (List<PropertyInfo>::Element *p = properties.front(); p != nullptr; p = p->next()) {
PropertyAPI property_api;
property_api.name = p->get().name;
property_api.getter = ClassDB::get_property_getter(class_name, p->get().name);
property_api.setter = ClassDB::get_property_setter(class_name, p->get().name);
if (p->get().name.find(":") != -1) {
property_api.type = p->get().name.get_slice(":", 1);
property_api.name = p->get().name.get_slice(":", 0);
} else {
property_api.type = get_type_name(p->get());
}
property_api.index = ClassDB::get_property_index(class_name, p->get().name);
if (!property_api.setter.empty() || !property_api.getter.empty()) {
class_api.properties.push_back(property_api);
}
}
}
//methods
{
List<MethodInfo> methods;
ClassDB::get_method_list(class_name, &methods, true);
methods.sort_custom<MethodInfoComparator>();
for (List<MethodInfo>::Element *m = methods.front(); m != nullptr; m = m->next()) {
MethodAPI method_api;
MethodBind *method_bind = ClassDB::get_method(class_name, m->get().name);
MethodInfo &method_info = m->get();
//method name
method_api.method_name = method_info.name;
//method return type
if (method_api.method_name.find(":") != -1) {
method_api.return_type = method_api.method_name.get_slice(":", 1);
method_api.method_name = method_api.method_name.get_slice(":", 0);
} else {
method_api.return_type = get_type_name(m->get().return_val);
}
method_api.argument_count = method_info.arguments.size();
method_api.has_varargs = method_bind && method_bind->is_vararg();
// Method flags
method_api.is_virtual = false;
if (method_info.flags) {
const uint32_t flags = method_info.flags;
method_api.is_editor = flags & METHOD_FLAG_EDITOR;
method_api.is_noscript = flags & METHOD_FLAG_NOSCRIPT;
method_api.is_const = flags & METHOD_FLAG_CONST;
method_api.is_reverse = flags & METHOD_FLAG_REVERSE;
method_api.is_virtual = flags & METHOD_FLAG_VIRTUAL;
method_api.is_from_script = flags & METHOD_FLAG_FROM_SCRIPT;
}
method_api.is_virtual = method_api.is_virtual || method_api.method_name[0] == '_';
// method argument name and type
for (int i = 0; i < method_api.argument_count; i++) {
String arg_name;
String arg_type;
PropertyInfo arg_info = method_info.arguments[i];
arg_name = arg_info.name;
if (arg_info.name.find(":") != -1) {
arg_type = arg_info.name.get_slice(":", 1);
arg_name = arg_info.name.get_slice(":", 0);
} else if (arg_info.hint == PROPERTY_HINT_RESOURCE_TYPE) {
arg_type = arg_info.hint_string;
} else if (arg_info.type == Variant::NIL) {
arg_type = "Variant";
} else if (arg_info.type == Variant::OBJECT) {
arg_type = arg_info.class_name;
if (arg_type == "") {
arg_type = Variant::get_type_name(arg_info.type);
}
} else {
arg_type = Variant::get_type_name(arg_info.type);
}
method_api.argument_names.push_back(arg_name);
method_api.argument_types.push_back(arg_type);
if (method_bind && method_bind->has_default_argument(i)) {
method_api.default_arguments[i] = method_bind->get_default_argument(i);
}
}
class_api.methods.push_back(method_api);
}
}
// enums
{
List<EnumAPI> enums;
List<StringName> enum_names;
ClassDB::get_enum_list(class_name, &enum_names, true);
for (List<StringName>::Element *E = enum_names.front(); E; E = E->next()) {
List<StringName> value_names;
EnumAPI enum_api;
enum_api.name = E->get();
ClassDB::get_enum_constants(class_name, E->get(), &value_names, true);
for (List<StringName>::Element *val_e = value_names.front(); val_e; val_e = val_e->next()) {
int int_val = ClassDB::get_integer_constant(class_name, val_e->get(), nullptr);
enum_api.values.push_back(Pair<int, String>(int_val, val_e->get()));
}
enum_api.values.sort_custom<PairSort<int, String>>();
class_api.enums.push_back(enum_api);
}
}
api.push_back(class_api);
}
return api;
}
/*
* Generates the JSON source from the API in p_api
*/
static List<String> generate_c_api_json(const List<ClassAPI> &p_api) {
// I'm sorry for the \t mess
List<String> source;
source.push_back("[\n");
for (const List<ClassAPI>::Element *c = p_api.front(); c != nullptr; c = c->next()) {
ClassAPI api = c->get();
source.push_back("\t{\n");
source.push_back("\t\t\"name\": \"" + api.class_name + "\",\n");
source.push_back("\t\t\"base_class\": \"" + api.super_class_name + "\",\n");
source.push_back(String("\t\t\"api_type\": \"") + (api.api_type == ClassDB::API_CORE ? "core" : (api.api_type == ClassDB::API_EDITOR ? "tools" : "none")) + "\",\n");
source.push_back(String("\t\t\"singleton\": ") + (api.is_singleton ? "true" : "false") + ",\n");
source.push_back("\t\t\"singleton_name\": \"" + api.singleton_name + "\",\n");
source.push_back(String("\t\t\"instanciable\": ") + (api.is_instanciable ? "true" : "false") + ",\n");
source.push_back(String("\t\t\"is_reference\": ") + (api.is_reference ? "true" : "false") + ",\n");
// @Unclear
source.push_back("\t\t\"constants\": {\n");
for (List<ConstantAPI>::Element *e = api.constants.front(); e; e = e->next()) {
source.push_back("\t\t\t\"" + e->get().constant_name + "\": " + String::num_int64(e->get().constant_value) + (e->next() ? "," : "") + "\n");
}
source.push_back("\t\t},\n");
source.push_back("\t\t\"properties\": [\n");
for (List<PropertyAPI>::Element *e = api.properties.front(); e; e = e->next()) {
source.push_back("\t\t\t{\n");
source.push_back("\t\t\t\t\"name\": \"" + e->get().name + "\",\n");
source.push_back("\t\t\t\t\"type\": \"" + e->get().type + "\",\n");
source.push_back("\t\t\t\t\"getter\": \"" + e->get().getter + "\",\n");
source.push_back("\t\t\t\t\"setter\": \"" + e->get().setter + "\",\n");
source.push_back(String("\t\t\t\t\"index\": ") + itos(e->get().index) + "\n");
source.push_back(String("\t\t\t}") + (e->next() ? "," : "") + "\n");
}
source.push_back("\t\t],\n");
source.push_back("\t\t\"signals\": [\n");
for (List<SignalAPI>::Element *e = api.signals_.front(); e; e = e->next()) {
source.push_back("\t\t\t{\n");
source.push_back("\t\t\t\t\"name\": \"" + e->get().name + "\",\n");
source.push_back("\t\t\t\t\"arguments\": [\n");
for (int i = 0; i < e->get().argument_names.size(); i++) {
source.push_back("\t\t\t\t\t{\n");
source.push_back("\t\t\t\t\t\t\"name\": \"" + e->get().argument_names[i] + "\",\n");
source.push_back("\t\t\t\t\t\t\"type\": \"" + e->get().argument_types[i] + "\",\n");
source.push_back(String("\t\t\t\t\t\t\"has_default_value\": ") + (e->get().default_arguments.has(i) ? "true" : "false") + ",\n");
source.push_back("\t\t\t\t\t\t\"default_value\": \"" + (e->get().default_arguments.has(i) ? (String)e->get().default_arguments[i] : "") + "\"\n");
source.push_back(String("\t\t\t\t\t}") + ((i < e->get().argument_names.size() - 1) ? "," : "") + "\n");
}
source.push_back("\t\t\t\t]\n");
source.push_back(String("\t\t\t}") + (e->next() ? "," : "") + "\n");
}
source.push_back("\t\t],\n");
source.push_back("\t\t\"methods\": [\n");
for (List<MethodAPI>::Element *e = api.methods.front(); e; e = e->next()) {
source.push_back("\t\t\t{\n");
source.push_back("\t\t\t\t\"name\": \"" + e->get().method_name + "\",\n");
source.push_back("\t\t\t\t\"return_type\": \"" + e->get().return_type + "\",\n");
source.push_back(String("\t\t\t\t\"is_editor\": ") + (e->get().is_editor ? "true" : "false") + ",\n");
source.push_back(String("\t\t\t\t\"is_noscript\": ") + (e->get().is_noscript ? "true" : "false") + ",\n");
source.push_back(String("\t\t\t\t\"is_const\": ") + (e->get().is_const ? "true" : "false") + ",\n");
source.push_back(String("\t\t\t\t\"is_reverse\": ") + (e->get().is_reverse ? "true" : "false") + ",\n");
source.push_back(String("\t\t\t\t\"is_virtual\": ") + (e->get().is_virtual ? "true" : "false") + ",\n");
source.push_back(String("\t\t\t\t\"has_varargs\": ") + (e->get().has_varargs ? "true" : "false") + ",\n");
source.push_back(String("\t\t\t\t\"is_from_script\": ") + (e->get().is_from_script ? "true" : "false") + ",\n");
source.push_back("\t\t\t\t\"arguments\": [\n");
for (int i = 0; i < e->get().argument_names.size(); i++) {
source.push_back("\t\t\t\t\t{\n");
source.push_back("\t\t\t\t\t\t\"name\": \"" + e->get().argument_names[i] + "\",\n");
source.push_back("\t\t\t\t\t\t\"type\": \"" + e->get().argument_types[i] + "\",\n");
source.push_back(String("\t\t\t\t\t\t\"has_default_value\": ") + (e->get().default_arguments.has(i) ? "true" : "false") + ",\n");
source.push_back("\t\t\t\t\t\t\"default_value\": \"" + (e->get().default_arguments.has(i) ? (String)e->get().default_arguments[i] : "") + "\"\n");
source.push_back(String("\t\t\t\t\t}") + ((i < e->get().argument_names.size() - 1) ? "," : "") + "\n");
}
source.push_back("\t\t\t\t]\n");
source.push_back(String("\t\t\t}") + (e->next() ? "," : "") + "\n");
}
source.push_back("\t\t],\n");
source.push_back("\t\t\"enums\": [\n");
for (List<EnumAPI>::Element *e = api.enums.front(); e; e = e->next()) {
source.push_back("\t\t\t{\n");
source.push_back("\t\t\t\t\"name\": \"" + e->get().name + "\",\n");
source.push_back("\t\t\t\t\"values\": {\n");
for (List<Pair<int, String>>::Element *val_e = e->get().values.front(); val_e; val_e = val_e->next()) {
source.push_back("\t\t\t\t\t\"" + val_e->get().second + "\": " + itos(val_e->get().first));
source.push_back(String((val_e->next() ? "," : "")) + "\n");
}
source.push_back("\t\t\t\t}\n");
source.push_back(String("\t\t\t}") + (e->next() ? "," : "") + "\n");
}
source.push_back("\t\t]\n");
source.push_back(String("\t}") + (c->next() ? "," : "") + "\n");
}
source.push_back("]");
return source;
}
#endif
/*
* Saves the whole Godot API to a JSON file located at
* p_path
*/
Error generate_c_api(const String &p_path) {
#ifndef TOOLS_ENABLED
return ERR_BUG;
#else
List<ClassAPI> api = generate_c_api_classes();
List<String> json_source = generate_c_api_json(api);
return save_file(p_path, json_source);
#endif
}

View File

@ -0,0 +1,39 @@
/**************************************************************************/
/* api_generator.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef API_GENERATOR_H
#define API_GENERATOR_H
#include "core/typedefs.h"
#include "core/ustring.h"
Error generate_c_api(const String &p_path);
#endif // API_GENERATOR_H

View File

@ -0,0 +1,322 @@
/**************************************************************************/
/* godot_nativescript.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "nativescript/godot_nativescript.h"
#include "core/class_db.h"
#include "core/error_macros.h"
#include "core/global_constants.h"
#include "core/project_settings.h"
#include "core/variant.h"
#include "gdnative/gdnative.h"
#include "nativescript.h"
#ifdef __cplusplus
extern "C" {
#endif
extern "C" void _native_script_hook() {
}
#define NSL NativeScriptLanguage::get_singleton()
// Script API
void GDAPI godot_nativescript_register_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc> *classes = &NSL->library_classes[*s];
NativeScriptDesc desc;
desc.create_func = p_create_func;
desc.destroy_func = p_destroy_func;
desc.is_tool = false;
desc.base = p_base;
if (classes->has(p_base)) {
desc.base_data = &(*classes)[p_base];
desc.base_native_type = desc.base_data->base_native_type;
} else {
desc.base_data = nullptr;
desc.base_native_type = p_base;
}
classes->insert(p_name, desc);
}
void GDAPI godot_nativescript_register_tool_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc> *classes = &NSL->library_classes[*s];
NativeScriptDesc desc;
desc.create_func = p_create_func;
desc.destroy_func = p_destroy_func;
desc.is_tool = true;
desc.base = p_base;
if (classes->has(p_base)) {
desc.base_data = &(*classes)[p_base];
desc.base_native_type = desc.base_data->base_native_type;
} else {
desc.base_data = nullptr;
desc.base_native_type = p_base;
}
classes->insert(p_name, desc);
}
void GDAPI godot_nativescript_register_method(void *p_gdnative_handle, const char *p_name, const char *p_function_name, godot_method_attributes p_attr, godot_instance_method p_method) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name);
ERR_FAIL_COND_MSG(!E, "Attempted to register method on non-existent class.");
NativeScriptDesc::Method method;
method.method = p_method;
method.rpc_mode = p_attr.rpc_type;
method.info = MethodInfo(p_function_name);
E->get().methods.insert(p_function_name, method);
}
void GDAPI godot_nativescript_register_property(void *p_gdnative_handle, const char *p_name, const char *p_path, godot_property_attributes *p_attr, godot_property_set_func p_set_func, godot_property_get_func p_get_func) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name);
ERR_FAIL_COND_MSG(!E, "Attempted to register method on non-existent class.");
NativeScriptDesc::Property property;
property.default_value = *(Variant *)&p_attr->default_value;
property.getter = p_get_func;
property.rset_mode = p_attr->rset_type;
property.setter = p_set_func;
property.info = PropertyInfo((Variant::Type)p_attr->type,
p_path,
(PropertyHint)p_attr->hint,
*(String *)&p_attr->hint_string,
(PropertyUsageFlags)p_attr->usage);
E->get().properties.insert(p_path, property);
}
void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const char *p_name, const godot_signal *p_signal) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name);
ERR_FAIL_COND_MSG(!E, "Attempted to register method on non-existent class.");
List<PropertyInfo> args;
Vector<Variant> default_args;
for (int i = 0; i < p_signal->num_args; i++) {
PropertyInfo info;
godot_signal_argument arg = p_signal->args[i];
info.hint = (PropertyHint)arg.hint;
info.hint_string = *(String *)&arg.hint_string;
info.name = *(String *)&arg.name;
info.type = (Variant::Type)arg.type;
info.usage = (PropertyUsageFlags)arg.usage;
args.push_back(info);
}
for (int i = 0; i < p_signal->num_default_args; i++) {
Variant *v;
godot_signal_argument attrib = p_signal->args[i];
v = (Variant *)&attrib.default_value;
default_args.push_back(*v);
}
MethodInfo method_info;
method_info.name = *(String *)&p_signal->name;
method_info.arguments = args;
method_info.default_arguments = default_args;
NativeScriptDesc::Signal signal;
signal.signal = method_info;
E->get().signals_.insert(*(String *)&p_signal->name, signal);
}
void GDAPI *godot_nativescript_get_userdata(godot_object *p_instance) {
Object *instance = (Object *)p_instance;
if (!instance) {
return nullptr;
}
if (instance->get_script_instance() && instance->get_script_instance()->get_language() == NativeScriptLanguage::get_singleton()) {
return ((NativeScriptInstance *)instance->get_script_instance())->userdata;
}
return nullptr;
}
/*
*
*
* NativeScript 1.1
*
*
*/
void GDAPI godot_nativescript_set_method_argument_information(void *p_gdnative_handle, const char *p_name, const char *p_function_name, int p_num_args, const godot_method_arg *p_args) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name);
ERR_FAIL_COND_MSG(!E, "Attempted to add argument information for a method on a non-existent class.");
Map<StringName, NativeScriptDesc::Method>::Element *method = E->get().methods.find(p_function_name);
ERR_FAIL_COND_MSG(!method, "Attempted to add argument information to non-existent method.");
MethodInfo *method_information = &method->get().info;
List<PropertyInfo> args;
for (int i = 0; i < p_num_args; i++) {
godot_method_arg arg = p_args[i];
String name = *(String *)&arg.name;
String hint_string = *(String *)&arg.hint_string;
Variant::Type type = (Variant::Type)arg.type;
PropertyHint hint = (PropertyHint)arg.hint;
args.push_back(PropertyInfo(type, p_name, hint, hint_string));
}
method_information->arguments = args;
}
void GDAPI godot_nativescript_set_class_documentation(void *p_gdnative_handle, const char *p_name, godot_string p_documentation) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name);
ERR_FAIL_COND_MSG(!E, "Attempted to add documentation to a non-existent class.");
E->get().documentation = *(String *)&p_documentation;
}
void GDAPI godot_nativescript_set_method_documentation(void *p_gdnative_handle, const char *p_name, const char *p_function_name, godot_string p_documentation) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name);
ERR_FAIL_COND_MSG(!E, "Attempted to add documentation to a method on a non-existent class.");
Map<StringName, NativeScriptDesc::Method>::Element *method = E->get().methods.find(p_function_name);
ERR_FAIL_COND_MSG(!method, "Attempted to add documentation to non-existent method.");
method->get().documentation = *(String *)&p_documentation;
}
void GDAPI godot_nativescript_set_property_documentation(void *p_gdnative_handle, const char *p_name, const char *p_path, godot_string p_documentation) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name);
ERR_FAIL_COND_MSG(!E, "Attempted to add documentation to a property on a non-existent class.");
OrderedHashMap<StringName, NativeScriptDesc::Property>::Element property = E->get().properties.find(p_path);
ERR_FAIL_COND_MSG(!property, "Attempted to add documentation to non-existent property.");
property.get().documentation = *(String *)&p_documentation;
}
void GDAPI godot_nativescript_set_signal_documentation(void *p_gdnative_handle, const char *p_name, const char *p_signal_name, godot_string p_documentation) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name);
ERR_FAIL_COND_MSG(!E, "Attempted to add documentation to a signal on a non-existent class.");
Map<StringName, NativeScriptDesc::Signal>::Element *signal = E->get().signals_.find(p_signal_name);
ERR_FAIL_COND_MSG(!signal, "Attempted to add documentation to non-existent signal.");
signal->get().documentation = *(String *)&p_documentation;
}
void GDAPI godot_nativescript_set_global_type_tag(int p_idx, const char *p_name, const void *p_type_tag) {
NativeScriptLanguage::get_singleton()->set_global_type_tag(p_idx, StringName(p_name), p_type_tag);
}
const void GDAPI *godot_nativescript_get_global_type_tag(int p_idx, const char *p_name) {
return NativeScriptLanguage::get_singleton()->get_global_type_tag(p_idx, StringName(p_name));
}
void GDAPI godot_nativescript_set_type_tag(void *p_gdnative_handle, const char *p_name, const void *p_type_tag) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name);
ERR_FAIL_COND_MSG(!E, "Attempted to set type tag on a non-existent class.");
E->get().type_tag = p_type_tag;
}
const void GDAPI *godot_nativescript_get_type_tag(const godot_object *p_object) {
const Object *o = (Object *)p_object;
if (!o->get_script_instance()) {
return nullptr;
} else {
NativeScript *script = Object::cast_to<NativeScript>(o->get_script_instance()->get_script().ptr());
if (!script) {
return nullptr;
}
if (script->get_script_desc()) {
return script->get_script_desc()->type_tag;
}
}
return nullptr;
}
int GDAPI godot_nativescript_register_instance_binding_data_functions(godot_instance_binding_functions p_binding_functions) {
return NativeScriptLanguage::get_singleton()->register_binding_functions(p_binding_functions);
}
void GDAPI godot_nativescript_unregister_instance_binding_data_functions(int p_idx) {
NativeScriptLanguage::get_singleton()->unregister_binding_functions(p_idx);
}
void GDAPI *godot_nativescript_get_instance_binding_data(int p_idx, godot_object *p_object) {
return NativeScriptLanguage::get_singleton()->get_instance_binding_data(p_idx, (Object *)p_object);
}
void GDAPI godot_nativescript_profiling_add_data(const char *p_signature, uint64_t p_time) {
NativeScriptLanguage::get_singleton()->profiling_add_data(StringName(p_signature), p_time);
}
#ifdef __cplusplus
}
#endif

File diff suppressed because it is too large Load Diff

394
nativescript/nativescript.h Normal file
View File

@ -0,0 +1,394 @@
/**************************************************************************/
/* nativescript.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef NATIVESCRIPT_H
#define NATIVESCRIPT_H
#include "core/io/resource_loader.h"
#include "core/io/resource_saver.h"
#include "core/oa_hash_map.h"
#include "core/ordered_hash_map.h"
#include "core/os/thread_safe.h"
#include "core/resource.h"
#include "core/safe_refcount.h"
#include "core/script_language.h"
#include "core/self_list.h"
#include "scene/main/node.h"
#include "modules/gdnative/gdnative.h"
#include <nativescript/godot_nativescript.h>
#ifndef NO_THREADS
#include "core/os/mutex.h"
#endif
struct NativeScriptDesc {
struct Method {
godot_instance_method method;
MethodInfo info;
int rpc_mode;
String documentation;
};
struct Property {
godot_property_set_func setter;
godot_property_get_func getter;
PropertyInfo info;
Variant default_value;
int rset_mode;
String documentation;
};
struct Signal {
MethodInfo signal;
String documentation;
};
Map<StringName, Method> methods;
OrderedHashMap<StringName, Property> properties;
Map<StringName, Signal> signals_; // QtCreator doesn't like the name signals
StringName base;
StringName base_native_type;
NativeScriptDesc *base_data;
godot_instance_create_func create_func;
godot_instance_destroy_func destroy_func;
String documentation;
const void *type_tag;
bool is_tool;
inline NativeScriptDesc() :
methods(),
properties(),
signals_(),
base(),
base_native_type(),
documentation(),
type_tag(nullptr) {
memset(&create_func, 0, sizeof(godot_instance_create_func));
memset(&destroy_func, 0, sizeof(godot_instance_destroy_func));
}
};
class NativeScript : public Script {
GDCLASS(NativeScript, Script);
#ifdef TOOLS_ENABLED
Set<PlaceHolderScriptInstance *> placeholders;
void _update_placeholder(PlaceHolderScriptInstance *p_placeholder);
virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder);
#endif
friend class NativeScriptInstance;
friend class NativeScriptLanguage;
friend class NativeReloadNode;
friend class GDNativeLibrary;
Ref<GDNativeLibrary> library;
String lib_path;
String class_name;
String script_class_name;
String script_class_icon_path;
Mutex owners_lock;
Set<Object *> instance_owners;
protected:
static void _bind_methods();
public:
inline NativeScriptDesc *get_script_desc() const;
bool inherits_script(const Ref<Script> &p_script) const;
void set_class_name(String p_class_name);
String get_class_name() const;
void set_library(Ref<GDNativeLibrary> p_library);
Ref<GDNativeLibrary> get_library() const;
void set_script_class_name(String p_type);
String get_script_class_name() const;
void set_script_class_icon_path(String p_icon_path);
String get_script_class_icon_path() const;
virtual bool can_instance() const;
virtual Ref<Script> get_base_script() const; //for script inheritance
virtual StringName get_instance_base_type() const; // this may not work in all scripts, will return empty if so
virtual ScriptInstance *instance_create(Object *p_this);
virtual PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this);
virtual bool instance_has(const Object *p_this) const;
virtual bool has_source_code() const;
virtual String get_source_code() const;
virtual void set_source_code(const String &p_code);
virtual Error reload(bool p_keep_state = false);
virtual bool has_method(const StringName &p_method) const;
virtual MethodInfo get_method_info(const StringName &p_method) const;
virtual bool is_tool() const;
virtual bool is_valid() const;
virtual ScriptLanguage *get_language() const;
virtual bool has_script_signal(const StringName &p_signal) const;
virtual void get_script_signal_list(List<MethodInfo> *r_signals) const;
virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const;
virtual void update_exports(); //editor tool
virtual void get_script_method_list(List<MethodInfo> *p_list) const;
virtual void get_script_property_list(List<PropertyInfo> *p_list) const;
String get_class_documentation() const;
String get_method_documentation(const StringName &p_method) const;
String get_signal_documentation(const StringName &p_signal_name) const;
String get_property_documentation(const StringName &p_path) const;
Variant _new(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
NativeScript();
~NativeScript();
};
class NativeScriptInstance : public ScriptInstance {
friend class NativeScript;
Object *owner;
Ref<NativeScript> script;
#ifdef DEBUG_ENABLED
StringName current_method_call;
#endif
void _ml_call_reversed(NativeScriptDesc *script_data, const StringName &p_method, const Variant **p_args, int p_argcount);
public:
void *userdata;
virtual bool set(const StringName &p_name, const Variant &p_value);
virtual bool get(const StringName &p_name, Variant &r_ret) const;
virtual void get_property_list(List<PropertyInfo> *p_properties) const;
virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid) const;
virtual void get_method_list(List<MethodInfo> *p_list) const;
virtual bool has_method(const StringName &p_method) const;
virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error);
virtual void notification(int p_notification);
String to_string(bool *r_valid);
virtual Ref<Script> get_script() const;
virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const;
virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const;
virtual ScriptLanguage *get_language();
virtual void call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount);
virtual void call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount);
virtual void refcount_incremented();
virtual bool refcount_decremented();
~NativeScriptInstance();
};
class NativeReloadNode;
class NativeScriptLanguage : public ScriptLanguage {
friend class NativeScript;
friend class NativeScriptInstance;
friend class NativeReloadNode;
private:
static NativeScriptLanguage *singleton;
int lang_idx;
void _unload_stuff(bool p_reload = false);
#ifndef NO_THREADS
Mutex mutex;
Set<Ref<GDNativeLibrary>> libs_to_init;
Set<NativeScript *> scripts_to_register;
SafeFlag has_objects_to_register; // so that we don't lock mutex every frame - it's rarely needed
void defer_init_library(Ref<GDNativeLibrary> lib, NativeScript *script);
#endif
void init_library(const Ref<GDNativeLibrary> &lib);
void register_script(NativeScript *script);
void unregister_script(NativeScript *script);
void call_libraries_cb(const StringName &name);
Vector<Pair<bool, godot_instance_binding_functions>> binding_functions;
Set<Vector<void *> *> binding_instances;
Map<int, HashMap<StringName, const void *>> global_type_tags;
struct ProfileData {
StringName signature;
uint64_t call_count;
uint64_t self_time;
uint64_t total_time;
uint64_t frame_call_count;
uint64_t frame_self_time;
uint64_t frame_total_time;
uint64_t last_frame_call_count;
uint64_t last_frame_self_time;
uint64_t last_frame_total_time;
};
Map<StringName, ProfileData> profile_data;
public:
// These two maps must only be touched on the main thread
Map<String, Map<StringName, NativeScriptDesc>> library_classes;
Map<String, Ref<GDNative>> library_gdnatives;
Map<String, Set<NativeScript *>> library_script_users;
StringName _init_call_type;
StringName _init_call_name;
StringName _terminate_call_name;
StringName _noarg_call_type;
StringName _frame_call_name;
#ifndef NO_THREADS
StringName _thread_enter_call_name;
StringName _thread_exit_call_name;
#endif
NativeScriptLanguage();
~NativeScriptLanguage();
inline static NativeScriptLanguage *get_singleton() {
return singleton;
}
_FORCE_INLINE_ void set_language_index(int p_idx) { lang_idx = p_idx; }
#ifndef NO_THREADS
virtual void thread_enter();
virtual void thread_exit();
#endif
virtual void frame();
virtual String get_name() const;
virtual void init();
virtual String get_type() const;
virtual String get_extension() const;
virtual Error execute_file(const String &p_path);
virtual void finish();
virtual void get_reserved_words(List<String> *p_words) const;
virtual bool is_control_flow_keyword(String p_keyword) const;
virtual void get_comment_delimiters(List<String> *p_delimiters) const;
virtual void get_string_delimiters(List<String> *p_delimiters) const;
virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const;
virtual Script *create_script() const;
virtual bool has_named_classes() const;
virtual bool supports_builtin_mode() const;
virtual int find_function(const String &p_function, const String &p_code) const;
virtual String make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const;
virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const;
virtual void add_global_constant(const StringName &p_variable, const Variant &p_value);
virtual String debug_get_error() const;
virtual int debug_get_stack_level_count() const;
virtual int debug_get_stack_level_line(int p_level) const;
virtual String debug_get_stack_level_function(int p_level) const;
virtual String debug_get_stack_level_source(int p_level) const;
virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth);
virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth);
virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth);
virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth);
virtual void reload_all_scripts();
virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual void get_public_functions(List<MethodInfo> *p_functions) const;
virtual void get_public_constants(List<Pair<String, Variant>> *p_constants) const;
virtual void profiling_start();
virtual void profiling_stop();
virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max);
virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max);
int register_binding_functions(godot_instance_binding_functions p_binding_functions);
void unregister_binding_functions(int p_idx);
void *get_instance_binding_data(int p_idx, Object *p_object);
virtual void *alloc_instance_binding_data(Object *p_object);
virtual void free_instance_binding_data(void *p_data);
virtual void refcount_incremented_instance_binding(Object *p_object);
virtual bool refcount_decremented_instance_binding(Object *p_object);
void set_global_type_tag(int p_idx, StringName p_class_name, const void *p_type_tag);
const void *get_global_type_tag(int p_idx, StringName p_class_name) const;
virtual bool handles_global_class_type(const String &p_type) const;
virtual String get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const;
void profiling_add_data(StringName p_signature, uint64_t p_time);
};
inline NativeScriptDesc *NativeScript::get_script_desc() const {
Map<StringName, NativeScriptDesc>::Element *E = NativeScriptLanguage::singleton->library_classes[lib_path].find(class_name);
return E ? &E->get() : nullptr;
}
class NativeReloadNode : public Node {
GDCLASS(NativeReloadNode, Node);
bool unloaded;
public:
static void _bind_methods();
void _notification(int p_what);
NativeReloadNode() :
unloaded(false) {}
};
class ResourceFormatLoaderNativeScript : public ResourceFormatLoader {
public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
};
class ResourceFormatSaverNativeScript : public ResourceFormatSaver {
virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0);
virtual bool recognize(const RES &p_resource) const;
virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const;
};
#endif // NATIVESCRIPT_H

View File

@ -0,0 +1,71 @@
/**************************************************************************/
/* register_types.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "register_types.h"
#include "core/io/resource_loader.h"
#include "core/io/resource_saver.h"
#include "nativescript.h"
#include "core/os/os.h"
NativeScriptLanguage *native_script_language;
Ref<ResourceFormatLoaderNativeScript> resource_loader_gdns;
Ref<ResourceFormatSaverNativeScript> resource_saver_gdns;
void register_nativescript_types() {
native_script_language = memnew(NativeScriptLanguage);
ClassDB::register_class<NativeScript>();
native_script_language->set_language_index(ScriptServer::get_language_count());
ScriptServer::register_language(native_script_language);
resource_saver_gdns.instance();
ResourceSaver::add_resource_format_saver(resource_saver_gdns);
resource_loader_gdns.instance();
ResourceLoader::add_resource_format_loader(resource_loader_gdns);
}
void unregister_nativescript_types() {
ResourceLoader::remove_resource_format_loader(resource_loader_gdns);
resource_loader_gdns.unref();
ResourceSaver::remove_resource_format_saver(resource_saver_gdns);
resource_saver_gdns.unref();
if (native_script_language) {
ScriptServer::unregister_language(native_script_language);
memdelete(native_script_language);
}
}

View File

@ -0,0 +1,37 @@
/**************************************************************************/
/* register_types.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef NATIVESCRIPT_REGISTER_TYPES_H
#define NATIVESCRIPT_REGISTER_TYPES_H
void register_nativescript_types();
void unregister_nativescript_types();
#endif // NATIVESCRIPT_REGISTER_TYPES_H

12
net/SCsub Normal file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env python
Import("env")
Import("env_gdnative")
env_net = env_gdnative.Clone()
has_webrtc = env_net["module_webrtc_enabled"]
if has_webrtc:
env_net.Append(CPPDEFINES=["WEBRTC_GDNATIVE_ENABLED"])
env_net.add_source_files(env.modules_sources, "*.cpp")

View File

@ -0,0 +1,125 @@
/**************************************************************************/
/* multiplayer_peer_gdnative.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "multiplayer_peer_gdnative.h"
MultiplayerPeerGDNative::MultiplayerPeerGDNative() {
interface = nullptr;
}
MultiplayerPeerGDNative::~MultiplayerPeerGDNative() {
}
void MultiplayerPeerGDNative::set_native_multiplayer_peer(const godot_net_multiplayer_peer *p_interface) {
interface = p_interface;
}
Error MultiplayerPeerGDNative::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED);
return (Error)interface->get_packet(interface->data, r_buffer, &r_buffer_size);
}
Error MultiplayerPeerGDNative::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED);
return (Error)interface->put_packet(interface->data, p_buffer, p_buffer_size);
}
int MultiplayerPeerGDNative::get_max_packet_size() const {
ERR_FAIL_COND_V(interface == nullptr, 0);
return interface->get_max_packet_size(interface->data);
}
int MultiplayerPeerGDNative::get_available_packet_count() const {
ERR_FAIL_COND_V(interface == nullptr, 0);
return interface->get_available_packet_count(interface->data);
}
/* NetworkedMultiplayerPeer */
void MultiplayerPeerGDNative::set_transfer_mode(TransferMode p_mode) {
ERR_FAIL_COND(interface == nullptr);
interface->set_transfer_mode(interface->data, (godot_int)p_mode);
}
NetworkedMultiplayerPeer::TransferMode MultiplayerPeerGDNative::get_transfer_mode() const {
ERR_FAIL_COND_V(interface == nullptr, TRANSFER_MODE_UNRELIABLE);
return (TransferMode)interface->get_transfer_mode(interface->data);
}
void MultiplayerPeerGDNative::set_target_peer(int p_peer_id) {
ERR_FAIL_COND(interface == nullptr);
interface->set_target_peer(interface->data, p_peer_id);
}
int MultiplayerPeerGDNative::get_packet_peer() const {
ERR_FAIL_COND_V(interface == nullptr, 0);
return interface->get_packet_peer(interface->data);
}
bool MultiplayerPeerGDNative::is_server() const {
ERR_FAIL_COND_V(interface == nullptr, false);
return interface->is_server(interface->data);
}
void MultiplayerPeerGDNative::poll() {
ERR_FAIL_COND(interface == nullptr);
interface->poll(interface->data);
}
int MultiplayerPeerGDNative::get_unique_id() const {
ERR_FAIL_COND_V(interface == nullptr, 0);
return interface->get_unique_id(interface->data);
}
void MultiplayerPeerGDNative::set_refuse_new_connections(bool p_enable) {
ERR_FAIL_COND(interface == nullptr);
interface->set_refuse_new_connections(interface->data, p_enable);
}
bool MultiplayerPeerGDNative::is_refusing_new_connections() const {
ERR_FAIL_COND_V(interface == nullptr, true);
return interface->is_refusing_new_connections(interface->data);
}
NetworkedMultiplayerPeer::ConnectionStatus MultiplayerPeerGDNative::get_connection_status() const {
ERR_FAIL_COND_V(interface == nullptr, CONNECTION_DISCONNECTED);
return (ConnectionStatus)interface->get_connection_status(interface->data);
}
void MultiplayerPeerGDNative::_bind_methods() {
ADD_PROPERTY_DEFAULT("transfer_mode", TRANSFER_MODE_UNRELIABLE);
ADD_PROPERTY_DEFAULT("refuse_new_connections", true);
}
extern "C" {
void GDAPI godot_net_bind_multiplayer_peer(godot_object *p_obj, const godot_net_multiplayer_peer *p_impl) {
((MultiplayerPeerGDNative *)p_obj)->set_native_multiplayer_peer(p_impl);
}
}

View File

@ -0,0 +1,77 @@
/**************************************************************************/
/* multiplayer_peer_gdnative.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef MULTIPLAYER_PEER_GDNATIVE_H
#define MULTIPLAYER_PEER_GDNATIVE_H
#include "core/io/networked_multiplayer_peer.h"
#include "modules/gdnative/gdnative.h"
#include "modules/gdnative/include/net/godot_net.h"
class MultiplayerPeerGDNative : public NetworkedMultiplayerPeer {
GDCLASS(MultiplayerPeerGDNative, NetworkedMultiplayerPeer);
protected:
static void _bind_methods();
const godot_net_multiplayer_peer *interface;
public:
MultiplayerPeerGDNative();
~MultiplayerPeerGDNative();
/* Sets the interface implementation from GDNative */
void set_native_multiplayer_peer(const godot_net_multiplayer_peer *p_impl);
/* Specific to PacketPeer */
virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size);
virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size);
virtual int get_max_packet_size() const;
virtual int get_available_packet_count() const;
/* Specific to NetworkedMultiplayerPeer */
virtual void set_transfer_mode(TransferMode p_mode);
virtual TransferMode get_transfer_mode() const;
virtual void set_target_peer(int p_peer_id);
virtual int get_packet_peer() const;
virtual bool is_server() const;
virtual void poll();
virtual int get_unique_id() const;
virtual void set_refuse_new_connections(bool p_enable);
virtual bool is_refusing_new_connections() const;
virtual ConnectionStatus get_connection_status() const;
};
#endif // MULTIPLAYER_PEER_GDNATIVE_H

View File

@ -0,0 +1,72 @@
/**************************************************************************/
/* packet_peer_gdnative.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "packet_peer_gdnative.h"
PacketPeerGDNative::PacketPeerGDNative() {
interface = nullptr;
}
PacketPeerGDNative::~PacketPeerGDNative() {
}
void PacketPeerGDNative::set_native_packet_peer(const godot_net_packet_peer *p_impl) {
interface = p_impl;
}
void PacketPeerGDNative::_bind_methods() {
}
Error PacketPeerGDNative::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED);
return (Error)interface->get_packet(interface->data, r_buffer, &r_buffer_size);
}
Error PacketPeerGDNative::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED);
return (Error)interface->put_packet(interface->data, p_buffer, p_buffer_size);
}
int PacketPeerGDNative::get_max_packet_size() const {
ERR_FAIL_COND_V(interface == nullptr, 0);
return interface->get_max_packet_size(interface->data);
}
int PacketPeerGDNative::get_available_packet_count() const {
ERR_FAIL_COND_V(interface == nullptr, 0);
return interface->get_available_packet_count(interface->data);
}
extern "C" {
void GDAPI godot_net_bind_packet_peer(godot_object *p_obj, const godot_net_packet_peer *p_impl) {
((PacketPeerGDNative *)p_obj)->set_native_packet_peer(p_impl);
}
}

View File

@ -0,0 +1,59 @@
/**************************************************************************/
/* packet_peer_gdnative.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef PACKET_PEER_GDNATIVE_H
#define PACKET_PEER_GDNATIVE_H
#include "core/io/packet_peer.h"
#include "modules/gdnative/gdnative.h"
#include "modules/gdnative/include/net/godot_net.h"
class PacketPeerGDNative : public PacketPeer {
GDCLASS(PacketPeerGDNative, PacketPeer);
protected:
static void _bind_methods();
const godot_net_packet_peer *interface;
public:
PacketPeerGDNative();
~PacketPeerGDNative();
/* Sets the interface implementation from GDNative */
void set_native_packet_peer(const godot_net_packet_peer *p_impl);
/* Specific to PacketPeer */
virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size);
virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size);
virtual int get_max_packet_size() const;
virtual int get_available_packet_count() const;
};
#endif // PACKET_PEER_GDNATIVE_H

43
net/register_types.cpp Normal file
View File

@ -0,0 +1,43 @@
/**************************************************************************/
/* register_types.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "register_types.h"
#include "multiplayer_peer_gdnative.h"
#include "packet_peer_gdnative.h"
#include "stream_peer_gdnative.h"
void register_net_types() {
ClassDB::register_class<MultiplayerPeerGDNative>();
ClassDB::register_class<PacketPeerGDNative>();
ClassDB::register_class<StreamPeerGDNative>();
}
void unregister_net_types() {
}

37
net/register_types.h Normal file
View File

@ -0,0 +1,37 @@
/**************************************************************************/
/* register_types.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef NET_REGISTER_TYPES_H
#define NET_REGISTER_TYPES_H
void register_net_types();
void unregister_net_types();
#endif // NET_REGISTER_TYPES_H

View File

@ -0,0 +1,77 @@
/**************************************************************************/
/* stream_peer_gdnative.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "stream_peer_gdnative.h"
StreamPeerGDNative::StreamPeerGDNative() {
interface = nullptr;
}
StreamPeerGDNative::~StreamPeerGDNative() {
}
void StreamPeerGDNative::set_native_stream_peer(const godot_net_stream_peer *p_interface) {
interface = p_interface;
}
void StreamPeerGDNative::_bind_methods() {
}
Error StreamPeerGDNative::put_data(const uint8_t *p_data, int p_bytes) {
ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED);
return (Error)(interface->put_data(interface->data, p_data, p_bytes));
}
Error StreamPeerGDNative::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) {
ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED);
return (Error)(interface->put_partial_data(interface->data, p_data, p_bytes, &r_sent));
}
Error StreamPeerGDNative::get_data(uint8_t *p_buffer, int p_bytes) {
ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED);
return (Error)(interface->get_data(interface->data, p_buffer, p_bytes));
}
Error StreamPeerGDNative::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) {
ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED);
return (Error)(interface->get_partial_data(interface->data, p_buffer, p_bytes, &r_received));
}
int StreamPeerGDNative::get_available_bytes() const {
ERR_FAIL_COND_V(interface == nullptr, 0);
return interface->get_available_bytes(interface->data);
}
extern "C" {
void GDAPI godot_net_bind_stream_peer(godot_object *p_obj, const godot_net_stream_peer *p_interface) {
((StreamPeerGDNative *)p_obj)->set_native_stream_peer(p_interface);
}
}

View File

@ -0,0 +1,60 @@
/**************************************************************************/
/* stream_peer_gdnative.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef STREAM_PEER_GDNATIVE_H
#define STREAM_PEER_GDNATIVE_H
#include "core/io/stream_peer.h"
#include "modules/gdnative/gdnative.h"
#include "modules/gdnative/include/net/godot_net.h"
class StreamPeerGDNative : public StreamPeer {
GDCLASS(StreamPeerGDNative, StreamPeer);
protected:
static void _bind_methods();
const godot_net_stream_peer *interface;
public:
StreamPeerGDNative();
~StreamPeerGDNative();
/* Sets the interface implementation from GDNative */
void set_native_stream_peer(const godot_net_stream_peer *p_interface);
/* Specific to StreamPeer */
Error put_data(const uint8_t *p_data, int p_bytes);
Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent);
Error get_data(uint8_t *p_buffer, int p_bytes);
Error get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received);
int get_available_bytes() const;
};
#endif // STREAM_PEER_GDNATIVE_H

60
net/webrtc_gdnative.cpp Normal file
View File

@ -0,0 +1,60 @@
/**************************************************************************/
/* webrtc_gdnative.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "modules/gdnative/gdnative.h"
#include "modules/gdnative/include/net/godot_net.h"
#ifdef WEBRTC_GDNATIVE_ENABLED
#include "modules/webrtc/webrtc_data_channel_gdnative.h"
#include "modules/webrtc/webrtc_peer_connection_gdnative.h"
#endif
extern "C" {
void GDAPI godot_net_bind_webrtc_peer_connection(godot_object *p_obj, const godot_net_webrtc_peer_connection *p_impl) {
#ifdef WEBRTC_GDNATIVE_ENABLED
((WebRTCPeerConnectionGDNative *)p_obj)->set_native_webrtc_peer_connection(p_impl);
#endif
}
void GDAPI godot_net_bind_webrtc_data_channel(godot_object *p_obj, const godot_net_webrtc_data_channel *p_impl) {
#ifdef WEBRTC_GDNATIVE_ENABLED
((WebRTCDataChannelGDNative *)p_obj)->set_native_webrtc_data_channel(p_impl);
#endif
}
godot_error GDAPI godot_net_set_webrtc_library(const godot_net_webrtc_library *p_lib) {
#ifdef WEBRTC_GDNATIVE_ENABLED
return (godot_error)WebRTCPeerConnectionGDNative::set_default_library(p_lib);
#else
return (godot_error)ERR_UNAVAILABLE;
#endif
}
}

6
pluginscript/SCsub Normal file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env python
Import("env")
Import("env_gdnative")
env_gdnative.add_source_files(env.modules_sources, "*.cpp")

View File

@ -0,0 +1,139 @@
/**************************************************************************/
/* pluginscript_instance.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "pluginscript_instance.h"
// Godot imports
#include "core/os/os.h"
#include "core/variant.h"
// PluginScript imports
#include "pluginscript_language.h"
#include "pluginscript_script.h"
bool PluginScriptInstance::set(const StringName &p_name, const Variant &p_value) {
String name = String(p_name);
return _desc->set_prop(_data, (const godot_string *)&name, (const godot_variant *)&p_value);
}
bool PluginScriptInstance::get(const StringName &p_name, Variant &r_ret) const {
String name = String(p_name);
return _desc->get_prop(_data, (const godot_string *)&name, (godot_variant *)&r_ret);
}
Ref<Script> PluginScriptInstance::get_script() const {
return _script;
}
ScriptLanguage *PluginScriptInstance::get_language() {
return _script->get_language();
}
Variant::Type PluginScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const {
if (!_script->has_property(p_name)) {
if (r_is_valid) {
*r_is_valid = false;
}
return Variant::NIL;
}
if (r_is_valid) {
*r_is_valid = true;
}
return _script->get_property_info(p_name).type;
}
void PluginScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const {
_script->get_script_property_list(p_properties);
}
void PluginScriptInstance::get_method_list(List<MethodInfo> *p_list) const {
_script->get_script_method_list(p_list);
}
bool PluginScriptInstance::has_method(const StringName &p_method) const {
return _script->has_method(p_method);
}
Variant PluginScriptInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
// TODO: optimize when calling a Godot method from Godot to avoid param conversion ?
godot_variant ret = _desc->call_method(
_data, (godot_string_name *)&p_method, (const godot_variant **)p_args,
p_argcount, (godot_variant_call_error *)&r_error);
Variant var_ret = *(Variant *)&ret;
godot_variant_destroy(&ret);
return var_ret;
}
void PluginScriptInstance::notification(int p_notification) {
_desc->notification(_data, p_notification);
}
MultiplayerAPI::RPCMode PluginScriptInstance::get_rpc_mode(const StringName &p_method) const {
return _script->get_rpc_mode(p_method);
}
MultiplayerAPI::RPCMode PluginScriptInstance::get_rset_mode(const StringName &p_variable) const {
return _script->get_rset_mode(p_variable);
}
void PluginScriptInstance::refcount_incremented() {
if (_desc->refcount_decremented) {
_desc->refcount_incremented(_data);
}
}
bool PluginScriptInstance::refcount_decremented() {
// Return true if it can die
if (_desc->refcount_decremented) {
return _desc->refcount_decremented(_data);
}
return true;
}
PluginScriptInstance::PluginScriptInstance() {
}
bool PluginScriptInstance::init(PluginScript *p_script, Object *p_owner) {
_owner = p_owner;
_owner_variant = Variant(p_owner);
_script = Ref<PluginScript>(p_script);
_desc = &p_script->_desc->instance_desc;
_data = _desc->init(p_script->_data, (godot_object *)p_owner);
ERR_FAIL_COND_V(_data == nullptr, false);
p_owner->set_script_instance(this);
return true;
}
PluginScriptInstance::~PluginScriptInstance() {
_desc->finish(_data);
_script->_language->lock();
_script->_instances.erase(_owner);
_script->_language->unlock();
}

View File

@ -0,0 +1,88 @@
/**************************************************************************/
/* pluginscript_instance.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef PLUGINSCRIPT_INSTANCE_H
#define PLUGINSCRIPT_INSTANCE_H
// Godot imports
#include "core/script_language.h"
// PluginScript imports
#include <pluginscript/godot_pluginscript.h>
class PluginScript;
class PluginScriptInstance : public ScriptInstance {
friend class PluginScript;
private:
Ref<PluginScript> _script;
Object *_owner;
Variant _owner_variant;
godot_pluginscript_instance_data *_data;
const godot_pluginscript_instance_desc *_desc;
public:
_FORCE_INLINE_ Object *get_owner() { return _owner; }
virtual bool set(const StringName &p_name, const Variant &p_value);
virtual bool get(const StringName &p_name, Variant &r_ret) const;
virtual void get_property_list(List<PropertyInfo> *p_properties) const;
virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const;
virtual void get_method_list(List<MethodInfo> *p_list) const;
virtual bool has_method(const StringName &p_method) const;
virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error);
// Rely on default implementations provided by ScriptInstance for the moment.
// Note that multilevel call could be removed in 3.0 release, so stay tuned
// (see https://godotengine.org/qa/9244/can-override-the-_ready-and-_process-functions-child-classes)
//virtual void call_multilevel(const StringName& p_method,const Variant** p_args,int p_argcount);
//virtual void call_multilevel_reversed(const StringName& p_method,const Variant** p_args,int p_argcount);
virtual void notification(int p_notification);
virtual Ref<Script> get_script() const;
virtual ScriptLanguage *get_language();
virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const;
virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const;
virtual void refcount_incremented();
virtual bool refcount_decremented();
PluginScriptInstance();
bool init(PluginScript *p_script, Object *p_owner);
virtual ~PluginScriptInstance();
};
#endif // PLUGINSCRIPT_INSTANCE_H

View File

@ -0,0 +1,418 @@
/**************************************************************************/
/* pluginscript_language.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
// Godot imports
#include "core/os/file_access.h"
#include "core/os/os.h"
#include "core/project_settings.h"
// PluginScript imports
#include "pluginscript_language.h"
#include "pluginscript_script.h"
String PluginScriptLanguage::get_name() const {
return String(_desc.name);
}
void PluginScriptLanguage::init() {
_data = _desc.init();
}
String PluginScriptLanguage::get_type() const {
// We should use _desc.type here, however the returned type is used to
// query ClassDB which would complain given the type is not registered
// from his point of view...
// To solve this we just use a more generic (but present in ClassDB) type.
return String("PluginScript");
}
String PluginScriptLanguage::get_extension() const {
return String(_desc.extension);
}
Error PluginScriptLanguage::execute_file(const String &p_path) {
// TODO: pretty sure this method is totally deprecated and should be removed...
return OK;
}
void PluginScriptLanguage::finish() {
_desc.finish(_data);
}
/* EDITOR FUNCTIONS */
void PluginScriptLanguage::get_reserved_words(List<String> *p_words) const {
if (_desc.reserved_words) {
const char **w = _desc.reserved_words;
while (*w) {
p_words->push_back(*w);
w++;
}
}
}
bool PluginScriptLanguage::is_control_flow_keyword(String p_keyword) const {
return false;
}
void PluginScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const {
if (_desc.comment_delimiters) {
const char **w = _desc.comment_delimiters;
while (*w) {
p_delimiters->push_back(*w);
w++;
}
}
}
void PluginScriptLanguage::get_string_delimiters(List<String> *p_delimiters) const {
if (_desc.string_delimiters) {
const char **w = _desc.string_delimiters;
while (*w) {
p_delimiters->push_back(*w);
w++;
}
}
}
Ref<Script> PluginScriptLanguage::get_template(const String &p_class_name, const String &p_base_class_name) const {
Script *ns = create_script();
Ref<Script> script = Ref<Script>(ns);
if (_desc.get_template_source_code) {
godot_string src = _desc.get_template_source_code(_data, (godot_string *)&p_class_name, (godot_string *)&p_base_class_name);
script->set_source_code(*(String *)&src);
godot_string_destroy(&src);
}
return script;
}
bool PluginScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const {
PoolStringArray functions;
if (_desc.validate) {
bool ret = _desc.validate(
_data,
(godot_string *)&p_script,
&r_line_error,
&r_col_error,
(godot_string *)&r_test_error,
(godot_string *)&p_path,
(godot_pool_string_array *)&functions);
for (int i = 0; i < functions.size(); i++) {
r_functions->push_back(functions[i]);
}
return ret;
}
return true;
}
Script *PluginScriptLanguage::create_script() const {
PluginScript *script = memnew(PluginScript());
// I'm hurting kittens doing this I guess...
script->init(const_cast<PluginScriptLanguage *>(this));
return script;
}
bool PluginScriptLanguage::has_named_classes() const {
return _desc.has_named_classes;
}
bool PluginScriptLanguage::supports_builtin_mode() const {
return _desc.supports_builtin_mode;
}
int PluginScriptLanguage::find_function(const String &p_function, const String &p_code) const {
if (_desc.find_function) {
return _desc.find_function(_data, (godot_string *)&p_function, (godot_string *)&p_code);
}
return -1;
}
String PluginScriptLanguage::make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const {
if (_desc.make_function) {
godot_string tmp = _desc.make_function(_data, (godot_string *)&p_class, (godot_string *)&p_name, (godot_pool_string_array *)&p_args);
String ret = *(String *)&tmp;
godot_string_destroy(&tmp);
return ret;
}
return String();
}
Error PluginScriptLanguage::complete_code(const String &p_code, const String &p_path, Object *p_owner, List<ScriptCodeCompletionOption> *r_options, bool &r_force, String &r_call_hint) {
if (_desc.complete_code) {
Array options;
godot_error tmp = _desc.complete_code(
_data,
(godot_string *)&p_code,
(godot_string *)&p_path,
(godot_object *)p_owner,
(godot_array *)&options,
&r_force,
(godot_string *)&r_call_hint);
for (int i = 0; i < options.size(); i++) {
ScriptCodeCompletionOption option(options[i], ScriptCodeCompletionOption::KIND_PLAIN_TEXT);
r_options->push_back(option);
}
return (Error)tmp;
}
return ERR_UNAVAILABLE;
}
void PluginScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_to_line) const {
if (_desc.auto_indent_code) {
_desc.auto_indent_code(_data, (godot_string *)&p_code, p_from_line, p_to_line);
}
return;
}
void PluginScriptLanguage::add_global_constant(const StringName &p_variable, const Variant &p_value) {
const String variable = String(p_variable);
_desc.add_global_constant(_data, (godot_string *)&variable, (godot_variant *)&p_value);
}
/* LOADER FUNCTIONS */
void PluginScriptLanguage::get_recognized_extensions(List<String> *p_extensions) const {
for (int i = 0; _desc.recognized_extensions[i]; ++i) {
p_extensions->push_back(String(_desc.recognized_extensions[i]));
}
}
void PluginScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const {
// TODO: provide this statically in `godot_pluginscript_language_desc` ?
if (_desc.get_public_functions) {
Array functions;
_desc.get_public_functions(_data, (godot_array *)&functions);
for (int i = 0; i < functions.size(); i++) {
MethodInfo mi = MethodInfo::from_dict(functions[i]);
p_functions->push_back(mi);
}
}
}
void PluginScriptLanguage::get_public_constants(List<Pair<String, Variant>> *p_constants) const {
// TODO: provide this statically in `godot_pluginscript_language_desc` ?
if (_desc.get_public_constants) {
Dictionary constants;
_desc.get_public_constants(_data, (godot_dictionary *)&constants);
for (const Variant *key = constants.next(); key; key = constants.next(key)) {
Variant value = constants[*key];
p_constants->push_back(Pair<String, Variant>(*key, value));
}
}
}
void PluginScriptLanguage::profiling_start() {
#ifdef DEBUG_ENABLED
if (_desc.profiling_start) {
lock();
_desc.profiling_start(_data);
unlock();
}
#endif
}
void PluginScriptLanguage::profiling_stop() {
#ifdef DEBUG_ENABLED
if (_desc.profiling_stop) {
lock();
_desc.profiling_stop(_data);
unlock();
}
#endif
}
int PluginScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) {
int info_count = 0;
#ifdef DEBUG_ENABLED
if (_desc.profiling_get_accumulated_data) {
godot_pluginscript_profiling_data *info = (godot_pluginscript_profiling_data *)memalloc(
sizeof(godot_pluginscript_profiling_data) * p_info_max);
info_count = _desc.profiling_get_accumulated_data(_data, info, p_info_max);
for (int i = 0; i < info_count; ++i) {
p_info_arr[i].signature = *(StringName *)&info[i].signature;
p_info_arr[i].call_count = info[i].call_count;
p_info_arr[i].total_time = info[i].total_time;
p_info_arr[i].self_time = info[i].self_time;
godot_string_name_destroy(&info[i].signature);
}
}
#endif
return info_count;
}
int PluginScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) {
int info_count = 0;
#ifdef DEBUG_ENABLED
if (_desc.profiling_get_frame_data) {
godot_pluginscript_profiling_data *info = (godot_pluginscript_profiling_data *)memalloc(
sizeof(godot_pluginscript_profiling_data) * p_info_max);
info_count = _desc.profiling_get_frame_data(_data, info, p_info_max);
for (int i = 0; i < info_count; ++i) {
p_info_arr[i].signature = *(StringName *)&info[i].signature;
p_info_arr[i].call_count = info[i].call_count;
p_info_arr[i].total_time = info[i].total_time;
p_info_arr[i].self_time = info[i].self_time;
godot_string_name_destroy(&info[i].signature);
}
}
#endif
return info_count;
}
void PluginScriptLanguage::frame() {
#ifdef DEBUG_ENABLED
if (_desc.profiling_frame) {
_desc.profiling_frame(_data);
}
#endif
}
/* DEBUGGER FUNCTIONS */
String PluginScriptLanguage::debug_get_error() const {
if (_desc.debug_get_error) {
godot_string tmp = _desc.debug_get_error(_data);
String ret = *(String *)&tmp;
godot_string_destroy(&tmp);
return ret;
}
return String("Nothing");
}
int PluginScriptLanguage::debug_get_stack_level_count() const {
if (_desc.debug_get_stack_level_count) {
return _desc.debug_get_stack_level_count(_data);
}
return 1;
}
int PluginScriptLanguage::debug_get_stack_level_line(int p_level) const {
if (_desc.debug_get_stack_level_line) {
return _desc.debug_get_stack_level_line(_data, p_level);
}
return 1;
}
String PluginScriptLanguage::debug_get_stack_level_function(int p_level) const {
if (_desc.debug_get_stack_level_function) {
godot_string tmp = _desc.debug_get_stack_level_function(_data, p_level);
String ret = *(String *)&tmp;
godot_string_destroy(&tmp);
return ret;
}
return String("Nothing");
}
String PluginScriptLanguage::debug_get_stack_level_source(int p_level) const {
if (_desc.debug_get_stack_level_source) {
godot_string tmp = _desc.debug_get_stack_level_source(_data, p_level);
String ret = *(String *)&tmp;
godot_string_destroy(&tmp);
return ret;
}
return String("Nothing");
}
void PluginScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
if (_desc.debug_get_stack_level_locals) {
PoolStringArray locals;
Array values;
_desc.debug_get_stack_level_locals(_data, p_level, (godot_pool_string_array *)&locals, (godot_array *)&values, p_max_subitems, p_max_depth);
for (int i = 0; i < locals.size(); i++) {
p_locals->push_back(locals[i]);
}
for (int i = 0; i < values.size(); i++) {
p_values->push_back(values[i]);
}
}
}
void PluginScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
if (_desc.debug_get_stack_level_members) {
PoolStringArray members;
Array values;
_desc.debug_get_stack_level_members(_data, p_level, (godot_pool_string_array *)&members, (godot_array *)&values, p_max_subitems, p_max_depth);
for (int i = 0; i < members.size(); i++) {
p_members->push_back(members[i]);
}
for (int i = 0; i < values.size(); i++) {
p_values->push_back(values[i]);
}
}
}
void PluginScriptLanguage::debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
if (_desc.debug_get_globals) {
PoolStringArray locals;
Array values;
_desc.debug_get_globals(_data, (godot_pool_string_array *)&locals, (godot_array *)&values, p_max_subitems, p_max_depth);
for (int i = 0; i < locals.size(); i++) {
p_locals->push_back(locals[i]);
}
for (int i = 0; i < values.size(); i++) {
p_values->push_back(values[i]);
}
}
}
String PluginScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) {
if (_desc.debug_parse_stack_level_expression) {
godot_string tmp = _desc.debug_parse_stack_level_expression(_data, p_level, (godot_string *)&p_expression, p_max_subitems, p_max_depth);
String ret = *(String *)&tmp;
godot_string_destroy(&tmp);
return ret;
}
return String("Nothing");
}
void PluginScriptLanguage::reload_all_scripts() {
// TODO
}
void PluginScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) {
#ifdef DEBUG_ENABLED
lock();
// TODO
unlock();
#endif
}
void PluginScriptLanguage::lock() {
_lock.lock();
}
void PluginScriptLanguage::unlock() {
_lock.unlock();
}
PluginScriptLanguage::PluginScriptLanguage(const godot_pluginscript_language_desc *desc) :
_desc(*desc) {
_resource_loader = Ref<ResourceFormatLoaderPluginScript>(memnew(ResourceFormatLoaderPluginScript(this)));
_resource_saver = Ref<ResourceFormatSaverPluginScript>(memnew(ResourceFormatSaverPluginScript(this)));
}

View File

@ -0,0 +1,133 @@
/**************************************************************************/
/* pluginscript_language.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef PLUGINSCRIPT_LANGUAGE_H
#define PLUGINSCRIPT_LANGUAGE_H
// Godot imports
#include "core/io/resource_loader.h"
#include "core/io/resource_saver.h"
#include "core/map.h"
#include "core/script_language.h"
#include "core/self_list.h"
// PluginScript imports
#include "pluginscript_loader.h"
#include <pluginscript/godot_pluginscript.h>
class PluginScript;
class PluginScriptInstance;
class PluginScriptLanguage : public ScriptLanguage {
friend class PluginScript;
friend class PluginScriptInstance;
Ref<ResourceFormatLoaderPluginScript> _resource_loader;
Ref<ResourceFormatSaverPluginScript> _resource_saver;
const godot_pluginscript_language_desc _desc;
godot_pluginscript_language_data *_data;
Mutex _lock;
SelfList<PluginScript>::List _script_list;
public:
virtual String get_name() const;
_FORCE_INLINE_ Ref<ResourceFormatLoaderPluginScript> get_resource_loader() { return _resource_loader; }
_FORCE_INLINE_ Ref<ResourceFormatSaverPluginScript> get_resource_saver() { return _resource_saver; }
/* LANGUAGE FUNCTIONS */
virtual void init();
virtual String get_type() const;
virtual String get_extension() const;
virtual Error execute_file(const String &p_path);
virtual void finish();
/* EDITOR FUNCTIONS */
virtual void get_reserved_words(List<String> *p_words) const;
virtual bool is_control_flow_keyword(String p_keyword) const;
virtual void get_comment_delimiters(List<String> *p_delimiters) const;
virtual void get_string_delimiters(List<String> *p_delimiters) const;
virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const;
virtual Script *create_script() const;
virtual bool has_named_classes() const;
virtual bool supports_builtin_mode() const;
virtual bool can_inherit_from_file() { return true; }
virtual int find_function(const String &p_function, const String &p_code) const;
virtual String make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const;
virtual Error complete_code(const String &p_code, const String &p_path, Object *p_owner, List<ScriptCodeCompletionOption> *r_options, bool &r_force, String &r_call_hint);
virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const;
virtual void add_global_constant(const StringName &p_variable, const Variant &p_value);
/* MULTITHREAD FUNCTIONS */
//some VMs need to be notified of thread creation/exiting to allocate a stack
// void thread_enter() {}
// void thread_exit() {}
/* DEBUGGER FUNCTIONS */
virtual String debug_get_error() const;
virtual int debug_get_stack_level_count() const;
virtual int debug_get_stack_level_line(int p_level) const;
virtual String debug_get_stack_level_function(int p_level) const;
virtual String debug_get_stack_level_source(int p_level) const;
virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems = -1, int p_max_depth = -1);
// virtual Vector<StackInfo> debug_get_current_stack_info() { return Vector<StackInfo>(); }
virtual void reload_all_scripts();
virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload);
/* LOADER FUNCTIONS */
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual void get_public_functions(List<MethodInfo> *p_functions) const;
virtual void get_public_constants(List<Pair<String, Variant>> *p_constants) const;
virtual void profiling_start();
virtual void profiling_stop();
virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max);
virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max);
virtual void frame();
void lock();
void unlock();
PluginScriptLanguage(const godot_pluginscript_language_desc *desc);
virtual ~PluginScriptLanguage() {}
};
#endif // PLUGINSCRIPT_LANGUAGE_H

View File

@ -0,0 +1,114 @@
/**************************************************************************/
/* pluginscript_loader.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
// Godot imports
#include "core/os/file_access.h"
// Pythonscript imports
#include "pluginscript_language.h"
#include "pluginscript_loader.h"
#include "pluginscript_script.h"
ResourceFormatLoaderPluginScript::ResourceFormatLoaderPluginScript(PluginScriptLanguage *language) {
_language = language;
}
RES ResourceFormatLoaderPluginScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
if (r_error) {
*r_error = ERR_FILE_CANT_OPEN;
}
PluginScript *script = memnew(PluginScript);
script->init(_language);
Ref<PluginScript> scriptres(script);
Error err = script->load_source_code(p_path);
ERR_FAIL_COND_V(err != OK, RES());
script->set_path(p_original_path);
script->reload();
if (r_error) {
*r_error = OK;
}
return scriptres;
}
void ResourceFormatLoaderPluginScript::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back(_language->get_extension());
}
bool ResourceFormatLoaderPluginScript::handles_type(const String &p_type) const {
return p_type == "Script" || p_type == _language->get_type();
}
String ResourceFormatLoaderPluginScript::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
if (el == _language->get_extension()) {
return _language->get_type();
}
return "";
}
ResourceFormatSaverPluginScript::ResourceFormatSaverPluginScript(PluginScriptLanguage *language) {
_language = language;
}
Error ResourceFormatSaverPluginScript::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
Ref<PluginScript> sqscr = p_resource;
ERR_FAIL_COND_V(sqscr.is_null(), ERR_INVALID_PARAMETER);
String source = sqscr->get_source_code();
Error err;
FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err);
ERR_FAIL_COND_V(err, err);
file->store_string(source);
if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) {
memdelete(file);
return ERR_CANT_CREATE;
}
file->close();
memdelete(file);
return OK;
}
void ResourceFormatSaverPluginScript::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
if (Object::cast_to<PluginScript>(*p_resource)) {
p_extensions->push_back(_language->get_extension());
}
}
bool ResourceFormatSaverPluginScript::recognize(const RES &p_resource) const {
return Object::cast_to<PluginScript>(*p_resource) != nullptr;
}

View File

@ -0,0 +1,62 @@
/**************************************************************************/
/* pluginscript_loader.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef PLUGINSCRIPT_LOADER_H
#define PLUGINSCRIPT_LOADER_H
// Godot imports
#include "core/io/resource_loader.h"
#include "core/io/resource_saver.h"
#include "core/script_language.h"
class PluginScriptLanguage;
class ResourceFormatLoaderPluginScript : public ResourceFormatLoader {
PluginScriptLanguage *_language;
public:
ResourceFormatLoaderPluginScript(PluginScriptLanguage *language);
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
};
class ResourceFormatSaverPluginScript : public ResourceFormatSaver {
PluginScriptLanguage *_language;
public:
ResourceFormatSaverPluginScript(PluginScriptLanguage *language);
virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0);
virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const;
virtual bool recognize(const RES &p_resource) const;
};
#endif // PLUGINSCRIPT_LOADER_H

Some files were not shown because too many files have changed in this diff Show More