Created EntityFile which loads an EntityXMLFile into a temporary world to be merged with another world when you want to create a copy of the entity loaded from disk. This allows us to free EntityXMLFile once it's loaded into an EntityFile.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
#ifndef EntityFile_h__
|
||||
#define EntityFile_h__
|
||||
|
||||
#include "World.h"
|
||||
#include "EntityXMLFile.h"
|
||||
#include "EntityXMLFilePreprocessor.h"
|
||||
#include "EntityXMLFileParser.h"
|
||||
#include "EntityWrapper.h"
|
||||
|
||||
class EntityFile : private World, public Resource
|
||||
{
|
||||
public:
|
||||
EntityFile(std::string path);
|
||||
|
||||
EntityWrapper MergeInto(World* other);
|
||||
|
||||
private:
|
||||
EntityID m_RootEntity = EntityID_Invalid;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "Core/EntityFile.h"
|
||||
|
||||
EntityFile::EntityFile(std::string path)
|
||||
{
|
||||
EntityXMLFile* xml = ResourceManager::Load<EntityXMLFile>(path);
|
||||
|
||||
EntityXMLFilePreprocessor preprocessor(xml);
|
||||
preprocessor.RegisterComponents(this);
|
||||
|
||||
EntityXMLFileParser parser(xml);
|
||||
m_RootEntity = parser.MergeEntities(this);
|
||||
|
||||
if (m_RootEntity == EntityID_Invalid) {
|
||||
throw Resource::FailedLoadingException("Failed to merge entities; root entity is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
EntityWrapper EntityFile::MergeInto(World* other)
|
||||
{
|
||||
auto mapping = other->Merge(this);
|
||||
return EntityWrapper(other, mapping.at(m_RootEntity));
|
||||
}
|
||||
+3
-1
@@ -11,6 +11,7 @@
|
||||
#include "Systems/PlayerSpawnSystem.h"
|
||||
#include "Systems/PlayerDeathSystem.h"
|
||||
#include "Systems/FloatingEffectSystem.h"
|
||||
#include "Core/EntityFile.h"
|
||||
#include "Core/EntityXMLFileWriter.h"
|
||||
#include "Game/Systems/CapturePointSystem.h"
|
||||
#include "Game/Systems/CapturePointHUDSystem.h"
|
||||
@@ -44,7 +45,8 @@ Game::Game(int argc, char* argv[])
|
||||
ResourceManager::RegisterType<Texture>("Texture");
|
||||
ResourceManager::RegisterType<PNG>("Png");
|
||||
ResourceManager::RegisterType<ShaderProgram>("ShaderProgram");
|
||||
ResourceManager::RegisterType<EntityXMLFile>("EntityFile");
|
||||
ResourceManager::RegisterType<EntityFile>("EntityFile");
|
||||
ResourceManager::RegisterType<EntityXMLFile>("EntityXMLFile");
|
||||
ResourceManager::RegisterType<Font>("FontFile");
|
||||
|
||||
m_Config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
|
||||
Reference in New Issue
Block a user