mirror of
https://github.com/Relintai/voxelman.git
synced 2024-11-12 10:15:12 +01:00
Work on fixing compile for 4.0.
This commit is contained in:
parent
9ea3cf8de2
commit
abe5db00cb
@ -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"
|
||||
@ -34,7 +37,6 @@ SOFTWARE.
|
||||
#endif
|
||||
|
||||
#include "core/math/aabb.h"
|
||||
|
||||
#include "scene/resources/texture.h"
|
||||
|
||||
class WorldArea : public Reference {
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -57,7 +57,11 @@ void VoxelmanLibrary::material_set(const int index, const Ref<Material> &value)
|
||||
}
|
||||
|
||||
void VoxelmanLibrary::material_remove(const int index) {
|
||||
#if VERSION_MAJOR <= 3
|
||||
_materials.remove(index);
|
||||
#else
|
||||
_materials.remove_at(index);
|
||||
#endif
|
||||
}
|
||||
|
||||
int VoxelmanLibrary::material_get_num() const {
|
||||
@ -102,7 +106,11 @@ void VoxelmanLibrary::liquid_material_set(const int index, const Ref<Material> &
|
||||
}
|
||||
|
||||
void VoxelmanLibrary::liquid_material_remove(const int index) {
|
||||
#if VERSION_MAJOR <= 3
|
||||
_liquid_materials.remove(index);
|
||||
#else
|
||||
_liquid_materials.remove_at(index);
|
||||
#endif
|
||||
}
|
||||
|
||||
int VoxelmanLibrary::liquid_material_get_num() const {
|
||||
@ -147,7 +155,11 @@ void VoxelmanLibrary::prop_material_set(const int index, const Ref<Material> &va
|
||||
}
|
||||
|
||||
void VoxelmanLibrary::prop_material_remove(const int index) {
|
||||
#if VERSION_MAJOR <= 3
|
||||
_prop_materials.remove(index);
|
||||
#else
|
||||
_prop_materials.remove_at(index);
|
||||
#endif
|
||||
}
|
||||
|
||||
int VoxelmanLibrary::prop_material_get_num() const {
|
||||
@ -227,8 +239,13 @@ void VoxelmanLibrary::refresh_rects() {
|
||||
}
|
||||
|
||||
void VoxelmanLibrary::setup_material_albedo(int material_index, Ref<Texture> texture) {
|
||||
if (has_method("_setup_material_albedo"))
|
||||
if (has_method("_setup_material_albedo")) {
|
||||
#if VERSION_MAJOR < 4
|
||||
call("_setup_material_albedo", material_index, texture);
|
||||
#else
|
||||
GDVIRTUAL_CALL(_setup_material_albedo, material_index, texture);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
VoxelmanLibrary::VoxelmanLibrary() {
|
||||
@ -246,7 +263,11 @@ void VoxelmanLibrary::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_initialized", "value"), &VoxelmanLibrary::set_initialized);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "initialized", PROPERTY_HINT_NONE, "", 0), "set_initialized", "get_initialized");
|
||||
|
||||
#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
|
||||
|
||||
ClassDB::bind_method(D_METHOD("material_get", "index"), &VoxelmanLibrary::material_get);
|
||||
ClassDB::bind_method(D_METHOD("material_add", "value"), &VoxelmanLibrary::material_add);
|
||||
|
@ -124,6 +124,11 @@ public:
|
||||
|
||||
void setup_material_albedo(int material_index, Ref<Texture> texture);
|
||||
|
||||
|
||||
#if VERSION_MAJOR >= 4
|
||||
GDVIRTUAL2(_setup_material_albedo, int, Ref<Texture>);
|
||||
#endif
|
||||
|
||||
VoxelmanLibrary();
|
||||
~VoxelmanLibrary();
|
||||
|
||||
|
@ -77,7 +77,11 @@ void VoxelmanLibrarySimple::voxel_surface_set(const int index, Ref<VoxelSurface>
|
||||
}
|
||||
|
||||
void VoxelmanLibrarySimple::voxel_surface_remove(const int index) {
|
||||
#if VERSION_MAJOR <= 3
|
||||
_voxel_surfaces.remove(index);
|
||||
#else
|
||||
_voxel_surfaces.remove_at(index);
|
||||
#endif
|
||||
}
|
||||
|
||||
int VoxelmanLibrarySimple::voxel_surface_get_num() const {
|
||||
|
@ -26,7 +26,10 @@ SOFTWARE.
|
||||
#include "core/version.h"
|
||||
|
||||
#if VERSION_MAJOR > 3
|
||||
#include "core/io/resource.h"
|
||||
#include "core/object/ref_counted.h"
|
||||
#ifndef Reference
|
||||
#define Reference RefCounted
|
||||
#endif
|
||||
#else
|
||||
#include "core/resource.h"
|
||||
#endif
|
||||
|
@ -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"
|
||||
#else
|
||||
#include "core/reference.h"
|
||||
|
@ -26,11 +26,15 @@ 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
|
||||
#else
|
||||
#include "core/reference.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include "marching_cubes_tables.h"
|
||||
|
||||
using namespace MarchingCubes;
|
||||
|
@ -26,15 +26,16 @@ 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
|
||||
#else
|
||||
#include "core/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../default/voxel_mesher_default.h"
|
||||
|
||||
#include "marching_cubes_cell_data.h"
|
||||
|
||||
#include "marching_cubes_tables.h"
|
||||
|
||||
using namespace MarchingCubes;
|
||||
|
@ -30,7 +30,6 @@ SOFTWARE.
|
||||
#include "../world/voxel_chunk.h"
|
||||
|
||||
bool VoxelMesher::Vertex::operator==(const Vertex &p_vertex) const {
|
||||
|
||||
if (vertex != p_vertex.vertex)
|
||||
return false;
|
||||
|
||||
@ -66,7 +65,6 @@ bool VoxelMesher::Vertex::operator==(const Vertex &p_vertex) const {
|
||||
}
|
||||
|
||||
uint32_t VoxelMesher::VertexHasher::hash(const Vertex &p_vtx) {
|
||||
|
||||
uint32_t h = hash_djb2_buffer((const uint8_t *)&p_vtx.vertex, sizeof(real_t) * 3);
|
||||
h = hash_djb2_buffer((const uint8_t *)&p_vtx.normal, sizeof(real_t) * 3, h);
|
||||
h = hash_djb2_buffer((const uint8_t *)&p_vtx.binormal, sizeof(real_t) * 3, h);
|
||||
@ -295,7 +293,6 @@ void VoxelMesher::build_mesh_into(RID mesh) {
|
||||
}
|
||||
|
||||
void VoxelMesher::generate_normals(bool p_flip) {
|
||||
|
||||
_format = _format | VisualServer::ARRAY_FORMAT_NORMAL;
|
||||
|
||||
for (int i = 0; i < _indices.size(); i += 3) {
|
||||
@ -346,7 +343,11 @@ void VoxelMesher::remove_doubles() {
|
||||
for (int j = 0; j < indices.size(); ++j) {
|
||||
int index = indices[j];
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
_vertices.remove(index);
|
||||
#else
|
||||
_vertices.remove_at(index);
|
||||
#endif
|
||||
|
||||
//make all indices that were bigger than the one we replaced one lower
|
||||
for (int k = 0; k < _indices.size(); ++k) {
|
||||
@ -398,8 +399,13 @@ void VoxelMesher::remove_doubles_hashed() {
|
||||
for (int j = 0; j < indices.size(); ++j) {
|
||||
int index = indices[j];
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
hashes.remove(index);
|
||||
_vertices.remove(index);
|
||||
#else
|
||||
hashes.remove_at(index);
|
||||
_vertices.remove_at(index);
|
||||
#endif
|
||||
|
||||
//make all indices that were bigger than the one we replaced one lower
|
||||
for (int k = 0; k < _indices.size(); ++k) {
|
||||
@ -582,11 +588,9 @@ PoolVector<Vector3> VoxelMesher::build_collider() const {
|
||||
return face_points;
|
||||
|
||||
if (_indices.size() == 0) {
|
||||
|
||||
int len = (_vertices.size() / 4);
|
||||
|
||||
for (int i = 0; i < len; ++i) {
|
||||
|
||||
face_points.push_back(_vertices.get(i * 4).vertex);
|
||||
face_points.push_back(_vertices.get((i * 4) + 2).vertex);
|
||||
face_points.push_back(_vertices.get((i * 4) + 1).vertex);
|
||||
@ -607,7 +611,7 @@ PoolVector<Vector3> VoxelMesher::build_collider() const {
|
||||
return face_points;
|
||||
}
|
||||
|
||||
void VoxelMesher::bake_lights(MeshInstance *node, Vector<Ref<VoxelLight> > &lights) {
|
||||
void VoxelMesher::bake_lights(MeshInstance *node, Vector<Ref<VoxelLight>> &lights) {
|
||||
ERR_FAIL_COND(node == NULL);
|
||||
|
||||
Color darkColor(0, 0, 0, 1);
|
||||
@ -649,13 +653,13 @@ void VoxelMesher::bake_lights(MeshInstance *node, Vector<Ref<VoxelLight> > &ligh
|
||||
v_lightDiffuse += value;
|
||||
|
||||
/*
|
||||
float dist2 = Mathf.Clamp(Vector3.Distance(transformedLights[i], vertices), 0f, 15f);
|
||||
dist2 /= 35f;
|
||||
float dist2 = Mathf.Clamp(Vector3.Distance(transformedLights[i], vertices), 0f, 15f);
|
||||
dist2 /= 35f;
|
||||
|
||||
Vector3 value = Vector3.one;
|
||||
value *= ((float) lights[i].Strength) / 255f;
|
||||
value *= (1 - dist2);
|
||||
v_lightDiffuse += value;*/
|
||||
Vector3 value = Vector3.one;
|
||||
value *= ((float) lights[i].Strength) / 255f;
|
||||
value *= (1 - dist2);
|
||||
v_lightDiffuse += value;*/
|
||||
}
|
||||
|
||||
Color f = vertexv.color;
|
||||
@ -742,7 +746,11 @@ Vector3 VoxelMesher::get_vertex(const int idx) const {
|
||||
}
|
||||
|
||||
void VoxelMesher::remove_vertex(const int idx) {
|
||||
#if VERSION_MAJOR < 4
|
||||
_vertices.remove(idx);
|
||||
#else
|
||||
_vertices.remove_at(idx);
|
||||
#endif
|
||||
}
|
||||
|
||||
PoolVector<Vector3> VoxelMesher::get_normals() const {
|
||||
@ -890,7 +898,11 @@ int VoxelMesher::get_index(const int idx) const {
|
||||
}
|
||||
|
||||
void VoxelMesher::remove_index(const int idx) {
|
||||
#if VERSION_MAJOR < 4
|
||||
_indices.remove(idx);
|
||||
#else
|
||||
_indices.remove_at(idx);
|
||||
#endif
|
||||
}
|
||||
|
||||
VoxelMesher::VoxelMesher(const Ref<VoxelmanLibrary> &library) {
|
||||
@ -927,9 +939,15 @@ VoxelMesher::~VoxelMesher() {
|
||||
}
|
||||
|
||||
void VoxelMesher::_bind_methods() {
|
||||
#if VERSION_MAJOR < 4
|
||||
BIND_VMETHOD(MethodInfo("_add_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
|
||||
BIND_VMETHOD(MethodInfo("_bake_colors", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
|
||||
BIND_VMETHOD(MethodInfo("_bake_liquid_colors", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
|
||||
#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"), &VoxelMesher::get_channel_index_type);
|
||||
ClassDB::bind_method(D_METHOD("set_channel_index_type", "value"), &VoxelMesher::set_channel_index_type);
|
||||
@ -983,7 +1001,12 @@ void VoxelMesher::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("add_mesh_data_resource_transform_colored", "mesh", "transform", "colors", "uv_rect"), &VoxelMesher::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, "VoxelMesher")));
|
||||
#else
|
||||
GDVIRTUAL_BIND(_add_mesher, "mesher");
|
||||
#endif
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_mesher", "mesher"), &VoxelMesher::add_mesher);
|
||||
ClassDB::bind_method(D_METHOD("_add_mesher", "mesher"), &VoxelMesher::_add_mesher);
|
||||
|
||||
|
@ -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
|
||||
@ -189,6 +192,13 @@ public:
|
||||
void remove_index(const int idx);
|
||||
void add_indices(const int index);
|
||||
|
||||
#if VERSION_MAJOR >= 4
|
||||
GDVIRTUAL1(_add_chunk, Ref<VoxelChunk>);
|
||||
GDVIRTUAL1(_bake_colors, Ref<VoxelChunk>);
|
||||
GDVIRTUAL1(_bake_liquid_colors, Ref<VoxelChunk>);
|
||||
GDVIRTUAL1(_add_mesher, Ref<VoxelMesher>);
|
||||
#endif
|
||||
|
||||
VoxelMesher(const Ref<VoxelmanLibrary> &library);
|
||||
VoxelMesher();
|
||||
~VoxelMesher();
|
||||
|
@ -179,13 +179,25 @@ Ref<VoxelChunk> VoxelWorldDefault::_create_chunk(int x, int y, int z, Ref<VoxelC
|
||||
|
||||
if (chunk->job_get_count() == 0) {
|
||||
Ref<VoxelTerrarinJob> tj;
|
||||
#if VERSION_MAJOR < 4
|
||||
tj.instance();
|
||||
#else
|
||||
tj.instantiate();
|
||||
#endif
|
||||
|
||||
Ref<VoxelLightJob> lj;
|
||||
#if VERSION_MAJOR < 4
|
||||
lj.instance();
|
||||
#else
|
||||
lj.instantiate();
|
||||
#endif
|
||||
|
||||
Ref<VoxelPropJob> pj;
|
||||
#if VERSION_MAJOR < 4
|
||||
pj.instance();
|
||||
#else
|
||||
pj.instantiate();
|
||||
#endif
|
||||
pj->set_prop_mesher(Ref<VoxelMesher>(memnew(VoxelMesherDefault)));
|
||||
|
||||
chunk->job_add(lj);
|
||||
|
@ -61,8 +61,13 @@ void EnvironmentData::set_indirect_energy(const int index, const float value) {
|
||||
}
|
||||
|
||||
void EnvironmentData::setup(WorldEnvironment *world_environment, DirectionalLight *primary_light, DirectionalLight *secondary_light) {
|
||||
if (has_method("_setup"))
|
||||
if (has_method("_setup")) {
|
||||
#if VERSION_MAJOR < 4
|
||||
call("_setup", world_environment, primary_light, secondary_light);
|
||||
#else
|
||||
GDVIRTUAL_CALL(_setup, world_environment, primary_light, secondary_light);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
void EnvironmentData::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));
|
||||
@ -84,7 +89,11 @@ EnvironmentData::~EnvironmentData() {
|
||||
}
|
||||
|
||||
void EnvironmentData::_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"), &EnvironmentData::get_environment);
|
||||
ClassDB::bind_method(D_METHOD("set_environment", "value"), &EnvironmentData::set_environment);
|
||||
|
@ -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
|
||||
|
||||
EnvironmentData();
|
||||
~EnvironmentData();
|
||||
|
||||
|
@ -32,7 +32,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
|
||||
#else
|
||||
#include "core/reference.h"
|
||||
#endif
|
||||
|
@ -230,7 +230,11 @@ void VoxelChunk::job_set(int index, const Ref<VoxelJob> &job) {
|
||||
void VoxelChunk::job_remove(const int index) {
|
||||
ERR_FAIL_INDEX(index, _jobs.size());
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
_jobs.remove(index);
|
||||
#else
|
||||
_jobs.remove_at(index);
|
||||
#endif
|
||||
}
|
||||
void VoxelChunk::job_add(const Ref<VoxelJob> &job) {
|
||||
_jobs.push_back(job);
|
||||
@ -284,9 +288,13 @@ Ref<VoxelJob> VoxelChunk::job_get_current() {
|
||||
|
||||
//Voxel Data
|
||||
void VoxelChunk::channel_setup() {
|
||||
#if VERSION_MAJOR < 4
|
||||
ERR_FAIL_COND_MSG(!has_method("_channel_setup"), "VoxelChunk: _setup_channels() is missing! Please implement it!");
|
||||
|
||||
call("_channel_setup");
|
||||
#else
|
||||
GDVIRTUAL_CALL(_channel_setup);
|
||||
#endif
|
||||
}
|
||||
|
||||
void VoxelChunk::set_size(const int size_x, const int size_y, const int size_z, const int margin_start, const int margin_end) {
|
||||
@ -583,13 +591,22 @@ void VoxelChunk::voxel_structure_remove(const Ref<VoxelStructure> &structure) {
|
||||
|
||||
int index = _voxel_structures.find(structure);
|
||||
|
||||
if (index != -1)
|
||||
if (index != -1) {
|
||||
#if VERSION_MAJOR < 4
|
||||
_voxel_structures.remove(index);
|
||||
#else
|
||||
_voxel_structures.remove_at(index);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
void VoxelChunk::voxel_structure_remove_index(const int index) {
|
||||
ERR_FAIL_INDEX(index, _voxel_structures.size());
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
_voxel_structures.remove(index);
|
||||
#else
|
||||
_voxel_structures.remove_at(index);
|
||||
#endif
|
||||
}
|
||||
void VoxelChunk::voxel_structure_clear() {
|
||||
_voxel_structures.clear();
|
||||
@ -625,7 +642,11 @@ void VoxelChunk::build() {
|
||||
ERR_FAIL_COND(!get_voxel_world()->is_inside_tree());
|
||||
ERR_FAIL_COND(!is_in_tree());
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
call("_build");
|
||||
#else
|
||||
GDVIRTUAL_CALL(_build);
|
||||
#endif
|
||||
}
|
||||
|
||||
void VoxelChunk::_build() {
|
||||
@ -646,25 +667,44 @@ void VoxelChunk::clear() {
|
||||
}
|
||||
|
||||
void VoxelChunk::finalize_build() {
|
||||
#if VERSION_MAJOR < 4
|
||||
if (has_method("_finalize_build")) {
|
||||
call("_finalize_build");
|
||||
}
|
||||
#else
|
||||
GDVIRTUAL_CALL(_finalize_build);
|
||||
#endif
|
||||
}
|
||||
|
||||
void VoxelChunk::bake_lights() {
|
||||
if (has_method("_bake_lights"))
|
||||
#if VERSION_MAJOR < 4
|
||||
if (has_method("_bake_lights")) {
|
||||
call("_bake_lights");
|
||||
}
|
||||
#else
|
||||
GDVIRTUAL_CALL(_bake_lights);
|
||||
#endif
|
||||
}
|
||||
void VoxelChunk::bake_light(Ref<VoxelLight> light) {
|
||||
if (!light.is_valid())
|
||||
return;
|
||||
|
||||
if (has_method("_bake_lights"))
|
||||
#if VERSION_MAJOR < 4
|
||||
if (has_method("_bake_light")) {
|
||||
call("_bake_light", light);
|
||||
}
|
||||
#else
|
||||
GDVIRTUAL_CALL(_bake_light, light);
|
||||
#endif
|
||||
}
|
||||
void VoxelChunk::clear_baked_lights() {
|
||||
if (has_method("_clear_baked_lights"))
|
||||
#if VERSION_MAJOR < 4
|
||||
if (has_method("_clear_baked_lights")) {
|
||||
call("_clear_baked_lights");
|
||||
}
|
||||
#else
|
||||
GDVIRTUAL_CALL(_clear_baked_lights);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if PROPS_PRESENT
|
||||
@ -693,7 +733,11 @@ int VoxelChunk::prop_get_count() const {
|
||||
void VoxelChunk::prop_remove(const int index) {
|
||||
ERR_FAIL_INDEX(index, _props.size());
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
_props.remove(index);
|
||||
#else
|
||||
_props.remove_at(index);
|
||||
#endif
|
||||
}
|
||||
void VoxelChunk::props_clear() {
|
||||
_props.clear();
|
||||
@ -735,8 +779,13 @@ int VoxelChunk::mesh_data_resource_addv(const Vector3 &local_data_pos, const Ref
|
||||
|
||||
_mesh_data_resources.push_back(e);
|
||||
|
||||
if (has_method("_mesh_data_resource_added"))
|
||||
#if VERSION_MAJOR < 4
|
||||
if (has_method("_mesh_data_resource_added")) {
|
||||
call("_mesh_data_resource_added", index);
|
||||
}
|
||||
#else
|
||||
GDVIRTUAL_CALL(_mesh_data_resource_added, index);
|
||||
#endif
|
||||
|
||||
return index;
|
||||
}
|
||||
@ -774,8 +823,13 @@ int VoxelChunk::mesh_data_resource_add(const Transform &local_transform, const R
|
||||
|
||||
_mesh_data_resources.push_back(e);
|
||||
|
||||
if (has_method("_mesh_data_resource_added"))
|
||||
#if VERSION_MAJOR < 4
|
||||
if (has_method("_mesh_data_resource_added")) {
|
||||
call("_mesh_data_resource_added", index);
|
||||
}
|
||||
#else
|
||||
GDVIRTUAL_CALL(_mesh_data_resource_added, index);
|
||||
#endif
|
||||
|
||||
return index;
|
||||
}
|
||||
@ -926,7 +980,11 @@ int VoxelChunk::collider_get_count() const {
|
||||
void VoxelChunk::collider_remove(const int index) {
|
||||
ERR_FAIL_INDEX(index, _colliders.size());
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
_colliders.remove(index);
|
||||
#else
|
||||
_colliders.remove_at(index);
|
||||
#endif
|
||||
}
|
||||
void VoxelChunk::colliders_clear() {
|
||||
_colliders.clear();
|
||||
@ -935,43 +993,92 @@ void VoxelChunk::colliders_clear() {
|
||||
void VoxelChunk::enter_tree() {
|
||||
_is_in_tree = true;
|
||||
|
||||
if (has_method("_enter_tree"))
|
||||
#if VERSION_MAJOR < 4
|
||||
if (has_method("_enter_tree")) {
|
||||
call("_enter_tree");
|
||||
}
|
||||
#else
|
||||
GDVIRTUAL_CALL(_enter_tree);
|
||||
#endif
|
||||
}
|
||||
void VoxelChunk::exit_tree() {
|
||||
_is_in_tree = false;
|
||||
|
||||
if (has_method("_exit_tree"))
|
||||
#if VERSION_MAJOR < 4
|
||||
if (has_method("_exit_tree")) {
|
||||
call("_exit_tree");
|
||||
}
|
||||
#else
|
||||
GDVIRTUAL_CALL(_exit_tree);
|
||||
#endif
|
||||
}
|
||||
void VoxelChunk::process(const float delta) {
|
||||
if (has_method("_process"))
|
||||
#if VERSION_MAJOR < 4
|
||||
if (has_method("_process")) {
|
||||
call("_process", delta);
|
||||
}
|
||||
#else
|
||||
GDVIRTUAL_CALL(_process, delta);
|
||||
#endif
|
||||
}
|
||||
void VoxelChunk::physics_process(const float delta) {
|
||||
if (has_method("_physics_process"))
|
||||
#if VERSION_MAJOR < 4
|
||||
if (has_method("_physics_process")) {
|
||||
call("_physics_process", delta);
|
||||
}
|
||||
#else
|
||||
GDVIRTUAL_CALL(_physics_process, delta);
|
||||
#endif
|
||||
}
|
||||
void VoxelChunk::world_transform_changed() {
|
||||
call("_world_transform_changed");
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
call("_world_transform_changed");
|
||||
#else
|
||||
GDVIRTUAL_CALL(_world_transform_changed);
|
||||
#endif
|
||||
}
|
||||
void VoxelChunk::visibility_changed(const bool visible) {
|
||||
if (has_method("_visibility_changed"))
|
||||
#if VERSION_MAJOR < 4
|
||||
if (has_method("_visibility_changed")) {
|
||||
call("_visibility_changed", _is_visible);
|
||||
}
|
||||
#else
|
||||
GDVIRTUAL_CALL(_visibility_changed, _is_visible);
|
||||
#endif
|
||||
}
|
||||
void VoxelChunk::world_light_added(const Ref<VoxelLight> &light) {
|
||||
if (has_method("_world_light_added"))
|
||||
#if VERSION_MAJOR < 4
|
||||
if (has_method("_world_light_added")) {
|
||||
call("_world_light_added", light);
|
||||
}
|
||||
#else
|
||||
GDVIRTUAL_CALL(_world_light_added, light);
|
||||
#endif
|
||||
}
|
||||
void VoxelChunk::world_light_removed(const Ref<VoxelLight> &light) {
|
||||
if (has_method("_world_light_removed"))
|
||||
#if VERSION_MAJOR < 4
|
||||
if (has_method("_world_light_removed")) {
|
||||
call("_world_light_removed", light);
|
||||
}
|
||||
#else
|
||||
GDVIRTUAL_CALL(_world_light_removed, light);
|
||||
#endif
|
||||
}
|
||||
void VoxelChunk::generation_process(const float delta) {
|
||||
#if VERSION_MAJOR < 4
|
||||
call("_generation_process", delta);
|
||||
#else
|
||||
GDVIRTUAL_CALL(_generation_process, delta);
|
||||
#endif
|
||||
}
|
||||
void VoxelChunk::generation_physics_process(const float delta) {
|
||||
#if VERSION_MAJOR < 4
|
||||
call("_generation_physics_process", delta);
|
||||
#else
|
||||
GDVIRTUAL_CALL(_generation_physics_process, delta);
|
||||
#endif
|
||||
}
|
||||
|
||||
Transform VoxelChunk::get_transform() const {
|
||||
@ -982,19 +1089,16 @@ void VoxelChunk::set_transform(const Transform &transform) {
|
||||
}
|
||||
|
||||
Transform VoxelChunk::get_global_transform() const {
|
||||
|
||||
ERR_FAIL_COND_V(!get_voxel_world(), Transform());
|
||||
|
||||
return get_voxel_world()->get_global_transform() * _transform;
|
||||
}
|
||||
|
||||
Vector3 VoxelChunk::to_local(Vector3 p_global) const {
|
||||
|
||||
return get_global_transform().affine_inverse().xform(p_global);
|
||||
}
|
||||
|
||||
Vector3 VoxelChunk::to_global(Vector3 p_local) const {
|
||||
|
||||
return get_global_transform().xform(p_local);
|
||||
}
|
||||
|
||||
@ -1195,6 +1299,7 @@ void VoxelChunk::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
void VoxelChunk::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo("mesh_generation_finished", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
BIND_VMETHOD(MethodInfo("_mesh_data_resource_added", PropertyInfo(Variant::INT, "index")));
|
||||
|
||||
BIND_VMETHOD(MethodInfo("_channel_setup"));
|
||||
@ -1202,11 +1307,21 @@ void VoxelChunk::_bind_methods() {
|
||||
BIND_VMETHOD(MethodInfo("_bake_lights"));
|
||||
BIND_VMETHOD(MethodInfo("_bake_light", PropertyInfo(Variant::OBJECT, "light", PROPERTY_HINT_RESOURCE_TYPE, "VoxelLight")));
|
||||
BIND_VMETHOD(MethodInfo("_clear_baked_lights"));
|
||||
#else
|
||||
GDVIRTUAL_BIND(_mesh_data_resource_added, "index");
|
||||
|
||||
GDVIRTUAL_BIND(_channel_setup);
|
||||
|
||||
GDVIRTUAL_BIND(_bake_lights);
|
||||
GDVIRTUAL_BIND(_bake_light, "light");
|
||||
GDVIRTUAL_BIND(_clear_baked_lights);
|
||||
#endif
|
||||
|
||||
ClassDB::bind_method(D_METHOD("bake_lights"), &VoxelChunk::bake_lights);
|
||||
ClassDB::bind_method(D_METHOD("bake_light", "light"), &VoxelChunk::bake_light);
|
||||
ClassDB::bind_method(D_METHOD("clear_baked_lights"), &VoxelChunk::clear_baked_lights);
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
BIND_VMETHOD(MethodInfo("_enter_tree"));
|
||||
BIND_VMETHOD(MethodInfo("_exit_tree"));
|
||||
BIND_VMETHOD(MethodInfo("_process", PropertyInfo(Variant::REAL, "delta")));
|
||||
@ -1220,6 +1335,21 @@ void VoxelChunk::_bind_methods() {
|
||||
BIND_VMETHOD(MethodInfo("_generation_physics_process", PropertyInfo(Variant::REAL, "delta")));
|
||||
|
||||
BIND_VMETHOD(MethodInfo("_finalize_build"));
|
||||
#else
|
||||
GDVIRTUAL_BIND(_enter_tree);
|
||||
GDVIRTUAL_BIND(_exit_tree);
|
||||
GDVIRTUAL_BIND(_process, "delta");
|
||||
GDVIRTUAL_BIND(_physics_process, "delta");
|
||||
GDVIRTUAL_BIND(_world_transform_changed);
|
||||
GDVIRTUAL_BIND(_visibility_changed, "visible");
|
||||
GDVIRTUAL_BIND(_world_light_added, "light");
|
||||
GDVIRTUAL_BIND(_world_light_removed, "light");
|
||||
|
||||
GDVIRTUAL_BIND(_generation_process, "delta");
|
||||
GDVIRTUAL_BIND(_generation_physics_process, "delta");
|
||||
|
||||
GDVIRTUAL_BIND(_finalize_build);
|
||||
#endif
|
||||
|
||||
ClassDB::bind_method(D_METHOD("enter_tree"), &VoxelChunk::enter_tree);
|
||||
ClassDB::bind_method(D_METHOD("exit_tree"), &VoxelChunk::exit_tree);
|
||||
@ -1437,7 +1567,12 @@ void VoxelChunk::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("collider_remove", "index"), &VoxelChunk::collider_remove);
|
||||
ClassDB::bind_method(D_METHOD("colliders_clear"), &VoxelChunk::colliders_clear);
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
BIND_VMETHOD(MethodInfo("_build"));
|
||||
#else
|
||||
GDVIRTUAL_BIND(_build);
|
||||
#endif
|
||||
|
||||
ClassDB::bind_method(D_METHOD("build"), &VoxelChunk::build);
|
||||
ClassDB::bind_method(D_METHOD("_build"), &VoxelChunk::_build);
|
||||
|
||||
|
@ -26,15 +26,15 @@ SOFTWARE.
|
||||
#include "core/version.h"
|
||||
|
||||
#if VERSION_MAJOR > 3
|
||||
#include "core/config/engine.h"
|
||||
#include "core/io/resource.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/config/engine.h"
|
||||
#include "core/variant/array.h"
|
||||
#else
|
||||
#include "core/array.h"
|
||||
#include "core/engine.h"
|
||||
#include "core/resource.h"
|
||||
#include "core/ustring.h"
|
||||
#include "core/engine.h"
|
||||
#include "core/array.h"
|
||||
#endif
|
||||
|
||||
#include "../defines.h"
|
||||
@ -62,11 +62,14 @@ include_pool_vector
|
||||
|
||||
#if VERSION_MAJOR >= 4
|
||||
#define Texture Texture2D
|
||||
|
||||
#include "core/math/transform_3d.h"
|
||||
typedef class Transform3D Transform;
|
||||
#endif
|
||||
|
||||
#include "../library/voxel_surface.h"
|
||||
#include "../library/voxelman_library.h"
|
||||
; //hackfix for a clang format issue
|
||||
; //hackfix for a clang format issue
|
||||
|
||||
class VoxelJob;
|
||||
class VoxelWorld;
|
||||
@ -292,6 +295,31 @@ public:
|
||||
Vector3 to_local(Vector3 p_global) const;
|
||||
Vector3 to_global(Vector3 p_local) const;
|
||||
|
||||
#if VERSION_MAJOR >= 4
|
||||
GDVIRTUAL1(_mesh_data_resource_added, int);
|
||||
|
||||
GDVIRTUAL0(_channel_setup);
|
||||
|
||||
GDVIRTUAL0(_bake_lights);
|
||||
GDVIRTUAL1(_bake_light, Ref<VoxelLight>);
|
||||
GDVIRTUAL0(_clear_baked_lights);
|
||||
|
||||
GDVIRTUAL0(_enter_tree);
|
||||
GDVIRTUAL0(_exit_tree);
|
||||
GDVIRTUAL1(_process, float);
|
||||
GDVIRTUAL1(_physics_process, float);
|
||||
GDVIRTUAL0(_world_transform_changed);
|
||||
GDVIRTUAL1(_visibility_changed, bool);
|
||||
GDVIRTUAL1(_world_light_added, Ref<VoxelLight>);
|
||||
GDVIRTUAL1(_world_light_removed, Ref<VoxelLight>);
|
||||
|
||||
GDVIRTUAL1(_generation_process, float);
|
||||
GDVIRTUAL1(_generation_physics_process, float);
|
||||
|
||||
GDVIRTUAL0(_finalize_build);
|
||||
GDVIRTUAL0(_build);
|
||||
#endif
|
||||
|
||||
VoxelChunk();
|
||||
~VoxelChunk();
|
||||
|
||||
@ -372,11 +400,11 @@ protected:
|
||||
float _voxel_scale;
|
||||
|
||||
int _current_job;
|
||||
Vector<Ref<VoxelJob> > _jobs;
|
||||
Vector<Ref<VoxelJob>> _jobs;
|
||||
|
||||
Ref<VoxelmanLibrary> _library;
|
||||
|
||||
Vector<Ref<VoxelStructure> > _voxel_structures;
|
||||
Vector<Ref<VoxelStructure>> _voxel_structures;
|
||||
|
||||
#if PROPS_PRESENT
|
||||
Vector<PropDataStore> _props;
|
||||
|
@ -66,8 +66,13 @@ void VoxelStructure::set_position(const int x, const int y, const int z) {
|
||||
void VoxelStructure::write_to_chunk(Ref<VoxelChunk> chunk) {
|
||||
ERR_FAIL_COND(!chunk.is_valid());
|
||||
|
||||
if (has_method("_write_to_chunk"))
|
||||
#if VERSION_MAJOR < 4
|
||||
if (has_method("_write_to_chunk")) {
|
||||
call("_write_to_chunk", chunk);
|
||||
}
|
||||
#else
|
||||
GDVIRTUAL_CALL(_write_to_chunk, chunk);
|
||||
#endif
|
||||
}
|
||||
|
||||
VoxelStructure::VoxelStructure() {
|
||||
@ -81,7 +86,11 @@ VoxelStructure::~VoxelStructure() {
|
||||
}
|
||||
|
||||
void VoxelStructure::_bind_methods() {
|
||||
#if VERSION_MAJOR < 4
|
||||
BIND_VMETHOD(MethodInfo("_write_to_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
|
||||
#else
|
||||
GDVIRTUAL_BIND(_write_to_chunk, "chunk");
|
||||
#endif
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_use_aabb"), &VoxelStructure::get_use_aabb);
|
||||
ClassDB::bind_method(D_METHOD("set_use_aabb", "value"), &VoxelStructure::set_use_aabb);
|
||||
|
@ -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 "voxel_chunk.h"
|
||||
|
||||
class VoxelStructure : public Resource {
|
||||
class VoxelStructure : public Resource {
|
||||
GDCLASS(VoxelStructure, Resource);
|
||||
|
||||
public:
|
||||
@ -64,6 +63,10 @@ public:
|
||||
|
||||
void write_to_chunk(Ref<VoxelChunk> chunk);
|
||||
|
||||
#if VERSION_MAJOR >= 4
|
||||
GDVIRTUAL1(_write_to_chunk, Ref<VoxelChunk>);
|
||||
#endif
|
||||
|
||||
VoxelStructure();
|
||||
~VoxelStructure();
|
||||
|
||||
|
@ -197,7 +197,11 @@ void VoxelWorld::world_area_add(const Ref<WorldArea> &area) {
|
||||
void VoxelWorld::world_area_remove(const int index) {
|
||||
ERR_FAIL_INDEX(index, _world_areas.size());
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
_world_areas.remove(index);
|
||||
#else
|
||||
_world_areas.remove_at(index);
|
||||
#endif
|
||||
}
|
||||
void VoxelWorld::world_areas_clear() {
|
||||
_world_areas.clear();
|
||||
@ -222,13 +226,22 @@ void VoxelWorld::voxel_structure_remove(const Ref<VoxelStructure> &structure) {
|
||||
|
||||
int index = _voxel_structures.find(structure);
|
||||
|
||||
if (index != -1)
|
||||
if (index != -1) {
|
||||
#if VERSION_MAJOR < 4
|
||||
_voxel_structures.remove(index);
|
||||
#else
|
||||
_voxel_structures.remove_at(index);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
void VoxelWorld::voxel_structure_remove_index(const int index) {
|
||||
ERR_FAIL_INDEX(index, _voxel_structures.size());
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
_voxel_structures.remove(index);
|
||||
#else
|
||||
_voxel_structures.remove_at(index);
|
||||
#endif
|
||||
}
|
||||
void VoxelWorld::voxel_structures_clear() {
|
||||
_voxel_structures.clear();
|
||||
@ -280,8 +293,13 @@ void VoxelWorld::chunk_add(Ref<VoxelChunk> chunk, const int x, const int y, cons
|
||||
if (is_inside_tree())
|
||||
chunk->enter_tree();
|
||||
|
||||
if (has_method("_chunk_added"))
|
||||
if (has_method("_chunk_added")) {
|
||||
#if VERSION_MAJOR < 4
|
||||
call("_chunk_added", chunk);
|
||||
#else
|
||||
GDVIRTUAL_CALL(_chunk_added, chunk);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
bool VoxelWorld::chunk_has(const int x, const int y, const int z) const {
|
||||
return _chunks.has(IntPos(x, y, z));
|
||||
@ -304,7 +322,11 @@ Ref<VoxelChunk> VoxelWorld::chunk_remove(const int x, const int y, const int z)
|
||||
|
||||
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
||||
if (_chunks_vector.get(i) == chunk) {
|
||||
#if VERSION_MAJOR < 4
|
||||
_chunks_vector.remove(i);
|
||||
#else
|
||||
_chunks_vector.remove_at(i);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -321,7 +343,11 @@ Ref<VoxelChunk> VoxelWorld::chunk_remove_index(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _chunks_vector.size(), NULL);
|
||||
|
||||
Ref<VoxelChunk> chunk = _chunks_vector.get(index);
|
||||
#if VERSION_MAJOR < 4
|
||||
_chunks_vector.remove(index);
|
||||
#else
|
||||
_chunks_vector.remove_at(index);
|
||||
#endif
|
||||
_chunks.erase(IntPos(chunk->get_position_x(), chunk->get_position_y(), chunk->get_position_z()));
|
||||
chunk->exit_tree();
|
||||
|
||||
@ -361,7 +387,12 @@ Ref<VoxelChunk> VoxelWorld::chunk_get_or_create(int x, int y, int z) {
|
||||
}
|
||||
|
||||
Ref<VoxelChunk> VoxelWorld::chunk_create(const int x, const int y, const int z) {
|
||||
#if VERSION_MAJOR < 4
|
||||
Ref<VoxelChunk> c = call("_create_chunk", x, y, z, Ref<VoxelChunk>());
|
||||
#else
|
||||
Ref<VoxelChunk> c;
|
||||
GDVIRTUAL_CALL(_create_chunk, x, y, z, Ref<VoxelChunk>(), c);
|
||||
#endif
|
||||
|
||||
generation_queue_add_to(c);
|
||||
|
||||
@ -371,12 +402,21 @@ Ref<VoxelChunk> VoxelWorld::chunk_create(const int x, const int y, const int z)
|
||||
void VoxelWorld::chunk_setup(Ref<VoxelChunk> chunk) {
|
||||
ERR_FAIL_COND(!chunk.is_valid());
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
call("_create_chunk", chunk->get_position_x(), chunk->get_position_y(), chunk->get_position_z(), chunk);
|
||||
#else
|
||||
Ref<VoxelChunk> c;
|
||||
GDVIRTUAL_CALL(_create_chunk, chunk->get_position_x(), chunk->get_position_y(), chunk->get_position_z(), chunk, c);
|
||||
#endif
|
||||
}
|
||||
|
||||
Ref<VoxelChunk> VoxelWorld::_create_chunk(const int x, const int y, const int z, Ref<VoxelChunk> chunk) {
|
||||
if (!chunk.is_valid()) {
|
||||
#if VERSION_MAJOR < 4
|
||||
chunk.instance();
|
||||
#else
|
||||
chunk.instantiate();
|
||||
#endif
|
||||
}
|
||||
|
||||
//no meshers here
|
||||
@ -405,10 +445,19 @@ Ref<VoxelChunk> VoxelWorld::_create_chunk(const int x, const int y, const int z,
|
||||
void VoxelWorld::chunk_generate(Ref<VoxelChunk> chunk) {
|
||||
ERR_FAIL_COND(!chunk.is_valid());
|
||||
|
||||
if (has_method("_prepare_chunk_for_generation"))
|
||||
if (has_method("_prepare_chunk_for_generation")) {
|
||||
#if VERSION_MAJOR < 4
|
||||
call("_prepare_chunk_for_generation", chunk);
|
||||
#else
|
||||
GDVIRTUAL_CALL(_prepare_chunk_for_generation, chunk);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
call("_generate_chunk", chunk);
|
||||
#else
|
||||
GDVIRTUAL_CALL(_generate_chunk, chunk);
|
||||
#endif
|
||||
|
||||
chunk->build();
|
||||
}
|
||||
@ -517,7 +566,11 @@ Ref<VoxelChunk> VoxelWorld::generation_queue_get_index(int index) {
|
||||
void VoxelWorld::generation_queue_remove_index(int index) {
|
||||
ERR_FAIL_INDEX(index, _generation_queue.size());
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
_generation_queue.remove(index);
|
||||
#else
|
||||
_generation_queue.remove_at(index);
|
||||
#endif
|
||||
}
|
||||
int VoxelWorld::generation_queue_get_size() const {
|
||||
return _generation_queue.size();
|
||||
@ -536,7 +589,11 @@ Ref<VoxelChunk> VoxelWorld::generation_get_index(const int index) {
|
||||
void VoxelWorld::generation_remove_index(const int index) {
|
||||
ERR_FAIL_INDEX(index, _generating.size());
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
_generating.remove(index);
|
||||
#else
|
||||
_generating.remove_at(index);
|
||||
#endif
|
||||
}
|
||||
int VoxelWorld::generation_get_size() const {
|
||||
return _generating.size();
|
||||
@ -589,7 +646,11 @@ void VoxelWorld::prop_add(Transform tarnsform, const Ref<PropData> &prop, const
|
||||
if (!sc.is_valid())
|
||||
continue;
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
Node *n = sc->instance();
|
||||
#else
|
||||
Node *n = sc->instantiate();
|
||||
#endif
|
||||
add_child(n);
|
||||
n->set_owner(this);
|
||||
|
||||
@ -837,11 +898,24 @@ Ref<VoxelChunk> VoxelWorld::get_or_create_chunk_at_world_position(const Vector3
|
||||
}
|
||||
|
||||
void VoxelWorld::set_voxel_with_tool(const bool mode_add, const Vector3 hit_position, const Vector3 hit_normal, const int selected_voxel, const int isolevel) {
|
||||
#if VERSION_MAJOR < 4
|
||||
call("_set_voxel_with_tool", mode_add, hit_position, hit_normal, selected_voxel, isolevel);
|
||||
#else
|
||||
GDVIRTUAL_CALL(_set_voxel_with_tool, mode_add, hit_position, hit_normal, selected_voxel, isolevel);
|
||||
#endif
|
||||
}
|
||||
|
||||
int VoxelWorld::get_channel_index_info(const VoxelWorld::ChannelTypeInfo channel_type) {
|
||||
#if VERSION_MAJOR < 4
|
||||
return call("_get_channel_index_info", channel_type);
|
||||
#else
|
||||
int ret;
|
||||
if (GDVIRTUAL_CALL(_get_channel_index_info, channel_type, ret)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
VoxelWorld::VoxelWorld() {
|
||||
@ -951,7 +1025,11 @@ void VoxelWorld::_notification(int p_what) {
|
||||
#endif
|
||||
_is_priority_generation = false;
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
call("_generation_finished");
|
||||
#else
|
||||
GDVIRTUAL_CALL(_generation_finished);
|
||||
#endif
|
||||
|
||||
emit_signal("generation_finished");
|
||||
|
||||
@ -962,7 +1040,11 @@ void VoxelWorld::_notification(int p_what) {
|
||||
Ref<VoxelChunk> chunk = _generating.get(i);
|
||||
|
||||
if (!chunk.is_valid() || !chunk->get_is_generating()) {
|
||||
#if VERSION_MAJOR < 4
|
||||
_generating.remove(i);
|
||||
#else
|
||||
_generating.remove_at(i);
|
||||
#endif
|
||||
--i;
|
||||
continue;
|
||||
}
|
||||
@ -976,7 +1058,12 @@ void VoxelWorld::_notification(int p_what) {
|
||||
|
||||
while (_generating.size() < _max_concurrent_generations && _generation_queue.size() != 0) {
|
||||
Ref<VoxelChunk> chunk = _generation_queue.get(0);
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
_generation_queue.remove(0);
|
||||
#else
|
||||
_generation_queue.remove_at(0);
|
||||
#endif
|
||||
|
||||
ERR_FAIL_COND(!chunk.is_valid());
|
||||
|
||||
@ -1112,7 +1199,11 @@ void VoxelWorld::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("voxel_structures_set"), &VoxelWorld::voxel_structures_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "voxel_structures", PROPERTY_HINT_NONE, "17/17:VoxelStructure", PROPERTY_USAGE_DEFAULT, "VoxelStructure"), "voxel_structures_set", "voxel_structures_get");
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
BIND_VMETHOD(MethodInfo("_chunk_added", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
|
||||
#else
|
||||
GDVIRTUAL_BIND(_chunk_added, "chunk");
|
||||
#endif
|
||||
|
||||
ClassDB::bind_method(D_METHOD("chunk_add", "chunk", "x", "y", "z"), &VoxelWorld::chunk_add);
|
||||
ClassDB::bind_method(D_METHOD("chunk_has", "x", "y", "z"), &VoxelWorld::chunk_has);
|
||||
@ -1140,11 +1231,19 @@ void VoxelWorld::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("generation_get_size"), &VoxelWorld::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, "VoxelChunk"), "_create_chunk", PropertyInfo(Variant::INT, "x"), PropertyInfo(Variant::INT, "y"), PropertyInfo(Variant::INT, "z"), PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
|
||||
BIND_VMETHOD(MethodInfo("_prepare_chunk_for_generation", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
|
||||
BIND_VMETHOD(MethodInfo("_generate_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
|
||||
#else
|
||||
GDVIRTUAL_BIND(_generation_finished);
|
||||
GDVIRTUAL_BIND(_create_chunk, "chunk", "x", "y", "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", "y", "z"), &VoxelWorld::chunk_get_or_create);
|
||||
ClassDB::bind_method(D_METHOD("chunk_create", "x", "y", "z"), &VoxelWorld::chunk_create);
|
||||
@ -1176,17 +1275,25 @@ void VoxelWorld::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_chunk_at_world_position", "world_position"), &VoxelWorld::get_chunk_at_world_position);
|
||||
ClassDB::bind_method(D_METHOD("get_or_create_chunk_at_world_position", "world_position"), &VoxelWorld::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"), &VoxelWorld::get_channel_index_info);
|
||||
ClassDB::bind_method(D_METHOD("_get_channel_index_info", "channel_type"), &VoxelWorld::_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"), &VoxelWorld::set_voxel_with_tool);
|
||||
ClassDB::bind_method(D_METHOD("_set_voxel_with_tool", "mode_add", "hit_position", "hit_normal", "selected_voxel", "isolevel"), &VoxelWorld::_set_voxel_with_tool);
|
||||
|
@ -191,6 +191,20 @@ public:
|
||||
|
||||
int get_channel_index_info(const ChannelTypeInfo channel_type);
|
||||
|
||||
#if VERSION_MAJOR >= 4
|
||||
GDVIRTUAL1(_chunk_added, Ref<VoxelChunk>);
|
||||
|
||||
GDVIRTUAL0(_generation_finished);
|
||||
|
||||
GDVIRTUAL4R(Ref<VoxelChunk>, _create_chunk, int, int, int, Ref<VoxelChunk>);
|
||||
GDVIRTUAL1(_prepare_chunk_for_generation, Ref<VoxelChunk>);
|
||||
GDVIRTUAL1(_generate_chunk, Ref<VoxelChunk>);
|
||||
|
||||
GDVIRTUAL1R(int, _get_channel_index_info, int);
|
||||
|
||||
GDVIRTUAL5(_set_voxel_with_tool, bool, Vector3, Vector3, int, int);
|
||||
#endif
|
||||
|
||||
VoxelWorld();
|
||||
~VoxelWorld();
|
||||
|
||||
|
@ -42,6 +42,7 @@ SOFTWARE.
|
||||
#include spatial_editor_plugin_h
|
||||
#include camera_h
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
bool VoxelWorldEditor::forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event) {
|
||||
if (!_world || !_world->get_editable()) {
|
||||
return false;
|
||||
@ -68,6 +69,39 @@ bool VoxelWorldEditor::forward_spatial_input_event(Camera *p_camera, const Ref<I
|
||||
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
EditorPlugin::AfterGUIInput VoxelWorldEditor::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<VoxelmanLibrary> 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 VoxelWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click) {
|
||||
if (!spatial_editor || !_world || !_world->is_inside_world())
|
||||
@ -85,7 +119,18 @@ bool VoxelWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_point,
|
||||
|
||||
PhysicsDirectSpaceState::RayResult res;
|
||||
|
||||
#if VERSION_MAJOR >= 4
|
||||
PhysicsDirectSpaceState::RayParameters keyparams;
|
||||
keyparams.from = from;
|
||||
keyparams.to = to;
|
||||
#endif
|
||||
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
if (ss->intersect_ray(from, to, res)) {
|
||||
#else
|
||||
if (ss->intersect_ray(keyparams, res)) {
|
||||
#endif
|
||||
int selected_voxel = 0;
|
||||
int channel = 0;
|
||||
|
||||
@ -158,7 +203,11 @@ void VoxelWorldEditor::edit(VoxelWorld *p_world) {
|
||||
|
||||
Button *button = memnew(Button);
|
||||
button->set_text(text);
|
||||
#if VERSION_MAJOR < 4
|
||||
button->set_text_align(Button::ALIGN_LEFT);
|
||||
#else
|
||||
button->set_text_alignment(HorizontalAlignment::HORIZONTAL_ALIGNMENT_LEFT);
|
||||
#endif
|
||||
button->set_meta("index", i);
|
||||
button->set_toggle_mode(true);
|
||||
button->set_button_group(_surfaces_button_group);
|
||||
@ -196,10 +245,18 @@ VoxelWorldEditor::VoxelWorldEditor(EditorNode *p_editor) {
|
||||
|
||||
spatial_editor_hb = memnew(HBoxContainer);
|
||||
spatial_editor_hb->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
#if VERSION_MAJOR < 4
|
||||
spatial_editor_hb->set_alignment(BoxContainer::ALIGN_BEGIN);
|
||||
#else
|
||||
spatial_editor_hb->set_alignment(BoxContainer::ALIGNMENT_BEGIN);
|
||||
#endif
|
||||
SpatialEditor::get_singleton()->add_control_to_menu_panel(spatial_editor_hb);
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
_tool_button_group.instance();
|
||||
#else
|
||||
_tool_button_group.instantiate();
|
||||
#endif
|
||||
|
||||
ToolButton *add_button = memnew(ToolButton);
|
||||
add_button->set_text("Add");
|
||||
@ -210,7 +267,12 @@ VoxelWorldEditor::VoxelWorldEditor(EditorNode *p_editor) {
|
||||
|
||||
add_button->CONNECT("button_up", this, VoxelWorldEditor, _on_tool_button_pressed);
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
add_button->set_shortcut(ED_SHORTCUT("voxelman_world_editor/add_mode", "Add Mode", KEY_A));
|
||||
#else
|
||||
add_button->set_shortcut(ED_SHORTCUT("voxelman_world_editor/add_mode", "Add Mode", Key::A));
|
||||
#endif
|
||||
|
||||
spatial_editor_hb->add_child(add_button);
|
||||
|
||||
ToolButton *remove_button = memnew(ToolButton);
|
||||
@ -221,7 +283,12 @@ VoxelWorldEditor::VoxelWorldEditor(EditorNode *p_editor) {
|
||||
|
||||
remove_button->CONNECT("button_up", this, VoxelWorldEditor, _on_tool_button_pressed);
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
remove_button->set_shortcut(ED_SHORTCUT("voxelman_world_editor/remove_mode", "Remove Mode", KEY_S));
|
||||
#else
|
||||
remove_button->set_shortcut(ED_SHORTCUT("voxelman_world_editor/remove_mode", "Remove Mode", Key::S));
|
||||
#endif
|
||||
|
||||
spatial_editor_hb->add_child(remove_button);
|
||||
|
||||
ToolButton *insert_buton = memnew(ToolButton);
|
||||
@ -229,7 +296,12 @@ VoxelWorldEditor::VoxelWorldEditor(EditorNode *p_editor) {
|
||||
|
||||
insert_buton->CONNECT("button_up", this, VoxelWorldEditor, _on_insert_block_at_camera_button_pressed);
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
insert_buton->set_shortcut(ED_SHORTCUT("voxelman_world_editor/instert_block_at_camera", "Insert at camera", KEY_B));
|
||||
#else
|
||||
insert_buton->set_shortcut(ED_SHORTCUT("voxelman_world_editor/instert_block_at_camera", "Insert at camera", Key::B));
|
||||
#endif
|
||||
|
||||
spatial_editor_hb->add_child(insert_buton);
|
||||
|
||||
set_custom_minimum_size(Size2(200 * EDSCALE, 0));
|
||||
@ -256,7 +328,11 @@ VoxelWorldEditor::VoxelWorldEditor(EditorNode *p_editor) {
|
||||
scs->add_child(_surfaces_vbox_container);
|
||||
_surfaces_vbox_container->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
_surfaces_button_group.instance();
|
||||
#else
|
||||
_surfaces_button_group.instantiate();
|
||||
#endif
|
||||
}
|
||||
VoxelWorldEditor::~VoxelWorldEditor() {
|
||||
_world = NULL;
|
||||
@ -299,7 +375,12 @@ void VoxelWorldEditor::_on_insert_block_at_camera_button_pressed() {
|
||||
if (!vp)
|
||||
return;
|
||||
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
Camera *cam = vp->get_camera();
|
||||
#else
|
||||
Camera *cam = vp->get_camera_3d();
|
||||
#endif
|
||||
|
||||
if (!cam)
|
||||
return;
|
||||
@ -337,7 +418,7 @@ void VoxelWorldEditorPlugin::_notification(int p_what) {
|
||||
case 1: { // Right.
|
||||
SpatialEditor::get_singleton()->get_palette_split()->move_child(voxel_world_editor, 1);
|
||||
} break;
|
||||
#else
|
||||
#else
|
||||
case 0: { // Left.
|
||||
SpatialEditor::get_singleton()->move_control_to_left_panel(voxel_world_editor);
|
||||
} break;
|
||||
|
@ -28,6 +28,11 @@ SOFTWARE.
|
||||
|
||||
#include "../defines.h"
|
||||
|
||||
#if VERSION_MAJOR > 3
|
||||
#include "core/math/transform_3d.h"
|
||||
typedef class Transform3D Transform;
|
||||
#endif
|
||||
|
||||
class VoxelWorld;
|
||||
class SpatialEditorPlugin;
|
||||
|
||||
@ -41,7 +46,11 @@ public:
|
||||
};
|
||||
|
||||
public:
|
||||
#if VERSION_MAJOR < 4
|
||||
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(VoxelWorld *p_world);
|
||||
bool do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click);
|
||||
@ -91,7 +100,13 @@ protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
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);
|
||||
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);
|
||||
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 "VoxelWorldEditor"; }
|
||||
bool has_main_screen() const { return false; }
|
||||
virtual void edit(Object *p_object);
|
||||
|
Loading…
Reference in New Issue
Block a user