chore: modifiers are aware of parent terrain
This commit is contained in:
parent
80eb6ef4c0
commit
953e4abe5b
3 changed files with 18 additions and 6 deletions
|
|
@ -9,16 +9,27 @@ void Terrain::_bind_methods() {
|
|||
BIND_PROPERTY(Variant::INT, thread_count);
|
||||
}
|
||||
|
||||
void Terrain::ready() {
|
||||
construct_chunk_grid();
|
||||
void Terrain::child_order_changed() {
|
||||
this->modifiers.clear();
|
||||
for (Variant var : get_children()) {
|
||||
if (TerrainModifier * mod{ cast_to<TerrainModifier>(var) }) {
|
||||
mod->set_terrain(this);
|
||||
this->modifiers.push_back(mod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Terrain::_notification(int what) {
|
||||
switch (what) {
|
||||
default:
|
||||
return;
|
||||
case NOTIFICATION_ENTER_TREE:
|
||||
if (!is_ready()) {
|
||||
connect("child_order_changed", callable_mp(this, &self_type::child_order_changed));
|
||||
}
|
||||
return;
|
||||
case NOTIFICATION_READY:
|
||||
ready();
|
||||
construct_chunk_grid();
|
||||
return;
|
||||
case NOTIFICATION_EXIT_TREE:
|
||||
this->workload_lock.lock();
|
||||
|
|
|
|||
|
|
@ -3,16 +3,14 @@
|
|||
#include "core/os/mutex.h"
|
||||
#include "core/os/thread.h"
|
||||
#include "core/templates/vector.h"
|
||||
#include "macros.h"
|
||||
#include "scene/main/node.h"
|
||||
#include "scene/main/timer.h"
|
||||
class TerrainChunkMesh;
|
||||
class TerrainModifier;
|
||||
|
||||
class Terrain : public Node {
|
||||
GDCLASS(Terrain, Node);
|
||||
static void _bind_methods();
|
||||
void ready();
|
||||
void child_order_changed();
|
||||
|
||||
protected:
|
||||
void _notification(int what);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "macros.h"
|
||||
#include "scene/3d/marker_3d.h"
|
||||
#include "scene/resources/curve.h"
|
||||
class Terrain;
|
||||
|
||||
class TerrainModifier : public Marker3D {
|
||||
GDCLASS(TerrainModifier, Marker3D);
|
||||
|
|
@ -27,6 +28,7 @@ private:
|
|||
BlendMode blend_mode{ Add };
|
||||
Vector3 thread_safe_global_position{};
|
||||
bool dirty{ false };
|
||||
Terrain *terrain{ nullptr };
|
||||
|
||||
public:
|
||||
Vector3 get_thread_safe_global_position() const;
|
||||
|
|
@ -35,6 +37,7 @@ public:
|
|||
void set_blend_mode(BlendMode mode);
|
||||
BlendMode get_blend_mode() const;
|
||||
GET_SET_FNS(bool, dirty);
|
||||
GET_SET_FNS(Terrain *, terrain);
|
||||
|
||||
static String const sig_changed;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue