Skip to content

Commit

Permalink
Traktor: Refactored "object store" in editor; no longer reference obj…
Browse files Browse the repository at this point in the history
…ects using names but instead types.
  • Loading branch information
apistol78 committed Apr 18, 2024
1 parent ddeb5b7 commit bccfc47
Show file tree
Hide file tree
Showing 45 changed files with 252 additions and 163 deletions.
2 changes: 1 addition & 1 deletion code/Animation/Editor/AnimationBrowsePreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ TypeInfoSet AnimationBrowsePreview::getPreviewTypes() const
return makeTypeInfoSet< AnimationAsset, SkeletonAsset >();
}

Ref< ui::Bitmap > AnimationBrowsePreview::generate(const editor::IEditor* editor, db::Instance* instance) const
Ref< ui::Bitmap > AnimationBrowsePreview::generate(editor::IEditor* editor, db::Instance* instance) const
{
Ref< const editor::Asset > asset = instance->getObject< editor::Asset >();
if (!asset)
Expand Down
2 changes: 1 addition & 1 deletion code/Animation/Editor/AnimationBrowsePreview.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class T_DLLCLASS AnimationBrowsePreview : public editor::IBrowsePreview
public:
virtual TypeInfoSet getPreviewTypes() const override final;

virtual Ref< ui::Bitmap > generate(const editor::IEditor* editor, db::Instance* instance) const override final;
virtual Ref< ui::Bitmap > generate(editor::IEditor* editor, db::Instance* instance) const override final;
};

}
3 changes: 2 additions & 1 deletion code/Animation/Editor/AnimationPreviewControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Animation/SkeletonUtils.h"
#include "Animation/Editor/AnimationPreviewControl.h"
#include "Core/Math/Plane.h"
#include "Core/Misc/ObjectStore.h"
#include "Core/Misc/SafeDestroy.h"
#include "Core/Settings/PropertyBoolean.h"
#include "Core/Settings/PropertyColor.h"
Expand Down Expand Up @@ -80,7 +81,7 @@ bool AnimationPreviewControl::create(ui::Widget* parent)
if (!Widget::create(parent, ui::WsNoCanvas))
return false;

m_renderSystem = m_editor->getStoreObject< render::IRenderSystem >(L"RenderSystem");
m_renderSystem = m_editor->getObjectStore()->get< render::IRenderSystem >();
if (!m_renderSystem)
return false;

Expand Down
45 changes: 45 additions & 0 deletions code/Core/Misc/ObjectStore.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* TRAKTOR
* Copyright (c) 2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* 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"

namespace traktor
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.ObjectStore", ObjectStore, Object)

void ObjectStore::set(Object* object)
{
const TypeInfo& objectType = type_of(object);
auto it = std::remove_if(m_objects.begin(), m_objects.end(), [&](Object* object) {
return is_type_of(
type_of(object),
objectType
);
});
m_objects.erase(it, m_objects.end());
m_objects.push_back(object);
}

bool ObjectStore::unset(Object* object)
{
return m_objects.remove(object);
}

Object* ObjectStore::get(const TypeInfo& objectType) const
{
auto it = std::find_if(m_objects.begin(), m_objects.end(), [&](Object* object) {
return is_type_of(
objectType,
type_of(object)
);
});
return it != m_objects.end() ? *it : nullptr;
}

}
57 changes: 57 additions & 0 deletions code/Core/Misc/ObjectStore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* TRAKTOR
* Copyright (c) 2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* 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/.
*/
#pragma once

#include "Core/Object.h"
#include "Core/RefArray.h"
#include "Core/Containers/SmallMap.h"

// import/export mechanism.
#undef T_DLLCLASS
#if defined(T_CORE_EXPORT)
# define T_DLLCLASS T_DLLEXPORT
#else
# define T_DLLCLASS T_DLLIMPORT
#endif

namespace traktor
{

/*! Object store container, maps type to instance.
* \ingroup Core
*/
class T_DLLCLASS ObjectStore : public Object
{
T_RTTI_CLASS;

public:
void set(Object* object);

bool unset(Object* object);

Object* get(const TypeInfo& objectType) const;

template < typename ObjectType >
ObjectType* get() const
{
return dynamic_type_cast< ObjectType* >(get(type_of< ObjectType >()));
}

template < typename ObjectType >
bool unset()
{
Object* object = get< ObjectType >();
return object ? unset(object) : false;
}

private:
RefArray< Object > m_objects;
};

}
2 changes: 1 addition & 1 deletion code/Editor/App/BrowseInstanceDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool recursiveIncludeGroup(db::Group* group, const IBrowseFilter* filter)

T_IMPLEMENT_RTTI_CLASS(L"traktor.editor.BrowseInstanceDialog", BrowseInstanceDialog, ui::ConfigDialog)

BrowseInstanceDialog::BrowseInstanceDialog(const IEditor* editor, PropertyGroup* settings)
BrowseInstanceDialog::BrowseInstanceDialog(IEditor* editor, PropertyGroup* settings)
: m_editor(editor)
, m_settings(settings)
, m_threadGeneratePreview(nullptr)
Expand Down
4 changes: 2 additions & 2 deletions code/Editor/App/BrowseInstanceDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class BrowseInstanceDialog : public ui::ConfigDialog
T_RTTI_CLASS;

public:
explicit BrowseInstanceDialog(const IEditor* editor, PropertyGroup* settings);
explicit BrowseInstanceDialog(IEditor* editor, PropertyGroup* settings);

bool create(ui::Widget* parent, db::Database* database, const IBrowseFilter* filter);

Expand All @@ -62,7 +62,7 @@ class BrowseInstanceDialog : public ui::ConfigDialog
Ref< db::Instance > getInstance();

private:
const IEditor* m_editor;
IEditor* m_editor;
Ref< PropertyGroup > m_settings;
Ref< ui::TreeView > m_treeDatabase;
Ref< ui::PreviewList > m_listInstances;
Expand Down
13 changes: 11 additions & 2 deletions code/Editor/App/DiscoveryPlugin.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* TRAKTOR
* Copyright (c) 2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* 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 "Core/Misc/SafeDestroy.h"
#include "Core/Settings/PropertyBoolean.h"
#include "Core/Settings/PropertyGroup.h"
Expand Down Expand Up @@ -26,13 +35,13 @@ bool DiscoveryPlugin::create(ui::Widget* parent, IEditorPageSite* site)
m_discoveryManager = new net::DiscoveryManager();
m_discoveryManager->create(mode);

m_editor->setStoreObject(L"DiscoveryManager", m_discoveryManager);
m_editor->getObjectStore()->set(m_discoveryManager);
return true;
}

void DiscoveryPlugin::destroy()
{
m_editor->setStoreObject(L"DiscoveryManager", nullptr);
m_editor->getObjectStore()->unset(m_discoveryManager);
safeDestroy(m_discoveryManager);
}

Expand Down
26 changes: 12 additions & 14 deletions code/Editor/App/EditorForm.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022-2023 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -14,6 +14,7 @@
#include "Core/Log/LogRedirectTarget.h"
#include "Core/Memory/Alloc.h"
#include "Core/Misc/CommandLine.h"
#include "Core/Misc/ObjectStore.h"
#include "Core/Misc/EnterLeave.h"
#include "Core/Misc/SafeDestroy.h"
#include "Core/Misc/String.h"
Expand Down Expand Up @@ -648,6 +649,9 @@ bool EditorForm::create(const CommandLine& cmdLine)
m_buildProgress->create(m_statusBar);
m_buildProgress->setVisible(false);

// Create object store.
m_objectStore = new ObjectStore();

// Create editor page factories.
for (const auto& editorPageFactoryType : type_of< IEditorPageFactory >().findAllOf(false))
{
Expand Down Expand Up @@ -783,7 +787,7 @@ bool EditorForm::create(const CommandLine& cmdLine)

// Create auxiliary tools.
Path thumbsPath = m_mergedSettings->getProperty< std::wstring >(L"Editor.ThumbsPath");
setStoreObject(L"ThumbnailGenerator", new ThumbnailGenerator(thumbsPath));
m_objectStore->set(new ThumbnailGenerator(thumbsPath));

// Restore last used form settings, if desktop size still match.
int32_t x = 0, y = 0, width = 1280, height = 900;
Expand Down Expand Up @@ -1549,8 +1553,8 @@ bool EditorForm::openWorkspace(const Path& workspacePath)
}

// Expose servers as stock objects.
setStoreObject(L"StreamServer", m_streamServer);
setStoreObject(L"DbConnectionManager", m_dbConnectionManager);
m_objectStore->set(m_streamServer);
m_objectStore->set(m_dbConnectionManager);

// Notify plugins about opened workspace.
for (auto editorPluginSite : m_editorPluginSites)
Expand Down Expand Up @@ -1600,8 +1604,8 @@ void EditorForm::closeWorkspace()
}

// Remove store objects.
setStoreObject(L"StreamServer", nullptr);
setStoreObject(L"DbConnectionManager", nullptr);
m_objectStore->unset(m_dbConnectionManager);
m_objectStore->unset(m_streamServer);

// Shutdown agents manager.
safeDestroy(m_dbConnectionManager);
Expand Down Expand Up @@ -1996,15 +2000,9 @@ Ref< IPipelineDepends> EditorForm::createPipelineDepends(PipelineDependencySet*
);
}

void EditorForm::setStoreObject(const std::wstring& name, Object* object)
{
m_objectStore[name] = object;
}

Object* EditorForm::getStoreObject(const std::wstring& name) const
ObjectStore* EditorForm::getObjectStore()
{
const auto it = m_objectStore.find(name);
return it != m_objectStore.end() ? it->second : nullptr;
return m_objectStore;
}

void EditorForm::beginBuild(int32_t index, int32_t count, const PipelineDependency* dependency)
Expand Down
6 changes: 2 additions & 4 deletions code/Editor/App/EditorForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ class EditorForm

virtual Ref< IPipelineDepends> createPipelineDepends(PipelineDependencySet* dependencySet, uint32_t recursionDepth) override final;

virtual void setStoreObject(const std::wstring& name, Object* object) override final;

virtual Object* getStoreObject(const std::wstring& name) const override final;
virtual ObjectStore* getObjectStore() override final;

//@}

Expand All @@ -188,7 +186,7 @@ class EditorForm
Ref< db::ConnectionManager > m_dbConnectionManager;
Ref< IPipelineDb > m_pipelineDb;
Ref< IPipelineCache > m_pipelineCache;
std::map< std::wstring, Ref< Object > > m_objectStore;
Ref< ObjectStore > m_objectStore;
Ref< MRU > m_mru;
std::list< ui::Command > m_shortcutCommands;
Ref< ui::ShortcutTable > m_shortcutTable;
Expand Down
11 changes: 3 additions & 8 deletions code/Editor/App/ObjectEditor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -190,14 +190,9 @@ Ref< IPipelineDepends> ObjectEditor::createPipelineDepends(PipelineDependencySet
return m_editor->createPipelineDepends(dependencySet, recursionDepth);
}

void ObjectEditor::setStoreObject(const std::wstring& name, Object* object)
ObjectStore* ObjectEditor::getObjectStore()
{
m_editor->setStoreObject(name, object);
}

Object* ObjectEditor::getStoreObject(const std::wstring& name) const
{
return m_editor->getStoreObject(name);
return m_editor->getObjectStore();
}

}
6 changes: 2 additions & 4 deletions code/Editor/App/ObjectEditor.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022-2023 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -92,9 +92,7 @@ class ObjectEditor

virtual Ref< IPipelineDepends> createPipelineDepends(PipelineDependencySet* dependencySet, uint32_t recursionDepth) override final;

virtual void setStoreObject(const std::wstring& name, Object* object) override final;

virtual Object* getStoreObject(const std::wstring& name) const override final;
virtual ObjectStore* getObjectStore() override final;

private:
IEditor* m_editor;
Expand Down
4 changes: 2 additions & 2 deletions code/Editor/IBrowsePreview.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -48,7 +48,7 @@ class T_DLLCLASS IBrowsePreview : public Object
public:
virtual TypeInfoSet getPreviewTypes() const = 0;

virtual Ref< ui::Bitmap > generate(const IEditor* editor, db::Instance* instance) const = 0;
virtual Ref< ui::Bitmap > generate(IEditor* editor, db::Instance* instance) const = 0;
};

}
Loading

0 comments on commit bccfc47

Please sign in to comment.