Skip to content

Commit

Permalink
Merged recent changes from main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
FishOfTheNorthStar committed May 10, 2024
1 parent 998ffd9 commit 593bb22
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 193 deletions.
41 changes: 38 additions & 3 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

using namespace godot;

//////////////////////////////////////
// Macro Constants & Syntactic Sugar
//////////////////////////////////////
// Constants

#define RS RenderingServer::get_singleton()

Expand All @@ -19,19 +17,56 @@ using namespace godot;
#define COLOR_NORMAL Color(0.5f, 0.5f, 1.0f, 1.0f)
#define COLOR_CONTROL Color(as_float(enc_auto(true)), 0.f, 0.f, 1.0f)

// For consistency between msvc, gcc, clang

#ifndef __FLT_MAX__
#define __FLT_MAX__ FLT_MAX
#endif

// Double precision builds

#ifdef REAL_T_IS_DOUBLE
typedef PackedFloat64Array PackedRealArray;
#else
typedef PackedFloat32Array PackedRealArray;
#endif

// Set class name for logger.h

#define CLASS_NAME() const String __class__ = get_class_static() + \
String("#") + String::num_uint64(get_instance_id()).right(4);

#define CLASS_NAME_STATIC(p_name) static inline const char *__class__ = p_name;
// Validation macros

#define NOP // a return value for void, to avoid warnings

#define IS_INIT(ret) \
if (_terrain == nullptr) { \
return ret; \
}

#define IS_INIT_MESG(mesg, ret) \
if (_terrain == nullptr) { \
LOG(ERROR, mesg); \
return ret; \
}

#define IS_INIT_COND(cond, ret) \
if (_terrain == nullptr || cond) { \
return ret; \
}

#define IS_STORAGE_INIT(ret) \
if (_terrain == nullptr || _terrain->get_storage().is_null()) { \
return ret; \
}

#define IS_STORAGE_INIT_MESG(mesg, ret) \
if (_terrain == nullptr || _terrain->get_storage().is_null()) { \
LOG(ERROR, mesg); \
return ret; \
}


#endif // CONSTANTS_CLASS_H
15 changes: 6 additions & 9 deletions src/terrain_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ void Terrain3D::_initialize() {
LOG(DEBUG, "Connecting texture_list.textures_changed to _material->_update_texture_arrays()");
_texture_list->connect("textures_changed", callable_mp(_material.ptr(), &Terrain3DMaterial::_update_texture_arrays));
}
if (!_storage->is_connected("region_size_changed", callable_mp(_material.ptr(), &Terrain3DMaterial::_set_region_size))) {
LOG(DEBUG, "Connecting region_size_changed signal to _material->_set_region_size()");
_storage->connect("region_size_changed", callable_mp(_material.ptr(), &Terrain3DMaterial::_set_region_size));
if (!_storage->is_connected("region_size_changed", callable_mp(_material.ptr(), &Terrain3DMaterial::_update_regions))) {
LOG(DEBUG, "Connecting region_size_changed signal to _material->_update_regions()");
_storage->connect("region_size_changed", callable_mp(_material.ptr(), &Terrain3DMaterial::_update_regions));
}
if (!_storage->is_connected("regions_changed", callable_mp(_material.ptr(), &Terrain3DMaterial::_update_regions))) {
LOG(DEBUG, "Connecting regions_changed signal to _material->_update_regions()");
Expand All @@ -66,9 +66,9 @@ void Terrain3D::_initialize() {

// Initialize the system
if (!_initialized && _is_inside_world && is_inside_tree()) {
_material->initialize(_storage->get_region_size());
_material->set_mesh_vertex_spacing(_mesh_vertex_spacing);
_storage->update_regions(true); // generate map arrays
_storage->initialize(this);
_material->initialize(this);
_material->_update_regions();
_texture_list->update_list(); // generate texture arrays
_setup_mouse_picking();
_build(_mesh_lods, _mesh_size);
Expand Down Expand Up @@ -656,9 +656,6 @@ void Terrain3D::set_mesh_vertex_spacing(real_t p_spacing) {
if (_mesh_vertex_spacing != p_spacing) {
LOG(INFO, "Setting mesh vertex spacing: ", p_spacing);
_mesh_vertex_spacing = p_spacing;
if (_storage != nullptr) {
_storage->_mesh_vertex_spacing = p_spacing;
}
_clear();
_initialize();
}
Expand Down
18 changes: 3 additions & 15 deletions src/terrain_3d_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,6 @@ void Terrain3DEditor::_apply_undo(const Array &p_set) {
// Public Functions
///////////////////////////

Terrain3DEditor::Terrain3DEditor() {
}

Terrain3DEditor::~Terrain3DEditor() {
}

void Terrain3DEditor::set_brush_data(Dictionary p_data) {
if (p_data.is_empty()) {
return;
Expand All @@ -530,10 +524,7 @@ void Terrain3DEditor::set_tool(Tool p_tool) {

// Called on mouse click
void Terrain3DEditor::start_operation(Vector3 p_global_position) {
if (!_terrain) {
LOG(ERROR, "_terrain not set");
return;
}
IS_STORAGE_INIT_MESG("Terrain isn't initialized", NOP);
_setup_undo();
_pending_undo = true;
_modified = false;
Expand All @@ -547,10 +538,10 @@ void Terrain3DEditor::start_operation(Vector3 p_global_position) {

// Called on mouse movement with left mouse button down
void Terrain3DEditor::operate(Vector3 p_global_position, real_t p_camera_direction) {
IS_STORAGE_INIT_MESG("Terrain isn't initialized", NOP);
if (!_pending_undo) {
return;
}

_operation_movement = p_global_position - _operation_position;
_operation_position = p_global_position;

Expand All @@ -563,10 +554,7 @@ void Terrain3DEditor::operate(Vector3 p_global_position, real_t p_camera_directi

// Called on left mouse button released
void Terrain3DEditor::stop_operation() {
if (!_terrain) {
LOG(ERROR, "_terrain not set");
return;
}
IS_STORAGE_INIT_MESG("Terrain isn't initialized", NOP);
if (_pending_undo && _modified) {
_store_undo();
_pending_undo = false;
Expand Down
5 changes: 2 additions & 3 deletions src/terrain_3d_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class Terrain3DEditor : public Object {
};

private:
// Object references
Terrain3D *_terrain = nullptr;

// Painter settings & variables
Expand All @@ -132,8 +131,8 @@ class Terrain3DEditor : public Object {
void _apply_undo(const Array &p_set);

public:
Terrain3DEditor();
~Terrain3DEditor();
Terrain3DEditor() {}
~Terrain3DEditor() {}

void set_terrain(Terrain3D *p_terrain) { _terrain = p_terrain; }
Terrain3D *get_terrain() const { return _terrain; }
Expand Down
Loading

0 comments on commit 593bb22

Please sign in to comment.