From f2562291393a2a2ad203d0eaaf71e82652998113 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 8 Feb 2022 11:52:29 +0100 Subject: [PATCH] Work on fixing compile for 4.0. --- areas/terra_world_area.h | 5 +- data/terra_light.h | 6 +- defines.h | 80 +++++++++++- library/terra_material_cache.cpp | 21 +++- library/terra_material_cache.h | 4 + library/terraman_library.cpp | 183 +++++++++++++++++++++++++--- library/terraman_library.h | 37 ++++++ library/terraman_library_simple.cpp | 2 +- meshers/terra_mesher.cpp | 35 ++++-- meshers/terra_mesher.h | 16 ++- world/jobs/terra_mesher_job_step.h | 5 +- world/terra_chunk.cpp | 12 +- world/terra_environment_data.cpp | 9 +- world/terra_environment_data.h | 6 +- world/terra_structure.cpp | 9 +- world/terra_structure.h | 9 +- world/terra_world.cpp | 76 ++++++++---- world/terra_world.h | 14 +++ world/terra_world_editor.cpp | 38 +++++- world/terra_world_editor.h | 18 ++- 20 files changed, 504 insertions(+), 81 deletions(-) diff --git a/areas/terra_world_area.h b/areas/terra_world_area.h index 9b1f297..085f644 100644 --- a/areas/terra_world_area.h +++ b/areas/terra_world_area.h @@ -26,7 +26,10 @@ SOFTWARE. #include "core/version.h" #if VERSION_MAJOR > 3 -#include "core/object/reference.h" +#include "core/object/ref_counted.h" +#ifndef Reference +#define Reference RefCounted +#endif #include "core/string/ustring.h" #else #include "core/reference.h" diff --git a/data/terra_light.h b/data/terra_light.h index 2d60cf6..2570591 100644 --- a/data/terra_light.h +++ b/data/terra_light.h @@ -26,7 +26,10 @@ SOFTWARE. #include "core/version.h" #if VERSION_MAJOR > 3 -#include "core/object/reference.h" +#include "core/object/ref_counted.h" +#ifndef Reference +#define Reference RefCounted +#endif #include "core/templates/vector.h" #include "core/math/color.h" #else @@ -35,6 +38,7 @@ SOFTWARE. #include "core/color.h" #endif + class TerraLight : public Reference { GDCLASS(TerraLight, Reference); diff --git a/defines.h b/defines.h index 286c6dd..358ddc8 100644 --- a/defines.h +++ b/defines.h @@ -14,7 +14,8 @@ #define spatial_editor_plugin_h "editor/plugins/node_3d_editor_plugin.h" #define camera_h "scene/3d/camera_3d.h" #define spatial_h "scene/3d/node_3d.h" -#define navigation_h "scene/3d/navigation_3d.h" +#define navigation_h "scene/3d/node_3d.h" +#define Navigation3D Node3D #define light_h "scene/3d/light_3d.h" #define visual_server_h "servers/rendering_server.h" #define mesh_instance_h "scene/3d/mesh_instance_3d.h" @@ -63,6 +64,7 @@ #define Camera Camera3D #define ToolButton Button #define Shape Shape3D +#define Reference RefCounted typedef class World3D World; @@ -112,11 +114,87 @@ typedef class RenderingServer VS; #define CONNECT(sig, obj, target_method_class, method) connect(sig, callable_mp(obj, &target_method_class::method)) #define DISCONNECT(sig, obj, target_method_class, method) disconnect(sig, callable_mp(obj, &target_method_class::method)) #define GET_WORLD get_world_3d +#define INSTANCE instantiate +#define VREMOVE remove_at + +#define CALL(func, ...) \ + _gdvirtual_##func##_call(__VA_ARGS__) + +#define RETURN_CALL(ret_type, func) \ + ret_type _return_call_ret_var; \ + _gdvirtual_##func##_call(_return_call_ret_var); \ + return _return_call_ret_var; + +#define RETURN_CALLP(ret_type, func, ...) \ + ret_type _return_call_ret_var; \ + _gdvirtual_##func##_call(__VA_ARGS__, _return_call_ret_var); \ + return _return_call_ret_var; + +#define GET_CALL(ret_type, ret_var, func) \ + _gdvirtual_##func##_call(ret_var); + +#define GET_CALLP(ret_type, ret_var, func, ...) \ + _gdvirtual_##func##_call(__VA_ARGS__, ret_var); + +#define RETURN_CALLD(ret_type, def_val, func) \ + ret_type _return_call_ret_var = def_val; \ + if (_gdvirtual_##func##_call(_return_call_ret_var)) { \ + return _return_call_ret_var; \ + } \ + return def_val; + +#define RETURN_CALLPD(ret_type, def_val, func, ...) \ + ret_type _return_call_ret_var = def_val; \ + if (_gdvirtual_##func##_call(__VA_ARGS__, _return_call_ret_var)) { \ + return _return_call_ret_var; \ + } \ + return def_val; + +#define GET_CALLD(ret_type, def_val, ret_var, func) \ + if (!_gdvirtual_##func##_call(ret_var)) { \ + ret_var = def_val; \ + } + +#define GET_CALLPD(ret_type, def_val, ret_var, func, ...) \ + if (!_gdvirtual_##func##_call(__VA_ARGS__, ret_var)) { \ + ret_var = def_val; \ + } + #else #define INSTANCE_VALIDATE(var) ObjectDB::instance_validate(var) #define CONNECT(sig, obj, target_method_class, method) connect(sig, obj, #method) #define DISCONNECT(sig, obj, target_method_class, method) disconnect(sig, obj, #method) #define GET_WORLD get_world +#define INSTANCE instance +#define VREMOVE remove + +#define CALL(func, ...) \ + call(#func, ##__VA_ARGS__); + +#define RETURN_CALL(ret_type, func) \ + return call(#func, ##__VA_ARGS__); + +#define RETURN_CALLP(ret_type, func, ...) \ + return call(#func, ##__VA_ARGS__); + +#define GET_CALL(ret_type, ret_var, func) \ + ret_var = call(#func); + +#define GET_CALLP(ret_type, ret_var, func, ...) \ + ret_var = call(#func, ##__VA_ARGS__); + +#define RETURN_CALLD(ret_type, def_val, func) \ + return call(#func, ##__VA_ARGS__); + +#define RETURN_CALLPD(ret_type, def_val, func, ...) \ + return call(#func, ##__VA_ARGS__); + +#define GET_CALLD(ret_type, def_val, ret_var, func) \ + ret_var = call(#func); + +#define GET_CALLPD(ret_type, def_val, ret_var, func, ...) \ + return call(#func, ##__VA_ARGS__); + #endif #endif \ No newline at end of file diff --git a/library/terra_material_cache.cpp b/library/terra_material_cache.cpp index 33eea43..161c7b8 100644 --- a/library/terra_material_cache.cpp +++ b/library/terra_material_cache.cpp @@ -22,6 +22,8 @@ SOFTWARE. #include "terra_material_cache.h" +#include "../defines.h" + #ifdef PROPS_PRESENT #include "../../props/props/prop_data.h" #include "../../props/props/prop_data_prop.h" @@ -85,7 +87,7 @@ void TerraMaterialCache::material_set(const int index, const Ref &valu } void TerraMaterialCache::material_remove(const int index) { - _materials.remove(index); + _materials.VREMOVE(index); } int TerraMaterialCache::material_get_num() const { @@ -146,7 +148,7 @@ void TerraMaterialCache::surface_set(int index, Ref value) { _surfaces.set(index, value); } void TerraMaterialCache::surface_remove(const int index) { - _surfaces.remove(index); + _surfaces.VREMOVE(index); } int TerraMaterialCache::surface_get_num() const { return _surfaces.size(); @@ -161,7 +163,7 @@ void TerraMaterialCache::additional_texture_add(const Ref &texture) { void TerraMaterialCache::additional_texture_remove(const Ref &texture) { for (int i = 0; i < _additional_textures.size(); ++i) { if (_additional_textures[i] == texture) { - _additional_textures.remove(i); + _additional_textures.VREMOVE(i); return; } } @@ -169,7 +171,7 @@ void TerraMaterialCache::additional_texture_remove(const Ref &texture) void TerraMaterialCache::additional_texture_remove_index(const int index) { ERR_FAIL_INDEX(index, _additional_textures.size()); - _additional_textures.remove(index); + _additional_textures.VREMOVE(index); } void TerraMaterialCache::additional_textures_clear() { _additional_textures.clear(); @@ -254,8 +256,13 @@ void TerraMaterialCache::refresh_rects() { } void TerraMaterialCache::setup_material_albedo(Ref texture) { - if (has_method("_setup_material_albedo")) +#if VERSION_MAJOR < 4 + if (has_method("_setup_material_albedo")) { call("_setup_material_albedo", texture); + } +#else + GDVIRTUAL_CALL(_setup_material_albedo, texture); +#endif } TerraMaterialCache::TerraMaterialCache() { @@ -279,7 +286,11 @@ void TerraMaterialCache::_bind_methods() { ClassDB::bind_method(D_METHOD("inc_ref_count"), &TerraMaterialCache::inc_ref_count); ClassDB::bind_method(D_METHOD("dec_ref_count"), &TerraMaterialCache::dec_ref_count); +#if VERSION_MAJOR < 4 BIND_VMETHOD(MethodInfo("_setup_material_albedo", PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"))); +#else + GDVIRTUAL_BIND(_setup_material_albedo, "texture"); +#endif ClassDB::bind_method(D_METHOD("material_get", "index"), &TerraMaterialCache::material_get); ClassDB::bind_method(D_METHOD("material_lod_get", "index"), &TerraMaterialCache::material_lod_get); diff --git a/library/terra_material_cache.h b/library/terra_material_cache.h index 73c3e2c..757e2bd 100644 --- a/library/terra_material_cache.h +++ b/library/terra_material_cache.h @@ -94,6 +94,10 @@ public: void setup_material_albedo(Ref texture); +#if VERSION_MAJOR >= 4 + GDVIRTUAL1(_setup_material_albedo, Ref); +#endif + TerraMaterialCache(); ~TerraMaterialCache(); diff --git a/library/terraman_library.cpp b/library/terraman_library.cpp index 729ebd1..cecc11f 100644 --- a/library/terraman_library.cpp +++ b/library/terraman_library.cpp @@ -34,6 +34,117 @@ SOFTWARE. #include "../defines.h" +#if VERSION_MAJOR > 3 + +#define TMCGDVIRTUAL1(m_class, m_name, m_type1) \ + bool m_class::_gdvirtual_##m_name##_call(m_type1 arg1) { \ + ScriptInstance *script_instance = ((Object *)(this))->get_script_instance(); \ + if (script_instance) { \ + Callable::CallError ce; \ + Variant vargs[1] = { Variant(arg1) }; \ + const Variant *vargptrs[1] = { &vargs[0] }; \ + \ + script_instance->call(_gdvirtual_##m_name##_sn, (const Variant **)vargptrs, 1, ce); \ + if (ce.error == Callable::CallError::CALL_OK) { \ + return true; \ + } \ + } \ + if (unlikely(_get_extension() && !_gdvirtual_##m_name##_initialized)) { \ + _gdvirtual_##m_name = (_get_extension() && _get_extension()->get_virtual) ? _get_extension()->get_virtual(_get_extension()->class_userdata, #m_name) : (GDNativeExtensionClassCallVirtual) nullptr; \ + _gdvirtual_##m_name##_initialized = true; \ + } \ + if (_gdvirtual_##m_name) { \ + PtrToArg::EncodeT argval1 = arg1; \ + const GDNativeTypePtr argptrs[1] = { &argval1 }; \ + \ + _gdvirtual_##m_name(_get_extension_instance(), (const GDNativeTypePtr *)argptrs, nullptr); \ + \ + return true; \ + } \ + \ + return false; \ + } \ + bool m_class::_gdvirtual_##m_name##_overridden() const { \ + ScriptInstance *script_instance = ((Object *)(this))->get_script_instance(); \ + if (script_instance) { \ + return script_instance->has_method(_gdvirtual_##m_name##_sn); \ + } \ + if (unlikely(_get_extension() && !_gdvirtual_##m_name##_initialized)) { \ + _gdvirtual_##m_name = (_get_extension() && _get_extension()->get_virtual) ? _get_extension()->get_virtual(_get_extension()->class_userdata, #m_name) : (GDNativeExtensionClassCallVirtual) nullptr; \ + _gdvirtual_##m_name##_initialized = true; \ + } \ + if (_gdvirtual_##m_name) { \ + return true; \ + } \ + return false; \ + } \ + \ + MethodInfo m_class::_gdvirtual_##m_name##_get_method_info() { \ + MethodInfo method_info; \ + method_info.name = #m_name; \ + method_info.flags = METHOD_FLAG_VIRTUAL; \ + method_info.arguments.push_back(GetTypeInfo::get_class_info()); \ + \ + return method_info; \ + } + +#define TMCGDVIRTUAL1R(m_class, m_ret, m_name, m_type1) \ + bool m_class::_gdvirtual_##m_name##_call(m_type1 arg1, m_ret &r_ret) { \ + ScriptInstance *script_instance = ((Object *)(this))->get_script_instance(); \ + if (script_instance) { \ + Callable::CallError ce; \ + Variant vargs[1] = { Variant(arg1) }; \ + const Variant *vargptrs[1] = { &vargs[0] }; \ + \ + Variant ret = script_instance->call(_gdvirtual_##m_name##_sn, (const Variant **)vargptrs, 1, ce); \ + if (ce.error == Callable::CallError::CALL_OK) { \ + r_ret = VariantCaster::cast(ret); \ + return true; \ + } \ + } \ + if (unlikely(_get_extension() && !_gdvirtual_##m_name##_initialized)) { \ + _gdvirtual_##m_name = (_get_extension() && _get_extension()->get_virtual) ? _get_extension()->get_virtual(_get_extension()->class_userdata, #m_name) : (GDNativeExtensionClassCallVirtual) nullptr; \ + _gdvirtual_##m_name##_initialized = true; \ + } \ + if (_gdvirtual_##m_name) { \ + PtrToArg::EncodeT argval1 = arg1; \ + const GDNativeTypePtr argptrs[1] = { &argval1 }; \ + \ + PtrToArg::EncodeT ret; \ + _gdvirtual_##m_name(_get_extension_instance(), (const GDNativeTypePtr *)argptrs, &ret); \ + r_ret = (m_ret)ret; \ + return true; \ + } \ + \ + return false; \ + } \ + bool m_class::_gdvirtual_##m_name##_overridden() const { \ + ScriptInstance *script_instance = ((Object *)(this))->get_script_instance(); \ + if (script_instance) { \ + return script_instance->has_method(_gdvirtual_##m_name##_sn); \ + } \ + if (unlikely(_get_extension() && !_gdvirtual_##m_name##_initialized)) { \ + _gdvirtual_##m_name = (_get_extension() && _get_extension()->get_virtual) ? _get_extension()->get_virtual(_get_extension()->class_userdata, #m_name) : (GDNativeExtensionClassCallVirtual) nullptr; \ + _gdvirtual_##m_name##_initialized = true; \ + } \ + if (_gdvirtual_##m_name) { \ + return true; \ + } \ + return false; \ + } \ + \ + MethodInfo m_class::_gdvirtual_##m_name##_get_method_info() { \ + MethodInfo method_info; \ + method_info.name = #m_name; \ + method_info.flags = METHOD_FLAG_VIRTUAL; \ + method_info.return_val = GetTypeInfo::get_class_info(); \ + method_info.arguments.push_back(GetTypeInfo::get_class_info()); \ + \ + return method_info; \ + } + +#endif + bool TerramanLibrary::get_initialized() const { return _initialized; } @@ -42,7 +153,7 @@ void TerramanLibrary::set_initialized(const bool value) { } bool TerramanLibrary::supports_caching() { - return call("_supports_caching"); + RETURN_CALLD(bool, false, _supports_caching); } bool TerramanLibrary::_supports_caching() { return false; @@ -70,14 +181,14 @@ Ref TerramanLibrary::material_lod_get(const int index) { } void TerramanLibrary::material_cache_get_key(Ref chunk) { - call("_material_cache_get_key", chunk); + CALL(_material_cache_get_key, chunk); } void TerramanLibrary::_material_cache_get_key(Ref chunk) { } Ref TerramanLibrary::material_cache_get(const int key) { - return call("_material_cache_get", key); + RETURN_CALLP(Ref, _material_cache_get, key); } Ref TerramanLibrary::_material_cache_get(const int key) { @@ -85,7 +196,7 @@ Ref TerramanLibrary::_material_cache_get(const int key) { } void TerramanLibrary::material_cache_unref(const int key) { - call("_material_cache_unref", key); + CALL(_material_cache_unref, key); } void TerramanLibrary::_material_cache_unref(const int key) { } @@ -103,7 +214,7 @@ void TerramanLibrary::material_set(const int index, const Ref &value) } void TerramanLibrary::material_remove(const int index) { - _materials.remove(index); + _materials.VREMOVE(index); } int TerramanLibrary::material_get_num() const { @@ -150,14 +261,14 @@ Ref TerramanLibrary::liquid_material_lod_get(const int index) { } void TerramanLibrary::liquid_material_cache_get_key(Ref chunk) { - call("_liquid_material_cache_get_key", chunk); + CALL(_liquid_material_cache_get_key, chunk); } void TerramanLibrary::_liquid_material_cache_get_key(Ref chunk) { } Ref TerramanLibrary::liquid_material_cache_get(const int key) { - return call("_liquid_material_cache_get", key); + RETURN_CALLP(Ref, _liquid_material_cache_get, key); } Ref TerramanLibrary::_liquid_material_cache_get(const int key) { @@ -165,7 +276,7 @@ Ref TerramanLibrary::_liquid_material_cache_get(const int ke } void TerramanLibrary::liquid_material_cache_unref(const int key) { - call("_liquid_material_cache_unref", key); + CALL(_liquid_material_cache_unref, key); } void TerramanLibrary::_liquid_material_cache_unref(const int key) { } @@ -183,7 +294,7 @@ void TerramanLibrary::liquid_material_set(const int index, const Ref & } void TerramanLibrary::liquid_material_remove(const int index) { - _liquid_materials.remove(index); + _liquid_materials.VREMOVE(index); } int TerramanLibrary::liquid_material_get_num() const { @@ -230,14 +341,14 @@ Ref TerramanLibrary::prop_material_lod_get(const int index) { } void TerramanLibrary::prop_material_cache_get_key(Ref chunk) { - call("_prop_material_cache_get_key", chunk); + CALL(_prop_material_cache_get_key, chunk); } void TerramanLibrary::_prop_material_cache_get_key(Ref chunk) { } Ref TerramanLibrary::prop_material_cache_get(const int key) { - return call("_prop_material_cache_get", key); + RETURN_CALLP(Ref, _prop_material_cache_get, key); } Ref TerramanLibrary::_prop_material_cache_get(const int key) { @@ -245,7 +356,7 @@ Ref TerramanLibrary::_prop_material_cache_get(const int key) } void TerramanLibrary::prop_material_cache_unref(const int key) { - call("_prop_material_cache_unref", key); + CALL(_prop_material_cache_unref, key); } void TerramanLibrary::_prop_material_cache_unref(const int key) { } @@ -263,7 +374,7 @@ void TerramanLibrary::prop_material_set(const int index, const Ref &va } void TerramanLibrary::prop_material_remove(const int index) { - _prop_materials.remove(index); + _prop_materials.VREMOVE(index); } int TerramanLibrary::prop_material_get_num() const { @@ -343,8 +454,9 @@ void TerramanLibrary::refresh_rects() { } void TerramanLibrary::setup_material_albedo(int material_index, Ref texture) { - if (has_method("_setup_material_albedo")) - call("_setup_material_albedo", material_index, texture); + if (has_method("_setup_material_albedo")) { + CALL(_setup_material_albedo, material_index, texture); + } } TerramanLibrary::TerramanLibrary() { @@ -357,20 +469,49 @@ TerramanLibrary::~TerramanLibrary() { _prop_materials.clear(); } +#if VERSION_MAJOR >= 4 +TMCGDVIRTUAL1(TerramanLibrary, _material_cache_get_key, Ref); +TMCGDVIRTUAL1R(TerramanLibrary, Ref, _material_cache_get, int); +TMCGDVIRTUAL1(TerramanLibrary, _material_cache_unref, int); + +TMCGDVIRTUAL1(TerramanLibrary, _liquid_material_cache_get_key, Ref); +TMCGDVIRTUAL1R(TerramanLibrary, Ref, _liquid_material_cache_get, int); +TMCGDVIRTUAL1(TerramanLibrary, _liquid_material_cache_unref, int); + +TMCGDVIRTUAL1(TerramanLibrary, _prop_material_cache_get_key, Ref); +TMCGDVIRTUAL1R(TerramanLibrary, Ref, _prop_material_cache_get, int); +TMCGDVIRTUAL1(TerramanLibrary, _prop_material_cache_unref, int); +#endif + void TerramanLibrary::_bind_methods() { ClassDB::bind_method(D_METHOD("get_initialized"), &TerramanLibrary::get_initialized); ClassDB::bind_method(D_METHOD("set_initialized", "value"), &TerramanLibrary::set_initialized); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "initialized", PROPERTY_HINT_NONE, "", 0), "set_initialized", "get_initialized"); +#if VERSION_MAJOR < 4 BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::BOOL, "ret"), "_supports_caching")); +#else + GDVIRTUAL_BIND(_supports_caching); +#endif + ClassDB::bind_method(D_METHOD("_supports_caching"), &TerramanLibrary::_supports_caching); ClassDB::bind_method(D_METHOD("supports_caching"), &TerramanLibrary::supports_caching); +#if VERSION_MAJOR < 4 BIND_VMETHOD(MethodInfo("_setup_material_albedo", PropertyInfo(Variant::INT, "material_index"), PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"))); +#else + GDVIRTUAL_BIND(_setup_material_albedo, "material_index", "texture"); +#endif +#if VERSION_MAJOR < 4 BIND_VMETHOD(MethodInfo("_material_cache_get_key", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"))); BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "ret", PROPERTY_HINT_RESOURCE_TYPE, "TerraMaterialCache"), "_material_cache_get", PropertyInfo(Variant::INT, "key"))); BIND_VMETHOD(MethodInfo("_material_cache_unref", PropertyInfo(Variant::INT, "key"))); +#else + GDVIRTUAL_BIND(_material_cache_get_key, "chunk", "texture"); + GDVIRTUAL_BIND(_material_cache_get, "key"); + GDVIRTUAL_BIND(_material_cache_unref, "key"); +#endif ClassDB::bind_method(D_METHOD("material_get", "index"), &TerramanLibrary::material_get); ClassDB::bind_method(D_METHOD("material_lod_get", "index"), &TerramanLibrary::material_lod_get); @@ -392,9 +533,15 @@ void TerramanLibrary::_bind_methods() { ClassDB::bind_method(D_METHOD("materials_set"), &TerramanLibrary::materials_set); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "materials", PROPERTY_HINT_NONE, "17/17:Material", PROPERTY_USAGE_DEFAULT, "Material"), "materials_set", "materials_get"); +#if VERSION_MAJOR < 4 BIND_VMETHOD(MethodInfo("_liquid_material_cache_get_key", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"))); BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "ret", PROPERTY_HINT_RESOURCE_TYPE, "TerraMaterialCache"), "_liquid_material_cache_get", PropertyInfo(Variant::INT, "key"))); BIND_VMETHOD(MethodInfo("_liquid_material_cache_unref", PropertyInfo(Variant::INT, "key"))); +#else + GDVIRTUAL_BIND(_liquid_material_cache_get_key, "chunk", "texture"); + GDVIRTUAL_BIND(_liquid_material_cache_get, "key"); + GDVIRTUAL_BIND(_liquid_material_cache_unref, "key"); +#endif ClassDB::bind_method(D_METHOD("liquid_material_get", "index"), &TerramanLibrary::liquid_material_get); ClassDB::bind_method(D_METHOD("liquid_material_lod_get", "index"), &TerramanLibrary::liquid_material_lod_get); @@ -416,9 +563,15 @@ void TerramanLibrary::_bind_methods() { ClassDB::bind_method(D_METHOD("liquid_materials_set"), &TerramanLibrary::liquid_materials_set); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "liquid_materials", PROPERTY_HINT_NONE, "17/17:Material", PROPERTY_USAGE_DEFAULT, "Material"), "liquid_materials_set", "liquid_materials_get"); +#if VERSION_MAJOR < 4 BIND_VMETHOD(MethodInfo("_prop_material_cache_get_key", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"))); BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "ret", PROPERTY_HINT_RESOURCE_TYPE, "TerraMaterialCache"), "_prop_material_cache_get", PropertyInfo(Variant::INT, "key"))); BIND_VMETHOD(MethodInfo("_prop_material_cache_unref", PropertyInfo(Variant::INT, "key"))); +#else + GDVIRTUAL_BIND(_prop_material_cache_get_key, "chunk", "texture"); + GDVIRTUAL_BIND(_prop_material_cache_get, "key"); + GDVIRTUAL_BIND(_prop_material_cache_unref, "key"); +#endif ClassDB::bind_method(D_METHOD("prop_material_get", "index"), &TerramanLibrary::prop_material_get); ClassDB::bind_method(D_METHOD("prop_material_lod_get", "index"), &TerramanLibrary::prop_material_lod_get); diff --git a/library/terraman_library.h b/library/terraman_library.h index 8925a78..dfa757d 100644 --- a/library/terraman_library.h +++ b/library/terraman_library.h @@ -27,6 +27,25 @@ SOFTWARE. #if VERSION_MAJOR > 3 #include "core/io/resource.h" + +// These are needed here to use incomplete classes as vmethod arguments (godot4) + +#define TMHGDVIRTUAL1(m_name, m_type1) \ + StringName _gdvirtual_##m_name##_sn = #m_name; \ + mutable bool _gdvirtual_##m_name##_initialized = false; \ + mutable GDNativeExtensionClassCallVirtual _gdvirtual_##m_name = nullptr; \ + bool _gdvirtual_##m_name##_call(m_type1 arg1); \ + bool _gdvirtual_##m_name##_overridden() const; \ + static MethodInfo _gdvirtual_##m_name##_get_method_info(); + +#define TMHGDVIRTUAL1R(m_ret, m_name, m_type1) \ + StringName _gdvirtual_##m_name##_sn = #m_name; \ + mutable bool _gdvirtual_##m_name##_initialized = false; \ + mutable GDNativeExtensionClassCallVirtual _gdvirtual_##m_name = nullptr; \ + bool _gdvirtual_##m_name##_call(m_type1 arg1, m_ret &r_ret); \ + bool _gdvirtual_##m_name##_overridden() const; \ + static MethodInfo _gdvirtual_##m_name##_get_method_info(); + #else #include "core/resource.h" #endif @@ -156,6 +175,24 @@ public: void setup_material_albedo(int material_index, Ref texture); +#if VERSION_MAJOR >= 4 + GDVIRTUAL0R(bool, _supports_caching); + + GDVIRTUAL2(_setup_material_albedo, int, Ref); + + TMHGDVIRTUAL1(_material_cache_get_key, Ref); + TMHGDVIRTUAL1R(Ref, _material_cache_get, int); + TMHGDVIRTUAL1(_material_cache_unref, int); + + TMHGDVIRTUAL1(_liquid_material_cache_get_key, Ref); + TMHGDVIRTUAL1R(Ref, _liquid_material_cache_get, int); + TMHGDVIRTUAL1(_liquid_material_cache_unref, int); + + TMHGDVIRTUAL1(_prop_material_cache_get_key, Ref); + TMHGDVIRTUAL1R(Ref, _prop_material_cache_get, int); + TMHGDVIRTUAL1(_prop_material_cache_unref, int); +#endif + TerramanLibrary(); ~TerramanLibrary(); diff --git a/library/terraman_library_simple.cpp b/library/terraman_library_simple.cpp index efe14ed..d61f360 100644 --- a/library/terraman_library_simple.cpp +++ b/library/terraman_library_simple.cpp @@ -77,7 +77,7 @@ void TerramanLibrarySimple::voxel_surface_set(const int index, Ref } void TerramanLibrarySimple::voxel_surface_remove(const int index) { - _voxel_surfaces.remove(index); + _voxel_surfaces.VREMOVE(index); } int TerramanLibrarySimple::voxel_surface_get_num() const { diff --git a/meshers/terra_mesher.cpp b/meshers/terra_mesher.cpp index 25cc28f..1dd0954 100644 --- a/meshers/terra_mesher.cpp +++ b/meshers/terra_mesher.cpp @@ -374,7 +374,7 @@ void TerraMesher::remove_doubles() { for (int j = 0; j < indices.size(); ++j) { int index = indices[j]; - _vertices.remove(index); + _vertices.VREMOVE(index); //make all indices that were bigger than the one we replaced one lower for (int k = 0; k < _indices.size(); ++k) { @@ -426,8 +426,8 @@ void TerraMesher::remove_doubles_hashed() { for (int j = 0; j < indices.size(); ++j) { int index = indices[j]; - hashes.remove(index); - _vertices.remove(index); + hashes.VREMOVE(index); + _vertices.VREMOVE(index); //make all indices that were bigger than the one we replaced one lower for (int k = 0; k < _indices.size(); ++k) { @@ -470,7 +470,7 @@ void TerraMesher::add_chunk(Ref chunk) { ERR_FAIL_COND(!has_method("_add_chunk")); ERR_FAIL_COND(!chunk.is_valid()); - call("_add_chunk", chunk); + CALL(_add_chunk, chunk); } #ifdef MESH_DATA_RESOURCE_PRESENT @@ -569,7 +569,7 @@ void TerraMesher::add_mesh_data_resource_transform_colored(Ref #endif void TerraMesher::add_mesher(const Ref &mesher) { - call("_add_mesher", mesher); + CALL(_add_mesher, mesher); } void TerraMesher::_add_mesher(const Ref &mesher) { int orig_size = _vertices.size(); @@ -592,15 +592,17 @@ void TerraMesher::_add_mesher(const Ref &mesher) { void TerraMesher::bake_colors(Ref chunk) { ERR_FAIL_COND(!chunk.is_valid()); - if (has_method("_bake_colors")) - call("_bake_colors", chunk); + if (has_method("_bake_colors")) { + CALL(_bake_colors, chunk); + } } void TerraMesher::bake_liquid_colors(Ref chunk) { ERR_FAIL_COND(!chunk.is_valid()); - if (has_method("_bake_liquid_colors")) - call("_bake_liquid_colors", chunk); + if (has_method("_bake_liquid_colors")) { + CALL(_bake_liquid_colors, chunk); + } } PoolVector TerraMesher::build_collider() const { @@ -768,7 +770,7 @@ Vector3 TerraMesher::get_vertex(const int idx) const { } void TerraMesher::remove_vertex(const int idx) { - _vertices.remove(idx); + _vertices.VREMOVE(idx); } PoolVector TerraMesher::get_normals() const { @@ -916,7 +918,7 @@ int TerraMesher::get_index(const int idx) const { } void TerraMesher::remove_index(const int idx) { - _indices.remove(idx); + _indices.VREMOVE(idx); } TerraMesher::TerraMesher(const Ref &library) { @@ -954,9 +956,15 @@ TerraMesher::~TerraMesher() { } void TerraMesher::_bind_methods() { +#if VERSION_MAJOR < 4 BIND_VMETHOD(MethodInfo("_add_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"))); BIND_VMETHOD(MethodInfo("_bake_colors", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"))); BIND_VMETHOD(MethodInfo("_bake_liquid_colors", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"))); +#else + GDVIRTUAL_BIND(_add_chunk, "chunk"); + GDVIRTUAL_BIND(_bake_colors, "chunk"); + GDVIRTUAL_BIND(_bake_liquid_colors, "chunk"); +#endif ClassDB::bind_method(D_METHOD("get_channel_index_type"), &TerraMesher::get_channel_index_type); ClassDB::bind_method(D_METHOD("set_channel_index_type", "value"), &TerraMesher::set_channel_index_type); @@ -1014,7 +1022,12 @@ void TerraMesher::_bind_methods() { ClassDB::bind_method(D_METHOD("add_mesh_data_resource_transform_colored", "mesh", "transform", "colors", "uv_rect"), &TerraMesher::add_mesh_data_resource_transform_colored, DEFVAL(Rect2(0, 0, 1, 1))); #endif + +#if VERSION_MAJOR < 4 BIND_VMETHOD(MethodInfo("_add_mesher", PropertyInfo(Variant::OBJECT, "mesher", PROPERTY_HINT_RESOURCE_TYPE, "TerraMesher"))); +#else + GDVIRTUAL_BIND(_add_mesher, "mesher"); +#endif ClassDB::bind_method(D_METHOD("add_mesher", "mesher"), &TerraMesher::add_mesher); ClassDB::bind_method(D_METHOD("_add_mesher", "mesher"), &TerraMesher::_add_mesher); diff --git a/meshers/terra_mesher.h b/meshers/terra_mesher.h index f1ae0e9..732a8bb 100644 --- a/meshers/terra_mesher.h +++ b/meshers/terra_mesher.h @@ -26,13 +26,16 @@ SOFTWARE. #include "core/version.h" #if VERSION_MAJOR > 3 -#include "core/math/color.h" -#include "core/object/reference.h" +#include "core/object/ref_counted.h" +#ifndef Reference +#define Reference RefCounted +#endif #include "core/templates/vector.h" +#include "core/math/color.h" #else -#include "core/color.h" #include "core/reference.h" #include "core/vector.h" +#include "core/color.h" #endif #include "../defines.h" @@ -191,6 +194,13 @@ public: void remove_index(const int idx); void add_indices(const int index); +#if VERSION_MAJOR >= 4 + GDVIRTUAL1(_add_chunk, Ref); + GDVIRTUAL1(_bake_colors, Ref); + GDVIRTUAL1(_bake_liquid_colors, Ref); + GDVIRTUAL1(_add_mesher, Ref); +#endif + TerraMesher(const Ref &library); TerraMesher(); ~TerraMesher(); diff --git a/world/jobs/terra_mesher_job_step.h b/world/jobs/terra_mesher_job_step.h index 700c779..34ce78b 100644 --- a/world/jobs/terra_mesher_job_step.h +++ b/world/jobs/terra_mesher_job_step.h @@ -26,7 +26,10 @@ SOFTWARE. #include "core/version.h" #if VERSION_MAJOR > 3 -#include "core/io/reference.h" +#include "core/object/ref_counted.h" +#ifndef Reference +#define Reference RefCounted +#endif #else #include "core/reference.h" #endif diff --git a/world/terra_chunk.cpp b/world/terra_chunk.cpp index ec00883..79cb1c9 100644 --- a/world/terra_chunk.cpp +++ b/world/terra_chunk.cpp @@ -255,7 +255,7 @@ void TerraChunk::job_set(int index, const Ref &job) { void TerraChunk::job_remove(const int index) { ERR_FAIL_INDEX(index, _jobs.size()); - _jobs.remove(index); + _jobs.VREMOVE(index); } void TerraChunk::job_add(const Ref &job) { _jobs.push_back(job); @@ -609,12 +609,12 @@ void TerraChunk::voxel_structure_remove(const Ref &structure) { int index = _voxel_structures.find(structure); if (index != -1) - _voxel_structures.remove(index); + _voxel_structures.VREMOVE(index); } void TerraChunk::voxel_structure_remove_index(const int index) { ERR_FAIL_INDEX(index, _voxel_structures.size()); - _voxel_structures.remove(index); + _voxel_structures.VREMOVE(index); } void TerraChunk::voxel_structure_clear() { _voxel_structures.clear(); @@ -718,7 +718,7 @@ int TerraChunk::prop_get_count() const { void TerraChunk::prop_remove(const int index) { ERR_FAIL_INDEX(index, _props.size()); - _props.remove(index); + _props.VREMOVE(index); } void TerraChunk::props_clear() { _props.clear(); @@ -876,7 +876,7 @@ int TerraChunk::mesh_data_resource_get_count() const { void TerraChunk::mesh_data_resource_remove(const int index) { ERR_FAIL_INDEX(index, _mesh_data_resources.size()); - _mesh_data_resources.remove(index); + _mesh_data_resources.VREMOVE(index); } void TerraChunk::mesh_data_resource_clear() { _mesh_data_resources.clear(); @@ -951,7 +951,7 @@ int TerraChunk::collider_get_count() const { void TerraChunk::collider_remove(const int index) { ERR_FAIL_INDEX(index, _colliders.size()); - _colliders.remove(index); + _colliders.VREMOVE(index); } void TerraChunk::colliders_clear() { _colliders.clear(); diff --git a/world/terra_environment_data.cpp b/world/terra_environment_data.cpp index 5a37fba..fc2ecfa 100644 --- a/world/terra_environment_data.cpp +++ b/world/terra_environment_data.cpp @@ -61,8 +61,9 @@ void TerraEnvironmentData::set_indirect_energy(const int index, const float valu } void TerraEnvironmentData::setup(WorldEnvironment *world_environment, DirectionalLight *primary_light, DirectionalLight *secondary_light) { - if (has_method("_setup")) - call("_setup", world_environment, primary_light, secondary_light); + if (has_method("_setup")) { + CALL(_setup, world_environment, primary_light, secondary_light); + } } void TerraEnvironmentData::setup_bind(Node *world_environment, Node *primary_light, Node *secondary_light) { setup(Object::cast_to(world_environment), Object::cast_to(primary_light), Object::cast_to(secondary_light)); @@ -84,7 +85,11 @@ TerraEnvironmentData::~TerraEnvironmentData() { } void TerraEnvironmentData::_bind_methods() { +#if VERSION_MAJOR < 4 BIND_VMETHOD(MethodInfo("_setup", PropertyInfo(Variant::OBJECT, "world_environment", PROPERTY_HINT_RESOURCE_TYPE, "WorldEnvironment"), PropertyInfo(Variant::OBJECT, "primary_light", PROPERTY_HINT_RESOURCE_TYPE, "DirectionalLight"), PropertyInfo(Variant::OBJECT, "secondary_light", PROPERTY_HINT_RESOURCE_TYPE, "DirectionalLight"))); +#else + GDVIRTUAL_BIND(_setup, "world_environment", "primary_light", "secondary_light"); +#endif ClassDB::bind_method(D_METHOD("get_environment"), &TerraEnvironmentData::get_environment); ClassDB::bind_method(D_METHOD("set_environment", "value"), &TerraEnvironmentData::set_environment); diff --git a/world/terra_environment_data.h b/world/terra_environment_data.h index 9ce30cc..554ac29 100644 --- a/world/terra_environment_data.h +++ b/world/terra_environment_data.h @@ -29,8 +29,8 @@ SOFTWARE. #include "core/io/resource.h" #include "core/math/color.h" #else -#include "core/resource.h" #include "core/color.h" +#include "core/resource.h" #endif #include "../defines.h" @@ -57,6 +57,10 @@ public: void setup(WorldEnvironment *world_environment, DirectionalLight *primary_light, DirectionalLight *secondary_light); void setup_bind(Node *world_environment, Node *primary_light, Node *secondary_light); +#if VERSION_MAJOR >= 4 + GDVIRTUAL3(_setup, WorldEnvironment *, DirectionalLight *, DirectionalLight *); +#endif + TerraEnvironmentData(); ~TerraEnvironmentData(); diff --git a/world/terra_structure.cpp b/world/terra_structure.cpp index e914132..9e251a8 100644 --- a/world/terra_structure.cpp +++ b/world/terra_structure.cpp @@ -66,8 +66,9 @@ void TerraStructure::set_position(const int x, const int y, const int z) { void TerraStructure::write_to_chunk(Ref chunk) { ERR_FAIL_COND(!chunk.is_valid()); - if (has_method("_write_to_chunk")) - call("_write_to_chunk", chunk); + if (has_method("_write_to_chunk")) { + CALL(_write_to_chunk, chunk); + } } TerraStructure::TerraStructure() { @@ -81,7 +82,11 @@ TerraStructure::~TerraStructure() { } void TerraStructure::_bind_methods() { +#if VERSION_MAJOR < 4 BIND_VMETHOD(MethodInfo("_write_to_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"))); +#else + GDVIRTUAL_BIND(_write_to_chunk, "chunk"); +#endif ClassDB::bind_method(D_METHOD("get_use_aabb"), &TerraStructure::get_use_aabb); ClassDB::bind_method(D_METHOD("set_use_aabb", "value"), &TerraStructure::set_use_aabb); diff --git a/world/terra_structure.h b/world/terra_structure.h index 49599b6..1b95ba5 100644 --- a/world/terra_structure.h +++ b/world/terra_structure.h @@ -29,19 +29,18 @@ SOFTWARE. #include "core/io/resource.h" #include "core/templates/hash_map.h" #else -#include "core/resource.h" #include "core/hash_map.h" +#include "core/resource.h" #endif #include "../defines.h" #include pool_vector_h include_pool_vector - #include "core/math/aabb.h" #include "terra_chunk.h" -class TerraStructure : public Resource { + class TerraStructure : public Resource { GDCLASS(TerraStructure, Resource); public: @@ -64,6 +63,10 @@ public: void write_to_chunk(Ref chunk); +#if VERSION_MAJOR >= 4 + GDVIRTUAL1(_write_to_chunk, Ref); +#endif + TerraStructure(); ~TerraStructure(); diff --git a/world/terra_world.cpp b/world/terra_world.cpp index b9be492..edaefe7 100644 --- a/world/terra_world.cpp +++ b/world/terra_world.cpp @@ -183,7 +183,7 @@ void TerraWorld::world_area_add(const Ref &area) { void TerraWorld::world_area_remove(const int index) { ERR_FAIL_INDEX(index, _world_areas.size()); - _world_areas.remove(index); + _world_areas.VREMOVE(index); } void TerraWorld::world_areas_clear() { _world_areas.clear(); @@ -209,12 +209,12 @@ void TerraWorld::voxel_structure_remove(const Ref &structure) { int index = _voxel_structures.find(structure); if (index != -1) - _voxel_structures.remove(index); + _voxel_structures.VREMOVE(index); } void TerraWorld::voxel_structure_remove_index(const int index) { ERR_FAIL_INDEX(index, _voxel_structures.size()); - _voxel_structures.remove(index); + _voxel_structures.VREMOVE(index); } void TerraWorld::voxel_structures_clear() { _voxel_structures.clear(); @@ -266,8 +266,9 @@ void TerraWorld::chunk_add(Ref chunk, const int x, const int z) { if (is_inside_tree()) chunk->enter_tree(); - if (has_method("_chunk_added")) - call("_chunk_added", chunk); + if (has_method("_chunk_added")) { + CALL(_chunk_added, chunk); + } emit_signal("chunk_added", chunk); } @@ -292,7 +293,7 @@ Ref TerraWorld::chunk_remove(const int x, const int z) { for (int i = 0; i < _chunks_vector.size(); ++i) { if (_chunks_vector.get(i) == chunk) { - _chunks_vector.remove(i); + _chunks_vector.VREMOVE(i); break; } } @@ -309,7 +310,7 @@ Ref TerraWorld::chunk_remove_index(const int index) { ERR_FAIL_INDEX_V(index, _chunks_vector.size(), NULL); Ref chunk = _chunks_vector.get(index); - _chunks_vector.remove(index); + _chunks_vector.VREMOVE(index); _chunks.erase(IntPos(chunk->get_position_x(), chunk->get_position_z())); chunk->exit_tree(); @@ -330,7 +331,7 @@ int TerraWorld::chunk_get_count() const { void TerraWorld::chunks_clear() { for (int i = 0; i < _chunks_vector.size(); ++i) { Ref chunk = _chunks_vector.get(i); - + chunk->exit_tree(); emit_signal("chunk_removed", chunk); @@ -355,7 +356,8 @@ Ref TerraWorld::chunk_get_or_create(int x, int z) { } Ref TerraWorld::chunk_create(const int x, const int z) { - Ref c = call("_create_chunk", x, z, Ref()); + Ref c; + GET_CALLP(Ref, c, _create_chunk, x, z, Ref()); generation_queue_add_to(c); @@ -365,12 +367,17 @@ Ref TerraWorld::chunk_create(const int x, const int z) { void TerraWorld::chunk_setup(Ref chunk) { ERR_FAIL_COND(!chunk.is_valid()); +#if VERSION_MAJOR < 4 call("_create_chunk", chunk->get_position_x(), chunk->get_position_z(), chunk); +#else + Ref c; + GDVIRTUAL_CALL(_create_chunk, chunk->get_position_x(), chunk->get_position_z(), chunk, c); +#endif } Ref TerraWorld::_create_chunk(const int x, const int z, Ref chunk) { if (!chunk.is_valid()) { - chunk.instance(); + chunk.INSTANCE(); } //no meshers here @@ -400,10 +407,11 @@ Ref TerraWorld::_create_chunk(const int x, const int z, Ref chunk) { ERR_FAIL_COND(!chunk.is_valid()); - if (has_method("_prepare_chunk_for_generation")) - call("_prepare_chunk_for_generation", chunk); + if (has_method("_prepare_chunk_for_generation")) { + CALL(_prepare_chunk_for_generation, chunk); + } - call("_generate_chunk", chunk); + CALL(_generate_chunk, chunk); chunk->build(); } @@ -511,7 +519,7 @@ Ref TerraWorld::generation_queue_get_index(int index) { void TerraWorld::generation_queue_remove_index(int index) { ERR_FAIL_INDEX(index, _generation_queue.size()); - _generation_queue.remove(index); + _generation_queue.VREMOVE(index); } int TerraWorld::generation_queue_get_size() const { return _generation_queue.size(); @@ -530,7 +538,7 @@ Ref TerraWorld::generation_get_index(const int index) { void TerraWorld::generation_remove_index(const int index) { ERR_FAIL_INDEX(index, _generating.size()); - _generating.remove(index); + _generating.VREMOVE(index); } int TerraWorld::generation_get_size() const { return _generating.size(); @@ -583,7 +591,7 @@ void TerraWorld::prop_add(Transform transform, const Ref &prop, const if (!sc.is_valid()) continue; - Node *n = sc->instance(); + Node *n = sc->INSTANCE(); add_child(n); n->set_owner(this); @@ -600,7 +608,7 @@ void TerraWorld::prop_add(Transform transform, const Ref &prop, const if (light_data.is_valid()) { Ref light; - light.instance(); + light.INSTANCE(); light->set_world_position(wp.x / get_voxel_scale(), wp.y / get_voxel_scale(), wp.z / get_voxel_scale()); light->set_color(light_data->get_light_color()); @@ -805,11 +813,11 @@ Ref TerraWorld::get_or_create_chunk_at_world_position(const Vector3 } void TerraWorld::set_voxel_with_tool(const bool mode_add, const Vector3 hit_position, const Vector3 hit_normal, const int selected_voxel, const int isolevel) { - call("_set_voxel_with_tool", mode_add, hit_position, hit_normal, selected_voxel, isolevel); + CALL(_set_voxel_with_tool, mode_add, hit_position, hit_normal, selected_voxel, isolevel); } int TerraWorld::get_channel_index_info(const TerraWorld::ChannelTypeInfo channel_type) { - return call("_get_channel_index_info", channel_type); + RETURN_CALLP(int, _get_channel_index_info, channel_type); } TerraWorld::TerraWorld() { @@ -919,7 +927,7 @@ void TerraWorld::_notification(int p_what) { #endif _is_priority_generation = false; - call("_generation_finished"); + CALL(_generation_finished); emit_signal("generation_finished"); @@ -930,7 +938,7 @@ void TerraWorld::_notification(int p_what) { Ref chunk = _generating.get(i); if (!chunk.is_valid() || !chunk->get_is_generating()) { - _generating.remove(i); + _generating.VREMOVE(i); --i; continue; } @@ -944,7 +952,7 @@ void TerraWorld::_notification(int p_what) { while (_generating.size() < _max_concurrent_generations && _generation_queue.size() != 0) { Ref chunk = _generation_queue.get(0); - _generation_queue.remove(0); + _generation_queue.VREMOVE(0); ERR_FAIL_COND(!chunk.is_valid()); @@ -1079,7 +1087,11 @@ void TerraWorld::_bind_methods() { ClassDB::bind_method(D_METHOD("voxel_structures_set"), &TerraWorld::voxel_structures_set); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "voxel_structures", PROPERTY_HINT_NONE, "17/17:TerraStructure", PROPERTY_USAGE_DEFAULT, "TerraStructure"), "voxel_structures_set", "voxel_structures_get"); +#if VERSION_MAJOR < 4 BIND_VMETHOD(MethodInfo("_chunk_added", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"))); +#else + GDVIRTUAL_BIND(_chunk_added, "chunk"); +#endif ClassDB::bind_method(D_METHOD("chunk_add", "chunk", "x", "z"), &TerraWorld::chunk_add); ClassDB::bind_method(D_METHOD("chunk_has", "x", "z"), &TerraWorld::chunk_has); @@ -1107,11 +1119,19 @@ void TerraWorld::_bind_methods() { ClassDB::bind_method(D_METHOD("generation_get_size"), &TerraWorld::generation_get_size); ADD_SIGNAL(MethodInfo("generation_finished")); + +#if VERSION_MAJOR < 4 BIND_VMETHOD(MethodInfo("_generation_finished")); - BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "ret", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"), "_create_chunk", PropertyInfo(Variant::INT, "x"), PropertyInfo(Variant::INT, "y"), PropertyInfo(Variant::INT, "z"), PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"))); + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "ret", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"), "_create_chunk", PropertyInfo(Variant::INT, "x"), PropertyInfo(Variant::INT, "z"), PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"))); BIND_VMETHOD(MethodInfo("_prepare_chunk_for_generation", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"))); BIND_VMETHOD(MethodInfo("_generate_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"))); +#else + GDVIRTUAL_BIND(_generation_finished); + GDVIRTUAL_BIND(_create_chunk, "chunk", "x", "z", "chunk", "ret"); + GDVIRTUAL_BIND(_prepare_chunk_for_generation, "chunk"); + GDVIRTUAL_BIND(_generate_chunk, "chunk"); +#endif ClassDB::bind_method(D_METHOD("chunk_get_or_create", "x", "z"), &TerraWorld::chunk_get_or_create); ClassDB::bind_method(D_METHOD("chunk_create", "x", "z"), &TerraWorld::chunk_create); @@ -1143,17 +1163,25 @@ void TerraWorld::_bind_methods() { ClassDB::bind_method(D_METHOD("get_chunk_at_world_position", "world_position"), &TerraWorld::get_chunk_at_world_position); ClassDB::bind_method(D_METHOD("get_or_create_chunk_at_world_position", "world_position"), &TerraWorld::get_or_create_chunk_at_world_position); - BIND_VMETHOD(MethodInfo("_get_channel_index_info", PropertyInfo(Variant::INT, "channel_type", PROPERTY_HINT_ENUM, BINDING_STRING_CHANNEL_TYPE_INFO))); +#if VERSION_MAJOR < 4 + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"), "_get_channel_index_info", PropertyInfo(Variant::INT, "channel_type", PROPERTY_HINT_ENUM, BINDING_STRING_CHANNEL_TYPE_INFO))); +#else + GDVIRTUAL_BIND(_get_channel_index_info, "channel_type", "ret"); +#endif ClassDB::bind_method(D_METHOD("get_channel_index_info", "channel_type"), &TerraWorld::get_channel_index_info); ClassDB::bind_method(D_METHOD("_get_channel_index_info", "channel_type"), &TerraWorld::_get_channel_index_info); +#if VERSION_MAJOR < 4 BIND_VMETHOD(MethodInfo("_set_voxel_with_tool", PropertyInfo(Variant::BOOL, "mode_add"), PropertyInfo(Variant::VECTOR3, "hit_position"), PropertyInfo(Variant::VECTOR3, "hit_normal"), PropertyInfo(Variant::INT, "selected_voxel"), PropertyInfo(Variant::INT, "isolevel"))); +#else + GDVIRTUAL_BIND(_set_voxel_with_tool, "mode_add", "hit_position", "hit_normal", "selected_voxel", "isolevel"); +#endif ClassDB::bind_method(D_METHOD("set_voxel_with_tool", "mode_add", "hit_position", "hit_normal", "selected_voxel", "isolevel"), &TerraWorld::set_voxel_with_tool); ClassDB::bind_method(D_METHOD("_set_voxel_with_tool", "mode_add", "hit_position", "hit_normal", "selected_voxel", "isolevel"), &TerraWorld::_set_voxel_with_tool); diff --git a/world/terra_world.h b/world/terra_world.h index 0a42540..7945795 100644 --- a/world/terra_world.h +++ b/world/terra_world.h @@ -192,6 +192,20 @@ public: int get_channel_index_info(const ChannelTypeInfo channel_type); +#if VERSION_MAJOR >= 4 + GDVIRTUAL1(_chunk_added, Ref); + + GDVIRTUAL0(_generation_finished); + + GDVIRTUAL3R(Ref, _create_chunk, int, int, Ref); + GDVIRTUAL1(_prepare_chunk_for_generation, Ref); + GDVIRTUAL1(_generate_chunk, Ref); + + GDVIRTUAL1R(int, _get_channel_index_info, int); + + GDVIRTUAL5(_set_voxel_with_tool, bool, Vector3, Vector3, int, int); +#endif + TerraWorld(); ~TerraWorld(); diff --git a/world/terra_world_editor.cpp b/world/terra_world_editor.cpp index 0be539e..c4d48a7 100644 --- a/world/terra_world_editor.cpp +++ b/world/terra_world_editor.cpp @@ -42,16 +42,17 @@ SOFTWARE. #include spatial_editor_plugin_h #include camera_h +#if VERSION_MAJOR < 4 bool TerraWorldEditor::forward_spatial_input_event(Camera *p_camera, const Ref &p_event) { if (!_world || !_world->get_editable()) { return false; } - Ref mb = p_event; + Ref mb = p_event; if (mb.is_valid()) { if (mb->is_pressed()) { - Ref lib = _world->get_library(); + Ref lib = _world->get_library(); if (!lib.is_valid()) return false; @@ -68,6 +69,39 @@ bool TerraWorldEditor::forward_spatial_input_event(Camera *p_camera, const Ref &p_event) { + if (!_world || !_world->get_editable()) { + return EditorPlugin::AFTER_GUI_INPUT_PASS; + } + + Ref mb = p_event; + + if (mb.is_valid()) { + if (mb->is_pressed()) { + Ref lib = _world->get_library(); + + if (!lib.is_valid()) + return EditorPlugin::AFTER_GUI_INPUT_PASS; + + if (mb->get_button_index() == MouseButton::LEFT) { + if (do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true)) { + return EditorPlugin::AFTER_GUI_INPUT_STOP; + } else { + return EditorPlugin::AFTER_GUI_INPUT_PASS; + } + } else { + return EditorPlugin::AFTER_GUI_INPUT_PASS; + } + + //return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true); + } + } + + return EditorPlugin::AFTER_GUI_INPUT_PASS; +} + +#endif bool TerraWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click) { if (!spatial_editor || !_world || !_world->is_inside_world()) diff --git a/world/terra_world_editor.h b/world/terra_world_editor.h index f97703a..090f66c 100644 --- a/world/terra_world_editor.h +++ b/world/terra_world_editor.h @@ -28,7 +28,12 @@ SOFTWARE. #include "../defines.h" -class TerraWorld; +#if VERSION_MAJOR > 3 +#include "core/math/transform_3d.h" +typedef class Transform3D Transform; +#endif + +class VoxelWorld; class SpatialEditorPlugin; class TerraWorldEditor : public PanelContainer { @@ -41,7 +46,11 @@ public: }; public: +#if VERSION_MAJOR < 4 bool forward_spatial_input_event(Camera *p_camera, const Ref &p_event); +#else + EditorPlugin::AfterGUIInput forward_spatial_input_event(Camera *p_camera, const Ref &p_event); +#endif void edit(TerraWorld *p_world); bool do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click); @@ -91,8 +100,13 @@ protected: void _notification(int p_what); public: - virtual bool forward_spatial_gui_input(Camera *p_camera, const Ref &p_event) { return voxel_world_editor->forward_spatial_input_event(p_camera, p_event); } +#if VERSION_MAJOR < 4 + bool forward_spatial_input_event(Camera *p_camera, const Ref &p_event) { return voxel_world_editor->forward_spatial_input_event(p_camera, p_event); } virtual bool forward_spatial_gui_input(int p_index, Camera *p_camera, const Ref &p_event) { return voxel_world_editor->forward_spatial_input_event(p_camera, p_event); } +#else + EditorPlugin::AfterGUIInput forward_spatial_input_event(Camera *p_camera, const Ref &p_event) { return voxel_world_editor->forward_spatial_input_event(p_camera, p_event); } + virtual EditorPlugin::AfterGUIInput forward_spatial_gui_input(int p_index, Camera *p_camera, const Ref &p_event) { return voxel_world_editor->forward_spatial_input_event(p_camera, p_event); } +#endif virtual String get_name() const { return "TerraWorldEditor"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_object);