Skip to content

Commit

Permalink
Traktor: Using IEntityFactory::initialize path in editor as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed May 15, 2024
1 parent 2c83bd4 commit a824c7b
Show file tree
Hide file tree
Showing 45 changed files with 131 additions and 155 deletions.
6 changes: 3 additions & 3 deletions code/Ai/Editor/AiEditorProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ void AiEditorProfile::createResourceFactories(

void AiEditorProfile::createEntityFactories(
scene::SceneEditorContext* context,
RefArray< const world::IEntityFactory >& outEntityFactories
RefArray< world::IEntityFactory >& outEntityFactories
) const
{
bool build = context->getEditor()->getSettings()->getProperty< bool >(L"NavMeshPipeline.Build", true);
outEntityFactories.push_back(new NavMeshEntityFactory(context->getResourceManager(), !build));
const bool build = context->getEditor()->getSettings()->getProperty< bool >(L"NavMeshPipeline.Build", true);
outEntityFactories.push_back(new NavMeshEntityFactory(!build));
}

void AiEditorProfile::createEntityRenderers(
Expand Down
2 changes: 1 addition & 1 deletion code/Ai/Editor/AiEditorProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class T_DLLCLASS AiEditorProfile : public scene::ISceneEditorProfile

virtual void createEntityFactories(
scene::SceneEditorContext* context,
RefArray< const world::IEntityFactory >& outEntityFactories
RefArray< world::IEntityFactory >& outEntityFactories
) const override final;

virtual void createEntityRenderers(
Expand Down
5 changes: 2 additions & 3 deletions code/Ai/NavMeshEntityFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ namespace traktor::ai

T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.ai.NavMeshEntityFactory", 0, NavMeshEntityFactory, world::AbstractEntityFactory)

NavMeshEntityFactory::NavMeshEntityFactory(resource::IResourceManager* resourceManager, bool suppress)
: m_resourceManager(resourceManager)
, m_suppress(suppress)
NavMeshEntityFactory::NavMeshEntityFactory(bool suppress)
: m_suppress(suppress)
{
}

Expand Down
2 changes: 1 addition & 1 deletion code/Ai/NavMeshEntityFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class T_DLLCLASS NavMeshEntityFactory : public world::AbstractEntityFactory
public:
NavMeshEntityFactory() = default;

explicit NavMeshEntityFactory(resource::IResourceManager* resourceManager, bool suppress);
explicit NavMeshEntityFactory(bool suppress);

virtual bool initialize(const ObjectStore& objectStore) override final;

Expand Down
7 changes: 0 additions & 7 deletions code/Animation/AnimationEntityFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ namespace traktor::animation

T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.animation.AnimationEntityFactory", 0, AnimationEntityFactory, world::AbstractEntityFactory)

AnimationEntityFactory::AnimationEntityFactory(resource::IResourceManager* resourceManager, render::IRenderSystem* renderSystem, physics::PhysicsManager* physicsManager)
: m_resourceManager(resourceManager)
, m_renderSystem(renderSystem)
, m_physicsManager(physicsManager)
{
}

bool AnimationEntityFactory::initialize(const ObjectStore& objectStore)
{
m_resourceManager = objectStore.get< resource::IResourceManager >();
Expand Down
4 changes: 0 additions & 4 deletions code/Animation/AnimationEntityFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ class T_DLLCLASS AnimationEntityFactory : public world::AbstractEntityFactory
T_RTTI_CLASS;

public:
AnimationEntityFactory() = default;

explicit AnimationEntityFactory(resource::IResourceManager* resourceManager, render::IRenderSystem* renderSystem, physics::PhysicsManager* physicsManager);

virtual bool initialize(const ObjectStore& objectStore) override final;

virtual const TypeInfoSet getEntityComponentTypes() const override final;
Expand Down
4 changes: 2 additions & 2 deletions code/Animation/Editor/AnimationEditorProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ void AnimationEditorProfile::createResourceFactories(

void AnimationEditorProfile::createEntityFactories(
scene::SceneEditorContext* context,
RefArray< const world::IEntityFactory >& outEntityFactories
RefArray< world::IEntityFactory >& outEntityFactories
) const
{
outEntityFactories.push_back(new AnimationEntityFactory(context->getResourceManager(), context->getRenderSystem(), context->getPhysicsManager()));
outEntityFactories.push_back(new AnimationEntityFactory());
}

void AnimationEditorProfile::createEntityRenderers(
Expand Down
2 changes: 1 addition & 1 deletion code/Animation/Editor/AnimationEditorProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class T_DLLCLASS AnimationEditorProfile : public scene::ISceneEditorProfile

virtual void createEntityFactories(
scene::SceneEditorContext* context,
RefArray< const world::IEntityFactory >& outEntityFactories
RefArray< world::IEntityFactory >& outEntityFactories
) const override final;

virtual void createEntityRenderers(
Expand Down
16 changes: 13 additions & 3 deletions code/Animation/Editor/AnimationPreviewControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ const float c_deltaMoveScale = 0.025f;
const float c_deltaScaleHead = 0.015f;
const float c_deltaScalePitch = 0.005f;

world::IEntityFactory* initializeFactory(world::IEntityFactory* entityFactory, const ObjectStore& objectStore)
{
return entityFactory->initialize(objectStore) ? entityFactory : nullptr;
}

}

T_IMPLEMENT_RTTI_CLASS(L"traktor.animation.AnimationPreviewControl", AnimationPreviewControl, ui::Widget)
Expand Down Expand Up @@ -91,10 +96,15 @@ bool AnimationPreviewControl::create(ui::Widget* parent)

m_resourceManager = new resource::ResourceManager(resourceDatabase, m_editor->getSettings()->getProperty< bool >(L"Resource.Verbose", false));

// Setup object store with relevant systems.
ObjectStore objectStore;
objectStore.set(m_resourceManager);
objectStore.set(m_renderSystem);

Ref< world::EntityFactory > entityFactory = new world::EntityFactory();
entityFactory->addFactory(new world::WorldEntityFactory(m_resourceManager, m_renderSystem, true));
entityFactory->addFactory(new weather::WeatherFactory(m_resourceManager, m_renderSystem));
entityFactory->addFactory(new mesh::MeshEntityFactory(m_resourceManager, m_renderSystem));
entityFactory->addFactory(initializeFactory(new world::WorldEntityFactory(true), objectStore));
entityFactory->addFactory(initializeFactory(new weather::WeatherFactory(), objectStore));
entityFactory->addFactory(initializeFactory(new mesh::MeshEntityFactory(), objectStore));

m_resourceManager->addFactory(new AnimationResourceFactory());
m_resourceManager->addFactory(new mesh::MeshResourceFactory(m_renderSystem));
Expand Down
2 changes: 1 addition & 1 deletion code/Heightfield/Editor/HeightfieldEditorProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void HeightfieldEditorProfile::createResourceFactories(

void HeightfieldEditorProfile::createEntityFactories(
scene::SceneEditorContext* context,
RefArray< const world::IEntityFactory >& outEntityFactories
RefArray< world::IEntityFactory >& outEntityFactories
) const
{
}
Expand Down
2 changes: 1 addition & 1 deletion code/Heightfield/Editor/HeightfieldEditorProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class T_DLLCLASS HeightfieldEditorProfile : public scene::ISceneEditorProfile

virtual void createEntityFactories(
scene::SceneEditorContext* context,
RefArray< const world::IEntityFactory >& outEntityFactories
RefArray< world::IEntityFactory >& outEntityFactories
) const override final;

virtual void createEntityRenderers(
Expand Down
4 changes: 2 additions & 2 deletions code/Mesh/Editor/MeshEditorProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ void MeshEditorProfile::createResourceFactories(

void MeshEditorProfile::createEntityFactories(
scene::SceneEditorContext* context,
RefArray< const world::IEntityFactory >& outEntityFactories
RefArray< world::IEntityFactory >& outEntityFactories
) const
{
outEntityFactories.push_back(new mesh::MeshEntityFactory(context->getResourceManager(), context->getRenderSystem()));
outEntityFactories.push_back(new mesh::MeshEntityFactory());
}

void MeshEditorProfile::createEntityRenderers(
Expand Down
2 changes: 1 addition & 1 deletion code/Mesh/Editor/MeshEditorProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class T_DLLCLASS MeshEditorProfile : public scene::ISceneEditorProfile

virtual void createEntityFactories(
scene::SceneEditorContext* context,
RefArray< const world::IEntityFactory >& outEntityFactories
RefArray< world::IEntityFactory >& outEntityFactories
) const override final;

virtual void createEntityRenderers(
Expand Down
6 changes: 0 additions & 6 deletions code/Mesh/MeshEntityFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ namespace traktor::mesh

T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.mesh.MeshEntityFactory", 0, MeshEntityFactory, world::AbstractEntityFactory)

MeshEntityFactory::MeshEntityFactory(resource::IResourceManager* resourceManager, render::IRenderSystem* renderSystem)
: m_resourceManager(resourceManager)
, m_renderSystem(renderSystem)
{
}

bool MeshEntityFactory::initialize(const ObjectStore& objectStore)
{
m_resourceManager = objectStore.get< resource::IResourceManager >();
Expand Down
4 changes: 0 additions & 4 deletions code/Mesh/MeshEntityFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ class T_DLLCLASS MeshEntityFactory : public world::AbstractEntityFactory
T_RTTI_CLASS;

public:
MeshEntityFactory() = default;

explicit MeshEntityFactory(resource::IResourceManager* resourceManager, render::IRenderSystem* renderSystem);

virtual bool initialize(const ObjectStore& objectStore) override final;

virtual const TypeInfoSet getEntityComponentTypes() const override final;
Expand Down
4 changes: 2 additions & 2 deletions code/Physics/Editor/PhysicsEditorProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ void PhysicsEditorProfile::createResourceFactories(

void PhysicsEditorProfile::createEntityFactories(
scene::SceneEditorContext* context,
RefArray< const world::IEntityFactory >& outEntityFactories
RefArray< world::IEntityFactory >& outEntityFactories
) const
{
outEntityFactories.push_back(new EntityFactory(context->getResourceManager(), context->getPhysicsManager()));
outEntityFactories.push_back(new EntityFactory());
}

void PhysicsEditorProfile::createEntityRenderers(
Expand Down
2 changes: 1 addition & 1 deletion code/Physics/Editor/PhysicsEditorProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class T_DLLCLASS PhysicsEditorProfile : public scene::ISceneEditorProfile

virtual void createEntityFactories(
scene::SceneEditorContext* context,
RefArray< const world::IEntityFactory >& outEntityFactories
RefArray< world::IEntityFactory >& outEntityFactories
) const override final;

virtual void createEntityRenderers(
Expand Down
9 changes: 0 additions & 9 deletions code/Physics/World/EntityFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ namespace traktor::physics

T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.physics.EntityFactory", 0, EntityFactory, world::AbstractEntityFactory)

EntityFactory::EntityFactory(
resource::IResourceManager* resourceManager,
PhysicsManager* physicsManager
)
: m_resourceManager(resourceManager)
, m_physicsManager(physicsManager)
{
}

bool EntityFactory::initialize(const ObjectStore& objectStore)
{
m_resourceManager = objectStore.get< resource::IResourceManager >();
Expand Down
7 changes: 0 additions & 7 deletions code/Physics/World/EntityFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ class T_DLLCLASS EntityFactory : public world::AbstractEntityFactory
T_RTTI_CLASS;

public:
EntityFactory() = default;

explicit EntityFactory(
resource::IResourceManager* resourceManager,
PhysicsManager* physicsManager
);

virtual bool initialize(const ObjectStore& objectStore) override final;

virtual const TypeInfoSet getEntityComponentTypes() const override final;
Expand Down
6 changes: 3 additions & 3 deletions code/Scene/Editor/DefaultEditorProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ void DefaultEditorProfile::createResourceFactories(

void DefaultEditorProfile::createEntityFactories(
SceneEditorContext* context,
RefArray< const world::IEntityFactory >& outEntityFactories
RefArray< world::IEntityFactory >& outEntityFactories
) const
{
outEntityFactories.push_back(new world::WorldEntityFactory(context->getResourceManager(), context->getRenderSystem(), true));
outEntityFactories.push_back(new world::WorldEntityFactory(true));
outEntityFactories.push_back(new world::WorldEditorEntityFactory());
outEntityFactories.push_back(new weather::WeatherFactory(context->getResourceManager(), context->getRenderSystem()));
outEntityFactories.push_back(new weather::WeatherFactory());
}

void DefaultEditorProfile::createEntityRenderers(
Expand Down
2 changes: 1 addition & 1 deletion code/Scene/Editor/DefaultEditorProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DefaultEditorProfile : public ISceneEditorProfile

virtual void createEntityFactories(
SceneEditorContext* context,
RefArray< const world::IEntityFactory >& outEntityFactories
RefArray< world::IEntityFactory >& outEntityFactories
) const override final;

virtual void createEntityRenderers(
Expand Down
2 changes: 1 addition & 1 deletion code/Scene/Editor/ISceneEditorProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class T_DLLCLASS ISceneEditorProfile : public Object
*/
virtual void createEntityFactories(
SceneEditorContext* context,
RefArray< const world::IEntityFactory >& outEntityFactories
RefArray< world::IEntityFactory >& outEntityFactories
) const = 0;

/*! Create entity renderers.
Expand Down
37 changes: 32 additions & 5 deletions code/Scene/Editor/SceneEditorContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
#include <stack>
#include "Core/Log/Log.h"
#include "Core/Math/Const.h"
#include "Core/Misc/ObjectStore.h"
#include "Core/Misc/SafeDestroy.h"
#include "Core/Serialization/DeepClone.h"
#include "Core/Serialization/DeepHash.h"
#include "Core/Timer/Timer.h"
#include "Database/Database.h"
#include "Physics/Body.h"
#include "Physics/PhysicsManager.h"
#include "Render/IRenderSystem.h"
#include "Render/ITexture.h"
#include "Resource/IResourceManager.h"
#include "Scene/Scene.h"
Expand Down Expand Up @@ -146,7 +149,7 @@ void SceneEditorContext::addEditorPlugin(ISceneEditorPlugin* editorPlugin)
m_editorPlugins.push_back(editorPlugin);
}

void SceneEditorContext::createFactories()
void SceneEditorContext::createEditorFactories()
{
m_entityEditorFactories.resize(0);
m_componentEditorFactories.resize(0);
Expand Down Expand Up @@ -440,14 +443,26 @@ void SceneEditorContext::buildEntities()

if (m_sceneAsset)
{
// Setup object store with relevant systems.
ObjectStore objectStore;
objectStore.set(getSourceDatabase());
objectStore.set(getPhysicsManager());
objectStore.set(getRenderSystem());
objectStore.set(getResourceManager());

// Create the entity factory.
Ref< world::EntityFactory > entityFactory = new world::EntityFactory();
for (auto editorProfile : m_editorProfiles)
{
RefArray< const world::IEntityFactory > entityFactories;
RefArray< world::IEntityFactory > entityFactories;
editorProfile->createEntityFactories(this, entityFactories);
for (auto factory : entityFactories)
entityFactory->addFactory(factory);
{
if (factory->initialize(objectStore))
entityFactory->addFactory(factory);
else
log::error << L"Failed to initialize entity factory \"" << type_name(factory) << L"\"." << Endl;
}
}

Ref< world::World > world = new world::World();
Expand Down Expand Up @@ -518,14 +533,26 @@ void SceneEditorContext::buildController()
{
T_FATAL_ASSERT(m_scene);

// Setup object store with relevant systems.
ObjectStore objectStore;
objectStore.set(getSourceDatabase());
objectStore.set(getPhysicsManager());
objectStore.set(getRenderSystem());
objectStore.set(getResourceManager());

// Create the entity factory.
Ref< world::EntityFactory > entityFactory = new world::EntityFactory();
for (auto editorProfile : m_editorProfiles)
{
RefArray< const world::IEntityFactory > entityFactories;
RefArray< world::IEntityFactory > entityFactories;
editorProfile->createEntityFactories(this, entityFactories);
for (auto factory : entityFactories)
entityFactory->addFactory(factory);
{
if (factory->initialize(objectStore))
entityFactory->addFactory(factory);
else
log::error << L"Failed to initialize entity factory \"" << type_name(factory) << L"\"." << Endl;
}
}

// Create all world components.
Expand Down
2 changes: 1 addition & 1 deletion code/Scene/Editor/SceneEditorContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class T_DLLCLASS SceneEditorContext : public ui::EventSubject

void addEditorPlugin(ISceneEditorPlugin* editorPlugin);

void createFactories();
void createEditorFactories();

void setControllerEditor(IWorldComponentEditor* controllerEditor);

Expand Down
18 changes: 15 additions & 3 deletions code/Scene/Editor/SceneEditorPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,28 @@ bool SceneEditorPage::create(ui::Container* parent)
}

// Create entity and component editor factories.
m_context->createFactories();
m_context->createEditorFactories();

// Setup object store with relevant systems.
ObjectStore objectStore;
objectStore.set(m_context->getSourceDatabase());
objectStore.set(m_context->getPhysicsManager());
objectStore.set(m_context->getRenderSystem());
objectStore.set(m_context->getResourceManager());

// Create scene instance resource factory, used by final render control etc.
Ref< world::EntityFactory > entityFactory = new world::EntityFactory();
for (auto editorProfile : m_context->getEditorProfiles())
{
RefArray< const world::IEntityFactory > entityFactories;
RefArray< world::IEntityFactory > entityFactories;
editorProfile->createEntityFactories(m_context, entityFactories);
for (auto factory : entityFactories)
entityFactory->addFactory(factory);
{
if (factory->initialize(objectStore))
entityFactory->addFactory(factory);
else
log::error << L"Failed to initialize entity factory \"" << type_name(factory) << L"\"." << Endl;
}
}
m_context->getResourceManager()->addFactory(new SceneFactory(entityFactory));

Expand Down
Loading

0 comments on commit a824c7b

Please sign in to comment.