54 lines
1.4 KiB
C++
54 lines
1.4 KiB
C++
#include "terrain_modifier.h"
|
|
#include "core/config/engine.h"
|
|
#include "core/variant/variant.h"
|
|
#include "scene/main/node.h"
|
|
#include "terrain/terrain.h"
|
|
|
|
String TerrainModifier::sig_terrain_changed{ "terrain_changed" };
|
|
|
|
void TerrainModifier::_bind_methods() {
|
|
ADD_SIGNAL(MethodInfo(sig_terrain_changed, PropertyInfo(Variant::OBJECT, "terrain", PROPERTY_HINT_NODE_TYPE, "Terrain")));
|
|
}
|
|
|
|
void TerrainModifier::_notification(int what) {
|
|
switch (what) {
|
|
default:
|
|
return;
|
|
case NOTIFICATION_ENTER_TREE:
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
|
set_notify_transform(true);
|
|
}
|
|
this->thread_safe_global_position = get_global_position();
|
|
return;
|
|
case NOTIFICATION_TRANSFORM_CHANGED:
|
|
this->thread_safe_global_position = get_global_position();
|
|
return;
|
|
}
|
|
}
|
|
|
|
void TerrainModifier::push_changed(Rect2 area) {
|
|
if (this->terrain) {
|
|
this->terrain->push_changed(area);
|
|
}
|
|
}
|
|
|
|
float TerrainModifier::evaluate_at(Vector2 world_coordinate, float before) {
|
|
Vector3 const global_position{ get_thread_safe_global_position() };
|
|
return global_position.y;
|
|
}
|
|
|
|
void TerrainModifier::set_bounds(Rect2 bounds) {
|
|
if (this->bounds != bounds) {
|
|
push_changed(bounds);
|
|
push_changed(this->bounds);
|
|
this->bounds = bounds;
|
|
}
|
|
}
|
|
|
|
Rect2 TerrainModifier::get_bounds() const {
|
|
return this->bounds;
|
|
}
|
|
|
|
Vector3 TerrainModifier::get_thread_safe_global_position() const {
|
|
return this->thread_safe_global_position;
|
|
}
|