2021-11-22 22:00:45 +01:00
|
|
|
/*
|
2022-02-22 10:33:06 +01:00
|
|
|
Copyright (c) 2019-2022 Péter Magyar
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2022-02-22 11:09:36 +01:00
|
|
|
#include "terrain_2d_chunk.h"
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:09:36 +01:00
|
|
|
#include "terrain_2d_world.h"
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
#include "../thirdparty/lz4/lz4.h"
|
|
|
|
|
|
|
|
#include "../defines.h"
|
|
|
|
|
2022-02-22 10:33:06 +01:00
|
|
|
#include "core/message_queue.h"
|
2022-02-22 11:09:36 +01:00
|
|
|
#include "jobs/terrain_2d_job.h"
|
|
|
|
#include "terrain_2d_structure.h"
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
#if THREAD_POOL_PRESENT
|
|
|
|
#include "../../thread_pool/thread_pool.h"
|
|
|
|
#endif
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ bool Terrain2DChunk::get_process() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _is_processing;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ void Terrain2DChunk::set_process(const bool value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_is_processing = value;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ bool Terrain2DChunk::get_physics_process() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _is_phisics_processing;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ void Terrain2DChunk::set_physics_process(const bool value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_is_phisics_processing = value;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
bool Terrain2DChunk::get_visible() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _is_visible;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::set_visible(const bool value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_is_visible = value;
|
|
|
|
|
|
|
|
visibility_changed(value);
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ bool Terrain2DChunk::get_is_generating() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _is_generating;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ void Terrain2DChunk::set_is_generating(const bool value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_is_generating = value;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
bool Terrain2DChunk::is_build_aborted() const {
|
2022-02-22 10:33:06 +01:00
|
|
|
return _abort_build;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
bool Terrain2DChunk::is_in_tree() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _is_in_tree;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ bool Terrain2DChunk::get_dirty() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _dirty;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ void Terrain2DChunk::set_dirty(const bool value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_dirty = value;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ int Terrain2DChunk::get_state() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _state;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ void Terrain2DChunk::set_state(const int value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_state = value;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ int Terrain2DChunk::get_position_x() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _position_x;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::set_position_x(const int value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_position_x = value;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ int Terrain2DChunk::get_position_z() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _position_z;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::set_position_z(const int value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_position_z = value;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ Vector2 Terrain2DChunk::get_position() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return Vector2(_position_x, _position_z);
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ Vector2 Terrain2DChunk::get_world_position() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return Vector2(_position_x * _size_x * _voxel_scale, _position_z * _size_z * _voxel_scale);
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ Vector3 Terrain2DChunk::get_world_size() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return Vector3(_size_x * _voxel_scale, _world_height * _voxel_scale, _size_z * _voxel_scale);
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ AABB Terrain2DChunk::get_world_aabb() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
Vector2 v = get_world_position();
|
|
|
|
|
|
|
|
return AABB(Vector3(v.x, 0, v.y), get_world_size());
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ int Terrain2DChunk::get_size_x() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _size_x;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ int Terrain2DChunk::get_size_z() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _size_z;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ void Terrain2DChunk::set_size_x(const int value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_size_x = value;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ void Terrain2DChunk::set_size_z(const int value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_size_z = value;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ Vector3 Terrain2DChunk::get_size() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return Vector3(_size_x, _world_height, _size_z);
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ int Terrain2DChunk::get_data_size_x() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _data_size_x;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ int Terrain2DChunk::get_data_size_z() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _data_size_z;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ void Terrain2DChunk::set_data_size_x(const int value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_data_size_x = value;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ void Terrain2DChunk::set_data_size_z(const int value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_data_size_z = value;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ float Terrain2DChunk::get_world_height() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _world_height;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::set_world_height(const float value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_world_height = value;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::set_position(const int x, const int z) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_position_x = x;
|
|
|
|
_position_z = z;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ int Terrain2DChunk::get_margin_start() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _margin_start;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ int Terrain2DChunk::get_margin_end() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _margin_end;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ void Terrain2DChunk::set_margin_start(const int value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_margin_start = value;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ void Terrain2DChunk::set_margin_end(const int value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_margin_end = value;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
int Terrain2DChunk::material_cache_key_get() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _material_cache_key;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::material_cache_key_set(const int value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_material_cache_key = value;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
bool Terrain2DChunk::material_cache_key_has() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _material_cache_key_has;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::material_cache_key_has_set(const bool value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_material_cache_key_has = value;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
int Terrain2DChunk::liquid_material_cache_key_get() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _liquid_material_cache_key;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::liquid_material_cache_key_set(const int value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_liquid_material_cache_key = value;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
bool Terrain2DChunk::liquid_material_cache_key_has() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _liquid_material_cache_key_has;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::liquid_material_cache_key_has_set(const bool value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_liquid_material_cache_key_has = value;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
int Terrain2DChunk::prop_material_cache_key_get() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _prop_material_cache_key;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::prop_material_cache_key_set(const int value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_prop_material_cache_key = value;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
bool Terrain2DChunk::prop_material_cache_key_has() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _prop_material_cache_key_has;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::prop_material_cache_key_has_set(const bool value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_prop_material_cache_key_has = value;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Terrain2DLibrary> Terrain2DChunk::get_library() {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _library;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::set_library(const Ref<Terrain2DLibrary> &value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_library = value;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
float Terrain2DChunk::get_voxel_scale() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _voxel_scale;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::set_voxel_scale(const float value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_voxel_scale = value;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Terrain2DWorld *Terrain2DChunk::get_voxel_world() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _voxel_world;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::set_voxel_world(Terrain2DWorld *world) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_voxel_world = world;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::set_voxel_world_bind(Node *world) {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (world == NULL) {
|
|
|
|
_voxel_world = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_voxel_world = Object::cast_to<Terrain2DWorld>(world);
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Terrain2DJob> Terrain2DChunk::job_get(int index) const {
|
|
|
|
ERR_FAIL_INDEX_V(index, _jobs.size(), Ref<Terrain2DJob>());
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
return _jobs.get(index);
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::job_set(int index, const Ref<Terrain2DJob> &job) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(index, _jobs.size());
|
|
|
|
|
|
|
|
_jobs.set(index, job);
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::job_remove(const int index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(index, _jobs.size());
|
|
|
|
|
2022-02-22 10:33:06 +01:00
|
|
|
_jobs.VREMOVE(index);
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::job_add(const Ref<Terrain2DJob> &job) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_jobs.push_back(job);
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
int Terrain2DChunk::job_get_count() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _jobs.size();
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
int Terrain2DChunk::job_get_current_index() {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _current_job;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::job_next() {
|
2022-02-22 10:33:06 +01:00
|
|
|
if (_abort_build) {
|
|
|
|
_is_generating = false;
|
|
|
|
_current_job = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-22 22:00:45 +01:00
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
|
|
|
|
|
++_current_job;
|
|
|
|
|
|
|
|
if (_current_job >= _jobs.size()) {
|
|
|
|
_current_job = -1;
|
|
|
|
set_is_generating(false);
|
|
|
|
finalize_build();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Terrain2DJob> j = _jobs[_current_job];
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
if (!j.is_valid()) {
|
|
|
|
//skip if invalid
|
|
|
|
job_next();
|
|
|
|
}
|
|
|
|
|
|
|
|
j->reset();
|
|
|
|
j->set_complete(false);
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
if (j->get_build_phase_type() == Terrain2DJob::BUILD_PHASE_TYPE_NORMAL) {
|
2021-11-22 22:00:45 +01:00
|
|
|
#if THREAD_POOL_PRESENT
|
|
|
|
ThreadPool::get_singleton()->add_job(j);
|
|
|
|
#else
|
|
|
|
j->execute();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Terrain2DJob> Terrain2DChunk::job_get_current() {
|
2021-11-22 22:00:45 +01:00
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
|
|
|
|
|
if (_current_job < 0 || _current_job >= _jobs.size()) {
|
2022-02-22 11:42:28 +01:00
|
|
|
return Ref<Terrain2DJob>();
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return _jobs[_current_job];
|
|
|
|
}
|
|
|
|
|
|
|
|
//Terra Data
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::channel_setup() {
|
|
|
|
ERR_FAIL_COND_MSG(!has_method("_channel_setup"), "Terrain2DChunk: _setup_channels() is missing! Please implement it!");
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
call("_channel_setup");
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::set_size(const int size_x, const int size_z, const int margin_start, const int margin_end) {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (_size_x == size_x && _size_z == size_z && _margin_start == margin_start && _margin_end == margin_end) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_size_x = size_x;
|
|
|
|
_size_z = size_z;
|
|
|
|
|
|
|
|
_data_size_x = size_x + margin_start + margin_end;
|
|
|
|
_data_size_z = size_z + margin_start + margin_end;
|
|
|
|
|
|
|
|
_margin_start = margin_start;
|
|
|
|
_margin_end = margin_end;
|
|
|
|
|
|
|
|
for (int i = 0; i < _channels.size(); ++i) {
|
|
|
|
uint8_t *ch = _channels[i];
|
|
|
|
|
|
|
|
if (ch != NULL) {
|
|
|
|
memdelete_arr(ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_channels.clear();
|
|
|
|
|
|
|
|
channel_setup();
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
bool Terrain2DChunk::validate_data_position(const int x, const int z) const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return x < _data_size_x && z < _data_size_z;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
uint8_t Terrain2DChunk::get_voxel(const int p_x, const int p_z, const int p_channel_index) const {
|
2021-11-22 22:00:45 +01:00
|
|
|
int x = p_x + _margin_start;
|
|
|
|
int z = p_z + _margin_start;
|
|
|
|
|
|
|
|
ERR_FAIL_INDEX_V(p_channel_index, _channels.size(), 0);
|
|
|
|
ERR_FAIL_COND_V_MSG(!validate_data_position(x, z), 0, "Error, index out of range! " + String::num(x) + " " + String::num(z));
|
|
|
|
|
|
|
|
uint8_t *ch = _channels.get(p_channel_index);
|
|
|
|
|
|
|
|
if (!ch)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return ch[get_data_index(x, z)];
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::set_voxel(const uint8_t p_value, const int p_x, const int p_z, const int p_channel_index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
int x = p_x + _margin_start;
|
|
|
|
int z = p_z + _margin_start;
|
|
|
|
|
|
|
|
ERR_FAIL_INDEX(p_channel_index, _channels.size());
|
|
|
|
ERR_FAIL_COND_MSG(!validate_data_position(x, z), "Error, index out of range! " + String::num(x) + " " + String::num(z));
|
|
|
|
|
|
|
|
uint8_t *ch = channel_get_valid(p_channel_index);
|
|
|
|
|
|
|
|
ch[get_data_index(x, z)] = p_value;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
int Terrain2DChunk::channel_get_count() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _channels.size();
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::channel_set_count(const int count) {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (count == _channels.size())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (_channels.size() >= count) {
|
|
|
|
for (int i = count; i < _channels.size(); ++i) {
|
|
|
|
uint8_t *ch = _channels[i];
|
|
|
|
|
|
|
|
if (ch != NULL) {
|
|
|
|
memdelete_arr(ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
_channels.set(i, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
_channels.resize(count);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int s = _channels.size();
|
|
|
|
_channels.resize(count);
|
|
|
|
|
|
|
|
for (int i = s; i < count; ++i) {
|
|
|
|
_channels.set(i, NULL);
|
|
|
|
}
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
bool Terrain2DChunk::channel_is_allocated(const int channel_index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX_V(channel_index, _channels.size(), false);
|
|
|
|
|
|
|
|
return _channels[channel_index] != NULL;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::channel_ensure_allocated(const int channel_index, const uint8_t default_value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(channel_index, _channels.size());
|
|
|
|
|
|
|
|
if (_channels[channel_index] == NULL)
|
|
|
|
channel_allocate(channel_index, default_value);
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::channel_allocate(const int channel_index, const uint8_t default_value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(channel_index, _channels.size());
|
|
|
|
|
|
|
|
if (_channels[channel_index] != NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint32_t size = _data_size_x * _data_size_z;
|
|
|
|
|
|
|
|
uint8_t *ch = memnew_arr(uint8_t, size);
|
|
|
|
memset(ch, default_value, size);
|
|
|
|
|
|
|
|
_channels.set(channel_index, ch);
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::channel_fill(const uint8_t value, const int channel_index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(channel_index, _channels.size());
|
|
|
|
|
|
|
|
uint8_t *ch = _channels.get(channel_index);
|
|
|
|
|
|
|
|
if (ch == NULL) {
|
|
|
|
channel_allocate(channel_index, value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t size = get_data_size();
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < size; ++i) {
|
|
|
|
ch[i] = value;
|
|
|
|
}
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::channel_dealloc(const int channel_index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(channel_index, _channels.size());
|
|
|
|
|
|
|
|
uint8_t *ch = _channels.get(channel_index);
|
|
|
|
|
|
|
|
if (ch != NULL) {
|
|
|
|
memdelete_arr(ch);
|
|
|
|
|
|
|
|
_channels.set(channel_index, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
uint8_t *Terrain2DChunk::channel_get(const int channel_index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX_V(channel_index, _channels.size(), NULL);
|
|
|
|
|
|
|
|
return _channels.get(channel_index);
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
uint8_t *Terrain2DChunk::channel_get_valid(const int channel_index, const uint8_t default_value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX_V(channel_index, _channels.size(), 0);
|
|
|
|
|
|
|
|
uint8_t *ch = _channels.get(channel_index);
|
|
|
|
|
|
|
|
if (ch == NULL) {
|
|
|
|
channel_allocate(channel_index, default_value);
|
|
|
|
|
|
|
|
return _channels.get(channel_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
PoolByteArray Terrain2DChunk::channel_get_array(const int channel_index) const {
|
2021-11-22 22:00:45 +01:00
|
|
|
PoolByteArray arr;
|
|
|
|
|
|
|
|
uint32_t size = _data_size_x * _data_size_z;
|
|
|
|
|
|
|
|
if (channel_index >= _channels.size())
|
|
|
|
return arr;
|
|
|
|
|
|
|
|
uint8_t *ch = _channels.get(channel_index);
|
|
|
|
|
|
|
|
if (ch == NULL)
|
|
|
|
return arr;
|
|
|
|
|
|
|
|
arr.resize(size);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < size; ++i) {
|
|
|
|
arr.set(i, ch[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return arr;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::channel_set_array(const int channel_index, const PoolByteArray &array) {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (array.size() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (_channels.size() <= channel_index)
|
|
|
|
channel_set_count(channel_index + 1);
|
|
|
|
|
|
|
|
uint8_t *ch = _channels.get(channel_index);
|
|
|
|
|
|
|
|
if (ch == NULL) {
|
|
|
|
if (_channels[channel_index] != NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ch = memnew_arr(uint8_t, array.size());
|
|
|
|
_channels.set(channel_index, ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < array.size(); ++i) {
|
|
|
|
ch[i] = array[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
PoolByteArray Terrain2DChunk::channel_get_compressed(const int channel_index) const {
|
2021-11-22 22:00:45 +01:00
|
|
|
PoolByteArray arr;
|
|
|
|
|
|
|
|
int size = _data_size_x * _data_size_z;
|
|
|
|
|
|
|
|
if (channel_index >= _channels.size())
|
|
|
|
return arr;
|
|
|
|
|
|
|
|
uint8_t *ch = _channels.get(channel_index);
|
|
|
|
|
|
|
|
if (ch == NULL)
|
|
|
|
return arr;
|
|
|
|
|
|
|
|
int bound = LZ4_compressBound(size);
|
|
|
|
arr.resize(bound);
|
|
|
|
|
|
|
|
#if !GODOT4
|
|
|
|
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;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::channel_set_compressed(const int channel_index, const PoolByteArray &data) {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (data.size() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int size = _data_size_x * _data_size_z;
|
|
|
|
|
|
|
|
if (_channels.size() <= channel_index)
|
|
|
|
channel_set_count(channel_index + 1);
|
|
|
|
|
|
|
|
uint8_t *ch = _channels.get(channel_index);
|
|
|
|
|
|
|
|
if (ch == NULL) {
|
|
|
|
if (_channels[channel_index] != NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ch = memnew_arr(uint8_t, size);
|
|
|
|
_channels.set(channel_index, ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ds = data.size();
|
|
|
|
|
|
|
|
#if !GODOT4
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ int Terrain2DChunk::get_index(const int x, const int z) const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return ((x + _margin_start) + _data_size_x * (z + _margin_start));
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ int Terrain2DChunk::get_data_index(const int x, const int z) const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return (x + _data_size_x * z);
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
_FORCE_INLINE_ int Terrain2DChunk::get_data_size() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _data_size_x * _data_size_z;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Terra Structures
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Terrain2DStructure> Terrain2DChunk::voxel_structure_get(const int index) const {
|
|
|
|
ERR_FAIL_INDEX_V(index, _voxel_structures.size(), Ref<Terrain2DStructure>());
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
return _voxel_structures.get(index);
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::voxel_structure_add(const Ref<Terrain2DStructure> &structure) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_voxel_structures.push_back(structure);
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::voxel_structure_remove(const Ref<Terrain2DStructure> &structure) {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (!structure.is_valid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
int index = _voxel_structures.find(structure);
|
|
|
|
|
|
|
|
if (index != -1)
|
2022-02-22 10:33:06 +01:00
|
|
|
_voxel_structures.VREMOVE(index);
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::voxel_structure_remove_index(const int index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(index, _voxel_structures.size());
|
|
|
|
|
2022-02-22 10:33:06 +01:00
|
|
|
_voxel_structures.VREMOVE(index);
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::voxel_structure_clear() {
|
2021-11-22 22:00:45 +01:00
|
|
|
_voxel_structures.clear();
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
int Terrain2DChunk::voxel_structure_get_count() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _voxel_structures.size();
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::voxel_structure_add_at_position(Ref<Terrain2DStructure> structure, const Vector3 &world_position) {
|
2021-11-22 22:00:45 +01:00
|
|
|
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));
|
|
|
|
|
|
|
|
voxel_structure_add(structure);
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Vector<Variant> Terrain2DChunk::voxel_structures_get() {
|
2021-11-22 22:00:45 +01:00
|
|
|
VARIANT_ARRAY_GET(_voxel_structures);
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::voxel_structures_set(const Vector<Variant> &structures) {
|
2021-11-22 22:00:45 +01:00
|
|
|
voxel_structure_clear();
|
|
|
|
|
|
|
|
for (int i = 0; i < structures.size(); ++i) {
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Terrain2DLight> structure = Ref<Terrain2DLight>(structures[i]);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
voxel_structure_add(structure);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::build() {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_COND(!INSTANCE_VALIDATE(get_voxel_world()));
|
|
|
|
ERR_FAIL_COND(!get_voxel_world()->is_inside_tree());
|
|
|
|
ERR_FAIL_COND(!is_in_tree());
|
|
|
|
|
|
|
|
call("_build");
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::_build() {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (get_is_generating()) {
|
|
|
|
_queued_generation = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_is_generating = true;
|
|
|
|
|
|
|
|
job_next();
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::clear() {
|
|
|
|
ERR_FAIL_COND_MSG(!has_method("_clear"), "Terrain2DChunk: _clear() is missing! Please implement it!");
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
call("_clear");
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::finalize_build() {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (has_method("_finalize_build")) {
|
|
|
|
call("_finalize_build");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::cancel_build() {
|
2022-02-22 10:33:06 +01:00
|
|
|
_queued_generation = false;
|
|
|
|
|
|
|
|
_abort_build = true;
|
|
|
|
|
|
|
|
#if THREAD_POOL_PRESENT
|
|
|
|
if (_is_generating) {
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Terrain2DJob> job = job_get_current();
|
2022-02-22 10:33:06 +01:00
|
|
|
|
|
|
|
if (job.is_valid()) {
|
|
|
|
ThreadPool::get_singleton()->cancel_job(job);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::bake_lights() {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (has_method("_bake_lights"))
|
|
|
|
call("_bake_lights");
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::bake_light(Ref<Terrain2DLight> light) {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (!light.is_valid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (has_method("_bake_lights"))
|
|
|
|
call("_bake_light", light);
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::clear_baked_lights() {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (has_method("_clear_baked_lights"))
|
|
|
|
call("_clear_baked_lights");
|
|
|
|
}
|
|
|
|
|
|
|
|
#if PROPS_PRESENT
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::prop_add(const Transform &tarnsform, const Ref<PropData> &prop) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_COND(!prop.is_valid());
|
|
|
|
|
|
|
|
PropDataStore s;
|
|
|
|
s.transform = tarnsform;
|
|
|
|
s.prop = prop;
|
|
|
|
|
|
|
|
_props.push_back(s);
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<PropData> Terrain2DChunk::prop_get(int index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX_V(index, _props.size(), Ref<PropData>());
|
|
|
|
|
|
|
|
return _props.get(index).prop;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
Transform Terrain2DChunk::prop_get_tarnsform(const int index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX_V(index, _props.size(), Transform());
|
|
|
|
|
|
|
|
return _props.get(index).transform;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
int Terrain2DChunk::prop_get_count() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _props.size();
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::prop_remove(const int index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(index, _props.size());
|
|
|
|
|
2022-02-22 10:33:06 +01:00
|
|
|
_props.VREMOVE(index);
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::props_clear() {
|
2021-11-22 22:00:45 +01:00
|
|
|
_props.clear();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MESH_DATA_RESOURCE_PRESENT
|
2022-02-22 11:42:28 +01:00
|
|
|
int Terrain2DChunk::mesh_data_resource_addv(const Vector3 &local_data_pos, const Ref<MeshDataResource> &mesh, const Ref<Texture> &texture, const Color &color, const bool apply_voxel_scale) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_COND_V(!mesh.is_valid(), 0);
|
|
|
|
|
|
|
|
int index = _mesh_data_resources.size();
|
|
|
|
|
|
|
|
MeshDataResourceEntry e;
|
|
|
|
|
|
|
|
if (apply_voxel_scale) {
|
|
|
|
e.transform = Transform(Basis().scaled(Vector3(_voxel_scale, _voxel_scale, _voxel_scale)));
|
|
|
|
e.transform.origin = local_data_pos * _voxel_scale;
|
|
|
|
} else {
|
|
|
|
e.transform.origin = local_data_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
e.mesh = mesh;
|
|
|
|
e.texture = texture;
|
|
|
|
e.color = color;
|
|
|
|
|
|
|
|
AABB aabb = AABB(Vector3(), get_world_size());
|
|
|
|
AABB mesh_aabb = e.transform.xform(mesh->get_aabb());
|
|
|
|
e.is_inside = aabb.encloses(mesh_aabb);
|
|
|
|
|
|
|
|
#if PROPS_PRESENT
|
|
|
|
if (get_library().is_valid() && texture.is_valid()) {
|
|
|
|
e.uv_rect = get_library()->get_prop_uv_rect(texture);
|
|
|
|
} else {
|
|
|
|
e.uv_rect = Rect2(0, 0, 1, 1);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
e.uv_rect = Rect2(0, 0, 1, 1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_mesh_data_resources.push_back(e);
|
|
|
|
|
|
|
|
if (has_method("_mesh_data_resource_added"))
|
|
|
|
call("_mesh_data_resource_added", index);
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
int Terrain2DChunk::mesh_data_resource_add(const Transform &local_transform, const Ref<MeshDataResource> &mesh, const Ref<Texture> &texture, const Color &color, const bool apply_voxel_scale) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_COND_V(!mesh.is_valid(), 0);
|
|
|
|
|
|
|
|
int index = _mesh_data_resources.size();
|
|
|
|
|
|
|
|
MeshDataResourceEntry e;
|
|
|
|
|
|
|
|
e.transform = local_transform;
|
|
|
|
|
|
|
|
if (apply_voxel_scale) {
|
|
|
|
e.transform.basis = e.transform.basis.scaled(Vector3(_voxel_scale, _voxel_scale, _voxel_scale));
|
|
|
|
e.transform.origin = e.transform.origin * _voxel_scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
e.mesh = mesh;
|
|
|
|
e.texture = texture;
|
|
|
|
e.color = color;
|
|
|
|
|
|
|
|
AABB aabb = AABB(Vector3(), get_world_size());
|
|
|
|
AABB mesh_aabb = e.transform.xform(mesh->get_aabb());
|
|
|
|
e.is_inside = aabb.encloses(mesh_aabb);
|
|
|
|
|
|
|
|
#if PROPS_PRESENT
|
|
|
|
if (get_library().is_valid() && texture.is_valid())
|
|
|
|
e.uv_rect = get_library()->get_prop_uv_rect(texture);
|
|
|
|
else
|
|
|
|
e.uv_rect = Rect2(0, 0, 1, 1);
|
|
|
|
#else
|
|
|
|
e.uv_rect = Rect2(0, 0, 1, 1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_mesh_data_resources.push_back(e);
|
|
|
|
|
|
|
|
if (has_method("_mesh_data_resource_added"))
|
|
|
|
call("_mesh_data_resource_added", index);
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<MeshDataResource> Terrain2DChunk::mesh_data_resource_get(const int index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX_V(index, _mesh_data_resources.size(), Ref<MeshDataResource>());
|
|
|
|
|
|
|
|
return _mesh_data_resources[index].mesh;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::mesh_data_resource_set(const int index, const Ref<MeshDataResource> &mesh) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(index, _mesh_data_resources.size());
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Texture> Terrain2DChunk::mesh_data_resource_get_texture(const int index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX_V(index, _mesh_data_resources.size(), Ref<Texture>());
|
|
|
|
|
|
|
|
return _mesh_data_resources[index].texture;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::mesh_data_resource_set_texture(const int index, const Ref<Texture> &texture) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(index, _mesh_data_resources.size());
|
|
|
|
|
|
|
|
_mesh_data_resources.write[index].texture = texture;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Color Terrain2DChunk::mesh_data_resource_get_color(const int index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX_V(index, _mesh_data_resources.size(), Color());
|
|
|
|
|
|
|
|
return _mesh_data_resources[index].color;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::mesh_data_resource_set_color(const int index, const Color &color) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(index, _mesh_data_resources.size());
|
|
|
|
|
|
|
|
_mesh_data_resources.write[index].color = color;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Rect2 Terrain2DChunk::mesh_data_resource_get_uv_rect(const int index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX_V(index, _mesh_data_resources.size(), Rect2());
|
|
|
|
|
|
|
|
return _mesh_data_resources[index].uv_rect;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::mesh_data_resource_set_uv_rect(const int index, const Rect2 &uv_rect) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(index, _mesh_data_resources.size());
|
|
|
|
|
|
|
|
_mesh_data_resources.write[index].uv_rect = uv_rect;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Transform Terrain2DChunk::mesh_data_resource_get_transform(const int index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX_V(index, _mesh_data_resources.size(), Transform());
|
|
|
|
|
|
|
|
return _mesh_data_resources.write[index].transform;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::mesh_data_resource_set_transform(const int index, const Transform &transform) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(index, _mesh_data_resources.size());
|
|
|
|
|
|
|
|
_mesh_data_resources.write[index].transform = transform;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
bool Terrain2DChunk::mesh_data_resource_get_is_inside(const int index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX_V(index, _mesh_data_resources.size(), true);
|
|
|
|
|
|
|
|
return _mesh_data_resources[index].is_inside;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::mesh_data_resource_set_is_inside(const int index, const bool inside) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(index, _mesh_data_resources.size());
|
|
|
|
|
|
|
|
_mesh_data_resources.write[index].is_inside = inside;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
int Terrain2DChunk::mesh_data_resource_get_count() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _mesh_data_resources.size();
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::mesh_data_resource_remove(const int index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(index, _mesh_data_resources.size());
|
|
|
|
|
2022-02-22 10:33:06 +01:00
|
|
|
_mesh_data_resources.VREMOVE(index);
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::mesh_data_resource_clear() {
|
2021-11-22 22:00:45 +01:00
|
|
|
_mesh_data_resources.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
int Terrain2DChunk::collider_add(const Transform &local_transform, const Ref<Shape> &shape, const RID &shape_rid, const RID &body) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_COND_V(!shape.is_valid() && shape_rid == RID(), 0);
|
|
|
|
|
|
|
|
int index = _colliders.size();
|
|
|
|
|
|
|
|
ColliderBody e;
|
|
|
|
e.transform = local_transform;
|
|
|
|
e.body = body;
|
|
|
|
e.shape = shape;
|
|
|
|
e.shape_rid = shape_rid;
|
|
|
|
|
|
|
|
_colliders.push_back(e);
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Transform Terrain2DChunk::collider_get_transform(const int index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX_V(index, _colliders.size(), Transform());
|
|
|
|
|
|
|
|
return _colliders[index].transform;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::collider_set_transform(const int index, const Transform &transform) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(index, _colliders.size());
|
|
|
|
|
|
|
|
_colliders.write[index].transform = transform;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Shape> Terrain2DChunk::collider_get_shape(const int index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX_V(index, _colliders.size(), Ref<Shape>());
|
|
|
|
|
|
|
|
return _colliders[index].shape;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::collider_set_shape(const int index, const Ref<Shape> &shape) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(index, _colliders.size());
|
|
|
|
|
|
|
|
_colliders.write[index].shape = shape;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
RID Terrain2DChunk::collider_get_shape_rid(const int index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX_V(index, _colliders.size(), RID());
|
|
|
|
|
|
|
|
return _colliders[index].shape_rid;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::collider_set_shape_rid(const int index, const RID &rid) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(index, _colliders.size());
|
|
|
|
|
|
|
|
_colliders.write[index].shape_rid = rid;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
RID Terrain2DChunk::collider_get_body(const int index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX_V(index, _colliders.size(), RID());
|
|
|
|
|
|
|
|
return _colliders[index].body;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::collider_set_body(const int index, const RID &rid) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(index, _colliders.size());
|
|
|
|
|
|
|
|
_colliders.write[index].body = rid;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
int Terrain2DChunk::collider_get_count() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _colliders.size();
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::collider_remove(const int index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(index, _colliders.size());
|
|
|
|
|
2022-02-22 10:33:06 +01:00
|
|
|
_colliders.VREMOVE(index);
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::colliders_clear() {
|
2021-11-22 22:00:45 +01:00
|
|
|
_colliders.clear();
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::enter_tree() {
|
2021-11-22 22:00:45 +01:00
|
|
|
_is_in_tree = true;
|
|
|
|
|
|
|
|
if (has_method("_enter_tree"))
|
|
|
|
call("_enter_tree");
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::exit_tree() {
|
2021-11-22 22:00:45 +01:00
|
|
|
_is_in_tree = false;
|
|
|
|
|
|
|
|
if (has_method("_exit_tree"))
|
|
|
|
call("_exit_tree");
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::process(const float delta) {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (has_method("_process"))
|
|
|
|
call("_process", delta);
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::physics_process(const float delta) {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (has_method("_physics_process"))
|
|
|
|
call("_physics_process", delta);
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::world_transform_changed() {
|
2021-11-22 22:00:45 +01:00
|
|
|
call("_world_transform_changed");
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::visibility_changed(const bool visible) {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (has_method("_visibility_changed"))
|
|
|
|
call("_visibility_changed", _is_visible);
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::world_light_added(const Ref<Terrain2DLight> &light) {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (has_method("_world_light_added"))
|
|
|
|
call("_world_light_added", light);
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::world_light_removed(const Ref<Terrain2DLight> &light) {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (has_method("_world_light_removed"))
|
|
|
|
call("_world_light_removed", light);
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::generation_process(const float delta) {
|
2021-11-22 22:00:45 +01:00
|
|
|
call("_generation_process", delta);
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::generation_physics_process(const float delta) {
|
2021-11-22 22:00:45 +01:00
|
|
|
call("_generation_physics_process", delta);
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Transform Terrain2DChunk::get_transform() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _transform;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::set_transform(const Transform &transform) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_transform = transform;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Transform Terrain2DChunk::get_global_transform() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_COND_V(!get_voxel_world(), Transform());
|
|
|
|
|
|
|
|
return get_voxel_world()->get_global_transform() * _transform;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Vector3 Terrain2DChunk::to_local(Vector3 p_global) const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return get_global_transform().affine_inverse().xform(p_global);
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Vector3 Terrain2DChunk::to_global(Vector3 p_local) const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return get_global_transform().xform(p_local);
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
bool Terrain2DChunk::is_safe_to_delete() {
|
2022-02-22 10:33:06 +01:00
|
|
|
#if THREAD_POOL_PRESENT
|
|
|
|
if (!_is_generating) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Terrain2DJob> job = job_get_current();
|
2022-02-22 10:33:06 +01:00
|
|
|
|
|
|
|
if (!job.is_valid()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !ThreadPool::get_singleton()->has_job(job);
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Terrain2DChunk::Terrain2DChunk() {
|
2021-11-22 22:00:45 +01:00
|
|
|
_is_processing = false;
|
|
|
|
_is_phisics_processing = false;
|
|
|
|
_is_in_tree = false;
|
|
|
|
|
|
|
|
_is_visible = true;
|
|
|
|
|
|
|
|
_is_generating = false;
|
|
|
|
_dirty = false;
|
2022-02-22 10:33:06 +01:00
|
|
|
_state = TERRAIN_CHUNK_STATE_OK;
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
_voxel_scale = 1;
|
|
|
|
|
|
|
|
_voxel_world = NULL;
|
|
|
|
|
|
|
|
_position_x = 0;
|
|
|
|
_position_z = 0;
|
|
|
|
|
|
|
|
_size_x = 0;
|
|
|
|
_size_z = 0;
|
|
|
|
|
|
|
|
_data_size_x = 0;
|
|
|
|
_data_size_z = 0;
|
|
|
|
|
|
|
|
_margin_start = 0;
|
|
|
|
_margin_end = 0;
|
|
|
|
|
|
|
|
_material_cache_key = 0;
|
|
|
|
_material_cache_key_has = false;
|
|
|
|
|
|
|
|
_liquid_material_cache_key = 0;
|
|
|
|
_liquid_material_cache_key_has = false;
|
|
|
|
|
|
|
|
_prop_material_cache_key = 0;
|
|
|
|
_prop_material_cache_key_has = false;
|
|
|
|
|
|
|
|
_current_job = -1;
|
|
|
|
|
|
|
|
_world_height = 256;
|
|
|
|
|
|
|
|
_queued_generation = false;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Terrain2DChunk::~Terrain2DChunk() {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (_library.is_valid()) {
|
|
|
|
_library.unref();
|
|
|
|
}
|
|
|
|
|
|
|
|
#if PROPS_PRESENT
|
|
|
|
props_clear();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MESH_DATA_RESOURCE_PRESENT
|
|
|
|
mesh_data_resource_clear();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (int i = 0; i < _channels.size(); ++i) {
|
|
|
|
uint8_t *ch = _channels[i];
|
|
|
|
|
|
|
|
if (ch != NULL) {
|
|
|
|
memdelete_arr(ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < _colliders.size(); ++i) {
|
|
|
|
PhysicsServer::get_singleton()->free(_colliders[i].body);
|
|
|
|
}
|
|
|
|
|
|
|
|
_colliders.clear();
|
|
|
|
|
|
|
|
_jobs.clear();
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::_enter_tree() {
|
2021-11-22 22:00:45 +01:00
|
|
|
for (int i = 0; i < _jobs.size(); ++i) {
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Terrain2DJob> j = _jobs[i];
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
if (j.is_valid()) {
|
2022-02-22 11:42:28 +01:00
|
|
|
j->set_chunk(Ref<Terrain2DChunk>(this));
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::_exit_tree() {
|
2022-02-22 10:33:06 +01:00
|
|
|
if (_is_generating) {
|
|
|
|
cancel_build();
|
|
|
|
}
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < _jobs.size(); ++i) {
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Terrain2DJob> j = _jobs[i];
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
if (j.is_valid()) {
|
|
|
|
j->chunk_exit_tree();
|
|
|
|
}
|
|
|
|
}
|
2022-02-22 10:33:06 +01:00
|
|
|
|
|
|
|
if (_library.is_valid() && _library->supports_caching()) {
|
|
|
|
if (material_cache_key_has()) {
|
|
|
|
_library->material_cache_unref(material_cache_key_get());
|
|
|
|
}
|
|
|
|
}
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::_generation_process(const float delta) {
|
2022-02-22 10:33:06 +01:00
|
|
|
if (_abort_build) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-22 22:00:45 +01:00
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
|
|
|
|
|
if (_current_job < 0 || _current_job >= _jobs.size())
|
|
|
|
return;
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Terrain2DJob> job = _jobs[_current_job];
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!job.is_valid());
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
if (job->get_build_phase_type() == Terrain2DJob::BUILD_PHASE_TYPE_PROCESS) {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (!_voxel_world->can_chunk_do_build_step())
|
|
|
|
return;
|
|
|
|
|
|
|
|
job->process(delta);
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
if (job->get_build_phase_type() == Terrain2DJob::BUILD_PHASE_TYPE_NORMAL) {
|
2021-11-22 22:00:45 +01:00
|
|
|
#if THREAD_POOL_PRESENT
|
|
|
|
ThreadPool::get_singleton()->add_job(job);
|
|
|
|
#else
|
|
|
|
job->execute();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::_generation_physics_process(const float delta) {
|
2022-02-22 10:33:06 +01:00
|
|
|
if (_abort_build) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-22 22:00:45 +01:00
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
|
|
|
|
|
if (_current_job < 0 || _current_job >= _jobs.size())
|
|
|
|
return;
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Terrain2DJob> job = _jobs[_current_job];
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!job.is_valid());
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
if (job->get_build_phase_type() == Terrain2DJob::BUILD_PHASE_TYPE_PHYSICS_PROCESS) {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (!_voxel_world->can_chunk_do_build_step())
|
|
|
|
return;
|
|
|
|
|
|
|
|
job->physics_process(delta);
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
if (job->get_build_phase_type() == Terrain2DJob::BUILD_PHASE_TYPE_NORMAL) {
|
2021-11-22 22:00:45 +01:00
|
|
|
#if THREAD_POOL_PRESENT
|
|
|
|
ThreadPool::get_singleton()->add_job(job);
|
|
|
|
#else
|
|
|
|
job->execute();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::_world_transform_changed() {
|
2021-11-22 22:00:45 +01:00
|
|
|
Transform wt;
|
|
|
|
|
|
|
|
if (_voxel_world != NULL) {
|
|
|
|
wt = _voxel_world->get_transform();
|
|
|
|
}
|
|
|
|
|
|
|
|
set_transform(wt * Transform(Basis(), Vector3(_position_x * static_cast<int>(_size_x) * _voxel_scale, 0, _position_z * static_cast<int>(_size_z) * _voxel_scale)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2022-02-22 11:42:28 +01:00
|
|
|
bool Terrain2DChunk::_set(const StringName &p_name, const Variant &p_value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
String name = p_name;
|
|
|
|
|
|
|
|
if (name.begins_with("channels/")) {
|
|
|
|
|
|
|
|
int index = name.get_slicec('/', 1).to_int();
|
|
|
|
|
|
|
|
if (_channels.size() <= index) {
|
|
|
|
set_channel_count(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
PoolByteArray arr = p_value;
|
|
|
|
|
|
|
|
if (arr.size() == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
set_channel_array(index, arr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
bool Terrain2DChunk::_get(const StringName &p_name, Variant &r_ret) const {
|
2021-11-22 22:00:45 +01:00
|
|
|
String name = p_name;
|
|
|
|
|
|
|
|
if (name.begins_with("channels/")) {
|
|
|
|
|
|
|
|
int index = name.get_slicec('/', 1).to_int();
|
|
|
|
|
|
|
|
r_ret = get_channel_array(index);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::_get_property_list(List<PropertyInfo> *p_list) const {
|
2021-11-22 22:00:45 +01:00
|
|
|
for (int i = 0; i < _channels.size(); ++i) {
|
|
|
|
p_list->push_back(PropertyInfo(Variant::POOL_BYTE_ARRAY, "channels/" + String::num(i), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DChunk::_bind_methods() {
|
|
|
|
ADD_SIGNAL(MethodInfo("mesh_generation_finished", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "Terrain2DChunk")));
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
BIND_VMETHOD(MethodInfo("_mesh_data_resource_added", PropertyInfo(Variant::INT, "index")));
|
|
|
|
|
|
|
|
BIND_VMETHOD(MethodInfo("_channel_setup"));
|
|
|
|
|
|
|
|
BIND_VMETHOD(MethodInfo("_bake_lights"));
|
2022-02-22 11:42:28 +01:00
|
|
|
BIND_VMETHOD(MethodInfo("_bake_light", PropertyInfo(Variant::OBJECT, "light", PROPERTY_HINT_RESOURCE_TYPE, "Terrain2DLight")));
|
2021-11-22 22:00:45 +01:00
|
|
|
BIND_VMETHOD(MethodInfo("_clear_baked_lights"));
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("bake_lights"), &Terrain2DChunk::bake_lights);
|
|
|
|
ClassDB::bind_method(D_METHOD("bake_light", "light"), &Terrain2DChunk::bake_light);
|
|
|
|
ClassDB::bind_method(D_METHOD("clear_baked_lights"), &Terrain2DChunk::clear_baked_lights);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
BIND_VMETHOD(MethodInfo("_enter_tree"));
|
|
|
|
BIND_VMETHOD(MethodInfo("_exit_tree"));
|
|
|
|
BIND_VMETHOD(MethodInfo("_process", PropertyInfo(Variant::REAL, "delta")));
|
|
|
|
BIND_VMETHOD(MethodInfo("_physics_process", PropertyInfo(Variant::REAL, "delta")));
|
|
|
|
BIND_VMETHOD(MethodInfo("_world_transform_changed"));
|
|
|
|
BIND_VMETHOD(MethodInfo("_visibility_changed", PropertyInfo(Variant::BOOL, "visible")));
|
2022-02-22 11:42:28 +01:00
|
|
|
BIND_VMETHOD(MethodInfo("_world_light_added", PropertyInfo(Variant::OBJECT, "light", PROPERTY_HINT_RESOURCE_TYPE, "Terrain2DLight")));
|
|
|
|
BIND_VMETHOD(MethodInfo("_world_light_removed", PropertyInfo(Variant::OBJECT, "light", PROPERTY_HINT_RESOURCE_TYPE, "Terrain2DLight")));
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
BIND_VMETHOD(MethodInfo("_generation_process", PropertyInfo(Variant::REAL, "delta")));
|
|
|
|
BIND_VMETHOD(MethodInfo("_generation_physics_process", PropertyInfo(Variant::REAL, "delta")));
|
|
|
|
|
|
|
|
BIND_VMETHOD(MethodInfo("_finalize_build"));
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("enter_tree"), &Terrain2DChunk::enter_tree);
|
|
|
|
ClassDB::bind_method(D_METHOD("exit_tree"), &Terrain2DChunk::exit_tree);
|
|
|
|
ClassDB::bind_method(D_METHOD("process", "delta"), &Terrain2DChunk::process);
|
|
|
|
ClassDB::bind_method(D_METHOD("physics_process", "delta"), &Terrain2DChunk::physics_process);
|
|
|
|
ClassDB::bind_method(D_METHOD("world_transform_changed"), &Terrain2DChunk::world_transform_changed);
|
|
|
|
ClassDB::bind_method(D_METHOD("visibility_changed", "visible"), &Terrain2DChunk::visibility_changed);
|
|
|
|
ClassDB::bind_method(D_METHOD("world_light_added", "light"), &Terrain2DChunk::world_light_added);
|
|
|
|
ClassDB::bind_method(D_METHOD("world_light_removed", "light"), &Terrain2DChunk::world_light_removed);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("generation_process", "delta"), &Terrain2DChunk::generation_process);
|
|
|
|
ClassDB::bind_method(D_METHOD("generation_physics_process", "delta"), &Terrain2DChunk::generation_physics_process);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("finalize_build"), &Terrain2DChunk::finalize_build);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("cancel_build"), &Terrain2DChunk::cancel_build);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_process"), &Terrain2DChunk::get_process);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_process", "value"), &Terrain2DChunk::set_process);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_physics_process"), &Terrain2DChunk::get_physics_process);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_physics_process", "value"), &Terrain2DChunk::set_physics_process);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("is_in_tree"), &Terrain2DChunk::is_in_tree);
|
2022-02-22 10:33:06 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_transform"), &Terrain2DChunk::get_transform);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_transform", "value"), &Terrain2DChunk::set_transform);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "transform"), "set_transform", "get_transform");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_visible"), &Terrain2DChunk::get_visible);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_visible", "value"), &Terrain2DChunk::set_visible);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "get_visible");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_is_generating"), &Terrain2DChunk::get_is_generating);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_is_generating", "value"), &Terrain2DChunk::set_is_generating);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "is_generating", PROPERTY_HINT_NONE, "", 0), "set_is_generating", "get_is_generating");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("is_build_aborted"), &Terrain2DChunk::is_build_aborted);
|
2022-02-22 10:33:06 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_dirty"), &Terrain2DChunk::get_dirty);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_dirty", "value"), &Terrain2DChunk::set_dirty);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "dirty", PROPERTY_HINT_NONE, "", 0), "set_dirty", "get_dirty");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_state"), &Terrain2DChunk::get_state);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_state", "value"), &Terrain2DChunk::set_state);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "state", PROPERTY_HINT_NONE, "", 0), "set_state", "get_state");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_position_x"), &Terrain2DChunk::get_position_x);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_position_x", "value"), &Terrain2DChunk::set_position_x);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "position_x"), "set_position_x", "get_position_x");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_position_z"), &Terrain2DChunk::get_position_z);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_position_z", "value"), &Terrain2DChunk::set_position_z);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "position_z"), "set_position_z", "get_position_z");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_size_x"), &Terrain2DChunk::get_size_x);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_size_x"), &Terrain2DChunk::set_size_x);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_x"), "set_size_x", "get_size_x");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_size_z"), &Terrain2DChunk::get_size_z);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_size_z"), &Terrain2DChunk::set_size_z);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_z"), "set_size_z", "get_size_z");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_data_size_x"), &Terrain2DChunk::get_data_size_x);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_data_size_x"), &Terrain2DChunk::set_data_size_x);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "data_size_x"), "set_data_size_x", "get_data_size_x");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_data_size_z"), &Terrain2DChunk::get_data_size_z);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_data_size_z"), &Terrain2DChunk::set_data_size_z);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "data_size_z"), "set_data_size_z", "get_data_size_z");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_world_height"), &Terrain2DChunk::get_world_height);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_world_height", "height"), &Terrain2DChunk::set_world_height);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "world_height"), "set_world_height", "get_world_height");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_position"), &Terrain2DChunk::get_position);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_position", "x", "z"), &Terrain2DChunk::set_position);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_world_position"), &Terrain2DChunk::get_world_position);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_world_size"), &Terrain2DChunk::get_world_size);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_world_aabb"), &Terrain2DChunk::get_world_aabb);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_margin_start"), &Terrain2DChunk::get_margin_start);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_margin_start"), &Terrain2DChunk::set_margin_start);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "margin_start"), "set_margin_start", "get_margin_start");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_margin_end"), &Terrain2DChunk::get_margin_end);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_margin_end"), &Terrain2DChunk::set_margin_end);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "margin_end"), "set_margin_end", "get_margin_end");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("material_cache_key_get"), &Terrain2DChunk::material_cache_key_get);
|
|
|
|
ClassDB::bind_method(D_METHOD("material_cache_key_set"), &Terrain2DChunk::material_cache_key_set);
|
2022-02-22 10:33:06 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "material_cache_key", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "material_cache_key_set", "material_cache_key_get");
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("material_cache_key_has"), &Terrain2DChunk::material_cache_key_has);
|
|
|
|
ClassDB::bind_method(D_METHOD("material_cache_key_has_set"), &Terrain2DChunk::material_cache_key_has_set);
|
2022-02-22 10:33:06 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "material_cache_key_has", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "material_cache_key_has_set", "material_cache_key_has");
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("liquid_material_cache_key_get"), &Terrain2DChunk::liquid_material_cache_key_get);
|
|
|
|
ClassDB::bind_method(D_METHOD("liquid_material_cache_key_set"), &Terrain2DChunk::liquid_material_cache_key_set);
|
2022-02-22 10:33:06 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "liquid_material_cache_key", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "liquid_material_cache_key_set", "liquid_material_cache_key_get");
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("liquid_material_cache_key_has"), &Terrain2DChunk::liquid_material_cache_key_has);
|
|
|
|
ClassDB::bind_method(D_METHOD("liquid_material_cache_key_has_set"), &Terrain2DChunk::liquid_material_cache_key_has_set);
|
2022-02-22 10:33:06 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "liquid_material_cache_key_has", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "liquid_material_cache_key_has_set", "liquid_material_cache_key_has");
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("prop_material_cache_key_get"), &Terrain2DChunk::prop_material_cache_key_get);
|
|
|
|
ClassDB::bind_method(D_METHOD("prop_material_cache_key_set"), &Terrain2DChunk::prop_material_cache_key_set);
|
2022-02-22 10:33:06 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "prop_material_cache_key", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "prop_material_cache_key_set", "prop_material_cache_key_get");
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("prop_material_cache_key_has"), &Terrain2DChunk::prop_material_cache_key_has);
|
|
|
|
ClassDB::bind_method(D_METHOD("prop_material_cache_key_has_set"), &Terrain2DChunk::prop_material_cache_key_has_set);
|
2022-02-22 10:33:06 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "prop_material_cache_key_has", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "prop_material_cache_key_has_set", "prop_material_cache_key_has");
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_library"), &Terrain2DChunk::get_library);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_library", "value"), &Terrain2DChunk::set_library);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "Terrain2DLibrary"), "set_library", "get_library");
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_voxel_scale"), &Terrain2DChunk::get_voxel_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_voxel_scale", "value"), &Terrain2DChunk::set_voxel_scale);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "voxel_scale"), "set_voxel_scale", "get_voxel_scale");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("job_get", "index"), &Terrain2DChunk::job_get);
|
|
|
|
ClassDB::bind_method(D_METHOD("job_set", "index", "job"), &Terrain2DChunk::job_set);
|
|
|
|
ClassDB::bind_method(D_METHOD("job_remove", "index"), &Terrain2DChunk::job_remove);
|
|
|
|
ClassDB::bind_method(D_METHOD("job_add", "job"), &Terrain2DChunk::job_add);
|
|
|
|
ClassDB::bind_method(D_METHOD("job_get_count"), &Terrain2DChunk::job_get_count);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("job_get_current_index"), &Terrain2DChunk::job_get_current_index);
|
|
|
|
ClassDB::bind_method(D_METHOD("job_next"), &Terrain2DChunk::job_next);
|
|
|
|
ClassDB::bind_method(D_METHOD("job_get_current"), &Terrain2DChunk::job_get_current);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_voxel_world"), &Terrain2DChunk::get_voxel_world);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_voxel_world", "world"), &Terrain2DChunk::set_voxel_world_bind);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "voxel_world", PROPERTY_HINT_RESOURCE_TYPE, "Terrain2DWorld", 0), "set_voxel_world", "get_voxel_world");
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
//Terra Data
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("channel_setup"), &Terrain2DChunk::channel_setup);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_size", "size_x", "size_z", "margin_start", "margin_end"), &Terrain2DChunk::set_size, DEFVAL(0), DEFVAL(0));
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("validate_data_position", "x", "z"), &Terrain2DChunk::validate_data_position);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_voxel", "x", "z", "index"), &Terrain2DChunk::get_voxel);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_voxel", "value", "x", "z", "index"), &Terrain2DChunk::set_voxel);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("channel_get_count"), &Terrain2DChunk::channel_get_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("channel_set_count", "count"), &Terrain2DChunk::channel_set_count);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "channel_count"), "channel_set_count", "channel_get_count");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("channel_is_allocated", "index"), &Terrain2DChunk::channel_is_allocated);
|
|
|
|
ClassDB::bind_method(D_METHOD("channel_ensure_allocated", "index", "default_value"), &Terrain2DChunk::channel_ensure_allocated);
|
|
|
|
ClassDB::bind_method(D_METHOD("channel_allocate", "index", "default_value"), &Terrain2DChunk::channel_allocate);
|
|
|
|
ClassDB::bind_method(D_METHOD("channel_fill", "value", "index"), &Terrain2DChunk::channel_fill);
|
|
|
|
ClassDB::bind_method(D_METHOD("channel_dealloc", "index"), &Terrain2DChunk::channel_dealloc);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("channel_get_array", "index"), &Terrain2DChunk::channel_get_array);
|
|
|
|
ClassDB::bind_method(D_METHOD("channel_set_array", "index", "array"), &Terrain2DChunk::channel_set_array);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("channel_get_compressed", "index"), &Terrain2DChunk::channel_get_compressed);
|
|
|
|
ClassDB::bind_method(D_METHOD("channel_set_compressed", "index", "array"), &Terrain2DChunk::channel_set_compressed);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_index", "x", "z"), &Terrain2DChunk::get_index);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_data_index", "x", "z"), &Terrain2DChunk::get_data_index);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_data_size"), &Terrain2DChunk::get_data_size);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("voxel_structure_get", "index"), &Terrain2DChunk::voxel_structure_get);
|
|
|
|
ClassDB::bind_method(D_METHOD("voxel_structure_add", "structure"), &Terrain2DChunk::voxel_structure_add);
|
|
|
|
ClassDB::bind_method(D_METHOD("voxel_structure_remove", "structure"), &Terrain2DChunk::voxel_structure_remove);
|
|
|
|
ClassDB::bind_method(D_METHOD("voxel_structure_remove_index", "index"), &Terrain2DChunk::voxel_structure_remove_index);
|
|
|
|
ClassDB::bind_method(D_METHOD("voxel_structure_clear"), &Terrain2DChunk::voxel_structure_clear);
|
|
|
|
ClassDB::bind_method(D_METHOD("voxel_structure_get_count"), &Terrain2DChunk::voxel_structure_get_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("voxel_structure_add_at_position", "structure", "world_position"), &Terrain2DChunk::voxel_structure_add_at_position);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("voxel_structures_get"), &Terrain2DChunk::voxel_structures_get);
|
|
|
|
ClassDB::bind_method(D_METHOD("voxel_structures_set"), &Terrain2DChunk::voxel_structures_set);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "voxel_structures", PROPERTY_HINT_NONE, "17/17:Terrain2DStructure", PROPERTY_USAGE_DEFAULT, "Terrain2DStructure"), "voxel_structures_set", "voxel_structures_get");
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
//Meshes
|
|
|
|
|
|
|
|
#if PROPS_PRESENT
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("prop_add", "prop"), &Terrain2DChunk::prop_add);
|
|
|
|
ClassDB::bind_method(D_METHOD("prop_get", "index"), &Terrain2DChunk::prop_get);
|
|
|
|
ClassDB::bind_method(D_METHOD("prop_get_count"), &Terrain2DChunk::prop_get_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("prop_remove", "index"), &Terrain2DChunk::prop_remove);
|
|
|
|
ClassDB::bind_method(D_METHOD("props_clear"), &Terrain2DChunk::props_clear);
|
2021-11-22 22:00:45 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MESH_DATA_RESOURCE_PRESENT
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("mesh_data_resource_addv", "local_data_pos", "mesh", "texture", "color", "apply_voxel_scale"), &Terrain2DChunk::mesh_data_resource_addv, DEFVAL(Ref<Texture>()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(true));
|
|
|
|
ClassDB::bind_method(D_METHOD("mesh_data_resource_add", "local_transform", "mesh", "texture", "color", "apply_voxel_scale"), &Terrain2DChunk::mesh_data_resource_add, DEFVAL(Ref<Texture>()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(true));
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("mesh_data_resource_get", "index"), &Terrain2DChunk::mesh_data_resource_get);
|
|
|
|
ClassDB::bind_method(D_METHOD("mesh_data_resource_set", "index", "mesh"), &Terrain2DChunk::mesh_data_resource_set);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("mesh_data_resource_get_texture", "index"), &Terrain2DChunk::mesh_data_resource_get_texture);
|
|
|
|
ClassDB::bind_method(D_METHOD("mesh_data_resource_set_texture", "index", "texture"), &Terrain2DChunk::mesh_data_resource_set_texture);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("mesh_data_resource_get_color", "index"), &Terrain2DChunk::mesh_data_resource_get_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("mesh_data_resource_set_color", "index", "color"), &Terrain2DChunk::mesh_data_resource_set_color);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("mesh_data_resource_get_uv_rect", "index"), &Terrain2DChunk::mesh_data_resource_get_uv_rect);
|
|
|
|
ClassDB::bind_method(D_METHOD("mesh_data_resource_set_uv_rect", "index", "uv_rect"), &Terrain2DChunk::mesh_data_resource_set_uv_rect);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("mesh_data_resource_get_transform", "index"), &Terrain2DChunk::mesh_data_resource_get_transform);
|
|
|
|
ClassDB::bind_method(D_METHOD("mesh_data_resource_set_transform", "index", "transform"), &Terrain2DChunk::mesh_data_resource_set_transform);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("mesh_data_resource_get_is_inside", "index"), &Terrain2DChunk::mesh_data_resource_get_is_inside);
|
|
|
|
ClassDB::bind_method(D_METHOD("mesh_data_resource_set_is_inside", "index", "inside"), &Terrain2DChunk::mesh_data_resource_set_is_inside);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("mesh_data_resource_get_count"), &Terrain2DChunk::mesh_data_resource_get_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("mesh_data_resource_remove", "index"), &Terrain2DChunk::mesh_data_resource_remove);
|
|
|
|
ClassDB::bind_method(D_METHOD("mesh_data_resource_clear"), &Terrain2DChunk::mesh_data_resource_clear);
|
2021-11-22 22:00:45 +01:00
|
|
|
#endif
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("collider_add", "local_transform", "shape", "shape_rid", "body"), &Terrain2DChunk::collider_add, DEFVAL(RID()), DEFVAL(RID()));
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("collider_get_transform", "index"), &Terrain2DChunk::collider_get_transform);
|
|
|
|
ClassDB::bind_method(D_METHOD("collider_set_transform", "index", "transform"), &Terrain2DChunk::collider_set_transform);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("collider_get_shape", "index"), &Terrain2DChunk::collider_get_shape);
|
|
|
|
ClassDB::bind_method(D_METHOD("collider_set_shape", "index", "shape"), &Terrain2DChunk::collider_set_shape);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("collider_get_shape_rid", "index"), &Terrain2DChunk::collider_get_shape_rid);
|
|
|
|
ClassDB::bind_method(D_METHOD("collider_set_shape_rid", "index", "rid"), &Terrain2DChunk::collider_set_shape_rid);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("collider_get_body", "index"), &Terrain2DChunk::collider_get_body);
|
|
|
|
ClassDB::bind_method(D_METHOD("collider_set_body", "index", "rid"), &Terrain2DChunk::collider_set_body);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("collider_get_count"), &Terrain2DChunk::collider_get_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("collider_remove", "index"), &Terrain2DChunk::collider_remove);
|
|
|
|
ClassDB::bind_method(D_METHOD("colliders_clear"), &Terrain2DChunk::colliders_clear);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
BIND_VMETHOD(MethodInfo("_build"));
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("build"), &Terrain2DChunk::build);
|
|
|
|
ClassDB::bind_method(D_METHOD("_build"), &Terrain2DChunk::_build);
|
2022-02-22 10:33:06 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_global_transform"), &Terrain2DChunk::get_global_transform);
|
|
|
|
ClassDB::bind_method(D_METHOD("to_local", "global"), &Terrain2DChunk::to_local);
|
|
|
|
ClassDB::bind_method(D_METHOD("to_global", "local"), &Terrain2DChunk::to_global);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("_world_transform_changed"), &Terrain2DChunk::_world_transform_changed);
|
|
|
|
ClassDB::bind_method(D_METHOD("_enter_tree"), &Terrain2DChunk::_enter_tree);
|
|
|
|
ClassDB::bind_method(D_METHOD("_exit_tree"), &Terrain2DChunk::_exit_tree);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("_generation_process"), &Terrain2DChunk::_generation_process);
|
|
|
|
ClassDB::bind_method(D_METHOD("_generation_physics_process"), &Terrain2DChunk::_generation_physics_process);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("is_safe_to_delete"), &Terrain2DChunk::is_safe_to_delete);
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|