Refactor prefab's objectsCache to be explicitly SceneObject values

This commit is contained in:
Wojtek Figat
2023-12-04 13:56:36 +01:00
parent f654d507e5
commit 3e940c28df
5 changed files with 8 additions and 8 deletions

View File

@@ -90,11 +90,11 @@ SceneObject* Prefab::GetDefaultInstance(const Guid& objectId)
if (objectId.IsValid()) if (objectId.IsValid())
{ {
const void* object; SceneObject* object;
if (ObjectsCache.TryGet(objectId, object)) if (ObjectsCache.TryGet(objectId, object))
{ {
// Actor or Script // Actor or Script
return (SceneObject*)object; return object;
} }
} }

View File

@@ -44,7 +44,7 @@ public:
/// <summary> /// <summary>
/// The objects cache maps the id of the object contained in the prefab asset (actor or script) to the default instance deserialized from prefab data. Valid only if asset is loaded and GetDefaultInstance was called. /// The objects cache maps the id of the object contained in the prefab asset (actor or script) to the default instance deserialized from prefab data. Valid only if asset is loaded and GetDefaultInstance was called.
/// </summary> /// </summary>
Dictionary<Guid, const void*> ObjectsCache; Dictionary<Guid, SceneObject*> ObjectsCache;
public: public:
/// <summary> /// <summary>

View File

@@ -76,12 +76,12 @@ Actor* PrefabManager::SpawnPrefab(Prefab* prefab, Actor* parent)
return SpawnPrefab(prefab, Transform(Vector3::Minimum), parent, nullptr); return SpawnPrefab(prefab, Transform(Vector3::Minimum), parent, nullptr);
} }
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, Actor* parent, Dictionary<Guid, const void*>* objectsCache, bool withSynchronization) Actor* PrefabManager::SpawnPrefab(Prefab* prefab, Actor* parent, Dictionary<Guid, SceneObject*>* objectsCache, bool withSynchronization)
{ {
return SpawnPrefab(prefab, Transform(Vector3::Minimum), parent, objectsCache, withSynchronization); return SpawnPrefab(prefab, Transform(Vector3::Minimum), parent, objectsCache, withSynchronization);
} }
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, const Transform& transform, Actor* parent, Dictionary<Guid, const void*>* objectsCache, bool withSynchronization) Actor* PrefabManager::SpawnPrefab(Prefab* prefab, const Transform& transform, Actor* parent, Dictionary<Guid, SceneObject*>* objectsCache, bool withSynchronization)
{ {
PROFILE_CPU_NAMED("Prefab.Spawn"); PROFILE_CPU_NAMED("Prefab.Spawn");
if (prefab == nullptr) if (prefab == nullptr)

View File

@@ -89,7 +89,7 @@ API_CLASS(Static) class FLAXENGINE_API PrefabManager
/// <param name="objectsCache">The options output objects cache that can be filled with prefab object id mapping to deserialized object (actor or script).</param> /// <param name="objectsCache">The options output objects cache that can be filled with prefab object id mapping to deserialized object (actor or script).</param>
/// <param name="withSynchronization">True if perform prefab changes synchronization for the spawned objects. It will check if need to add new objects due to nested prefab modifications.</param> /// <param name="withSynchronization">True if perform prefab changes synchronization for the spawned objects. It will check if need to add new objects due to nested prefab modifications.</param>
/// <returns>The created actor (root) or null if failed.</returns> /// <returns>The created actor (root) or null if failed.</returns>
static Actor* SpawnPrefab(Prefab* prefab, Actor* parent, Dictionary<Guid, const void*, HeapAllocation>* objectsCache, bool withSynchronization = false); static Actor* SpawnPrefab(Prefab* prefab, Actor* parent, Dictionary<Guid, SceneObject*, HeapAllocation>* objectsCache, bool withSynchronization = false);
/// <summary> /// <summary>
/// Spawns the instance of the prefab objects. If parent actor is specified then created actors are fully initialized (OnLoad event and BeginPlay is called if parent actor is already during gameplay). /// Spawns the instance of the prefab objects. If parent actor is specified then created actors are fully initialized (OnLoad event and BeginPlay is called if parent actor is already during gameplay).
@@ -100,7 +100,7 @@ API_CLASS(Static) class FLAXENGINE_API PrefabManager
/// <param name="objectsCache">The options output objects cache that can be filled with prefab object id mapping to deserialized object (actor or script).</param> /// <param name="objectsCache">The options output objects cache that can be filled with prefab object id mapping to deserialized object (actor or script).</param>
/// <param name="withSynchronization">True if perform prefab changes synchronization for the spawned objects. It will check if need to add new objects due to nested prefab modifications.</param> /// <param name="withSynchronization">True if perform prefab changes synchronization for the spawned objects. It will check if need to add new objects due to nested prefab modifications.</param>
/// <returns>The created actor (root) or null if failed.</returns> /// <returns>The created actor (root) or null if failed.</returns>
static Actor* SpawnPrefab(Prefab* prefab, const Transform& transform, Actor* parent, Dictionary<Guid, const void*, HeapAllocation>* objectsCache, bool withSynchronization = false); static Actor* SpawnPrefab(Prefab* prefab, const Transform& transform, Actor* parent, Dictionary<Guid, SceneObject*, HeapAllocation>* objectsCache, bool withSynchronization = false);
#if USE_EDITOR #if USE_EDITOR

View File

@@ -466,7 +466,7 @@ void JsonWriter::SceneObject(::SceneObject* obj)
prefab->GetDefaultInstance(); prefab->GetDefaultInstance();
// Get prefab object instance from the prefab // Get prefab object instance from the prefab
const void* prefabObject; ::SceneObject* prefabObject;
if (prefab->ObjectsCache.TryGet(obj->GetPrefabObjectID(), prefabObject)) if (prefab->ObjectsCache.TryGet(obj->GetPrefabObjectID(), prefabObject))
{ {
// Serialize modified properties compared with the default object from prefab // Serialize modified properties compared with the default object from prefab