mirror of
https://github.com/Relintai/terraman.git
synced 2025-04-25 21:45:00 +02:00
Now the world can be deactivated when needed.
This commit is contained in:
parent
ecf09d1245
commit
632586f4b3
@ -62,6 +62,10 @@ void TerraWorldDefault::set_num_lods(const int value) {
|
||||
}
|
||||
|
||||
void TerraWorldDefault::update_lods() {
|
||||
if (!get_active()) {
|
||||
return;
|
||||
}
|
||||
|
||||
call("_update_lods");
|
||||
}
|
||||
|
||||
@ -191,7 +195,7 @@ Ref<TerraChunk> TerraWorldDefault::_create_chunk(int x, int z, Ref<TerraChunk> c
|
||||
s.instance();
|
||||
s->set_job_type(TerraMesherJobStep::TYPE_NORMAL);
|
||||
tj->add_jobs_step(s);
|
||||
|
||||
|
||||
s.instance();
|
||||
s->set_job_type(TerraMesherJobStep::TYPE_NORMAL_LOD);
|
||||
s->set_lod_index(1);
|
||||
@ -261,6 +265,34 @@ TerraWorldDefault::TerraWorldDefault() {
|
||||
TerraWorldDefault ::~TerraWorldDefault() {
|
||||
}
|
||||
|
||||
void TerraWorldDefault::_notification(int p_what) {
|
||||
TerraWorld::_notification(p_what);
|
||||
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ACTIVE_STATE_CHANGED: {
|
||||
if (!is_inside_tree()) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool active = get_active();
|
||||
|
||||
for (int i = 0; i < chunk_get_count(); ++i) {
|
||||
Ref<TerraChunk> chunk = chunk_get_index(i);
|
||||
|
||||
if (chunk.is_valid()) {
|
||||
chunk->set_visible(active);
|
||||
}
|
||||
}
|
||||
|
||||
if (active) {
|
||||
update_lods();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void TerraWorldDefault::_notification(int p_what) {
|
||||
TerraWorld::_notification(p_what);
|
||||
|
@ -52,6 +52,7 @@ public:
|
||||
~TerraWorldDefault();
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
void _update_lods();
|
||||
Ref<TerraChunk> _create_chunk(int x, int z, Ref<TerraChunk> p_chunk);
|
||||
virtual void _chunk_added(Ref<TerraChunk> chunk);
|
||||
|
@ -43,6 +43,15 @@ SOFTWARE.
|
||||
|
||||
const String TerraWorld::BINDING_STRING_CHANNEL_TYPE_INFO = "Type,Isolevel,Liquid,Liquid Level";
|
||||
|
||||
bool TerraWorld::get_active() const {
|
||||
return _active;
|
||||
}
|
||||
void TerraWorld::set_active(const bool value) {
|
||||
_active = value;
|
||||
|
||||
notification(NOTIFICATION_ACTIVE_STATE_CHANGED);
|
||||
}
|
||||
|
||||
bool TerraWorld::get_editable() const {
|
||||
return _editable;
|
||||
}
|
||||
@ -371,6 +380,10 @@ Ref<TerraChunk> TerraWorld::_create_chunk(const int x, const int z, Ref<TerraChu
|
||||
chunk->set_size(_chunk_size_x, _chunk_size_z, _data_margin_start, _data_margin_end);
|
||||
//chunk->set_translation(Vector3(x * _chunk_size_x * _voxel_scale, y * _chunk_size_y * _voxel_scale, z * _chunk_size_z * _voxel_scale));
|
||||
|
||||
if (!get_active()) {
|
||||
chunk->set_visible(false);
|
||||
}
|
||||
|
||||
chunk_add(chunk, x, z);
|
||||
|
||||
return chunk;
|
||||
@ -792,6 +805,7 @@ int TerraWorld::get_channel_index_info(const TerraWorld::ChannelTypeInfo channel
|
||||
}
|
||||
|
||||
TerraWorld::TerraWorld() {
|
||||
_active = true;
|
||||
_editable = false;
|
||||
|
||||
_is_priority_generation = true;
|
||||
@ -871,7 +885,8 @@ void TerraWorld::_notification(int p_what) {
|
||||
chunk->build();
|
||||
}
|
||||
}
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
case NOTIFICATION_INTERNAL_PROCESS: {
|
||||
_num_frame_chunk_build_steps = 0;
|
||||
|
||||
@ -929,7 +944,8 @@ void TerraWorld::_notification(int p_what) {
|
||||
|
||||
chunk_generate(chunk);
|
||||
}
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
|
||||
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
||||
Ref<TerraChunk> chunk = _chunks_vector[i];
|
||||
@ -944,8 +960,8 @@ void TerraWorld::_notification(int p_what) {
|
||||
chunk->generation_physics_process(get_physics_process_delta_time());
|
||||
}
|
||||
}
|
||||
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
||||
Ref<TerraChunk> chunk = _chunks_vector[i];
|
||||
@ -957,8 +973,8 @@ void TerraWorld::_notification(int p_what) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
case NOTIFICATION_TRANSFORM_CHANGED: {
|
||||
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
||||
Ref<TerraChunk> chunk = _chunks_vector[i];
|
||||
@ -967,14 +983,18 @@ void TerraWorld::_notification(int p_what) {
|
||||
chunk->world_transform_changed();
|
||||
}
|
||||
}
|
||||
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TerraWorld::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo("chunk_mesh_generation_finished", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk")));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_active"), &TerraWorld::get_active);
|
||||
ClassDB::bind_method(D_METHOD("set_active", "value"), &TerraWorld::set_active);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "active"), "set_active", "get_active");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_editable"), &TerraWorld::get_editable);
|
||||
ClassDB::bind_method(D_METHOD("set_editable", "value"), &TerraWorld::set_editable);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "get_editable");
|
||||
@ -1131,4 +1151,6 @@ void TerraWorld::_bind_methods() {
|
||||
BIND_ENUM_CONSTANT(CHANNEL_TYPE_INFO_TYPE);
|
||||
BIND_ENUM_CONSTANT(CHANNEL_TYPE_INFO_ISOLEVEL);
|
||||
BIND_ENUM_CONSTANT(CHANNEL_TYPE_INFO_LIQUID_FLOW);
|
||||
|
||||
BIND_CONSTANT(NOTIFICATION_ACTIVE_STATE_CHANGED);
|
||||
}
|
||||
|
@ -26,11 +26,11 @@ SOFTWARE.
|
||||
#include "core/version.h"
|
||||
|
||||
#if VERSION_MAJOR > 3
|
||||
#include "core/templates/hash_map.h"
|
||||
#include "core/config/engine.h"
|
||||
#include "core/templates/hash_map.h"
|
||||
#else
|
||||
#include "core/hash_map.h"
|
||||
#include "core/engine.h"
|
||||
#include "core/hash_map.h"
|
||||
#endif
|
||||
|
||||
#include "../defines.h"
|
||||
@ -61,9 +61,16 @@ public:
|
||||
CHANNEL_TYPE_INFO_LIQUID_FLOW,
|
||||
};
|
||||
|
||||
enum {
|
||||
NOTIFICATION_ACTIVE_STATE_CHANGED = 9000,
|
||||
};
|
||||
|
||||
static const String BINDING_STRING_CHANNEL_TYPE_INFO;
|
||||
|
||||
public:
|
||||
bool get_active() const;
|
||||
void set_active(const bool value);
|
||||
|
||||
bool get_editable() const;
|
||||
void set_editable(const bool value);
|
||||
|
||||
@ -228,6 +235,7 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
bool _active;
|
||||
bool _editable;
|
||||
|
||||
bool _is_priority_generation;
|
||||
@ -245,22 +253,22 @@ private:
|
||||
int _chunk_spawn_range;
|
||||
|
||||
HashMap<IntPos, Ref<TerraChunk>, IntPosHasher> _chunks;
|
||||
Vector<Ref<TerraChunk> > _chunks_vector;
|
||||
Vector<Ref<TerraChunk>> _chunks_vector;
|
||||
|
||||
Vector<Ref<TerraWorldArea> > _world_areas;
|
||||
Vector<Ref<TerraWorldArea>> _world_areas;
|
||||
|
||||
Vector<Ref<TerraStructure> > _voxel_structures;
|
||||
Vector<Ref<TerraStructure>> _voxel_structures;
|
||||
|
||||
NodePath _player_path;
|
||||
Spatial *_player;
|
||||
|
||||
int _max_concurrent_generations;
|
||||
Vector<Ref<TerraChunk> > _generation_queue;
|
||||
Vector<Ref<TerraChunk> > _generating;
|
||||
Vector<Ref<TerraChunk>> _generation_queue;
|
||||
Vector<Ref<TerraChunk>> _generating;
|
||||
int _max_frame_chunk_build_steps;
|
||||
int _num_frame_chunk_build_steps;
|
||||
|
||||
Vector<Ref<TerraLight> > _lights;
|
||||
Vector<Ref<TerraLight>> _lights;
|
||||
};
|
||||
|
||||
_FORCE_INLINE_ bool operator==(const TerraWorld::IntPos &a, const TerraWorld::IntPos &b) {
|
||||
|
Loading…
Reference in New Issue
Block a user