summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/static_checks.yml8
-rw-r--r--SConstruct3
-rw-r--r--core/config/engine.cpp5
-rw-r--r--core/core_bind.cpp4
-rw-r--r--core/core_bind.h4
-rw-r--r--core/core_constants.cpp4
-rw-r--r--core/crypto/aes_context.cpp1
-rw-r--r--core/crypto/aes_context.h2
-rw-r--r--core/crypto/crypto_core.h8
-rw-r--r--core/crypto/hashing_context.h2
-rw-r--r--core/debugger/debugger_marshalls.cpp2
-rw-r--r--core/debugger/debugger_marshalls.h2
-rw-r--r--core/io/file_access_encrypted.h4
-rw-r--r--core/io/file_access_memory.h4
-rw-r--r--core/io/image.cpp12
-rw-r--r--core/io/image.h4
-rw-r--r--core/io/packed_data_container.h2
-rw-r--r--core/io/pck_packer.h8
-rw-r--r--core/math/a_star.h16
-rw-r--r--core/math/expression.h22
-rw-r--r--core/math/quick_hull.h10
-rw-r--r--core/object/method_bind.h17
-rw-r--r--core/object/reference.h4
-rw-r--r--core/os/dir_access.h1
-rw-r--r--core/os/file_access.cpp4
-rw-r--r--core/templates/hash_map.h2
-rw-r--r--core/templates/list.h6
-rw-r--r--core/templates/safe_refcount.h2
-rw-r--r--core/templates/set.h2
-rw-r--r--core/templates/thread_work_pool.h4
-rw-r--r--core/variant/array.cpp2
-rw-r--r--core/variant/binder_common.h26
-rw-r--r--core/variant/callable.h6
-rw-r--r--core/variant/method_ptrcall.h26
-rw-r--r--core/variant/typed_array.h4
-rw-r--r--core/variant/variant.h5
-rw-r--r--core/variant/variant_internal.h233
-rw-r--r--core/variant/variant_op.cpp222
-rw-r--r--doc/classes/AudioStreamPlayer3D.xml28
-rw-r--r--doc/classes/EditorNode3DGizmoPlugin.xml2
-rw-r--r--doc/classes/Image.xml54
-rw-r--r--doc/classes/Input.xml36
-rw-r--r--doc/classes/InputMap.xml2
-rw-r--r--doc/classes/Reference.xml1
-rw-r--r--doc/classes/RenderingServer.xml3
-rw-r--r--doc/classes/Resource.xml1
-rw-r--r--drivers/alsa/audio_driver_alsa.h10
-rw-r--r--drivers/dummy/rasterizer_dummy.h20
-rw-r--r--drivers/unix/ip_unix.cpp2
-rw-r--r--drivers/vulkan/rendering_device_vulkan.cpp1
-rw-r--r--drivers/vulkan/rendering_device_vulkan.h226
-rw-r--r--drivers/vulkan/vulkan_context.h32
-rw-r--r--drivers/windows/dir_access_windows.cpp2
-rw-r--r--drivers/windows/dir_access_windows.h10
-rw-r--r--drivers/xaudio2/audio_driver_xaudio2.h22
-rw-r--r--editor/editor_node.cpp2
-rw-r--r--editor/editor_settings.cpp3
-rw-r--r--editor/import/resource_importer_texture_atlas.cpp8
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp2
-rw-r--r--modules/gdnative/SCsub2
-rw-r--r--modules/gdnative/config.py2
-rw-r--r--modules/gdscript/gdscript_analyzer.cpp16
-rw-r--r--modules/gdscript/gdscript_byte_codegen.cpp704
-rw-r--r--modules/gdscript/gdscript_byte_codegen.h198
-rw-r--r--modules/gdscript/gdscript_codegen.h9
-rw-r--r--modules/gdscript/gdscript_compiler.cpp119
-rw-r--r--modules/gdscript/gdscript_disassembler.cpp813
-rw-r--r--modules/gdscript/gdscript_function.cpp2090
-rw-r--r--modules/gdscript/gdscript_function.h183
-rw-r--r--modules/gdscript/gdscript_vm.cpp2863
-rw-r--r--modules/mono/config.py1
-rw-r--r--modules/regex/regex.h1
-rw-r--r--modules/regex/tests/test_regex.h164
-rw-r--r--modules/webm/doc_classes/VideoStreamWebm.xml1
-rw-r--r--modules/webrtc/library_godot_webrtc.js248
-rw-r--r--modules/websocket/library_godot_websocket.js92
-rw-r--r--platform/android/export/export.cpp113
-rw-r--r--platform/android/export/gradle_export_util.h2
-rw-r--r--platform/android/java/app/build.gradle39
-rw-r--r--platform/android/java/app/config.gradle40
-rw-r--r--platform/iphone/native_video_view.m6
-rw-r--r--platform/iphone/view_controller.mm5
-rw-r--r--platform/javascript/.eslintrc.engine.js10
-rw-r--r--platform/javascript/.eslintrc.js43
-rw-r--r--platform/javascript/.eslintrc.libs.js22
-rw-r--r--platform/javascript/SCsub23
-rw-r--r--platform/javascript/engine/preloader.js135
-rw-r--r--platform/javascript/js/engine/engine.externs.js (renamed from platform/javascript/engine/externs.js)0
-rw-r--r--platform/javascript/js/engine/engine.js (renamed from platform/javascript/engine/engine.js)150
-rw-r--r--platform/javascript/js/engine/preloader.js127
-rw-r--r--platform/javascript/js/engine/utils.js (renamed from platform/javascript/engine/utils.js)43
-rw-r--r--platform/javascript/js/libs/audio.worklet.js (renamed from platform/javascript/native/audio.worklet.js)27
-rw-r--r--platform/javascript/js/libs/library_godot_audio.js (renamed from platform/javascript/native/library_godot_audio.js)154
-rw-r--r--platform/javascript/js/libs/library_godot_display.js (renamed from platform/javascript/native/library_godot_display.js)237
-rw-r--r--platform/javascript/js/libs/library_godot_editor_tools.js (renamed from platform/javascript/native/library_godot_editor_tools.js)8
-rw-r--r--platform/javascript/js/libs/library_godot_eval.js (renamed from platform/javascript/native/library_godot_eval.js)68
-rw-r--r--platform/javascript/js/libs/library_godot_http_request.js (renamed from platform/javascript/native/http_request.js)89
-rw-r--r--platform/javascript/js/libs/library_godot_os.js (renamed from platform/javascript/native/library_godot_os.js)146
-rw-r--r--platform/javascript/js/libs/library_godot_runtime.js120
-rw-r--r--platform/javascript/package-lock.json1605
-rw-r--r--platform/javascript/package.json24
-rw-r--r--platform/linuxbsd/detect.py1
-rw-r--r--platform/server/detect.py1
-rw-r--r--scene/2d/camera_2d.cpp2
-rw-r--r--scene/gui/line_edit.cpp1
-rw-r--r--scene/gui/scroll_container.cpp4
-rw-r--r--tests/test_aabb.h375
-rw-r--r--tests/test_main.cpp1
-rw-r--r--tests/test_string.h13
109 files changed, 8529 insertions, 3771 deletions
diff --git a/.github/workflows/static_checks.yml b/.github/workflows/static_checks.yml
index 3fa759bb03..da3327246b 100644
--- a/.github/workflows/static_checks.yml
+++ b/.github/workflows/static_checks.yml
@@ -9,7 +9,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- # Azure repositories are not reliable, we need to prevent azure giving us packages.
+ # Azure repositories are not reliable, we need to prevent Azure giving us packages.
- name: Make apt sources.list use the default Ubuntu repositories
run: |
sudo rm -f /etc/apt/sources.list.d/*
@@ -33,6 +33,12 @@ jobs:
run: |
bash ./misc/scripts/black_format.sh
+ - name: JavaScript style checks via ESLint
+ run: |
+ cd platform/javascript
+ npm ci
+ npm run lint
+
- name: Documentation checks
run: |
doc/tools/makerst.py --dry-run doc/classes modules
diff --git a/SConstruct b/SConstruct
index f134dfddac..d82ceb514b 100644
--- a/SConstruct
+++ b/SConstruct
@@ -67,7 +67,6 @@ if "TERM" in os.environ:
env_base.AppendENVPath("PATH", os.getenv("PATH"))
env_base.AppendENVPath("PKG_CONFIG_PATH", os.getenv("PKG_CONFIG_PATH"))
env_base.disabled_modules = []
-env_base.use_ptrcall = False
env_base.module_version_string = ""
env_base.msvc = False
@@ -561,8 +560,6 @@ if selected_platform in platform_list:
env["LIBSUFFIX"] = suffix + env["LIBSUFFIX"]
env["SHLIBSUFFIX"] = suffix + env["SHLIBSUFFIX"]
- if env.use_ptrcall:
- env.Append(CPPDEFINES=["PTRCALL_ENABLED"])
if env["tools"]:
env.Append(CPPDEFINES=["TOOLS_ENABLED"])
if env["disable_3d"]:
diff --git a/core/config/engine.cpp b/core/config/engine.cpp
index 8e2ab094b0..26f8cdf840 100644
--- a/core/config/engine.cpp
+++ b/core/config/engine.cpp
@@ -224,8 +224,9 @@ Engine::Singleton::Singleton(const StringName &p_name, Object *p_ptr) :
name(p_name),
ptr(p_ptr) {
#ifdef DEBUG_ENABLED
- if (Object::cast_to<Reference>(p_ptr)) {
- ERR_PRINT("A class intended to be used as a singleton must *not* inherit from Reference.");
+ Reference *ref = Object::cast_to<Reference>(p_ptr);
+ if (ref && !ref->is_referenced()) {
+ WARN_PRINT("You must use Ref<> to ensure the lifetime of a Reference object intended to be used as a singleton.");
}
#endif
}
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index f3bdea1eec..259d899d39 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -542,9 +542,9 @@ void _OS::dump_memory_to_file(const String &p_file) {
struct _OSCoreBindImg {
String path;
Size2 size;
- int fmt;
+ int fmt = 0;
ObjectID id;
- int vram;
+ int vram = 0;
bool operator<(const _OSCoreBindImg &p_img) const { return vram == p_img.vram ? id < p_img.id : vram > p_img.vram; }
};
diff --git a/core/core_bind.h b/core/core_bind.h
index 4a642c47ce..f3a77a4fa6 100644
--- a/core/core_bind.h
+++ b/core/core_bind.h
@@ -492,8 +492,8 @@ public:
virtual ~_Directory();
private:
- bool _list_skip_navigational;
- bool _list_skip_hidden;
+ bool _list_skip_navigational = false;
+ bool _list_skip_hidden = false;
};
class _Marshalls : public Object {
diff --git a/core/core_constants.cpp b/core/core_constants.cpp
index 64bfff1c58..57ea10c074 100644
--- a/core/core_constants.cpp
+++ b/core/core_constants.cpp
@@ -38,10 +38,10 @@
struct _CoreConstant {
#ifdef DEBUG_METHODS_ENABLED
StringName enum_name;
- bool ignore_value_in_docs;
+ bool ignore_value_in_docs = false;
#endif
const char *name;
- int value;
+ int value = 0;
_CoreConstant() {}
diff --git a/core/crypto/aes_context.cpp b/core/crypto/aes_context.cpp
index 8ef1f4f1d4..608f3c912c 100644
--- a/core/crypto/aes_context.cpp
+++ b/core/crypto/aes_context.cpp
@@ -112,5 +112,4 @@ void AESContext::_bind_methods() {
}
AESContext::AESContext() {
- mode = MODE_MAX;
}
diff --git a/core/crypto/aes_context.h b/core/crypto/aes_context.h
index c23c504a72..557bde1f04 100644
--- a/core/crypto/aes_context.h
+++ b/core/crypto/aes_context.h
@@ -47,7 +47,7 @@ public:
};
private:
- Mode mode;
+ Mode mode = MODE_MAX;
CryptoCore::AESContext ctx;
PackedByteArray iv;
diff --git a/core/crypto/crypto_core.h b/core/crypto/crypto_core.h
index 57ba469f8d..c2ec6febe3 100644
--- a/core/crypto/crypto_core.h
+++ b/core/crypto/crypto_core.h
@@ -37,7 +37,7 @@ class CryptoCore {
public:
class MD5Context {
private:
- void *ctx; // To include, or not to include...
+ void *ctx = nullptr; // To include, or not to include...
public:
MD5Context();
@@ -50,7 +50,7 @@ public:
class SHA1Context {
private:
- void *ctx; // To include, or not to include...
+ void *ctx = nullptr; // To include, or not to include...
public:
SHA1Context();
@@ -63,7 +63,7 @@ public:
class SHA256Context {
private:
- void *ctx; // To include, or not to include...
+ void *ctx = nullptr; // To include, or not to include...
public:
SHA256Context();
@@ -76,7 +76,7 @@ public:
class AESContext {
private:
- void *ctx; // To include, or not to include...
+ void *ctx = nullptr; // To include, or not to include...
public:
AESContext();
diff --git a/core/crypto/hashing_context.h b/core/crypto/hashing_context.h
index 40d075afa9..7cd55ba267 100644
--- a/core/crypto/hashing_context.h
+++ b/core/crypto/hashing_context.h
@@ -45,7 +45,7 @@ public:
private:
void *ctx = nullptr;
- HashType type;
+ HashType type = HASH_MD5;
protected:
static void _bind_methods();
diff --git a/core/debugger/debugger_marshalls.cpp b/core/debugger/debugger_marshalls.cpp
index 3f949b0ae1..03de832b5e 100644
--- a/core/debugger/debugger_marshalls.cpp
+++ b/core/debugger/debugger_marshalls.cpp
@@ -171,7 +171,7 @@ bool DebuggerMarshalls::ServersProfilerFrame::deserialize(const Array &p_arr) {
}
servers.push_back(si);
}
- CHECK_SIZE(p_arr, idx + 3, "ServersProfilerFrame");
+ CHECK_SIZE(p_arr, idx + 1, "ServersProfilerFrame");
int func_size = p_arr[idx];
idx += 1;
CHECK_SIZE(p_arr, idx + func_size, "ServersProfilerFrame");
diff --git a/core/debugger/debugger_marshalls.h b/core/debugger/debugger_marshalls.h
index f5a1a891bf..0c13790d60 100644
--- a/core/debugger/debugger_marshalls.h
+++ b/core/debugger/debugger_marshalls.h
@@ -148,7 +148,7 @@ struct DebuggerMarshalls {
// Visual Profiler
struct VisualProfilerFrame {
- uint64_t frame_number;
+ uint64_t frame_number = 0;
Vector<RS::FrameProfileArea> areas;
Array serialize();
diff --git a/core/io/file_access_encrypted.h b/core/io/file_access_encrypted.h
index fddc6842f3..c760933038 100644
--- a/core/io/file_access_encrypted.h
+++ b/core/io/file_access_encrypted.h
@@ -47,8 +47,8 @@ private:
Vector<uint8_t> key;
bool writing = false;
FileAccess *file = nullptr;
- size_t base;
- size_t length;
+ size_t base = 0;
+ size_t length = 0;
Vector<uint8_t> data;
mutable int pos = 0;
mutable bool eofed = false;
diff --git a/core/io/file_access_memory.h b/core/io/file_access_memory.h
index 1a9bd3fbbb..47012b4e83 100644
--- a/core/io/file_access_memory.h
+++ b/core/io/file_access_memory.h
@@ -35,8 +35,8 @@
class FileAccessMemory : public FileAccess {
uint8_t *data = nullptr;
- int length;
- mutable int pos;
+ int length = 0;
+ mutable int pos = 0;
static FileAccess *create();
diff --git a/core/io/image.cpp b/core/io/image.cpp
index f3c87a0f2d..6dde25af32 100644
--- a/core/io/image.cpp
+++ b/core/io/image.cpp
@@ -2766,8 +2766,8 @@ Dictionary Image::_get_data() const {
return d;
}
-Color Image::get_pixelv(const Point2 &p_src) const {
- return get_pixel(p_src.x, p_src.y);
+Color Image::get_pixelv(const Point2i &p_point) const {
+ return get_pixel(p_point.x, p_point.y);
}
Color Image::_get_color_at_ofs(const uint8_t *ptr, uint32_t ofs) const {
@@ -2976,8 +2976,8 @@ Color Image::get_pixel(int p_x, int p_y) const {
return _get_color_at_ofs(data.ptr(), ofs);
}
-void Image::set_pixelv(const Point2 &p_dst, const Color &p_color) {
- set_pixel(p_dst.x, p_dst.y, p_color);
+void Image::set_pixelv(const Point2i &p_point, const Color &p_color) {
+ set_pixel(p_point.x, p_point.y, p_color);
}
void Image::set_pixel(int p_x, int p_y, const Color &p_color) {
@@ -3132,9 +3132,9 @@ void Image::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_data", "data"), &Image::_set_data);
ClassDB::bind_method(D_METHOD("_get_data"), &Image::_get_data);
- ClassDB::bind_method(D_METHOD("get_pixelv", "src"), &Image::get_pixelv);
+ ClassDB::bind_method(D_METHOD("get_pixelv", "point"), &Image::get_pixelv);
ClassDB::bind_method(D_METHOD("get_pixel", "x", "y"), &Image::get_pixel);
- ClassDB::bind_method(D_METHOD("set_pixelv", "dst", "color"), &Image::set_pixelv);
+ ClassDB::bind_method(D_METHOD("set_pixelv", "point", "color"), &Image::set_pixelv);
ClassDB::bind_method(D_METHOD("set_pixel", "x", "y", "color"), &Image::set_pixel);
ClassDB::bind_method(D_METHOD("load_png_from_buffer", "buffer"), &Image::load_png_from_buffer);
diff --git a/core/io/image.h b/core/io/image.h
index c5ec74f02f..c4c84589e5 100644
--- a/core/io/image.h
+++ b/core/io/image.h
@@ -387,9 +387,9 @@ public:
UsedChannels detect_used_channels(CompressSource p_source = COMPRESS_SOURCE_GENERIC);
void optimize_channels();
- Color get_pixelv(const Point2 &p_src) const;
+ Color get_pixelv(const Point2i &p_point) const;
Color get_pixel(int p_x, int p_y) const;
- void set_pixelv(const Point2 &p_dst, const Color &p_color);
+ void set_pixelv(const Point2i &p_point, const Color &p_color);
void set_pixel(int p_x, int p_y, const Color &p_color);
void set_as_black();
diff --git a/core/io/packed_data_container.h b/core/io/packed_data_container.h
index b784abcd16..3899c14bb4 100644
--- a/core/io/packed_data_container.h
+++ b/core/io/packed_data_container.h
@@ -84,7 +84,7 @@ class PackedDataContainerRef : public Reference {
GDCLASS(PackedDataContainerRef, Reference);
friend class PackedDataContainer;
- uint32_t offset;
+ uint32_t offset = 0;
Ref<PackedDataContainer> from;
protected:
diff --git a/core/io/pck_packer.h b/core/io/pck_packer.h
index c1026c2499..56be1b52df 100644
--- a/core/io/pck_packer.h
+++ b/core/io/pck_packer.h
@@ -39,7 +39,7 @@ class PCKPacker : public Reference {
GDCLASS(PCKPacker, Reference);
FileAccess *file = nullptr;
- int alignment;
+ int alignment = 0;
uint64_t ofs = 0;
Vector<uint8_t> key;
@@ -50,9 +50,9 @@ class PCKPacker : public Reference {
struct File {
String path;
String src_path;
- uint64_t ofs;
- uint64_t size;
- bool encrypted;
+ uint64_t ofs = 0;
+ uint64_t size = 0;
+ bool encrypted = false;
Vector<uint8_t> md5;
};
Vector<File> files;
diff --git a/core/math/a_star.h b/core/math/a_star.h
index a6fa771b30..7cfa73f2c2 100644
--- a/core/math/a_star.h
+++ b/core/math/a_star.h
@@ -47,20 +47,20 @@ class AStar : public Reference {
struct Point {
Point() {}
- int id;
+ int id = 0;
Vector3 pos;
- real_t weight_scale;
- bool enabled;
+ real_t weight_scale = 0;
+ bool enabled = false;
OAHashMap<int, Point *> neighbours = 4u;
OAHashMap<int, Point *> unlinked_neighbours = 4u;
// Used for pathfinding.
- Point *prev_point;
- real_t g_score;
- real_t f_score;
- uint64_t open_pass;
- uint64_t closed_pass;
+ Point *prev_point = nullptr;
+ real_t g_score = 0;
+ real_t f_score = 0;
+ uint64_t open_pass = 0;
+ uint64_t closed_pass = 0;
};
struct SortPoints {
diff --git a/core/math/expression.h b/core/math/expression.h
index d9cedb8c2c..6b34bc6ae8 100644
--- a/core/math/expression.h
+++ b/core/math/expression.h
@@ -133,7 +133,7 @@ private:
ENode *next = nullptr;
- Type type;
+ Type type = TYPE_INPUT;
ENode() {}
virtual ~ENode() {
@@ -144,7 +144,7 @@ private:
};
struct ExpressionNode {
- bool is_op;
+ bool is_op = false;
union {
Variant::Operator op;
ENode *node;
@@ -154,23 +154,23 @@ private:
ENode *_parse_expression();
struct InputNode : public ENode {
- int index;
+ int index = 0;
InputNode() {
type = TYPE_INPUT;
}
};
struct ConstantNode : public ENode {
- Variant value;
+ Variant value = Variant::NIL;
ConstantNode() {
type = TYPE_CONSTANT;
}
};
struct OperatorNode : public ENode {
- Variant::Operator op;
+ Variant::Operator op = Variant::Operator::OP_ADD;
- ENode *nodes[2];
+ ENode *nodes[2] = { nullptr, nullptr };
OperatorNode() {
type = TYPE_OPERATOR;
@@ -184,8 +184,8 @@ private:
};
struct IndexNode : public ENode {
- ENode *base;
- ENode *index;
+ ENode *base = nullptr;
+ ENode *index = nullptr;
IndexNode() {
type = TYPE_INDEX;
@@ -193,7 +193,7 @@ private:
};
struct NamedIndexNode : public ENode {
- ENode *base;
+ ENode *base = nullptr;
StringName name;
NamedIndexNode() {
@@ -202,7 +202,7 @@ private:
};
struct ConstructorNode : public ENode {
- Variant::Type data_type;
+ Variant::Type data_type = Variant::Type::NIL;
Vector<ENode *> arguments;
ConstructorNode() {
@@ -211,7 +211,7 @@ private:
};
struct CallNode : public ENode {
- ENode *base;
+ ENode *base = nullptr;
StringName method;
Vector<ENode *> arguments;
diff --git a/core/math/quick_hull.h b/core/math/quick_hull.h
index 80f32e191b..024325c4fc 100644
--- a/core/math/quick_hull.h
+++ b/core/math/quick_hull.h
@@ -41,7 +41,7 @@ public:
struct Edge {
union {
uint32_t vertices[2];
- uint64_t id;
+ uint64_t id = 0;
};
bool operator<(const Edge &p_edge) const {
@@ -60,7 +60,7 @@ public:
struct Face {
Plane plane;
- uint32_t vertices[3];
+ uint32_t vertices[3] = { 0 };
Vector<int> points_over;
bool operator<(const Face &p_face) const {
@@ -70,11 +70,13 @@ public:
private:
struct FaceConnect {
- List<Face>::Element *left, *right = nullptr;
+ List<Face>::Element *left = nullptr;
+ List<Face>::Element *right = nullptr;
FaceConnect() {}
};
struct RetFaceConnect {
- List<Geometry3D::MeshData::Face>::Element *left, *right = nullptr;
+ List<Geometry3D::MeshData::Face>::Element *left = nullptr;
+ List<Geometry3D::MeshData::Face>::Element *right = nullptr;
RetFaceConnect() {}
};
diff --git a/core/object/method_bind.h b/core/object/method_bind.h
index ddd6ab6baa..bd308c9630 100644
--- a/core/object/method_bind.h
+++ b/core/object/method_bind.h
@@ -123,10 +123,7 @@ public:
_FORCE_INLINE_ int get_argument_count() const { return argument_count; };
virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) = 0;
-
-#ifdef PTRCALL_ENABLED
virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) = 0;
-#endif
StringName get_name() const;
void set_name(const StringName &p_name);
@@ -205,11 +202,9 @@ public:
#endif
}
-#ifdef PTRCALL_ENABLED
virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) {
- ERR_FAIL(); //can't call
- } //todo
-#endif
+ ERR_FAIL(); // Can't call.
+ }
void set_method(NativeCall p_method) { call_method = p_method; }
virtual bool is_const() const { return false; }
@@ -289,7 +284,6 @@ public:
return Variant();
}
-#ifdef PTRCALL_ENABLED
virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) {
#ifdef TYPED_METHOD_BIND
call_with_ptr_args<T, P...>(static_cast<T *>(p_object), method, p_args);
@@ -297,7 +291,6 @@ public:
call_with_ptr_args<MB_T, P...>((MB_T *)(p_object), method, p_args);
#endif
}
-#endif
MethodBindT(void (MB_T::*p_method)(P...)) {
method = p_method;
@@ -370,7 +363,6 @@ public:
return Variant();
}
-#ifdef PTRCALL_ENABLED
virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) {
#ifdef TYPED_METHOD_BIND
call_with_ptr_argsc<T, P...>(static_cast<T *>(p_object), method, p_args);
@@ -378,7 +370,6 @@ public:
call_with_ptr_argsc<MB_T, P...>((MB_T *)(p_object), method, p_args);
#endif
}
-#endif
MethodBindTC(void (MB_T::*p_method)(P...) const) {
method = p_method;
@@ -462,7 +453,6 @@ public:
return ret;
}
-#ifdef PTRCALL_ENABLED
virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) {
#ifdef TYPED_METHOD_BIND
call_with_ptr_args_ret<T, R, P...>(static_cast<T *>(p_object), method, p_args, r_ret);
@@ -470,7 +460,6 @@ public:
call_with_ptr_args_ret<MB_T, R, P...>((MB_T *)(p_object), method, p_args, r_ret);
#endif
}
-#endif
MethodBindTR(R (MB_T::*p_method)(P...)) {
method = p_method;
@@ -555,7 +544,6 @@ public:
return ret;
}
-#ifdef PTRCALL_ENABLED
virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) {
#ifdef TYPED_METHOD_BIND
call_with_ptr_args_retc<T, R, P...>(static_cast<T *>(p_object), method, p_args, r_ret);
@@ -563,7 +551,6 @@ public:
call_with_ptr_args_retc<MB_T, R, P...>((MB_T *)(p_object), method, p_args, r_ret);
#endif
}
-#endif
MethodBindTRC(R (MB_T::*p_method)(P...) const) {
method = p_method;
diff --git a/core/object/reference.h b/core/object/reference.h
index 575f1cd914..0eb127f362 100644
--- a/core/object/reference.h
+++ b/core/object/reference.h
@@ -252,8 +252,6 @@ public:
WeakRef() {}
};
-#ifdef PTRCALL_ENABLED
-
template <class T>
struct PtrToArg<Ref<T>> {
_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
@@ -272,8 +270,6 @@ struct PtrToArg<const Ref<T> &> {
}
};
-#endif // PTRCALL_ENABLED
-
#ifdef DEBUG_METHODS_ENABLED
template <class T>
diff --git a/core/os/dir_access.h b/core/os/dir_access.h
index 0f4fa9b250..17f84d3c52 100644
--- a/core/os/dir_access.h
+++ b/core/os/dir_access.h
@@ -57,7 +57,6 @@ protected:
String _get_root_string() const;
String fix_path(String p_path) const;
- bool next_is_dir;
template <class T>
static DirAccess *_create_builtin() {
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index fd3c6f8806..b962f61e1f 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -254,8 +254,8 @@ class CharBuffer {
Vector<char> vector;
char stack_buffer[256];
- char *buffer;
- int capacity;
+ char *buffer = nullptr;
+ int capacity = 0;
int written = 0;
bool grow() {
diff --git a/core/templates/hash_map.h b/core/templates/hash_map.h
index f6b889015a..e1ba381595 100644
--- a/core/templates/hash_map.h
+++ b/core/templates/hash_map.h
@@ -73,7 +73,7 @@ public:
private:
friend class HashMap;
- uint32_t hash;
+ uint32_t hash = 0;
Element *next = nullptr;
Element() {}
Pair pair;
diff --git a/core/templates/list.h b/core/templates/list.h
index d745066e4c..8e14aaa90d 100644
--- a/core/templates/list.h
+++ b/core/templates/list.h
@@ -137,9 +137,9 @@ public:
private:
struct _Data {
- Element *first;
- Element *last;
- int size_cache;
+ Element *first = nullptr;
+ Element *last = nullptr;
+ int size_cache = 0;
bool erase(const Element *p_I) {
ERR_FAIL_COND_V(!p_I, false);
diff --git a/core/templates/safe_refcount.h b/core/templates/safe_refcount.h
index dc4e62354a..6b08b876f8 100644
--- a/core/templates/safe_refcount.h
+++ b/core/templates/safe_refcount.h
@@ -165,7 +165,7 @@ uint64_t atomic_exchange_if_greater(volatile uint64_t *pw, volatile uint64_t val
#endif
struct SafeRefCount {
- uint32_t count;
+ uint32_t count = 0;
public:
// destroy() is called when weak_count_ drops to zero.
diff --git a/core/templates/set.h b/core/templates/set.h
index 1bc0a3f41e..d0ac71a710 100644
--- a/core/templates/set.h
+++ b/core/templates/set.h
@@ -80,7 +80,7 @@ public:
private:
struct _Data {
Element *_root = nullptr;
- Element *_nil;
+ Element *_nil = nullptr;
int size_cache = 0;
_FORCE_INLINE_ _Data() {
diff --git a/core/templates/thread_work_pool.h b/core/templates/thread_work_pool.h
index 661060aa3f..e083cdcb24 100644
--- a/core/templates/thread_work_pool.h
+++ b/core/templates/thread_work_pool.h
@@ -41,8 +41,8 @@ class ThreadWorkPool {
std::atomic<uint32_t> index;
struct BaseWork {
- std::atomic<uint32_t> *index;
- uint32_t max_elements;
+ std::atomic<uint32_t> *index = nullptr;
+ uint32_t max_elements = 0;
virtual void work() = 0;
virtual ~BaseWork() = default;
};
diff --git a/core/variant/array.cpp b/core/variant/array.cpp
index 79bc01b89c..5043868b1d 100644
--- a/core/variant/array.cpp
+++ b/core/variant/array.cpp
@@ -371,7 +371,7 @@ void Array::sort() {
}
struct _ArrayVariantSortCustom {
- Object *obj;
+ Object *obj = nullptr;
StringName func;
_FORCE_INLINE_ bool operator()(const Variant &p_l, const Variant &p_r) const {
diff --git a/core/variant/binder_common.h b/core/variant/binder_common.h
index 2e38ce5b06..e950709526 100644
--- a/core/variant/binder_common.h
+++ b/core/variant/binder_common.h
@@ -63,8 +63,6 @@ struct VariantCaster<const T &> {
}
};
-#ifdef PTRCALL_ENABLED
-
#define VARIANT_ENUM_CAST(m_enum) \
MAKE_ENUM_TYPE_INFO(m_enum) \
template <> \
@@ -83,19 +81,6 @@ struct VariantCaster<const T &> {
} \
};
-#else
-
-#define VARIANT_ENUM_CAST(m_enum) \
- MAKE_ENUM_TYPE_INFO(m_enum) \
- template <> \
- struct VariantCaster<m_enum> { \
- static _FORCE_INLINE_ m_enum cast(const Variant &p_variant) { \
- return (m_enum)p_variant.operator int(); \
- } \
- };
-
-#endif
-
// Object enum casts must go here
VARIANT_ENUM_CAST(Object::ConnectFlags);
@@ -118,7 +103,7 @@ struct VariantCaster<char32_t> {
return (char32_t)p_variant.operator int();
}
};
-#ifdef PTRCALL_ENABLED
+
template <>
struct PtrToArg<char32_t> {
_FORCE_INLINE_ static char32_t convert(const void *p_ptr) {
@@ -128,7 +113,6 @@ struct PtrToArg<char32_t> {
*(int *)p_ptr = p_val;
}
};
-#endif
template <typename T>
struct VariantObjectClassChecker {
@@ -228,8 +212,6 @@ void call_with_variant_argsc_helper(T *p_instance, void (T::*p_method)(P...) con
(void)(p_args); //avoid warning
}
-#ifdef PTRCALL_ENABLED
-
template <class T, class... P, size_t... Is>
void call_with_ptr_args_helper(T *p_instance, void (T::*p_method)(P...), const void **p_args, IndexSequence<Is...>) {
(p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...);
@@ -255,8 +237,6 @@ void call_with_ptr_args_static_retc_helper(T *p_instance, R (*p_method)(T *, P..
PtrToArg<R>::encode(p_method(p_instance, PtrToArg<P>::convert(p_args[Is])...), r_ret);
}
-#endif // PTRCALL_ENABLED
-
template <class T, class... P, size_t... Is>
void call_with_validated_variant_args_helper(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, IndexSequence<Is...>) {
(p_instance->*p_method)((VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...);
@@ -450,8 +430,6 @@ void call_with_variant_args_retc_dv(T *p_instance, R (T::*p_method)(P...) const,
call_with_variant_args_retc_helper(p_instance, p_method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
}
-#ifdef PTRCALL_ENABLED
-
template <class T, class... P>
void call_with_ptr_args(T *p_instance, void (T::*p_method)(P...), const void **p_args) {
call_with_ptr_args_helper<T, P...>(p_instance, p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
@@ -477,8 +455,6 @@ void call_with_ptr_args_static_retc(T *p_instance, R (*p_method)(T *, P...), con
call_with_ptr_args_static_retc_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
}
-#endif // PTRCALL_ENABLED
-
template <class T, class... P>
void call_with_validated_variant_args(Variant *base, void (T::*p_method)(P...), const Variant **p_args) {
call_with_validated_variant_args_helper<T, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
diff --git a/core/variant/callable.h b/core/variant/callable.h
index 40621fbde3..9334ae3581 100644
--- a/core/variant/callable.h
+++ b/core/variant/callable.h
@@ -62,9 +62,9 @@ public:
CALL_ERROR_TOO_FEW_ARGUMENTS, // expected is number of arguments
CALL_ERROR_INSTANCE_IS_NULL,
};
- Error error;
- int argument;
- int expected;
+ Error error = Error::CALL_OK;
+ int argument = 0;
+ int expected = 0;
};
void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, CallError &r_call_error) const;
diff --git a/core/variant/method_ptrcall.h b/core/variant/method_ptrcall.h
index 936de145f8..40fa3543dc 100644
--- a/core/variant/method_ptrcall.h
+++ b/core/variant/method_ptrcall.h
@@ -36,11 +36,8 @@
#include "core/typedefs.h"
#include "core/variant/variant.h"
-#ifdef PTRCALL_ENABLED
-
template <class T>
-struct PtrToArg {
-};
+struct PtrToArg {};
#define MAKE_PTRARG(m_type) \
template <> \
@@ -146,7 +143,7 @@ MAKE_PTRARG(PackedVector3Array);
MAKE_PTRARG(PackedColorArray);
MAKE_PTRARG_BY_REFERENCE(Variant);
-//this is for Object
+// This is for Object.
template <class T>
struct PtrToArg<T *> {
@@ -170,7 +167,7 @@ struct PtrToArg<const T *> {
}
};
-//this is for ObjectID
+// This is for ObjectID.
template <>
struct PtrToArg<ObjectID> {
@@ -183,7 +180,7 @@ struct PtrToArg<ObjectID> {
}
};
-//this is for the special cases used by Variant
+// This is for the special cases used by Variant.
#define MAKE_VECARG(m_type) \
template <> \
@@ -274,18 +271,11 @@ struct PtrToArg<ObjectID> {
return ret; \
} \
}
-/*
-MAKE_VECARG(String);
-MAKE_VECARG(uint8_t);
-MAKE_VECARG(int);
-MAKE_VECARG(float);
-MAKE_VECARG(Vector2);
-MAKE_VECARG(Vector3);
-MAKE_VECARG(Color);
-*/
+
MAKE_VECARG_ALT(String, StringName);
-//for stuff that gets converted to Array vectors
+// For stuff that gets converted to Array vectors.
+
#define MAKE_VECARR(m_type) \
template <> \
struct PtrToArg<Vector<m_type>> { \
@@ -429,6 +419,7 @@ struct PtrToArg<Vector<Face3>> {
}
}
};
+
template <>
struct PtrToArg<const Vector<Face3> &> {
_FORCE_INLINE_ static Vector<Face3> convert(const void *p_ptr) {
@@ -450,4 +441,3 @@ struct PtrToArg<const Vector<Face3> &> {
};
#endif // METHOD_PTRCALL_H
-#endif
diff --git a/core/variant/typed_array.h b/core/variant/typed_array.h
index ff42cb687e..2f11f22ff8 100644
--- a/core/variant/typed_array.h
+++ b/core/variant/typed_array.h
@@ -120,8 +120,6 @@ MAKE_TYPED_ARRAY(Vector<Vector2>, Variant::PACKED_VECTOR2_ARRAY)
MAKE_TYPED_ARRAY(Vector<Vector3>, Variant::PACKED_VECTOR3_ARRAY)
MAKE_TYPED_ARRAY(Vector<Color>, Variant::PACKED_COLOR_ARRAY)
-#ifdef PTRCALL_ENABLED
-
template <class T>
struct PtrToArg<TypedArray<T>> {
_FORCE_INLINE_ static TypedArray<T> convert(const void *p_ptr) {
@@ -140,8 +138,6 @@ struct PtrToArg<const TypedArray<T> &> {
}
};
-#endif // PTRCALL_ENABLED
-
#ifdef DEBUG_METHODS_ENABLED
template <class T>
diff --git a/core/variant/variant.h b/core/variant/variant.h
index 093daf0c6f..d87078b5da 100644
--- a/core/variant/variant.h
+++ b/core/variant/variant.h
@@ -128,7 +128,7 @@ private:
struct ObjData {
ObjectID id;
- Object *obj;
+ Object *obj = nullptr;
};
/* array helpers */
@@ -370,7 +370,6 @@ public:
#ifdef NEED_LONG_INT
Variant(signed long p_long); // real one
Variant(unsigned long p_long);
-//Variant(long unsigned int p_long);
#endif
Variant(signed short p_short); // real one
Variant(unsigned short p_short);
@@ -471,10 +470,8 @@ public:
static Variant::Type get_operator_return_type(Operator p_operator, Type p_type_a, Type p_type_b);
typedef void (*ValidatedOperatorEvaluator)(const Variant *left, const Variant *right, Variant *r_ret);
static ValidatedOperatorEvaluator get_validated_operator_evaluator(Operator p_operator, Type p_type_a, Type p_type_b);
-#ifdef PTRCALL_ENABLED
typedef void (*PTROperatorEvaluator)(const void *left, const void *right, void *r_ret);
static PTROperatorEvaluator get_ptr_operator_evaluator(Operator p_operator, Type p_type_a, Type p_type_b);
-#endif
void zero();
Variant duplicate(bool deep = false) const;
diff --git a/core/variant/variant_internal.h b/core/variant/variant_internal.h
index 3c3be44ef7..bf7e46eed7 100644
--- a/core/variant/variant_internal.h
+++ b/core/variant/variant_internal.h
@@ -38,7 +38,82 @@
class VariantInternal {
public:
// Set type.
- _FORCE_INLINE_ static void initialize(Variant *v, Variant::Type p_type) { v->type = p_type; }
+ _FORCE_INLINE_ static void initialize(Variant *v, Variant::Type p_type) {
+ v->clear();
+ v->type = p_type;
+
+ switch (p_type) {
+ case Variant::AABB:
+ init_aabb(v);
+ break;
+ case Variant::TRANSFORM2D:
+ init_transform2d(v);
+ break;
+ case Variant::TRANSFORM:
+ init_transform(v);
+ break;
+ case Variant::STRING:
+ init_string(v);
+ break;
+ case Variant::STRING_NAME:
+ init_string_name(v);
+ break;
+ case Variant::NODE_PATH:
+ init_node_path(v);
+ break;
+ case Variant::CALLABLE:
+ init_callable(v);
+ break;
+ case Variant::SIGNAL:
+ init_signal(v);
+ break;
+ case Variant::DICTIONARY:
+ init_dictionary(v);
+ break;
+ case Variant::ARRAY:
+ init_array(v);
+ break;
+ case Variant::PACKED_BYTE_ARRAY:
+ init_byte_array(v);
+ break;
+ case Variant::PACKED_INT32_ARRAY:
+ init_int32_array(v);
+ break;
+ case Variant::PACKED_INT64_ARRAY:
+ init_int64_array(v);
+ break;
+ case Variant::PACKED_FLOAT32_ARRAY:
+ init_float32_array(v);
+ break;
+ case Variant::PACKED_FLOAT64_ARRAY:
+ init_float64_array(v);
+ break;
+ case Variant::PACKED_STRING_ARRAY:
+ init_string_array(v);
+ break;
+ case Variant::PACKED_VECTOR2_ARRAY:
+ init_vector2_array(v);
+ break;
+ case Variant::PACKED_VECTOR3_ARRAY:
+ init_vector3_array(v);
+ break;
+ case Variant::PACKED_COLOR_ARRAY:
+ init_color_array(v);
+ break;
+ default:
+ break;
+ }
+ }
+
+ _FORCE_INLINE_ static void set_object(Variant *v, Object *obj) {
+ if (obj) {
+ v->_get_obj().obj = obj;
+ v->_get_obj().id = obj->get_instance_id();
+ } else {
+ v->_get_obj().obj = nullptr;
+ v->_get_obj().id = ObjectID();
+ }
+ }
// Atomic types.
_FORCE_INLINE_ static bool *get_bool(Variant *v) { return &v->_data._bool; }
@@ -216,6 +291,162 @@ public:
v->_get_obj().obj = nullptr;
v->_get_obj().id = ObjectID();
}
+
+ _FORCE_INLINE_ static void *get_opaque_pointer(Variant *v) {
+ switch (v->type) {
+ case Variant::NIL:
+ return nullptr;
+ case Variant::BOOL:
+ return get_bool(v);
+ case Variant::INT:
+ return get_int(v);
+ case Variant::FLOAT:
+ return get_float(v);
+ case Variant::STRING:
+ return get_string(v);
+ case Variant::VECTOR2:
+ return get_vector2(v);
+ case Variant::VECTOR2I:
+ return get_vector2i(v);
+ case Variant::VECTOR3:
+ return get_vector3(v);
+ case Variant::VECTOR3I:
+ return get_vector3i(v);
+ case Variant::RECT2:
+ return get_rect2(v);
+ case Variant::RECT2I:
+ return get_rect2i(v);
+ case Variant::TRANSFORM:
+ return get_transform(v);
+ case Variant::TRANSFORM2D:
+ return get_transform2d(v);
+ case Variant::QUAT:
+ return get_quat(v);
+ case Variant::PLANE:
+ return get_plane(v);
+ case Variant::BASIS:
+ return get_basis(v);
+ case Variant::AABB:
+ return get_aabb(v);
+ case Variant::COLOR:
+ return get_color(v);
+ case Variant::STRING_NAME:
+ return get_string_name(v);
+ case Variant::NODE_PATH:
+ return get_node_path(v);
+ case Variant::RID:
+ return get_rid(v);
+ case Variant::CALLABLE:
+ return get_callable(v);
+ case Variant::SIGNAL:
+ return get_signal(v);
+ case Variant::DICTIONARY:
+ return get_dictionary(v);
+ case Variant::ARRAY:
+ return get_array(v);
+ case Variant::PACKED_BYTE_ARRAY:
+ return get_byte_array(v);
+ case Variant::PACKED_INT32_ARRAY:
+ return get_int32_array(v);
+ case Variant::PACKED_INT64_ARRAY:
+ return get_int64_array(v);
+ case Variant::PACKED_FLOAT32_ARRAY:
+ return get_float32_array(v);
+ case Variant::PACKED_FLOAT64_ARRAY:
+ return get_float64_array(v);
+ case Variant::PACKED_STRING_ARRAY:
+ return get_string_array(v);
+ case Variant::PACKED_VECTOR2_ARRAY:
+ return get_vector2_array(v);
+ case Variant::PACKED_VECTOR3_ARRAY:
+ return get_vector3_array(v);
+ case Variant::PACKED_COLOR_ARRAY:
+ return get_color_array(v);
+ case Variant::OBJECT:
+ return v->_get_obj().obj;
+ case Variant::VARIANT_MAX:
+ ERR_FAIL_V(nullptr);
+ }
+ ERR_FAIL_V(nullptr);
+ }
+
+ _FORCE_INLINE_ static const void *get_opaque_pointer(const Variant *v) {
+ switch (v->type) {
+ case Variant::NIL:
+ return nullptr;
+ case Variant::BOOL:
+ return get_bool(v);
+ case Variant::INT:
+ return get_int(v);
+ case Variant::FLOAT:
+ return get_float(v);
+ case Variant::STRING:
+ return get_string(v);
+ case Variant::VECTOR2:
+ return get_vector2(v);
+ case Variant::VECTOR2I:
+ return get_vector2i(v);
+ case Variant::VECTOR3:
+ return get_vector3(v);
+ case Variant::VECTOR3I:
+ return get_vector3i(v);
+ case Variant::RECT2:
+ return get_rect2(v);
+ case Variant::RECT2I:
+ return get_rect2i(v);
+ case Variant::TRANSFORM:
+ return get_transform(v);
+ case Variant::TRANSFORM2D:
+ return get_transform2d(v);
+ case Variant::QUAT:
+ return get_quat(v);
+ case Variant::PLANE:
+ return get_plane(v);
+ case Variant::BASIS:
+ return get_basis(v);
+ case Variant::AABB:
+ return get_aabb(v);
+ case Variant::COLOR:
+ return get_color(v);
+ case Variant::STRING_NAME:
+ return get_string_name(v);
+ case Variant::NODE_PATH:
+ return get_node_path(v);
+ case Variant::RID:
+ return get_rid(v);
+ case Variant::CALLABLE:
+ return get_callable(v);
+ case Variant::SIGNAL:
+ return get_signal(v);
+ case Variant::DICTIONARY:
+ return get_dictionary(v);
+ case Variant::ARRAY:
+ return get_array(v);
+ case Variant::PACKED_BYTE_ARRAY:
+ return get_byte_array(v);
+ case Variant::PACKED_INT32_ARRAY:
+ return get_int32_array(v);
+ case Variant::PACKED_INT64_ARRAY:
+ return get_int64_array(v);
+ case Variant::PACKED_FLOAT32_ARRAY:
+ return get_float32_array(v);
+ case Variant::PACKED_FLOAT64_ARRAY:
+ return get_float64_array(v);
+ case Variant::PACKED_STRING_ARRAY:
+ return get_string_array(v);
+ case Variant::PACKED_VECTOR2_ARRAY:
+ return get_vector2_array(v);
+ case Variant::PACKED_VECTOR3_ARRAY:
+ return get_vector3_array(v);
+ case Variant::PACKED_COLOR_ARRAY:
+ return get_color_array(v);
+ case Variant::OBJECT:
+ return v->_get_obj().obj;
+ case Variant::VARIANT_MAX:
+ ERR_FAIL_V(nullptr);
+ }
+ ERR_FAIL_V(nullptr);
+ }
};
template <class T>
diff --git a/core/variant/variant_op.cpp b/core/variant/variant_op.cpp
index 74ecbfb8d1..07b024ecb4 100644
--- a/core/variant/variant_op.cpp
+++ b/core/variant/variant_op.cpp
@@ -47,11 +47,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) + *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) + PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -68,11 +66,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) - *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) - PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -89,11 +85,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) * *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) * PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -110,11 +104,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = VariantGetInternalPtr<A>::get_ptr(left)->xform(*VariantGetInternalPtr<B>::get_ptr(right));
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left).xform(PtrToArg<B>::convert(right)), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -131,11 +123,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = VariantGetInternalPtr<B>::get_ptr(right)->xform_inv(*VariantGetInternalPtr<A>::get_ptr(left));
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<B>::convert(right).xform_inv(PtrToArg<A>::convert(left)), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -152,11 +142,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) / *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) / PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -178,11 +166,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) / *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) / PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -199,11 +185,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) % *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) % PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -225,11 +209,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) % *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) % PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -245,11 +227,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = -*VariantGetInternalPtr<A>::get_ptr(left);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(-PtrToArg<A>::convert(left), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -265,11 +245,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -286,11 +264,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) << *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) << PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -307,11 +283,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) >> *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) >> PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -328,11 +302,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) | *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) | PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -348,11 +320,9 @@ public:
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) & *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) & PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -369,11 +339,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) ^ *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(PtrToArg<A>::convert(left) ^ PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -389,11 +357,9 @@ public:
VariantTypeChanger<R>::change(r_ret);
*VariantGetInternalPtr<R>::get_ptr(r_ret) = ~*VariantGetInternalPtr<A>::get_ptr(left);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<R>::encode(~PtrToArg<A>::convert(left), r_ret);
}
-#endif
static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; }
};
@@ -410,14 +376,12 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) == *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<A>::convert(left) == PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
-//equalobject
+
class OperatorEvaluatorEqualObject {
public:
static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
@@ -432,11 +396,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = a == b;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) == PtrToArg<Object *>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -452,11 +414,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = a == nullptr;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) == nullptr, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -472,11 +432,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = nullptr == b;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(nullptr == PtrToArg<Object *>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -493,11 +451,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) != *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<A>::convert(left) != PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -515,11 +471,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = a != b;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) != PtrToArg<Object *>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -535,11 +489,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = a != nullptr;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) != nullptr, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -555,11 +507,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = nullptr != b;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(nullptr != PtrToArg<Object *>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -576,11 +526,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) < *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<A>::convert(left) < PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -597,11 +545,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) <= *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<A>::convert(left) <= PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -618,11 +564,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) > *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<A>::convert(left) > PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -639,11 +583,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) >= *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<A>::convert(left) >= PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -660,12 +602,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) && *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<A>::convert(left) && PtrToArg<B>::convert(right), r_ret);
}
-#endif
-
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -682,11 +621,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) || *VariantGetInternalPtr<B>::get_ptr(right);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<A>::convert(left) || PtrToArg<B>::convert(right), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -697,7 +634,6 @@ public:
_FORCE_INLINE_ static bool xor_op(const A &a, const B &b) {
return ((a) || (b)) && !((a) && (b));
}
-
static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left);
const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right);
@@ -708,12 +644,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = xor_op(*VariantGetInternalPtr<A>::get_ptr(left), *VariantGetInternalPtr<B>::get_ptr(right));
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(xor_op(PtrToArg<A>::convert(left), PtrToArg<B>::convert(right)), r_ret);
}
-#endif
-
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -729,11 +662,9 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<A>::get_ptr(left);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(!PtrToArg<A>::convert(left));
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -764,14 +695,11 @@ public:
VariantTypeChanger<Array>::change(r_ret);
_add_arrays(*VariantGetInternalPtr<Array>::get_ptr(r_ret), *VariantGetInternalPtr<Array>::get_ptr(left), *VariantGetInternalPtr<Array>::get_ptr(right));
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
Array ret;
_add_arrays(ret, PtrToArg<Array>::convert(left), PtrToArg<Array>::convert(right));
PtrToArg<Array>::encode(ret, r_ret);
}
-#endif
-
static Variant::Type get_return_type() { return Variant::ARRAY; }
};
@@ -791,14 +719,11 @@ public:
*VariantGetInternalPtr<Vector<T>>::get_ptr(r_ret) = *VariantGetInternalPtr<Vector<T>>::get_ptr(left);
VariantGetInternalPtr<Vector<T>>::get_ptr(r_ret)->append_array(*VariantGetInternalPtr<Vector<T>>::get_ptr(right));
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
Vector<T> sum = PtrToArg<Vector<T>>::convert(left);
sum.append_array(PtrToArg<Vector<T>>::convert(right));
PtrToArg<Vector<T>>::encode(sum, r_ret);
}
-#endif
-
static Variant::Type get_return_type() { return GetTypeInfo<Vector<T>>::VARIANT_TYPE; }
};
@@ -819,16 +744,13 @@ public:
*r_ret = do_mod(a, &r_valid);
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<String>::change(r_ret);
*VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), nullptr);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), nullptr), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::STRING; }
};
@@ -846,16 +768,13 @@ public:
*r_ret = do_mod(a, *VariantGetInternalPtr<Array>::get_ptr(&p_right), &r_valid);
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<String>::change(r_ret);
*VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), *VariantGetInternalPtr<Array>::get_ptr(right), nullptr);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), PtrToArg<Array>::convert(right), nullptr), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::STRING; }
};
@@ -876,16 +795,13 @@ public:
*r_ret = do_mod(a, p_right.get_validated_object(), &r_valid);
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<String>::change(r_ret);
*VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), right->get_validated_object(), nullptr);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), PtrToArg<Object *>::convert(right), nullptr), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::STRING; }
};
@@ -906,16 +822,13 @@ public:
*r_ret = do_mod(a, *VariantGetInternalPtr<T>::get_ptr(&p_right), &r_valid);
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<String>::change(r_ret);
*VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), *VariantGetInternalPtr<T>::get_ptr(right), nullptr);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), PtrToArg<T>::convert(right), nullptr), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::STRING; }
};
@@ -926,16 +839,13 @@ public:
*r_ret = true;
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = true;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(true, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -946,16 +856,13 @@ public:
*r_ret = false;
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = false;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(false, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -964,9 +871,11 @@ public:
_FORCE_INLINE_ static bool _operate_or(bool p_left, bool p_right) {
return p_left || p_right;
}
+
_FORCE_INLINE_ static bool _operate_and(bool p_left, bool p_right) {
return p_left && p_right;
}
+
_FORCE_INLINE_ static bool _operate_xor(bool p_left, bool p_right) {
return (p_left || p_right) && !(p_left && p_right);
}
@@ -991,29 +900,6 @@ _FORCE_INLINE_ static bool _operate_get_object(const Variant *p_ptr) {
return p_ptr->get_validated_object() != nullptr;
}
-#ifndef PTRCALL_ENABLED
-
-#define OP_EVALUATOR(m_class_name, m_left, m_right, m_op) \
- class m_class_name { \
- public: \
- static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { \
- *r_ret = m_op(_operate_get_##m_left(&p_left), _operate_get_##m_right(&p_right)); \
- r_valid = true; \
- } \
- \
- static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { \
- VariantTypeChanger<bool>::change(r_ret); \
- *VariantGetInternalPtr<bool>::get_ptr(r_ret) = m_op(_operate_get_##m_left(left), _operate_get_##m_right(right)); \
- } \
- \
- static Variant::Type \
- get_return_type() { \
- return Variant::BOOL; \
- } \
- };
-
-#else
-
_FORCE_INLINE_ static bool _operate_get_ptr_nil(const void *p_ptr) {
return false;
}
@@ -1056,11 +942,9 @@ _FORCE_INLINE_ static bool _operate_get_ptr_object(const void *p_ptr) {
} \
};
-#endif
-
// OR
-//nil
+// nil
OP_EVALUATOR(OperatorEvaluatorNilXBoolOr, nil, bool, _operate_or)
OP_EVALUATOR(OperatorEvaluatorBoolXNilOr, bool, nil, _operate_or)
@@ -1073,7 +957,7 @@ OP_EVALUATOR(OperatorEvaluatorFloatXNilOr, float, nil, _operate_or)
OP_EVALUATOR(OperatorEvaluatorObjectXNilOr, object, nil, _operate_or)
OP_EVALUATOR(OperatorEvaluatorNilXObjectOr, nil, object, _operate_or)
-//bool
+// bool
OP_EVALUATOR(OperatorEvaluatorBoolXBoolOr, bool, bool, _operate_or)
OP_EVALUATOR(OperatorEvaluatorBoolXIntOr, bool, int, _operate_or)
@@ -1085,8 +969,7 @@ OP_EVALUATOR(OperatorEvaluatorFloatXBoolOr, float, bool, _operate_or)
OP_EVALUATOR(OperatorEvaluatorBoolXObjectOr, bool, object, _operate_or)
OP_EVALUATOR(OperatorEvaluatorObjectXBoolOr, object, bool, _operate_or)
-//int
-
+// int
OP_EVALUATOR(OperatorEvaluatorIntXIntOr, int, int, _operate_or)
OP_EVALUATOR(OperatorEvaluatorIntXFloatOr, int, float, _operate_or)
@@ -1095,20 +978,18 @@ OP_EVALUATOR(OperatorEvaluatorFloatXIntOr, float, int, _operate_or)
OP_EVALUATOR(OperatorEvaluatorIntXObjectOr, int, object, _operate_or)
OP_EVALUATOR(OperatorEvaluatorObjectXIntOr, object, int, _operate_or)
-//float
-
+// float
OP_EVALUATOR(OperatorEvaluatorFloatXFloatOr, float, float, _operate_or)
OP_EVALUATOR(OperatorEvaluatorFloatXObjectOr, float, object, _operate_or)
OP_EVALUATOR(OperatorEvaluatorObjectXFloatOr, object, float, _operate_or)
-//object
-
+// object
OP_EVALUATOR(OperatorEvaluatorObjectXObjectOr, object, object, _operate_or)
// AND
-//nil
+// nil
OP_EVALUATOR(OperatorEvaluatorNilXBoolAnd, nil, bool, _operate_and)
OP_EVALUATOR(OperatorEvaluatorBoolXNilAnd, bool, nil, _operate_and)
@@ -1121,7 +1002,7 @@ OP_EVALUATOR(OperatorEvaluatorFloatXNilAnd, float, nil, _operate_and)
OP_EVALUATOR(OperatorEvaluatorObjectXNilAnd, object, nil, _operate_and)
OP_EVALUATOR(OperatorEvaluatorNilXObjectAnd, nil, object, _operate_and)
-//bool
+// bool
OP_EVALUATOR(OperatorEvaluatorBoolXBoolAnd, bool, bool, _operate_and)
OP_EVALUATOR(OperatorEvaluatorBoolXIntAnd, bool, int, _operate_and)
@@ -1133,8 +1014,7 @@ OP_EVALUATOR(OperatorEvaluatorFloatXBoolAnd, float, bool, _operate_and)
OP_EVALUATOR(OperatorEvaluatorBoolXObjectAnd, bool, object, _operate_and)
OP_EVALUATOR(OperatorEvaluatorObjectXBoolAnd, object, bool, _operate_and)
-//int
-
+// int
OP_EVALUATOR(OperatorEvaluatorIntXIntAnd, int, int, _operate_and)
OP_EVALUATOR(OperatorEvaluatorIntXFloatAnd, int, float, _operate_and)
@@ -1143,20 +1023,18 @@ OP_EVALUATOR(OperatorEvaluatorFloatXIntAnd, float, int, _operate_and)
OP_EVALUATOR(OperatorEvaluatorIntXObjectAnd, int, object, _operate_and)
OP_EVALUATOR(OperatorEvaluatorObjectXIntAnd, object, int, _operate_and)
-//float
-
+// float
OP_EVALUATOR(OperatorEvaluatorFloatXFloatAnd, float, float, _operate_and)
OP_EVALUATOR(OperatorEvaluatorFloatXObjectAnd, float, object, _operate_and)
OP_EVALUATOR(OperatorEvaluatorObjectXFloatAnd, object, float, _operate_and)
-//object
-
+// object
OP_EVALUATOR(OperatorEvaluatorObjectXObjectAnd, object, object, _operate_and)
// XOR
-//nil
+// nil
OP_EVALUATOR(OperatorEvaluatorNilXBoolXor, nil, bool, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorBoolXNilXor, bool, nil, _operate_xor)
@@ -1169,7 +1047,7 @@ OP_EVALUATOR(OperatorEvaluatorFloatXNilXor, float, nil, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorObjectXNilXor, object, nil, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorNilXObjectXor, nil, object, _operate_xor)
-//bool
+// bool
OP_EVALUATOR(OperatorEvaluatorBoolXBoolXor, bool, bool, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorBoolXIntXor, bool, int, _operate_xor)
@@ -1181,8 +1059,7 @@ OP_EVALUATOR(OperatorEvaluatorFloatXBoolXor, float, bool, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorBoolXObjectXor, bool, object, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorObjectXBoolXor, object, bool, _operate_xor)
-//int
-
+// int
OP_EVALUATOR(OperatorEvaluatorIntXIntXor, int, int, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorIntXFloatXor, int, float, _operate_xor)
@@ -1191,15 +1068,13 @@ OP_EVALUATOR(OperatorEvaluatorFloatXIntXor, float, int, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorIntXObjectXor, int, object, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorObjectXIntXor, object, int, _operate_xor)
-//float
-
+// float
OP_EVALUATOR(OperatorEvaluatorFloatXFloatXor, float, float, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorFloatXObjectXor, float, object, _operate_xor)
OP_EVALUATOR(OperatorEvaluatorObjectXFloatXor, object, float, _operate_xor)
-//object
-
+// object
OP_EVALUATOR(OperatorEvaluatorObjectXObjectXor, object, object, _operate_xor)
class OperatorEvaluatorNotBool {
@@ -1208,17 +1083,13 @@ public:
*r_ret = !*VariantGetInternalPtr<bool>::get_ptr(&p_left);
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<bool>::get_ptr(left);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(!PtrToArg<bool>::convert(left), r_ret);
}
-#endif
-
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1228,17 +1099,13 @@ public:
*r_ret = !*VariantGetInternalPtr<int64_t>::get_ptr(&p_left);
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<int64_t>::get_ptr(left);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(!PtrToArg<int64_t>::convert(left), r_ret);
}
-#endif
-
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1248,17 +1115,13 @@ public:
*r_ret = !*VariantGetInternalPtr<double>::get_ptr(&p_left);
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<double>::get_ptr(left);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(!PtrToArg<double>::convert(left), r_ret);
}
-#endif
-
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1268,17 +1131,13 @@ public:
*r_ret = p_left.get_validated_object() == nullptr;
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = left->get_validated_object() == nullptr;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) == nullptr, r_ret);
}
-#endif
-
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1293,18 +1152,15 @@ public:
*r_ret = str_b.find(str_a) != -1;
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
const String &str_a = *VariantGetInternalPtr<String>::get_ptr(left);
const String &str_b = *VariantGetInternalPtr<String>::get_ptr(right);
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = str_b.find(str_a) != -1;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<String>::convert(right).find(PtrToArg<String>::convert(left)) != -1, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1318,18 +1174,15 @@ public:
*r_ret = b.find(a) != -1;
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
const A &a = *VariantGetInternalPtr<A>::get_ptr(left);
const B &b = *VariantGetInternalPtr<B>::get_ptr(right);
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.find(a) != -1;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<B>::convert(right).find(PtrToArg<A>::convert(left)) != -1, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1340,17 +1193,14 @@ public:
*r_ret = b.find(Variant()) != -1;
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
const Array &b = *VariantGetInternalPtr<Array>::get_ptr(right);
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.find(Variant()) != -1;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Array>::convert(right).find(Variant()) != -1, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1361,17 +1211,14 @@ public:
*r_ret = b.find(p_left) != -1;
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
const Array &b = *VariantGetInternalPtr<Array>::get_ptr(right);
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.find(*left) != -1;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Array>::convert(right).find(PtrToArg<Object *>::convert(left)) != -1, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1385,18 +1232,15 @@ public:
*r_ret = b.has(a);
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(right);
const A &a = *VariantGetInternalPtr<A>::get_ptr(left);
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.has(a);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Dictionary>::convert(right).has(PtrToArg<A>::convert(left)), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1408,17 +1252,14 @@ public:
*r_ret = b.has(Variant());
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(right);
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.has(Variant());
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Dictionary>::convert(right).has(Variant()), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1430,17 +1271,14 @@ public:
*r_ret = b.has(p_left);
r_valid = true;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(right);
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.has(*left);
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
PtrToArg<bool>::encode(PtrToArg<Dictionary>::convert(right).has(PtrToArg<Object *>::convert(left)), r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1459,7 +1297,6 @@ public:
b->get(a, &r_valid);
*r_ret = r_valid;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
Object *l = right->get_validated_object();
ERR_FAIL_COND(l == nullptr);
@@ -1470,13 +1307,11 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = valid;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
bool valid;
PtrToArg<Object *>::convert(right)->get(PtrToArg<String>::convert(left), &valid);
PtrToArg<bool>::encode(valid, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1495,7 +1330,6 @@ public:
b->get(a, &r_valid);
*r_ret = r_valid;
}
-
static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
Object *l = right->get_validated_object();
ERR_FAIL_COND(l == nullptr);
@@ -1506,13 +1340,11 @@ public:
VariantTypeChanger<bool>::change(r_ret);
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = valid;
}
-#ifdef PTRCALL_ENABLED
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
bool valid;
PtrToArg<Object *>::convert(right)->get(PtrToArg<StringName>::convert(left), &valid);
PtrToArg<bool>::encode(valid, r_ret);
}
-#endif
static Variant::Type get_return_type() { return Variant::BOOL; }
};
@@ -1521,27 +1353,21 @@ typedef void (*VariantEvaluatorFunction)(const Variant &p_left, const Variant &p
static Variant::Type operator_return_type_table[Variant::OP_MAX][Variant::VARIANT_MAX][Variant::VARIANT_MAX];
static VariantEvaluatorFunction operator_evaluator_table[Variant::OP_MAX][Variant::VARIANT_MAX][Variant::VARIANT_MAX];
static Variant::ValidatedOperatorEvaluator validated_operator_evaluator_table[Variant::OP_MAX][Variant::VARIANT_MAX][Variant::VARIANT_MAX];
-#ifdef PTRCALL_ENABLED
static Variant::PTROperatorEvaluator ptr_operator_evaluator_table[Variant::OP_MAX][Variant::VARIANT_MAX][Variant::VARIANT_MAX];
-#endif
template <class T>
void register_op(Variant::Operator p_op, Variant::Type p_type_a, Variant::Type p_type_b) {
operator_return_type_table[p_op][p_type_a][p_type_b] = T::get_return_type();
operator_evaluator_table[p_op][p_type_a][p_type_b] = T::evaluate;
validated_operator_evaluator_table[p_op][p_type_a][p_type_b] = T::validated_evaluate;
-#ifdef PTRCALL_ENABLED
ptr_operator_evaluator_table[p_op][p_type_a][p_type_b] = T::ptr_evaluate;
-#endif
}
void Variant::_register_variant_operators() {
zeromem(operator_return_type_table, sizeof(operator_return_type_table));
zeromem(operator_evaluator_table, sizeof(operator_evaluator_table));
zeromem(validated_operator_evaluator_table, sizeof(validated_operator_evaluator_table));
-#ifdef PTRCALL_ENABLED
zeromem(ptr_operator_evaluator_table, sizeof(ptr_operator_evaluator_table));
-#endif
register_op<OperatorEvaluatorAdd<int64_t, int64_t, int64_t>>(Variant::OP_ADD, Variant::INT, Variant::INT);
register_op<OperatorEvaluatorAdd<double, int64_t, double>>(Variant::OP_ADD, Variant::INT, Variant::FLOAT);
@@ -1896,7 +1722,7 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_OR, Variant::NIL, Variant::NIL>>(Variant::OP_OR, Variant::NIL, Variant::NIL);
- //OR
+ // OR
register_op<OperatorEvaluatorNilXBoolOr>(Variant::OP_OR, Variant::NIL, Variant::BOOL);
register_op<OperatorEvaluatorBoolXNilOr>(Variant::OP_OR, Variant::BOOL, Variant::NIL);
register_op<OperatorEvaluatorNilXIntOr>(Variant::OP_OR, Variant::NIL, Variant::INT);
@@ -1924,7 +1750,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorFloatXObjectOr>(Variant::OP_OR, Variant::FLOAT, Variant::OBJECT);
register_op<OperatorEvaluatorObjectXFloatOr>(Variant::OP_OR, Variant::OBJECT, Variant::FLOAT);
register_op<OperatorEvaluatorObjectXObjectOr>(Variant::OP_OR, Variant::OBJECT, Variant::OBJECT);
- //AND
+
+ // AND
register_op<OperatorEvaluatorNilXBoolAnd>(Variant::OP_AND, Variant::NIL, Variant::BOOL);
register_op<OperatorEvaluatorBoolXNilAnd>(Variant::OP_AND, Variant::BOOL, Variant::NIL);
register_op<OperatorEvaluatorNilXIntAnd>(Variant::OP_AND, Variant::NIL, Variant::INT);
@@ -1952,7 +1779,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorFloatXObjectAnd>(Variant::OP_AND, Variant::FLOAT, Variant::OBJECT);
register_op<OperatorEvaluatorObjectXFloatAnd>(Variant::OP_AND, Variant::OBJECT, Variant::FLOAT);
register_op<OperatorEvaluatorObjectXObjectAnd>(Variant::OP_AND, Variant::OBJECT, Variant::OBJECT);
- //XOR
+
+ // XOR
register_op<OperatorEvaluatorNilXBoolXor>(Variant::OP_XOR, Variant::NIL, Variant::BOOL);
register_op<OperatorEvaluatorBoolXNilXor>(Variant::OP_XOR, Variant::BOOL, Variant::NIL);
register_op<OperatorEvaluatorNilXIntXor>(Variant::OP_XOR, Variant::NIL, Variant::INT);
@@ -2124,7 +1952,7 @@ Variant::ValidatedOperatorEvaluator Variant::get_validated_operator_evaluator(Op
ERR_FAIL_INDEX_V(p_type_b, Variant::VARIANT_MAX, nullptr);
return validated_operator_evaluator_table[p_operator][p_type_a][p_type_b];
}
-#ifdef PTRCALL_ENABLED
+
Variant::PTROperatorEvaluator Variant::get_ptr_operator_evaluator(Operator p_operator, Type p_type_a, Type p_type_b) {
ERR_FAIL_INDEX_V(p_operator, Variant::OP_MAX, nullptr);
ERR_FAIL_INDEX_V(p_type_a, Variant::VARIANT_MAX, nullptr);
@@ -2132,8 +1960,6 @@ Variant::PTROperatorEvaluator Variant::get_ptr_operator_evaluator(Operator p_ope
return ptr_operator_evaluator_table[p_operator][p_type_a][p_type_b];
}
-#endif
-
static const char *_op_names[Variant::OP_MAX] = {
"==",
"!=",
diff --git a/doc/classes/AudioStreamPlayer3D.xml b/doc/classes/AudioStreamPlayer3D.xml
index aadbc865bb..7a8c4b2cc7 100644
--- a/doc/classes/AudioStreamPlayer3D.xml
+++ b/doc/classes/AudioStreamPlayer3D.xml
@@ -4,7 +4,7 @@
Plays 3D sound in 3D space.
</brief_description>
<description>
- Plays a sound effect with directed sound effects, dampens with distance if needed, generates effect of hearable position in space.
+ Plays a sound effect with directed sound effects, dampens with distance if needed, generates effect of hearable position in space. For greater realism, a low-pass filter is automatically applied to distant sounds. This can be disabled by setting [member attenuation_filter_cutoff_hz] to [code]20500[/code].
By default, audio is heard from the camera position. This can be changed by adding a [Listener3D] node to the scene and enabling it by calling [method Listener3D.make_current] on it.
</description>
<tutorials>
@@ -56,19 +56,19 @@
Areas in which this sound plays.
</member>
<member name="attenuation_filter_cutoff_hz" type="float" setter="set_attenuation_filter_cutoff_hz" getter="get_attenuation_filter_cutoff_hz" default="5000.0">
- Dampens audio above this frequency, in Hz.
+ Dampens audio using a low-pass filter above this frequency, in Hz. To disable the dampening effect entirely, set this to [code]20500[/code] as this frequency is above the human hearing limit.
</member>
<member name="attenuation_filter_db" type="float" setter="set_attenuation_filter_db" getter="get_attenuation_filter_db" default="-24.0">
- Amount how much the filter affects the loudness, in dB.
+ Amount how much the filter affects the loudness, in decibels.
</member>
<member name="attenuation_model" type="int" setter="set_attenuation_model" getter="get_attenuation_model" enum="AudioStreamPlayer3D.AttenuationModel" default="0">
Decides if audio should get quieter with distance linearly, quadratically, logarithmically, or not be affected by distance, effectively disabling attenuation.
</member>
<member name="autoplay" type="bool" setter="set_autoplay" getter="is_autoplay_enabled" default="false">
- If [code]true[/code], audio plays when added to scene tree.
+ If [code]true[/code], audio plays when the AudioStreamPlayer3D node is added to scene tree.
</member>
<member name="bus" type="StringName" setter="set_bus" getter="get_bus" default="@&quot;Master&quot;">
- Bus on which this audio is playing.
+ The bus on which this audio is playing.
</member>
<member name="doppler_tracking" type="int" setter="set_doppler_tracking" getter="get_doppler_tracking" enum="AudioStreamPlayer3D.DopplerTracking" default="0">
Decides in which step the Doppler effect should be calculated.
@@ -80,10 +80,10 @@
If [code]true[/code], the audio should be dampened according to the direction of the sound.
</member>
<member name="emission_angle_filter_attenuation_db" type="float" setter="set_emission_angle_filter_attenuation_db" getter="get_emission_angle_filter_attenuation_db" default="-12.0">
- Dampens audio if camera is outside of [member emission_angle_degrees] and [member emission_angle_enabled] is set by this factor, in dB.
+ Dampens audio if camera is outside of [member emission_angle_degrees] and [member emission_angle_enabled] is set by this factor, in decibels.
</member>
<member name="max_db" type="float" setter="set_max_db" getter="get_max_db" default="3.0">
- Sets the absolute maximum of the soundlevel, in dB.
+ Sets the absolute maximum of the soundlevel, in decibels.
</member>
<member name="max_distance" type="float" setter="set_max_distance" getter="get_max_distance" default="0.0">
Sets the distance from which the [member out_of_range_mode] takes effect. Has no effect if set to 0.
@@ -98,16 +98,16 @@
If [code]true[/code], audio is playing.
</member>
<member name="stream" type="AudioStream" setter="set_stream" getter="get_stream">
- The [AudioStream] object to be played.
+ The [AudioStream] resource to be played.
</member>
<member name="stream_paused" type="bool" setter="set_stream_paused" getter="get_stream_paused" default="false">
- If [code]true[/code], the playback is paused. You can resume it by setting [code]stream_paused[/code] to [code]false[/code].
+ If [code]true[/code], the playback is paused. You can resume it by setting [member stream_paused] to [code]false[/code].
</member>
<member name="unit_db" type="float" setter="set_unit_db" getter="get_unit_db" default="0.0">
- Base sound level unaffected by dampening, in dB.
+ The base sound level unaffected by dampening, in decibels.
</member>
<member name="unit_size" type="float" setter="set_unit_size" getter="get_unit_size" default="1.0">
- Factor for the attenuation effect.
+ The factor for the attenuation effect. Higher values make the sound audible over a larger distance.
</member>
</members>
<signals>
@@ -128,13 +128,13 @@
Logarithmic dampening of loudness according to distance.
</constant>
<constant name="ATTENUATION_DISABLED" value="3" enum="AttenuationModel">
- No dampening of loudness according to distance.
+ No dampening of loudness according to distance. The sound will still be heard positionally, unlike an [AudioStreamPlayer].
</constant>
<constant name="OUT_OF_RANGE_MIX" value="0" enum="OutOfRangeMode">
- Mix this audio in, even when it's out of range.
+ Mix this audio in, even when it's out of range. This increases CPU usage, but keeps the sound playing at the correct position if the camera leaves and enters the [AudioStreamPlayer3D]'s [member max_distance] radius.
</constant>
<constant name="OUT_OF_RANGE_PAUSE" value="1" enum="OutOfRangeMode">
- Pause this audio when it gets out of range.
+ Pause this audio when it gets out of range. This decreases CPU usage, but will cause the sound to restart if the camera leaves and enters the [AudioStreamPlayer3D]'s [member max_distance] radius.
</constant>
<constant name="DOPPLER_TRACKING_DISABLED" value="0" enum="DopplerTracking">
Disables doppler tracking.
diff --git a/doc/classes/EditorNode3DGizmoPlugin.xml b/doc/classes/EditorNode3DGizmoPlugin.xml
index adaaed4f1c..322cff4e43 100644
--- a/doc/classes/EditorNode3DGizmoPlugin.xml
+++ b/doc/classes/EditorNode3DGizmoPlugin.xml
@@ -125,7 +125,7 @@
</return>
<argument index="0" name="name" type="String">
</argument>
- <argument index="1" name="gizmo" type="EditorNode3DGizmo">
+ <argument index="1" name="gizmo" type="EditorNode3DGizmo" default="null">
</argument>
<description>
Gets material from the internal list of materials. If an [EditorNode3DGizmo] is provided, it will try to get the corresponding variant (selected and/or editable).
diff --git a/doc/classes/Image.xml b/doc/classes/Image.xml
index edf27b1660..b4325e822c 100644
--- a/doc/classes/Image.xml
+++ b/doc/classes/Image.xml
@@ -269,16 +269,18 @@
<argument index="1" name="y" type="int">
</argument>
<description>
- Returns the color of the pixel at [code](x, y)[/code]. This is the same as [method get_pixelv], but with two integer arguments instead of a [Vector2] argument.
+ Returns the color of the pixel at [code](x, y)[/code].
+ This is the same as [method get_pixelv], but with two integer arguments instead of a [Vector2i] argument.
</description>
</method>
<method name="get_pixelv" qualifiers="const">
<return type="Color">
</return>
- <argument index="0" name="src" type="Vector2">
+ <argument index="0" name="point" type="Vector2i">
</argument>
<description>
- Returns the color of the pixel at [code]src[/code]. This is the same as [method get_pixel], but with a [Vector2] argument instead of two integer arguments.
+ Returns the color of the pixel at [code]point[/code].
+ This is the same as [method get_pixel], but with a [Vector2i] argument instead of two integer arguments.
</description>
</method>
<method name="get_rect" qualifiers="const">
@@ -475,28 +477,56 @@
<argument index="2" name="color" type="Color">
</argument>
<description>
- Sets the [Color] of the pixel at [code](x, y)[/code]. Example:
- [codeblock]
+ Sets the [Color] of the pixel at [code](x, y)[/code] to [code]color[/code]. Example:
+ [codeblocks]
+ [gdscript]
+ var img_width = 10
+ var img_height = 5
var img = Image.new()
img.create(img_width, img_height, false, Image.FORMAT_RGBA8)
- img.set_pixel(x, y, color)
- [/codeblock]
+
+ img.set_pixel(1, 2, Color.red) # Sets the color at (1, 2) to red.
+ [/gdscript]
+ [csharp]
+ int imgWidth = 10;
+ int imgHeight = 5;
+ var img = new Image();
+ img.Create(imgWidth, imgHeight, false, Image.Format.Rgba8);
+
+ img.SetPixel(1, 2, Colors.Red); // Sets the color at (1, 2) to red.
+ [/csharp]
+ [/codeblocks]
+ This is the same as [method set_pixelv], but with a two integer arguments instead of a [Vector2i] argument.
</description>
</method>
<method name="set_pixelv">
<return type="void">
</return>
- <argument index="0" name="dst" type="Vector2">
+ <argument index="0" name="point" type="Vector2i">
</argument>
<argument index="1" name="color" type="Color">
</argument>
<description>
- Sets the [Color] of the pixel at [code](dst.x, dst.y)[/code]. Note that the [code]dst[/code] values must be integers. Example:
- [codeblock]
+ Sets the [Color] of the pixel at [code]point[/code] to [code]color[/code]. Example:
+ [codeblocks]
+ [gdscript]
+ var img_width = 10
+ var img_height = 5
var img = Image.new()
img.create(img_width, img_height, false, Image.FORMAT_RGBA8)
- img.set_pixelv(Vector2(x, y), color)
- [/codeblock]
+
+ img.set_pixelv(Vector2i(1, 2), Color.red) # Sets the color at (1, 2) to red.
+ [/gdscript]
+ [csharp]
+ int imgWidth = 10;
+ int imgHeight = 5;
+ var img = new Image();
+ img.Create(imgWidth, imgHeight, false, Image.Format.Rgba8);
+
+ img.SetPixelv(new Vector2i(1, 2), Colors.Red); // Sets the color at (1, 2) to red.
+ [/csharp]
+ [/codeblocks]
+ This is the same as [method set_pixel], but with a [Vector2i] argument instead of two integer arguments.
</description>
</method>
<method name="shrink_x2">
diff --git a/doc/classes/Input.xml b/doc/classes/Input.xml
index eafae7310c..2e619802e3 100644
--- a/doc/classes/Input.xml
+++ b/doc/classes/Input.xml
@@ -125,42 +125,6 @@
Returns the current value of the joypad axis at given index (see [enum JoyAxisList]).
</description>
</method>
- <method name="get_joy_axis_index_from_string">
- <return type="int">
- </return>
- <argument index="0" name="axis" type="String">
- </argument>
- <description>
- Returns the index of the provided axis name.
- </description>
- </method>
- <method name="get_joy_axis_string">
- <return type="String">
- </return>
- <argument index="0" name="axis_index" type="int">
- </argument>
- <description>
- Receives a [enum JoyAxisList] axis and returns its equivalent name as a string.
- </description>
- </method>
- <method name="get_joy_button_index_from_string">
- <return type="int">
- </return>
- <argument index="0" name="button" type="String">
- </argument>
- <description>
- Returns the index of the provided button name.
- </description>
- </method>
- <method name="get_joy_button_string">
- <return type="String">
- </return>
- <argument index="0" name="button_index" type="int">
- </argument>
- <description>
- Receives a gamepad button from [enum JoyButtonList] and returns its equivalent name as a string.
- </description>
- </method>
<method name="get_joy_guid" qualifiers="const">
<return type="String">
</return>
diff --git a/doc/classes/InputMap.xml b/doc/classes/InputMap.xml
index 062ac3869d..49d29b3a53 100644
--- a/doc/classes/InputMap.xml
+++ b/doc/classes/InputMap.xml
@@ -120,7 +120,7 @@
Returns [code]true[/code] if the [InputMap] has a registered action with the given name.
</description>
</method>
- <method name="load_from_globals">
+ <method name="load_from_project_settings">
<return type="void">
</return>
<description>
diff --git a/doc/classes/Reference.xml b/doc/classes/Reference.xml
index 9c3d1d5d9d..44ee6fbda1 100644
--- a/doc/classes/Reference.xml
+++ b/doc/classes/Reference.xml
@@ -7,6 +7,7 @@
Base class for any object that keeps a reference count. [Resource] and many other helper objects inherit this class.
Unlike [Object]s, References keep an internal reference counter so that they are automatically released when no longer in use, and only then. References therefore do not need to be freed manually with [method Object.free].
In the vast majority of use cases, instantiating and using [Reference]-derived types is all you need to do. The methods provided in this class are only for advanced users, and can cause issues if misused.
+ [b]Note:[/b] In C#, references will not be freed instantly after they are no longer in use. Instead, garbage collection will run periodically and will free references that are no longer in use. This means that unused references will linger on for a while before being removed.
</description>
<tutorials>
<link title="When and how to avoid using nodes for everything">https://docs.godotengine.org/en/latest/getting_started/workflow/best_practices/node_alternatives.html</link>
diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml
index 5830a8452c..22a9925d4b 100644
--- a/doc/classes/RenderingServer.xml
+++ b/doc/classes/RenderingServer.xml
@@ -3365,7 +3365,8 @@
Objects are displayed with only light information.
</constant>
<constant name="VIEWPORT_DEBUG_DRAW_OVERDRAW" value="3" enum="ViewportDebugDraw">
- Objects are displayed semi-transparent with additive blending so you can see where they are drawing over top of one another. A higher overdraw means you are wasting performance on drawing pixels that are being hidden behind others.
+ Objects are displayed semi-transparent with additive blending so you can see where they are drawing over top of one another. A higher overdraw (represented by brighter colors) means you are wasting performance on drawing pixels that are being hidden behind others.
+ [b]Note:[/b] When using this debug draw mode, custom shaders will be ignored. This means vertex displacement won't be visible anymore.
</constant>
<constant name="VIEWPORT_DEBUG_DRAW_WIREFRAME" value="4" enum="ViewportDebugDraw">
Debug draw draws objects in wireframe.
diff --git a/doc/classes/Resource.xml b/doc/classes/Resource.xml
index e79a2e0ea9..1ce2c376dd 100644
--- a/doc/classes/Resource.xml
+++ b/doc/classes/Resource.xml
@@ -5,6 +5,7 @@
</brief_description>
<description>
Resource is the base class for all Godot-specific resource types, serving primarily as data containers. Unlike [Object]s, they are reference-counted and freed when no longer in use. They are also cached once loaded from disk, so that any further attempts to load a resource from a given path will return the same reference (all this in contrast to a [Node], which is not reference-counted and can be instanced from disk as many times as desired). Resources can be saved externally on disk or bundled into another object, such as a [Node] or another resource.
+ [b]Note:[/b] In C#, resources will not be freed instantly after they are no longer in use. Instead, garbage collection will run periodically and will free resources that are no longer in use. This means that unused resources will linger on for a while before being removed.
</description>
<tutorials>
<link title="Resources">https://docs.godotengine.org/en/latest/getting_started/step_by_step/resources.html</link>
diff --git a/drivers/alsa/audio_driver_alsa.h b/drivers/alsa/audio_driver_alsa.h
index d1220d126e..bb4b1c5476 100644
--- a/drivers/alsa/audio_driver_alsa.h
+++ b/drivers/alsa/audio_driver_alsa.h
@@ -56,17 +56,17 @@ class AudioDriverALSA : public AudioDriver {
static void thread_func(void *p_udata);
- unsigned int mix_rate;
+ unsigned int mix_rate = 0;
SpeakerMode speaker_mode;
snd_pcm_uframes_t buffer_frames;
snd_pcm_uframes_t buffer_size;
snd_pcm_uframes_t period_size;
- int channels;
+ int channels = 0;
- bool active;
- bool thread_exited;
- mutable bool exit_thread;
+ bool active = false;
+ bool thread_exited = false;
+ mutable bool exit_thread = false;
public:
const char *get_name() const {
diff --git a/drivers/dummy/rasterizer_dummy.h b/drivers/dummy/rasterizer_dummy.h
index fd9c26bdb9..dceda8e34f 100644
--- a/drivers/dummy/rasterizer_dummy.h
+++ b/drivers/dummy/rasterizer_dummy.h
@@ -183,21 +183,21 @@ class RasterizerStorageDummy : public RasterizerStorage {
public:
/* TEXTURE API */
struct DummyTexture {
- int width;
- int height;
- uint32_t flags;
- Image::Format format;
+ int width = 0;
+ int height = 0;
+ uint32_t flags = 0;
+ Image::Format format = Image::Format::FORMAT_MAX;
Ref<Image> image;
String path;
};
struct DummySurface {
- uint32_t format;
- RS::PrimitiveType primitive;
+ uint32_t format = 0;
+ RS::PrimitiveType primitive = RS::PrimitiveType::PRIMITIVE_MAX;
Vector<uint8_t> array;
- int vertex_count;
+ int vertex_count = 0;
Vector<uint8_t> index_array;
- int index_count;
+ int index_count = 0;
AABB aabb;
Vector<Vector<uint8_t>> blend_shapes;
Vector<AABB> bone_aabbs;
@@ -205,8 +205,8 @@ public:
struct DummyMesh {
Vector<DummySurface> surfaces;
- int blend_shape_count;
- RS::BlendShapeMode blend_shape_mode;
+ int blend_shape_count = 0;
+ RS::BlendShapeMode blend_shape_mode = RS::BlendShapeMode::BLEND_SHAPE_MODE_NORMALIZED;
};
mutable RID_PtrOwner<DummyTexture> texture_owner;
diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp
index 05eedccc1d..94ea567c3b 100644
--- a/drivers/unix/ip_unix.cpp
+++ b/drivers/unix/ip_unix.cpp
@@ -91,7 +91,7 @@ static IP_Address _sockaddr2ip(struct sockaddr *p_addr) {
IP_Address IP_Unix::_resolve_hostname(const String &p_hostname, Type p_type) {
struct addrinfo hints;
- struct addrinfo *result;
+ struct addrinfo *result = nullptr;
memset(&hints, 0, sizeof(struct addrinfo));
if (p_type == TYPE_IPV4) {
diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp
index 0a42450675..23e6b3bfb6 100644
--- a/drivers/vulkan/rendering_device_vulkan.cpp
+++ b/drivers/vulkan/rendering_device_vulkan.cpp
@@ -7645,7 +7645,6 @@ RenderingDevice *RenderingDeviceVulkan::create_local_device() {
}
RenderingDeviceVulkan::RenderingDeviceVulkan() {
- screen_prepared = false;
}
RenderingDeviceVulkan::~RenderingDeviceVulkan() {
diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h
index 6463078d0a..35fc6debdd 100644
--- a/drivers/vulkan/rendering_device_vulkan.h
+++ b/drivers/vulkan/rendering_device_vulkan.h
@@ -99,7 +99,7 @@ class RenderingDeviceVulkan : public RenderingDevice {
ID_BASE_SHIFT = 58 //5 bits for ID types
};
- VkDevice device;
+ VkDevice device = VK_NULL_HANDLE;
Map<RID, Set<RID>> dependency_map; //IDs to IDs that depend on it
Map<RID, Set<RID>> reverse_dependency_map; //same as above, but in reverse
@@ -124,35 +124,35 @@ class RenderingDeviceVulkan : public RenderingDevice {
// for a framebuffer to render into it.
struct Texture {
- VkImage image;
- VmaAllocation allocation;
+ VkImage image = VK_NULL_HANDLE;
+ VmaAllocation allocation = nullptr;
VmaAllocationInfo allocation_info;
- VkImageView view;
+ VkImageView view = VK_NULL_HANDLE;
TextureType type;
DataFormat format;
TextureSamples samples;
- uint32_t width;
- uint32_t height;
- uint32_t depth;
- uint32_t layers;
- uint32_t mipmaps;
- uint32_t usage_flags;
- uint32_t base_mipmap;
- uint32_t base_layer;
+ uint32_t width = 0;
+ uint32_t height = 0;
+ uint32_t depth = 0;
+ uint32_t layers = 0;
+ uint32_t mipmaps = 0;
+ uint32_t usage_flags = 0;
+ uint32_t base_mipmap = 0;
+ uint32_t base_layer = 0;
Vector<DataFormat> allowed_shared_formats;
VkImageLayout layout;
- uint32_t read_aspect_mask;
- uint32_t barrier_aspect_mask;
- bool bound; //bound to framebffer
+ uint32_t read_aspect_mask = 0;
+ uint32_t barrier_aspect_mask = 0;
+ bool bound = false; //bound to framebffer
RID owner;
};
RID_Owner<Texture, true> texture_owner;
- uint32_t texture_upload_region_size_px;
+ uint32_t texture_upload_region_size_px = 0;
Vector<uint8_t> _texture_get_data_from_image(Texture *tex, VkImage p_image, VmaAllocation p_allocation, uint32_t p_layer, bool p_2d = false);
@@ -188,32 +188,28 @@ class RenderingDeviceVulkan : public RenderingDevice {
// See the comments in the code to understand better how it works.
struct StagingBufferBlock {
- VkBuffer buffer;
- VmaAllocation allocation;
- uint64_t frame_used;
- uint32_t fill_amount;
+ VkBuffer buffer = VK_NULL_HANDLE;
+ VmaAllocation allocation = nullptr;
+ uint64_t frame_used = 0;
+ uint32_t fill_amount = 0;
};
Vector<StagingBufferBlock> staging_buffer_blocks;
- int staging_buffer_current;
- uint32_t staging_buffer_block_size;
- uint64_t staging_buffer_max_size;
- bool staging_buffer_used;
+ int staging_buffer_current = 0;
+ uint32_t staging_buffer_block_size = 0;
+ uint64_t staging_buffer_max_size = 0;
+ bool staging_buffer_used = false;
Error _staging_buffer_allocate(uint32_t p_amount, uint32_t p_required_align, uint32_t &r_alloc_offset, uint32_t &r_alloc_size, bool p_can_segment = true, bool p_on_draw_command_buffer = false);
Error _insert_staging_block();
struct Buffer {
- uint32_t size;
- uint32_t usage;
- VkBuffer buffer;
- VmaAllocation allocation;
+ uint32_t size = 0;
+ uint32_t usage = 0;
+ VkBuffer buffer = VK_NULL_HANDLE;
+ VmaAllocation allocation = nullptr;
VkDescriptorBufferInfo buffer_info; //used for binding
Buffer() {
- size = 0;
- usage = 0;
- buffer = VK_NULL_HANDLE;
- allocation = nullptr;
}
};
@@ -276,15 +272,15 @@ class RenderingDeviceVulkan : public RenderingDevice {
Map<FramebufferFormatKey, FramebufferFormatID> framebuffer_format_cache;
struct FramebufferFormat {
const Map<FramebufferFormatKey, FramebufferFormatID>::Element *E;
- VkRenderPass render_pass; //here for constructing shaders, never used, see section (7.2. Render Pass Compatibility from Vulkan spec)
- int color_attachments; //used for pipeline validation
+ VkRenderPass render_pass = VK_NULL_HANDLE; //here for constructing shaders, never used, see section (7.2. Render Pass Compatibility from Vulkan spec)
+ int color_attachments = 0; //used for pipeline validation
TextureSamples samples;
};
Map<FramebufferFormatID, FramebufferFormat> framebuffer_formats;
struct Framebuffer {
- FramebufferFormatID format_id;
+ FramebufferFormatID format_id = 0;
struct VersionKey {
InitialAction initial_color_action;
FinalAction final_color_action;
@@ -307,12 +303,12 @@ class RenderingDeviceVulkan : public RenderingDevice {
}
};
- uint32_t storage_mask;
+ uint32_t storage_mask = 0;
Vector<RID> texture_ids;
struct Version {
- VkFramebuffer framebuffer;
- VkRenderPass render_pass; //this one is owned
+ VkFramebuffer framebuffer = VK_NULL_HANDLE;
+ VkRenderPass render_pass = VK_NULL_HANDLE; //this one is owned
};
Map<VersionKey, Version> framebuffers;
@@ -399,8 +395,8 @@ class RenderingDeviceVulkan : public RenderingDevice {
struct VertexDescriptionCache {
Vector<VertexAttribute> vertex_formats;
- VkVertexInputBindingDescription *bindings;
- VkVertexInputAttributeDescription *attributes;
+ VkVertexInputBindingDescription *bindings = nullptr;
+ VkVertexInputAttributeDescription *attributes = nullptr;
VkPipelineVertexInputStateCreateInfo create_info;
};
@@ -408,9 +404,9 @@ class RenderingDeviceVulkan : public RenderingDevice {
struct VertexArray {
RID buffer;
- VertexFormatID description;
- int vertex_count;
- uint32_t max_instances_allowed;
+ VertexFormatID description = 0;
+ int vertex_count = 0;
+ uint32_t max_instances_allowed = 0;
Vector<VkBuffer> buffers; //not owned, just referenced
Vector<VkDeviceSize> offsets;
@@ -419,21 +415,21 @@ class RenderingDeviceVulkan : public RenderingDevice {
RID_Owner<VertexArray, true> vertex_array_owner;
struct IndexBuffer : public Buffer {
- uint32_t max_index; //used for validation
- uint32_t index_count;
- VkIndexType index_type;
- bool supports_restart_indices;
+ uint32_t max_index = 0; //used for validation
+ uint32_t index_count = 0;
+ VkIndexType index_type = VK_INDEX_TYPE_NONE_NV;
+ bool supports_restart_indices = false;
};
RID_Owner<IndexBuffer, true> index_buffer_owner;
struct IndexArray {
- uint32_t max_index; //remember the maximum index here too, for validation
+ uint32_t max_index = 0; //remember the maximum index here too, for validation
VkBuffer buffer; //not owned, inherited from index buffer
- uint32_t offset;
- uint32_t indices;
- VkIndexType index_type;
- bool supports_restart_indices;
+ uint32_t offset = 0;
+ uint32_t indices = 0;
+ VkIndexType index_type = VK_INDEX_TYPE_NONE_NV;
+ bool supports_restart_indices = false;
};
RID_Owner<IndexArray, true> index_array_owner;
@@ -459,10 +455,10 @@ class RenderingDeviceVulkan : public RenderingDevice {
};
struct UniformInfo {
- UniformType type;
- int binding;
- uint32_t stages;
- int length; //size of arrays (in total elements), or ubos (in bytes * total elements)
+ UniformType type = UniformType::UNIFORM_TYPE_MAX;
+ int binding = 0;
+ uint32_t stages = 0;
+ int length = 0; //size of arrays (in total elements), or ubos (in bytes * total elements)
bool operator!=(const UniformInfo &p_info) const {
return (binding != p_info.binding || type != p_info.type || stages != p_info.stages || length != p_info.length);
@@ -528,25 +524,25 @@ class RenderingDeviceVulkan : public RenderingDevice {
struct Shader {
struct Set {
Vector<UniformInfo> uniform_info;
- VkDescriptorSetLayout descriptor_set_layout;
+ VkDescriptorSetLayout descriptor_set_layout = VK_NULL_HANDLE;
};
- uint32_t vertex_input_mask; //inputs used, this is mostly for validation
- int fragment_outputs;
+ uint32_t vertex_input_mask = 0; //inputs used, this is mostly for validation
+ int fragment_outputs = 0;
struct PushConstant {
- uint32_t push_constant_size;
- uint32_t push_constants_vk_stage;
+ uint32_t push_constant_size = 0;
+ uint32_t push_constants_vk_stage = 0;
};
PushConstant push_constant;
bool is_compute = false;
- int max_output;
+ int max_output = 0;
Vector<Set> sets;
Vector<uint32_t> set_formats;
Vector<VkPipelineShaderStageCreateInfo> pipeline_stages;
- VkPipelineLayout pipeline_layout;
+ VkPipelineLayout pipeline_layout = VK_NULL_HANDLE;
};
String _shader_uniform_debug(RID p_shader, int p_set = -1);
@@ -610,7 +606,7 @@ class RenderingDeviceVulkan : public RenderingDevice {
};
Map<DescriptorPoolKey, Set<DescriptorPool *>> descriptor_pools;
- uint32_t max_descriptors_per_pool;
+ uint32_t max_descriptors_per_pool = 0;
DescriptorPool *_descriptor_pool_allocate(const DescriptorPoolKey &p_key);
void _descriptor_pool_free(const DescriptorPoolKey &p_key, DescriptorPool *p_pool);
@@ -621,7 +617,7 @@ class RenderingDeviceVulkan : public RenderingDevice {
//texture buffer needs a view
struct TextureBuffer {
Buffer buffer;
- VkBufferView view;
+ VkBufferView view = VK_NULL_HANDLE;
};
RID_Owner<TextureBuffer, true> texture_buffer_owner;
@@ -635,12 +631,12 @@ class RenderingDeviceVulkan : public RenderingDevice {
// the above restriction is not too serious.
struct UniformSet {
- uint32_t format;
+ uint32_t format = 0;
RID shader_id;
- uint32_t shader_set;
- DescriptorPool *pool;
+ uint32_t shader_set = 0;
+ DescriptorPool *pool = nullptr;
DescriptorPoolKey pool_key;
- VkDescriptorSet descriptor_set;
+ VkDescriptorSet descriptor_set = VK_NULL_HANDLE;
//VkPipelineLayout pipeline_layout; //not owned, inherited from shader
Vector<RID> attachable_textures; //used for validation
Vector<Texture *> mutable_sampled_textures; //used for layout change
@@ -668,21 +664,21 @@ class RenderingDeviceVulkan : public RenderingDevice {
//Cached values for validation
#ifdef DEBUG_ENABLED
struct Validation {
- FramebufferFormatID framebuffer_format;
- uint32_t dynamic_state;
- VertexFormatID vertex_format;
- bool uses_restart_indices;
- uint32_t primitive_minimum;
- uint32_t primitive_divisor;
+ FramebufferFormatID framebuffer_format = 0;
+ uint32_t dynamic_state = 0;
+ VertexFormatID vertex_format = 0;
+ bool uses_restart_indices = false;
+ uint32_t primitive_minimum = 0;
+ uint32_t primitive_divisor = 0;
} validation;
#endif
//Actual pipeline
RID shader;
Vector<uint32_t> set_formats;
- VkPipelineLayout pipeline_layout; // not owned, needed for push constants
- VkPipeline pipeline;
- uint32_t push_constant_size;
- uint32_t push_constant_stages;
+ VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; // not owned, needed for push constants
+ VkPipeline pipeline = VK_NULL_HANDLE;
+ uint32_t push_constant_size = 0;
+ uint32_t push_constant_stages = 0;
};
RID_Owner<RenderPipeline, true> render_pipeline_owner;
@@ -690,10 +686,10 @@ class RenderingDeviceVulkan : public RenderingDevice {
struct ComputePipeline {
RID shader;
Vector<uint32_t> set_formats;
- VkPipelineLayout pipeline_layout; // not owned, needed for push constants
- VkPipeline pipeline;
- uint32_t push_constant_size;
- uint32_t push_constant_stages;
+ VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; // not owned, needed for push constants
+ VkPipeline pipeline = VK_NULL_HANDLE;
+ uint32_t push_constant_size = 0;
+ uint32_t push_constant_stages = 0;
};
RID_Owner<ComputePipeline, true> compute_pipeline_owner;
@@ -714,14 +710,14 @@ class RenderingDeviceVulkan : public RenderingDevice {
// each needs it's own command pool.
struct SplitDrawListAllocator {
- VkCommandPool command_pool;
+ VkCommandPool command_pool = VK_NULL_HANDLE;
Vector<VkCommandBuffer> command_buffers; //one for each frame
};
Vector<SplitDrawListAllocator> split_draw_list_allocators;
struct DrawList {
- VkCommandBuffer command_buffer; // If persistent, this is owned, otherwise it's shared with the ringbuffer.
+ VkCommandBuffer command_buffer = VK_NULL_HANDLE; // If persistent, this is owned, otherwise it's shared with the ringbuffer.
Rect2i viewport;
struct SetState {
@@ -755,7 +751,7 @@ class RenderingDeviceVulkan : public RenderingDevice {
bool index_buffer_uses_restart_indices = false;
uint32_t index_array_size = 0;
uint32_t index_array_max_index = 0;
- uint32_t index_array_offset;
+ uint32_t index_array_offset = 0;
Vector<uint32_t> set_formats;
Vector<bool> set_bound;
Vector<RID> set_rids;
@@ -766,8 +762,8 @@ class RenderingDeviceVulkan : public RenderingDevice {
RID pipeline_shader;
uint32_t invalid_set_from = 0;
bool pipeline_uses_restart_indices = false;
- uint32_t pipeline_primitive_divisor;
- uint32_t pipeline_primitive_minimum;
+ uint32_t pipeline_primitive_divisor = 0;
+ uint32_t pipeline_primitive_minimum = 0;
Vector<uint32_t> pipeline_set_formats;
uint32_t pipeline_push_constant_size = 0;
bool pipeline_push_constant_supplied = false;
@@ -781,13 +777,13 @@ class RenderingDeviceVulkan : public RenderingDevice {
#endif
};
- DrawList *draw_list; // One for regular draw lists, multiple for split.
- uint32_t draw_list_count;
- bool draw_list_split;
+ DrawList *draw_list = nullptr; // One for regular draw lists, multiple for split.
+ uint32_t draw_list_count = 0;
+ bool draw_list_split = false;
Vector<RID> draw_list_bound_textures;
Vector<RID> draw_list_storage_textures;
- bool draw_list_unbind_color_textures;
- bool draw_list_unbind_depth_textures;
+ bool draw_list_unbind_color_textures = false;
+ bool draw_list_unbind_depth_textures = false;
void _draw_list_insert_clear_region(DrawList *draw_list, Framebuffer *framebuffer, Point2i viewport_offset, Point2i viewport_size, bool p_clear_color, const Vector<Color> &p_clear_colors, bool p_clear_depth, float p_depth, uint32_t p_stencil);
Error _draw_list_setup_framebuffer(Framebuffer *p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, VkFramebuffer *r_framebuffer, VkRenderPass *r_render_pass);
@@ -800,7 +796,7 @@ class RenderingDeviceVulkan : public RenderingDevice {
/**********************/
struct ComputeList {
- VkCommandBuffer command_buffer; // If persistent, this is owned, otherwise it's shared with the ringbuffer.
+ VkCommandBuffer command_buffer = VK_NULL_HANDLE; // If persistent, this is owned, otherwise it's shared with the ringbuffer.
struct SetState {
uint32_t pipeline_expected_format = 0;
@@ -837,7 +833,7 @@ class RenderingDeviceVulkan : public RenderingDevice {
#endif
};
- ComputeList *compute_list;
+ ComputeList *compute_list = nullptr;
/**************************/
/**** FRAME MANAGEMENT ****/
@@ -869,46 +865,46 @@ class RenderingDeviceVulkan : public RenderingDevice {
List<RenderPipeline> render_pipelines_to_dispose_of;
List<ComputePipeline> compute_pipelines_to_dispose_of;
- VkCommandPool command_pool;
- VkCommandBuffer setup_command_buffer; //used at the beginning of every frame for set-up
- VkCommandBuffer draw_command_buffer; //used at the beginning of every frame for set-up
+ VkCommandPool command_pool = VK_NULL_HANDLE;
+ VkCommandBuffer setup_command_buffer = VK_NULL_HANDLE; //used at the beginning of every frame for set-up
+ VkCommandBuffer draw_command_buffer = VK_NULL_HANDLE; //used at the beginning of every frame for set-up
struct Timestamp {
String description;
- uint64_t value;
+ uint64_t value = 0;
};
VkQueryPool timestamp_pool;
- String *timestamp_names;
- uint64_t *timestamp_cpu_values;
- uint32_t timestamp_count;
- String *timestamp_result_names;
- uint64_t *timestamp_cpu_result_values;
- uint64_t *timestamp_result_values;
- uint32_t timestamp_result_count;
- uint64_t index;
+ String *timestamp_names = nullptr;
+ uint64_t *timestamp_cpu_values = nullptr;
+ uint32_t timestamp_count = 0;
+ String *timestamp_result_names = nullptr;
+ uint64_t *timestamp_cpu_result_values = nullptr;
+ uint64_t *timestamp_result_values = nullptr;
+ uint32_t timestamp_result_count = 0;
+ uint64_t index = 0;
};
- uint32_t max_timestamp_query_elements;
+ uint32_t max_timestamp_query_elements = 0;
- Frame *frames; //frames available, for main device they are cycled (usually 3), for local devices only 1
- int frame; //current frame
- int frame_count; //total amount of frames
- uint64_t frames_drawn;
+ Frame *frames = nullptr; //frames available, for main device they are cycled (usually 3), for local devices only 1
+ int frame = 0; //current frame
+ int frame_count = 0; //total amount of frames
+ uint64_t frames_drawn = 0;
RID local_device;
bool local_device_processing = false;
void _free_pending_resources(int p_frame);
- VmaAllocator allocator;
+ VmaAllocator allocator = nullptr;
- VulkanContext *context;
+ VulkanContext *context = nullptr;
void _free_internal(RID p_id);
void _flush(bool p_current_frame);
- bool screen_prepared;
+ bool screen_prepared = false;
template <class T>
void _free_rids(T &p_owner, const char *p_type);
diff --git a/drivers/vulkan/vulkan_context.h b/drivers/vulkan/vulkan_context.h
index 62b97a7e60..1aaad29ccd 100644
--- a/drivers/vulkan/vulkan_context.h
+++ b/drivers/vulkan/vulkan_context.h
@@ -47,13 +47,13 @@ class VulkanContext {
FRAME_LAG = 2
};
- VkInstance inst;
- VkSurfaceKHR surface;
- VkPhysicalDevice gpu;
+ VkInstance inst = VK_NULL_HANDLE;
+ VkSurfaceKHR surface = VK_NULL_HANDLE;
+ VkPhysicalDevice gpu = VK_NULL_HANDLE;
VkPhysicalDeviceProperties gpu_props;
- uint32_t queue_family_count;
+ uint32_t queue_family_count = 0;
VkQueueFamilyProperties *queue_props = nullptr;
- VkDevice device;
+ VkDevice device = VK_NULL_HANDLE;
bool device_initialized = false;
bool inst_initialized = false;
@@ -61,17 +61,17 @@ class VulkanContext {
// Present queue.
bool queues_initialized = false;
- uint32_t graphics_queue_family_index;
- uint32_t present_queue_family_index;
- bool separate_present_queue;
- VkQueue graphics_queue;
- VkQueue present_queue;
+ uint32_t graphics_queue_family_index = 0;
+ uint32_t present_queue_family_index = 0;
+ bool separate_present_queue = false;
+ VkQueue graphics_queue = VK_NULL_HANDLE;
+ VkQueue present_queue = VK_NULL_HANDLE;
VkColorSpaceKHR color_space;
VkFormat format;
VkSemaphore image_acquired_semaphores[FRAME_LAG];
VkSemaphore draw_complete_semaphores[FRAME_LAG];
VkSemaphore image_ownership_semaphores[FRAME_LAG];
- int frame_index;
+ int frame_index = 0;
VkFence fences[FRAME_LAG];
VkPhysicalDeviceMemoryProperties memory_properties;
VkPhysicalDeviceFeatures physical_device_features;
@@ -91,14 +91,14 @@ class VulkanContext {
uint32_t current_buffer = 0;
int width = 0;
int height = 0;
- VkCommandPool present_cmd_pool; // For separate present queue.
+ VkCommandPool present_cmd_pool = VK_NULL_HANDLE; // For separate present queue.
VkRenderPass render_pass = VK_NULL_HANDLE;
};
struct LocalDevice {
bool waiting = false;
- VkDevice device;
- VkQueue queue;
+ VkDevice device = VK_NULL_HANDLE;
+ VkQueue queue = VK_NULL_HANDLE;
};
RID_Owner<LocalDevice, true> local_device_owner;
@@ -108,7 +108,7 @@ class VulkanContext {
// Commands.
- bool prepared;
+ bool prepared = false;
Vector<VkCommandBuffer> command_buffer_queue;
int command_buffer_count = 1;
@@ -142,7 +142,7 @@ class VulkanContext {
PFN_vkGetRefreshCycleDurationGOOGLE fpGetRefreshCycleDurationGOOGLE;
PFN_vkGetPastPresentationTimingGOOGLE fpGetPastPresentationTimingGOOGLE;
- VkDebugUtilsMessengerEXT dbg_messenger;
+ VkDebugUtilsMessengerEXT dbg_messenger = VK_NULL_HANDLE;
Error _create_validation_layers();
Error _initialize_extensions();
diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp
index 3c61aa7289..197cd1d074 100644
--- a/drivers/windows/dir_access_windows.cpp
+++ b/drivers/windows/dir_access_windows.cpp
@@ -367,8 +367,6 @@ DirAccessWindows::DirAccessWindows() {
p->h = INVALID_HANDLE_VALUE;
current_dir = ".";
- drive_count = 0;
-
#ifdef UWP_ENABLED
Windows::Storage::StorageFolder ^ install_folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
change_dir(install_folder->Path->Data());
diff --git a/drivers/windows/dir_access_windows.h b/drivers/windows/dir_access_windows.h
index 47aedfecf5..3b059b1626 100644
--- a/drivers/windows/dir_access_windows.h
+++ b/drivers/windows/dir_access_windows.h
@@ -46,16 +46,16 @@ class DirAccessWindows : public DirAccess {
MAX_DRIVES = 26
};
- DirAccessWindowsPrivate *p;
+ DirAccessWindowsPrivate *p = nullptr;
/* Windows stuff */
- char drives[MAX_DRIVES]; // a-z:
- int drive_count;
+ char drives[MAX_DRIVES] = { 0 }; // a-z:
+ int drive_count = 0;
String current_dir;
- bool _cisdir;
- bool _cishidden;
+ bool _cisdir = false;
+ bool _cishidden = false;
public:
virtual Error list_dir_begin(); ///< This starts dir listing
diff --git a/drivers/xaudio2/audio_driver_xaudio2.h b/drivers/xaudio2/audio_driver_xaudio2.h
index 7fc1bb428d..0aed072ec6 100644
--- a/drivers/xaudio2/audio_driver_xaudio2.h
+++ b/drivers/xaudio2/audio_driver_xaudio2.h
@@ -65,28 +65,28 @@ class AudioDriverXAudio2 : public AudioDriver {
Thread *thread = nullptr;
Mutex mutex;
- int32_t *samples_in;
+ int32_t *samples_in = nullptr;
int16_t *samples_out[AUDIO_BUFFERS];
static void thread_func(void *p_udata);
- int buffer_size;
+ int buffer_size = 0;
- unsigned int mix_rate;
- SpeakerMode speaker_mode;
+ unsigned int mix_rate = 0;
+ SpeakerMode speaker_mode = SpeakerMode::SPEAKER_MODE_STEREO;
- int channels;
+ int channels = 0;
- bool active;
- bool thread_exited;
- mutable bool exit_thread;
- bool pcm_open;
+ bool active = false;
+ bool thread_exited = false;
+ mutable bool exit_thread = false;
+ bool pcm_open = false;
WAVEFORMATEX wave_format = { 0 };
Microsoft::WRL::ComPtr<IXAudio2> xaudio;
int current_buffer = 0;
- IXAudio2MasteringVoice *mastering_voice;
+ IXAudio2MasteringVoice *mastering_voice = nullptr;
XAUDIO2_BUFFER xaudio_buffer[AUDIO_BUFFERS];
- IXAudio2SourceVoice *source_voice;
+ IXAudio2SourceVoice *source_voice = nullptr;
XAudio2DriverVoiceCallback voice_callback;
public:
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 976afd8e8e..9fcb5fff35 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -6821,7 +6821,7 @@ EditorNode::EditorNode() {
ED_SHORTCUT("editor/editor_3d", TTR("Open 3D Editor"), KEY_MASK_CTRL | KEY_F2);
ED_SHORTCUT("editor/editor_script", TTR("Open Script Editor"), KEY_MASK_CTRL | KEY_F3);
ED_SHORTCUT("editor/editor_assetlib", TTR("Open Asset Library"), KEY_MASK_CTRL | KEY_F4);
- ED_SHORTCUT("editor/editor_help", TTR("Search Help"), KEY_MASK_SHIFT | KEY_F1);
+ ED_SHORTCUT("editor/editor_help", TTR("Search Help"), KEY_F1);
#endif
ED_SHORTCUT("editor/editor_next", TTR("Open the next Editor"));
ED_SHORTCUT("editor/editor_prev", TTR("Open the previous Editor"));
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index f5c1de9def..2cf0bed7d0 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -510,7 +510,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
hints["editors/3d/secondary_grid_color"] = PropertyInfo(Variant::COLOR, "editors/3d/secondary_grid_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT);
// If a line is a multiple of this, it uses the primary grid color.
- _initial_set("editors/3d/primary_grid_steps", 10);
+ // Use a power of 2 value by default as it's more common to use powers of 2 in level design.
+ _initial_set("editors/3d/primary_grid_steps", 8);
hints["editors/3d/primary_grid_steps"] = PropertyInfo(Variant::INT, "editors/3d/primary_grid_steps", PROPERTY_HINT_RANGE, "1,100,1", PROPERTY_USAGE_DEFAULT);
// At 1000, the grid mostly looks like it has no edge.
diff --git a/editor/import/resource_importer_texture_atlas.cpp b/editor/import/resource_importer_texture_atlas.cpp
index 2423553d22..c9f689cc08 100644
--- a/editor/import/resource_importer_texture_atlas.cpp
+++ b/editor/import/resource_importer_texture_atlas.cpp
@@ -97,7 +97,7 @@ Error ResourceImporterTextureAtlas::import(const String &p_source_file, const St
return OK;
}
-static void _plot_triangle(Vector2 *vertices, const Vector2 &p_offset, bool p_transposed, Ref<Image> p_image, const Ref<Image> &p_src_image) {
+static void _plot_triangle(Vector2i *vertices, const Vector2i &p_offset, bool p_transposed, Ref<Image> p_image, const Ref<Image> &p_src_image) {
int width = p_image->get_width();
int height = p_image->get_height();
int src_width = p_src_image->get_width();
@@ -281,13 +281,13 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
for (int j = 0; j < pack_data.chart_pieces.size(); j++) {
const EditorAtlasPacker::Chart &chart = charts[pack_data.chart_pieces[j]];
for (int k = 0; k < chart.faces.size(); k++) {
- Vector2 positions[3];
+ Vector2i positions[3];
for (int l = 0; l < 3; l++) {
int vertex_idx = chart.faces[k].vertex[l];
- positions[l] = chart.vertices[vertex_idx];
+ positions[l] = Vector2i(chart.vertices[vertex_idx]);
}
- _plot_triangle(positions, chart.final_offset, chart.transposed, new_atlas, pack_data.image);
+ _plot_triangle(positions, Vector2i(chart.final_offset), chart.transposed, new_atlas, pack_data.image);
}
}
}
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index fa7300c930..8420faa302 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -6847,7 +6847,7 @@ void EditorNode3DGizmoPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("create_handle_material", "name", "billboard", "texture"), &EditorNode3DGizmoPlugin::create_handle_material, DEFVAL(false), DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("add_material", "name", "material"), &EditorNode3DGizmoPlugin::add_material);
- ClassDB::bind_method(D_METHOD("get_material", "name", "gizmo"), &EditorNode3DGizmoPlugin::get_material); //, DEFVAL(Ref<EditorNode3DGizmo>()));
+ ClassDB::bind_method(D_METHOD("get_material", "name", "gizmo"), &EditorNode3DGizmoPlugin::get_material, DEFVAL(Ref<EditorNode3DGizmo>()));
BIND_VMETHOD(MethodInfo(Variant::STRING, "get_name"));
BIND_VMETHOD(MethodInfo(Variant::INT, "get_priority"));
diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub
index 0e2291c1f9..bd06347afb 100644
--- a/modules/gdnative/SCsub
+++ b/modules/gdnative/SCsub
@@ -30,5 +30,3 @@ _, gensource = env_gdnative.CommandNoCache(
env.Run(gdnative_builders.build_gdnative_api_struct, "Generating GDNative API."),
)
env_gdnative.add_source_files(env.modules_sources, [gensource])
-
-env.use_ptrcall = True
diff --git a/modules/gdnative/config.py b/modules/gdnative/config.py
index 7603e7d69d..fd860e9763 100644
--- a/modules/gdnative/config.py
+++ b/modules/gdnative/config.py
@@ -3,7 +3,7 @@ def can_build(env, platform):
def configure(env):
- env.use_ptrcall = True
+ pass
def get_doc_classes():
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp
index 6b23ab1616..851994eff3 100644
--- a/modules/gdscript/gdscript_analyzer.cpp
+++ b/modules/gdscript/gdscript_analyzer.cpp
@@ -978,7 +978,7 @@ void GDScriptAnalyzer::resolve_for(GDScriptParser::ForNode *p_for) {
if (!call->arguments[i]->is_constant) {
all_is_constant = false;
- } else {
+ } else if (all_is_constant) {
args.write[i] = call->arguments[i]->reduced_value;
}
@@ -1011,11 +1011,15 @@ void GDScriptAnalyzer::resolve_for(GDScriptParser::ForNode *p_for) {
}
}
- GDScriptParser::DataType list_type;
- list_type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT;
- list_type.kind = GDScriptParser::DataType::BUILTIN;
- list_type.builtin_type = Variant::ARRAY;
- p_for->list->set_datatype(list_type);
+ if (p_for->list->is_constant) {
+ p_for->list->set_datatype(type_from_variant(p_for->list->reduced_value, p_for->list));
+ } else {
+ GDScriptParser::DataType list_type;
+ list_type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT;
+ list_type.kind = GDScriptParser::DataType::BUILTIN;
+ list_type.builtin_type = Variant::ARRAY;
+ p_for->list->set_datatype(list_type);
+ }
}
}
}
diff --git a/modules/gdscript/gdscript_byte_codegen.cpp b/modules/gdscript/gdscript_byte_codegen.cpp
index cc9e87b882..a81b3298ef 100644
--- a/modules/gdscript/gdscript_byte_codegen.cpp
+++ b/modules/gdscript/gdscript_byte_codegen.cpp
@@ -77,11 +77,22 @@ uint32_t GDScriptByteCodeGenerator::add_or_get_name(const StringName &p_name) {
uint32_t GDScriptByteCodeGenerator::add_temporary() {
current_temporaries++;
- return increase_stack();
+ int idx = increase_stack();
+#ifdef DEBUG_ENABLED
+ temp_stack.push_back(idx);
+#endif
+ return idx;
}
void GDScriptByteCodeGenerator::pop_temporary() {
+ ERR_FAIL_COND(current_temporaries == 0);
current_stack_size--;
+#ifdef DEBUG_ENABLED
+ if (temp_stack.back()->get() != current_stack_size) {
+ ERR_PRINT("Mismatched popping of temporary value");
+ }
+ temp_stack.pop_back();
+#endif
current_temporaries--;
}
@@ -111,7 +122,12 @@ void GDScriptByteCodeGenerator::write_start(GDScript *p_script, const StringName
}
GDScriptFunction *GDScriptByteCodeGenerator::write_end() {
- append(GDScriptFunction::OPCODE_END);
+#ifdef DEBUG_ENABLED
+ if (current_temporaries != 0) {
+ ERR_PRINT("Non-zero temporary variables at end of function: " + itos(current_temporaries));
+ }
+#endif
+ append(GDScriptFunction::OPCODE_END, 0);
if (constant_map.size()) {
function->_constant_count = constant_map.size();
@@ -158,11 +174,132 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() {
function->_default_arg_ptr = nullptr;
}
+ if (operator_func_map.size()) {
+ function->operator_funcs.resize(operator_func_map.size());
+ function->_operator_funcs_count = function->operator_funcs.size();
+ function->_operator_funcs_ptr = function->operator_funcs.ptr();
+ for (const Map<Variant::ValidatedOperatorEvaluator, int>::Element *E = operator_func_map.front(); E; E = E->next()) {
+ function->operator_funcs.write[E->get()] = E->key();
+ }
+ } else {
+ function->_operator_funcs_count = 0;
+ function->_operator_funcs_ptr = nullptr;
+ }
+
+ if (setters_map.size()) {
+ function->setters.resize(setters_map.size());
+ function->_setters_count = function->setters.size();
+ function->_setters_ptr = function->setters.ptr();
+ for (const Map<Variant::ValidatedSetter, int>::Element *E = setters_map.front(); E; E = E->next()) {
+ function->setters.write[E->get()] = E->key();
+ }
+ } else {
+ function->_setters_count = 0;
+ function->_setters_ptr = nullptr;
+ }
+
+ if (getters_map.size()) {
+ function->getters.resize(getters_map.size());
+ function->_getters_count = function->getters.size();
+ function->_getters_ptr = function->getters.ptr();
+ for (const Map<Variant::ValidatedGetter, int>::Element *E = getters_map.front(); E; E = E->next()) {
+ function->getters.write[E->get()] = E->key();
+ }
+ } else {
+ function->_getters_count = 0;
+ function->_getters_ptr = nullptr;
+ }
+
+ if (keyed_setters_map.size()) {
+ function->keyed_setters.resize(keyed_setters_map.size());
+ function->_keyed_setters_count = function->keyed_setters.size();
+ function->_keyed_setters_ptr = function->keyed_setters.ptr();
+ for (const Map<Variant::ValidatedKeyedSetter, int>::Element *E = keyed_setters_map.front(); E; E = E->next()) {
+ function->keyed_setters.write[E->get()] = E->key();
+ }
+ } else {
+ function->_keyed_setters_count = 0;
+ function->_keyed_setters_ptr = nullptr;
+ }
+
+ if (keyed_getters_map.size()) {
+ function->keyed_getters.resize(keyed_getters_map.size());
+ function->_keyed_getters_count = function->keyed_getters.size();
+ function->_keyed_getters_ptr = function->keyed_getters.ptr();
+ for (const Map<Variant::ValidatedKeyedGetter, int>::Element *E = keyed_getters_map.front(); E; E = E->next()) {
+ function->keyed_getters.write[E->get()] = E->key();
+ }
+ } else {
+ function->_keyed_getters_count = 0;
+ function->_keyed_getters_ptr = nullptr;
+ }
+
+ if (indexed_setters_map.size()) {
+ function->indexed_setters.resize(indexed_setters_map.size());
+ function->_indexed_setters_count = function->indexed_setters.size();
+ function->_indexed_setters_ptr = function->indexed_setters.ptr();
+ for (const Map<Variant::ValidatedIndexedSetter, int>::Element *E = indexed_setters_map.front(); E; E = E->next()) {
+ function->indexed_setters.write[E->get()] = E->key();
+ }
+ } else {
+ function->_indexed_setters_count = 0;
+ function->_indexed_setters_ptr = nullptr;
+ }
+
+ if (indexed_getters_map.size()) {
+ function->indexed_getters.resize(indexed_getters_map.size());
+ function->_indexed_getters_count = function->indexed_getters.size();
+ function->_indexed_getters_ptr = function->indexed_getters.ptr();
+ for (const Map<Variant::ValidatedIndexedGetter, int>::Element *E = indexed_getters_map.front(); E; E = E->next()) {
+ function->indexed_getters.write[E->get()] = E->key();
+ }
+ } else {
+ function->_indexed_getters_count = 0;
+ function->_indexed_getters_ptr = nullptr;
+ }
+
+ if (builtin_method_map.size()) {
+ function->builtin_methods.resize(builtin_method_map.size());
+ function->_builtin_methods_ptr = function->builtin_methods.ptr();
+ function->_builtin_methods_count = builtin_method_map.size();
+ for (const Map<Variant::ValidatedBuiltInMethod, int>::Element *E = builtin_method_map.front(); E; E = E->next()) {
+ function->builtin_methods.write[E->get()] = E->key();
+ }
+ } else {
+ function->_builtin_methods_ptr = nullptr;
+ function->_builtin_methods_count = 0;
+ }
+
+ if (constructors_map.size()) {
+ function->constructors.resize(constructors_map.size());
+ function->_constructors_ptr = function->constructors.ptr();
+ function->_constructors_count = constructors_map.size();
+ for (const Map<Variant::ValidatedConstructor, int>::Element *E = constructors_map.front(); E; E = E->next()) {
+ function->constructors.write[E->get()] = E->key();
+ }
+ } else {
+ function->_constructors_ptr = nullptr;
+ function->_constructors_count = 0;
+ }
+
+ if (method_bind_map.size()) {
+ function->methods.resize(method_bind_map.size());
+ function->_methods_ptr = function->methods.ptrw();
+ function->_methods_count = method_bind_map.size();
+ for (const Map<MethodBind *, int>::Element *E = method_bind_map.front(); E; E = E->next()) {
+ function->methods.write[E->get()] = E->key();
+ }
+ } else {
+ function->_methods_ptr = nullptr;
+ function->_methods_count = 0;
+ }
+
if (debug_stack) {
function->stack_debug = stack_debug;
}
function->_stack_size = stack_max;
- function->_call_size = call_max;
+ function->_instruction_args_size = instr_args_max;
+ function->_ptrcall_args_size = ptrcall_max;
ended = true;
return function;
@@ -178,37 +315,56 @@ void GDScriptByteCodeGenerator::set_initial_line(int p_line) {
function->_initial_line = p_line;
}
+#define HAS_BUILTIN_TYPE(m_var) \
+ (m_var.type.has_type && m_var.type.kind == GDScriptDataType::BUILTIN)
+
+#define IS_BUILTIN_TYPE(m_var, m_type) \
+ (m_var.type.has_type && m_var.type.kind == GDScriptDataType::BUILTIN && m_var.type.builtin_type == m_type)
+
void GDScriptByteCodeGenerator::write_operator(const Address &p_target, Variant::Operator p_operator, const Address &p_left_operand, const Address &p_right_operand) {
- append(GDScriptFunction::OPCODE_OPERATOR);
- append(p_operator);
+ if (HAS_BUILTIN_TYPE(p_left_operand) && HAS_BUILTIN_TYPE(p_right_operand)) {
+ // Gather specific operator.
+ Variant::ValidatedOperatorEvaluator op_func = Variant::get_validated_operator_evaluator(p_operator, p_left_operand.type.builtin_type, p_right_operand.type.builtin_type);
+
+ append(GDScriptFunction::OPCODE_OPERATOR_VALIDATED, 3);
+ append(p_left_operand);
+ append(p_right_operand);
+ append(p_target);
+ append(op_func);
+ return;
+ }
+
+ // No specific types, perform variant evaluation.
+ append(GDScriptFunction::OPCODE_OPERATOR, 3);
append(p_left_operand);
append(p_right_operand);
append(p_target);
+ append(p_operator);
}
void GDScriptByteCodeGenerator::write_type_test(const Address &p_target, const Address &p_source, const Address &p_type) {
- append(GDScriptFunction::OPCODE_EXTENDS_TEST);
+ append(GDScriptFunction::OPCODE_EXTENDS_TEST, 3);
append(p_source);
append(p_type);
append(p_target);
}
void GDScriptByteCodeGenerator::write_type_test_builtin(const Address &p_target, const Address &p_source, Variant::Type p_type) {
- append(GDScriptFunction::OPCODE_IS_BUILTIN);
+ append(GDScriptFunction::OPCODE_IS_BUILTIN, 3);
append(p_source);
- append(p_type);
append(p_target);
+ append(p_type);
}
void GDScriptByteCodeGenerator::write_and_left_operand(const Address &p_left_operand) {
- append(GDScriptFunction::OPCODE_JUMP_IF_NOT);
+ append(GDScriptFunction::OPCODE_JUMP_IF_NOT, 1);
append(p_left_operand);
logic_op_jump_pos1.push_back(opcodes.size());
append(0); // Jump target, will be patched.
}
void GDScriptByteCodeGenerator::write_and_right_operand(const Address &p_right_operand) {
- append(GDScriptFunction::OPCODE_JUMP_IF_NOT);
+ append(GDScriptFunction::OPCODE_JUMP_IF_NOT, 1);
append(p_right_operand);
logic_op_jump_pos2.push_back(opcodes.size());
append(0); // Jump target, will be patched.
@@ -216,29 +372,29 @@ void GDScriptByteCodeGenerator::write_and_right_operand(const Address &p_right_o
void GDScriptByteCodeGenerator::write_end_and(const Address &p_target) {
// If here means both operands are true.
- append(GDScriptFunction::OPCODE_ASSIGN_TRUE);
+ append(GDScriptFunction::OPCODE_ASSIGN_TRUE, 1);
append(p_target);
// Jump away from the fail condition.
- append(GDScriptFunction::OPCODE_JUMP);
+ append(GDScriptFunction::OPCODE_JUMP, 0);
append(opcodes.size() + 3);
// Here it means one of operands is false.
patch_jump(logic_op_jump_pos1.back()->get());
patch_jump(logic_op_jump_pos2.back()->get());
logic_op_jump_pos1.pop_back();
logic_op_jump_pos2.pop_back();
- append(GDScriptFunction::OPCODE_ASSIGN_FALSE);
+ append(GDScriptFunction::OPCODE_ASSIGN_FALSE, 0);
append(p_target);
}
void GDScriptByteCodeGenerator::write_or_left_operand(const Address &p_left_operand) {
- append(GDScriptFunction::OPCODE_JUMP_IF);
+ append(GDScriptFunction::OPCODE_JUMP_IF, 1);
append(p_left_operand);
logic_op_jump_pos1.push_back(opcodes.size());
append(0); // Jump target, will be patched.
}
void GDScriptByteCodeGenerator::write_or_right_operand(const Address &p_right_operand) {
- append(GDScriptFunction::OPCODE_JUMP_IF);
+ append(GDScriptFunction::OPCODE_JUMP_IF, 1);
append(p_right_operand);
logic_op_jump_pos2.push_back(opcodes.size());
append(0); // Jump target, will be patched.
@@ -246,17 +402,17 @@ void GDScriptByteCodeGenerator::write_or_right_operand(const Address &p_right_op
void GDScriptByteCodeGenerator::write_end_or(const Address &p_target) {
// If here means both operands are false.
- append(GDScriptFunction::OPCODE_ASSIGN_FALSE);
+ append(GDScriptFunction::OPCODE_ASSIGN_FALSE, 1);
append(p_target);
// Jump away from the success condition.
- append(GDScriptFunction::OPCODE_JUMP);
+ append(GDScriptFunction::OPCODE_JUMP, 0);
append(opcodes.size() + 3);
// Here it means one of operands is false.
patch_jump(logic_op_jump_pos1.back()->get());
patch_jump(logic_op_jump_pos2.back()->get());
logic_op_jump_pos1.pop_back();
logic_op_jump_pos2.pop_back();
- append(GDScriptFunction::OPCODE_ASSIGN_TRUE);
+ append(GDScriptFunction::OPCODE_ASSIGN_TRUE, 1);
append(p_target);
}
@@ -265,18 +421,18 @@ void GDScriptByteCodeGenerator::write_start_ternary(const Address &p_target) {
}
void GDScriptByteCodeGenerator::write_ternary_condition(const Address &p_condition) {
- append(GDScriptFunction::OPCODE_JUMP_IF_NOT);
+ append(GDScriptFunction::OPCODE_JUMP_IF_NOT, 1);
append(p_condition);
ternary_jump_fail_pos.push_back(opcodes.size());
append(0); // Jump target, will be patched.
}
void GDScriptByteCodeGenerator::write_ternary_true_expr(const Address &p_expr) {
- append(GDScriptFunction::OPCODE_ASSIGN);
+ append(GDScriptFunction::OPCODE_ASSIGN, 2);
append(ternary_result.back()->get());
append(p_expr);
// Jump away from the false path.
- append(GDScriptFunction::OPCODE_JUMP);
+ append(GDScriptFunction::OPCODE_JUMP, 0);
ternary_jump_skip_pos.push_back(opcodes.size());
append(0);
// Fail must jump here.
@@ -285,7 +441,7 @@ void GDScriptByteCodeGenerator::write_ternary_true_expr(const Address &p_expr) {
}
void GDScriptByteCodeGenerator::write_ternary_false_expr(const Address &p_expr) {
- append(GDScriptFunction::OPCODE_ASSIGN);
+ append(GDScriptFunction::OPCODE_ASSIGN, 2);
append(ternary_result.back()->get());
append(p_expr);
}
@@ -296,43 +452,100 @@ void GDScriptByteCodeGenerator::write_end_ternary() {
}
void GDScriptByteCodeGenerator::write_set(const Address &p_target, const Address &p_index, const Address &p_source) {
- append(GDScriptFunction::OPCODE_SET);
+ if (HAS_BUILTIN_TYPE(p_target)) {
+ if (IS_BUILTIN_TYPE(p_index, Variant::INT) && Variant::get_member_validated_indexed_setter(p_target.type.builtin_type)) {
+ // Use indexed setter instead.
+ Variant::ValidatedIndexedSetter setter = Variant::get_member_validated_indexed_setter(p_target.type.builtin_type);
+ append(GDScriptFunction::OPCODE_SET_INDEXED_VALIDATED, 3);
+ append(p_target);
+ append(p_index);
+ append(p_source);
+ append(setter);
+ return;
+ } else if (Variant::get_member_validated_keyed_setter(p_target.type.builtin_type)) {
+ Variant::ValidatedKeyedSetter setter = Variant::get_member_validated_keyed_setter(p_target.type.builtin_type);
+ append(GDScriptFunction::OPCODE_SET_KEYED_VALIDATED, 3);
+ append(p_target);
+ append(p_index);
+ append(p_source);
+ append(setter);
+ return;
+ }
+ }
+
+ append(GDScriptFunction::OPCODE_SET_KEYED, 3);
append(p_target);
append(p_index);
append(p_source);
}
void GDScriptByteCodeGenerator::write_get(const Address &p_target, const Address &p_index, const Address &p_source) {
- append(GDScriptFunction::OPCODE_GET);
+ if (HAS_BUILTIN_TYPE(p_source)) {
+ if (IS_BUILTIN_TYPE(p_index, Variant::INT) && Variant::get_member_validated_indexed_getter(p_source.type.builtin_type)) {
+ // Use indexed getter instead.
+ Variant::ValidatedIndexedGetter getter = Variant::get_member_validated_indexed_getter(p_source.type.builtin_type);
+ append(GDScriptFunction::OPCODE_GET_INDEXED_VALIDATED, 3);
+ append(p_source);
+ append(p_index);
+ append(p_target);
+ append(getter);
+ return;
+ } else if (Variant::get_member_validated_keyed_getter(p_source.type.builtin_type)) {
+ Variant::ValidatedKeyedGetter getter = Variant::get_member_validated_keyed_getter(p_source.type.builtin_type);
+ append(GDScriptFunction::OPCODE_GET_KEYED_VALIDATED, 3);
+ append(p_source);
+ append(p_index);
+ append(p_target);
+ append(getter);
+ return;
+ }
+ }
+ append(GDScriptFunction::OPCODE_GET_KEYED, 3);
append(p_source);
append(p_index);
append(p_target);
}
void GDScriptByteCodeGenerator::write_set_named(const Address &p_target, const StringName &p_name, const Address &p_source) {
- append(GDScriptFunction::OPCODE_SET_NAMED);
+ if (HAS_BUILTIN_TYPE(p_target) && Variant::get_member_validated_setter(p_target.type.builtin_type, p_name)) {
+ Variant::ValidatedSetter setter = Variant::get_member_validated_setter(p_target.type.builtin_type, p_name);
+ append(GDScriptFunction::OPCODE_SET_NAMED_VALIDATED, 2);
+ append(p_target);
+ append(p_source);
+ append(setter);
+ return;
+ }
+ append(GDScriptFunction::OPCODE_SET_NAMED, 2);
append(p_target);
- append(p_name);
append(p_source);
+ append(p_name);
}
void GDScriptByteCodeGenerator::write_get_named(const Address &p_target, const StringName &p_name, const Address &p_source) {
- append(GDScriptFunction::OPCODE_GET_NAMED);
+ if (HAS_BUILTIN_TYPE(p_source) && Variant::get_member_validated_getter(p_source.type.builtin_type, p_name)) {
+ Variant::ValidatedGetter getter = Variant::get_member_validated_getter(p_source.type.builtin_type, p_name);
+ append(GDScriptFunction::OPCODE_GET_NAMED_VALIDATED, 2);
+ append(p_source);
+ append(p_target);
+ append(getter);
+ return;
+ }
+ append(GDScriptFunction::OPCODE_GET_NAMED, 2);
append(p_source);
- append(p_name);
append(p_target);
+ append(p_name);
}
void GDScriptByteCodeGenerator::write_set_member(const Address &p_value, const StringName &p_name) {
- append(GDScriptFunction::OPCODE_SET_MEMBER);
- append(p_name);
+ append(GDScriptFunction::OPCODE_SET_MEMBER, 1);
append(p_value);
+ append(p_name);
}
void GDScriptByteCodeGenerator::write_get_member(const Address &p_target, const StringName &p_name) {
- append(GDScriptFunction::OPCODE_GET_MEMBER);
- append(p_name);
+ append(GDScriptFunction::OPCODE_GET_MEMBER, 1);
append(p_target);
+ append(p_name);
}
void GDScriptByteCodeGenerator::write_assign(const Address &p_target, const Address &p_source) {
@@ -340,34 +553,35 @@ void GDScriptByteCodeGenerator::write_assign(const Address &p_target, const Addr
// Typed assignment.
switch (p_target.type.kind) {
case GDScriptDataType::BUILTIN: {
- append(GDScriptFunction::OPCODE_ASSIGN_TYPED_BUILTIN);
- append(p_target.type.builtin_type);
+ append(GDScriptFunction::OPCODE_ASSIGN_TYPED_BUILTIN, 2);
append(p_target);
append(p_source);
+ append(p_target.type.builtin_type);
} break;
case GDScriptDataType::NATIVE: {
int class_idx = GDScriptLanguage::get_singleton()->get_global_map()[p_target.type.native_type];
class_idx |= (GDScriptFunction::ADDR_TYPE_GLOBAL << GDScriptFunction::ADDR_BITS);
- append(GDScriptFunction::OPCODE_ASSIGN_TYPED_NATIVE);
- append(class_idx);
+ append(GDScriptFunction::OPCODE_ASSIGN_TYPED_NATIVE, 3);
append(p_target);
append(p_source);
+ append(class_idx);
} break;
case GDScriptDataType::SCRIPT:
case GDScriptDataType::GDSCRIPT: {
Variant script = p_target.type.script_type;
int idx = get_constant_pos(script);
+ idx |= (GDScriptFunction::ADDR_TYPE_LOCAL_CONSTANT << GDScriptFunction::ADDR_BITS);
- append(GDScriptFunction::OPCODE_ASSIGN_TYPED_SCRIPT);
- append(idx);
+ append(GDScriptFunction::OPCODE_ASSIGN_TYPED_SCRIPT, 3);
append(p_target);
append(p_source);
+ append(idx);
} break;
default: {
ERR_PRINT("Compiler bug: unresolved assign.");
// Shouldn't get here, but fail-safe to a regular assignment
- append(GDScriptFunction::OPCODE_ASSIGN);
+ append(GDScriptFunction::OPCODE_ASSIGN, 2);
append(p_target);
append(p_source);
}
@@ -375,13 +589,13 @@ void GDScriptByteCodeGenerator::write_assign(const Address &p_target, const Addr
} else {
if (p_target.type.kind == GDScriptDataType::BUILTIN && p_source.type.kind == GDScriptDataType::BUILTIN && p_target.type.builtin_type != p_source.type.builtin_type) {
// Need conversion..
- append(GDScriptFunction::OPCODE_ASSIGN_TYPED_BUILTIN);
- append(p_target.type.builtin_type);
+ append(GDScriptFunction::OPCODE_ASSIGN_TYPED_BUILTIN, 2);
append(p_target);
append(p_source);
+ append(p_target.type.builtin_type);
} else {
// Either untyped assignment or already type-checked by the parser
- append(GDScriptFunction::OPCODE_ASSIGN);
+ append(GDScriptFunction::OPCODE_ASSIGN, 2);
append(p_target);
append(p_source);
}
@@ -389,34 +603,37 @@ void GDScriptByteCodeGenerator::write_assign(const Address &p_target, const Addr
}
void GDScriptByteCodeGenerator::write_assign_true(const Address &p_target) {
- append(GDScriptFunction::OPCODE_ASSIGN_TRUE);
+ append(GDScriptFunction::OPCODE_ASSIGN_TRUE, 1);
append(p_target);
}
void GDScriptByteCodeGenerator::write_assign_false(const Address &p_target) {
- append(GDScriptFunction::OPCODE_ASSIGN_FALSE);
+ append(GDScriptFunction::OPCODE_ASSIGN_FALSE, 1);
append(p_target);
}
void GDScriptByteCodeGenerator::write_cast(const Address &p_target, const Address &p_source, const GDScriptDataType &p_type) {
+ int index = 0;
+
switch (p_type.kind) {
case GDScriptDataType::BUILTIN: {
- append(GDScriptFunction::OPCODE_CAST_TO_BUILTIN);
- append(p_type.builtin_type);
+ append(GDScriptFunction::OPCODE_CAST_TO_BUILTIN, 2);
+ index = p_type.builtin_type;
} break;
case GDScriptDataType::NATIVE: {
int class_idx = GDScriptLanguage::get_singleton()->get_global_map()[p_type.native_type];
class_idx |= (GDScriptFunction::ADDR_TYPE_GLOBAL << GDScriptFunction::ADDR_BITS);
- append(GDScriptFunction::OPCODE_CAST_TO_NATIVE);
- append(class_idx);
+ append(GDScriptFunction::OPCODE_CAST_TO_NATIVE, 3);
+ index = class_idx;
} break;
case GDScriptDataType::SCRIPT:
case GDScriptDataType::GDSCRIPT: {
Variant script = p_type.script_type;
int idx = get_constant_pos(script);
+ idx |= (GDScriptFunction::ADDR_TYPE_LOCAL_CONSTANT << GDScriptFunction::ADDR_BITS);
- append(GDScriptFunction::OPCODE_CAST_TO_SCRIPT);
- append(idx);
+ append(GDScriptFunction::OPCODE_CAST_TO_SCRIPT, 3);
+ index = idx;
} break;
default: {
return;
@@ -425,147 +642,272 @@ void GDScriptByteCodeGenerator::write_cast(const Address &p_target, const Addres
append(p_source);
append(p_target);
+ append(index);
}
void GDScriptByteCodeGenerator::write_call(const Address &p_target, const Address &p_base, const StringName &p_function_name, const Vector<Address> &p_arguments) {
- append(p_target.mode == Address::NIL ? GDScriptFunction::OPCODE_CALL : GDScriptFunction::OPCODE_CALL_RETURN);
- append(p_arguments.size());
- append(p_base);
- append(p_function_name);
+ append(p_target.mode == Address::NIL ? GDScriptFunction::OPCODE_CALL : GDScriptFunction::OPCODE_CALL_RETURN, 2 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
+ append(p_base);
append(p_target);
- alloc_call(p_arguments.size());
+ append(p_arguments.size());
+ append(p_function_name);
}
void GDScriptByteCodeGenerator::write_super_call(const Address &p_target, const StringName &p_function_name, const Vector<Address> &p_arguments) {
- append(GDScriptFunction::OPCODE_CALL_SELF_BASE);
- append(p_function_name);
- append(p_arguments.size());
+ append(GDScriptFunction::OPCODE_CALL_SELF_BASE, 1 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
append(p_target);
- alloc_call(p_arguments.size());
+ append(p_arguments.size());
+ append(p_function_name);
}
void GDScriptByteCodeGenerator::write_call_async(const Address &p_target, const Address &p_base, const StringName &p_function_name, const Vector<Address> &p_arguments) {
- append(GDScriptFunction::OPCODE_CALL_ASYNC);
- append(p_arguments.size());
- append(p_base);
- append(p_function_name);
+ append(GDScriptFunction::OPCODE_CALL_ASYNC, 2 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
+ append(p_base);
append(p_target);
- alloc_call(p_arguments.size());
+ append(p_arguments.size());
+ append(p_function_name);
}
void GDScriptByteCodeGenerator::write_call_builtin(const Address &p_target, GDScriptFunctions::Function p_function, const Vector<Address> &p_arguments) {
- append(GDScriptFunction::OPCODE_CALL_BUILT_IN);
- append(p_function);
- append(p_arguments.size());
+ append(GDScriptFunction::OPCODE_CALL_BUILT_IN, 1 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
append(p_target);
- alloc_call(p_arguments.size());
+ append(p_arguments.size());
+ append(p_function);
}
-void GDScriptByteCodeGenerator::write_call_method_bind(const Address &p_target, const Address &p_base, const MethodBind *p_method, const Vector<Address> &p_arguments) {
- append(p_target.mode == Address::NIL ? GDScriptFunction::OPCODE_CALL : GDScriptFunction::OPCODE_CALL_RETURN);
- append(p_arguments.size());
- append(p_base);
- append(p_method->get_name());
+void GDScriptByteCodeGenerator::write_call_builtin_type(const Address &p_target, const Address &p_base, Variant::Type p_type, const StringName &p_method, const Vector<Address> &p_arguments) {
+ bool is_validated = false;
+
+ // Check if all types are correct.
+ if (Variant::is_builtin_method_vararg(p_type, p_method)) {
+ is_validated = true; // Vararg works fine with any argument, since they can be any type.
+ } else if (p_arguments.size() == Variant::get_builtin_method_argument_count(p_type, p_method)) {
+ bool all_types_exact = true;
+ for (int i = 0; i < p_arguments.size(); i++) {
+ if (!IS_BUILTIN_TYPE(p_arguments[i], Variant::get_builtin_method_argument_type(p_type, p_method, i))) {
+ all_types_exact = false;
+ break;
+ }
+ }
+
+ is_validated = all_types_exact;
+ }
+
+ if (!is_validated) {
+ // Perform regular call.
+ write_call(p_target, p_base, p_method, p_arguments);
+ return;
+ }
+
+ append(GDScriptFunction::OPCODE_CALL_BUILTIN_TYPE_VALIDATED, 2 + p_arguments.size());
+
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
+ append(p_base);
append(p_target);
- alloc_call(p_arguments.size());
+ append(p_arguments.size());
+ append(Variant::get_validated_builtin_method(p_type, p_method));
}
-void GDScriptByteCodeGenerator::write_call_ptrcall(const Address &p_target, const Address &p_base, const MethodBind *p_method, const Vector<Address> &p_arguments) {
- append(p_target.mode == Address::NIL ? GDScriptFunction::OPCODE_CALL : GDScriptFunction::OPCODE_CALL_RETURN);
- append(p_arguments.size());
+void GDScriptByteCodeGenerator::write_call_method_bind(const Address &p_target, const Address &p_base, MethodBind *p_method, const Vector<Address> &p_arguments) {
+ append(p_target.mode == Address::NIL ? GDScriptFunction::OPCODE_CALL_METHOD_BIND : GDScriptFunction::OPCODE_CALL_METHOD_BIND_RET, 2 + p_arguments.size());
+ for (int i = 0; i < p_arguments.size(); i++) {
+ append(p_arguments[i]);
+ }
append(p_base);
- append(p_method->get_name());
+ append(p_target);
+ append(p_arguments.size());
+ append(p_method);
+}
+
+void GDScriptByteCodeGenerator::write_call_ptrcall(const Address &p_target, const Address &p_base, MethodBind *p_method, const Vector<Address> &p_arguments) {
+#define CASE_TYPE(m_type) \
+ case Variant::m_type: \
+ append(GDScriptFunction::OPCODE_CALL_PTRCALL_##m_type, 2 + p_arguments.size()); \
+ break
+
+ bool is_ptrcall = true;
+
+ if (p_method->has_return()) {
+ MethodInfo info;
+ ClassDB::get_method_info(p_method->get_instance_class(), p_method->get_name(), &info);
+ switch (info.return_val.type) {
+ CASE_TYPE(BOOL);
+ CASE_TYPE(INT);
+ CASE_TYPE(FLOAT);
+ CASE_TYPE(STRING);
+ CASE_TYPE(VECTOR2);
+ CASE_TYPE(VECTOR2I);
+ CASE_TYPE(RECT2);
+ CASE_TYPE(RECT2I);
+ CASE_TYPE(VECTOR3);
+ CASE_TYPE(VECTOR3I);
+ CASE_TYPE(TRANSFORM2D);
+ CASE_TYPE(PLANE);
+ CASE_TYPE(AABB);
+ CASE_TYPE(BASIS);
+ CASE_TYPE(TRANSFORM);
+ CASE_TYPE(COLOR);
+ CASE_TYPE(STRING_NAME);
+ CASE_TYPE(NODE_PATH);
+ CASE_TYPE(RID);
+ CASE_TYPE(QUAT);
+ CASE_TYPE(OBJECT);
+ CASE_TYPE(CALLABLE);
+ CASE_TYPE(SIGNAL);
+ CASE_TYPE(DICTIONARY);
+ CASE_TYPE(ARRAY);
+ CASE_TYPE(PACKED_BYTE_ARRAY);
+ CASE_TYPE(PACKED_INT32_ARRAY);
+ CASE_TYPE(PACKED_INT64_ARRAY);
+ CASE_TYPE(PACKED_FLOAT32_ARRAY);
+ CASE_TYPE(PACKED_FLOAT64_ARRAY);
+ CASE_TYPE(PACKED_STRING_ARRAY);
+ CASE_TYPE(PACKED_VECTOR2_ARRAY);
+ CASE_TYPE(PACKED_VECTOR3_ARRAY);
+ CASE_TYPE(PACKED_COLOR_ARRAY);
+ default:
+ append(p_target.mode == Address::NIL ? GDScriptFunction::OPCODE_CALL_METHOD_BIND : GDScriptFunction::OPCODE_CALL_METHOD_BIND_RET, 2 + p_arguments.size());
+ is_ptrcall = false;
+ break;
+ }
+ } else {
+ append(GDScriptFunction::OPCODE_CALL_PTRCALL_NO_RETURN, 2 + p_arguments.size());
+ }
+
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
+ append(p_base);
append(p_target);
- alloc_call(p_arguments.size());
+ append(p_arguments.size());
+ append(p_method);
+ if (is_ptrcall) {
+ alloc_ptrcall(p_arguments.size());
+ }
+
+#undef CASE_TYPE
}
void GDScriptByteCodeGenerator::write_call_self(const Address &p_target, const StringName &p_function_name, const Vector<Address> &p_arguments) {
- append(p_target.mode == Address::NIL ? GDScriptFunction::OPCODE_CALL : GDScriptFunction::OPCODE_CALL_RETURN);
- append(p_arguments.size());
- append(GDScriptFunction::ADDR_TYPE_SELF << GDScriptFunction::ADDR_BITS);
- append(p_function_name);
+ append(p_target.mode == Address::NIL ? GDScriptFunction::OPCODE_CALL : GDScriptFunction::OPCODE_CALL_RETURN, 2 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
+ append(GDScriptFunction::ADDR_TYPE_SELF << GDScriptFunction::ADDR_BITS);
append(p_target);
- alloc_call(p_arguments.size());
+ append(p_arguments.size());
+ append(p_function_name);
}
void GDScriptByteCodeGenerator::write_call_script_function(const Address &p_target, const Address &p_base, const StringName &p_function_name, const Vector<Address> &p_arguments) {
- append(p_target.mode == Address::NIL ? GDScriptFunction::OPCODE_CALL : GDScriptFunction::OPCODE_CALL_RETURN);
- append(p_arguments.size());
- append(p_base);
- append(p_function_name);
+ append(p_target.mode == Address::NIL ? GDScriptFunction::OPCODE_CALL : GDScriptFunction::OPCODE_CALL_RETURN, 2 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
+ append(p_base);
append(p_target);
- alloc_call(p_arguments.size());
+ append(p_arguments.size());
+ append(p_function_name);
}
void GDScriptByteCodeGenerator::write_construct(const Address &p_target, Variant::Type p_type, const Vector<Address> &p_arguments) {
- append(GDScriptFunction::OPCODE_CONSTRUCT);
- append(p_type);
- append(p_arguments.size());
+ // Try to find an appropriate constructor.
+ bool all_have_type = true;
+ Vector<Variant::Type> arg_types;
+ for (int i = 0; i < p_arguments.size(); i++) {
+ if (!HAS_BUILTIN_TYPE(p_arguments[i])) {
+ all_have_type = false;
+ break;
+ }
+ arg_types.push_back(p_arguments[i].type.builtin_type);
+ }
+ if (all_have_type) {
+ int valid_constructor = -1;
+ for (int i = 0; i < Variant::get_constructor_count(p_type); i++) {
+ if (Variant::get_constructor_argument_count(p_type, i) != p_arguments.size()) {
+ continue;
+ }
+ int types_correct = true;
+ for (int j = 0; j < arg_types.size(); j++) {
+ if (arg_types[j] != Variant::get_constructor_argument_type(p_type, i, j)) {
+ types_correct = false;
+ break;
+ }
+ }
+ if (types_correct) {
+ valid_constructor = i;
+ break;
+ }
+ }
+ if (valid_constructor >= 0) {
+ append(GDScriptFunction::OPCODE_CONSTRUCT_VALIDATED, 1 + p_arguments.size());
+ for (int i = 0; i < p_arguments.size(); i++) {
+ append(p_arguments[i]);
+ }
+ append(p_target);
+ append(p_arguments.size());
+ append(Variant::get_validated_constructor(p_type, valid_constructor));
+ return;
+ }
+ }
+
+ append(GDScriptFunction::OPCODE_CONSTRUCT, 1 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
append(p_target);
- alloc_call(p_arguments.size());
+ append(p_arguments.size());
+ append(p_type);
}
void GDScriptByteCodeGenerator::write_construct_array(const Address &p_target, const Vector<Address> &p_arguments) {
- append(GDScriptFunction::OPCODE_CONSTRUCT_ARRAY);
- append(p_arguments.size());
+ append(GDScriptFunction::OPCODE_CONSTRUCT_ARRAY, 1 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
append(p_target);
+ append(p_arguments.size());
}
void GDScriptByteCodeGenerator::write_construct_dictionary(const Address &p_target, const Vector<Address> &p_arguments) {
- append(GDScriptFunction::OPCODE_CONSTRUCT_DICTIONARY);
- append(p_arguments.size() / 2); // This is number of key-value pairs, so only half of actual arguments.
+ append(GDScriptFunction::OPCODE_CONSTRUCT_DICTIONARY, 1 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
append(p_target);
+ append(p_arguments.size() / 2); // This is number of key-value pairs, so only half of actual arguments.
}
void GDScriptByteCodeGenerator::write_await(const Address &p_target, const Address &p_operand) {
- append(GDScriptFunction::OPCODE_AWAIT);
+ append(GDScriptFunction::OPCODE_AWAIT, 1);
append(p_operand);
- append(GDScriptFunction::OPCODE_AWAIT_RESUME);
+ append(GDScriptFunction::OPCODE_AWAIT_RESUME, 1);
append(p_target);
}
void GDScriptByteCodeGenerator::write_if(const Address &p_condition) {
- append(GDScriptFunction::OPCODE_JUMP_IF_NOT);
+ append(GDScriptFunction::OPCODE_JUMP_IF_NOT, 1);
append(p_condition);
if_jmp_addrs.push_back(opcodes.size());
append(0); // Jump destination, will be patched.
}
void GDScriptByteCodeGenerator::write_else() {
- append(GDScriptFunction::OPCODE_JUMP); // Jump from true if block;
+ append(GDScriptFunction::OPCODE_JUMP, 0); // Jump from true if block;
int else_jmp_addr = opcodes.size();
append(0); // Jump destination, will be patched.
@@ -579,41 +921,144 @@ void GDScriptByteCodeGenerator::write_endif() {
if_jmp_addrs.pop_back();
}
-void GDScriptByteCodeGenerator::write_for(const Address &p_variable, const Address &p_list) {
- int counter_pos = add_temporary() | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS);
- int container_pos = add_temporary() | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS);
+void GDScriptByteCodeGenerator::start_for(const GDScriptDataType &p_iterator_type, const GDScriptDataType &p_list_type) {
+ Address counter(Address::LOCAL_VARIABLE, add_local("@counter_pos", p_iterator_type), p_iterator_type);
+ Address container(Address::LOCAL_VARIABLE, add_local("@container_pos", p_list_type), p_list_type);
- current_breaks_to_patch.push_back(List<int>());
+ // Store state.
+ for_counter_variables.push_back(counter);
+ for_container_variables.push_back(container);
+}
+
+void GDScriptByteCodeGenerator::write_for_assignment(const Address &p_variable, const Address &p_list) {
+ const Address &container = for_container_variables.back()->get();
// Assign container.
- append(GDScriptFunction::OPCODE_ASSIGN);
- append(container_pos);
+ append(GDScriptFunction::OPCODE_ASSIGN, 2);
+ append(container);
append(p_list);
+ for_iterator_variables.push_back(p_variable);
+}
+
+void GDScriptByteCodeGenerator::write_for() {
+ const Address &iterator = for_iterator_variables.back()->get();
+ const Address &counter = for_counter_variables.back()->get();
+ const Address &container = for_container_variables.back()->get();
+
+ current_breaks_to_patch.push_back(List<int>());
+
+ GDScriptFunction::Opcode begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN;
+ GDScriptFunction::Opcode iterate_opcode = GDScriptFunction::OPCODE_ITERATE;
+
+ if (container.type.has_type) {
+ if (container.type.kind == GDScriptDataType::BUILTIN) {
+ switch (container.type.builtin_type) {
+ case Variant::INT:
+ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_INT;
+ iterate_opcode = GDScriptFunction::OPCODE_ITERATE_INT;
+ break;
+ case Variant::FLOAT:
+ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_FLOAT;
+ iterate_opcode = GDScriptFunction::OPCODE_ITERATE_FLOAT;
+ break;
+ case Variant::VECTOR2:
+ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_VECTOR2;
+ iterate_opcode = GDScriptFunction::OPCODE_ITERATE_VECTOR2;
+ break;
+ case Variant::VECTOR2I:
+ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_VECTOR2I;
+ iterate_opcode = GDScriptFunction::OPCODE_ITERATE_VECTOR2I;
+ break;
+ case Variant::VECTOR3:
+ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_VECTOR3;
+ iterate_opcode = GDScriptFunction::OPCODE_ITERATE_VECTOR3;
+ break;
+ case Variant::VECTOR3I:
+ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_VECTOR3I;
+ iterate_opcode = GDScriptFunction::OPCODE_ITERATE_VECTOR3I;
+ break;
+ case Variant::STRING:
+ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_STRING;
+ iterate_opcode = GDScriptFunction::OPCODE_ITERATE_STRING;
+ break;
+ case Variant::DICTIONARY:
+ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_DICTIONARY;
+ iterate_opcode = GDScriptFunction::OPCODE_ITERATE_DICTIONARY;
+ break;
+ case Variant::ARRAY:
+ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_ARRAY;
+ iterate_opcode = GDScriptFunction::OPCODE_ITERATE_ARRAY;
+ break;
+ case Variant::PACKED_BYTE_ARRAY:
+ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_PACKED_BYTE_ARRAY;
+ iterate_opcode = GDScriptFunction::OPCODE_ITERATE_PACKED_BYTE_ARRAY;
+ break;
+ case Variant::PACKED_INT32_ARRAY:
+ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_PACKED_INT32_ARRAY;
+ iterate_opcode = GDScriptFunction::OPCODE_ITERATE_PACKED_INT32_ARRAY;
+ break;
+ case Variant::PACKED_INT64_ARRAY:
+ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_PACKED_INT64_ARRAY;
+ iterate_opcode = GDScriptFunction::OPCODE_ITERATE_PACKED_INT64_ARRAY;
+ break;
+ case Variant::PACKED_FLOAT32_ARRAY:
+ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_PACKED_FLOAT32_ARRAY;
+ iterate_opcode = GDScriptFunction::OPCODE_ITERATE_PACKED_FLOAT32_ARRAY;
+ break;
+ case Variant::PACKED_FLOAT64_ARRAY:
+ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_PACKED_FLOAT64_ARRAY;
+ iterate_opcode = GDScriptFunction::OPCODE_ITERATE_PACKED_FLOAT64_ARRAY;
+ break;
+ case Variant::PACKED_STRING_ARRAY:
+ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_PACKED_STRING_ARRAY;
+ iterate_opcode = GDScriptFunction::OPCODE_ITERATE_PACKED_STRING_ARRAY;
+ break;
+ case Variant::PACKED_VECTOR2_ARRAY:
+ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_PACKED_VECTOR2_ARRAY;
+ iterate_opcode = GDScriptFunction::OPCODE_ITERATE_PACKED_VECTOR2_ARRAY;
+ break;
+ case Variant::PACKED_VECTOR3_ARRAY:
+ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_PACKED_VECTOR3_ARRAY;
+ iterate_opcode = GDScriptFunction::OPCODE_ITERATE_PACKED_VECTOR3_ARRAY;
+ break;
+ case Variant::PACKED_COLOR_ARRAY:
+ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_PACKED_COLOR_ARRAY;
+ iterate_opcode = GDScriptFunction::OPCODE_ITERATE_PACKED_COLOR_ARRAY;
+ break;
+ default:
+ break;
+ }
+ } else {
+ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_OBJECT;
+ iterate_opcode = GDScriptFunction::OPCODE_ITERATE_OBJECT;
+ }
+ }
+
// Begin loop.
- append(GDScriptFunction::OPCODE_ITERATE_BEGIN);
- append(counter_pos);
- append(container_pos);
+ append(begin_opcode, 3);
+ append(counter);
+ append(container);
+ append(iterator);
for_jmp_addrs.push_back(opcodes.size());
append(0); // End of loop address, will be patched.
- append(p_variable);
- append(GDScriptFunction::OPCODE_JUMP);
+ append(GDScriptFunction::OPCODE_JUMP, 0);
append(opcodes.size() + 6); // Skip over 'continue' code.
// Next iteration.
int continue_addr = opcodes.size();
continue_addrs.push_back(continue_addr);
- append(GDScriptFunction::OPCODE_ITERATE);
- append(counter_pos);
- append(container_pos);
+ append(iterate_opcode, 3);
+ append(counter);
+ append(container);
+ append(iterator);
for_jmp_addrs.push_back(opcodes.size());
append(0); // Jump destination, will be patched.
- append(p_variable);
}
void GDScriptByteCodeGenerator::write_endfor() {
// Jump back to loop check.
- append(GDScriptFunction::OPCODE_JUMP);
+ append(GDScriptFunction::OPCODE_JUMP, 0);
append(continue_addrs.back()->get());
continue_addrs.pop_back();
@@ -629,9 +1074,10 @@ void GDScriptByteCodeGenerator::write_endfor() {
}
current_breaks_to_patch.pop_back();
- // Remove loop temporaries.
- pop_temporary();
- pop_temporary();
+ // Pop state.
+ for_iterator_variables.pop_back();
+ for_counter_variables.pop_back();
+ for_container_variables.pop_back();
}
void GDScriptByteCodeGenerator::start_while_condition() {
@@ -641,7 +1087,7 @@ void GDScriptByteCodeGenerator::start_while_condition() {
void GDScriptByteCodeGenerator::write_while(const Address &p_condition) {
// Condition check.
- append(GDScriptFunction::OPCODE_JUMP_IF_NOT);
+ append(GDScriptFunction::OPCODE_JUMP_IF_NOT, 1);
append(p_condition);
while_jmp_addrs.push_back(opcodes.size());
append(0); // End of loop address, will be patched.
@@ -649,7 +1095,7 @@ void GDScriptByteCodeGenerator::write_while(const Address &p_condition) {
void GDScriptByteCodeGenerator::write_endwhile() {
// Jump back to loop check.
- append(GDScriptFunction::OPCODE_JUMP);
+ append(GDScriptFunction::OPCODE_JUMP, 0);
append(continue_addrs.back()->get());
continue_addrs.pop_back();
@@ -687,39 +1133,39 @@ void GDScriptByteCodeGenerator::end_match() {
}
void GDScriptByteCodeGenerator::write_break() {
- append(GDScriptFunction::OPCODE_JUMP);
+ append(GDScriptFunction::OPCODE_JUMP, 0);
current_breaks_to_patch.back()->get().push_back(opcodes.size());
append(0);
}
void GDScriptByteCodeGenerator::write_continue() {
- append(GDScriptFunction::OPCODE_JUMP);
+ append(GDScriptFunction::OPCODE_JUMP, 0);
append(continue_addrs.back()->get());
}
void GDScriptByteCodeGenerator::write_continue_match() {
- append(GDScriptFunction::OPCODE_JUMP);
+ append(GDScriptFunction::OPCODE_JUMP, 0);
match_continues_to_patch.back()->get().push_back(opcodes.size());
append(0);
}
void GDScriptByteCodeGenerator::write_breakpoint() {
- append(GDScriptFunction::OPCODE_BREAKPOINT);
+ append(GDScriptFunction::OPCODE_BREAKPOINT, 0);
}
void GDScriptByteCodeGenerator::write_newline(int p_line) {
- append(GDScriptFunction::OPCODE_LINE);
+ append(GDScriptFunction::OPCODE_LINE, 0);
append(p_line);
current_line = p_line;
}
void GDScriptByteCodeGenerator::write_return(const Address &p_return_value) {
- append(GDScriptFunction::OPCODE_RETURN);
+ append(GDScriptFunction::OPCODE_RETURN, 1);
append(p_return_value);
}
void GDScriptByteCodeGenerator::write_assert(const Address &p_test, const Address &p_message) {
- append(GDScriptFunction::OPCODE_ASSERT);
+ append(GDScriptFunction::OPCODE_ASSERT, 2);
append(p_test);
append(p_message);
}
diff --git a/modules/gdscript/gdscript_byte_codegen.h b/modules/gdscript/gdscript_byte_codegen.h
index 62438b6dd2..0173b7f820 100644
--- a/modules/gdscript/gdscript_byte_codegen.h
+++ b/modules/gdscript/gdscript_byte_codegen.h
@@ -33,6 +33,8 @@
#include "gdscript_codegen.h"
+#include "gdscript_function.h"
+
class GDScriptByteCodeGenerator : public GDScriptCodeGenerator {
bool ended = false;
GDScriptFunction *function = nullptr;
@@ -41,6 +43,7 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator {
Vector<int> opcodes;
List<Map<StringName, int>> stack_id_stack;
Map<StringName, int> stack_identifiers;
+ List<int> stack_identifiers_counts;
Map<StringName, int> local_constants;
List<GDScriptFunction::StackDebug> stack_debug;
@@ -49,18 +52,38 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator {
int current_stack_size = 0;
int current_temporaries = 0;
+ int current_locals = 0;
+ int current_line = 0;
+ int stack_max = 0;
+ int instr_args_max = 0;
+ int ptrcall_max = 0;
+
+#ifdef DEBUG_ENABLED
+ List<int> temp_stack;
+#endif
HashMap<Variant, int, VariantHasher, VariantComparator> constant_map;
Map<StringName, int> name_map;
#ifdef TOOLS_ENABLED
Vector<StringName> named_globals;
#endif
- int current_line = 0;
- int stack_max = 0;
- int call_max = 0;
-
- List<int> if_jmp_addrs; // List since this can be nested.
+ Map<Variant::ValidatedOperatorEvaluator, int> operator_func_map;
+ Map<Variant::ValidatedSetter, int> setters_map;
+ Map<Variant::ValidatedGetter, int> getters_map;
+ Map<Variant::ValidatedKeyedSetter, int> keyed_setters_map;
+ Map<Variant::ValidatedKeyedGetter, int> keyed_getters_map;
+ Map<Variant::ValidatedIndexedSetter, int> indexed_setters_map;
+ Map<Variant::ValidatedIndexedGetter, int> indexed_getters_map;
+ Map<Variant::ValidatedBuiltInMethod, int> builtin_method_map;
+ Map<Variant::ValidatedConstructor, int> constructors_map;
+ Map<MethodBind *, int> method_bind_map;
+
+ // Lists since these can be nested.
+ List<int> if_jmp_addrs;
List<int> for_jmp_addrs;
+ List<Address> for_iterator_variables;
+ List<Address> for_counter_variables;
+ List<Address> for_container_variables;
List<int> while_jmp_addrs;
List<int> continue_addrs;
@@ -76,6 +99,7 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator {
List<List<int>> match_continues_to_patch;
void add_stack_identifier(const StringName &p_id, int p_stackpos) {
+ current_locals++;
stack_identifiers[p_id] = p_stackpos;
if (debug_stack) {
block_identifiers[p_id] = p_stackpos;
@@ -89,17 +113,26 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator {
}
void push_stack_identifiers() {
+ stack_identifiers_counts.push_back(current_locals);
stack_id_stack.push_back(stack_identifiers);
if (debug_stack) {
- block_identifier_stack.push_back(block_identifiers);
+ Map<StringName, int> block_ids(block_identifiers);
+ block_identifier_stack.push_back(block_ids);
block_identifiers.clear();
}
}
void pop_stack_identifiers() {
+ current_locals = stack_identifiers_counts.back()->get();
+ stack_identifiers_counts.pop_back();
stack_identifiers = stack_id_stack.back()->get();
- current_stack_size = stack_identifiers.size() + current_temporaries;
stack_id_stack.pop_back();
+#ifdef DEBUG_ENABLED
+ if (current_temporaries != 0) {
+ ERR_PRINT("Leaving block with non-zero temporary variables: " + itos(current_temporaries));
+ }
+#endif
+ current_stack_size = current_locals;
if (debug_stack) {
for (Map<StringName, int>::Element *E = block_identifiers.front(); E; E = E->next()) {
@@ -134,22 +167,105 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator {
return pos;
}
+ int get_operation_pos(const Variant::ValidatedOperatorEvaluator p_operation) {
+ if (operator_func_map.has(p_operation))
+ return operator_func_map[p_operation];
+ int pos = operator_func_map.size();
+ operator_func_map[p_operation] = pos;
+ return pos;
+ }
+
+ int get_setter_pos(const Variant::ValidatedSetter p_setter) {
+ if (setters_map.has(p_setter))
+ return setters_map[p_setter];
+ int pos = setters_map.size();
+ setters_map[p_setter] = pos;
+ return pos;
+ }
+
+ int get_getter_pos(const Variant::ValidatedGetter p_getter) {
+ if (getters_map.has(p_getter))
+ return getters_map[p_getter];
+ int pos = getters_map.size();
+ getters_map[p_getter] = pos;
+ return pos;
+ }
+
+ int get_keyed_setter_pos(const Variant::ValidatedKeyedSetter p_keyed_setter) {
+ if (keyed_setters_map.has(p_keyed_setter))
+ return keyed_setters_map[p_keyed_setter];
+ int pos = keyed_setters_map.size();
+ keyed_setters_map[p_keyed_setter] = pos;
+ return pos;
+ }
+
+ int get_keyed_getter_pos(const Variant::ValidatedKeyedGetter p_keyed_getter) {
+ if (keyed_getters_map.has(p_keyed_getter))
+ return keyed_getters_map[p_keyed_getter];
+ int pos = keyed_getters_map.size();
+ keyed_getters_map[p_keyed_getter] = pos;
+ return pos;
+ }
+
+ int get_indexed_setter_pos(const Variant::ValidatedIndexedSetter p_indexed_setter) {
+ if (indexed_setters_map.has(p_indexed_setter))
+ return indexed_setters_map[p_indexed_setter];
+ int pos = indexed_setters_map.size();
+ indexed_setters_map[p_indexed_setter] = pos;
+ return pos;
+ }
+
+ int get_indexed_getter_pos(const Variant::ValidatedIndexedGetter p_indexed_getter) {
+ if (indexed_getters_map.has(p_indexed_getter))
+ return indexed_getters_map[p_indexed_getter];
+ int pos = indexed_getters_map.size();
+ indexed_getters_map[p_indexed_getter] = pos;
+ return pos;
+ }
+
+ int get_builtin_method_pos(const Variant::ValidatedBuiltInMethod p_method) {
+ if (builtin_method_map.has(p_method)) {
+ return builtin_method_map[p_method];
+ }
+ int pos = builtin_method_map.size();
+ builtin_method_map[p_method] = pos;
+ return pos;
+ }
+
+ int get_constructor_pos(const Variant::ValidatedConstructor p_constructor) {
+ if (constructors_map.has(p_constructor)) {
+ return constructors_map[p_constructor];
+ }
+ int pos = constructors_map.size();
+ constructors_map[p_constructor] = pos;
+ return pos;
+ }
+
+ int get_method_bind_pos(MethodBind *p_method) {
+ if (method_bind_map.has(p_method)) {
+ return method_bind_map[p_method];
+ }
+ int pos = method_bind_map.size();
+ method_bind_map[p_method] = pos;
+ return pos;
+ }
+
void alloc_stack(int p_level) {
if (p_level >= stack_max)
stack_max = p_level + 1;
}
- void alloc_call(int p_params) {
- if (p_params >= call_max)
- call_max = p_params;
- }
-
int increase_stack() {
int top = current_stack_size++;
alloc_stack(current_stack_size);
return top;
}
+ void alloc_ptrcall(int p_params) {
+ if (p_params >= ptrcall_max)
+ ptrcall_max = p_params;
+ }
+
int address_of(const Address &p_address) {
switch (p_address.mode) {
case Address::SELF:
@@ -177,8 +293,13 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator {
return -1; // Unreachable.
}
- void append(int code) {
- opcodes.push_back(code);
+ void append(GDScriptFunction::Opcode p_code, int p_argument_count) {
+ opcodes.push_back((p_code & GDScriptFunction::INSTR_MASK) | (p_argument_count << GDScriptFunction::INSTR_BITS));
+ instr_args_max = MAX(instr_args_max, p_argument_count);
+ }
+
+ void append(int p_code) {
+ opcodes.push_back(p_code);
}
void append(const Address &p_address) {
@@ -189,6 +310,46 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator {
opcodes.push_back(get_name_map_pos(p_name));
}
+ void append(const Variant::ValidatedOperatorEvaluator p_operation) {
+ opcodes.push_back(get_operation_pos(p_operation));
+ }
+
+ void append(const Variant::ValidatedSetter p_setter) {
+ opcodes.push_back(get_setter_pos(p_setter));
+ }
+
+ void append(const Variant::ValidatedGetter p_getter) {
+ opcodes.push_back(get_getter_pos(p_getter));
+ }
+
+ void append(const Variant::ValidatedKeyedSetter p_keyed_setter) {
+ opcodes.push_back(get_keyed_setter_pos(p_keyed_setter));
+ }
+
+ void append(const Variant::ValidatedKeyedGetter p_keyed_getter) {
+ opcodes.push_back(get_keyed_getter_pos(p_keyed_getter));
+ }
+
+ void append(const Variant::ValidatedIndexedSetter p_indexed_setter) {
+ opcodes.push_back(get_indexed_setter_pos(p_indexed_setter));
+ }
+
+ void append(const Variant::ValidatedIndexedGetter p_indexed_getter) {
+ opcodes.push_back(get_indexed_getter_pos(p_indexed_getter));
+ }
+
+ void append(const Variant::ValidatedBuiltInMethod p_method) {
+ opcodes.push_back(get_builtin_method_pos(p_method));
+ }
+
+ void append(const Variant::ValidatedConstructor p_constructor) {
+ opcodes.push_back(get_constructor_pos(p_constructor));
+ }
+
+ void append(MethodBind *p_method) {
+ opcodes.push_back(get_method_bind_pos(p_method));
+ }
+
void patch_jump(int p_address) {
opcodes.write[p_address] = opcodes.size();
}
@@ -244,8 +405,9 @@ public:
virtual void write_super_call(const Address &p_target, const StringName &p_function_name, const Vector<Address> &p_arguments) override;
virtual void write_call_async(const Address &p_target, const Address &p_base, const StringName &p_function_name, const Vector<Address> &p_arguments) override;
virtual void write_call_builtin(const Address &p_target, GDScriptFunctions::Function p_function, const Vector<Address> &p_arguments) override;
- virtual void write_call_method_bind(const Address &p_target, const Address &p_base, const MethodBind *p_method, const Vector<Address> &p_arguments) override;
- virtual void write_call_ptrcall(const Address &p_target, const Address &p_base, const MethodBind *p_method, const Vector<Address> &p_arguments) override;
+ virtual void write_call_builtin_type(const Address &p_target, const Address &p_base, Variant::Type p_type, const StringName &p_method, const Vector<Address> &p_arguments) override;
+ virtual void write_call_method_bind(const Address &p_target, const Address &p_base, MethodBind *p_method, const Vector<Address> &p_arguments) override;
+ virtual void write_call_ptrcall(const Address &p_target, const Address &p_base, MethodBind *p_method, const Vector<Address> &p_arguments) override;
virtual void write_call_self(const Address &p_target, const StringName &p_function_name, const Vector<Address> &p_arguments) override;
virtual void write_call_script_function(const Address &p_target, const Address &p_base, const StringName &p_function_name, const Vector<Address> &p_arguments) override;
virtual void write_construct(const Address &p_target, Variant::Type p_type, const Vector<Address> &p_arguments) override;
@@ -255,7 +417,9 @@ public:
virtual void write_if(const Address &p_condition) override;
virtual void write_else() override;
virtual void write_endif() override;
- virtual void write_for(const Address &p_variable, const Address &p_list) override;
+ virtual void start_for(const GDScriptDataType &p_iterator_type, const GDScriptDataType &p_list_type) override;
+ virtual void write_for_assignment(const Address &p_variable, const Address &p_list) override;
+ virtual void write_for() override;
virtual void write_endfor() override;
virtual void start_while_condition() override;
virtual void write_while(const Address &p_condition) override;
diff --git a/modules/gdscript/gdscript_codegen.h b/modules/gdscript/gdscript_codegen.h
index 9872a61423..decab3df0b 100644
--- a/modules/gdscript/gdscript_codegen.h
+++ b/modules/gdscript/gdscript_codegen.h
@@ -126,8 +126,9 @@ public:
virtual void write_super_call(const Address &p_target, const StringName &p_function_name, const Vector<Address> &p_arguments) = 0;
virtual void write_call_async(const Address &p_target, const Address &p_base, const StringName &p_function_name, const Vector<Address> &p_arguments) = 0;
virtual void write_call_builtin(const Address &p_target, GDScriptFunctions::Function p_function, const Vector<Address> &p_arguments) = 0;
- virtual void write_call_method_bind(const Address &p_target, const Address &p_base, const MethodBind *p_method, const Vector<Address> &p_arguments) = 0;
- virtual void write_call_ptrcall(const Address &p_target, const Address &p_base, const MethodBind *p_method, const Vector<Address> &p_arguments) = 0;
+ virtual void write_call_builtin_type(const Address &p_target, const Address &p_base, Variant::Type p_type, const StringName &p_method, const Vector<Address> &p_arguments) = 0;
+ virtual void write_call_method_bind(const Address &p_target, const Address &p_base, MethodBind *p_method, const Vector<Address> &p_arguments) = 0;
+ virtual void write_call_ptrcall(const Address &p_target, const Address &p_base, MethodBind *p_method, const Vector<Address> &p_arguments) = 0;
virtual void write_call_self(const Address &p_target, const StringName &p_function_name, const Vector<Address> &p_arguments) = 0;
virtual void write_call_script_function(const Address &p_target, const Address &p_base, const StringName &p_function_name, const Vector<Address> &p_arguments) = 0;
virtual void write_construct(const Address &p_target, Variant::Type p_type, const Vector<Address> &p_arguments) = 0;
@@ -138,7 +139,9 @@ public:
// virtual void write_elseif(const Address &p_condition) = 0; This kind of makes things more difficult for no real benefit.
virtual void write_else() = 0;
virtual void write_endif() = 0;
- virtual void write_for(const Address &p_variable, const Address &p_list) = 0;
+ virtual void start_for(const GDScriptDataType &p_iterator_type, const GDScriptDataType &p_list_type) = 0;
+ virtual void write_for_assignment(const Address &p_variable, const Address &p_list) = 0;
+ virtual void write_for() = 0;
virtual void write_endfor() = 0;
virtual void start_while_condition() = 0; // Used to allow a jump to the expression evaluation.
virtual void write_while(const Address &p_condition) = 0;
diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp
index a64a05fcba..3d327cebeb 100644
--- a/modules/gdscript/gdscript_compiler.cpp
+++ b/modules/gdscript/gdscript_compiler.cpp
@@ -158,6 +158,48 @@ GDScriptDataType GDScriptCompiler::_gdtype_from_datatype(const GDScriptParser::D
return result;
}
+static bool _is_exact_type(const PropertyInfo &p_par_type, const GDScriptDataType &p_arg_type) {
+ if (!p_arg_type.has_type) {
+ return false;
+ }
+ if (p_par_type.type == Variant::NIL) {
+ return false;
+ }
+ if (p_par_type.type == Variant::OBJECT) {
+ if (p_arg_type.kind == GDScriptDataType::BUILTIN) {
+ return false;
+ }
+ StringName class_name;
+ if (p_arg_type.kind == GDScriptDataType::NATIVE) {
+ class_name = p_arg_type.native_type;
+ } else {
+ class_name = p_arg_type.native_type == StringName() ? p_arg_type.script_type->get_instance_base_type() : p_arg_type.native_type;
+ }
+ return p_par_type.class_name == class_name || ClassDB::is_parent_class(class_name, p_par_type.class_name);
+ } else {
+ if (p_arg_type.kind != GDScriptDataType::BUILTIN) {
+ return false;
+ }
+ return p_par_type.type == p_arg_type.builtin_type;
+ }
+}
+
+static bool _have_exact_arguments(const MethodBind *p_method, const Vector<GDScriptCodeGenerator::Address> &p_arguments) {
+ if (p_method->get_argument_count() != p_arguments.size()) {
+ // ptrcall won't work with default arguments.
+ return false;
+ }
+ MethodInfo info;
+ ClassDB::get_method_info(p_method->get_instance_class(), p_method->get_name(), &info);
+ for (int i = 0; i < p_arguments.size(); i++) {
+ const PropertyInfo &prop = info.arguments[i];
+ if (!_is_exact_type(prop, p_arguments[i].type)) {
+ return false;
+ }
+ }
+ return true;
+}
+
GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &codegen, Error &r_error, const GDScriptParser::ExpressionNode *p_expression, bool p_root, bool p_initializer, const GDScriptCodeGenerator::Address &p_index_addr) {
if (p_expression->is_constant) {
return codegen.add_constant(p_expression->reduced_value);
@@ -395,7 +437,7 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code
gen->pop_temporary();
}
- return source;
+ return result;
} break;
case GDScriptParser::Node::CALL: {
const GDScriptParser::CallNode *call = static_cast<const GDScriptParser::CallNode *>(p_expression);
@@ -430,7 +472,20 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code
} else {
if (callee->type == GDScriptParser::Node::IDENTIFIER) {
// Self function call.
- if ((codegen.function_node && codegen.function_node->is_static) || call->function_name == "new") {
+ if (ClassDB::has_method(codegen.script->native->get_name(), call->function_name)) {
+ // Native method, use faster path.
+ GDScriptCodeGenerator::Address self;
+ self.mode = GDScriptCodeGenerator::Address::SELF;
+ MethodBind *method = ClassDB::get_method(codegen.script->native->get_name(), call->function_name);
+
+ if (_have_exact_arguments(method, arguments)) {
+ // Exact arguments, use ptrcall.
+ gen->write_call_ptrcall(result, self, method, arguments);
+ } else {
+ // Not exact arguments, but still can use method bind call.
+ gen->write_call_method_bind(result, self, method, arguments);
+ }
+ } else if ((codegen.function_node && codegen.function_node->is_static) || call->function_name == "new") {
GDScriptCodeGenerator::Address self;
self.mode = GDScriptCodeGenerator::Address::CLASS;
gen->write_call(result, self, call->function_name, arguments);
@@ -447,6 +502,28 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code
}
if (within_await) {
gen->write_call_async(result, base, call->function_name, arguments);
+ } else if (base.type.has_type && base.type.kind != GDScriptDataType::BUILTIN) {
+ // Native method, use faster path.
+ StringName class_name;
+ if (base.type.kind == GDScriptDataType::NATIVE) {
+ class_name = base.type.native_type;
+ } else {
+ class_name = base.type.native_type == StringName() ? base.type.script_type->get_instance_base_type() : base.type.native_type;
+ }
+ if (ClassDB::class_exists(class_name) && ClassDB::has_method(class_name, call->function_name)) {
+ MethodBind *method = ClassDB::get_method(class_name, call->function_name);
+ if (_have_exact_arguments(method, arguments)) {
+ // Exact arguments, use ptrcall.
+ gen->write_call_ptrcall(result, base, method, arguments);
+ } else {
+ // Not exact arguments, but still can use method bind call.
+ gen->write_call_method_bind(result, base, method, arguments);
+ }
+ } else {
+ gen->write_call(result, base, call->function_name, arguments);
+ }
+ } else if (base.type.has_type && base.type.kind == GDScriptDataType::BUILTIN) {
+ gen->write_call_builtin_type(result, base, base.type.builtin_type, call->function_name, arguments);
} else {
gen->write_call(result, base, call->function_name, arguments);
}
@@ -493,7 +570,7 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code
GDScriptCodeGenerator::Address result = codegen.add_temporary(_gdtype_from_datatype(get_node->get_datatype()));
MethodBind *get_node_method = ClassDB::get_method("Node", "get_node");
- gen->write_call_method_bind(result, GDScriptCodeGenerator::Address(GDScriptCodeGenerator::Address::SELF), get_node_method, args);
+ gen->write_call_ptrcall(result, GDScriptCodeGenerator::Address(GDScriptCodeGenerator::Address::SELF), get_node_method, args);
return result;
} break;
@@ -1397,13 +1474,27 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Sui
codegen.start_block();
// Evaluate the match expression.
+ GDScriptCodeGenerator::Address value_local = codegen.add_local("@match_value", _gdtype_from_datatype(match->test->get_datatype()));
GDScriptCodeGenerator::Address value = _parse_expression(codegen, error, match->test);
if (error) {
return error;
}
+ // Assign to local.
+ // TODO: This can be improved by passing the target to parse_expression().
+ gen->write_assign(value_local, value);
+
+ if (value.mode == GDScriptCodeGenerator::Address::TEMPORARY) {
+ codegen.generator->pop_temporary();
+ }
+
// Then, let's save the type of the value in the stack too, so we can reuse for later comparisons.
- GDScriptCodeGenerator::Address type = codegen.add_temporary();
+ GDScriptDataType typeof_type;
+ typeof_type.has_type = true;
+ typeof_type.kind = GDScriptDataType::BUILTIN;
+ typeof_type.builtin_type = Variant::INT;
+ GDScriptCodeGenerator::Address type = codegen.add_local("@match_type", typeof_type);
+
Vector<GDScriptCodeGenerator::Address> typeof_args;
typeof_args.push_back(value);
gen->write_call_builtin(type, GDScriptFunctions::TYPE_OF, typeof_args);
@@ -1457,12 +1548,6 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Sui
gen->write_endif();
}
- gen->pop_temporary();
-
- if (value.mode == GDScriptCodeGenerator::Address::TEMPORARY) {
- codegen.generator->pop_temporary();
- }
-
gen->end_match();
} break;
case GDScriptParser::Node::IF: {
@@ -1500,12 +1585,20 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Sui
codegen.start_block();
GDScriptCodeGenerator::Address iterator = codegen.add_local(for_n->variable->name, _gdtype_from_datatype(for_n->variable->get_datatype()));
+ gen->start_for(iterator.type, _gdtype_from_datatype(for_n->list->get_datatype()));
+
GDScriptCodeGenerator::Address list = _parse_expression(codegen, error, for_n->list);
if (error) {
return error;
}
- gen->write_for(iterator, list);
+ gen->write_for_assignment(iterator, list);
+
+ if (list.mode == GDScriptCodeGenerator::Address::TEMPORARY) {
+ codegen.generator->pop_temporary();
+ }
+
+ gen->write_for();
error = _parse_block(codegen, for_n->loop);
if (error) {
@@ -1514,10 +1607,6 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Sui
gen->write_endfor();
- if (list.mode == GDScriptCodeGenerator::Address::TEMPORARY) {
- codegen.generator->pop_temporary();
- }
-
codegen.end_block();
} break;
case GDScriptParser::Node::WHILE: {
diff --git a/modules/gdscript/gdscript_disassembler.cpp b/modules/gdscript/gdscript_disassembler.cpp
new file mode 100644
index 0000000000..c918251772
--- /dev/null
+++ b/modules/gdscript/gdscript_disassembler.cpp
@@ -0,0 +1,813 @@
+/*************************************************************************/
+/* gdscript_disassembler.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* 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 DEBUG_ENABLED
+
+#include "gdscript_function.h"
+
+#include "core/string/string_builder.h"
+#include "gdscript.h"
+#include "gdscript_functions.h"
+
+static String _get_variant_string(const Variant &p_variant) {
+ String txt;
+ if (p_variant.get_type() == Variant::STRING) {
+ txt = "\"" + String(p_variant) + "\"";
+ } else if (p_variant.get_type() == Variant::STRING_NAME) {
+ txt = "&\"" + String(p_variant) + "\"";
+ } else if (p_variant.get_type() == Variant::NODE_PATH) {
+ txt = "^\"" + String(p_variant) + "\"";
+ } else if (p_variant.get_type() == Variant::OBJECT) {
+ Object *obj = p_variant;
+ if (!obj) {
+ txt = "null";
+ } else {
+ GDScriptNativeClass *cls = Object::cast_to<GDScriptNativeClass>(obj);
+ if (cls) {
+ txt += cls->get_name();
+ txt += " (class)";
+ } else {
+ txt = obj->get_class();
+ if (obj->get_script_instance()) {
+ txt += "(" + obj->get_script_instance()->get_script()->get_path() + ")";
+ }
+ }
+ }
+ } else {
+ txt = p_variant;
+ }
+ return txt;
+}
+
+static String _disassemble_address(const GDScript *p_script, const GDScriptFunction &p_function, int p_address) {
+ int addr = p_address & GDScriptFunction::ADDR_MASK;
+
+ switch (p_address >> GDScriptFunction::ADDR_BITS) {
+ case GDScriptFunction::ADDR_TYPE_SELF: {
+ return "self";
+ } break;
+ case GDScriptFunction::ADDR_TYPE_CLASS: {
+ return "class";
+ } break;
+ case GDScriptFunction::ADDR_TYPE_MEMBER: {
+ return "member(" + p_script->debug_get_member_by_index(addr) + ")";
+ } break;
+ case GDScriptFunction::ADDR_TYPE_CLASS_CONSTANT: {
+ return "class_const(" + p_function.get_global_name(addr) + ")";
+ } break;
+ case GDScriptFunction::ADDR_TYPE_LOCAL_CONSTANT: {
+ return "const(" + _get_variant_string(p_function.get_constant(addr)) + ")";
+ } break;
+ case GDScriptFunction::ADDR_TYPE_STACK: {
+ return "stack(" + itos(addr) + ")";
+ } break;
+ case GDScriptFunction::ADDR_TYPE_STACK_VARIABLE: {
+ return "var_stack(" + itos(addr) + ")";
+ } break;
+ case GDScriptFunction::ADDR_TYPE_GLOBAL: {
+ return "global(" + _get_variant_string(GDScriptLanguage::get_singleton()->get_global_array()[addr]) + ")";
+ } break;
+ case GDScriptFunction::ADDR_TYPE_NAMED_GLOBAL: {
+ return "named_global(" + p_function.get_global_name(addr) + ")";
+ } break;
+ case GDScriptFunction::ADDR_TYPE_NIL: {
+ return "nil";
+ } break;
+ }
+
+ return "<err>";
+}
+
+void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
+#define DADDR(m_ip) (_disassemble_address(_script, *this, _code_ptr[ip + m_ip]))
+
+ for (int ip = 0; ip < _code_size;) {
+ StringBuilder text;
+ int incr = 0;
+
+ text += " ";
+ text += itos(ip);
+ text += ": ";
+
+ // This makes the compiler complain if some opcode is unchecked in the switch.
+ Opcode code = Opcode(_code_ptr[ip] & INSTR_MASK);
+ int instr_var_args = (_code_ptr[ip] & INSTR_ARGS_MASK) >> INSTR_BITS;
+
+ switch (code) {
+ case OPCODE_OPERATOR: {
+ int operation = _code_ptr[ip + 4];
+
+ text += "operator ";
+
+ text += DADDR(3);
+ text += " = ";
+ text += DADDR(1);
+ text += " ";
+ text += Variant::get_operator_name(Variant::Operator(operation));
+ text += " ";
+ text += DADDR(2);
+
+ incr += 5;
+ } break;
+ case OPCODE_OPERATOR_VALIDATED: {
+ text += "validated operator ";
+
+ text += DADDR(3);
+ text += " = ";
+ text += DADDR(1);
+ text += " <operator function> ";
+ text += DADDR(2);
+
+ incr += 5;
+ } break;
+ case OPCODE_EXTENDS_TEST: {
+ text += "is object ";
+ text += DADDR(3);
+ text += " = ";
+ text += DADDR(1);
+ text += " is ";
+ text += DADDR(2);
+
+ incr += 4;
+ } break;
+ case OPCODE_IS_BUILTIN: {
+ text += "is builtin ";
+ text += DADDR(2);
+ text += " = ";
+ text += DADDR(1);
+ text += " is ";
+ text += Variant::get_type_name(Variant::Type(_code_ptr[ip + 3]));
+
+ incr += 4;
+ } break;
+ case OPCODE_SET_KEYED: {
+ text += "set keyed ";
+ text += DADDR(1);
+ text += "[";
+ text += DADDR(2);
+ text += "] = ";
+ text += DADDR(3);
+
+ incr += 4;
+ } break;
+ case OPCODE_SET_KEYED_VALIDATED: {
+ text += "set keyed validated ";
+ text += DADDR(1);
+ text += "[";
+ text += DADDR(2);
+ text += "] = ";
+ text += DADDR(3);
+
+ incr += 5;
+ } break;
+ case OPCODE_SET_INDEXED_VALIDATED: {
+ text += "set indexed validated ";
+ text += DADDR(1);
+ text += "[";
+ text += DADDR(2);
+ text += "] = ";
+ text += DADDR(3);
+
+ incr += 5;
+ } break;
+ case OPCODE_GET_KEYED: {
+ text += "get keyed ";
+ text += DADDR(3);
+ text += " = ";
+ text += DADDR(1);
+ text += "[";
+ text += DADDR(2);
+ text += "]";
+
+ incr += 4;
+ } break;
+ case OPCODE_GET_KEYED_VALIDATED: {
+ text += "get keyed validated ";
+ text += DADDR(3);
+ text += " = ";
+ text += DADDR(1);
+ text += "[";
+ text += DADDR(2);
+ text += "]";
+
+ incr += 5;
+ } break;
+ case OPCODE_GET_INDEXED_VALIDATED: {
+ text += "get indexed validated ";
+ text += DADDR(3);
+ text += " = ";
+ text += DADDR(1);
+ text += "[";
+ text += DADDR(2);
+ text += "]";
+
+ incr += 5;
+ } break;
+ case OPCODE_SET_NAMED: {
+ text += "set_named ";
+ text += DADDR(1);
+ text += "[\"";
+ text += _global_names_ptr[_code_ptr[ip + 3]];
+ text += "\"] = ";
+ text += DADDR(2);
+
+ incr += 4;
+ } break;
+ case OPCODE_SET_NAMED_VALIDATED: {
+ text += "set_named validated ";
+ text += DADDR(1);
+ text += "[\"";
+ text += "<unknown name>";
+ text += "\"] = ";
+ text += DADDR(2);
+
+ incr += 4;
+ } break;
+ case OPCODE_GET_NAMED: {
+ text += "get_named ";
+ text += DADDR(2);
+ text += " = ";
+ text += DADDR(1);
+ text += "[\"";
+ text += _global_names_ptr[_code_ptr[ip + 3]];
+ text += "\"]";
+
+ incr += 4;
+ } break;
+ case OPCODE_GET_NAMED_VALIDATED: {
+ text += "get_named validated ";
+ text += DADDR(2);
+ text += " = ";
+ text += DADDR(1);
+ text += "[\"";
+ text += "<unknown name>";
+ text += "\"]";
+
+ incr += 4;
+ } break;
+ case OPCODE_SET_MEMBER: {
+ text += "set_member ";
+ text += "[\"";
+ text += _global_names_ptr[_code_ptr[ip + 2]];
+ text += "\"] = ";
+ text += DADDR(1);
+
+ incr += 3;
+ } break;
+ case OPCODE_GET_MEMBER: {
+ text += "get_member ";
+ text += DADDR(1);
+ text += " = ";
+ text += "[\"";
+ text += _global_names_ptr[_code_ptr[ip + 2]];
+ text += "\"]";
+
+ incr += 3;
+ } break;
+ case OPCODE_ASSIGN: {
+ text += "assign ";
+ text += DADDR(1);
+ text += " = ";
+ text += DADDR(2);
+
+ incr += 3;
+ } break;
+ case OPCODE_ASSIGN_TRUE: {
+ text += "assign ";
+ text += DADDR(1);
+ text += " = true";
+
+ incr += 2;
+ } break;
+ case OPCODE_ASSIGN_FALSE: {
+ text += "assign ";
+ text += DADDR(1);
+ text += " = false";
+
+ incr += 2;
+ } break;
+ case OPCODE_ASSIGN_TYPED_BUILTIN: {
+ text += "assign typed builtin (";
+ text += Variant::get_type_name((Variant::Type)_code_ptr[ip + 3]);
+ text += ") ";
+ text += DADDR(1);
+ text += " = ";
+ text += DADDR(2);
+
+ incr += 4;
+ } break;
+ case OPCODE_ASSIGN_TYPED_NATIVE: {
+ Variant class_name = _constants_ptr[_code_ptr[ip + 3]];
+ GDScriptNativeClass *nc = Object::cast_to<GDScriptNativeClass>(class_name.operator Object *());
+
+ text += "assign typed native (";
+ text += nc->get_name().operator String();
+ text += ") ";
+ text += DADDR(1);
+ text += " = ";
+ text += DADDR(2);
+
+ incr += 4;
+ } break;
+ case OPCODE_ASSIGN_TYPED_SCRIPT: {
+ Variant script = _constants_ptr[_code_ptr[ip + 3]];
+ Script *sc = Object::cast_to<Script>(script.operator Object *());
+
+ text += "assign typed script (";
+ text += sc->get_path();
+ text += ") ";
+ text += DADDR(1);
+ text += " = ";
+ text += DADDR(2);
+
+ incr += 4;
+ } break;
+ case OPCODE_CAST_TO_BUILTIN: {
+ text += "cast builtin ";
+ text += DADDR(2);
+ text += " = ";
+ text += DADDR(1);
+ text += " as ";
+ text += Variant::get_type_name(Variant::Type(_code_ptr[ip + 1]));
+
+ incr += 4;
+ } break;
+ case OPCODE_CAST_TO_NATIVE: {
+ Variant class_name = _constants_ptr[_code_ptr[ip + 1]];
+ GDScriptNativeClass *nc = Object::cast_to<GDScriptNativeClass>(class_name.operator Object *());
+
+ text += "cast native ";
+ text += DADDR(2);
+ text += " = ";
+ text += DADDR(1);
+ text += " as ";
+ text += nc->get_name();
+
+ incr += 4;
+ } break;
+ case OPCODE_CAST_TO_SCRIPT: {
+ text += "cast ";
+ text += DADDR(2);
+ text += " = ";
+ text += DADDR(1);
+ text += " as ";
+ text += DADDR(3);
+
+ incr += 4;
+ } break;
+ case OPCODE_CONSTRUCT: {
+ Variant::Type t = Variant::Type(_code_ptr[ip + 3 + instr_var_args]);
+ int argc = _code_ptr[ip + 1 + instr_var_args];
+
+ text += "construct ";
+ text += DADDR(1 + argc);
+ text += " = ";
+
+ text += Variant::get_type_name(t) + "(";
+ for (int i = 0; i < argc; i++) {
+ if (i > 0)
+ text += ", ";
+ text += DADDR(i + 1);
+ }
+ text += ")";
+
+ incr = 3 + instr_var_args;
+ } break;
+ case OPCODE_CONSTRUCT_VALIDATED: {
+ int argc = _code_ptr[ip + 1 + instr_var_args];
+
+ text += "construct validated ";
+ text += DADDR(1 + argc);
+ text += " = ";
+
+ text += "<unkown type>(";
+ for (int i = 0; i < argc; i++) {
+ if (i > 0)
+ text += ", ";
+ text += DADDR(i + 1);
+ }
+ text += ")";
+
+ incr = 3 + instr_var_args;
+ } break;
+ case OPCODE_CONSTRUCT_ARRAY: {
+ int argc = _code_ptr[ip + 1 + instr_var_args];
+ text += " make_array ";
+ text += DADDR(1 + argc);
+ text += " = [";
+
+ for (int i = 0; i < argc; i++) {
+ if (i > 0)
+ text += ", ";
+ text += DADDR(1 + i);
+ }
+
+ text += "]";
+
+ incr += 3 + argc;
+ } break;
+ case OPCODE_CONSTRUCT_DICTIONARY: {
+ int argc = _code_ptr[ip + 1 + instr_var_args];
+ text += "make_dict ";
+ text += DADDR(1 + argc * 2);
+ text += " = {";
+
+ for (int i = 0; i < argc; i++) {
+ if (i > 0)
+ text += ", ";
+ text += DADDR(1 + i * 2 + 0);
+ text += ": ";
+ text += DADDR(1 + i * 2 + 1);
+ }
+
+ text += "}";
+
+ incr += 3 + argc * 2;
+ } break;
+ case OPCODE_CALL:
+ case OPCODE_CALL_RETURN:
+ case OPCODE_CALL_ASYNC: {
+ bool ret = (_code_ptr[ip] & INSTR_MASK) == OPCODE_CALL_RETURN;
+ bool async = (_code_ptr[ip] & INSTR_MASK) == OPCODE_CALL_ASYNC;
+
+ if (ret) {
+ text += "call-ret ";
+ } else if (async) {
+ text += "call-async ";
+ } else {
+ text += "call ";
+ }
+
+ int argc = _code_ptr[ip + 1 + instr_var_args];
+ if (ret || async) {
+ text += DADDR(2 + argc) + " = ";
+ }
+
+ text += DADDR(1 + argc) + ".";
+ text += String(_global_names_ptr[_code_ptr[ip + 2 + instr_var_args]]);
+ text += "(";
+
+ for (int i = 0; i < argc; i++) {
+ if (i > 0)
+ text += ", ";
+ text += DADDR(1 + i);
+ }
+ text += ")";
+
+ incr = 5 + argc;
+ } break;
+ case OPCODE_CALL_METHOD_BIND:
+ case OPCODE_CALL_METHOD_BIND_RET: {
+ bool ret = (_code_ptr[ip] & INSTR_MASK) == OPCODE_CALL_METHOD_BIND_RET;
+
+ if (ret) {
+ text += "call-method_bind-ret ";
+ } else {
+ text += "call-method_bind ";
+ }
+
+ MethodBind *method = _methods_ptr[_code_ptr[ip + 2 + instr_var_args]];
+
+ int argc = _code_ptr[ip + 1 + instr_var_args];
+ if (ret) {
+ text += DADDR(2 + argc) + " = ";
+ }
+
+ text += DADDR(1 + argc) + ".";
+ text += method->get_name();
+ text += "(";
+
+ for (int i = 0; i < argc; i++) {
+ if (i > 0)
+ text += ", ";
+ text += DADDR(1 + i);
+ }
+ text += ")";
+
+ incr = 5 + argc;
+ } break;
+ case OPCODE_CALL_PTRCALL_NO_RETURN: {
+ text += "call-ptrcall (no return) ";
+
+ MethodBind *method = _methods_ptr[_code_ptr[ip + 2 + instr_var_args]];
+
+ int argc = _code_ptr[ip + 1 + instr_var_args];
+
+ text += DADDR(1 + argc) + ".";
+ text += method->get_name();
+ text += "(";
+
+ for (int i = 0; i < argc; i++) {
+ if (i > 0)
+ text += ", ";
+ text += DADDR(1 + i);
+ }
+ text += ")";
+
+ incr = 5 + argc;
+ } break;
+
+#define DISASSEMBLE_PTRCALL(m_type) \
+ case OPCODE_CALL_PTRCALL_##m_type: { \
+ text += "call-ptrcall (return "; \
+ text += #m_type; \
+ text += ") "; \
+ MethodBind *method = _methods_ptr[_code_ptr[ip + 2 + instr_var_args]]; \
+ int argc = _code_ptr[ip + 1 + instr_var_args]; \
+ text += DADDR(2 + argc) + " = "; \
+ text += DADDR(1 + argc) + "."; \
+ text += method->get_name(); \
+ text += "("; \
+ for (int i = 0; i < argc; i++) { \
+ if (i > 0) \
+ text += ", "; \
+ text += DADDR(1 + i); \
+ } \
+ text += ")"; \
+ incr = 5 + argc; \
+ } break
+
+ DISASSEMBLE_PTRCALL(BOOL);
+ DISASSEMBLE_PTRCALL(INT);
+ DISASSEMBLE_PTRCALL(FLOAT);
+ DISASSEMBLE_PTRCALL(STRING);
+ DISASSEMBLE_PTRCALL(VECTOR2);
+ DISASSEMBLE_PTRCALL(VECTOR2I);
+ DISASSEMBLE_PTRCALL(RECT2);
+ DISASSEMBLE_PTRCALL(RECT2I);
+ DISASSEMBLE_PTRCALL(VECTOR3);
+ DISASSEMBLE_PTRCALL(VECTOR3I);
+ DISASSEMBLE_PTRCALL(TRANSFORM2D);
+ DISASSEMBLE_PTRCALL(PLANE);
+ DISASSEMBLE_PTRCALL(AABB);
+ DISASSEMBLE_PTRCALL(BASIS);
+ DISASSEMBLE_PTRCALL(TRANSFORM);
+ DISASSEMBLE_PTRCALL(COLOR);
+ DISASSEMBLE_PTRCALL(STRING_NAME);
+ DISASSEMBLE_PTRCALL(NODE_PATH);
+ DISASSEMBLE_PTRCALL(RID);
+ DISASSEMBLE_PTRCALL(QUAT);
+ DISASSEMBLE_PTRCALL(OBJECT);
+ DISASSEMBLE_PTRCALL(CALLABLE);
+ DISASSEMBLE_PTRCALL(SIGNAL);
+ DISASSEMBLE_PTRCALL(DICTIONARY);
+ DISASSEMBLE_PTRCALL(ARRAY);
+ DISASSEMBLE_PTRCALL(PACKED_BYTE_ARRAY);
+ DISASSEMBLE_PTRCALL(PACKED_INT32_ARRAY);
+ DISASSEMBLE_PTRCALL(PACKED_INT64_ARRAY);
+ DISASSEMBLE_PTRCALL(PACKED_FLOAT32_ARRAY);
+ DISASSEMBLE_PTRCALL(PACKED_FLOAT64_ARRAY);
+ DISASSEMBLE_PTRCALL(PACKED_STRING_ARRAY);
+ DISASSEMBLE_PTRCALL(PACKED_VECTOR2_ARRAY);
+ DISASSEMBLE_PTRCALL(PACKED_VECTOR3_ARRAY);
+ DISASSEMBLE_PTRCALL(PACKED_COLOR_ARRAY);
+
+ case OPCODE_CALL_BUILTIN_TYPE_VALIDATED: {
+ int argc = _code_ptr[ip + 1 + instr_var_args];
+
+ text += "call-builtin-method validated ";
+
+ text += DADDR(2 + argc) + " = ";
+
+ text += DADDR(1) + ".";
+ text += "<unknown method>";
+
+ text += "(";
+
+ for (int i = 0; i < argc; i++) {
+ if (i > 0)
+ text += ", ";
+ text += DADDR(1 + i);
+ }
+ text += ")";
+
+ incr = 5 + argc;
+ } break;
+ case OPCODE_CALL_BUILT_IN: {
+ text += "call-built-in ";
+
+ int argc = _code_ptr[ip + 1 + instr_var_args];
+ text += DADDR(1 + argc) + " = ";
+
+ text += GDScriptFunctions::get_func_name(GDScriptFunctions::Function(_code_ptr[ip + 2 + instr_var_args]));
+ text += "(";
+
+ for (int i = 0; i < argc; i++) {
+ if (i > 0)
+ text += ", ";
+ text += DADDR(1 + i);
+ }
+ text += ")";
+
+ incr = 4 + argc;
+ } break;
+ case OPCODE_CALL_SELF_BASE: {
+ text += "call-self-base ";
+
+ int argc = _code_ptr[ip + 1 + instr_var_args];
+ text += DADDR(2 + argc) + " = ";
+
+ text += _global_names_ptr[_code_ptr[ip + 2 + instr_var_args]];
+ text += "(";
+
+ for (int i = 0; i < argc; i++) {
+ if (i > 0)
+ text += ", ";
+ text += DADDR(1 + i);
+ }
+ text += ")";
+
+ incr = 4 + argc;
+ } break;
+ case OPCODE_AWAIT: {
+ text += "await ";
+ text += DADDR(1);
+
+ incr += 2;
+ } break;
+ case OPCODE_AWAIT_RESUME: {
+ text += "await resume ";
+ text += DADDR(1);
+
+ incr = 2;
+ } break;
+ case OPCODE_JUMP: {
+ text += "jump ";
+ text += itos(_code_ptr[ip + 1]);
+
+ incr = 2;
+ } break;
+ case OPCODE_JUMP_IF: {
+ text += "jump-if ";
+ text += DADDR(1);
+ text += " to ";
+ text += itos(_code_ptr[ip + 2]);
+
+ incr = 3;
+ } break;
+ case OPCODE_JUMP_IF_NOT: {
+ text += "jump-if-not ";
+ text += DADDR(1);
+ text += " to ";
+ text += itos(_code_ptr[ip + 2]);
+
+ incr = 3;
+ } break;
+ case OPCODE_JUMP_TO_DEF_ARGUMENT: {
+ text += "jump-to-default-argument ";
+
+ incr = 1;
+ } break;
+ case OPCODE_RETURN: {
+ text += "return ";
+ text += DADDR(1);
+
+ incr = 2;
+ } break;
+
+#define DISASSEMBLE_ITERATE(m_type) \
+ case OPCODE_ITERATE_##m_type: { \
+ text += "for-loop (typed "; \
+ text += #m_type; \
+ text += ") "; \
+ text += DADDR(3); \
+ text += " in "; \
+ text += DADDR(2); \
+ text += " counter "; \
+ text += DADDR(1); \
+ text += " end "; \
+ text += itos(_code_ptr[ip + 4]); \
+ incr += 5; \
+ } break
+
+#define DISASSEMBLE_ITERATE_BEGIN(m_type) \
+ case OPCODE_ITERATE_BEGIN_##m_type: { \
+ text += "for-init (typed "; \
+ text += #m_type; \
+ text += ") "; \
+ text += DADDR(3); \
+ text += " in "; \
+ text += DADDR(2); \
+ text += " counter "; \
+ text += DADDR(1); \
+ text += " end "; \
+ text += itos(_code_ptr[ip + 4]); \
+ incr += 5; \
+ } break
+
+#define DISASSEMBLE_ITERATE_TYPES(m_macro) \
+ m_macro(INT); \
+ m_macro(FLOAT); \
+ m_macro(VECTOR2); \
+ m_macro(VECTOR2I); \
+ m_macro(VECTOR3); \
+ m_macro(VECTOR3I); \
+ m_macro(STRING); \
+ m_macro(DICTIONARY); \
+ m_macro(ARRAY); \
+ m_macro(PACKED_BYTE_ARRAY); \
+ m_macro(PACKED_INT32_ARRAY); \
+ m_macro(PACKED_INT64_ARRAY); \
+ m_macro(PACKED_FLOAT32_ARRAY); \
+ m_macro(PACKED_FLOAT64_ARRAY); \
+ m_macro(PACKED_STRING_ARRAY); \
+ m_macro(PACKED_VECTOR2_ARRAY); \
+ m_macro(PACKED_VECTOR3_ARRAY); \
+ m_macro(PACKED_COLOR_ARRAY); \
+ m_macro(OBJECT)
+
+ case OPCODE_ITERATE_BEGIN: {
+ text += "for-init ";
+ text += DADDR(3);
+ text += " in ";
+ text += DADDR(2);
+ text += " counter ";
+ text += DADDR(1);
+ text += " end ";
+ text += itos(_code_ptr[ip + 4]);
+
+ incr += 5;
+ } break;
+ DISASSEMBLE_ITERATE_TYPES(DISASSEMBLE_ITERATE_BEGIN);
+ case OPCODE_ITERATE: {
+ text += "for-loop ";
+ text += DADDR(2);
+ text += " in ";
+ text += DADDR(2);
+ text += " counter ";
+ text += DADDR(1);
+ text += " end ";
+ text += itos(_code_ptr[ip + 4]);
+
+ incr += 5;
+ } break;
+ DISASSEMBLE_ITERATE_TYPES(DISASSEMBLE_ITERATE);
+ case OPCODE_LINE: {
+ int line = _code_ptr[ip + 1] - 1;
+ if (line >= 0 && line < p_code_lines.size()) {
+ text += "line ";
+ text += itos(line + 1);
+ text += ": ";
+ text += p_code_lines[line];
+ } else {
+ text += "";
+ }
+
+ incr += 2;
+ } break;
+ case OPCODE_ASSERT: {
+ text += "assert (";
+ text += DADDR(1);
+ text += ", ";
+ text += DADDR(2);
+ text += ")";
+
+ incr += 3;
+ } break;
+ case OPCODE_BREAKPOINT: {
+ text += "breakpoint";
+
+ incr += 1;
+ } break;
+ case OPCODE_END: {
+ text += "== END ==";
+
+ incr += 1;
+ } break;
+ }
+
+ ip += incr;
+ if (text.get_string_length() > 0) {
+ print_line(text.as_string());
+ }
+ }
+}
+
+#endif
diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp
index 8372672cf7..32372439c5 100644
--- a/modules/gdscript/gdscript_function.cpp
+++ b/modules/gdscript/gdscript_function.cpp
@@ -30,1574 +30,7 @@
#include "gdscript_function.h"
-#include "core/os/os.h"
#include "gdscript.h"
-#include "gdscript_functions.h"
-
-#ifdef DEBUG_ENABLED
-#include "core/string/string_builder.h"
-#endif
-
-Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_instance, GDScript *p_script, Variant &self, Variant &static_ref, Variant *p_stack, String &r_error) const {
- int address = p_address & ADDR_MASK;
-
- //sequential table (jump table generated by compiler)
- switch ((p_address & ADDR_TYPE_MASK) >> ADDR_BITS) {
- case ADDR_TYPE_SELF: {
-#ifdef DEBUG_ENABLED
- if (unlikely(!p_instance)) {
- r_error = "Cannot access self without instance.";
- return nullptr;
- }
-#endif
- return &self;
- } break;
- case ADDR_TYPE_CLASS: {
- return &static_ref;
- } break;
- case ADDR_TYPE_MEMBER: {
-#ifdef DEBUG_ENABLED
- if (unlikely(!p_instance)) {
- r_error = "Cannot access member without instance.";
- return nullptr;
- }
-#endif
- //member indexing is O(1)
- return &p_instance->members.write[address];
- } break;
- case ADDR_TYPE_CLASS_CONSTANT: {
- //todo change to index!
- GDScript *s = p_script;
-#ifdef DEBUG_ENABLED
- ERR_FAIL_INDEX_V(address, _global_names_count, nullptr);
-#endif
- const StringName *sn = &_global_names_ptr[address];
-
- while (s) {
- GDScript *o = s;
- while (o) {
- Map<StringName, Variant>::Element *E = o->constants.find(*sn);
- if (E) {
- return &E->get();
- }
- o = o->_owner;
- }
- s = s->_base;
- }
-
- ERR_FAIL_V_MSG(nullptr, "GDScriptCompiler bug.");
- } break;
- case ADDR_TYPE_LOCAL_CONSTANT: {
-#ifdef DEBUG_ENABLED
- ERR_FAIL_INDEX_V(address, _constant_count, nullptr);
-#endif
- return &_constants_ptr[address];
- } break;
- case ADDR_TYPE_STACK:
- case ADDR_TYPE_STACK_VARIABLE: {
-#ifdef DEBUG_ENABLED
- ERR_FAIL_INDEX_V(address, _stack_size, nullptr);
-#endif
- return &p_stack[address];
- } break;
- case ADDR_TYPE_GLOBAL: {
-#ifdef DEBUG_ENABLED
- ERR_FAIL_INDEX_V(address, GDScriptLanguage::get_singleton()->get_global_array_size(), nullptr);
-#endif
- return &GDScriptLanguage::get_singleton()->get_global_array()[address];
- } break;
-#ifdef TOOLS_ENABLED
- case ADDR_TYPE_NAMED_GLOBAL: {
-#ifdef DEBUG_ENABLED
- ERR_FAIL_INDEX_V(address, _global_names_count, nullptr);
-#endif
- StringName id = _global_names_ptr[address];
-
- if (GDScriptLanguage::get_singleton()->get_named_globals_map().has(id)) {
- return (Variant *)&GDScriptLanguage::get_singleton()->get_named_globals_map()[id];
- } else {
- r_error = "Autoload singleton '" + String(id) + "' has been removed.";
- return nullptr;
- }
- } break;
-#endif
- case ADDR_TYPE_NIL: {
- return &nil;
- } break;
- }
-
- ERR_FAIL_V_MSG(nullptr, "Bad code! (unknown addressing mode).");
- return nullptr;
-}
-
-#ifdef DEBUG_ENABLED
-static String _get_var_type(const Variant *p_var) {
- String basestr;
-
- if (p_var->get_type() == Variant::OBJECT) {
- bool was_freed;
- Object *bobj = p_var->get_validated_object_with_check(was_freed);
- if (!bobj) {
- if (was_freed) {
- basestr = "null instance";
- } else {
- basestr = "previously freed";
- }
- } else {
- if (bobj->get_script_instance()) {
- basestr = bobj->get_class() + " (" + bobj->get_script_instance()->get_script()->get_path().get_file() + ")";
- } else {
- basestr = bobj->get_class();
- }
- }
-
- } else {
- basestr = Variant::get_type_name(p_var->get_type());
- }
-
- return basestr;
-}
-#endif // DEBUG_ENABLED
-
-String GDScriptFunction::_get_call_error(const Callable::CallError &p_err, const String &p_where, const Variant **argptrs) const {
- String err_text;
-
- if (p_err.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) {
- int errorarg = p_err.argument;
- // Handle the Object to Object case separately as we don't have further class details.
-#ifdef DEBUG_ENABLED
- if (p_err.expected == Variant::OBJECT && argptrs[errorarg]->get_type() == p_err.expected) {
- err_text = "Invalid type in " + p_where + ". The Object-derived class of argument " + itos(errorarg + 1) + " (" + _get_var_type(argptrs[errorarg]) + ") is not a subclass of the expected argument class.";
- } else
-#endif // DEBUG_ENABLED
- {
- err_text = "Invalid type in " + p_where + ". Cannot convert argument " + itos(errorarg + 1) + " from " + Variant::get_type_name(argptrs[errorarg]->get_type()) + " to " + Variant::get_type_name(Variant::Type(p_err.expected)) + ".";
- }
- } else if (p_err.error == Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) {
- err_text = "Invalid call to " + p_where + ". Expected " + itos(p_err.argument) + " arguments.";
- } else if (p_err.error == Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) {
- err_text = "Invalid call to " + p_where + ". Expected " + itos(p_err.argument) + " arguments.";
- } else if (p_err.error == Callable::CallError::CALL_ERROR_INVALID_METHOD) {
- err_text = "Invalid call. Nonexistent " + p_where + ".";
- } else if (p_err.error == Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL) {
- err_text = "Attempt to call " + p_where + " on a null instance.";
- } else {
- err_text = "Bug, call error: #" + itos(p_err.error);
- }
-
- return err_text;
-}
-
-#if defined(__GNUC__)
-#define OPCODES_TABLE \
- static const void *switch_table_ops[] = { \
- &&OPCODE_OPERATOR, \
- &&OPCODE_EXTENDS_TEST, \
- &&OPCODE_IS_BUILTIN, \
- &&OPCODE_SET, \
- &&OPCODE_GET, \
- &&OPCODE_SET_NAMED, \
- &&OPCODE_GET_NAMED, \
- &&OPCODE_SET_MEMBER, \
- &&OPCODE_GET_MEMBER, \
- &&OPCODE_ASSIGN, \
- &&OPCODE_ASSIGN_TRUE, \
- &&OPCODE_ASSIGN_FALSE, \
- &&OPCODE_ASSIGN_TYPED_BUILTIN, \
- &&OPCODE_ASSIGN_TYPED_NATIVE, \
- &&OPCODE_ASSIGN_TYPED_SCRIPT, \
- &&OPCODE_CAST_TO_BUILTIN, \
- &&OPCODE_CAST_TO_NATIVE, \
- &&OPCODE_CAST_TO_SCRIPT, \
- &&OPCODE_CONSTRUCT, \
- &&OPCODE_CONSTRUCT_ARRAY, \
- &&OPCODE_CONSTRUCT_DICTIONARY, \
- &&OPCODE_CALL, \
- &&OPCODE_CALL_RETURN, \
- &&OPCODE_CALL_ASYNC, \
- &&OPCODE_CALL_BUILT_IN, \
- &&OPCODE_CALL_SELF_BASE, \
- &&OPCODE_AWAIT, \
- &&OPCODE_AWAIT_RESUME, \
- &&OPCODE_JUMP, \
- &&OPCODE_JUMP_IF, \
- &&OPCODE_JUMP_IF_NOT, \
- &&OPCODE_JUMP_TO_DEF_ARGUMENT, \
- &&OPCODE_RETURN, \
- &&OPCODE_ITERATE_BEGIN, \
- &&OPCODE_ITERATE, \
- &&OPCODE_ASSERT, \
- &&OPCODE_BREAKPOINT, \
- &&OPCODE_LINE, \
- &&OPCODE_END \
- }; \
- static_assert((sizeof(switch_table_ops) / sizeof(switch_table_ops[0]) == (OPCODE_END + 1)), "Opcodes in jump table aren't the same as opcodes in enum.");
-
-#define OPCODE(m_op) \
- m_op:
-#define OPCODE_WHILE(m_test)
-#define OPCODES_END \
- OPSEXIT:
-#define OPCODES_OUT \
- OPSOUT:
-#define DISPATCH_OPCODE goto *switch_table_ops[_code_ptr[ip]]
-#define OPCODE_SWITCH(m_test) DISPATCH_OPCODE;
-#define OPCODE_BREAK goto OPSEXIT
-#define OPCODE_OUT goto OPSOUT
-#else
-#define OPCODES_TABLE
-#define OPCODE(m_op) case m_op:
-#define OPCODE_WHILE(m_test) while (m_test)
-#define OPCODES_END
-#define OPCODES_OUT
-#define DISPATCH_OPCODE continue
-#define OPCODE_SWITCH(m_test) switch (m_test)
-#define OPCODE_BREAK break
-#define OPCODE_OUT break
-#endif
-
-Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_args, int p_argcount, Callable::CallError &r_err, CallState *p_state) {
- OPCODES_TABLE;
-
- if (!_code_ptr) {
- return Variant();
- }
-
- r_err.error = Callable::CallError::CALL_OK;
-
- Variant self;
- Variant static_ref;
- Variant retvalue;
- Variant *stack = nullptr;
- Variant **call_args;
- int defarg = 0;
-
-#ifdef DEBUG_ENABLED
-
- //GDScriptLanguage::get_singleton()->calls++;
-
-#endif
-
- uint32_t alloca_size = 0;
- GDScript *script;
- int ip = 0;
- int line = _initial_line;
-
- if (p_state) {
- //use existing (supplied) state (awaited)
- stack = (Variant *)p_state->stack.ptr();
- call_args = (Variant **)&p_state->stack.ptr()[sizeof(Variant) * p_state->stack_size]; //ptr() to avoid bounds check
- line = p_state->line;
- ip = p_state->ip;
- alloca_size = p_state->stack.size();
- script = p_state->script;
- p_instance = p_state->instance;
- defarg = p_state->defarg;
- self = p_state->self;
-
- } else {
- if (p_argcount != _argument_count) {
- if (p_argcount > _argument_count) {
- r_err.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
- r_err.argument = _argument_count;
-
- return Variant();
- } else if (p_argcount < _argument_count - _default_arg_count) {
- r_err.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
- r_err.argument = _argument_count - _default_arg_count;
- return Variant();
- } else {
- defarg = _argument_count - p_argcount;
- }
- }
-
- alloca_size = sizeof(Variant *) * _call_size + sizeof(Variant) * _stack_size;
-
- if (alloca_size) {
- uint8_t *aptr = (uint8_t *)alloca(alloca_size);
-
- if (_stack_size) {
- stack = (Variant *)aptr;
- for (int i = 0; i < p_argcount; i++) {
- if (!argument_types[i].has_type) {
- memnew_placement(&stack[i], Variant(*p_args[i]));
- continue;
- }
-
- if (!argument_types[i].is_type(*p_args[i], true)) {
- r_err.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_err.argument = i;
- r_err.expected = argument_types[i].kind == GDScriptDataType::BUILTIN ? argument_types[i].builtin_type : Variant::OBJECT;
- return Variant();
- }
- if (argument_types[i].kind == GDScriptDataType::BUILTIN) {
- Variant arg;
- Variant::construct(argument_types[i].builtin_type, arg, &p_args[i], 1, r_err);
- memnew_placement(&stack[i], Variant(arg));
- } else {
- memnew_placement(&stack[i], Variant(*p_args[i]));
- }
- }
- for (int i = p_argcount; i < _stack_size; i++) {
- memnew_placement(&stack[i], Variant);
- }
- } else {
- stack = nullptr;
- }
-
- if (_call_size) {
- call_args = (Variant **)&aptr[sizeof(Variant) * _stack_size];
- } else {
- call_args = nullptr;
- }
-
- } else {
- stack = nullptr;
- call_args = nullptr;
- }
-
- if (p_instance) {
- if (p_instance->base_ref && static_cast<Reference *>(p_instance->owner)->is_referenced()) {
- self = REF(static_cast<Reference *>(p_instance->owner));
- } else {
- self = p_instance->owner;
- }
- script = p_instance->script.ptr();
- } else {
- script = _script;
- }
- }
-
- static_ref = script;
-
- String err_text;
-
-#ifdef DEBUG_ENABLED
-
- if (EngineDebugger::is_active()) {
- GDScriptLanguage::get_singleton()->enter_function(p_instance, this, stack, &ip, &line);
- }
-
-#define GD_ERR_BREAK(m_cond) \
- { \
- if (unlikely(m_cond)) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Breaking..:"); \
- OPCODE_BREAK; \
- } \
- }
-
-#define CHECK_SPACE(m_space) \
- GD_ERR_BREAK((ip + m_space) > _code_size)
-
-#define GET_VARIANT_PTR(m_v, m_code_ofs) \
- Variant *m_v; \
- m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, script, self, static_ref, stack, err_text); \
- if (unlikely(!m_v)) \
- OPCODE_BREAK;
-
-#else
-#define GD_ERR_BREAK(m_cond)
-#define CHECK_SPACE(m_space)
-#define GET_VARIANT_PTR(m_v, m_code_ofs) \
- Variant *m_v; \
- m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, script, self, static_ref, stack, err_text);
-
-#endif
-
-#ifdef DEBUG_ENABLED
-
- uint64_t function_start_time = 0;
- uint64_t function_call_time = 0;
-
- if (GDScriptLanguage::get_singleton()->profiling) {
- function_start_time = OS::get_singleton()->get_ticks_usec();
- function_call_time = 0;
- profile.call_count++;
- profile.frame_call_count++;
- }
- bool exit_ok = false;
- bool awaited = false;
-#endif
-
-#ifdef DEBUG_ENABLED
- OPCODE_WHILE(ip < _code_size) {
- int last_opcode = _code_ptr[ip];
-#else
- OPCODE_WHILE(true) {
-#endif
-
- OPCODE_SWITCH(_code_ptr[ip]) {
- OPCODE(OPCODE_OPERATOR) {
- CHECK_SPACE(5);
-
- bool valid;
- Variant::Operator op = (Variant::Operator)_code_ptr[ip + 1];
- GD_ERR_BREAK(op >= Variant::OP_MAX);
-
- GET_VARIANT_PTR(a, 2);
- GET_VARIANT_PTR(b, 3);
- GET_VARIANT_PTR(dst, 4);
-
-#ifdef DEBUG_ENABLED
-
- Variant ret;
- Variant::evaluate(op, *a, *b, ret, valid);
-#else
- Variant::evaluate(op, *a, *b, *dst, valid);
-#endif
-#ifdef DEBUG_ENABLED
- if (!valid) {
- if (ret.get_type() == Variant::STRING) {
- //return a string when invalid with the error
- err_text = ret;
- err_text += " in operator '" + Variant::get_operator_name(op) + "'.";
- } else {
- err_text = "Invalid operands '" + Variant::get_type_name(a->get_type()) + "' and '" + Variant::get_type_name(b->get_type()) + "' in operator '" + Variant::get_operator_name(op) + "'.";
- }
- OPCODE_BREAK;
- }
- *dst = ret;
-#endif
- ip += 5;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_EXTENDS_TEST) {
- CHECK_SPACE(4);
-
- GET_VARIANT_PTR(a, 1);
- GET_VARIANT_PTR(b, 2);
- GET_VARIANT_PTR(dst, 3);
-
-#ifdef DEBUG_ENABLED
- if (b->get_type() != Variant::OBJECT || b->operator Object *() == nullptr) {
- err_text = "Right operand of 'is' is not a class.";
- OPCODE_BREAK;
- }
-#endif
-
- bool extends_ok = false;
- if (a->get_type() == Variant::OBJECT && a->operator Object *() != nullptr) {
-#ifdef DEBUG_ENABLED
- bool was_freed;
- Object *obj_A = a->get_validated_object_with_check(was_freed);
-
- if (was_freed) {
- err_text = "Left operand of 'is' is a previously freed instance.";
- OPCODE_BREAK;
- }
-
- Object *obj_B = b->get_validated_object_with_check(was_freed);
-
- if (was_freed) {
- err_text = "Right operand of 'is' is a previously freed instance.";
- OPCODE_BREAK;
- }
-#else
-
- Object *obj_A = *a;
- Object *obj_B = *b;
-#endif // DEBUG_ENABLED
-
- GDScript *scr_B = Object::cast_to<GDScript>(obj_B);
-
- if (scr_B) {
- //if B is a script, the only valid condition is that A has an instance which inherits from the script
- //in other situation, this shoul return false.
-
- if (obj_A->get_script_instance() && obj_A->get_script_instance()->get_language() == GDScriptLanguage::get_singleton()) {
- GDScript *cmp = static_cast<GDScript *>(obj_A->get_script_instance()->get_script().ptr());
- //bool found=false;
- while (cmp) {
- if (cmp == scr_B) {
- //inherits from script, all ok
- extends_ok = true;
- break;
- }
-
- cmp = cmp->_base;
- }
- }
-
- } else {
- GDScriptNativeClass *nc = Object::cast_to<GDScriptNativeClass>(obj_B);
-
-#ifdef DEBUG_ENABLED
- if (!nc) {
- err_text = "Right operand of 'is' is not a class (type: '" + obj_B->get_class() + "').";
- OPCODE_BREAK;
- }
-#endif
- extends_ok = ClassDB::is_parent_class(obj_A->get_class_name(), nc->get_name());
- }
- }
-
- *dst = extends_ok;
- ip += 4;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_IS_BUILTIN) {
- CHECK_SPACE(4);
-
- GET_VARIANT_PTR(value, 1);
- Variant::Type var_type = (Variant::Type)_code_ptr[ip + 2];
- GET_VARIANT_PTR(dst, 3);
-
- GD_ERR_BREAK(var_type < 0 || var_type >= Variant::VARIANT_MAX);
-
- *dst = value->get_type() == var_type;
- ip += 4;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_SET) {
- CHECK_SPACE(3);
-
- GET_VARIANT_PTR(dst, 1);
- GET_VARIANT_PTR(index, 2);
- GET_VARIANT_PTR(value, 3);
-
- bool valid;
- dst->set(*index, *value, &valid);
-
-#ifdef DEBUG_ENABLED
- if (!valid) {
- String v = index->operator String();
- if (v != "") {
- v = "'" + v + "'";
- } else {
- v = "of type '" + _get_var_type(index) + "'";
- }
- err_text = "Invalid set index " + v + " (on base: '" + _get_var_type(dst) + "') with value of type '" + _get_var_type(value) + "'";
- OPCODE_BREAK;
- }
-#endif
- ip += 4;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_GET) {
- CHECK_SPACE(3);
-
- GET_VARIANT_PTR(src, 1);
- GET_VARIANT_PTR(index, 2);
- GET_VARIANT_PTR(dst, 3);
-
- bool valid;
-#ifdef DEBUG_ENABLED
- //allow better error message in cases where src and dst are the same stack position
- Variant ret = src->get(*index, &valid);
-#else
- *dst = src->get(*index, &valid);
-
-#endif
-#ifdef DEBUG_ENABLED
- if (!valid) {
- String v = index->operator String();
- if (v != "") {
- v = "'" + v + "'";
- } else {
- v = "of type '" + _get_var_type(index) + "'";
- }
- err_text = "Invalid get index " + v + " (on base: '" + _get_var_type(src) + "').";
- OPCODE_BREAK;
- }
- *dst = ret;
-#endif
- ip += 4;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_SET_NAMED) {
- CHECK_SPACE(3);
-
- GET_VARIANT_PTR(dst, 1);
- GET_VARIANT_PTR(value, 3);
-
- int indexname = _code_ptr[ip + 2];
-
- GD_ERR_BREAK(indexname < 0 || indexname >= _global_names_count);
- const StringName *index = &_global_names_ptr[indexname];
-
- bool valid;
- dst->set_named(*index, *value, valid);
-
-#ifdef DEBUG_ENABLED
- if (!valid) {
- String err_type;
- err_text = "Invalid set index '" + String(*index) + "' (on base: '" + _get_var_type(dst) + "') with value of type '" + _get_var_type(value) + "'.";
- OPCODE_BREAK;
- }
-#endif
- ip += 4;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_GET_NAMED) {
- CHECK_SPACE(4);
-
- GET_VARIANT_PTR(src, 1);
- GET_VARIANT_PTR(dst, 3);
-
- int indexname = _code_ptr[ip + 2];
-
- GD_ERR_BREAK(indexname < 0 || indexname >= _global_names_count);
- const StringName *index = &_global_names_ptr[indexname];
-
- bool valid;
-#ifdef DEBUG_ENABLED
- //allow better error message in cases where src and dst are the same stack position
- Variant ret = src->get_named(*index, valid);
-
-#else
- *dst = src->get_named(*index, valid);
-#endif
-#ifdef DEBUG_ENABLED
- if (!valid) {
- if (src->has_method(*index)) {
- err_text = "Invalid get index '" + index->operator String() + "' (on base: '" + _get_var_type(src) + "'). Did you mean '." + index->operator String() + "()' or funcref(obj, \"" + index->operator String() + "\") ?";
- } else {
- err_text = "Invalid get index '" + index->operator String() + "' (on base: '" + _get_var_type(src) + "').";
- }
- OPCODE_BREAK;
- }
- *dst = ret;
-#endif
- ip += 4;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_SET_MEMBER) {
- CHECK_SPACE(3);
- int indexname = _code_ptr[ip + 1];
- GD_ERR_BREAK(indexname < 0 || indexname >= _global_names_count);
- const StringName *index = &_global_names_ptr[indexname];
- GET_VARIANT_PTR(src, 2);
-
- bool valid;
-#ifndef DEBUG_ENABLED
- ClassDB::set_property(p_instance->owner, *index, *src, &valid);
-#else
- bool ok = ClassDB::set_property(p_instance->owner, *index, *src, &valid);
- if (!ok) {
- err_text = "Internal error setting property: " + String(*index);
- OPCODE_BREAK;
- } else if (!valid) {
- err_text = "Error setting property '" + String(*index) + "' with value of type " + Variant::get_type_name(src->get_type()) + ".";
- OPCODE_BREAK;
- }
-#endif
- ip += 3;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_GET_MEMBER) {
- CHECK_SPACE(3);
- int indexname = _code_ptr[ip + 1];
- GD_ERR_BREAK(indexname < 0 || indexname >= _global_names_count);
- const StringName *index = &_global_names_ptr[indexname];
- GET_VARIANT_PTR(dst, 2);
-
-#ifndef DEBUG_ENABLED
- ClassDB::get_property(p_instance->owner, *index, *dst);
-#else
- bool ok = ClassDB::get_property(p_instance->owner, *index, *dst);
- if (!ok) {
- err_text = "Internal error getting property: " + String(*index);
- OPCODE_BREAK;
- }
-#endif
- ip += 3;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_ASSIGN) {
- CHECK_SPACE(3);
- GET_VARIANT_PTR(dst, 1);
- GET_VARIANT_PTR(src, 2);
-
- *dst = *src;
-
- ip += 3;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_ASSIGN_TRUE) {
- CHECK_SPACE(2);
- GET_VARIANT_PTR(dst, 1);
-
- *dst = true;
-
- ip += 2;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_ASSIGN_FALSE) {
- CHECK_SPACE(2);
- GET_VARIANT_PTR(dst, 1);
-
- *dst = false;
-
- ip += 2;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_ASSIGN_TYPED_BUILTIN) {
- CHECK_SPACE(4);
- GET_VARIANT_PTR(dst, 2);
- GET_VARIANT_PTR(src, 3);
-
- Variant::Type var_type = (Variant::Type)_code_ptr[ip + 1];
- GD_ERR_BREAK(var_type < 0 || var_type >= Variant::VARIANT_MAX);
-
- if (src->get_type() != var_type) {
-#ifdef DEBUG_ENABLED
- if (Variant::can_convert_strict(src->get_type(), var_type)) {
-#endif // DEBUG_ENABLED
- Callable::CallError ce;
- Variant::construct(var_type, *dst, const_cast<const Variant **>(&src), 1, ce);
- } else {
-#ifdef DEBUG_ENABLED
- err_text = "Trying to assign value of type '" + Variant::get_type_name(src->get_type()) +
- "' to a variable of type '" + Variant::get_type_name(var_type) + "'.";
- OPCODE_BREAK;
- }
- } else {
-#endif // DEBUG_ENABLED
- *dst = *src;
- }
-
- ip += 4;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_ASSIGN_TYPED_NATIVE) {
- CHECK_SPACE(4);
- GET_VARIANT_PTR(dst, 2);
- GET_VARIANT_PTR(src, 3);
-
-#ifdef DEBUG_ENABLED
- GET_VARIANT_PTR(type, 1);
- GDScriptNativeClass *nc = Object::cast_to<GDScriptNativeClass>(type->operator Object *());
- GD_ERR_BREAK(!nc);
- if (src->get_type() != Variant::OBJECT && src->get_type() != Variant::NIL) {
- err_text = "Trying to assign value of type '" + Variant::get_type_name(src->get_type()) +
- "' to a variable of type '" + nc->get_name() + "'.";
- OPCODE_BREAK;
- }
- Object *src_obj = src->operator Object *();
-
- if (src_obj && !ClassDB::is_parent_class(src_obj->get_class_name(), nc->get_name())) {
- err_text = "Trying to assign value of type '" + src_obj->get_class_name() +
- "' to a variable of type '" + nc->get_name() + "'.";
- OPCODE_BREAK;
- }
-#endif // DEBUG_ENABLED
- *dst = *src;
-
- ip += 4;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_ASSIGN_TYPED_SCRIPT) {
- CHECK_SPACE(4);
- GET_VARIANT_PTR(dst, 2);
- GET_VARIANT_PTR(src, 3);
-
-#ifdef DEBUG_ENABLED
- GET_VARIANT_PTR(type, 1);
- Script *base_type = Object::cast_to<Script>(type->operator Object *());
-
- GD_ERR_BREAK(!base_type);
-
- if (src->get_type() != Variant::OBJECT && src->get_type() != Variant::NIL) {
- err_text = "Trying to assign a non-object value to a variable of type '" + base_type->get_path().get_file() + "'.";
- OPCODE_BREAK;
- }
-
- if (src->get_type() != Variant::NIL && src->operator Object *() != nullptr) {
- ScriptInstance *scr_inst = src->operator Object *()->get_script_instance();
- if (!scr_inst) {
- err_text = "Trying to assign value of type '" + src->operator Object *()->get_class_name() +
- "' to a variable of type '" + base_type->get_path().get_file() + "'.";
- OPCODE_BREAK;
- }
-
- Script *src_type = src->operator Object *()->get_script_instance()->get_script().ptr();
- bool valid = false;
-
- while (src_type) {
- if (src_type == base_type) {
- valid = true;
- break;
- }
- src_type = src_type->get_base_script().ptr();
- }
-
- if (!valid) {
- err_text = "Trying to assign value of type '" + src->operator Object *()->get_script_instance()->get_script()->get_path().get_file() +
- "' to a variable of type '" + base_type->get_path().get_file() + "'.";
- OPCODE_BREAK;
- }
- }
-#endif // DEBUG_ENABLED
-
- *dst = *src;
-
- ip += 4;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_CAST_TO_BUILTIN) {
- CHECK_SPACE(4);
- Variant::Type to_type = (Variant::Type)_code_ptr[ip + 1];
- GET_VARIANT_PTR(src, 2);
- GET_VARIANT_PTR(dst, 3);
-
- GD_ERR_BREAK(to_type < 0 || to_type >= Variant::VARIANT_MAX);
-
- Callable::CallError err;
- Variant::construct(to_type, *dst, (const Variant **)&src, 1, err);
-
-#ifdef DEBUG_ENABLED
- if (err.error != Callable::CallError::CALL_OK) {
- err_text = "Invalid cast: could not convert value to '" + Variant::get_type_name(to_type) + "'.";
- OPCODE_BREAK;
- }
-#endif
-
- ip += 4;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_CAST_TO_NATIVE) {
- CHECK_SPACE(4);
- GET_VARIANT_PTR(to_type, 1);
- GET_VARIANT_PTR(src, 2);
- GET_VARIANT_PTR(dst, 3);
-
- GDScriptNativeClass *nc = Object::cast_to<GDScriptNativeClass>(to_type->operator Object *());
- GD_ERR_BREAK(!nc);
-
-#ifdef DEBUG_ENABLED
- if (src->get_type() != Variant::OBJECT && src->get_type() != Variant::NIL) {
- err_text = "Invalid cast: can't convert a non-object value to an object type.";
- OPCODE_BREAK;
- }
-#endif
- Object *src_obj = src->operator Object *();
-
- if (src_obj && !ClassDB::is_parent_class(src_obj->get_class_name(), nc->get_name())) {
- *dst = Variant(); // invalid cast, assign NULL
- } else {
- *dst = *src;
- }
-
- ip += 4;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_CAST_TO_SCRIPT) {
- CHECK_SPACE(4);
- GET_VARIANT_PTR(to_type, 1);
- GET_VARIANT_PTR(src, 2);
- GET_VARIANT_PTR(dst, 3);
-
- Script *base_type = Object::cast_to<Script>(to_type->operator Object *());
-
- GD_ERR_BREAK(!base_type);
-
-#ifdef DEBUG_ENABLED
- if (src->get_type() != Variant::OBJECT && src->get_type() != Variant::NIL) {
- err_text = "Trying to assign a non-object value to a variable of type '" + base_type->get_path().get_file() + "'.";
- OPCODE_BREAK;
- }
-#endif
-
- bool valid = false;
-
- if (src->get_type() != Variant::NIL && src->operator Object *() != nullptr) {
- ScriptInstance *scr_inst = src->operator Object *()->get_script_instance();
-
- if (scr_inst) {
- Script *src_type = src->operator Object *()->get_script_instance()->get_script().ptr();
-
- while (src_type) {
- if (src_type == base_type) {
- valid = true;
- break;
- }
- src_type = src_type->get_base_script().ptr();
- }
- }
- }
-
- if (valid) {
- *dst = *src; // Valid cast, copy the source object
- } else {
- *dst = Variant(); // invalid cast, assign NULL
- }
-
- ip += 4;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_CONSTRUCT) {
- CHECK_SPACE(2);
- Variant::Type t = Variant::Type(_code_ptr[ip + 1]);
- int argc = _code_ptr[ip + 2];
- CHECK_SPACE(argc + 2);
- Variant **argptrs = call_args;
- for (int i = 0; i < argc; i++) {
- GET_VARIANT_PTR(v, 3 + i);
- argptrs[i] = v;
- }
-
- GET_VARIANT_PTR(dst, 3 + argc);
- Callable::CallError err;
- Variant::construct(t, *dst, (const Variant **)argptrs, argc, err);
-
-#ifdef DEBUG_ENABLED
- if (err.error != Callable::CallError::CALL_OK) {
- err_text = _get_call_error(err, "'" + Variant::get_type_name(t) + "' constructor", (const Variant **)argptrs);
- OPCODE_BREAK;
- }
-#endif
-
- ip += 4 + argc;
- //construct a basic type
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_CONSTRUCT_ARRAY) {
- CHECK_SPACE(1);
- int argc = _code_ptr[ip + 1];
- Array array; //arrays are always shared
- array.resize(argc);
- CHECK_SPACE(argc + 2);
-
- for (int i = 0; i < argc; i++) {
- GET_VARIANT_PTR(v, 2 + i);
- array[i] = *v;
- }
-
- GET_VARIANT_PTR(dst, 2 + argc);
-
- *dst = array;
-
- ip += 3 + argc;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_CONSTRUCT_DICTIONARY) {
- CHECK_SPACE(1);
- int argc = _code_ptr[ip + 1];
- Dictionary dict; //arrays are always shared
-
- CHECK_SPACE(argc * 2 + 2);
-
- for (int i = 0; i < argc; i++) {
- GET_VARIANT_PTR(k, 2 + i * 2 + 0);
- GET_VARIANT_PTR(v, 2 + i * 2 + 1);
- dict[*k] = *v;
- }
-
- GET_VARIANT_PTR(dst, 2 + argc * 2);
-
- *dst = dict;
-
- ip += 3 + argc * 2;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_CALL_ASYNC)
- OPCODE(OPCODE_CALL_RETURN)
- OPCODE(OPCODE_CALL) {
- CHECK_SPACE(4);
- bool call_ret = _code_ptr[ip] != OPCODE_CALL;
-#ifdef DEBUG_ENABLED
- bool call_async = _code_ptr[ip] == OPCODE_CALL_ASYNC;
-#endif
-
- int argc = _code_ptr[ip + 1];
- GET_VARIANT_PTR(base, 2);
- int nameg = _code_ptr[ip + 3];
-
- GD_ERR_BREAK(nameg < 0 || nameg >= _global_names_count);
- const StringName *methodname = &_global_names_ptr[nameg];
-
- GD_ERR_BREAK(argc < 0);
- ip += 4;
- CHECK_SPACE(argc + 1);
- Variant **argptrs = call_args;
-
- for (int i = 0; i < argc; i++) {
- GET_VARIANT_PTR(v, i);
- argptrs[i] = v;
- }
-
-#ifdef DEBUG_ENABLED
- uint64_t call_time = 0;
-
- if (GDScriptLanguage::get_singleton()->profiling) {
- call_time = OS::get_singleton()->get_ticks_usec();
- }
-
-#endif
- Callable::CallError err;
- if (call_ret) {
- GET_VARIANT_PTR(ret, argc);
- base->call(*methodname, (const Variant **)argptrs, argc, *ret, err);
-#ifdef DEBUG_ENABLED
- if (!call_async && ret->get_type() == Variant::OBJECT) {
- // Check if getting a function state without await.
- bool was_freed = false;
- Object *obj = ret->get_validated_object_with_check(was_freed);
-
- if (was_freed) {
- err_text = "Got a freed object as a result of the call.";
- OPCODE_BREAK;
- }
- if (obj && obj->is_class_ptr(GDScriptFunctionState::get_class_ptr_static())) {
- err_text = R"(Trying to call an async function without "await".)";
- OPCODE_BREAK;
- }
- }
-#endif
- } else {
- Variant ret;
- base->call(*methodname, (const Variant **)argptrs, argc, ret, err);
- }
-#ifdef DEBUG_ENABLED
- if (GDScriptLanguage::get_singleton()->profiling) {
- function_call_time += OS::get_singleton()->get_ticks_usec() - call_time;
- }
-
- if (err.error != Callable::CallError::CALL_OK) {
- String methodstr = *methodname;
- String basestr = _get_var_type(base);
-
- if (methodstr == "call") {
- if (argc >= 1) {
- methodstr = String(*argptrs[0]) + " (via call)";
- if (err.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) {
- err.argument += 1;
- }
- }
- } else if (methodstr == "free") {
- if (err.error == Callable::CallError::CALL_ERROR_INVALID_METHOD) {
- if (base->is_ref()) {
- err_text = "Attempted to free a reference.";
- OPCODE_BREAK;
- } else if (base->get_type() == Variant::OBJECT) {
- err_text = "Attempted to free a locked object (calling or emitting).";
- OPCODE_BREAK;
- }
- }
- } else if (methodstr == "call_recursive" && basestr == "TreeItem") {
- if (argc >= 1) {
- methodstr = String(*argptrs[0]) + " (via TreeItem.call_recursive)";
- if (err.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) {
- err.argument += 1;
- }
- }
- }
- err_text = _get_call_error(err, "function '" + methodstr + "' in base '" + basestr + "'", (const Variant **)argptrs);
- OPCODE_BREAK;
- }
-#endif
-
- //_call_func(nullptr,base,*methodname,ip,argc,p_instance,stack);
- ip += argc + 1;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_CALL_BUILT_IN) {
- CHECK_SPACE(4);
-
- GDScriptFunctions::Function func = GDScriptFunctions::Function(_code_ptr[ip + 1]);
- int argc = _code_ptr[ip + 2];
- GD_ERR_BREAK(argc < 0);
-
- ip += 3;
- CHECK_SPACE(argc + 1);
- Variant **argptrs = call_args;
-
- for (int i = 0; i < argc; i++) {
- GET_VARIANT_PTR(v, i);
- argptrs[i] = v;
- }
-
- GET_VARIANT_PTR(dst, argc);
-
- Callable::CallError err;
-
- GDScriptFunctions::call(func, (const Variant **)argptrs, argc, *dst, err);
-
-#ifdef DEBUG_ENABLED
- if (err.error != Callable::CallError::CALL_OK) {
- String methodstr = GDScriptFunctions::get_func_name(func);
- if (dst->get_type() == Variant::STRING) {
- //call provided error string
- err_text = "Error calling built-in function '" + methodstr + "': " + String(*dst);
- } else {
- err_text = _get_call_error(err, "built-in function '" + methodstr + "'", (const Variant **)argptrs);
- }
- OPCODE_BREAK;
- }
-#endif
- ip += argc + 1;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_CALL_SELF_BASE) {
- CHECK_SPACE(2);
- int self_fun = _code_ptr[ip + 1];
-
-#ifdef DEBUG_ENABLED
- if (self_fun < 0 || self_fun >= _global_names_count) {
- err_text = "compiler bug, function name not found";
- OPCODE_BREAK;
- }
-#endif
- const StringName *methodname = &_global_names_ptr[self_fun];
-
- int argc = _code_ptr[ip + 2];
-
- CHECK_SPACE(2 + argc + 1);
-
- Variant **argptrs = call_args;
-
- for (int i = 0; i < argc; i++) {
- GET_VARIANT_PTR(v, i + 3);
- argptrs[i] = v;
- }
-
- GET_VARIANT_PTR(dst, argc + 3);
-
- const GDScript *gds = _script;
-
- const Map<StringName, GDScriptFunction *>::Element *E = nullptr;
- while (gds->base.ptr()) {
- gds = gds->base.ptr();
- E = gds->member_functions.find(*methodname);
- if (E) {
- break;
- }
- }
-
- Callable::CallError err;
-
- if (E) {
- *dst = E->get()->call(p_instance, (const Variant **)argptrs, argc, err);
- } else if (gds->native.ptr()) {
- if (*methodname != GDScriptLanguage::get_singleton()->strings._init) {
- MethodBind *mb = ClassDB::get_method(gds->native->get_name(), *methodname);
- if (!mb) {
- err.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
- } else {
- *dst = mb->call(p_instance->owner, (const Variant **)argptrs, argc, err);
- }
- } else {
- err.error = Callable::CallError::CALL_OK;
- }
- } else {
- if (*methodname != GDScriptLanguage::get_singleton()->strings._init) {
- err.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
- } else {
- err.error = Callable::CallError::CALL_OK;
- }
- }
-
- if (err.error != Callable::CallError::CALL_OK) {
- String methodstr = *methodname;
- err_text = _get_call_error(err, "function '" + methodstr + "'", (const Variant **)argptrs);
-
- OPCODE_BREAK;
- }
-
- ip += 4 + argc;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_AWAIT) {
- CHECK_SPACE(2);
-
- //do the oneshot connect
- GET_VARIANT_PTR(argobj, 1);
-
- Signal sig;
- bool is_signal = true;
-
- {
- Variant result = *argobj;
-
- if (argobj->get_type() == Variant::OBJECT) {
- bool was_freed = false;
- Object *obj = argobj->get_validated_object_with_check(was_freed);
-
- if (was_freed) {
- err_text = "Trying to await on a freed object.";
- OPCODE_BREAK;
- }
-
- // Is this even possible to be null at this point?
- if (obj) {
- if (obj->is_class_ptr(GDScriptFunctionState::get_class_ptr_static())) {
- static StringName completed = _scs_create("completed");
- result = Signal(obj, completed);
- }
- }
- }
-
- if (result.get_type() != Variant::SIGNAL) {
- ip += 4; // Skip OPCODE_AWAIT_RESUME and its data.
- // The stack pointer should be the same, so we don't need to set a return value.
- is_signal = false;
- } else {
- sig = result;
- }
- }
-
- if (is_signal) {
- Ref<GDScriptFunctionState> gdfs = memnew(GDScriptFunctionState);
- gdfs->function = this;
-
- gdfs->state.stack.resize(alloca_size);
- //copy variant stack
- for (int i = 0; i < _stack_size; i++) {
- memnew_placement(&gdfs->state.stack.write[sizeof(Variant) * i], Variant(stack[i]));
- }
- gdfs->state.stack_size = _stack_size;
- gdfs->state.self = self;
- gdfs->state.alloca_size = alloca_size;
- gdfs->state.ip = ip + 2;
- gdfs->state.line = line;
- gdfs->state.script = _script;
- {
- MutexLock lock(GDScriptLanguage::get_singleton()->lock);
- _script->pending_func_states.add(&gdfs->scripts_list);
- if (p_instance) {
- gdfs->state.instance = p_instance;
- p_instance->pending_func_states.add(&gdfs->instances_list);
- } else {
- gdfs->state.instance = nullptr;
- }
- }
-#ifdef DEBUG_ENABLED
- gdfs->state.function_name = name;
- gdfs->state.script_path = _script->get_path();
-#endif
- gdfs->state.defarg = defarg;
- gdfs->function = this;
-
- retvalue = gdfs;
-
- Error err = sig.connect(Callable(gdfs.ptr(), "_signal_callback"), varray(gdfs), Object::CONNECT_ONESHOT);
- if (err != OK) {
- err_text = "Error connecting to signal: " + sig.get_name() + " during await.";
- OPCODE_BREAK;
- }
-
-#ifdef DEBUG_ENABLED
- exit_ok = true;
- awaited = true;
-#endif
- OPCODE_BREAK;
- }
- }
- DISPATCH_OPCODE; // Needed for synchronous calls (when result is immediately available).
-
- OPCODE(OPCODE_AWAIT_RESUME) {
- CHECK_SPACE(2);
-#ifdef DEBUG_ENABLED
- if (!p_state) {
- err_text = ("Invalid Resume (bug?)");
- OPCODE_BREAK;
- }
-#endif
- GET_VARIANT_PTR(result, 1);
- *result = p_state->result;
- ip += 2;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_JUMP) {
- CHECK_SPACE(2);
- int to = _code_ptr[ip + 1];
-
- GD_ERR_BREAK(to < 0 || to > _code_size);
- ip = to;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_JUMP_IF) {
- CHECK_SPACE(3);
-
- GET_VARIANT_PTR(test, 1);
-
- bool result = test->booleanize();
-
- if (result) {
- int to = _code_ptr[ip + 2];
- GD_ERR_BREAK(to < 0 || to > _code_size);
- ip = to;
- } else {
- ip += 3;
- }
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_JUMP_IF_NOT) {
- CHECK_SPACE(3);
-
- GET_VARIANT_PTR(test, 1);
-
- bool result = test->booleanize();
-
- if (!result) {
- int to = _code_ptr[ip + 2];
- GD_ERR_BREAK(to < 0 || to > _code_size);
- ip = to;
- } else {
- ip += 3;
- }
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_JUMP_TO_DEF_ARGUMENT) {
- CHECK_SPACE(2);
- ip = _default_arg_ptr[defarg];
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_RETURN) {
- CHECK_SPACE(2);
- GET_VARIANT_PTR(r, 1);
- retvalue = *r;
-#ifdef DEBUG_ENABLED
- exit_ok = true;
-#endif
- OPCODE_BREAK;
- }
-
- OPCODE(OPCODE_ITERATE_BEGIN) {
- CHECK_SPACE(8); //space for this a regular iterate
-
- GET_VARIANT_PTR(counter, 1);
- GET_VARIANT_PTR(container, 2);
-
- bool valid;
- if (!container->iter_init(*counter, valid)) {
-#ifdef DEBUG_ENABLED
- if (!valid) {
- err_text = "Unable to iterate on object of type '" + Variant::get_type_name(container->get_type()) + "'.";
- OPCODE_BREAK;
- }
-#endif
- int jumpto = _code_ptr[ip + 3];
- GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
- ip = jumpto;
- } else {
- GET_VARIANT_PTR(iterator, 4);
-
- *iterator = container->iter_get(*counter, valid);
-#ifdef DEBUG_ENABLED
- if (!valid) {
- err_text = "Unable to obtain iterator object of type '" + Variant::get_type_name(container->get_type()) + "'.";
- OPCODE_BREAK;
- }
-#endif
- ip += 5; //skip regular iterate which is always next
- }
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_ITERATE) {
- CHECK_SPACE(4);
-
- GET_VARIANT_PTR(counter, 1);
- GET_VARIANT_PTR(container, 2);
-
- bool valid;
- if (!container->iter_next(*counter, valid)) {
-#ifdef DEBUG_ENABLED
- if (!valid) {
- err_text = "Unable to iterate on object of type '" + Variant::get_type_name(container->get_type()) + "' (type changed since first iteration?).";
- OPCODE_BREAK;
- }
-#endif
- int jumpto = _code_ptr[ip + 3];
- GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
- ip = jumpto;
- } else {
- GET_VARIANT_PTR(iterator, 4);
-
- *iterator = container->iter_get(*counter, valid);
-#ifdef DEBUG_ENABLED
- if (!valid) {
- err_text = "Unable to obtain iterator object of type '" + Variant::get_type_name(container->get_type()) + "' (but was obtained on first iteration?).";
- OPCODE_BREAK;
- }
-#endif
- ip += 5; //loop again
- }
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_ASSERT) {
- CHECK_SPACE(3);
-
-#ifdef DEBUG_ENABLED
- GET_VARIANT_PTR(test, 1);
- bool result = test->booleanize();
-
- if (!result) {
- String message_str;
- if (_code_ptr[ip + 2] != 0) {
- GET_VARIANT_PTR(message, 2);
- message_str = *message;
- }
- if (message_str.empty()) {
- err_text = "Assertion failed.";
- } else {
- err_text = "Assertion failed: " + message_str;
- }
- OPCODE_BREAK;
- }
-
-#endif
- ip += 3;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_BREAKPOINT) {
-#ifdef DEBUG_ENABLED
- if (EngineDebugger::is_active()) {
- GDScriptLanguage::get_singleton()->debug_break("Breakpoint Statement", true);
- }
-#endif
- ip += 1;
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_LINE) {
- CHECK_SPACE(2);
-
- line = _code_ptr[ip + 1];
- ip += 2;
-
- if (EngineDebugger::is_active()) {
- // line
- bool do_break = false;
-
- if (EngineDebugger::get_script_debugger()->get_lines_left() > 0) {
- if (EngineDebugger::get_script_debugger()->get_depth() <= 0) {
- EngineDebugger::get_script_debugger()->set_lines_left(EngineDebugger::get_script_debugger()->get_lines_left() - 1);
- }
- if (EngineDebugger::get_script_debugger()->get_lines_left() <= 0) {
- do_break = true;
- }
- }
-
- if (EngineDebugger::get_script_debugger()->is_breakpoint(line, source)) {
- do_break = true;
- }
-
- if (do_break) {
- GDScriptLanguage::get_singleton()->debug_break("Breakpoint", true);
- }
-
- EngineDebugger::get_singleton()->line_poll();
- }
- }
- DISPATCH_OPCODE;
-
- OPCODE(OPCODE_END) {
-#ifdef DEBUG_ENABLED
- exit_ok = true;
-#endif
- OPCODE_BREAK;
- }
-
-#if 0 // Enable for debugging.
- default: {
- err_text = "Illegal opcode " + itos(_code_ptr[ip]) + " at address " + itos(ip);
- OPCODE_BREAK;
- }
-#endif
- }
-
- OPCODES_END
-#ifdef DEBUG_ENABLED
- if (exit_ok) {
- OPCODE_OUT;
- }
- //error
- // function, file, line, error, explanation
- String err_file;
- if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->path != "") {
- err_file = p_instance->script->path;
- } else if (script) {
- err_file = script->path;
- }
- if (err_file == "") {
- err_file = "<built-in>";
- }
- String err_func = name;
- if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->name != "") {
- err_func = p_instance->script->name + "." + err_func;
- }
- int err_line = line;
- if (err_text == "") {
- err_text = "Internal Script Error! - opcode #" + itos(last_opcode) + " (report please).";
- }
-
- if (!GDScriptLanguage::get_singleton()->debug_break(err_text, false)) {
- // debugger break did not happen
-
- _err_print_error(err_func.utf8().get_data(), err_file.utf8().get_data(), err_line, err_text.utf8().get_data(), ERR_HANDLER_SCRIPT);
- }
-
-#endif
- OPCODE_OUT;
- }
-
- OPCODES_OUT
-#ifdef DEBUG_ENABLED
- if (GDScriptLanguage::get_singleton()->profiling) {
- uint64_t time_taken = OS::get_singleton()->get_ticks_usec() - function_start_time;
- profile.total_time += time_taken;
- profile.self_time += time_taken - function_call_time;
- profile.frame_total_time += time_taken;
- profile.frame_self_time += time_taken - function_call_time;
- GDScriptLanguage::get_singleton()->script_frame_time += time_taken - function_call_time;
- }
-
- // Check if this is the last time the function is resuming from await
- // Will be true if never awaited as well
- // When it's the last resume it will postpone the exit from stack,
- // so the debugger knows which function triggered the resume of the next function (if any)
- if (!p_state || awaited) {
- if (EngineDebugger::is_active()) {
- GDScriptLanguage::get_singleton()->exit_function();
- }
-#endif
-
- if (_stack_size) {
- //free stack
- for (int i = 0; i < _stack_size; i++) {
- stack[i].~Variant();
- }
- }
-
-#ifdef DEBUG_ENABLED
- }
-#endif
-
- return retvalue;
-}
const int *GDScriptFunction::get_code() const {
return _code_ptr;
@@ -1706,31 +139,13 @@ void GDScriptFunction::debug_get_stack_member_state(int p_line, List<Pair<String
}
}
-GDScriptFunction::GDScriptFunction() :
- function_list(this) {
- _stack_size = 0;
- _call_size = 0;
- rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED;
+GDScriptFunction::GDScriptFunction() {
name = "<anonymous>";
#ifdef DEBUG_ENABLED
- _func_cname = nullptr;
-
{
MutexLock lock(GDScriptLanguage::get_singleton()->lock);
-
GDScriptLanguage::get_singleton()->function_list.add(&function_list);
}
-
- profile.call_count = 0;
- profile.self_time = 0;
- profile.total_time = 0;
- profile.frame_call_count = 0;
- profile.frame_self_time = 0;
- profile.frame_total_time = 0;
- profile.last_frame_call_count = 0;
- profile.last_frame_self_time = 0;
- profile.last_frame_total_time = 0;
-
#endif
}
@@ -1891,506 +306,3 @@ GDScriptFunctionState::~GDScriptFunctionState() {
instances_list.remove_from_list();
}
}
-
-#ifdef DEBUG_ENABLED
-static String _get_variant_string(const Variant &p_variant) {
- String txt;
- if (p_variant.get_type() == Variant::STRING) {
- txt = "\"" + String(p_variant) + "\"";
- } else if (p_variant.get_type() == Variant::STRING_NAME) {
- txt = "&\"" + String(p_variant) + "\"";
- } else if (p_variant.get_type() == Variant::NODE_PATH) {
- txt = "^\"" + String(p_variant) + "\"";
- } else if (p_variant.get_type() == Variant::OBJECT) {
- Object *obj = p_variant;
- if (!obj) {
- txt = "null";
- } else {
- GDScriptNativeClass *cls = Object::cast_to<GDScriptNativeClass>(obj);
- if (cls) {
- txt += cls->get_name();
- txt += " (class)";
- } else {
- txt = obj->get_class();
- if (obj->get_script_instance()) {
- txt += "(" + obj->get_script_instance()->get_script()->get_path() + ")";
- }
- }
- }
- } else {
- txt = p_variant;
- }
- return txt;
-}
-
-static String _disassemble_address(const GDScript *p_script, const GDScriptFunction &p_function, int p_address) {
- int addr = p_address & GDScriptFunction::ADDR_MASK;
-
- switch (p_address >> GDScriptFunction::ADDR_BITS) {
- case GDScriptFunction::ADDR_TYPE_SELF: {
- return "self";
- } break;
- case GDScriptFunction::ADDR_TYPE_CLASS: {
- return "class";
- } break;
- case GDScriptFunction::ADDR_TYPE_MEMBER: {
- return "member(" + p_script->debug_get_member_by_index(addr) + ")";
- } break;
- case GDScriptFunction::ADDR_TYPE_CLASS_CONSTANT: {
- return "class_const(" + p_function.get_global_name(addr) + ")";
- } break;
- case GDScriptFunction::ADDR_TYPE_LOCAL_CONSTANT: {
- return "const(" + _get_variant_string(p_function.get_constant(addr)) + ")";
- } break;
- case GDScriptFunction::ADDR_TYPE_STACK: {
- return "stack(" + itos(addr) + ")";
- } break;
- case GDScriptFunction::ADDR_TYPE_STACK_VARIABLE: {
- return "var_stack(" + itos(addr) + ")";
- } break;
- case GDScriptFunction::ADDR_TYPE_GLOBAL: {
- return "global(" + _get_variant_string(GDScriptLanguage::get_singleton()->get_global_array()[addr]) + ")";
- } break;
- case GDScriptFunction::ADDR_TYPE_NAMED_GLOBAL: {
- return "named_global(" + p_function.get_global_name(addr) + ")";
- } break;
- case GDScriptFunction::ADDR_TYPE_NIL: {
- return "nil";
- } break;
- }
-
- return "<err>";
-}
-
-void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
-#define DADDR(m_ip) (_disassemble_address(_script, *this, _code_ptr[ip + m_ip]))
-
- for (int ip = 0; ip < _code_size;) {
- StringBuilder text;
- int incr = 0;
-
- text += " ";
- text += itos(ip);
- text += ": ";
-
- // This makes the compiler complain if some opcode is unchecked in the switch.
- Opcode code = Opcode(_code_ptr[ip]);
-
- switch (code) {
- case OPCODE_OPERATOR: {
- int operation = _code_ptr[ip + 1];
-
- text += "operator ";
-
- text += DADDR(4);
- text += " = ";
- text += DADDR(2);
- text += " ";
- text += Variant::get_operator_name(Variant::Operator(operation));
- text += " ";
- text += DADDR(3);
-
- incr += 5;
- } break;
- case OPCODE_EXTENDS_TEST: {
- text += "is object ";
- text += DADDR(3);
- text += " = ";
- text += DADDR(1);
- text += " is ";
- text += DADDR(2);
-
- incr += 4;
- } break;
- case OPCODE_IS_BUILTIN: {
- text += "is builtin ";
- text += DADDR(3);
- text += " = ";
- text += DADDR(1);
- text += " is ";
- text += Variant::get_type_name(Variant::Type(_code_ptr[ip + 2]));
-
- incr += 4;
- } break;
- case OPCODE_SET: {
- text += "set ";
- text += DADDR(1);
- text += "[";
- text += DADDR(2);
- text += "] = ";
- text += DADDR(3);
-
- incr += 4;
- } break;
- case OPCODE_GET: {
- text += "get ";
- text += DADDR(3);
- text += " = ";
- text += DADDR(1);
- text += "[";
- text += DADDR(2);
- text += "]";
-
- incr += 4;
- } break;
- case OPCODE_SET_NAMED: {
- text += "set_named ";
- text += DADDR(1);
- text += "[\"";
- text += _global_names_ptr[_code_ptr[ip + 2]];
- text += "\"] = ";
- text += DADDR(3);
-
- incr += 4;
- } break;
- case OPCODE_GET_NAMED: {
- text += "get_named ";
- text += DADDR(3);
- text += " = ";
- text += DADDR(1);
- text += "[\"";
- text += _global_names_ptr[_code_ptr[ip + 2]];
- text += "\"]";
-
- incr += 4;
- } break;
- case OPCODE_SET_MEMBER: {
- text += "set_member ";
- text += "[\"";
- text += _global_names_ptr[_code_ptr[ip + 1]];
- text += "\"] = ";
- text += DADDR(2);
-
- incr += 3;
- } break;
- case OPCODE_GET_MEMBER: {
- text += "get_member ";
- text += DADDR(2);
- text += " = ";
- text += "[\"";
- text += _global_names_ptr[_code_ptr[ip + 1]];
- text += "\"]";
-
- incr += 3;
- } break;
- case OPCODE_ASSIGN: {
- text += "assign ";
- text += DADDR(1);
- text += " = ";
- text += DADDR(2);
-
- incr += 3;
- } break;
- case OPCODE_ASSIGN_TRUE: {
- text += "assign ";
- text += DADDR(1);
- text += " = true";
-
- incr += 2;
- } break;
- case OPCODE_ASSIGN_FALSE: {
- text += "assign ";
- text += DADDR(1);
- text += " = false";
-
- incr += 2;
- } break;
- case OPCODE_ASSIGN_TYPED_BUILTIN: {
- text += "assign typed builtin (";
- text += Variant::get_type_name((Variant::Type)_code_ptr[ip + 1]);
- text += ") ";
- text += DADDR(2);
- text += " = ";
- text += DADDR(3);
-
- incr += 4;
- } break;
- case OPCODE_ASSIGN_TYPED_NATIVE: {
- Variant class_name = _constants_ptr[_code_ptr[ip + 1]];
- GDScriptNativeClass *nc = Object::cast_to<GDScriptNativeClass>(class_name.operator Object *());
-
- text += "assign typed native (";
- text += nc->get_name().operator String();
- text += ") ";
- text += DADDR(2);
- text += " = ";
- text += DADDR(3);
-
- incr += 4;
- } break;
- case OPCODE_ASSIGN_TYPED_SCRIPT: {
- Variant script = _constants_ptr[_code_ptr[ip + 1]];
- Script *sc = Object::cast_to<Script>(script.operator Object *());
-
- text += "assign typed script (";
- text += sc->get_path();
- text += ") ";
- text += DADDR(2);
- text += " = ";
- text += DADDR(3);
-
- incr += 4;
- } break;
- case OPCODE_CAST_TO_BUILTIN: {
- text += "cast builtin ";
- text += DADDR(3);
- text += " = ";
- text += DADDR(2);
- text += " as ";
- text += Variant::get_type_name(Variant::Type(_code_ptr[ip + 1]));
-
- incr += 4;
- } break;
- case OPCODE_CAST_TO_NATIVE: {
- Variant class_name = _constants_ptr[_code_ptr[ip + 1]];
- GDScriptNativeClass *nc = Object::cast_to<GDScriptNativeClass>(class_name.operator Object *());
-
- text += "cast native ";
- text += DADDR(3);
- text += " = ";
- text += DADDR(2);
- text += " as ";
- text += nc->get_name();
-
- incr += 4;
- } break;
- case OPCODE_CAST_TO_SCRIPT: {
- text += "cast ";
- text += DADDR(3);
- text += " = ";
- text += DADDR(2);
- text += " as ";
- text += DADDR(1);
-
- incr += 4;
- } break;
- case OPCODE_CONSTRUCT: {
- Variant::Type t = Variant::Type(_code_ptr[ip + 1]);
- int argc = _code_ptr[ip + 2];
-
- text += "construct ";
- text += DADDR(3 + argc);
- text += " = ";
-
- text += Variant::get_type_name(t) + "(";
- for (int i = 0; i < argc; i++) {
- if (i > 0)
- text += ", ";
- text += DADDR(i + 3);
- }
- text += ")";
-
- incr = 4 + argc;
- } break;
- case OPCODE_CONSTRUCT_ARRAY: {
- int argc = _code_ptr[ip + 1];
- text += " make_array ";
- text += DADDR(2 + argc);
- text += " = [";
-
- for (int i = 0; i < argc; i++) {
- if (i > 0)
- text += ", ";
- text += DADDR(2 + i);
- }
-
- text += "]";
-
- incr += 3 + argc;
- } break;
- case OPCODE_CONSTRUCT_DICTIONARY: {
- int argc = _code_ptr[ip + 1];
- text += "make_dict ";
- text += DADDR(2 + argc * 2);
- text += " = {";
-
- for (int i = 0; i < argc; i++) {
- if (i > 0)
- text += ", ";
- text += DADDR(2 + i * 2 + 0);
- text += ": ";
- text += DADDR(2 + i * 2 + 1);
- }
-
- text += "}";
-
- incr += 3 + argc * 2;
- } break;
- case OPCODE_CALL:
- case OPCODE_CALL_RETURN:
- case OPCODE_CALL_ASYNC: {
- bool ret = _code_ptr[ip] == OPCODE_CALL_RETURN;
- bool async = _code_ptr[ip] == OPCODE_CALL_ASYNC;
-
- if (ret) {
- text += "call-ret ";
- } else if (async) {
- text += "call-async ";
- } else {
- text += "call ";
- }
-
- int argc = _code_ptr[ip + 1];
- if (ret || async) {
- text += DADDR(4 + argc) + " = ";
- }
-
- text += DADDR(2) + ".";
- text += String(_global_names_ptr[_code_ptr[ip + 3]]);
- text += "(";
-
- for (int i = 0; i < argc; i++) {
- if (i > 0)
- text += ", ";
- text += DADDR(4 + i);
- }
- text += ")";
-
- incr = 5 + argc;
- } break;
- case OPCODE_CALL_BUILT_IN: {
- text += "call-built-in ";
-
- int argc = _code_ptr[ip + 2];
- text += DADDR(3 + argc) + " = ";
-
- text += GDScriptFunctions::get_func_name(GDScriptFunctions::Function(_code_ptr[ip + 1]));
- text += "(";
-
- for (int i = 0; i < argc; i++) {
- if (i > 0)
- text += ", ";
- text += DADDR(3 + i);
- }
- text += ")";
-
- incr = 4 + argc;
- } break;
- case OPCODE_CALL_SELF_BASE: {
- text += "call-self-base ";
-
- int argc = _code_ptr[ip + 2];
- text += DADDR(3 + argc) + " = ";
-
- text += _global_names_ptr[_code_ptr[ip + 1]];
- text += "(";
-
- for (int i = 0; i < argc; i++) {
- if (i > 0)
- text += ", ";
- text += DADDR(3 + i);
- }
- text += ")";
-
- incr = 4 + argc;
- } break;
- case OPCODE_AWAIT: {
- text += "await ";
- text += DADDR(1);
-
- incr += 2;
- } break;
- case OPCODE_AWAIT_RESUME: {
- text += "await resume ";
- text += DADDR(1);
-
- incr = 2;
- } break;
- case OPCODE_JUMP: {
- text += "jump ";
- text += itos(_code_ptr[ip + 1]);
-
- incr = 2;
- } break;
- case OPCODE_JUMP_IF: {
- text += "jump-if ";
- text += DADDR(1);
- text += " to ";
- text += itos(_code_ptr[ip + 2]);
-
- incr = 3;
- } break;
- case OPCODE_JUMP_IF_NOT: {
- text += "jump-if-not ";
- text += DADDR(1);
- text += " to ";
- text += itos(_code_ptr[ip + 2]);
-
- incr = 3;
- } break;
- case OPCODE_JUMP_TO_DEF_ARGUMENT: {
- text += "jump-to-default-argument ";
-
- incr = 1;
- } break;
- case OPCODE_RETURN: {
- text += "return ";
- text += DADDR(1);
-
- incr = 2;
- } break;
- case OPCODE_ITERATE_BEGIN: {
- text += "for-init ";
- text += DADDR(4);
- text += " in ";
- text += DADDR(2);
- text += " counter ";
- text += DADDR(1);
- text += " end ";
- text += itos(_code_ptr[ip + 3]);
-
- incr += 5;
- } break;
- case OPCODE_ITERATE: {
- text += "for-loop ";
- text += DADDR(4);
- text += " in ";
- text += DADDR(2);
- text += " counter ";
- text += DADDR(1);
- text += " end ";
- text += itos(_code_ptr[ip + 3]);
-
- incr += 5;
- } break;
- case OPCODE_LINE: {
- int line = _code_ptr[ip + 1] - 1;
- if (line >= 0 && line < p_code_lines.size()) {
- text += "line ";
- text += itos(line + 1);
- text += ": ";
- text += p_code_lines[line];
- } else {
- text += "";
- }
-
- incr += 2;
- } break;
- case OPCODE_ASSERT: {
- text += "assert (";
- text += DADDR(1);
- text += ", ";
- text += DADDR(2);
- text += ")";
-
- incr += 3;
- } break;
- case OPCODE_BREAKPOINT: {
- text += "breakpoint";
-
- incr += 1;
- } break;
- case OPCODE_END: {
- text += "== END ==";
-
- incr += 1;
- } break;
- }
-
- ip += incr;
- if (text.get_string_length() > 0) {
- print_line(text.as_string());
- }
- }
-}
-#endif
diff --git a/modules/gdscript/gdscript_function.h b/modules/gdscript/gdscript_function.h
index 50eadcaf86..bb5cc1284d 100644
--- a/modules/gdscript/gdscript_function.h
+++ b/modules/gdscript/gdscript_function.h
@@ -159,12 +159,19 @@ class GDScriptFunction {
public:
enum Opcode {
OPCODE_OPERATOR,
+ OPCODE_OPERATOR_VALIDATED,
OPCODE_EXTENDS_TEST,
OPCODE_IS_BUILTIN,
- OPCODE_SET,
- OPCODE_GET,
+ OPCODE_SET_KEYED,
+ OPCODE_SET_KEYED_VALIDATED,
+ OPCODE_SET_INDEXED_VALIDATED,
+ OPCODE_GET_KEYED,
+ OPCODE_GET_KEYED_VALIDATED,
+ OPCODE_GET_INDEXED_VALIDATED,
OPCODE_SET_NAMED,
+ OPCODE_SET_NAMED_VALIDATED,
OPCODE_GET_NAMED,
+ OPCODE_GET_NAMED_VALIDATED,
OPCODE_SET_MEMBER,
OPCODE_GET_MEMBER,
OPCODE_ASSIGN,
@@ -176,14 +183,54 @@ public:
OPCODE_CAST_TO_BUILTIN,
OPCODE_CAST_TO_NATIVE,
OPCODE_CAST_TO_SCRIPT,
- OPCODE_CONSTRUCT, //only for basic types!!
+ OPCODE_CONSTRUCT, // Only for basic types!
+ OPCODE_CONSTRUCT_VALIDATED, // Only for basic types!
OPCODE_CONSTRUCT_ARRAY,
OPCODE_CONSTRUCT_DICTIONARY,
OPCODE_CALL,
OPCODE_CALL_RETURN,
OPCODE_CALL_ASYNC,
OPCODE_CALL_BUILT_IN,
+ OPCODE_CALL_BUILTIN_TYPE_VALIDATED,
OPCODE_CALL_SELF_BASE,
+ OPCODE_CALL_METHOD_BIND,
+ OPCODE_CALL_METHOD_BIND_RET,
+ // ptrcall have one instruction per return type.
+ OPCODE_CALL_PTRCALL_NO_RETURN,
+ OPCODE_CALL_PTRCALL_BOOL,
+ OPCODE_CALL_PTRCALL_INT,
+ OPCODE_CALL_PTRCALL_FLOAT,
+ OPCODE_CALL_PTRCALL_STRING,
+ OPCODE_CALL_PTRCALL_VECTOR2,
+ OPCODE_CALL_PTRCALL_VECTOR2I,
+ OPCODE_CALL_PTRCALL_RECT2,
+ OPCODE_CALL_PTRCALL_RECT2I,
+ OPCODE_CALL_PTRCALL_VECTOR3,
+ OPCODE_CALL_PTRCALL_VECTOR3I,
+ OPCODE_CALL_PTRCALL_TRANSFORM2D,
+ OPCODE_CALL_PTRCALL_PLANE,
+ OPCODE_CALL_PTRCALL_QUAT,
+ OPCODE_CALL_PTRCALL_AABB,
+ OPCODE_CALL_PTRCALL_BASIS,
+ OPCODE_CALL_PTRCALL_TRANSFORM,
+ OPCODE_CALL_PTRCALL_COLOR,
+ OPCODE_CALL_PTRCALL_STRING_NAME,
+ OPCODE_CALL_PTRCALL_NODE_PATH,
+ OPCODE_CALL_PTRCALL_RID,
+ OPCODE_CALL_PTRCALL_OBJECT,
+ OPCODE_CALL_PTRCALL_CALLABLE,
+ OPCODE_CALL_PTRCALL_SIGNAL,
+ OPCODE_CALL_PTRCALL_DICTIONARY,
+ OPCODE_CALL_PTRCALL_ARRAY,
+ OPCODE_CALL_PTRCALL_PACKED_BYTE_ARRAY,
+ OPCODE_CALL_PTRCALL_PACKED_INT32_ARRAY,
+ OPCODE_CALL_PTRCALL_PACKED_INT64_ARRAY,
+ OPCODE_CALL_PTRCALL_PACKED_FLOAT32_ARRAY,
+ OPCODE_CALL_PTRCALL_PACKED_FLOAT64_ARRAY,
+ OPCODE_CALL_PTRCALL_PACKED_STRING_ARRAY,
+ OPCODE_CALL_PTRCALL_PACKED_VECTOR2_ARRAY,
+ OPCODE_CALL_PTRCALL_PACKED_VECTOR3_ARRAY,
+ OPCODE_CALL_PTRCALL_PACKED_COLOR_ARRAY,
OPCODE_AWAIT,
OPCODE_AWAIT_RESUME,
OPCODE_JUMP,
@@ -192,7 +239,45 @@ public:
OPCODE_JUMP_TO_DEF_ARGUMENT,
OPCODE_RETURN,
OPCODE_ITERATE_BEGIN,
+ OPCODE_ITERATE_BEGIN_INT,
+ OPCODE_ITERATE_BEGIN_FLOAT,
+ OPCODE_ITERATE_BEGIN_VECTOR2,
+ OPCODE_ITERATE_BEGIN_VECTOR2I,
+ OPCODE_ITERATE_BEGIN_VECTOR3,
+ OPCODE_ITERATE_BEGIN_VECTOR3I,
+ OPCODE_ITERATE_BEGIN_STRING,
+ OPCODE_ITERATE_BEGIN_DICTIONARY,
+ OPCODE_ITERATE_BEGIN_ARRAY,
+ OPCODE_ITERATE_BEGIN_PACKED_BYTE_ARRAY,
+ OPCODE_ITERATE_BEGIN_PACKED_INT32_ARRAY,
+ OPCODE_ITERATE_BEGIN_PACKED_INT64_ARRAY,
+ OPCODE_ITERATE_BEGIN_PACKED_FLOAT32_ARRAY,
+ OPCODE_ITERATE_BEGIN_PACKED_FLOAT64_ARRAY,
+ OPCODE_ITERATE_BEGIN_PACKED_STRING_ARRAY,
+ OPCODE_ITERATE_BEGIN_PACKED_VECTOR2_ARRAY,
+ OPCODE_ITERATE_BEGIN_PACKED_VECTOR3_ARRAY,
+ OPCODE_ITERATE_BEGIN_PACKED_COLOR_ARRAY,
+ OPCODE_ITERATE_BEGIN_OBJECT,
OPCODE_ITERATE,
+ OPCODE_ITERATE_INT,
+ OPCODE_ITERATE_FLOAT,
+ OPCODE_ITERATE_VECTOR2,
+ OPCODE_ITERATE_VECTOR2I,
+ OPCODE_ITERATE_VECTOR3,
+ OPCODE_ITERATE_VECTOR3I,
+ OPCODE_ITERATE_STRING,
+ OPCODE_ITERATE_DICTIONARY,
+ OPCODE_ITERATE_ARRAY,
+ OPCODE_ITERATE_PACKED_BYTE_ARRAY,
+ OPCODE_ITERATE_PACKED_INT32_ARRAY,
+ OPCODE_ITERATE_PACKED_INT64_ARRAY,
+ OPCODE_ITERATE_PACKED_FLOAT32_ARRAY,
+ OPCODE_ITERATE_PACKED_FLOAT64_ARRAY,
+ OPCODE_ITERATE_PACKED_STRING_ARRAY,
+ OPCODE_ITERATE_PACKED_VECTOR2_ARRAY,
+ OPCODE_ITERATE_PACKED_VECTOR3_ARRAY,
+ OPCODE_ITERATE_PACKED_COLOR_ARRAY,
+ OPCODE_ITERATE_OBJECT,
OPCODE_ASSERT,
OPCODE_BREAKPOINT,
OPCODE_LINE,
@@ -215,6 +300,12 @@ public:
ADDR_TYPE_NIL = 9
};
+ enum Instruction {
+ INSTR_BITS = 20,
+ INSTR_MASK = ((1 << INSTR_BITS) - 1),
+ INSTR_ARGS_MASK = ~INSTR_MASK,
+ };
+
struct StackDebug {
int line;
int pos;
@@ -229,27 +320,59 @@ private:
StringName source;
mutable Variant nil;
- mutable Variant *_constants_ptr;
- int _constant_count;
- const StringName *_global_names_ptr;
- int _global_names_count;
- const int *_default_arg_ptr;
- int _default_arg_count;
- const int *_code_ptr;
- int _code_size;
- int _argument_count;
- int _stack_size;
- int _call_size;
- int _initial_line;
- bool _static;
- MultiplayerAPI::RPCMode rpc_mode;
-
- GDScript *_script;
+ mutable Variant *_constants_ptr = nullptr;
+ int _constant_count = 0;
+ const StringName *_global_names_ptr = nullptr;
+ int _global_names_count = 0;
+ const int *_default_arg_ptr = nullptr;
+ int _default_arg_count = 0;
+ int _operator_funcs_count = 0;
+ const Variant::ValidatedOperatorEvaluator *_operator_funcs_ptr = nullptr;
+ int _setters_count = 0;
+ const Variant::ValidatedSetter *_setters_ptr = nullptr;
+ int _getters_count = 0;
+ const Variant::ValidatedGetter *_getters_ptr = nullptr;
+ int _keyed_setters_count = 0;
+ const Variant::ValidatedKeyedSetter *_keyed_setters_ptr = nullptr;
+ int _keyed_getters_count = 0;
+ const Variant::ValidatedKeyedGetter *_keyed_getters_ptr = nullptr;
+ int _indexed_setters_count = 0;
+ const Variant::ValidatedIndexedSetter *_indexed_setters_ptr = nullptr;
+ int _indexed_getters_count = 0;
+ const Variant::ValidatedIndexedGetter *_indexed_getters_ptr = nullptr;
+ int _builtin_methods_count = 0;
+ const Variant::ValidatedBuiltInMethod *_builtin_methods_ptr = nullptr;
+ int _constructors_count = 0;
+ const Variant::ValidatedConstructor *_constructors_ptr = nullptr;
+ int _methods_count = 0;
+ MethodBind **_methods_ptr = nullptr;
+ const int *_code_ptr = nullptr;
+ int _code_size = 0;
+ int _argument_count = 0;
+ int _stack_size = 0;
+ int _instruction_args_size = 0;
+ int _ptrcall_args_size = 0;
+
+ int _initial_line = 0;
+ bool _static = false;
+ MultiplayerAPI::RPCMode rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED;
+
+ GDScript *_script = nullptr;
StringName name;
Vector<Variant> constants;
Vector<StringName> global_names;
Vector<int> default_arguments;
+ Vector<Variant::ValidatedOperatorEvaluator> operator_funcs;
+ Vector<Variant::ValidatedSetter> setters;
+ Vector<Variant::ValidatedGetter> getters;
+ Vector<Variant::ValidatedKeyedSetter> keyed_setters;
+ Vector<Variant::ValidatedKeyedGetter> keyed_getters;
+ Vector<Variant::ValidatedIndexedSetter> indexed_setters;
+ Vector<Variant::ValidatedIndexedGetter> indexed_getters;
+ Vector<Variant::ValidatedBuiltInMethod> builtin_methods;
+ Vector<Variant::ValidatedConstructor> constructors;
+ Vector<MethodBind *> methods;
Vector<int> code;
Vector<GDScriptDataType> argument_types;
GDScriptDataType return_type;
@@ -265,22 +388,22 @@ private:
friend class GDScriptLanguage;
- SelfList<GDScriptFunction> function_list;
+ SelfList<GDScriptFunction> function_list{ this };
#ifdef DEBUG_ENABLED
CharString func_cname;
- const char *_func_cname;
+ const char *_func_cname = nullptr;
struct Profile {
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;
+ uint64_t call_count = 0;
+ uint64_t self_time = 0;
+ uint64_t total_time = 0;
+ uint64_t frame_call_count = 0;
+ uint64_t frame_self_time = 0;
+ uint64_t frame_total_time = 0;
+ uint64_t last_frame_call_count = 0;
+ uint64_t last_frame_self_time = 0;
+ uint64_t last_frame_total_time = 0;
} profile;
#endif
diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp
new file mode 100644
index 0000000000..7c8bfcd944
--- /dev/null
+++ b/modules/gdscript/gdscript_vm.cpp
@@ -0,0 +1,2863 @@
+/*************************************************************************/
+/* gdscript_vm.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* 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 "gdscript_function.h"
+
+#include "core/core_string_names.h"
+#include "core/os/os.h"
+#include "gdscript.h"
+#include "gdscript_functions.h"
+
+Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_instance, GDScript *p_script, Variant &self, Variant &static_ref, Variant *p_stack, String &r_error) const {
+ int address = p_address & ADDR_MASK;
+
+ //sequential table (jump table generated by compiler)
+ switch ((p_address & ADDR_TYPE_MASK) >> ADDR_BITS) {
+ case ADDR_TYPE_SELF: {
+#ifdef DEBUG_ENABLED
+ if (unlikely(!p_instance)) {
+ r_error = "Cannot access self without instance.";
+ return nullptr;
+ }
+#endif
+ return &self;
+ } break;
+ case ADDR_TYPE_CLASS: {
+ return &static_ref;
+ } break;
+ case ADDR_TYPE_MEMBER: {
+#ifdef DEBUG_ENABLED
+ if (unlikely(!p_instance)) {
+ r_error = "Cannot access member without instance.";
+ return nullptr;
+ }
+#endif
+ //member indexing is O(1)
+ return &p_instance->members.write[address];
+ } break;
+ case ADDR_TYPE_CLASS_CONSTANT: {
+ //todo change to index!
+ GDScript *s = p_script;
+#ifdef DEBUG_ENABLED
+ ERR_FAIL_INDEX_V(address, _global_names_count, nullptr);
+#endif
+ const StringName *sn = &_global_names_ptr[address];
+
+ while (s) {
+ GDScript *o = s;
+ while (o) {
+ Map<StringName, Variant>::Element *E = o->constants.find(*sn);
+ if (E) {
+ return &E->get();
+ }
+ o = o->_owner;
+ }
+ s = s->_base;
+ }
+
+ ERR_FAIL_V_MSG(nullptr, "GDScriptCompiler bug.");
+ } break;
+ case ADDR_TYPE_LOCAL_CONSTANT: {
+#ifdef DEBUG_ENABLED
+ ERR_FAIL_INDEX_V(address, _constant_count, nullptr);
+#endif
+ return &_constants_ptr[address];
+ } break;
+ case ADDR_TYPE_STACK:
+ case ADDR_TYPE_STACK_VARIABLE: {
+#ifdef DEBUG_ENABLED
+ ERR_FAIL_INDEX_V(address, _stack_size, nullptr);
+#endif
+ return &p_stack[address];
+ } break;
+ case ADDR_TYPE_GLOBAL: {
+#ifdef DEBUG_ENABLED
+ ERR_FAIL_INDEX_V(address, GDScriptLanguage::get_singleton()->get_global_array_size(), nullptr);
+#endif
+ return &GDScriptLanguage::get_singleton()->get_global_array()[address];
+ } break;
+#ifdef TOOLS_ENABLED
+ case ADDR_TYPE_NAMED_GLOBAL: {
+#ifdef DEBUG_ENABLED
+ ERR_FAIL_INDEX_V(address, _global_names_count, nullptr);
+#endif
+ StringName id = _global_names_ptr[address];
+
+ if (GDScriptLanguage::get_singleton()->get_named_globals_map().has(id)) {
+ return (Variant *)&GDScriptLanguage::get_singleton()->get_named_globals_map()[id];
+ } else {
+ r_error = "Autoload singleton '" + String(id) + "' has been removed.";
+ return nullptr;
+ }
+ } break;
+#endif
+ case ADDR_TYPE_NIL: {
+ return &nil;
+ } break;
+ }
+
+ ERR_FAIL_V_MSG(nullptr, "Bad code! (unknown addressing mode).");
+ return nullptr;
+}
+
+#ifdef DEBUG_ENABLED
+static String _get_var_type(const Variant *p_var) {
+ String basestr;
+
+ if (p_var->get_type() == Variant::OBJECT) {
+ bool was_freed;
+ Object *bobj = p_var->get_validated_object_with_check(was_freed);
+ if (!bobj) {
+ if (was_freed) {
+ basestr = "null instance";
+ } else {
+ basestr = "previously freed";
+ }
+ } else {
+ if (bobj->get_script_instance()) {
+ basestr = bobj->get_class() + " (" + bobj->get_script_instance()->get_script()->get_path().get_file() + ")";
+ } else {
+ basestr = bobj->get_class();
+ }
+ }
+
+ } else {
+ basestr = Variant::get_type_name(p_var->get_type());
+ }
+
+ return basestr;
+}
+#endif // DEBUG_ENABLED
+
+String GDScriptFunction::_get_call_error(const Callable::CallError &p_err, const String &p_where, const Variant **argptrs) const {
+ String err_text;
+
+ if (p_err.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) {
+ int errorarg = p_err.argument;
+ // Handle the Object to Object case separately as we don't have further class details.
+#ifdef DEBUG_ENABLED
+ if (p_err.expected == Variant::OBJECT && argptrs[errorarg]->get_type() == p_err.expected) {
+ err_text = "Invalid type in " + p_where + ". The Object-derived class of argument " + itos(errorarg + 1) + " (" + _get_var_type(argptrs[errorarg]) + ") is not a subclass of the expected argument class.";
+ } else
+#endif // DEBUG_ENABLED
+ {
+ err_text = "Invalid type in " + p_where + ". Cannot convert argument " + itos(errorarg + 1) + " from " + Variant::get_type_name(argptrs[errorarg]->get_type()) + " to " + Variant::get_type_name(Variant::Type(p_err.expected)) + ".";
+ }
+ } else if (p_err.error == Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) {
+ err_text = "Invalid call to " + p_where + ". Expected " + itos(p_err.argument) + " arguments.";
+ } else if (p_err.error == Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) {
+ err_text = "Invalid call to " + p_where + ". Expected " + itos(p_err.argument) + " arguments.";
+ } else if (p_err.error == Callable::CallError::CALL_ERROR_INVALID_METHOD) {
+ err_text = "Invalid call. Nonexistent " + p_where + ".";
+ } else if (p_err.error == Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL) {
+ err_text = "Attempt to call " + p_where + " on a null instance.";
+ } else {
+ err_text = "Bug, call error: #" + itos(p_err.error);
+ }
+
+ return err_text;
+}
+
+#if defined(__GNUC__)
+#define OPCODES_TABLE \
+ static const void *switch_table_ops[] = { \
+ &&OPCODE_OPERATOR, \
+ &&OPCODE_OPERATOR_VALIDATED, \
+ &&OPCODE_EXTENDS_TEST, \
+ &&OPCODE_IS_BUILTIN, \
+ &&OPCODE_SET_KEYED, \
+ &&OPCODE_SET_KEYED_VALIDATED, \
+ &&OPCODE_SET_INDEXED_VALIDATED, \
+ &&OPCODE_GET_KEYED, \
+ &&OPCODE_GET_KEYED_VALIDATED, \
+ &&OPCODE_GET_INDEXED_VALIDATED, \
+ &&OPCODE_SET_NAMED, \
+ &&OPCODE_SET_NAMED_VALIDATED, \
+ &&OPCODE_GET_NAMED, \
+ &&OPCODE_GET_NAMED_VALIDATED, \
+ &&OPCODE_SET_MEMBER, \
+ &&OPCODE_GET_MEMBER, \
+ &&OPCODE_ASSIGN, \
+ &&OPCODE_ASSIGN_TRUE, \
+ &&OPCODE_ASSIGN_FALSE, \
+ &&OPCODE_ASSIGN_TYPED_BUILTIN, \
+ &&OPCODE_ASSIGN_TYPED_NATIVE, \
+ &&OPCODE_ASSIGN_TYPED_SCRIPT, \
+ &&OPCODE_CAST_TO_BUILTIN, \
+ &&OPCODE_CAST_TO_NATIVE, \
+ &&OPCODE_CAST_TO_SCRIPT, \
+ &&OPCODE_CONSTRUCT, \
+ &&OPCODE_CONSTRUCT_VALIDATED, \
+ &&OPCODE_CONSTRUCT_ARRAY, \
+ &&OPCODE_CONSTRUCT_DICTIONARY, \
+ &&OPCODE_CALL, \
+ &&OPCODE_CALL_RETURN, \
+ &&OPCODE_CALL_ASYNC, \
+ &&OPCODE_CALL_BUILT_IN, \
+ &&OPCODE_CALL_BUILTIN_TYPE_VALIDATED, \
+ &&OPCODE_CALL_SELF_BASE, \
+ &&OPCODE_CALL_METHOD_BIND, \
+ &&OPCODE_CALL_METHOD_BIND_RET, \
+ &&OPCODE_CALL_PTRCALL_NO_RETURN, \
+ &&OPCODE_CALL_PTRCALL_BOOL, \
+ &&OPCODE_CALL_PTRCALL_INT, \
+ &&OPCODE_CALL_PTRCALL_FLOAT, \
+ &&OPCODE_CALL_PTRCALL_STRING, \
+ &&OPCODE_CALL_PTRCALL_VECTOR2, \
+ &&OPCODE_CALL_PTRCALL_VECTOR2I, \
+ &&OPCODE_CALL_PTRCALL_RECT2, \
+ &&OPCODE_CALL_PTRCALL_RECT2I, \
+ &&OPCODE_CALL_PTRCALL_VECTOR3, \
+ &&OPCODE_CALL_PTRCALL_VECTOR3I, \
+ &&OPCODE_CALL_PTRCALL_TRANSFORM2D, \
+ &&OPCODE_CALL_PTRCALL_PLANE, \
+ &&OPCODE_CALL_PTRCALL_QUAT, \
+ &&OPCODE_CALL_PTRCALL_AABB, \
+ &&OPCODE_CALL_PTRCALL_BASIS, \
+ &&OPCODE_CALL_PTRCALL_TRANSFORM, \
+ &&OPCODE_CALL_PTRCALL_COLOR, \
+ &&OPCODE_CALL_PTRCALL_STRING_NAME, \
+ &&OPCODE_CALL_PTRCALL_NODE_PATH, \
+ &&OPCODE_CALL_PTRCALL_RID, \
+ &&OPCODE_CALL_PTRCALL_OBJECT, \
+ &&OPCODE_CALL_PTRCALL_CALLABLE, \
+ &&OPCODE_CALL_PTRCALL_SIGNAL, \
+ &&OPCODE_CALL_PTRCALL_DICTIONARY, \
+ &&OPCODE_CALL_PTRCALL_ARRAY, \
+ &&OPCODE_CALL_PTRCALL_PACKED_BYTE_ARRAY, \
+ &&OPCODE_CALL_PTRCALL_PACKED_INT32_ARRAY, \
+ &&OPCODE_CALL_PTRCALL_PACKED_INT64_ARRAY, \
+ &&OPCODE_CALL_PTRCALL_PACKED_FLOAT32_ARRAY, \
+ &&OPCODE_CALL_PTRCALL_PACKED_FLOAT64_ARRAY, \
+ &&OPCODE_CALL_PTRCALL_PACKED_STRING_ARRAY, \
+ &&OPCODE_CALL_PTRCALL_PACKED_VECTOR2_ARRAY, \
+ &&OPCODE_CALL_PTRCALL_PACKED_VECTOR3_ARRAY, \
+ &&OPCODE_CALL_PTRCALL_PACKED_COLOR_ARRAY, \
+ &&OPCODE_AWAIT, \
+ &&OPCODE_AWAIT_RESUME, \
+ &&OPCODE_JUMP, \
+ &&OPCODE_JUMP_IF, \
+ &&OPCODE_JUMP_IF_NOT, \
+ &&OPCODE_JUMP_TO_DEF_ARGUMENT, \
+ &&OPCODE_RETURN, \
+ &&OPCODE_ITERATE_BEGIN, \
+ &&OPCODE_ITERATE_BEGIN_INT, \
+ &&OPCODE_ITERATE_BEGIN_FLOAT, \
+ &&OPCODE_ITERATE_BEGIN_VECTOR2, \
+ &&OPCODE_ITERATE_BEGIN_VECTOR2I, \
+ &&OPCODE_ITERATE_BEGIN_VECTOR3, \
+ &&OPCODE_ITERATE_BEGIN_VECTOR3I, \
+ &&OPCODE_ITERATE_BEGIN_STRING, \
+ &&OPCODE_ITERATE_BEGIN_DICTIONARY, \
+ &&OPCODE_ITERATE_BEGIN_ARRAY, \
+ &&OPCODE_ITERATE_BEGIN_PACKED_BYTE_ARRAY, \
+ &&OPCODE_ITERATE_BEGIN_PACKED_INT32_ARRAY, \
+ &&OPCODE_ITERATE_BEGIN_PACKED_INT64_ARRAY, \
+ &&OPCODE_ITERATE_BEGIN_PACKED_FLOAT32_ARRAY, \
+ &&OPCODE_ITERATE_BEGIN_PACKED_FLOAT64_ARRAY, \
+ &&OPCODE_ITERATE_BEGIN_PACKED_STRING_ARRAY, \
+ &&OPCODE_ITERATE_BEGIN_PACKED_VECTOR2_ARRAY, \
+ &&OPCODE_ITERATE_BEGIN_PACKED_VECTOR3_ARRAY, \
+ &&OPCODE_ITERATE_BEGIN_PACKED_COLOR_ARRAY, \
+ &&OPCODE_ITERATE_BEGIN_OBJECT, \
+ &&OPCODE_ITERATE, \
+ &&OPCODE_ITERATE_INT, \
+ &&OPCODE_ITERATE_FLOAT, \
+ &&OPCODE_ITERATE_VECTOR2, \
+ &&OPCODE_ITERATE_VECTOR2I, \
+ &&OPCODE_ITERATE_VECTOR3, \
+ &&OPCODE_ITERATE_VECTOR3I, \
+ &&OPCODE_ITERATE_STRING, \
+ &&OPCODE_ITERATE_DICTIONARY, \
+ &&OPCODE_ITERATE_ARRAY, \
+ &&OPCODE_ITERATE_PACKED_BYTE_ARRAY, \
+ &&OPCODE_ITERATE_PACKED_INT32_ARRAY, \
+ &&OPCODE_ITERATE_PACKED_INT64_ARRAY, \
+ &&OPCODE_ITERATE_PACKED_FLOAT32_ARRAY, \
+ &&OPCODE_ITERATE_PACKED_FLOAT64_ARRAY, \
+ &&OPCODE_ITERATE_PACKED_STRING_ARRAY, \
+ &&OPCODE_ITERATE_PACKED_VECTOR2_ARRAY, \
+ &&OPCODE_ITERATE_PACKED_VECTOR3_ARRAY, \
+ &&OPCODE_ITERATE_PACKED_COLOR_ARRAY, \
+ &&OPCODE_ITERATE_OBJECT, \
+ &&OPCODE_ASSERT, \
+ &&OPCODE_BREAKPOINT, \
+ &&OPCODE_LINE, \
+ &&OPCODE_END \
+ }; \
+ static_assert((sizeof(switch_table_ops) / sizeof(switch_table_ops[0]) == (OPCODE_END + 1)), "Opcodes in jump table aren't the same as opcodes in enum.");
+
+#define OPCODE(m_op) \
+ m_op:
+#define OPCODE_WHILE(m_test) \
+ OPSWHILE:
+#define OPCODES_END \
+ OPSEXIT:
+#define OPCODES_OUT \
+ OPSOUT:
+#define DISPATCH_OPCODE goto OPSWHILE
+#define OPCODE_SWITCH(m_test) goto *switch_table_ops[m_test];
+#define OPCODE_BREAK goto OPSEXIT
+#define OPCODE_OUT goto OPSOUT
+#else
+#define OPCODES_TABLE
+#define OPCODE(m_op) case m_op:
+#define OPCODE_WHILE(m_test) while (m_test)
+#define OPCODES_END
+#define OPCODES_OUT
+#define DISPATCH_OPCODE continue
+#define OPCODE_SWITCH(m_test) switch (m_test)
+#define OPCODE_BREAK break
+#define OPCODE_OUT break
+#endif
+
+// Helpers for VariantInternal methods in macros.
+#define OP_GET_BOOL get_bool
+#define OP_GET_INT get_int
+#define OP_GET_FLOAT get_float
+#define OP_GET_VECTOR2 get_vector2
+#define OP_GET_VECTOR2I get_vector2i
+#define OP_GET_VECTOR3 get_vector3
+#define OP_GET_VECTOR3I get_vector3i
+#define OP_GET_RECT2 get_rect2
+#define OP_GET_RECT2I get_rect2i
+#define OP_GET_QUAT get_quat
+#define OP_GET_COLOR get_color
+#define OP_GET_STRING get_string
+#define OP_GET_STRING_NAME get_string_name
+#define OP_GET_NODE_PATH get_node_path
+#define OP_GET_CALLABLE get_callable
+#define OP_GET_SIGNAL get_signal
+#define OP_GET_ARRAY get_array
+#define OP_GET_DICTIONARY get_dictionary
+#define OP_GET_PACKED_BYTE_ARRAY get_byte_array
+#define OP_GET_PACKED_INT32_ARRAY get_int32_array
+#define OP_GET_PACKED_INT64_ARRAY get_int64_array
+#define OP_GET_PACKED_FLOAT32_ARRAY get_float32_array
+#define OP_GET_PACKED_FLOAT64_ARRAY get_float64_array
+#define OP_GET_PACKED_STRING_ARRAY get_string_array
+#define OP_GET_PACKED_VECTOR2_ARRAY get_vector2_array
+#define OP_GET_PACKED_VECTOR3_ARRAY get_vector3_array
+#define OP_GET_PACKED_COLOR_ARRAY get_color_array
+#define OP_GET_TRANSFORM get_transform
+#define OP_GET_TRANSFORM2D get_transform2d
+#define OP_GET_PLANE get_plane
+#define OP_GET_AABB get_aabb
+#define OP_GET_BASIS get_basis
+#define OP_GET_RID get_rid
+
+Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_args, int p_argcount, Callable::CallError &r_err, CallState *p_state) {
+ OPCODES_TABLE;
+
+ if (!_code_ptr) {
+ return Variant();
+ }
+
+ r_err.error = Callable::CallError::CALL_OK;
+
+ Variant self;
+ Variant static_ref;
+ Variant retvalue;
+ Variant *stack = nullptr;
+ Variant **instruction_args;
+ const void **call_args_ptr = nullptr;
+ int defarg = 0;
+
+#ifdef DEBUG_ENABLED
+
+ //GDScriptLanguage::get_singleton()->calls++;
+
+#endif
+
+ uint32_t alloca_size = 0;
+ GDScript *script;
+ int ip = 0;
+ int line = _initial_line;
+
+ if (p_state) {
+ //use existing (supplied) state (awaited)
+ stack = (Variant *)p_state->stack.ptr();
+ instruction_args = (Variant **)&p_state->stack.ptr()[sizeof(Variant) * p_state->stack_size]; //ptr() to avoid bounds check
+ line = p_state->line;
+ ip = p_state->ip;
+ alloca_size = p_state->stack.size();
+ script = p_state->script;
+ p_instance = p_state->instance;
+ defarg = p_state->defarg;
+ self = p_state->self;
+
+ } else {
+ if (p_argcount != _argument_count) {
+ if (p_argcount > _argument_count) {
+ r_err.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
+ r_err.argument = _argument_count;
+
+ return Variant();
+ } else if (p_argcount < _argument_count - _default_arg_count) {
+ r_err.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_err.argument = _argument_count - _default_arg_count;
+ return Variant();
+ } else {
+ defarg = _argument_count - p_argcount;
+ }
+ }
+
+ alloca_size = sizeof(Variant *) * _instruction_args_size + sizeof(Variant) * _stack_size;
+
+ if (alloca_size) {
+ uint8_t *aptr = (uint8_t *)alloca(alloca_size);
+
+ if (_stack_size) {
+ stack = (Variant *)aptr;
+ for (int i = 0; i < p_argcount; i++) {
+ if (!argument_types[i].has_type) {
+ memnew_placement(&stack[i], Variant(*p_args[i]));
+ continue;
+ }
+
+ if (!argument_types[i].is_type(*p_args[i], true)) {
+ r_err.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_err.argument = i;
+ r_err.expected = argument_types[i].kind == GDScriptDataType::BUILTIN ? argument_types[i].builtin_type : Variant::OBJECT;
+ return Variant();
+ }
+ if (argument_types[i].kind == GDScriptDataType::BUILTIN) {
+ Variant arg;
+ Variant::construct(argument_types[i].builtin_type, arg, &p_args[i], 1, r_err);
+ memnew_placement(&stack[i], Variant(arg));
+ } else {
+ memnew_placement(&stack[i], Variant(*p_args[i]));
+ }
+ }
+ for (int i = p_argcount; i < _stack_size; i++) {
+ memnew_placement(&stack[i], Variant);
+ }
+ } else {
+ stack = nullptr;
+ }
+
+ if (_instruction_args_size) {
+ instruction_args = (Variant **)&aptr[sizeof(Variant) * _stack_size];
+ } else {
+ instruction_args = nullptr;
+ }
+
+ } else {
+ stack = nullptr;
+ instruction_args = nullptr;
+ }
+
+ if (p_instance) {
+ if (p_instance->base_ref && static_cast<Reference *>(p_instance->owner)->is_referenced()) {
+ self = REF(static_cast<Reference *>(p_instance->owner));
+ } else {
+ self = p_instance->owner;
+ }
+ script = p_instance->script.ptr();
+ } else {
+ script = _script;
+ }
+ }
+ if (_ptrcall_args_size) {
+ call_args_ptr = (const void **)alloca(_ptrcall_args_size * sizeof(void *));
+ } else {
+ call_args_ptr = nullptr;
+ }
+
+ static_ref = script;
+
+ String err_text;
+
+#ifdef DEBUG_ENABLED
+
+ if (EngineDebugger::is_active()) {
+ GDScriptLanguage::get_singleton()->enter_function(p_instance, this, stack, &ip, &line);
+ }
+
+#define GD_ERR_BREAK(m_cond) \
+ { \
+ if (unlikely(m_cond)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Breaking..:"); \
+ OPCODE_BREAK; \
+ } \
+ }
+
+#define CHECK_SPACE(m_space) \
+ GD_ERR_BREAK((ip + m_space) > _code_size)
+
+#define GET_VARIANT_PTR(m_v, m_code_ofs) \
+ Variant *m_v; \
+ m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, script, self, static_ref, stack, err_text); \
+ if (unlikely(!m_v)) \
+ OPCODE_BREAK;
+
+#else
+#define GD_ERR_BREAK(m_cond)
+#define CHECK_SPACE(m_space)
+#define GET_VARIANT_PTR(m_v, m_code_ofs) \
+ Variant *m_v; \
+ m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, script, self, static_ref, stack, err_text);
+
+#endif
+
+#define GET_INSTRUCTION_ARG(m_v, m_idx) \
+ Variant *m_v = instruction_args[m_idx]
+
+#ifdef DEBUG_ENABLED
+
+ uint64_t function_start_time = 0;
+ uint64_t function_call_time = 0;
+
+ if (GDScriptLanguage::get_singleton()->profiling) {
+ function_start_time = OS::get_singleton()->get_ticks_usec();
+ function_call_time = 0;
+ profile.call_count++;
+ profile.frame_call_count++;
+ }
+ bool exit_ok = false;
+ bool awaited = false;
+#endif
+
+#ifdef DEBUG_ENABLED
+ OPCODE_WHILE(ip < _code_size) {
+ int last_opcode = _code_ptr[ip];
+#else
+ OPCODE_WHILE(true) {
+#endif
+ // Load arguments for the instruction before each instruction.
+ int instr_arg_count = ((_code_ptr[ip]) & INSTR_ARGS_MASK) >> INSTR_BITS;
+ for (int i = 0; i < instr_arg_count; i++) {
+ GET_VARIANT_PTR(v, i + 1);
+ instruction_args[i] = v;
+ }
+
+ OPCODE_SWITCH(_code_ptr[ip] & INSTR_MASK) {
+ OPCODE(OPCODE_OPERATOR) {
+ CHECK_SPACE(5);
+
+ bool valid;
+ Variant::Operator op = (Variant::Operator)_code_ptr[ip + 4];
+ GD_ERR_BREAK(op >= Variant::OP_MAX);
+
+ GET_INSTRUCTION_ARG(a, 0);
+ GET_INSTRUCTION_ARG(b, 1);
+ GET_INSTRUCTION_ARG(dst, 2);
+
+#ifdef DEBUG_ENABLED
+
+ Variant ret;
+ Variant::evaluate(op, *a, *b, ret, valid);
+#else
+ Variant::evaluate(op, *a, *b, *dst, valid);
+#endif
+#ifdef DEBUG_ENABLED
+ if (!valid) {
+ if (ret.get_type() == Variant::STRING) {
+ //return a string when invalid with the error
+ err_text = ret;
+ err_text += " in operator '" + Variant::get_operator_name(op) + "'.";
+ } else {
+ err_text = "Invalid operands '" + Variant::get_type_name(a->get_type()) + "' and '" + Variant::get_type_name(b->get_type()) + "' in operator '" + Variant::get_operator_name(op) + "'.";
+ }
+ OPCODE_BREAK;
+ }
+ *dst = ret;
+#endif
+ ip += 5;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_OPERATOR_VALIDATED) {
+ CHECK_SPACE(5);
+
+ int operator_idx = _code_ptr[ip + 4];
+ GD_ERR_BREAK(operator_idx < 0 || operator_idx >= _operator_funcs_count);
+ Variant::ValidatedOperatorEvaluator operator_func = _operator_funcs_ptr[operator_idx];
+
+ GET_INSTRUCTION_ARG(a, 0);
+ GET_INSTRUCTION_ARG(b, 1);
+ GET_INSTRUCTION_ARG(dst, 2);
+
+ operator_func(a, b, dst);
+
+ ip += 5;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_EXTENDS_TEST) {
+ CHECK_SPACE(4);
+
+ GET_INSTRUCTION_ARG(a, 0);
+ GET_INSTRUCTION_ARG(b, 1);
+ GET_INSTRUCTION_ARG(dst, 2);
+
+#ifdef DEBUG_ENABLED
+ if (b->get_type() != Variant::OBJECT || b->operator Object *() == nullptr) {
+ err_text = "Right operand of 'is' is not a class.";
+ OPCODE_BREAK;
+ }
+#endif
+
+ bool extends_ok = false;
+ if (a->get_type() == Variant::OBJECT && a->operator Object *() != nullptr) {
+#ifdef DEBUG_ENABLED
+ bool was_freed;
+ Object *obj_A = a->get_validated_object_with_check(was_freed);
+
+ if (was_freed) {
+ err_text = "Left operand of 'is' is a previously freed instance.";
+ OPCODE_BREAK;
+ }
+
+ Object *obj_B = b->get_validated_object_with_check(was_freed);
+
+ if (was_freed) {
+ err_text = "Right operand of 'is' is a previously freed instance.";
+ OPCODE_BREAK;
+ }
+#else
+
+ Object *obj_A = *a;
+ Object *obj_B = *b;
+#endif // DEBUG_ENABLED
+
+ GDScript *scr_B = Object::cast_to<GDScript>(obj_B);
+
+ if (scr_B) {
+ //if B is a script, the only valid condition is that A has an instance which inherits from the script
+ //in other situation, this shoul return false.
+
+ if (obj_A->get_script_instance() && obj_A->get_script_instance()->get_language() == GDScriptLanguage::get_singleton()) {
+ GDScript *cmp = static_cast<GDScript *>(obj_A->get_script_instance()->get_script().ptr());
+ //bool found=false;
+ while (cmp) {
+ if (cmp == scr_B) {
+ //inherits from script, all ok
+ extends_ok = true;
+ break;
+ }
+
+ cmp = cmp->_base;
+ }
+ }
+
+ } else {
+ GDScriptNativeClass *nc = Object::cast_to<GDScriptNativeClass>(obj_B);
+
+#ifdef DEBUG_ENABLED
+ if (!nc) {
+ err_text = "Right operand of 'is' is not a class (type: '" + obj_B->get_class() + "').";
+ OPCODE_BREAK;
+ }
+#endif
+ extends_ok = ClassDB::is_parent_class(obj_A->get_class_name(), nc->get_name());
+ }
+ }
+
+ *dst = extends_ok;
+ ip += 4;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_IS_BUILTIN) {
+ CHECK_SPACE(4);
+
+ GET_INSTRUCTION_ARG(value, 0);
+ GET_INSTRUCTION_ARG(dst, 1);
+ Variant::Type var_type = (Variant::Type)_code_ptr[ip + 3];
+
+ GD_ERR_BREAK(var_type < 0 || var_type >= Variant::VARIANT_MAX);
+
+ *dst = value->get_type() == var_type;
+ ip += 4;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_SET_KEYED) {
+ CHECK_SPACE(3);
+
+ GET_INSTRUCTION_ARG(dst, 0);
+ GET_INSTRUCTION_ARG(index, 1);
+ GET_INSTRUCTION_ARG(value, 2);
+
+ bool valid;
+ dst->set(*index, *value, &valid);
+
+#ifdef DEBUG_ENABLED
+ if (!valid) {
+ String v = index->operator String();
+ if (v != "") {
+ v = "'" + v + "'";
+ } else {
+ v = "of type '" + _get_var_type(index) + "'";
+ }
+ err_text = "Invalid set index " + v + " (on base: '" + _get_var_type(dst) + "') with value of type '" + _get_var_type(value) + "'";
+ OPCODE_BREAK;
+ }
+#endif
+ ip += 4;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_SET_KEYED_VALIDATED) {
+ CHECK_SPACE(4);
+
+ GET_INSTRUCTION_ARG(dst, 0);
+ GET_INSTRUCTION_ARG(index, 1);
+ GET_INSTRUCTION_ARG(value, 2);
+
+ int index_setter = _code_ptr[ip + 4];
+ GD_ERR_BREAK(index_setter < 0 || index_setter >= _keyed_setters_count);
+ const Variant::ValidatedKeyedSetter setter = _keyed_setters_ptr[index_setter];
+
+ bool valid;
+ setter(dst, index, value, valid);
+
+#ifdef DEBUG_ENABLED
+ if (!valid) {
+ String v = index->operator String();
+ if (v != "") {
+ v = "'" + v + "'";
+ } else {
+ v = "of type '" + _get_var_type(index) + "'";
+ }
+ err_text = "Invalid set index " + v + " (on base: '" + _get_var_type(dst) + "') with value of type '" + _get_var_type(value) + "'";
+ OPCODE_BREAK;
+ }
+#endif
+ ip += 5;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_SET_INDEXED_VALIDATED) {
+ CHECK_SPACE(4);
+
+ GET_INSTRUCTION_ARG(dst, 0);
+ GET_INSTRUCTION_ARG(index, 1);
+ GET_INSTRUCTION_ARG(value, 2);
+
+ int index_setter = _code_ptr[ip + 4];
+ GD_ERR_BREAK(index_setter < 0 || index_setter >= _indexed_setters_count);
+ const Variant::ValidatedIndexedSetter setter = _indexed_setters_ptr[index_setter];
+
+ int64_t int_index = *VariantInternal::get_int(index);
+
+ bool oob;
+ setter(dst, int_index, value, oob);
+
+#ifdef DEBUG_ENABLED
+ if (oob) {
+ String v = index->operator String();
+ if (v != "") {
+ v = "'" + v + "'";
+ } else {
+ v = "of type '" + _get_var_type(index) + "'";
+ }
+ err_text = "Out of bounds set index " + v + " (on base: '" + _get_var_type(dst) + "')";
+ OPCODE_BREAK;
+ }
+#endif
+ ip += 5;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_GET_KEYED) {
+ CHECK_SPACE(3);
+
+ GET_INSTRUCTION_ARG(src, 0);
+ GET_INSTRUCTION_ARG(index, 1);
+ GET_INSTRUCTION_ARG(dst, 2);
+
+ bool valid;
+#ifdef DEBUG_ENABLED
+ // Allow better error message in cases where src and dst are the same stack position.
+ Variant ret = src->get(*index, &valid);
+#else
+ *dst = src->get(*index, &valid);
+
+#endif
+#ifdef DEBUG_ENABLED
+ if (!valid) {
+ String v = index->operator String();
+ if (v != "") {
+ v = "'" + v + "'";
+ } else {
+ v = "of type '" + _get_var_type(index) + "'";
+ }
+ err_text = "Invalid get index " + v + " (on base: '" + _get_var_type(src) + "').";
+ OPCODE_BREAK;
+ }
+ *dst = ret;
+#endif
+ ip += 4;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_GET_KEYED_VALIDATED) {
+ CHECK_SPACE(4);
+
+ GET_INSTRUCTION_ARG(src, 0);
+ GET_INSTRUCTION_ARG(key, 1);
+ GET_INSTRUCTION_ARG(dst, 2);
+
+ int index_getter = _code_ptr[ip + 4];
+ GD_ERR_BREAK(index_getter < 0 || index_getter >= _keyed_getters_count);
+ const Variant::ValidatedKeyedGetter getter = _keyed_getters_ptr[index_getter];
+
+ bool valid;
+#ifdef DEBUG_ENABLED
+ // Allow better error message in cases where src and dst are the same stack position.
+ Variant ret;
+ getter(src, key, &ret, valid);
+#else
+ getter(src, key, dst, valid);
+#endif
+#ifdef DEBUG_ENABLED
+ if (!valid) {
+ String v = key->operator String();
+ if (v != "") {
+ v = "'" + v + "'";
+ } else {
+ v = "of type '" + _get_var_type(key) + "'";
+ }
+ err_text = "Invalid get index " + v + " (on base: '" + _get_var_type(src) + "').";
+ OPCODE_BREAK;
+ }
+ *dst = ret;
+#endif
+ ip += 5;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_GET_INDEXED_VALIDATED) {
+ CHECK_SPACE(4);
+
+ GET_INSTRUCTION_ARG(src, 0);
+ GET_INSTRUCTION_ARG(index, 1);
+ GET_INSTRUCTION_ARG(dst, 2);
+
+ int index_getter = _code_ptr[ip + 4];
+ GD_ERR_BREAK(index_getter < 0 || index_getter >= _indexed_getters_count);
+ const Variant::ValidatedIndexedGetter getter = _indexed_getters_ptr[index_getter];
+
+ int64_t int_index = *VariantInternal::get_int(index);
+
+ bool oob;
+ getter(src, int_index, dst, oob);
+
+#ifdef DEBUG_ENABLED
+ if (oob) {
+ String v = index->operator String();
+ if (v != "") {
+ v = "'" + v + "'";
+ } else {
+ v = "of type '" + _get_var_type(index) + "'";
+ }
+ err_text = "Out of bounds get index " + v + " (on base: '" + _get_var_type(src) + "')";
+ OPCODE_BREAK;
+ }
+#endif
+ ip += 5;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_SET_NAMED) {
+ CHECK_SPACE(3);
+
+ GET_INSTRUCTION_ARG(dst, 0);
+ GET_INSTRUCTION_ARG(value, 1);
+
+ int indexname = _code_ptr[ip + 3];
+
+ GD_ERR_BREAK(indexname < 0 || indexname >= _global_names_count);
+ const StringName *index = &_global_names_ptr[indexname];
+
+ bool valid;
+ dst->set_named(*index, *value, valid);
+
+#ifdef DEBUG_ENABLED
+ if (!valid) {
+ String err_type;
+ err_text = "Invalid set index '" + String(*index) + "' (on base: '" + _get_var_type(dst) + "') with value of type '" + _get_var_type(value) + "'.";
+ OPCODE_BREAK;
+ }
+#endif
+ ip += 4;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_SET_NAMED_VALIDATED) {
+ CHECK_SPACE(3);
+
+ GET_INSTRUCTION_ARG(dst, 0);
+ GET_INSTRUCTION_ARG(value, 1);
+
+ int index_setter = _code_ptr[ip + 3];
+ GD_ERR_BREAK(index_setter < 0 || index_setter >= _setters_count);
+ const Variant::ValidatedSetter setter = _setters_ptr[index_setter];
+
+ setter(dst, value);
+ ip += 4;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_GET_NAMED) {
+ CHECK_SPACE(4);
+
+ GET_INSTRUCTION_ARG(src, 0);
+ GET_INSTRUCTION_ARG(dst, 1);
+
+ int indexname = _code_ptr[ip + 3];
+
+ GD_ERR_BREAK(indexname < 0 || indexname >= _global_names_count);
+ const StringName *index = &_global_names_ptr[indexname];
+
+ bool valid;
+#ifdef DEBUG_ENABLED
+ //allow better error message in cases where src and dst are the same stack position
+ Variant ret = src->get_named(*index, valid);
+
+#else
+ *dst = src->get_named(*index, valid);
+#endif
+#ifdef DEBUG_ENABLED
+ if (!valid) {
+ if (src->has_method(*index)) {
+ err_text = "Invalid get index '" + index->operator String() + "' (on base: '" + _get_var_type(src) + "'). Did you mean '." + index->operator String() + "()' or funcref(obj, \"" + index->operator String() + "\") ?";
+ } else {
+ err_text = "Invalid get index '" + index->operator String() + "' (on base: '" + _get_var_type(src) + "').";
+ }
+ OPCODE_BREAK;
+ }
+ *dst = ret;
+#endif
+ ip += 4;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_GET_NAMED_VALIDATED) {
+ CHECK_SPACE(3);
+
+ GET_INSTRUCTION_ARG(src, 0);
+ GET_INSTRUCTION_ARG(dst, 1);
+
+ int index_getter = _code_ptr[ip + 3];
+ GD_ERR_BREAK(index_getter < 0 || index_getter >= _getters_count);
+ const Variant::ValidatedGetter getter = _getters_ptr[index_getter];
+
+ getter(src, dst);
+ ip += 4;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_SET_MEMBER) {
+ CHECK_SPACE(3);
+ GET_INSTRUCTION_ARG(src, 0);
+ int indexname = _code_ptr[ip + 2];
+ GD_ERR_BREAK(indexname < 0 || indexname >= _global_names_count);
+ const StringName *index = &_global_names_ptr[indexname];
+
+ bool valid;
+#ifndef DEBUG_ENABLED
+ ClassDB::set_property(p_instance->owner, *index, *src, &valid);
+#else
+ bool ok = ClassDB::set_property(p_instance->owner, *index, *src, &valid);
+ if (!ok) {
+ err_text = "Internal error setting property: " + String(*index);
+ OPCODE_BREAK;
+ } else if (!valid) {
+ err_text = "Error setting property '" + String(*index) + "' with value of type " + Variant::get_type_name(src->get_type()) + ".";
+ OPCODE_BREAK;
+ }
+#endif
+ ip += 3;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_GET_MEMBER) {
+ CHECK_SPACE(3);
+ GET_INSTRUCTION_ARG(dst, 0);
+ int indexname = _code_ptr[ip + 2];
+ GD_ERR_BREAK(indexname < 0 || indexname >= _global_names_count);
+ const StringName *index = &_global_names_ptr[indexname];
+#ifndef DEBUG_ENABLED
+ ClassDB::get_property(p_instance->owner, *index, *dst);
+#else
+ bool ok = ClassDB::get_property(p_instance->owner, *index, *dst);
+ if (!ok) {
+ err_text = "Internal error getting property: " + String(*index);
+ OPCODE_BREAK;
+ }
+#endif
+ ip += 3;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ASSIGN) {
+ CHECK_SPACE(3);
+ GET_INSTRUCTION_ARG(dst, 0);
+ GET_INSTRUCTION_ARG(src, 1);
+
+ *dst = *src;
+
+ ip += 3;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ASSIGN_TRUE) {
+ CHECK_SPACE(2);
+ GET_INSTRUCTION_ARG(dst, 0);
+
+ *dst = true;
+
+ ip += 2;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ASSIGN_FALSE) {
+ CHECK_SPACE(2);
+ GET_INSTRUCTION_ARG(dst, 0);
+
+ *dst = false;
+
+ ip += 2;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ASSIGN_TYPED_BUILTIN) {
+ CHECK_SPACE(4);
+ GET_INSTRUCTION_ARG(dst, 0);
+ GET_INSTRUCTION_ARG(src, 1);
+
+ Variant::Type var_type = (Variant::Type)_code_ptr[ip + 3];
+ GD_ERR_BREAK(var_type < 0 || var_type >= Variant::VARIANT_MAX);
+
+ if (src->get_type() != var_type) {
+#ifdef DEBUG_ENABLED
+ if (Variant::can_convert_strict(src->get_type(), var_type)) {
+#endif // DEBUG_ENABLED
+ Callable::CallError ce;
+ Variant::construct(var_type, *dst, const_cast<const Variant **>(&src), 1, ce);
+ } else {
+#ifdef DEBUG_ENABLED
+ err_text = "Trying to assign value of type '" + Variant::get_type_name(src->get_type()) +
+ "' to a variable of type '" + Variant::get_type_name(var_type) + "'.";
+ OPCODE_BREAK;
+ }
+ } else {
+#endif // DEBUG_ENABLED
+ *dst = *src;
+ }
+
+ ip += 4;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ASSIGN_TYPED_NATIVE) {
+ CHECK_SPACE(4);
+ GET_INSTRUCTION_ARG(dst, 0);
+ GET_INSTRUCTION_ARG(src, 1);
+
+#ifdef DEBUG_ENABLED
+ GET_INSTRUCTION_ARG(type, 2);
+ GDScriptNativeClass *nc = Object::cast_to<GDScriptNativeClass>(type->operator Object *());
+ GD_ERR_BREAK(!nc);
+ if (src->get_type() != Variant::OBJECT && src->get_type() != Variant::NIL) {
+ err_text = "Trying to assign value of type '" + Variant::get_type_name(src->get_type()) +
+ "' to a variable of type '" + nc->get_name() + "'.";
+ OPCODE_BREAK;
+ }
+ Object *src_obj = src->operator Object *();
+
+ if (src_obj && !ClassDB::is_parent_class(src_obj->get_class_name(), nc->get_name())) {
+ err_text = "Trying to assign value of type '" + src_obj->get_class_name() +
+ "' to a variable of type '" + nc->get_name() + "'.";
+ OPCODE_BREAK;
+ }
+#endif // DEBUG_ENABLED
+ *dst = *src;
+
+ ip += 4;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ASSIGN_TYPED_SCRIPT) {
+ CHECK_SPACE(4);
+ GET_INSTRUCTION_ARG(dst, 0);
+ GET_INSTRUCTION_ARG(src, 1);
+
+#ifdef DEBUG_ENABLED
+ GET_INSTRUCTION_ARG(type, 2);
+ Script *base_type = Object::cast_to<Script>(type->operator Object *());
+
+ GD_ERR_BREAK(!base_type);
+
+ if (src->get_type() != Variant::OBJECT && src->get_type() != Variant::NIL) {
+ err_text = "Trying to assign a non-object value to a variable of type '" + base_type->get_path().get_file() + "'.";
+ OPCODE_BREAK;
+ }
+
+ if (src->get_type() != Variant::NIL && src->operator Object *() != nullptr) {
+ ScriptInstance *scr_inst = src->operator Object *()->get_script_instance();
+ if (!scr_inst) {
+ err_text = "Trying to assign value of type '" + src->operator Object *()->get_class_name() +
+ "' to a variable of type '" + base_type->get_path().get_file() + "'.";
+ OPCODE_BREAK;
+ }
+
+ Script *src_type = src->operator Object *()->get_script_instance()->get_script().ptr();
+ bool valid = false;
+
+ while (src_type) {
+ if (src_type == base_type) {
+ valid = true;
+ break;
+ }
+ src_type = src_type->get_base_script().ptr();
+ }
+
+ if (!valid) {
+ err_text = "Trying to assign value of type '" + src->operator Object *()->get_script_instance()->get_script()->get_path().get_file() +
+ "' to a variable of type '" + base_type->get_path().get_file() + "'.";
+ OPCODE_BREAK;
+ }
+ }
+#endif // DEBUG_ENABLED
+
+ *dst = *src;
+
+ ip += 4;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_CAST_TO_BUILTIN) {
+ CHECK_SPACE(4);
+ GET_INSTRUCTION_ARG(src, 0);
+ GET_INSTRUCTION_ARG(dst, 1);
+ Variant::Type to_type = (Variant::Type)_code_ptr[ip + 3];
+
+ GD_ERR_BREAK(to_type < 0 || to_type >= Variant::VARIANT_MAX);
+
+ Callable::CallError err;
+ Variant::construct(to_type, *dst, (const Variant **)&src, 1, err);
+
+#ifdef DEBUG_ENABLED
+ if (err.error != Callable::CallError::CALL_OK) {
+ err_text = "Invalid cast: could not convert value to '" + Variant::get_type_name(to_type) + "'.";
+ OPCODE_BREAK;
+ }
+#endif
+
+ ip += 4;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_CAST_TO_NATIVE) {
+ CHECK_SPACE(4);
+ GET_INSTRUCTION_ARG(src, 0);
+ GET_INSTRUCTION_ARG(dst, 1);
+ GET_INSTRUCTION_ARG(to_type, 2);
+
+ GDScriptNativeClass *nc = Object::cast_to<GDScriptNativeClass>(to_type->operator Object *());
+ GD_ERR_BREAK(!nc);
+
+#ifdef DEBUG_ENABLED
+ if (src->get_type() != Variant::OBJECT && src->get_type() != Variant::NIL) {
+ err_text = "Invalid cast: can't convert a non-object value to an object type.";
+ OPCODE_BREAK;
+ }
+#endif
+ Object *src_obj = src->operator Object *();
+
+ if (src_obj && !ClassDB::is_parent_class(src_obj->get_class_name(), nc->get_name())) {
+ *dst = Variant(); // invalid cast, assign NULL
+ } else {
+ *dst = *src;
+ }
+
+ ip += 4;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_CAST_TO_SCRIPT) {
+ CHECK_SPACE(4);
+ GET_INSTRUCTION_ARG(src, 0);
+ GET_INSTRUCTION_ARG(dst, 1);
+ GET_INSTRUCTION_ARG(to_type, 2);
+
+ Script *base_type = Object::cast_to<Script>(to_type->operator Object *());
+
+ GD_ERR_BREAK(!base_type);
+
+#ifdef DEBUG_ENABLED
+ if (src->get_type() != Variant::OBJECT && src->get_type() != Variant::NIL) {
+ err_text = "Trying to assign a non-object value to a variable of type '" + base_type->get_path().get_file() + "'.";
+ OPCODE_BREAK;
+ }
+#endif
+
+ bool valid = false;
+
+ if (src->get_type() != Variant::NIL && src->operator Object *() != nullptr) {
+ ScriptInstance *scr_inst = src->operator Object *()->get_script_instance();
+
+ if (scr_inst) {
+ Script *src_type = src->operator Object *()->get_script_instance()->get_script().ptr();
+
+ while (src_type) {
+ if (src_type == base_type) {
+ valid = true;
+ break;
+ }
+ src_type = src_type->get_base_script().ptr();
+ }
+ }
+ }
+
+ if (valid) {
+ *dst = *src; // Valid cast, copy the source object
+ } else {
+ *dst = Variant(); // invalid cast, assign NULL
+ }
+
+ ip += 4;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_CONSTRUCT) {
+ CHECK_SPACE(2 + instr_arg_count);
+
+ ip += instr_arg_count;
+
+ int argc = _code_ptr[ip + 1];
+
+ Variant::Type t = Variant::Type(_code_ptr[ip + 2]);
+ Variant **argptrs = instruction_args;
+
+ GET_INSTRUCTION_ARG(dst, argc);
+
+ Callable::CallError err;
+ Variant::construct(t, *dst, (const Variant **)argptrs, argc, err);
+
+#ifdef DEBUG_ENABLED
+ if (err.error != Callable::CallError::CALL_OK) {
+ err_text = _get_call_error(err, "'" + Variant::get_type_name(t) + "' constructor", (const Variant **)argptrs);
+ OPCODE_BREAK;
+ }
+#endif
+
+ ip += 3;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_CONSTRUCT_VALIDATED) {
+ CHECK_SPACE(2 + instr_arg_count);
+
+ ip += instr_arg_count;
+
+ int argc = _code_ptr[ip + 1];
+
+ int constructor_idx = _code_ptr[ip + 2];
+ GD_ERR_BREAK(constructor_idx < 0 || constructor_idx >= _constructors_count);
+ Variant::ValidatedConstructor constructor = _constructors_ptr[constructor_idx];
+
+ Variant **argptrs = instruction_args;
+
+ GET_INSTRUCTION_ARG(dst, argc);
+
+ constructor(*dst, (const Variant **)argptrs);
+
+ ip += 3;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_CONSTRUCT_ARRAY) {
+ CHECK_SPACE(1 + instr_arg_count);
+ ip += instr_arg_count;
+
+ int argc = _code_ptr[ip + 1];
+ Array array;
+ array.resize(argc);
+
+ for (int i = 0; i < argc; i++) {
+ array[i] = *(instruction_args[i]);
+ }
+
+ GET_INSTRUCTION_ARG(dst, argc);
+
+ *dst = array;
+
+ ip += 2;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_CONSTRUCT_DICTIONARY) {
+ CHECK_SPACE(2 + instr_arg_count);
+
+ ip += instr_arg_count;
+
+ int argc = _code_ptr[ip + 1];
+ Dictionary dict;
+
+ for (int i = 0; i < argc; i++) {
+ GET_INSTRUCTION_ARG(k, i * 2 + 0);
+ GET_INSTRUCTION_ARG(v, i * 2 + 1);
+ dict[*k] = *v;
+ }
+
+ GET_INSTRUCTION_ARG(dst, argc * 2);
+
+ *dst = dict;
+
+ ip += 2;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_CALL_ASYNC)
+ OPCODE(OPCODE_CALL_RETURN)
+ OPCODE(OPCODE_CALL) {
+ CHECK_SPACE(3 + instr_arg_count);
+ bool call_ret = (_code_ptr[ip] & INSTR_MASK) != OPCODE_CALL;
+#ifdef DEBUG_ENABLED
+ bool call_async = (_code_ptr[ip] & INSTR_MASK) == OPCODE_CALL_ASYNC;
+#endif
+
+ ip += instr_arg_count;
+
+ int argc = _code_ptr[ip + 1];
+ GD_ERR_BREAK(argc < 0);
+
+ int methodname_idx = _code_ptr[ip + 2];
+ GD_ERR_BREAK(methodname_idx < 0 || methodname_idx >= _global_names_count);
+ const StringName *methodname = &_global_names_ptr[methodname_idx];
+
+ GET_INSTRUCTION_ARG(base, argc);
+ Variant **argptrs = instruction_args;
+
+#ifdef DEBUG_ENABLED
+ uint64_t call_time = 0;
+
+ if (GDScriptLanguage::get_singleton()->profiling) {
+ call_time = OS::get_singleton()->get_ticks_usec();
+ }
+
+#endif
+ Callable::CallError err;
+ if (call_ret) {
+ GET_INSTRUCTION_ARG(ret, argc + 1);
+ base->call(*methodname, (const Variant **)argptrs, argc, *ret, err);
+#ifdef DEBUG_ENABLED
+ if (!call_async && ret->get_type() == Variant::OBJECT) {
+ // Check if getting a function state without await.
+ bool was_freed = false;
+ Object *obj = ret->get_validated_object_with_check(was_freed);
+
+ if (was_freed) {
+ err_text = "Got a freed object as a result of the call.";
+ OPCODE_BREAK;
+ }
+ if (obj && obj->is_class_ptr(GDScriptFunctionState::get_class_ptr_static())) {
+ err_text = R"(Trying to call an async function without "await".)";
+ OPCODE_BREAK;
+ }
+ }
+#endif
+ } else {
+ Variant ret;
+ base->call(*methodname, (const Variant **)argptrs, argc, ret, err);
+ }
+#ifdef DEBUG_ENABLED
+ if (GDScriptLanguage::get_singleton()->profiling) {
+ function_call_time += OS::get_singleton()->get_ticks_usec() - call_time;
+ }
+
+ if (err.error != Callable::CallError::CALL_OK) {
+ String methodstr = *methodname;
+ String basestr = _get_var_type(base);
+
+ if (methodstr == "call") {
+ if (argc >= 1) {
+ methodstr = String(*argptrs[0]) + " (via call)";
+ if (err.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) {
+ err.argument += 1;
+ }
+ }
+ } else if (methodstr == "free") {
+ if (err.error == Callable::CallError::CALL_ERROR_INVALID_METHOD) {
+ if (base->is_ref()) {
+ err_text = "Attempted to free a reference.";
+ OPCODE_BREAK;
+ } else if (base->get_type() == Variant::OBJECT) {
+ err_text = "Attempted to free a locked object (calling or emitting).";
+ OPCODE_BREAK;
+ }
+ }
+ } else if (methodstr == "call_recursive" && basestr == "TreeItem") {
+ if (argc >= 1) {
+ methodstr = String(*argptrs[0]) + " (via TreeItem.call_recursive)";
+ if (err.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) {
+ err.argument += 1;
+ }
+ }
+ }
+ err_text = _get_call_error(err, "function '" + methodstr + "' in base '" + basestr + "'", (const Variant **)argptrs);
+ OPCODE_BREAK;
+ }
+#endif
+
+ ip += 3;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_CALL_METHOD_BIND)
+ OPCODE(OPCODE_CALL_METHOD_BIND_RET) {
+ CHECK_SPACE(3 + instr_arg_count);
+ bool call_ret = (_code_ptr[ip] & INSTR_MASK) == OPCODE_CALL_METHOD_BIND_RET;
+
+ ip += instr_arg_count;
+
+ int argc = _code_ptr[ip + 1];
+ GD_ERR_BREAK(argc < 0);
+ GD_ERR_BREAK(_code_ptr[ip + 2] < 0 || _code_ptr[ip + 2] >= _methods_count);
+ MethodBind *method = _methods_ptr[_code_ptr[ip + 2]];
+
+ GET_INSTRUCTION_ARG(base, argc);
+
+#ifdef DEBUG_ENABLED
+ bool freed = false;
+ Object *base_obj = base->get_validated_object_with_check(freed);
+ if (freed) {
+ err_text = "Trying to call a function on a previously freed instance.";
+ OPCODE_BREAK;
+ } else if (!base_obj) {
+ err_text = "Trying to call a function on a null value.";
+ OPCODE_BREAK;
+ }
+#else
+ Object *base_obj = base->operator Object *();
+#endif
+ Variant **argptrs = instruction_args;
+
+#ifdef DEBUG_ENABLED
+ uint64_t call_time = 0;
+
+ if (GDScriptLanguage::get_singleton()->profiling) {
+ call_time = OS::get_singleton()->get_ticks_usec();
+ }
+#endif
+
+ Callable::CallError err;
+ if (call_ret) {
+ GET_INSTRUCTION_ARG(ret, argc + 1);
+ *ret = method->call(base_obj, (const Variant **)argptrs, argc, err);
+ } else {
+ method->call(base_obj, (const Variant **)argptrs, argc, err);
+ }
+
+#ifdef DEBUG_ENABLED
+ if (GDScriptLanguage::get_singleton()->profiling) {
+ function_call_time += OS::get_singleton()->get_ticks_usec() - call_time;
+ }
+
+ if (err.error != Callable::CallError::CALL_OK) {
+ String methodstr = method->get_name();
+ String basestr = _get_var_type(base);
+
+ if (methodstr == "call") {
+ if (argc >= 1) {
+ methodstr = String(*argptrs[0]) + " (via call)";
+ if (err.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) {
+ err.argument += 1;
+ }
+ }
+ } else if (methodstr == "free") {
+ if (err.error == Callable::CallError::CALL_ERROR_INVALID_METHOD) {
+ if (base->is_ref()) {
+ err_text = "Attempted to free a reference.";
+ OPCODE_BREAK;
+ } else if (base->get_type() == Variant::OBJECT) {
+ err_text = "Attempted to free a locked object (calling or emitting).";
+ OPCODE_BREAK;
+ }
+ }
+ }
+ err_text = _get_call_error(err, "function '" + methodstr + "' in base '" + basestr + "'", (const Variant **)argptrs);
+ OPCODE_BREAK;
+ }
+#endif
+ ip += 3;
+ }
+ DISPATCH_OPCODE;
+
+#ifdef DEBUG_ENABLED
+#define OPCODE_CALL_PTR(m_type) \
+ OPCODE(OPCODE_CALL_PTRCALL_##m_type) { \
+ CHECK_SPACE(3 + instr_arg_count); \
+ ip += instr_arg_count; \
+ int argc = _code_ptr[ip + 1]; \
+ GD_ERR_BREAK(argc < 0); \
+ GET_INSTRUCTION_ARG(base, argc); \
+ GD_ERR_BREAK(_code_ptr[ip + 2] < 0 || _code_ptr[ip + 2] >= _methods_count); \
+ MethodBind *method = _methods_ptr[_code_ptr[ip + 2]]; \
+ bool freed = false; \
+ Object *base_obj = base->get_validated_object_with_check(freed); \
+ if (freed) { \
+ err_text = "Trying to call a function on a previously freed instance."; \
+ OPCODE_BREAK; \
+ } else if (!base_obj) { \
+ err_text = "Trying to call a function on a null value."; \
+ OPCODE_BREAK; \
+ } \
+ const void **argptrs = call_args_ptr; \
+ for (int i = 0; i < argc; i++) { \
+ GET_INSTRUCTION_ARG(v, i); \
+ argptrs[i] = VariantInternal::get_opaque_pointer((const Variant *)v); \
+ } \
+ uint64_t call_time = 0; \
+ if (GDScriptLanguage::get_singleton()->profiling) { \
+ call_time = OS::get_singleton()->get_ticks_usec(); \
+ } \
+ GET_INSTRUCTION_ARG(ret, argc + 1); \
+ VariantInternal::initialize(ret, Variant::m_type); \
+ void *ret_opaque = VariantInternal::OP_GET_##m_type(ret); \
+ method->ptrcall(base_obj, argptrs, ret_opaque); \
+ if (GDScriptLanguage::get_singleton()->profiling) { \
+ function_call_time += OS::get_singleton()->get_ticks_usec() - call_time; \
+ } \
+ ip += 3; \
+ } \
+ DISPATCH_OPCODE
+#else
+#define OPCODE_CALL_PTR(m_type) \
+ OPCODE(OPCODE_CALL_PTRCALL_##m_type) { \
+ CHECK_SPACE(3 + instr_arg_count); \
+ int argc = _code_ptr[ip + 1]; \
+ GET_INSTRUCTION_ARG(base, argc); \
+ MethodBind *method = _methods_ptr[_code_ptr[ip + 2]]; \
+ Object *base_obj = *VariantInternal::get_object(base); \
+ const void **argptrs = call_args_ptr; \
+ for (int i = 0; i < argc; i++) { \
+ GET_INSTRUCTION_ARG(v, i); \
+ argptrs[i] = VariantInternal::get_opaque_pointer((const Variant *)v); \
+ } \
+ GET_INSTRUCTION_ARG(ret, argc + 1); \
+ VariantInternal::initialize(ret, Variant::m_type); \
+ void *ret_opaque = VariantInternal::OP_GET_##m_type(ret); \
+ method->ptrcall(base_obj, argptrs, ret_opaque); \
+ ip += 3; \
+ } \
+ DISPATCH_OPCODE
+#endif
+
+ OPCODE_CALL_PTR(BOOL);
+ OPCODE_CALL_PTR(INT);
+ OPCODE_CALL_PTR(FLOAT);
+ OPCODE_CALL_PTR(STRING);
+ OPCODE_CALL_PTR(VECTOR2);
+ OPCODE_CALL_PTR(VECTOR2I);
+ OPCODE_CALL_PTR(RECT2);
+ OPCODE_CALL_PTR(RECT2I);
+ OPCODE_CALL_PTR(VECTOR3);
+ OPCODE_CALL_PTR(VECTOR3I);
+ OPCODE_CALL_PTR(TRANSFORM2D);
+ OPCODE_CALL_PTR(PLANE);
+ OPCODE_CALL_PTR(QUAT);
+ OPCODE_CALL_PTR(AABB);
+ OPCODE_CALL_PTR(BASIS);
+ OPCODE_CALL_PTR(TRANSFORM);
+ OPCODE_CALL_PTR(COLOR);
+ OPCODE_CALL_PTR(STRING_NAME);
+ OPCODE_CALL_PTR(NODE_PATH);
+ OPCODE_CALL_PTR(RID);
+ OPCODE_CALL_PTR(CALLABLE);
+ OPCODE_CALL_PTR(SIGNAL);
+ OPCODE_CALL_PTR(DICTIONARY);
+ OPCODE_CALL_PTR(ARRAY);
+ OPCODE_CALL_PTR(PACKED_BYTE_ARRAY);
+ OPCODE_CALL_PTR(PACKED_INT32_ARRAY);
+ OPCODE_CALL_PTR(PACKED_INT64_ARRAY);
+ OPCODE_CALL_PTR(PACKED_FLOAT32_ARRAY);
+ OPCODE_CALL_PTR(PACKED_FLOAT64_ARRAY);
+ OPCODE_CALL_PTR(PACKED_STRING_ARRAY);
+ OPCODE_CALL_PTR(PACKED_VECTOR2_ARRAY);
+ OPCODE_CALL_PTR(PACKED_VECTOR3_ARRAY);
+ OPCODE_CALL_PTR(PACKED_COLOR_ARRAY);
+ OPCODE(OPCODE_CALL_PTRCALL_OBJECT) {
+ CHECK_SPACE(3 + instr_arg_count);
+
+ ip += instr_arg_count;
+
+ int argc = _code_ptr[ip + 1];
+ GD_ERR_BREAK(argc < 0);
+
+ GD_ERR_BREAK(_code_ptr[ip + 2] < 0 || _code_ptr[ip + 2] >= _methods_count);
+ MethodBind *method = _methods_ptr[_code_ptr[ip + 2]];
+
+ GET_INSTRUCTION_ARG(base, argc);
+#ifdef DEBUG_ENABLED
+ bool freed = false;
+ Object *base_obj = base->get_validated_object_with_check(freed);
+ if (freed) {
+ err_text = "Trying to call a function on a previously freed instance.";
+ OPCODE_BREAK;
+ } else if (!base_obj) {
+ err_text = "Trying to call a function on a null value.";
+ OPCODE_BREAK;
+ }
+#else
+ Object *base_obj = *VariantInternal::get_object(base);
+#endif
+
+ const void **argptrs = call_args_ptr;
+
+ for (int i = 0; i < argc; i++) {
+ GET_INSTRUCTION_ARG(v, i);
+ argptrs[i] = VariantInternal::get_opaque_pointer((const Variant *)v);
+ }
+#ifdef DEBUG_ENABLED
+ uint64_t call_time = 0;
+
+ if (GDScriptLanguage::get_singleton()->profiling) {
+ call_time = OS::get_singleton()->get_ticks_usec();
+ }
+#endif
+
+ GET_INSTRUCTION_ARG(ret, argc + 1);
+ VariantInternal::initialize(ret, Variant::OBJECT);
+ Object **ret_opaque = VariantInternal::get_object(ret);
+ method->ptrcall(base_obj, argptrs, ret_opaque);
+ VariantInternal::set_object(ret, *ret_opaque);
+
+#ifdef DEBUG_ENABLED
+ if (GDScriptLanguage::get_singleton()->profiling) {
+ function_call_time += OS::get_singleton()->get_ticks_usec() - call_time;
+ }
+#endif
+ ip += 3;
+ }
+ DISPATCH_OPCODE;
+ OPCODE(OPCODE_CALL_PTRCALL_NO_RETURN) {
+ CHECK_SPACE(3 + instr_arg_count);
+
+ ip += instr_arg_count;
+
+ int argc = _code_ptr[ip + 1];
+ GD_ERR_BREAK(argc < 0);
+
+ GD_ERR_BREAK(_code_ptr[ip + 2] < 0 || _code_ptr[ip + 2] >= _methods_count);
+ MethodBind *method = _methods_ptr[_code_ptr[ip + 2]];
+
+ GET_INSTRUCTION_ARG(base, argc);
+#ifdef DEBUG_ENABLED
+ bool freed = false;
+ Object *base_obj = base->get_validated_object_with_check(freed);
+ if (freed) {
+ err_text = "Trying to call a function on a previously freed instance.";
+ OPCODE_BREAK;
+ } else if (!base_obj) {
+ err_text = "Trying to call a function on a null value.";
+ OPCODE_BREAK;
+ }
+#else
+ Object *base_obj = *VariantInternal::get_object(base);
+#endif
+ const void **argptrs = call_args_ptr;
+
+ for (int i = 0; i < argc; i++) {
+ GET_INSTRUCTION_ARG(v, i);
+ argptrs[i] = VariantInternal::get_opaque_pointer((const Variant *)v);
+ }
+#ifdef DEBUG_ENABLED
+ uint64_t call_time = 0;
+
+ if (GDScriptLanguage::get_singleton()->profiling) {
+ call_time = OS::get_singleton()->get_ticks_usec();
+ }
+#endif
+
+ GET_INSTRUCTION_ARG(ret, argc + 1);
+ VariantInternal::initialize(ret, Variant::NIL);
+ method->ptrcall(base_obj, argptrs, nullptr);
+
+#ifdef DEBUG_ENABLED
+ if (GDScriptLanguage::get_singleton()->profiling) {
+ function_call_time += OS::get_singleton()->get_ticks_usec() - call_time;
+ }
+#endif
+ ip += 3;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_CALL_BUILTIN_TYPE_VALIDATED) {
+ CHECK_SPACE(3 + instr_arg_count);
+
+ ip += instr_arg_count;
+
+ int argc = _code_ptr[ip + 1];
+ GD_ERR_BREAK(argc < 0);
+
+ GET_INSTRUCTION_ARG(base, argc);
+
+ GD_ERR_BREAK(_code_ptr[ip + 2] < 0 || _code_ptr[ip + 2] >= _builtin_methods_count);
+ Variant::ValidatedBuiltInMethod method = _builtin_methods_ptr[_code_ptr[ip + 2]];
+ Variant **argptrs = instruction_args;
+
+#ifdef DEBUG_ENABLED
+ uint64_t call_time = 0;
+ if (GDScriptLanguage::get_singleton()->profiling) {
+ call_time = OS::get_singleton()->get_ticks_usec();
+ }
+#endif
+
+ GET_INSTRUCTION_ARG(ret, argc + 1);
+ method(base, (const Variant **)argptrs, argc, ret);
+
+#ifdef DEBUG_ENABLED
+ if (GDScriptLanguage::get_singleton()->profiling) {
+ function_call_time += OS::get_singleton()->get_ticks_usec() - call_time;
+ }
+#endif
+
+ ip += 3;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_CALL_BUILT_IN) {
+ CHECK_SPACE(3 + instr_arg_count);
+
+ ip += instr_arg_count;
+
+ int argc = _code_ptr[ip + 1];
+ GD_ERR_BREAK(argc < 0);
+
+ GDScriptFunctions::Function func = GDScriptFunctions::Function(_code_ptr[ip + 2]);
+ Variant **argptrs = instruction_args;
+
+ GET_INSTRUCTION_ARG(dst, argc);
+
+ Callable::CallError err;
+ GDScriptFunctions::call(func, (const Variant **)argptrs, argc, *dst, err);
+
+#ifdef DEBUG_ENABLED
+ if (err.error != Callable::CallError::CALL_OK) {
+ String methodstr = GDScriptFunctions::get_func_name(func);
+ if (dst->get_type() == Variant::STRING) {
+ //call provided error string
+ err_text = "Error calling built-in function '" + methodstr + "': " + String(*dst);
+ } else {
+ err_text = _get_call_error(err, "built-in function '" + methodstr + "'", (const Variant **)argptrs);
+ }
+ OPCODE_BREAK;
+ }
+#endif
+ ip += 3;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_CALL_SELF_BASE) {
+ CHECK_SPACE(3 + instr_arg_count);
+
+ ip += instr_arg_count;
+
+ int self_fun = _code_ptr[ip + 1];
+#ifdef DEBUG_ENABLED
+ if (self_fun < 0 || self_fun >= _global_names_count) {
+ err_text = "compiler bug, function name not found";
+ OPCODE_BREAK;
+ }
+#endif
+ const StringName *methodname = &_global_names_ptr[self_fun];
+
+ int argc = _code_ptr[ip + 2];
+ GD_ERR_BREAK(argc < 0);
+
+ Variant **argptrs = instruction_args;
+
+ GET_INSTRUCTION_ARG(dst, argc);
+
+ const GDScript *gds = _script;
+
+ const Map<StringName, GDScriptFunction *>::Element *E = nullptr;
+ while (gds->base.ptr()) {
+ gds = gds->base.ptr();
+ E = gds->member_functions.find(*methodname);
+ if (E) {
+ break;
+ }
+ }
+
+ Callable::CallError err;
+
+ if (E) {
+ *dst = E->get()->call(p_instance, (const Variant **)argptrs, argc, err);
+ } else if (gds->native.ptr()) {
+ if (*methodname != GDScriptLanguage::get_singleton()->strings._init) {
+ MethodBind *mb = ClassDB::get_method(gds->native->get_name(), *methodname);
+ if (!mb) {
+ err.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
+ } else {
+ *dst = mb->call(p_instance->owner, (const Variant **)argptrs, argc, err);
+ }
+ } else {
+ err.error = Callable::CallError::CALL_OK;
+ }
+ } else {
+ if (*methodname != GDScriptLanguage::get_singleton()->strings._init) {
+ err.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
+ } else {
+ err.error = Callable::CallError::CALL_OK;
+ }
+ }
+
+ if (err.error != Callable::CallError::CALL_OK) {
+ String methodstr = *methodname;
+ err_text = _get_call_error(err, "function '" + methodstr + "'", (const Variant **)argptrs);
+
+ OPCODE_BREAK;
+ }
+
+ ip += 3;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_AWAIT) {
+ CHECK_SPACE(2);
+
+ // Do the oneshot connect.
+ GET_INSTRUCTION_ARG(argobj, 0);
+
+ Signal sig;
+ bool is_signal = true;
+
+ {
+ Variant result = *argobj;
+
+ if (argobj->get_type() == Variant::OBJECT) {
+ bool was_freed = false;
+ Object *obj = argobj->get_validated_object_with_check(was_freed);
+
+ if (was_freed) {
+ err_text = "Trying to await on a freed object.";
+ OPCODE_BREAK;
+ }
+
+ // Is this even possible to be null at this point?
+ if (obj) {
+ if (obj->is_class_ptr(GDScriptFunctionState::get_class_ptr_static())) {
+ static StringName completed = _scs_create("completed");
+ result = Signal(obj, completed);
+ }
+ }
+ }
+
+ if (result.get_type() != Variant::SIGNAL) {
+ ip += 4; // Skip OPCODE_AWAIT_RESUME and its data.
+ // The stack pointer should be the same, so we don't need to set a return value.
+ is_signal = false;
+ } else {
+ sig = result;
+ }
+ }
+
+ if (is_signal) {
+ Ref<GDScriptFunctionState> gdfs = memnew(GDScriptFunctionState);
+ gdfs->function = this;
+
+ gdfs->state.stack.resize(alloca_size);
+ //copy variant stack
+ for (int i = 0; i < _stack_size; i++) {
+ memnew_placement(&gdfs->state.stack.write[sizeof(Variant) * i], Variant(stack[i]));
+ }
+ gdfs->state.stack_size = _stack_size;
+ gdfs->state.self = self;
+ gdfs->state.alloca_size = alloca_size;
+ gdfs->state.ip = ip + 2;
+ gdfs->state.line = line;
+ gdfs->state.script = _script;
+ {
+ MutexLock lock(GDScriptLanguage::get_singleton()->lock);
+ _script->pending_func_states.add(&gdfs->scripts_list);
+ if (p_instance) {
+ gdfs->state.instance = p_instance;
+ p_instance->pending_func_states.add(&gdfs->instances_list);
+ } else {
+ gdfs->state.instance = nullptr;
+ }
+ }
+#ifdef DEBUG_ENABLED
+ gdfs->state.function_name = name;
+ gdfs->state.script_path = _script->get_path();
+#endif
+ gdfs->state.defarg = defarg;
+ gdfs->function = this;
+
+ retvalue = gdfs;
+
+ Error err = sig.connect(Callable(gdfs.ptr(), "_signal_callback"), varray(gdfs), Object::CONNECT_ONESHOT);
+ if (err != OK) {
+ err_text = "Error connecting to signal: " + sig.get_name() + " during await.";
+ OPCODE_BREAK;
+ }
+
+#ifdef DEBUG_ENABLED
+ exit_ok = true;
+ awaited = true;
+#endif
+ OPCODE_BREAK;
+ }
+ }
+ DISPATCH_OPCODE; // Needed for synchronous calls (when result is immediately available).
+
+ OPCODE(OPCODE_AWAIT_RESUME) {
+ CHECK_SPACE(2);
+#ifdef DEBUG_ENABLED
+ if (!p_state) {
+ err_text = ("Invalid Resume (bug?)");
+ OPCODE_BREAK;
+ }
+#endif
+ GET_INSTRUCTION_ARG(result, 0);
+ *result = p_state->result;
+ ip += 2;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_JUMP) {
+ CHECK_SPACE(2);
+ int to = _code_ptr[ip + 1];
+
+ GD_ERR_BREAK(to < 0 || to > _code_size);
+ ip = to;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_JUMP_IF) {
+ CHECK_SPACE(3);
+
+ GET_INSTRUCTION_ARG(test, 0);
+
+ bool result = test->booleanize();
+
+ if (result) {
+ int to = _code_ptr[ip + 2];
+ GD_ERR_BREAK(to < 0 || to > _code_size);
+ ip = to;
+ } else {
+ ip += 3;
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_JUMP_IF_NOT) {
+ CHECK_SPACE(3);
+
+ GET_INSTRUCTION_ARG(test, 0);
+
+ bool result = test->booleanize();
+
+ if (!result) {
+ int to = _code_ptr[ip + 2];
+ GD_ERR_BREAK(to < 0 || to > _code_size);
+ ip = to;
+ } else {
+ ip += 3;
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_JUMP_TO_DEF_ARGUMENT) {
+ CHECK_SPACE(2);
+ ip = _default_arg_ptr[defarg];
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_RETURN) {
+ CHECK_SPACE(2);
+ GET_INSTRUCTION_ARG(r, 0);
+ retvalue = *r;
+#ifdef DEBUG_ENABLED
+ exit_ok = true;
+#endif
+ OPCODE_BREAK;
+ }
+
+ OPCODE(OPCODE_ITERATE_BEGIN) {
+ CHECK_SPACE(8); // Space for this and a regular iterate.
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ bool valid;
+ if (!container->iter_init(*counter, valid)) {
+#ifdef DEBUG_ENABLED
+ if (!valid) {
+ err_text = "Unable to iterate on object of type '" + Variant::get_type_name(container->get_type()) + "'.";
+ OPCODE_BREAK;
+ }
+#endif
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ } else {
+ GET_INSTRUCTION_ARG(iterator, 2);
+
+ *iterator = container->iter_get(*counter, valid);
+#ifdef DEBUG_ENABLED
+ if (!valid) {
+ err_text = "Unable to obtain iterator object of type '" + Variant::get_type_name(container->get_type()) + "'.";
+ OPCODE_BREAK;
+ }
+#endif
+ ip += 5; // Skip regular iterate which is always next.
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ITERATE_BEGIN_INT) {
+ CHECK_SPACE(8); // Check space for iterate instruction too.
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ int64_t size = *VariantInternal::get_int(container);
+
+ VariantInternal::initialize(counter, Variant::INT);
+ *VariantInternal::get_int(counter) = 0;
+
+ if (size > 0) {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ VariantInternal::initialize(iterator, Variant::INT);
+ *VariantInternal::get_int(iterator) = 0;
+
+ // Skip regular iterate.
+ ip += 5;
+ } else {
+ // Jump to end of loop.
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ITERATE_BEGIN_FLOAT) {
+ CHECK_SPACE(8); // Check space for iterate instruction too.
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ double size = *VariantInternal::get_float(container);
+
+ VariantInternal::initialize(counter, Variant::FLOAT);
+ *VariantInternal::get_float(counter) = 0.0;
+
+ if (size > 0) {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ VariantInternal::initialize(iterator, Variant::FLOAT);
+ *VariantInternal::get_float(iterator) = 0;
+
+ // Skip regular iterate.
+ ip += 5;
+ } else {
+ // Jump to end of loop.
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ITERATE_BEGIN_VECTOR2) {
+ CHECK_SPACE(8); // Check space for iterate instruction too.
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ Vector2 *bounds = VariantInternal::get_vector2(container);
+
+ VariantInternal::initialize(counter, Variant::FLOAT);
+ *VariantInternal::get_float(counter) = bounds->x;
+
+ if (bounds->x < bounds->y) {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ VariantInternal::initialize(iterator, Variant::FLOAT);
+ *VariantInternal::get_float(iterator) = bounds->x;
+
+ // Skip regular iterate.
+ ip += 5;
+ } else {
+ // Jump to end of loop.
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ITERATE_BEGIN_VECTOR2I) {
+ CHECK_SPACE(8); // Check space for iterate instruction too.
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ Vector2i *bounds = VariantInternal::get_vector2i(container);
+
+ VariantInternal::initialize(counter, Variant::FLOAT);
+ *VariantInternal::get_int(counter) = bounds->x;
+
+ if (bounds->x < bounds->y) {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ VariantInternal::initialize(iterator, Variant::INT);
+ *VariantInternal::get_int(iterator) = bounds->x;
+
+ // Skip regular iterate.
+ ip += 5;
+ } else {
+ // Jump to end of loop.
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ITERATE_BEGIN_VECTOR3) {
+ CHECK_SPACE(8); // Check space for iterate instruction too.
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ Vector3 *bounds = VariantInternal::get_vector3(container);
+ double from = bounds->x;
+ double to = bounds->y;
+ double step = bounds->z;
+
+ VariantInternal::initialize(counter, Variant::FLOAT);
+ *VariantInternal::get_float(counter) = from;
+
+ bool do_continue = from == to ? false : (from < to ? step > 0 : step < 0);
+
+ if (do_continue) {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ VariantInternal::initialize(iterator, Variant::FLOAT);
+ *VariantInternal::get_float(iterator) = from;
+
+ // Skip regular iterate.
+ ip += 5;
+ } else {
+ // Jump to end of loop.
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ITERATE_BEGIN_VECTOR3I) {
+ CHECK_SPACE(8); // Check space for iterate instruction too.
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ Vector3i *bounds = VariantInternal::get_vector3i(container);
+ int64_t from = bounds->x;
+ int64_t to = bounds->y;
+ int64_t step = bounds->z;
+
+ VariantInternal::initialize(counter, Variant::INT);
+ *VariantInternal::get_int(counter) = from;
+
+ bool do_continue = from == to ? false : (from < to ? step > 0 : step < 0);
+
+ if (do_continue) {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ VariantInternal::initialize(iterator, Variant::INT);
+ *VariantInternal::get_int(iterator) = from;
+
+ // Skip regular iterate.
+ ip += 5;
+ } else {
+ // Jump to end of loop.
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ITERATE_BEGIN_STRING) {
+ CHECK_SPACE(8); // Check space for iterate instruction too.
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ String *str = VariantInternal::get_string(container);
+
+ VariantInternal::initialize(counter, Variant::INT);
+ *VariantInternal::get_int(counter) = 0;
+
+ if (!str->empty()) {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ VariantInternal::initialize(iterator, Variant::STRING);
+ *VariantInternal::get_string(iterator) = str->substr(0, 1);
+
+ // Skip regular iterate.
+ ip += 5;
+ } else {
+ // Jump to end of loop.
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ITERATE_BEGIN_DICTIONARY) {
+ CHECK_SPACE(8); // Check space for iterate instruction too.
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ Dictionary *dict = VariantInternal::get_dictionary(container);
+ const Variant *next = dict->next(nullptr);
+ *counter = *next;
+
+ if (!dict->empty()) {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ *iterator = *next;
+
+ // Skip regular iterate.
+ ip += 5;
+ } else {
+ // Jump to end of loop.
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ITERATE_BEGIN_ARRAY) {
+ CHECK_SPACE(8); // Check space for iterate instruction too.
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ Array *array = VariantInternal::get_array(container);
+
+ VariantInternal::initialize(counter, Variant::INT);
+ *VariantInternal::get_int(counter) = 0;
+
+ if (!array->empty()) {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ *iterator = array->get(0);
+
+ // Skip regular iterate.
+ ip += 5;
+ } else {
+ // Jump to end of loop.
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ }
+ }
+ DISPATCH_OPCODE;
+
+#define OPCODE_ITERATE_BEGIN_PACKED_ARRAY(m_var_type, m_elem_type, m_get_func, m_var_ret_type, m_ret_type, m_ret_get_func) \
+ OPCODE(OPCODE_ITERATE_BEGIN_PACKED_##m_var_type##_ARRAY) { \
+ CHECK_SPACE(8); \
+ GET_INSTRUCTION_ARG(counter, 0); \
+ GET_INSTRUCTION_ARG(container, 1); \
+ Vector<m_elem_type> *array = VariantInternal::m_get_func(container); \
+ VariantInternal::initialize(counter, Variant::INT); \
+ *VariantInternal::get_int(counter) = 0; \
+ if (!array->empty()) { \
+ GET_INSTRUCTION_ARG(iterator, 2); \
+ VariantInternal::initialize(iterator, Variant::m_var_ret_type); \
+ m_ret_type *it = VariantInternal::m_ret_get_func(iterator); \
+ *it = array->get(0); \
+ ip += 5; \
+ } else { \
+ int jumpto = _code_ptr[ip + 4]; \
+ GD_ERR_BREAK(jumpto<0 || jumpto> _code_size); \
+ ip = jumpto; \
+ } \
+ } \
+ DISPATCH_OPCODE
+
+ OPCODE_ITERATE_BEGIN_PACKED_ARRAY(BYTE, uint8_t, get_byte_array, INT, int64_t, get_int);
+ OPCODE_ITERATE_BEGIN_PACKED_ARRAY(INT32, int32_t, get_int32_array, INT, int64_t, get_int);
+ OPCODE_ITERATE_BEGIN_PACKED_ARRAY(INT64, int64_t, get_int64_array, INT, int64_t, get_int);
+ OPCODE_ITERATE_BEGIN_PACKED_ARRAY(FLOAT32, float, get_float32_array, FLOAT, double, get_float);
+ OPCODE_ITERATE_BEGIN_PACKED_ARRAY(FLOAT64, double, get_float64_array, FLOAT, double, get_float);
+ OPCODE_ITERATE_BEGIN_PACKED_ARRAY(STRING, String, get_string_array, STRING, String, get_string);
+ OPCODE_ITERATE_BEGIN_PACKED_ARRAY(VECTOR2, Vector2, get_vector2_array, VECTOR2, Vector2, get_vector2);
+ OPCODE_ITERATE_BEGIN_PACKED_ARRAY(VECTOR3, Vector3, get_vector3_array, VECTOR3, Vector3, get_vector3);
+ OPCODE_ITERATE_BEGIN_PACKED_ARRAY(COLOR, Color, get_color_array, COLOR, Color, get_color);
+
+ OPCODE(OPCODE_ITERATE_BEGIN_OBJECT) {
+ CHECK_SPACE(4);
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+#ifdef DEBUG_ENABLED
+ bool freed = false;
+ Object *obj = container->get_validated_object_with_check(freed);
+ if (freed) {
+ err_text = "Trying to iterate on a previously freed object.";
+ OPCODE_BREAK;
+ } else if (!obj) {
+ err_text = "Trying to iterate on a null value.";
+ OPCODE_BREAK;
+ }
+#else
+ Object *obj = *VariantInternal::get_object(container);
+#endif
+ Array ref;
+ ref.push_back(*counter);
+ Variant vref;
+ VariantInternal::initialize(&vref, Variant::ARRAY);
+ *VariantInternal::get_array(&vref) = ref;
+
+ Variant **args = instruction_args; // Overriding an instruction argument, but we don't need access to that anymore.
+ args[0] = &vref;
+
+ Callable::CallError ce;
+ Variant has_next = obj->call(CoreStringNames::get_singleton()->_iter_init, (const Variant **)args, 1, ce);
+
+#ifdef DEBUG_ENABLED
+ if (ce.error != Callable::CallError::CALL_OK) {
+ err_text = vformat(R"(There was an error calling "_iter_next" on iterator object of type %s.)", *container);
+ OPCODE_BREAK;
+ }
+#endif
+ if (!has_next.booleanize()) {
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ } else {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ *iterator = obj->call(CoreStringNames::get_singleton()->_iter_get, (const Variant **)args, 1, ce);
+#ifdef DEBUG_ENABLED
+ if (ce.error != Callable::CallError::CALL_OK) {
+ err_text = vformat(R"(There was an error calling "_iter_get" on iterator object of type %s.)", *container);
+ OPCODE_BREAK;
+ }
+#endif
+
+ ip += 5; // Loop again.
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ITERATE) {
+ CHECK_SPACE(4);
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ bool valid;
+ if (!container->iter_next(*counter, valid)) {
+#ifdef DEBUG_ENABLED
+ if (!valid) {
+ err_text = "Unable to iterate on object of type '" + Variant::get_type_name(container->get_type()) + "' (type changed since first iteration?).";
+ OPCODE_BREAK;
+ }
+#endif
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ } else {
+ GET_INSTRUCTION_ARG(iterator, 2);
+
+ *iterator = container->iter_get(*counter, valid);
+#ifdef DEBUG_ENABLED
+ if (!valid) {
+ err_text = "Unable to obtain iterator object of type '" + Variant::get_type_name(container->get_type()) + "' (but was obtained on first iteration?).";
+ OPCODE_BREAK;
+ }
+#endif
+ ip += 5; //loop again
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ITERATE_INT) {
+ CHECK_SPACE(4);
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ int64_t size = *VariantInternal::get_int(container);
+ int64_t *count = VariantInternal::get_int(counter);
+
+ (*count)++;
+
+ if (*count >= size) {
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ } else {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ *VariantInternal::get_int(iterator) = *count;
+
+ ip += 5; // Loop again.
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ITERATE_FLOAT) {
+ CHECK_SPACE(4);
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ double size = *VariantInternal::get_float(container);
+ double *count = VariantInternal::get_float(counter);
+
+ (*count)++;
+
+ if (*count >= size) {
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ } else {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ *VariantInternal::get_float(iterator) = *count;
+
+ ip += 5; // Loop again.
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ITERATE_VECTOR2) {
+ CHECK_SPACE(4);
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ const Vector2 *bounds = VariantInternal::get_vector2((const Variant *)container);
+ double *count = VariantInternal::get_float(counter);
+
+ (*count)++;
+
+ if (*count >= bounds->y) {
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ } else {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ *VariantInternal::get_float(iterator) = *count;
+
+ ip += 5; // Loop again.
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ITERATE_VECTOR2I) {
+ CHECK_SPACE(4);
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ const Vector2i *bounds = VariantInternal::get_vector2i((const Variant *)container);
+ int64_t *count = VariantInternal::get_int(counter);
+
+ (*count)++;
+
+ if (*count >= bounds->y) {
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ } else {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ *VariantInternal::get_int(iterator) = *count;
+
+ ip += 5; // Loop again.
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ITERATE_VECTOR3) {
+ CHECK_SPACE(4);
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ const Vector3 *bounds = VariantInternal::get_vector3((const Variant *)container);
+ double *count = VariantInternal::get_float(counter);
+
+ *count += bounds->z;
+
+ if ((bounds->z < 0 && *count <= bounds->y) || (bounds->z > 0 && *count >= bounds->y)) {
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ } else {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ *VariantInternal::get_float(iterator) = *count;
+
+ ip += 5; // Loop again.
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ITERATE_VECTOR3I) {
+ CHECK_SPACE(4);
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ const Vector3i *bounds = VariantInternal::get_vector3i((const Variant *)container);
+ int64_t *count = VariantInternal::get_int(counter);
+
+ *count += bounds->z;
+
+ if ((bounds->z < 0 && *count <= bounds->y) || (bounds->z > 0 && *count >= bounds->y)) {
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ } else {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ *VariantInternal::get_int(iterator) = *count;
+
+ ip += 5; // Loop again.
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ITERATE_STRING) {
+ CHECK_SPACE(4);
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ const String *str = VariantInternal::get_string((const Variant *)container);
+ int64_t *idx = VariantInternal::get_int(counter);
+ (*idx)++;
+
+ if (*idx >= str->length()) {
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ } else {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ *VariantInternal::get_string(iterator) = str->substr(*idx, 1);
+
+ ip += 5; // Loop again.
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ITERATE_DICTIONARY) {
+ CHECK_SPACE(4);
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ const Dictionary *dict = VariantInternal::get_dictionary((const Variant *)container);
+ const Variant *next = dict->next(counter);
+
+ if (!next) {
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ } else {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ *counter = *next;
+ *iterator = *next;
+
+ ip += 5; // Loop again.
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ITERATE_ARRAY) {
+ CHECK_SPACE(4);
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+ const Array *array = VariantInternal::get_array((const Variant *)container);
+ int64_t *idx = VariantInternal::get_int(counter);
+ (*idx)++;
+
+ if (*idx >= array->size()) {
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ } else {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ *iterator = array->get(*idx);
+
+ ip += 5; // Loop again.
+ }
+ }
+ DISPATCH_OPCODE;
+
+#define OPCODE_ITERATE_PACKED_ARRAY(m_var_type, m_elem_type, m_get_func, m_ret_get_func) \
+ OPCODE(OPCODE_ITERATE_PACKED_##m_var_type##_ARRAY) { \
+ CHECK_SPACE(4); \
+ GET_INSTRUCTION_ARG(counter, 0); \
+ GET_INSTRUCTION_ARG(container, 1); \
+ const Vector<m_elem_type> *array = VariantInternal::m_get_func((const Variant *)container); \
+ int64_t *idx = VariantInternal::get_int(counter); \
+ (*idx)++; \
+ if (*idx >= array->size()) { \
+ int jumpto = _code_ptr[ip + 4]; \
+ GD_ERR_BREAK(jumpto<0 || jumpto> _code_size); \
+ ip = jumpto; \
+ } else { \
+ GET_INSTRUCTION_ARG(iterator, 2); \
+ *VariantInternal::m_ret_get_func(iterator) = array->get(*idx); \
+ ip += 5; \
+ } \
+ } \
+ DISPATCH_OPCODE
+
+ OPCODE_ITERATE_PACKED_ARRAY(BYTE, uint8_t, get_byte_array, get_int);
+ OPCODE_ITERATE_PACKED_ARRAY(INT32, int32_t, get_int32_array, get_int);
+ OPCODE_ITERATE_PACKED_ARRAY(INT64, int64_t, get_int64_array, get_int);
+ OPCODE_ITERATE_PACKED_ARRAY(FLOAT32, float, get_float32_array, get_float);
+ OPCODE_ITERATE_PACKED_ARRAY(FLOAT64, double, get_float64_array, get_float);
+ OPCODE_ITERATE_PACKED_ARRAY(STRING, String, get_string_array, get_string);
+ OPCODE_ITERATE_PACKED_ARRAY(VECTOR2, Vector2, get_vector2_array, get_vector2);
+ OPCODE_ITERATE_PACKED_ARRAY(VECTOR3, Vector3, get_vector3_array, get_vector3);
+ OPCODE_ITERATE_PACKED_ARRAY(COLOR, Color, get_color_array, get_color);
+
+ OPCODE(OPCODE_ITERATE_OBJECT) {
+ CHECK_SPACE(4);
+
+ GET_INSTRUCTION_ARG(counter, 0);
+ GET_INSTRUCTION_ARG(container, 1);
+
+#ifdef DEBUG_ENABLED
+ bool freed = false;
+ Object *obj = container->get_validated_object_with_check(freed);
+ if (freed) {
+ err_text = "Trying to iterate on a previously freed object.";
+ OPCODE_BREAK;
+ } else if (!obj) {
+ err_text = "Trying to iterate on a null value.";
+ OPCODE_BREAK;
+ }
+#else
+ Object *obj = *VariantInternal::get_object(container);
+#endif
+ Array ref;
+ ref.push_back(*counter);
+ Variant vref;
+ VariantInternal::initialize(&vref, Variant::ARRAY);
+ *VariantInternal::get_array(&vref) = ref;
+
+ Variant **args = instruction_args; // Overriding an instruction argument, but we don't need access to that anymore.
+ args[0] = &vref;
+
+ Callable::CallError ce;
+ Variant has_next = obj->call(CoreStringNames::get_singleton()->_iter_next, (const Variant **)args, 1, ce);
+
+#ifdef DEBUG_ENABLED
+ if (ce.error != Callable::CallError::CALL_OK) {
+ err_text = vformat(R"(There was an error calling "_iter_next" on iterator object of type %s.)", *container);
+ OPCODE_BREAK;
+ }
+#endif
+ if (!has_next.booleanize()) {
+ int jumpto = _code_ptr[ip + 4];
+ GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
+ } else {
+ GET_INSTRUCTION_ARG(iterator, 2);
+ *iterator = obj->call(CoreStringNames::get_singleton()->_iter_get, (const Variant **)args, 1, ce);
+#ifdef DEBUG_ENABLED
+ if (ce.error != Callable::CallError::CALL_OK) {
+ err_text = vformat(R"(There was an error calling "_iter_get" on iterator object of type %s.)", *container);
+ OPCODE_BREAK;
+ }
+#endif
+
+ ip += 5; // Loop again.
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_ASSERT) {
+ CHECK_SPACE(3);
+
+#ifdef DEBUG_ENABLED
+ GET_INSTRUCTION_ARG(test, 0);
+ bool result = test->booleanize();
+
+ if (!result) {
+ String message_str;
+ if (_code_ptr[ip + 2] != 0) {
+ GET_INSTRUCTION_ARG(message, 1);
+ message_str = *message;
+ }
+ if (message_str.empty()) {
+ err_text = "Assertion failed.";
+ } else {
+ err_text = "Assertion failed: " + message_str;
+ }
+ OPCODE_BREAK;
+ }
+
+#endif
+ ip += 3;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_BREAKPOINT) {
+#ifdef DEBUG_ENABLED
+ if (EngineDebugger::is_active()) {
+ GDScriptLanguage::get_singleton()->debug_break("Breakpoint Statement", true);
+ }
+#endif
+ ip += 1;
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_LINE) {
+ CHECK_SPACE(2);
+
+ line = _code_ptr[ip + 1];
+ ip += 2;
+
+ if (EngineDebugger::is_active()) {
+ // line
+ bool do_break = false;
+
+ if (EngineDebugger::get_script_debugger()->get_lines_left() > 0) {
+ if (EngineDebugger::get_script_debugger()->get_depth() <= 0) {
+ EngineDebugger::get_script_debugger()->set_lines_left(EngineDebugger::get_script_debugger()->get_lines_left() - 1);
+ }
+ if (EngineDebugger::get_script_debugger()->get_lines_left() <= 0) {
+ do_break = true;
+ }
+ }
+
+ if (EngineDebugger::get_script_debugger()->is_breakpoint(line, source)) {
+ do_break = true;
+ }
+
+ if (do_break) {
+ GDScriptLanguage::get_singleton()->debug_break("Breakpoint", true);
+ }
+
+ EngineDebugger::get_singleton()->line_poll();
+ }
+ }
+ DISPATCH_OPCODE;
+
+ OPCODE(OPCODE_END) {
+#ifdef DEBUG_ENABLED
+ exit_ok = true;
+#endif
+ OPCODE_BREAK;
+ }
+
+#if 0 // Enable for debugging.
+ default: {
+ err_text = "Illegal opcode " + itos(_code_ptr[ip]) + " at address " + itos(ip);
+ OPCODE_BREAK;
+ }
+#endif
+ }
+
+ OPCODES_END
+#ifdef DEBUG_ENABLED
+ if (exit_ok) {
+ OPCODE_OUT;
+ }
+ //error
+ // function, file, line, error, explanation
+ String err_file;
+ if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->path != "") {
+ err_file = p_instance->script->path;
+ } else if (script) {
+ err_file = script->path;
+ }
+ if (err_file == "") {
+ err_file = "<built-in>";
+ }
+ String err_func = name;
+ if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->name != "") {
+ err_func = p_instance->script->name + "." + err_func;
+ }
+ int err_line = line;
+ if (err_text == "") {
+ err_text = "Internal Script Error! - opcode #" + itos(last_opcode) + " (report please).";
+ }
+
+ if (!GDScriptLanguage::get_singleton()->debug_break(err_text, false)) {
+ // debugger break did not happen
+
+ _err_print_error(err_func.utf8().get_data(), err_file.utf8().get_data(), err_line, err_text.utf8().get_data(), ERR_HANDLER_SCRIPT);
+ }
+
+#endif
+ OPCODE_OUT;
+ }
+
+ OPCODES_OUT
+#ifdef DEBUG_ENABLED
+ if (GDScriptLanguage::get_singleton()->profiling) {
+ uint64_t time_taken = OS::get_singleton()->get_ticks_usec() - function_start_time;
+ profile.total_time += time_taken;
+ profile.self_time += time_taken - function_call_time;
+ profile.frame_total_time += time_taken;
+ profile.frame_self_time += time_taken - function_call_time;
+ GDScriptLanguage::get_singleton()->script_frame_time += time_taken - function_call_time;
+ }
+
+ // Check if this is the last time the function is resuming from await
+ // Will be true if never awaited as well
+ // When it's the last resume it will postpone the exit from stack,
+ // so the debugger knows which function triggered the resume of the next function (if any)
+ if (!p_state || awaited) {
+ if (EngineDebugger::is_active()) {
+ GDScriptLanguage::get_singleton()->exit_function();
+ }
+#endif
+
+ if (_stack_size) {
+ //free stack
+ for (int i = 0; i < _stack_size; i++) {
+ stack[i].~Variant();
+ }
+ }
+
+#ifdef DEBUG_ENABLED
+ }
+#endif
+
+ return retvalue;
+}
diff --git a/modules/mono/config.py b/modules/mono/config.py
index d060ae9b28..c4a6b408e6 100644
--- a/modules/mono/config.py
+++ b/modules/mono/config.py
@@ -11,7 +11,6 @@ def configure(env):
if platform not in supported_platforms:
raise RuntimeError("This module does not currently support building for this platform")
- env.use_ptrcall = True
env.add_module_version_string("mono")
from SCons.Script import BoolVariable, PathVariable, Variables, Help
diff --git a/modules/regex/regex.h b/modules/regex/regex.h
index 8cf19e1ca6..5b4798b65a 100644
--- a/modules/regex/regex.h
+++ b/modules/regex/regex.h
@@ -83,7 +83,6 @@ protected:
public:
void clear();
Error compile(const String &p_pattern);
- void _init(const String &p_pattern = "");
Ref<RegExMatch> search(const String &p_subject, int p_offset = 0, int p_end = -1) const;
Array search_all(const String &p_subject, int p_offset = 0, int p_end = -1) const;
diff --git a/modules/regex/tests/test_regex.h b/modules/regex/tests/test_regex.h
new file mode 100644
index 0000000000..4b9e7e18eb
--- /dev/null
+++ b/modules/regex/tests/test_regex.h
@@ -0,0 +1,164 @@
+/*************************************************************************/
+/* test_regex.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* 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 TEST_REGEX_H
+#define TEST_REGEX_H
+
+#include "core/string/ustring.h"
+#include "modules/regex/regex.h"
+
+#include "tests/test_macros.h"
+
+namespace TestRegEx {
+
+TEST_CASE("[RegEx] Initialization") {
+ const String pattern = "(?<vowel>[aeiou])";
+
+ RegEx re1(pattern);
+ CHECK(re1.is_valid());
+ CHECK(re1.get_pattern() == pattern);
+ CHECK(re1.get_group_count() == 1);
+
+ Array names = re1.get_names();
+ CHECK(names.size() == 1);
+ CHECK(names[0] == "vowel");
+
+ RegEx re2;
+ CHECK(re2.is_valid() == false);
+ CHECK(re2.compile(pattern) == OK);
+ CHECK(re2.is_valid());
+
+ CHECK(re1.get_pattern() == re2.get_pattern());
+ CHECK(re1.get_group_count() == re2.get_group_count());
+
+ names = re2.get_names();
+ CHECK(names.size() == 1);
+ CHECK(names[0] == "vowel");
+}
+
+TEST_CASE("[RegEx] Clearing") {
+ RegEx re("Godot");
+ REQUIRE(re.is_valid());
+ re.clear();
+ CHECK(re.is_valid() == false);
+}
+
+TEST_CASE("[RegEx] Searching") {
+ const String s = "Searching";
+ const String vowels = "[aeiou]{1,2}";
+ const String numerics = "\\d";
+
+ RegEx re(vowels);
+ REQUIRE(re.is_valid());
+
+ Ref<RegExMatch> match = re.search(s);
+ REQUIRE(match != nullptr);
+ CHECK(match->get_string(0) == "ea");
+
+ match = re.search(s, 2, 4);
+ REQUIRE(match != nullptr);
+ CHECK(match->get_string(0) == "a");
+
+ const Array all_results = re.search_all(s);
+ CHECK(all_results.size() == 2);
+ match = all_results[0];
+ REQUIRE(match != nullptr);
+ CHECK(match->get_string(0) == "ea");
+ match = all_results[1];
+ REQUIRE(match != nullptr);
+ CHECK(match->get_string(0) == "i");
+
+ CHECK(re.compile(numerics) == OK);
+ CHECK(re.is_valid());
+ CHECK(re.search(s) == nullptr);
+ CHECK(re.search_all(s).size() == 0);
+}
+
+TEST_CASE("[RegEx] Substitution") {
+ String s = "Double all the vowels.";
+
+ RegEx re("(?<vowel>[aeiou])");
+ REQUIRE(re.is_valid());
+ CHECK(re.sub(s, "$0$vowel", true) == "Doouublee aall thee vooweels.");
+}
+
+TEST_CASE("[RegEx] Uninitialized use") {
+ const String s = "Godot";
+
+ RegEx re;
+ ERR_PRINT_OFF;
+ CHECK(re.search(s) == nullptr);
+ CHECK(re.search_all(s).size() == 0);
+ CHECK(re.sub(s, "") == "");
+ CHECK(re.get_group_count() == 0);
+ CHECK(re.get_names().size() == 0);
+ ERR_PRINT_ON
+}
+
+TEST_CASE("[RegEx] Empty Pattern") {
+ const String s = "Godot";
+
+ RegEx re;
+ CHECK(re.compile("") == OK);
+ CHECK(re.is_valid());
+}
+
+TEST_CASE("[RegEx] Invalid offset") {
+ const String s = "Godot";
+
+ RegEx re("o");
+ REQUIRE(re.is_valid());
+ CHECK(re.search(s, -1) == nullptr);
+ CHECK(re.search_all(s, -1).size() == 0);
+ CHECK(re.sub(s, "", true, -1) == "");
+}
+
+TEST_CASE("[RegEx] Invalid end position") {
+ const String s = "Godot";
+
+ RegEx re("o");
+ REQUIRE(re.is_valid());
+ Ref<RegExMatch> match = re.search(s, 0, 10);
+ CHECK(match->get_string(0) == "o");
+
+ const Array all_results = re.search_all(s, 0, 10);
+ CHECK(all_results.size() == 2);
+ match = all_results[0];
+ REQUIRE(match != nullptr);
+ CHECK(match->get_string(0) == String("o"));
+ match = all_results[1];
+ REQUIRE(match != nullptr);
+ CHECK(match->get_string(0) == String("o"));
+
+ CHECK(re.sub(s, "", true, 0, 10) == "Gdt");
+}
+} // namespace TestRegEx
+
+#endif // TEST_REGEX_H
diff --git a/modules/webm/doc_classes/VideoStreamWebm.xml b/modules/webm/doc_classes/VideoStreamWebm.xml
index 2edbc08cc8..f3e13ba31a 100644
--- a/modules/webm/doc_classes/VideoStreamWebm.xml
+++ b/modules/webm/doc_classes/VideoStreamWebm.xml
@@ -5,6 +5,7 @@
</brief_description>
<description>
[VideoStream] resource handling the [url=https://www.webmproject.org/]WebM[/url] video format with [code].webm[/code] extension. Both the VP8 and VP9 codecs are supported. The VP8 and VP9 codecs are more efficient than [VideoStreamTheora], but they require more CPU resources to decode (especially VP9). Both the VP8 and VP9 codecs are decoded on the CPU.
+ [b]Note:[/b] Alpha channel (also known as transparency) is not supported. The video will always appear to have a black background, even if it originally contains an alpha channel.
[b]Note:[/b] There are known bugs and performance issues with WebM video playback in Godot. If you run into problems, try using the Ogg Theora format instead: [VideoStreamTheora]
</description>
<tutorials>
diff --git a/modules/webrtc/library_godot_webrtc.js b/modules/webrtc/library_godot_webrtc.js
index d4c38f15a2..f725a10a6f 100644
--- a/modules/webrtc/library_godot_webrtc.js
+++ b/modules/webrtc/library_godot_webrtc.js
@@ -28,11 +28,11 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-var GodotRTCDataChannel = {
+const GodotRTCDataChannel = {
// Our socket implementation that forwards events to C++.
- $GodotRTCDataChannel__deps: ['$IDHandler', '$GodotOS'],
+ $GodotRTCDataChannel__deps: ['$IDHandler', '$GodotRuntime'],
$GodotRTCDataChannel: {
- connect: function(p_id, p_on_open, p_on_message, p_on_error, p_on_close) {
+ connect: function (p_id, p_on_open, p_on_message, p_on_error, p_on_close) {
const ref = IDHandler.get(p_id);
if (!ref) {
return;
@@ -48,31 +48,31 @@ var GodotRTCDataChannel = {
ref.onerror = function (event) {
p_on_error();
};
- ref.onmessage = function(event) {
- var buffer;
- var is_string = 0;
+ ref.onmessage = function (event) {
+ let buffer;
+ let is_string = 0;
if (event.data instanceof ArrayBuffer) {
buffer = new Uint8Array(event.data);
} else if (event.data instanceof Blob) {
- console.error("Blob type not supported");
+ GodotRuntime.error('Blob type not supported');
return;
- } else if (typeof event.data === "string") {
+ } else if (typeof event.data === 'string') {
is_string = 1;
- var enc = new TextEncoder("utf-8");
+ const enc = new TextEncoder('utf-8');
buffer = new Uint8Array(enc.encode(event.data));
} else {
- console.error("Unknown message type");
+ GodotRuntime.error('Unknown message type');
return;
}
- var len = buffer.length*buffer.BYTES_PER_ELEMENT;
- var out = _malloc(len);
+ const len = buffer.length * buffer.BYTES_PER_ELEMENT;
+ const out = GodotRuntime.malloc(len);
HEAPU8.set(buffer, out);
p_on_message(out, len, is_string);
- _free(out);
- }
+ GodotRuntime.free(out);
+ };
},
- close: function(p_id) {
+ close: function (p_id) {
const ref = IDHandler.get(p_id);
if (!ref) {
return;
@@ -84,40 +84,40 @@ var GodotRTCDataChannel = {
ref.close();
},
- get_prop: function(p_id, p_prop, p_def) {
+ get_prop: function (p_id, p_prop, p_def) {
const ref = IDHandler.get(p_id);
return (ref && ref[p_prop] !== undefined) ? ref[p_prop] : p_def;
},
},
- godot_js_rtc_datachannel_ready_state_get: function(p_id) {
+ godot_js_rtc_datachannel_ready_state_get: function (p_id) {
const ref = IDHandler.get(p_id);
if (!ref) {
return 3; // CLOSED
}
- switch(ref.readyState) {
- case "connecting":
- return 0;
- case "open":
- return 1;
- case "closing":
- return 2;
- case "closed":
- return 3;
+ switch (ref.readyState) {
+ case 'connecting':
+ return 0;
+ case 'open':
+ return 1;
+ case 'closing':
+ return 2;
+ case 'closed':
+ default:
+ return 3;
}
- return 3; // CLOSED
},
- godot_js_rtc_datachannel_send: function(p_id, p_buffer, p_length, p_raw) {
+ godot_js_rtc_datachannel_send: function (p_id, p_buffer, p_length, p_raw) {
const ref = IDHandler.get(p_id);
if (!ref) {
return 1;
}
const bytes_array = new Uint8Array(p_length);
- for (var i = 0; i < p_length; i++) {
- bytes_array[i] = getValue(p_buffer + i, 'i8');
+ for (let i = 0; i < p_length; i++) {
+ bytes_array[i] = GodotRuntime.getHeapValue(p_buffer + i, 'i8');
}
if (p_raw) {
@@ -126,17 +126,18 @@ var GodotRTCDataChannel = {
const string = new TextDecoder('utf-8').decode(bytes_array);
ref.send(string);
}
+ return 0;
},
- godot_js_rtc_datachannel_is_ordered: function(p_id) {
+ godot_js_rtc_datachannel_is_ordered: function (p_id) {
return IDHandler.get_prop(p_id, 'ordered', true);
},
- godot_js_rtc_datachannel_id_get: function(p_id) {
+ godot_js_rtc_datachannel_id_get: function (p_id) {
return IDHandler.get_prop(p_id, 'id', 65535);
},
- godot_js_rtc_datachannel_max_packet_lifetime_get: function(p_id) {
+ godot_js_rtc_datachannel_max_packet_lifetime_get: function (p_id) {
const ref = IDHandler.get(p_id);
if (!ref) {
return 65535;
@@ -150,44 +151,44 @@ var GodotRTCDataChannel = {
return 65535;
},
- godot_js_rtc_datachannel_max_retransmits_get: function(p_id) {
+ godot_js_rtc_datachannel_max_retransmits_get: function (p_id) {
return IDHandler.get_prop(p_id, 'maxRetransmits', 65535);
},
- godot_js_rtc_datachannel_is_negotiated: function(p_id, p_def) {
+ godot_js_rtc_datachannel_is_negotiated: function (p_id, p_def) {
return IDHandler.get_prop(p_id, 'negotiated', 65535);
},
- godot_js_rtc_datachannel_label_get: function(p_id) {
+ godot_js_rtc_datachannel_label_get: function (p_id) {
const ref = IDHandler.get(p_id);
if (!ref || !ref.label) {
return 0;
}
- return GodotOS.allocString(ref.label);
+ return GodotRuntime.allocString(ref.label);
},
- godot_js_rtc_datachannel_protocol_get: function(p_id) {
+ godot_js_rtc_datachannel_protocol_get: function (p_id) {
const ref = IDHandler.get(p_id);
if (!ref || !ref.protocol) {
return 0;
}
- return GodotOS.allocString(ref.protocol);
+ return GodotRuntime.allocString(ref.protocol);
},
- godot_js_rtc_datachannel_destroy: function(p_id) {
+ godot_js_rtc_datachannel_destroy: function (p_id) {
GodotRTCDataChannel.close(p_id);
IDHandler.remove(p_id);
},
- godot_js_rtc_datachannel_connect: function(p_id, p_ref, p_on_open, p_on_message, p_on_error, p_on_close) {
- const onopen = GodotOS.get_func(p_on_open).bind(null, p_ref);
- const onmessage = GodotOS.get_func(p_on_message).bind(null, p_ref);
- const onerror = GodotOS.get_func(p_on_error).bind(null, p_ref);
- const onclose = GodotOS.get_func(p_on_close).bind(null, p_ref);
+ godot_js_rtc_datachannel_connect: function (p_id, p_ref, p_on_open, p_on_message, p_on_error, p_on_close) {
+ const onopen = GodotRuntime.get_func(p_on_open).bind(null, p_ref);
+ const onmessage = GodotRuntime.get_func(p_on_message).bind(null, p_ref);
+ const onerror = GodotRuntime.get_func(p_on_error).bind(null, p_ref);
+ const onclose = GodotRuntime.get_func(p_on_close).bind(null, p_ref);
GodotRTCDataChannel.connect(p_id, onopen, onmessage, onerror, onclose);
},
- godot_js_rtc_datachannel_close: function(p_id) {
+ godot_js_rtc_datachannel_close: function (p_id) {
const ref = IDHandler.get(p_id);
if (!ref) {
return;
@@ -199,48 +200,55 @@ var GodotRTCDataChannel = {
autoAddDeps(GodotRTCDataChannel, '$GodotRTCDataChannel');
mergeInto(LibraryManager.library, GodotRTCDataChannel);
-var GodotRTCPeerConnection = {
- $GodotRTCPeerConnection__deps: ['$IDHandler', '$GodotOS', '$GodotRTCDataChannel'],
+const GodotRTCPeerConnection = {
+ $GodotRTCPeerConnection__deps: ['$IDHandler', '$GodotRuntime', '$GodotRTCDataChannel'],
$GodotRTCPeerConnection: {
- onstatechange: function(p_id, p_conn, callback, event) {
+ onstatechange: function (p_id, p_conn, callback, event) {
const ref = IDHandler.get(p_id);
if (!ref) {
return;
}
- var state = 5; // CLOSED
- switch(p_conn.iceConnectionState) {
- case "new":
- state = 0;
- case "checking":
- state = 1;
- case "connected":
- case "completed":
- state = 2;
- case "disconnected":
- state = 3;
- case "failed":
- state = 4;
- case "closed":
- state = 5;
+ let state;
+ switch (p_conn.iceConnectionState) {
+ case 'new':
+ state = 0;
+ break;
+ case 'checking':
+ state = 1;
+ break;
+ case 'connected':
+ case 'completed':
+ state = 2;
+ break;
+ case 'disconnected':
+ state = 3;
+ break;
+ case 'failed':
+ state = 4;
+ break;
+ case 'closed':
+ default:
+ state = 5;
+ break;
}
callback(state);
},
- onicecandidate: function(p_id, callback, event) {
+ onicecandidate: function (p_id, callback, event) {
const ref = IDHandler.get(p_id);
if (!ref || !event.candidate) {
return;
}
- let c = event.candidate;
- let candidate_str = GodotOS.allocString(c.candidate);
- let mid_str = GodotOS.allocString(c.sdpMid);
+ const c = event.candidate;
+ const candidate_str = GodotRuntime.allocString(c.candidate);
+ const mid_str = GodotRuntime.allocString(c.sdpMid);
callback(mid_str, c.sdpMLineIndex, candidate_str);
- _free(candidate_str);
- _free(mid_str);
+ GodotRuntime.free(candidate_str);
+ GodotRuntime.free(mid_str);
},
- ondatachannel: function(p_id, callback, event) {
+ ondatachannel: function (p_id, callback, event) {
const ref = IDHandler.get(p_id);
if (!ref) {
return;
@@ -250,39 +258,39 @@ var GodotRTCPeerConnection = {
callback(cid);
},
- onsession: function(p_id, callback, session) {
+ onsession: function (p_id, callback, session) {
const ref = IDHandler.get(p_id);
if (!ref) {
return;
}
- let type_str = GodotOS.allocString(session.type);
- let sdp_str = GodotOS.allocString(session.sdp);
+ const type_str = GodotRuntime.allocString(session.type);
+ const sdp_str = GodotRuntime.allocString(session.sdp);
callback(type_str, sdp_str);
- _free(type_str);
- _free(sdp_str);
+ GodotRuntime.free(type_str);
+ GodotRuntime.free(sdp_str);
},
- onerror: function(p_id, callback, error) {
+ onerror: function (p_id, callback, error) {
const ref = IDHandler.get(p_id);
if (!ref) {
return;
}
- console.error(error);
+ GodotRuntime.error(error);
callback();
},
},
- godot_js_rtc_pc_create: function(p_config, p_ref, p_on_state_change, p_on_candidate, p_on_datachannel) {
- const onstatechange = GodotOS.get_func(p_on_state_change).bind(null, p_ref);
- const oncandidate = GodotOS.get_func(p_on_candidate).bind(null, p_ref);
- const ondatachannel = GodotOS.get_func(p_on_datachannel).bind(null, p_ref);
+ godot_js_rtc_pc_create: function (p_config, p_ref, p_on_state_change, p_on_candidate, p_on_datachannel) {
+ const onstatechange = GodotRuntime.get_func(p_on_state_change).bind(null, p_ref);
+ const oncandidate = GodotRuntime.get_func(p_on_candidate).bind(null, p_ref);
+ const ondatachannel = GodotRuntime.get_func(p_on_datachannel).bind(null, p_ref);
- var config = JSON.parse(UTF8ToString(p_config));
- var conn = null;
+ const config = JSON.parse(GodotRuntime.parseString(p_config));
+ let conn = null;
try {
conn = new RTCPeerConnection(config);
} catch (e) {
- console.error(e);
+ GodotRuntime.error(e);
return 0;
}
@@ -294,7 +302,7 @@ var GodotRTCPeerConnection = {
return id;
},
- godot_js_rtc_pc_close: function(p_id) {
+ godot_js_rtc_pc_close: function (p_id) {
const ref = IDHandler.get(p_id);
if (!ref) {
return;
@@ -302,7 +310,7 @@ var GodotRTCPeerConnection = {
ref.close();
},
- godot_js_rtc_pc_destroy: function(p_id) {
+ godot_js_rtc_pc_destroy: function (p_id) {
const ref = IDHandler.get(p_id);
if (!ref) {
return;
@@ -313,93 +321,93 @@ var GodotRTCPeerConnection = {
IDHandler.remove(p_id);
},
- godot_js_rtc_pc_offer_create: function(p_id, p_obj, p_on_session, p_on_error) {
+ godot_js_rtc_pc_offer_create: function (p_id, p_obj, p_on_session, p_on_error) {
const ref = IDHandler.get(p_id);
if (!ref) {
return;
}
- const onsession = GodotOS.get_func(p_on_session).bind(null, p_obj);
- const onerror = GodotOS.get_func(p_on_error).bind(null, p_obj);
- ref.createOffer().then(function(session) {
+ const onsession = GodotRuntime.get_func(p_on_session).bind(null, p_obj);
+ const onerror = GodotRuntime.get_func(p_on_error).bind(null, p_obj);
+ ref.createOffer().then(function (session) {
GodotRTCPeerConnection.onsession(p_id, onsession, session);
- }).catch(function(error) {
+ }).catch(function (error) {
GodotRTCPeerConnection.onerror(p_id, onerror, error);
});
},
- godot_js_rtc_pc_local_description_set: function(p_id, p_type, p_sdp, p_obj, p_on_error) {
+ godot_js_rtc_pc_local_description_set: function (p_id, p_type, p_sdp, p_obj, p_on_error) {
const ref = IDHandler.get(p_id);
if (!ref) {
return;
}
- const type = UTF8ToString(p_type);
- const sdp = UTF8ToString(p_sdp);
- const onerror = GodotOS.get_func(p_on_error).bind(null, p_obj);
+ const type = GodotRuntime.parseString(p_type);
+ const sdp = GodotRuntime.parseString(p_sdp);
+ const onerror = GodotRuntime.get_func(p_on_error).bind(null, p_obj);
ref.setLocalDescription({
'sdp': sdp,
- 'type': type
- }).catch(function(error) {
+ 'type': type,
+ }).catch(function (error) {
GodotRTCPeerConnection.onerror(p_id, onerror, error);
});
},
- godot_js_rtc_pc_remote_description_set: function(p_id, p_type, p_sdp, p_obj, p_session_created, p_on_error) {
+ godot_js_rtc_pc_remote_description_set: function (p_id, p_type, p_sdp, p_obj, p_session_created, p_on_error) {
const ref = IDHandler.get(p_id);
if (!ref) {
return;
}
- const type = UTF8ToString(p_type);
- const sdp = UTF8ToString(p_sdp);
- const onerror = GodotOS.get_func(p_on_error).bind(null, p_obj);
- const onsession = GodotOS.get_func(p_session_created).bind(null, p_obj);
+ const type = GodotRuntime.parseString(p_type);
+ const sdp = GodotRuntime.parseString(p_sdp);
+ const onerror = GodotRuntime.get_func(p_on_error).bind(null, p_obj);
+ const onsession = GodotRuntime.get_func(p_session_created).bind(null, p_obj);
ref.setRemoteDescription({
'sdp': sdp,
- 'type': type
- }).then(function() {
- if (type != 'offer') {
- return;
+ 'type': type,
+ }).then(function () {
+ if (type !== 'offer') {
+ return Promise.resolve();
}
- return ref.createAnswer().then(function(session) {
+ return ref.createAnswer().then(function (session) {
GodotRTCPeerConnection.onsession(p_id, onsession, session);
});
- }).catch(function(error) {
+ }).catch(function (error) {
GodotRTCPeerConnection.onerror(p_id, onerror, error);
});
},
- godot_js_rtc_pc_ice_candidate_add: function(p_id, p_mid_name, p_mline_idx, p_sdp) {
+ godot_js_rtc_pc_ice_candidate_add: function (p_id, p_mid_name, p_mline_idx, p_sdp) {
const ref = IDHandler.get(p_id);
if (!ref) {
return;
}
- var sdpMidName = UTF8ToString(p_mid_name);
- var sdpName = UTF8ToString(p_sdp);
+ const sdpMidName = GodotRuntime.parseString(p_mid_name);
+ const sdpName = GodotRuntime.parseString(p_sdp);
ref.addIceCandidate(new RTCIceCandidate({
- "candidate": sdpName,
- "sdpMid": sdpMidName,
- "sdpMlineIndex": p_mline_idx,
+ 'candidate': sdpName,
+ 'sdpMid': sdpMidName,
+ 'sdpMlineIndex': p_mline_idx,
}));
},
godot_js_rtc_pc_datachannel_create__deps: ['$GodotRTCDataChannel'],
- godot_js_rtc_pc_datachannel_create: function(p_id, p_label, p_config) {
+ godot_js_rtc_pc_datachannel_create: function (p_id, p_label, p_config) {
try {
const ref = IDHandler.get(p_id);
if (!ref) {
return 0;
}
- const label = UTF8ToString(p_label);
- const config = JSON.parse(UTF8ToString(p_config));
+ const label = GodotRuntime.parseString(p_label);
+ const config = JSON.parse(GodotRuntime.parseString(p_config));
const channel = ref.createDataChannel(label, config);
return IDHandler.add(channel);
} catch (e) {
- console.error(e);
+ GodotRuntime.error(e);
return 0;
}
},
};
-autoAddDeps(GodotRTCPeerConnection, '$GodotRTCPeerConnection')
+autoAddDeps(GodotRTCPeerConnection, '$GodotRTCPeerConnection');
mergeInto(LibraryManager.library, GodotRTCPeerConnection);
diff --git a/modules/websocket/library_godot_websocket.js b/modules/websocket/library_godot_websocket.js
index 7076a6f43d..6ada4e7335 100644
--- a/modules/websocket/library_godot_websocket.js
+++ b/modules/websocket/library_godot_websocket.js
@@ -28,51 +28,51 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-var GodotWebSocket = {
+const GodotWebSocket = {
// Our socket implementation that forwards events to C++.
- $GodotWebSocket__deps: ['$IDHandler'],
+ $GodotWebSocket__deps: ['$IDHandler', '$GodotRuntime'],
$GodotWebSocket: {
// Connection opened, report selected protocol
- _onopen: function(p_id, callback, event) {
+ _onopen: function (p_id, callback, event) {
const ref = IDHandler.get(p_id);
if (!ref) {
return; // Godot object is gone.
}
- let c_str = GodotOS.allocString(ref.protocol);
+ const c_str = GodotRuntime.allocString(ref.protocol);
callback(c_str);
- _free(c_str);
+ GodotRuntime.free(c_str);
},
// Message received, report content and type (UTF8 vs binary)
- _onmessage: function(p_id, callback, event) {
+ _onmessage: function (p_id, callback, event) {
const ref = IDHandler.get(p_id);
if (!ref) {
return; // Godot object is gone.
}
- var buffer;
- var is_string = 0;
+ let buffer;
+ let is_string = 0;
if (event.data instanceof ArrayBuffer) {
buffer = new Uint8Array(event.data);
} else if (event.data instanceof Blob) {
- alert("Blob type not supported");
+ GodotRuntime.error('Blob type not supported');
return;
- } else if (typeof event.data === "string") {
+ } else if (typeof event.data === 'string') {
is_string = 1;
- var enc = new TextEncoder("utf-8");
+ const enc = new TextEncoder('utf-8');
buffer = new Uint8Array(enc.encode(event.data));
} else {
- alert("Unknown message type");
+ GodotRuntime.error('Unknown message type');
return;
}
- var len = buffer.length*buffer.BYTES_PER_ELEMENT;
- var out = _malloc(len);
+ const len = buffer.length * buffer.BYTES_PER_ELEMENT;
+ const out = GodotRuntime.malloc(len);
HEAPU8.set(buffer, out);
callback(out, len, is_string);
- _free(out);
+ GodotRuntime.free(out);
},
// An error happened, 'onclose' will be called after this.
- _onerror: function(p_id, callback, event) {
+ _onerror: function (p_id, callback, event) {
const ref = IDHandler.get(p_id);
if (!ref) {
return; // Godot object is gone.
@@ -81,27 +81,27 @@ var GodotWebSocket = {
},
// Connection is closed, this is always fired. Report close code, reason, and clean status.
- _onclose: function(p_id, callback, event) {
+ _onclose: function (p_id, callback, event) {
const ref = IDHandler.get(p_id);
if (!ref) {
return; // Godot object is gone.
}
- let c_str = GodotOS.allocString(event.reason);
+ const c_str = GodotRuntime.allocString(event.reason);
callback(event.code, c_str, event.wasClean ? 1 : 0);
- _free(c_str);
+ GodotRuntime.free(c_str);
},
// Send a message
- send: function(p_id, p_data) {
+ send: function (p_id, p_data) {
const ref = IDHandler.get(p_id);
- if (!ref || ref.readyState != ref.OPEN) {
+ if (!ref || ref.readyState !== ref.OPEN) {
return 1; // Godot object is gone or socket is not in a ready state.
}
ref.send(p_data);
return 0;
},
- create: function(socket, p_on_open, p_on_message, p_on_error, p_on_close) {
+ create: function (socket, p_on_open, p_on_message, p_on_error, p_on_close) {
const id = IDHandler.add(socket);
socket.onopen = GodotWebSocket._onopen.bind(null, id, p_on_open);
socket.onmessage = GodotWebSocket._onmessage.bind(null, id, p_on_message);
@@ -111,17 +111,17 @@ var GodotWebSocket = {
},
// Closes the JavaScript WebSocket (if not already closing) associated to a given C++ object.
- close: function(p_id, p_code, p_reason) {
+ close: function (p_id, p_code, p_reason) {
const ref = IDHandler.get(p_id);
if (ref && ref.readyState < ref.CLOSING) {
const code = p_code;
- const reason = UTF8ToString(p_reason);
+ const reason = GodotRuntime.parseString(p_reason);
ref.close(code, reason);
}
},
// Deletes the reference to a C++ object (closing any connected socket if necessary).
- destroy: function(p_id) {
+ destroy: function (p_id) {
const ref = IDHandler.get(p_id);
if (!ref) {
return;
@@ -135,50 +135,50 @@ var GodotWebSocket = {
},
},
- godot_js_websocket_create: function(p_ref, p_url, p_proto, p_on_open, p_on_message, p_on_error, p_on_close) {
- const on_open = GodotOS.get_func(p_on_open).bind(null, p_ref);
- const on_message = GodotOS.get_func(p_on_message).bind(null, p_ref);
- const on_error = GodotOS.get_func(p_on_error).bind(null, p_ref);
- const on_close = GodotOS.get_func(p_on_close).bind(null, p_ref);
- const url = UTF8ToString(p_url);
- const protos = UTF8ToString(p_proto);
- var socket = null;
+ godot_js_websocket_create: function (p_ref, p_url, p_proto, p_on_open, p_on_message, p_on_error, p_on_close) {
+ const on_open = GodotRuntime.get_func(p_on_open).bind(null, p_ref);
+ const on_message = GodotRuntime.get_func(p_on_message).bind(null, p_ref);
+ const on_error = GodotRuntime.get_func(p_on_error).bind(null, p_ref);
+ const on_close = GodotRuntime.get_func(p_on_close).bind(null, p_ref);
+ const url = GodotRuntime.parseString(p_url);
+ const protos = GodotRuntime.parseString(p_proto);
+ let socket = null;
try {
if (protos) {
- socket = new WebSocket(url, protos.split(","));
+ socket = new WebSocket(url, protos.split(','));
} else {
socket = new WebSocket(url);
}
} catch (e) {
return 0;
}
- socket.binaryType = "arraybuffer";
+ socket.binaryType = 'arraybuffer';
return GodotWebSocket.create(socket, on_open, on_message, on_error, on_close);
},
- godot_js_websocket_send: function(p_id, p_buf, p_buf_len, p_raw) {
- var bytes_array = new Uint8Array(p_buf_len);
- var i = 0;
- for(i = 0; i < p_buf_len; i++) {
- bytes_array[i] = getValue(p_buf + i, 'i8');
+ godot_js_websocket_send: function (p_id, p_buf, p_buf_len, p_raw) {
+ const bytes_array = new Uint8Array(p_buf_len);
+ let i = 0;
+ for (i = 0; i < p_buf_len; i++) {
+ bytes_array[i] = GodotRuntime.getHeapValue(p_buf + i, 'i8');
}
- var out = bytes_array.buffer;
+ let out = bytes_array.buffer;
if (!p_raw) {
- out = new TextDecoder("utf-8").decode(bytes_array);
+ out = new TextDecoder('utf-8').decode(bytes_array);
}
return GodotWebSocket.send(p_id, out);
},
- godot_js_websocket_close: function(p_id, p_code, p_reason) {
+ godot_js_websocket_close: function (p_id, p_code, p_reason) {
const code = p_code;
- const reason = UTF8ToString(p_reason);
+ const reason = GodotRuntime.parseString(p_reason);
GodotWebSocket.close(p_id, code, reason);
},
- godot_js_websocket_destroy: function(p_id) {
+ godot_js_websocket_destroy: function (p_id) {
GodotWebSocket.destroy(p_id);
},
};
-autoAddDeps(GodotWebSocket, '$GodotWebSocket')
+autoAddDeps(GodotWebSocket, '$GodotWebSocket');
mergeInto(LibraryManager.library, GodotWebSocket);
diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp
index 9288fff82f..d24c96f87a 100644
--- a/platform/android/export/export.cpp
+++ b/platform/android/export/export.cpp
@@ -1982,15 +1982,6 @@ public:
err += "\n";
valid = false;
}
-
- // Check for the build-tools directory.
- DirAccessRef build_tools_da = DirAccess::open(sdk_path.plus_file("build-tools"), &errn);
- if (errn != OK) {
- err += TTR("Invalid Android SDK path for custom build in Editor Settings.");
- err += TTR("Missing 'build-tools' directory!");
- err += "\n";
- valid = false;
- }
}
if (!FileAccess::exists("res://android/build/build.gradle")) {
@@ -2275,65 +2266,6 @@ public:
}
}
- Error _zip_align_project(const String &sdk_path, const String &unaligned_file_path, const String &aligned_file_path) {
- // Look for the zipalign tool.
- String zipalign_command_name;
-#ifdef WINDOWS_ENABLED
- zipalign_command_name = "zipalign.exe";
-#else
- zipalign_command_name = "zipalign";
-#endif
-
- String zipalign_command;
- Error errn;
- String build_tools_dir = sdk_path.plus_file("build-tools");
- DirAccessRef da = DirAccess::open(build_tools_dir, &errn);
- if (errn != OK) {
- return errn;
- }
-
- // There are additional versions directories we need to go through.
- da->list_dir_begin();
- String sub_dir = da->get_next();
- while (!sub_dir.empty()) {
- if (!sub_dir.begins_with(".") && da->current_is_dir()) {
- // Check if the tool is here.
- String tool_path = build_tools_dir.plus_file(sub_dir).plus_file(zipalign_command_name);
- if (FileAccess::exists(tool_path)) {
- zipalign_command = tool_path;
- break;
- }
- }
- sub_dir = da->get_next();
- }
- da->list_dir_end();
-
- if (zipalign_command.empty()) {
- EditorNode::get_singleton()->show_warning(TTR("Unable to find the zipalign tool."));
- return ERR_CANT_CREATE;
- }
-
- List<String> zipalign_args;
- zipalign_args.push_back("-f");
- zipalign_args.push_back("-v");
- zipalign_args.push_back("4");
- zipalign_args.push_back(unaligned_file_path); // source file
- zipalign_args.push_back(aligned_file_path); // destination file
-
- int result = EditorNode::get_singleton()->execute_and_show_output(TTR("Aligning APK..."), zipalign_command, zipalign_args);
- if (result != 0) {
- EditorNode::get_singleton()->show_warning(TTR("Unable to complete APK alignment."));
- return ERR_CANT_CREATE;
- }
-
- // Delete the unaligned path.
- errn = da->remove(unaligned_file_path);
- if (errn != OK) {
- EditorNode::get_singleton()->show_warning(TTR("Unable to delete unaligned APK."));
- }
- return OK;
- }
-
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) override {
ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
@@ -2445,6 +2377,8 @@ public:
String version_code = itos(p_preset->get("version/code"));
String version_name = p_preset->get("version/name");
String enabled_abi_string = String("|").join(enabled_abis);
+ String sign_flag = _signed ? "true" : "false";
+ String zipalign_flag = "true";
Vector<PluginConfig> enabled_plugins = get_enabled_plugins(p_preset);
String local_plugins_binaries = get_plugins_binaries(BINARY_TYPE_LOCAL, enabled_plugins);
@@ -2473,15 +2407,25 @@ public:
cmdline.push_back("-Pplugins_local_binaries=" + local_plugins_binaries); // argument to specify the list of plugins local dependencies.
cmdline.push_back("-Pplugins_remote_binaries=" + remote_plugins_binaries); // argument to specify the list of plugins remote dependencies.
cmdline.push_back("-Pplugins_maven_repos=" + custom_maven_repos); // argument to specify the list of custom maven repos for the plugins dependencies.
+ cmdline.push_back("-Pperform_zipalign=" + zipalign_flag); // argument to specify whether the build should be zipaligned.
+ cmdline.push_back("-Pperform_signing=" + sign_flag); // argument to specify whether the build should be signed.
+ if (_signed && !p_debug) {
+ // Pass the release keystore info as well
+ String release_keystore = p_preset->get("keystore/release");
+ String release_username = p_preset->get("keystore/release_user");
+ String release_password = p_preset->get("keystore/release_password");
+ if (!FileAccess::exists(release_keystore)) {
+ EditorNode::add_io_error("Could not find keystore, unable to export.");
+ return ERR_FILE_CANT_OPEN;
+ }
+
+ cmdline.push_back("-Prelease_keystore_file=" + release_keystore); // argument to specify the release keystore file.
+ cmdline.push_back("-Prelease_keystore_alias=" + release_username); // argument to specify the release keystore alias.
+ cmdline.push_back("-Prelease_keystore_password=" + release_password); // argument to specity the release keystore password.
+ }
cmdline.push_back("-p"); // argument to specify the start directory.
cmdline.push_back(build_path); // start directory.
- /*{ used for debug
- int ec;
- String pipe;
- OS::get_singleton()->execute(build_command, cmdline, true, nullptr, nullptr, &ec);
- print_line("exit code: " + itos(ec));
- }
- */
+
int result = EditorNode::get_singleton()->execute_and_show_output(TTR("Building Android Project (gradle)"), build_command, cmdline);
if (result != 0) {
EditorNode::get_singleton()->show_warning(TTR("Building of Android project failed, check output for the error.\nAlternatively visit docs.godotengine.org for Android build documentation."));
@@ -2502,16 +2446,11 @@ public:
copy_args.push_back(build_path); // start directory.
String export_filename = p_path.get_file();
- if (export_format == 0) {
- // By default, generated apk are not aligned.
- export_filename += ".unaligned";
- }
String export_path = p_path.get_base_dir();
if (export_path.is_rel_path()) {
export_path = OS::get_singleton()->get_resource_dir().plus_file(export_path);
}
export_path = ProjectSettings::get_singleton()->globalize_path(export_path).simplify_path();
- String export_file_path = export_path.plus_file(export_filename);
copy_args.push_back("-Pexport_path=file:" + export_path);
copy_args.push_back("-Pexport_filename=" + export_filename);
@@ -2521,20 +2460,6 @@ public:
EditorNode::get_singleton()->show_warning(TTR("Unable to copy and rename export file, check gradle project directory for outputs."));
return ERR_CANT_CREATE;
}
- if (_signed) {
- err = sign_apk(p_preset, p_debug, export_file_path, ep);
- if (err != OK) {
- return err;
- }
- }
-
- if (export_format == 0) {
- // Perform zip alignment
- err = _zip_align_project(sdk_path, export_file_path, export_path.plus_file(p_path.get_file()));
- if (err != OK) {
- return err;
- }
- }
return OK;
}
diff --git a/platform/android/export/gradle_export_util.h b/platform/android/export/gradle_export_util.h
index 3bc3651712..a9f38869e0 100644
--- a/platform/android/export/gradle_export_util.h
+++ b/platform/android/export/gradle_export_util.h
@@ -291,7 +291,7 @@ String _get_application_tag(const Ref<EditorExportPreset> &p_preset, const Strin
String manifest_application_text =
" <application android:label=\"@string/godot_project_name_string\"\n"
" android:allowBackup=\"false\" tools:ignore=\"GoogleAppIndexingWarning\"\n"
- " android:icon=\"@mipmap/icon\">)\n\n"
+ " android:icon=\"@mipmap/icon\">\n\n"
" <meta-data tools:node=\"remove\" android:name=\"xr_mode_metadata_name\" />\n";
manifest_application_text += _get_plugins_tag(plugins_names);
diff --git a/platform/android/java/app/build.gradle b/platform/android/java/app/build.gradle
index 6de1d2dd30..53d11fda5b 100644
--- a/platform/android/java/app/build.gradle
+++ b/platform/android/java/app/build.gradle
@@ -106,10 +106,41 @@ android {
// doNotStrip '**/*.so'
}
- // Both signing and zip-aligning will be done at export time
- buildTypes.all { buildType ->
- buildType.zipAlignEnabled false
- buildType.signingConfig null
+ signingConfigs {
+ release {
+ File keystoreFile = new File(getReleaseKeystoreFile())
+ if (keystoreFile.isFile()) {
+ storeFile keystoreFile
+ storePassword getReleaseKeystorePassword()
+ keyAlias getReleaseKeyAlias()
+ keyPassword getReleaseKeystorePassword()
+ }
+ }
+ }
+
+ buildTypes {
+
+ debug {
+ // Signing and zip-aligning are skipped for prebuilt builds, but
+ // performed for custom builds.
+ zipAlignEnabled shouldZipAlign()
+ if (shouldSign()) {
+ signingConfig signingConfigs.debug
+ } else {
+ signingConfig null
+ }
+ }
+
+ release {
+ // Signing and zip-aligning are skipped for prebuilt builds, but
+ // performed for custom builds.
+ zipAlignEnabled shouldZipAlign()
+ if (shouldSign()) {
+ signingConfig signingConfigs.release
+ } else {
+ signingConfig null
+ }
+ }
}
sourceSets {
diff --git a/platform/android/java/app/config.gradle b/platform/android/java/app/config.gradle
index e6c45b73a7..80cf6f7ede 100644
--- a/platform/android/java/app/config.gradle
+++ b/platform/android/java/app/config.gradle
@@ -34,7 +34,11 @@ ext.getExportVersionCode = { ->
if (versionCode == null || versionCode.isEmpty()) {
versionCode = "1"
}
- return Integer.parseInt(versionCode)
+ try {
+ return Integer.parseInt(versionCode)
+ } catch (NumberFormatException ignored) {
+ return 1
+ }
}
ext.getExportVersionName = { ->
@@ -136,3 +140,37 @@ ext.getGodotPluginsLocalBinaries = { ->
return binDeps
}
+
+ext.getReleaseKeystoreFile = { ->
+ String keystoreFile = project.hasProperty("release_keystore_file") ? project.property("release_keystore_file") : ""
+ if (keystoreFile == null || keystoreFile.isEmpty()) {
+ keystoreFile = "."
+ }
+ return keystoreFile
+}
+
+ext.getReleaseKeystorePassword = { ->
+ String keystorePassword = project.hasProperty("release_keystore_password") ? project.property("release_keystore_password") : ""
+ return keystorePassword
+}
+
+ext.getReleaseKeyAlias = { ->
+ String keyAlias = project.hasProperty("release_keystore_alias") ? project.property("release_keystore_alias") : ""
+ return keyAlias
+}
+
+ext.shouldZipAlign = { ->
+ String zipAlignFlag = project.hasProperty("perform_zipalign") ? project.property("perform_zipalign") : ""
+ if (zipAlignFlag == null || zipAlignFlag.isEmpty()) {
+ zipAlignFlag = "false"
+ }
+ return Boolean.parseBoolean(zipAlignFlag)
+}
+
+ext.shouldSign = { ->
+ String signFlag = project.hasProperty("perform_signing") ? project.property("perform_signing") : ""
+ if (signFlag == null || signFlag.isEmpty()) {
+ signFlag = "false"
+ }
+ return Boolean.parseBoolean(signFlag)
+}
diff --git a/platform/iphone/native_video_view.m b/platform/iphone/native_video_view.m
index a4e9f209f0..1193946f2b 100644
--- a/platform/iphone/native_video_view.m
+++ b/platform/iphone/native_video_view.m
@@ -71,6 +71,12 @@
[self observeVideoAudio];
}
+- (void)layoutSubviews {
+ [super layoutSubviews];
+
+ self.avPlayerLayer.frame = self.bounds;
+}
+
- (void)observeVideoAudio {
printf("******** adding observer for sound routing changes\n");
[[NSNotificationCenter defaultCenter]
diff --git a/platform/iphone/view_controller.mm b/platform/iphone/view_controller.mm
index d3969e6b02..7e44d30851 100644
--- a/platform/iphone/view_controller.mm
+++ b/platform/iphone/view_controller.mm
@@ -218,8 +218,11 @@
} else {
// Create autoresizing view for video playback.
GodotNativeVideoView *videoView = [[GodotNativeVideoView alloc] initWithFrame:self.view.bounds];
- videoView.autoresizingMask = UIViewAutoresizingFlexibleWidth & UIViewAutoresizingFlexibleHeight;
+ videoView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:videoView];
+
+ self.videoView = videoView;
+
return [self.videoView playVideoAtPath:filePath volume:videoVolume audio:audioTrack subtitle:subtitleTrack];
}
}
diff --git a/platform/javascript/.eslintrc.engine.js b/platform/javascript/.eslintrc.engine.js
new file mode 100644
index 0000000000..00f0f147a9
--- /dev/null
+++ b/platform/javascript/.eslintrc.engine.js
@@ -0,0 +1,10 @@
+module.exports = {
+ "extends": [
+ "./.eslintrc.js",
+ ],
+ "globals": {
+ "Godot": true,
+ "Preloader": true,
+ "Utils": true,
+ },
+};
diff --git a/platform/javascript/.eslintrc.js b/platform/javascript/.eslintrc.js
new file mode 100644
index 0000000000..0ff9d67d26
--- /dev/null
+++ b/platform/javascript/.eslintrc.js
@@ -0,0 +1,43 @@
+module.exports = {
+ "env": {
+ "browser": true,
+ "es2021": true,
+ },
+ "extends": [
+ "airbnb-base",
+ ],
+ "parserOptions": {
+ "ecmaVersion": 12,
+ },
+ "ignorePatterns": "*.externs.js",
+ "rules": {
+ "func-names": "off",
+ // Use tabs for consistency with the C++ codebase.
+ "indent": ["error", "tab"],
+ "max-len": "off",
+ "no-else-return": ["error", {allowElseIf: true}],
+ "curly": ["error", "all"],
+ "brace-style": ["error", "1tbs", { "allowSingleLine": false }],
+ "no-bitwise": "off",
+ "no-continue": "off",
+ "no-self-assign": "off",
+ "no-tabs": "off",
+ "no-param-reassign": ["error", { "props": false }],
+ "no-plusplus": "off",
+ "no-unused-vars": ["error", { "args": "none" }],
+ "prefer-destructuring": "off",
+ "prefer-rest-params": "off",
+ "prefer-spread": "off",
+ "camelcase": "off",
+ "no-underscore-dangle": "off",
+ "max-classes-per-file": "off",
+ "prefer-arrow-callback": "off",
+ // Messes up with copyright headers in source files.
+ "spaced-comment": "off",
+ // Completely breaks emscripten libraries.
+ "object-shorthand": "off",
+ // Closure compiler (exported properties)
+ "quote-props": ["error", "consistent"],
+ "dot-notation": "off",
+ }
+};
diff --git a/platform/javascript/.eslintrc.libs.js b/platform/javascript/.eslintrc.libs.js
new file mode 100644
index 0000000000..e5f0c3d147
--- /dev/null
+++ b/platform/javascript/.eslintrc.libs.js
@@ -0,0 +1,22 @@
+module.exports = {
+ "extends": [
+ "./.eslintrc.js",
+ ],
+ "globals": {
+ "LibraryManager": true,
+ "mergeInto": true,
+ "autoAddDeps": true,
+ "HEAP8": true,
+ "HEAPU8": true,
+ "HEAP32": true,
+ "HEAPF32": true,
+ "ERRNO_CODES": true,
+ "FS": true,
+ "IDBFS": true,
+ "GodotOS": true,
+ "GodotConfig": true,
+ "GodotRuntime": true,
+ "GodotFS": true,
+ "IDHandler": true,
+ },
+};
diff --git a/platform/javascript/SCsub b/platform/javascript/SCsub
index a0e6fa0e18..627ae778b1 100644
--- a/platform/javascript/SCsub
+++ b/platform/javascript/SCsub
@@ -20,27 +20,28 @@ build = env.add_program(build_targets, javascript_files)
env.AddJSLibraries(
[
- "native/http_request.js",
- "native/library_godot_audio.js",
- "native/library_godot_display.js",
- "native/library_godot_os.js",
+ "js/libs/library_godot_audio.js",
+ "js/libs/library_godot_display.js",
+ "js/libs/library_godot_http_request.js",
+ "js/libs/library_godot_os.js",
+ "js/libs/library_godot_runtime.js",
]
)
if env["tools"]:
- env.AddJSLibraries(["native/library_godot_editor_tools.js"])
+ env.AddJSLibraries(["js/libs/library_godot_editor_tools.js"])
if env["javascript_eval"]:
- env.AddJSLibraries(["native/library_godot_eval.js"])
+ env.AddJSLibraries(["js/libs/library_godot_eval.js"])
for lib in env["JS_LIBS"]:
env.Append(LINKFLAGS=["--js-library", lib])
env.Depends(build, env["JS_LIBS"])
engine = [
- "engine/preloader.js",
- "engine/utils.js",
- "engine/engine.js",
+ "js/engine/preloader.js",
+ "js/engine/utils.js",
+ "js/engine/engine.js",
]
-externs = [env.File("#platform/javascript/engine/externs.js")]
+externs = [env.File("#platform/javascript/js/engine/engine.externs.js")]
js_engine = env.CreateEngineFile("#bin/godot${PROGSUFFIX}.engine.js", engine, externs)
env.Depends(js_engine, externs)
@@ -59,7 +60,7 @@ out_files = [
zip_dir.File(binary_name + ".audio.worklet.js"),
]
html_file = "#misc/dist/html/editor.html" if env["tools"] else "#misc/dist/html/full-size.html"
-in_files = [js_wrapped, build[1], html_file, "#platform/javascript/native/audio.worklet.js"]
+in_files = [js_wrapped, build[1], html_file, "#platform/javascript/js/libs/audio.worklet.js"]
if env["threads_enabled"]:
in_files.append(build[2])
out_files.append(zip_dir.File(binary_name + ".worker.js"))
diff --git a/platform/javascript/engine/preloader.js b/platform/javascript/engine/preloader.js
deleted file mode 100644
index b3467d009f..0000000000
--- a/platform/javascript/engine/preloader.js
+++ /dev/null
@@ -1,135 +0,0 @@
-var Preloader = /** @constructor */ function() {
- var DOWNLOAD_ATTEMPTS_MAX = 4;
- var progressFunc = null;
- var lastProgress = { loaded: 0, total: 0 };
-
- var loadingFiles = {};
- this.preloadedFiles = [];
-
- function loadXHR(resolve, reject, file, tracker) {
- var xhr = new XMLHttpRequest;
- xhr.open('GET', file);
- if (!file.endsWith('.js')) {
- xhr.responseType = 'arraybuffer';
- }
- ['loadstart', 'progress', 'load', 'error', 'abort'].forEach(function(ev) {
- xhr.addEventListener(ev, onXHREvent.bind(xhr, resolve, reject, file, tracker));
- });
- xhr.send();
- }
-
- function onXHREvent(resolve, reject, file, tracker, ev) {
- if (this.status >= 400) {
- if (this.status < 500 || ++tracker[file].attempts >= DOWNLOAD_ATTEMPTS_MAX) {
- reject(new Error("Failed loading file '" + file + "': " + this.statusText));
- this.abort();
- return;
- } else {
- setTimeout(loadXHR.bind(null, resolve, reject, file, tracker), 1000);
- }
- }
-
- switch (ev.type) {
- case 'loadstart':
- if (tracker[file] === undefined) {
- tracker[file] = {
- total: ev.total,
- loaded: ev.loaded,
- attempts: 0,
- final: false,
- };
- }
- break;
-
- case 'progress':
- tracker[file].loaded = ev.loaded;
- tracker[file].total = ev.total;
- break;
-
- case 'load':
- tracker[file].final = true;
- resolve(this);
- break;
-
- case 'error':
- if (++tracker[file].attempts >= DOWNLOAD_ATTEMPTS_MAX) {
- tracker[file].final = true;
- reject(new Error("Failed loading file '" + file + "'"));
- } else {
- setTimeout(loadXHR.bind(null, resolve, reject, file, tracker), 1000);
- }
- break;
-
- case 'abort':
- tracker[file].final = true;
- reject(new Error("Loading file '" + file + "' was aborted."));
- break;
- }
- }
-
- this.loadPromise = function(file) {
- return new Promise(function(resolve, reject) {
- loadXHR(resolve, reject, file, loadingFiles);
- });
- }
-
- this.preload = function(pathOrBuffer, destPath) {
- if (pathOrBuffer instanceof ArrayBuffer) {
- pathOrBuffer = new Uint8Array(pathOrBuffer);
- } else if (ArrayBuffer.isView(pathOrBuffer)) {
- pathOrBuffer = new Uint8Array(pathOrBuffer.buffer);
- }
- if (pathOrBuffer instanceof Uint8Array) {
- this.preloadedFiles.push({
- path: destPath,
- buffer: pathOrBuffer
- });
- return Promise.resolve();
- } else if (typeof pathOrBuffer === 'string') {
- var me = this;
- return this.loadPromise(pathOrBuffer).then(function(xhr) {
- me.preloadedFiles.push({
- path: destPath || pathOrBuffer,
- buffer: xhr.response
- });
- return Promise.resolve();
- });
- } else {
- throw Promise.reject("Invalid object for preloading");
- }
- };
-
- var animateProgress = function() {
- var loaded = 0;
- var total = 0;
- var totalIsValid = true;
- var progressIsFinal = true;
-
- Object.keys(loadingFiles).forEach(function(file) {
- const stat = loadingFiles[file];
- if (!stat.final) {
- progressIsFinal = false;
- }
- if (!totalIsValid || stat.total === 0) {
- totalIsValid = false;
- total = 0;
- } else {
- total += stat.total;
- }
- loaded += stat.loaded;
- });
- if (loaded !== lastProgress.loaded || total !== lastProgress.total) {
- lastProgress.loaded = loaded;
- lastProgress.total = total;
- if (typeof progressFunc === 'function')
- progressFunc(loaded, total);
- }
- if (!progressIsFinal)
- requestAnimationFrame(animateProgress);
- }
- this.animateProgress = animateProgress; // Also exposed to start it.
-
- this.setProgressFunc = function(callback) {
- progressFunc = callback;
- }
-};
diff --git a/platform/javascript/engine/externs.js b/platform/javascript/js/engine/engine.externs.js
index 1a94dd15ec..1a94dd15ec 100644
--- a/platform/javascript/engine/externs.js
+++ b/platform/javascript/js/engine/engine.externs.js
diff --git a/platform/javascript/engine/engine.js b/platform/javascript/js/engine/engine.js
index 3745e04479..74153b672a 100644
--- a/platform/javascript/engine/engine.js
+++ b/platform/javascript/js/engine/engine.js
@@ -1,14 +1,14 @@
-Function('return this')()['Engine'] = (function() {
- var preloader = new Preloader();
+const Engine = (function () {
+ const preloader = new Preloader();
- var wasmExt = '.wasm';
- var unloadAfterInit = true;
- var loadPath = '';
- var loadPromise = null;
- var initPromise = null;
- var stderr = null;
- var stdout = null;
- var progressFunc = null;
+ let wasmExt = '.wasm';
+ let unloadAfterInit = true;
+ let loadPath = '';
+ let loadPromise = null;
+ let initPromise = null;
+ let stderr = null;
+ let stdout = null;
+ let progressFunc = null;
function load(basePath) {
if (loadPromise == null) {
@@ -18,14 +18,14 @@ Function('return this')()['Engine'] = (function() {
requestAnimationFrame(preloader.animateProgress);
}
return loadPromise;
- };
+ }
function unload() {
loadPromise = null;
- };
+ }
/** @constructor */
- function Engine() {
+ function Engine() { // eslint-disable-line no-shadow
this.canvas = null;
this.executableName = '';
this.rtenv = null;
@@ -34,30 +34,32 @@ Function('return this')()['Engine'] = (function() {
this.onExecute = null;
this.onExit = null;
this.persistentPaths = ['/userfs'];
- };
+ }
- Engine.prototype.init = /** @param {string=} basePath */ function(basePath) {
+ Engine.prototype.init = /** @param {string=} basePath */ function (basePath) {
if (initPromise) {
return initPromise;
}
if (loadPromise == null) {
if (!basePath) {
- initPromise = Promise.reject(new Error("A base path must be provided when calling `init` and the engine is not loaded."));
+ initPromise = Promise.reject(new Error('A base path must be provided when calling `init` and the engine is not loaded.'));
return initPromise;
}
load(basePath);
}
- var config = {};
- if (typeof stdout === 'function')
+ let config = {};
+ if (typeof stdout === 'function') {
config.print = stdout;
- if (typeof stderr === 'function')
+ }
+ if (typeof stderr === 'function') {
config.printErr = stderr;
- var me = this;
- initPromise = new Promise(function(resolve, reject) {
+ }
+ const me = this;
+ initPromise = new Promise(function (resolve, reject) {
config['locateFile'] = Utils.createLocateRewrite(loadPath);
config['instantiateWasm'] = Utils.createInstantiatePromise(loadPromise);
- Godot(config).then(function(module) {
- module['initFS'](me.persistentPaths).then(function(fs_err) {
+ Godot(config).then(function (module) {
+ module['initFS'](me.persistentPaths).then(function (fs_err) {
me.rtenv = module;
if (unloadAfterInit) {
unload();
@@ -71,25 +73,28 @@ Function('return this')()['Engine'] = (function() {
};
/** @type {function(string, string):Object} */
- Engine.prototype.preloadFile = function(file, path) {
+ Engine.prototype.preloadFile = function (file, path) {
return preloader.preload(file, path);
};
/** @type {function(...string):Object} */
- Engine.prototype.start = function() {
+ Engine.prototype.start = function () {
// Start from arguments.
- var args = [];
- for (var i = 0; i < arguments.length; i++) {
+ const args = [];
+ for (let i = 0; i < arguments.length; i++) {
args.push(arguments[i]);
}
- var me = this;
- return me.init().then(function() {
+ const me = this;
+ return me.init().then(function () {
if (!me.rtenv) {
return Promise.reject(new Error('The engine must be initialized before it can be started'));
}
if (!(me.canvas instanceof HTMLCanvasElement)) {
me.canvas = Utils.findCanvas();
+ if (!me.canvas) {
+ return Promise.reject(new Error('No canvas found in page'));
+ }
}
// Canvas can grab focus on click, or key events won't work.
@@ -98,18 +103,18 @@ Function('return this')()['Engine'] = (function() {
}
// Disable right-click context menu.
- me.canvas.addEventListener('contextmenu', function(ev) {
+ me.canvas.addEventListener('contextmenu', function (ev) {
ev.preventDefault();
}, false);
// Until context restoration is implemented warn the user of context loss.
- me.canvas.addEventListener('webglcontextlost', function(ev) {
- alert("WebGL context lost, please reload the page");
+ me.canvas.addEventListener('webglcontextlost', function (ev) {
+ alert('WebGL context lost, please reload the page'); // eslint-disable-line no-alert
ev.preventDefault();
}, false);
// Browser locale, or custom one if defined.
- var locale = me.customLocale;
+ let locale = me.customLocale;
if (!locale) {
locale = navigator.languages ? navigator.languages[0] : navigator.language;
locale = locale.split('.')[0];
@@ -122,14 +127,14 @@ Function('return this')()['Engine'] = (function() {
'resizeCanvasOnStart': me.resizeCanvasOnStart,
'canvas': me.canvas,
'locale': locale,
- 'onExecute': function(p_args) {
+ 'onExecute': function (p_args) {
if (me.onExecute) {
me.onExecute(p_args);
return 0;
}
return 1;
},
- 'onExit': function(p_code) {
+ 'onExit': function (p_code) {
me.rtenv['deinitFS']();
if (me.onExit) {
me.onExit(p_code);
@@ -138,8 +143,8 @@ Function('return this')()['Engine'] = (function() {
},
});
- return new Promise(function(resolve, reject) {
- preloader.preloadedFiles.forEach(function(file) {
+ return new Promise(function (resolve, reject) {
+ preloader.preloadedFiles.forEach(function (file) {
me.rtenv['copyToFS'](file.path, file.buffer);
});
preloader.preloadedFiles.length = 0; // Clear memory
@@ -150,95 +155,101 @@ Function('return this')()['Engine'] = (function() {
});
};
- Engine.prototype.startGame = function(execName, mainPack, extraArgs) {
+ Engine.prototype.startGame = function (execName, mainPack, extraArgs) {
// Start and init with execName as loadPath if not inited.
this.executableName = execName;
- var me = this;
+ const me = this;
return Promise.all([
this.init(execName),
- this.preloadFile(mainPack, mainPack)
- ]).then(function() {
- var args = ['--main-pack', mainPack];
- if (extraArgs)
+ this.preloadFile(mainPack, mainPack),
+ ]).then(function () {
+ let args = ['--main-pack', mainPack];
+ if (extraArgs) {
args = args.concat(extraArgs);
+ }
return me.start.apply(me, args);
});
};
- Engine.prototype.setWebAssemblyFilenameExtension = function(override) {
+ Engine.prototype.setWebAssemblyFilenameExtension = function (override) {
if (String(override).length === 0) {
throw new Error('Invalid WebAssembly filename extension override');
}
wasmExt = String(override);
};
- Engine.prototype.setUnloadAfterInit = function(enabled) {
+ Engine.prototype.setUnloadAfterInit = function (enabled) {
unloadAfterInit = enabled;
};
- Engine.prototype.setCanvas = function(canvasElem) {
+ Engine.prototype.setCanvas = function (canvasElem) {
this.canvas = canvasElem;
};
- Engine.prototype.setCanvasResizedOnStart = function(enabled) {
+ Engine.prototype.setCanvasResizedOnStart = function (enabled) {
this.resizeCanvasOnStart = enabled;
};
- Engine.prototype.setLocale = function(locale) {
+ Engine.prototype.setLocale = function (locale) {
this.customLocale = locale;
};
- Engine.prototype.setExecutableName = function(newName) {
+ Engine.prototype.setExecutableName = function (newName) {
this.executableName = newName;
};
- Engine.prototype.setProgressFunc = function(func) {
+ Engine.prototype.setProgressFunc = function (func) {
progressFunc = func;
};
- Engine.prototype.setStdoutFunc = function(func) {
- var print = function(text) {
+ Engine.prototype.setStdoutFunc = function (func) {
+ const print = function (text) {
+ let msg = text;
if (arguments.length > 1) {
- text = Array.prototype.slice.call(arguments).join(" ");
+ msg = Array.prototype.slice.call(arguments).join(' ');
}
- func(text);
+ func(msg);
};
- if (this.rtenv)
+ if (this.rtenv) {
this.rtenv.print = print;
+ }
stdout = print;
};
- Engine.prototype.setStderrFunc = function(func) {
- var printErr = function(text) {
- if (arguments.length > 1)
- text = Array.prototype.slice.call(arguments).join(" ");
- func(text);
+ Engine.prototype.setStderrFunc = function (func) {
+ const printErr = function (text) {
+ let msg = text;
+ if (arguments.length > 1) {
+ msg = Array.prototype.slice.call(arguments).join(' ');
+ }
+ func(msg);
};
- if (this.rtenv)
+ if (this.rtenv) {
this.rtenv.printErr = printErr;
+ }
stderr = printErr;
};
- Engine.prototype.setOnExecute = function(onExecute) {
+ Engine.prototype.setOnExecute = function (onExecute) {
this.onExecute = onExecute;
};
- Engine.prototype.setOnExit = function(onExit) {
+ Engine.prototype.setOnExit = function (onExit) {
this.onExit = onExit;
};
- Engine.prototype.copyToFS = function(path, buffer) {
+ Engine.prototype.copyToFS = function (path, buffer) {
if (this.rtenv == null) {
- throw new Error("Engine must be inited before copying files");
+ throw new Error('Engine must be inited before copying files');
}
this.rtenv['copyToFS'](path, buffer);
};
- Engine.prototype.setPersistentPaths = function(persistentPaths) {
+ Engine.prototype.setPersistentPaths = function (persistentPaths) {
this.persistentPaths = persistentPaths;
};
- Engine.prototype.requestQuit = function() {
+ Engine.prototype.requestQuit = function () {
if (this.rtenv) {
this.rtenv['request_quit']();
}
@@ -268,4 +279,7 @@ Function('return this')()['Engine'] = (function() {
Engine.prototype['setPersistentPaths'] = Engine.prototype.setPersistentPaths;
Engine.prototype['requestQuit'] = Engine.prototype.requestQuit;
return Engine;
-})();
+}());
+if (typeof window !== 'undefined') {
+ window['Engine'] = Engine;
+}
diff --git a/platform/javascript/js/engine/preloader.js b/platform/javascript/js/engine/preloader.js
new file mode 100644
index 0000000000..ec34fb93f2
--- /dev/null
+++ b/platform/javascript/js/engine/preloader.js
@@ -0,0 +1,127 @@
+const Preloader = /** @constructor */ function () { // eslint-disable-line no-unused-vars
+ const loadXHR = function (resolve, reject, file, tracker, attempts) {
+ const xhr = new XMLHttpRequest();
+ tracker[file] = {
+ total: 0,
+ loaded: 0,
+ final: false,
+ };
+ xhr.onerror = function () {
+ if (attempts <= 1) {
+ reject(new Error(`Failed loading file '${file}'`));
+ } else {
+ setTimeout(function () {
+ loadXHR(resolve, reject, file, tracker, attempts - 1);
+ }, 1000);
+ }
+ };
+ xhr.onabort = function () {
+ tracker[file].final = true;
+ reject(new Error(`Loading file '${file}' was aborted.`));
+ };
+ xhr.onloadstart = function (ev) {
+ tracker[file].total = ev.total;
+ tracker[file].loaded = ev.loaded;
+ };
+ xhr.onprogress = function (ev) {
+ tracker[file].loaded = ev.loaded;
+ tracker[file].total = ev.total;
+ };
+ xhr.onload = function () {
+ if (xhr.status >= 400) {
+ if (xhr.status < 500 || attempts <= 1) {
+ reject(new Error(`Failed loading file '${file}': ${xhr.statusText}`));
+ xhr.abort();
+ } else {
+ setTimeout(function () {
+ loadXHR(resolve, reject, file, tracker, attempts - 1);
+ }, 1000);
+ }
+ } else {
+ tracker[file].final = true;
+ resolve(xhr);
+ }
+ };
+ // Make request.
+ xhr.open('GET', file);
+ if (!file.endsWith('.js')) {
+ xhr.responseType = 'arraybuffer';
+ }
+ xhr.send();
+ };
+
+ const DOWNLOAD_ATTEMPTS_MAX = 4;
+ const loadingFiles = {};
+ const lastProgress = { loaded: 0, total: 0 };
+ let progressFunc = null;
+
+ const animateProgress = function () {
+ let loaded = 0;
+ let total = 0;
+ let totalIsValid = true;
+ let progressIsFinal = true;
+
+ Object.keys(loadingFiles).forEach(function (file) {
+ const stat = loadingFiles[file];
+ if (!stat.final) {
+ progressIsFinal = false;
+ }
+ if (!totalIsValid || stat.total === 0) {
+ totalIsValid = false;
+ total = 0;
+ } else {
+ total += stat.total;
+ }
+ loaded += stat.loaded;
+ });
+ if (loaded !== lastProgress.loaded || total !== lastProgress.total) {
+ lastProgress.loaded = loaded;
+ lastProgress.total = total;
+ if (typeof progressFunc === 'function') {
+ progressFunc(loaded, total);
+ }
+ }
+ if (!progressIsFinal) {
+ requestAnimationFrame(animateProgress);
+ }
+ };
+
+ this.animateProgress = animateProgress;
+
+ this.setProgressFunc = function (callback) {
+ progressFunc = callback;
+ };
+
+ this.loadPromise = function (file) {
+ return new Promise(function (resolve, reject) {
+ loadXHR(resolve, reject, file, loadingFiles, DOWNLOAD_ATTEMPTS_MAX);
+ });
+ };
+
+ this.preloadedFiles = [];
+ this.preload = function (pathOrBuffer, destPath) {
+ let buffer = null;
+ if (typeof pathOrBuffer === 'string') {
+ const me = this;
+ return this.loadPromise(pathOrBuffer).then(function (xhr) {
+ me.preloadedFiles.push({
+ path: destPath || pathOrBuffer,
+ buffer: xhr.response,
+ });
+ return Promise.resolve();
+ });
+ } else if (pathOrBuffer instanceof ArrayBuffer) {
+ buffer = new Uint8Array(pathOrBuffer);
+ } else if (ArrayBuffer.isView(pathOrBuffer)) {
+ buffer = new Uint8Array(pathOrBuffer.buffer);
+ }
+ if (buffer) {
+ this.preloadedFiles.push({
+ path: destPath,
+ buffer: pathOrBuffer,
+ });
+ return Promise.resolve();
+ }
+ return Promise.reject(new Error('Invalid object for preloading'));
+ };
+};
diff --git a/platform/javascript/engine/utils.js b/platform/javascript/js/engine/utils.js
index 8455739a25..d0fca4e1cb 100644
--- a/platform/javascript/engine/utils.js
+++ b/platform/javascript/js/engine/utils.js
@@ -1,51 +1,56 @@
-var Utils = {
- createLocateRewrite: function(execName) {
+const Utils = { // eslint-disable-line no-unused-vars
+
+ createLocateRewrite: function (execName) {
function rw(path) {
if (path.endsWith('.worker.js')) {
- return execName + '.worker.js';
+ return `${execName}.worker.js`;
} else if (path.endsWith('.audio.worklet.js')) {
- return execName + '.audio.worklet.js';
+ return `${execName}.audio.worklet.js`;
} else if (path.endsWith('.js')) {
- return execName + '.js';
+ return `${execName}.js`;
} else if (path.endsWith('.wasm')) {
- return execName + '.wasm';
+ return `${execName}.wasm`;
}
+ return path;
}
return rw;
},
- createInstantiatePromise: function(wasmLoader) {
+ createInstantiatePromise: function (wasmLoader) {
+ let loader = wasmLoader;
function instantiateWasm(imports, onSuccess) {
- wasmLoader.then(function(xhr) {
- WebAssembly.instantiate(xhr.response, imports).then(function(result) {
+ loader.then(function (xhr) {
+ WebAssembly.instantiate(xhr.response, imports).then(function (result) {
onSuccess(result['instance'], result['module']);
});
});
- wasmLoader = null;
+ loader = null;
return {};
- };
+ }
return instantiateWasm;
},
- findCanvas: function() {
- var nodes = document.getElementsByTagName('canvas');
+ findCanvas: function () {
+ const nodes = document.getElementsByTagName('canvas');
if (nodes.length && nodes[0] instanceof HTMLCanvasElement) {
return nodes[0];
}
- throw new Error("No canvas found");
+ return null;
},
- isWebGLAvailable: function(majorVersion = 1) {
- var testContext = false;
+ isWebGLAvailable: function (majorVersion = 1) {
+ let testContext = false;
try {
- var testCanvas = document.createElement('canvas');
+ const testCanvas = document.createElement('canvas');
if (majorVersion === 1) {
testContext = testCanvas.getContext('webgl') || testCanvas.getContext('experimental-webgl');
} else if (majorVersion === 2) {
testContext = testCanvas.getContext('webgl2') || testCanvas.getContext('experimental-webgl2');
}
- } catch (e) {}
+ } catch (e) {
+ // Not available
+ }
return !!testContext;
- }
+ },
};
diff --git a/platform/javascript/native/audio.worklet.js b/platform/javascript/js/libs/audio.worklet.js
index f91787b993..414dc37097 100644
--- a/platform/javascript/native/audio.worklet.js
+++ b/platform/javascript/js/libs/audio.worklet.js
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
class RingBuffer {
constructor(p_buffer, p_state) {
this.buffer = p_buffer;
@@ -104,7 +105,7 @@ class GodotProcessor extends AudioWorkletProcessor {
}
parse_message(p_cmd, p_data) {
- if (p_cmd == "start" && p_data) {
+ if (p_cmd === 'start' && p_data) {
const state = p_data[0];
let idx = 0;
this.lock = state.subarray(idx, ++idx);
@@ -113,14 +114,14 @@ class GodotProcessor extends AudioWorkletProcessor {
const avail_out = state.subarray(idx, ++idx);
this.input = new RingBuffer(p_data[1], avail_in);
this.output = new RingBuffer(p_data[2], avail_out);
- } else if (p_cmd == "stop") {
+ } else if (p_cmd === 'stop') {
this.runing = false;
this.output = null;
this.input = null;
}
}
- array_has_data(arr) {
+ static array_has_data(arr) {
return arr.length && arr[0].length && arr[0][0].length;
}
@@ -131,39 +132,39 @@ class GodotProcessor extends AudioWorkletProcessor {
if (this.output === null) {
return true; // Not ready yet, keep processing.
}
- const process_input = this.array_has_data(inputs);
+ const process_input = GodotProcessor.array_has_data(inputs);
if (process_input) {
const input = inputs[0];
const chunk = input[0].length * input.length;
- if (this.input_buffer.length != chunk) {
+ if (this.input_buffer.length !== chunk) {
this.input_buffer = new Float32Array(chunk);
}
if (this.input.space_left() >= chunk) {
- this.write_input(this.input_buffer, input);
+ GodotProcessor.write_input(this.input_buffer, input);
this.input.write(this.input_buffer);
} else {
- this.port.postMessage("Input buffer is full! Skipping input frame.");
+ this.port.postMessage('Input buffer is full! Skipping input frame.');
}
}
- const process_output = this.array_has_data(outputs);
+ const process_output = GodotProcessor.array_has_data(outputs);
if (process_output) {
const output = outputs[0];
const chunk = output[0].length * output.length;
- if (this.output_buffer.length != chunk) {
+ if (this.output_buffer.length !== chunk) {
this.output_buffer = new Float32Array(chunk);
}
if (this.output.data_left() >= chunk) {
this.output.read(this.output_buffer);
- this.write_output(output, this.output_buffer);
+ GodotProcessor.write_output(output, this.output_buffer);
} else {
- this.port.postMessage("Output buffer has not enough frames! Skipping output frame.");
+ this.port.postMessage('Output buffer has not enough frames! Skipping output frame.');
}
}
this.process_notify();
return true;
}
- write_output(dest, source) {
+ static write_output(dest, source) {
const channels = dest.length;
for (let ch = 0; ch < channels; ch++) {
for (let sample = 0; sample < dest[ch].length; sample++) {
@@ -172,7 +173,7 @@ class GodotProcessor extends AudioWorkletProcessor {
}
}
- write_input(dest, source) {
+ static write_input(dest, source) {
const channels = source.length;
for (let ch = 0; ch < channels; ch++) {
for (let sample = 0; sample < source[ch].length; sample++) {
diff --git a/platform/javascript/native/library_godot_audio.js b/platform/javascript/js/libs/library_godot_audio.js
index 3a0c8f297a..0c1f477f34 100644
--- a/platform/javascript/native/library_godot_audio.js
+++ b/platform/javascript/js/libs/library_godot_audio.js
@@ -29,73 +29,79 @@
/*************************************************************************/
const GodotAudio = {
- $GodotAudio__deps: ['$GodotOS'],
+ $GodotAudio__deps: ['$GodotRuntime', '$GodotOS'],
$GodotAudio: {
ctx: null,
input: null,
driver: null,
interval: 0,
- init: function(mix_rate, latency, onstatechange, onlatencyupdate) {
+ init: function (mix_rate, latency, onstatechange, onlatencyupdate) {
const ctx = new (window.AudioContext || window.webkitAudioContext)({
sampleRate: mix_rate,
// latencyHint: latency / 1000 // Do not specify, leave 'interactive' for good performance.
});
GodotAudio.ctx = ctx;
- onstatechange(ctx.state); // Immeditately notify state.
- ctx.onstatechange = function() {
+ ctx.onstatechange = function () {
let state = 0;
switch (ctx.state) {
- case 'suspended':
- state = 0;
- break;
- case 'running':
- state = 1;
- break;
- case 'closed':
- state = 2;
- break;
+ case 'suspended':
+ state = 0;
+ break;
+ case 'running':
+ state = 1;
+ break;
+ case 'closed':
+ state = 2;
+ break;
+
+ // no default
}
onstatechange(state);
- }
+ };
+ ctx.onstatechange(); // Immeditately notify state.
// Update computed latency
- GodotAudio.interval = setInterval(function() {
- let latency = 0;
+ GodotAudio.interval = setInterval(function () {
+ let computed_latency = 0;
if (ctx.baseLatency) {
- latency += GodotAudio.ctx.baseLatency;
+ computed_latency += GodotAudio.ctx.baseLatency;
}
if (ctx.outputLatency) {
- latency += GodotAudio.ctx.outputLatency;
+ computed_latency += GodotAudio.ctx.outputLatency;
}
- onlatencyupdate(latency);
+ onlatencyupdate(computed_latency);
}, 1000);
GodotOS.atexit(GodotAudio.close_async);
return ctx.destination.channelCount;
},
- create_input: function(callback) {
+ create_input: function (callback) {
if (GodotAudio.input) {
return; // Already started.
}
function gotMediaInput(stream) {
GodotAudio.input = GodotAudio.ctx.createMediaStreamSource(stream);
- callback(GodotAudio.input)
+ callback(GodotAudio.input);
}
if (navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({
- "audio": true
- }).then(gotMediaInput, function(e) { out(e) });
+ 'audio': true,
+ }).then(gotMediaInput, function (e) {
+ GodotRuntime.print(e);
+ });
} else {
if (!navigator.getUserMedia) {
navigator.getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
}
navigator.getUserMedia({
- "audio": true
- }, gotMediaInput, function(e) { out(e) });
+ 'audio': true,
+ }, gotMediaInput, function (e) {
+ GodotRuntime.print(e);
+ });
}
},
- close_async: function(resolve, reject) {
+ close_async: function (resolve, reject) {
const ctx = GodotAudio.ctx;
GodotAudio.ctx = null;
// Audio was not initialized.
@@ -118,14 +124,14 @@ const GodotAudio = {
if (GodotAudio.driver) {
closed = GodotAudio.driver.close();
}
- closed.then(function() {
+ closed.then(function () {
return ctx.close();
- }).then(function() {
+ }).then(function () {
ctx.onstatechange = null;
resolve();
- }).catch(function(e) {
+ }).catch(function (e) {
ctx.onstatechange = null;
- console.error("Error closing AudioContext", e);
+ GodotRuntime.error('Error closing AudioContext', e);
resolve();
});
},
@@ -139,30 +145,30 @@ const GodotAudio = {
return 1;
},
- godot_audio_init: function(p_mix_rate, p_latency, p_state_change, p_latency_update) {
- const statechange = GodotOS.get_func(p_state_change);
- const latencyupdate = GodotOS.get_func(p_latency_update);
+ godot_audio_init: function (p_mix_rate, p_latency, p_state_change, p_latency_update) {
+ const statechange = GodotRuntime.get_func(p_state_change);
+ const latencyupdate = GodotRuntime.get_func(p_latency_update);
return GodotAudio.init(p_mix_rate, p_latency, statechange, latencyupdate);
},
- godot_audio_resume: function() {
- if (GodotAudio.ctx && GodotAudio.ctx.state != 'running') {
+ godot_audio_resume: function () {
+ if (GodotAudio.ctx && GodotAudio.ctx.state !== 'running') {
GodotAudio.ctx.resume();
}
},
godot_audio_capture_start__proxy: 'sync',
- godot_audio_capture_start: function() {
+ godot_audio_capture_start: function () {
if (GodotAudio.input) {
return; // Already started.
}
- GodotAudio.create_input(function(input) {
+ GodotAudio.create_input(function (input) {
input.connect(GodotAudio.driver.get_node());
});
},
godot_audio_capture_stop__proxy: 'sync',
- godot_audio_capture_stop: function() {
+ godot_audio_capture_stop: function () {
if (GodotAudio.input) {
const tracks = GodotAudio.input['mediaStream']['getTracks']();
for (let i = 0; i < tracks.length; i++) {
@@ -174,54 +180,54 @@ const GodotAudio = {
},
};
-autoAddDeps(GodotAudio, "$GodotAudio");
+autoAddDeps(GodotAudio, '$GodotAudio');
mergeInto(LibraryManager.library, GodotAudio);
/**
* The AudioWorklet API driver, used when threads are available.
*/
const GodotAudioWorklet = {
- $GodotAudioWorklet__deps: ['$GodotAudio'],
+ $GodotAudioWorklet__deps: ['$GodotAudio', '$GodotConfig'],
$GodotAudioWorklet: {
promise: null,
worklet: null,
- create: function(channels) {
- const path = Module['locateFile']('godot.audio.worklet.js');
- GodotAudioWorklet.promise = GodotAudio.ctx.audioWorklet.addModule(path).then(function() {
+ create: function (channels) {
+ const path = GodotConfig.locate_file('godot.audio.worklet.js');
+ GodotAudioWorklet.promise = GodotAudio.ctx.audioWorklet.addModule(path).then(function () {
GodotAudioWorklet.worklet = new AudioWorkletNode(
GodotAudio.ctx,
'godot-processor',
{
- 'outputChannelCount': [channels]
- }
+ 'outputChannelCount': [channels],
+ },
);
return Promise.resolve();
});
GodotAudio.driver = GodotAudioWorklet;
},
- start: function(in_buf, out_buf, state) {
- GodotAudioWorklet.promise.then(function() {
+ start: function (in_buf, out_buf, state) {
+ GodotAudioWorklet.promise.then(function () {
const node = GodotAudioWorklet.worklet;
node.connect(GodotAudio.ctx.destination);
node.port.postMessage({
'cmd': 'start',
'data': [state, in_buf, out_buf],
});
- node.port.onmessage = function(event) {
- console.error(event.data);
+ node.port.onmessage = function (event) {
+ GodotRuntime.error(event.data);
};
});
},
- get_node: function() {
+ get_node: function () {
return GodotAudioWorklet.worklet;
},
- close: function() {
- return new Promise(function(resolve, reject) {
- GodotAudioWorklet.promise.then(function() {
+ close: function () {
+ return new Promise(function (resolve, reject) {
+ GodotAudioWorklet.promise.then(function () {
GodotAudioWorklet.worklet.port.postMessage({
'cmd': 'stop',
'data': null,
@@ -235,32 +241,32 @@ const GodotAudioWorklet = {
},
},
- godot_audio_worklet_create: function(channels) {
+ godot_audio_worklet_create: function (channels) {
GodotAudioWorklet.create(channels);
},
- godot_audio_worklet_start: function(p_in_buf, p_in_size, p_out_buf, p_out_size, p_state) {
- const out_buffer = GodotOS.heapSub(HEAPF32, p_out_buf, p_out_size);
- const in_buffer = GodotOS.heapSub(HEAPF32, p_in_buf, p_in_size);
- const state = GodotOS.heapSub(HEAP32, p_state, 4);
+ godot_audio_worklet_start: function (p_in_buf, p_in_size, p_out_buf, p_out_size, p_state) {
+ const out_buffer = GodotRuntime.heapSub(HEAPF32, p_out_buf, p_out_size);
+ const in_buffer = GodotRuntime.heapSub(HEAPF32, p_in_buf, p_in_size);
+ const state = GodotRuntime.heapSub(HEAP32, p_state, 4);
GodotAudioWorklet.start(in_buffer, out_buffer, state);
},
- godot_audio_worklet_state_wait: function(p_state, p_idx, p_expected, p_timeout) {
+ godot_audio_worklet_state_wait: function (p_state, p_idx, p_expected, p_timeout) {
Atomics.wait(HEAP32, (p_state >> 2) + p_idx, p_expected, p_timeout);
return Atomics.load(HEAP32, (p_state >> 2) + p_idx);
},
- godot_audio_worklet_state_add: function(p_state, p_idx, p_value) {
+ godot_audio_worklet_state_add: function (p_state, p_idx, p_value) {
return Atomics.add(HEAP32, (p_state >> 2) + p_idx, p_value);
},
- godot_audio_worklet_state_get: function(p_state, p_idx) {
+ godot_audio_worklet_state_get: function (p_state, p_idx) {
return Atomics.load(HEAP32, (p_state >> 2) + p_idx);
},
};
-autoAddDeps(GodotAudioWorklet, "$GodotAudioWorklet");
+autoAddDeps(GodotAudioWorklet, '$GodotAudioWorklet');
mergeInto(LibraryManager.library, GodotAudioWorklet);
/*
@@ -271,16 +277,16 @@ const GodotAudioScript = {
$GodotAudioScript: {
script: null,
- create: function(buffer_length, channel_count) {
+ create: function (buffer_length, channel_count) {
GodotAudioScript.script = GodotAudio.ctx.createScriptProcessor(buffer_length, 2, channel_count);
GodotAudio.driver = GodotAudioScript;
return GodotAudioScript.script.bufferSize;
},
- start: function(p_in_buf, p_in_size, p_out_buf, p_out_size, onprocess) {
- GodotAudioScript.script.onaudioprocess = function(event) {
+ start: function (p_in_buf, p_in_size, p_out_buf, p_out_size, onprocess) {
+ GodotAudioScript.script.onaudioprocess = function (event) {
// Read input
- const inb = GodotOS.heapSub(HEAPF32, p_in_buf, p_in_size);
+ const inb = GodotRuntime.heapSub(HEAPF32, p_in_buf, p_in_size);
const input = event.inputBuffer;
if (GodotAudio.input) {
const inlen = input.getChannelData(0).length;
@@ -296,7 +302,7 @@ const GodotAudioScript = {
onprocess();
// Write the output.
- const outb = GodotOS.heapSub(HEAPF32, p_out_buf, p_out_size);
+ const outb = GodotRuntime.heapSub(HEAPF32, p_out_buf, p_out_size);
const output = event.outputBuffer;
const channels = output.numberOfChannels;
for (let ch = 0; ch < channels; ch++) {
@@ -310,12 +316,12 @@ const GodotAudioScript = {
GodotAudioScript.script.connect(GodotAudio.ctx.destination);
},
- get_node: function() {
+ get_node: function () {
return GodotAudioScript.script;
},
- close: function() {
- return new Promise(function(resolve, reject) {
+ close: function () {
+ return new Promise(function (resolve, reject) {
GodotAudioScript.script.disconnect();
GodotAudioScript.script.onaudioprocess = null;
GodotAudioScript.script = null;
@@ -324,15 +330,15 @@ const GodotAudioScript = {
},
},
- godot_audio_script_create: function(buffer_length, channel_count) {
+ godot_audio_script_create: function (buffer_length, channel_count) {
return GodotAudioScript.create(buffer_length, channel_count);
},
- godot_audio_script_start: function(p_in_buf, p_in_size, p_out_buf, p_out_size, p_cb) {
- const onprocess = GodotOS.get_func(p_cb);
+ godot_audio_script_start: function (p_in_buf, p_in_size, p_out_buf, p_out_size, p_cb) {
+ const onprocess = GodotRuntime.get_func(p_cb);
GodotAudioScript.start(p_in_buf, p_in_size, p_out_buf, p_out_size, onprocess);
},
};
-autoAddDeps(GodotAudioScript, "$GodotAudioScript");
+autoAddDeps(GodotAudioScript, '$GodotAudioScript');
mergeInto(LibraryManager.library, GodotAudioScript);
diff --git a/platform/javascript/native/library_godot_display.js b/platform/javascript/js/libs/library_godot_display.js
index 11bbfbc60d..9651b48952 100644
--- a/platform/javascript/native/library_godot_display.js
+++ b/platform/javascript/js/libs/library_godot_display.js
@@ -33,32 +33,33 @@
* Keeps track of registered event listeners so it can remove them on shutdown.
*/
const GodotDisplayListeners = {
+ $GodotDisplayListeners__deps: ['$GodotOS'],
$GodotDisplayListeners__postset: 'GodotOS.atexit(function(resolve, reject) { GodotDisplayListeners.clear(); resolve(); });',
$GodotDisplayListeners: {
handlers: [],
- has: function(target, event, method, capture) {
- return GodotDisplayListeners.handlers.findIndex(function(e) {
- return e.target === target && e.event === event && e.method === method && e.capture == capture;
+ has: function (target, event, method, capture) {
+ return GodotDisplayListeners.handlers.findIndex(function (e) {
+ return e.target === target && e.event === event && e.method === method && e.capture === capture;
}) !== -1;
},
- add: function(target, event, method, capture) {
+ add: function (target, event, method, capture) {
if (GodotDisplayListeners.has(target, event, method, capture)) {
return;
}
- function Handler(target, event, method, capture) {
- this.target = target;
- this.event = event;
- this.method = method;
- this.capture = capture;
- };
+ function Handler(p_target, p_event, p_method, p_capture) {
+ this.target = p_target;
+ this.event = p_event;
+ this.method = p_method;
+ this.capture = p_capture;
+ }
GodotDisplayListeners.handlers.push(new Handler(target, event, method, capture));
target.addEventListener(event, method, capture);
},
- clear: function() {
- GodotDisplayListeners.handlers.forEach(function(h) {
+ clear: function () {
+ GodotDisplayListeners.handlers.forEach(function (h) {
h.target.removeEventListener(h.event, h.method, h.capture);
});
GodotDisplayListeners.handlers.length = 0;
@@ -83,20 +84,20 @@ const GodotDisplayDragDrop = {
promises: [],
pending_files: [],
- add_entry: function(entry) {
+ add_entry: function (entry) {
if (entry.isDirectory) {
GodotDisplayDragDrop.add_dir(entry);
} else if (entry.isFile) {
GodotDisplayDragDrop.add_file(entry);
} else {
- console.error("Unrecognized entry...", entry);
+ GodotRuntime.error('Unrecognized entry...', entry);
}
},
- add_dir: function(entry) {
- GodotDisplayDragDrop.promises.push(new Promise(function(resolve, reject) {
+ add_dir: function (entry) {
+ GodotDisplayDragDrop.promises.push(new Promise(function (resolve, reject) {
const reader = entry.createReader();
- reader.readEntries(function(entries) {
+ reader.readEntries(function (entries) {
for (let i = 0; i < entries.length; i++) {
GodotDisplayDragDrop.add_entry(entries[i]);
}
@@ -105,58 +106,58 @@ const GodotDisplayDragDrop = {
}));
},
- add_file: function(entry) {
- GodotDisplayDragDrop.promises.push(new Promise(function(resolve, reject) {
- entry.file(function(file) {
+ add_file: function (entry) {
+ GodotDisplayDragDrop.promises.push(new Promise(function (resolve, reject) {
+ entry.file(function (file) {
const reader = new FileReader();
- reader.onload = function() {
+ reader.onload = function () {
const f = {
- "path": file.relativePath || file.webkitRelativePath,
- "name": file.name,
- "type": file.type,
- "size": file.size,
- "data": reader.result
+ 'path': file.relativePath || file.webkitRelativePath,
+ 'name': file.name,
+ 'type': file.type,
+ 'size': file.size,
+ 'data': reader.result,
};
if (!f['path']) {
f['path'] = f['name'];
}
GodotDisplayDragDrop.pending_files.push(f);
- resolve()
+ resolve();
};
- reader.onerror = function() {
- console.log("Error reading file");
+ reader.onerror = function () {
+ GodotRuntime.print('Error reading file');
reject();
- }
+ };
reader.readAsArrayBuffer(file);
- }, function(err) {
- console.log("Error!");
+ }, function (err) {
+ GodotRuntime.print('Error!');
reject();
});
}));
},
- process: function(resolve, reject) {
- if (GodotDisplayDragDrop.promises.length == 0) {
+ process: function (resolve, reject) {
+ if (GodotDisplayDragDrop.promises.length === 0) {
resolve();
return;
}
- GodotDisplayDragDrop.promises.pop().then(function() {
- setTimeout(function() {
+ GodotDisplayDragDrop.promises.pop().then(function () {
+ setTimeout(function () {
GodotDisplayDragDrop.process(resolve, reject);
}, 0);
});
},
- _process_event: function(ev, callback) {
+ _process_event: function (ev, callback) {
ev.preventDefault();
if (ev.dataTransfer.items) {
// Use DataTransferItemList interface to access the file(s)
for (let i = 0; i < ev.dataTransfer.items.length; i++) {
const item = ev.dataTransfer.items[i];
let entry = null;
- if ("getAsEntry" in item) {
+ if ('getAsEntry' in item) {
entry = item.getAsEntry();
- } else if ("webkitGetAsEntry" in item) {
+ } else if ('webkitGetAsEntry' in item) {
entry = item.webkitGetAsEntry();
}
if (entry) {
@@ -164,25 +165,25 @@ const GodotDisplayDragDrop = {
}
}
} else {
- console.error("File upload not supported");
+ GodotRuntime.error('File upload not supported');
}
- new Promise(GodotDisplayDragDrop.process).then(function() {
- const DROP = "/tmp/drop-" + parseInt(Math.random() * Math.pow(2, 31)) + "/";
+ new Promise(GodotDisplayDragDrop.process).then(function () {
+ const DROP = `/tmp/drop-${parseInt(Math.random() * (1 << 30), 10)}/`;
const drops = [];
const files = [];
FS.mkdir(DROP);
GodotDisplayDragDrop.pending_files.forEach((elem) => {
const path = elem['path'];
GodotFS.copy_to_fs(DROP + path, elem['data']);
- let idx = path.indexOf("/");
- if (idx == -1) {
+ let idx = path.indexOf('/');
+ if (idx === -1) {
// Root file
drops.push(DROP + path);
} else {
// Subdir
const sub = path.substr(0, idx);
- idx = sub.indexOf("/");
- if (idx < 0 && drops.indexOf(DROP + sub) == -1) {
+ idx = sub.indexOf('/');
+ if (idx < 0 && drops.indexOf(DROP + sub) === -1) {
drops.push(DROP + sub);
}
}
@@ -191,37 +192,38 @@ const GodotDisplayDragDrop = {
GodotDisplayDragDrop.promises = [];
GodotDisplayDragDrop.pending_files = [];
callback(drops);
- const dirs = [DROP.substr(0, DROP.length -1)];
+ const dirs = [DROP.substr(0, DROP.length - 1)];
// Remove temporary files
files.forEach(function (file) {
FS.unlink(file);
- let dir = file.replace(DROP, "");
- let idx = dir.lastIndexOf("/");
+ let dir = file.replace(DROP, '');
+ let idx = dir.lastIndexOf('/');
while (idx > 0) {
dir = dir.substr(0, idx);
- if (dirs.indexOf(DROP + dir) == -1) {
+ if (dirs.indexOf(DROP + dir) === -1) {
dirs.push(DROP + dir);
}
- idx = dir.lastIndexOf("/");
+ idx = dir.lastIndexOf('/');
}
});
// Remove dirs.
- dirs.sort(function(a, b) {
+ dirs.sort(function (a, b) {
const al = (a.match(/\//g) || []).length;
const bl = (b.match(/\//g) || []).length;
- if (al > bl)
+ if (al > bl) {
return -1;
- else if (al < bl)
+ } else if (al < bl) {
return 1;
+ }
return 0;
- }).forEach(function(dir) {
+ }).forEach(function (dir) {
FS.rmdir(dir);
});
});
},
- handler: function(callback) {
- return function(ev) {
+ handler: function (callback) {
+ return function (ev) {
GodotDisplayDragDrop._process_event(ev, callback);
};
},
@@ -234,31 +236,31 @@ mergeInto(LibraryManager.library, GodotDisplayDragDrop);
* Keeps track of cursor status and custom shapes.
*/
const GodotDisplayCursor = {
+ $GodotDisplayCursor__deps: ['$GodotOS', '$GodotConfig'],
$GodotDisplayCursor__postset: 'GodotOS.atexit(function(resolve, reject) { GodotDisplayCursor.clear(); resolve(); });',
- $GodotDisplayCursor__deps: ['$GodotConfig', '$GodotOS'],
$GodotDisplayCursor: {
shape: 'auto',
visible: true,
cursors: {},
- set_style: function(style) {
+ set_style: function (style) {
GodotConfig.canvas.style.cursor = style;
},
- set_shape: function(shape) {
+ set_shape: function (shape) {
GodotDisplayCursor.shape = shape;
let css = shape;
if (shape in GodotDisplayCursor.cursors) {
const c = GodotDisplayCursor.cursors[shape];
- css = 'url("' + c.url + '") ' + c.x + ' ' + c.y + ', auto';
+ css = `url("${c.url}") ${c.x} ${c.y}, auto`;
}
if (GodotDisplayCursor.visible) {
GodotDisplayCursor.set_style(css);
}
},
- clear: function() {
+ clear: function () {
GodotDisplayCursor.set_style('');
GodotDisplayCursor.shape = 'auto';
GodotDisplayCursor.visible = true;
- Object.keys(GodotDisplayCursor.cursors).forEach(function(key) {
+ Object.keys(GodotDisplayCursor.cursors).forEach(function (key) {
URL.revokeObjectURL(GodotDisplayCursor.cursors[key]);
delete GodotDisplayCursor.cursors[key];
});
@@ -273,75 +275,74 @@ mergeInto(LibraryManager.library, GodotDisplayCursor);
* Exposes all the functions needed by DisplayServer implementation.
*/
const GodotDisplay = {
- $GodotDisplay__deps: ['$GodotConfig', '$GodotOS', '$GodotDisplayCursor', '$GodotDisplayListeners', '$GodotDisplayDragDrop'],
+ $GodotDisplay__deps: ['$GodotConfig', '$GodotRuntime', '$GodotDisplayCursor', '$GodotDisplayListeners', '$GodotDisplayDragDrop'],
$GodotDisplay: {
window_icon: '',
},
- godot_js_display_is_swap_ok_cancel: function() {
+ godot_js_display_is_swap_ok_cancel: function () {
const win = (['Windows', 'Win64', 'Win32', 'WinCE']);
- const plat = navigator.platform || "";
+ const plat = navigator.platform || '';
if (win.indexOf(plat) !== -1) {
return 1;
}
return 0;
},
- godot_js_display_alert: function(p_text) {
- window.alert(UTF8ToString(p_text));
+ godot_js_display_alert: function (p_text) {
+ window.alert(GodotRuntime.parseString(p_text)); // eslint-disable-line no-alert
},
- godot_js_display_pixel_ratio_get: function() {
+ godot_js_display_pixel_ratio_get: function () {
return window.devicePixelRatio || 1;
},
/*
* Canvas
*/
- godot_js_display_canvas_focus: function() {
+ godot_js_display_canvas_focus: function () {
GodotConfig.canvas.focus();
},
- godot_js_display_canvas_is_focused: function() {
- return document.activeElement == GodotConfig.canvas;
+ godot_js_display_canvas_is_focused: function () {
+ return document.activeElement === GodotConfig.canvas;
},
- godot_js_display_canvas_bounding_rect_position_get: function(r_x, r_y) {
+ godot_js_display_canvas_bounding_rect_position_get: function (r_x, r_y) {
const brect = GodotConfig.canvas.getBoundingClientRect();
- setValue(r_x, brect.x, 'i32');
- setValue(r_y, brect.y, 'i32');
+ GodotRuntime.setHeapValue(r_x, brect.x, 'i32');
+ GodotRuntime.setHeapValue(r_y, brect.y, 'i32');
},
/*
* Touchscreen
*/
- godot_js_display_touchscreen_is_available: function() {
+ godot_js_display_touchscreen_is_available: function () {
return 'ontouchstart' in window;
},
/*
* Clipboard
*/
- godot_js_display_clipboard_set: function(p_text) {
- const text = UTF8ToString(p_text);
+ godot_js_display_clipboard_set: function (p_text) {
+ const text = GodotRuntime.parseString(p_text);
if (!navigator.clipboard || !navigator.clipboard.writeText) {
return 1;
}
- navigator.clipboard.writeText(text).catch(function(e) {
+ navigator.clipboard.writeText(text).catch(function (e) {
// Setting OS clipboard is only possible from an input callback.
- console.error("Setting OS clipboard is only possible from an input callback for the HTML5 plafrom. Exception:", e);
+ GodotRuntime.error('Setting OS clipboard is only possible from an input callback for the HTML5 plafrom. Exception:', e);
});
return 0;
},
- godot_js_display_clipboard_get_deps: ['$GodotOS'],
- godot_js_display_clipboard_get: function(callback) {
- const func = GodotOS.get_func(callback);
+ godot_js_display_clipboard_get: function (callback) {
+ const func = GodotRuntime.get_func(callback);
try {
navigator.clipboard.readText().then(function (result) {
- const ptr = allocate(intArrayFromString(result), ALLOC_NORMAL);
+ const ptr = GodotRuntime.allocString(result);
func(ptr);
- _free(ptr);
+ GodotRuntime.free(ptr);
}).catch(function (e) {
// Fail graciously.
});
@@ -353,19 +354,19 @@ const GodotDisplay = {
/*
* Window
*/
- godot_js_display_window_request_fullscreen: function() {
+ godot_js_display_window_request_fullscreen: function () {
const canvas = GodotConfig.canvas;
- (canvas.requestFullscreen || canvas.msRequestFullscreen ||
- canvas.mozRequestFullScreen || canvas.mozRequestFullscreen ||
- canvas.webkitRequestFullscreen
+ (canvas.requestFullscreen || canvas.msRequestFullscreen
+ || canvas.mozRequestFullScreen || canvas.mozRequestFullscreen
+ || canvas.webkitRequestFullscreen
).call(canvas);
},
- godot_js_display_window_title_set: function(p_data) {
- document.title = UTF8ToString(p_data);
+ godot_js_display_window_title_set: function (p_data) {
+ document.title = GodotRuntime.parseString(p_data);
},
- godot_js_display_window_icon_set: function(p_ptr, p_len) {
+ godot_js_display_window_icon_set: function (p_ptr, p_len) {
let link = document.getElementById('-gd-engine-icon');
if (link === null) {
link = document.createElement('link');
@@ -374,7 +375,7 @@ const GodotDisplay = {
document.head.appendChild(link);
}
const old_icon = GodotDisplay.window_icon;
- const png = new Blob([GodotOS.heapCopy(HEAPU8, p_ptr, p_len)], { type: "image/png" });
+ const png = new Blob([GodotRuntime.heapCopy(HEAPU8, p_ptr, p_len)], { type: 'image/png' });
GodotDisplay.window_icon = URL.createObjectURL(png);
link.href = GodotDisplay.window_icon;
if (old_icon) {
@@ -385,9 +386,9 @@ const GodotDisplay = {
/*
* Cursor
*/
- godot_js_display_cursor_set_visible: function(p_visible) {
- const visible = p_visible != 0;
- if (visible == GodotDisplayCursor.visible) {
+ godot_js_display_cursor_set_visible: function (p_visible) {
+ const visible = p_visible !== 0;
+ if (visible === GodotDisplayCursor.visible) {
return;
}
GodotDisplayCursor.visible = visible;
@@ -398,19 +399,19 @@ const GodotDisplay = {
}
},
- godot_js_display_cursor_is_hidden: function() {
+ godot_js_display_cursor_is_hidden: function () {
return !GodotDisplayCursor.visible;
},
- godot_js_display_cursor_set_shape: function(p_string) {
- GodotDisplayCursor.set_shape(UTF8ToString(p_string));
+ godot_js_display_cursor_set_shape: function (p_string) {
+ GodotDisplayCursor.set_shape(GodotRuntime.parseString(p_string));
},
- godot_js_display_cursor_set_custom_shape: function(p_shape, p_ptr, p_len, p_hotspot_x, p_hotspot_y) {
- const shape = UTF8ToString(p_shape);
+ godot_js_display_cursor_set_custom_shape: function (p_shape, p_ptr, p_len, p_hotspot_x, p_hotspot_y) {
+ const shape = GodotRuntime.parseString(p_shape);
const old_shape = GodotDisplayCursor.cursors[shape];
if (p_len > 0) {
- const png = new Blob([GodotOS.heapCopy(HEAPU8, p_ptr, p_len)], { type: 'image/png' });
+ const png = new Blob([GodotRuntime.heapCopy(HEAPU8, p_ptr, p_len)], { type: 'image/png' });
const url = URL.createObjectURL(png);
GodotDisplayCursor.cursors[shape] = {
url: url,
@@ -420,7 +421,7 @@ const GodotDisplay = {
} else {
delete GodotDisplayCursor.cursors[shape];
}
- if (shape == GodotDisplayCursor.shape) {
+ if (shape === GodotDisplayCursor.shape) {
GodotDisplayCursor.set_shape(GodotDisplayCursor.shape);
}
if (old_shape) {
@@ -431,41 +432,41 @@ const GodotDisplay = {
/*
* Listeners
*/
- godot_js_display_notification_cb: function(callback, p_enter, p_exit, p_in, p_out) {
+ godot_js_display_notification_cb: function (callback, p_enter, p_exit, p_in, p_out) {
const canvas = GodotConfig.canvas;
- const func = GodotOS.get_func(callback);
+ const func = GodotRuntime.get_func(callback);
const notif = [p_enter, p_exit, p_in, p_out];
- ['mouseover', 'mouseleave', 'focus', 'blur'].forEach(function(evt_name, idx) {
- GodotDisplayListeners.add(canvas, evt_name, function() {
+ ['mouseover', 'mouseleave', 'focus', 'blur'].forEach(function (evt_name, idx) {
+ GodotDisplayListeners.add(canvas, evt_name, function () {
func.bind(null, notif[idx]);
}, true);
});
},
- godot_js_display_paste_cb: function(callback) {
- const func = GodotOS.get_func(callback);
- GodotDisplayListeners.add(window, 'paste', function(evt) {
+ godot_js_display_paste_cb: function (callback) {
+ const func = GodotRuntime.get_func(callback);
+ GodotDisplayListeners.add(window, 'paste', function (evt) {
const text = evt.clipboardData.getData('text');
- const ptr = allocate(intArrayFromString(text), ALLOC_NORMAL);
+ const ptr = GodotRuntime.allocString(text);
func(ptr);
- _free(ptr);
+ GodotRuntime.free(ptr);
}, false);
},
- godot_js_display_drop_files_cb: function(callback) {
- const func = GodotOS.get_func(callback)
- const dropFiles = function(files) {
+ godot_js_display_drop_files_cb: function (callback) {
+ const func = GodotRuntime.get_func(callback);
+ const dropFiles = function (files) {
const args = files || [];
if (!args.length) {
return;
}
const argc = args.length;
- const argv = GodotOS.allocStringArray(args);
+ const argv = GodotRuntime.allocStringArray(args);
func(argv, argc);
- GodotOS.freeStringArray(argv, argc);
+ GodotRuntime.freeStringArray(argv, argc);
};
const canvas = GodotConfig.canvas;
- GodotDisplayListeners.add(canvas, 'dragover', function(ev) {
+ GodotDisplayListeners.add(canvas, 'dragover', function (ev) {
// Prevent default behavior (which would try to open the file(s))
ev.preventDefault();
}, false);
diff --git a/platform/javascript/native/library_godot_editor_tools.js b/platform/javascript/js/libs/library_godot_editor_tools.js
index 202a198adb..f39fed04a8 100644
--- a/platform/javascript/native/library_godot_editor_tools.js
+++ b/platform/javascript/js/libs/library_godot_editor_tools.js
@@ -30,10 +30,10 @@
const GodotEditorTools = {
godot_js_editor_download_file__deps: ['$FS'],
- godot_js_editor_download_file: function(p_path, p_name, p_mime) {
- const path = UTF8ToString(p_path);
- const name = UTF8ToString(p_name);
- const mime = UTF8ToString(p_mime);
+ godot_js_editor_download_file: function (p_path, p_name, p_mime) {
+ const path = GodotRuntime.parseString(p_path);
+ const name = GodotRuntime.parseString(p_name);
+ const mime = GodotRuntime.parseString(p_mime);
const size = FS.stat(path)['size'];
const buf = new Uint8Array(size);
const fd = FS.open(path, 'r');
diff --git a/platform/javascript/native/library_godot_eval.js b/platform/javascript/js/libs/library_godot_eval.js
index 44d356a4fb..33ff231726 100644
--- a/platform/javascript/native/library_godot_eval.js
+++ b/platform/javascript/js/libs/library_godot_eval.js
@@ -29,57 +29,57 @@
/*************************************************************************/
const GodotEval = {
- godot_js_eval__deps: ['$GodotOS'],
- godot_js_eval: function(p_js, p_use_global_ctx, p_union_ptr, p_byte_arr, p_byte_arr_write, p_callback) {
- const js_code = UTF8ToString(p_js);
+ godot_js_eval__deps: ['$GodotRuntime'],
+ godot_js_eval: function (p_js, p_use_global_ctx, p_union_ptr, p_byte_arr, p_byte_arr_write, p_callback) {
+ const js_code = GodotRuntime.parseString(p_js);
let eval_ret = null;
try {
if (p_use_global_ctx) {
// indirect eval call grants global execution context
- const global_eval = eval;
+ const global_eval = eval; // eslint-disable-line no-eval
eval_ret = global_eval(js_code);
} else {
- eval_ret = eval(js_code);
+ eval_ret = eval(js_code); // eslint-disable-line no-eval
}
} catch (e) {
- err(e);
+ GodotRuntime.error(e);
}
switch (typeof eval_ret) {
- case 'boolean':
- setValue(p_union_ptr, eval_ret, 'i32');
- return 1; // BOOL
+ case 'boolean':
+ GodotRuntime.setHeapValue(p_union_ptr, eval_ret, 'i32');
+ return 1; // BOOL
- case 'number':
- setValue(p_union_ptr, eval_ret, 'double');
- return 3; // REAL
+ case 'number':
+ GodotRuntime.setHeapValue(p_union_ptr, eval_ret, 'double');
+ return 3; // REAL
- case 'string':
- let array_ptr = GodotOS.allocString(eval_ret);
- setValue(p_union_ptr, array_ptr , '*');
- return 4; // STRING
+ case 'string':
+ GodotRuntime.setHeapValue(p_union_ptr, GodotRuntime.allocString(eval_ret), '*');
+ return 4; // STRING
- case 'object':
- if (eval_ret === null) {
- break;
- }
-
- if (ArrayBuffer.isView(eval_ret) && !(eval_ret instanceof Uint8Array)) {
- eval_ret = new Uint8Array(eval_ret.buffer);
- }
- else if (eval_ret instanceof ArrayBuffer) {
- eval_ret = new Uint8Array(eval_ret);
- }
- if (eval_ret instanceof Uint8Array) {
- const func = GodotOS.get_func(p_callback);
- const bytes_ptr = func(p_byte_arr, p_byte_arr_write, eval_ret.length);
- HEAPU8.set(eval_ret, bytes_ptr);
- return 20; // POOL_BYTE_ARRAY
- }
+ case 'object':
+ if (eval_ret === null) {
break;
+ }
+
+ if (ArrayBuffer.isView(eval_ret) && !(eval_ret instanceof Uint8Array)) {
+ eval_ret = new Uint8Array(eval_ret.buffer);
+ } else if (eval_ret instanceof ArrayBuffer) {
+ eval_ret = new Uint8Array(eval_ret);
+ }
+ if (eval_ret instanceof Uint8Array) {
+ const func = GodotRuntime.get_func(p_callback);
+ const bytes_ptr = func(p_byte_arr, p_byte_arr_write, eval_ret.length);
+ HEAPU8.set(eval_ret, bytes_ptr);
+ return 20; // POOL_BYTE_ARRAY
+ }
+ break;
+
+ // no default
}
return 0; // NIL
},
-}
+};
mergeInto(LibraryManager.library, GodotEval);
diff --git a/platform/javascript/native/http_request.js b/platform/javascript/js/libs/library_godot_http_request.js
index 272154aee3..2b9aa88208 100644
--- a/platform/javascript/native/http_request.js
+++ b/platform/javascript/js/libs/library_godot_http_request.js
@@ -27,118 +27,119 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-var GodotHTTPRequest = {
+
+const GodotHTTPRequest = {
+ $GodotHTTPRequest__deps: ['$GodotRuntime'],
$GodotHTTPRequest: {
requests: [],
- getUnusedRequestId: function() {
- var idMax = GodotHTTPRequest.requests.length;
- for (var potentialId = 0; potentialId < idMax; ++potentialId) {
+ getUnusedRequestId: function () {
+ const idMax = GodotHTTPRequest.requests.length;
+ for (let potentialId = 0; potentialId < idMax; ++potentialId) {
if (GodotHTTPRequest.requests[potentialId] instanceof XMLHttpRequest) {
continue;
}
return potentialId;
}
- GodotHTTPRequest.requests.push(null)
+ GodotHTTPRequest.requests.push(null);
return idMax;
},
- setupRequest: function(xhr) {
+ setupRequest: function (xhr) {
xhr.responseType = 'arraybuffer';
},
},
- godot_xhr_new: function() {
- var newId = GodotHTTPRequest.getUnusedRequestId();
- GodotHTTPRequest.requests[newId] = new XMLHttpRequest;
+ godot_xhr_new: function () {
+ const newId = GodotHTTPRequest.getUnusedRequestId();
+ GodotHTTPRequest.requests[newId] = new XMLHttpRequest();
GodotHTTPRequest.setupRequest(GodotHTTPRequest.requests[newId]);
return newId;
},
- godot_xhr_reset: function(xhrId) {
- GodotHTTPRequest.requests[xhrId] = new XMLHttpRequest;
+ godot_xhr_reset: function (xhrId) {
+ GodotHTTPRequest.requests[xhrId] = new XMLHttpRequest();
GodotHTTPRequest.setupRequest(GodotHTTPRequest.requests[xhrId]);
},
- godot_xhr_free: function(xhrId) {
+ godot_xhr_free: function (xhrId) {
GodotHTTPRequest.requests[xhrId].abort();
GodotHTTPRequest.requests[xhrId] = null;
},
- godot_xhr_open: function(xhrId, method, url, user, password) {
- user = user > 0 ? UTF8ToString(user) : null;
- password = password > 0 ? UTF8ToString(password) : null;
- GodotHTTPRequest.requests[xhrId].open(UTF8ToString(method), UTF8ToString(url), true, user, password);
+ godot_xhr_open: function (xhrId, method, url, p_user, p_password) {
+ const user = p_user > 0 ? GodotRuntime.parseString(p_user) : null;
+ const password = p_password > 0 ? GodotRuntime.parseString(p_password) : null;
+ GodotHTTPRequest.requests[xhrId].open(GodotRuntime.parseString(method), GodotRuntime.parseString(url), true, user, password);
},
- godot_xhr_set_request_header: function(xhrId, header, value) {
- GodotHTTPRequest.requests[xhrId].setRequestHeader(UTF8ToString(header), UTF8ToString(value));
+ godot_xhr_set_request_header: function (xhrId, header, value) {
+ GodotHTTPRequest.requests[xhrId].setRequestHeader(GodotRuntime.parseString(header), GodotRuntime.parseString(value));
},
- godot_xhr_send_null: function(xhrId) {
+ godot_xhr_send_null: function (xhrId) {
GodotHTTPRequest.requests[xhrId].send();
},
- godot_xhr_send_string: function(xhrId, strPtr) {
+ godot_xhr_send_string: function (xhrId, strPtr) {
if (!strPtr) {
- err("Failed to send string per XHR: null pointer");
+ GodotRuntime.error('Failed to send string per XHR: null pointer');
return;
}
- GodotHTTPRequest.requests[xhrId].send(UTF8ToString(strPtr));
+ GodotHTTPRequest.requests[xhrId].send(GodotRuntime.parseString(strPtr));
},
- godot_xhr_send_data: function(xhrId, ptr, len) {
+ godot_xhr_send_data: function (xhrId, ptr, len) {
if (!ptr) {
- err("Failed to send data per XHR: null pointer");
+ GodotRuntime.error('Failed to send data per XHR: null pointer');
return;
}
if (len < 0) {
- err("Failed to send data per XHR: buffer length less than 0");
+ GodotRuntime.error('Failed to send data per XHR: buffer length less than 0');
return;
}
GodotHTTPRequest.requests[xhrId].send(HEAPU8.subarray(ptr, ptr + len));
},
- godot_xhr_abort: function(xhrId) {
+ godot_xhr_abort: function (xhrId) {
GodotHTTPRequest.requests[xhrId].abort();
},
- godot_xhr_get_status: function(xhrId) {
+ godot_xhr_get_status: function (xhrId) {
return GodotHTTPRequest.requests[xhrId].status;
},
- godot_xhr_get_ready_state: function(xhrId) {
+ godot_xhr_get_ready_state: function (xhrId) {
return GodotHTTPRequest.requests[xhrId].readyState;
},
- godot_xhr_get_response_headers_length: function(xhrId) {
- var headers = GodotHTTPRequest.requests[xhrId].getAllResponseHeaders();
- return headers === null ? 0 : lengthBytesUTF8(headers);
+ godot_xhr_get_response_headers_length: function (xhrId) {
+ const headers = GodotHTTPRequest.requests[xhrId].getAllResponseHeaders();
+ return headers === null ? 0 : GodotRuntime.strlen(headers);
},
- godot_xhr_get_response_headers: function(xhrId, dst, len) {
- var str = GodotHTTPRequest.requests[xhrId].getAllResponseHeaders();
- if (str === null)
+ godot_xhr_get_response_headers: function (xhrId, dst, len) {
+ const str = GodotHTTPRequest.requests[xhrId].getAllResponseHeaders();
+ if (str === null) {
return;
- var buf = new Uint8Array(len + 1);
- stringToUTF8Array(str, buf, 0, buf.length);
- buf = buf.subarray(0, -1);
- HEAPU8.set(buf, dst);
+ }
+ GodotRuntime.stringToHeap(str, dst, len);
},
- godot_xhr_get_response_length: function(xhrId) {
- var body = GodotHTTPRequest.requests[xhrId].response;
+ godot_xhr_get_response_length: function (xhrId) {
+ const body = GodotHTTPRequest.requests[xhrId].response;
return body === null ? 0 : body.byteLength;
},
- godot_xhr_get_response: function(xhrId, dst, len) {
- var buf = GodotHTTPRequest.requests[xhrId].response;
- if (buf === null)
+ godot_xhr_get_response: function (xhrId, dst, len) {
+ let buf = GodotHTTPRequest.requests[xhrId].response;
+ if (buf === null) {
return;
+ }
buf = new Uint8Array(buf).subarray(0, len);
HEAPU8.set(buf, dst);
},
};
-autoAddDeps(GodotHTTPRequest, "$GodotHTTPRequest");
+autoAddDeps(GodotHTTPRequest, '$GodotHTTPRequest');
mergeInto(LibraryManager.library, GodotHTTPRequest);
diff --git a/platform/javascript/native/library_godot_os.js b/platform/javascript/js/libs/library_godot_os.js
index a1424a691a..488753d704 100644
--- a/platform/javascript/native/library_godot_os.js
+++ b/platform/javascript/js/libs/library_godot_os.js
@@ -33,52 +33,57 @@ const IDHandler = {
_last_id: 0,
_references: {},
- get: function(p_id) {
+ get: function (p_id) {
return IDHandler._references[p_id];
},
- add: function(p_data) {
+ add: function (p_data) {
const id = ++IDHandler._last_id;
IDHandler._references[id] = p_data;
return id;
},
- remove: function(p_id) {
+ remove: function (p_id) {
delete IDHandler._references[p_id];
},
},
};
-autoAddDeps(IDHandler, "$IDHandler");
+autoAddDeps(IDHandler, '$IDHandler');
mergeInto(LibraryManager.library, IDHandler);
const GodotConfig = {
$GodotConfig__postset: 'Module["initConfig"] = GodotConfig.init_config;',
+ $GodotConfig__deps: ['$GodotRuntime'],
$GodotConfig: {
canvas: null,
- locale: "en",
+ locale: 'en',
resize_on_start: false,
on_execute: null,
- init_config: function(p_opts) {
- GodotConfig.resize_on_start = p_opts['resizeCanvasOnStart'] ? true : false;
+ init_config: function (p_opts) {
+ GodotConfig.resize_on_start = !!p_opts['resizeCanvasOnStart'];
GodotConfig.canvas = p_opts['canvas'];
GodotConfig.locale = p_opts['locale'] || GodotConfig.locale;
GodotConfig.on_execute = p_opts['onExecute'];
// This is called by emscripten, even if undocumented.
- Module['onExit'] = p_opts['onExit'];
+ Module['onExit'] = p_opts['onExit']; // eslint-disable-line no-undef
+ },
+
+ locate_file: function (file) {
+ return Module['locateFile'](file); // eslint-disable-line no-undef
},
},
- godot_js_config_canvas_id_get: function(p_ptr, p_ptr_max) {
- stringToUTF8('#' + GodotConfig.canvas.id, p_ptr, p_ptr_max);
+ godot_js_config_canvas_id_get: function (p_ptr, p_ptr_max) {
+ GodotRuntime.stringToHeap(`#${GodotConfig.canvas.id}`, p_ptr, p_ptr_max);
},
- godot_js_config_locale_get: function(p_ptr, p_ptr_max) {
- stringToUTF8(GodotConfig.locale, p_ptr, p_ptr_max);
+ godot_js_config_locale_get: function (p_ptr, p_ptr_max) {
+ GodotRuntime.stringToHeap(GodotConfig.locale, p_ptr, p_ptr_max);
},
- godot_js_config_is_resize_on_start: function() {
+ godot_js_config_is_resize_on_start: function () {
return GodotConfig.resize_on_start ? 1 : 0;
},
};
@@ -87,7 +92,7 @@ autoAddDeps(GodotConfig, '$GodotConfig');
mergeInto(LibraryManager.library, GodotConfig);
const GodotFS = {
- $GodotFS__deps: ['$FS', '$IDBFS'],
+ $GodotFS__deps: ['$FS', '$IDBFS', '$GodotRuntime'],
$GodotFS__postset: [
'Module["initFS"] = GodotFS.init;',
'Module["deinitFS"] = GodotFS.deinit;',
@@ -98,7 +103,7 @@ const GodotFS = {
_syncing: false,
_mount_points: [],
- is_persistent: function() {
+ is_persistent: function () {
return GodotFS._idbfs ? 1 : 0;
},
@@ -106,7 +111,7 @@ const GodotFS = {
// Returns a promise that resolves when the FS is ready.
// We keep track of mount_points, so that we can properly close the IDBFS
// since emscripten is not doing it by itself. (emscripten GH#12516).
- init: function(persistentPaths) {
+ init: function (persistentPaths) {
GodotFS._idbfs = false;
if (!Array.isArray(persistentPaths)) {
return Promise.reject(new Error('Persistent paths must be an array'));
@@ -127,16 +132,16 @@ const GodotFS = {
}
}
- GodotFS._mount_points.forEach(function(path) {
+ GodotFS._mount_points.forEach(function (path) {
createRecursive(path);
FS.mount(IDBFS, {}, path);
});
- return new Promise(function(resolve, reject) {
- FS.syncfs(true, function(err) {
+ return new Promise(function (resolve, reject) {
+ FS.syncfs(true, function (err) {
if (err) {
GodotFS._mount_points = [];
GodotFS._idbfs = false;
- console.log("IndexedDB not available: " + err.message);
+ GodotRuntime.print(`IndexedDB not available: ${err.message}`);
} else {
GodotFS._idbfs = true;
}
@@ -146,12 +151,12 @@ const GodotFS = {
},
// Deinit godot file system, making sure to unmount file systems, and close IDBFS(s).
- deinit: function() {
- GodotFS._mount_points.forEach(function(path) {
+ deinit: function () {
+ GodotFS._mount_points.forEach(function (path) {
try {
FS.unmount(path);
} catch (e) {
- console.log("Already unmounted", e);
+ GodotRuntime.print('Already unmounted', e);
}
if (GodotFS._idbfs && IDBFS.dbs[path]) {
IDBFS.dbs[path].close();
@@ -163,16 +168,16 @@ const GodotFS = {
GodotFS._syncing = false;
},
- sync: function() {
+ sync: function () {
if (GodotFS._syncing) {
- err('Already syncing!');
+ GodotRuntime.error('Already syncing!');
return Promise.resolve();
}
GodotFS._syncing = true;
return new Promise(function (resolve, reject) {
- FS.syncfs(false, function(error) {
+ FS.syncfs(false, function (error) {
if (error) {
- err('Failed to save IDB file system: ' + error.message);
+ GodotRuntime.error(`Failed to save IDB file system: ${error.message}`);
}
GodotFS._syncing = false;
resolve(error);
@@ -181,9 +186,9 @@ const GodotFS = {
},
// Copies a buffer to the internal file system. Creating directories recursively.
- copy_to_fs: function(path, buffer) {
- const idx = path.lastIndexOf("/");
- let dir = "/";
+ copy_to_fs: function (path, buffer) {
+ const idx = path.lastIndexOf('/');
+ let dir = '/';
if (idx > 0) {
dir = path.slice(0, idx);
}
@@ -195,105 +200,68 @@ const GodotFS = {
}
FS.mkdirTree(dir);
}
- FS.writeFile(path, new Uint8Array(buffer), {'flags': 'wx+'});
+ FS.writeFile(path, new Uint8Array(buffer), { 'flags': 'wx+' });
},
},
};
mergeInto(LibraryManager.library, GodotFS);
const GodotOS = {
- $GodotOS__deps: ['$GodotFS'],
+ $GodotOS__deps: ['$GodotFS', '$GodotRuntime'],
$GodotOS__postset: [
'Module["request_quit"] = function() { GodotOS.request_quit() };',
'GodotOS._fs_sync_promise = Promise.resolve();',
].join(''),
$GodotOS: {
- request_quit: function() {},
+ request_quit: function () {},
_async_cbs: [],
_fs_sync_promise: null,
- get_func: function(ptr) {
- return wasmTable.get(ptr);
- },
-
- atexit: function(p_promise_cb) {
+ atexit: function (p_promise_cb) {
GodotOS._async_cbs.push(p_promise_cb);
},
- finish_async: function(callback) {
- GodotOS._fs_sync_promise.then(function(err) {
+ finish_async: function (callback) {
+ GodotOS._fs_sync_promise.then(function (err) {
const promises = [];
- GodotOS._async_cbs.forEach(function(cb) {
+ GodotOS._async_cbs.forEach(function (cb) {
promises.push(new Promise(cb));
});
return Promise.all(promises);
- }).then(function() {
+ }).then(function () {
return GodotFS.sync(); // Final FS sync.
- }).then(function(err) {
+ }).then(function (err) {
// Always deferred.
- setTimeout(function() {
+ setTimeout(function () {
callback();
}, 0);
});
},
-
- allocString: function(p_str) {
- const length = lengthBytesUTF8(p_str)+1;
- const c_str = _malloc(length);
- stringToUTF8(p_str, c_str, length);
- return c_str;
- },
-
- allocStringArray: function(strings) {
- const size = strings.length;
- const c_ptr = _malloc(size * 4);
- for (let i = 0; i < size; i++) {
- HEAP32[(c_ptr >> 2) + i] = GodotOS.allocString(strings[i]);
- }
- return c_ptr;
- },
-
- freeStringArray: function(c_ptr, size) {
- for (let i = 0; i < size; i++) {
- _free(HEAP32[(c_ptr >> 2) + i]);
- }
- _free(c_ptr);
- },
-
- heapSub: function(heap, ptr, size) {
- const bytes = heap.BYTES_PER_ELEMENT;
- return heap.subarray(ptr / bytes, ptr / bytes + size);
- },
-
- heapCopy: function(heap, ptr, size) {
- const bytes = heap.BYTES_PER_ELEMENT;
- return heap.slice(ptr / bytes, ptr / bytes + size);
- },
},
- godot_js_os_finish_async: function(p_callback) {
- const func = GodotOS.get_func(p_callback);
+ godot_js_os_finish_async: function (p_callback) {
+ const func = GodotRuntime.get_func(p_callback);
GodotOS.finish_async(func);
},
- godot_js_os_request_quit_cb: function(p_callback) {
- GodotOS.request_quit = GodotOS.get_func(p_callback);
+ godot_js_os_request_quit_cb: function (p_callback) {
+ GodotOS.request_quit = GodotRuntime.get_func(p_callback);
},
- godot_js_os_fs_is_persistent: function() {
+ godot_js_os_fs_is_persistent: function () {
return GodotFS.is_persistent();
},
- godot_js_os_fs_sync: function(callback) {
- const func = GodotOS.get_func(callback);
+ godot_js_os_fs_sync: function (callback) {
+ const func = GodotRuntime.get_func(callback);
GodotOS._fs_sync_promise = GodotFS.sync();
- GodotOS._fs_sync_promise.then(function(err) {
+ GodotOS._fs_sync_promise.then(function (err) {
func();
});
},
- godot_js_os_execute: function(p_json) {
- const json_args = UTF8ToString(p_json);
+ godot_js_os_execute: function (p_json) {
+ const json_args = GodotRuntime.parseString(p_json);
const args = JSON.parse(json_args);
if (GodotConfig.on_execute) {
GodotConfig.on_execute(args);
@@ -302,8 +270,8 @@ const GodotOS = {
return 1;
},
- godot_js_os_shell_open: function(p_uri) {
- window.open(UTF8ToString(p_uri), '_blank');
+ godot_js_os_shell_open: function (p_uri) {
+ window.open(GodotRuntime.parseString(p_uri), '_blank');
},
};
diff --git a/platform/javascript/js/libs/library_godot_runtime.js b/platform/javascript/js/libs/library_godot_runtime.js
new file mode 100644
index 0000000000..04f29ad681
--- /dev/null
+++ b/platform/javascript/js/libs/library_godot_runtime.js
@@ -0,0 +1,120 @@
+/*************************************************************************/
+/* library_godot_runtime.js */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* 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. */
+/*************************************************************************/
+
+const GodotRuntime = {
+ $GodotRuntime: {
+ /*
+ * Functions
+ */
+ get_func: function (ptr) {
+ return wasmTable.get(ptr); // eslint-disable-line no-undef
+ },
+
+ /*
+ * Prints
+ */
+ error: function () {
+ err.apply(null, Array.from(arguments)); // eslint-disable-line no-undef
+ },
+
+ print: function () {
+ out.apply(null, Array.from(arguments)); // eslint-disable-line no-undef
+ },
+
+ /*
+ * Memory
+ */
+ malloc: function (p_size) {
+ return _malloc(p_size); // eslint-disable-line no-undef
+ },
+
+ free: function (p_ptr) {
+ _free(p_ptr); // eslint-disable-line no-undef
+ },
+
+ getHeapValue: function (p_ptr, p_type) {
+ return getValue(p_ptr, p_type); // eslint-disable-line no-undef
+ },
+
+ setHeapValue: function (p_ptr, p_value, p_type) {
+ setValue(p_ptr, p_value, p_type); // eslint-disable-line no-undef
+ },
+
+ heapSub: function (p_heap, p_ptr, p_len) {
+ const bytes = p_heap.BYTES_PER_ELEMENT;
+ return p_heap.subarray(p_ptr / bytes, p_ptr / bytes + p_len);
+ },
+
+ heapCopy: function (p_heap, p_ptr, p_len) {
+ const bytes = p_heap.BYTES_PER_ELEMENT;
+ return p_heap.slice(p_ptr / bytes, p_ptr / bytes + p_len);
+ },
+
+ /*
+ * Strings
+ */
+ parseString: function (p_ptr) {
+ return UTF8ToString(p_ptr); // eslint-disable-line no-undef
+ },
+
+ strlen: function (p_str) {
+ return lengthBytesUTF8(p_str); // eslint-disable-line no-undef
+ },
+
+ allocString: function (p_str) {
+ const length = GodotRuntime.strlen(p_str) + 1;
+ const c_str = GodotRuntime.malloc(length);
+ stringToUTF8(p_str, c_str, length); // eslint-disable-line no-undef
+ return c_str;
+ },
+
+ allocStringArray: function (p_strings) {
+ const size = p_strings.length;
+ const c_ptr = GodotRuntime.malloc(size * 4);
+ for (let i = 0; i < size; i++) {
+ HEAP32[(c_ptr >> 2) + i] = GodotRuntime.allocString(p_strings[i]);
+ }
+ return c_ptr;
+ },
+
+ freeStringArray: function (p_ptr, p_len) {
+ for (let i = 0; i < p_len; i++) {
+ GodotRuntime.free(HEAP32[(p_ptr >> 2) + i]);
+ }
+ GodotRuntime.free(p_ptr);
+ },
+
+ stringToHeap: function (p_str, p_ptr, p_len) {
+ return stringToUTF8Array(p_str, HEAP8, p_ptr, p_len); // eslint-disable-line no-undef
+ },
+ },
+};
+autoAddDeps(GodotRuntime, '$GodotRuntime');
+mergeInto(LibraryManager.library, GodotRuntime);
diff --git a/platform/javascript/package-lock.json b/platform/javascript/package-lock.json
new file mode 100644
index 0000000000..8e298a495e
--- /dev/null
+++ b/platform/javascript/package-lock.json
@@ -0,0 +1,1605 @@
+{
+ "name": "godot",
+ "version": "1.0.0",
+ "lockfileVersion": 1,
+ "requires": true,
+ "dependencies": {
+ "@babel/code-frame": {
+ "version": "7.10.4",
+ "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.4.tgz",
+ "integrity": "sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==",
+ "dev": true,
+ "requires": {
+ "@babel/highlight": "^7.10.4"
+ }
+ },
+ "@babel/helper-validator-identifier": {
+ "version": "7.10.4",
+ "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.4.tgz",
+ "integrity": "sha512-3U9y+43hz7ZM+rzG24Qe2mufW5KhvFg/NhnNph+i9mgCtdTCtMJuI1TMkrIUiK7Ix4PYlRF9I5dhqaLYA/ADXw==",
+ "dev": true
+ },
+ "@babel/highlight": {
+ "version": "7.10.4",
+ "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.10.4.tgz",
+ "integrity": "sha512-i6rgnR/YgPEQzZZnbTHHuZdlE8qyoBNalD6F+q4vAFlcMEcqmkoG+mPqJYJCo63qPf74+Y1UZsl3l6f7/RIkmA==",
+ "dev": true,
+ "requires": {
+ "@babel/helper-validator-identifier": "^7.10.4",
+ "chalk": "^2.0.0",
+ "js-tokens": "^4.0.0"
+ },
+ "dependencies": {
+ "chalk": {
+ "version": "2.4.2",
+ "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
+ "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
+ "dev": true,
+ "requires": {
+ "ansi-styles": "^3.2.1",
+ "escape-string-regexp": "^1.0.5",
+ "supports-color": "^5.3.0"
+ }
+ }
+ }
+ },
+ "@eslint/eslintrc": {
+ "version": "0.1.3",
+ "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.1.3.tgz",
+ "integrity": "sha512-4YVwPkANLeNtRjMekzux1ci8hIaH5eGKktGqR0d3LWsKNn5B2X/1Z6Trxy7jQXl9EBGE6Yj02O+t09FMeRllaA==",
+ "dev": true,
+ "requires": {
+ "ajv": "^6.12.4",
+ "debug": "^4.1.1",
+ "espree": "^7.3.0",
+ "globals": "^12.1.0",
+ "ignore": "^4.0.6",
+ "import-fresh": "^3.2.1",
+ "js-yaml": "^3.13.1",
+ "lodash": "^4.17.19",
+ "minimatch": "^3.0.4",
+ "strip-json-comments": "^3.1.1"
+ }
+ },
+ "@types/color-name": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
+ "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==",
+ "dev": true
+ },
+ "@types/json5": {
+ "version": "0.0.29",
+ "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz",
+ "integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=",
+ "dev": true
+ },
+ "acorn": {
+ "version": "7.4.0",
+ "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.0.tgz",
+ "integrity": "sha512-+G7P8jJmCHr+S+cLfQxygbWhXy+8YTVGzAkpEbcLo2mLoL7tij/VG41QSHACSf5QgYRhMZYHuNc6drJaO0Da+w==",
+ "dev": true
+ },
+ "acorn-jsx": {
+ "version": "5.3.1",
+ "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.1.tgz",
+ "integrity": "sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng==",
+ "dev": true
+ },
+ "ajv": {
+ "version": "6.12.5",
+ "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.5.tgz",
+ "integrity": "sha512-lRF8RORchjpKG50/WFf8xmg7sgCLFiYNNnqdKflk63whMQcWR5ngGjiSXkL9bjxy6B2npOK2HSMN49jEBMSkag==",
+ "dev": true,
+ "requires": {
+ "fast-deep-equal": "^3.1.1",
+ "fast-json-stable-stringify": "^2.0.0",
+ "json-schema-traverse": "^0.4.1",
+ "uri-js": "^4.2.2"
+ }
+ },
+ "ansi-colors": {
+ "version": "4.1.1",
+ "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz",
+ "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==",
+ "dev": true
+ },
+ "ansi-regex": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
+ "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
+ "dev": true
+ },
+ "ansi-styles": {
+ "version": "3.2.1",
+ "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
+ "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
+ "dev": true,
+ "requires": {
+ "color-convert": "^1.9.0"
+ }
+ },
+ "argparse": {
+ "version": "1.0.10",
+ "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
+ "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
+ "dev": true,
+ "requires": {
+ "sprintf-js": "~1.0.2"
+ }
+ },
+ "array-includes": {
+ "version": "3.1.1",
+ "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.1.tgz",
+ "integrity": "sha512-c2VXaCHl7zPsvpkFsw4nxvFie4fh1ur9bpcgsVkIjqn0H/Xwdg+7fv3n2r/isyS8EBj5b06M9kHyZuIr4El6WQ==",
+ "dev": true,
+ "requires": {
+ "define-properties": "^1.1.3",
+ "es-abstract": "^1.17.0",
+ "is-string": "^1.0.5"
+ },
+ "dependencies": {
+ "es-abstract": {
+ "version": "1.17.6",
+ "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.6.tgz",
+ "integrity": "sha512-Fr89bON3WFyUi5EvAeI48QTWX0AyekGgLA8H+c+7fbfCkJwRWRMLd8CQedNEyJuoYYhmtEqY92pgte1FAhBlhw==",
+ "dev": true,
+ "requires": {
+ "es-to-primitive": "^1.2.1",
+ "function-bind": "^1.1.1",
+ "has": "^1.0.3",
+ "has-symbols": "^1.0.1",
+ "is-callable": "^1.2.0",
+ "is-regex": "^1.1.0",
+ "object-inspect": "^1.7.0",
+ "object-keys": "^1.1.1",
+ "object.assign": "^4.1.0",
+ "string.prototype.trimend": "^1.0.1",
+ "string.prototype.trimstart": "^1.0.1"
+ }
+ }
+ }
+ },
+ "array.prototype.flat": {
+ "version": "1.2.3",
+ "resolved": "https://registry.npmjs.org/array.prototype.flat/-/array.prototype.flat-1.2.3.tgz",
+ "integrity": "sha512-gBlRZV0VSmfPIeWfuuy56XZMvbVfbEUnOXUvt3F/eUUUSyzlgLxhEX4YAEpxNAogRGehPSnfXyPtYyKAhkzQhQ==",
+ "dev": true,
+ "requires": {
+ "define-properties": "^1.1.3",
+ "es-abstract": "^1.17.0-next.1"
+ },
+ "dependencies": {
+ "es-abstract": {
+ "version": "1.17.6",
+ "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.6.tgz",
+ "integrity": "sha512-Fr89bON3WFyUi5EvAeI48QTWX0AyekGgLA8H+c+7fbfCkJwRWRMLd8CQedNEyJuoYYhmtEqY92pgte1FAhBlhw==",
+ "dev": true,
+ "requires": {
+ "es-to-primitive": "^1.2.1",
+ "function-bind": "^1.1.1",
+ "has": "^1.0.3",
+ "has-symbols": "^1.0.1",
+ "is-callable": "^1.2.0",
+ "is-regex": "^1.1.0",
+ "object-inspect": "^1.7.0",
+ "object-keys": "^1.1.1",
+ "object.assign": "^4.1.0",
+ "string.prototype.trimend": "^1.0.1",
+ "string.prototype.trimstart": "^1.0.1"
+ }
+ }
+ }
+ },
+ "astral-regex": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz",
+ "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==",
+ "dev": true
+ },
+ "balanced-match": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
+ "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
+ "dev": true
+ },
+ "brace-expansion": {
+ "version": "1.1.11",
+ "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
+ "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
+ "dev": true,
+ "requires": {
+ "balanced-match": "^1.0.0",
+ "concat-map": "0.0.1"
+ }
+ },
+ "callsites": {
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz",
+ "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==",
+ "dev": true
+ },
+ "chalk": {
+ "version": "4.1.0",
+ "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz",
+ "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==",
+ "dev": true,
+ "requires": {
+ "ansi-styles": "^4.1.0",
+ "supports-color": "^7.1.0"
+ },
+ "dependencies": {
+ "ansi-styles": {
+ "version": "4.2.1",
+ "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz",
+ "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==",
+ "dev": true,
+ "requires": {
+ "@types/color-name": "^1.1.1",
+ "color-convert": "^2.0.1"
+ }
+ },
+ "color-convert": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
+ "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
+ "dev": true,
+ "requires": {
+ "color-name": "~1.1.4"
+ }
+ },
+ "color-name": {
+ "version": "1.1.4",
+ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
+ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
+ "dev": true
+ },
+ "has-flag": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
+ "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
+ "dev": true
+ },
+ "supports-color": {
+ "version": "7.2.0",
+ "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
+ "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
+ "dev": true,
+ "requires": {
+ "has-flag": "^4.0.0"
+ }
+ }
+ }
+ },
+ "color-convert": {
+ "version": "1.9.3",
+ "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
+ "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
+ "dev": true,
+ "requires": {
+ "color-name": "1.1.3"
+ }
+ },
+ "color-name": {
+ "version": "1.1.3",
+ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
+ "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
+ "dev": true
+ },
+ "concat-map": {
+ "version": "0.0.1",
+ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
+ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
+ "dev": true
+ },
+ "confusing-browser-globals": {
+ "version": "1.0.9",
+ "resolved": "https://registry.npmjs.org/confusing-browser-globals/-/confusing-browser-globals-1.0.9.tgz",
+ "integrity": "sha512-KbS1Y0jMtyPgIxjO7ZzMAuUpAKMt1SzCL9fsrKsX6b0zJPTaT0SiSPmewwVZg9UAO83HVIlEhZF84LIjZ0lmAw==",
+ "dev": true
+ },
+ "contains-path": {
+ "version": "0.1.0",
+ "resolved": "https://registry.npmjs.org/contains-path/-/contains-path-0.1.0.tgz",
+ "integrity": "sha1-/ozxhP9mcLa67wGp1IYaXL7EEgo=",
+ "dev": true
+ },
+ "cross-spawn": {
+ "version": "7.0.3",
+ "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
+ "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==",
+ "dev": true,
+ "requires": {
+ "path-key": "^3.1.0",
+ "shebang-command": "^2.0.0",
+ "which": "^2.0.1"
+ }
+ },
+ "debug": {
+ "version": "4.1.1",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
+ "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
+ "dev": true,
+ "requires": {
+ "ms": "^2.1.1"
+ }
+ },
+ "deep-is": {
+ "version": "0.1.3",
+ "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz",
+ "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=",
+ "dev": true
+ },
+ "define-properties": {
+ "version": "1.1.3",
+ "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz",
+ "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==",
+ "dev": true,
+ "requires": {
+ "object-keys": "^1.0.12"
+ }
+ },
+ "doctrine": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz",
+ "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==",
+ "dev": true,
+ "requires": {
+ "esutils": "^2.0.2"
+ }
+ },
+ "emoji-regex": {
+ "version": "7.0.3",
+ "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz",
+ "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==",
+ "dev": true
+ },
+ "enquirer": {
+ "version": "2.3.6",
+ "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz",
+ "integrity": "sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==",
+ "dev": true,
+ "requires": {
+ "ansi-colors": "^4.1.1"
+ }
+ },
+ "error-ex": {
+ "version": "1.3.2",
+ "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz",
+ "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==",
+ "dev": true,
+ "requires": {
+ "is-arrayish": "^0.2.1"
+ }
+ },
+ "es-abstract": {
+ "version": "1.18.0-next.0",
+ "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.0-next.0.tgz",
+ "integrity": "sha512-elZXTZXKn51hUBdJjSZGYRujuzilgXo8vSPQzjGYXLvSlGiCo8VO8ZGV3kjo9a0WNJJ57hENagwbtlRuHuzkcQ==",
+ "dev": true,
+ "requires": {
+ "es-to-primitive": "^1.2.1",
+ "function-bind": "^1.1.1",
+ "has": "^1.0.3",
+ "has-symbols": "^1.0.1",
+ "is-callable": "^1.2.0",
+ "is-negative-zero": "^2.0.0",
+ "is-regex": "^1.1.1",
+ "object-inspect": "^1.8.0",
+ "object-keys": "^1.1.1",
+ "object.assign": "^4.1.0",
+ "string.prototype.trimend": "^1.0.1",
+ "string.prototype.trimstart": "^1.0.1"
+ }
+ },
+ "es-to-primitive": {
+ "version": "1.2.1",
+ "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz",
+ "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==",
+ "dev": true,
+ "requires": {
+ "is-callable": "^1.1.4",
+ "is-date-object": "^1.0.1",
+ "is-symbol": "^1.0.2"
+ }
+ },
+ "escape-string-regexp": {
+ "version": "1.0.5",
+ "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
+ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
+ "dev": true
+ },
+ "eslint": {
+ "version": "7.9.0",
+ "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.9.0.tgz",
+ "integrity": "sha512-V6QyhX21+uXp4T+3nrNfI3hQNBDa/P8ga7LoQOenwrlEFXrEnUEE+ok1dMtaS3b6rmLXhT1TkTIsG75HMLbknA==",
+ "dev": true,
+ "requires": {
+ "@babel/code-frame": "^7.0.0",
+ "@eslint/eslintrc": "^0.1.3",
+ "ajv": "^6.10.0",
+ "chalk": "^4.0.0",
+ "cross-spawn": "^7.0.2",
+ "debug": "^4.0.1",
+ "doctrine": "^3.0.0",
+ "enquirer": "^2.3.5",
+ "eslint-scope": "^5.1.0",
+ "eslint-utils": "^2.1.0",
+ "eslint-visitor-keys": "^1.3.0",
+ "espree": "^7.3.0",
+ "esquery": "^1.2.0",
+ "esutils": "^2.0.2",
+ "file-entry-cache": "^5.0.1",
+ "functional-red-black-tree": "^1.0.1",
+ "glob-parent": "^5.0.0",
+ "globals": "^12.1.0",
+ "ignore": "^4.0.6",
+ "import-fresh": "^3.0.0",
+ "imurmurhash": "^0.1.4",
+ "is-glob": "^4.0.0",
+ "js-yaml": "^3.13.1",
+ "json-stable-stringify-without-jsonify": "^1.0.1",
+ "levn": "^0.4.1",
+ "lodash": "^4.17.19",
+ "minimatch": "^3.0.4",
+ "natural-compare": "^1.4.0",
+ "optionator": "^0.9.1",
+ "progress": "^2.0.0",
+ "regexpp": "^3.1.0",
+ "semver": "^7.2.1",
+ "strip-ansi": "^6.0.0",
+ "strip-json-comments": "^3.1.0",
+ "table": "^5.2.3",
+ "text-table": "^0.2.0",
+ "v8-compile-cache": "^2.0.3"
+ }
+ },
+ "eslint-config-airbnb-base": {
+ "version": "14.2.0",
+ "resolved": "https://registry.npmjs.org/eslint-config-airbnb-base/-/eslint-config-airbnb-base-14.2.0.tgz",
+ "integrity": "sha512-Snswd5oC6nJaevs3nZoLSTvGJBvzTfnBqOIArkf3cbyTyq9UD79wOk8s+RiL6bhca0p/eRO6veczhf6A/7Jy8Q==",
+ "dev": true,
+ "requires": {
+ "confusing-browser-globals": "^1.0.9",
+ "object.assign": "^4.1.0",
+ "object.entries": "^1.1.2"
+ }
+ },
+ "eslint-import-resolver-node": {
+ "version": "0.3.4",
+ "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.4.tgz",
+ "integrity": "sha512-ogtf+5AB/O+nM6DIeBUNr2fuT7ot9Qg/1harBfBtaP13ekEWFQEEMP94BCB7zaNW3gyY+8SHYF00rnqYwXKWOA==",
+ "dev": true,
+ "requires": {
+ "debug": "^2.6.9",
+ "resolve": "^1.13.1"
+ },
+ "dependencies": {
+ "debug": {
+ "version": "2.6.9",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
+ "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
+ "dev": true,
+ "requires": {
+ "ms": "2.0.0"
+ }
+ },
+ "ms": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
+ "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
+ "dev": true
+ }
+ }
+ },
+ "eslint-module-utils": {
+ "version": "2.6.0",
+ "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.6.0.tgz",
+ "integrity": "sha512-6j9xxegbqe8/kZY8cYpcp0xhbK0EgJlg3g9mib3/miLaExuuwc3n5UEfSnU6hWMbT0FAYVvDbL9RrRgpUeQIvA==",
+ "dev": true,
+ "requires": {
+ "debug": "^2.6.9",
+ "pkg-dir": "^2.0.0"
+ },
+ "dependencies": {
+ "debug": {
+ "version": "2.6.9",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
+ "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
+ "dev": true,
+ "requires": {
+ "ms": "2.0.0"
+ }
+ },
+ "ms": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
+ "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
+ "dev": true
+ }
+ }
+ },
+ "eslint-plugin-import": {
+ "version": "2.22.0",
+ "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.22.0.tgz",
+ "integrity": "sha512-66Fpf1Ln6aIS5Gr/55ts19eUuoDhAbZgnr6UxK5hbDx6l/QgQgx61AePq+BV4PP2uXQFClgMVzep5zZ94qqsxg==",
+ "dev": true,
+ "requires": {
+ "array-includes": "^3.1.1",
+ "array.prototype.flat": "^1.2.3",
+ "contains-path": "^0.1.0",
+ "debug": "^2.6.9",
+ "doctrine": "1.5.0",
+ "eslint-import-resolver-node": "^0.3.3",
+ "eslint-module-utils": "^2.6.0",
+ "has": "^1.0.3",
+ "minimatch": "^3.0.4",
+ "object.values": "^1.1.1",
+ "read-pkg-up": "^2.0.0",
+ "resolve": "^1.17.0",
+ "tsconfig-paths": "^3.9.0"
+ },
+ "dependencies": {
+ "debug": {
+ "version": "2.6.9",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
+ "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
+ "dev": true,
+ "requires": {
+ "ms": "2.0.0"
+ }
+ },
+ "doctrine": {
+ "version": "1.5.0",
+ "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz",
+ "integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=",
+ "dev": true,
+ "requires": {
+ "esutils": "^2.0.2",
+ "isarray": "^1.0.0"
+ }
+ },
+ "ms": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
+ "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
+ "dev": true
+ }
+ }
+ },
+ "eslint-scope": {
+ "version": "5.1.1",
+ "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz",
+ "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==",
+ "dev": true,
+ "requires": {
+ "esrecurse": "^4.3.0",
+ "estraverse": "^4.1.1"
+ }
+ },
+ "eslint-utils": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.1.0.tgz",
+ "integrity": "sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg==",
+ "dev": true,
+ "requires": {
+ "eslint-visitor-keys": "^1.1.0"
+ }
+ },
+ "eslint-visitor-keys": {
+ "version": "1.3.0",
+ "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz",
+ "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==",
+ "dev": true
+ },
+ "espree": {
+ "version": "7.3.0",
+ "resolved": "https://registry.npmjs.org/espree/-/espree-7.3.0.tgz",
+ "integrity": "sha512-dksIWsvKCixn1yrEXO8UosNSxaDoSYpq9reEjZSbHLpT5hpaCAKTLBwq0RHtLrIr+c0ByiYzWT8KTMRzoRCNlw==",
+ "dev": true,
+ "requires": {
+ "acorn": "^7.4.0",
+ "acorn-jsx": "^5.2.0",
+ "eslint-visitor-keys": "^1.3.0"
+ }
+ },
+ "esprima": {
+ "version": "4.0.1",
+ "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
+ "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",
+ "dev": true
+ },
+ "esquery": {
+ "version": "1.3.1",
+ "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.3.1.tgz",
+ "integrity": "sha512-olpvt9QG0vniUBZspVRN6lwB7hOZoTRtT+jzR+tS4ffYx2mzbw+z0XCOk44aaLYKApNX5nMm+E+P6o25ip/DHQ==",
+ "dev": true,
+ "requires": {
+ "estraverse": "^5.1.0"
+ },
+ "dependencies": {
+ "estraverse": {
+ "version": "5.2.0",
+ "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.2.0.tgz",
+ "integrity": "sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ==",
+ "dev": true
+ }
+ }
+ },
+ "esrecurse": {
+ "version": "4.3.0",
+ "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz",
+ "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==",
+ "dev": true,
+ "requires": {
+ "estraverse": "^5.2.0"
+ },
+ "dependencies": {
+ "estraverse": {
+ "version": "5.2.0",
+ "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.2.0.tgz",
+ "integrity": "sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ==",
+ "dev": true
+ }
+ }
+ },
+ "estraverse": {
+ "version": "4.3.0",
+ "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz",
+ "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==",
+ "dev": true
+ },
+ "esutils": {
+ "version": "2.0.3",
+ "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz",
+ "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==",
+ "dev": true
+ },
+ "fast-deep-equal": {
+ "version": "3.1.3",
+ "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
+ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
+ "dev": true
+ },
+ "fast-json-stable-stringify": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",
+ "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==",
+ "dev": true
+ },
+ "fast-levenshtein": {
+ "version": "2.0.6",
+ "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz",
+ "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=",
+ "dev": true
+ },
+ "file-entry-cache": {
+ "version": "5.0.1",
+ "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-5.0.1.tgz",
+ "integrity": "sha512-bCg29ictuBaKUwwArK4ouCaqDgLZcysCFLmM/Yn/FDoqndh/9vNuQfXRDvTuXKLxfD/JtZQGKFT8MGcJBK644g==",
+ "dev": true,
+ "requires": {
+ "flat-cache": "^2.0.1"
+ }
+ },
+ "find-up": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz",
+ "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=",
+ "dev": true,
+ "requires": {
+ "locate-path": "^2.0.0"
+ }
+ },
+ "flat-cache": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-2.0.1.tgz",
+ "integrity": "sha512-LoQe6yDuUMDzQAEH8sgmh4Md6oZnc/7PjtwjNFSzveXqSHt6ka9fPBuso7IGf9Rz4uqnSnWiFH2B/zj24a5ReA==",
+ "dev": true,
+ "requires": {
+ "flatted": "^2.0.0",
+ "rimraf": "2.6.3",
+ "write": "1.0.3"
+ }
+ },
+ "flatted": {
+ "version": "2.0.2",
+ "resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.2.tgz",
+ "integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==",
+ "dev": true
+ },
+ "fs.realpath": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
+ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
+ "dev": true
+ },
+ "function-bind": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
+ "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
+ "dev": true
+ },
+ "functional-red-black-tree": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz",
+ "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=",
+ "dev": true
+ },
+ "glob": {
+ "version": "7.1.6",
+ "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
+ "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
+ "dev": true,
+ "requires": {
+ "fs.realpath": "^1.0.0",
+ "inflight": "^1.0.4",
+ "inherits": "2",
+ "minimatch": "^3.0.4",
+ "once": "^1.3.0",
+ "path-is-absolute": "^1.0.0"
+ }
+ },
+ "glob-parent": {
+ "version": "5.1.1",
+ "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz",
+ "integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==",
+ "dev": true,
+ "requires": {
+ "is-glob": "^4.0.1"
+ }
+ },
+ "globals": {
+ "version": "12.4.0",
+ "resolved": "https://registry.npmjs.org/globals/-/globals-12.4.0.tgz",
+ "integrity": "sha512-BWICuzzDvDoH54NHKCseDanAhE3CeDorgDL5MT6LMXXj2WCnd9UC2szdk4AWLfjdgNBCXLUanXYcpBBKOSWGwg==",
+ "dev": true,
+ "requires": {
+ "type-fest": "^0.8.1"
+ }
+ },
+ "graceful-fs": {
+ "version": "4.2.4",
+ "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz",
+ "integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==",
+ "dev": true
+ },
+ "has": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
+ "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
+ "dev": true,
+ "requires": {
+ "function-bind": "^1.1.1"
+ }
+ },
+ "has-flag": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
+ "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
+ "dev": true
+ },
+ "has-symbols": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz",
+ "integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg==",
+ "dev": true
+ },
+ "hosted-git-info": {
+ "version": "2.8.8",
+ "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz",
+ "integrity": "sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==",
+ "dev": true
+ },
+ "ignore": {
+ "version": "4.0.6",
+ "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz",
+ "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==",
+ "dev": true
+ },
+ "import-fresh": {
+ "version": "3.2.1",
+ "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.2.1.tgz",
+ "integrity": "sha512-6e1q1cnWP2RXD9/keSkxHScg508CdXqXWgWBaETNhyuBFz+kUZlKboh+ISK+bU++DmbHimVBrOz/zzPe0sZ3sQ==",
+ "dev": true,
+ "requires": {
+ "parent-module": "^1.0.0",
+ "resolve-from": "^4.0.0"
+ }
+ },
+ "imurmurhash": {
+ "version": "0.1.4",
+ "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz",
+ "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=",
+ "dev": true
+ },
+ "inflight": {
+ "version": "1.0.6",
+ "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
+ "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
+ "dev": true,
+ "requires": {
+ "once": "^1.3.0",
+ "wrappy": "1"
+ }
+ },
+ "inherits": {
+ "version": "2.0.4",
+ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
+ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
+ "dev": true
+ },
+ "is-arrayish": {
+ "version": "0.2.1",
+ "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz",
+ "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=",
+ "dev": true
+ },
+ "is-callable": {
+ "version": "1.2.1",
+ "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.1.tgz",
+ "integrity": "sha512-wliAfSzx6V+6WfMOmus1xy0XvSgf/dlStkvTfq7F0g4bOIW0PSUbnyse3NhDwdyYS1ozfUtAAySqTws3z9Eqgg==",
+ "dev": true
+ },
+ "is-date-object": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.2.tgz",
+ "integrity": "sha512-USlDT524woQ08aoZFzh3/Z6ch9Y/EWXEHQ/AaRN0SkKq4t2Jw2R2339tSXmwuVoY7LLlBCbOIlx2myP/L5zk0g==",
+ "dev": true
+ },
+ "is-extglob": {
+ "version": "2.1.1",
+ "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
+ "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=",
+ "dev": true
+ },
+ "is-fullwidth-code-point": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
+ "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=",
+ "dev": true
+ },
+ "is-glob": {
+ "version": "4.0.1",
+ "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz",
+ "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==",
+ "dev": true,
+ "requires": {
+ "is-extglob": "^2.1.1"
+ }
+ },
+ "is-negative-zero": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.0.tgz",
+ "integrity": "sha1-lVOxIbD6wohp2p7UWeIMdUN4hGE=",
+ "dev": true
+ },
+ "is-regex": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.1.tgz",
+ "integrity": "sha512-1+QkEcxiLlB7VEyFtyBg94e08OAsvq7FUBgApTq/w2ymCLyKJgDPsybBENVtA7XCQEgEXxKPonG+mvYRxh/LIg==",
+ "dev": true,
+ "requires": {
+ "has-symbols": "^1.0.1"
+ }
+ },
+ "is-string": {
+ "version": "1.0.5",
+ "resolved": "https://registry.npmjs.org/is-string/-/is-string-1.0.5.tgz",
+ "integrity": "sha512-buY6VNRjhQMiF1qWDouloZlQbRhDPCebwxSjxMjxgemYT46YMd2NR0/H+fBhEfWX4A/w9TBJ+ol+okqJKFE6vQ==",
+ "dev": true
+ },
+ "is-symbol": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.3.tgz",
+ "integrity": "sha512-OwijhaRSgqvhm/0ZdAcXNZt9lYdKFpcRDT5ULUuYXPoT794UNOdU+gpT6Rzo7b4V2HUl/op6GqY894AZwv9faQ==",
+ "dev": true,
+ "requires": {
+ "has-symbols": "^1.0.1"
+ }
+ },
+ "isarray": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
+ "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=",
+ "dev": true
+ },
+ "isexe": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
+ "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=",
+ "dev": true
+ },
+ "js-tokens": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
+ "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
+ "dev": true
+ },
+ "js-yaml": {
+ "version": "3.14.0",
+ "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.0.tgz",
+ "integrity": "sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A==",
+ "dev": true,
+ "requires": {
+ "argparse": "^1.0.7",
+ "esprima": "^4.0.0"
+ }
+ },
+ "json-schema-traverse": {
+ "version": "0.4.1",
+ "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
+ "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==",
+ "dev": true
+ },
+ "json-stable-stringify-without-jsonify": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz",
+ "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=",
+ "dev": true
+ },
+ "json5": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz",
+ "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==",
+ "dev": true,
+ "requires": {
+ "minimist": "^1.2.0"
+ }
+ },
+ "levn": {
+ "version": "0.4.1",
+ "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz",
+ "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==",
+ "dev": true,
+ "requires": {
+ "prelude-ls": "^1.2.1",
+ "type-check": "~0.4.0"
+ }
+ },
+ "load-json-file": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz",
+ "integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=",
+ "dev": true,
+ "requires": {
+ "graceful-fs": "^4.1.2",
+ "parse-json": "^2.2.0",
+ "pify": "^2.0.0",
+ "strip-bom": "^3.0.0"
+ }
+ },
+ "locate-path": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz",
+ "integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=",
+ "dev": true,
+ "requires": {
+ "p-locate": "^2.0.0",
+ "path-exists": "^3.0.0"
+ }
+ },
+ "lodash": {
+ "version": "4.17.20",
+ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz",
+ "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==",
+ "dev": true
+ },
+ "minimatch": {
+ "version": "3.0.4",
+ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
+ "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
+ "dev": true,
+ "requires": {
+ "brace-expansion": "^1.1.7"
+ }
+ },
+ "minimist": {
+ "version": "1.2.5",
+ "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
+ "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
+ "dev": true
+ },
+ "mkdirp": {
+ "version": "0.5.5",
+ "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
+ "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
+ "dev": true,
+ "requires": {
+ "minimist": "^1.2.5"
+ }
+ },
+ "ms": {
+ "version": "2.1.2",
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
+ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
+ "dev": true
+ },
+ "natural-compare": {
+ "version": "1.4.0",
+ "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
+ "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=",
+ "dev": true
+ },
+ "normalize-package-data": {
+ "version": "2.5.0",
+ "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz",
+ "integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==",
+ "dev": true,
+ "requires": {
+ "hosted-git-info": "^2.1.4",
+ "resolve": "^1.10.0",
+ "semver": "2 || 3 || 4 || 5",
+ "validate-npm-package-license": "^3.0.1"
+ },
+ "dependencies": {
+ "semver": {
+ "version": "5.7.1",
+ "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz",
+ "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==",
+ "dev": true
+ }
+ }
+ },
+ "object-inspect": {
+ "version": "1.8.0",
+ "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.8.0.tgz",
+ "integrity": "sha512-jLdtEOB112fORuypAyl/50VRVIBIdVQOSUUGQHzJ4xBSbit81zRarz7GThkEFZy1RceYrWYcPcBFPQwHyAc1gA==",
+ "dev": true
+ },
+ "object-keys": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz",
+ "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==",
+ "dev": true
+ },
+ "object.assign": {
+ "version": "4.1.1",
+ "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.1.tgz",
+ "integrity": "sha512-VT/cxmx5yaoHSOTSyrCygIDFco+RsibY2NM0a4RdEeY/4KgqezwFtK1yr3U67xYhqJSlASm2pKhLVzPj2lr4bA==",
+ "dev": true,
+ "requires": {
+ "define-properties": "^1.1.3",
+ "es-abstract": "^1.18.0-next.0",
+ "has-symbols": "^1.0.1",
+ "object-keys": "^1.1.1"
+ }
+ },
+ "object.entries": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/object.entries/-/object.entries-1.1.2.tgz",
+ "integrity": "sha512-BQdB9qKmb/HyNdMNWVr7O3+z5MUIx3aiegEIJqjMBbBf0YT9RRxTJSim4mzFqtyr7PDAHigq0N9dO0m0tRakQA==",
+ "dev": true,
+ "requires": {
+ "define-properties": "^1.1.3",
+ "es-abstract": "^1.17.5",
+ "has": "^1.0.3"
+ },
+ "dependencies": {
+ "es-abstract": {
+ "version": "1.17.6",
+ "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.6.tgz",
+ "integrity": "sha512-Fr89bON3WFyUi5EvAeI48QTWX0AyekGgLA8H+c+7fbfCkJwRWRMLd8CQedNEyJuoYYhmtEqY92pgte1FAhBlhw==",
+ "dev": true,
+ "requires": {
+ "es-to-primitive": "^1.2.1",
+ "function-bind": "^1.1.1",
+ "has": "^1.0.3",
+ "has-symbols": "^1.0.1",
+ "is-callable": "^1.2.0",
+ "is-regex": "^1.1.0",
+ "object-inspect": "^1.7.0",
+ "object-keys": "^1.1.1",
+ "object.assign": "^4.1.0",
+ "string.prototype.trimend": "^1.0.1",
+ "string.prototype.trimstart": "^1.0.1"
+ }
+ }
+ }
+ },
+ "object.values": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/object.values/-/object.values-1.1.1.tgz",
+ "integrity": "sha512-WTa54g2K8iu0kmS/us18jEmdv1a4Wi//BZ/DTVYEcH0XhLM5NYdpDHja3gt57VrZLcNAO2WGA+KpWsDBaHt6eA==",
+ "dev": true,
+ "requires": {
+ "define-properties": "^1.1.3",
+ "es-abstract": "^1.17.0-next.1",
+ "function-bind": "^1.1.1",
+ "has": "^1.0.3"
+ },
+ "dependencies": {
+ "es-abstract": {
+ "version": "1.17.6",
+ "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.6.tgz",
+ "integrity": "sha512-Fr89bON3WFyUi5EvAeI48QTWX0AyekGgLA8H+c+7fbfCkJwRWRMLd8CQedNEyJuoYYhmtEqY92pgte1FAhBlhw==",
+ "dev": true,
+ "requires": {
+ "es-to-primitive": "^1.2.1",
+ "function-bind": "^1.1.1",
+ "has": "^1.0.3",
+ "has-symbols": "^1.0.1",
+ "is-callable": "^1.2.0",
+ "is-regex": "^1.1.0",
+ "object-inspect": "^1.7.0",
+ "object-keys": "^1.1.1",
+ "object.assign": "^4.1.0",
+ "string.prototype.trimend": "^1.0.1",
+ "string.prototype.trimstart": "^1.0.1"
+ }
+ }
+ }
+ },
+ "once": {
+ "version": "1.4.0",
+ "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
+ "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
+ "dev": true,
+ "requires": {
+ "wrappy": "1"
+ }
+ },
+ "optionator": {
+ "version": "0.9.1",
+ "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz",
+ "integrity": "sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==",
+ "dev": true,
+ "requires": {
+ "deep-is": "^0.1.3",
+ "fast-levenshtein": "^2.0.6",
+ "levn": "^0.4.1",
+ "prelude-ls": "^1.2.1",
+ "type-check": "^0.4.0",
+ "word-wrap": "^1.2.3"
+ }
+ },
+ "p-limit": {
+ "version": "1.3.0",
+ "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz",
+ "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==",
+ "dev": true,
+ "requires": {
+ "p-try": "^1.0.0"
+ }
+ },
+ "p-locate": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz",
+ "integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=",
+ "dev": true,
+ "requires": {
+ "p-limit": "^1.1.0"
+ }
+ },
+ "p-try": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz",
+ "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=",
+ "dev": true
+ },
+ "parent-module": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz",
+ "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==",
+ "dev": true,
+ "requires": {
+ "callsites": "^3.0.0"
+ }
+ },
+ "parse-json": {
+ "version": "2.2.0",
+ "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-2.2.0.tgz",
+ "integrity": "sha1-9ID0BDTvgHQfhGkJn43qGPVaTck=",
+ "dev": true,
+ "requires": {
+ "error-ex": "^1.2.0"
+ }
+ },
+ "path-exists": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz",
+ "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=",
+ "dev": true
+ },
+ "path-is-absolute": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
+ "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
+ "dev": true
+ },
+ "path-key": {
+ "version": "3.1.1",
+ "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
+ "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
+ "dev": true
+ },
+ "path-parse": {
+ "version": "1.0.6",
+ "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz",
+ "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==",
+ "dev": true
+ },
+ "path-type": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/path-type/-/path-type-2.0.0.tgz",
+ "integrity": "sha1-8BLMuEFbcJb8LaoQVMPXI4lZTHM=",
+ "dev": true,
+ "requires": {
+ "pify": "^2.0.0"
+ }
+ },
+ "pify": {
+ "version": "2.3.0",
+ "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
+ "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
+ "dev": true
+ },
+ "pkg-dir": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-2.0.0.tgz",
+ "integrity": "sha1-9tXREJ4Z1j7fQo4L1X4Sd3YVM0s=",
+ "dev": true,
+ "requires": {
+ "find-up": "^2.1.0"
+ }
+ },
+ "prelude-ls": {
+ "version": "1.2.1",
+ "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
+ "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==",
+ "dev": true
+ },
+ "progress": {
+ "version": "2.0.3",
+ "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz",
+ "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==",
+ "dev": true
+ },
+ "punycode": {
+ "version": "2.1.1",
+ "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
+ "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==",
+ "dev": true
+ },
+ "read-pkg": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz",
+ "integrity": "sha1-jvHAYjxqbbDcZxPEv6xGMysjaPg=",
+ "dev": true,
+ "requires": {
+ "load-json-file": "^2.0.0",
+ "normalize-package-data": "^2.3.2",
+ "path-type": "^2.0.0"
+ }
+ },
+ "read-pkg-up": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-2.0.0.tgz",
+ "integrity": "sha1-a3KoBImE4MQeeVEP1en6mbO1Sb4=",
+ "dev": true,
+ "requires": {
+ "find-up": "^2.0.0",
+ "read-pkg": "^2.0.0"
+ }
+ },
+ "regexpp": {
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.1.0.tgz",
+ "integrity": "sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q==",
+ "dev": true
+ },
+ "resolve": {
+ "version": "1.17.0",
+ "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz",
+ "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==",
+ "dev": true,
+ "requires": {
+ "path-parse": "^1.0.6"
+ }
+ },
+ "resolve-from": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz",
+ "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==",
+ "dev": true
+ },
+ "rimraf": {
+ "version": "2.6.3",
+ "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz",
+ "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==",
+ "dev": true,
+ "requires": {
+ "glob": "^7.1.3"
+ }
+ },
+ "semver": {
+ "version": "7.3.2",
+ "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz",
+ "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==",
+ "dev": true
+ },
+ "shebang-command": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
+ "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
+ "dev": true,
+ "requires": {
+ "shebang-regex": "^3.0.0"
+ }
+ },
+ "shebang-regex": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
+ "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
+ "dev": true
+ },
+ "slice-ansi": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz",
+ "integrity": "sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ==",
+ "dev": true,
+ "requires": {
+ "ansi-styles": "^3.2.0",
+ "astral-regex": "^1.0.0",
+ "is-fullwidth-code-point": "^2.0.0"
+ }
+ },
+ "spdx-correct": {
+ "version": "3.1.1",
+ "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.1.tgz",
+ "integrity": "sha512-cOYcUWwhCuHCXi49RhFRCyJEK3iPj1Ziz9DpViV3tbZOwXD49QzIN3MpOLJNxh2qwq2lJJZaKMVw9qNi4jTC0w==",
+ "dev": true,
+ "requires": {
+ "spdx-expression-parse": "^3.0.0",
+ "spdx-license-ids": "^3.0.0"
+ }
+ },
+ "spdx-exceptions": {
+ "version": "2.3.0",
+ "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.3.0.tgz",
+ "integrity": "sha512-/tTrYOC7PPI1nUAgx34hUpqXuyJG+DTHJTnIULG4rDygi4xu/tfgmq1e1cIRwRzwZgo4NLySi+ricLkZkw4i5A==",
+ "dev": true
+ },
+ "spdx-expression-parse": {
+ "version": "3.0.1",
+ "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.1.tgz",
+ "integrity": "sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q==",
+ "dev": true,
+ "requires": {
+ "spdx-exceptions": "^2.1.0",
+ "spdx-license-ids": "^3.0.0"
+ }
+ },
+ "spdx-license-ids": {
+ "version": "3.0.6",
+ "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.6.tgz",
+ "integrity": "sha512-+orQK83kyMva3WyPf59k1+Y525csj5JejicWut55zeTWANuN17qSiSLUXWtzHeNWORSvT7GLDJ/E/XiIWoXBTw==",
+ "dev": true
+ },
+ "sprintf-js": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
+ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
+ "dev": true
+ },
+ "string-width": {
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz",
+ "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==",
+ "dev": true,
+ "requires": {
+ "emoji-regex": "^7.0.1",
+ "is-fullwidth-code-point": "^2.0.0",
+ "strip-ansi": "^5.1.0"
+ },
+ "dependencies": {
+ "ansi-regex": {
+ "version": "4.1.0",
+ "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz",
+ "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==",
+ "dev": true
+ },
+ "strip-ansi": {
+ "version": "5.2.0",
+ "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz",
+ "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==",
+ "dev": true,
+ "requires": {
+ "ansi-regex": "^4.1.0"
+ }
+ }
+ }
+ },
+ "string.prototype.trimend": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.1.tgz",
+ "integrity": "sha512-LRPxFUaTtpqYsTeNKaFOw3R4bxIzWOnbQ837QfBylo8jIxtcbK/A/sMV7Q+OAV/vWo+7s25pOE10KYSjaSO06g==",
+ "dev": true,
+ "requires": {
+ "define-properties": "^1.1.3",
+ "es-abstract": "^1.17.5"
+ },
+ "dependencies": {
+ "es-abstract": {
+ "version": "1.17.6",
+ "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.6.tgz",
+ "integrity": "sha512-Fr89bON3WFyUi5EvAeI48QTWX0AyekGgLA8H+c+7fbfCkJwRWRMLd8CQedNEyJuoYYhmtEqY92pgte1FAhBlhw==",
+ "dev": true,
+ "requires": {
+ "es-to-primitive": "^1.2.1",
+ "function-bind": "^1.1.1",
+ "has": "^1.0.3",
+ "has-symbols": "^1.0.1",
+ "is-callable": "^1.2.0",
+ "is-regex": "^1.1.0",
+ "object-inspect": "^1.7.0",
+ "object-keys": "^1.1.1",
+ "object.assign": "^4.1.0",
+ "string.prototype.trimend": "^1.0.1",
+ "string.prototype.trimstart": "^1.0.1"
+ }
+ }
+ }
+ },
+ "string.prototype.trimstart": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.1.tgz",
+ "integrity": "sha512-XxZn+QpvrBI1FOcg6dIpxUPgWCPuNXvMD72aaRaUQv1eD4e/Qy8i/hFTe0BUmD60p/QA6bh1avmuPTfNjqVWRw==",
+ "dev": true,
+ "requires": {
+ "define-properties": "^1.1.3",
+ "es-abstract": "^1.17.5"
+ },
+ "dependencies": {
+ "es-abstract": {
+ "version": "1.17.6",
+ "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.6.tgz",
+ "integrity": "sha512-Fr89bON3WFyUi5EvAeI48QTWX0AyekGgLA8H+c+7fbfCkJwRWRMLd8CQedNEyJuoYYhmtEqY92pgte1FAhBlhw==",
+ "dev": true,
+ "requires": {
+ "es-to-primitive": "^1.2.1",
+ "function-bind": "^1.1.1",
+ "has": "^1.0.3",
+ "has-symbols": "^1.0.1",
+ "is-callable": "^1.2.0",
+ "is-regex": "^1.1.0",
+ "object-inspect": "^1.7.0",
+ "object-keys": "^1.1.1",
+ "object.assign": "^4.1.0",
+ "string.prototype.trimend": "^1.0.1",
+ "string.prototype.trimstart": "^1.0.1"
+ }
+ }
+ }
+ },
+ "strip-ansi": {
+ "version": "6.0.0",
+ "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz",
+ "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==",
+ "dev": true,
+ "requires": {
+ "ansi-regex": "^5.0.0"
+ }
+ },
+ "strip-bom": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz",
+ "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=",
+ "dev": true
+ },
+ "strip-json-comments": {
+ "version": "3.1.1",
+ "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz",
+ "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==",
+ "dev": true
+ },
+ "supports-color": {
+ "version": "5.5.0",
+ "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
+ "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
+ "dev": true,
+ "requires": {
+ "has-flag": "^3.0.0"
+ }
+ },
+ "table": {
+ "version": "5.4.6",
+ "resolved": "https://registry.npmjs.org/table/-/table-5.4.6.tgz",
+ "integrity": "sha512-wmEc8m4fjnob4gt5riFRtTu/6+4rSe12TpAELNSqHMfF3IqnA+CH37USM6/YR3qRZv7e56kAEAtd6nKZaxe0Ug==",
+ "dev": true,
+ "requires": {
+ "ajv": "^6.10.2",
+ "lodash": "^4.17.14",
+ "slice-ansi": "^2.1.0",
+ "string-width": "^3.0.0"
+ }
+ },
+ "text-table": {
+ "version": "0.2.0",
+ "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz",
+ "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=",
+ "dev": true
+ },
+ "tsconfig-paths": {
+ "version": "3.9.0",
+ "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz",
+ "integrity": "sha512-dRcuzokWhajtZWkQsDVKbWyY+jgcLC5sqJhg2PSgf4ZkH2aHPvaOY8YWGhmjb68b5qqTfasSsDO9k7RUiEmZAw==",
+ "dev": true,
+ "requires": {
+ "@types/json5": "^0.0.29",
+ "json5": "^1.0.1",
+ "minimist": "^1.2.0",
+ "strip-bom": "^3.0.0"
+ }
+ },
+ "type-check": {
+ "version": "0.4.0",
+ "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz",
+ "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==",
+ "dev": true,
+ "requires": {
+ "prelude-ls": "^1.2.1"
+ }
+ },
+ "type-fest": {
+ "version": "0.8.1",
+ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz",
+ "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==",
+ "dev": true
+ },
+ "uri-js": {
+ "version": "4.4.0",
+ "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.0.tgz",
+ "integrity": "sha512-B0yRTzYdUCCn9n+F4+Gh4yIDtMQcaJsmYBDsTSG8g/OejKBodLQ2IHfN3bM7jUsRXndopT7OIXWdYqc1fjmV6g==",
+ "dev": true,
+ "requires": {
+ "punycode": "^2.1.0"
+ }
+ },
+ "v8-compile-cache": {
+ "version": "2.1.1",
+ "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.1.1.tgz",
+ "integrity": "sha512-8OQ9CL+VWyt3JStj7HX7/ciTL2V3Rl1Wf5OL+SNTm0yK1KvtReVulksyeRnCANHHuUxHlQig+JJDlUhBt1NQDQ==",
+ "dev": true
+ },
+ "validate-npm-package-license": {
+ "version": "3.0.4",
+ "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz",
+ "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==",
+ "dev": true,
+ "requires": {
+ "spdx-correct": "^3.0.0",
+ "spdx-expression-parse": "^3.0.0"
+ }
+ },
+ "which": {
+ "version": "2.0.2",
+ "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
+ "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
+ "dev": true,
+ "requires": {
+ "isexe": "^2.0.0"
+ }
+ },
+ "word-wrap": {
+ "version": "1.2.3",
+ "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
+ "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==",
+ "dev": true
+ },
+ "wrappy": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
+ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
+ "dev": true
+ },
+ "write": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/write/-/write-1.0.3.tgz",
+ "integrity": "sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig==",
+ "dev": true,
+ "requires": {
+ "mkdirp": "^0.5.1"
+ }
+ }
+ }
+}
diff --git a/platform/javascript/package.json b/platform/javascript/package.json
new file mode 100644
index 0000000000..630b584f5b
--- /dev/null
+++ b/platform/javascript/package.json
@@ -0,0 +1,24 @@
+{
+ "name": "godot",
+ "private": true,
+ "version": "1.0.0",
+ "description": "Linting setup for Godot's HTML5 platform code",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1",
+ "lint": "npm run lint:engine && npm run lint:libs && npm run lint:modules",
+ "lint:engine": "eslint \"js/engine/*.js\" --no-eslintrc -c .eslintrc.engine.js",
+ "lint:libs": "eslint \"js/libs/*.js\" --no-eslintrc -c .eslintrc.libs.js",
+ "lint:modules": "eslint \"../../modules/**/*.js\" --no-eslintrc -c .eslintrc.libs.js",
+ "format": "npm run format:engine && npm run format:libs && npm run format:modules",
+ "format:engine": "npm run lint:engine -- --fix",
+ "format:libs": "npm run lint:libs -- --fix",
+ "format:modules": "npm run lint:modules -- --fix"
+ },
+ "author": "Godot Engine contributors",
+ "license": "MIT",
+ "devDependencies": {
+ "eslint": "^7.9.0",
+ "eslint-config-airbnb-base": "^14.2.0",
+ "eslint-plugin-import": "^2.22.0"
+ }
+}
diff --git a/platform/linuxbsd/detect.py b/platform/linuxbsd/detect.py
index a1bc5867c5..a8bc3a09f6 100644
--- a/platform/linuxbsd/detect.py
+++ b/platform/linuxbsd/detect.py
@@ -129,7 +129,6 @@ def configure(env):
if "clang++" not in os.path.basename(env["CXX"]):
env["CC"] = "clang"
env["CXX"] = "clang++"
- env.Append(CPPDEFINES=["TYPED_METHOD_BIND"])
env.extra_suffix = ".llvm" + env.extra_suffix
if env["use_lld"]:
diff --git a/platform/server/detect.py b/platform/server/detect.py
index a3f60b0710..d9ac357679 100644
--- a/platform/server/detect.py
+++ b/platform/server/detect.py
@@ -94,7 +94,6 @@ def configure(env):
if "clang++" not in os.path.basename(env["CXX"]):
env["CC"] = "clang"
env["CXX"] = "clang++"
- env.Append(CPPDEFINES=["TYPED_METHOD_BIND"])
env.extra_suffix = ".llvm" + env.extra_suffix
if env["use_coverage"]:
diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp
index e22b24c16f..79b0b64efb 100644
--- a/scene/2d/camera_2d.cpp
+++ b/scene/2d/camera_2d.cpp
@@ -198,10 +198,10 @@ Transform2D Camera2D::get_camera_transform() {
camera_screen_center = screen_rect.position + screen_rect.size * 0.5;
Transform2D xform;
+ xform.scale_basis(zoom);
if (rotating) {
xform.set_rotation(angle);
}
- xform.scale_basis(zoom);
xform.set_origin(screen_rect.position /*.floor()*/);
/*
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 649f5a5f66..857c96bea3 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -70,6 +70,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
if (!text.empty() && is_editable() && _is_over_clear_button(b->get_position())) {
clear_button_status.press_attempt = true;
clear_button_status.pressing_inside = true;
+ update();
return;
}
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp
index f4e31c45d2..8aad5f262d 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -414,12 +414,12 @@ void ScrollContainer::update_scrollbars() {
bool hide_scroll_v = !scroll_v || min.height <= size.height;
bool hide_scroll_h = !scroll_h || min.width <= size.width;
+ v_scroll->set_max(min.height);
if (hide_scroll_v) {
v_scroll->hide();
scroll.y = 0;
} else {
v_scroll->show();
- v_scroll->set_max(min.height);
if (hide_scroll_h) {
v_scroll->set_page(size.height);
} else {
@@ -429,12 +429,12 @@ void ScrollContainer::update_scrollbars() {
scroll.y = v_scroll->get_value();
}
+ h_scroll->set_max(min.width);
if (hide_scroll_h) {
h_scroll->hide();
scroll.x = 0;
} else {
h_scroll->show();
- h_scroll->set_max(min.width);
if (hide_scroll_v) {
h_scroll->set_page(size.width);
} else {
diff --git a/tests/test_aabb.h b/tests/test_aabb.h
new file mode 100644
index 0000000000..8acd2a9963
--- /dev/null
+++ b/tests/test_aabb.h
@@ -0,0 +1,375 @@
+/*************************************************************************/
+/* test_aabb.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* 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 TEST_AABB_H
+#define TEST_AABB_H
+
+#include "core/math/aabb.h"
+#include "core/string/print_string.h"
+#include "tests/test_macros.h"
+
+#include "thirdparty/doctest/doctest.h"
+
+namespace TestAABB {
+
+TEST_CASE("[AABB] Constructor methods") {
+ const AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6));
+ const AABB aabb_copy = AABB(aabb);
+
+ CHECK_MESSAGE(
+ aabb == aabb_copy,
+ "AABBs created with the same dimensions but by different methods should be equal.");
+}
+
+TEST_CASE("[AABB] String conversion") {
+ CHECK_MESSAGE(
+ String(AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6))) == "-1.5, 2, -2.5 - 4, 5, 6",
+ "The string representation shouild match the expected value.");
+}
+
+TEST_CASE("[AABB] Basic getters") {
+ const AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6));
+ CHECK_MESSAGE(
+ aabb.get_position().is_equal_approx(Vector3(-1.5, 2, -2.5)),
+ "get_position() should return the expected value.");
+ CHECK_MESSAGE(
+ aabb.get_size().is_equal_approx(Vector3(4, 5, 6)),
+ "get_size() should return the expected value.");
+ CHECK_MESSAGE(
+ aabb.get_end().is_equal_approx(Vector3(2.5, 7, 3.5)),
+ "get_end() should return the expected value.");
+}
+
+TEST_CASE("[AABB] Basic setters") {
+ AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6));
+ aabb.set_end(Vector3(100, 0, 100));
+ CHECK_MESSAGE(
+ aabb.is_equal_approx(AABB(Vector3(-1.5, 2, -2.5), Vector3(101.5, -2, 102.5))),
+ "set_end() should result in the expected AABB.");
+
+ aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6));
+ aabb.set_position(Vector3(-1000, -2000, -3000));
+ CHECK_MESSAGE(
+ aabb.is_equal_approx(AABB(Vector3(-1000, -2000, -3000), Vector3(4, 5, 6))),
+ "set_position() should result in the expected AABB.");
+
+ aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6));
+ aabb.set_size(Vector3(0, 0, -50));
+ CHECK_MESSAGE(
+ aabb.is_equal_approx(AABB(Vector3(-1.5, 2, -2.5), Vector3(0, 0, -50))),
+ "set_size() should result in the expected AABB.");
+}
+
+TEST_CASE("[AABB] Area getters") {
+ AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6));
+ CHECK_MESSAGE(
+ Math::is_equal_approx(aabb.get_area(), 120),
+ "get_area() should return the expected value with positive size.");
+ CHECK_MESSAGE(
+ !aabb.has_no_area(),
+ "Non-empty volumetric AABB should have an area.");
+
+ aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(-4, 5, 6));
+ CHECK_MESSAGE(
+ Math::is_equal_approx(aabb.get_area(), -120),
+ "get_area() should return the expected value with negative size (1 component).");
+
+ aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(-4, -5, 6));
+ CHECK_MESSAGE(
+ Math::is_equal_approx(aabb.get_area(), 120),
+ "get_area() should return the expected value with negative size (2 components).");
+
+ aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(-4, -5, -6));
+ CHECK_MESSAGE(
+ Math::is_equal_approx(aabb.get_area(), -120),
+ "get_area() should return the expected value with negative size (3 components).");
+
+ aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 0, 6));
+ CHECK_MESSAGE(
+ aabb.has_no_area(),
+ "Non-empty flat AABB should not have an area.");
+
+ CHECK_MESSAGE(
+ AABB().has_no_area(),
+ "Empty AABB should not have an area.");
+}
+
+TEST_CASE("[AABB] Surface getters") {
+ AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6));
+ CHECK_MESSAGE(
+ !aabb.has_no_surface(),
+ "Non-empty volumetric AABB should have an surface.");
+
+ aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 0, 6));
+ CHECK_MESSAGE(
+ !aabb.has_no_surface(),
+ "Non-empty flat AABB should have a surface.");
+
+ CHECK_MESSAGE(
+ AABB().has_no_surface(),
+ "Empty AABB should not have an surface.");
+}
+
+TEST_CASE("[AABB] Intersection") {
+ const AABB aabb_big = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6));
+
+ AABB aabb_small = AABB(Vector3(-1.5, 2, -2.5), Vector3(1, 1, 1));
+ CHECK_MESSAGE(
+ aabb_big.intersects(aabb_small),
+ "intersects() with fully contained AABB (touching the edge) should return the expected result.");
+
+ aabb_small = AABB(Vector3(0.5, 1.5, -2), Vector3(1, 1, 1));
+ CHECK_MESSAGE(
+ aabb_big.intersects(aabb_small),
+ "intersects() with partially contained AABB (overflowing on Y axis) should return the expected result.");
+
+ aabb_small = AABB(Vector3(10, -10, -10), Vector3(1, 1, 1));
+ CHECK_MESSAGE(
+ !aabb_big.intersects(aabb_small),
+ "intersects() with non-contained AABB should return the expected result.");
+
+ aabb_small = AABB(Vector3(-1.5, 2, -2.5), Vector3(1, 1, 1));
+ CHECK_MESSAGE(
+ aabb_big.intersection(aabb_small).is_equal_approx(aabb_small),
+ "intersection() with fully contained AABB (touching the edge) should return the expected result.");
+
+ aabb_small = AABB(Vector3(0.5, 1.5, -2), Vector3(1, 1, 1));
+ CHECK_MESSAGE(
+ aabb_big.intersection(aabb_small).is_equal_approx(AABB(Vector3(0.5, 2, -2), Vector3(1, 0.5, 1))),
+ "intersection() with partially contained AABB (overflowing on Y axis) should return the expected result.");
+
+ aabb_small = AABB(Vector3(10, -10, -10), Vector3(1, 1, 1));
+ CHECK_MESSAGE(
+ aabb_big.intersection(aabb_small).is_equal_approx(AABB()),
+ "intersection() with non-contained AABB should return the expected result.");
+
+ CHECK_MESSAGE(
+ aabb_big.intersects_plane(Plane(Vector3(0, 1, 0), 4)),
+ "intersects_plane() should return the expected result.");
+ CHECK_MESSAGE(
+ aabb_big.intersects_plane(Plane(Vector3(0, -1, 0), -4)),
+ "intersects_plane() should return the expected result.");
+ CHECK_MESSAGE(
+ !aabb_big.intersects_plane(Plane(Vector3(0, 1, 0), 200)),
+ "intersects_plane() should return the expected result.");
+
+ CHECK_MESSAGE(
+ aabb_big.intersects_segment(Vector3(1, 3, 0), Vector3(0, 3, 0)),
+ "intersects_segment() should return the expected result.");
+ CHECK_MESSAGE(
+ aabb_big.intersects_segment(Vector3(0, 3, 0), Vector3(0, -300, 0)),
+ "intersects_segment() should return the expected result.");
+ CHECK_MESSAGE(
+ aabb_big.intersects_segment(Vector3(-50, 3, -50), Vector3(50, 3, 50)),
+ "intersects_segment() should return the expected result.");
+ CHECK_MESSAGE(
+ !aabb_big.intersects_segment(Vector3(-50, 25, -50), Vector3(50, 25, 50)),
+ "intersects_segment() should return the expected result.");
+ CHECK_MESSAGE(
+ aabb_big.intersects_segment(Vector3(0, 3, 0), Vector3(0, 3, 0)),
+ "intersects_segment() should return the expected result with segment of length 0.");
+ CHECK_MESSAGE(
+ !aabb_big.intersects_segment(Vector3(0, 300, 0), Vector3(0, 300, 0)),
+ "intersects_segment() should return the expected result with segment of length 0.");
+}
+
+TEST_CASE("[AABB] Merging") {
+ const AABB aabb_big = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6));
+
+ AABB aabb_small = AABB(Vector3(-1.5, 2, -2.5), Vector3(1, 1, 1));
+ CHECK_MESSAGE(
+ aabb_big.merge(aabb_small).is_equal_approx(aabb_big),
+ "merge() with fully contained AABB (touching the edge) should return the expected result.");
+
+ aabb_small = AABB(Vector3(0.5, 1.5, -2), Vector3(1, 1, 1));
+ CHECK_MESSAGE(
+ aabb_big.merge(aabb_small).is_equal_approx(AABB(Vector3(-1.5, 1.5, -2.5), Vector3(4, 5.5, 6))),
+ "merge() with partially contained AABB (overflowing on Y axis) should return the expected result.");
+
+ aabb_small = AABB(Vector3(10, -10, -10), Vector3(1, 1, 1));
+ CHECK_MESSAGE(
+ aabb_big.merge(aabb_small).is_equal_approx(AABB(Vector3(-1.5, -10, -10), Vector3(12.5, 17, 13.5))),
+ "merge() with non-contained AABB should return the expected result.");
+}
+
+TEST_CASE("[AABB] Encloses") {
+ const AABB aabb_big = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6));
+
+ AABB aabb_small = AABB(Vector3(-1.5, 2, -2.5), Vector3(1, 1, 1));
+ CHECK_MESSAGE(
+ aabb_big.encloses(aabb_small),
+ "encloses() with fully contained AABB (touching the edge) should return the expected result.");
+
+ aabb_small = AABB(Vector3(0.5, 1.5, -2), Vector3(1, 1, 1));
+ CHECK_MESSAGE(
+ !aabb_big.encloses(aabb_small),
+ "encloses() with partially contained AABB (overflowing on Y axis) should return the expected result.");
+
+ aabb_small = AABB(Vector3(10, -10, -10), Vector3(1, 1, 1));
+ CHECK_MESSAGE(
+ !aabb_big.encloses(aabb_small),
+ "encloses() with non-contained AABB should return the expected result.");
+}
+
+TEST_CASE("[AABB] Get endpoints") {
+ const AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6));
+ CHECK_MESSAGE(
+ aabb.get_endpoint(0).is_equal_approx(Vector3(-1.5, 2, -2.5)),
+ "The endpoint at index 0 should match the expected value.");
+ CHECK_MESSAGE(
+ aabb.get_endpoint(1).is_equal_approx(Vector3(-1.5, 2, 3.5)),
+ "The endpoint at index 1 should match the expected value.");
+ CHECK_MESSAGE(
+ aabb.get_endpoint(2).is_equal_approx(Vector3(-1.5, 7, -2.5)),
+ "The endpoint at index 2 should match the expected value.");
+ CHECK_MESSAGE(
+ aabb.get_endpoint(3).is_equal_approx(Vector3(-1.5, 7, 3.5)),
+ "The endpoint at index 3 should match the expected value.");
+ CHECK_MESSAGE(
+ aabb.get_endpoint(4).is_equal_approx(Vector3(2.5, 2, -2.5)),
+ "The endpoint at index 4 should match the expected value.");
+ CHECK_MESSAGE(
+ aabb.get_endpoint(5).is_equal_approx(Vector3(2.5, 2, 3.5)),
+ "The endpoint at index 5 should match the expected value.");
+ CHECK_MESSAGE(
+ aabb.get_endpoint(6).is_equal_approx(Vector3(2.5, 7, -2.5)),
+ "The endpoint at index 6 should match the expected value.");
+ CHECK_MESSAGE(
+ aabb.get_endpoint(7).is_equal_approx(Vector3(2.5, 7, 3.5)),
+ "The endpoint at index 7 should match the expected value.");
+
+ ERR_PRINT_OFF;
+ CHECK_MESSAGE(
+ aabb.get_endpoint(8).is_equal_approx(Vector3()),
+ "The endpoint at invalid index 8 should match the expected value.");
+ CHECK_MESSAGE(
+ aabb.get_endpoint(-1).is_equal_approx(Vector3()),
+ "The endpoint at invalid index -1 should match the expected value.");
+ ERR_PRINT_ON;
+}
+
+TEST_CASE("[AABB] Get longest/shortest axis") {
+ const AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6));
+ CHECK_MESSAGE(
+ aabb.get_longest_axis().is_equal_approx(Vector3(0, 0, 1)),
+ "get_longest_axis() should return the expected value.");
+ CHECK_MESSAGE(
+ aabb.get_longest_axis_index() == Vector3::AXIS_Z,
+ "get_longest_axis() should return the expected value.");
+ CHECK_MESSAGE(
+ Math::is_equal_approx(aabb.get_longest_axis_size(), 6),
+ "get_longest_axis() should return the expected value.");
+
+ CHECK_MESSAGE(
+ aabb.get_shortest_axis().is_equal_approx(Vector3(1, 0, 0)),
+ "get_shortest_axis() should return the expected value.");
+ CHECK_MESSAGE(
+ aabb.get_shortest_axis_index() == Vector3::AXIS_X,
+ "get_shortest_axis() should return the expected value.");
+ CHECK_MESSAGE(
+ Math::is_equal_approx(aabb.get_shortest_axis_size(), 4),
+ "get_shortest_axis() should return the expected value.");
+}
+
+TEST_CASE("[AABB] Get support") {
+ const AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6));
+ CHECK_MESSAGE(
+ aabb.get_support(Vector3(1, 0, 0)).is_equal_approx(Vector3(-1.5, 7, 3.5)),
+ "get_support() should return the expected value.");
+ CHECK_MESSAGE(
+ aabb.get_support(Vector3(0.5, 1, 0)).is_equal_approx(Vector3(-1.5, 2, 3.5)),
+ "get_support() should return the expected value.");
+ CHECK_MESSAGE(
+ aabb.get_support(Vector3(0.5, 1, -400)).is_equal_approx(Vector3(-1.5, 2, 3.5)),
+ "get_support() should return the expected value.");
+ CHECK_MESSAGE(
+ aabb.get_support(Vector3(0, -1, 0)).is_equal_approx(Vector3(2.5, 7, 3.5)),
+ "get_support() should return the expected value.");
+ CHECK_MESSAGE(
+ aabb.get_support(Vector3(0, -0.1, 0)).is_equal_approx(Vector3(2.5, 7, 3.5)),
+ "get_support() should return the expected value.");
+ CHECK_MESSAGE(
+ aabb.get_support(Vector3()).is_equal_approx(Vector3(2.5, 7, 3.5)),
+ "get_support() should return the expected value with a null vector.");
+}
+
+TEST_CASE("[AABB] Grow") {
+ const AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6));
+ CHECK_MESSAGE(
+ aabb.grow(0.25).is_equal_approx(AABB(Vector3(-1.75, 1.75, -2.75), Vector3(4.5, 5.5, 6.5))),
+ "grow() with positive value should return the expected AABB.");
+ CHECK_MESSAGE(
+ aabb.grow(-0.25).is_equal_approx(AABB(Vector3(-1.25, 2.25, -2.25), Vector3(3.5, 4.5, 5.5))),
+ "grow() with negative value should return the expected AABB.");
+ CHECK_MESSAGE(
+ aabb.grow(-10).is_equal_approx(AABB(Vector3(8.5, 12, 7.5), Vector3(-16, -15, -14))),
+ "grow() with large negative value should return the expected AABB.");
+}
+
+TEST_CASE("[AABB] Has point") {
+ const AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6));
+ CHECK_MESSAGE(
+ aabb.has_point(Vector3(-1, 3, 0)),
+ "has_point() with contained point should return the expected value.");
+ CHECK_MESSAGE(
+ aabb.has_point(Vector3(2, 3, 0)),
+ "has_point() with contained point should return the expected value.");
+ CHECK_MESSAGE(
+ aabb.has_point(Vector3(-1.5, 3, 0)),
+ "has_point() with contained point on negative edge should return the expected value.");
+ CHECK_MESSAGE(
+ aabb.has_point(Vector3(2.5, 3, 0)),
+ "has_point() with contained point on positive edge should return the expected value.");
+ CHECK_MESSAGE(
+ !aabb.has_point(Vector3(-20, 0, 0)),
+ "has_point() with non-contained point should return the expected value.");
+}
+
+TEST_CASE("[AABB] Expanding") {
+ const AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6));
+ CHECK_MESSAGE(
+ aabb.expand(Vector3(-1, 3, 0)).is_equal_approx(aabb),
+ "expand() with contained point should return the expected AABB.");
+ CHECK_MESSAGE(
+ aabb.expand(Vector3(2, 3, 0)).is_equal_approx(aabb),
+ "expand() with contained point should return the expected AABB.");
+ CHECK_MESSAGE(
+ aabb.expand(Vector3(-1.5, 3, 0)).is_equal_approx(aabb),
+ "expand() with contained point on negative edge should return the expected AABB.");
+ CHECK_MESSAGE(
+ aabb.expand(Vector3(2.5, 3, 0)).is_equal_approx(aabb),
+ "expand() with contained point on positive edge should return the expected AABB.");
+ CHECK_MESSAGE(
+ aabb.expand(Vector3(-20, 0, 0)).is_equal_approx(AABB(Vector3(-20, 0, -2.5), Vector3(22.5, 7, 6))),
+ "expand() with non-contained point should return the expected AABB.");
+}
+} // namespace TestAABB
+
+#endif // TEST_AABB_H
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
index 4388654d08..c9bf9ab5d5 100644
--- a/tests/test_main.cpp
+++ b/tests/test_main.cpp
@@ -32,6 +32,7 @@
#include "core/templates/list.h"
+#include "test_aabb.h"
#include "test_astar.h"
#include "test_basis.h"
#include "test_class_db.h"
diff --git a/tests/test_string.h b/tests/test_string.h
index 48132cb278..3c5d4a2f01 100644
--- a/tests/test_string.h
+++ b/tests/test_string.h
@@ -40,10 +40,6 @@
#include "core/os/os.h"
#include "core/string/ustring.h"
-#ifdef MODULE_REGEX_ENABLED
-#include "modules/regex/regex.h"
-#endif
-
#include "tests/test_macros.h"
namespace TestString {
@@ -475,15 +471,6 @@ TEST_CASE("[String] Erasing") {
CHECK(s == "Josephine is such a girl!");
}
-#ifdef MODULE_REGEX_ENABLED
-TEST_CASE("[String] Regex substitution") {
- String s = "Double all the vowels.";
- RegEx re("(?<vowel>[aeiou])");
- s = re.sub(s, "$0$vowel", true);
- CHECK(s == "Doouublee aall thee vooweels.");
-}
-#endif
-
struct test_27_data {
char const *data;
char const *part;