Work on fixing compile for 4.0.

This commit is contained in:
Relintai 2022-02-08 11:52:29 +01:00
parent 2aa31ea22e
commit f256229139
20 changed files with 504 additions and 81 deletions

View File

@ -26,7 +26,10 @@ SOFTWARE.
#include "core/version.h" #include "core/version.h"
#if VERSION_MAJOR > 3 #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" #include "core/string/ustring.h"
#else #else
#include "core/reference.h" #include "core/reference.h"

View File

@ -26,7 +26,10 @@ SOFTWARE.
#include "core/version.h" #include "core/version.h"
#if VERSION_MAJOR > 3 #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/templates/vector.h"
#include "core/math/color.h" #include "core/math/color.h"
#else #else
@ -35,6 +38,7 @@ SOFTWARE.
#include "core/color.h" #include "core/color.h"
#endif #endif
class TerraLight : public Reference { class TerraLight : public Reference {
GDCLASS(TerraLight, Reference); GDCLASS(TerraLight, Reference);

View File

@ -14,7 +14,8 @@
#define spatial_editor_plugin_h "editor/plugins/node_3d_editor_plugin.h" #define spatial_editor_plugin_h "editor/plugins/node_3d_editor_plugin.h"
#define camera_h "scene/3d/camera_3d.h" #define camera_h "scene/3d/camera_3d.h"
#define spatial_h "scene/3d/node_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 light_h "scene/3d/light_3d.h"
#define visual_server_h "servers/rendering_server.h" #define visual_server_h "servers/rendering_server.h"
#define mesh_instance_h "scene/3d/mesh_instance_3d.h" #define mesh_instance_h "scene/3d/mesh_instance_3d.h"
@ -63,6 +64,7 @@
#define Camera Camera3D #define Camera Camera3D
#define ToolButton Button #define ToolButton Button
#define Shape Shape3D #define Shape Shape3D
#define Reference RefCounted
typedef class World3D World; 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 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 DISCONNECT(sig, obj, target_method_class, method) disconnect(sig, callable_mp(obj, &target_method_class::method))
#define GET_WORLD get_world_3d #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 #else
#define INSTANCE_VALIDATE(var) ObjectDB::instance_validate(var) #define INSTANCE_VALIDATE(var) ObjectDB::instance_validate(var)
#define CONNECT(sig, obj, target_method_class, method) connect(sig, obj, #method) #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 DISCONNECT(sig, obj, target_method_class, method) disconnect(sig, obj, #method)
#define GET_WORLD get_world #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
#endif #endif

View File

@ -22,6 +22,8 @@ SOFTWARE.
#include "terra_material_cache.h" #include "terra_material_cache.h"
#include "../defines.h"
#ifdef PROPS_PRESENT #ifdef PROPS_PRESENT
#include "../../props/props/prop_data.h" #include "../../props/props/prop_data.h"
#include "../../props/props/prop_data_prop.h" #include "../../props/props/prop_data_prop.h"
@ -85,7 +87,7 @@ void TerraMaterialCache::material_set(const int index, const Ref<Material> &valu
} }
void TerraMaterialCache::material_remove(const int index) { void TerraMaterialCache::material_remove(const int index) {
_materials.remove(index); _materials.VREMOVE(index);
} }
int TerraMaterialCache::material_get_num() const { int TerraMaterialCache::material_get_num() const {
@ -146,7 +148,7 @@ void TerraMaterialCache::surface_set(int index, Ref<TerraSurface> value) {
_surfaces.set(index, value); _surfaces.set(index, value);
} }
void TerraMaterialCache::surface_remove(const int index) { void TerraMaterialCache::surface_remove(const int index) {
_surfaces.remove(index); _surfaces.VREMOVE(index);
} }
int TerraMaterialCache::surface_get_num() const { int TerraMaterialCache::surface_get_num() const {
return _surfaces.size(); return _surfaces.size();
@ -161,7 +163,7 @@ void TerraMaterialCache::additional_texture_add(const Ref<Texture> &texture) {
void TerraMaterialCache::additional_texture_remove(const Ref<Texture> &texture) { void TerraMaterialCache::additional_texture_remove(const Ref<Texture> &texture) {
for (int i = 0; i < _additional_textures.size(); ++i) { for (int i = 0; i < _additional_textures.size(); ++i) {
if (_additional_textures[i] == texture) { if (_additional_textures[i] == texture) {
_additional_textures.remove(i); _additional_textures.VREMOVE(i);
return; return;
} }
} }
@ -169,7 +171,7 @@ void TerraMaterialCache::additional_texture_remove(const Ref<Texture> &texture)
void TerraMaterialCache::additional_texture_remove_index(const int index) { void TerraMaterialCache::additional_texture_remove_index(const int index) {
ERR_FAIL_INDEX(index, _additional_textures.size()); ERR_FAIL_INDEX(index, _additional_textures.size());
_additional_textures.remove(index); _additional_textures.VREMOVE(index);
} }
void TerraMaterialCache::additional_textures_clear() { void TerraMaterialCache::additional_textures_clear() {
_additional_textures.clear(); _additional_textures.clear();
@ -254,8 +256,13 @@ void TerraMaterialCache::refresh_rects() {
} }
void TerraMaterialCache::setup_material_albedo(Ref<Texture> texture) { void TerraMaterialCache::setup_material_albedo(Ref<Texture> texture) {
if (has_method("_setup_material_albedo")) #if VERSION_MAJOR < 4
if (has_method("_setup_material_albedo")) {
call("_setup_material_albedo", texture); call("_setup_material_albedo", texture);
}
#else
GDVIRTUAL_CALL(_setup_material_albedo, texture);
#endif
} }
TerraMaterialCache::TerraMaterialCache() { 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("inc_ref_count"), &TerraMaterialCache::inc_ref_count);
ClassDB::bind_method(D_METHOD("dec_ref_count"), &TerraMaterialCache::dec_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"))); 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_get", "index"), &TerraMaterialCache::material_get);
ClassDB::bind_method(D_METHOD("material_lod_get", "index"), &TerraMaterialCache::material_lod_get); ClassDB::bind_method(D_METHOD("material_lod_get", "index"), &TerraMaterialCache::material_lod_get);

View File

@ -94,6 +94,10 @@ public:
void setup_material_albedo(Ref<Texture> texture); void setup_material_albedo(Ref<Texture> texture);
#if VERSION_MAJOR >= 4
GDVIRTUAL1(_setup_material_albedo, Ref<Texture>);
#endif
TerraMaterialCache(); TerraMaterialCache();
~TerraMaterialCache(); ~TerraMaterialCache();

View File

@ -34,6 +34,117 @@ SOFTWARE.
#include "../defines.h" #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<m_type1>::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<m_type1>::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<m_ret>::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<m_type1>::EncodeT argval1 = arg1; \
const GDNativeTypePtr argptrs[1] = { &argval1 }; \
\
PtrToArg<m_ret>::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<m_ret>::get_class_info(); \
method_info.arguments.push_back(GetTypeInfo<m_type1>::get_class_info()); \
\
return method_info; \
}
#endif
bool TerramanLibrary::get_initialized() const { bool TerramanLibrary::get_initialized() const {
return _initialized; return _initialized;
} }
@ -42,7 +153,7 @@ void TerramanLibrary::set_initialized(const bool value) {
} }
bool TerramanLibrary::supports_caching() { bool TerramanLibrary::supports_caching() {
return call("_supports_caching"); RETURN_CALLD(bool, false, _supports_caching);
} }
bool TerramanLibrary::_supports_caching() { bool TerramanLibrary::_supports_caching() {
return false; return false;
@ -70,14 +181,14 @@ Ref<Material> TerramanLibrary::material_lod_get(const int index) {
} }
void TerramanLibrary::material_cache_get_key(Ref<TerraChunk> chunk) { void TerramanLibrary::material_cache_get_key(Ref<TerraChunk> chunk) {
call("_material_cache_get_key", chunk); CALL(_material_cache_get_key, chunk);
} }
void TerramanLibrary::_material_cache_get_key(Ref<TerraChunk> chunk) { void TerramanLibrary::_material_cache_get_key(Ref<TerraChunk> chunk) {
} }
Ref<TerraMaterialCache> TerramanLibrary::material_cache_get(const int key) { Ref<TerraMaterialCache> TerramanLibrary::material_cache_get(const int key) {
return call("_material_cache_get", key); RETURN_CALLP(Ref<TerraMaterialCache>, _material_cache_get, key);
} }
Ref<TerraMaterialCache> TerramanLibrary::_material_cache_get(const int key) { Ref<TerraMaterialCache> TerramanLibrary::_material_cache_get(const int key) {
@ -85,7 +196,7 @@ Ref<TerraMaterialCache> TerramanLibrary::_material_cache_get(const int key) {
} }
void TerramanLibrary::material_cache_unref(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) { void TerramanLibrary::_material_cache_unref(const int key) {
} }
@ -103,7 +214,7 @@ void TerramanLibrary::material_set(const int index, const Ref<Material> &value)
} }
void TerramanLibrary::material_remove(const int index) { void TerramanLibrary::material_remove(const int index) {
_materials.remove(index); _materials.VREMOVE(index);
} }
int TerramanLibrary::material_get_num() const { int TerramanLibrary::material_get_num() const {
@ -150,14 +261,14 @@ Ref<Material> TerramanLibrary::liquid_material_lod_get(const int index) {
} }
void TerramanLibrary::liquid_material_cache_get_key(Ref<TerraChunk> chunk) { void TerramanLibrary::liquid_material_cache_get_key(Ref<TerraChunk> chunk) {
call("_liquid_material_cache_get_key", chunk); CALL(_liquid_material_cache_get_key, chunk);
} }
void TerramanLibrary::_liquid_material_cache_get_key(Ref<TerraChunk> chunk) { void TerramanLibrary::_liquid_material_cache_get_key(Ref<TerraChunk> chunk) {
} }
Ref<TerraMaterialCache> TerramanLibrary::liquid_material_cache_get(const int key) { Ref<TerraMaterialCache> TerramanLibrary::liquid_material_cache_get(const int key) {
return call("_liquid_material_cache_get", key); RETURN_CALLP(Ref<TerraMaterialCache>, _liquid_material_cache_get, key);
} }
Ref<TerraMaterialCache> TerramanLibrary::_liquid_material_cache_get(const int key) { Ref<TerraMaterialCache> TerramanLibrary::_liquid_material_cache_get(const int key) {
@ -165,7 +276,7 @@ Ref<TerraMaterialCache> TerramanLibrary::_liquid_material_cache_get(const int ke
} }
void TerramanLibrary::liquid_material_cache_unref(const int key) { 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) { void TerramanLibrary::_liquid_material_cache_unref(const int key) {
} }
@ -183,7 +294,7 @@ void TerramanLibrary::liquid_material_set(const int index, const Ref<Material> &
} }
void TerramanLibrary::liquid_material_remove(const int index) { void TerramanLibrary::liquid_material_remove(const int index) {
_liquid_materials.remove(index); _liquid_materials.VREMOVE(index);
} }
int TerramanLibrary::liquid_material_get_num() const { int TerramanLibrary::liquid_material_get_num() const {
@ -230,14 +341,14 @@ Ref<Material> TerramanLibrary::prop_material_lod_get(const int index) {
} }
void TerramanLibrary::prop_material_cache_get_key(Ref<TerraChunk> chunk) { void TerramanLibrary::prop_material_cache_get_key(Ref<TerraChunk> chunk) {
call("_prop_material_cache_get_key", chunk); CALL(_prop_material_cache_get_key, chunk);
} }
void TerramanLibrary::_prop_material_cache_get_key(Ref<TerraChunk> chunk) { void TerramanLibrary::_prop_material_cache_get_key(Ref<TerraChunk> chunk) {
} }
Ref<TerraMaterialCache> TerramanLibrary::prop_material_cache_get(const int key) { Ref<TerraMaterialCache> TerramanLibrary::prop_material_cache_get(const int key) {
return call("_prop_material_cache_get", key); RETURN_CALLP(Ref<TerraMaterialCache>, _prop_material_cache_get, key);
} }
Ref<TerraMaterialCache> TerramanLibrary::_prop_material_cache_get(const int key) { Ref<TerraMaterialCache> TerramanLibrary::_prop_material_cache_get(const int key) {
@ -245,7 +356,7 @@ Ref<TerraMaterialCache> TerramanLibrary::_prop_material_cache_get(const int key)
} }
void TerramanLibrary::prop_material_cache_unref(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) { void TerramanLibrary::_prop_material_cache_unref(const int key) {
} }
@ -263,7 +374,7 @@ void TerramanLibrary::prop_material_set(const int index, const Ref<Material> &va
} }
void TerramanLibrary::prop_material_remove(const int index) { void TerramanLibrary::prop_material_remove(const int index) {
_prop_materials.remove(index); _prop_materials.VREMOVE(index);
} }
int TerramanLibrary::prop_material_get_num() const { 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> texture) { void TerramanLibrary::setup_material_albedo(int material_index, Ref<Texture> texture) {
if (has_method("_setup_material_albedo")) if (has_method("_setup_material_albedo")) {
call("_setup_material_albedo", material_index, texture); CALL(_setup_material_albedo, material_index, texture);
}
} }
TerramanLibrary::TerramanLibrary() { TerramanLibrary::TerramanLibrary() {
@ -357,20 +469,49 @@ TerramanLibrary::~TerramanLibrary() {
_prop_materials.clear(); _prop_materials.clear();
} }
#if VERSION_MAJOR >= 4
TMCGDVIRTUAL1(TerramanLibrary, _material_cache_get_key, Ref<TerraChunk>);
TMCGDVIRTUAL1R(TerramanLibrary, Ref<TerraMaterialCache>, _material_cache_get, int);
TMCGDVIRTUAL1(TerramanLibrary, _material_cache_unref, int);
TMCGDVIRTUAL1(TerramanLibrary, _liquid_material_cache_get_key, Ref<TerraChunk>);
TMCGDVIRTUAL1R(TerramanLibrary, Ref<TerraMaterialCache>, _liquid_material_cache_get, int);
TMCGDVIRTUAL1(TerramanLibrary, _liquid_material_cache_unref, int);
TMCGDVIRTUAL1(TerramanLibrary, _prop_material_cache_get_key, Ref<TerraChunk>);
TMCGDVIRTUAL1R(TerramanLibrary, Ref<TerraMaterialCache>, _prop_material_cache_get, int);
TMCGDVIRTUAL1(TerramanLibrary, _prop_material_cache_unref, int);
#endif
void TerramanLibrary::_bind_methods() { void TerramanLibrary::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_initialized"), &TerramanLibrary::get_initialized); ClassDB::bind_method(D_METHOD("get_initialized"), &TerramanLibrary::get_initialized);
ClassDB::bind_method(D_METHOD("set_initialized", "value"), &TerramanLibrary::set_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"); 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")); 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);
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"))); 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("_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(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"))); 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_get", "index"), &TerramanLibrary::material_get);
ClassDB::bind_method(D_METHOD("material_lod_get", "index"), &TerramanLibrary::material_lod_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); 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"); 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("_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(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"))); 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_get", "index"), &TerramanLibrary::liquid_material_get);
ClassDB::bind_method(D_METHOD("liquid_material_lod_get", "index"), &TerramanLibrary::liquid_material_lod_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); 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"); 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("_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(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"))); 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_get", "index"), &TerramanLibrary::prop_material_get);
ClassDB::bind_method(D_METHOD("prop_material_lod_get", "index"), &TerramanLibrary::prop_material_lod_get); ClassDB::bind_method(D_METHOD("prop_material_lod_get", "index"), &TerramanLibrary::prop_material_lod_get);

View File

@ -27,6 +27,25 @@ SOFTWARE.
#if VERSION_MAJOR > 3 #if VERSION_MAJOR > 3
#include "core/io/resource.h" #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 #else
#include "core/resource.h" #include "core/resource.h"
#endif #endif
@ -156,6 +175,24 @@ public:
void setup_material_albedo(int material_index, Ref<Texture> texture); void setup_material_albedo(int material_index, Ref<Texture> texture);
#if VERSION_MAJOR >= 4
GDVIRTUAL0R(bool, _supports_caching);
GDVIRTUAL2(_setup_material_albedo, int, Ref<Texture>);
TMHGDVIRTUAL1(_material_cache_get_key, Ref<TerraChunk>);
TMHGDVIRTUAL1R(Ref<TerraMaterialCache>, _material_cache_get, int);
TMHGDVIRTUAL1(_material_cache_unref, int);
TMHGDVIRTUAL1(_liquid_material_cache_get_key, Ref<TerraChunk>);
TMHGDVIRTUAL1R(Ref<TerraMaterialCache>, _liquid_material_cache_get, int);
TMHGDVIRTUAL1(_liquid_material_cache_unref, int);
TMHGDVIRTUAL1(_prop_material_cache_get_key, Ref<TerraChunk>);
TMHGDVIRTUAL1R(Ref<TerraMaterialCache>, _prop_material_cache_get, int);
TMHGDVIRTUAL1(_prop_material_cache_unref, int);
#endif
TerramanLibrary(); TerramanLibrary();
~TerramanLibrary(); ~TerramanLibrary();

View File

@ -77,7 +77,7 @@ void TerramanLibrarySimple::voxel_surface_set(const int index, Ref<TerraSurface>
} }
void TerramanLibrarySimple::voxel_surface_remove(const int index) { void TerramanLibrarySimple::voxel_surface_remove(const int index) {
_voxel_surfaces.remove(index); _voxel_surfaces.VREMOVE(index);
} }
int TerramanLibrarySimple::voxel_surface_get_num() const { int TerramanLibrarySimple::voxel_surface_get_num() const {

View File

@ -374,7 +374,7 @@ void TerraMesher::remove_doubles() {
for (int j = 0; j < indices.size(); ++j) { for (int j = 0; j < indices.size(); ++j) {
int index = indices[j]; int index = indices[j];
_vertices.remove(index); _vertices.VREMOVE(index);
//make all indices that were bigger than the one we replaced one lower //make all indices that were bigger than the one we replaced one lower
for (int k = 0; k < _indices.size(); ++k) { 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) { for (int j = 0; j < indices.size(); ++j) {
int index = indices[j]; int index = indices[j];
hashes.remove(index); hashes.VREMOVE(index);
_vertices.remove(index); _vertices.VREMOVE(index);
//make all indices that were bigger than the one we replaced one lower //make all indices that were bigger than the one we replaced one lower
for (int k = 0; k < _indices.size(); ++k) { for (int k = 0; k < _indices.size(); ++k) {
@ -470,7 +470,7 @@ void TerraMesher::add_chunk(Ref<TerraChunk> chunk) {
ERR_FAIL_COND(!has_method("_add_chunk")); ERR_FAIL_COND(!has_method("_add_chunk"));
ERR_FAIL_COND(!chunk.is_valid()); ERR_FAIL_COND(!chunk.is_valid());
call("_add_chunk", chunk); CALL(_add_chunk, chunk);
} }
#ifdef MESH_DATA_RESOURCE_PRESENT #ifdef MESH_DATA_RESOURCE_PRESENT
@ -569,7 +569,7 @@ void TerraMesher::add_mesh_data_resource_transform_colored(Ref<MeshDataResource>
#endif #endif
void TerraMesher::add_mesher(const Ref<TerraMesher> &mesher) { void TerraMesher::add_mesher(const Ref<TerraMesher> &mesher) {
call("_add_mesher", mesher); CALL(_add_mesher, mesher);
} }
void TerraMesher::_add_mesher(const Ref<TerraMesher> &mesher) { void TerraMesher::_add_mesher(const Ref<TerraMesher> &mesher) {
int orig_size = _vertices.size(); int orig_size = _vertices.size();
@ -592,15 +592,17 @@ void TerraMesher::_add_mesher(const Ref<TerraMesher> &mesher) {
void TerraMesher::bake_colors(Ref<TerraChunk> chunk) { void TerraMesher::bake_colors(Ref<TerraChunk> chunk) {
ERR_FAIL_COND(!chunk.is_valid()); ERR_FAIL_COND(!chunk.is_valid());
if (has_method("_bake_colors")) if (has_method("_bake_colors")) {
call("_bake_colors", chunk); CALL(_bake_colors, chunk);
}
} }
void TerraMesher::bake_liquid_colors(Ref<TerraChunk> chunk) { void TerraMesher::bake_liquid_colors(Ref<TerraChunk> chunk) {
ERR_FAIL_COND(!chunk.is_valid()); ERR_FAIL_COND(!chunk.is_valid());
if (has_method("_bake_liquid_colors")) if (has_method("_bake_liquid_colors")) {
call("_bake_liquid_colors", chunk); CALL(_bake_liquid_colors, chunk);
}
} }
PoolVector<Vector3> TerraMesher::build_collider() const { PoolVector<Vector3> TerraMesher::build_collider() const {
@ -768,7 +770,7 @@ Vector3 TerraMesher::get_vertex(const int idx) const {
} }
void TerraMesher::remove_vertex(const int idx) { void TerraMesher::remove_vertex(const int idx) {
_vertices.remove(idx); _vertices.VREMOVE(idx);
} }
PoolVector<Vector3> TerraMesher::get_normals() const { PoolVector<Vector3> TerraMesher::get_normals() const {
@ -916,7 +918,7 @@ int TerraMesher::get_index(const int idx) const {
} }
void TerraMesher::remove_index(const int idx) { void TerraMesher::remove_index(const int idx) {
_indices.remove(idx); _indices.VREMOVE(idx);
} }
TerraMesher::TerraMesher(const Ref<TerramanLibrary> &library) { TerraMesher::TerraMesher(const Ref<TerramanLibrary> &library) {
@ -954,9 +956,15 @@ TerraMesher::~TerraMesher() {
} }
void TerraMesher::_bind_methods() { 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("_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_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"))); 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("get_channel_index_type"), &TerraMesher::get_channel_index_type);
ClassDB::bind_method(D_METHOD("set_channel_index_type", "value"), &TerraMesher::set_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))); 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 #endif
#if VERSION_MAJOR < 4
BIND_VMETHOD(MethodInfo("_add_mesher", PropertyInfo(Variant::OBJECT, "mesher", PROPERTY_HINT_RESOURCE_TYPE, "TerraMesher"))); 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);
ClassDB::bind_method(D_METHOD("_add_mesher", "mesher"), &TerraMesher::_add_mesher); ClassDB::bind_method(D_METHOD("_add_mesher", "mesher"), &TerraMesher::_add_mesher);

View File

@ -26,13 +26,16 @@ SOFTWARE.
#include "core/version.h" #include "core/version.h"
#if VERSION_MAJOR > 3 #if VERSION_MAJOR > 3
#include "core/math/color.h" #include "core/object/ref_counted.h"
#include "core/object/reference.h" #ifndef Reference
#define Reference RefCounted
#endif
#include "core/templates/vector.h" #include "core/templates/vector.h"
#include "core/math/color.h"
#else #else
#include "core/color.h"
#include "core/reference.h" #include "core/reference.h"
#include "core/vector.h" #include "core/vector.h"
#include "core/color.h"
#endif #endif
#include "../defines.h" #include "../defines.h"
@ -191,6 +194,13 @@ public:
void remove_index(const int idx); void remove_index(const int idx);
void add_indices(const int index); void add_indices(const int index);
#if VERSION_MAJOR >= 4
GDVIRTUAL1(_add_chunk, Ref<TerraChunk>);
GDVIRTUAL1(_bake_colors, Ref<TerraChunk>);
GDVIRTUAL1(_bake_liquid_colors, Ref<TerraChunk>);
GDVIRTUAL1(_add_mesher, Ref<TerraChunk>);
#endif
TerraMesher(const Ref<TerramanLibrary> &library); TerraMesher(const Ref<TerramanLibrary> &library);
TerraMesher(); TerraMesher();
~TerraMesher(); ~TerraMesher();

View File

@ -26,7 +26,10 @@ SOFTWARE.
#include "core/version.h" #include "core/version.h"
#if VERSION_MAJOR > 3 #if VERSION_MAJOR > 3
#include "core/io/reference.h" #include "core/object/ref_counted.h"
#ifndef Reference
#define Reference RefCounted
#endif
#else #else
#include "core/reference.h" #include "core/reference.h"
#endif #endif

View File

@ -255,7 +255,7 @@ void TerraChunk::job_set(int index, const Ref<TerraJob> &job) {
void TerraChunk::job_remove(const int index) { void TerraChunk::job_remove(const int index) {
ERR_FAIL_INDEX(index, _jobs.size()); ERR_FAIL_INDEX(index, _jobs.size());
_jobs.remove(index); _jobs.VREMOVE(index);
} }
void TerraChunk::job_add(const Ref<TerraJob> &job) { void TerraChunk::job_add(const Ref<TerraJob> &job) {
_jobs.push_back(job); _jobs.push_back(job);
@ -609,12 +609,12 @@ void TerraChunk::voxel_structure_remove(const Ref<TerraStructure> &structure) {
int index = _voxel_structures.find(structure); int index = _voxel_structures.find(structure);
if (index != -1) if (index != -1)
_voxel_structures.remove(index); _voxel_structures.VREMOVE(index);
} }
void TerraChunk::voxel_structure_remove_index(const int index) { void TerraChunk::voxel_structure_remove_index(const int index) {
ERR_FAIL_INDEX(index, _voxel_structures.size()); ERR_FAIL_INDEX(index, _voxel_structures.size());
_voxel_structures.remove(index); _voxel_structures.VREMOVE(index);
} }
void TerraChunk::voxel_structure_clear() { void TerraChunk::voxel_structure_clear() {
_voxel_structures.clear(); _voxel_structures.clear();
@ -718,7 +718,7 @@ int TerraChunk::prop_get_count() const {
void TerraChunk::prop_remove(const int index) { void TerraChunk::prop_remove(const int index) {
ERR_FAIL_INDEX(index, _props.size()); ERR_FAIL_INDEX(index, _props.size());
_props.remove(index); _props.VREMOVE(index);
} }
void TerraChunk::props_clear() { void TerraChunk::props_clear() {
_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) { void TerraChunk::mesh_data_resource_remove(const int index) {
ERR_FAIL_INDEX(index, _mesh_data_resources.size()); ERR_FAIL_INDEX(index, _mesh_data_resources.size());
_mesh_data_resources.remove(index); _mesh_data_resources.VREMOVE(index);
} }
void TerraChunk::mesh_data_resource_clear() { void TerraChunk::mesh_data_resource_clear() {
_mesh_data_resources.clear(); _mesh_data_resources.clear();
@ -951,7 +951,7 @@ int TerraChunk::collider_get_count() const {
void TerraChunk::collider_remove(const int index) { void TerraChunk::collider_remove(const int index) {
ERR_FAIL_INDEX(index, _colliders.size()); ERR_FAIL_INDEX(index, _colliders.size());
_colliders.remove(index); _colliders.VREMOVE(index);
} }
void TerraChunk::colliders_clear() { void TerraChunk::colliders_clear() {
_colliders.clear(); _colliders.clear();

View File

@ -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) { void TerraEnvironmentData::setup(WorldEnvironment *world_environment, DirectionalLight *primary_light, DirectionalLight *secondary_light) {
if (has_method("_setup")) if (has_method("_setup")) {
call("_setup", world_environment, primary_light, secondary_light); CALL(_setup, world_environment, primary_light, secondary_light);
}
} }
void TerraEnvironmentData::setup_bind(Node *world_environment, Node *primary_light, Node *secondary_light) { void TerraEnvironmentData::setup_bind(Node *world_environment, Node *primary_light, Node *secondary_light) {
setup(Object::cast_to<WorldEnvironment>(world_environment), Object::cast_to<DirectionalLight>(primary_light), Object::cast_to<DirectionalLight>(secondary_light)); setup(Object::cast_to<WorldEnvironment>(world_environment), Object::cast_to<DirectionalLight>(primary_light), Object::cast_to<DirectionalLight>(secondary_light));
@ -84,7 +85,11 @@ TerraEnvironmentData::~TerraEnvironmentData() {
} }
void TerraEnvironmentData::_bind_methods() { 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"))); 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("get_environment"), &TerraEnvironmentData::get_environment);
ClassDB::bind_method(D_METHOD("set_environment", "value"), &TerraEnvironmentData::set_environment); ClassDB::bind_method(D_METHOD("set_environment", "value"), &TerraEnvironmentData::set_environment);

View File

@ -29,8 +29,8 @@ SOFTWARE.
#include "core/io/resource.h" #include "core/io/resource.h"
#include "core/math/color.h" #include "core/math/color.h"
#else #else
#include "core/resource.h"
#include "core/color.h" #include "core/color.h"
#include "core/resource.h"
#endif #endif
#include "../defines.h" #include "../defines.h"
@ -57,6 +57,10 @@ public:
void setup(WorldEnvironment *world_environment, DirectionalLight *primary_light, DirectionalLight *secondary_light); void setup(WorldEnvironment *world_environment, DirectionalLight *primary_light, DirectionalLight *secondary_light);
void setup_bind(Node *world_environment, Node *primary_light, Node *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();
~TerraEnvironmentData(); ~TerraEnvironmentData();

View File

@ -66,8 +66,9 @@ void TerraStructure::set_position(const int x, const int y, const int z) {
void TerraStructure::write_to_chunk(Ref<TerraChunk> chunk) { void TerraStructure::write_to_chunk(Ref<TerraChunk> chunk) {
ERR_FAIL_COND(!chunk.is_valid()); ERR_FAIL_COND(!chunk.is_valid());
if (has_method("_write_to_chunk")) if (has_method("_write_to_chunk")) {
call("_write_to_chunk", chunk); CALL(_write_to_chunk, chunk);
}
} }
TerraStructure::TerraStructure() { TerraStructure::TerraStructure() {
@ -81,7 +82,11 @@ TerraStructure::~TerraStructure() {
} }
void TerraStructure::_bind_methods() { void TerraStructure::_bind_methods() {
#if VERSION_MAJOR < 4
BIND_VMETHOD(MethodInfo("_write_to_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"))); 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("get_use_aabb"), &TerraStructure::get_use_aabb);
ClassDB::bind_method(D_METHOD("set_use_aabb", "value"), &TerraStructure::set_use_aabb); ClassDB::bind_method(D_METHOD("set_use_aabb", "value"), &TerraStructure::set_use_aabb);

View File

@ -29,19 +29,18 @@ SOFTWARE.
#include "core/io/resource.h" #include "core/io/resource.h"
#include "core/templates/hash_map.h" #include "core/templates/hash_map.h"
#else #else
#include "core/resource.h"
#include "core/hash_map.h" #include "core/hash_map.h"
#include "core/resource.h"
#endif #endif
#include "../defines.h" #include "../defines.h"
#include pool_vector_h #include pool_vector_h
include_pool_vector include_pool_vector
#include "core/math/aabb.h" #include "core/math/aabb.h"
#include "terra_chunk.h" #include "terra_chunk.h"
class TerraStructure : public Resource { class TerraStructure : public Resource {
GDCLASS(TerraStructure, Resource); GDCLASS(TerraStructure, Resource);
public: public:
@ -64,6 +63,10 @@ public:
void write_to_chunk(Ref<TerraChunk> chunk); void write_to_chunk(Ref<TerraChunk> chunk);
#if VERSION_MAJOR >= 4
GDVIRTUAL1(_write_to_chunk, Ref<TerraChunk>);
#endif
TerraStructure(); TerraStructure();
~TerraStructure(); ~TerraStructure();

View File

@ -183,7 +183,7 @@ void TerraWorld::world_area_add(const Ref<TerraWorldArea> &area) {
void TerraWorld::world_area_remove(const int index) { void TerraWorld::world_area_remove(const int index) {
ERR_FAIL_INDEX(index, _world_areas.size()); ERR_FAIL_INDEX(index, _world_areas.size());
_world_areas.remove(index); _world_areas.VREMOVE(index);
} }
void TerraWorld::world_areas_clear() { void TerraWorld::world_areas_clear() {
_world_areas.clear(); _world_areas.clear();
@ -209,12 +209,12 @@ void TerraWorld::voxel_structure_remove(const Ref<TerraStructure> &structure) {
int index = _voxel_structures.find(structure); int index = _voxel_structures.find(structure);
if (index != -1) if (index != -1)
_voxel_structures.remove(index); _voxel_structures.VREMOVE(index);
} }
void TerraWorld::voxel_structure_remove_index(const int index) { void TerraWorld::voxel_structure_remove_index(const int index) {
ERR_FAIL_INDEX(index, _voxel_structures.size()); ERR_FAIL_INDEX(index, _voxel_structures.size());
_voxel_structures.remove(index); _voxel_structures.VREMOVE(index);
} }
void TerraWorld::voxel_structures_clear() { void TerraWorld::voxel_structures_clear() {
_voxel_structures.clear(); _voxel_structures.clear();
@ -266,8 +266,9 @@ void TerraWorld::chunk_add(Ref<TerraChunk> chunk, const int x, const int z) {
if (is_inside_tree()) if (is_inside_tree())
chunk->enter_tree(); chunk->enter_tree();
if (has_method("_chunk_added")) if (has_method("_chunk_added")) {
call("_chunk_added", chunk); CALL(_chunk_added, chunk);
}
emit_signal("chunk_added", chunk); emit_signal("chunk_added", chunk);
} }
@ -292,7 +293,7 @@ Ref<TerraChunk> TerraWorld::chunk_remove(const int x, const int z) {
for (int i = 0; i < _chunks_vector.size(); ++i) { for (int i = 0; i < _chunks_vector.size(); ++i) {
if (_chunks_vector.get(i) == chunk) { if (_chunks_vector.get(i) == chunk) {
_chunks_vector.remove(i); _chunks_vector.VREMOVE(i);
break; break;
} }
} }
@ -309,7 +310,7 @@ Ref<TerraChunk> TerraWorld::chunk_remove_index(const int index) {
ERR_FAIL_INDEX_V(index, _chunks_vector.size(), NULL); ERR_FAIL_INDEX_V(index, _chunks_vector.size(), NULL);
Ref<TerraChunk> chunk = _chunks_vector.get(index); Ref<TerraChunk> chunk = _chunks_vector.get(index);
_chunks_vector.remove(index); _chunks_vector.VREMOVE(index);
_chunks.erase(IntPos(chunk->get_position_x(), chunk->get_position_z())); _chunks.erase(IntPos(chunk->get_position_x(), chunk->get_position_z()));
chunk->exit_tree(); chunk->exit_tree();
@ -330,7 +331,7 @@ int TerraWorld::chunk_get_count() const {
void TerraWorld::chunks_clear() { void TerraWorld::chunks_clear() {
for (int i = 0; i < _chunks_vector.size(); ++i) { for (int i = 0; i < _chunks_vector.size(); ++i) {
Ref<TerraChunk> chunk = _chunks_vector.get(i); Ref<TerraChunk> chunk = _chunks_vector.get(i);
chunk->exit_tree(); chunk->exit_tree();
emit_signal("chunk_removed", chunk); emit_signal("chunk_removed", chunk);
@ -355,7 +356,8 @@ Ref<TerraChunk> TerraWorld::chunk_get_or_create(int x, int z) {
} }
Ref<TerraChunk> TerraWorld::chunk_create(const int x, const int z) { Ref<TerraChunk> TerraWorld::chunk_create(const int x, const int z) {
Ref<TerraChunk> c = call("_create_chunk", x, z, Ref<TerraChunk>()); Ref<TerraChunk> c;
GET_CALLP(Ref<TerraChunk>, c, _create_chunk, x, z, Ref<TerraChunk>());
generation_queue_add_to(c); generation_queue_add_to(c);
@ -365,12 +367,17 @@ Ref<TerraChunk> TerraWorld::chunk_create(const int x, const int z) {
void TerraWorld::chunk_setup(Ref<TerraChunk> chunk) { void TerraWorld::chunk_setup(Ref<TerraChunk> chunk) {
ERR_FAIL_COND(!chunk.is_valid()); ERR_FAIL_COND(!chunk.is_valid());
#if VERSION_MAJOR < 4
call("_create_chunk", chunk->get_position_x(), chunk->get_position_z(), chunk); call("_create_chunk", chunk->get_position_x(), chunk->get_position_z(), chunk);
#else
Ref<TerraChunk> c;
GDVIRTUAL_CALL(_create_chunk, chunk->get_position_x(), chunk->get_position_z(), chunk, c);
#endif
} }
Ref<TerraChunk> TerraWorld::_create_chunk(const int x, const int z, Ref<TerraChunk> chunk) { Ref<TerraChunk> TerraWorld::_create_chunk(const int x, const int z, Ref<TerraChunk> chunk) {
if (!chunk.is_valid()) { if (!chunk.is_valid()) {
chunk.instance(); chunk.INSTANCE();
} }
//no meshers here //no meshers here
@ -400,10 +407,11 @@ Ref<TerraChunk> TerraWorld::_create_chunk(const int x, const int z, Ref<TerraChu
void TerraWorld::chunk_generate(Ref<TerraChunk> chunk) { void TerraWorld::chunk_generate(Ref<TerraChunk> chunk) {
ERR_FAIL_COND(!chunk.is_valid()); ERR_FAIL_COND(!chunk.is_valid());
if (has_method("_prepare_chunk_for_generation")) if (has_method("_prepare_chunk_for_generation")) {
call("_prepare_chunk_for_generation", chunk); CALL(_prepare_chunk_for_generation, chunk);
}
call("_generate_chunk", chunk); CALL(_generate_chunk, chunk);
chunk->build(); chunk->build();
} }
@ -511,7 +519,7 @@ Ref<TerraChunk> TerraWorld::generation_queue_get_index(int index) {
void TerraWorld::generation_queue_remove_index(int index) { void TerraWorld::generation_queue_remove_index(int index) {
ERR_FAIL_INDEX(index, _generation_queue.size()); ERR_FAIL_INDEX(index, _generation_queue.size());
_generation_queue.remove(index); _generation_queue.VREMOVE(index);
} }
int TerraWorld::generation_queue_get_size() const { int TerraWorld::generation_queue_get_size() const {
return _generation_queue.size(); return _generation_queue.size();
@ -530,7 +538,7 @@ Ref<TerraChunk> TerraWorld::generation_get_index(const int index) {
void TerraWorld::generation_remove_index(const int index) { void TerraWorld::generation_remove_index(const int index) {
ERR_FAIL_INDEX(index, _generating.size()); ERR_FAIL_INDEX(index, _generating.size());
_generating.remove(index); _generating.VREMOVE(index);
} }
int TerraWorld::generation_get_size() const { int TerraWorld::generation_get_size() const {
return _generating.size(); return _generating.size();
@ -583,7 +591,7 @@ void TerraWorld::prop_add(Transform transform, const Ref<PropData> &prop, const
if (!sc.is_valid()) if (!sc.is_valid())
continue; continue;
Node *n = sc->instance(); Node *n = sc->INSTANCE();
add_child(n); add_child(n);
n->set_owner(this); n->set_owner(this);
@ -600,7 +608,7 @@ void TerraWorld::prop_add(Transform transform, const Ref<PropData> &prop, const
if (light_data.is_valid()) { if (light_data.is_valid()) {
Ref<TerraLight> light; Ref<TerraLight> 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_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()); light->set_color(light_data->get_light_color());
@ -805,11 +813,11 @@ Ref<TerraChunk> 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) { 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) { 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() { TerraWorld::TerraWorld() {
@ -919,7 +927,7 @@ void TerraWorld::_notification(int p_what) {
#endif #endif
_is_priority_generation = false; _is_priority_generation = false;
call("_generation_finished"); CALL(_generation_finished);
emit_signal("generation_finished"); emit_signal("generation_finished");
@ -930,7 +938,7 @@ void TerraWorld::_notification(int p_what) {
Ref<TerraChunk> chunk = _generating.get(i); Ref<TerraChunk> chunk = _generating.get(i);
if (!chunk.is_valid() || !chunk->get_is_generating()) { if (!chunk.is_valid() || !chunk->get_is_generating()) {
_generating.remove(i); _generating.VREMOVE(i);
--i; --i;
continue; continue;
} }
@ -944,7 +952,7 @@ void TerraWorld::_notification(int p_what) {
while (_generating.size() < _max_concurrent_generations && _generation_queue.size() != 0) { while (_generating.size() < _max_concurrent_generations && _generation_queue.size() != 0) {
Ref<TerraChunk> chunk = _generation_queue.get(0); Ref<TerraChunk> chunk = _generation_queue.get(0);
_generation_queue.remove(0); _generation_queue.VREMOVE(0);
ERR_FAIL_COND(!chunk.is_valid()); 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); 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"); 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"))); 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_add", "chunk", "x", "z"), &TerraWorld::chunk_add);
ClassDB::bind_method(D_METHOD("chunk_has", "x", "z"), &TerraWorld::chunk_has); 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); ClassDB::bind_method(D_METHOD("generation_get_size"), &TerraWorld::generation_get_size);
ADD_SIGNAL(MethodInfo("generation_finished")); ADD_SIGNAL(MethodInfo("generation_finished"));
#if VERSION_MAJOR < 4
BIND_VMETHOD(MethodInfo("_generation_finished")); 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("_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"))); 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_get_or_create", "x", "z"), &TerraWorld::chunk_get_or_create);
ClassDB::bind_method(D_METHOD("chunk_create", "x", "z"), &TerraWorld::chunk_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_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); 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);
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", BIND_VMETHOD(MethodInfo("_set_voxel_with_tool",
PropertyInfo(Variant::BOOL, "mode_add"), PropertyInfo(Variant::BOOL, "mode_add"),
PropertyInfo(Variant::VECTOR3, "hit_position"), PropertyInfo(Variant::VECTOR3, "hit_position"),
PropertyInfo(Variant::VECTOR3, "hit_normal"), PropertyInfo(Variant::VECTOR3, "hit_normal"),
PropertyInfo(Variant::INT, "selected_voxel"), PropertyInfo(Variant::INT, "selected_voxel"),
PropertyInfo(Variant::INT, "isolevel"))); 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);
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);

View File

@ -192,6 +192,20 @@ public:
int get_channel_index_info(const ChannelTypeInfo channel_type); int get_channel_index_info(const ChannelTypeInfo channel_type);
#if VERSION_MAJOR >= 4
GDVIRTUAL1(_chunk_added, Ref<TerraChunk>);
GDVIRTUAL0(_generation_finished);
GDVIRTUAL3R(Ref<TerraChunk>, _create_chunk, int, int, Ref<TerraChunk>);
GDVIRTUAL1(_prepare_chunk_for_generation, Ref<TerraChunk>);
GDVIRTUAL1(_generate_chunk, Ref<TerraChunk>);
GDVIRTUAL1R(int, _get_channel_index_info, int);
GDVIRTUAL5(_set_voxel_with_tool, bool, Vector3, Vector3, int, int);
#endif
TerraWorld(); TerraWorld();
~TerraWorld(); ~TerraWorld();

View File

@ -42,16 +42,17 @@ SOFTWARE.
#include spatial_editor_plugin_h #include spatial_editor_plugin_h
#include camera_h #include camera_h
#if VERSION_MAJOR < 4
bool TerraWorldEditor::forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event) { bool TerraWorldEditor::forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event) {
if (!_world || !_world->get_editable()) { if (!_world || !_world->get_editable()) {
return false; return false;
} }
Ref<InputEventMouseButton> mb = p_event; Ref<TerramanLibrary> mb = p_event;
if (mb.is_valid()) { if (mb.is_valid()) {
if (mb->is_pressed()) { if (mb->is_pressed()) {
Ref<TerramanLibrary> lib = _world->get_library(); Ref<VoxelmanLibrary> lib = _world->get_library();
if (!lib.is_valid()) if (!lib.is_valid())
return false; return false;
@ -68,6 +69,39 @@ bool TerraWorldEditor::forward_spatial_input_event(Camera *p_camera, const Ref<I
return false; return false;
} }
#else
EditorPlugin::AfterGUIInput TerraWorldEditor::forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event) {
if (!_world || !_world->get_editable()) {
return EditorPlugin::AFTER_GUI_INPUT_PASS;
}
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid()) {
if (mb->is_pressed()) {
Ref<TerramanLibrary> 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) { bool TerraWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click) {
if (!spatial_editor || !_world || !_world->is_inside_world()) if (!spatial_editor || !_world || !_world->is_inside_world())

View File

@ -28,7 +28,12 @@ SOFTWARE.
#include "../defines.h" #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 SpatialEditorPlugin;
class TerraWorldEditor : public PanelContainer { class TerraWorldEditor : public PanelContainer {
@ -41,7 +46,11 @@ public:
}; };
public: public:
#if VERSION_MAJOR < 4
bool forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event); bool forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event);
#else
EditorPlugin::AfterGUIInput forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event);
#endif
void edit(TerraWorld *p_world); void edit(TerraWorld *p_world);
bool do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click); bool do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click);
@ -91,8 +100,13 @@ protected:
void _notification(int p_what); void _notification(int p_what);
public: public:
virtual bool forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &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<InputEvent> &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<InputEvent> &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<InputEvent> &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<InputEvent> &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<InputEvent> &p_event) { return voxel_world_editor->forward_spatial_input_event(p_camera, p_event); }
#endif
virtual String get_name() const { return "TerraWorldEditor"; } virtual String get_name() const { return "TerraWorldEditor"; }
bool has_main_screen() const { return false; } bool has_main_screen() const { return false; }
virtual void edit(Object *p_object); virtual void edit(Object *p_object);