Fix build for 4.0.

This commit is contained in:
Relintai 2020-04-09 12:34:39 +02:00
parent 9fe51572f4
commit 073e1aeb97
25 changed files with 331 additions and 35 deletions

View File

@ -24,6 +24,14 @@ SOFTWARE.
#include "voxelman_library_merger.h"
#include "core/version.h"
#if VERSION_MAJOR >= 4
#define Texture Texture2D
typedef class StandardMaterial3D SpatialMaterial;
#endif
Ref<AtlasTexture> VoxelSurfaceMerger::get_region(const VoxelSurfaceSides side) {
return _regions[side];
}
@ -41,7 +49,7 @@ void VoxelSurfaceMerger::set_texture(const VoxelSurfaceSides side, Ref<Texture>
void VoxelSurfaceMerger::refresh_rects() {
VoxelmanLibraryMerger *lib = Object::cast_to<VoxelmanLibraryMerger>(_library);
ERR_FAIL_COND(!ObjectDB::instance_validate(lib));
ERR_FAIL_COND(lib == NULL);
for (int i = 0; i < VOXEL_SIDES_COUNT; ++i) {
if (!_regions[i].is_valid()) {

View File

@ -29,6 +29,12 @@ SOFTWARE.
#include "../../texture_packer/texture_packer.h"
#include "core/version.h"
#if VERSION_MAJOR >= 4
#define Texture Texture2D
#endif
class VoxelSurfaceMerger : public VoxelSurface {
GDCLASS(VoxelSurfaceMerger, VoxelSurface)

View File

@ -49,7 +49,7 @@ void VoxelSurfaceSimple::set_atlas_y(const VoxelSurfaceSides side, int value) {
void VoxelSurfaceSimple::refresh_rects() {
VoxelmanLibrarySimple *lib = Object::cast_to<VoxelmanLibrarySimple>(_library);
ERR_FAIL_COND(!ObjectDB::instance_validate(lib));
ERR_FAIL_COND(lib == NULL);
for (int i = 0; i < VOXEL_SIDES_COUNT; ++i) {
float culomn = 1.0 / static_cast<float>(lib->get_atlas_columns());

View File

@ -24,6 +24,8 @@ SOFTWARE.
#include "scene/resources/packed_scene.h"
#include "core/version.h"
//Materials
Ref<Material> VoxelmanLibrary::get_material(const int index) {
ERR_FAIL_INDEX_V(index, _materials.size(), Ref<VoxelSurface>(NULL));
@ -58,7 +60,11 @@ void VoxelmanLibrary::clear_materials() {
Vector<Variant> VoxelmanLibrary::get_materials() {
Vector<Variant> r;
for (int i = 0; i < _materials.size(); i++) {
#if VERSION_MAJOR < 4
r.push_back(_materials[i].get_ref_ptr());
#else
r.push_back(_materials[i]);
#endif
}
return r;
}
@ -107,7 +113,11 @@ void VoxelmanLibrary::clear_liquid_materials() {
Vector<Variant> VoxelmanLibrary::get_liquid_materials() {
Vector<Variant> r;
for (int i = 0; i < _liquid_materials.size(); i++) {
#if VERSION_MAJOR < 4
r.push_back(_liquid_materials[i].get_ref_ptr());
#else
r.push_back(_liquid_materials[i]);
#endif
}
return r;
}

View File

@ -23,9 +23,14 @@ SOFTWARE.
#include "voxelman_library_merger.h"
#include "scene/resources/packed_scene.h"
#include "scene/resources/texture.h"
#include "core/version.h"
#if VERSION_MAJOR >= 4
#define SpatialMaterial StandardMaterial3D
#endif
int VoxelmanLibraryMerger::get_texture_flags() const {
return _packer->get_texture_flags();
}
@ -130,7 +135,11 @@ void VoxelmanLibraryMerger::clear_surfaces() {
Vector<Variant> VoxelmanLibraryMerger::get_voxel_surfaces() {
Vector<Variant> r;
for (int i = 0; i < _voxel_surfaces.size(); i++) {
#if VERSION_MAJOR < 4
r.push_back(_voxel_surfaces[i].get_ref_ptr());
#else
r.push_back(_voxel_surfaces[i]);
#endif
}
return r;
}
@ -208,7 +217,11 @@ void VoxelmanLibraryMerger::clear_liquid_surfaces() {
Vector<Variant> VoxelmanLibraryMerger::get_liquid_voxel_surfaces() {
Vector<Variant> r;
for (int i = 0; i < _liquid_surfaces.size(); i++) {
#if VERSION_MAJOR < 4
r.push_back(_liquid_surfaces[i].get_ref_ptr());
#else
r.push_back(_liquid_surfaces[i]);
#endif
}
return r;
}
@ -373,7 +386,13 @@ void VoxelmanLibraryMerger::_setup_material_albedo(int material_index, Ref<Textu
VoxelmanLibraryMerger::VoxelmanLibraryMerger() {
_packer.instance();
#if VERSION_MAJOR < 4
_packer->set_texture_flags(Texture::FLAG_MIPMAPS | Texture::FLAG_FILTER);
#else
//nyi
#endif
_packer->set_max_atlas_size(1024);
_packer->set_keep_original_atlases(false);
_packer->set_margin(0);

View File

@ -22,6 +22,8 @@ SOFTWARE.
#include "voxelman_library_simple.h"
#include "core/version.h"
int VoxelmanLibrarySimple::get_atlas_columns() const {
return _atlas_columns;
}
@ -89,7 +91,11 @@ void VoxelmanLibrarySimple::clear_surfaces() {
Vector<Variant> VoxelmanLibrarySimple::get_voxel_surfaces() {
Vector<Variant> r;
for (int i = 0; i < _voxel_surfaces.size(); i++) {
#if VERSION_MAJOR < 4
r.push_back(_voxel_surfaces[i].get_ref_ptr());
#else
r.push_back(_voxel_surfaces[i]);
#endif
}
return r;
}
@ -158,7 +164,11 @@ void VoxelmanLibrarySimple::clear_liquid_surfaces() {
Vector<Variant> VoxelmanLibrarySimple::get_liquid_voxel_surfaces() {
Vector<Variant> r;
for (int i = 0; i < _liquid_surfaces.size(); i++) {
#if VERSION_MAJOR < 4
r.push_back(_liquid_surfaces[i].get_ref_ptr());
#else
r.push_back(_liquid_surfaces[i]);
#endif
}
return r;
}

View File

@ -24,6 +24,16 @@ SOFTWARE.
#include "../../world/default/voxel_chunk_default.h"
#if VERSION_MAJOR < 4
#include "servers/visual_server.h"
#else
#include "servers/rendering_server.h"
typedef class RenderingServer VisualServer;
typedef class RenderingServer VS;
#endif
void VoxelMesherCubic::_add_chunk(Ref<VoxelChunk> p_chunk) {
Ref<VoxelChunkDefault> chunk = p_chunk;

View File

@ -24,6 +24,19 @@ SOFTWARE.
#include "../../world/default/voxel_chunk_default.h"
#if VERSION_MAJOR < 4
#include "servers/visual_server.h"
#include "scene/3d/mesh_instance.h"
#else
#include "servers/rendering_server.h"
typedef class RenderingServer VisualServer;
typedef class RenderingServer VS;
#include "scene/3d/mesh_instance_3d.h"
#endif
_FORCE_INLINE_ int VoxelMesherDefault::get_build_flags() const {
return _build_flags;
}

View File

@ -26,7 +26,16 @@ SOFTWARE.
#include "../../world/voxel_chunk.h"
#include "core/array.h"
#include "core/dictionary.h"
#include "core/version.h"
#if VERSION_MAJOR < 4
#include "servers/visual_server.h"
#else
#include "servers/rendering_server.h"
typedef class RenderingServer VisualServer;
#endif
int VoxelMesherUVTransvoxel::get_texture_scale() const {
return _texture_scale;

View File

@ -22,6 +22,23 @@ SOFTWARE.
#include "voxel_mesher.h"
#include "core/version.h"
#if VERSION_MAJOR < 4
#include "servers/visual_server.h"
#include "scene/3d/mesh_instance.h"
#else
#include "servers/rendering_server.h"
typedef class RenderingServer VisualServer;
typedef class RenderingServer VS;
#include "scene/3d/mesh_instance_3d.h"
#define REAL FLOAT
#endif
#include "../world/default/voxel_chunk_default.h"
#include "../world/voxel_chunk.h"
@ -150,13 +167,18 @@ Array VoxelMesher::build_mesh() {
{
PoolVector<Vector3> array;
array.resize(_vertices.size());
#if VERSION_MAJOR < 4
PoolVector<Vector3>::Write w = array.write();
#endif
for (int i = 0; i < _vertices.size(); ++i) {
array.set(i, _vertices[i].vertex);
}
#if VERSION_MAJOR < 4
w.release();
#endif
a[VisualServer::ARRAY_VERTEX] = array;
}
@ -167,65 +189,86 @@ Array VoxelMesher::build_mesh() {
{
PoolVector<Vector3> array;
array.resize(_vertices.size());
#if VERSION_MAJOR < 4
PoolVector<Vector3>::Write w = array.write();
#endif
for (int i = 0; i < _vertices.size(); ++i) {
array.set(i, _vertices[i].normal);
}
#if VERSION_MAJOR < 4
w.release();
#endif
a[VisualServer::ARRAY_NORMAL] = array;
}
if ((_format & VisualServer::ARRAY_FORMAT_COLOR) != 0) {
PoolVector<Color> array;
array.resize(_vertices.size());
#if VERSION_MAJOR < 4
PoolVector<Color>::Write w = array.write();
#endif
for (int i = 0; i < _vertices.size(); ++i) {
array.set(i, _vertices[i].color);
}
#if VERSION_MAJOR < 4
w.release();
#endif
a[VisualServer::ARRAY_COLOR] = array;
}
if ((_format & VisualServer::ARRAY_FORMAT_TEX_UV) != 0) {
PoolVector<Vector2> array;
array.resize(_vertices.size());
#if VERSION_MAJOR < 4
PoolVector<Vector2>::Write w = array.write();
#endif
for (int i = 0; i < _vertices.size(); ++i) {
array.set(i, _vertices[i].uv);
}
#if VERSION_MAJOR < 4
w.release();
#endif
a[VisualServer::ARRAY_TEX_UV] = array;
}
if ((_format & VisualServer::ARRAY_FORMAT_TEX_UV2) != 0) {
PoolVector<Vector2> array;
array.resize(_vertices.size());
#if VERSION_MAJOR < 4
PoolVector<Vector2>::Write w = array.write();
#endif
for (int i = 0; i < _vertices.size(); ++i) {
array.set(i, _vertices[i].uv2);
}
#if VERSION_MAJOR < 4
w.release();
#endif
a[VisualServer::ARRAY_TEX_UV2] = array;
}
if (_indices.size() > 0) {
PoolVector<int> array;
array.resize(_indices.size());
#if VERSION_MAJOR < 4
PoolVector<int>::Write w = array.write();
#endif
for (int i = 0; i < _indices.size(); ++i) {
array.set(i, _indices[i]);
}
#if VERSION_MAJOR < 4
w.release();
#endif
a[VisualServer::ARRAY_INDEX] = array;
}

View File

@ -23,18 +23,30 @@ SOFTWARE.
#ifndef VOXEL_TOOLS_H
#define VOXEL_TOOLS_H
#include "core/reference.h"
#include "core/version.h"
#if VERSION_MAJOR < 4
#include "core/pool_vector.h"
#else
#include "core/vector.h"
template <class N>
using PoolVector = Vector<N>;
typedef PackedByteArray PoolByteArray;
class MeshInstance3D;
typedef MeshInstance3D MeshInstance;
#endif
#include "core/color.h"
#include "core/math/rect2.h"
#include "core/math/vector2.h"
#include "core/math/vector3.h"
#include "core/pool_vector.h"
#include "core/reference.h"
#include "core/vector.h"
#include "scene/3d/immediate_geometry.h"
#include "scene/3d/mesh_instance.h"
#include "scene/3d/spatial.h"
#include "scene/main/node.h"
#include "scene/resources/concave_polygon_shape.h"
#include "scene/resources/material.h"
#include "scene/resources/mesh.h"

View File

@ -25,8 +25,17 @@ SOFTWARE.
#include "voxel_structure.h"
#include "core/hash_map.h"
#include "core/version.h"
#if VERSION_MAJOR < 4
#include "core/pool_vector.h"
#else
#include "core/vector.h"
typedef PackedByteArray PoolByteArray;
#endif
#include "core/hash_map.h"
#include "voxel_chunk.h"
class BlockVoxelStructure : public VoxelStructure {

View File

@ -24,6 +24,14 @@ SOFTWARE.
#include "../../meshers/blocky/voxel_mesher_blocky.h"
#include "core/version.h"
#if VERSION_MAJOR >= 4
#define POOL_BYTE_ARRAY PACKED_BYTE_ARRAY
#endif
VoxelChunkBlocky::VoxelChunkBlocky() {
}
@ -54,7 +62,7 @@ void VoxelChunkBlocky::_create_meshers() {
}
void VoxelChunkBlocky::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::POOL_BYTE_ARRAY, "data_channel"), "set_channel_compressed", "get_channel_compressed", 0);
ADD_PROPERTYI(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "data_channel"), "set_channel_compressed", "get_channel_compressed", 0);
//ClassDB::bind_method(D_METHOD("get_channel_compressed", "channel_index"), &VoxelChunk::get_channel_compressed);
//ClassDB::bind_method(D_METHOD("set_channel_compressed", "channel_index", "array"), &VoxelChunk::set_channel_compressed);

View File

@ -22,10 +22,25 @@ SOFTWARE.
#include "voxel_chunk_default.h"
#include "core/version.h"
#if VERSION_MAJOR < 4
#include "servers/visual_server.h"
#else
#include "servers/rendering_server.h"
typedef class RenderingServer VisualServer;
typedef class RenderingServer VS;
#include "servers/physics_server_3d.h"
typedef class PhysicsServer3D PhysicsServer;
typedef class StandardMaterial3D SpatialMaterial;
#endif
#include "../voxel_world.h"
#include "../../meshers/default/voxel_mesher_default.h"
#include "../../../opensimplex/open_simplex_noise.h"
const String VoxelChunkDefault::BINDING_STRING_ACTIVE_BUILD_PHASE_TYPE = "Normal,Process,Physics Process";
@ -706,7 +721,7 @@ void VoxelChunkDefault::create_debug_immediate_geometry() {
}
void VoxelChunkDefault::free_debug_immediate_geometry() {
if (ObjectDB::instance_validate(_debug_drawer)) {
if (_debug_drawer != NULL) {
_debug_drawer->queue_delete();
_debug_drawer = NULL;

View File

@ -25,7 +25,16 @@ SOFTWARE.
#include "../voxel_chunk.h"
#include "scene/3d/spatial.h"
#include "core/version.h"
#if VERSION_MAJOR < 4
#include "scene/3d/immediate_geometry.h"
#else
#include "scene/3d/immediate_geometry_3d.h"
typedef class ImmediateGeometry3D ImmediateGeometry;
#endif
#include "core/engine.h"
#include "core/os/mutex.h"
@ -34,12 +43,7 @@ SOFTWARE.
#include "core/ustring.h"
#include "core/array.h"
#include "core/pool_vector.h"
#include "scene/3d/collision_shape.h"
#include "scene/3d/mesh_instance.h"
#include "scene/3d/physics_body.h"
#include "scene/3d/spatial.h"
#include "scene/resources/concave_polygon_shape.h"
#include "scene/resources/packed_scene.h"
#include "../voxel_world.h"

View File

@ -22,6 +22,12 @@ SOFTWARE.
#include "environment_data.h"
#include "core/version.h"
#if VERSION_MAJOR >= 4
#define REAL FLOAT
#endif
Ref<Environment> EnvironmentData::get_environment() {
return _environment;
}

View File

@ -23,9 +23,19 @@ SOFTWARE.
#ifndef ENVIRONMENT_DATA_H
#define ENVIRONMENT_DATA_H
#include "core/version.h"
#if VERSION_MAJOR < 4
#include "scene/3d/light.h"
#else
#include "scene/3d/light_3d.h"
typedef class DirectionalLight3D DirectionalLight;
#endif
#include "core/color.h"
#include "core/resource.h"
#include "scene/3d/light.h"
#include "scene/3d/world_environment.h"
#include "scene/main/node.h"

View File

@ -26,6 +26,22 @@ SOFTWARE.
#include "../thirdparty/lz4/lz4.h"
#if VERSION_MAJOR < 4
#include "servers/visual_server.h"
#else
#include "servers/rendering_server.h"
typedef class RenderingServer VisualServer;
typedef class RenderingServer VS;
#define REAL FLOAT
typedef PackedVector3Array PoolVector3Array;
typedef PackedVector2Array PoolVector2Array;
typedef PackedColorArray PoolColorArray;
typedef PackedInt32Array PoolIntArray;
#endif
_FORCE_INLINE_ bool VoxelChunk::get_process() const {
return _is_processing;
}
@ -429,11 +445,15 @@ PoolByteArray VoxelChunk::get_channel_compressed(int channel_index) const {
int bound = LZ4_compressBound(size);
arr.resize(bound);
#if VERSION_MAJOR < 4
PoolByteArray::Write w = arr.write();
int ns = LZ4_compress_default(reinterpret_cast<char *>(ch), reinterpret_cast<char *>(w.ptr()), size, bound);
w.release();
#else
int ns = LZ4_compress_default(reinterpret_cast<char *>(ch), reinterpret_cast<char *>(arr.ptrw()), size, bound);
#endif
arr.resize(ns);
return arr;
@ -459,12 +479,19 @@ void VoxelChunk::set_channel_compressed(int channel_index, const PoolByteArray &
int ds = data.size();
#if VERSION_MAJOR < 4
PoolByteArray::Read r = data.read();
//We are not going to write to it
uint8_t *data_arr = const_cast<uint8_t *>(r.ptr());
LZ4_decompress_safe(reinterpret_cast<char *>(data_arr), reinterpret_cast<char *>(ch), ds, size);
#else
//We are not going to write to it
uint8_t *data_arr = const_cast<uint8_t *>(data.ptr());
LZ4_decompress_safe(reinterpret_cast<char *>(data_arr), reinterpret_cast<char *>(ch), ds, size);
#endif
}
_FORCE_INLINE_ int VoxelChunk::get_index(const int x, const int y, const int z) const {
@ -561,7 +588,9 @@ Array VoxelChunk::bake_mesh_array_uv(Array arr, Ref<Texture> tex, float mul_colo
PoolVector2Array uvs = arr[VisualServer::ARRAY_TEX_UV];
PoolColorArray colors = arr[VisualServer::ARRAY_COLOR];
#if VERSION_MAJOR < 4
img->lock();
#endif
for (int i = 0; i < uvs.size(); ++i) {
Vector2 uv = uvs[i];
@ -572,7 +601,9 @@ Array VoxelChunk::bake_mesh_array_uv(Array arr, Ref<Texture> tex, float mul_colo
colors.set(i, colors[i] * c * mul_color);
}
#if VERSION_MAJOR < 4
img->unlock();
#endif
arr[VisualServer::ARRAY_COLOR] = colors;

View File

@ -25,6 +25,14 @@ SOFTWARE.
#include "core/resource.h"
#include "core/version.h"
#if VERSION_MAJOR < 4
#include "core/pool_vector.h"
#else
#include "core/vector.h"
#endif
#include "core/engine.h"
#include "core/os/mutex.h"
#include "core/os/thread.h"
@ -32,12 +40,7 @@ SOFTWARE.
#include "core/ustring.h"
#include "core/array.h"
#include "core/pool_vector.h"
#include "scene/3d/collision_shape.h"
#include "scene/3d/mesh_instance.h"
#include "scene/3d/physics_body.h"
#include "scene/3d/spatial.h"
#include "scene/resources/concave_polygon_shape.h"
#include "scene/resources/packed_scene.h"
#include "voxel_world.h"
@ -52,8 +55,15 @@ SOFTWARE.
#include "voxel_chunk_prop_data.h"
#include "core/version.h"
#if VERSION_MAJOR >= 4
#define Texture Texture2D
#endif
class VoxelWorld;
class VoxelChunk : public Resource {
GDCLASS(VoxelChunk, Resource);

View File

@ -58,7 +58,7 @@ void VoxelStructure::set_world_position_z(const int value) {
}
void VoxelStructure::write_to_chunk(Node *chunk) {
ERR_FAIL_COND(!ObjectDB::instance_validate(Object::cast_to<VoxelChunk>(chunk)));
ERR_FAIL_COND(Object::cast_to<VoxelChunk>(chunk) == NULL);
if (has_method("_write_to_chunk"))
call("_write_to_chunk", chunk);

View File

@ -25,9 +25,19 @@ SOFTWARE.
#include "core/reference.h"
#include "core/version.h"
#if VERSION_MAJOR < 4
#include "core/pool_vector.h"
#else
#include "core/vector.h"
template <class N>
using PoolVector = Vector<N>;
#endif
#include "core/hash_map.h"
#include "core/math/aabb.h"
#include "core/pool_vector.h"
#include "voxel_chunk.h"
class VoxelStructure : public Reference {

View File

@ -24,6 +24,12 @@ SOFTWARE.
#include "voxel_chunk.h"
#include "core/version.h"
#if VERSION_MAJOR >= 4
#define REAL FLOAT
#endif
bool VoxelWorld::get_editable() const {
return _editable;
}
@ -361,7 +367,11 @@ void VoxelWorld::on_chunk_mesh_generation_finished(Ref<VoxelChunk> p_chunk) {
Vector<Variant> VoxelWorld::get_chunks() {
Vector<Variant> r;
for (int i = 0; i < _chunks_vector.size(); i++) {
#if VERSION_MAJOR < 4
r.push_back(_chunks_vector[i].get_ref_ptr());
#else
r.push_back(_chunks_vector[i]);
#endif
}
return r;
}

View File

@ -23,9 +23,21 @@ SOFTWARE.
#ifndef VOXEL_WORLD_H
#define VOXEL_WORLD_H
#include "core/version.h"
#if VERSION_MAJOR < 4
#include "scene/3d/navigation.h"
#include "scene/3d/spatial.h"
#else
#include "scene/3d/navigation_3d.h"
#include "scene/3d/node_3d.h"
typedef class Navigation3D Navigation;
typedef class Node3D Spatial;
#endif
#include "core/engine.h"
#include "core/hash_map.h"
#include "scene/3d/navigation.h"
#include "../areas/world_area.h"
#include "../level_generator/voxelman_level_generator.h"

View File

@ -22,11 +22,13 @@ SOFTWARE.
#include "voxel_world_editor.h"
#include "core/os/input.h"
#include "core/version.h"
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "editor/plugins/spatial_editor_plugin.h"
#include "scene/3d/camera.h"
#include "voxel_world.h"
#include "core/math/geometry.h"
@ -34,6 +36,26 @@ SOFTWARE.
#include "voxel_chunk.h"
#include "core/version.h"
#if VERSION_MAJOR < 4
#include "core/os/input.h"
#include "editor/plugins/spatial_editor_plugin.h"
#include "scene/3d/camera.h"
#else
#include "core/input/input_event.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/camera_3d.h"
#define PhysicsDirectSpaceState PhysicsDirectSpaceState3D
#define SpatialEditor Node3DEditor
#define SpatialEditorPlugin Node3DEditorPlugin
#endif
bool VoxelWorldEditor::forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event) {
if (!_world || !_world->get_editable()) {
return false;

View File

@ -26,6 +26,15 @@ SOFTWARE.
#include "editor/editor_node.h"
#include "editor/editor_plugin.h"
#include "core/version.h"
#if VERSION_MAJOR >= 4
#define Camera Camera3D
#define PhysicsDirectSpaceState PhysicsDirectSpaceState3D
#define SpatialEditor Node3DEditor
#define SpatialEditorPlugin Node3DEditorPlugin
#endif
class VoxelWorld;
class SpatialEditorPlugin;