7#include <Utility/traits.h>
8#include <Common/assertion.h>
9#include <Common/exceptions.h>
10#include <Common/logging.h>
11#include <SDL/sdl_helpers.h>
22template<
typename ObjectType>
27 static_assert(CDerived<ObjectType, DesignerObject>,
28 "Object must be a designer object.");
35 obj->getScene().deleteObject(obj);
43 return "untitled scene";
46template<
typename ObjectType>
48 const bool shouldInit,
49 const bool shouldSetToDefault)
52 ObjectType::getSdlClass(),
57 return static_cast<ObjectType*
>(obj);
60template<
typename ObjectType>
62 const bool shouldInit,
63 const bool shouldSetToDefault)
66 ObjectType::getSdlClass(),
71 return static_cast<ObjectType*
>(obj);
74template<
typename ObjectType>
76 const bool shouldInit,
77 const bool shouldSetToDefault)
80 ObjectType::getSdlClass(),
84 return std::static_pointer_cast<ObjectType>(std::move(rootObj));
87template<
typename ObjectType,
typename... DeducedArgs>
88inline ObjectType* DesignerScene::makeObjectFromStorage(DeducedArgs&&... args)
90 static_assert(CDerived<ObjectType, DesignerObject>,
91 "Object must be a designer object.");
99 "Cannot create object when paused--this may modify object storage.");
103 auto storageIndex =
static_cast<uint64
>(-1);
106 if(m_freeObjStorageIndices.empty())
108 m_objStorage.add<ObjectType>(
nullptr);
109 storageIndex = m_objStorage.size() - 1;
114 storageIndex = m_freeObjStorageIndices.back();
115 m_freeObjStorageIndices.pop_back();
118 auto uniqueObj = std::make_unique<ObjectType>(std::forward<DeducedArgs>(args)...);
119 ObjectType* obj = uniqueObj.get();
120 m_objStorage.getUniquePtr(storageIndex) = std::move(uniqueObj);
122 PH_ASSERT(obj !=
nullptr);
123 obj->setSceneStorageIndex(storageIndex);
127template<
typename ObjectType>
130 static_assert(CDerived<ObjectType, DesignerObject>,
131 "Object must be a designer object.");
133 const SdlClass*
const clazz = ObjectType::getSdlClass();
134 if(classToObjMaker.find(clazz) != classToObjMaker.end())
137 "designer object already registered ({})",
138 sdl::gen_pretty_name(clazz));
143 classToObjMaker[clazz] =
146 if constexpr(std::is_abstract_v<ObjectType>)
149 "Attempting to create object of an abstract type.");
154 return scene.makeObjectFromStorage<ObjectType>();
159inline bool DesignerScene::removeObjectFromStorage(
DesignerObject*
const obj)
165 "Cannot remove object when paused--this may modify object storage.");
170 if(!obj || &(obj->
getScene()) !=
this || obj->getSceneStorageIndex() ==
static_cast<uint64
>(-1))
175 const auto objIndex = obj->getSceneStorageIndex();
176 PH_ASSERT(obj == m_objStorage[objIndex]);
177 m_objStorage.getUniquePtr(objIndex) =
nullptr;
178 m_freeObjStorageIndices.push_back(objIndex);
198 const bool hasParent = obj.
getParent() !=
nullptr;
200 return isChild && !hasParent;
218 PH_ASSERT_MSG(m_rendererScene,
219 "Please make sure you are calling from render command generating methods.");
221 return *m_rendererScene;
227 PH_ASSERT_MSG(m_rendererScene,
228 "Please make sure you are calling from render command generating methods.");
230 return *m_rendererScene;
235 return m_selectedObjs.empty() ? nullptr : m_selectedObjs.front();
240 return m_selectedObjs;
243inline bool DesignerScene::SceneAction::isDone()
const
245 return !updateTask && !renderTask;
250 return m_workingDirectory;
255 return m_rendererBindings;
265 return m_renderDescription;
270 return m_renderDescription;
275 return m_renderDescriptionLink;
280 m_renderDescriptionLink = std::move(link);
293template<
typename ObjectType>
296 ObjectType* result =
nullptr;
302 if constexpr(CDerived<DesignerObject, ObjectType>)
313 static_assert(CDerived<ObjectType, DesignerObject>,
314 "Object must be a designer object.");
321 result =
dynamic_cast<ObjectType*
>(obj);
332template<
typename ObjectType>
335 out_objs.reserve(out_objs.size() + m_objStorage.size());
341 if constexpr(CDerived<DesignerObject, ObjectType>)
343 out_objs.push_back(obj);
348 static_assert(CDerived<ObjectType, DesignerObject>,
349 "Object must be a designer object.");
351 auto const derivedObj =
dynamic_cast<ObjectType*
>(obj);
354 out_objs.push_back(derivedObj);
363template<
typename PerObjectOperation>
366 static_assert(std::is_invocable_r_v<bool, PerObjectOperation, DesignerObject*>);
370 for(
auto& objRes : m_objStorage)
392 const bool shouldContinue = op(obj);
402 return m_rootObjs.size();
407 return m_tickingObjs.size();
412 return m_renderTickingObjs.size();
417 return m_objStorage.size();
const TEnumFlags< EObjectState > & getState() const
Definition AbstractDesignerObject.ipp:10
Definition DesignerObject.h:31
DesignerScene & getScene()
Definition DesignerObject.cpp:287
DesignerObject * getParent()
Definition DesignerObject.cpp:309
const std::string & getName() const
Definition DesignerObject.ipp:66
Definition DesignerScene.h:58
void findObjectsByType(std::vector< ObjectType * > &out_objs) const
Find usable objects of a matching type.
Definition DesignerScene.ipp:333
Editor & getEditor()
Definition DesignerScene.ipp:203
static bool isInitialized(const DesignerObject &obj)
Definition DesignerScene.ipp:189
static void registerObjectType()
Definition DesignerScene.ipp:128
void setRenderDescriptionLink(ResourceIdentifier link)
Definition DesignerScene.ipp:278
const ResourceIdentifier & getRenderDescriptionLink() const
Definition DesignerScene.ipp:273
DesignerObject * getPrimarySelectedObject() const
Definition DesignerScene.ipp:233
std::size_t numRenderTickingObjects() const
Definition DesignerScene.ipp:410
ObjectType * newObject(bool shouldInit=true, bool shouldSetToDefault=true)
Create a new object.
Definition DesignerScene.ipp:47
TSpanView< DesignerRendererBinding > getRendererBindings() const
Definition DesignerScene.ipp:253
ObjectType * findObjectByName(std::string_view name) const
Find a usable object with the specified name.
Definition DesignerScene.ipp:294
render::Scene & getRendererScene()
Definition DesignerScene.ipp:215
const Path & getWorkingDirectory() const
Definition DesignerScene.ipp:248
static const char * defaultSceneName()
Definition DesignerScene.ipp:41
std::size_t numAllocatedObjects() const
Definition DesignerScene.ipp:415
std::shared_ptr< ObjectType > newSharedRootObject(bool shouldInit=true, bool shouldSetToDefault=true)
Create root object with automatic lifetime management. The root object will delete itself once the sh...
Definition DesignerScene.ipp:75
TSpanView< DesignerObject * > getSelection() const
Definition DesignerScene.ipp:238
bool isPaused() const
Whether the scene is pausing. When the scene is pausing, object and scene states should not be modifi...
Definition DesignerScene.ipp:288
std::size_t numTickingObjects() const
Definition DesignerScene.ipp:405
static bool isFullyInitialized(const DesignerObject &obj)
Definition DesignerScene.ipp:183
TSpanView< DesignerObject * > getRootObjects() const
Definition DesignerScene.ipp:283
void forEachUsableObject(PerObjectOperation op) const
Definition DesignerScene.ipp:364
std::size_t numRootObjects() const
Definition DesignerScene.ipp:400
ObjectType * newRootObject(bool shouldInit=true, bool shouldSetToDefault=true)
Create a new root object.
Definition DesignerScene.ipp:61
SceneDescription & getRenderDescription()
Definition DesignerScene.ipp:263
const std::string & getName() const
Definition DesignerScene.ipp:258
static bool isOnMainThread()
Whether current thread is the thread that called main().
Definition Threads.h:47
A scene for the editor renderer only.
Definition Scene.h:34
Definition ph_editor.h:10
Definition DesignerScene.ipp:24
void operator()(ObjectType *const obj) const
Definition DesignerScene.ipp:25