Skip to content

Commit

Permalink
Traktor: Runtime dynamically create IResourceFactory instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed Apr 19, 2024
1 parent 4542d52 commit 39d255b
Show file tree
Hide file tree
Showing 50 changed files with 217 additions and 96 deletions.
7 changes: 6 additions & 1 deletion code/Ai/NavMeshFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
namespace traktor::ai
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.ai.NavMeshFactory", NavMeshFactory, resource::IResourceFactory)
T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.ai.NavMeshFactory", 0, NavMeshFactory, resource::IResourceFactory)

bool NavMeshFactory::initialize(const ObjectStore& objectStore)
{
return true;
}

const TypeInfoSet NavMeshFactory::getResourceTypes() const
{
Expand Down
2 changes: 2 additions & 0 deletions code/Ai/NavMeshFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class T_DLLCLASS NavMeshFactory : public resource::IResourceFactory
T_RTTI_CLASS;

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

virtual const TypeInfoSet getResourceTypes() const override final;

virtual const TypeInfoSet getProductTypes(const TypeInfo& resourceType) const override final;
Expand Down
7 changes: 6 additions & 1 deletion code/Animation/AnimationResourceFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
namespace traktor::animation
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.animation.AnimationResourceFactory", AnimationResourceFactory, resource::IResourceFactory)
T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.animation.AnimationResourceFactory", 0, AnimationResourceFactory, resource::IResourceFactory)

bool AnimationResourceFactory::initialize(const ObjectStore& objectStore)
{
return true;
}

const TypeInfoSet AnimationResourceFactory::getResourceTypes() const
{
Expand Down
2 changes: 2 additions & 0 deletions code/Animation/AnimationResourceFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class T_DLLCLASS AnimationResourceFactory : public resource::IResourceFactory
T_RTTI_CLASS;

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

virtual const TypeInfoSet getResourceTypes() const override final;

virtual const TypeInfoSet getProductTypes(const TypeInfo& resourceType) const override final;
Expand Down
7 changes: 6 additions & 1 deletion code/Heightfield/HeightfieldFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
namespace traktor::hf
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.hf.HeightfieldFactory", HeightfieldFactory, resource::IResourceFactory)
T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.hf.HeightfieldFactory", 0, HeightfieldFactory, resource::IResourceFactory)

bool HeightfieldFactory::initialize(const ObjectStore& objectStore)
{
return true;
}

const TypeInfoSet HeightfieldFactory::getResourceTypes() const
{
Expand Down
2 changes: 2 additions & 0 deletions code/Heightfield/HeightfieldFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class T_DLLCLASS HeightfieldFactory : public resource::IResourceFactory
T_RTTI_CLASS;

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

virtual const TypeInfoSet getResourceTypes() const override final;

virtual const TypeInfoSet getProductTypes(const TypeInfo& resourceType) const override final;
Expand Down
7 changes: 6 additions & 1 deletion code/Input/RumbleEffectFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
namespace traktor::input
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.input.RumbleEffectFactory", RumbleEffectFactory, resource::IResourceFactory)
T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.input.RumbleEffectFactory", 0, RumbleEffectFactory, resource::IResourceFactory)

bool RumbleEffectFactory::initialize(const ObjectStore& objectStore)
{
return true;
}

const TypeInfoSet RumbleEffectFactory::getResourceTypes() const
{
Expand Down
2 changes: 2 additions & 0 deletions code/Input/RumbleEffectFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class T_DLLCLASS RumbleEffectFactory : public resource::IResourceFactory
T_RTTI_CLASS;

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

virtual const TypeInfoSet getResourceTypes() const override final;

virtual const TypeInfoSet getProductTypes(const TypeInfo& resourceType) const override final;
Expand Down
15 changes: 14 additions & 1 deletion code/Mesh/MeshResourceFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@
#include "Compress/Lzf/InflateStreamLzf.h"
#include "Core/Io/IStream.h"
#include "Core/Log/Log.h"
#include "Core/Misc/ObjectStore.h"
#include "Database/Instance.h"
#include "Mesh/IMesh.h"
#include "Mesh/MeshResource.h"
#include "Mesh/MeshResourceFactory.h"
#include "Render/IRenderSystem.h"
#include "Render/Mesh/RenderMeshFactory.h"

namespace traktor::mesh
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.mesh.MeshResourceFactory", MeshResourceFactory, resource::IResourceFactory)
T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.mesh.MeshResourceFactory", 0, MeshResourceFactory, resource::IResourceFactory)

MeshResourceFactory::MeshResourceFactory(render::IRenderSystem* renderSystem, render::MeshFactory* meshFactory)
: m_renderSystem(renderSystem)
Expand All @@ -28,6 +30,17 @@ MeshResourceFactory::MeshResourceFactory(render::IRenderSystem* renderSystem, re
m_meshFactory = new render::RenderMeshFactory(m_renderSystem);
}

bool MeshResourceFactory::initialize(const ObjectStore& objectStore)
{
m_renderSystem = objectStore.get< render::IRenderSystem >();
m_meshFactory = objectStore.get< render::MeshFactory >();

if (!m_meshFactory)
m_meshFactory = new render::RenderMeshFactory(m_renderSystem);

return true;
}

const TypeInfoSet MeshResourceFactory::getResourceTypes() const
{
return makeTypeInfoSet< MeshResource >();
Expand Down
4 changes: 4 additions & 0 deletions code/Mesh/MeshResourceFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ class T_DLLCLASS MeshResourceFactory : public resource::IResourceFactory
T_RTTI_CLASS;

public:
MeshResourceFactory() = default;

explicit MeshResourceFactory(render::IRenderSystem* renderSystem, render::MeshFactory* meshFactory = nullptr);

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

virtual const TypeInfoSet getResourceTypes() const override final;

virtual const TypeInfoSet getProductTypes(const TypeInfo& resourceType) const override final;
Expand Down
7 changes: 6 additions & 1 deletion code/Physics/PhysicsFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
namespace traktor::physics
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.physics.PhysicsFactory", PhysicsFactory, resource::IResourceFactory)
T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.physics.PhysicsFactory", 0, PhysicsFactory, resource::IResourceFactory)

bool PhysicsFactory::initialize(const ObjectStore& objectStore)
{
return true;
}

const TypeInfoSet PhysicsFactory::getResourceTypes() const
{
Expand Down
2 changes: 2 additions & 0 deletions code/Physics/PhysicsFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class T_DLLCLASS PhysicsFactory : public resource::IResourceFactory
T_RTTI_CLASS;

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

virtual const TypeInfoSet getResourceTypes() const override final;

virtual const TypeInfoSet getProductTypes(const TypeInfo& resourceType) const override final;
Expand Down
10 changes: 9 additions & 1 deletion code/Render/Image2/ImageGraphFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,29 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "Core/Misc/ObjectStore.h"
#include "Database/Instance.h"
#include "Render/IRenderSystem.h"
#include "Render/Image2/ImageGraph.h"
#include "Render/Image2/ImageGraphData.h"
#include "Render/Image2/ImageGraphFactory.h"

namespace traktor::render
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.render.ImageGraphFactory", ImageGraphFactory, resource::IResourceFactory)
T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.render.ImageGraphFactory", 0, ImageGraphFactory, resource::IResourceFactory)

ImageGraphFactory::ImageGraphFactory(IRenderSystem* renderSystem)
: m_renderSystem(renderSystem)
{
}

bool ImageGraphFactory::initialize(const ObjectStore& objectStore)
{
m_renderSystem = objectStore.get< IRenderSystem >();
return true;
}

const TypeInfoSet ImageGraphFactory::getResourceTypes() const
{
return makeTypeInfoSet< ImageGraphData >();
Expand Down
4 changes: 4 additions & 0 deletions code/Render/Image2/ImageGraphFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ class T_DLLCLASS ImageGraphFactory : public resource::IResourceFactory
T_RTTI_CLASS;

public:
ImageGraphFactory() = default;

explicit ImageGraphFactory(IRenderSystem* renderSystem);

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

virtual const TypeInfoSet getResourceTypes() const override final;

virtual const TypeInfoSet getProductTypes(const TypeInfo& resourceType) const override final;
Expand Down
7 changes: 6 additions & 1 deletion code/Render/Resource/AliasTextureFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
namespace traktor::render
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.render.AliasTextureFactory", AliasTextureFactory, resource::IResourceFactory)
T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.render.AliasTextureFactory", 0, AliasTextureFactory, resource::IResourceFactory)

bool AliasTextureFactory::initialize(const ObjectStore& objectStore)
{
return true;
}

const TypeInfoSet AliasTextureFactory::getResourceTypes() const
{
Expand Down
2 changes: 2 additions & 0 deletions code/Render/Resource/AliasTextureFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class T_DLLCLASS AliasTextureFactory : public resource::IResourceFactory
T_RTTI_CLASS;

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

virtual const TypeInfoSet getResourceTypes() const override final;

virtual const TypeInfoSet getProductTypes(const TypeInfo& resourceType) const override final;
Expand Down
9 changes: 8 additions & 1 deletion code/Render/Resource/ShaderFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "Core/Log/Log.h"
#include "Core/Misc/ObjectStore.h"
#include "Database/Instance.h"
#include "Render/IProgram.h"
#include "Render/IRenderSystem.h"
Expand Down Expand Up @@ -51,13 +52,19 @@ class TextureReaderAdapter : public TextureLinker::TextureReader

}

T_IMPLEMENT_RTTI_CLASS(L"traktor.render.ShaderFactory", ShaderFactory, resource::IResourceFactory)
T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.render.ShaderFactory", 0, ShaderFactory, resource::IResourceFactory)

ShaderFactory::ShaderFactory(IRenderSystem* renderSystem)
: m_renderSystem(renderSystem)
{
}

bool ShaderFactory::initialize(const ObjectStore& objectStore)
{
m_renderSystem = objectStore.get< IRenderSystem >();
return true;
}

const TypeInfoSet ShaderFactory::getResourceTypes() const
{
return makeTypeInfoSet< ShaderResource >();
Expand Down
4 changes: 4 additions & 0 deletions code/Render/Resource/ShaderFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ class T_DLLCLASS ShaderFactory : public resource::IResourceFactory
T_RTTI_CLASS;

public:
ShaderFactory() = default;

explicit ShaderFactory(IRenderSystem* renderSystem);

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

virtual const TypeInfoSet getResourceTypes() const override final;

virtual const TypeInfoSet getProductTypes(const TypeInfo& resourceType) const override final;
Expand Down
9 changes: 8 additions & 1 deletion code/Render/Resource/TextureFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Core/Io/Reader.h"
#include "Core/Log/Log.h"
#include "Core/Misc/AutoPtr.h"
#include "Core/Misc/ObjectStore.h"
#include "Database/Instance.h"
#include "Render/IRenderSystem.h"
#include "Render/Resource/TextureFactory.h"
Expand All @@ -35,7 +36,7 @@ uint32_t mipChainSize(TextureFormat format, int width, int height, int mipCount)

}

T_IMPLEMENT_RTTI_CLASS(L"traktor.render.TextureFactory", TextureFactory, resource::IResourceFactory)
T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.render.TextureFactory", 0, TextureFactory, resource::IResourceFactory)

TextureFactory::TextureFactory(IRenderSystem* renderSystem, int32_t skipMips)
: m_renderSystem(renderSystem)
Expand All @@ -53,6 +54,12 @@ int32_t TextureFactory::getSkipMips() const
return m_skipMips;
}

bool TextureFactory::initialize(const ObjectStore& objectStore)
{
m_renderSystem = objectStore.get< IRenderSystem >();
return true;
}

const TypeInfoSet TextureFactory::getResourceTypes() const
{
return makeTypeInfoSet< TextureResource >();
Expand Down
6 changes: 5 additions & 1 deletion code/Render/Resource/TextureFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ class T_DLLCLASS TextureFactory : public resource::IResourceFactory
T_RTTI_CLASS;

public:
TextureFactory() = default;

explicit TextureFactory(IRenderSystem* renderSystem, int32_t skipMips);

void setSkipMips(int32_t skipMips);

int32_t getSkipMips() const;

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

virtual const TypeInfoSet getResourceTypes() const override final;

virtual const TypeInfoSet getProductTypes(const TypeInfo& resourceType) const override final;
Expand All @@ -47,7 +51,7 @@ class T_DLLCLASS TextureFactory : public resource::IResourceFactory

private:
Ref< IRenderSystem > m_renderSystem;
int32_t m_skipMips;
int32_t m_skipMips = 0;
};

}
10 changes: 10 additions & 0 deletions code/Resource/IResourceFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
# define T_DLLCLASS T_DLLIMPORT
#endif

namespace traktor
{

class ObjectStore;

}

namespace traktor::db
{

Expand Down Expand Up @@ -48,6 +55,9 @@ class T_DLLCLASS IResourceFactory : public Object
T_RTTI_CLASS;

public:
/*! */
virtual bool initialize(const ObjectStore& objectStore) = 0;

/*! Get resource types.
*
* Return a set of resource types this factory
Expand Down
2 changes: 1 addition & 1 deletion code/Runtime/IWorldServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class T_DLLCLASS IWorldServer : public IServer

virtual void removeEntityRenderer(world::IEntityRenderer* entityRenderer) = 0;

virtual const world::IEntityFactory* getEntityFactory() = 0;
virtual world::IEntityFactory* getEntityFactory() = 0;

virtual world::WorldEntityRenderers* getEntityRenderers() = 0;

Expand Down
8 changes: 0 additions & 8 deletions code/Runtime/Impl/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,6 @@ bool Application::create(

// Resource factories
T_DEBUG(L"Creating resource factories...");
if (m_audioServer)
m_audioServer->createResourceFactories(m_environment);
if (m_inputServer)
m_inputServer->createResourceFactories(m_environment);
if (m_physicsServer)
m_physicsServer->createResourceFactories(m_environment);
if (m_renderServer)
m_renderServer->createResourceFactories(m_environment);
if (m_resourceServer)
Expand All @@ -296,8 +290,6 @@ bool Application::create(
T_DEBUG(L"Creating entity factories...");
if (m_worldServer)
m_worldServer->createEntityFactories(m_environment);
if (m_worldServer && m_physicsServer)
m_physicsServer->createEntityFactories(m_environment);

// Entity renderers.
T_DEBUG(L"Creating entity renderers...");
Expand Down
Loading

0 comments on commit 39d255b

Please sign in to comment.