From 26398f05866099d1ba972d21c4e21ec7c20d4759 Mon Sep 17 00:00:00 2001 From: Vulpovile Date: Fri, 3 Nov 2023 23:56:59 -0700 Subject: [PATCH] Fixed template --- Blocks3D.vcproj | 44 ++++++ src/include/DataModelV3/Instance.h | 49 +++++++ src/include/Reflection/ReflectionDataTable.h | 9 +- src/include/Reflection/ReflectionProperty.h | 9 +- .../ReflectionProperty_imp.h} | 11 +- src/source/DataModelV3/Instance.cpp | 135 ++++++++++++++++++ src/source/Reflection/ReflectionDataTable.cpp | 4 +- 7 files changed, 245 insertions(+), 16 deletions(-) create mode 100644 src/include/DataModelV3/Instance.h rename src/{source/Reflection/ReflectionProperty.cpp => include/ReflectionProperty_imp.h} (60%) create mode 100644 src/source/DataModelV3/Instance.cpp diff --git a/Blocks3D.vcproj b/Blocks3D.vcproj index 63a1146..3e734e7 100644 --- a/Blocks3D.vcproj +++ b/Blocks3D.vcproj @@ -683,6 +683,22 @@ > + + + + + + + + + + + + + + + + + + + + + + + +namespace B3D +{ + class Instance + { + public: + //Constructors + Instance(void); + Instance(const Instance&); + virtual ~Instance(void); + + //Virtual Functions + virtual void render(RenderDevice*); + virtual void renderName(RenderDevice*); + virtual void update(); + virtual void setParent(Instance*); + virtual Instance* clone() const { return new Instance(*this); } + + //Functions + std::vector children; // All children. + std::string getClassName(); + Instance* findFirstChild(std::string); + std::vector getChildren(); + std::vector getAllChildren(); + void setName(std::string newName); + void addChild(Instance*); + void removeChild(Instance*); + void clearChildren(); + Instance* getParent(); + + //Variables + Reflection::ReflectionProperty name; + protected: + //Constructor + //Used specifically to identify an instance class by an instance class, + //NOT for use outside of Instance and decendants! + Instance(std::string className); + + //Variables + Reflection::ReflectionDataTable * dataTable; + Instance * parent; + }; +} diff --git a/src/include/Reflection/ReflectionDataTable.h b/src/include/Reflection/ReflectionDataTable.h index 5403892..511ca23 100644 --- a/src/include/Reflection/ReflectionDataTable.h +++ b/src/include/Reflection/ReflectionDataTable.h @@ -4,14 +4,13 @@ #include #include "ReflectionProperty.h" namespace B3D{ - namespace Instance{ - class Instance; - } + class Instance; + namespace Reflection{ class ReflectionDataTable { public: - ReflectionDataTable(Instance::Instance * parentInstance, std::string className); + ReflectionDataTable(Instance * parentInstance, std::string className); ReflectionDataTable::ReflectionDataTable(void); ~ReflectionDataTable(void); @@ -20,7 +19,7 @@ namespace B3D{ //Perhaps not stored here? std::string className; std::map*> propertyTable; - Instance::Instance * parentInstance; + Instance * parentInstance; }; } } diff --git a/src/include/Reflection/ReflectionProperty.h b/src/include/Reflection/ReflectionProperty.h index d98819e..c2ef4ac 100644 --- a/src/include/Reflection/ReflectionProperty.h +++ b/src/include/Reflection/ReflectionProperty.h @@ -8,13 +8,13 @@ namespace B3D{ namespace Reflection{ class ReflectionDataTable; - template + template class ReflectionProperty { public: T * value; ReflectionType type; - ReflectionProperty(T * value, ReflectionType type, ReflectionDataTable * containerTable, bool archivable = true, bool locked = false, bool propertyHidden = false); + ReflectionProperty(T * value, ReflectionType type, ReflectionDataTable * containerTable); ReflectionProperty(void); ~ReflectionProperty(void); private: @@ -25,4 +25,7 @@ namespace B3D{ ReflectionDataTable * containerTable; }; } -} \ No newline at end of file +} + +//***really*** wanted to avoid implementing this inside of the header +#include "ReflectionProperty_imp.h" \ No newline at end of file diff --git a/src/source/Reflection/ReflectionProperty.cpp b/src/include/ReflectionProperty_imp.h similarity index 60% rename from src/source/Reflection/ReflectionProperty.cpp rename to src/include/ReflectionProperty_imp.h index d2b3f5f..80d1bbd 100644 --- a/src/source/Reflection/ReflectionProperty.cpp +++ b/src/include/ReflectionProperty_imp.h @@ -1,8 +1,7 @@ -#include "Reflection\ReflectionProperty.h" using namespace B3D::Reflection; -template -ReflectionProperty::ReflectionProperty(T * value, ReflectionType type, ReflectionDataTable * containerTable, bool archivable = true, bool locked = false, bool propertyHidden = false) +template +ReflectionProperty::ReflectionProperty(T * value, ReflectionType type, ReflectionDataTable * containerTable) { this->value = value; this->type = type; @@ -12,12 +11,12 @@ ReflectionProperty::ReflectionProperty(T * value, ReflectionType type, Reflec this->propertyHidden = propertyHidden; } -template +template ReflectionProperty::ReflectionProperty(void) { } -template +template ReflectionProperty::~ReflectionProperty(void) { -} +} \ No newline at end of file diff --git a/src/source/DataModelV3/Instance.cpp b/src/source/DataModelV3/Instance.cpp new file mode 100644 index 0000000..bf7d444 --- /dev/null +++ b/src/source/DataModelV3/Instance.cpp @@ -0,0 +1,135 @@ +#include "DataModelV3/Instance.h" + +using namespace B3D; + +Instance::Instance(std::string className) +{ + this->parent = NULL; + this->dataTable = new Reflection::ReflectionDataTable(this, className); + this->name = Reflection::ReflectionProperty(new std::string("Default Game Instance"), Reflection::TYPE_STRING, dataTable); +} + +Instance::Instance(void) +{ + Instance::Instance("BaseInstance"); +} + +Instance::~Instance(void) +{ + for(size_t i = 0; i < children.size(); i++) + { + delete children.at(i); + } + delete dataTable; +} + +Instance::Instance(const Instance &oinst) +{ + //CLONE WITH REFLECTION!!! +} + +//Perhaps should be separated +void Instance::render(RenderDevice* rd) +{ + for(size_t i = 0; i < children.size(); i++) + { + children[i]->render(rd); + } +} + +void Instance::renderName(RenderDevice* rd) +{ + for(size_t i = 0; i < children.size(); i++) + { + children[i]->renderName(rd); + } +} + +void Instance::update() +{ +} + +void Instance::setName(std::string newName) +{ + *name.value = newName; +} + +std::string Instance::getClassName() +{ + return dataTable->getClassName(); +} + +std::vector Instance::getChildren() +{ + return children; +} + +std::vector Instance::getAllChildren() +{ + if(!children.empty()) + { + std::vector totalchildren = children; + for(size_t i = 0; i < children.size(); i++) + { + std::vector subchildren = children.at(i)->getAllChildren(); + if(!subchildren.empty()) + totalchildren.insert(totalchildren.end(), subchildren.begin(), subchildren.end()); + } + return totalchildren; + } + return children; +} + +void Instance::setParent(Instance* newParent) +{ + if(parent != NULL) + { + parent->removeChild(this); + } + parent = newParent; + if(newParent != NULL) + { + newParent->addChild(this); + } +} + +Instance* Instance::getParent() +{ + return parent; +} + +void Instance::addChild(Instance* newChild) +{ + children.push_back(newChild); +} + +void Instance::clearChildren() +{ + for (size_t i = 0; i < children.size(); i++) + { + delete children.at(i); + } + children.clear(); +} +void Instance::removeChild(Instance* oldChild) +{ + for(size_t i = 0; i < children.size(); i++) + { + if(children.at(i) == oldChild) + { + children.erase(children.begin() + i); + } + } +} + +Instance* Instance::findFirstChild(std::string searchName) +{ + for(size_t i = 0; i < children.size(); i++) + { + if(children.at(i)->name.value->compare(searchName) == 0) + { + return children.at(i); + } + } + return NULL; +} \ No newline at end of file diff --git a/src/source/Reflection/ReflectionDataTable.cpp b/src/source/Reflection/ReflectionDataTable.cpp index 530b63e..7268c03 100644 --- a/src/source/Reflection/ReflectionDataTable.cpp +++ b/src/source/Reflection/ReflectionDataTable.cpp @@ -1,8 +1,8 @@ -#include "Reflection\ReflectionDataTable.h" +#include "Reflection/ReflectionDataTable.h" using namespace B3D::Reflection; -ReflectionDataTable::ReflectionDataTable(B3D::Instance::Instance * parentInstance, std::string className) +ReflectionDataTable::ReflectionDataTable(B3D::Instance * parentInstance, std::string className) { this->parentInstance = parentInstance; this->className = className;