8884227fe6
This translates all usages of MCore::Array to AZStd::vector. It is designed to be as minimal of a change as possible (no changing to range-for loops or other C++11 stuff). We can decide to submit this wholesale, or submit it to a separate branch that we can then integrate individual files from once we're ready to do a specific class's transition. It does not completely solve the `uint32`->`size_t` transition. One important finding from doing this: `MCore::Array` uses a `memcpy` when it reallocates. `AZStd::vector` will use the contained type's copy or move constructor, per element. This is a significant change in behavior. If you have type, `SomeStruct` that defines a destructor, that type is copyable and not movable. So if you have a `MCore::Array<SomeStruct>`, and you call `Add(); Add(); Add()`, that reallocates 3 times, copying the contents using `memcpy`, and never invokes `SomeStruct`'s copy constructor or destructor. Translating that to `AZStd::vector<SomeStruct>` and calling `push_back(); push_back(); push_back();` will still reallocate 3 times, but it sees that `SomeStruct` is non-movable, and uses the copy constructor to make the copies, and then the destructor on the previous values. This call to the destructor wasn't there before, and can cause things to be deleted that weren't before. The solution to this is to make that struct be a move-only type. Where possible, this was done by changing that type to use `AZStd::unique_ptr` instead of a raw pointer, to get the proper move behavior. Where that is not possible (types that inherit from `MCore::MemoryObject`), a hand-written move constructor was created. In general: GetLength() becomes size() GetMaxLength() becomes capacity() GetIsEmpty() becomes empty() Reserve() becomes reserve() ReserveExact() becomes reserve() Resize() becomes resize() ResizeFast() becomes resize_no_construct() Add() becomes emplace_back() AddExact() becomes emplace_back() AddEmpty() becomes emplace_back() AddEmptyExact() becomes emplace_back() GetPtr() becomes data() GetItem() becomes at() Shrink() becomes shrink_to_fit() GetFirst() becomes front() GetLast() becomes back() Remove() becomes erase() RemoveFirst() becomes erase() RemoveLast() becomes pop_back() RemoveByValue() becomes if (const auto it = AZStd::find(...); it != end(container)) container.erase(it); Insert() becomes emplace() Swap() becomes swap() Clear(true) becomes clear(); shrink_to_fit() Clear() becomes clear(); shrink_to_fit() Clear(false) becomes clear() Swap() becomes swap() Find() becomes AZStd::find MoveElements() becomes AZStd::move SetMemoryCategory() is removed Signed-off-by: Chris Burel <burelc@amazon.com>
196 lines
6.5 KiB
C++
196 lines
6.5 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
#include <Editor/PropertyWidgets/ActorGoalNodeHandler.h>
|
|
#include <Editor/ActorEditorBus.h>
|
|
#include <EMotionFX/Source/Attachment.h>
|
|
#include <EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/EMStudioManager.h>
|
|
#include <EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/NodeSelectionWindow.h>
|
|
#include <Editor/AnimGraphEditorBus.h>
|
|
#include <QHBoxLayout>
|
|
#include <QMessageBox>
|
|
|
|
|
|
namespace EMotionFX
|
|
{
|
|
AZ_CLASS_ALLOCATOR_IMPL(ActorGoalNodePicker, EditorAllocator, 0)
|
|
AZ_CLASS_ALLOCATOR_IMPL(ActorGoalNodeHandler, EditorAllocator, 0)
|
|
|
|
ActorGoalNodePicker::ActorGoalNodePicker(QWidget* parent)
|
|
: QWidget(parent)
|
|
{
|
|
QHBoxLayout* hLayout = new QHBoxLayout();
|
|
hLayout->setMargin(0);
|
|
|
|
m_pickButton = new QPushButton(this);
|
|
connect(m_pickButton, &QPushButton::clicked, this, &ActorGoalNodePicker::OnPickClicked);
|
|
hLayout->addWidget(m_pickButton);
|
|
|
|
m_resetButton = new QPushButton(this);
|
|
EMStudio::EMStudioManager::MakeTransparentButton(m_resetButton, "Images/Icons/Clear.svg", "Reset selection");
|
|
connect(m_resetButton, &QPushButton::clicked, this, &ActorGoalNodePicker::OnResetClicked);
|
|
hLayout->addWidget(m_resetButton);
|
|
|
|
setLayout(hLayout);
|
|
}
|
|
|
|
|
|
void ActorGoalNodePicker::OnResetClicked()
|
|
{
|
|
if (m_goalNode.first.empty() && m_goalNode.second == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
SetGoalNode(AZStd::make_pair(AZStd::string(), 0));
|
|
emit SelectionChanged();
|
|
}
|
|
|
|
|
|
void ActorGoalNodePicker::UpdateInterface()
|
|
{
|
|
if (m_goalNode.first.empty())
|
|
{
|
|
m_pickButton->setText("Select node");
|
|
m_resetButton->setVisible(false);
|
|
}
|
|
else
|
|
{
|
|
m_pickButton->setText(m_goalNode.first.c_str());
|
|
m_resetButton->setVisible(true);
|
|
}
|
|
}
|
|
|
|
|
|
void ActorGoalNodePicker::SetGoalNode(const AZStd::pair<AZStd::string, int>& goalNode)
|
|
{
|
|
m_goalNode = goalNode;
|
|
UpdateInterface();
|
|
}
|
|
|
|
|
|
AZStd::pair<AZStd::string, int> ActorGoalNodePicker::GetGoalNode() const
|
|
{
|
|
return m_goalNode;
|
|
}
|
|
|
|
|
|
void ActorGoalNodePicker::OnPickClicked()
|
|
{
|
|
EMotionFX::ActorInstance* actorInstance = nullptr;
|
|
ActorEditorRequestBus::BroadcastResult(actorInstance, &ActorEditorRequests::GetSelectedActorInstance);
|
|
if (!actorInstance)
|
|
{
|
|
QMessageBox::warning(this, "No Actor Instance", "Cannot open node selection window. No valid actor instance selected.");
|
|
return;
|
|
}
|
|
EMotionFX::Actor* actor = actorInstance->GetActor();
|
|
|
|
// Create and show the node picker window
|
|
EMStudio::NodeSelectionWindow nodeSelectionWindow(this, true);
|
|
nodeSelectionWindow.GetNodeHierarchyWidget()->SetSelectionMode(true);
|
|
|
|
CommandSystem::SelectionList prevSelection;
|
|
EMotionFX::Node* node = actor->GetSkeleton()->FindNodeByName(m_goalNode.first.c_str());
|
|
if (node)
|
|
{
|
|
prevSelection.AddNode(node);
|
|
}
|
|
|
|
|
|
AZStd::vector<uint32> actorInstanceIDs;
|
|
|
|
// Add the current actor instance and all the ones it is attached to
|
|
EMotionFX::ActorInstance* currentInstance = actorInstance;
|
|
while (currentInstance)
|
|
{
|
|
actorInstanceIDs.emplace_back(currentInstance->GetID());
|
|
EMotionFX::Attachment* attachment = currentInstance->GetSelfAttachment();
|
|
if (attachment)
|
|
{
|
|
currentInstance = attachment->GetAttachToActorInstance();
|
|
}
|
|
else
|
|
{
|
|
currentInstance = nullptr;
|
|
}
|
|
}
|
|
|
|
|
|
nodeSelectionWindow.Update(actorInstanceIDs, &prevSelection);
|
|
nodeSelectionWindow.setModal(true);
|
|
|
|
if (nodeSelectionWindow.exec() != QDialog::Rejected)
|
|
{
|
|
AZStd::vector<SelectionItem>& newSelection = nodeSelectionWindow.GetNodeHierarchyWidget()->GetSelectedItems();
|
|
if (newSelection.size() == 1)
|
|
{
|
|
AZStd::string selectedNodeName = newSelection[0].GetNodeName();
|
|
AZ::u32 selectedActorInstanceId = newSelection[0].mActorInstanceID;
|
|
|
|
const auto parentDepth = AZStd::find(begin(actorInstanceIDs), end(actorInstanceIDs), selectedActorInstanceId);
|
|
AZ_Assert(parentDepth != end(actorInstanceIDs), "Cannot get parent depth. The selected actor instance was not shown in the selection window.");
|
|
|
|
m_goalNode = {AZStd::move(selectedNodeName), static_cast<int>(AZStd::distance(begin(actorInstanceIDs), parentDepth))};
|
|
|
|
UpdateInterface();
|
|
emit SelectionChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
AZ::u32 ActorGoalNodeHandler::GetHandlerName() const
|
|
{
|
|
return AZ_CRC("ActorGoalNode", 0xaf1e8a3a);
|
|
}
|
|
|
|
|
|
QWidget* ActorGoalNodeHandler::CreateGUI(QWidget* parent)
|
|
{
|
|
ActorGoalNodePicker* picker = aznew ActorGoalNodePicker(parent);
|
|
|
|
connect(picker, &ActorGoalNodePicker::SelectionChanged, this, [picker]()
|
|
{
|
|
EBUS_EVENT(AzToolsFramework::PropertyEditorGUIMessages::Bus, RequestWrite, picker);
|
|
});
|
|
|
|
return picker;
|
|
}
|
|
|
|
|
|
void ActorGoalNodeHandler::ConsumeAttribute(ActorGoalNodePicker* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, [[maybe_unused]] const char* debugName)
|
|
{
|
|
if (attrib == AZ::Edit::Attributes::ReadOnly)
|
|
{
|
|
bool value;
|
|
if (attrValue->Read<bool>(value))
|
|
{
|
|
GUI->setEnabled(!value);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void ActorGoalNodeHandler::WriteGUIValuesIntoProperty([[maybe_unused]] size_t index, ActorGoalNodePicker* GUI, property_t& instance, [[maybe_unused]] AzToolsFramework::InstanceDataNode* node)
|
|
{
|
|
instance = GUI->GetGoalNode();
|
|
}
|
|
|
|
|
|
bool ActorGoalNodeHandler::ReadValuesIntoGUI([[maybe_unused]] size_t index, ActorGoalNodePicker* GUI, const property_t& instance, [[maybe_unused]] AzToolsFramework::InstanceDataNode* node)
|
|
{
|
|
QSignalBlocker signalBlocker(GUI);
|
|
GUI->SetGoalNode(instance);
|
|
return true;
|
|
}
|
|
} // namespace EMotionFX
|
|
|
|
#include <Source/Editor/PropertyWidgets/moc_ActorGoalNodeHandler.cpp>
|