Skip to content

Commit 72542c4

Browse files
committed
Traktor: Scene asset operator data share base class to ensure valid data types are used.
1 parent 1f4d170 commit 72542c4

13 files changed

Lines changed: 103 additions & 108 deletions

code/Scene/Editor/ExternalOperationData.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
/*
22
* TRAKTOR
3-
* Copyright (c) 2022 Anders Pistol.
3+
* Copyright (c) 2022-2026 Anders Pistol.
44
*
55
* This Source Code Form is subject to the terms of the Mozilla Public
66
* License, v. 2.0. If a copy of the MPL was not distributed with this
77
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
88
*/
9+
#include "Scene/Editor/ExternalOperationData.h"
10+
911
#include "Core/Serialization/ISerializer.h"
1012
#include "Core/Serialization/Member.h"
11-
#include "Scene/Editor/ExternalOperationData.h"
1213

1314
namespace traktor::scene
1415
{
1516

16-
T_IMPLEMENT_RTTI_EDIT_CLASS(L"traktor.scene.ExternalOperationData", 0, ExternalOperationData, ISerializable)
17+
T_IMPLEMENT_RTTI_EDIT_CLASS(L"traktor.scene.ExternalOperationData", 0, ExternalOperationData, ISceneOperationData)
1718

1819
void ExternalOperationData::serialize(ISerializer& s)
1920
{

code/Scene/Editor/ExternalOperationData.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* TRAKTOR
3-
* Copyright (c) 2022 Anders Pistol.
3+
* Copyright (c) 2022-2026 Anders Pistol.
44
*
55
* This Source Code Form is subject to the terms of the Mozilla Public
66
* License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -9,7 +9,7 @@
99
#pragma once
1010

1111
#include "Core/Guid.h"
12-
#include "Core/Serialization/ISerializable.h"
12+
#include "Scene/Editor/ISceneOperationData.h"
1313

1414
// import/export mechanism.
1515
#undef T_DLLCLASS
@@ -22,7 +22,7 @@
2222
namespace traktor::scene
2323
{
2424

25-
class T_DLLCLASS ExternalOperationData : public ISerializable
25+
class T_DLLCLASS ExternalOperationData : public ISceneOperationData
2626
{
2727
T_RTTI_CLASS;
2828

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* TRAKTOR
3+
* Copyright (c) 2026 Anders Pistol.
4+
*
5+
* This Source Code Form is subject to the terms of the Mozilla Public
6+
* License, v. 2.0. If a copy of the MPL was not distributed with this
7+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
8+
*/
9+
#include "Scene/Editor/ISceneOperationData.h"
10+
11+
namespace traktor::scene
12+
{
13+
14+
T_IMPLEMENT_RTTI_CLASS(L"traktor.scene.ISceneOperationData", ISceneOperationData, ISerializable)
15+
16+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* TRAKTOR
3+
* Copyright (c) 2026 Anders Pistol.
4+
*
5+
* This Source Code Form is subject to the terms of the Mozilla Public
6+
* License, v. 2.0. If a copy of the MPL was not distributed with this
7+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
8+
*/
9+
#pragma once
10+
11+
#include "Core/Serialization/ISerializable.h"
12+
13+
// import/export mechanism.
14+
#undef T_DLLCLASS
15+
#if defined(T_SCENE_EDITOR_EXPORT)
16+
# define T_DLLCLASS T_DLLEXPORT
17+
#else
18+
# define T_DLLCLASS T_DLLIMPORT
19+
#endif
20+
21+
namespace traktor::scene
22+
{
23+
24+
class T_DLLCLASS ISceneOperationData : public ISerializable
25+
{
26+
T_RTTI_CLASS;
27+
};
28+
29+
}

code/Scene/Editor/SceneAsset.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/*
22
* TRAKTOR
3-
* Copyright (c) 2022-2024 Anders Pistol.
3+
* Copyright (c) 2022-2026 Anders Pistol.
44
*
55
* This Source Code Form is subject to the terms of the Mozilla Public
66
* License, v. 2.0. If a copy of the MPL was not distributed with this
77
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
88
*/
9+
#include "Scene/Editor/SceneAsset.h"
10+
911
#include "Core/Serialization/AttributePrivate.h"
1012
#include "Core/Serialization/ISerializer.h"
1113
#include "Core/Serialization/MemberComposite.h"
@@ -14,8 +16,8 @@
1416
#include "Core/Serialization/MemberSmallMap.h"
1517
#include "Render/ITexture.h"
1618
#include "Resource/Member.h"
19+
#include "Scene/Editor/ISceneOperationData.h"
1720
#include "Scene/Scene.h"
18-
#include "Scene/Editor/SceneAsset.h"
1921
#include "World/EntityData.h"
2022
#include "World/IWorldComponentData.h"
2123
#include "World/WorldRenderSettings.h"
@@ -83,12 +85,12 @@ const RefArray< world::EntityData >& SceneAsset::getLayers() const
8385
return m_layers;
8486
}
8587

86-
void SceneAsset::setOperationData(const RefArray< ISerializable >& operationData)
88+
void SceneAsset::setOperationData(const RefArray< ISceneOperationData >& operationData)
8789
{
8890
m_operationData = operationData;
8991
}
9092

91-
const RefArray< ISerializable >& SceneAsset::getOperationData() const
93+
const RefArray< ISceneOperationData >& SceneAsset::getOperationData() const
9294
{
9395
return m_operationData;
9496
}
@@ -100,7 +102,7 @@ void SceneAsset::serialize(ISerializer& s)
100102
s >> MemberRef< world::WorldRenderSettings >(L"worldRenderSettings", m_worldRenderSettings);
101103
s >> MemberRefArray< world::IWorldComponentData >(L"worldComponents", m_worldComponents);
102104
s >> MemberRefArray< world::EntityData >(L"layers", m_layers, AttributePrivate());
103-
s >> MemberRefArray< ISerializable >(L"operationData", m_operationData);
105+
s >> MemberRefArray< ISceneOperationData >(L"operationData", m_operationData);
104106
}
105107

106108
}

code/Scene/Editor/SceneAsset.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* TRAKTOR
3-
* Copyright (c) 2022-2024 Anders Pistol.
3+
* Copyright (c) 2022-2026 Anders Pistol.
44
*
55
* This Source Code Form is subject to the terms of the Mozilla Public
66
* License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -33,6 +33,8 @@ class WorldRenderSettings;
3333
namespace traktor::scene
3434
{
3535

36+
class ISceneOperationData;
37+
3638
class T_DLLCLASS SceneAsset : public ISerializable
3739
{
3840
T_RTTI_CLASS;
@@ -72,17 +74,17 @@ class T_DLLCLASS SceneAsset : public ISerializable
7274

7375
const RefArray< world::EntityData >& getLayers() const;
7476

75-
void setOperationData(const RefArray< ISerializable >& operationData);
77+
void setOperationData(const RefArray< ISceneOperationData >& operationData);
7678

77-
const RefArray< ISerializable >& getOperationData() const;
79+
const RefArray< ISceneOperationData >& getOperationData() const;
7880

7981
virtual void serialize(ISerializer& s) override final;
8082

8183
private:
8284
Ref< world::WorldRenderSettings > m_worldRenderSettings;
8385
RefArray< world::IWorldComponentData > m_worldComponents;
8486
RefArray< world::EntityData > m_layers;
85-
RefArray< ISerializable > m_operationData;
87+
RefArray< ISceneOperationData > m_operationData;
8688
};
8789

8890
}

code/Scene/Editor/SceneEditorPage.cpp

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "Scene/Editor/Events/PreModifyEvent.h"
5252
#include "Scene/Editor/Events/SceneSelectionChangeEvent.h"
5353
#include "Scene/Editor/ISceneEditorPlugin.h"
54+
#include "Scene/Editor/ISceneOperationData.h"
5455
#include "Scene/Editor/IWorldComponentEditor.h"
5556
#include "Scene/Editor/IWorldComponentEditorFactory.h"
5657
#include "Scene/Editor/SceneAsset.h"
@@ -118,33 +119,6 @@ constexpr int32_t c_instanceGridDynamic = 1;
118119
constexpr int32_t c_instanceGridVisible = 2;
119120
constexpr int32_t c_instanceGridLocked = 3;
120121

121-
void renameIds(ISerializable* object, const SmallMap< Guid, Guid >& renamedMap)
122-
{
123-
Ref< Reflection > reflection = Reflection::create(object);
124-
125-
// Rename all id;s in this object first.
126-
RefArray< ReflectionMember > idMembers;
127-
reflection->findMembers(RfpMemberType(type_of< RfmPrimitiveGuid >()), idMembers);
128-
for (auto idMember : idMembers)
129-
{
130-
auto id = static_cast< RfmPrimitiveGuid* >(idMember.ptr());
131-
auto it = renamedMap.find(id->get());
132-
if (it != renamedMap.end())
133-
id->set(it->second);
134-
}
135-
136-
// Recurse with child objects.
137-
RefArray< ReflectionMember > objectMembers;
138-
reflection->findMembers(RfpMemberType(type_of< RfmObject >()), objectMembers);
139-
for (auto objectMember : objectMembers)
140-
{
141-
auto object = static_cast< RfmObject* >(objectMember.ptr());
142-
renameIds(object->get(), renamedMap);
143-
}
144-
145-
reflection->apply(object);
146-
}
147-
148122
bool isChildEntitySelected(const EntityAdapter* entityAdapter)
149123
{
150124
for (auto child : entityAdapter->getChildren())
@@ -976,20 +950,11 @@ bool SceneEditorPage::handleCommand(const ui::Command& command)
976950
{
977951
if (ui::MessageBox::show(m_editControl, i18n::Text(L"SCENE_EDITOR_RENAME_ALL_ENTITY_IDS_MESSAGE"), i18n::Text(L"SCENE_EDITOR_RENAME_ALL_ENTITY_IDS_TITLE"), ui::MbIconExclamation | ui::MbYesNo) == ui::DialogResult::Yes)
978952
{
979-
SmallMap< Guid, Guid > renamedMap;
980-
981-
// Create new IDs for each entity.
982953
for (auto entity : m_context->getEntities(SceneEditorContext::GfDescendants))
983954
{
984-
Guid newEntityId = Guid::create();
985-
if (entity->getEntityData()->getId().isNotNull())
986-
renamedMap.insert(entity->getEntityData()->getId(), newEntityId);
955+
const Guid newEntityId = Guid::create();
987956
entity->getEntityData()->setId(newEntityId);
988957
}
989-
990-
// Also ensure attached data contain updated entity identities.
991-
for (auto operationData : m_context->getSceneAsset()->getOperationData())
992-
renameIds(operationData, renamedMap);
993958
}
994959
}
995960
else if (command == L"Scene.Editor.PlaceOnGround")

code/Scene/Editor/SceneEditorPageFactory.cpp

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "Editor/IEditor.h"
1616
#include "Scene/Editor/ISceneEditorUIExtension.h"
1717
#include "Scene/Editor/ISceneEditorPlugin.h"
18+
#include "Scene/Editor/ISceneOperationData.h"
1819
#include "Scene/Editor/SceneAsset.h"
1920
#include "Scene/Editor/SceneEditorPage.h"
2021
#include "Scene/Editor/SceneEditorPageFactory.h"
@@ -24,37 +25,6 @@
2425

2526
namespace traktor::scene
2627
{
27-
namespace
28-
{
29-
30-
void renameIds(ISerializable* object, const SmallMap< Guid, Guid >& renamedMap)
31-
{
32-
Ref< Reflection > reflection = Reflection::create(object);
33-
34-
// Rename all id;s in this object first.
35-
RefArray< ReflectionMember > idMembers;
36-
reflection->findMembers(RfpMemberType(type_of< RfmPrimitiveGuid >()), idMembers);
37-
for (auto idMember : idMembers)
38-
{
39-
auto id = static_cast< RfmPrimitiveGuid* >(idMember.ptr());
40-
auto it = renamedMap.find(id->get());
41-
if (it != renamedMap.end())
42-
id->set(it->second);
43-
}
44-
45-
// Recurse with child objects.
46-
RefArray< ReflectionMember > objectMembers;
47-
reflection->findMembers(RfpMemberType(type_of< RfmObject >()), objectMembers);
48-
for (auto objectMember : objectMembers)
49-
{
50-
auto object = static_cast< RfmObject* >(objectMember.ptr());
51-
renameIds(object->get(), renamedMap);
52-
}
53-
54-
reflection->apply(object);
55-
}
56-
57-
}
5828

5929
T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.scene.SceneEditorPageFactory", 0, SceneEditorPageFactory, editor::IEditorPageFactory)
6030

@@ -144,36 +114,21 @@ Ref< ISerializable > SceneEditorPageFactory::cloneAsset(const ISerializable* ass
144114

145115
if (auto mutableSceneAsset = dynamic_type_cast< SceneAsset* >(mutableAsset))
146116
{
147-
SmallMap< Guid, Guid > renamedMap;
148-
149-
// Rename all entities.
150117
Traverser::visit(mutableSceneAsset, [&](Ref< world::EntityData >& inoutEntityData) -> Traverser::Result {
151-
Guid newEntityId = Guid::create();
152-
if (inoutEntityData->getId().isNotNull())
153-
renamedMap.insert(inoutEntityData->getId(), newEntityId);
118+
const Guid newEntityId = Guid::create();
154119
inoutEntityData->setId(newEntityId);
155120
return Traverser::Result::Continue;
156121
});
157-
158-
// Also ensure attached data contain updated entity identities.
159-
for (auto operationData : mutableSceneAsset->getOperationData())
160-
renameIds(operationData, renamedMap);
161122
}
162123
else if (auto mutableEntityData = dynamic_type_cast< world::EntityData* >(mutableAsset))
163124
{
164-
SmallMap< Guid, Guid > renamedMap;
165-
166125
// Rename root entity data.
167-
Guid newEntityId = Guid::create();
168-
if (mutableEntityData->getId().isNotNull())
169-
renamedMap.insert(mutableEntityData->getId(), newEntityId);
126+
const Guid newEntityId = Guid::create();
170127
mutableEntityData->setId(newEntityId);
171128

172129
// Rename all entities.
173130
Traverser::visit(mutableEntityData, [&](Ref< world::EntityData >& inoutEntityData) -> Traverser::Result {
174-
Guid newEntityId = Guid::create();
175-
if (inoutEntityData->getId().isNotNull())
176-
renamedMap.insert(inoutEntityData->getId(), newEntityId);
131+
const Guid newEntityId = Guid::create();
177132
inoutEntityData->setId(newEntityId);
178133
return Traverser::Result::Continue;
179134
});

code/Scene/Editor/ScenePipeline.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "Editor/Pipeline/PipelineProfiler.h"
1919
#include "Scene/SceneResource.h"
2020
#include "Scene/Editor/ExternalOperationData.h"
21+
#include "Scene/Editor/ISceneOperationData.h"
2122
#include "Scene/Editor/IScenePipelineOperator.h"
2223
#include "Scene/Editor/ScenePipeline.h"
2324
#include "Scene/Editor/SceneAsset.h"
@@ -97,12 +98,12 @@ bool ScenePipeline::buildDependencies(
9798
Ref< SceneAsset > mutableSceneAsset = DeepClone(sceneAsset).create< SceneAsset >();
9899
for (const auto op : sceneAsset->getOperationData())
99100
{
100-
Ref< const ISerializable > operationData = op;
101+
Ref< const ISceneOperationData > operationData = op;
101102

102103
// Check if external data is references; if so add dependency and resolve external data.
103104
if (const ExternalOperationData* externalOperationData = dynamic_type_cast< const ExternalOperationData* >(operationData))
104105
{
105-
operationData = pipelineDepends->getObjectReadOnly(externalOperationData->getExternalDataId());
106+
operationData = pipelineDepends->getObjectReadOnly< ISceneOperationData >(externalOperationData->getExternalDataId());
106107
if (!operationData)
107108
{
108109
log::error << L"Scene pipeline failed; unable to read operation data " << externalOperationData->getExternalDataId().format() << L"." << Endl;

code/Shape/Editor/Bake/BakeConfiguration.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* TRAKTOR
3-
* Copyright (c) 2022-2024 Anders Pistol.
3+
* Copyright (c) 2022-2026 Anders Pistol.
44
*
55
* This Source Code Form is subject to the terms of the Mozilla Public
66
* License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -18,7 +18,7 @@
1818
namespace traktor::shape
1919
{
2020

21-
T_IMPLEMENT_RTTI_EDIT_CLASS(L"traktor.shape.BakeConfiguration", 33, BakeConfiguration, ISerializable)
21+
T_IMPLEMENT_RTTI_EDIT_CLASS(L"traktor.shape.BakeConfiguration", 33, BakeConfiguration, scene::ISceneOperationData)
2222

2323
uint32_t BakeConfiguration::calculateModelRelevanteHash() const
2424
{

0 commit comments

Comments
 (0)