Skip to content

Commit

Permalink
Fix GDCLASS public override
Browse files Browse the repository at this point in the history
  • Loading branch information
TokisanGames committed Nov 16, 2023
1 parent a747f40 commit a3d32cf
Show file tree
Hide file tree
Showing 17 changed files with 141 additions and 118 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ Braces:

Private & Public:
* Private variables/functions prefaced with `_`
* Private/public/protected explicit and grouped together in that order, in header and cpp files
* One initial public section for constants
* Private/public/protected for members and functions in that order, in header and cpp files
* Functions in h and cpp files in same order

Other formatting:
Expand Down
2 changes: 1 addition & 1 deletion src/generated_tex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

void GeneratedTex::create(const TypedArray<Image> &p_layers) {
if (!p_layers.is_empty()) {
if (Terrain3D::_debug_level >= DEBUG) {
if (Terrain3D::debug_level >= DEBUG) {
LOG(DEBUG, "RenderingServer creating Texture2DArray, layers size: ", p_layers.size());
for (int i = 0; i < p_layers.size(); i++) {
Ref<Image> img = p_layers[i];
Expand Down
5 changes: 4 additions & 1 deletion src/generated_tex.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
using namespace godot;

class GeneratedTex {
private:
public:
// Constants
static inline const char *__class__ = "Terrain3DGeneratedTex";

private:
RID _rid = RID();
Ref<Image> _image;
bool _dirty = false;
Expand Down
4 changes: 3 additions & 1 deletion src/geoclipmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
using namespace godot;

class GeoClipMap {
private:
public:
// Constants
static inline const char *__class__ = "Terrain3DGeoClipMap";

private:
static inline int _patch_2d(int x, int y, int res);
static RID _create_mesh(PackedVector3Array p_vertices, PackedInt32Array p_indices, AABB p_aabb);

Expand Down
2 changes: 1 addition & 1 deletion src/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
UtilityFunctions::push_error(__class__, "::", __func__, ": ", __VA_ARGS__); \
else if (level == WARN) \
UtilityFunctions::push_warning(__class__, "::", __func__, ": ", __VA_ARGS__); \
else if (Terrain3D::_debug_level >= level) \
else if (Terrain3D::debug_level >= level) \
UtilityFunctions::print(__class__, "::", __func__, ": ", __VA_ARGS__);

#endif // LOGGER_CLASS_H
8 changes: 4 additions & 4 deletions src/terrain_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
///////////////////////////

// Initialize static member variable
int Terrain3D::_debug_level{ ERROR };
int Terrain3D::debug_level{ ERROR };

void Terrain3D::_initialize() {
LOG(INFO, "Checking material, storage, texture_list, signal, and mesh initialization");
Expand Down Expand Up @@ -67,8 +67,8 @@ void Terrain3D::_initialize() {
// Initialize the system
if (!_initialized && _is_inside_world && is_inside_tree()) {
_material->initialize(_storage->get_region_size());
_storage->_update_regions(true); // generate map arrays
_texture_list->_update_list(); // generate texture arrays
_storage->update_regions(true); // generate map arrays
_texture_list->update_list(); // generate texture arrays
_build(_clipmap_levels, _clipmap_size);
_build_collision();
_initialized = true;
Expand Down Expand Up @@ -480,7 +480,7 @@ Terrain3D::~Terrain3D() {

void Terrain3D::set_debug_level(int p_level) {
LOG(INFO, "Setting debug level: ", p_level);
_debug_level = CLAMP(p_level, 0, DEBUG_MAX);
debug_level = CLAMP(p_level, 0, DEBUG_MAX);
}

void Terrain3D::set_clipmap_levels(int p_count) {
Expand Down
10 changes: 7 additions & 3 deletions src/terrain_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@
using namespace godot;

class Terrain3D : public Node3D {
private:
GDCLASS(Terrain3D, Node3D);

public:
// Constants
static inline const char *__class__ = "Terrain3D";

private:
// Terrain state
String _version = "0.8.4-dev";
bool _is_inside_world = false;
bool _initialized = false;

// Terrain settings
static int _debug_level;
int _clipmap_size = 48;
int _clipmap_levels = 7;

Expand Down Expand Up @@ -86,13 +88,15 @@ class Terrain3D : public Node3D {
void _update_instances();

public:
static int debug_level;

Terrain3D();
~Terrain3D();

// Terrain settings
String get_version() const { return _version; }
void set_debug_level(int p_level);
int get_debug_level() const { return _debug_level; }
int get_debug_level() const { return debug_level; }
void set_clipmap_levels(int p_count);
int get_clipmap_levels() const { return _clipmap_levels; }
void set_clipmap_size(int p_size);
Expand Down
10 changes: 4 additions & 6 deletions src/terrain_3d_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
using namespace godot;

class Terrain3DEditor : public Object {
private:
GDCLASS(Terrain3DEditor, Object);
static inline const char *__class__ = "Terrain3DEditor";

// Constants & Definitions
public:
// Constants
static inline const char *__class__ = "Terrain3DEditor";

enum Operation {
ADD,
Expand Down Expand Up @@ -94,12 +94,11 @@ class Terrain3DEditor : public Object {
real_t get_jitter() const { return _jitter; }
};

private:
// Object references

Terrain3D *_terrain = nullptr;

// Painter settings & variables

Tool _tool = REGION;
Operation _operation = ADD;
Brush _brush;
Expand All @@ -109,7 +108,6 @@ class Terrain3DEditor : public Object {
bool _modified = false;
Array _undo_set; // 0-2: map 0,1,2, 3: Region offsets, 4: height range

private:
void _operate_region(Vector3 p_global_position);
void _operate_map(Vector3 p_global_position, real_t p_camera_direction);
bool _is_in_bounds(Vector2i p_position, Vector2i p_max_position);
Expand Down
4 changes: 2 additions & 2 deletions src/terrain_3d_material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void Terrain3DMaterial::_preload_shaders() {
#include "shaders/main.glsl"
);

if (Terrain3D::_debug_level >= DEBUG) {
if (Terrain3D::debug_level >= DEBUG) {
Array keys = _shader_code.keys();
for (int i = 0; i < keys.size(); i++) {
LOG(DEBUG, "Loaded shader insert: ", keys[i]);
Expand Down Expand Up @@ -186,7 +186,7 @@ void Terrain3DMaterial::_update_regions(const Array &p_args) {
RS->material_set_param(_material, "_region_map", _region_map);
RS->material_set_param(_material, "_region_map_size", Terrain3DStorage::REGION_MAP_SIZE);
RS->material_set_param(_material, "_region_uv_limit", Terrain3DStorage::REGION_MAP_SIZE / 2);
if (Terrain3D::_debug_level >= DEBUG) {
if (Terrain3D::debug_level >= DEBUG) {
LOG(DEBUG, "Region map");
for (int i = 0; i < _region_map.size(); i++) {
if (_region_map[i]) {
Expand Down
5 changes: 4 additions & 1 deletion src/terrain_3d_material.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
using namespace godot;

class Terrain3DMaterial : public Resource {
private:
GDCLASS(Terrain3DMaterial, Resource);

public:
// Constants
static inline const char *__class__ = "Terrain3DMaterial";

private:
bool _initialized = false;
RID _material;
RID _shader;
Expand Down
116 changes: 58 additions & 58 deletions src/terrain_3d_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,58 +22,6 @@ void Terrain3DStorage::_clear() {
_generated_color_maps.clear();
}

void Terrain3DStorage::_update_regions(bool force_emit) {
if (_generated_height_maps.is_dirty()) {
LOG(DEBUG_CONT, "Regenerating height layered texture from ", _height_maps.size(), " maps");
_generated_height_maps.create(_height_maps);
force_emit = true;
_modified = true;
emit_signal("height_maps_changed");
}

if (_generated_control_maps.is_dirty()) {
LOG(DEBUG_CONT, "Regenerating control layered texture from ", _control_maps.size(), " maps");
_generated_control_maps.create(_control_maps);
force_emit = true;
_modified = true;
}

if (_generated_color_maps.is_dirty()) {
LOG(DEBUG_CONT, "Regenerating color layered texture from ", _color_maps.size(), " maps");
_generated_color_maps.create(_color_maps);
force_emit = true;
_modified = true;
}

if (_region_map_dirty) {
LOG(DEBUG_CONT, "Regenerating ", REGION_MAP_VSIZE, " region map array");
_region_map.clear();
_region_map.resize(REGION_MAP_SIZE * REGION_MAP_SIZE);
_region_map_dirty = false;
for (int i = 0; i < _region_offsets.size(); i++) {
Vector2i ofs = _region_offsets[i];
Vector2i pos = Vector2i(ofs + (REGION_MAP_VSIZE / 2));
if (pos.x >= REGION_MAP_SIZE || pos.y >= REGION_MAP_SIZE || pos.x < 0 || pos.y < 0) {
continue;
}
_region_map[pos.y * REGION_MAP_SIZE + pos.x] = i + 1; // 0 = no region
}
force_emit = true;
_modified = true;
}

// Don't emit if no changes and not requested
if (force_emit) {
Array region_signal_args;
region_signal_args.push_back(_generated_height_maps.get_rid());
region_signal_args.push_back(_generated_control_maps.get_rid());
region_signal_args.push_back(_generated_color_maps.get_rid());
region_signal_args.push_back(_region_map);
region_signal_args.push_back(_region_offsets);
emit_signal("regions_changed", region_signal_args);
}
}

///////////////////////////
// Public Functions
///////////////////////////
Expand Down Expand Up @@ -155,7 +103,7 @@ void Terrain3DStorage::set_region_offsets(const TypedArray<Vector2i> &p_offsets)
LOG(INFO, "Setting region offsets with array sized: ", p_offsets.size());
_region_offsets = p_offsets;
_region_map_dirty = true;
_update_regions();
update_regions();
}

/** Returns a region offset given a location */
Expand Down Expand Up @@ -231,11 +179,11 @@ Error Terrain3DStorage::add_region(Vector3 p_global_position, const TypedArray<I
_generated_height_maps.clear();
_generated_control_maps.clear();
_generated_color_maps.clear();
_update_regions();
update_regions();
notify_property_list_changed();
emit_changed();
} else {
_update_regions();
update_regions();
}
return OK;
}
Expand Down Expand Up @@ -266,11 +214,63 @@ void Terrain3DStorage::remove_region(Vector3 p_global_position, bool p_update) {
_generated_height_maps.clear();
_generated_control_maps.clear();
_generated_color_maps.clear();
_update_regions();
update_regions();
notify_property_list_changed();
emit_changed();
} else {
_update_regions();
update_regions();
}
}

void Terrain3DStorage::update_regions(bool force_emit) {
if (_generated_height_maps.is_dirty()) {
LOG(DEBUG_CONT, "Regenerating height layered texture from ", _height_maps.size(), " maps");
_generated_height_maps.create(_height_maps);
force_emit = true;
_modified = true;
emit_signal("height_maps_changed");
}

if (_generated_control_maps.is_dirty()) {
LOG(DEBUG_CONT, "Regenerating control layered texture from ", _control_maps.size(), " maps");
_generated_control_maps.create(_control_maps);
force_emit = true;
_modified = true;
}

if (_generated_color_maps.is_dirty()) {
LOG(DEBUG_CONT, "Regenerating color layered texture from ", _color_maps.size(), " maps");
_generated_color_maps.create(_color_maps);
force_emit = true;
_modified = true;
}

if (_region_map_dirty) {
LOG(DEBUG_CONT, "Regenerating ", REGION_MAP_VSIZE, " region map array");
_region_map.clear();
_region_map.resize(REGION_MAP_SIZE * REGION_MAP_SIZE);
_region_map_dirty = false;
for (int i = 0; i < _region_offsets.size(); i++) {
Vector2i ofs = _region_offsets[i];
Vector2i pos = Vector2i(ofs + (REGION_MAP_VSIZE / 2));
if (pos.x >= REGION_MAP_SIZE || pos.y >= REGION_MAP_SIZE || pos.x < 0 || pos.y < 0) {
continue;
}
_region_map[pos.y * REGION_MAP_SIZE + pos.x] = i + 1; // 0 = no region
}
force_emit = true;
_modified = true;
}

// Don't emit if no changes and not requested
if (force_emit) {
Array region_signal_args;
region_signal_args.push_back(_generated_height_maps.get_rid());
region_signal_args.push_back(_generated_control_maps.get_rid());
region_signal_args.push_back(_generated_color_maps.get_rid());
region_signal_args.push_back(_region_map);
region_signal_args.push_back(_region_offsets);
emit_signal("regions_changed", region_signal_args);
}
}

Expand Down Expand Up @@ -615,7 +615,7 @@ void Terrain3DStorage::force_update_maps(MapType p_map_type) {
_generated_color_maps.clear();
break;
}
_update_regions();
update_regions();
}

void Terrain3DStorage::save() {
Expand Down
11 changes: 5 additions & 6 deletions src/terrain_3d_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
using namespace godot;

class Terrain3DStorage : public Resource {
private:
GDCLASS(Terrain3DStorage, Resource);
static inline const char *__class__ = "Terrain3DStorage";

// Constants & Definitions
public:
// Constants
static inline const char *__class__ = "Terrain3DStorage";

static inline const real_t CURRENT_VERSION = 0.842;
static inline const int REGION_MAP_SIZE = 16;
Expand Down Expand Up @@ -66,16 +66,15 @@ class Terrain3DStorage : public Resource {
HEIGHT_FILTER_MINIMUM
};

private:
// Storage Settings & flags

real_t _version = 0.8; // Set to ensure Godot always saves this
bool _modified = false;
bool _save_16_bit = false;
RegionSize _region_size = SIZE_1024;
Vector2i _region_sizev = Vector2i(_region_size, _region_size);

// Stored Data

Vector2 _height_range = Vector2(0, 0);

/**
Expand All @@ -99,7 +98,6 @@ class Terrain3DStorage : public Resource {

// Functions
void _clear();
void _update_regions(bool force_emit = false);

// DEPRECATED 0.8.3, remove 0.9
Ref<Terrain3DTextureList> _texture_list;
Expand Down Expand Up @@ -133,6 +131,7 @@ class Terrain3DStorage : public Resource {
bool has_region(Vector3 p_global_position) { return get_region_index(p_global_position) != -1; }
Error add_region(Vector3 p_global_position, const TypedArray<Image> &p_images = TypedArray<Image>(), bool p_update = true);
void remove_region(Vector3 p_global_position, bool p_update = true);
void update_regions(bool force_emit = false);

// Maps
void set_map_region(MapType p_map_type, int p_region_index, const Ref<Image> p_image);
Expand Down
Loading

0 comments on commit a3d32cf

Please sign in to comment.