From 916676cfab21c92c40fa0a802608d8785a7b4d14 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 21 Sep 2019 00:02:10 +0200 Subject: [PATCH] Renamed VoxelPropData, and cleaned up VoxelProp bit. --- SCsub | 2 +- props/voxelman_prop.cpp | 59 +++++++------- props/voxelman_prop.h | 19 +++-- ..._prop_data.cpp => voxelman_prop_entry.cpp} | 80 +++++++++---------- ...lman_prop_data.h => voxelman_prop_entry.h} | 8 +- register_types.cpp | 4 +- world/voxel_chunk.cpp | 4 +- world/voxel_chunk.h | 2 +- 8 files changed, 90 insertions(+), 88 deletions(-) rename props/{voxelman_prop_data.cpp => voxelman_prop_entry.cpp} (50%) rename props/{voxelman_prop_data.h => voxelman_prop_entry.h} (90%) diff --git a/SCsub b/SCsub index 3721d04..2a4f86f 100644 --- a/SCsub +++ b/SCsub @@ -23,7 +23,7 @@ env.add_source_files(env.modules_sources,"world/voxel_chunk.cpp") env.add_source_files(env.modules_sources,"meshers/cubic_mesher/voxel_mesher_cubic.cpp") env.add_source_files(env.modules_sources,"meshers/cubic_mesher/voxel_cube_points.cpp") -env.add_source_files(env.modules_sources,"props/voxelman_prop_data.cpp") +env.add_source_files(env.modules_sources,"props/voxelman_prop_entry.cpp") env.add_source_files(env.modules_sources,"props/voxelman_prop.cpp") env.add_source_files(env.modules_sources,"level_generator/voxelman_level_generator.cpp") diff --git a/props/voxelman_prop.cpp b/props/voxelman_prop.cpp index 5bc9e89..a290282 100644 --- a/props/voxelman_prop.cpp +++ b/props/voxelman_prop.cpp @@ -1,26 +1,42 @@ #include "voxelman_prop.h" -Ref VoxelmanProp::get_prop(const int index) const { - ERR_FAIL_INDEX_V(index, _props.size(), Ref()); +Ref VoxelmanProp::get_prop(const int index) const { + ERR_FAIL_INDEX_V(index, _props.size(), Ref()); return _props.get(index); } -void VoxelmanProp::set_prop(const int index, const Ref prop) { +void VoxelmanProp::set_prop(const int index, const Ref prop) { ERR_FAIL_INDEX(index, _props.size()); _props.set(index, prop); } +void VoxelmanProp::add_prop(const Ref prop) { + _props.push_back(prop); +} +void VoxelmanProp::remove_prop(const int index) { + ERR_FAIL_INDEX(index, _props.size()); + + _props.remove(index); +} int VoxelmanProp::get_prop_count() const { return _props.size(); } -void VoxelmanProp::set_prop_count(const int size) { - if (size > MAX_PROPS) { - _props.resize(MAX_PROPS); - return; - } - _props.resize(size); +Vector VoxelmanProp::get_props() { + Vector r; + for (int i = 0; i < _props.size(); i++) { + r.push_back(_props[i].get_ref_ptr()); + } + return r; +} +void VoxelmanProp::set_props(const Vector &props) { + _props.clear(); + for (int i = 0; i < props.size(); i++) { + Ref prop = Ref(props[i]); + + _props.push_back(prop); + } } VoxelmanProp::VoxelmanProp() { @@ -29,28 +45,15 @@ VoxelmanProp::~VoxelmanProp() { _props.clear(); } -void VoxelmanProp::_validate_property(PropertyInfo &property) const { - - String prop = property.name; - if (prop.begins_with("Prop_")) { - int num = prop.get_slicec('/', 0).get_slicec('_', 1).to_int(); - if (num >= _props.size()) { - property.usage = 0; - } - } -} - void VoxelmanProp::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_prop_count"), &VoxelmanProp::get_prop_count); - ClassDB::bind_method(D_METHOD("set_prop_count", "value"), &VoxelmanProp::set_prop_count); - ADD_PROPERTY(PropertyInfo(Variant::INT, "prop_count", PROPERTY_HINT_RANGE, "0," + itos(MAX_PROPS), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_prop_count", "get_prop_count"); - ClassDB::bind_method(D_METHOD("get_prop", "index"), &VoxelmanProp::get_prop); ClassDB::bind_method(D_METHOD("set_prop", "index", "spell"), &VoxelmanProp::set_prop); + ClassDB::bind_method(D_METHOD("add_prop", "prop"), &VoxelmanProp::add_prop); + ClassDB::bind_method(D_METHOD("remove_prop", "index"), &VoxelmanProp::remove_prop); - for (int i = 0; i < MAX_PROPS; ++i) { - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "Prop_" + itos(i), PROPERTY_HINT_RESOURCE_TYPE, "VoxelmanPropData", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_prop", "get_prop", i); - } + ClassDB::bind_method(D_METHOD("get_prop_count"), &VoxelmanProp::get_prop_count); - BIND_CONSTANT(MAX_PROPS); + ClassDB::bind_method(D_METHOD("get_props"), &VoxelmanProp::get_props); + ClassDB::bind_method(D_METHOD("set_props", "props"), &VoxelmanProp::set_props); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "props", PROPERTY_HINT_NONE, "17/17:VoxelmanPropEntry", PROPERTY_USAGE_DEFAULT, "VoxelmanPropEntry"), "set_props", "get_props"); } diff --git a/props/voxelman_prop.h b/props/voxelman_prop.h index 668d36e..8c11b94 100644 --- a/props/voxelman_prop.h +++ b/props/voxelman_prop.h @@ -4,31 +4,30 @@ #include "core/reference.h" #include "core/vector.h" -#include "voxelman_prop_data.h" +#include "voxelman_prop_entry.h" class VoxelmanProp : public Resource { GDCLASS(VoxelmanProp, Resource); public: - Ref get_prop(const int index) const; - void set_prop(const int index, const Ref prop); + Ref get_prop(const int index) const; + void set_prop(const int index, const Ref prop); + void add_prop(const Ref prop); + void remove_prop(const int index); int get_prop_count() const; - void set_prop_count(const int size); + + Vector get_props(); + void set_props(const Vector &props); VoxelmanProp(); ~VoxelmanProp(); - enum { - MAX_PROPS = 36 - }; - protected: static void _bind_methods(); - void _validate_property(PropertyInfo &property) const; private: - Vector > _props; + Vector > _props; }; #endif diff --git a/props/voxelman_prop_data.cpp b/props/voxelman_prop_entry.cpp similarity index 50% rename from props/voxelman_prop_data.cpp rename to props/voxelman_prop_entry.cpp index f8fc9ea..70e1add 100644 --- a/props/voxelman_prop_data.cpp +++ b/props/voxelman_prop_entry.cpp @@ -1,77 +1,77 @@ -#include "voxelman_prop_data.h" +#include "voxelman_prop_entry.h" #include "voxelman_prop.h" -Ref VoxelmanPropData::get_mesh() const { +Ref VoxelmanPropEntry::get_mesh() const { return _mesh; } -void VoxelmanPropData::set_mesh(const Ref mesh) { +void VoxelmanPropEntry::set_mesh(const Ref mesh) { _mesh = mesh; } -int VoxelmanPropData::get_has_light() const { +int VoxelmanPropEntry::get_has_light() const { return _has_light; } -void VoxelmanPropData::set_has_light(const int value){ +void VoxelmanPropEntry::set_has_light(const int value){ _has_light = value; } -Color VoxelmanPropData::get_light_color() const { +Color VoxelmanPropEntry::get_light_color() const { return _light_color; } -void VoxelmanPropData::set_light_color(const Color value) { +void VoxelmanPropEntry::set_light_color(const Color value) { _light_color = value; } -int VoxelmanPropData::get_light_size() const { +int VoxelmanPropEntry::get_light_size() const { return _light_size; } -void VoxelmanPropData::set_light_size(const int value) { +void VoxelmanPropEntry::set_light_size(const int value) { _has_light = value; } -Ref VoxelmanPropData::get_scene() const { +Ref VoxelmanPropEntry::get_scene() const { return _scene; } -void VoxelmanPropData::set_scene(const Ref value) { +void VoxelmanPropEntry::set_scene(const Ref value) { _scene = value; } -Vector3 VoxelmanPropData::get_position() const { +Vector3 VoxelmanPropEntry::get_position() const { return _position; } -void VoxelmanPropData::set_position(const Vector3 value) { +void VoxelmanPropEntry::set_position(const Vector3 value) { _position = value; } -Vector3 VoxelmanPropData::get_rotation() const { +Vector3 VoxelmanPropEntry::get_rotation() const { return _rotation; } -void VoxelmanPropData::set_rotation(const Vector3 value) { +void VoxelmanPropEntry::set_rotation(const Vector3 value) { _rotation = value; } -Vector3 VoxelmanPropData::get_scale() const { +Vector3 VoxelmanPropEntry::get_scale() const { return _scale; } -void VoxelmanPropData::set_scale(const Vector3 value) { +void VoxelmanPropEntry::set_scale(const Vector3 value) { _scale = value; } -Ref VoxelmanPropData::get_prop() const { +Ref VoxelmanPropEntry::get_prop() const { return _prop; } -void VoxelmanPropData::set_prop(const Ref prop) { +void VoxelmanPropEntry::set_prop(const Ref prop) { _prop = prop; } -VoxelmanPropData::VoxelmanPropData() { +VoxelmanPropEntry::VoxelmanPropEntry() { _has_light = false; _light_size = 5; _scale = Vector3(1.0, 1.0, 1.0); } -VoxelmanPropData::~VoxelmanPropData() { +VoxelmanPropEntry::~VoxelmanPropEntry() { if (_mesh.is_valid()) _mesh.unref(); @@ -79,40 +79,40 @@ VoxelmanPropData::~VoxelmanPropData() { _scene.unref(); } -void VoxelmanPropData::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_mesh"), &VoxelmanPropData::get_mesh); - ClassDB::bind_method(D_METHOD("set_mesh", "value"), &VoxelmanPropData::set_mesh); +void VoxelmanPropEntry::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_mesh"), &VoxelmanPropEntry::get_mesh); + ClassDB::bind_method(D_METHOD("set_mesh", "value"), &VoxelmanPropEntry::set_mesh); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "MeshDataResource"), "set_mesh", "get_mesh"); - ClassDB::bind_method(D_METHOD("get_has_light"), &VoxelmanPropData::get_has_light); - ClassDB::bind_method(D_METHOD("set_has_light", "value"), &VoxelmanPropData::set_has_light); + ClassDB::bind_method(D_METHOD("get_has_light"), &VoxelmanPropEntry::get_has_light); + ClassDB::bind_method(D_METHOD("set_has_light", "value"), &VoxelmanPropEntry::set_has_light); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "has_light"), "set_has_light", "get_has_light"); - ClassDB::bind_method(D_METHOD("get_light_color"), &VoxelmanPropData::get_light_color); - ClassDB::bind_method(D_METHOD("set_light_color", "value"), &VoxelmanPropData::set_light_color); + ClassDB::bind_method(D_METHOD("get_light_color"), &VoxelmanPropEntry::get_light_color); + ClassDB::bind_method(D_METHOD("set_light_color", "value"), &VoxelmanPropEntry::set_light_color); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "light_color"), "set_light_color", "get_light_color"); - ClassDB::bind_method(D_METHOD("get_light_size"), &VoxelmanPropData::get_light_size); - ClassDB::bind_method(D_METHOD("set_light_size", "value"), &VoxelmanPropData::set_light_size); + ClassDB::bind_method(D_METHOD("get_light_size"), &VoxelmanPropEntry::get_light_size); + ClassDB::bind_method(D_METHOD("set_light_size", "value"), &VoxelmanPropEntry::set_light_size); ADD_PROPERTY(PropertyInfo(Variant::INT, "light_size"), "set_light_size", "get_light_size"); - ClassDB::bind_method(D_METHOD("get_scene"), &VoxelmanPropData::get_scene); - ClassDB::bind_method(D_METHOD("set_scene", "value"), &VoxelmanPropData::set_scene); + ClassDB::bind_method(D_METHOD("get_scene"), &VoxelmanPropEntry::get_scene); + ClassDB::bind_method(D_METHOD("set_scene", "value"), &VoxelmanPropEntry::set_scene); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "scene", PROPERTY_HINT_RESOURCE_TYPE, "PackedScene"), "set_scene", "get_scene"); - ClassDB::bind_method(D_METHOD("get_prop"), &VoxelmanPropData::get_prop); - ClassDB::bind_method(D_METHOD("set_prop", "value"), &VoxelmanPropData::set_prop); + ClassDB::bind_method(D_METHOD("get_prop"), &VoxelmanPropEntry::get_prop); + ClassDB::bind_method(D_METHOD("set_prop", "value"), &VoxelmanPropEntry::set_prop); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "prop", PROPERTY_HINT_RESOURCE_TYPE, "VoxelmanProp"), "set_prop", "get_prop"); - ClassDB::bind_method(D_METHOD("get_position"), &VoxelmanPropData::get_position); - ClassDB::bind_method(D_METHOD("set_position", "value"), &VoxelmanPropData::set_position); + ClassDB::bind_method(D_METHOD("get_position"), &VoxelmanPropEntry::get_position); + ClassDB::bind_method(D_METHOD("set_position", "value"), &VoxelmanPropEntry::set_position); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "position"), "set_position", "get_position"); - ClassDB::bind_method(D_METHOD("get_rotation"), &VoxelmanPropData::get_rotation); - ClassDB::bind_method(D_METHOD("set_rotation", "value"), &VoxelmanPropData::set_rotation); + ClassDB::bind_method(D_METHOD("get_rotation"), &VoxelmanPropEntry::get_rotation); + ClassDB::bind_method(D_METHOD("set_rotation", "value"), &VoxelmanPropEntry::set_rotation); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation"), "set_rotation", "get_rotation"); - ClassDB::bind_method(D_METHOD("get_scale"), &VoxelmanPropData::get_scale); - ClassDB::bind_method(D_METHOD("set_scale", "value"), &VoxelmanPropData::set_scale); + ClassDB::bind_method(D_METHOD("get_scale"), &VoxelmanPropEntry::get_scale); + ClassDB::bind_method(D_METHOD("set_scale", "value"), &VoxelmanPropEntry::set_scale); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "scale"), "set_scale", "get_scale"); } diff --git a/props/voxelman_prop_data.h b/props/voxelman_prop_entry.h similarity index 90% rename from props/voxelman_prop_data.h rename to props/voxelman_prop_entry.h index b464886..e8bbbfb 100644 --- a/props/voxelman_prop_data.h +++ b/props/voxelman_prop_entry.h @@ -10,8 +10,8 @@ class VoxelmanProp; -class VoxelmanPropData : public Resource { - GDCLASS(VoxelmanPropData, Resource); +class VoxelmanPropEntry : public Resource { + GDCLASS(VoxelmanPropEntry, Resource); public: Ref get_mesh() const; @@ -41,8 +41,8 @@ public: Ref get_prop() const; void set_prop(const Ref prop); - VoxelmanPropData(); - ~VoxelmanPropData(); + VoxelmanPropEntry(); + ~VoxelmanPropEntry(); protected: static void _bind_methods(); diff --git a/register_types.cpp b/register_types.cpp index 2285dc4..64a388c 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -16,7 +16,7 @@ #include "meshers/cubic_mesher/voxel_mesher_cubic.h" #include "meshers/cubic_mesher/voxel_cube_points.h" -#include "props/voxelman_prop_data.h" +#include "props/voxelman_prop_entry.h" #include "props/voxelman_prop.h" #include "level_generator/voxelman_level_generator.h" @@ -39,7 +39,7 @@ void register_voxelman_types() { ClassDB::register_class(); ClassDB::register_class(); - ClassDB::register_class(); + ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); diff --git a/world/voxel_chunk.cpp b/world/voxel_chunk.cpp index 5a43f56..485924e 100644 --- a/world/voxel_chunk.cpp +++ b/world/voxel_chunk.cpp @@ -437,7 +437,7 @@ void VoxelChunk::process_prop_light(Ref prop, const Transform tran ERR_FAIL_COND(!prop.is_valid()); for (int i = 0; i < prop->get_prop_count(); ++i) { - Ref data = prop->get_prop(i); + Ref data = prop->get_prop(i); if (!data.is_valid()) continue; @@ -462,7 +462,7 @@ void VoxelChunk::process_prop(Ref prop, const Transform transform) ERR_FAIL_COND(!prop.is_valid()); for (int i = 0; i < prop->get_prop_count(); ++i) { - Ref data = prop->get_prop(i); + Ref data = prop->get_prop(i); if (!data.is_valid()) continue; diff --git a/world/voxel_chunk.h b/world/voxel_chunk.h index 2f89e5a..737e321 100644 --- a/world/voxel_chunk.h +++ b/world/voxel_chunk.h @@ -27,7 +27,7 @@ #include "../../entity_spell_system/meshes/mesh_data_resource.h" #include "../props/voxelman_prop.h" -#include "../props/voxelman_prop_data.h" +#include "../props/voxelman_prop_entry.h" class VoxelWorld;