2020-01-31 19:52:37 +01:00
|
|
|
/*
|
|
|
|
Copyright (c) 2019-2020 Péter Magyar
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2019-06-07 01:33:41 +02:00
|
|
|
#include "voxel_world.h"
|
|
|
|
|
2019-08-12 20:40:05 +02:00
|
|
|
#include "voxel_chunk.h"
|
2020-04-16 13:40:39 +02:00
|
|
|
#include "voxel_structure.h"
|
2019-08-12 20:40:05 +02:00
|
|
|
|
2020-05-23 10:34:47 +02:00
|
|
|
#include "../defines.h"
|
2020-04-09 12:34:39 +02:00
|
|
|
|
2020-07-07 02:22:45 +02:00
|
|
|
#if PROPS_PRESENT
|
|
|
|
#include "../../props/props/prop_data_entry.h"
|
|
|
|
#include "../../props/props/prop_data_light.h"
|
|
|
|
#include "../../props/props/prop_data_prop.h"
|
|
|
|
#include "../../props/props/prop_data_scene.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MESH_DATA_RESOURCE_PRESENT
|
|
|
|
#include "../../mesh_data_resource/props/prop_data_mesh_data.h"
|
|
|
|
#endif
|
|
|
|
|
2020-04-16 21:59:30 +02:00
|
|
|
const String VoxelWorld::BINDING_STRING_CHANNEL_TYPE_INFO = "Type,Isolevel,Liquid,Liquid Level";
|
|
|
|
|
2020-03-31 13:25:31 +02:00
|
|
|
bool VoxelWorld::get_editable() const {
|
|
|
|
return _editable;
|
|
|
|
}
|
|
|
|
void VoxelWorld::set_editable(const bool value) {
|
|
|
|
_editable = value;
|
|
|
|
}
|
|
|
|
|
2019-08-12 13:12:42 +02:00
|
|
|
int VoxelWorld::get_chunk_size_x() const {
|
2019-11-18 22:22:41 +01:00
|
|
|
return _chunk_size_x;
|
2019-08-12 13:12:42 +02:00
|
|
|
}
|
|
|
|
void VoxelWorld::set_chunk_size_x(const int value) {
|
2019-11-18 22:22:41 +01:00
|
|
|
_chunk_size_x = value;
|
2019-08-12 13:12:42 +02:00
|
|
|
}
|
2019-08-12 20:40:05 +02:00
|
|
|
|
2019-08-12 13:12:42 +02:00
|
|
|
int VoxelWorld::get_chunk_size_y() const {
|
2019-11-18 22:22:41 +01:00
|
|
|
return _chunk_size_y;
|
2019-08-12 13:12:42 +02:00
|
|
|
}
|
|
|
|
void VoxelWorld::set_chunk_size_y(const int value) {
|
2019-11-18 22:22:41 +01:00
|
|
|
_chunk_size_y = value;
|
2019-08-12 13:12:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int VoxelWorld::get_chunk_size_z() const {
|
2019-11-18 22:22:41 +01:00
|
|
|
return _chunk_size_z;
|
2019-08-12 13:12:42 +02:00
|
|
|
}
|
|
|
|
void VoxelWorld::set_chunk_size_z(const int value) {
|
2019-11-18 22:22:41 +01:00
|
|
|
_chunk_size_z = value;
|
2019-08-12 13:12:42 +02:00
|
|
|
}
|
|
|
|
|
2020-02-14 03:19:15 +01:00
|
|
|
int VoxelWorld::get_data_margin_start() const {
|
|
|
|
return _data_margin_start;
|
|
|
|
}
|
|
|
|
void VoxelWorld::set_data_margin_start(const int value) {
|
|
|
|
_data_margin_start = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
int VoxelWorld::get_data_margin_end() const {
|
|
|
|
return _data_margin_end;
|
|
|
|
}
|
|
|
|
void VoxelWorld::set_data_margin_end(const int value) {
|
|
|
|
_data_margin_end = value;
|
|
|
|
}
|
|
|
|
|
2019-11-19 14:42:21 +01:00
|
|
|
int VoxelWorld::get_current_seed() const {
|
|
|
|
return _current_seed;
|
|
|
|
}
|
|
|
|
void VoxelWorld::set_current_seed(const int value) {
|
|
|
|
_current_seed = value;
|
|
|
|
}
|
|
|
|
|
2020-04-16 17:10:04 +02:00
|
|
|
bool VoxelWorld::get_use_threads() const {
|
2019-11-19 14:42:21 +01:00
|
|
|
return _use_threads;
|
|
|
|
}
|
2020-04-16 17:10:04 +02:00
|
|
|
void VoxelWorld::set_use_threads(const bool value) {
|
2019-11-19 14:42:21 +01:00
|
|
|
_use_threads = OS::get_singleton()->can_use_threads() ? value : false;
|
2020-04-18 02:15:01 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < get_chunk_count(); ++i) {
|
|
|
|
Ref<VoxelChunk> c = get_chunk_index(i);
|
|
|
|
|
|
|
|
if (!c.is_valid())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
c->set_is_build_threaded(_use_threads);
|
|
|
|
}
|
2019-11-19 14:42:21 +01:00
|
|
|
}
|
|
|
|
|
2020-03-31 13:32:06 +02:00
|
|
|
int VoxelWorld::get_max_concurrent_generations() const {
|
2019-11-19 14:42:21 +01:00
|
|
|
return _max_concurrent_generations;
|
|
|
|
}
|
2020-03-31 13:32:06 +02:00
|
|
|
void VoxelWorld::set_max_concurrent_generations(const int value) {
|
2019-11-19 14:42:21 +01:00
|
|
|
_max_concurrent_generations = OS::get_singleton()->can_use_threads() ? value : 1;
|
|
|
|
}
|
|
|
|
|
2020-03-31 13:32:06 +02:00
|
|
|
int VoxelWorld::get_max_frame_chunk_build_steps() const {
|
2020-03-04 14:59:34 +01:00
|
|
|
return _max_frame_chunk_build_steps;
|
|
|
|
}
|
2020-03-31 13:32:06 +02:00
|
|
|
void VoxelWorld::set_max_frame_chunk_build_steps(const int value) {
|
2020-03-04 14:59:34 +01:00
|
|
|
_max_frame_chunk_build_steps = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<VoxelmanLibrary> VoxelWorld::get_library() {
|
2019-08-12 20:40:05 +02:00
|
|
|
return _library;
|
|
|
|
}
|
2020-04-16 17:10:04 +02:00
|
|
|
void VoxelWorld::set_library(const Ref<VoxelmanLibrary> &library) {
|
2019-08-12 20:40:05 +02:00
|
|
|
_library = library;
|
2020-04-18 02:15:01 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < get_chunk_count(); ++i) {
|
|
|
|
Ref<VoxelChunk> c = get_chunk_index(i);
|
|
|
|
|
|
|
|
if (!c.is_valid())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
c->set_library(_library);
|
|
|
|
}
|
2019-08-12 13:12:42 +02:00
|
|
|
}
|
2019-08-12 20:40:05 +02:00
|
|
|
|
2019-09-03 13:52:32 +02:00
|
|
|
Ref<VoxelmanLevelGenerator> VoxelWorld::get_level_generator() const {
|
2019-11-06 03:37:22 +01:00
|
|
|
return _level_generator;
|
2019-09-03 13:52:32 +02:00
|
|
|
}
|
2020-04-16 17:10:04 +02:00
|
|
|
void VoxelWorld::set_level_generator(const Ref<VoxelmanLevelGenerator> &level_generator) {
|
2019-11-06 03:37:22 +01:00
|
|
|
_level_generator = level_generator;
|
2019-09-03 13:52:32 +02:00
|
|
|
}
|
|
|
|
|
2019-08-12 20:40:05 +02:00
|
|
|
float VoxelWorld::get_voxel_scale() const {
|
|
|
|
return _voxel_scale;
|
|
|
|
}
|
|
|
|
void VoxelWorld::set_voxel_scale(const float value) {
|
|
|
|
_voxel_scale = value;
|
2020-04-18 02:15:01 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < get_chunk_count(); ++i) {
|
|
|
|
Ref<VoxelChunk> c = get_chunk_index(i);
|
|
|
|
|
|
|
|
if (!c.is_valid())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
c->set_voxel_scale(_voxel_scale);
|
|
|
|
}
|
2019-08-12 20:40:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int VoxelWorld::get_chunk_spawn_range() const {
|
|
|
|
return _chunk_spawn_range;
|
|
|
|
}
|
|
|
|
void VoxelWorld::set_chunk_spawn_range(const int value) {
|
|
|
|
_chunk_spawn_range = value;
|
2019-08-12 13:12:42 +02:00
|
|
|
}
|
|
|
|
|
2020-04-16 17:10:04 +02:00
|
|
|
NodePath VoxelWorld::get_player_path() const {
|
2019-06-07 01:33:41 +02:00
|
|
|
return _player_path;
|
|
|
|
}
|
|
|
|
|
2020-04-16 17:10:04 +02:00
|
|
|
void VoxelWorld::set_player_path(const NodePath &player_path) {
|
2019-06-07 01:33:41 +02:00
|
|
|
_player_path = player_path;
|
|
|
|
}
|
|
|
|
|
2019-08-12 20:40:05 +02:00
|
|
|
Spatial *VoxelWorld::get_player() const {
|
|
|
|
return _player;
|
|
|
|
}
|
|
|
|
void VoxelWorld::set_player(Spatial *player) {
|
|
|
|
_player = player;
|
|
|
|
}
|
|
|
|
void VoxelWorld::set_player_bind(Node *player) {
|
|
|
|
set_player(Object::cast_to<Spatial>(player));
|
|
|
|
}
|
|
|
|
|
2019-11-10 01:03:48 +01:00
|
|
|
Ref<WorldArea> VoxelWorld::get_world_area(const int index) const {
|
|
|
|
ERR_FAIL_INDEX_V(index, _world_areas.size(), Ref<WorldArea>());
|
|
|
|
|
|
|
|
return _world_areas.get(index);
|
|
|
|
}
|
2020-04-16 13:40:39 +02:00
|
|
|
void VoxelWorld::add_world_area(const Ref<WorldArea> &area) {
|
2019-11-10 01:03:48 +01:00
|
|
|
_world_areas.push_back(area);
|
|
|
|
}
|
|
|
|
void VoxelWorld::remove_world_area(const int index) {
|
|
|
|
ERR_FAIL_INDEX(index, _world_areas.size());
|
|
|
|
|
|
|
|
_world_areas.remove(index);
|
|
|
|
}
|
|
|
|
void VoxelWorld::clear_world_areas() {
|
|
|
|
_world_areas.clear();
|
|
|
|
}
|
|
|
|
int VoxelWorld::get_world_area_count() const {
|
|
|
|
return _world_areas.size();
|
|
|
|
}
|
|
|
|
|
2020-04-16 13:40:39 +02:00
|
|
|
//Voxel Structures
|
|
|
|
|
|
|
|
Ref<VoxelStructure> VoxelWorld::get_voxel_structure(const int index) const {
|
2020-04-20 18:19:33 +02:00
|
|
|
ERR_FAIL_INDEX_V(index, _voxel_structures.size(), Ref<VoxelStructure>());
|
2020-04-16 13:40:39 +02:00
|
|
|
|
|
|
|
return _voxel_structures.get(index);
|
|
|
|
}
|
|
|
|
void VoxelWorld::add_voxel_structure(const Ref<VoxelStructure> &structure) {
|
|
|
|
_voxel_structures.push_back(structure);
|
|
|
|
}
|
|
|
|
void VoxelWorld::remove_voxel_structure(const Ref<VoxelStructure> &structure) {
|
|
|
|
if (!structure.is_valid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
int index = _voxel_structures.find(structure);
|
|
|
|
|
|
|
|
if (index != -1)
|
|
|
|
_voxel_structures.remove(index);
|
|
|
|
}
|
|
|
|
void VoxelWorld::remove_voxel_structure_index(const int index) {
|
|
|
|
ERR_FAIL_INDEX(index, _voxel_structures.size());
|
|
|
|
|
|
|
|
_voxel_structures.remove(index);
|
|
|
|
}
|
|
|
|
void VoxelWorld::clear_voxel_structures() {
|
|
|
|
_voxel_structures.clear();
|
|
|
|
}
|
|
|
|
int VoxelWorld::get_voxel_structure_count() const {
|
|
|
|
return _voxel_structures.size();
|
|
|
|
}
|
|
|
|
void VoxelWorld::add_voxel_structure_at_position(Ref<VoxelStructure> structure, const Vector3 &world_position) {
|
|
|
|
ERR_FAIL_COND(!structure.is_valid());
|
|
|
|
|
|
|
|
structure->set_position_x(static_cast<int>(world_position.x / _voxel_scale));
|
|
|
|
structure->set_position_y(static_cast<int>(world_position.y / _voxel_scale));
|
|
|
|
structure->set_position_z(static_cast<int>(world_position.z / _voxel_scale));
|
|
|
|
|
|
|
|
add_voxel_structure(structure);
|
|
|
|
}
|
|
|
|
|
2020-04-16 14:07:10 +02:00
|
|
|
Vector<Variant> VoxelWorld::get_voxel_structures() {
|
2020-05-23 10:34:47 +02:00
|
|
|
VARIANT_ARRAY_GET(_voxel_structures);
|
2020-04-16 14:07:10 +02:00
|
|
|
}
|
|
|
|
void VoxelWorld::set_voxel_structures(const Vector<Variant> &structures) {
|
|
|
|
clear_voxel_structures();
|
|
|
|
|
|
|
|
for (int i = 0; i < structures.size(); ++i) {
|
|
|
|
Ref<VoxelLight> structure = Ref<VoxelLight>(structures[i]);
|
|
|
|
|
|
|
|
add_voxel_structure(structure);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
void VoxelWorld::add_chunk(Ref<VoxelChunk> chunk, const int x, const int y, const int z) {
|
|
|
|
ERR_FAIL_COND(!chunk.is_valid());
|
2020-04-22 15:57:00 +02:00
|
|
|
ERR_FAIL_COND_MSG(chunk->get_voxel_world() != NULL && chunk->get_voxel_world() != this, "Chunk is already owned by an another world!");
|
2020-03-04 14:59:34 +01:00
|
|
|
|
|
|
|
IntPos pos(x, y, z);
|
|
|
|
|
|
|
|
ERR_FAIL_COND(_chunks.has(pos));
|
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
chunk->set_voxel_world(this);
|
2019-11-18 22:22:41 +01:00
|
|
|
chunk->set_position(x, y, z);
|
2020-04-02 21:28:19 +02:00
|
|
|
chunk->world_transform_changed();
|
2019-08-12 20:40:05 +02:00
|
|
|
|
2020-03-04 14:59:34 +01:00
|
|
|
_chunks.set(pos, chunk);
|
2019-08-12 20:40:05 +02:00
|
|
|
_chunks_vector.push_back(chunk);
|
2019-11-06 03:37:22 +01:00
|
|
|
|
2020-04-22 12:33:14 +02:00
|
|
|
if (is_inside_tree())
|
|
|
|
chunk->enter_tree();
|
2020-04-06 13:55:22 +02:00
|
|
|
|
|
|
|
if (has_method("_chunk_added"))
|
|
|
|
call("_chunk_added", chunk);
|
2019-11-06 03:37:22 +01:00
|
|
|
}
|
2020-03-04 14:59:34 +01:00
|
|
|
bool VoxelWorld::has_chunk(const int x, const int y, const int z) const {
|
|
|
|
return _chunks.has(IntPos(x, y, z));
|
|
|
|
}
|
2020-04-02 21:28:19 +02:00
|
|
|
Ref<VoxelChunk> VoxelWorld::get_chunk(const int x, const int y, const int z) {
|
2020-03-04 14:59:34 +01:00
|
|
|
IntPos pos(x, y, z);
|
|
|
|
|
|
|
|
if (_chunks.has(pos))
|
|
|
|
return _chunks.get(pos);
|
2019-11-06 03:37:22 +01:00
|
|
|
|
2020-04-17 10:15:50 +02:00
|
|
|
return Ref<VoxelChunk>();
|
2019-08-12 20:40:05 +02:00
|
|
|
}
|
2020-04-02 21:28:19 +02:00
|
|
|
Ref<VoxelChunk> VoxelWorld::remove_chunk(const int x, const int y, const int z) {
|
2020-03-04 10:48:53 +01:00
|
|
|
IntPos pos(x, y, z);
|
|
|
|
|
2020-03-04 14:59:34 +01:00
|
|
|
if (!_chunks.has(pos))
|
|
|
|
return NULL;
|
2019-08-12 20:40:05 +02:00
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
Ref<VoxelChunk> chunk = _chunks.get(pos);
|
2019-08-12 20:40:05 +02:00
|
|
|
|
2019-11-06 03:37:22 +01:00
|
|
|
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
|
|
|
if (_chunks_vector.get(i) == chunk) {
|
|
|
|
_chunks_vector.remove(i);
|
|
|
|
break;
|
2019-08-12 20:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
chunk->exit_tree();
|
|
|
|
|
2020-03-04 14:59:34 +01:00
|
|
|
ERR_FAIL_COND_V(!_chunks.erase(pos), NULL);
|
|
|
|
|
|
|
|
//_chunks.erase(pos);
|
2020-03-04 10:48:53 +01:00
|
|
|
|
|
|
|
return chunk;
|
|
|
|
}
|
2020-04-02 21:28:19 +02:00
|
|
|
Ref<VoxelChunk> VoxelWorld::remove_chunk_index(const int index) {
|
2020-03-04 10:48:53 +01:00
|
|
|
ERR_FAIL_INDEX_V(index, _chunks_vector.size(), NULL);
|
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
Ref<VoxelChunk> chunk = _chunks_vector.get(index);
|
2020-03-04 10:48:53 +01:00
|
|
|
_chunks_vector.remove(index);
|
2020-03-04 14:59:34 +01:00
|
|
|
_chunks.erase(IntPos(chunk->get_position_x(), chunk->get_position_y(), chunk->get_position_z()));
|
2020-04-02 21:28:19 +02:00
|
|
|
chunk->exit_tree();
|
2020-03-04 10:48:53 +01:00
|
|
|
|
2019-11-06 03:37:22 +01:00
|
|
|
return chunk;
|
2019-08-12 20:40:05 +02:00
|
|
|
}
|
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
Ref<VoxelChunk> VoxelWorld::get_chunk_index(const int index) {
|
2019-11-06 03:37:22 +01:00
|
|
|
ERR_FAIL_INDEX_V(index, _chunks_vector.size(), NULL);
|
|
|
|
|
2019-08-12 20:40:05 +02:00
|
|
|
return _chunks_vector.get(index);
|
|
|
|
}
|
|
|
|
int VoxelWorld::get_chunk_count() const {
|
|
|
|
return _chunks_vector.size();
|
|
|
|
}
|
|
|
|
|
2020-04-16 17:10:04 +02:00
|
|
|
void VoxelWorld::add_to_generation_queue(const Ref<VoxelChunk> &chunk) {
|
2020-04-02 21:28:19 +02:00
|
|
|
ERR_FAIL_COND(!chunk.is_valid());
|
2019-11-19 16:33:06 +01:00
|
|
|
|
2019-11-19 16:42:38 +01:00
|
|
|
set_process_internal(true);
|
|
|
|
|
2019-11-19 16:33:06 +01:00
|
|
|
_generation_queue.push_back(chunk);
|
|
|
|
}
|
2020-04-02 21:28:19 +02:00
|
|
|
Ref<VoxelChunk> VoxelWorld::get_generation_queue_index(int index) {
|
2019-11-19 16:33:06 +01:00
|
|
|
ERR_FAIL_INDEX_V(index, _generation_queue.size(), NULL);
|
|
|
|
|
|
|
|
return _generation_queue.get(index);
|
|
|
|
}
|
|
|
|
void VoxelWorld::remove_generation_queue_index(int index) {
|
|
|
|
ERR_FAIL_INDEX(index, _generation_queue.size());
|
|
|
|
|
|
|
|
_generation_queue.remove(index);
|
|
|
|
}
|
2020-04-16 17:10:04 +02:00
|
|
|
int VoxelWorld::get_generation_queue_size() const {
|
2019-11-19 16:33:06 +01:00
|
|
|
return _generation_queue.size();
|
|
|
|
}
|
|
|
|
|
2020-04-16 17:10:04 +02:00
|
|
|
void VoxelWorld::add_to_generation(const Ref<VoxelChunk> &chunk) {
|
2020-04-02 21:28:19 +02:00
|
|
|
ERR_FAIL_COND(!chunk.is_valid());
|
2019-11-19 16:33:06 +01:00
|
|
|
|
|
|
|
_generating.push_back(chunk);
|
|
|
|
}
|
2020-04-16 17:10:04 +02:00
|
|
|
Ref<VoxelChunk> VoxelWorld::get_generation_index(const int index) {
|
2019-11-19 16:33:06 +01:00
|
|
|
ERR_FAIL_INDEX_V(index, _generating.size(), NULL);
|
|
|
|
|
|
|
|
return _generating.get(index);
|
|
|
|
}
|
2020-04-16 17:10:04 +02:00
|
|
|
void VoxelWorld::remove_generation_index(const int index) {
|
2019-11-19 16:33:06 +01:00
|
|
|
ERR_FAIL_INDEX(index, _generating.size());
|
|
|
|
|
|
|
|
_generating.remove(index);
|
|
|
|
}
|
2020-04-16 17:10:04 +02:00
|
|
|
int VoxelWorld::get_generation_size() const {
|
2019-11-19 16:33:06 +01:00
|
|
|
return _generating.size();
|
|
|
|
}
|
|
|
|
|
2020-04-15 12:41:52 +02:00
|
|
|
void VoxelWorld::clear_chunks() {
|
2019-08-12 20:40:05 +02:00
|
|
|
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
2020-04-02 21:28:19 +02:00
|
|
|
_chunks_vector.get(i)->exit_tree();
|
2019-08-12 20:40:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_chunks_vector.clear();
|
|
|
|
|
|
|
|
_chunks.clear();
|
2019-11-19 16:33:06 +01:00
|
|
|
|
|
|
|
_generation_queue.clear();
|
|
|
|
_generating.clear();
|
2019-08-12 20:40:05 +02:00
|
|
|
}
|
|
|
|
|
2020-04-10 13:39:11 +02:00
|
|
|
Ref<VoxelChunk> VoxelWorld::get_or_create_chunk(int x, int y, int z) {
|
|
|
|
Ref<VoxelChunk> chunk = get_chunk(x, y, z);
|
|
|
|
|
|
|
|
if (!chunk.is_valid()) {
|
|
|
|
chunk = create_chunk(x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
return chunk;
|
|
|
|
}
|
|
|
|
|
2020-04-16 17:10:04 +02:00
|
|
|
Ref<VoxelChunk> VoxelWorld::create_chunk(const int x, const int y, const int z) {
|
2020-04-02 21:28:19 +02:00
|
|
|
Ref<VoxelChunk> c = call("_create_chunk", x, y, z, Ref<VoxelChunk>());
|
2019-11-19 20:39:45 +01:00
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
return c;
|
2019-11-19 14:42:21 +01:00
|
|
|
}
|
2020-04-16 17:10:04 +02:00
|
|
|
Ref<VoxelChunk> VoxelWorld::_create_chunk(const int x, const int y, const int z, Ref<VoxelChunk> chunk) {
|
2020-04-02 21:28:19 +02:00
|
|
|
if (!chunk.is_valid()) {
|
|
|
|
chunk.instance();
|
2019-11-19 20:39:45 +01:00
|
|
|
}
|
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
ERR_FAIL_COND_V(!chunk.is_valid(), NULL);
|
2019-11-19 20:39:45 +01:00
|
|
|
|
2019-11-19 16:33:06 +01:00
|
|
|
chunk->set_name("Chunk[" + String::num(x) + "," + String::num(y) + "," + String::num(z) + "]");
|
2019-11-19 14:42:21 +01:00
|
|
|
|
2019-11-19 16:33:06 +01:00
|
|
|
chunk->set_voxel_world(this);
|
2020-03-12 23:23:38 +01:00
|
|
|
|
|
|
|
//TODO this will need to be changed
|
|
|
|
if (chunk->has_method("set_is_build_threaded"))
|
|
|
|
chunk->call("set_is_build_threaded", _use_threads);
|
|
|
|
|
2019-11-19 16:33:06 +01:00
|
|
|
chunk->set_position(x, y, z);
|
|
|
|
chunk->set_library(_library);
|
|
|
|
chunk->set_voxel_scale(_voxel_scale);
|
2020-02-14 03:19:15 +01:00
|
|
|
chunk->set_size(_chunk_size_x, _chunk_size_y, _chunk_size_z, _data_margin_start, _data_margin_end);
|
2020-04-02 21:28:19 +02:00
|
|
|
//chunk->set_translation(Vector3(x * _chunk_size_x * _voxel_scale, y * _chunk_size_y * _voxel_scale, z * _chunk_size_z * _voxel_scale));
|
2019-11-19 16:33:06 +01:00
|
|
|
|
|
|
|
add_chunk(chunk, x, y, z);
|
|
|
|
|
2019-11-19 20:39:45 +01:00
|
|
|
add_to_generation_queue(chunk);
|
2019-11-19 16:33:06 +01:00
|
|
|
|
|
|
|
return chunk;
|
2019-11-19 14:42:21 +01:00
|
|
|
}
|
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
void VoxelWorld::generate_chunk(Ref<VoxelChunk> chunk) {
|
|
|
|
ERR_FAIL_COND(!chunk.is_valid());
|
2019-11-19 14:42:21 +01:00
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
chunk->set_is_generating(true);
|
2019-11-19 14:42:21 +01:00
|
|
|
|
|
|
|
if (has_method("_prepare_chunk_for_generation"))
|
2020-04-02 21:28:19 +02:00
|
|
|
call("_prepare_chunk_for_generation", chunk);
|
2019-11-19 14:42:21 +01:00
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
call("_generate_chunk", chunk);
|
2019-11-19 19:14:46 +01:00
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
chunk->build();
|
2019-11-19 14:42:21 +01:00
|
|
|
}
|
2020-04-16 21:59:30 +02:00
|
|
|
int VoxelWorld::_get_channel_index_info(const VoxelWorld::ChannelTypeInfo channel_type) {
|
|
|
|
return -1;
|
|
|
|
}
|
2019-11-19 14:42:21 +01:00
|
|
|
|
2020-03-04 14:59:34 +01:00
|
|
|
bool VoxelWorld::can_chunk_do_build_step() {
|
|
|
|
if (_max_frame_chunk_build_steps == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-11-19 14:42:21 +01:00
|
|
|
|
2020-03-04 14:59:34 +01:00
|
|
|
return _num_frame_chunk_build_steps++ < _max_frame_chunk_build_steps;
|
2019-11-19 14:42:21 +01:00
|
|
|
}
|
|
|
|
|
2020-03-04 15:21:32 +01:00
|
|
|
bool VoxelWorld::is_position_walkable(const Vector3 &p_pos) {
|
2020-03-04 18:35:09 +01:00
|
|
|
int x = static_cast<int>(Math::floor(p_pos.x / (_chunk_size_x * _voxel_scale)));
|
|
|
|
int y = static_cast<int>(Math::floor(p_pos.y / (_chunk_size_y * _voxel_scale)));
|
|
|
|
int z = static_cast<int>(Math::floor(p_pos.z / (_chunk_size_z * _voxel_scale)));
|
2020-03-04 15:21:32 +01:00
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
Ref<VoxelChunk> c = get_chunk(x, y, z);
|
2020-03-04 15:21:32 +01:00
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
if (!c.is_valid())
|
2020-03-04 15:21:32 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return !c->get_is_generating();
|
|
|
|
}
|
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
void VoxelWorld::on_chunk_mesh_generation_finished(Ref<VoxelChunk> p_chunk) {
|
2020-04-10 15:50:53 +02:00
|
|
|
call_deferred("emit_signal", "chunk_mesh_generation_finished", p_chunk);
|
2020-03-04 15:21:32 +01:00
|
|
|
}
|
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
Vector<Variant> VoxelWorld::get_chunks() {
|
2020-05-23 10:34:47 +02:00
|
|
|
VARIANT_ARRAY_GET(_chunks_vector);
|
2020-04-02 21:28:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VoxelWorld::set_chunks(const Vector<Variant> &chunks) {
|
2020-04-22 15:57:00 +02:00
|
|
|
if (is_inside_tree()) {
|
|
|
|
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
|
|
|
Ref<VoxelChunk> chunk = Ref<VoxelChunk>(_chunks_vector[i]);
|
2020-04-06 00:51:25 +02:00
|
|
|
|
2020-04-22 15:57:00 +02:00
|
|
|
if (chunks.find(chunk) == -1) {
|
|
|
|
remove_chunk_index(i);
|
|
|
|
_generation_queue.erase(chunk);
|
|
|
|
_generating.erase(chunk);
|
|
|
|
--i;
|
|
|
|
}
|
2020-04-06 00:51:25 +02:00
|
|
|
}
|
|
|
|
|
2020-04-22 15:57:00 +02:00
|
|
|
//add the difference
|
|
|
|
for (int i = 0; i < chunks.size(); ++i) {
|
|
|
|
Ref<VoxelChunk> chunk = Ref<VoxelChunk>(chunks[i]);
|
2020-03-04 15:21:32 +01:00
|
|
|
|
2020-04-22 15:57:00 +02:00
|
|
|
if (!chunk.is_valid())
|
|
|
|
continue;
|
2020-03-04 15:21:32 +01:00
|
|
|
|
2020-04-22 15:57:00 +02:00
|
|
|
if (_chunks_vector.find(chunk) != -1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
add_chunk(chunk, chunk->get_position_x(), chunk->get_position_y(), chunk->get_position_z());
|
2020-04-06 20:05:19 +02:00
|
|
|
}
|
2020-04-22 15:57:00 +02:00
|
|
|
} else {
|
|
|
|
_chunks_vector.clear();
|
2020-04-06 00:51:25 +02:00
|
|
|
|
2020-04-22 15:57:00 +02:00
|
|
|
for (int i = 0; i < chunks.size(); ++i) {
|
|
|
|
Ref<VoxelChunk> chunk = Ref<VoxelChunk>(chunks[i]);
|
2020-04-22 12:35:48 +02:00
|
|
|
|
2020-04-22 15:57:00 +02:00
|
|
|
_chunks_vector.push_back(chunk);
|
|
|
|
}
|
2020-04-02 21:28:19 +02:00
|
|
|
}
|
2020-03-04 15:21:32 +01:00
|
|
|
}
|
|
|
|
|
2020-07-07 01:06:46 +02:00
|
|
|
#if PROPS_PRESENT
|
2020-07-07 17:02:30 +02:00
|
|
|
void VoxelWorld::add_prop(Transform tarnsform, const Ref<PropData> &prop, const bool apply_voxel_scael) {
|
2020-07-07 02:22:45 +02:00
|
|
|
ERR_FAIL_COND(!prop.is_valid());
|
|
|
|
|
2020-07-07 17:02:30 +02:00
|
|
|
if (apply_voxel_scael) {
|
|
|
|
tarnsform = tarnsform.scaled(Vector3(get_voxel_scale(), get_voxel_scale(), get_voxel_scale()));
|
|
|
|
}
|
|
|
|
|
2020-07-07 02:22:45 +02:00
|
|
|
Vector3 wp;
|
|
|
|
wp = tarnsform.xform(wp);
|
|
|
|
Ref<VoxelChunk> chunk = get_or_create_chunk_at_world_position(wp);
|
|
|
|
|
|
|
|
chunk->add_prop(tarnsform, prop);
|
|
|
|
|
|
|
|
int count = prop->get_prop_count();
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
Ref<PropDataEntry> entry = prop->get_prop(i);
|
|
|
|
|
|
|
|
if (!entry.is_valid())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Transform t = tarnsform * entry->get_transform();
|
|
|
|
|
2020-07-07 17:02:30 +02:00
|
|
|
wp = t.xform(Vector3());
|
2020-07-07 02:22:45 +02:00
|
|
|
chunk = get_or_create_chunk_at_world_position(wp);
|
|
|
|
|
|
|
|
Ref<PropDataProp> prop_entry_data = entry;
|
|
|
|
|
|
|
|
if (prop_entry_data.is_valid()) {
|
|
|
|
Ref<PropData> p = prop_entry_data->get_prop();
|
|
|
|
|
|
|
|
if (!p.is_valid())
|
|
|
|
continue;
|
|
|
|
|
2020-07-07 17:02:30 +02:00
|
|
|
add_prop(t, p, false);
|
2020-07-07 02:22:45 +02:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<PropDataScene> scene_data = entry;
|
|
|
|
|
|
|
|
if (scene_data.is_valid()) {
|
|
|
|
Ref<PackedScene> sc = scene_data->get_scene();
|
|
|
|
|
|
|
|
if (!sc.is_valid())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Node *n = sc->instance();
|
|
|
|
add_child(n);
|
|
|
|
n->set_owner(this);
|
|
|
|
|
|
|
|
Spatial *sp = Object::cast_to<Spatial>(n);
|
|
|
|
|
|
|
|
if (sp) {
|
|
|
|
sp->set_transform(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<PropDataLight> light_data = entry;
|
|
|
|
|
|
|
|
if (light_data.is_valid()) {
|
|
|
|
Ref<VoxelLight> light;
|
|
|
|
light.instance();
|
|
|
|
|
2020-07-07 18:01:21 +02:00
|
|
|
light->set_world_position(wp.x / get_voxel_scale(), wp.y / get_voxel_scale(), wp.z / get_voxel_scale());
|
2020-07-07 02:22:45 +02:00
|
|
|
light->set_color(light_data->get_light_color());
|
|
|
|
light->set_size(light_data->get_light_size());
|
|
|
|
|
|
|
|
add_light(light);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if MESH_DATA_RESOURCE_PRESENT
|
|
|
|
Ref<PropDataMeshData> mesh_data = entry;
|
|
|
|
|
|
|
|
if (mesh_data.is_valid()) {
|
|
|
|
Ref<MeshDataResource> mdr = mesh_data->get_mesh();
|
|
|
|
|
|
|
|
if (!mdr.is_valid())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
chunk->add_mesh_data_resource(t, mdr, mesh_data->get_texture());
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2020-04-15 13:06:45 +02:00
|
|
|
}
|
2020-07-07 01:06:46 +02:00
|
|
|
#endif
|
2020-04-15 12:41:52 +02:00
|
|
|
|
2020-04-15 13:06:45 +02:00
|
|
|
//Lights
|
2020-04-15 12:41:52 +02:00
|
|
|
void VoxelWorld::add_light(const Ref<VoxelLight> &light) {
|
|
|
|
_lights.push_back(light);
|
|
|
|
|
|
|
|
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
|
|
|
Ref<VoxelChunk> chunk = _chunks_vector[i];
|
|
|
|
|
|
|
|
if (chunk.is_valid()) {
|
|
|
|
chunk->world_light_added(light);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ref<VoxelLight> VoxelWorld::get_light(const int index) {
|
|
|
|
ERR_FAIL_INDEX_V(index, _lights.size(), Ref<VoxelLight>());
|
|
|
|
|
|
|
|
return _lights.get(index);
|
|
|
|
}
|
|
|
|
void VoxelWorld::remove_light(const int index) {
|
|
|
|
ERR_FAIL_INDEX(index, _lights.size());
|
|
|
|
|
|
|
|
Ref<VoxelLight> light = _lights[index];
|
|
|
|
|
|
|
|
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
|
|
|
Ref<VoxelChunk> chunk = _chunks_vector[i];
|
|
|
|
|
|
|
|
if (chunk.is_valid()) {
|
|
|
|
chunk->world_light_removed(light);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int VoxelWorld::get_light_count() const {
|
|
|
|
return _lights.size();
|
|
|
|
}
|
|
|
|
void VoxelWorld::clear_lights() {
|
|
|
|
for (int i = 0; i < _lights.size(); ++i) {
|
|
|
|
Ref<VoxelLight> light = _lights[i];
|
|
|
|
|
|
|
|
if (!light.is_valid())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (int j = 0; j < _chunks_vector.size(); ++j) {
|
|
|
|
Ref<VoxelChunk> chunk = _chunks_vector[j];
|
|
|
|
|
|
|
|
if (chunk.is_valid()) {
|
|
|
|
chunk->world_light_removed(light);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_lights.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<Variant> VoxelWorld::get_lights() {
|
2020-05-23 10:34:47 +02:00
|
|
|
VARIANT_ARRAY_GET(_lights);
|
2020-04-15 12:41:52 +02:00
|
|
|
}
|
|
|
|
void VoxelWorld::set_lights(const Vector<Variant> &chunks) {
|
|
|
|
clear_lights();
|
|
|
|
|
|
|
|
for (int i = 0; i < chunks.size(); ++i) {
|
|
|
|
Ref<VoxelLight> light = Ref<VoxelLight>(chunks[i]);
|
|
|
|
|
|
|
|
add_light(light);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-17 10:15:50 +02:00
|
|
|
uint8_t VoxelWorld::get_voxel_at_world_position(const Vector3 &world_position, const int channel_index) {
|
|
|
|
Vector3 pos = world_position / get_voxel_scale();
|
|
|
|
|
|
|
|
//Note: floor is needed to handle negative numbers proiberly
|
2020-05-19 00:50:19 +02:00
|
|
|
int x = static_cast<int>(Math::floor(pos.x / get_chunk_size_x()));
|
|
|
|
int y = static_cast<int>(Math::floor(pos.y / get_chunk_size_y()));
|
|
|
|
int z = static_cast<int>(Math::floor(pos.z / get_chunk_size_z()));
|
2020-04-17 10:15:50 +02:00
|
|
|
|
2020-05-19 00:50:19 +02:00
|
|
|
int bx = static_cast<int>(Math::floor(pos.x)) % get_chunk_size_x();
|
|
|
|
int by = static_cast<int>(Math::floor(pos.y)) % get_chunk_size_y();
|
|
|
|
int bz = static_cast<int>(Math::floor(pos.z)) % get_chunk_size_z();
|
2020-04-17 10:15:50 +02:00
|
|
|
|
|
|
|
if (bx < 0) {
|
|
|
|
bx += get_chunk_size_x();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (by < 0) {
|
|
|
|
by += get_chunk_size_y();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bz < 0) {
|
|
|
|
bz += get_chunk_size_z();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<VoxelChunk> chunk = get_chunk(x, y, z);
|
|
|
|
|
|
|
|
if (chunk.is_valid())
|
|
|
|
return chunk->get_voxel(bx, by, bz, channel_index);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-16 14:44:22 +02:00
|
|
|
void VoxelWorld::set_voxel_at_world_position(const Vector3 &world_position, const uint8_t data, const int channel_index) {
|
|
|
|
Vector3 pos = world_position / get_voxel_scale();
|
|
|
|
|
|
|
|
//Note: floor is needed to handle negative numbers proiberly
|
2020-05-19 00:50:19 +02:00
|
|
|
int x = static_cast<int>(Math::floor(pos.x / get_chunk_size_x()));
|
|
|
|
int y = static_cast<int>(Math::floor(pos.y / get_chunk_size_y()));
|
|
|
|
int z = static_cast<int>(Math::floor(pos.z / get_chunk_size_z()));
|
2020-04-16 14:44:22 +02:00
|
|
|
|
2020-05-19 00:50:19 +02:00
|
|
|
int bx = static_cast<int>(Math::floor(pos.x)) % get_chunk_size_x();
|
|
|
|
int by = static_cast<int>(Math::floor(pos.y)) % get_chunk_size_y();
|
|
|
|
int bz = static_cast<int>(Math::floor(pos.z)) % get_chunk_size_z();
|
2020-04-16 14:44:22 +02:00
|
|
|
|
|
|
|
if (bx < 0) {
|
|
|
|
bx += get_chunk_size_x();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (by < 0) {
|
|
|
|
by += get_chunk_size_y();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bz < 0) {
|
|
|
|
bz += get_chunk_size_z();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_data_margin_end() > 0) {
|
|
|
|
if (bx == 0) {
|
|
|
|
Ref<VoxelChunk> chunk = get_or_create_chunk(x - 1, y, z);
|
|
|
|
chunk->set_voxel(data, get_chunk_size_x(), by, bz, channel_index);
|
|
|
|
chunk->build();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (by == 0) {
|
|
|
|
Ref<VoxelChunk> chunk = get_or_create_chunk(x, y - 1, z);
|
|
|
|
chunk->set_voxel(data, bx, get_chunk_size_y(), bz, channel_index);
|
|
|
|
chunk->build();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bz == 0) {
|
|
|
|
Ref<VoxelChunk> chunk = get_or_create_chunk(x, y, z - 1);
|
|
|
|
chunk->set_voxel(data, bx, by, get_chunk_size_z(), channel_index);
|
|
|
|
chunk->build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_data_margin_start() > 0) {
|
|
|
|
if (bx == get_chunk_size_x() - 1) {
|
|
|
|
Ref<VoxelChunk> chunk = get_or_create_chunk(x + 1, y, z);
|
|
|
|
chunk->set_voxel(data, -1, by, bz, channel_index);
|
|
|
|
chunk->build();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (by == get_chunk_size_y() - 1) {
|
|
|
|
Ref<VoxelChunk> chunk = get_or_create_chunk(x, y + 1, z);
|
|
|
|
chunk->set_voxel(data, bx, -1, bz, channel_index);
|
|
|
|
chunk->build();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bz == get_chunk_size_z() - 1) {
|
|
|
|
Ref<VoxelChunk> chunk = get_or_create_chunk(x, y, z + 1);
|
|
|
|
chunk->set_voxel(data, bx, by, -1, channel_index);
|
|
|
|
chunk->build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<VoxelChunk> chunk = get_or_create_chunk(x, y, z);
|
|
|
|
chunk->set_voxel(data, bx, by, bz, channel_index);
|
|
|
|
chunk->build();
|
|
|
|
}
|
|
|
|
|
2020-04-17 10:15:50 +02:00
|
|
|
Ref<VoxelChunk> VoxelWorld::get_chunk_at_world_position(const Vector3 &world_position) {
|
|
|
|
Vector3 pos = world_position / get_voxel_scale();
|
|
|
|
|
|
|
|
//Note: floor is needed to handle negative numbers proiberly
|
2020-05-19 00:50:19 +02:00
|
|
|
int x = static_cast<int>(Math::floor(pos.x / get_chunk_size_x()));
|
|
|
|
int y = static_cast<int>(Math::floor(pos.y / get_chunk_size_y()));
|
|
|
|
int z = static_cast<int>(Math::floor(pos.z / get_chunk_size_z()));
|
2020-04-17 10:15:50 +02:00
|
|
|
|
|
|
|
return get_chunk(x, y, z);
|
|
|
|
}
|
|
|
|
Ref<VoxelChunk> VoxelWorld::get_or_create_chunk_at_world_position(const Vector3 &world_position) {
|
|
|
|
Vector3 pos = world_position / get_voxel_scale();
|
|
|
|
|
|
|
|
//Note: floor is needed to handle negative numbers proiberly
|
2020-05-19 00:50:19 +02:00
|
|
|
int x = static_cast<int>(Math::floor(pos.x / get_chunk_size_x()));
|
|
|
|
int y = static_cast<int>(Math::floor(pos.y / get_chunk_size_y()));
|
|
|
|
int z = static_cast<int>(Math::floor(pos.z / get_chunk_size_z()));
|
2020-04-17 10:15:50 +02:00
|
|
|
|
|
|
|
return get_or_create_chunk(x, y, z);
|
|
|
|
}
|
|
|
|
|
2020-04-16 21:59:30 +02:00
|
|
|
int VoxelWorld::get_channel_index_info(const VoxelWorld::ChannelTypeInfo channel_type) {
|
|
|
|
return call("_get_channel_index_info", channel_type);
|
|
|
|
}
|
|
|
|
|
2019-08-12 13:12:42 +02:00
|
|
|
VoxelWorld::VoxelWorld() {
|
2020-03-31 13:25:31 +02:00
|
|
|
_editable = false;
|
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
_is_priority_generation = true;
|
|
|
|
|
2019-11-18 22:22:41 +01:00
|
|
|
_chunk_size_x = 16;
|
|
|
|
_chunk_size_y = 16;
|
|
|
|
_chunk_size_z = 16;
|
2019-11-19 14:42:21 +01:00
|
|
|
_current_seed = 0;
|
2020-02-14 03:19:15 +01:00
|
|
|
_data_margin_start = 0;
|
|
|
|
_data_margin_end = 0;
|
2019-11-19 14:42:21 +01:00
|
|
|
|
|
|
|
set_use_threads(true);
|
|
|
|
set_max_concurrent_generations(3);
|
2019-08-12 20:40:05 +02:00
|
|
|
|
|
|
|
_voxel_scale = 1;
|
|
|
|
_chunk_spawn_range = 4;
|
|
|
|
|
|
|
|
_player = NULL;
|
2020-03-04 14:59:34 +01:00
|
|
|
_max_frame_chunk_build_steps = 0;
|
|
|
|
_num_frame_chunk_build_steps = 0;
|
2019-08-12 13:12:42 +02:00
|
|
|
}
|
|
|
|
|
2019-06-07 19:13:07 +02:00
|
|
|
VoxelWorld ::~VoxelWorld() {
|
|
|
|
_chunks.clear();
|
2019-08-12 20:40:05 +02:00
|
|
|
_chunks_vector.clear();
|
2019-11-10 01:03:48 +01:00
|
|
|
_world_areas.clear();
|
2020-04-16 13:40:39 +02:00
|
|
|
_voxel_structures.clear();
|
2019-08-12 20:40:05 +02:00
|
|
|
|
|
|
|
_library.unref();
|
2019-11-19 14:42:21 +01:00
|
|
|
_level_generator.unref();
|
|
|
|
|
|
|
|
_player = NULL;
|
|
|
|
|
|
|
|
_generation_queue.clear();
|
2019-11-19 20:39:45 +01:00
|
|
|
_generating.clear();
|
2020-04-15 12:41:52 +02:00
|
|
|
|
|
|
|
_lights.clear();
|
2019-11-19 14:42:21 +01:00
|
|
|
}
|
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
void VoxelWorld::_generate_chunk(Ref<VoxelChunk> chunk) {
|
|
|
|
ERR_FAIL_COND(!chunk.is_valid());
|
2020-03-04 14:59:34 +01:00
|
|
|
|
2020-04-22 12:21:50 +02:00
|
|
|
if (_level_generator.is_valid())
|
|
|
|
_level_generator->generate_chunk(chunk);
|
2020-04-16 13:40:39 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < _voxel_structures.size(); ++i) {
|
|
|
|
Ref<VoxelStructure> structure = _voxel_structures.get(i);
|
|
|
|
|
|
|
|
if (!structure.is_valid())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (structure->get_use_aabb()) {
|
|
|
|
if (structure->get_chunk_aabb().has_point(Vector3(chunk->get_position_x(), chunk->get_position_y(), chunk->get_position_z())))
|
|
|
|
structure->write_to_chunk(chunk);
|
|
|
|
} else {
|
|
|
|
structure->write_to_chunk(chunk);
|
|
|
|
}
|
|
|
|
}
|
2020-03-04 14:59:34 +01:00
|
|
|
}
|
|
|
|
|
2019-11-19 14:42:21 +01:00
|
|
|
void VoxelWorld::_notification(int p_what) {
|
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2020-04-17 22:09:55 +02:00
|
|
|
set_player_bind(get_node_or_null(get_player_path()));
|
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
set_process_internal(true);
|
|
|
|
set_physics_process_internal(true);
|
|
|
|
set_notify_transform(true);
|
2019-11-19 14:42:21 +01:00
|
|
|
|
2020-04-06 20:10:57 +02:00
|
|
|
if (_library.is_valid())
|
2019-11-19 14:42:21 +01:00
|
|
|
_library->refresh_rects();
|
2020-04-02 21:28:19 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
|
|
|
Ref<VoxelChunk> chunk = _chunks_vector[i];
|
|
|
|
|
|
|
|
if (chunk.is_valid()) {
|
2020-04-06 00:51:25 +02:00
|
|
|
IntPos pos(chunk->get_position_x(), chunk->get_position_y(), chunk->get_position_z());
|
|
|
|
|
|
|
|
chunk->set_voxel_world(this);
|
|
|
|
chunk->world_transform_changed();
|
|
|
|
|
|
|
|
_chunks.set(pos, chunk);
|
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
chunk->enter_tree();
|
2020-04-06 00:51:25 +02:00
|
|
|
|
|
|
|
chunk->build();
|
2020-04-02 21:28:19 +02:00
|
|
|
}
|
|
|
|
}
|
2020-03-15 19:33:10 +01:00
|
|
|
} break;
|
2019-11-19 14:42:21 +01:00
|
|
|
case NOTIFICATION_INTERNAL_PROCESS: {
|
2020-03-04 14:59:34 +01:00
|
|
|
_num_frame_chunk_build_steps = 0;
|
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
|
|
|
Ref<VoxelChunk> chunk = _chunks_vector[i];
|
|
|
|
|
|
|
|
ERR_CONTINUE(!chunk.is_valid());
|
|
|
|
|
|
|
|
if (chunk->get_process()) {
|
|
|
|
chunk->process(get_physics_process_delta_time());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_is_priority_generation && _generation_queue.empty() && _generating.empty()) {
|
|
|
|
_is_priority_generation = false;
|
|
|
|
|
2019-11-19 14:42:21 +01:00
|
|
|
call("_generation_finished");
|
|
|
|
|
|
|
|
emit_signal("generation_finished");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < _generating.size(); ++i) {
|
2020-04-02 21:28:19 +02:00
|
|
|
Ref<VoxelChunk> chunk = _generating.get(i);
|
2019-11-19 14:42:21 +01:00
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
if (!chunk.is_valid() || !chunk->get_is_generating()) {
|
2019-11-19 14:42:21 +01:00
|
|
|
_generating.remove(i);
|
|
|
|
--i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_generating.size() >= _max_concurrent_generations)
|
|
|
|
return;
|
|
|
|
|
2019-11-19 16:33:06 +01:00
|
|
|
if (_generation_queue.size() == 0)
|
2019-11-19 14:42:21 +01:00
|
|
|
return;
|
|
|
|
|
2019-11-19 19:14:46 +01:00
|
|
|
while (_generating.size() < _max_concurrent_generations && _generation_queue.size() != 0) {
|
2020-04-02 21:28:19 +02:00
|
|
|
Ref<VoxelChunk> chunk = _generation_queue.get(0);
|
2019-11-19 19:14:46 +01:00
|
|
|
_generation_queue.remove(0);
|
2019-11-19 14:42:21 +01:00
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
ERR_FAIL_COND(!chunk.is_valid());
|
2019-11-19 14:42:21 +01:00
|
|
|
|
2019-11-19 19:14:46 +01:00
|
|
|
_generating.push_back(chunk);
|
2019-11-19 14:42:21 +01:00
|
|
|
|
2019-11-19 19:14:46 +01:00
|
|
|
generate_chunk(chunk);
|
|
|
|
}
|
2020-03-15 19:33:10 +01:00
|
|
|
} break;
|
2020-04-02 21:28:19 +02:00
|
|
|
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
|
|
|
|
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
|
|
|
Ref<VoxelChunk> chunk = _chunks_vector[i];
|
|
|
|
|
|
|
|
ERR_CONTINUE(!chunk.is_valid());
|
|
|
|
|
|
|
|
if (chunk->get_process()) {
|
|
|
|
chunk->physics_process(get_physics_process_delta_time());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2019-11-19 20:39:45 +01:00
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
2020-04-02 21:28:19 +02:00
|
|
|
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
|
|
|
Ref<VoxelChunk> chunk = _chunks_vector[i];
|
|
|
|
|
|
|
|
if (chunk.is_valid()) {
|
2020-04-22 15:57:00 +02:00
|
|
|
if (chunk->get_voxel_world() == this) {
|
|
|
|
chunk->exit_tree();
|
|
|
|
chunk->set_voxel_world(NULL);
|
|
|
|
}
|
2020-04-02 21:28:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_TRANSFORM_CHANGED: {
|
|
|
|
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
|
|
|
Ref<VoxelChunk> chunk = _chunks_vector[i];
|
|
|
|
|
|
|
|
if (chunk.is_valid()) {
|
|
|
|
chunk->world_transform_changed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-15 19:33:10 +01:00
|
|
|
} break;
|
2019-11-19 14:42:21 +01:00
|
|
|
}
|
2019-06-07 19:13:07 +02:00
|
|
|
}
|
|
|
|
|
2019-06-07 01:33:41 +02:00
|
|
|
void VoxelWorld::_bind_methods() {
|
2020-03-04 15:21:32 +01:00
|
|
|
ADD_SIGNAL(MethodInfo("chunk_mesh_generation_finished", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
|
|
|
|
|
2020-03-31 13:25:31 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_editable"), &VoxelWorld::get_editable);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_editable", "value"), &VoxelWorld::set_editable);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "get_editable");
|
|
|
|
|
2019-08-12 20:40:05 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_chunk_size_x"), &VoxelWorld::get_chunk_size_x);
|
2019-08-12 13:12:42 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_chunk_size_x", "value"), &VoxelWorld::set_chunk_size_x);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_size_x"), "set_chunk_size_x", "get_chunk_size_x");
|
|
|
|
|
2019-08-12 20:40:05 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_chunk_size_y"), &VoxelWorld::get_chunk_size_y);
|
2019-08-12 13:12:42 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_chunk_size_y", "value"), &VoxelWorld::set_chunk_size_y);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_size_y"), "set_chunk_size_y", "get_chunk_size_y");
|
2019-08-12 20:40:05 +02:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_chunk_size_z"), &VoxelWorld::get_chunk_size_z);
|
2019-08-12 13:12:42 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_chunk_size_z", "value"), &VoxelWorld::set_chunk_size_z);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_size_z"), "set_chunk_size_z", "get_chunk_size_z");
|
2019-08-12 20:40:05 +02:00
|
|
|
|
2020-02-14 03:19:15 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_data_margin_start"), &VoxelWorld::get_data_margin_start);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_data_margin_start", "value"), &VoxelWorld::set_data_margin_start);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "data_margin_start"), "set_data_margin_start", "get_data_margin_start");
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_data_margin_end"), &VoxelWorld::get_data_margin_end);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_data_margin_end", "value"), &VoxelWorld::set_data_margin_end);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "data_margin_end"), "set_data_margin_end", "get_data_margin_end");
|
|
|
|
|
2019-11-19 14:42:21 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_current_seed"), &VoxelWorld::get_current_seed);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_current_seed", "value"), &VoxelWorld::set_current_seed);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_seed"), "set_current_seed", "get_current_seed");
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_use_threads"), &VoxelWorld::get_use_threads);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_use_threads", "value"), &VoxelWorld::set_use_threads);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_threads"), "set_use_threads", "get_use_threads");
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_max_concurrent_generations"), &VoxelWorld::get_max_concurrent_generations);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_max_concurrent_generations", "value"), &VoxelWorld::set_max_concurrent_generations);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_concurrent_generations"), "set_max_concurrent_generations", "get_max_concurrent_generations");
|
|
|
|
|
2020-03-04 14:59:34 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_max_frame_chunk_build_steps"), &VoxelWorld::get_max_frame_chunk_build_steps);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_max_frame_chunk_build_steps", "value"), &VoxelWorld::set_max_frame_chunk_build_steps);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_frame_chunk_build_steps"), "set_max_frame_chunk_build_steps", "get_max_frame_chunk_build_steps");
|
|
|
|
|
2019-08-12 20:40:05 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_library"), &VoxelWorld::get_library);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_library", "library"), &VoxelWorld::set_library);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "VoxelmanLibrary"), "set_library", "get_library");
|
2019-11-06 03:37:22 +01:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_level_generator"), &VoxelWorld::get_level_generator);
|
2019-09-03 13:52:32 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_level_generator", "level_generator"), &VoxelWorld::set_level_generator);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "level_generator", PROPERTY_HINT_RESOURCE_TYPE, "VoxelmanLevelGenerator"), "set_level_generator", "get_level_generator");
|
2019-11-06 03:37:22 +01:00
|
|
|
|
2019-08-12 20:40:05 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_voxel_scale"), &VoxelWorld::get_voxel_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_voxel_scale", "value"), &VoxelWorld::set_voxel_scale);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "voxel_scale"), "set_voxel_scale", "get_voxel_scale");
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_chunk_spawn_range"), &VoxelWorld::get_chunk_spawn_range);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_chunk_spawn_range", "value"), &VoxelWorld::set_chunk_spawn_range);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_spawn_range"), "set_chunk_spawn_range", "get_chunk_spawn_range");
|
|
|
|
|
2019-06-07 01:33:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_player_path"), &VoxelWorld::get_player_path);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_player_path", "value"), &VoxelWorld::set_player_path);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "player_path"), "set_player_path", "get_player_path");
|
2019-08-12 20:40:05 +02:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_player"), &VoxelWorld::get_player);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_player", "player"), &VoxelWorld::set_player_bind);
|
2020-04-17 22:09:55 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "player", PROPERTY_HINT_RESOURCE_TYPE, "Spatial", 0), "set_player", "get_player");
|
2019-08-12 20:40:05 +02:00
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_chunks"), &VoxelWorld::get_chunks);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_chunks"), &VoxelWorld::set_chunks);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "chunks", PROPERTY_HINT_NONE, "17/17:VoxelChunk", PROPERTY_USAGE_DEFAULT, "VoxelChunk"), "set_chunks", "get_chunks");
|
|
|
|
|
2019-11-10 01:03:48 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_world_area", "index"), &VoxelWorld::get_world_area);
|
|
|
|
ClassDB::bind_method(D_METHOD("add_world_area", "area"), &VoxelWorld::add_world_area);
|
|
|
|
ClassDB::bind_method(D_METHOD("remove_world_area", "index"), &VoxelWorld::remove_world_area);
|
|
|
|
ClassDB::bind_method(D_METHOD("clear_world_areas"), &VoxelWorld::clear_world_areas);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_world_area_count"), &VoxelWorld::get_world_area_count);
|
|
|
|
|
2020-04-16 13:40:39 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_voxel_structure", "index"), &VoxelWorld::get_voxel_structure);
|
|
|
|
ClassDB::bind_method(D_METHOD("add_voxel_structure", "structure"), &VoxelWorld::add_voxel_structure);
|
|
|
|
ClassDB::bind_method(D_METHOD("remove_voxel_structure", "structure"), &VoxelWorld::remove_voxel_structure);
|
|
|
|
ClassDB::bind_method(D_METHOD("remove_voxel_structure_index", "index"), &VoxelWorld::remove_voxel_structure_index);
|
|
|
|
ClassDB::bind_method(D_METHOD("clear_voxel_structures"), &VoxelWorld::clear_voxel_structures);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_voxel_structure_count"), &VoxelWorld::get_voxel_structure_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("add_voxel_structure_at_position", "structure", "world_position"), &VoxelWorld::add_voxel_structure_at_position);
|
|
|
|
|
2020-04-16 14:07:10 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_voxel_structures"), &VoxelWorld::get_voxel_structures);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_voxel_structures"), &VoxelWorld::set_voxel_structures);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "voxel_structures", PROPERTY_HINT_NONE, "17/17:VoxelStructure", PROPERTY_USAGE_DEFAULT, "VoxelStructure"), "set_voxel_structures", "get_voxel_structures");
|
|
|
|
|
2020-04-06 13:55:22 +02:00
|
|
|
BIND_VMETHOD(MethodInfo("_chunk_added", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
|
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("add_chunk", "chunk", "x", "y", "z"), &VoxelWorld::add_chunk);
|
2020-03-04 14:59:34 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("has_chunk", "x", "y", "z"), &VoxelWorld::has_chunk);
|
2019-08-12 20:40:05 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_chunk", "x", "y", "z"), &VoxelWorld::get_chunk);
|
|
|
|
ClassDB::bind_method(D_METHOD("remove_chunk", "x", "y", "z"), &VoxelWorld::remove_chunk);
|
2020-03-04 10:48:53 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("remove_chunk_index", "index"), &VoxelWorld::remove_chunk_index);
|
2019-08-12 20:40:05 +02:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_chunk_index", "index"), &VoxelWorld::get_chunk_index);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_chunk_count"), &VoxelWorld::get_chunk_count);
|
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("add_to_generation_queue", "chunk"), &VoxelWorld::add_to_generation_queue);
|
2019-11-19 16:33:06 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_generation_queue_index", "index"), &VoxelWorld::get_generation_queue_index);
|
|
|
|
ClassDB::bind_method(D_METHOD("remove_generation_queue_index", "index"), &VoxelWorld::remove_generation_queue_index);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_generation_queue_size"), &VoxelWorld::get_generation_queue_size);
|
|
|
|
|
2020-04-02 21:28:19 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("add_to_generation", "chunk"), &VoxelWorld::add_to_generation);
|
2019-11-19 16:33:06 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_generation_index", "index"), &VoxelWorld::get_generation_index);
|
|
|
|
ClassDB::bind_method(D_METHOD("remove_generation_index", "index"), &VoxelWorld::remove_generation_index);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_generation_size"), &VoxelWorld::get_generation_size);
|
|
|
|
|
2020-04-15 12:41:52 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("clear_chunks"), &VoxelWorld::clear_chunks);
|
2019-11-19 14:42:21 +01:00
|
|
|
|
2019-11-19 19:14:46 +01:00
|
|
|
ADD_SIGNAL(MethodInfo("generation_finished"));
|
|
|
|
BIND_VMETHOD(MethodInfo("_generation_finished"));
|
|
|
|
|
2019-11-19 20:39:45 +01:00
|
|
|
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")));
|
2019-11-19 19:14:46 +01:00
|
|
|
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")));
|
|
|
|
|
2020-04-10 13:39:11 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_or_create_chunk", "x", "y", "z"), &VoxelWorld::get_or_create_chunk);
|
2019-11-19 16:33:06 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("create_chunk", "x", "y", "z"), &VoxelWorld::create_chunk);
|
2020-01-09 04:29:05 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("_create_chunk", "x", "y", "z", "chunk"), &VoxelWorld::_create_chunk);
|
2019-11-19 19:14:46 +01:00
|
|
|
|
2020-01-09 04:29:05 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("_generate_chunk", "chunk"), &VoxelWorld::_generate_chunk);
|
2020-03-04 15:21:32 +01:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("can_chunk_do_build_step"), &VoxelWorld::can_chunk_do_build_step);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_position_walkable", "position"), &VoxelWorld::is_position_walkable);
|
2020-04-02 21:28:19 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("on_chunk_mesh_generation_finished", "chunk"), &VoxelWorld::on_chunk_mesh_generation_finished);
|
2020-04-15 12:41:52 +02:00
|
|
|
|
2020-07-07 02:22:45 +02:00
|
|
|
#if PROPS_PRESENT
|
2020-07-07 17:02:30 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("add_prop", "transform", "prop", "apply_voxel_scael"), &VoxelWorld::add_prop, DEFVAL(true));
|
2020-07-07 02:22:45 +02:00
|
|
|
#endif
|
2020-04-15 13:06:45 +02:00
|
|
|
|
2020-04-15 12:41:52 +02:00
|
|
|
//Lights
|
|
|
|
ClassDB::bind_method(D_METHOD("add_light", "light"), &VoxelWorld::add_light);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_light", "index"), &VoxelWorld::get_light);
|
|
|
|
ClassDB::bind_method(D_METHOD("remove_light", "index"), &VoxelWorld::remove_light);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_light_count"), &VoxelWorld::get_light_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("clear_lights"), &VoxelWorld::clear_lights);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_lights"), &VoxelWorld::get_lights);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_lights", "chunks"), &VoxelWorld::set_lights);
|
2020-04-16 14:44:22 +02:00
|
|
|
|
2020-04-17 10:15:50 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_voxel_at_world_position", "world_position", "channel_index"), &VoxelWorld::get_voxel_at_world_position);
|
2020-04-16 14:44:22 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_voxel_at_world_position", "world_position", "data", "channel_index"), &VoxelWorld::set_voxel_at_world_position);
|
2020-04-17 10:15:50 +02:00
|
|
|
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);
|
2020-04-16 21:59:30 +02:00
|
|
|
|
|
|
|
BIND_VMETHOD(MethodInfo("_get_channel_index_info", PropertyInfo(Variant::INT, "channel_type", PROPERTY_HINT_ENUM, BINDING_STRING_CHANNEL_TYPE_INFO)));
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(CHANNEL_TYPE_INFO_TYPE);
|
|
|
|
BIND_ENUM_CONSTANT(CHANNEL_TYPE_INFO_ISOLEVEL);
|
2020-04-19 23:35:47 +02:00
|
|
|
BIND_ENUM_CONSTANT(CHANNEL_TYPE_INFO_LIQUID_FLOW);
|
2019-06-07 01:33:41 +02:00
|
|
|
}
|