New version with edge binary no longer embedded.
This commit is contained in:
parent
0a8277871a
commit
9d3914d46e
2278 changed files with 140552 additions and 79597 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,3 +6,4 @@ temp/
|
|||
scp.sh
|
||||
start-edge.sh
|
||||
console-edge.sh
|
||||
old/
|
||||
|
|
|
@ -16,9 +16,7 @@ ln -f -s ../custom.py .
|
|||
scons platform=linuxbsd target=editor arch=x86_64 ${LTO}
|
||||
|
||||
# Create JSON for IDE support.
|
||||
#if [[ ! -f compile_commands.json ]]; then
|
||||
scons compiledb=yes
|
||||
#fi
|
||||
|
||||
# Build Templates.
|
||||
scons platform=linuxbsd target=template_release arch=x86_64 ${TEMPLATE} ${LTO}
|
28
build-n2n.sh
Executable file
28
build-n2n.sh
Executable file
|
@ -0,0 +1,28 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Build n2n for current platform.
|
||||
|
||||
mkdir -p bin
|
||||
|
||||
mkdir -p n2n/thirdparty/libnatpmp/build
|
||||
pushd n2n/thirdparty/libnatpmp/build
|
||||
cmake ..
|
||||
make
|
||||
popd
|
||||
|
||||
mkdir -p n2n/thirdparty/miniupnp/miniupnpc/build
|
||||
pushd n2n/thirdparty/miniupnp/miniupnpc/build
|
||||
cmake ..
|
||||
make
|
||||
popd
|
||||
|
||||
pushd n2n
|
||||
./autogen.sh
|
||||
CFLAGS="-I thirdparty/libnatpmp -I thirdparty/miniupnp/miniupnpc/include" \
|
||||
LDFLAGS="-L thirdparty/libnatpmp/build -L thirdparty/miniupnp/miniupnpc/build" \
|
||||
./configure --enable-pthread --enable-natpmp --enable-miniupnp
|
||||
make edge
|
||||
make supernode
|
||||
mv edge ../bin/.
|
||||
mv supernode ../bin/.
|
||||
popd
|
|
@ -40,5 +40,4 @@ module_visual_script_enabled = "no"
|
|||
module_vorbis_enabled = "no"
|
||||
module_websocket_enabled = "no"
|
||||
module_webxr_enabled = "no"
|
||||
custom_modules = "../modules"
|
||||
|
||||
#custom_modules = "../modules"
|
||||
|
|
4
edit.sh
4
edit.sh
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash
|
||||
#sudo godot/bin/godot.linuxbsd.editor.x86_64 --editor --path hamncheese | tee output.log
|
||||
godot/bin/godot.linuxbsd.editor.x86_64 --editor --path test | tee output.log
|
||||
#~/.steam/steam/steamapps/common/Godot\ Engine/godot.x11.opt.tools.64 --editor --path hamncheese | tee output.log
|
||||
godot/bin/godot.linuxbsd.editor.x86_64 --editor --path hamncheese | tee output.log
|
||||
|
||||
|
|
18
godot/.gitignore
vendored
18
godot/.gitignore
vendored
|
@ -132,23 +132,9 @@ cppcheck-cppcheck-build-dir/
|
|||
*.pydevproject
|
||||
*.launch
|
||||
|
||||
# Gcov and Lcov code coverage
|
||||
*.gcno
|
||||
# GCOV code coverage
|
||||
*.gcda
|
||||
*.gcov.html
|
||||
*.func.html
|
||||
*.func-sort-c.html
|
||||
*index-sort-f.html
|
||||
*index-sort-l.html
|
||||
*index.html
|
||||
godot.info
|
||||
amber.png
|
||||
emerald.png
|
||||
glass.png
|
||||
ruby.png
|
||||
snow.png
|
||||
updown.png
|
||||
gcov.css
|
||||
*.gcno
|
||||
|
||||
# Geany
|
||||
*.geany
|
||||
|
|
|
@ -204,7 +204,7 @@ License: OFL-1.1
|
|||
|
||||
Files: ./thirdparty/freetype/
|
||||
Comment: The FreeType Project
|
||||
Copyright: 1996-2022, David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
Copyright: 1996-2023, David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
License: FTL
|
||||
|
||||
Files: ./thirdparty/glad/
|
||||
|
@ -256,6 +256,12 @@ Comment: jpeg-compressor
|
|||
Copyright: 2012, Rich Geldreich
|
||||
License: public-domain or Apache-2.0
|
||||
|
||||
Files: ./thirdparty/libktx/
|
||||
Comment: KTX
|
||||
Copyright: 2013-2020, Mark Callow
|
||||
2010-2020 The Khronos Group, Inc.
|
||||
License: Apache-2.0
|
||||
|
||||
Files: ./thirdparty/libogg/
|
||||
Comment: OggVorbis
|
||||
Copyright: 2002, Xiph.org Foundation
|
||||
|
@ -487,7 +493,7 @@ License: Expat
|
|||
|
||||
Files: ./thirdparty/zlib/
|
||||
Comment: zlib
|
||||
Copyright: 1995-2022, Jean-loup Gailly and Mark Adler
|
||||
Copyright: 1995-2023, Jean-loup Gailly and Mark Adler
|
||||
License: Zlib
|
||||
|
||||
Files: ./thirdparty/zstd/
|
||||
|
|
|
@ -193,6 +193,7 @@ opts.Add(BoolVariable("vulkan", "Enable the vulkan rendering driver", True))
|
|||
opts.Add(BoolVariable("opengl3", "Enable the OpenGL/GLES3 rendering driver", True))
|
||||
opts.Add(BoolVariable("openxr", "Enable the OpenXR driver", True))
|
||||
opts.Add(BoolVariable("use_volk", "Use the volk library to load the Vulkan loader dynamically", True))
|
||||
opts.Add(BoolVariable("disable_exceptions", "Force disabling exception handling code", True))
|
||||
opts.Add("custom_modules", "A list of comma-separated directory paths containing custom modules to build.", "")
|
||||
opts.Add(BoolVariable("custom_modules_recursive", "Detect custom modules recursively for each specified path.", True))
|
||||
|
||||
|
@ -710,6 +711,16 @@ if selected_platform in platform_list:
|
|||
)
|
||||
Exit(255)
|
||||
|
||||
# Disable exception handling. Godot doesn't use exceptions anywhere, and this
|
||||
# saves around 20% of binary size and very significant build time (GH-80513).
|
||||
if env["disable_exceptions"]:
|
||||
if env.msvc:
|
||||
env.Append(CPPDEFINES=[("_HAS_EXCEPTIONS", 0)])
|
||||
else:
|
||||
env.Append(CCFLAGS=["-fno-exceptions"])
|
||||
elif env.msvc:
|
||||
env.Append(CCFLAGS=["/EHsc"])
|
||||
|
||||
# Configure compiler warnings
|
||||
if env.msvc: # MSVC
|
||||
if env["warnings"] == "no":
|
||||
|
@ -739,11 +750,9 @@ if selected_platform in platform_list:
|
|||
]
|
||||
)
|
||||
|
||||
# Set exception handling model to avoid warnings caused by Windows system headers.
|
||||
env.Append(CCFLAGS=["/EHsc"])
|
||||
|
||||
if env["werror"]:
|
||||
env.Append(CCFLAGS=["/WX"])
|
||||
env.Append(LINKFLAGS=["/WX"])
|
||||
else: # GCC, Clang
|
||||
common_warnings = []
|
||||
|
||||
|
@ -969,7 +978,7 @@ if selected_platform in platform_list:
|
|||
print("Error: The `vsproj` option is only usable on Windows with Visual Studio.")
|
||||
Exit(255)
|
||||
env["CPPPATH"] = [Dir(path) for path in env["CPPPATH"]]
|
||||
methods.generate_vs_project(env, GetOption("num_jobs"), env["vsproj_name"])
|
||||
methods.generate_vs_project(env, ARGUMENTS, env["vsproj_name"])
|
||||
methods.generate_cpp_hint_file("cpp.hint")
|
||||
|
||||
# Check for the existence of headers
|
||||
|
|
|
@ -74,6 +74,14 @@ int Engine::get_max_fps() const {
|
|||
return _max_fps;
|
||||
}
|
||||
|
||||
void Engine::set_audio_output_latency(int p_msec) {
|
||||
_audio_output_latency = p_msec > 1 ? p_msec : 1;
|
||||
}
|
||||
|
||||
int Engine::get_audio_output_latency() const {
|
||||
return _audio_output_latency;
|
||||
}
|
||||
|
||||
uint64_t Engine::get_frames_drawn() {
|
||||
return frames_drawn;
|
||||
}
|
||||
|
@ -239,6 +247,10 @@ bool Engine::is_validation_layers_enabled() const {
|
|||
return use_validation_layers;
|
||||
}
|
||||
|
||||
bool Engine::is_generate_spirv_debug_info_enabled() const {
|
||||
return generate_spirv_debug_info;
|
||||
}
|
||||
|
||||
void Engine::set_print_error_messages(bool p_enabled) {
|
||||
CoreGlobals::print_error_enabled = p_enabled;
|
||||
}
|
||||
|
|
|
@ -61,12 +61,14 @@ private:
|
|||
double physics_jitter_fix = 0.5;
|
||||
double _fps = 1;
|
||||
int _max_fps = 0;
|
||||
int _audio_output_latency = 0;
|
||||
double _time_scale = 1.0;
|
||||
uint64_t _physics_frames = 0;
|
||||
int max_physics_steps_per_frame = 8;
|
||||
double _physics_interpolation_fraction = 0.0f;
|
||||
bool abort_on_gpu_errors = false;
|
||||
bool use_validation_layers = false;
|
||||
bool generate_spirv_debug_info = false;
|
||||
int32_t gpu_idx = -1;
|
||||
|
||||
uint64_t _process_frames = 0;
|
||||
|
@ -98,6 +100,9 @@ public:
|
|||
virtual void set_max_fps(int p_fps);
|
||||
virtual int get_max_fps() const;
|
||||
|
||||
virtual void set_audio_output_latency(int p_msec);
|
||||
virtual int get_audio_output_latency() const;
|
||||
|
||||
virtual double get_frames_per_second() const { return _fps; }
|
||||
|
||||
uint64_t get_frames_drawn();
|
||||
|
@ -156,6 +161,7 @@ public:
|
|||
|
||||
bool is_abort_on_gpu_errors_enabled() const;
|
||||
bool is_validation_layers_enabled() const;
|
||||
bool is_generate_spirv_debug_info_enabled() const;
|
||||
int32_t get_gpu_index() const;
|
||||
|
||||
Engine();
|
||||
|
|
|
@ -249,6 +249,11 @@ bool ProjectSettings::get_ignore_value_in_docs(const String &p_name) const {
|
|||
#endif
|
||||
}
|
||||
|
||||
void ProjectSettings::add_hidden_prefix(const String &p_prefix) {
|
||||
ERR_FAIL_COND_MSG(hidden_prefixes.find(p_prefix) > -1, vformat("Hidden prefix '%s' already exists.", p_prefix));
|
||||
hidden_prefixes.push_back(p_prefix);
|
||||
}
|
||||
|
||||
String ProjectSettings::globalize_path(const String &p_path) const {
|
||||
if (p_path.begins_with("res://")) {
|
||||
if (!resource_path.is_empty()) {
|
||||
|
@ -388,7 +393,18 @@ void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const {
|
|||
vc.name = E.key;
|
||||
vc.order = v->order;
|
||||
vc.type = v->variant.get_type();
|
||||
if (v->internal || vc.name.begins_with("input/") || vc.name.begins_with("importer_defaults/") || vc.name.begins_with("import/") || vc.name.begins_with("autoload/") || vc.name.begins_with("editor_plugins/") || vc.name.begins_with("shader_globals/")) {
|
||||
|
||||
bool internal = v->internal;
|
||||
if (!internal) {
|
||||
for (const String &F : hidden_prefixes) {
|
||||
if (vc.name.begins_with(F)) {
|
||||
internal = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (internal) {
|
||||
vc.flags = PROPERTY_USAGE_STORAGE;
|
||||
} else {
|
||||
vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
|
||||
|
@ -1382,11 +1398,13 @@ ProjectSettings::ProjectSettings() {
|
|||
GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "rendering/textures/canvas_textures/default_texture_filter", PROPERTY_HINT_ENUM, "Nearest,Linear,Linear Mipmap,Nearest Mipmap"), 1);
|
||||
GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "rendering/textures/canvas_textures/default_texture_repeat", PROPERTY_HINT_ENUM, "Disable,Enable,Mirror"), 0);
|
||||
|
||||
// These properties will not show up in the dialog nor in the documentation. If you want to exclude whole groups, see _get_property_list() method.
|
||||
// These properties will not show up in the dialog. If you want to exclude whole groups, use add_hidden_prefix().
|
||||
GLOBAL_DEF_INTERNAL("application/config/features", PackedStringArray());
|
||||
GLOBAL_DEF_INTERNAL("internationalization/locale/translation_remaps", PackedStringArray());
|
||||
GLOBAL_DEF_INTERNAL("internationalization/locale/translations", PackedStringArray());
|
||||
GLOBAL_DEF_INTERNAL("internationalization/locale/translations_pot_files", PackedStringArray());
|
||||
|
||||
ProjectSettings::get_singleton()->add_hidden_prefix("input/");
|
||||
}
|
||||
|
||||
ProjectSettings::~ProjectSettings() {
|
||||
|
|
|
@ -104,6 +104,7 @@ protected:
|
|||
HashSet<String> custom_features;
|
||||
HashMap<StringName, LocalVector<Pair<StringName, StringName>>> feature_overrides;
|
||||
|
||||
LocalVector<String> hidden_prefixes;
|
||||
HashMap<StringName, AutoloadInfo> autoloads;
|
||||
|
||||
Array global_class_list;
|
||||
|
@ -168,6 +169,7 @@ public:
|
|||
void set_restart_if_changed(const String &p_name, bool p_restart);
|
||||
void set_ignore_value_in_docs(const String &p_name, bool p_ignore);
|
||||
bool get_ignore_value_in_docs(const String &p_name) const;
|
||||
void add_hidden_prefix(const String &p_prefix);
|
||||
|
||||
String get_project_data_dir_name() const;
|
||||
String get_project_data_path() const;
|
||||
|
|
|
@ -929,6 +929,17 @@ Geometry3D *Geometry3D::get_singleton() {
|
|||
return singleton;
|
||||
}
|
||||
|
||||
Vector<Vector3> Geometry3D::compute_convex_mesh_points(const TypedArray<Plane> &p_planes) {
|
||||
Vector<Plane> planes_vec;
|
||||
int size = p_planes.size();
|
||||
planes_vec.resize(size);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
planes_vec.set(i, p_planes[i]);
|
||||
}
|
||||
Variant ret = ::Geometry3D::compute_convex_mesh_points(planes_vec.ptr(), size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
TypedArray<Plane> Geometry3D::build_box_planes(const Vector3 &p_extents) {
|
||||
Variant ret = ::Geometry3D::build_box_planes(p_extents);
|
||||
return ret;
|
||||
|
@ -1029,6 +1040,7 @@ Vector<Vector3> Geometry3D::clip_polygon(const Vector<Vector3> &p_points, const
|
|||
}
|
||||
|
||||
void Geometry3D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("compute_convex_mesh_points", "planes"), &Geometry3D::compute_convex_mesh_points);
|
||||
ClassDB::bind_method(D_METHOD("build_box_planes", "extents"), &Geometry3D::build_box_planes);
|
||||
ClassDB::bind_method(D_METHOD("build_cylinder_planes", "radius", "height", "sides", "axis"), &Geometry3D::build_cylinder_planes, DEFVAL(Vector3::AXIS_Z));
|
||||
ClassDB::bind_method(D_METHOD("build_capsule_planes", "radius", "height", "sides", "lats", "axis"), &Geometry3D::build_capsule_planes, DEFVAL(Vector3::AXIS_Z));
|
||||
|
|
|
@ -320,6 +320,7 @@ protected:
|
|||
|
||||
public:
|
||||
static Geometry3D *get_singleton();
|
||||
Vector<Vector3> compute_convex_mesh_points(const TypedArray<Plane> &p_planes);
|
||||
TypedArray<Plane> build_box_planes(const Vector3 &p_extents);
|
||||
TypedArray<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis = Vector3::AXIS_Z);
|
||||
TypedArray<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis = Vector3::AXIS_Z);
|
||||
|
|
|
@ -420,6 +420,10 @@ void register_global_constants() {
|
|||
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCHD);
|
||||
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCHE);
|
||||
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCHF);
|
||||
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, GLOBE);
|
||||
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KEYBOARD);
|
||||
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, JIS_EISU);
|
||||
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, JIS_KANA);
|
||||
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UNKNOWN);
|
||||
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SPACE);
|
||||
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, EXCLAM);
|
||||
|
@ -492,10 +496,6 @@ void register_global_constants() {
|
|||
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ASCIITILDE);
|
||||
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, YEN);
|
||||
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SECTION);
|
||||
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, GLOBE);
|
||||
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KEYBOARD);
|
||||
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, JIS_EISU);
|
||||
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, JIS_KANA);
|
||||
|
||||
BIND_CORE_BITFIELD_CLASS_FLAG_CUSTOM(KeyModifierMask, KEY_CODE_MASK, CODE_MASK);
|
||||
BIND_CORE_BITFIELD_CLASS_FLAG_CUSTOM(KeyModifierMask, KEY_MODIFIER_MASK, MODIFIER_MASK);
|
||||
|
|
|
@ -73,7 +73,7 @@ Error CryptoCore::RandomGenerator::init() {
|
|||
}
|
||||
|
||||
Error CryptoCore::RandomGenerator::get_random_bytes(uint8_t *r_buffer, size_t p_bytes) {
|
||||
ERR_FAIL_COND_V(!ctx, ERR_UNCONFIGURED);
|
||||
ERR_FAIL_NULL_V(ctx, ERR_UNCONFIGURED);
|
||||
int ret = mbedtls_ctr_drbg_random((mbedtls_ctr_drbg_context *)ctx, r_buffer, p_bytes);
|
||||
ERR_FAIL_COND_V_MSG(ret, FAILED, " failed\n ! mbedtls_ctr_drbg_seed returned an error" + itos(ret));
|
||||
return OK;
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
Error HashingContext::start(HashType p_type) {
|
||||
ERR_FAIL_COND_V(ctx != nullptr, ERR_ALREADY_IN_USE);
|
||||
_create_ctx(p_type);
|
||||
ERR_FAIL_COND_V(ctx == nullptr, ERR_UNAVAILABLE);
|
||||
ERR_FAIL_NULL_V(ctx, ERR_UNAVAILABLE);
|
||||
switch (type) {
|
||||
case HASH_MD5:
|
||||
return ((CryptoCore::MD5Context *)ctx)->start();
|
||||
|
@ -48,7 +48,7 @@ Error HashingContext::start(HashType p_type) {
|
|||
}
|
||||
|
||||
Error HashingContext::update(PackedByteArray p_chunk) {
|
||||
ERR_FAIL_COND_V(ctx == nullptr, ERR_UNCONFIGURED);
|
||||
ERR_FAIL_NULL_V(ctx, ERR_UNCONFIGURED);
|
||||
size_t len = p_chunk.size();
|
||||
ERR_FAIL_COND_V(len == 0, FAILED);
|
||||
const uint8_t *r = p_chunk.ptr();
|
||||
|
@ -64,7 +64,7 @@ Error HashingContext::update(PackedByteArray p_chunk) {
|
|||
}
|
||||
|
||||
PackedByteArray HashingContext::finish() {
|
||||
ERR_FAIL_COND_V(ctx == nullptr, PackedByteArray());
|
||||
ERR_FAIL_NULL_V(ctx, PackedByteArray());
|
||||
PackedByteArray out;
|
||||
Error err = FAILED;
|
||||
switch (type) {
|
||||
|
|
|
@ -31,10 +31,8 @@
|
|||
#ifndef ENGINE_PROFILER_H
|
||||
#define ENGINE_PROFILER_H
|
||||
|
||||
#include "core/object/ref_counted.h"
|
||||
|
||||
#include "core/object/gdvirtual.gen.inc"
|
||||
#include "core/object/script_language.h"
|
||||
#include "core/object/ref_counted.h"
|
||||
|
||||
class EngineProfiler : public RefCounted {
|
||||
GDCLASS(EngineProfiler, RefCounted);
|
||||
|
|
|
@ -415,7 +415,7 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
|
|||
Array msg;
|
||||
msg.push_back(p_can_continue);
|
||||
msg.push_back(error_str);
|
||||
ERR_FAIL_COND(!script_lang);
|
||||
ERR_FAIL_NULL(script_lang);
|
||||
msg.push_back(script_lang->debug_get_stack_level_count() > 0);
|
||||
msg.push_back(Thread::get_caller_id() == Thread::get_main_id() ? String(RTR("Main Thread")) : itos(Thread::get_caller_id()));
|
||||
if (allow_focus_steal_fn) {
|
||||
|
@ -485,7 +485,7 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
|
|||
|
||||
} else if (command == "get_stack_frame_vars") {
|
||||
ERR_FAIL_COND(data.size() != 1);
|
||||
ERR_FAIL_COND(!script_lang);
|
||||
ERR_FAIL_NULL(script_lang);
|
||||
int lv = data[0];
|
||||
|
||||
List<String> members;
|
||||
|
|
|
@ -750,6 +750,9 @@ Dictionary GDExtensionAPIDump::generate_extension_api() {
|
|||
class_list.sort_custom<StringName::AlphCompare>();
|
||||
|
||||
for (const StringName &class_name : class_list) {
|
||||
if (!ClassDB::is_class_exposed(class_name)) {
|
||||
continue;
|
||||
}
|
||||
Dictionary d;
|
||||
d["name"] = String(class_name);
|
||||
d["is_refcounted"] = ClassDB::is_parent_class(class_name, "RefCounted");
|
||||
|
|
|
@ -281,7 +281,42 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
void GDExtension::_register_extension_class(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo *p_extension_funcs) {
|
||||
const GDExtensionClassCreationInfo2 class_info2 = {
|
||||
p_extension_funcs->is_virtual, // GDExtensionBool is_virtual;
|
||||
p_extension_funcs->is_abstract, // GDExtensionBool is_abstract;
|
||||
true, // GDExtensionBool is_exposed;
|
||||
p_extension_funcs->set_func, // GDExtensionClassSet set_func;
|
||||
p_extension_funcs->get_func, // GDExtensionClassGet get_func;
|
||||
p_extension_funcs->get_property_list_func, // GDExtensionClassGetPropertyList get_property_list_func;
|
||||
p_extension_funcs->free_property_list_func, // GDExtensionClassFreePropertyList free_property_list_func;
|
||||
p_extension_funcs->property_can_revert_func, // GDExtensionClassPropertyCanRevert property_can_revert_func;
|
||||
p_extension_funcs->property_get_revert_func, // GDExtensionClassPropertyGetRevert property_get_revert_func;
|
||||
nullptr, // GDExtensionClassValidateProperty validate_property_func;
|
||||
nullptr, // GDExtensionClassNotification2 notification_func;
|
||||
p_extension_funcs->to_string_func, // GDExtensionClassToString to_string_func;
|
||||
p_extension_funcs->reference_func, // GDExtensionClassReference reference_func;
|
||||
p_extension_funcs->unreference_func, // GDExtensionClassUnreference unreference_func;
|
||||
p_extension_funcs->create_instance_func, // GDExtensionClassCreateInstance create_instance_func; /* this one is mandatory */
|
||||
p_extension_funcs->free_instance_func, // GDExtensionClassFreeInstance free_instance_func; /* this one is mandatory */
|
||||
p_extension_funcs->get_virtual_func, // GDExtensionClassGetVirtual get_virtual_func;
|
||||
p_extension_funcs->get_rid_func, // GDExtensionClassGetRID get_rid;
|
||||
p_extension_funcs->class_userdata, // void *class_userdata;
|
||||
};
|
||||
|
||||
const ClassCreationDeprecatedInfo legacy = {
|
||||
p_extension_funcs->notification_func,
|
||||
};
|
||||
_register_extension_class_internal(p_library, p_class_name, p_parent_class_name, &class_info2, &legacy);
|
||||
}
|
||||
#endif // DISABLE_DEPRECATED
|
||||
|
||||
void GDExtension::_register_extension_class2(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo2 *p_extension_funcs) {
|
||||
_register_extension_class_internal(p_library, p_class_name, p_parent_class_name, p_extension_funcs);
|
||||
}
|
||||
|
||||
void GDExtension::_register_extension_class_internal(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo2 *p_extension_funcs, const ClassCreationDeprecatedInfo *p_deprecated_funcs) {
|
||||
GDExtension *self = reinterpret_cast<GDExtension *>(p_library);
|
||||
|
||||
StringName class_name = *reinterpret_cast<const StringName *>(p_class_name);
|
||||
|
@ -319,13 +354,20 @@ void GDExtension::_register_extension_class(GDExtensionClassLibraryPtr p_library
|
|||
extension->gdextension.editor_class = self->level_initialized == INITIALIZATION_LEVEL_EDITOR;
|
||||
extension->gdextension.is_virtual = p_extension_funcs->is_virtual;
|
||||
extension->gdextension.is_abstract = p_extension_funcs->is_abstract;
|
||||
extension->gdextension.is_exposed = p_extension_funcs->is_exposed;
|
||||
extension->gdextension.set = p_extension_funcs->set_func;
|
||||
extension->gdextension.get = p_extension_funcs->get_func;
|
||||
extension->gdextension.get_property_list = p_extension_funcs->get_property_list_func;
|
||||
extension->gdextension.free_property_list = p_extension_funcs->free_property_list_func;
|
||||
extension->gdextension.property_can_revert = p_extension_funcs->property_can_revert_func;
|
||||
extension->gdextension.property_get_revert = p_extension_funcs->property_get_revert_func;
|
||||
extension->gdextension.notification = p_extension_funcs->notification_func;
|
||||
extension->gdextension.validate_property = p_extension_funcs->validate_property_func;
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
if (p_deprecated_funcs) {
|
||||
extension->gdextension.notification = p_deprecated_funcs->notification_func;
|
||||
}
|
||||
#endif // DISABLE_DEPRECATED
|
||||
extension->gdextension.notification2 = p_extension_funcs->notification_func;
|
||||
extension->gdextension.to_string = p_extension_funcs->to_string_func;
|
||||
extension->gdextension.reference = p_extension_funcs->reference_func;
|
||||
extension->gdextension.unreference = p_extension_funcs->unreference_func;
|
||||
|
@ -337,6 +379,7 @@ void GDExtension::_register_extension_class(GDExtensionClassLibraryPtr p_library
|
|||
|
||||
ClassDB::register_extension_class(&extension->gdextension);
|
||||
}
|
||||
|
||||
void GDExtension::_register_extension_class_method(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, const GDExtensionClassMethodInfo *p_method_info) {
|
||||
GDExtension *self = reinterpret_cast<GDExtension *>(p_library);
|
||||
|
||||
|
@ -448,7 +491,7 @@ void GDExtension::register_interface_function(StringName p_function_name, GDExte
|
|||
|
||||
GDExtensionInterfaceFunctionPtr GDExtension::get_interface_function(StringName p_function_name) {
|
||||
GDExtensionInterfaceFunctionPtr *function = gdextension_interface_functions.getptr(p_function_name);
|
||||
ERR_FAIL_COND_V_MSG(function == nullptr, nullptr, "Attempt to get non-existent interface function: " + p_function_name);
|
||||
ERR_FAIL_NULL_V_MSG(function, nullptr, "Attempt to get non-existent interface function: " + String(p_function_name) + ".");
|
||||
return *function;
|
||||
}
|
||||
|
||||
|
@ -482,9 +525,16 @@ Error GDExtension::open_library(const String &p_path, const String &p_entry_symb
|
|||
}
|
||||
|
||||
void GDExtension::close_library() {
|
||||
ERR_FAIL_COND(library == nullptr);
|
||||
ERR_FAIL_NULL(library);
|
||||
OS::get_singleton()->close_dynamic_library(library);
|
||||
|
||||
#if defined(TOOLS_ENABLED) && defined(WINDOWS_ENABLED)
|
||||
// Delete temporary copy of library if it exists.
|
||||
if (!temp_lib_path.is_empty() && Engine::get_singleton()->is_editor_hint()) {
|
||||
DirAccess::remove_absolute(temp_lib_path);
|
||||
}
|
||||
#endif
|
||||
|
||||
library = nullptr;
|
||||
}
|
||||
|
||||
|
@ -493,12 +543,12 @@ bool GDExtension::is_library_open() const {
|
|||
}
|
||||
|
||||
GDExtension::InitializationLevel GDExtension::get_minimum_library_initialization_level() const {
|
||||
ERR_FAIL_COND_V(library == nullptr, INITIALIZATION_LEVEL_CORE);
|
||||
ERR_FAIL_NULL_V(library, INITIALIZATION_LEVEL_CORE);
|
||||
return InitializationLevel(initialization.minimum_initialization_level);
|
||||
}
|
||||
|
||||
void GDExtension::initialize_library(InitializationLevel p_level) {
|
||||
ERR_FAIL_COND(library == nullptr);
|
||||
ERR_FAIL_NULL(library);
|
||||
ERR_FAIL_COND_MSG(p_level <= int32_t(level_initialized), vformat("Level '%d' must be higher than the current level '%d'", p_level, level_initialized));
|
||||
|
||||
level_initialized = int32_t(p_level);
|
||||
|
@ -508,7 +558,7 @@ void GDExtension::initialize_library(InitializationLevel p_level) {
|
|||
initialization.initialize(initialization.userdata, GDExtensionInitializationLevel(p_level));
|
||||
}
|
||||
void GDExtension::deinitialize_library(InitializationLevel p_level) {
|
||||
ERR_FAIL_COND(library == nullptr);
|
||||
ERR_FAIL_NULL(library);
|
||||
ERR_FAIL_COND(p_level > int32_t(level_initialized));
|
||||
|
||||
level_initialized = int32_t(p_level) - 1;
|
||||
|
@ -541,7 +591,10 @@ GDExtension::~GDExtension() {
|
|||
void GDExtension::initialize_gdextensions() {
|
||||
gdextension_setup_interface();
|
||||
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
register_interface_function("classdb_register_extension_class", (GDExtensionInterfaceFunctionPtr)&GDExtension::_register_extension_class);
|
||||
#endif // DISABLE_DEPRECATED
|
||||
register_interface_function("classdb_register_extension_class2", (GDExtensionInterfaceFunctionPtr)&GDExtension::_register_extension_class2);
|
||||
register_interface_function("classdb_register_extension_class_method", (GDExtensionInterfaceFunctionPtr)&GDExtension::_register_extension_class_method);
|
||||
register_interface_function("classdb_register_extension_class_integer_constant", (GDExtensionInterfaceFunctionPtr)&GDExtension::_register_extension_class_integer_constant);
|
||||
register_interface_function("classdb_register_extension_class_property", (GDExtensionInterfaceFunctionPtr)&GDExtension::_register_extension_class_property);
|
||||
|
@ -607,12 +660,13 @@ Ref<Resource> GDExtensionResourceLoader::load(const String &p_path, const String
|
|||
}
|
||||
|
||||
bool compatible = true;
|
||||
if (VERSION_MAJOR < compatibility_minimum[0]) {
|
||||
compatible = false;
|
||||
} else if (VERSION_MINOR < compatibility_minimum[1]) {
|
||||
compatible = false;
|
||||
} else if (VERSION_PATCH < compatibility_minimum[2]) {
|
||||
compatible = false;
|
||||
// Check version lexicographically.
|
||||
if (VERSION_MAJOR != compatibility_minimum[0]) {
|
||||
compatible = VERSION_MAJOR > compatibility_minimum[0];
|
||||
} else if (VERSION_MINOR != compatibility_minimum[1]) {
|
||||
compatible = VERSION_MINOR > compatibility_minimum[1];
|
||||
} else {
|
||||
compatible = VERSION_PATCH >= compatibility_minimum[2];
|
||||
}
|
||||
if (!compatible) {
|
||||
if (r_error) {
|
||||
|
@ -640,6 +694,45 @@ Ref<Resource> GDExtensionResourceLoader::load(const String &p_path, const String
|
|||
Ref<GDExtension> lib;
|
||||
lib.instantiate();
|
||||
String abs_path = ProjectSettings::get_singleton()->globalize_path(library_path);
|
||||
|
||||
#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED)
|
||||
// If running on the editor on Windows, we copy the library and open the copy.
|
||||
// This is so the original file isn't locked and can be updated by a compiler.
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
if (!FileAccess::exists(abs_path)) {
|
||||
if (r_error) {
|
||||
*r_error = ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
ERR_PRINT("GDExtension library not found: " + library_path);
|
||||
return Ref<Resource>();
|
||||
}
|
||||
|
||||
// Copy the file to the same directory as the original with a prefix in the name.
|
||||
// This is so relative path to dependencies are satisfied.
|
||||
String copy_path = abs_path.get_base_dir().path_join("~" + abs_path.get_file());
|
||||
|
||||
// If there's a left-over copy (possibly from a crash) then delete it first.
|
||||
if (FileAccess::exists(copy_path)) {
|
||||
DirAccess::remove_absolute(copy_path);
|
||||
}
|
||||
|
||||
Error copy_err = DirAccess::copy_absolute(abs_path, copy_path);
|
||||
if (copy_err) {
|
||||
if (r_error) {
|
||||
*r_error = ERR_CANT_CREATE;
|
||||
}
|
||||
ERR_PRINT("Error copying GDExtension library: " + library_path);
|
||||
return Ref<Resource>();
|
||||
}
|
||||
FileAccess::set_hidden_attribute(copy_path, true);
|
||||
|
||||
// Save the copied path so it can be deleted later.
|
||||
lib->set_temp_library_path(copy_path);
|
||||
|
||||
// Use the copy to open the library.
|
||||
abs_path = copy_path;
|
||||
}
|
||||
#endif
|
||||
err = lib->open_library(abs_path, entry_symbol);
|
||||
|
||||
if (r_error) {
|
||||
|
@ -647,6 +740,12 @@ Ref<Resource> GDExtensionResourceLoader::load(const String &p_path, const String
|
|||
}
|
||||
|
||||
if (err != OK) {
|
||||
#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED)
|
||||
// If the DLL fails to load, make sure that temporary DLL copies are cleaned up.
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
DirAccess::remove_absolute(lib->get_temp_library_path());
|
||||
}
|
||||
#endif
|
||||
// Errors already logged in open_library()
|
||||
return Ref<Resource>();
|
||||
}
|
||||
|
|
|
@ -43,6 +43,9 @@ class GDExtension : public Resource {
|
|||
|
||||
void *library = nullptr; // pointer if valid,
|
||||
String library_path;
|
||||
#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED)
|
||||
String temp_lib_path;
|
||||
#endif
|
||||
|
||||
struct Extension {
|
||||
ObjectGDExtension gdextension;
|
||||
|
@ -50,7 +53,17 @@ class GDExtension : public Resource {
|
|||
|
||||
HashMap<StringName, Extension> extension_classes;
|
||||
|
||||
struct ClassCreationDeprecatedInfo {
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
GDExtensionClassNotification notification_func = nullptr;
|
||||
#endif // DISABLE_DEPRECATED
|
||||
};
|
||||
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
static void _register_extension_class(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo *p_extension_funcs);
|
||||
#endif // DISABLE_DEPRECATED
|
||||
static void _register_extension_class2(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo2 *p_extension_funcs);
|
||||
static void _register_extension_class_internal(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo2 *p_extension_funcs, const ClassCreationDeprecatedInfo *p_deprecated_funcs = nullptr);
|
||||
static void _register_extension_class_method(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, const GDExtensionClassMethodInfo *p_method_info);
|
||||
static void _register_extension_class_integer_constant(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_enum_name, GDExtensionConstStringNamePtr p_constant_name, GDExtensionInt p_constant_value, GDExtensionBool p_is_bitfield);
|
||||
static void _register_extension_class_property(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, const GDExtensionPropertyInfo *p_info, GDExtensionConstStringNamePtr p_setter, GDExtensionConstStringNamePtr p_getter);
|
||||
|
@ -76,6 +89,11 @@ public:
|
|||
Error open_library(const String &p_path, const String &p_entry_symbol);
|
||||
void close_library();
|
||||
|
||||
#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED)
|
||||
void set_temp_library_path(const String &p_path) { temp_lib_path = p_path; }
|
||||
String get_temp_library_path() const { return temp_lib_path; }
|
||||
#endif
|
||||
|
||||
enum InitializationLevel {
|
||||
INITIALIZATION_LEVEL_CORE = GDEXTENSION_INITIALIZATION_CORE,
|
||||
INITIALIZATION_LEVEL_SERVERS = GDEXTENSION_INITIALIZATION_SERVERS,
|
||||
|
|
|
@ -1041,13 +1041,85 @@ static void gdextension_ref_set_object(GDExtensionRefPtr p_ref, GDExtensionObjec
|
|||
ref->reference_ptr(o);
|
||||
}
|
||||
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
static GDExtensionScriptInstancePtr gdextension_script_instance_create(const GDExtensionScriptInstanceInfo *p_info, GDExtensionScriptInstanceDataPtr p_instance_data) {
|
||||
GDExtensionScriptInstanceInfo2 *info_2 = memnew(GDExtensionScriptInstanceInfo2);
|
||||
info_2->set_func = p_info->set_func;
|
||||
info_2->get_func = p_info->get_func;
|
||||
info_2->get_property_list_func = p_info->get_property_list_func;
|
||||
info_2->free_property_list_func = p_info->free_property_list_func;
|
||||
info_2->property_can_revert_func = p_info->property_can_revert_func;
|
||||
info_2->property_get_revert_func = p_info->property_get_revert_func;
|
||||
info_2->get_owner_func = p_info->get_owner_func;
|
||||
info_2->get_property_state_func = p_info->get_property_state_func;
|
||||
info_2->get_method_list_func = p_info->get_method_list_func;
|
||||
info_2->free_method_list_func = p_info->free_method_list_func;
|
||||
info_2->get_property_type_func = p_info->get_property_type_func;
|
||||
info_2->validate_property_func = nullptr;
|
||||
info_2->has_method_func = p_info->has_method_func;
|
||||
info_2->call_func = p_info->call_func;
|
||||
info_2->notification_func = nullptr;
|
||||
info_2->to_string_func = p_info->to_string_func;
|
||||
info_2->refcount_incremented_func = p_info->refcount_incremented_func;
|
||||
info_2->refcount_decremented_func = p_info->refcount_decremented_func;
|
||||
info_2->get_script_func = p_info->get_script_func;
|
||||
info_2->is_placeholder_func = p_info->is_placeholder_func;
|
||||
info_2->set_fallback_func = p_info->set_fallback_func;
|
||||
info_2->get_fallback_func = p_info->get_fallback_func;
|
||||
info_2->get_language_func = p_info->get_language_func;
|
||||
info_2->free_func = p_info->free_func;
|
||||
|
||||
ScriptInstanceExtension *script_instance_extension = memnew(ScriptInstanceExtension);
|
||||
script_instance_extension->instance = p_instance_data;
|
||||
script_instance_extension->native_info = info_2;
|
||||
script_instance_extension->free_native_info = true;
|
||||
script_instance_extension->deprecated_native_info.notification_func = p_info->notification_func;
|
||||
return reinterpret_cast<GDExtensionScriptInstancePtr>(script_instance_extension);
|
||||
}
|
||||
#endif // DISABLE_DEPRECATED
|
||||
|
||||
static GDExtensionScriptInstancePtr gdextension_script_instance_create2(const GDExtensionScriptInstanceInfo2 *p_info, GDExtensionScriptInstanceDataPtr p_instance_data) {
|
||||
ScriptInstanceExtension *script_instance_extension = memnew(ScriptInstanceExtension);
|
||||
script_instance_extension->instance = p_instance_data;
|
||||
script_instance_extension->native_info = p_info;
|
||||
return reinterpret_cast<GDExtensionScriptInstancePtr>(script_instance_extension);
|
||||
}
|
||||
|
||||
static GDExtensionScriptInstancePtr gdextension_placeholder_script_instance_create(GDExtensionObjectPtr p_language, GDExtensionObjectPtr p_script, GDExtensionObjectPtr p_owner) {
|
||||
ScriptLanguage *language = (ScriptLanguage *)p_language;
|
||||
Ref<Script> script;
|
||||
script.reference_ptr((Script *)p_script);
|
||||
Object *owner = (Object *)p_owner;
|
||||
|
||||
PlaceHolderScriptInstance *placeholder = memnew(PlaceHolderScriptInstance(language, script, owner));
|
||||
return reinterpret_cast<GDExtensionScriptInstancePtr>(placeholder);
|
||||
}
|
||||
|
||||
static void gdextension_placeholder_script_instance_update(GDExtensionScriptInstancePtr p_placeholder, GDExtensionConstTypePtr p_properties, GDExtensionConstTypePtr p_values) {
|
||||
PlaceHolderScriptInstance *placeholder = dynamic_cast<PlaceHolderScriptInstance *>(reinterpret_cast<ScriptInstance *>(p_placeholder));
|
||||
ERR_FAIL_NULL_MSG(placeholder, "Unable to update placeholder, expected a PlaceHolderScriptInstance but received an invalid type.");
|
||||
|
||||
const Array &properties = *reinterpret_cast<const Array *>(p_properties);
|
||||
const Dictionary &values = *reinterpret_cast<const Dictionary *>(p_values);
|
||||
|
||||
List<PropertyInfo> properties_list;
|
||||
HashMap<StringName, Variant> values_map;
|
||||
|
||||
for (int i = 0; i < properties.size(); i++) {
|
||||
Dictionary d = properties[i];
|
||||
properties_list.push_back(PropertyInfo::from_dict(d));
|
||||
}
|
||||
|
||||
List<Variant> keys;
|
||||
values.get_key_list(&keys);
|
||||
|
||||
for (const Variant &E : keys) {
|
||||
values_map.insert(E, values[E]);
|
||||
}
|
||||
|
||||
placeholder->update(properties_list, values_map);
|
||||
}
|
||||
|
||||
static GDExtensionScriptInstancePtr gdextension_object_get_script_instance(GDExtensionConstObjectPtr p_object, GDExtensionConstObjectPtr p_language) {
|
||||
if (!p_object || !p_language) {
|
||||
return nullptr;
|
||||
|
@ -1076,7 +1148,7 @@ static GDExtensionMethodBindPtr gdextension_classdb_get_method_bind(GDExtensionC
|
|||
ERR_PRINT("Method '" + classname + "." + methodname + "' has changed and no compatibility fallback has been provided. Please open an issue.");
|
||||
return nullptr;
|
||||
}
|
||||
ERR_FAIL_COND_V(!mb, nullptr);
|
||||
ERR_FAIL_NULL_V(mb, nullptr);
|
||||
if (mb->get_hash() != p_hash) {
|
||||
ERR_PRINT("Hash mismatch for method '" + classname + "." + methodname + "'.");
|
||||
return nullptr;
|
||||
|
@ -1234,7 +1306,12 @@ void gdextension_setup_interface() {
|
|||
REGISTER_INTERFACE_FUNC(object_get_instance_id);
|
||||
REGISTER_INTERFACE_FUNC(ref_get_object);
|
||||
REGISTER_INTERFACE_FUNC(ref_set_object);
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
REGISTER_INTERFACE_FUNC(script_instance_create);
|
||||
#endif // DISABLE_DEPRECATED
|
||||
REGISTER_INTERFACE_FUNC(script_instance_create2);
|
||||
REGISTER_INTERFACE_FUNC(placeholder_script_instance_create);
|
||||
REGISTER_INTERFACE_FUNC(placeholder_script_instance_update);
|
||||
REGISTER_INTERFACE_FUNC(object_get_script_instance);
|
||||
REGISTER_INTERFACE_FUNC(classdb_construct_object);
|
||||
REGISTER_INTERFACE_FUNC(classdb_get_method_bind);
|
||||
|
|
|
@ -258,7 +258,9 @@ typedef const GDExtensionPropertyInfo *(*GDExtensionClassGetPropertyList)(GDExte
|
|||
typedef void (*GDExtensionClassFreePropertyList)(GDExtensionClassInstancePtr p_instance, const GDExtensionPropertyInfo *p_list);
|
||||
typedef GDExtensionBool (*GDExtensionClassPropertyCanRevert)(GDExtensionClassInstancePtr p_instance, GDExtensionConstStringNamePtr p_name);
|
||||
typedef GDExtensionBool (*GDExtensionClassPropertyGetRevert)(GDExtensionClassInstancePtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionVariantPtr r_ret);
|
||||
typedef void (*GDExtensionClassNotification)(GDExtensionClassInstancePtr p_instance, int32_t p_what);
|
||||
typedef GDExtensionBool (*GDExtensionClassValidateProperty)(GDExtensionClassInstancePtr p_instance, GDExtensionPropertyInfo *p_property);
|
||||
typedef void (*GDExtensionClassNotification)(GDExtensionClassInstancePtr p_instance, int32_t p_what); // Deprecated. Use GDExtensionClassNotification2 instead.
|
||||
typedef void (*GDExtensionClassNotification2)(GDExtensionClassInstancePtr p_instance, int32_t p_what, GDExtensionBool p_reversed);
|
||||
typedef void (*GDExtensionClassToString)(GDExtensionClassInstancePtr p_instance, GDExtensionBool *r_is_valid, GDExtensionStringPtr p_out);
|
||||
typedef void (*GDExtensionClassReference)(GDExtensionClassInstancePtr p_instance);
|
||||
typedef void (*GDExtensionClassUnreference)(GDExtensionClassInstancePtr p_instance);
|
||||
|
@ -285,7 +287,29 @@ typedef struct {
|
|||
GDExtensionClassGetVirtual get_virtual_func; // Queries a virtual function by name and returns a callback to invoke the requested virtual function.
|
||||
GDExtensionClassGetRID get_rid_func;
|
||||
void *class_userdata; // Per-class user data, later accessible in instance bindings.
|
||||
} GDExtensionClassCreationInfo;
|
||||
} GDExtensionClassCreationInfo; // Deprecated. Use GDExtensionClassCreationInfo2 instead.
|
||||
|
||||
typedef struct {
|
||||
GDExtensionBool is_virtual;
|
||||
GDExtensionBool is_abstract;
|
||||
GDExtensionBool is_exposed;
|
||||
GDExtensionClassSet set_func;
|
||||
GDExtensionClassGet get_func;
|
||||
GDExtensionClassGetPropertyList get_property_list_func;
|
||||
GDExtensionClassFreePropertyList free_property_list_func;
|
||||
GDExtensionClassPropertyCanRevert property_can_revert_func;
|
||||
GDExtensionClassPropertyGetRevert property_get_revert_func;
|
||||
GDExtensionClassValidateProperty validate_property_func;
|
||||
GDExtensionClassNotification2 notification_func;
|
||||
GDExtensionClassToString to_string_func;
|
||||
GDExtensionClassReference reference_func;
|
||||
GDExtensionClassUnreference unreference_func;
|
||||
GDExtensionClassCreateInstance create_instance_func; // (Default) constructor; mandatory. If the class is not instantiable, consider making it virtual or abstract.
|
||||
GDExtensionClassFreeInstance free_instance_func; // Destructor; mandatory.
|
||||
GDExtensionClassGetVirtual get_virtual_func; // Queries a virtual function by name and returns a callback to invoke the requested virtual function.
|
||||
GDExtensionClassGetRID get_rid_func;
|
||||
void *class_userdata; // Per-class user data, later accessible in instance bindings.
|
||||
} GDExtensionClassCreationInfo2;
|
||||
|
||||
typedef void *GDExtensionClassLibraryPtr;
|
||||
|
||||
|
@ -352,6 +376,7 @@ typedef GDExtensionBool (*GDExtensionScriptInstanceGet)(GDExtensionScriptInstanc
|
|||
typedef const GDExtensionPropertyInfo *(*GDExtensionScriptInstanceGetPropertyList)(GDExtensionScriptInstanceDataPtr p_instance, uint32_t *r_count);
|
||||
typedef void (*GDExtensionScriptInstanceFreePropertyList)(GDExtensionScriptInstanceDataPtr p_instance, const GDExtensionPropertyInfo *p_list);
|
||||
typedef GDExtensionVariantType (*GDExtensionScriptInstanceGetPropertyType)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionBool *r_is_valid);
|
||||
typedef GDExtensionBool (*GDExtensionScriptInstanceValidateProperty)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionPropertyInfo *p_property);
|
||||
|
||||
typedef GDExtensionBool (*GDExtensionScriptInstancePropertyCanRevert)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name);
|
||||
typedef GDExtensionBool (*GDExtensionScriptInstancePropertyGetRevert)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionVariantPtr r_ret);
|
||||
|
@ -366,7 +391,8 @@ typedef void (*GDExtensionScriptInstanceFreeMethodList)(GDExtensionScriptInstanc
|
|||
typedef GDExtensionBool (*GDExtensionScriptInstanceHasMethod)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name);
|
||||
|
||||
typedef void (*GDExtensionScriptInstanceCall)(GDExtensionScriptInstanceDataPtr p_self, GDExtensionConstStringNamePtr p_method, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionVariantPtr r_return, GDExtensionCallError *r_error);
|
||||
typedef void (*GDExtensionScriptInstanceNotification)(GDExtensionScriptInstanceDataPtr p_instance, int32_t p_what);
|
||||
typedef void (*GDExtensionScriptInstanceNotification)(GDExtensionScriptInstanceDataPtr p_instance, int32_t p_what); // Deprecated. Use GDExtensionScriptInstanceNotification2 instead.
|
||||
typedef void (*GDExtensionScriptInstanceNotification2)(GDExtensionScriptInstanceDataPtr p_instance, int32_t p_what, GDExtensionBool p_reversed);
|
||||
typedef void (*GDExtensionScriptInstanceToString)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionBool *r_is_valid, GDExtensionStringPtr r_out);
|
||||
|
||||
typedef void (*GDExtensionScriptInstanceRefCountIncremented)(GDExtensionScriptInstanceDataPtr p_instance);
|
||||
|
@ -420,7 +446,47 @@ typedef struct {
|
|||
|
||||
GDExtensionScriptInstanceFree free_func;
|
||||
|
||||
} GDExtensionScriptInstanceInfo;
|
||||
} GDExtensionScriptInstanceInfo; // Deprecated. Use GDExtensionScriptInstanceInfo2 instead.
|
||||
|
||||
typedef struct {
|
||||
GDExtensionScriptInstanceSet set_func;
|
||||
GDExtensionScriptInstanceGet get_func;
|
||||
GDExtensionScriptInstanceGetPropertyList get_property_list_func;
|
||||
GDExtensionScriptInstanceFreePropertyList free_property_list_func;
|
||||
|
||||
GDExtensionScriptInstancePropertyCanRevert property_can_revert_func;
|
||||
GDExtensionScriptInstancePropertyGetRevert property_get_revert_func;
|
||||
|
||||
GDExtensionScriptInstanceGetOwner get_owner_func;
|
||||
GDExtensionScriptInstanceGetPropertyState get_property_state_func;
|
||||
|
||||
GDExtensionScriptInstanceGetMethodList get_method_list_func;
|
||||
GDExtensionScriptInstanceFreeMethodList free_method_list_func;
|
||||
GDExtensionScriptInstanceGetPropertyType get_property_type_func;
|
||||
GDExtensionScriptInstanceValidateProperty validate_property_func;
|
||||
|
||||
GDExtensionScriptInstanceHasMethod has_method_func;
|
||||
|
||||
GDExtensionScriptInstanceCall call_func;
|
||||
GDExtensionScriptInstanceNotification2 notification_func;
|
||||
|
||||
GDExtensionScriptInstanceToString to_string_func;
|
||||
|
||||
GDExtensionScriptInstanceRefCountIncremented refcount_incremented_func;
|
||||
GDExtensionScriptInstanceRefCountDecremented refcount_decremented_func;
|
||||
|
||||
GDExtensionScriptInstanceGetScript get_script_func;
|
||||
|
||||
GDExtensionScriptInstanceIsPlaceholder is_placeholder_func;
|
||||
|
||||
GDExtensionScriptInstanceSet set_fallback_func;
|
||||
GDExtensionScriptInstanceGet get_fallback_func;
|
||||
|
||||
GDExtensionScriptInstanceGetLanguage get_language_func;
|
||||
|
||||
GDExtensionScriptInstanceFree free_func;
|
||||
|
||||
} GDExtensionScriptInstanceInfo2;
|
||||
|
||||
/* INITIALIZATION */
|
||||
|
||||
|
@ -2116,6 +2182,7 @@ typedef void (*GDExtensionInterfaceRefSetObject)(GDExtensionRefPtr p_ref, GDExte
|
|||
/**
|
||||
* @name script_instance_create
|
||||
* @since 4.1
|
||||
* @deprecated in Godot 4.2. Use `script_instance_create2` instead.
|
||||
*
|
||||
* Creates a script instance that contains the given info and instance data.
|
||||
*
|
||||
|
@ -2126,6 +2193,50 @@ typedef void (*GDExtensionInterfaceRefSetObject)(GDExtensionRefPtr p_ref, GDExte
|
|||
*/
|
||||
typedef GDExtensionScriptInstancePtr (*GDExtensionInterfaceScriptInstanceCreate)(const GDExtensionScriptInstanceInfo *p_info, GDExtensionScriptInstanceDataPtr p_instance_data);
|
||||
|
||||
/**
|
||||
* @name script_instance_create2
|
||||
* @since 4.2
|
||||
*
|
||||
* Creates a script instance that contains the given info and instance data.
|
||||
*
|
||||
* @param p_info A pointer to a GDExtensionScriptInstanceInfo2 struct.
|
||||
* @param p_instance_data A pointer to a data representing the script instance in the GDExtension. This will be passed to all the function pointers on p_info.
|
||||
*
|
||||
* @return A pointer to a ScriptInstanceExtension object.
|
||||
*/
|
||||
typedef GDExtensionScriptInstancePtr (*GDExtensionInterfaceScriptInstanceCreate2)(const GDExtensionScriptInstanceInfo2 *p_info, GDExtensionScriptInstanceDataPtr p_instance_data);
|
||||
|
||||
/**
|
||||
* @name placeholder_script_instance_create
|
||||
* @since 4.2
|
||||
*
|
||||
* Creates a placeholder script instance for a given script and instance.
|
||||
*
|
||||
* This interface is optional as a custom placeholder could also be created with script_instance_create().
|
||||
*
|
||||
* @param p_language A pointer to a ScriptLanguage.
|
||||
* @param p_script A pointer to a Script.
|
||||
* @param p_owner A pointer to an Object.
|
||||
*
|
||||
* @return A pointer to a PlaceHolderScriptInstance object.
|
||||
*/
|
||||
typedef GDExtensionScriptInstancePtr (*GDExtensionInterfacePlaceHolderScriptInstanceCreate)(GDExtensionObjectPtr p_language, GDExtensionObjectPtr p_script, GDExtensionObjectPtr p_owner);
|
||||
|
||||
/**
|
||||
* @name placeholder_script_instance_update
|
||||
* @since 4.2
|
||||
*
|
||||
* Updates a placeholder script instance with the given properties and values.
|
||||
*
|
||||
* The passed in placeholder must be an instance of PlaceHolderScriptInstance
|
||||
* such as the one returned by placeholder_script_instance_create().
|
||||
*
|
||||
* @param p_placeholder A pointer to a PlaceHolderScriptInstance.
|
||||
* @param p_properties A pointer to an Array of Dictionary representing PropertyInfo.
|
||||
* @param p_values A pointer to a Dictionary mapping StringName to Variant values.
|
||||
*/
|
||||
typedef void (*GDExtensionInterfacePlaceHolderScriptInstanceUpdate)(GDExtensionScriptInstancePtr p_placeholder, GDExtensionConstTypePtr p_properties, GDExtensionConstTypePtr p_values);
|
||||
|
||||
/**
|
||||
* @name object_get_script_instance
|
||||
* @since 4.2
|
||||
|
@ -2186,6 +2297,7 @@ typedef void *(*GDExtensionInterfaceClassdbGetClassTag)(GDExtensionConstStringNa
|
|||
/**
|
||||
* @name classdb_register_extension_class
|
||||
* @since 4.1
|
||||
* @deprecated in Godot 4.2. Use `classdb_register_extension_class2` instead.
|
||||
*
|
||||
* Registers an extension class in the ClassDB.
|
||||
*
|
||||
|
@ -2198,6 +2310,21 @@ typedef void *(*GDExtensionInterfaceClassdbGetClassTag)(GDExtensionConstStringNa
|
|||
*/
|
||||
typedef void (*GDExtensionInterfaceClassdbRegisterExtensionClass)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo *p_extension_funcs);
|
||||
|
||||
/**
|
||||
* @name classdb_register_extension_class2
|
||||
* @since 4.2
|
||||
*
|
||||
* Registers an extension class in the ClassDB.
|
||||
*
|
||||
* Provided struct can be safely freed once the function returns.
|
||||
*
|
||||
* @param p_library A pointer the library received by the GDExtension's entry point function.
|
||||
* @param p_class_name A pointer to a StringName with the class name.
|
||||
* @param p_parent_class_name A pointer to a StringName with the parent class name.
|
||||
* @param p_extension_funcs A pointer to a GDExtensionClassCreationInfo2 struct.
|
||||
*/
|
||||
typedef void (*GDExtensionInterfaceClassdbRegisterExtensionClass2)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo2 *p_extension_funcs);
|
||||
|
||||
/**
|
||||
* @name classdb_register_extension_class_method
|
||||
* @since 4.1
|
||||
|
|
|
@ -143,6 +143,8 @@ void GDExtensionManager::load_extensions() {
|
|||
ERR_CONTINUE_MSG(err == LOAD_STATUS_FAILED, "Error loading extension: " + s);
|
||||
}
|
||||
}
|
||||
|
||||
OS::get_singleton()->load_platform_gdextensions();
|
||||
}
|
||||
|
||||
GDExtensionManager *GDExtensionManager::get_singleton() {
|
||||
|
|
|
@ -33,6 +33,3 @@ Linux20d6a713,Bensussen Deutsch & Associates Inc.(BDA) NSW Wired controller,a:b1
|
|||
Linux054c05c4,Sony Computer Entertainment Wireless Controller,a:b0,b:b1,y:b2,x:b3,start:b9,back:b8,leftstick:b11,rightstick:b12,leftshoulder:b4,rightshoulder:b5,dpup:-a7,dpleft:-a6,dpdown:+a7,dpright:+a6,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,platform:Web
|
||||
Linux18d19400,18d1-9400-Google LLC Stadia Controller rev. A,a:b0,b:b1,y:b3,x:b2,start:b7,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:-a7,dpleft:-a6,dpdown:+a7,dpright:+a6,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a5,righttrigger:a4,platform:Web
|
||||
Linux054c0268,054c-0268-Sony PLAYSTATION(R)3 Controller,a:b0,b:b1,y:b2,x:b3,start:b9,guide:b10,back:b8,leftstick:b11,rightstick:b12,leftshoulder:b4,rightshoulder:b5,dpup:b13,dpleft:b15,dpdown:b14,dpright:b16,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,platform:Web
|
||||
|
||||
# UWP
|
||||
__UWP_GAMEPAD__,Xbox Controller,a:b2,b:b3,x:b4,y:b5,start:b0,back:b1,leftstick:b12,rightstick:b13,leftshoulder:b10,rightshoulder:b11,dpup:b6,dpdown:b7,dpleft:b8,dpright:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,platform:UWP,
|
||||
|
|
|
@ -285,7 +285,7 @@ bool Input::is_joy_button_pressed(int p_device, JoyButton p_button) const {
|
|||
|
||||
bool Input::is_action_pressed(const StringName &p_action, bool p_exact) const {
|
||||
ERR_FAIL_COND_V_MSG(!InputMap::get_singleton()->has_action(p_action), false, InputMap::get_singleton()->suggest_actions(p_action));
|
||||
return action_state.has(p_action) && action_state[p_action].pressed && (p_exact ? action_state[p_action].exact : true);
|
||||
return action_state.has(p_action) && action_state[p_action].pressed > 0 && (p_exact ? action_state[p_action].exact : true);
|
||||
}
|
||||
|
||||
bool Input::is_action_just_pressed(const StringName &p_action, bool p_exact) const {
|
||||
|
@ -697,25 +697,53 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
|
|||
for (const KeyValue<StringName, InputMap::Action> &E : InputMap::get_singleton()->get_action_map()) {
|
||||
if (InputMap::get_singleton()->event_is_action(p_event, E.key)) {
|
||||
Action &action = action_state[E.key];
|
||||
// If not echo and action pressed state has changed
|
||||
if (!p_event->is_echo() && is_action_pressed(E.key, false) != p_event->is_action_pressed(E.key)) {
|
||||
bool is_pressed = false;
|
||||
|
||||
if (!p_event->is_echo()) {
|
||||
if (p_event->is_action_pressed(E.key)) {
|
||||
action.pressed = true;
|
||||
if (jm.is_valid()) {
|
||||
// If axis is already pressed, don't increase the pressed counter.
|
||||
if (!action.axis_pressed) {
|
||||
action.pressed++;
|
||||
action.axis_pressed = true;
|
||||
}
|
||||
} else {
|
||||
action.pressed++;
|
||||
}
|
||||
|
||||
is_pressed = true;
|
||||
if (action.pressed == 1) {
|
||||
action.pressed_physics_frame = Engine::get_singleton()->get_physics_frames();
|
||||
action.pressed_process_frame = Engine::get_singleton()->get_process_frames();
|
||||
}
|
||||
} else {
|
||||
action.pressed = false;
|
||||
bool is_released = true;
|
||||
if (jm.is_valid()) {
|
||||
// Same as above. Don't release axis when not pressed.
|
||||
if (action.axis_pressed) {
|
||||
action.axis_pressed = false;
|
||||
} else {
|
||||
is_released = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_released) {
|
||||
if (action.pressed == 1) {
|
||||
action.released_physics_frame = Engine::get_singleton()->get_physics_frames();
|
||||
action.released_process_frame = Engine::get_singleton()->get_process_frames();
|
||||
}
|
||||
action.strength = 0.0f;
|
||||
action.raw_strength = 0.0f;
|
||||
action.pressed = MAX(action.pressed - 1, 0);
|
||||
}
|
||||
}
|
||||
action.exact = InputMap::get_singleton()->event_is_action(p_event, E.key, true);
|
||||
}
|
||||
|
||||
if (is_pressed || action.pressed == 0) {
|
||||
action.strength = p_event->get_action_strength(E.key);
|
||||
action.raw_strength = p_event->get_action_raw_strength(E.key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event_dispatch_function) {
|
||||
_THREAD_SAFE_UNLOCK_
|
||||
|
@ -831,9 +859,11 @@ void Input::action_press(const StringName &p_action, float p_strength) {
|
|||
// Create or retrieve existing action.
|
||||
Action &action = action_state[p_action];
|
||||
|
||||
action.pressed++;
|
||||
if (action.pressed == 1) {
|
||||
action.pressed_physics_frame = Engine::get_singleton()->get_physics_frames();
|
||||
action.pressed_process_frame = Engine::get_singleton()->get_process_frames();
|
||||
action.pressed = true;
|
||||
}
|
||||
action.strength = p_strength;
|
||||
action.raw_strength = p_strength;
|
||||
action.exact = true;
|
||||
|
@ -843,9 +873,11 @@ void Input::action_release(const StringName &p_action) {
|
|||
// Create or retrieve existing action.
|
||||
Action &action = action_state[p_action];
|
||||
|
||||
action.pressed--;
|
||||
if (action.pressed == 0) {
|
||||
action.released_physics_frame = Engine::get_singleton()->get_physics_frames();
|
||||
action.released_process_frame = Engine::get_singleton()->get_process_frames();
|
||||
action.pressed = false;
|
||||
}
|
||||
action.strength = 0.0f;
|
||||
action.raw_strength = 0.0f;
|
||||
action.exact = true;
|
||||
|
@ -1006,8 +1038,10 @@ void Input::release_pressed_events() {
|
|||
joy_buttons_pressed.clear();
|
||||
_joy_axis.clear();
|
||||
|
||||
for (const KeyValue<StringName, Input::Action> &E : action_state) {
|
||||
if (E.value.pressed) {
|
||||
for (KeyValue<StringName, Input::Action> &E : action_state) {
|
||||
if (E.value.pressed > 0) {
|
||||
// Make sure the action is really released.
|
||||
E.value.pressed = 1;
|
||||
action_release(E.key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,7 +103,8 @@ private:
|
|||
uint64_t pressed_process_frame = UINT64_MAX;
|
||||
uint64_t released_physics_frame = UINT64_MAX;
|
||||
uint64_t released_process_frame = UINT64_MAX;
|
||||
bool pressed = false;
|
||||
int pressed = 0;
|
||||
bool axis_pressed = false;
|
||||
bool exact = true;
|
||||
float strength = 0.0f;
|
||||
float raw_strength = 0.0f;
|
||||
|
|
|
@ -51,7 +51,6 @@ def make_default_controller_mappings(target, source, env):
|
|||
"Android": "#if defined(__ANDROID__)",
|
||||
"iOS": "#ifdef IOS_ENABLED",
|
||||
"Web": "#ifdef WEB_ENABLED",
|
||||
"UWP": "#ifdef UWP_ENABLED",
|
||||
}
|
||||
|
||||
g.write("const char* DefaultControllerMappings::mappings[] = {\n")
|
||||
|
|
|
@ -1722,7 +1722,27 @@ String InputEventMIDI::as_text() const {
|
|||
}
|
||||
|
||||
String InputEventMIDI::to_string() {
|
||||
return vformat("InputEventMIDI: channel=%d, message=%d, pitch=%d, velocity=%d, pressure=%d, controller_number=%d, controller_value=%d", channel, message, pitch, velocity, pressure, controller_number, controller_value);
|
||||
String ret;
|
||||
switch (message) {
|
||||
case MIDIMessage::NOTE_ON:
|
||||
ret = vformat("Note On: channel=%d, pitch=%d, velocity=%d", channel, pitch, velocity);
|
||||
break;
|
||||
case MIDIMessage::NOTE_OFF:
|
||||
ret = vformat("Note Off: channel=%d, pitch=%d, velocity=%d", channel, pitch, velocity);
|
||||
break;
|
||||
case MIDIMessage::PITCH_BEND:
|
||||
ret = vformat("Pitch Bend: channel=%d, pitch=%d", channel, pitch);
|
||||
break;
|
||||
case MIDIMessage::CHANNEL_PRESSURE:
|
||||
ret = vformat("Channel Pressure: channel=%d, pressure=%d", channel, pressure);
|
||||
break;
|
||||
case MIDIMessage::CONTROL_CHANGE:
|
||||
ret = vformat("Control Change: channel=%d, controller_number=%d, controller_value=%d", channel, controller_number, controller_value);
|
||||
break;
|
||||
default:
|
||||
ret = vformat("channel=%d, message=%d, pitch=%d, velocity=%d, pressure=%d, controller_number=%d, controller_value=%d, instrument=%d", channel, message, pitch, velocity, pressure, controller_number, controller_value, instrument);
|
||||
}
|
||||
return "InputEventMIDI: " + ret;
|
||||
}
|
||||
|
||||
void InputEventMIDI::_bind_methods() {
|
||||
|
|
|
@ -215,7 +215,7 @@ int Compression::decompress_dynamic(Vector<uint8_t> *p_dst_vect, int p_max_dst_s
|
|||
#ifdef BROTLI_ENABLED
|
||||
BrotliDecoderResult ret;
|
||||
BrotliDecoderState *state = BrotliDecoderCreateInstance(nullptr, nullptr, nullptr);
|
||||
ERR_FAIL_COND_V(state == nullptr, Z_DATA_ERROR);
|
||||
ERR_FAIL_NULL_V(state, Z_DATA_ERROR);
|
||||
|
||||
// Setup the stream inputs.
|
||||
const uint8_t *next_in = p_src;
|
||||
|
|
|
@ -79,7 +79,7 @@ Error FileAccessMemory::open_custom(const uint8_t *p_data, uint64_t p_len) {
|
|||
}
|
||||
|
||||
Error FileAccessMemory::open_internal(const String &p_path, int p_mode_flags) {
|
||||
ERR_FAIL_COND_V(!files, ERR_FILE_NOT_FOUND);
|
||||
ERR_FAIL_NULL_V(files, ERR_FILE_NOT_FOUND);
|
||||
|
||||
String name = fix_path(p_path);
|
||||
//name = DirAccess::normalize_path(name);
|
||||
|
@ -99,22 +99,22 @@ bool FileAccessMemory::is_open() const {
|
|||
}
|
||||
|
||||
void FileAccessMemory::seek(uint64_t p_position) {
|
||||
ERR_FAIL_COND(!data);
|
||||
ERR_FAIL_NULL(data);
|
||||
pos = p_position;
|
||||
}
|
||||
|
||||
void FileAccessMemory::seek_end(int64_t p_position) {
|
||||
ERR_FAIL_COND(!data);
|
||||
ERR_FAIL_NULL(data);
|
||||
pos = length + p_position;
|
||||
}
|
||||
|
||||
uint64_t FileAccessMemory::get_position() const {
|
||||
ERR_FAIL_COND_V(!data, 0);
|
||||
ERR_FAIL_NULL_V(data, 0);
|
||||
return pos;
|
||||
}
|
||||
|
||||
uint64_t FileAccessMemory::get_length() const {
|
||||
ERR_FAIL_COND_V(!data, 0);
|
||||
ERR_FAIL_NULL_V(data, 0);
|
||||
return length;
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ uint8_t FileAccessMemory::get_8() const {
|
|||
|
||||
uint64_t FileAccessMemory::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
|
||||
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);
|
||||
ERR_FAIL_COND_V(!data, -1);
|
||||
ERR_FAIL_NULL_V(data, -1);
|
||||
|
||||
uint64_t left = length - pos;
|
||||
uint64_t read = MIN(p_length, left);
|
||||
|
@ -154,11 +154,11 @@ Error FileAccessMemory::get_error() const {
|
|||
}
|
||||
|
||||
void FileAccessMemory::flush() {
|
||||
ERR_FAIL_COND(!data);
|
||||
ERR_FAIL_NULL(data);
|
||||
}
|
||||
|
||||
void FileAccessMemory::store_8(uint8_t p_byte) {
|
||||
ERR_FAIL_COND(!data);
|
||||
ERR_FAIL_NULL(data);
|
||||
ERR_FAIL_COND(pos >= length);
|
||||
data[pos++] = p_byte;
|
||||
}
|
||||
|
|
|
@ -239,7 +239,7 @@ Error FileAccessZip::open_internal(const String &p_path, int p_mode_flags) {
|
|||
|
||||
ERR_FAIL_COND_V(p_mode_flags & FileAccess::WRITE, FAILED);
|
||||
ZipArchive *arch = ZipArchive::get_singleton();
|
||||
ERR_FAIL_COND_V(!arch, FAILED);
|
||||
ERR_FAIL_NULL_V(arch, FAILED);
|
||||
zfile = arch->get_file_handle(p_path);
|
||||
ERR_FAIL_COND_V(!zfile, FAILED);
|
||||
|
||||
|
@ -255,7 +255,7 @@ void FileAccessZip::_close() {
|
|||
}
|
||||
|
||||
ZipArchive *arch = ZipArchive::get_singleton();
|
||||
ERR_FAIL_COND(!arch);
|
||||
ERR_FAIL_NULL(arch);
|
||||
arch->close_handle(zfile);
|
||||
zfile = nullptr;
|
||||
}
|
||||
|
|
|
@ -2356,7 +2356,7 @@ void Image::initialize_data(const char **p_xpm) {
|
|||
}
|
||||
|
||||
Color *colorptr = colormap.getptr(pixelstr);
|
||||
ERR_FAIL_COND(!colorptr);
|
||||
ERR_FAIL_NULL(colorptr);
|
||||
uint8_t pixel[4];
|
||||
for (uint32_t i = 0; i < pixel_size; i++) {
|
||||
pixel[i] = CLAMP((*colorptr)[i] * 255, 0, 255);
|
||||
|
@ -2646,23 +2646,23 @@ Error Image::compress_from_channels(CompressMode p_mode, UsedChannels p_channels
|
|||
|
||||
switch (p_mode) {
|
||||
case COMPRESS_S3TC: {
|
||||
ERR_FAIL_COND_V(!_image_compress_bc_func, ERR_UNAVAILABLE);
|
||||
ERR_FAIL_NULL_V(_image_compress_bc_func, ERR_UNAVAILABLE);
|
||||
_image_compress_bc_func(this, p_channels);
|
||||
} break;
|
||||
case COMPRESS_ETC: {
|
||||
ERR_FAIL_COND_V(!_image_compress_etc1_func, ERR_UNAVAILABLE);
|
||||
ERR_FAIL_NULL_V(_image_compress_etc1_func, ERR_UNAVAILABLE);
|
||||
_image_compress_etc1_func(this);
|
||||
} break;
|
||||
case COMPRESS_ETC2: {
|
||||
ERR_FAIL_COND_V(!_image_compress_etc2_func, ERR_UNAVAILABLE);
|
||||
ERR_FAIL_NULL_V(_image_compress_etc2_func, ERR_UNAVAILABLE);
|
||||
_image_compress_etc2_func(this, p_channels);
|
||||
} break;
|
||||
case COMPRESS_BPTC: {
|
||||
ERR_FAIL_COND_V(!_image_compress_bptc_func, ERR_UNAVAILABLE);
|
||||
ERR_FAIL_NULL_V(_image_compress_bptc_func, ERR_UNAVAILABLE);
|
||||
_image_compress_bptc_func(this, p_channels);
|
||||
} break;
|
||||
case COMPRESS_ASTC: {
|
||||
ERR_FAIL_COND_V(!_image_compress_astc_func, ERR_UNAVAILABLE);
|
||||
ERR_FAIL_NULL_V(_image_compress_astc_func, ERR_UNAVAILABLE);
|
||||
_image_compress_astc_func(this, p_astc_format);
|
||||
} break;
|
||||
case COMPRESS_MAX: {
|
||||
|
@ -3017,7 +3017,7 @@ ImageMemLoadFunc Image::_webp_mem_loader_func = nullptr;
|
|||
ImageMemLoadFunc Image::_tga_mem_loader_func = nullptr;
|
||||
ImageMemLoadFunc Image::_bmp_mem_loader_func = nullptr;
|
||||
ScalableImageMemLoadFunc Image::_svg_scalable_mem_loader_func = nullptr;
|
||||
ImageMemLoadFunc Image::_dds_mem_loader_func = nullptr;
|
||||
ImageMemLoadFunc Image::_ktx_mem_loader_func = nullptr;
|
||||
|
||||
void (*Image::_image_compress_bc_func)(Image *, Image::UsedChannels) = nullptr;
|
||||
void (*Image::_image_compress_bptc_func)(Image *, Image::UsedChannels) = nullptr;
|
||||
|
@ -3489,7 +3489,7 @@ void Image::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("load_webp_from_buffer", "buffer"), &Image::load_webp_from_buffer);
|
||||
ClassDB::bind_method(D_METHOD("load_tga_from_buffer", "buffer"), &Image::load_tga_from_buffer);
|
||||
ClassDB::bind_method(D_METHOD("load_bmp_from_buffer", "buffer"), &Image::load_bmp_from_buffer);
|
||||
ClassDB::bind_method(D_METHOD("load_dds_from_buffer", "buffer"), &Image::load_dds_from_buffer);
|
||||
ClassDB::bind_method(D_METHOD("load_ktx_from_buffer", "buffer"), &Image::load_ktx_from_buffer);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("load_svg_from_buffer", "buffer", "scale"), &Image::load_svg_from_buffer, DEFVAL(1.0));
|
||||
ClassDB::bind_method(D_METHOD("load_svg_from_string", "svg_str", "scale"), &Image::load_svg_from_string, DEFVAL(1.0));
|
||||
|
@ -3655,7 +3655,7 @@ void Image::bump_map_to_normal_map(float bump_scale) {
|
|||
const uint8_t *rp = data.ptr();
|
||||
uint8_t *wp = result_image.ptrw();
|
||||
|
||||
ERR_FAIL_COND(!rp);
|
||||
ERR_FAIL_NULL(rp);
|
||||
|
||||
unsigned char *write_ptr = wp;
|
||||
float *read_ptr = (float *)rp;
|
||||
|
@ -3865,12 +3865,12 @@ Error Image::load_svg_from_string(const String &p_svg_str, float scale) {
|
|||
return load_svg_from_buffer(p_svg_str.to_utf8_buffer(), scale);
|
||||
}
|
||||
|
||||
Error Image::load_dds_from_buffer(const Vector<uint8_t> &p_array) {
|
||||
Error Image::load_ktx_from_buffer(const Vector<uint8_t> &p_array) {
|
||||
ERR_FAIL_NULL_V_MSG(
|
||||
_dds_mem_loader_func,
|
||||
_ktx_mem_loader_func,
|
||||
ERR_UNAVAILABLE,
|
||||
"The DDS module isn't enabled. Recompile the Godot editor or export template binary with the `module_dds_enabled=yes` SCons option.");
|
||||
return _load_from_buffer(p_array, _dds_mem_loader_func);
|
||||
"The KTX module isn't enabled. Recompile the Godot editor or export template binary with the `module_ktx_enabled=yes` SCons option.");
|
||||
return _load_from_buffer(p_array, _ktx_mem_loader_func);
|
||||
}
|
||||
|
||||
void Image::convert_rg_to_ra_rgba8() {
|
||||
|
@ -3916,7 +3916,7 @@ Error Image::_load_from_buffer(const Vector<uint8_t> &p_array, ImageMemLoadFunc
|
|||
int buffer_size = p_array.size();
|
||||
|
||||
ERR_FAIL_COND_V(buffer_size == 0, ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_COND_V(!p_loader, ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_NULL_V(p_loader, ERR_INVALID_PARAMETER);
|
||||
|
||||
const uint8_t *r = p_array.ptr();
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ public:
|
|||
static ImageMemLoadFunc _tga_mem_loader_func;
|
||||
static ImageMemLoadFunc _bmp_mem_loader_func;
|
||||
static ScalableImageMemLoadFunc _svg_scalable_mem_loader_func;
|
||||
static ImageMemLoadFunc _dds_mem_loader_func;
|
||||
static ImageMemLoadFunc _ktx_mem_loader_func;
|
||||
|
||||
static void (*_image_compress_bc_func)(Image *, UsedChannels p_channels);
|
||||
static void (*_image_compress_bptc_func)(Image *, UsedChannels p_channels);
|
||||
|
@ -403,7 +403,7 @@ public:
|
|||
Error load_webp_from_buffer(const Vector<uint8_t> &p_array);
|
||||
Error load_tga_from_buffer(const Vector<uint8_t> &p_array);
|
||||
Error load_bmp_from_buffer(const Vector<uint8_t> &p_array);
|
||||
Error load_dds_from_buffer(const Vector<uint8_t> &p_array);
|
||||
Error load_ktx_from_buffer(const Vector<uint8_t> &p_array);
|
||||
|
||||
Error load_svg_from_buffer(const Vector<uint8_t> &p_array, float scale = 1.0);
|
||||
Error load_svg_from_string(const String &p_svg_str, float scale = 1.0);
|
||||
|
|
|
@ -333,7 +333,7 @@ IP *(*IP::_create)() = nullptr;
|
|||
|
||||
IP *IP::create() {
|
||||
ERR_FAIL_COND_V_MSG(singleton, nullptr, "IP singleton already exist.");
|
||||
ERR_FAIL_COND_V(!_create, nullptr);
|
||||
ERR_FAIL_NULL_V(_create, nullptr);
|
||||
return _create();
|
||||
}
|
||||
|
||||
|
|
|
@ -640,7 +640,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
|
|||
} else {
|
||||
Object *obj = ClassDB::instantiate(str);
|
||||
|
||||
ERR_FAIL_COND_V(!obj, ERR_UNAVAILABLE);
|
||||
ERR_FAIL_NULL_V(obj, ERR_UNAVAILABLE);
|
||||
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
||||
|
||||
int32_t count = decode_uint32(buf);
|
||||
|
@ -1576,7 +1576,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
|
|||
buf += len;
|
||||
}
|
||||
Variant *v = d.getptr(E);
|
||||
ERR_FAIL_COND_V(!v, ERR_BUG);
|
||||
ERR_FAIL_NULL_V(v, ERR_BUG);
|
||||
err = encode_variant(*v, buf, len, p_full_objects, p_depth + 1);
|
||||
ERR_FAIL_COND_V(err, err);
|
||||
ERR_FAIL_COND_V(len % 4, ERR_BUG);
|
||||
|
|
|
@ -125,7 +125,7 @@ Variant PackedDataContainer::_get_at_ofs(uint32_t p_ofs, const uint8_t *p_buf, b
|
|||
uint32_t PackedDataContainer::_type_at_ofs(uint32_t p_ofs) const {
|
||||
ERR_FAIL_COND_V(p_ofs + 4 > (uint32_t)data.size(), 0);
|
||||
const uint8_t *rd = data.ptr();
|
||||
ERR_FAIL_COND_V(!rd, 0);
|
||||
ERR_FAIL_NULL_V(rd, 0);
|
||||
const uint8_t *r = &rd[p_ofs];
|
||||
uint32_t type = decode_uint32(r);
|
||||
|
||||
|
@ -135,7 +135,7 @@ uint32_t PackedDataContainer::_type_at_ofs(uint32_t p_ofs) const {
|
|||
int PackedDataContainer::_size(uint32_t p_ofs) const {
|
||||
ERR_FAIL_COND_V(p_ofs + 4 > (uint32_t)data.size(), 0);
|
||||
const uint8_t *rd = data.ptr();
|
||||
ERR_FAIL_COND_V(!rd, 0);
|
||||
ERR_FAIL_NULL_V(rd, 0);
|
||||
const uint8_t *r = &rd[p_ofs];
|
||||
uint32_t type = decode_uint32(r);
|
||||
|
||||
|
@ -156,7 +156,7 @@ Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs, const Variant &p_key, b
|
|||
const uint8_t *rd = data.ptr();
|
||||
if (!rd) {
|
||||
err = true;
|
||||
ERR_FAIL_COND_V(!rd, Variant());
|
||||
ERR_FAIL_NULL_V(rd, Variant());
|
||||
}
|
||||
const uint8_t *r = &rd[p_ofs];
|
||||
uint32_t type = decode_uint32(r);
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
|
||||
#include "core/extension/ext_wrappers.gen.inc"
|
||||
#include "core/object/gdvirtual.gen.inc"
|
||||
#include "core/object/script_language.h"
|
||||
#include "core/variant/native_ptr.h"
|
||||
|
||||
class PacketPeer : public RefCounted {
|
||||
|
|
|
@ -205,7 +205,7 @@ Error PCKPacker::flush(bool p_verbose) {
|
|||
|
||||
int header_padding = _get_pad(alignment, file->get_position());
|
||||
for (int i = 0; i < header_padding; i++) {
|
||||
file->store_8(Math::rand() % 256);
|
||||
file->store_8(0);
|
||||
}
|
||||
|
||||
int64_t file_base = file->get_position();
|
||||
|
@ -244,7 +244,7 @@ Error PCKPacker::flush(bool p_verbose) {
|
|||
|
||||
int pad = _get_pad(alignment, file->get_position());
|
||||
for (int j = 0; j < pad; j++) {
|
||||
file->store_8(Math::rand() % 256);
|
||||
file->store_8(0);
|
||||
}
|
||||
|
||||
count += 1;
|
||||
|
|
|
@ -44,8 +44,8 @@ protected:
|
|||
String _get_cache_path() { return cache_path; }
|
||||
struct FileCache {
|
||||
String path; // Local path (as in "folder/to/file.png")
|
||||
uint64_t server_modified_time; // MD5 checksum.
|
||||
uint64_t modified_time;
|
||||
uint64_t server_modified_time = 0; // MD5 checksum.
|
||||
uint64_t modified_time = 0;
|
||||
};
|
||||
virtual bool _is_configured() { return !cache_path.is_empty(); }
|
||||
// Can be re-implemented per platform. If so, feel free to ignore get_cache_path()
|
||||
|
|
|
@ -239,6 +239,7 @@ void Resource::configure_for_local_scene(Node *p_for_scene, HashMap<Ref<Resource
|
|||
List<PropertyInfo> plist;
|
||||
get_property_list(&plist);
|
||||
|
||||
reset_local_to_scene();
|
||||
local_scene = p_for_scene;
|
||||
|
||||
for (const PropertyInfo &E : plist) {
|
||||
|
@ -382,6 +383,10 @@ void Resource::setup_local_to_scene() {
|
|||
emit_signal(SNAME("setup_local_to_scene_requested"));
|
||||
}
|
||||
|
||||
void Resource::reset_local_to_scene() {
|
||||
// Restores the state as if setup_local_to_scene() hadn't been called.
|
||||
}
|
||||
|
||||
Node *(*Resource::_get_local_scene_func)() = nullptr;
|
||||
void (*Resource::_update_configuration_warning)() = nullptr;
|
||||
|
||||
|
|
|
@ -80,6 +80,8 @@ protected:
|
|||
void _set_path(const String &p_path);
|
||||
void _take_over_path(const String &p_path);
|
||||
|
||||
virtual void reset_local_to_scene();
|
||||
|
||||
public:
|
||||
static Node *(*_get_local_scene_func)(); //used by editor
|
||||
static void (*_update_configuration_warning)(); //used by editor
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "core/io/image.h"
|
||||
#include "core/io/marshalls.h"
|
||||
#include "core/io/missing_resource.h"
|
||||
#include "core/object/script_language.h"
|
||||
#include "core/version.h"
|
||||
|
||||
//#define print_bl(m_what) print_line(m_what)
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "core/config/project_settings.h"
|
||||
#include "core/io/file_access.h"
|
||||
#include "core/io/resource_importer.h"
|
||||
#include "core/object/script_language.h"
|
||||
#include "core/os/condition_variable.h"
|
||||
#include "core/os/os.h"
|
||||
#include "core/string/print_string.h"
|
||||
|
@ -1113,7 +1114,7 @@ bool ResourceLoader::add_custom_resource_format_loader(String script_path) {
|
|||
|
||||
Object *obj = ClassDB::instantiate(ibt);
|
||||
|
||||
ERR_FAIL_COND_V_MSG(obj == nullptr, false, "Cannot instance script as custom resource loader, expected 'ResourceFormatLoader' inheritance, got: " + String(ibt) + ".");
|
||||
ERR_FAIL_NULL_V_MSG(obj, false, "Cannot instance script as custom resource loader, expected 'ResourceFormatLoader' inheritance, got: " + String(ibt) + ".");
|
||||
|
||||
Ref<ResourceFormatLoader> crl = Object::cast_to<ResourceFormatLoader>(obj);
|
||||
crl->set_script(s);
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
|
||||
#include "core/io/resource.h"
|
||||
#include "core/object/gdvirtual.gen.inc"
|
||||
#include "core/object/script_language.h"
|
||||
#include "core/object/worker_thread_pool.h"
|
||||
#include "core/os/semaphore.h"
|
||||
#include "core/os/thread.h"
|
||||
|
|
|
@ -241,7 +241,7 @@ bool ResourceSaver::add_custom_resource_format_saver(String script_path) {
|
|||
|
||||
Object *obj = ClassDB::instantiate(ibt);
|
||||
|
||||
ERR_FAIL_COND_V_MSG(obj == nullptr, false, "Cannot instance script as custom resource saver, expected 'ResourceFormatSaver' inheritance, got: " + String(ibt) + ".");
|
||||
ERR_FAIL_NULL_V_MSG(obj, false, "Cannot instance script as custom resource saver, expected 'ResourceFormatSaver' inheritance, got: " + String(ibt) + ".");
|
||||
|
||||
Ref<ResourceFormatSaver> crl = Object::cast_to<ResourceFormatSaver>(obj);
|
||||
crl->set_script(s);
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
|
||||
#include "core/io/resource.h"
|
||||
#include "core/object/gdvirtual.gen.inc"
|
||||
#include "core/object/script_language.h"
|
||||
|
||||
class ResourceFormatSaver : public RefCounted {
|
||||
GDCLASS(ResourceFormatSaver, RefCounted);
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
|
||||
#include "core/extension/ext_wrappers.gen.inc"
|
||||
#include "core/object/gdvirtual.gen.inc"
|
||||
#include "core/object/script_language.h"
|
||||
#include "core/variant/native_ptr.h"
|
||||
|
||||
class StreamPeer : public RefCounted {
|
||||
|
|
|
@ -102,7 +102,7 @@ Error StreamPeerGZIP::_start(bool p_compress, bool p_is_deflate, int buffer_size
|
|||
}
|
||||
|
||||
Error StreamPeerGZIP::_process(uint8_t *p_dst, int p_dst_size, const uint8_t *p_src, int p_src_size, int &r_consumed, int &r_out, bool p_close) {
|
||||
ERR_FAIL_COND_V(!ctx, ERR_UNCONFIGURED);
|
||||
ERR_FAIL_NULL_V(ctx, ERR_UNCONFIGURED);
|
||||
z_stream &strm = *(z_stream *)ctx;
|
||||
strm.avail_in = p_src_size;
|
||||
strm.avail_out = p_dst_size;
|
||||
|
@ -132,7 +132,7 @@ Error StreamPeerGZIP::put_data(const uint8_t *p_data, int p_bytes) {
|
|||
}
|
||||
|
||||
Error StreamPeerGZIP::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) {
|
||||
ERR_FAIL_COND_V(!ctx, ERR_UNCONFIGURED);
|
||||
ERR_FAIL_NULL_V(ctx, ERR_UNCONFIGURED);
|
||||
ERR_FAIL_COND_V(p_bytes < 0, ERR_INVALID_PARAMETER);
|
||||
|
||||
// Ensure we have enough space in temporary buffer.
|
||||
|
|
|
@ -336,7 +336,7 @@ uint64_t XMLParser::get_node_offset() const {
|
|||
}
|
||||
|
||||
Error XMLParser::seek(uint64_t p_pos) {
|
||||
ERR_FAIL_COND_V(!data, ERR_FILE_EOF);
|
||||
ERR_FAIL_NULL_V(data, ERR_FILE_EOF);
|
||||
ERR_FAIL_COND_V(p_pos >= length, ERR_FILE_EOF);
|
||||
|
||||
P = data + p_pos;
|
||||
|
@ -474,7 +474,7 @@ Error XMLParser::open_buffer(const Vector<uint8_t> &p_buffer) {
|
|||
|
||||
Error XMLParser::_open_buffer(const uint8_t *p_buffer, size_t p_size) {
|
||||
ERR_FAIL_COND_V(p_size == 0, ERR_INVALID_DATA);
|
||||
ERR_FAIL_COND_V(!p_buffer, ERR_INVALID_DATA);
|
||||
ERR_FAIL_NULL_V(p_buffer, ERR_INVALID_DATA);
|
||||
|
||||
if (data_copy) {
|
||||
memdelete_arr(data_copy);
|
||||
|
|
|
@ -74,7 +74,7 @@ int godot_unzip_locate_file(unzFile p_zip_file, String p_filepath, bool p_case_s
|
|||
|
||||
void *zipio_open(voidpf opaque, const char *p_fname, int mode) {
|
||||
Ref<FileAccess> *fa = reinterpret_cast<Ref<FileAccess> *>(opaque);
|
||||
ERR_FAIL_COND_V(fa == nullptr, nullptr);
|
||||
ERR_FAIL_NULL_V(fa, nullptr);
|
||||
|
||||
String fname;
|
||||
fname.parse_utf8(p_fname);
|
||||
|
@ -100,7 +100,7 @@ void *zipio_open(voidpf opaque, const char *p_fname, int mode) {
|
|||
|
||||
uLong zipio_read(voidpf opaque, voidpf stream, void *buf, uLong size) {
|
||||
Ref<FileAccess> *fa = reinterpret_cast<Ref<FileAccess> *>(opaque);
|
||||
ERR_FAIL_COND_V(fa == nullptr, 0);
|
||||
ERR_FAIL_NULL_V(fa, 0);
|
||||
ERR_FAIL_COND_V(fa->is_null(), 0);
|
||||
|
||||
return (*fa)->get_buffer((uint8_t *)buf, size);
|
||||
|
@ -108,7 +108,7 @@ uLong zipio_read(voidpf opaque, voidpf stream, void *buf, uLong size) {
|
|||
|
||||
uLong zipio_write(voidpf opaque, voidpf stream, const void *buf, uLong size) {
|
||||
Ref<FileAccess> *fa = reinterpret_cast<Ref<FileAccess> *>(opaque);
|
||||
ERR_FAIL_COND_V(fa == nullptr, 0);
|
||||
ERR_FAIL_NULL_V(fa, 0);
|
||||
ERR_FAIL_COND_V(fa->is_null(), 0);
|
||||
|
||||
(*fa)->store_buffer((uint8_t *)buf, size);
|
||||
|
@ -117,7 +117,7 @@ uLong zipio_write(voidpf opaque, voidpf stream, const void *buf, uLong size) {
|
|||
|
||||
long zipio_tell(voidpf opaque, voidpf stream) {
|
||||
Ref<FileAccess> *fa = reinterpret_cast<Ref<FileAccess> *>(opaque);
|
||||
ERR_FAIL_COND_V(fa == nullptr, 0);
|
||||
ERR_FAIL_NULL_V(fa, 0);
|
||||
ERR_FAIL_COND_V(fa->is_null(), 0);
|
||||
|
||||
return (*fa)->get_position();
|
||||
|
@ -125,7 +125,7 @@ long zipio_tell(voidpf opaque, voidpf stream) {
|
|||
|
||||
long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
|
||||
Ref<FileAccess> *fa = reinterpret_cast<Ref<FileAccess> *>(opaque);
|
||||
ERR_FAIL_COND_V(fa == nullptr, 0);
|
||||
ERR_FAIL_NULL_V(fa, 0);
|
||||
ERR_FAIL_COND_V(fa->is_null(), 0);
|
||||
|
||||
uint64_t pos = offset;
|
||||
|
@ -146,7 +146,7 @@ long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
|
|||
|
||||
int zipio_close(voidpf opaque, voidpf stream) {
|
||||
Ref<FileAccess> *fa = reinterpret_cast<Ref<FileAccess> *>(opaque);
|
||||
ERR_FAIL_COND_V(fa == nullptr, 0);
|
||||
ERR_FAIL_NULL_V(fa, 0);
|
||||
ERR_FAIL_COND_V(fa->is_null(), 0);
|
||||
|
||||
fa->unref();
|
||||
|
@ -155,7 +155,7 @@ int zipio_close(voidpf opaque, voidpf stream) {
|
|||
|
||||
int zipio_testerror(voidpf opaque, voidpf stream) {
|
||||
Ref<FileAccess> *fa = reinterpret_cast<Ref<FileAccess> *>(opaque);
|
||||
ERR_FAIL_COND_V(fa == nullptr, 1);
|
||||
ERR_FAIL_NULL_V(fa, 1);
|
||||
ERR_FAIL_COND_V(fa->is_null(), 0);
|
||||
|
||||
return (fa->is_valid() && (*fa)->get_error() != OK) ? 1 : 0;
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
|
||||
#include "core/object/gdvirtual.gen.inc"
|
||||
#include "core/object/ref_counted.h"
|
||||
#include "core/object/script_language.h"
|
||||
#include "core/templates/oa_hash_map.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
|
||||
#include "core/object/gdvirtual.gen.inc"
|
||||
#include "core/object/ref_counted.h"
|
||||
#include "core/object/script_language.h"
|
||||
#include "core/templates/list.h"
|
||||
#include "core/templates/local_vector.h"
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ void DisjointSet<T, H, C, AL>::get_representatives(Vector<T> &out_representative
|
|||
template <typename T, class H, class C, class AL>
|
||||
void DisjointSet<T, H, C, AL>::get_members(Vector<T> &out_members, T representative) {
|
||||
typename MapT::Iterator rep_itr = elements.find(representative);
|
||||
ERR_FAIL_COND(rep_itr == nullptr);
|
||||
ERR_FAIL_NULL(rep_itr);
|
||||
|
||||
Element *rep_element = rep_itr->value;
|
||||
ERR_FAIL_COND(rep_element->parent != rep_element);
|
||||
|
|
|
@ -190,7 +190,7 @@ private:
|
|||
_FORCE_INLINE_ bool is_internal() const { return (!is_leaf()); }
|
||||
|
||||
_FORCE_INLINE_ int get_index_in_parent() const {
|
||||
ERR_FAIL_COND_V(!parent, 0);
|
||||
ERR_FAIL_NULL_V(parent, 0);
|
||||
return (parent->children[1] == this) ? 1 : 0;
|
||||
}
|
||||
void get_max_depth(int depth, int &maxdepth) {
|
||||
|
|
|
@ -88,6 +88,17 @@ public:
|
|||
static _ALWAYS_INLINE_ double atan2(double p_y, double p_x) { return ::atan2(p_y, p_x); }
|
||||
static _ALWAYS_INLINE_ float atan2(float p_y, float p_x) { return ::atan2f(p_y, p_x); }
|
||||
|
||||
static _ALWAYS_INLINE_ double asinh(double p_x) { return ::asinh(p_x); }
|
||||
static _ALWAYS_INLINE_ float asinh(float p_x) { return ::asinhf(p_x); }
|
||||
|
||||
// Always does clamping so always safe to use.
|
||||
static _ALWAYS_INLINE_ double acosh(double p_x) { return p_x < 1 ? 0 : ::acosh(p_x); }
|
||||
static _ALWAYS_INLINE_ float acosh(float p_x) { return p_x < 1 ? 0 : ::acoshf(p_x); }
|
||||
|
||||
// Always does clamping so always safe to use.
|
||||
static _ALWAYS_INLINE_ double atanh(double p_x) { return p_x <= -1 ? -INFINITY : (p_x >= 1 ? INFINITY : ::atanh(p_x)); }
|
||||
static _ALWAYS_INLINE_ float atanh(float p_x) { return p_x <= -1 ? -INFINITY : (p_x >= 1 ? INFINITY : ::atanhf(p_x)); }
|
||||
|
||||
static _ALWAYS_INLINE_ double sqrt(double p_x) { return ::sqrt(p_x); }
|
||||
static _ALWAYS_INLINE_ float sqrt(float p_x) { return ::sqrtf(p_x); }
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ StringName ClassDB::get_compatibility_remapped_class(const StringName &p_class)
|
|||
|
||||
StringName ClassDB::_get_parent_class(const StringName &p_class) {
|
||||
ClassInfo *ti = classes.getptr(p_class);
|
||||
ERR_FAIL_COND_V_MSG(!ti, StringName(), "Cannot get class '" + String(p_class) + "'.");
|
||||
ERR_FAIL_NULL_V_MSG(ti, StringName(), "Cannot get class '" + String(p_class) + "'.");
|
||||
return ti->inherits;
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) {
|
|||
|
||||
ClassInfo *ti = classes.getptr(p_class);
|
||||
|
||||
ERR_FAIL_COND_V_MSG(!ti, API_NONE, "Cannot get class '" + String(p_class) + "'.");
|
||||
ERR_FAIL_NULL_V_MSG(ti, API_NONE, "Cannot get class '" + String(p_class) + "'.");
|
||||
return ti->api;
|
||||
}
|
||||
|
||||
|
@ -180,7 +180,7 @@ uint32_t ClassDB::get_api_hash(APIType p_api) {
|
|||
|
||||
for (const StringName &E : class_list) {
|
||||
ClassInfo *t = classes.getptr(E);
|
||||
ERR_FAIL_COND_V_MSG(!t, 0, "Cannot get class '" + String(E) + "'.");
|
||||
ERR_FAIL_NULL_V_MSG(t, 0, "Cannot get class '" + String(E) + "'.");
|
||||
if (t->api != p_api || !t->exposed) {
|
||||
continue;
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ uint32_t ClassDB::get_api_hash(APIType p_api) {
|
|||
|
||||
for (const StringName &F : snames) {
|
||||
PropertySetGet *psg = t->property_setget.getptr(F);
|
||||
ERR_FAIL_COND_V(!psg, 0);
|
||||
ERR_FAIL_NULL_V(psg, 0);
|
||||
|
||||
hash = hash_murmur3_one_64(F.hash(), hash);
|
||||
hash = hash_murmur3_one_64(psg->setter.hash(), hash);
|
||||
|
@ -336,9 +336,9 @@ Object *ClassDB::instantiate(const StringName &p_class) {
|
|||
ti = classes.getptr(compat_classes[p_class]);
|
||||
}
|
||||
}
|
||||
ERR_FAIL_COND_V_MSG(!ti, nullptr, "Cannot get class '" + String(p_class) + "'.");
|
||||
ERR_FAIL_NULL_V_MSG(ti, nullptr, "Cannot get class '" + String(p_class) + "'.");
|
||||
ERR_FAIL_COND_V_MSG(ti->disabled, nullptr, "Class '" + String(p_class) + "' is disabled.");
|
||||
ERR_FAIL_COND_V_MSG(!ti->creation_func, nullptr, "Class '" + String(p_class) + "' or its base class cannot be instantiated.");
|
||||
ERR_FAIL_NULL_V_MSG(ti->creation_func, nullptr, "Class '" + String(p_class) + "' or its base class cannot be instantiated.");
|
||||
}
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (ti->api == API_EDITOR && !Engine::get_singleton()->is_editor_hint()) {
|
||||
|
@ -354,7 +354,7 @@ Object *ClassDB::instantiate(const StringName &p_class) {
|
|||
}
|
||||
|
||||
void ClassDB::set_object_extension_instance(Object *p_object, const StringName &p_class, GDExtensionClassInstancePtr p_instance) {
|
||||
ERR_FAIL_COND(!p_object);
|
||||
ERR_FAIL_NULL(p_object);
|
||||
ClassInfo *ti;
|
||||
{
|
||||
OBJTYPE_RLOCK;
|
||||
|
@ -364,9 +364,9 @@ void ClassDB::set_object_extension_instance(Object *p_object, const StringName &
|
|||
ti = classes.getptr(compat_classes[p_class]);
|
||||
}
|
||||
}
|
||||
ERR_FAIL_COND_MSG(!ti, "Cannot get class '" + String(p_class) + "'.");
|
||||
ERR_FAIL_NULL_MSG(ti, "Cannot get class '" + String(p_class) + "'.");
|
||||
ERR_FAIL_COND_MSG(ti->disabled, "Class '" + String(p_class) + "' is disabled.");
|
||||
ERR_FAIL_COND_MSG(!ti->gdextension, "Class '" + String(p_class) + "' has no native extension.");
|
||||
ERR_FAIL_NULL_MSG(ti->gdextension, "Class '" + String(p_class) + "' has no native extension.");
|
||||
}
|
||||
|
||||
p_object->_extension = ti->gdextension;
|
||||
|
@ -377,7 +377,7 @@ bool ClassDB::can_instantiate(const StringName &p_class) {
|
|||
OBJTYPE_RLOCK;
|
||||
|
||||
ClassInfo *ti = classes.getptr(p_class);
|
||||
ERR_FAIL_COND_V_MSG(!ti, false, "Cannot get class '" + String(p_class) + "'.");
|
||||
ERR_FAIL_NULL_V_MSG(ti, false, "Cannot get class '" + String(p_class) + "'.");
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (ti->api == API_EDITOR && !Engine::get_singleton()->is_editor_hint()) {
|
||||
return false;
|
||||
|
@ -621,7 +621,7 @@ void ClassDB::bind_integer_constant(const StringName &p_class, const StringName
|
|||
|
||||
ClassInfo *type = classes.getptr(p_class);
|
||||
|
||||
ERR_FAIL_COND(!type);
|
||||
ERR_FAIL_NULL(type);
|
||||
|
||||
if (type->constant_map.has(p_name)) {
|
||||
ERR_FAIL();
|
||||
|
@ -790,7 +790,7 @@ void ClassDB::set_method_error_return_values(const StringName &p_class, const St
|
|||
#ifdef DEBUG_METHODS_ENABLED
|
||||
ClassInfo *type = classes.getptr(p_class);
|
||||
|
||||
ERR_FAIL_COND(!type);
|
||||
ERR_FAIL_NULL(type);
|
||||
|
||||
type->method_error_values[p_method] = p_values;
|
||||
#endif
|
||||
|
@ -800,7 +800,7 @@ Vector<Error> ClassDB::get_method_error_return_values(const StringName &p_class,
|
|||
#ifdef DEBUG_METHODS_ENABLED
|
||||
ClassInfo *type = classes.getptr(p_class);
|
||||
|
||||
ERR_FAIL_COND_V(!type, Vector<Error>());
|
||||
ERR_FAIL_NULL_V(type, Vector<Error>());
|
||||
|
||||
if (!type->method_error_values.has(p_method)) {
|
||||
return Vector<Error>();
|
||||
|
@ -853,7 +853,7 @@ void ClassDB::add_signal(const StringName &p_class, const MethodInfo &p_signal)
|
|||
OBJTYPE_WLOCK;
|
||||
|
||||
ClassInfo *type = classes.getptr(p_class);
|
||||
ERR_FAIL_COND(!type);
|
||||
ERR_FAIL_NULL(type);
|
||||
|
||||
StringName sname = p_signal.name;
|
||||
|
||||
|
@ -872,7 +872,7 @@ void ClassDB::get_signal_list(const StringName &p_class, List<MethodInfo> *p_sig
|
|||
OBJTYPE_RLOCK;
|
||||
|
||||
ClassInfo *type = classes.getptr(p_class);
|
||||
ERR_FAIL_COND(!type);
|
||||
ERR_FAIL_NULL(type);
|
||||
|
||||
ClassInfo *check = type;
|
||||
|
||||
|
@ -926,7 +926,7 @@ bool ClassDB::get_signal(const StringName &p_class, const StringName &p_signal,
|
|||
void ClassDB::add_property_group(const StringName &p_class, const String &p_name, const String &p_prefix, int p_indent_depth) {
|
||||
OBJTYPE_WLOCK;
|
||||
ClassInfo *type = classes.getptr(p_class);
|
||||
ERR_FAIL_COND(!type);
|
||||
ERR_FAIL_NULL(type);
|
||||
|
||||
String prefix = p_prefix;
|
||||
if (p_indent_depth > 0) {
|
||||
|
@ -939,7 +939,7 @@ void ClassDB::add_property_group(const StringName &p_class, const String &p_name
|
|||
void ClassDB::add_property_subgroup(const StringName &p_class, const String &p_name, const String &p_prefix, int p_indent_depth) {
|
||||
OBJTYPE_WLOCK;
|
||||
ClassInfo *type = classes.getptr(p_class);
|
||||
ERR_FAIL_COND(!type);
|
||||
ERR_FAIL_NULL(type);
|
||||
|
||||
String prefix = p_prefix;
|
||||
if (p_indent_depth > 0) {
|
||||
|
@ -956,7 +956,7 @@ void ClassDB::add_property_array_count(const StringName &p_class, const String &
|
|||
void ClassDB::add_property_array(const StringName &p_class, const StringName &p_path, const String &p_array_element_prefix) {
|
||||
OBJTYPE_WLOCK;
|
||||
ClassInfo *type = classes.getptr(p_class);
|
||||
ERR_FAIL_COND(!type);
|
||||
ERR_FAIL_NULL(type);
|
||||
|
||||
type->property_list.push_back(PropertyInfo(Variant::NIL, p_path, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_ARRAY, p_array_element_prefix));
|
||||
}
|
||||
|
@ -967,14 +967,14 @@ void ClassDB::add_property(const StringName &p_class, const PropertyInfo &p_pinf
|
|||
ClassInfo *type = classes.getptr(p_class);
|
||||
lock.read_unlock();
|
||||
|
||||
ERR_FAIL_COND(!type);
|
||||
ERR_FAIL_NULL(type);
|
||||
|
||||
MethodBind *mb_set = nullptr;
|
||||
if (p_setter) {
|
||||
mb_set = get_method(p_class, p_setter);
|
||||
#ifdef DEBUG_METHODS_ENABLED
|
||||
|
||||
ERR_FAIL_COND_MSG(!mb_set, "Invalid setter '" + p_class + "::" + p_setter + "' for property '" + p_pinfo.name + "'.");
|
||||
ERR_FAIL_NULL_MSG(mb_set, "Invalid setter '" + p_class + "::" + p_setter + "' for property '" + p_pinfo.name + "'.");
|
||||
|
||||
int exp_args = 1 + (p_index >= 0 ? 1 : 0);
|
||||
ERR_FAIL_COND_MSG(mb_set->get_argument_count() != exp_args, "Invalid function for setter '" + p_class + "::" + p_setter + " for property '" + p_pinfo.name + "'.");
|
||||
|
@ -986,7 +986,7 @@ void ClassDB::add_property(const StringName &p_class, const PropertyInfo &p_pinf
|
|||
mb_get = get_method(p_class, p_getter);
|
||||
#ifdef DEBUG_METHODS_ENABLED
|
||||
|
||||
ERR_FAIL_COND_MSG(!mb_get, "Invalid getter '" + p_class + "::" + p_getter + "' for property '" + p_pinfo.name + "'.");
|
||||
ERR_FAIL_NULL_MSG(mb_get, "Invalid getter '" + p_class + "::" + p_getter + "' for property '" + p_pinfo.name + "'.");
|
||||
|
||||
int exp_args = 0 + (p_index >= 0 ? 1 : 0);
|
||||
ERR_FAIL_COND_MSG(mb_get->get_argument_count() != exp_args, "Invalid function for getter '" + p_class + "::" + p_getter + "' for property: '" + p_pinfo.name + "'.");
|
||||
|
@ -1031,7 +1031,7 @@ void ClassDB::add_linked_property(const StringName &p_class, const String &p_pro
|
|||
#ifdef TOOLS_ENABLED
|
||||
OBJTYPE_WLOCK;
|
||||
ClassInfo *type = classes.getptr(p_class);
|
||||
ERR_FAIL_COND(!type);
|
||||
ERR_FAIL_NULL(type);
|
||||
|
||||
ERR_FAIL_COND(!type->property_map.has(p_property));
|
||||
ERR_FAIL_COND(!type->property_map.has(p_linked_property));
|
||||
|
@ -1306,7 +1306,7 @@ void ClassDB::set_method_flags(const StringName &p_class, const StringName &p_me
|
|||
OBJTYPE_WLOCK;
|
||||
ClassInfo *type = classes.getptr(p_class);
|
||||
ClassInfo *check = type;
|
||||
ERR_FAIL_COND(!check);
|
||||
ERR_FAIL_NULL(check);
|
||||
ERR_FAIL_COND(!check->method_map.has(p_method));
|
||||
check->method_map[p_method]->set_hint_flags(p_flags);
|
||||
}
|
||||
|
@ -1374,7 +1374,7 @@ MethodBind *ClassDB::_bind_vararg_method(MethodBind *p_bind, const StringName &p
|
|||
ClassInfo *type = classes.getptr(instance_type);
|
||||
if (!type) {
|
||||
memdelete(bind);
|
||||
ERR_FAIL_COND_V(!type, nullptr);
|
||||
ERR_FAIL_NULL_V(type, nullptr);
|
||||
}
|
||||
|
||||
if (p_compatibility) {
|
||||
|
@ -1406,7 +1406,7 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, bool p_
|
|||
#endif
|
||||
|
||||
OBJTYPE_WLOCK;
|
||||
ERR_FAIL_COND_V(!p_bind, nullptr);
|
||||
ERR_FAIL_NULL_V(p_bind, nullptr);
|
||||
p_bind->set_name(mdname);
|
||||
|
||||
String instance_type = p_bind->get_instance_class();
|
||||
|
@ -1532,7 +1532,7 @@ bool ClassDB::is_class_enabled(const StringName &p_class) {
|
|||
}
|
||||
}
|
||||
|
||||
ERR_FAIL_COND_V_MSG(!ti, false, "Cannot get class '" + String(p_class) + "'.");
|
||||
ERR_FAIL_NULL_V_MSG(ti, false, "Cannot get class '" + String(p_class) + "'.");
|
||||
return !ti->disabled;
|
||||
}
|
||||
|
||||
|
@ -1540,7 +1540,7 @@ bool ClassDB::is_class_exposed(const StringName &p_class) {
|
|||
OBJTYPE_RLOCK;
|
||||
|
||||
ClassInfo *ti = classes.getptr(p_class);
|
||||
ERR_FAIL_COND_V_MSG(!ti, false, "Cannot get class '" + String(p_class) + "'.");
|
||||
ERR_FAIL_NULL_V_MSG(ti, false, "Cannot get class '" + String(p_class) + "'.");
|
||||
return ti->exposed;
|
||||
}
|
||||
|
||||
|
@ -1661,19 +1661,34 @@ void ClassDB::register_extension_class(ObjectGDExtension *p_extension) {
|
|||
c.name = p_extension->class_name;
|
||||
c.is_virtual = p_extension->is_virtual;
|
||||
if (!p_extension->is_abstract) {
|
||||
c.creation_func = parent->creation_func;
|
||||
// Find the closest ancestor which is either non-abstract or native (or both).
|
||||
ClassInfo *concrete_ancestor = parent;
|
||||
while (concrete_ancestor->creation_func == nullptr &&
|
||||
concrete_ancestor->inherits_ptr != nullptr &&
|
||||
concrete_ancestor->gdextension != nullptr) {
|
||||
concrete_ancestor = concrete_ancestor->inherits_ptr;
|
||||
}
|
||||
ERR_FAIL_NULL_MSG(concrete_ancestor->creation_func, "Extension class " + String(p_extension->class_name) + " cannot extend native abstract class " + String(concrete_ancestor->name));
|
||||
c.creation_func = concrete_ancestor->creation_func;
|
||||
}
|
||||
c.inherits = parent->name;
|
||||
c.class_ptr = parent->class_ptr;
|
||||
c.inherits_ptr = parent;
|
||||
c.exposed = true;
|
||||
c.exposed = p_extension->is_exposed;
|
||||
if (c.exposed) {
|
||||
// The parent classes should be exposed if it has an exposed child class.
|
||||
while (parent && !parent->exposed) {
|
||||
parent->exposed = true;
|
||||
parent = classes.getptr(parent->name);
|
||||
}
|
||||
}
|
||||
|
||||
classes[p_extension->class_name] = c;
|
||||
}
|
||||
|
||||
void ClassDB::unregister_extension_class(const StringName &p_class) {
|
||||
ClassInfo *c = classes.getptr(p_class);
|
||||
ERR_FAIL_COND_MSG(!c, "Class " + p_class + "does not exist");
|
||||
ERR_FAIL_NULL_MSG(c, "Class '" + String(p_class) + "' does not exist.");
|
||||
for (KeyValue<StringName, MethodBind *> &F : c->method_map) {
|
||||
memdelete(F.value);
|
||||
}
|
||||
|
|
|
@ -187,9 +187,10 @@ public:
|
|||
template <class T>
|
||||
static void register_class(bool p_virtual = false) {
|
||||
GLOBAL_LOCK_FUNCTION;
|
||||
static_assert(TypesAreSame<typename T::self_type, T>::value, "Class not declared properly, please use GDCLASS.");
|
||||
T::initialize_class();
|
||||
ClassInfo *t = classes.getptr(T::get_class_static());
|
||||
ERR_FAIL_COND(!t);
|
||||
ERR_FAIL_NULL(t);
|
||||
t->creation_func = &creator<T>;
|
||||
t->exposed = true;
|
||||
t->is_virtual = p_virtual;
|
||||
|
@ -201,15 +202,31 @@ public:
|
|||
template <class T>
|
||||
static void register_abstract_class() {
|
||||
GLOBAL_LOCK_FUNCTION;
|
||||
static_assert(TypesAreSame<typename T::self_type, T>::value, "Class not declared properly, please use GDCLASS.");
|
||||
T::initialize_class();
|
||||
ClassInfo *t = classes.getptr(T::get_class_static());
|
||||
ERR_FAIL_COND(!t);
|
||||
ERR_FAIL_NULL(t);
|
||||
t->exposed = true;
|
||||
t->class_ptr = T::get_class_ptr_static();
|
||||
t->api = current_api;
|
||||
//nothing
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static void register_internal_class() {
|
||||
GLOBAL_LOCK_FUNCTION;
|
||||
static_assert(TypesAreSame<typename T::self_type, T>::value, "Class not declared properly, please use GDCLASS.");
|
||||
T::initialize_class();
|
||||
ClassInfo *t = classes.getptr(T::get_class_static());
|
||||
ERR_FAIL_NULL(t);
|
||||
t->creation_func = &creator<T>;
|
||||
t->exposed = false;
|
||||
t->is_virtual = false;
|
||||
t->class_ptr = T::get_class_ptr_static();
|
||||
t->api = current_api;
|
||||
T::register_custom_data_to_otdb();
|
||||
}
|
||||
|
||||
static void register_extension_class(ObjectGDExtension *p_extension);
|
||||
static void unregister_extension_class(const StringName &p_class);
|
||||
|
||||
|
@ -221,9 +238,10 @@ public:
|
|||
template <class T>
|
||||
static void register_custom_instance_class() {
|
||||
GLOBAL_LOCK_FUNCTION;
|
||||
static_assert(TypesAreSame<typename T::self_type, T>::value, "Class not declared properly, please use GDCLASS.");
|
||||
T::initialize_class();
|
||||
ClassInfo *t = classes.getptr(T::get_class_static());
|
||||
ERR_FAIL_COND(!t);
|
||||
ERR_FAIL_NULL(t);
|
||||
t->creation_func = &_create_ptr_func<T>;
|
||||
t->exposed = true;
|
||||
t->class_ptr = T::get_class_ptr_static();
|
||||
|
@ -329,7 +347,7 @@ public:
|
|||
GLOBAL_LOCK_FUNCTION;
|
||||
|
||||
MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
|
||||
ERR_FAIL_COND_V(!bind, nullptr);
|
||||
ERR_FAIL_NULL_V(bind, nullptr);
|
||||
|
||||
if constexpr (std::is_same<typename member_function_traits<M>::return_type, Object *>::value) {
|
||||
bind->set_return_type_is_raw_object_ptr(true);
|
||||
|
@ -342,7 +360,7 @@ public:
|
|||
GLOBAL_LOCK_FUNCTION;
|
||||
|
||||
MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
|
||||
ERR_FAIL_COND_V(!bind, nullptr);
|
||||
ERR_FAIL_NULL_V(bind, nullptr);
|
||||
|
||||
if constexpr (std::is_same<typename member_function_traits<M>::return_type, Object *>::value) {
|
||||
bind->set_return_type_is_raw_object_ptr(true);
|
||||
|
@ -480,6 +498,10 @@ _FORCE_INLINE_ Vector<Error> errarray(P... p_args) {
|
|||
if (m_class::_class_is_enabled) { \
|
||||
::ClassDB::register_abstract_class<m_class>(); \
|
||||
}
|
||||
#define GDREGISTER_INTERNAL_CLASS(m_class) \
|
||||
if (m_class::_class_is_enabled) { \
|
||||
::ClassDB::register_internal_class<m_class>(); \
|
||||
}
|
||||
|
||||
#define GDREGISTER_NATIVE_STRUCT(m_class, m_code) ClassDB::register_native_struct(#m_class, m_code, sizeof(m_class))
|
||||
|
||||
|
|
|
@ -160,6 +160,8 @@ def run(target, source, env):
|
|||
#ifndef GDVIRTUAL_GEN_H
|
||||
#define GDVIRTUAL_GEN_H
|
||||
|
||||
#include "core/object/script_instance.h"
|
||||
|
||||
|
||||
"""
|
||||
|
||||
|
|
|
@ -485,7 +485,7 @@ void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) cons
|
|||
if (_extension) {
|
||||
const ObjectGDExtension *current_extension = _extension;
|
||||
while (current_extension) {
|
||||
p_list->push_back(PropertyInfo(Variant::NIL, current_extension->class_name, PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_CATEGORY));
|
||||
p_list->push_back(PropertyInfo(Variant::NIL, current_extension->class_name, PROPERTY_HINT_NONE, current_extension->class_name, PROPERTY_USAGE_CATEGORY));
|
||||
|
||||
ClassDB::get_property_list(current_extension->class_name, p_list, true, this);
|
||||
|
||||
|
@ -526,6 +526,31 @@ void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) cons
|
|||
|
||||
void Object::validate_property(PropertyInfo &p_property) const {
|
||||
_validate_propertyv(p_property);
|
||||
|
||||
if (_extension && _extension->validate_property) {
|
||||
// GDExtension uses a StringName rather than a String for property name.
|
||||
StringName prop_name = p_property.name;
|
||||
GDExtensionPropertyInfo gdext_prop = {
|
||||
(GDExtensionVariantType)p_property.type,
|
||||
&prop_name,
|
||||
&p_property.class_name,
|
||||
(uint32_t)p_property.hint,
|
||||
&p_property.hint_string,
|
||||
p_property.usage,
|
||||
};
|
||||
if (_extension->validate_property(_extension_instance, &gdext_prop)) {
|
||||
p_property.type = (Variant::Type)gdext_prop.type;
|
||||
p_property.name = *reinterpret_cast<StringName *>(gdext_prop.name);
|
||||
p_property.class_name = *reinterpret_cast<StringName *>(gdext_prop.class_name);
|
||||
p_property.hint = (PropertyHint)gdext_prop.hint;
|
||||
p_property.hint_string = *reinterpret_cast<String *>(gdext_prop.hint_string);
|
||||
p_property.usage = gdext_prop.usage;
|
||||
};
|
||||
}
|
||||
|
||||
if (script_instance) { // Call it last to allow user altering already validated properties.
|
||||
script_instance->validate_property(p_property);
|
||||
}
|
||||
}
|
||||
|
||||
bool Object::property_can_revert(const StringName &p_name) const {
|
||||
|
@ -795,14 +820,30 @@ Variant Object::call_const(const StringName &p_method, const Variant **p_args, i
|
|||
}
|
||||
|
||||
void Object::notification(int p_notification, bool p_reversed) {
|
||||
_notificationv(p_notification, p_reversed);
|
||||
|
||||
if (p_reversed) {
|
||||
if (script_instance) {
|
||||
script_instance->notification(p_notification);
|
||||
script_instance->notification(p_notification, p_reversed);
|
||||
}
|
||||
} else {
|
||||
_notificationv(p_notification, p_reversed);
|
||||
}
|
||||
|
||||
if (_extension && _extension->notification) {
|
||||
if (_extension) {
|
||||
if (_extension->notification2) {
|
||||
_extension->notification2(_extension_instance, p_notification, static_cast<GDExtensionBool>(p_reversed));
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
} else if (_extension->notification) {
|
||||
_extension->notification(_extension_instance, p_notification);
|
||||
#endif // DISABLE_DEPRECATED
|
||||
}
|
||||
}
|
||||
|
||||
if (p_reversed) {
|
||||
_notificationv(p_notification, p_reversed);
|
||||
} else {
|
||||
if (script_instance) {
|
||||
script_instance->notification(p_notification, p_reversed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -826,7 +867,7 @@ String Object::to_string() {
|
|||
void Object::set_script_and_instance(const Variant &p_script, ScriptInstance *p_instance) {
|
||||
//this function is not meant to be used in any of these ways
|
||||
ERR_FAIL_COND(p_script.is_null());
|
||||
ERR_FAIL_COND(!p_instance);
|
||||
ERR_FAIL_NULL(p_instance);
|
||||
ERR_FAIL_COND(script_instance != nullptr || !script.is_null());
|
||||
|
||||
script = p_script;
|
||||
|
@ -1259,7 +1300,7 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, ui
|
|||
ERR_FAIL_COND_V_MSG(p_callable.is_null(), ERR_INVALID_PARAMETER, "Cannot connect to '" + p_signal + "': the provided callable is null.");
|
||||
|
||||
Object *target_object = p_callable.get_object();
|
||||
ERR_FAIL_COND_V_MSG(!target_object, ERR_INVALID_PARAMETER, "Cannot connect to '" + p_signal + "' to callable '" + p_callable + "': the callable object is null.");
|
||||
ERR_FAIL_NULL_V_MSG(target_object, ERR_INVALID_PARAMETER, "Cannot connect to '" + p_signal + "' to callable '" + p_callable + "': the callable object is null.");
|
||||
|
||||
SignalData *s = signal_map.getptr(p_signal);
|
||||
if (!s) {
|
||||
|
@ -1344,7 +1385,7 @@ bool Object::_disconnect(const StringName &p_signal, const Callable &p_callable,
|
|||
ERR_FAIL_COND_V_MSG(p_callable.is_null(), false, "Cannot disconnect from '" + p_signal + "': the provided callable is null.");
|
||||
|
||||
Object *target_object = p_callable.get_object();
|
||||
ERR_FAIL_COND_V_MSG(!target_object, false, "Cannot disconnect '" + p_signal + "' from callable '" + p_callable + "': the callable object is null.");
|
||||
ERR_FAIL_NULL_V_MSG(target_object, false, "Cannot disconnect '" + p_signal + "' from callable '" + p_callable + "': the callable object is null.");
|
||||
|
||||
SignalData *s = signal_map.getptr(p_signal);
|
||||
if (!s) {
|
||||
|
@ -1352,7 +1393,7 @@ bool Object::_disconnect(const StringName &p_signal, const Callable &p_callable,
|
|||
(!script.is_null() && Ref<Script>(script)->has_script_signal(p_signal));
|
||||
ERR_FAIL_COND_V_MSG(signal_is_valid, false, "Attempt to disconnect a nonexistent connection from '" + to_string() + "'. Signal: '" + p_signal + "', callable: '" + p_callable + "'.");
|
||||
}
|
||||
ERR_FAIL_COND_V_MSG(!s, false, vformat("Disconnecting nonexistent signal '%s' in %s.", p_signal, to_string()));
|
||||
ERR_FAIL_NULL_V_MSG(s, false, vformat("Disconnecting nonexistent signal '%s' in %s.", p_signal, to_string()));
|
||||
|
||||
ERR_FAIL_COND_V_MSG(!s->slot_map.has(*p_callable.get_base_comparator()), false, "Attempt to disconnect a nonexistent connection from '" + to_string() + "'. Signal: '" + p_signal + "', callable: '" + p_callable + "'.");
|
||||
|
||||
|
@ -1604,6 +1645,8 @@ void Object::_bind_methods() {
|
|||
plget.return_val.hint_string = "Dictionary";
|
||||
BIND_OBJ_CORE_METHOD(plget);
|
||||
|
||||
BIND_OBJ_CORE_METHOD(MethodInfo(Variant::NIL, "_validate_property", PropertyInfo(Variant::DICTIONARY, "property")));
|
||||
|
||||
BIND_OBJ_CORE_METHOD(MethodInfo(Variant::BOOL, "_property_can_revert", PropertyInfo(Variant::STRING_NAME, "property")));
|
||||
MethodInfo mipgr("_property_get_revert", PropertyInfo(Variant::STRING_NAME, "property"));
|
||||
mipgr.return_val.name = "Variant";
|
||||
|
|
|
@ -315,13 +315,18 @@ struct ObjectGDExtension {
|
|||
bool editor_class = false;
|
||||
bool is_virtual = false;
|
||||
bool is_abstract = false;
|
||||
bool is_exposed = true;
|
||||
GDExtensionClassSet set;
|
||||
GDExtensionClassGet get;
|
||||
GDExtensionClassGetPropertyList get_property_list;
|
||||
GDExtensionClassFreePropertyList free_property_list;
|
||||
GDExtensionClassPropertyCanRevert property_can_revert;
|
||||
GDExtensionClassPropertyGetRevert property_get_revert;
|
||||
GDExtensionClassValidateProperty validate_property;
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
GDExtensionClassNotification notification;
|
||||
#endif // DISABLE_DEPRECATED
|
||||
GDExtensionClassNotification2 notification2;
|
||||
GDExtensionClassToString to_string;
|
||||
GDExtensionClassReference reference;
|
||||
GDExtensionClassReference unreference;
|
||||
|
@ -382,6 +387,7 @@ private:
|
|||
friend class ::ClassDB; \
|
||||
\
|
||||
public: \
|
||||
typedef m_class self_type; \
|
||||
static constexpr bool _class_is_enabled = !bool(GD_IS_DEFINED(ClassDB_Disable_##m_class)) && m_inherits::_class_is_enabled; \
|
||||
virtual String get_class() const override { \
|
||||
if (_get_extension()) { \
|
||||
|
@ -485,7 +491,7 @@ protected:
|
|||
if (!p_reversed) { \
|
||||
m_inherits::_get_property_listv(p_list, p_reversed); \
|
||||
} \
|
||||
p_list->push_back(PropertyInfo(Variant::NIL, get_class_static(), PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_CATEGORY)); \
|
||||
p_list->push_back(PropertyInfo(Variant::NIL, get_class_static(), PROPERTY_HINT_NONE, get_class_static(), PROPERTY_USAGE_CATEGORY)); \
|
||||
if (!_is_gpl_reversed()) { \
|
||||
::ClassDB::get_property_list(#m_class, p_list, true, this); \
|
||||
} \
|
||||
|
@ -557,6 +563,8 @@ class ScriptInstance;
|
|||
|
||||
class Object {
|
||||
public:
|
||||
typedef Object self_type;
|
||||
|
||||
enum ConnectFlags {
|
||||
CONNECT_DEFERRED = 1,
|
||||
CONNECT_PERSIST = 2, // hint for scene to save this connection
|
||||
|
|
|
@ -71,7 +71,7 @@ class Ref {
|
|||
}
|
||||
|
||||
void ref_pointer(T *p_ref) {
|
||||
ERR_FAIL_COND(!p_ref);
|
||||
ERR_FAIL_NULL(p_ref);
|
||||
|
||||
if (p_ref->init_ref()) {
|
||||
reference = p_ref;
|
||||
|
|
71
godot/core/object/script_instance.cpp
Normal file
71
godot/core/object/script_instance.cpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
/**************************************************************************/
|
||||
/* script_instance.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "script_instance.h"
|
||||
|
||||
#include "core/object/script_language.h"
|
||||
|
||||
Variant ScriptInstance::call_const(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
|
||||
return callp(p_method, p_args, p_argcount, r_error);
|
||||
}
|
||||
|
||||
void ScriptInstance::get_property_state(List<Pair<StringName, Variant>> &state) {
|
||||
List<PropertyInfo> pinfo;
|
||||
get_property_list(&pinfo);
|
||||
for (const PropertyInfo &E : pinfo) {
|
||||
if (E.usage & PROPERTY_USAGE_STORAGE) {
|
||||
Pair<StringName, Variant> p;
|
||||
p.first = E.name;
|
||||
if (get(p.first, p.second)) {
|
||||
state.push_back(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptInstance::property_set_fallback(const StringName &, const Variant &, bool *r_valid) {
|
||||
if (r_valid) {
|
||||
*r_valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
Variant ScriptInstance::property_get_fallback(const StringName &, bool *r_valid) {
|
||||
if (r_valid) {
|
||||
*r_valid = false;
|
||||
}
|
||||
return Variant();
|
||||
}
|
||||
|
||||
const Variant ScriptInstance::get_rpc_config() const {
|
||||
return get_script()->get_rpc_config();
|
||||
}
|
||||
|
||||
ScriptInstance::~ScriptInstance() {
|
||||
}
|
98
godot/core/object/script_instance.h
Normal file
98
godot/core/object/script_instance.h
Normal file
|
@ -0,0 +1,98 @@
|
|||
/**************************************************************************/
|
||||
/* script_instance.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef SCRIPT_INSTANCE_H
|
||||
#define SCRIPT_INSTANCE_H
|
||||
|
||||
#include "core/object/ref_counted.h"
|
||||
|
||||
class Script;
|
||||
class ScriptLanguage;
|
||||
|
||||
class ScriptInstance {
|
||||
public:
|
||||
virtual bool set(const StringName &p_name, const Variant &p_value) = 0;
|
||||
virtual bool get(const StringName &p_name, Variant &r_ret) const = 0;
|
||||
virtual void get_property_list(List<PropertyInfo> *p_properties) const = 0;
|
||||
virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const = 0;
|
||||
virtual void validate_property(PropertyInfo &p_property) const = 0;
|
||||
|
||||
virtual bool property_can_revert(const StringName &p_name) const = 0;
|
||||
virtual bool property_get_revert(const StringName &p_name, Variant &r_ret) const = 0;
|
||||
|
||||
virtual Object *get_owner() { return nullptr; }
|
||||
virtual void get_property_state(List<Pair<StringName, Variant>> &state);
|
||||
|
||||
virtual void get_method_list(List<MethodInfo> *p_list) const = 0;
|
||||
virtual bool has_method(const StringName &p_method) const = 0;
|
||||
|
||||
virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) = 0;
|
||||
|
||||
template <typename... VarArgs>
|
||||
Variant call(const StringName &p_method, VarArgs... p_args) {
|
||||
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
|
||||
const Variant *argptrs[sizeof...(p_args) + 1];
|
||||
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
|
||||
argptrs[i] = &args[i];
|
||||
}
|
||||
Callable::CallError cerr;
|
||||
return callp(p_method, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args), cerr);
|
||||
}
|
||||
|
||||
virtual Variant call_const(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error); // implement if language supports const functions
|
||||
virtual void notification(int p_notification, bool p_reversed = false) = 0;
|
||||
virtual String to_string(bool *r_valid) {
|
||||
if (r_valid) {
|
||||
*r_valid = false;
|
||||
}
|
||||
return String();
|
||||
}
|
||||
|
||||
//this is used by script languages that keep a reference counter of their own
|
||||
//you can make make Ref<> not die when it reaches zero, so deleting the reference
|
||||
//depends entirely from the script
|
||||
|
||||
virtual void refcount_incremented() {}
|
||||
virtual bool refcount_decremented() { return true; } //return true if it can die
|
||||
|
||||
virtual Ref<Script> get_script() const = 0;
|
||||
|
||||
virtual bool is_placeholder() const { return false; }
|
||||
|
||||
virtual void property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid);
|
||||
virtual Variant property_get_fallback(const StringName &p_name, bool *r_valid);
|
||||
|
||||
virtual const Variant get_rpc_config() const;
|
||||
|
||||
virtual ScriptLanguage *get_language() = 0;
|
||||
virtual ~ScriptInstance();
|
||||
};
|
||||
|
||||
#endif // SCRIPT_INSTANCE_H
|
|
@ -388,40 +388,6 @@ String ScriptServer::get_global_class_cache_file_path() {
|
|||
|
||||
////////////////////
|
||||
|
||||
Variant ScriptInstance::call_const(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
|
||||
return callp(p_method, p_args, p_argcount, r_error);
|
||||
}
|
||||
|
||||
void ScriptInstance::get_property_state(List<Pair<StringName, Variant>> &state) {
|
||||
List<PropertyInfo> pinfo;
|
||||
get_property_list(&pinfo);
|
||||
for (const PropertyInfo &E : pinfo) {
|
||||
if (E.usage & PROPERTY_USAGE_STORAGE) {
|
||||
Pair<StringName, Variant> p;
|
||||
p.first = E.name;
|
||||
if (get(p.first, p.second)) {
|
||||
state.push_back(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptInstance::property_set_fallback(const StringName &, const Variant &, bool *r_valid) {
|
||||
if (r_valid) {
|
||||
*r_valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
Variant ScriptInstance::property_get_fallback(const StringName &, bool *r_valid) {
|
||||
if (r_valid) {
|
||||
*r_valid = false;
|
||||
}
|
||||
return Variant();
|
||||
}
|
||||
|
||||
ScriptInstance::~ScriptInstance() {
|
||||
}
|
||||
|
||||
ScriptCodeCompletionCache *ScriptCodeCompletionCache::singleton = nullptr;
|
||||
ScriptCodeCompletionCache::ScriptCodeCompletionCache() {
|
||||
singleton = this;
|
||||
|
@ -482,7 +448,6 @@ TypedArray<int> ScriptLanguage::CodeCompletionOption::get_option_characteristics
|
|||
}
|
||||
charac.push_back(matches.size());
|
||||
charac.push_back((matches[0].first == 0) ? 0 : 1);
|
||||
charac.push_back(location);
|
||||
const char32_t *target_char = &p_base[0];
|
||||
int bad_case = 0;
|
||||
for (const Pair<int, int> &match_segment : matches) {
|
||||
|
@ -494,6 +459,7 @@ TypedArray<int> ScriptLanguage::CodeCompletionOption::get_option_characteristics
|
|||
}
|
||||
}
|
||||
charac.push_back(bad_case);
|
||||
charac.push_back(location);
|
||||
charac.push_back(matches[0].first);
|
||||
last_matches = matches;
|
||||
return charac;
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
#include "core/doc_data.h"
|
||||
#include "core/io/resource.h"
|
||||
#include "core/object/script_instance.h"
|
||||
#include "core/templates/pair.h"
|
||||
#include "core/templates/rb_map.h"
|
||||
#include "core/templates/safe_refcount.h"
|
||||
|
@ -101,7 +102,6 @@ public:
|
|||
static bool are_languages_finished() { return languages_finished.is_set(); }
|
||||
};
|
||||
|
||||
class ScriptInstance;
|
||||
class PlaceHolderScriptInstance;
|
||||
|
||||
class Script : public Resource {
|
||||
|
@ -141,6 +141,7 @@ public:
|
|||
|
||||
#ifdef TOOLS_ENABLED
|
||||
virtual Vector<DocData::ClassDoc> get_documentation() const = 0;
|
||||
virtual String get_class_icon_path() const = 0;
|
||||
virtual PropertyInfo get_class_category() const;
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
|
@ -173,64 +174,6 @@ public:
|
|||
Script() {}
|
||||
};
|
||||
|
||||
class ScriptInstance {
|
||||
public:
|
||||
virtual bool set(const StringName &p_name, const Variant &p_value) = 0;
|
||||
virtual bool get(const StringName &p_name, Variant &r_ret) const = 0;
|
||||
virtual void get_property_list(List<PropertyInfo> *p_properties) const = 0;
|
||||
virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const = 0;
|
||||
|
||||
virtual bool property_can_revert(const StringName &p_name) const = 0;
|
||||
virtual bool property_get_revert(const StringName &p_name, Variant &r_ret) const = 0;
|
||||
|
||||
virtual Object *get_owner() { return nullptr; }
|
||||
virtual void get_property_state(List<Pair<StringName, Variant>> &state);
|
||||
|
||||
virtual void get_method_list(List<MethodInfo> *p_list) const = 0;
|
||||
virtual bool has_method(const StringName &p_method) const = 0;
|
||||
|
||||
virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) = 0;
|
||||
|
||||
template <typename... VarArgs>
|
||||
Variant call(const StringName &p_method, VarArgs... p_args) {
|
||||
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
|
||||
const Variant *argptrs[sizeof...(p_args) + 1];
|
||||
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
|
||||
argptrs[i] = &args[i];
|
||||
}
|
||||
Callable::CallError cerr;
|
||||
return callp(p_method, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args), cerr);
|
||||
}
|
||||
|
||||
virtual Variant call_const(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error); // implement if language supports const functions
|
||||
virtual void notification(int p_notification) = 0;
|
||||
virtual String to_string(bool *r_valid) {
|
||||
if (r_valid) {
|
||||
*r_valid = false;
|
||||
}
|
||||
return String();
|
||||
}
|
||||
|
||||
//this is used by script languages that keep a reference counter of their own
|
||||
//you can make make Ref<> not die when it reaches zero, so deleting the reference
|
||||
//depends entirely from the script
|
||||
|
||||
virtual void refcount_incremented() {}
|
||||
virtual bool refcount_decremented() { return true; } //return true if it can die
|
||||
|
||||
virtual Ref<Script> get_script() const = 0;
|
||||
|
||||
virtual bool is_placeholder() const { return false; }
|
||||
|
||||
virtual void property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid);
|
||||
virtual Variant property_get_fallback(const StringName &p_name, bool *r_valid);
|
||||
|
||||
virtual const Variant get_rpc_config() const { return get_script()->get_rpc_config(); }
|
||||
|
||||
virtual ScriptLanguage *get_language() = 0;
|
||||
virtual ~ScriptInstance();
|
||||
};
|
||||
|
||||
class ScriptCodeCompletionCache {
|
||||
static ScriptCodeCompletionCache *singleton;
|
||||
|
||||
|
@ -342,14 +285,16 @@ public:
|
|||
Vector<Pair<int, int>> matches;
|
||||
Vector<Pair<int, int>> last_matches = { { -1, -1 } }; // This value correspond to an impossible match
|
||||
int location = LOCATION_OTHER;
|
||||
String theme_color_name;
|
||||
|
||||
CodeCompletionOption() {}
|
||||
|
||||
CodeCompletionOption(const String &p_text, CodeCompletionKind p_kind, int p_location = LOCATION_OTHER) {
|
||||
CodeCompletionOption(const String &p_text, CodeCompletionKind p_kind, int p_location = LOCATION_OTHER, const String &p_theme_color_name = "") {
|
||||
display = p_text;
|
||||
insert_text = p_text;
|
||||
kind = p_kind;
|
||||
location = p_location;
|
||||
theme_color_name = p_theme_color_name;
|
||||
}
|
||||
|
||||
TypedArray<int> get_option_characteristics(const String &p_base);
|
||||
|
@ -462,6 +407,7 @@ public:
|
|||
virtual bool get(const StringName &p_name, Variant &r_ret) const override;
|
||||
virtual void get_property_list(List<PropertyInfo> *p_properties) const override;
|
||||
virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const override;
|
||||
virtual void validate_property(PropertyInfo &p_property) const override {}
|
||||
|
||||
virtual bool property_can_revert(const StringName &p_name) const override { return false; };
|
||||
virtual bool property_get_revert(const StringName &p_name, Variant &r_ret) const override { return false; };
|
||||
|
@ -473,7 +419,7 @@ public:
|
|||
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
||||
return Variant();
|
||||
}
|
||||
virtual void notification(int p_notification) override {}
|
||||
virtual void notification(int p_notification, bool p_reversed = false) override {}
|
||||
|
||||
virtual Ref<Script> get_script() const override { return script; }
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ void ScriptExtension::_bind_methods() {
|
|||
GDVIRTUAL_BIND(_reload, "keep_state");
|
||||
|
||||
GDVIRTUAL_BIND(_get_documentation);
|
||||
GDVIRTUAL_BIND(_get_class_icon_path);
|
||||
|
||||
GDVIRTUAL_BIND(_has_method, "method");
|
||||
GDVIRTUAL_BIND(_get_method_info, "method");
|
||||
|
|
|
@ -77,6 +77,7 @@ public:
|
|||
EXBIND1R(Error, reload, bool)
|
||||
|
||||
GDVIRTUAL0RC(TypedArray<Dictionary>, _get_documentation)
|
||||
GDVIRTUAL0RC(String, _get_class_icon_path)
|
||||
#ifdef TOOLS_ENABLED
|
||||
virtual Vector<DocData::ClassDoc> get_documentation() const override {
|
||||
TypedArray<Dictionary> doc;
|
||||
|
@ -89,6 +90,12 @@ public:
|
|||
|
||||
return class_doc;
|
||||
}
|
||||
|
||||
virtual String get_class_icon_path() const override {
|
||||
String ret;
|
||||
GDVIRTUAL_CALL(_get_class_icon_path, ret);
|
||||
return ret;
|
||||
}
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
EXBIND1RC(bool, has_method, const StringName &)
|
||||
|
@ -623,7 +630,12 @@ VARIANT_ENUM_CAST(ScriptLanguageExtension::CodeCompletionLocation)
|
|||
|
||||
class ScriptInstanceExtension : public ScriptInstance {
|
||||
public:
|
||||
const GDExtensionScriptInstanceInfo *native_info;
|
||||
const GDExtensionScriptInstanceInfo2 *native_info;
|
||||
bool free_native_info = false;
|
||||
struct {
|
||||
GDExtensionClassNotification notification_func;
|
||||
} deprecated_native_info;
|
||||
|
||||
GDExtensionScriptInstanceDataPtr instance = nullptr;
|
||||
|
||||
// There should not be warnings on explicit casts.
|
||||
|
@ -675,6 +687,28 @@ public:
|
|||
}
|
||||
return Variant::NIL;
|
||||
}
|
||||
virtual void validate_property(PropertyInfo &p_property) const override {
|
||||
if (native_info->validate_property_func) {
|
||||
// GDExtension uses a StringName rather than a String for property name.
|
||||
StringName prop_name = p_property.name;
|
||||
GDExtensionPropertyInfo gdext_prop = {
|
||||
(GDExtensionVariantType)p_property.type,
|
||||
&prop_name,
|
||||
&p_property.class_name,
|
||||
(uint32_t)p_property.hint,
|
||||
&p_property.hint_string,
|
||||
p_property.usage,
|
||||
};
|
||||
if (native_info->validate_property_func(instance, &gdext_prop)) {
|
||||
p_property.type = (Variant::Type)gdext_prop.type;
|
||||
p_property.name = *reinterpret_cast<StringName *>(gdext_prop.name);
|
||||
p_property.class_name = *reinterpret_cast<StringName *>(gdext_prop.class_name);
|
||||
p_property.hint = (PropertyHint)gdext_prop.hint;
|
||||
p_property.hint_string = *reinterpret_cast<String *>(gdext_prop.hint_string);
|
||||
p_property.usage = gdext_prop.usage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool property_can_revert(const StringName &p_name) const override {
|
||||
if (native_info->property_can_revert_func) {
|
||||
|
@ -736,11 +770,16 @@ public:
|
|||
return ret;
|
||||
}
|
||||
|
||||
virtual void notification(int p_notification) override {
|
||||
virtual void notification(int p_notification, bool p_reversed = false) override {
|
||||
if (native_info->notification_func) {
|
||||
native_info->notification_func(instance, p_notification);
|
||||
native_info->notification_func(instance, p_notification, p_reversed);
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
} else if (deprecated_native_info.notification_func) {
|
||||
deprecated_native_info.notification_func(instance, p_notification);
|
||||
#endif // DISABLE_DEPRECATED
|
||||
}
|
||||
}
|
||||
|
||||
virtual String to_string(bool *r_valid) override {
|
||||
if (native_info->to_string_func) {
|
||||
GDExtensionBool valid;
|
||||
|
@ -812,6 +851,9 @@ public:
|
|||
if (native_info->free_func) {
|
||||
native_info->free_func(instance);
|
||||
}
|
||||
if (free_native_info) {
|
||||
memfree(const_cast<GDExtensionScriptInstanceInfo2 *>(native_info));
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
|
|
|
@ -178,7 +178,7 @@ void UndoRedo::add_undo_method(const Callable &p_callable) {
|
|||
}
|
||||
|
||||
void UndoRedo::add_do_property(Object *p_object, const StringName &p_property, const Variant &p_value) {
|
||||
ERR_FAIL_COND(p_object == nullptr);
|
||||
ERR_FAIL_NULL(p_object);
|
||||
ERR_FAIL_COND(action_level <= 0);
|
||||
ERR_FAIL_COND((current_action + 1) >= actions.size());
|
||||
Operation do_op;
|
||||
|
@ -194,7 +194,7 @@ void UndoRedo::add_do_property(Object *p_object, const StringName &p_property, c
|
|||
}
|
||||
|
||||
void UndoRedo::add_undo_property(Object *p_object, const StringName &p_property, const Variant &p_value) {
|
||||
ERR_FAIL_COND(p_object == nullptr);
|
||||
ERR_FAIL_NULL(p_object);
|
||||
ERR_FAIL_COND(action_level <= 0);
|
||||
ERR_FAIL_COND((current_action + 1) >= actions.size());
|
||||
|
||||
|
@ -217,7 +217,7 @@ void UndoRedo::add_undo_property(Object *p_object, const StringName &p_property,
|
|||
}
|
||||
|
||||
void UndoRedo::add_do_reference(Object *p_object) {
|
||||
ERR_FAIL_COND(p_object == nullptr);
|
||||
ERR_FAIL_NULL(p_object);
|
||||
ERR_FAIL_COND(action_level <= 0);
|
||||
ERR_FAIL_COND((current_action + 1) >= actions.size());
|
||||
Operation do_op;
|
||||
|
@ -231,7 +231,7 @@ void UndoRedo::add_do_reference(Object *p_object) {
|
|||
}
|
||||
|
||||
void UndoRedo::add_undo_reference(Object *p_object) {
|
||||
ERR_FAIL_COND(p_object == nullptr);
|
||||
ERR_FAIL_NULL(p_object);
|
||||
ERR_FAIL_COND(action_level <= 0);
|
||||
ERR_FAIL_COND((current_action + 1) >= actions.size());
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
#include "core/os/thread_safe.h"
|
||||
|
||||
void WorkerThreadPool::Task::free_template_userdata() {
|
||||
ERR_FAIL_COND(!template_userdata);
|
||||
ERR_FAIL_COND(native_func_userdata == nullptr);
|
||||
ERR_FAIL_NULL(template_userdata);
|
||||
ERR_FAIL_NULL(native_func_userdata);
|
||||
BaseTemplateUserdata *btu = (BaseTemplateUserdata *)native_func_userdata;
|
||||
memdelete(btu);
|
||||
}
|
||||
|
|
|
@ -146,6 +146,7 @@ static const _KeyCodeText _keycodes[] = {
|
|||
{Key::FAVORITES ,"Favorites"},
|
||||
{Key::SEARCH ,"Search"},
|
||||
{Key::STANDBY ,"StandBy"},
|
||||
{Key::OPENURL ,"OpenURL"},
|
||||
{Key::LAUNCHMAIL ,"LaunchMail"},
|
||||
{Key::LAUNCHMEDIA ,"LaunchMedia"},
|
||||
{Key::LAUNCH0 ,"Launch0"},
|
||||
|
@ -238,6 +239,8 @@ static const _KeyCodeText _keycodes[] = {
|
|||
{Key::BAR ,"Bar"},
|
||||
{Key::BRACERIGHT ,"BraceRight"},
|
||||
{Key::ASCIITILDE ,"AsciiTilde"},
|
||||
{Key::YEN ,"Yen"},
|
||||
{Key::SECTION ,"Section"},
|
||||
{Key::NONE ,nullptr}
|
||||
/* clang-format on */
|
||||
};
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
// Keep the values in this enum in sync with `_keycodes` in `keyboard.cpp`,
|
||||
// and the bindings in `core_constants.cpp`.
|
||||
enum class Key {
|
||||
NONE = 0,
|
||||
// Special key: The strategy here is similar to the one used by toolkits,
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
#include "core/input/input_event.h"
|
||||
#include "core/object/gdvirtual.gen.inc"
|
||||
#include "core/object/ref_counted.h"
|
||||
#include "core/object/script_language.h"
|
||||
|
||||
class MainLoop : public Object {
|
||||
GDCLASS(MainLoop, Object);
|
||||
|
|
|
@ -74,7 +74,7 @@ void *Memory::alloc_static(size_t p_bytes, bool p_pad_align) {
|
|||
|
||||
void *mem = malloc(p_bytes + (prepad ? PAD_ALIGN : 0));
|
||||
|
||||
ERR_FAIL_COND_V(!mem, nullptr);
|
||||
ERR_FAIL_NULL_V(mem, nullptr);
|
||||
|
||||
alloc_count.increment();
|
||||
|
||||
|
@ -127,7 +127,7 @@ void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) {
|
|||
*s = p_bytes;
|
||||
|
||||
mem = (uint8_t *)realloc(mem, p_bytes + PAD_ALIGN);
|
||||
ERR_FAIL_COND_V(!mem, nullptr);
|
||||
ERR_FAIL_NULL_V(mem, nullptr);
|
||||
|
||||
s = (uint64_t *)mem;
|
||||
|
||||
|
@ -145,7 +145,7 @@ void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) {
|
|||
}
|
||||
|
||||
void Memory::free_static(void *p_ptr, bool p_pad_align) {
|
||||
ERR_FAIL_COND(p_ptr == nullptr);
|
||||
ERR_FAIL_NULL(p_ptr);
|
||||
|
||||
uint8_t *mem = (uint8_t *)p_ptr;
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ T *memnew_arr_template(size_t p_elements) {
|
|||
size_t len = sizeof(T) * p_elements;
|
||||
uint64_t *mem = (uint64_t *)Memory::alloc_static(len, true);
|
||||
T *failptr = nullptr; //get rid of a warning
|
||||
ERR_FAIL_COND_V(!mem, failptr);
|
||||
ERR_FAIL_NULL_V(mem, failptr);
|
||||
*(mem - 1) = p_elements;
|
||||
|
||||
if (!std::is_trivially_constructible<T>::value) {
|
||||
|
|
|
@ -328,6 +328,10 @@ public:
|
|||
|
||||
virtual PreferredTextureFormat get_preferred_texture_format() const;
|
||||
|
||||
// Load GDExtensions specific to this platform.
|
||||
// This is invoked by the GDExtensionManager after loading GDExtensions specified by the project.
|
||||
virtual void load_platform_gdextensions() const {}
|
||||
|
||||
OS();
|
||||
virtual ~OS();
|
||||
};
|
||||
|
|
|
@ -305,7 +305,7 @@ Error PoolAllocator::resize(ID p_mem, int p_new_size) {
|
|||
|
||||
if (!e) {
|
||||
mt_unlock();
|
||||
ERR_FAIL_COND_V(!e, ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_NULL_V(e, ERR_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
if (needs_locking && e->lock) {
|
||||
|
@ -431,7 +431,7 @@ bool PoolAllocator::is_locked(ID p_mem) const {
|
|||
const void *PoolAllocator::get(ID p_mem) const {
|
||||
if (!needs_locking) {
|
||||
const Entry *e = get_entry(p_mem);
|
||||
ERR_FAIL_COND_V(!e, nullptr);
|
||||
ERR_FAIL_NULL_V(e, nullptr);
|
||||
return &pool[e->pos];
|
||||
}
|
||||
|
||||
|
@ -440,7 +440,7 @@ const void *PoolAllocator::get(ID p_mem) const {
|
|||
|
||||
if (!e) {
|
||||
mt_unlock();
|
||||
ERR_FAIL_COND_V(!e, nullptr);
|
||||
ERR_FAIL_NULL_V(e, nullptr);
|
||||
}
|
||||
if (e->lock == 0) {
|
||||
mt_unlock();
|
||||
|
@ -463,7 +463,7 @@ const void *PoolAllocator::get(ID p_mem) const {
|
|||
void *PoolAllocator::get(ID p_mem) {
|
||||
if (!needs_locking) {
|
||||
Entry *e = get_entry(p_mem);
|
||||
ERR_FAIL_COND_V(!e, nullptr);
|
||||
ERR_FAIL_NULL_V(e, nullptr);
|
||||
return &pool[e->pos];
|
||||
}
|
||||
|
||||
|
@ -472,7 +472,7 @@ void *PoolAllocator::get(ID p_mem) {
|
|||
|
||||
if (!e) {
|
||||
mt_unlock();
|
||||
ERR_FAIL_COND_V(!e, nullptr);
|
||||
ERR_FAIL_NULL_V(e, nullptr);
|
||||
}
|
||||
if (e->lock == 0) {
|
||||
mt_unlock();
|
||||
|
@ -500,7 +500,7 @@ void PoolAllocator::unlock(ID p_mem) {
|
|||
Entry *e = get_entry(p_mem);
|
||||
if (!e) {
|
||||
mt_unlock();
|
||||
ERR_FAIL_COND(!e);
|
||||
ERR_FAIL_NULL(e);
|
||||
}
|
||||
if (e->lock == 0) {
|
||||
mt_unlock();
|
||||
|
@ -540,7 +540,7 @@ void PoolAllocator::create_pool(void *p_mem, int p_size, int p_max_entries) {
|
|||
|
||||
PoolAllocator::PoolAllocator(int p_size, bool p_needs_locking, int p_max_entries) {
|
||||
mem_ptr = memalloc(p_size);
|
||||
ERR_FAIL_COND(!mem_ptr);
|
||||
ERR_FAIL_NULL(mem_ptr);
|
||||
align = 1;
|
||||
create_pool(mem_ptr, p_size, p_max_entries);
|
||||
needs_locking = p_needs_locking;
|
||||
|
|
|
@ -73,7 +73,7 @@ int NodePath::get_name_count() const {
|
|||
}
|
||||
|
||||
StringName NodePath::get_name(int p_idx) const {
|
||||
ERR_FAIL_COND_V(!data, StringName());
|
||||
ERR_FAIL_NULL_V(data, StringName());
|
||||
ERR_FAIL_INDEX_V(p_idx, data->path.size(), StringName());
|
||||
return data->path[p_idx];
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ int NodePath::get_subname_count() const {
|
|||
}
|
||||
|
||||
StringName NodePath::get_subname(int p_idx) const {
|
||||
ERR_FAIL_COND_V(!data, StringName());
|
||||
ERR_FAIL_NULL_V(data, StringName());
|
||||
ERR_FAIL_INDEX_V(p_idx, data->subpath.size(), StringName());
|
||||
return data->subpath[p_idx];
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ Vector<StringName> NodePath::get_subnames() const {
|
|||
}
|
||||
|
||||
StringName NodePath::get_concatenated_names() const {
|
||||
ERR_FAIL_COND_V(!data, StringName());
|
||||
ERR_FAIL_NULL_V(data, StringName());
|
||||
|
||||
if (!data->concatenated_path) {
|
||||
int pc = data->path.size();
|
||||
|
@ -215,7 +215,7 @@ StringName NodePath::get_concatenated_names() const {
|
|||
}
|
||||
|
||||
StringName NodePath::get_concatenated_subnames() const {
|
||||
ERR_FAIL_COND_V(!data, StringName());
|
||||
ERR_FAIL_NULL_V(data, StringName());
|
||||
|
||||
if (!data->concatenated_subpath) {
|
||||
int spc = data->subpath.size();
|
||||
|
|
|
@ -65,7 +65,7 @@ void remove_print_handler(const PrintHandlerList *p_handler) {
|
|||
//OS::get_singleton()->print("print handler list is %p\n",print_handler_list);
|
||||
|
||||
_global_unlock();
|
||||
ERR_FAIL_COND(l == nullptr);
|
||||
ERR_FAIL_NULL(l);
|
||||
}
|
||||
|
||||
void __print_line(String p_string) {
|
||||
|
|
|
@ -390,7 +390,7 @@ StringName::StringName(const String &p_name, bool p_static) {
|
|||
StringName StringName::search(const char *p_name) {
|
||||
ERR_FAIL_COND_V(!configured, StringName());
|
||||
|
||||
ERR_FAIL_COND_V(!p_name, StringName());
|
||||
ERR_FAIL_NULL_V(p_name, StringName());
|
||||
if (!p_name[0]) {
|
||||
return StringName();
|
||||
}
|
||||
|
@ -426,7 +426,7 @@ StringName StringName::search(const char *p_name) {
|
|||
StringName StringName::search(const char32_t *p_name) {
|
||||
ERR_FAIL_COND_V(!configured, StringName());
|
||||
|
||||
ERR_FAIL_COND_V(!p_name, StringName());
|
||||
ERR_FAIL_NULL_V(p_name, StringName());
|
||||
if (!p_name[0]) {
|
||||
return StringName();
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
|
||||
#include "core/io/resource.h"
|
||||
#include "core/object/gdvirtual.gen.inc"
|
||||
#include "core/object/script_language.h"
|
||||
|
||||
class Translation : public Resource {
|
||||
GDCLASS(Translation, Resource);
|
||||
|
|
|
@ -1493,9 +1493,9 @@ String String::num(double p_num, int p_decimals) {
|
|||
|
||||
if (p_decimals < 0) {
|
||||
p_decimals = 14;
|
||||
const double abs_num = ABS(p_num);
|
||||
const double abs_num = Math::abs(p_num);
|
||||
if (abs_num > 10) {
|
||||
// We want to align the digits to the above sane default, so we only
|
||||
// We want to align the digits to the above reasonable default, so we only
|
||||
// need to subtract log10 for numbers with a positive power of ten.
|
||||
p_decimals -= (int)floor(log10(abs_num));
|
||||
}
|
||||
|
@ -3635,6 +3635,23 @@ String String::repeat(int p_count) const {
|
|||
return new_string;
|
||||
}
|
||||
|
||||
String String::reverse() const {
|
||||
int len = length();
|
||||
if (len <= 1) {
|
||||
return *this;
|
||||
}
|
||||
String new_string;
|
||||
new_string.resize(len + 1);
|
||||
|
||||
const char32_t *src = ptr();
|
||||
char32_t *dst = new_string.ptrw();
|
||||
for (int i = 0; i < len; i++) {
|
||||
dst[i] = src[len - i - 1];
|
||||
}
|
||||
dst[len] = _null;
|
||||
return new_string;
|
||||
}
|
||||
|
||||
String String::left(int p_len) const {
|
||||
if (p_len < 0) {
|
||||
p_len = length() + p_len;
|
||||
|
@ -3648,7 +3665,9 @@ String String::left(int p_len) const {
|
|||
return *this;
|
||||
}
|
||||
|
||||
return substr(0, p_len);
|
||||
String s;
|
||||
s.copy_from_unchecked(&get_data()[0], p_len);
|
||||
return s;
|
||||
}
|
||||
|
||||
String String::right(int p_len) const {
|
||||
|
@ -3664,7 +3683,9 @@ String String::right(int p_len) const {
|
|||
return *this;
|
||||
}
|
||||
|
||||
return substr(length() - p_len);
|
||||
String s;
|
||||
s.copy_from_unchecked(&get_data()[length() - p_len], p_len);
|
||||
return s;
|
||||
}
|
||||
|
||||
char32_t String::unicode_at(int p_idx) const {
|
||||
|
@ -4869,8 +4890,8 @@ String String::sprintf(const Array &values, bool *error) const {
|
|||
}
|
||||
|
||||
double value = values[value_index];
|
||||
bool is_negative = (value < 0);
|
||||
String str = String::num(ABS(value), min_decimals);
|
||||
bool is_negative = signbit(value);
|
||||
String str = String::num(Math::abs(value), min_decimals);
|
||||
const bool is_finite = Math::is_finite(value);
|
||||
|
||||
// Pad decimals out.
|
||||
|
@ -4932,7 +4953,7 @@ String String::sprintf(const Array &values, bool *error) const {
|
|||
String str = "(";
|
||||
for (int i = 0; i < count; i++) {
|
||||
double val = vec[i];
|
||||
String number_str = String::num(ABS(val), min_decimals);
|
||||
String number_str = String::num(Math::abs(val), min_decimals);
|
||||
const bool is_finite = Math::is_finite(val);
|
||||
|
||||
// Pad decimals out.
|
||||
|
|
|
@ -305,6 +305,7 @@ public:
|
|||
String replace(const char *p_key, const char *p_with) const;
|
||||
String replacen(const String &p_key, const String &p_with) const;
|
||||
String repeat(int p_count) const;
|
||||
String reverse() const;
|
||||
String insert(int p_at_pos, const String &p_string) const;
|
||||
String erase(int p_pos, int p_chars = 1) const;
|
||||
String pad_decimals(int p_digits) const;
|
||||
|
|
|
@ -409,7 +409,7 @@ public:
|
|||
}
|
||||
|
||||
void wait_and_flush() {
|
||||
ERR_FAIL_COND(!sync);
|
||||
ERR_FAIL_NULL(sync);
|
||||
sync->wait();
|
||||
_flush();
|
||||
}
|
||||
|
|
|
@ -286,7 +286,7 @@ Error CowData<T>::resize(int p_size) {
|
|||
if (current_size == 0) {
|
||||
// alloc from scratch
|
||||
uint32_t *ptr = (uint32_t *)Memory::alloc_static(alloc_size, true);
|
||||
ERR_FAIL_COND_V(!ptr, ERR_OUT_OF_MEMORY);
|
||||
ERR_FAIL_NULL_V(ptr, ERR_OUT_OF_MEMORY);
|
||||
*(ptr - 1) = 0; //size, currently none
|
||||
new (ptr - 2) SafeNumeric<uint32_t>(1); //refcount
|
||||
|
||||
|
@ -294,7 +294,7 @@ Error CowData<T>::resize(int p_size) {
|
|||
|
||||
} else {
|
||||
uint32_t *_ptrnew = (uint32_t *)Memory::realloc_static(_ptr, alloc_size, true);
|
||||
ERR_FAIL_COND_V(!_ptrnew, ERR_OUT_OF_MEMORY);
|
||||
ERR_FAIL_NULL_V(_ptrnew, ERR_OUT_OF_MEMORY);
|
||||
new (_ptrnew - 2) SafeNumeric<uint32_t>(rc); //refcount
|
||||
|
||||
_ptr = (T *)(_ptrnew);
|
||||
|
@ -324,7 +324,7 @@ Error CowData<T>::resize(int p_size) {
|
|||
|
||||
if (alloc_size != current_alloc_size) {
|
||||
uint32_t *_ptrnew = (uint32_t *)Memory::realloc_static(_ptr, alloc_size, true);
|
||||
ERR_FAIL_COND_V(!_ptrnew, ERR_OUT_OF_MEMORY);
|
||||
ERR_FAIL_NULL_V(_ptrnew, ERR_OUT_OF_MEMORY);
|
||||
new (_ptrnew - 2) SafeNumeric<uint32_t>(rc); //refcount
|
||||
|
||||
_ptr = (T *)(_ptrnew);
|
||||
|
|
|
@ -219,7 +219,7 @@ private:
|
|||
int size_cache = 0;
|
||||
|
||||
bool erase(const Element *p_I) {
|
||||
ERR_FAIL_COND_V(!p_I, false);
|
||||
ERR_FAIL_NULL_V(p_I, false);
|
||||
ERR_FAIL_COND_V(p_I->data != this, false);
|
||||
|
||||
if (first == p_I) {
|
||||
|
|
|
@ -112,7 +112,7 @@ public:
|
|||
}
|
||||
|
||||
void configure(uint32_t p_page_size) {
|
||||
ERR_FAIL_COND(page_pool != nullptr); //sanity check
|
||||
ERR_FAIL_COND(page_pool != nullptr); // Safety check.
|
||||
ERR_FAIL_COND(p_page_size == 0);
|
||||
page_size = nearest_power_of_2_templated(p_page_size);
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ public:
|
|||
uint32_t new_page_count = page_count + 1;
|
||||
|
||||
if (unlikely(new_page_count > max_pages_used)) {
|
||||
ERR_FAIL_COND(page_pool == nullptr); //sanity check
|
||||
ERR_FAIL_NULL(page_pool); // Safety check.
|
||||
|
||||
_grow_page_array(); //keep out of inline
|
||||
}
|
||||
|
@ -352,7 +352,7 @@ public:
|
|||
}
|
||||
|
||||
void set_page_pool(PagedArrayPool<T> *p_page_pool) {
|
||||
ERR_FAIL_COND(max_pages_used > 0); //sanity check
|
||||
ERR_FAIL_COND(max_pages_used > 0); // Safety check.
|
||||
|
||||
page_pool = p_page_pool;
|
||||
page_size_mask = page_pool->get_page_size_mask();
|
||||
|
|
|
@ -211,12 +211,12 @@ public:
|
|||
}
|
||||
void initialize_rid(RID p_rid) {
|
||||
T *mem = get_or_null(p_rid, true);
|
||||
ERR_FAIL_COND(!mem);
|
||||
ERR_FAIL_NULL(mem);
|
||||
memnew_placement(mem, T);
|
||||
}
|
||||
void initialize_rid(RID p_rid, const T &p_value) {
|
||||
T *mem = get_or_null(p_rid, true);
|
||||
ERR_FAIL_COND(!mem);
|
||||
ERR_FAIL_NULL(mem);
|
||||
memnew_placement(mem, T(p_value));
|
||||
}
|
||||
|
||||
|
@ -391,7 +391,7 @@ public:
|
|||
|
||||
_FORCE_INLINE_ void replace(const RID &p_rid, T *p_new_ptr) {
|
||||
T **ptr = alloc.get_or_null(p_rid);
|
||||
ERR_FAIL_COND(!ptr);
|
||||
ERR_FAIL_NULL(ptr);
|
||||
*ptr = p_new_ptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ constexpr T ABS(T m_v) {
|
|||
|
||||
template <typename T>
|
||||
constexpr const T SIGN(const T m_v) {
|
||||
return m_v == 0 ? 0.0f : (m_v < 0 ? -1.0f : +1.0f);
|
||||
return m_v > 0 ? +1.0f : (m_v < 0 ? -1.0f : 0.0f);
|
||||
}
|
||||
|
||||
template <typename T, typename T2>
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
void Array::_ref(const Array &p_from) const {
|
||||
ArrayPrivate *_fp = p_from._p;
|
||||
|
||||
ERR_FAIL_COND(!_fp); // should NOT happen.
|
||||
ERR_FAIL_NULL(_fp); // Should NOT happen.
|
||||
|
||||
if (_fp == _p) {
|
||||
return; // whatever it is, nothing to do here move along
|
||||
|
|
|
@ -465,20 +465,20 @@ Error Signal::emit(const Variant **p_arguments, int p_argcount) const {
|
|||
|
||||
Error Signal::connect(const Callable &p_callable, uint32_t p_flags) {
|
||||
Object *obj = get_object();
|
||||
ERR_FAIL_COND_V(!obj, ERR_UNCONFIGURED);
|
||||
ERR_FAIL_NULL_V(obj, ERR_UNCONFIGURED);
|
||||
|
||||
return obj->connect(name, p_callable, p_flags);
|
||||
}
|
||||
|
||||
void Signal::disconnect(const Callable &p_callable) {
|
||||
Object *obj = get_object();
|
||||
ERR_FAIL_COND(!obj);
|
||||
ERR_FAIL_NULL(obj);
|
||||
obj->disconnect(name, p_callable);
|
||||
}
|
||||
|
||||
bool Signal::is_connected(const Callable &p_callable) const {
|
||||
Object *obj = get_object();
|
||||
ERR_FAIL_COND_V(!obj, false);
|
||||
ERR_FAIL_NULL_V(obj, false);
|
||||
|
||||
return obj->is_connected(name, p_callable);
|
||||
}
|
||||
|
@ -500,7 +500,7 @@ Array Signal::get_connections() const {
|
|||
}
|
||||
|
||||
Signal::Signal(const Object *p_object, const StringName &p_name) {
|
||||
ERR_FAIL_COND_MSG(p_object == nullptr, "Object argument to Signal constructor must be non-null");
|
||||
ERR_FAIL_NULL_MSG(p_object, "Object argument to Signal constructor must be non-null.");
|
||||
|
||||
object = p_object->get_instance_id();
|
||||
name = p_name;
|
||||
|
|
|
@ -88,7 +88,7 @@ ObjectID CallableCustomBind::get_object() const {
|
|||
}
|
||||
|
||||
const Callable *CallableCustomBind::get_base_comparator() const {
|
||||
return &callable;
|
||||
return callable.get_base_comparator();
|
||||
}
|
||||
|
||||
int CallableCustomBind::get_bound_arguments_count() const {
|
||||
|
@ -222,7 +222,7 @@ ObjectID CallableCustomUnbind::get_object() const {
|
|||
}
|
||||
|
||||
const Callable *CallableCustomUnbind::get_base_comparator() const {
|
||||
return &callable;
|
||||
return callable.get_base_comparator();
|
||||
}
|
||||
|
||||
int CallableCustomUnbind::get_bound_arguments_count() const {
|
||||
|
|
|
@ -113,7 +113,7 @@ struct ContainerTypeValidate {
|
|||
return true; // This is fine, it's null.
|
||||
}
|
||||
Object *object = ObjectDB::get_instance(object_id);
|
||||
ERR_FAIL_COND_V_MSG(object == nullptr, false, "Attempted to " + String(p_operation) + " an invalid (previously freed?) object instance into a '" + String(where) + ".");
|
||||
ERR_FAIL_NULL_V_MSG(object, false, "Attempted to " + String(p_operation) + " an invalid (previously freed?) object instance into a '" + String(where) + ".");
|
||||
#else
|
||||
Object *object = p_variant;
|
||||
if (object == nullptr) {
|
||||
|
|
|
@ -248,7 +248,7 @@ void Dictionary::merge(const Dictionary &p_dictionary, bool p_overwrite) {
|
|||
}
|
||||
|
||||
void Dictionary::_unref() const {
|
||||
ERR_FAIL_COND(!_p);
|
||||
ERR_FAIL_NULL(_p);
|
||||
if (_p->refcount.unref()) {
|
||||
if (_p->read_only) {
|
||||
memdelete(_p->read_only);
|
||||
|
|
|
@ -230,4 +230,7 @@ MAKE_TYPED_ARRAY_INFO(Vector<Vector3>, Variant::PACKED_VECTOR3_ARRAY)
|
|||
MAKE_TYPED_ARRAY_INFO(Vector<Color>, Variant::PACKED_COLOR_ARRAY)
|
||||
MAKE_TYPED_ARRAY_INFO(IPAddress, Variant::STRING)
|
||||
|
||||
#undef MAKE_TYPED_ARRAY
|
||||
#undef MAKE_TYPED_ARRAY_INFO
|
||||
|
||||
#endif // TYPED_ARRAY_H
|
||||
|
|
|
@ -1754,11 +1754,10 @@ String Variant::stringify(int recursion_count) const {
|
|||
case COLOR:
|
||||
return operator Color();
|
||||
case DICTIONARY: {
|
||||
ERR_FAIL_COND_V_MSG(recursion_count > MAX_RECURSION, "{ ... }", "Maximum dictionary recursion reached!");
|
||||
recursion_count++;
|
||||
|
||||
const Dictionary &d = *reinterpret_cast<const Dictionary *>(_data._mem);
|
||||
if (recursion_count > MAX_RECURSION) {
|
||||
ERR_PRINT("Maximum dictionary recursion reached!");
|
||||
return "{ ... }";
|
||||
}
|
||||
|
||||
// Add leading and trailing space to Dictionary printing. This distinguishes it
|
||||
// from array printing on fonts that have similar-looking {} and [] characters.
|
||||
|
@ -1768,7 +1767,6 @@ String Variant::stringify(int recursion_count) const {
|
|||
|
||||
Vector<_VariantStrPair> pairs;
|
||||
|
||||
recursion_count++;
|
||||
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
|
||||
_VariantStrPair sp;
|
||||
sp.key = stringify_variant_clean(E->get(), recursion_count);
|
||||
|
@ -1787,6 +1785,7 @@ String Variant::stringify(int recursion_count) const {
|
|||
|
||||
return str;
|
||||
}
|
||||
// Packed arrays cannot contain recursive structures, the recursion_count increment is not needed.
|
||||
case PACKED_VECTOR2_ARRAY: {
|
||||
return stringify_vector(operator Vector<Vector2>(), recursion_count);
|
||||
}
|
||||
|
@ -1815,13 +1814,10 @@ String Variant::stringify(int recursion_count) const {
|
|||
return stringify_vector(operator Vector<double>(), recursion_count);
|
||||
}
|
||||
case ARRAY: {
|
||||
Array arr = operator Array();
|
||||
if (recursion_count > MAX_RECURSION) {
|
||||
ERR_PRINT("Maximum array recursion reached!");
|
||||
return "[...]";
|
||||
}
|
||||
ERR_FAIL_COND_V_MSG(recursion_count > MAX_RECURSION, "[...]", "Maximum array recursion reached!");
|
||||
recursion_count++;
|
||||
|
||||
return stringify_vector(arr, recursion_count);
|
||||
return stringify_vector(operator Array(), recursion_count);
|
||||
}
|
||||
case OBJECT: {
|
||||
if (_get_obj().obj) {
|
||||
|
|
|
@ -561,8 +561,8 @@ static _FORCE_INLINE_ void vc_ptrcall(void (*method)(T *, P...), void *p_base, c
|
|||
} \
|
||||
static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \
|
||||
LocalVector<Variant> vars; \
|
||||
vars.resize(p_argcount); \
|
||||
LocalVector<const Variant *> vars_ptrs; \
|
||||
vars.resize(p_argcount); \
|
||||
vars_ptrs.resize(p_argcount); \
|
||||
for (int i = 0; i < p_argcount; i++) { \
|
||||
vars[i] = PtrToArg<Variant>::convert(p_args[i]); \
|
||||
|
@ -571,7 +571,7 @@ static _FORCE_INLINE_ void vc_ptrcall(void (*method)(T *, P...), void *p_base, c
|
|||
Variant base = PtrToArg<m_class>::convert(p_base); \
|
||||
Variant ret; \
|
||||
Callable::CallError ce; \
|
||||
m_method_ptr(&base, (const Variant **)&vars_ptrs[0], p_argcount, ret, ce); \
|
||||
m_method_ptr(&base, vars_ptrs.ptr(), p_argcount, ret, ce); \
|
||||
if (m_has_return) { \
|
||||
m_return_type r = ret; \
|
||||
PtrToArg<m_return_type>::encode(ret, r_ret); \
|
||||
|
@ -617,8 +617,8 @@ static _FORCE_INLINE_ void vc_ptrcall(void (*method)(T *, P...), void *p_base, c
|
|||
} \
|
||||
static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \
|
||||
LocalVector<Variant> vars; \
|
||||
vars.resize(p_argcount); \
|
||||
LocalVector<const Variant *> vars_ptrs; \
|
||||
vars.resize(p_argcount); \
|
||||
vars_ptrs.resize(p_argcount); \
|
||||
for (int i = 0; i < p_argcount; i++) { \
|
||||
vars[i] = PtrToArg<Variant>::convert(p_args[i]); \
|
||||
|
@ -627,7 +627,7 @@ static _FORCE_INLINE_ void vc_ptrcall(void (*method)(T *, P...), void *p_base, c
|
|||
Variant base = PtrToArg<m_class>::convert(p_base); \
|
||||
Variant ret; \
|
||||
Callable::CallError ce; \
|
||||
m_method_ptr(&base, (const Variant **)&vars_ptrs[0], p_argcount, ret, ce); \
|
||||
m_method_ptr(&base, vars_ptrs.ptr(), p_argcount, ret, ce); \
|
||||
} \
|
||||
static int get_argument_count() { \
|
||||
return 1; \
|
||||
|
@ -1132,11 +1132,7 @@ static void register_builtin_method(const Vector<String> &p_argnames, const Vect
|
|||
|
||||
imi.call = T::call;
|
||||
imi.validated_call = T::validated_call;
|
||||
if (T::is_vararg()) {
|
||||
imi.ptrcall = nullptr;
|
||||
} else {
|
||||
imi.ptrcall = T::ptrcall;
|
||||
}
|
||||
|
||||
imi.default_arguments = p_def_args;
|
||||
imi.argument_names = p_argnames;
|
||||
|
@ -1263,28 +1259,28 @@ bool Variant::has_builtin_method(Variant::Type p_type, const StringName &p_metho
|
|||
Variant::ValidatedBuiltInMethod Variant::get_validated_builtin_method(Variant::Type p_type, const StringName &p_method) {
|
||||
ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, nullptr);
|
||||
const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
|
||||
ERR_FAIL_COND_V(!method, nullptr);
|
||||
ERR_FAIL_NULL_V(method, nullptr);
|
||||
return method->validated_call;
|
||||
}
|
||||
|
||||
Variant::PTRBuiltInMethod Variant::get_ptr_builtin_method(Variant::Type p_type, const StringName &p_method) {
|
||||
ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, nullptr);
|
||||
const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
|
||||
ERR_FAIL_COND_V(!method, nullptr);
|
||||
ERR_FAIL_NULL_V(method, nullptr);
|
||||
return method->ptrcall;
|
||||
}
|
||||
|
||||
int Variant::get_builtin_method_argument_count(Variant::Type p_type, const StringName &p_method) {
|
||||
ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, 0);
|
||||
const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
|
||||
ERR_FAIL_COND_V(!method, 0);
|
||||
ERR_FAIL_NULL_V(method, 0);
|
||||
return method->argument_count;
|
||||
}
|
||||
|
||||
Variant::Type Variant::get_builtin_method_argument_type(Variant::Type p_type, const StringName &p_method, int p_argument) {
|
||||
ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, Variant::NIL);
|
||||
const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
|
||||
ERR_FAIL_COND_V(!method, Variant::NIL);
|
||||
ERR_FAIL_NULL_V(method, Variant::NIL);
|
||||
ERR_FAIL_INDEX_V(p_argument, method->argument_count, Variant::NIL);
|
||||
return method->get_argument_type(p_argument);
|
||||
}
|
||||
|
@ -1292,7 +1288,7 @@ Variant::Type Variant::get_builtin_method_argument_type(Variant::Type p_type, co
|
|||
String Variant::get_builtin_method_argument_name(Variant::Type p_type, const StringName &p_method, int p_argument) {
|
||||
ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, String());
|
||||
const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
|
||||
ERR_FAIL_COND_V(!method, String());
|
||||
ERR_FAIL_NULL_V(method, String());
|
||||
#ifdef DEBUG_METHODS_ENABLED
|
||||
ERR_FAIL_INDEX_V(p_argument, method->argument_count, String());
|
||||
return method->argument_names[p_argument];
|
||||
|
@ -1304,14 +1300,14 @@ String Variant::get_builtin_method_argument_name(Variant::Type p_type, const Str
|
|||
Vector<Variant> Variant::get_builtin_method_default_arguments(Variant::Type p_type, const StringName &p_method) {
|
||||
ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, Vector<Variant>());
|
||||
const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
|
||||
ERR_FAIL_COND_V(!method, Vector<Variant>());
|
||||
ERR_FAIL_NULL_V(method, Vector<Variant>());
|
||||
return method->default_arguments;
|
||||
}
|
||||
|
||||
bool Variant::has_builtin_method_return_value(Variant::Type p_type, const StringName &p_method) {
|
||||
ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
|
||||
const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
|
||||
ERR_FAIL_COND_V(!method, false);
|
||||
ERR_FAIL_NULL_V(method, false);
|
||||
return method->has_return_type;
|
||||
}
|
||||
|
||||
|
@ -1330,35 +1326,35 @@ int Variant::get_builtin_method_count(Variant::Type p_type) {
|
|||
Variant::Type Variant::get_builtin_method_return_type(Variant::Type p_type, const StringName &p_method) {
|
||||
ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, Variant::NIL);
|
||||
const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
|
||||
ERR_FAIL_COND_V(!method, Variant::NIL);
|
||||
ERR_FAIL_NULL_V(method, Variant::NIL);
|
||||
return method->return_type;
|
||||
}
|
||||
|
||||
bool Variant::is_builtin_method_const(Variant::Type p_type, const StringName &p_method) {
|
||||
ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
|
||||
const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
|
||||
ERR_FAIL_COND_V(!method, false);
|
||||
ERR_FAIL_NULL_V(method, false);
|
||||
return method->is_const;
|
||||
}
|
||||
|
||||
bool Variant::is_builtin_method_static(Variant::Type p_type, const StringName &p_method) {
|
||||
ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
|
||||
const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
|
||||
ERR_FAIL_COND_V(!method, false);
|
||||
ERR_FAIL_NULL_V(method, false);
|
||||
return method->is_static;
|
||||
}
|
||||
|
||||
bool Variant::is_builtin_method_vararg(Variant::Type p_type, const StringName &p_method) {
|
||||
ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
|
||||
const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
|
||||
ERR_FAIL_COND_V(!method, false);
|
||||
ERR_FAIL_NULL_V(method, false);
|
||||
return method->is_vararg;
|
||||
}
|
||||
|
||||
uint32_t Variant::get_builtin_method_hash(Variant::Type p_type, const StringName &p_method) {
|
||||
ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, 0);
|
||||
const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
|
||||
ERR_FAIL_COND_V(!method, 0);
|
||||
ERR_FAIL_NULL_V(method, 0);
|
||||
uint32_t hash = hash_murmur3_one_32(method->is_const);
|
||||
hash = hash_murmur3_one_32(method->is_static, hash);
|
||||
hash = hash_murmur3_one_32(method->is_vararg, hash);
|
||||
|
@ -1659,6 +1655,7 @@ static void _register_variant_builtin_methods() {
|
|||
bind_string_methodv(replace, static_cast<String (String::*)(const String &, const String &) const>(&String::replace), sarray("what", "forwhat"), varray());
|
||||
bind_string_method(replacen, sarray("what", "forwhat"), varray());
|
||||
bind_string_method(repeat, sarray("count"), varray());
|
||||
bind_string_method(reverse, sarray(), varray());
|
||||
bind_string_method(insert, sarray("position", "what"), varray());
|
||||
bind_string_method(erase, sarray("position", "chars"), varray(1));
|
||||
bind_string_method(capitalize, sarray(), varray());
|
||||
|
|
|
@ -1493,7 +1493,7 @@ public:
|
|||
}
|
||||
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
|
||||
Object *l = right->get_validated_object();
|
||||
ERR_FAIL_COND(l == nullptr);
|
||||
ERR_FAIL_NULL(l);
|
||||
const String &a = *VariantGetInternalPtr<String>::get_ptr(left);
|
||||
|
||||
bool valid;
|
||||
|
@ -1527,7 +1527,7 @@ public:
|
|||
}
|
||||
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
|
||||
Object *l = right->get_validated_object();
|
||||
ERR_FAIL_COND(l == nullptr);
|
||||
ERR_FAIL_NULL(l);
|
||||
const StringName &a = *VariantGetInternalPtr<StringName>::get_ptr(left);
|
||||
|
||||
bool valid;
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "core/input/input_event.h"
|
||||
#include "core/io/resource_loader.h"
|
||||
#include "core/object/script_language.h"
|
||||
#include "core/os/keyboard.h"
|
||||
#include "core/string/string_buffer.h"
|
||||
|
||||
|
@ -1708,7 +1709,7 @@ static String rtos_fix(double p_value) {
|
|||
}
|
||||
}
|
||||
|
||||
Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_string_func, void *p_store_string_ud, EncodeResourceFunc p_encode_res_func, void *p_encode_res_ud, int recursion_count) {
|
||||
Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_string_func, void *p_store_string_ud, EncodeResourceFunc p_encode_res_func, void *p_encode_res_ud, int p_recursion_count) {
|
||||
switch (p_variant.get_type()) {
|
||||
case Variant::NIL: {
|
||||
p_store_string_func(p_store_string_ud, "null");
|
||||
|
@ -1730,10 +1731,11 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
} break;
|
||||
case Variant::STRING: {
|
||||
String str = p_variant;
|
||||
|
||||
str = "\"" + str.c_escape_multiline() + "\"";
|
||||
p_store_string_func(p_store_string_ud, str);
|
||||
} break;
|
||||
|
||||
// Math types.
|
||||
case Variant::VECTOR2: {
|
||||
Vector2 v = p_variant;
|
||||
p_store_string_func(p_store_string_ud, "Vector2(" + rtos_fix(v.x) + ", " + rtos_fix(v.y) + ")");
|
||||
|
@ -1745,12 +1747,10 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
case Variant::RECT2: {
|
||||
Rect2 aabb = p_variant;
|
||||
p_store_string_func(p_store_string_ud, "Rect2(" + rtos_fix(aabb.position.x) + ", " + rtos_fix(aabb.position.y) + ", " + rtos_fix(aabb.size.x) + ", " + rtos_fix(aabb.size.y) + ")");
|
||||
|
||||
} break;
|
||||
case Variant::RECT2I: {
|
||||
Rect2i aabb = p_variant;
|
||||
p_store_string_func(p_store_string_ud, "Rect2i(" + itos(aabb.position.x) + ", " + itos(aabb.position.y) + ", " + itos(aabb.size.x) + ", " + itos(aabb.size.y) + ")");
|
||||
|
||||
} break;
|
||||
case Variant::VECTOR3: {
|
||||
Vector3 v = p_variant;
|
||||
|
@ -1771,17 +1771,14 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
case Variant::PLANE: {
|
||||
Plane p = p_variant;
|
||||
p_store_string_func(p_store_string_ud, "Plane(" + rtos_fix(p.normal.x) + ", " + rtos_fix(p.normal.y) + ", " + rtos_fix(p.normal.z) + ", " + rtos_fix(p.d) + ")");
|
||||
|
||||
} break;
|
||||
case Variant::AABB: {
|
||||
AABB aabb = p_variant;
|
||||
p_store_string_func(p_store_string_ud, "AABB(" + rtos_fix(aabb.position.x) + ", " + rtos_fix(aabb.position.y) + ", " + rtos_fix(aabb.position.z) + ", " + rtos_fix(aabb.size.x) + ", " + rtos_fix(aabb.size.y) + ", " + rtos_fix(aabb.size.z) + ")");
|
||||
|
||||
} break;
|
||||
case Variant::QUATERNION: {
|
||||
Quaternion quaternion = p_variant;
|
||||
p_store_string_func(p_store_string_ud, "Quaternion(" + rtos_fix(quaternion.x) + ", " + rtos_fix(quaternion.y) + ", " + rtos_fix(quaternion.z) + ", " + rtos_fix(quaternion.w) + ")");
|
||||
|
||||
} break;
|
||||
case Variant::TRANSFORM2D: {
|
||||
String s = "Transform2D(";
|
||||
|
@ -1796,7 +1793,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, s + ")");
|
||||
|
||||
} break;
|
||||
case Variant::BASIS: {
|
||||
String s = "Basis(";
|
||||
|
@ -1811,7 +1807,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, s + ")");
|
||||
|
||||
} break;
|
||||
case Variant::TRANSFORM3D: {
|
||||
String s = "Transform3D(";
|
||||
|
@ -1845,30 +1840,23 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
p_store_string_func(p_store_string_ud, s + ")");
|
||||
} break;
|
||||
|
||||
// misc types
|
||||
// Misc types.
|
||||
case Variant::COLOR: {
|
||||
Color c = p_variant;
|
||||
p_store_string_func(p_store_string_ud, "Color(" + rtos_fix(c.r) + ", " + rtos_fix(c.g) + ", " + rtos_fix(c.b) + ", " + rtos_fix(c.a) + ")");
|
||||
|
||||
} break;
|
||||
case Variant::STRING_NAME: {
|
||||
String str = p_variant;
|
||||
|
||||
str = "&\"" + str.c_escape() + "\"";
|
||||
p_store_string_func(p_store_string_ud, str);
|
||||
|
||||
} break;
|
||||
case Variant::NODE_PATH: {
|
||||
String str = p_variant;
|
||||
|
||||
str = "NodePath(\"" + str.c_escape() + "\")";
|
||||
p_store_string_func(p_store_string_ud, str);
|
||||
|
||||
} break;
|
||||
|
||||
case Variant::RID: {
|
||||
RID rid = p_variant;
|
||||
|
||||
if (rid == RID()) {
|
||||
p_store_string_func(p_store_string_ud, "RID()");
|
||||
} else {
|
||||
|
@ -1885,6 +1873,13 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
} break;
|
||||
|
||||
case Variant::OBJECT: {
|
||||
if (unlikely(p_recursion_count > MAX_RECURSION)) {
|
||||
ERR_PRINT("Max recursion reached");
|
||||
p_store_string_func(p_store_string_ud, "null");
|
||||
return OK;
|
||||
}
|
||||
p_recursion_count++;
|
||||
|
||||
Object *obj = p_variant.get_validated_object();
|
||||
|
||||
if (!obj) {
|
||||
|
@ -1934,21 +1929,20 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, "\"" + E.name + "\":");
|
||||
write(obj->get(E.name), p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud);
|
||||
write(obj->get(E.name), p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, p_recursion_count);
|
||||
}
|
||||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, ")\n");
|
||||
|
||||
} break;
|
||||
|
||||
case Variant::DICTIONARY: {
|
||||
Dictionary dict = p_variant;
|
||||
if (recursion_count > MAX_RECURSION) {
|
||||
if (unlikely(p_recursion_count > MAX_RECURSION)) {
|
||||
ERR_PRINT("Max recursion reached");
|
||||
p_store_string_func(p_store_string_ud, "{}");
|
||||
} else {
|
||||
recursion_count++;
|
||||
p_recursion_count++;
|
||||
|
||||
List<Variant> keys;
|
||||
dict.get_key_list(&keys);
|
||||
|
@ -1961,9 +1955,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
|
||||
p_store_string_func(p_store_string_ud, "{\n");
|
||||
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
|
||||
write(E->get(), p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, recursion_count);
|
||||
write(E->get(), p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, p_recursion_count);
|
||||
p_store_string_func(p_store_string_ud, ": ");
|
||||
write(dict[E->get()], p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, recursion_count);
|
||||
write(dict[E->get()], p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, p_recursion_count);
|
||||
if (E->next()) {
|
||||
p_store_string_func(p_store_string_ud, ",\n");
|
||||
} else {
|
||||
|
@ -1973,7 +1967,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
|
||||
p_store_string_func(p_store_string_ud, "}");
|
||||
}
|
||||
|
||||
} break;
|
||||
|
||||
case Variant::ARRAY: {
|
||||
|
@ -2009,11 +2002,11 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
p_store_string_func(p_store_string_ud, "](");
|
||||
}
|
||||
|
||||
if (recursion_count > MAX_RECURSION) {
|
||||
if (unlikely(p_recursion_count > MAX_RECURSION)) {
|
||||
ERR_PRINT("Max recursion reached");
|
||||
p_store_string_func(p_store_string_ud, "[]");
|
||||
} else {
|
||||
recursion_count++;
|
||||
p_recursion_count++;
|
||||
|
||||
p_store_string_func(p_store_string_ud, "[");
|
||||
int len = array.size();
|
||||
|
@ -2021,7 +2014,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
if (i > 0) {
|
||||
p_store_string_func(p_store_string_ud, ", ");
|
||||
}
|
||||
write(array[i], p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, recursion_count);
|
||||
write(array[i], p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, p_recursion_count);
|
||||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, "]");
|
||||
|
@ -2030,7 +2023,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
if (array.get_typed_builtin() != Variant::NIL) {
|
||||
p_store_string_func(p_store_string_ud, ")");
|
||||
}
|
||||
|
||||
} break;
|
||||
|
||||
case Variant::PACKED_BYTE_ARRAY: {
|
||||
|
@ -2048,7 +2040,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, ")");
|
||||
|
||||
} break;
|
||||
case Variant::PACKED_INT32_ARRAY: {
|
||||
p_store_string_func(p_store_string_ud, "PackedInt32Array(");
|
||||
|
@ -2065,7 +2056,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, ")");
|
||||
|
||||
} break;
|
||||
case Variant::PACKED_INT64_ARRAY: {
|
||||
p_store_string_func(p_store_string_ud, "PackedInt64Array(");
|
||||
|
@ -2082,7 +2072,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, ")");
|
||||
|
||||
} break;
|
||||
case Variant::PACKED_FLOAT32_ARRAY: {
|
||||
p_store_string_func(p_store_string_ud, "PackedFloat32Array(");
|
||||
|
@ -2098,7 +2087,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, ")");
|
||||
|
||||
} break;
|
||||
case Variant::PACKED_FLOAT64_ARRAY: {
|
||||
p_store_string_func(p_store_string_ud, "PackedFloat64Array(");
|
||||
|
@ -2114,7 +2102,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, ")");
|
||||
|
||||
} break;
|
||||
case Variant::PACKED_STRING_ARRAY: {
|
||||
p_store_string_func(p_store_string_ud, "PackedStringArray(");
|
||||
|
@ -2130,7 +2117,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, ")");
|
||||
|
||||
} break;
|
||||
case Variant::PACKED_VECTOR2_ARRAY: {
|
||||
p_store_string_func(p_store_string_ud, "PackedVector2Array(");
|
||||
|
@ -2146,7 +2132,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, ")");
|
||||
|
||||
} break;
|
||||
case Variant::PACKED_VECTOR3_ARRAY: {
|
||||
p_store_string_func(p_store_string_ud, "PackedVector3Array(");
|
||||
|
@ -2162,7 +2147,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, ")");
|
||||
|
||||
} break;
|
||||
case Variant::PACKED_COLOR_ARRAY: {
|
||||
p_store_string_func(p_store_string_ud, "PackedColorArray(");
|
||||
|
@ -2178,8 +2162,8 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, ")");
|
||||
|
||||
} break;
|
||||
|
||||
default: {
|
||||
ERR_PRINT("Unknown variant type");
|
||||
return ERR_BUG;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue