Entity 0 is now a real entity in the world, created by the first entity read while importing. This makes the difference between map files and entity files automatic, since consecutive entity file loads should automatically get the world as parent, as long as the world entity has been created earlier.
This commit is contained in:
@@ -162,7 +162,7 @@ private:
|
|||||||
xercesc::SAX2XMLReader* m_Reader;
|
xercesc::SAX2XMLReader* m_Reader;
|
||||||
//State m_CurrentScope = State::Unknown;
|
//State m_CurrentScope = State::Unknown;
|
||||||
std::stack<State> m_StateStack;
|
std::stack<State> m_StateStack;
|
||||||
unsigned int m_NextEntityID = 1;
|
unsigned int m_NextEntityID = 0;
|
||||||
std::stack<EntityID> m_EntityStack;
|
std::stack<EntityID> m_EntityStack;
|
||||||
std::string m_CurrentComponent;
|
std::string m_CurrentComponent;
|
||||||
std::string m_CurrentField;
|
std::string m_CurrentField;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WriteWorld(World* world);
|
void WriteWorld(World* world);
|
||||||
|
void WriteEntity(World* world, EntityID entity);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::filesystem::path m_FilePath;
|
boost::filesystem::path m_FilePath;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public:
|
|||||||
const std::unordered_multimap<EntityID, EntityID>& GetEntityChildren() const { return m_EntityChildren; }
|
const std::unordered_multimap<EntityID, EntityID>& GetEntityChildren() const { return m_EntityChildren; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EntityID m_CurrentEntityID = 1;
|
EntityID m_CurrentEntityID = 0;
|
||||||
|
|
||||||
std::unordered_map<EntityID, EntityID> m_EntityParents;
|
std::unordered_map<EntityID, EntityID> m_EntityParents;
|
||||||
// TODO: This should be a more effective structure
|
// TODO: This should be a more effective structure
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ void EntityFileParser::onStartEntity(EntityID entity, EntityID parent)
|
|||||||
void EntityFileParser::onStartComponent(EntityID entity, std::string component)
|
void EntityFileParser::onStartComponent(EntityID entity, std::string component)
|
||||||
{
|
{
|
||||||
EntityID realEntity = m_EntityIDMapper.at(entity);
|
EntityID realEntity = m_EntityIDMapper.at(entity);
|
||||||
m_World->AttachComponent(entity, component);
|
m_World->AttachComponent(realEntity, component);
|
||||||
LOG_DEBUG("Attached component of type \"%s\" to entity #%i (%i)", component.c_str(), entity, realEntity);
|
LOG_DEBUG("Attached component of type \"%s\" to entity #%i (%i)", component.c_str(), entity, realEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,11 @@
|
|||||||
#define X(str) XS::ToXMLCh(str)
|
#define X(str) XS::ToXMLCh(str)
|
||||||
|
|
||||||
void EntityFileWriter::WriteWorld(World* world)
|
void EntityFileWriter::WriteWorld(World* world)
|
||||||
|
{
|
||||||
|
WriteEntity(world, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityFileWriter::WriteEntity(World* world, EntityID entity)
|
||||||
{
|
{
|
||||||
using namespace xercesc;
|
using namespace xercesc;
|
||||||
DOMDocument* doc = m_DOMImplementation->createDocument(nullptr, X("Entity"), nullptr);
|
DOMDocument* doc = m_DOMImplementation->createDocument(nullptr, X("Entity"), nullptr);
|
||||||
@@ -13,16 +18,18 @@ void EntityFileWriter::WriteWorld(World* world)
|
|||||||
|
|
||||||
DOMElement* componentsElement = doc->createElement(X("Components"));
|
DOMElement* componentsElement = doc->createElement(X("Components"));
|
||||||
root->appendChild(componentsElement);
|
root->appendChild(componentsElement);
|
||||||
appentEntityComponents(componentsElement, world, 0);
|
appentEntityComponents(componentsElement, world, entity);
|
||||||
|
|
||||||
DOMElement* childrenElement = doc->createElement(X("Children"));
|
DOMElement* childrenElement = doc->createElement(X("Children"));
|
||||||
root->appendChild(childrenElement);
|
root->appendChild(childrenElement);
|
||||||
appendEntityChildren(childrenElement, world, 0);
|
appendEntityChildren(childrenElement, world, entity);
|
||||||
|
|
||||||
XMLFormatTarget* target = new StdOutFormatTarget();
|
XMLFormatTarget* target = new StdOutFormatTarget();
|
||||||
DOMLSOutput* output = static_cast<DOMImplementationLS*>(m_DOMImplementation)->createLSOutput();
|
DOMLSOutput* output = static_cast<DOMImplementationLS*>(m_DOMImplementation)->createLSOutput();
|
||||||
output->setByteStream(target);
|
output->setByteStream(target);
|
||||||
m_DOMLSSerializer->write(doc, output);
|
m_DOMLSSerializer->write(doc, output);
|
||||||
|
|
||||||
|
doc->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityFileWriter::appendEntityChildren(xercesc::DOMElement* parentElement, const World* world, EntityID entity)
|
void EntityFileWriter::appendEntityChildren(xercesc::DOMElement* parentElement, const World* world, EntityID entity)
|
||||||
|
|||||||
@@ -10,12 +10,15 @@ World::~World()
|
|||||||
EntityID World::CreateEntity(EntityID parent /*= 0*/)
|
EntityID World::CreateEntity(EntityID parent /*= 0*/)
|
||||||
{
|
{
|
||||||
EntityID newEntity = generateEntityID();
|
EntityID newEntity = generateEntityID();
|
||||||
m_EntityParents[newEntity] = parent;
|
if (newEntity != parent) {
|
||||||
m_EntityChildren.insert(std::make_pair(parent, newEntity));
|
m_EntityParents[newEntity] = parent;
|
||||||
|
m_EntityChildren.insert(std::make_pair(parent, newEntity));
|
||||||
|
} else {
|
||||||
|
LOG_WARNING("Attempted to create an entity with itself as parent! Entity#%i with parent #%i", newEntity, parent);
|
||||||
|
}
|
||||||
return newEntity;
|
return newEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void World::DeleteEntity(EntityID entity)
|
void World::DeleteEntity(EntityID entity)
|
||||||
{
|
{
|
||||||
// Delete components
|
// Delete components
|
||||||
|
|||||||
Reference in New Issue
Block a user