summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/gdnative/SCsub3
-rw-r--r--modules/gdnative/gdnative.cpp13
-rw-r--r--modules/gdnative/gdnative.h3
-rw-r--r--modules/gdnative/godot/array.cpp2
-rw-r--r--modules/gdnative/godot/array.h6
-rw-r--r--modules/gdnative/godot/basis.cpp4
-rw-r--r--modules/gdnative/godot/basis.h6
-rw-r--r--modules/gdnative/godot/color.cpp4
-rw-r--r--modules/gdnative/godot/color.h4
-rw-r--r--modules/gdnative/godot/dictionary.cpp3
-rw-r--r--modules/gdnative/godot/dictionary.h6
-rw-r--r--modules/gdnative/godot/gdnative.cpp7
-rw-r--r--modules/gdnative/godot/gdnative.h39
-rw-r--r--modules/gdnative/godot/node_path.cpp6
-rw-r--r--modules/gdnative/godot/node_path.h4
-rw-r--r--modules/gdnative/godot/plane.cpp4
-rw-r--r--modules/gdnative/godot/plane.h4
-rw-r--r--modules/gdnative/godot/pool_arrays.cpp2
-rw-r--r--modules/gdnative/godot/pool_arrays.h10
-rw-r--r--modules/gdnative/godot/quat.cpp4
-rw-r--r--modules/gdnative/godot/quat.h4
-rw-r--r--modules/gdnative/godot/rect2.cpp4
-rw-r--r--modules/gdnative/godot/rect2.h4
-rw-r--r--modules/gdnative/godot/rect3.cpp4
-rw-r--r--modules/gdnative/godot/rect3.h6
-rw-r--r--modules/gdnative/godot/rid.cpp4
-rw-r--r--modules/gdnative/godot/rid.h2
-rw-r--r--modules/gdnative/godot/string.cpp2
-rw-r--r--modules/gdnative/godot/string.h2
-rw-r--r--modules/gdnative/godot/transform.cpp4
-rw-r--r--modules/gdnative/godot/transform.h8
-rw-r--r--modules/gdnative/godot/transform2d.cpp4
-rw-r--r--modules/gdnative/godot/transform2d.h6
-rw-r--r--modules/gdnative/godot/variant.cpp4
-rw-r--r--modules/gdnative/godot/variant.h38
-rw-r--r--modules/gdnative/godot/vector2.cpp4
-rw-r--r--modules/gdnative/godot/vector2.h2
-rw-r--r--modules/gdnative/godot/vector3.cpp4
-rw-r--r--modules/gdnative/godot/vector3.h4
-rw-r--r--modules/gdnative/register_types.cpp25
-rw-r--r--modules/gdscript/gd_parser.cpp3
-rw-r--r--modules/nativescript/nativescript.cpp240
-rw-r--r--modules/nativescript/nativescript.h42
-rw-r--r--modules/nativescript/register_types.cpp27
-rw-r--r--modules/stb_vorbis/audio_stream_ogg_vorbis.cpp2
-rw-r--r--modules/visual_script/visual_script_editor.cpp10
-rw-r--r--modules/visual_script/visual_script_nodes.cpp2
47 files changed, 433 insertions, 162 deletions
diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub
index ac13319a1d..65970d48c1 100644
--- a/modules/gdnative/SCsub
+++ b/modules/gdnative/SCsub
@@ -6,9 +6,8 @@ env.add_source_files(env.modules_sources, "*.cpp")
env.add_source_files(env.modules_sources, "godot/*.cpp")
env.Append(CPPFLAGS=['-DGDAPI_BUILT_IN'])
+env.Append(CPPPATH=['#modules/gdnative/'])
if "platform" in env and env["platform"] == "x11": # there has to be a better solution?
env.Append(LINKFLAGS=["-rdynamic"])
env.use_ptrcall = True
-
-Export('env')
diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp
index e810c33f1c..07dba921b1 100644
--- a/modules/gdnative/gdnative.cpp
+++ b/modules/gdnative/gdnative.cpp
@@ -155,7 +155,6 @@ String GDNativeLibrary::get_active_library_path() const {
}
GDNative::GDNative() {
- initialized = false;
native_handle = NULL;
}
@@ -185,6 +184,8 @@ void GDNative::_bind_methods() {
}
void GDNative::set_library(Ref<GDNativeLibrary> p_library) {
+ ERR_EXPLAIN("Tried to change library of GDNative when it is already set");
+ ERR_FAIL_COND(library.is_valid());
library = p_library;
}
@@ -217,6 +218,9 @@ bool GDNative::initialize() {
library_init);
if (err || !library_init) {
+ OS::get_singleton()->close_dynamic_library(native_handle);
+ native_handle = NULL;
+ ERR_PRINT("Failed to obtain godot_gdnative_init symbol");
return false;
}
@@ -229,6 +233,7 @@ bool GDNative::initialize() {
options.core_api_hash = ClassDB::get_api_hash(ClassDB::API_CORE);
options.editor_api_hash = ClassDB::get_api_hash(ClassDB::API_EDITOR);
options.no_api_hash = ClassDB::get_api_hash(ClassDB::API_NONE);
+ options.gd_native_library = (godot_object *)(get_library().ptr());
library_init_fpointer(&options);
@@ -269,7 +274,11 @@ bool GDNative::terminate() {
OS::get_singleton()->close_dynamic_library(native_handle);
native_handle = NULL;
- return false;
+ return true;
+}
+
+bool GDNative::is_initialized() {
+ return (native_handle != NULL);
}
void GDNativeCallRegistry::register_native_call_type(StringName p_call_type, native_call_cb p_callback) {
diff --git a/modules/gdnative/gdnative.h b/modules/gdnative/gdnative.h
index dd845cab7a..b03866f432 100644
--- a/modules/gdnative/gdnative.h
+++ b/modules/gdnative/gdnative.h
@@ -35,7 +35,7 @@
#include "os/thread_safe.h"
#include "resource.h"
-#include "godot/gdnative.h"
+#include <godot/gdnative.h>
class GDNativeLibrary : public Resource {
GDCLASS(GDNativeLibrary, Resource)
@@ -117,7 +117,6 @@ class GDNative : public Reference {
GDCLASS(GDNative, Reference)
Ref<GDNativeLibrary> library;
- bool initialized;
// TODO(karroffel): different platforms? WASM????
void *native_handle;
diff --git a/modules/gdnative/godot/array.cpp b/modules/gdnative/godot/array.cpp
index c068eecf8f..97c73dc253 100644
--- a/modules/gdnative/godot/array.cpp
+++ b/modules/gdnative/godot/array.cpp
@@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "array.h"
+#include <godot/array.h>
#include "core/array.h"
#include "core/os/memory.h"
diff --git a/modules/gdnative/godot/array.h b/modules/gdnative/godot/array.h
index cbdbfbdde3..158170ba0e 100644
--- a/modules/gdnative/godot/array.h
+++ b/modules/gdnative/godot/array.h
@@ -46,10 +46,10 @@ typedef struct {
} godot_array;
#endif
-#include "pool_arrays.h"
-#include "variant.h"
+#include <godot/pool_arrays.h>
+#include <godot/variant.h>
-#include "gdnative.h"
+#include <godot/gdnative.h>
void GDAPI godot_array_new(godot_array *r_dest);
void GDAPI godot_array_new_copy(godot_array *r_dest, const godot_array *p_src);
diff --git a/modules/gdnative/godot/basis.cpp b/modules/gdnative/godot/basis.cpp
index 7188215d04..5cf379b7d5 100644
--- a/modules/gdnative/godot/basis.cpp
+++ b/modules/gdnative/godot/basis.cpp
@@ -27,10 +27,10 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "basis.h"
-#include "core/variant.h"
+#include <godot/basis.h>
#include "core/math/matrix3.h"
+#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
diff --git a/modules/gdnative/godot/basis.h b/modules/gdnative/godot/basis.h
index 79b2b45fdd..e96b8b730d 100644
--- a/modules/gdnative/godot/basis.h
+++ b/modules/gdnative/godot/basis.h
@@ -45,9 +45,9 @@ typedef struct {
} godot_basis;
#endif
-#include "gdnative.h"
-#include "quat.h"
-#include "vector3.h"
+#include <godot/gdnative.h>
+#include <godot/quat.h>
+#include <godot/vector3.h>
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);
diff --git a/modules/gdnative/godot/color.cpp b/modules/gdnative/godot/color.cpp
index eac966ca1f..a5ffee1e0b 100644
--- a/modules/gdnative/godot/color.cpp
+++ b/modules/gdnative/godot/color.cpp
@@ -27,10 +27,10 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "color.h"
-#include "core/variant.h"
+#include <godot/color.h>
#include "core/color.h"
+#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
diff --git a/modules/gdnative/godot/color.h b/modules/gdnative/godot/color.h
index 77e709fbe3..2cd6b48b48 100644
--- a/modules/gdnative/godot/color.h
+++ b/modules/gdnative/godot/color.h
@@ -45,8 +45,8 @@ typedef struct {
} godot_color;
#endif
-#include "gdnative.h"
-#include "string.h"
+#include <godot/gdnative.h>
+#include <godot/string.h>
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);
diff --git a/modules/gdnative/godot/dictionary.cpp b/modules/gdnative/godot/dictionary.cpp
index 1c0761edfd..b92c8125bb 100644
--- a/modules/gdnative/godot/dictionary.cpp
+++ b/modules/gdnative/godot/dictionary.cpp
@@ -27,7 +27,8 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "dictionary.h"
+#include <godot/dictionary.h>
+
#include "core/variant.h"
#include "core/dictionary.h"
diff --git a/modules/gdnative/godot/dictionary.h b/modules/gdnative/godot/dictionary.h
index a08deb27df..594b02b4dd 100644
--- a/modules/gdnative/godot/dictionary.h
+++ b/modules/gdnative/godot/dictionary.h
@@ -45,9 +45,9 @@ typedef struct {
} godot_dictionary;
#endif
-#include "array.h"
-#include "gdnative.h"
-#include "variant.h"
+#include <godot/array.h>
+#include <godot/gdnative.h>
+#include <godot/variant.h>
void GDAPI godot_dictionary_new(godot_dictionary *r_dest);
void GDAPI godot_dictionary_new_copy(godot_dictionary *r_dest, const godot_dictionary *p_src);
diff --git a/modules/gdnative/godot/gdnative.cpp b/modules/gdnative/godot/gdnative.cpp
index 7b94b75a52..4cda1f4560 100644
--- a/modules/gdnative/godot/gdnative.cpp
+++ b/modules/gdnative/godot/gdnative.cpp
@@ -27,12 +27,13 @@
/* 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 <godot/gdnative.h>
#include "class_db.h"
#include "error_macros.h"
#include "gdnative.h"
#include "global_constants.h"
+#include "os/os.h"
#include "project_settings.h"
#include "variant.h"
@@ -89,6 +90,10 @@ godot_object GDAPI *godot_global_get_singleton(char *p_name) {
return (godot_object *)ProjectSettings::get_singleton()->get_singleton_object(String(p_name));
} // result shouldn't be freed
+void GDAPI *godot_get_stack_bottom() {
+ return OS::get_singleton()->get_stack_bottom();
+}
+
// MethodBind API
godot_method_bind GDAPI *godot_method_bind_get_method(const char *p_classname, const char *p_methodname) {
diff --git a/modules/gdnative/godot/gdnative.h b/modules/gdnative/godot/gdnative.h
index 4b79706b52..d849999079 100644
--- a/modules/gdnative/godot/gdnative.h
+++ b/modules/gdnative/godot/gdnative.h
@@ -174,77 +174,81 @@ typedef struct godot_pool_color_array godot_pool_color_array;
*/
/////// String
-#include "string.h"
+#include <godot/string.h>
////// Vector2
-#include "vector2.h"
+#include <godot/vector2.h>
////// Rect2
-#include "rect2.h"
+#include <godot/rect2.h>
////// Vector3
-#include "vector3.h"
+#include <godot/vector3.h>
////// Transform2D
-#include "transform2d.h"
+#include <godot/transform2d.h>
/////// Plane
-#include "plane.h"
+#include <godot/plane.h>
/////// Quat
-#include "quat.h"
+#include <godot/quat.h>
/////// Rect3
-#include "rect3.h"
+#include <godot/rect3.h>
/////// Basis
-#include "basis.h"
+#include <godot/basis.h>
/////// Transform
-#include "transform.h"
+#include <godot/transform.h>
/////// Color
-#include "color.h"
+#include <godot/color.h>
/////// NodePath
-#include "node_path.h"
+#include <godot/node_path.h>
/////// RID
-#include "rid.h"
+#include <godot/rid.h>
/////// Dictionary
-#include "dictionary.h"
+#include <godot/dictionary.h>
/////// Array
-#include "array.h"
+#include <godot/array.h>
// single API file for Pool*Array
-#include "pool_arrays.h"
+#include <godot/pool_arrays.h>
void GDAPI godot_object_destroy(godot_object *p_o);
////// Variant
-#include "variant.h"
+#include <godot/variant.h>
////// Singleton API
godot_object GDAPI *godot_global_get_singleton(char *p_name); // result shouldn't be freed
+////// OS API
+
+void GDAPI *godot_get_stack_bottom(); // returns stack bottom of the main thread
+
////// MethodBind API
typedef struct {
@@ -261,6 +265,7 @@ typedef struct {
uint64_t core_api_hash;
uint64_t editor_api_hash;
uint64_t no_api_hash;
+ godot_object *gd_native_library; // pointer to GDNativeLibrary that is being initialized
} godot_gdnative_init_options;
typedef struct {
diff --git a/modules/gdnative/godot/node_path.cpp b/modules/gdnative/godot/node_path.cpp
index a9edbc8352..f4179361be 100644
--- a/modules/gdnative/godot/node_path.cpp
+++ b/modules/gdnative/godot/node_path.cpp
@@ -27,10 +27,10 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "node_path.h"
-#include "core/variant.h"
+#include <godot/node_path.h>
-#include "core/path_db.h"
+#include "core/node_path.h"
+#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
diff --git a/modules/gdnative/godot/node_path.h b/modules/gdnative/godot/node_path.h
index 06955a052e..4d3dc4e0ee 100644
--- a/modules/gdnative/godot/node_path.h
+++ b/modules/gdnative/godot/node_path.h
@@ -45,8 +45,8 @@ typedef struct {
} godot_node_path;
#endif
-#include "gdnative.h"
-#include "string.h"
+#include <godot/gdnative.h>
+#include <godot/string.h>
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);
diff --git a/modules/gdnative/godot/plane.cpp b/modules/gdnative/godot/plane.cpp
index e9e659e5da..5c5b302345 100644
--- a/modules/gdnative/godot/plane.cpp
+++ b/modules/gdnative/godot/plane.cpp
@@ -27,10 +27,10 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "plane.h"
-#include "core/variant.h"
+#include <godot/plane.h>
#include "core/math/plane.h"
+#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
diff --git a/modules/gdnative/godot/plane.h b/modules/gdnative/godot/plane.h
index e9e3b71e03..8519ac60c4 100644
--- a/modules/gdnative/godot/plane.h
+++ b/modules/gdnative/godot/plane.h
@@ -45,8 +45,8 @@ typedef struct {
} godot_plane;
#endif
-#include "gdnative.h"
-#include "vector3.h"
+#include <godot/gdnative.h>
+#include <godot/vector3.h>
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);
diff --git a/modules/gdnative/godot/pool_arrays.cpp b/modules/gdnative/godot/pool_arrays.cpp
index 6a6ee0f126..fa460be8bc 100644
--- a/modules/gdnative/godot/pool_arrays.cpp
+++ b/modules/gdnative/godot/pool_arrays.cpp
@@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "pool_arrays.h"
+#include <godot/pool_arrays.h>
#include "array.h"
#include "core/variant.h"
diff --git a/modules/gdnative/godot/pool_arrays.h b/modules/gdnative/godot/pool_arrays.h
index 1e2916cea9..29517d21ac 100644
--- a/modules/gdnative/godot/pool_arrays.h
+++ b/modules/gdnative/godot/pool_arrays.h
@@ -113,12 +113,12 @@ typedef struct {
} godot_pool_color_array;
#endif
-#include "array.h"
-#include "color.h"
-#include "vector2.h"
-#include "vector3.h"
+#include <godot/array.h>
+#include <godot/color.h>
+#include <godot/vector2.h>
+#include <godot/vector3.h>
-#include "gdnative.h"
+#include <godot/gdnative.h>
// byte
diff --git a/modules/gdnative/godot/quat.cpp b/modules/gdnative/godot/quat.cpp
index 6800f7fc7e..37ee4d6b15 100644
--- a/modules/gdnative/godot/quat.cpp
+++ b/modules/gdnative/godot/quat.cpp
@@ -27,10 +27,10 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "quat.h"
-#include "core/variant.h"
+#include <godot/quat.h>
#include "core/math/quat.h"
+#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
diff --git a/modules/gdnative/godot/quat.h b/modules/gdnative/godot/quat.h
index b86cbacc62..0979653d93 100644
--- a/modules/gdnative/godot/quat.h
+++ b/modules/gdnative/godot/quat.h
@@ -45,8 +45,8 @@ typedef struct {
} godot_quat;
#endif
-#include "gdnative.h"
-#include "vector3.h"
+#include <godot/gdnative.h>
+#include <godot/vector3.h>
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);
diff --git a/modules/gdnative/godot/rect2.cpp b/modules/gdnative/godot/rect2.cpp
index 830d7bb496..023584c4f6 100644
--- a/modules/gdnative/godot/rect2.cpp
+++ b/modules/gdnative/godot/rect2.cpp
@@ -27,10 +27,10 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "rect2.h"
-#include "core/variant.h"
+#include <godot/rect2.h>
#include "core/math/math_2d.h"
+#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
diff --git a/modules/gdnative/godot/rect2.h b/modules/gdnative/godot/rect2.h
index 7b6613d9dd..cb1ddb58cf 100644
--- a/modules/gdnative/godot/rect2.h
+++ b/modules/gdnative/godot/rect2.h
@@ -43,8 +43,8 @@ typedef struct godot_rect2 {
} godot_rect2;
#endif
-#include "gdnative.h"
-#include "vector2.h"
+#include <godot/gdnative.h>
+#include <godot/vector2.h>
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);
diff --git a/modules/gdnative/godot/rect3.cpp b/modules/gdnative/godot/rect3.cpp
index 0fabba5b7b..708d2987f2 100644
--- a/modules/gdnative/godot/rect3.cpp
+++ b/modules/gdnative/godot/rect3.cpp
@@ -27,10 +27,10 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "rect3.h"
-#include "core/variant.h"
+#include <godot/rect3.h>
#include "core/math/rect3.h"
+#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
diff --git a/modules/gdnative/godot/rect3.h b/modules/gdnative/godot/rect3.h
index 638d89f76f..69279351c4 100644
--- a/modules/gdnative/godot/rect3.h
+++ b/modules/gdnative/godot/rect3.h
@@ -45,9 +45,9 @@ typedef struct {
} godot_rect3;
#endif
-#include "gdnative.h"
-#include "plane.h"
-#include "vector3.h"
+#include <godot/gdnative.h>
+#include <godot/plane.h>
+#include <godot/vector3.h>
void GDAPI godot_rect3_new(godot_rect3 *r_dest, const godot_vector3 *p_pos, const godot_vector3 *p_size);
diff --git a/modules/gdnative/godot/rid.cpp b/modules/gdnative/godot/rid.cpp
index 2b724e554d..eb9538e692 100644
--- a/modules/gdnative/godot/rid.cpp
+++ b/modules/gdnative/godot/rid.cpp
@@ -27,11 +27,11 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "rid.h"
-#include "core/variant.h"
+#include <godot/rid.h>
#include "core/resource.h"
#include "core/rid.h"
+#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
diff --git a/modules/gdnative/godot/rid.h b/modules/gdnative/godot/rid.h
index 92e101fd2e..ac5b5383d9 100644
--- a/modules/gdnative/godot/rid.h
+++ b/modules/gdnative/godot/rid.h
@@ -45,7 +45,7 @@ typedef struct {
} godot_rid;
#endif
-#include "gdnative.h"
+#include <godot/gdnative.h>
void GDAPI godot_rid_new(godot_rid *r_dest);
diff --git a/modules/gdnative/godot/string.cpp b/modules/gdnative/godot/string.cpp
index e54ef3655f..3573f266ac 100644
--- a/modules/gdnative/godot/string.cpp
+++ b/modules/gdnative/godot/string.cpp
@@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "string.h"
+#include <godot/string.h>
#include "string_db.h"
#include "ustring.h"
diff --git a/modules/gdnative/godot/string.h b/modules/gdnative/godot/string.h
index d4d6d6c1d0..9013326454 100644
--- a/modules/gdnative/godot/string.h
+++ b/modules/gdnative/godot/string.h
@@ -46,7 +46,7 @@ typedef struct {
} godot_string;
#endif
-#include "gdnative.h"
+#include <godot/gdnative.h>
void GDAPI godot_string_new(godot_string *r_dest);
void GDAPI godot_string_new_copy(godot_string *r_dest, const godot_string *p_src);
diff --git a/modules/gdnative/godot/transform.cpp b/modules/gdnative/godot/transform.cpp
index e566ed0b6e..87fee918bd 100644
--- a/modules/gdnative/godot/transform.cpp
+++ b/modules/gdnative/godot/transform.cpp
@@ -27,10 +27,10 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "transform.h"
-#include "core/variant.h"
+#include <godot/transform.h>
#include "core/math/transform.h"
+#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
diff --git a/modules/gdnative/godot/transform.h b/modules/gdnative/godot/transform.h
index d14190ec49..30b9970f67 100644
--- a/modules/gdnative/godot/transform.h
+++ b/modules/gdnative/godot/transform.h
@@ -45,10 +45,10 @@ typedef struct {
} godot_transform;
#endif
-#include "basis.h"
-#include "gdnative.h"
-#include "variant.h"
-#include "vector3.h"
+#include <godot/basis.h>
+#include <godot/gdnative.h>
+#include <godot/variant.h>
+#include <godot/vector3.h>
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);
diff --git a/modules/gdnative/godot/transform2d.cpp b/modules/gdnative/godot/transform2d.cpp
index 01db3f7ae0..65f9f8ee32 100644
--- a/modules/gdnative/godot/transform2d.cpp
+++ b/modules/gdnative/godot/transform2d.cpp
@@ -27,10 +27,10 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "transform2d.h"
-#include "core/variant.h"
+#include <godot/transform2d.h>
#include "core/math/math_2d.h"
+#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
diff --git a/modules/gdnative/godot/transform2d.h b/modules/gdnative/godot/transform2d.h
index 7171e528f2..41c8ba982c 100644
--- a/modules/gdnative/godot/transform2d.h
+++ b/modules/gdnative/godot/transform2d.h
@@ -45,9 +45,9 @@ typedef struct {
} godot_transform2d;
#endif
-#include "gdnative.h"
-#include "variant.h"
-#include "vector2.h"
+#include <godot/gdnative.h>
+#include <godot/variant.h>
+#include <godot/vector2.h>
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);
diff --git a/modules/gdnative/godot/variant.cpp b/modules/gdnative/godot/variant.cpp
index 3469058cfd..d814ef913c 100644
--- a/modules/gdnative/godot/variant.cpp
+++ b/modules/gdnative/godot/variant.cpp
@@ -27,7 +27,8 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "variant.h"
+#include <godot/variant.h>
+
#include "core/variant.h"
#ifdef __cplusplus
@@ -432,7 +433,6 @@ godot_variant GDAPI godot_variant_call(godot_variant *p_self, const godot_string
Variant *dest = (Variant *)&raw_dest;
Variant::CallError error;
memnew_placement_custom(dest, Variant, Variant(self->call(*method, args, p_argcount, error)));
- *dest = self->call(StringName(*method), args, p_argcount, r_error);
if (r_error) {
r_error->error = (godot_variant_call_error_error)error.error;
r_error->argument = error.argument;
diff --git a/modules/gdnative/godot/variant.h b/modules/gdnative/godot/variant.h
index b56d5824fa..1c19d2a25b 100644
--- a/modules/gdnative/godot/variant.h
+++ b/modules/gdnative/godot/variant.h
@@ -99,25 +99,25 @@ typedef struct godot_variant_call_error {
godot_variant_type expected;
} godot_variant_call_error;
-#include "array.h"
-#include "basis.h"
-#include "color.h"
-#include "dictionary.h"
-#include "node_path.h"
-#include "plane.h"
-#include "pool_arrays.h"
-#include "quat.h"
-#include "rect2.h"
-#include "rect3.h"
-#include "rid.h"
-#include "string.h"
-#include "transform.h"
-#include "transform2d.h"
-#include "variant.h"
-#include "vector2.h"
-#include "vector3.h"
-
-#include "gdnative.h"
+#include <godot/array.h>
+#include <godot/basis.h>
+#include <godot/color.h>
+#include <godot/dictionary.h>
+#include <godot/node_path.h>
+#include <godot/plane.h>
+#include <godot/pool_arrays.h>
+#include <godot/quat.h>
+#include <godot/rect2.h>
+#include <godot/rect3.h>
+#include <godot/rid.h>
+#include <godot/string.h>
+#include <godot/transform.h>
+#include <godot/transform2d.h>
+#include <godot/variant.h>
+#include <godot/vector2.h>
+#include <godot/vector3.h>
+
+#include <godot/gdnative.h>
godot_variant_type GDAPI godot_variant_get_type(const godot_variant *p_v);
diff --git a/modules/gdnative/godot/vector2.cpp b/modules/gdnative/godot/vector2.cpp
index 6b40e31a89..05d4b1acc8 100644
--- a/modules/gdnative/godot/vector2.cpp
+++ b/modules/gdnative/godot/vector2.cpp
@@ -27,10 +27,10 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "vector2.h"
-#include "core/variant.h"
+#include <godot/vector2.h>
#include "core/math/math_2d.h"
+#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
diff --git a/modules/gdnative/godot/vector2.h b/modules/gdnative/godot/vector2.h
index 9934ddadbb..9db238b4fd 100644
--- a/modules/gdnative/godot/vector2.h
+++ b/modules/gdnative/godot/vector2.h
@@ -45,7 +45,7 @@ typedef struct {
} godot_vector2;
#endif
-#include "gdnative.h"
+#include <godot/gdnative.h>
void GDAPI godot_vector2_new(godot_vector2 *r_dest, const godot_real p_x, const godot_real p_y);
diff --git a/modules/gdnative/godot/vector3.cpp b/modules/gdnative/godot/vector3.cpp
index 904cdad9d0..fe27e740e2 100644
--- a/modules/gdnative/godot/vector3.cpp
+++ b/modules/gdnative/godot/vector3.cpp
@@ -27,9 +27,9 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "vector3.h"
-#include "core/variant.h"
+#include <godot/vector3.h>
+#include "core/variant.h"
#include "core/vector.h"
#ifdef __cplusplus
diff --git a/modules/gdnative/godot/vector3.h b/modules/gdnative/godot/vector3.h
index b5f8d0f49a..8aba1d9a85 100644
--- a/modules/gdnative/godot/vector3.h
+++ b/modules/gdnative/godot/vector3.h
@@ -45,8 +45,8 @@ typedef struct {
} godot_vector3;
#endif
-#include "basis.h"
-#include "gdnative.h"
+#include <godot/basis.h>
+#include <godot/gdnative.h>
typedef enum {
GODOT_VECTOR3_AXIS_X,
diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp
index 20ac1ecc0c..da50104e26 100644
--- a/modules/gdnative/register_types.cpp
+++ b/modules/gdnative/register_types.cpp
@@ -47,7 +47,8 @@ godot_variant cb_standard_varcall(void *handle, godot_string *p_procedure, godot
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
handle,
*(String *)p_procedure,
- library_proc);
+ library_proc,
+ true); // we roll our own message
if (err != OK) {
ERR_PRINT((String("GDNative procedure \"" + *(String *)p_procedure) + "\" does not exists and can't be called").utf8().get_data());
godot_variant ret;
@@ -75,4 +76,26 @@ void register_gdnative_types() {
void unregister_gdnative_types() {
memdelete(GDNativeCallRegistry::singleton);
+
+ // This is for printing out the sizes of the core types
+
+ /*
+ print_line(String("array:\t") + itos(sizeof(Array)));
+ print_line(String("basis:\t") + itos(sizeof(Basis)));
+ print_line(String("color:\t") + itos(sizeof(Color)));
+ print_line(String("dict:\t" ) + itos(sizeof(Dictionary)));
+ print_line(String("node_path:\t") + itos(sizeof(NodePath)));
+ print_line(String("plane:\t") + itos(sizeof(Plane)));
+ print_line(String("poolarray:\t") + itos(sizeof(PoolByteArray)));
+ print_line(String("quat:\t") + itos(sizeof(Quat)));
+ print_line(String("rect2:\t") + itos(sizeof(Rect2)));
+ print_line(String("rect3:\t") + itos(sizeof(Rect3)));
+ print_line(String("rid:\t") + itos(sizeof(RID)));
+ print_line(String("string:\t") + itos(sizeof(String)));
+ print_line(String("transform:\t") + itos(sizeof(Transform)));
+ print_line(String("transfo2D:\t") + itos(sizeof(Transform2D)));
+ print_line(String("variant:\t") + itos(sizeof(Variant)));
+ print_line(String("vector2:\t") + itos(sizeof(Vector2)));
+ print_line(String("vector3:\t") + itos(sizeof(Vector3)));
+ */
}
diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp
index ba0413a5a9..36aa249398 100644
--- a/modules/gdscript/gd_parser.cpp
+++ b/modules/gdscript/gd_parser.cpp
@@ -314,9 +314,10 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool
path += String(tokenizer->get_token_literal());
tokenizer->advance();
need_identifier = false;
+ } else {
+ done = true;
}
- done = true;
break;
}
}
diff --git a/modules/nativescript/nativescript.cpp b/modules/nativescript/nativescript.cpp
index fd83b74727..fb334e573c 100644
--- a/modules/nativescript/nativescript.cpp
+++ b/modules/nativescript/nativescript.cpp
@@ -40,6 +40,10 @@
#include "scene/main/scene_tree.h"
#include "scene/resources/scene_format_text.h"
+#ifndef NO_THREADS
+#include "os/thread.h"
+#endif
+
#if defined(TOOLS_ENABLED) && defined(DEBUG_METHODS_ENABLED)
#include "api_generator.h"
#endif
@@ -106,42 +110,16 @@ void NativeScript::set_library(Ref<GDNativeLibrary> p_library) {
return;
}
library = p_library;
-
- // See if this library was "registered" already.
-
lib_path = library->get_active_library_path();
- Map<String, Ref<GDNative> >::Element *E = NSL->library_gdnatives.find(lib_path);
-
- if (!E) {
- Ref<GDNative> gdn;
- gdn.instance();
- gdn->set_library(library);
-
- // TODO(karroffel): check the return value?
- gdn->initialize();
-
- NSL->library_gdnatives.insert(lib_path, gdn);
-
- NSL->library_classes.insert(lib_path, Map<StringName, NativeScriptDesc>());
-
- if (!NSL->library_script_users.has(lib_path))
- NSL->library_script_users.insert(lib_path, Set<NativeScript *>());
-
- NSL->library_script_users[lib_path].insert(this);
- void *args[1] = {
- (void *)&lib_path
- };
-
- // here the library registers all the classes and stuff.
- gdn->call_native_raw(NSL->_init_call_type,
- NSL->_init_call_name,
- NULL,
- 1,
- args,
- NULL);
- } else {
- // already initialized. Nice.
+#ifndef NO_THREADS
+ if (Thread::get_caller_ID() != Thread::get_main_ID()) {
+ NSL->defer_init_library(p_library, this);
+ } else
+#endif
+ {
+ NSL->init_library(p_library);
+ NSL->register_script(this);
}
}
@@ -225,7 +203,16 @@ ScriptInstance *NativeScript::instance_create(Object *p_this) {
nsi->userdata = script_data->create_func.create_func((godot_object *)p_this, script_data->create_func.method_data);
#endif
+#ifndef NO_THREADS
+ owners_lock->lock();
+#endif
+
instance_owners.insert(p_this);
+
+#ifndef NO_THREADS
+ owners_lock->unlock();
+#endif
+
return nsi;
}
@@ -296,9 +283,13 @@ ScriptLanguage *NativeScript::get_language() const {
bool NativeScript::has_script_signal(const StringName &p_signal) const {
NativeScriptDesc *script_data = get_script_desc();
- if (!script_data)
- return false;
- return script_data->signals_.has(p_signal);
+
+ while (script_data) {
+ if (script_data->signals_.has(p_signal))
+ return true;
+ script_data = script_data->base_data;
+ }
+ return false;
}
void NativeScript::get_script_signal_list(List<MethodInfo> *r_signals) const {
@@ -415,9 +406,6 @@ Variant NativeScript::_new(const Variant **p_args, int p_argcount, Variant::Call
ref = REF(r);
}
- // GDScript does it like this: _create_instance(p_args, p_argcount, owner, r != NULL, r_error);
- // TODO(karroffel): support varargs for constructors.
-
NativeScriptInstance *instance = (NativeScriptInstance *)instance_create(owner);
owner->set_script_instance(instance);
@@ -441,11 +429,18 @@ NativeScript::NativeScript() {
library = Ref<GDNative>();
lib_path = "";
class_name = "";
+#ifndef NO_THREADS
+ owners_lock = Mutex::create();
+#endif
}
// TODO(karroffel): implement this
NativeScript::~NativeScript() {
- NSL->library_script_users[lib_path].erase(this);
+ NSL->unregister_script(this);
+
+#ifndef NO_THREADS
+ memdelete(owners_lock);
+#endif
}
////// ScriptInstance stuff
@@ -650,6 +645,28 @@ void NativeScriptInstance::notification(int p_notification) {
call_multilevel("_notification", args, 1);
}
+void NativeScriptInstance::refcount_incremented() {
+ Variant::CallError err;
+ call("_refcount_incremented", NULL, 0, err);
+ if (err.error != Variant::CallError::CALL_OK && err.error != Variant::CallError::CALL_ERROR_INVALID_METHOD) {
+ ERR_PRINT("Failed to invoke _refcount_incremented - should not happen");
+ }
+}
+
+bool NativeScriptInstance::refcount_decremented() {
+ Variant::CallError err;
+ Variant ret = call("_refcount_decremented", NULL, 0, err);
+ if (err.error != Variant::CallError::CALL_OK && err.error != Variant::CallError::CALL_ERROR_INVALID_METHOD) {
+ ERR_PRINT("Failed to invoke _refcount_decremented - should not happen");
+ return true; // assume we can destroy the object
+ }
+ if (err.error == Variant::CallError::CALL_ERROR_INVALID_METHOD) {
+ // the method does not exist, default is true
+ return true;
+ }
+ return ret;
+}
+
Ref<Script> NativeScriptInstance::get_script() const {
return script;
}
@@ -754,7 +771,16 @@ NativeScriptInstance::~NativeScriptInstance() {
script_data->destroy_func.destroy_func((godot_object *)owner, script_data->destroy_func.method_data, userdata);
if (owner) {
+
+#ifndef NO_THREADS
+ script->owners_lock->lock();
+#endif
+
script->instance_owners.erase(owner);
+
+#ifndef NO_THREADS
+ script->owners_lock->unlock();
+#endif
}
}
@@ -798,6 +824,9 @@ void NativeScriptLanguage::_unload_stuff() {
NativeScriptLanguage::NativeScriptLanguage() {
NativeScriptLanguage::singleton = this;
+#ifndef NO_THREADS
+ mutex = Mutex::create();
+#endif
}
// TODO(karroffel): implement this
@@ -811,6 +840,10 @@ NativeScriptLanguage::~NativeScriptLanguage() {
NSL->library_gdnatives.clear();
NSL->library_script_users.clear();
}
+
+#ifndef NO_THREADS
+ memdelete(mutex);
+#endif
}
String NativeScriptLanguage::get_name() const {
@@ -948,6 +981,122 @@ int NativeScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, in
return -1;
}
+#ifndef NO_THREADS
+void NativeScriptLanguage::defer_init_library(Ref<GDNativeLibrary> lib, NativeScript *script) {
+ MutexLock lock(mutex);
+ libs_to_init.insert(lib);
+ scripts_to_register.insert(script);
+ has_objects_to_register = true;
+}
+#endif
+
+void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) {
+#ifndef NO_THREADS
+ MutexLock lock(mutex);
+#endif
+ // See if this library was "registered" already.
+ const String &lib_path = lib->get_active_library_path();
+ Map<String, Ref<GDNative> >::Element *E = library_gdnatives.find(lib_path);
+
+ if (!E) {
+ Ref<GDNative> gdn;
+ gdn.instance();
+ gdn->set_library(lib);
+
+ // TODO(karroffel): check the return value?
+ gdn->initialize();
+
+ library_gdnatives.insert(lib_path, gdn);
+
+ library_classes.insert(lib_path, Map<StringName, NativeScriptDesc>());
+
+ if (!library_script_users.has(lib_path))
+ library_script_users.insert(lib_path, Set<NativeScript *>());
+
+ void *args[1] = {
+ (void *)&lib_path
+ };
+
+ // here the library registers all the classes and stuff.
+ gdn->call_native_raw(_init_call_type,
+ _init_call_name,
+ NULL,
+ 1,
+ args,
+ NULL);
+ } else {
+ // already initialized. Nice.
+ }
+}
+
+void NativeScriptLanguage::register_script(NativeScript *script) {
+#ifndef NO_THREADS
+ MutexLock lock(mutex);
+#endif
+ library_script_users[script->lib_path].insert(script);
+}
+
+void NativeScriptLanguage::unregister_script(NativeScript *script) {
+#ifndef NO_THREADS
+ MutexLock lock(mutex);
+#endif
+ Map<String, Set<NativeScript *> >::Element *S = library_script_users.find(script->lib_path);
+ if (S) {
+ S->get().erase(script);
+ if (S->get().size() == 0) {
+ library_script_users.erase(S);
+ }
+ }
+#ifndef NO_THREADS
+ scripts_to_register.erase(script);
+#endif
+}
+
+void NativeScriptLanguage::call_libraries_cb(const StringName &name) {
+ // library_gdnatives is modified only from the main thread, so it's safe not to use mutex here
+ for (Map<String, Ref<GDNative> >::Element *L = library_gdnatives.front(); L; L = L->next()) {
+ if (L->get()->is_initialized()) {
+ L->get()->call_native_raw(
+ _noarg_call_type,
+ name,
+ NULL,
+ 0,
+ NULL,
+ NULL);
+ }
+ }
+}
+
+void NativeScriptLanguage::frame() {
+#ifndef NO_THREADS
+ if (has_objects_to_register) {
+ MutexLock lock(mutex);
+ for (Set<Ref<GDNativeLibrary> >::Element *L = libs_to_init.front(); L; L = L->next()) {
+ init_library(L->get());
+ }
+ libs_to_init.clear();
+ for (Set<NativeScript *>::Element *S = scripts_to_register.front(); S; S = S->next()) {
+ register_script(S->get());
+ }
+ scripts_to_register.clear();
+ has_objects_to_register = false;
+ }
+#endif
+ call_libraries_cb(_frame_call_name);
+}
+
+#ifndef NO_THREADS
+
+void NativeScriptLanguage::thread_enter() {
+ call_libraries_cb(_thread_enter_call_name);
+}
+
+void NativeScriptLanguage::thread_exit() {
+ call_libraries_cb(_thread_exit_call_name);
+}
+
+#endif // NO_THREADS
+
void NativeReloadNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("_notification"), &NativeReloadNode::_notification);
}
@@ -960,7 +1109,9 @@ void NativeReloadNode::_notification(int p_what) {
if (unloaded)
break;
-
+#ifndef NO_THREADS
+ MutexLock lock(NSL->mutex);
+#endif
NSL->_unload_stuff();
for (Map<String, Ref<GDNative> >::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) {
@@ -976,9 +1127,10 @@ void NativeReloadNode::_notification(int p_what) {
if (!unloaded)
break;
-
+#ifndef NO_THREADS
+ MutexLock lock(NSL->mutex);
+#endif
Set<StringName> libs_to_remove;
-
for (Map<String, Ref<GDNative> >::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) {
if (!L->get()->initialize()) {
diff --git a/modules/nativescript/nativescript.h b/modules/nativescript/nativescript.h
index bc7a6e3ed6..c60effd0c1 100644
--- a/modules/nativescript/nativescript.h
+++ b/modules/nativescript/nativescript.h
@@ -41,6 +41,10 @@
#include "godot_nativescript.h"
#include "modules/gdnative/gdnative.h"
+#ifndef NO_THREADS
+#include "os/mutex.h"
+#endif
+
struct NativeScriptDesc {
struct Method {
@@ -102,6 +106,9 @@ class NativeScript : public Script {
String class_name;
+#ifndef NO_THREADS
+ Mutex *owners_lock;
+#endif
Set<Object *> instance_owners;
protected:
@@ -181,6 +188,9 @@ public:
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();
};
@@ -197,7 +207,23 @@ private:
void _unload_stuff();
+#ifndef NO_THREADS
+ Mutex *mutex;
+
+ Set<Ref<GDNativeLibrary> > libs_to_init;
+ Set<NativeScript *> scripts_to_register;
+ volatile bool 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);
+
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;
@@ -206,6 +232,15 @@ public:
const StringName _init_call_type = "nativescript_init";
const StringName _init_call_name = "godot_nativescript_init";
+ const StringName _noarg_call_type = "nativescript_no_arg";
+
+ const StringName _frame_call_name = "godot_nativescript_frame";
+
+#ifndef NO_THREADS
+ const StringName _thread_enter_call_name = "godot_nativescript_thread_enter";
+ const StringName _thread_exit_call_name = "godot_nativescript_thread_exit";
+#endif
+
NativeScriptLanguage();
~NativeScriptLanguage();
@@ -215,6 +250,13 @@ public:
void _hacky_api_anchor();
+#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;
diff --git a/modules/nativescript/register_types.cpp b/modules/nativescript/register_types.cpp
index 6c88b04a56..c28b982884 100644
--- a/modules/nativescript/register_types.cpp
+++ b/modules/nativescript/register_types.cpp
@@ -50,7 +50,8 @@ void init_call_cb(void *p_handle, godot_string *p_proc_name, void *p_data, int p
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
p_handle,
*(String *)p_proc_name,
- library_proc);
+ library_proc,
+ true); // we print our own message
if (err != OK) {
ERR_PRINT((String("GDNative procedure \"" + *(String *)p_proc_name) + "\" does not exists and can't be called").utf8().get_data());
return;
@@ -61,6 +62,29 @@ void init_call_cb(void *p_handle, godot_string *p_proc_name, void *p_data, int p
fn(args[0]);
}
+typedef void (*native_script_empty_callback)();
+
+void noarg_call_cb(void *p_handle, godot_string *p_proc_name, void *p_data, int p_num_args, void **args, void *r_ret) {
+ if (p_handle == NULL) {
+ ERR_PRINT("No valid library handle, can't call nativescript callback");
+ return;
+ }
+
+ void *library_proc;
+ Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
+ p_handle,
+ *(String *)p_proc_name,
+ library_proc,
+ true);
+ if (err != OK) {
+ // it's fine if thread callbacks are not present in the library.
+ return;
+ }
+
+ native_script_empty_callback fn = (native_script_empty_callback)library_proc;
+ fn();
+}
+
ResourceFormatLoaderNativeScript *resource_loader_gdns = NULL;
ResourceFormatSaverNativeScript *resource_saver_gdns = NULL;
@@ -72,6 +96,7 @@ void register_nativescript_types() {
ScriptServer::register_language(native_script_language);
GDNativeCallRegistry::singleton->register_native_raw_call_type(native_script_language->_init_call_type, init_call_cb);
+ GDNativeCallRegistry::singleton->register_native_raw_call_type(native_script_language->_noarg_call_type, noarg_call_cb);
resource_saver_gdns = memnew(ResourceFormatSaverNativeScript);
ResourceSaver::add_resource_format_saver(resource_saver_gdns);
diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
index c645a55703..7b8b2abebb 100644
--- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
+++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
@@ -39,7 +39,7 @@ void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_fra
int todo = p_frames;
- while (todo) {
+ while (todo && active) {
int mixed = stb_vorbis_get_samples_float_interleaved(ogg_stream, 2, (float *)p_buffer, todo * 2);
todo -= mixed;
diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp
index ba3463445d..35358d5a1f 100644
--- a/modules/visual_script/visual_script_editor.cpp
+++ b/modules/visual_script/visual_script_editor.cpp
@@ -2328,6 +2328,16 @@ void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot,
undo_redo->add_do_method(script.ptr(), "sequence_connect", edited_func, p_from.to_int(), from_port, p_to.to_int());
undo_redo->add_undo_method(script.ptr(), "sequence_disconnect", edited_func, p_from.to_int(), from_port, p_to.to_int());
} else {
+
+ // disconect current, and connect the new one
+ if (script->is_input_value_port_connected(edited_func, p_to.to_int(), to_port)) {
+ int conn_from;
+ int conn_port;
+ script->get_input_value_port_connection_source(edited_func, p_to.to_int(), to_port, &conn_from, &conn_port);
+ undo_redo->add_do_method(script.ptr(), "data_disconnect", edited_func, conn_from, conn_port, p_to.to_int(), to_port);
+ undo_redo->add_undo_method(script.ptr(), "data_connect", edited_func, conn_from, conn_port, p_to.to_int(), to_port);
+ }
+
undo_redo->add_do_method(script.ptr(), "data_connect", edited_func, p_from.to_int(), from_port, p_to.to_int(), to_port);
undo_redo->add_undo_method(script.ptr(), "data_disconnect", edited_func, p_from.to_int(), from_port, p_to.to_int(), to_port);
//update nodes in sgraph
diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp
index 69aa10ebca..d5d8b8fe6e 100644
--- a/modules/visual_script/visual_script_nodes.cpp
+++ b/modules/visual_script/visual_script_nodes.cpp
@@ -2798,7 +2798,7 @@ public:
r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
return 0;
}
- *p_outputs[0] = subcall->call(VisualScriptLanguage::singleton->_subcall, p_inputs, input_args, r_error_str);
+ *p_outputs[0] = subcall->call(VisualScriptLanguage::singleton->_subcall, p_inputs, input_args, r_error);
return 0;
}
};