Merge pull request #5174 from aws-lumberyard-dev/Prefab/RevertImmediatePropagation

Prefab/revert immediate propagation
monroegm-disable-blank-issue-2
Mike Balfour 4 years ago committed by GitHub
commit d106c9aba5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -46,11 +46,10 @@ namespace AzToolsFramework
//! Updates the template links (updating instances) for the given template and triggers propagation on its instances. //! Updates the template links (updating instances) for the given template and triggers propagation on its instances.
//! @param providedPatch The patch to apply to the template. //! @param providedPatch The patch to apply to the template.
//! @param templateId The id of the template to update. //! @param templateId The id of the template to update.
//! @param immediate An optional flag whether to apply the patch immediately (needed for Undo/Redos) or wait until next system tick.
//! @param instanceToExclude An optional reference to an instance of the template being updated that should not be refreshes as part of propagation. //! @param instanceToExclude An optional reference to an instance of the template being updated that should not be refreshes as part of propagation.
//! Defaults to nullopt, which means that all instances will be refreshed. //! Defaults to nullopt, which means that all instances will be refreshed.
//! @return True if the template was patched correctly, false if the operation failed. //! @return True if the template was patched correctly, false if the operation failed.
virtual bool PatchTemplate(PrefabDomValue& providedPatch, TemplateId templateId, bool immediate = false, InstanceOptionalReference instanceToExclude = AZStd::nullopt) = 0; virtual bool PatchTemplate(PrefabDomValue& providedPatch, TemplateId templateId, InstanceOptionalReference instanceToExclude = AZStd::nullopt) = 0;
virtual void ApplyPatchesToInstance(const AZ::EntityId& entityId, PrefabDom& patches, const Instance& instanceToAddPatches) = 0; virtual void ApplyPatchesToInstance(const AZ::EntityId& entityId, PrefabDom& patches, const Instance& instanceToAddPatches) = 0;

@ -156,7 +156,7 @@ namespace AzToolsFramework
} }
} }
bool InstanceToTemplatePropagator::PatchTemplate(PrefabDomValue& providedPatch, TemplateId templateId, bool immediate, InstanceOptionalReference instanceToExclude) bool InstanceToTemplatePropagator::PatchTemplate(PrefabDomValue& providedPatch, TemplateId templateId, InstanceOptionalReference instanceToExclude)
{ {
PrefabDom& templateDomReference = m_prefabSystemComponentInterface->FindTemplateDom(templateId); PrefabDom& templateDomReference = m_prefabSystemComponentInterface->FindTemplateDom(templateId);
@ -178,7 +178,7 @@ namespace AzToolsFramework
(result.GetOutcome() != AZ::JsonSerializationResult::Outcomes::PartialSkip), (result.GetOutcome() != AZ::JsonSerializationResult::Outcomes::PartialSkip),
"Some of the patches were not successfully applied."); "Some of the patches were not successfully applied.");
m_prefabSystemComponentInterface->SetTemplateDirtyFlag(templateId, true); m_prefabSystemComponentInterface->SetTemplateDirtyFlag(templateId, true);
m_prefabSystemComponentInterface->PropagateTemplateChanges(templateId, immediate, instanceToExclude); m_prefabSystemComponentInterface->PropagateTemplateChanges(templateId, instanceToExclude);
return true; return true;
} }
} }

@ -33,7 +33,7 @@ namespace AzToolsFramework
InstanceOptionalReference GetTopMostInstanceInHierarchy(AZ::EntityId entityId) override; InstanceOptionalReference GetTopMostInstanceInHierarchy(AZ::EntityId entityId) override;
bool PatchTemplate(PrefabDomValue& providedPatch, TemplateId templateId, bool immediate = false, InstanceOptionalReference instanceToExclude = AZStd::nullopt) override; bool PatchTemplate(PrefabDomValue& providedPatch, TemplateId templateId, InstanceOptionalReference instanceToExclude = AZStd::nullopt) override;
void ApplyPatchesToInstance(const AZ::EntityId& entityId, PrefabDom& patches, const Instance& instanceToAddPatches) override; void ApplyPatchesToInstance(const AZ::EntityId& entityId, PrefabDom& patches, const Instance& instanceToAddPatches) override;

@ -52,7 +52,7 @@ namespace AzToolsFramework
AZ::Interface<InstanceUpdateExecutorInterface>::Unregister(this); AZ::Interface<InstanceUpdateExecutorInterface>::Unregister(this);
} }
void InstanceUpdateExecutor::AddTemplateInstancesToQueue(TemplateId instanceTemplateId, bool immediate, InstanceOptionalReference instanceToExclude) void InstanceUpdateExecutor::AddTemplateInstancesToQueue(TemplateId instanceTemplateId, InstanceOptionalReference instanceToExclude)
{ {
auto findInstancesResult = auto findInstancesResult =
m_templateInstanceMapperInterface->FindInstancesOwnedByTemplate(instanceTemplateId); m_templateInstanceMapperInterface->FindInstancesOwnedByTemplate(instanceTemplateId);
@ -79,11 +79,6 @@ namespace AzToolsFramework
m_instancesUpdateQueue.emplace_back(instance); m_instancesUpdateQueue.emplace_back(instance);
} }
} }
if (immediate)
{
UpdateTemplateInstancesInQueue();
}
} }
void InstanceUpdateExecutor::RemoveTemplateInstanceFromQueue(const Instance* instance) void InstanceUpdateExecutor::RemoveTemplateInstanceFromQueue(const Instance* instance)

@ -31,7 +31,7 @@ namespace AzToolsFramework
explicit InstanceUpdateExecutor(int instanceCountToUpdateInBatch = 0); explicit InstanceUpdateExecutor(int instanceCountToUpdateInBatch = 0);
void AddTemplateInstancesToQueue(TemplateId instanceTemplateId, bool immediate = false, InstanceOptionalReference instanceToExclude = AZStd::nullopt) override; void AddTemplateInstancesToQueue(TemplateId instanceTemplateId, InstanceOptionalReference instanceToExclude = AZStd::nullopt) override;
bool UpdateTemplateInstancesInQueue() override; bool UpdateTemplateInstancesInQueue() override;
virtual void RemoveTemplateInstanceFromQueue(const Instance* instance) override; virtual void RemoveTemplateInstanceFromQueue(const Instance* instance) override;

@ -23,7 +23,7 @@ namespace AzToolsFramework
virtual ~InstanceUpdateExecutorInterface() = default; virtual ~InstanceUpdateExecutorInterface() = default;
// Add all Instances of Template with given Id into a queue for updating them later. // Add all Instances of Template with given Id into a queue for updating them later.
virtual void AddTemplateInstancesToQueue(TemplateId instanceTemplateId, bool immediate = false, InstanceOptionalReference instanceToExclude = AZStd::nullopt) = 0; virtual void AddTemplateInstancesToQueue(TemplateId instanceTemplateId, InstanceOptionalReference instanceToExclude = AZStd::nullopt) = 0;
// Update Instances in the waiting queue. // Update Instances in the waiting queue.
virtual bool UpdateTemplateInstancesInQueue() = 0; virtual bool UpdateTemplateInstancesInQueue() = 0;

@ -1051,7 +1051,7 @@ namespace AzToolsFramework
DuplicateNestedEntitiesInInstance(commonOwningInstance->get(), DuplicateNestedEntitiesInInstance(commonOwningInstance->get(),
entities, instanceDomAfter, duplicatedEntityAndInstanceIds, duplicateEntityAliasMap); entities, instanceDomAfter, duplicatedEntityAndInstanceIds, duplicateEntityAliasMap);
PrefabUndoInstance* command = aznew PrefabUndoInstance("Entity/Instance duplication", false); PrefabUndoInstance* command = aznew PrefabUndoInstance("Entity/Instance duplication");
command->SetParent(undoBatch.GetUndoBatch()); command->SetParent(undoBatch.GetUndoBatch());
command->Capture(instanceDomBefore, instanceDomAfter, commonOwningInstance->get().GetTemplateId()); command->Capture(instanceDomBefore, instanceDomAfter, commonOwningInstance->get().GetTemplateId());
command->Redo(); command->Redo();
@ -1322,7 +1322,7 @@ namespace AzToolsFramework
Prefab::PrefabDom instanceDomAfter; Prefab::PrefabDom instanceDomAfter;
m_instanceToTemplateInterface->GenerateDomForInstance(instanceDomAfter, parentInstance); m_instanceToTemplateInterface->GenerateDomForInstance(instanceDomAfter, parentInstance);
PrefabUndoInstance* command = aznew PrefabUndoInstance("Instance detachment", false); PrefabUndoInstance* command = aznew PrefabUndoInstance("Instance detachment");
command->Capture(instanceDomBefore, instanceDomAfter, parentTemplateId); command->Capture(instanceDomBefore, instanceDomAfter, parentTemplateId);
command->SetParent(undoBatch.GetUndoBatch()); command->SetParent(undoBatch.GetUndoBatch());
{ {

@ -160,9 +160,9 @@ namespace AzToolsFramework
} }
} }
void PrefabSystemComponent::PropagateTemplateChanges(TemplateId templateId, bool immediate, InstanceOptionalReference instanceToExclude) void PrefabSystemComponent::PropagateTemplateChanges(TemplateId templateId, InstanceOptionalReference instanceToExclude)
{ {
UpdatePrefabInstances(templateId, immediate, instanceToExclude); UpdatePrefabInstances(templateId, instanceToExclude);
auto templateIdToLinkIdsIterator = m_templateToLinkIdsMap.find(templateId); auto templateIdToLinkIdsIterator = m_templateToLinkIdsMap.find(templateId);
if (templateIdToLinkIdsIterator != m_templateToLinkIdsMap.end()) if (templateIdToLinkIdsIterator != m_templateToLinkIdsMap.end())
@ -191,9 +191,9 @@ namespace AzToolsFramework
} }
} }
void PrefabSystemComponent::UpdatePrefabInstances(TemplateId templateId, bool immediate, InstanceOptionalReference instanceToExclude) void PrefabSystemComponent::UpdatePrefabInstances(TemplateId templateId, InstanceOptionalReference instanceToExclude)
{ {
m_instanceUpdateExecutor.AddTemplateInstancesToQueue(templateId, immediate, instanceToExclude); m_instanceUpdateExecutor.AddTemplateInstancesToQueue(templateId, instanceToExclude);
} }
void PrefabSystemComponent::UpdateLinkedInstances(AZStd::queue<LinkIds>& linkIdsQueue) void PrefabSystemComponent::UpdateLinkedInstances(AZStd::queue<LinkIds>& linkIdsQueue)

@ -231,17 +231,16 @@ namespace AzToolsFramework
*/ */
void UpdatePrefabTemplate(TemplateId templateId, const PrefabDom& updatedDom) override; void UpdatePrefabTemplate(TemplateId templateId, const PrefabDom& updatedDom) override;
void PropagateTemplateChanges(TemplateId templateId, bool immediate = false, InstanceOptionalReference instanceToExclude = AZStd::nullopt) override; void PropagateTemplateChanges(TemplateId templateId, InstanceOptionalReference instanceToExclude = AZStd::nullopt) override;
/** /**
* Updates all Instances owned by a Template. * Updates all Instances owned by a Template.
* *
* @param templateId The id of the Template owning Instances to update. * @param templateId The id of the Template owning Instances to update.
* @param immediate An optional flag whether to apply the patch immediately (needed for Undo/Redos) or wait until next system tick. * @param instanceToExclude An optional reference to an instance of the template being updated that should not be refreshed
* @param instanceToExclude An optional reference to an instance of the template being updated that should not be refreshes as part of propagation. * as part of propagation.Defaults to nullopt, which means that all instances will be refreshed.
* Defaults to nullopt, which means that all instances will be refreshed.
*/ */
void UpdatePrefabInstances(TemplateId templateId, bool immediate = false, InstanceOptionalReference instanceToExclude = AZStd::nullopt); void UpdatePrefabInstances(TemplateId templateId, InstanceOptionalReference instanceToExclude = AZStd::nullopt);
private: private:
AZ_DISABLE_COPY_MOVE(PrefabSystemComponent); AZ_DISABLE_COPY_MOVE(PrefabSystemComponent);

@ -67,7 +67,7 @@ namespace AzToolsFramework
virtual PrefabDom& FindTemplateDom(TemplateId templateId) = 0; virtual PrefabDom& FindTemplateDom(TemplateId templateId) = 0;
virtual void UpdatePrefabTemplate(TemplateId templateId, const PrefabDom& updatedDom) = 0; virtual void UpdatePrefabTemplate(TemplateId templateId, const PrefabDom& updatedDom) = 0;
virtual void PropagateTemplateChanges(TemplateId templateId, bool immediate = false, InstanceOptionalReference instanceToExclude = AZStd::nullopt) = 0; virtual void PropagateTemplateChanges(TemplateId templateId, InstanceOptionalReference instanceToExclude = AZStd::nullopt) = 0;
virtual AZStd::unique_ptr<Instance> InstantiatePrefab( virtual AZStd::unique_ptr<Instance> InstantiatePrefab(
AZ::IO::PathView filePath, InstanceOptionalReference parent = AZStd::nullopt) = 0; AZ::IO::PathView filePath, InstanceOptionalReference parent = AZStd::nullopt) = 0;

@ -17,16 +17,17 @@ namespace AzToolsFramework
{ {
PrefabUndoBase::PrefabUndoBase(const AZStd::string& undoOperationName) PrefabUndoBase::PrefabUndoBase(const AZStd::string& undoOperationName)
: UndoSystem::URSequencePoint(undoOperationName) : UndoSystem::URSequencePoint(undoOperationName)
, m_changed(true)
, m_templateId(InvalidTemplateId)
{ {
m_instanceToTemplateInterface = AZ::Interface<InstanceToTemplateInterface>::Get(); m_instanceToTemplateInterface = AZ::Interface<InstanceToTemplateInterface>::Get();
AZ_Assert(m_instanceToTemplateInterface, "Failed to grab instance to template interface"); AZ_Assert(m_instanceToTemplateInterface, "Failed to grab instance to template interface");
} }
//PrefabInstanceUndo //PrefabInstanceUndo
PrefabUndoInstance::PrefabUndoInstance(const AZStd::string& undoOperationName, bool useImmediatePropagation) PrefabUndoInstance::PrefabUndoInstance(const AZStd::string& undoOperationName)
: PrefabUndoBase(undoOperationName) : PrefabUndoBase(undoOperationName)
{ {
m_useImmediatePropagation = useImmediatePropagation;
} }
void PrefabUndoInstance::Capture( void PrefabUndoInstance::Capture(
@ -42,12 +43,12 @@ namespace AzToolsFramework
void PrefabUndoInstance::Undo() void PrefabUndoInstance::Undo()
{ {
m_instanceToTemplateInterface->PatchTemplate(m_undoPatch, m_templateId, m_useImmediatePropagation); m_instanceToTemplateInterface->PatchTemplate(m_undoPatch, m_templateId);
} }
void PrefabUndoInstance::Redo() void PrefabUndoInstance::Redo()
{ {
m_instanceToTemplateInterface->PatchTemplate(m_redoPatch, m_templateId, m_useImmediatePropagation); m_instanceToTemplateInterface->PatchTemplate(m_redoPatch, m_templateId);
} }
@ -90,7 +91,7 @@ namespace AzToolsFramework
void PrefabUndoEntityUpdate::Undo() void PrefabUndoEntityUpdate::Undo()
{ {
[[maybe_unused]] bool isPatchApplicationSuccessful = [[maybe_unused]] bool isPatchApplicationSuccessful =
m_instanceToTemplateInterface->PatchTemplate(m_undoPatch, m_templateId, true); m_instanceToTemplateInterface->PatchTemplate(m_undoPatch, m_templateId);
AZ_Error( AZ_Error(
"Prefab", isPatchApplicationSuccessful, "Prefab", isPatchApplicationSuccessful,
@ -101,7 +102,7 @@ namespace AzToolsFramework
void PrefabUndoEntityUpdate::Redo() void PrefabUndoEntityUpdate::Redo()
{ {
[[maybe_unused]] bool isPatchApplicationSuccessful = [[maybe_unused]] bool isPatchApplicationSuccessful =
m_instanceToTemplateInterface->PatchTemplate(m_redoPatch, m_templateId, true); m_instanceToTemplateInterface->PatchTemplate(m_redoPatch, m_templateId);
AZ_Error( AZ_Error(
"Prefab", isPatchApplicationSuccessful, "Prefab", isPatchApplicationSuccessful,
@ -112,7 +113,7 @@ namespace AzToolsFramework
void PrefabUndoEntityUpdate::Redo(InstanceOptionalReference instanceToExclude) void PrefabUndoEntityUpdate::Redo(InstanceOptionalReference instanceToExclude)
{ {
[[maybe_unused]] bool isPatchApplicationSuccessful = [[maybe_unused]] bool isPatchApplicationSuccessful =
m_instanceToTemplateInterface->PatchTemplate(m_redoPatch, m_templateId, false, instanceToExclude); m_instanceToTemplateInterface->PatchTemplate(m_redoPatch, m_templateId, instanceToExclude);
AZ_Error( AZ_Error(
"Prefab", isPatchApplicationSuccessful, "Prefab", isPatchApplicationSuccessful,
@ -328,7 +329,7 @@ namespace AzToolsFramework
//propagate the link changes //propagate the link changes
link->get().UpdateTarget(); link->get().UpdateTarget();
m_prefabSystemComponentInterface->PropagateTemplateChanges(link->get().GetTargetTemplateId(), false, instanceToExclude); m_prefabSystemComponentInterface->PropagateTemplateChanges(link->get().GetTargetTemplateId(), instanceToExclude);
//mark as dirty //mark as dirty
m_prefabSystemComponentInterface->SetTemplateDirtyFlag(link->get().GetTargetTemplateId(), true); m_prefabSystemComponentInterface->SetTemplateDirtyFlag(link->get().GetTargetTemplateId(), true);

@ -29,15 +29,14 @@ namespace AzToolsFramework
bool Changed() const override { return m_changed; } bool Changed() const override { return m_changed; }
protected: protected:
TemplateId m_templateId = InvalidTemplateId; TemplateId m_templateId;
PrefabDom m_redoPatch; PrefabDom m_redoPatch;
PrefabDom m_undoPatch; PrefabDom m_undoPatch;
InstanceToTemplateInterface* m_instanceToTemplateInterface = nullptr; InstanceToTemplateInterface* m_instanceToTemplateInterface = nullptr;
bool m_changed = true; bool m_changed;
bool m_useImmediatePropagation = true;
}; };
//! handles the addition and removal of entities from instances //! handles the addition and removal of entities from instances
@ -45,7 +44,7 @@ namespace AzToolsFramework
: public PrefabUndoBase : public PrefabUndoBase
{ {
public: public:
explicit PrefabUndoInstance(const AZStd::string& undoOperationName, bool useImmediatePropagation = true); explicit PrefabUndoInstance(const AZStd::string& undoOperationName);
void Capture( void Capture(
const PrefabDom& initialState, const PrefabDom& initialState,

@ -23,7 +23,7 @@ namespace AzToolsFramework
PrefabDom instanceDomAfterUpdate; PrefabDom instanceDomAfterUpdate;
PrefabDomUtils::StoreInstanceInPrefabDom(instance, instanceDomAfterUpdate); PrefabDomUtils::StoreInstanceInPrefabDom(instance, instanceDomAfterUpdate);
PrefabUndoInstance* state = aznew Prefab::PrefabUndoInstance(undoMessage, false); PrefabUndoInstance* state = aznew Prefab::PrefabUndoInstance(undoMessage);
state->Capture(instanceDomBeforeUpdate, instanceDomAfterUpdate, instance.GetTemplateId()); state->Capture(instanceDomBeforeUpdate, instanceDomAfterUpdate, instance.GetTemplateId());
state->SetParent(undoBatch); state->SetParent(undoBatch);
state->Redo(); state->Redo();

Loading…
Cancel
Save