Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Need to add context for a factories list beyond /dev/defaultFactories…

…, also need to fix GameInterfaces
  • Loading branch information...
commit 155c8eb08c81e2ac4c543c312e19e2ce97b86450 1 parent 61500b6
@deek0146 authored
View
20 AbstractFactory/Compilation.cpp
@@ -0,0 +1,20 @@
+#include <AbstractFactory/Compilation.h>
+
+Compilation::Compilation()
+{
+}
+
+void Compilation::init(PropertyBagInterface* _loader)
+{
+}
+
+GameComponent* Compilation::useFactory(PropertyBagInterface* _parameters)
+{
+ throw -1;
+}
+
+AbstractFactoryBase* Compilation::gameObjectFactory()
+{
+ //static AbstractFactoryBase* factory = dynamic_cast<AbstractFactoryBase*>(DefaultFactories::global()->getNode("GameObject"));
+ //return factory;
+}
View
18 AbstractFactory/Compilation.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include <AbstractFactory/AbstractFactory.h>
+
+class Compilation: public AbstractFactory<Compilation>
+{
+public:
+ Compilation();
+ void init(PropertyBagInterface* _loader);
+ GameComponent* useFactory(PropertyBagInterface* _parameters);
+ static std::string name()
+ {
+ return "Compilation";
+ }
+private:
+ static AbstractFactoryBase* gameObjectFactory();
+ //std::vector<AbstractFactoryBase*> factories;
+};
View
3  AbstractFactory/DefaultFactories.h
@@ -29,5 +29,8 @@ void DefaultFactories::registerSimpleFactory()
template <typename Factory>
void DefaultFactories::registerFactoryType()
{
+ unsigned int count1 = countChildren();
attachChild(new FactoryFactory<Factory>());
+ unsigned int count2 = countChildren();
+ assert(count2 == count1+1);
}
View
15 AbstractFactory/Factories/FactoryFactory.h
@@ -1,14 +1,17 @@
#pragma once
template <typename Factory>
-class FactoryFactory : public TypedGameComponent<FactoryFactory<Factory>>
+class FactoryFactory : public AbstractFactoryBase
{
public:
+ FactoryFactory():AbstractFactoryBase(name()){}
+ void baseInit(const std::string& _name, PropertyBagInterface* _loader){}
+ GameComponent* privateUseFactory(PropertyBagInterface* _params, GameComponent* _parent);
void build(PropertyBagInterface* _parameters);
static void registerActions(GameComponentType* _type);
static std::string name()
{
- return Factory::name() + "Factory";
+ return Factory::name();
}
};
@@ -16,14 +19,16 @@ class FactoryFactory : public TypedGameComponent<FactoryFactory<Factory>>
template <typename Factory>
void FactoryFactory<Factory>::registerActions(GameComponentType* _type)
{
- _type->createActionHandle<FactoryFactory<Factory>, PropertyBagInterface>("build", &FactoryFactory<Factory>::build);
-
+ //_type->createActionHandle<FactoryFactory<Factory>, PropertyBagInterface>("build", &FactoryFactory<Factory>::build);
}
template <typename Factory>
-void FactoryFactory<Factory>::build(PropertyBagInterface* _parameters)
+GameComponent* FactoryFactory<Factory>::privateUseFactory(PropertyBagInterface* _parameters, GameComponent* _parent)
{
+ _parameters->setParent(_parent);
Factory* factory = new Factory;
factory->baseInit(_parameters->getProductName(), _parameters);
_parameters->setProduct(factory);
+ _parent->attachChild(factory);
+ return factory;
}
View
28 AbstractFactory/InstanceParameters.cpp
@@ -4,8 +4,9 @@
#include <AbstractFactory/AbstractFactory.h>
#include <Objects/GameInterfaces/FactoryInterface.h>
-InstanceParameters::InstanceParameters()
- :GameComponent(&componentType, std::string("InstanceParameters")),
+InstanceParameters::InstanceParameters(const std::string& _name)
+ //:TypedGameComponent<InstanceParameters>(std::string("InstanceParameters")),
+ :TypedGameComponent<InstanceParameters>(_name),
table(nullptr, false)
{
}
@@ -16,9 +17,26 @@ InstanceParameters::~InstanceParameters()
GameComponent* InstanceParameters::build(GameComponent* _parent)
{
+ std::cout << _parent->getName() << std::endl;
+ //assert(_parent->getParentNode() != _parent);
+ //assert(_parent->getParentNode() != _parent->getParentNode()->getParentNode());
GameComponentPropertyBagInterface interface(this);
GameComponent* factories = Filesystem::global()->getNode("/dev/defaultFactories");
- GameComponent* factory = factories->getNode(type);
+ /*std::cout << factories->getName() << ":" << std::endl;
+ for (auto child = factories->getChildren(); child; child = child->getNext())
+ std::cout << child->getName() << " " << child << "," << std::endl;
+ std::cout << std::endl;*/
+
+ GameComponent* factory = nullptr;
+ try
+ {
+ factory = factories->getNode(type);
+ }
+ catch (...)
+ {
+ factory = Filesystem::global()->getNode("/dev/game/factories")->getNode(type);
+ //factory = _parent->getParentNode()->getParentNode()->getNode("factories")->getNode(type);
+ }
FactoryInterface* factoryInterface = nullptr;
factoryInterface = factory->getInterface<FactoryInterface>();
//assert(dynamic_cast<AbstractFactoryBase<GameComponent>*>(factory));
@@ -43,4 +61,6 @@ void InstanceParameters::setType(const std::string& _type)
/// FIXME might need to set a variable in GameComponent later on, not been written yet though
}
-GameComponentType InstanceParameters::componentType("InstanceParametersblargh");
+void InstanceParameters::registerActions(GameComponentType* _type)
+{
+}
View
11 AbstractFactory/InstanceParameters.h
@@ -7,10 +7,10 @@
#include <string>
class PropertyBagSerializer;
-class InstanceParameters : public GameComponent
+class InstanceParameters : public TypedGameComponent<InstanceParameters>
{
public:
- InstanceParameters();
+ InstanceParameters(const std::string& _name);
~InstanceParameters();
template <typename Type>
@@ -47,11 +47,16 @@ class InstanceParameters : public GameComponent
GameComponent* build(GameComponent* _parent);
+ static std::string name()
+ {
+ return "InstanceParameters";
+ }
+ static void registerActions(GameComponentType* _type);
+
protected:
private:
//std::unordered_map<std::string, float> _parameters;
TypeTable table;
- static GameComponentType componentType;
std::string type;
};
View
5 Editor/Data/DataManager.cpp
@@ -5,9 +5,8 @@ namespace Editor
{
DataManager::DataManager()
{
- entities = new InstanceParameters;
- entities->setName("game");
- entities->setType("/dev/defaultFactories/Folder");
+ entities = new InstanceParameters("game");
+ entities->setType("Folder");
}
DataManager::~DataManager()
{
View
10 Editor/Editor.cpp
@@ -39,8 +39,12 @@ namespace Editor
{
std::string command("new Folder named entities in .");
executeCommand(&command);
- command = "new GameObject named crate in entities";
+ command = "new Folder named factories in .";
executeCommand(&command);
+ command = "new Compilation named Crate in factories"; // ? What is "Type" and why does it already exist
+ executeCommand(&command);
+ command = "new Crate named crate in entities";
+ //executeCommand(&command);
CEGUI::Window* root = CEGUI::System::getSingleton().getGUISheet();
//EntityListData* entityList = data->getEntityLists()->getObject(0);
//activeMode = new EntityListEditor(this, entityList, root);
@@ -70,7 +74,9 @@ namespace Editor
{
//GameComponent* defaultFactories = Filesystem::global()->getNode("/dev/defaultFactories");
//factories->setBackupFactory(defaultFactories);
-
+ std::cout << "Root is: " << _parameters->getName() << std::endl;
+ assert(_parameters->getName() == "game");
+ assert(_parameters->getType() == "Folder");
GameComponent* dev = Filesystem::global()->getNode("dev");
GameComponent* game = _parameters->build(dev);
/*factories->getType()->getActionHandle("build")->execute<InstanceParameters>(factories, _parameters);
View
3  Editor/Parser/CommandParser.cpp
@@ -176,9 +176,8 @@ namespace Editor
{
/*AbstractFactories* factories = getFactories();
AbstractFactoryBase<GameComponent>* factory = factories->getFactory<GameComponent>(_type);*/
- InstanceParameters* params = new InstanceParameters;
+ InstanceParameters* params = new InstanceParameters(_name);
params->setType(_type);
- params->setName(_name);
std::cout << "Root name: " << data->getRoot()->getName() << std::endl;
if (data->getRoot()->getChildren())
std::cout << "Child: " << data->getRoot()->getChildren()->getName() << std::endl;
View
6 Filesystem/Folder.cpp
@@ -7,6 +7,8 @@ Folder::Folder()
Folder::Folder(const std::string& _name, GameComponent* _parent, bool _orphan)
:TypedGameComponent<Folder>(_name, _parent)
{
+ if (_name == "no name programmed")
+ std::cout << "Derp derp" << std::endl;
//ctor
}
@@ -26,6 +28,8 @@ void Folder::registerActions(GameComponentType* _type)
std::cout << factories->getName() << ":" << std::endl;
for (auto child = factories->getChildren(); child; child = child->getNext())
- std::cout << child->getName() << " " << child << "," << std::endl;
+ {
+ std::cout << child->getName() << " " << child << "," << std::endl;
+ }
std::cout << std::endl;
}
View
19 Types/Tree.h
@@ -15,6 +15,7 @@ class List
void append(Object* _child);
void remove(Object* _child);
Object* front();
+ unsigned int countChildren();
protected:
Object* children;
virtual void childAttached(Object* _child){}
@@ -127,17 +128,24 @@ class TreeNode: public ListNode<Node>, public List<Node>
return children;
}
+template <typename Object>
+unsigned int List<Object>::countChildren()
+{
+ unsigned int count = 0;
+ for (auto child = children; child; child = child->getNext())
+ count++;
+ return count;
+}
template <typename Object>
void List<Object>::append(Object* _object)
{
- _object->next = nullptr;
- _object->prev = children;
+ _object->next = children;
+ _object->prev = nullptr;
if (children != nullptr)
{
- children->next = _object;
+ children->prev = _object;
}
- else
- children = _object;
+ children = _object;
}
template <typename Object>
void List<Object>::remove(Object* _object)
@@ -213,6 +221,7 @@ class TreeNode: public ListNode<Node>, public List<Node>
static_cast<List<Object>*>(this)->append(_child);
static_cast<TreeNode<Object>*>(_child)->parentChanged(oldParent);
+ assert(_child->parent != _child);
}
Please sign in to comment.
Something went wrong with that request. Please try again.