Merge branch 'main' of https://github.com/aws-lumberyard/o3de into cgalvan/DuplicateEntities

This commit is contained in:
Chris Galvan
2021-05-21 10:54:44 -05:00
78 changed files with 3016 additions and 507 deletions
@@ -133,7 +133,15 @@ namespace AZ
if (!id.m_guid.IsNull())
{
*instance = AssetManager::Instance().FindOrCreateAsset(id, instance->GetType(), instance->GetAutoLoadBehavior());
if (!instance->GetId().IsValid())
{
// If the asset failed to be created, FindOrCreateAsset returns an asset instance with a null
// id. To preserve the asset id in the source json, reset the asset to an empty one, but with
// the right id.
const auto loadBehavior = instance->GetAutoLoadBehavior();
*instance = Asset<AssetData>(id, instance->GetType());
instance->SetAutoLoadBehavior(loadBehavior);
}
result.Combine(context.Report(result, "Successfully created Asset<T> with id."));
}
@@ -880,6 +880,13 @@ namespace AZ
const Specializations& specializations, const rapidjson::Pointer& historyPointer, AZStd::string_view folderPath)
{
using namespace rapidjson;
if (&lhs == &rhs)
{
// Early return to avoid setting the collisionFound reference to true
// std::sort is allowed to pass in the same memory address for the left and right elements
return false;
}
AZ_Assert(!lhs.m_tags.empty(), "Comparing a settings file without at least a name tag.");
AZ_Assert(!rhs.m_tags.empty(), "Comparing a settings file without at least a name tag.");
@@ -30,6 +30,16 @@ namespace AzPhysics
classElement.AddElementWithData(context, "name", name);
return true;
}
bool SimulatedBodyVersionConverter([[maybe_unused]] AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement)
{
if (classElement.GetVersion() <= 1)
{
classElement.RemoveElementByName(AZ_CRC_CE("scale"));
}
return true;
}
}
AZ_CLASS_ALLOCATOR_IMPL(SimulatedBodyConfiguration, AZ::SystemAllocator, 0);
@@ -40,11 +50,10 @@ namespace AzPhysics
{
serializeContext->ClassDeprecate("WorldBodyConfiguration", "{6EEB377C-DC60-4E10-AF12-9626C0763B2D}", &Internal::DeprecateWorldBodyConfiguration);
serializeContext->Class<SimulatedBodyConfiguration>()
->Version(1)
->Version(2, &Internal::SimulatedBodyVersionConverter)
->Field("name", &SimulatedBodyConfiguration::m_debugName)
->Field("position", &SimulatedBodyConfiguration::m_position)
->Field("orientation", &SimulatedBodyConfiguration::m_orientation)
->Field("scale", &SimulatedBodyConfiguration::m_scale)
->Field("entityId", &SimulatedBodyConfiguration::m_entityId)
->Field("startSimulationEnabled", &SimulatedBodyConfiguration::m_startSimulationEnabled)
;
@@ -38,7 +38,6 @@ namespace AzPhysics
// Basic initial settings.
AZ::Vector3 m_position = AZ::Vector3::CreateZero();
AZ::Quaternion m_orientation = AZ::Quaternion::CreateIdentity();
AZ::Vector3 m_scale = AZ::Vector3::CreateOne();
bool m_startSimulationEnabled = true;
// Entity/object association.
@@ -18,7 +18,6 @@
#include <AzCore/std/numeric.h>
#include <AzFramework/Input/Devices/Keyboard/InputDeviceKeyboard.h>
#include <AzFramework/Input/Devices/Mouse/InputDeviceMouse.h>
#include <AzFramework/Windowing/WindowBus.h>
namespace AzFramework
{
@@ -160,24 +159,27 @@ namespace AzFramework
bool CameraSystem::HandleEvents(const InputEvent& event)
{
if (const auto& cursor = AZStd::get_if<CursorEvent>(&event))
if (const auto& horizonalMotion = AZStd::get_if<HorizontalMotionEvent>(&event))
{
m_cursorState.SetCurrentPosition(cursor->m_position);
m_motionDelta.m_x = horizonalMotion->m_delta;
}
else if (const auto& verticalMotion = AZStd::get_if<VerticalMotionEvent>(&event))
{
m_motionDelta.m_y = verticalMotion->m_delta;
}
else if (const auto& scroll = AZStd::get_if<ScrollEvent>(&event))
{
m_scrollDelta = scroll->m_delta;
}
return m_cameras.HandleEvents(event, m_cursorState.CursorDelta(), m_scrollDelta);
return m_cameras.HandleEvents(event, m_motionDelta, m_scrollDelta);
}
Camera CameraSystem::StepCamera(const Camera& targetCamera, const float deltaTime)
{
const auto nextCamera = m_cameras.StepCamera(targetCamera, m_cursorState.CursorDelta(), m_scrollDelta, deltaTime);
m_cursorState.Update();
const auto nextCamera = m_cameras.StepCamera(targetCamera, m_motionDelta, m_scrollDelta, deltaTime);
m_motionDelta = ScreenVector{0, 0};
m_scrollDelta = 0.0f;
return nextCamera;
@@ -720,7 +722,7 @@ namespace AzFramework
return camera;
}
InputEvent BuildInputEvent(const InputChannel& inputChannel, const WindowSize& windowSize)
InputEvent BuildInputEvent(const InputChannel& inputChannel)
{
const auto& inputChannelId = inputChannel.GetInputChannelId();
const auto& inputDeviceId = inputChannel.GetInputDevice().GetInputDeviceId();
@@ -730,13 +732,13 @@ namespace AzFramework
return button == inputChannelId;
});
if (inputChannelId == InputDeviceMouse::Movement::X || inputChannelId == InputDeviceMouse::Movement::Y)
if (inputChannelId == InputDeviceMouse::Movement::X)
{
const auto* position = inputChannel.GetCustomData<AzFramework::InputChannel::PositionData2D>();
AZ_Assert(position, "Expected PositionData2D but found nullptr");
return CursorEvent{ScreenPoint(
position->m_normalizedPosition.GetX() * windowSize.m_width, position->m_normalizedPosition.GetY() * windowSize.m_height)};
return HorizontalMotionEvent{(int)inputChannel.GetValue()};
}
else if (inputChannelId == InputDeviceMouse::Movement::Y)
{
return VerticalMotionEvent{(int)inputChannel.GetValue()};
}
else if (inputChannelId == InputDeviceMouse::Movement::Z)
{
@@ -18,7 +18,6 @@
#include <AzCore/std/optional.h>
#include <AzFramework/Input/Channels/InputChannel.h>
#include <AzFramework/Viewport/ClickDetector.h>
#include <AzFramework/Viewport/CursorState.h>
#include <AzFramework/Viewport/ScreenGeometry.h>
#include <AzFramework/Viewport/ViewportId.h>
@@ -72,11 +71,16 @@ namespace AzFramework
void UpdateCameraFromTransform(Camera& camera, const AZ::Transform& transform);
struct CursorEvent
//! Generic motion type
template<typename MotionTag>
struct MotionEvent
{
ScreenPoint m_position;
int m_delta;
};
using HorizontalMotionEvent = MotionEvent<struct HorizontalMotionTag>;
using VerticalMotionEvent = MotionEvent<struct VerticalMotionTag>;
struct ScrollEvent
{
float m_delta;
@@ -88,7 +92,7 @@ namespace AzFramework
InputChannel::State m_state; //!< Channel state. (e.g. Begin/update/end event).
};
using InputEvent = AZStd::variant<AZStd::monostate, CursorEvent, ScrollEvent, DiscreteInputEvent>;
using InputEvent = AZStd::variant<AZStd::monostate, HorizontalMotionEvent, VerticalMotionEvent, ScrollEvent, DiscreteInputEvent>;
class CameraInput
{
@@ -194,6 +198,7 @@ namespace AzFramework
m_activeCameraInputs.begin(), m_activeCameraInputs.end(), [](const auto& cameraInput) { return cameraInput->Exclusive(); });
}
//! Responsible for updating a series of cameras given various inputs.
class CameraSystem
{
public:
@@ -203,8 +208,8 @@ namespace AzFramework
Cameras m_cameras;
private:
CursorState m_cursorState;
float m_scrollDelta = 0.0f;
ScreenVector m_motionDelta; //!< The delta used for look/orbit/pan (rotation + translation) - two dimensional.
float m_scrollDelta = 0.0f; //!< The delta used for dolly/movement (translation) - one dimensional.
};
class RotateCameraInput : public CameraInput
@@ -419,8 +424,6 @@ namespace AzFramework
return true;
}
struct WindowSize;
//! Map from a generic InputChannel event to a camera specific InputEvent.
InputEvent BuildInputEvent(const InputChannel& inputChannel, const WindowSize& windowSize);
InputEvent BuildInputEvent(const InputChannel& inputChannel);
} // namespace AzFramework
@@ -19,6 +19,8 @@
namespace AzNetworking
{
using NetworkInterfaces = AZStd::unordered_map<AZ::Name, AZStd::unique_ptr<INetworkInterface>>;
//! @class INetworking
//! @brief The interface for creating and working with network interfaces.
class INetworking
@@ -60,5 +62,25 @@ namespace AzNetworking
//! @param name The name of the Compressor factory to unregister, must match result of factory->GetFactoryName()
//! @return Whether the factory was found and unregistered
virtual bool UnregisterCompressorFactory(AZ::Name name) = 0;
//! Returns the raw network interfaces owned by the networking instance.
//! @return the raw network interfaces owned by the networking instance
virtual const NetworkInterfaces& GetNetworkInterfaces() const = 0;
//! Returns the number of sockets monitored by our TcpListenThread.
//! @return the number of sockets monitored by our TcpListenThread
virtual uint32_t GetTcpListenThreadSocketCount() const = 0;
//! Returns the total time spent updating our TcpListenThread.
//! @return the total time spent updating our TcpListenThread
virtual AZ::TimeMs GetTcpListenThreadUpdateTime() const = 0;
//! Returns the number of sockets monitored by our UdpReaderThread.
//! @return the number of sockets monitored by our UdpReaderThread
virtual uint32_t GetUdpReaderThreadSocketCount() const = 0;
//! Returns the total time spent updating our UdpReaderThread.
//! @return the total time spent updating our UdpReaderThread
virtual AZ::TimeMs GetUdpReaderThreadUpdateTime() const = 0;
};
}
@@ -149,12 +149,37 @@ namespace AzNetworking
return m_compressorFactories.erase(name) > 0;
}
const NetworkInterfaces& NetworkingSystemComponent::GetNetworkInterfaces() const
{
return m_networkInterfaces;
}
uint32_t NetworkingSystemComponent::GetTcpListenThreadSocketCount() const
{
return m_listenThread->GetSocketCount();
}
AZ::TimeMs NetworkingSystemComponent::GetTcpListenThreadUpdateTime() const
{
return m_listenThread->GetUpdateTimeMs();
}
uint32_t NetworkingSystemComponent::GetUdpReaderThreadSocketCount() const
{
return m_readerThread->GetSocketCount();
}
AZ::TimeMs NetworkingSystemComponent::GetUdpReaderThreadUpdateTime() const
{
return m_readerThread->GetUpdateTimeMs();
}
void NetworkingSystemComponent::DumpStats([[maybe_unused]] const AZ::ConsoleCommandContainer& arguments)
{
AZLOG_INFO("Total sockets monitored by TcpListenThread: %u", m_listenThread->GetSocketCount());
AZLOG_INFO("Total time spent updating TcpListenThread: %lld", aznumeric_cast<AZ::s64>(m_listenThread->GetUpdateTimeMs()));
AZLOG_INFO("Total sockets monitored by UdpReaderThread: %u", m_readerThread->GetSocketCount());
AZLOG_INFO("Total time spent updating UdpReaderThread: %lld", aznumeric_cast<AZ::s64>(m_readerThread->GetUpdateTimeMs()));
AZLOG_INFO("Total sockets monitored by TcpListenThread: %u", GetTcpListenThreadSocketCount());
AZLOG_INFO("Total time spent updating TcpListenThread: %lld", aznumeric_cast<AZ::s64>(GetTcpListenThreadUpdateTime()));
AZLOG_INFO("Total sockets monitored by UdpReaderThread: %u", GetUdpReaderThreadSocketCount());
AZLOG_INFO("Total time spent updating UdpReaderThread: %lld", aznumeric_cast<AZ::s64>(GetUdpReaderThreadUpdateTime()));
for (auto& networkInterface : m_networkInterfaces)
{
@@ -63,6 +63,11 @@ namespace AzNetworking
void RegisterCompressorFactory(ICompressorFactory* factory) override;
AZStd::unique_ptr<ICompressor> CreateCompressor(AZ::Name name) override;
bool UnregisterCompressorFactory(AZ::Name name) override;
const NetworkInterfaces& GetNetworkInterfaces() const override;
uint32_t GetTcpListenThreadSocketCount() const override;
AZ::TimeMs GetTcpListenThreadUpdateTime() const override;
uint32_t GetUdpReaderThreadSocketCount() const override;
AZ::TimeMs GetUdpReaderThreadUpdateTime() const override;
//! @}
//! Console commands.
@@ -74,7 +79,6 @@ namespace AzNetworking
AZ_CONSOLEFUNC(NetworkingSystemComponent, DumpStats, AZ::ConsoleFunctorFlags::Null, "Dumps stats for all instantiated network interfaces");
using NetworkInterfaces = AZStd::unordered_map<AZ::Name, AZStd::unique_ptr<INetworkInterface>>;
NetworkInterfaces m_networkInterfaces;
AZStd::unique_ptr<TcpListenThread> m_listenThread;
AZStd::unique_ptr<UdpReaderThread> m_readerThread;
@@ -46,6 +46,12 @@ namespace AzNetworking
void TcpSocketManager::ProcessEvents(AZ::TimeMs maxBlockMs, const SocketEventCallback& readCallback, const SocketEventCallback& writeCallback)
{
if(static_cast<int32_t>(m_maxFd) <= 0 && m_socketFds.empty())
{
// There are no available sockets to process
return;
}
m_readerFdSet = m_sourceFdSet;
m_writerFdSet = m_sourceFdSet;
@@ -93,28 +93,12 @@ namespace AzToolsFramework
EditorContextMenuBus::Handler::BusConnect();
PrefabInstanceContainerNotificationBus::Handler::BusConnect();
AZ::Interface<PrefabIntegrationInterface>::Register(this);
bool prefabWipFeaturesEnabled = false;
AzFramework::ApplicationRequests::Bus::BroadcastResult(
prefabWipFeaturesEnabled, &AzFramework::ApplicationRequests::ArePrefabWipFeaturesEnabled);
if (prefabWipFeaturesEnabled)
{
AssetBrowser::AssetBrowserSourceDropBus::Handler::BusConnect(s_prefabFileExtension);
}
AssetBrowser::AssetBrowserSourceDropBus::Handler::BusConnect(s_prefabFileExtension);
}
PrefabIntegrationManager::~PrefabIntegrationManager()
{
bool prefabWipFeaturesEnabled = false;
AzFramework::ApplicationRequests::Bus::BroadcastResult(
prefabWipFeaturesEnabled, &AzFramework::ApplicationRequests::ArePrefabWipFeaturesEnabled);
if (prefabWipFeaturesEnabled)
{
AssetBrowser::AssetBrowserSourceDropBus::Handler::BusDisconnect();
}
AssetBrowser::AssetBrowserSourceDropBus::Handler::BusDisconnect();
AZ::Interface<PrefabIntegrationInterface>::Unregister(this);
PrefabInstanceContainerNotificationBus::Handler::BusDisconnect();
EditorContextMenuBus::Handler::BusDisconnect();
@@ -137,66 +121,63 @@ namespace AzToolsFramework
void PrefabIntegrationManager::PopulateEditorGlobalContextMenu(QMenu* menu) const
{
bool prefabWipFeaturesEnabled = false;
AzFramework::ApplicationRequests::Bus::BroadcastResult(
prefabWipFeaturesEnabled, &AzFramework::ApplicationRequests::ArePrefabWipFeaturesEnabled);
AzToolsFramework::EntityIdList selectedEntities;
AzToolsFramework::ToolsApplicationRequestBus::BroadcastResult(
selectedEntities, &AzToolsFramework::ToolsApplicationRequests::GetSelectedEntities);
if (prefabWipFeaturesEnabled)
bool prefabWipFeaturesEnabled = false;
AzFramework::ApplicationRequests::Bus::BroadcastResult(
prefabWipFeaturesEnabled, &AzFramework::ApplicationRequests::ArePrefabWipFeaturesEnabled);
// Create Prefab
{
// Create Prefab
if (!selectedEntities.empty())
{
if (!selectedEntities.empty())
// Hide if the only selected entity is the Level Container
if (selectedEntities.size() > 1 || !s_prefabPublicInterface->IsLevelInstanceContainerEntity(selectedEntities[0]))
{
// Hide if the only selected entity is the Level Container
if (selectedEntities.size() > 1 || !s_prefabPublicInterface->IsLevelInstanceContainerEntity(selectedEntities[0]))
bool layerInSelection = false;
for (AZ::EntityId entityId : selectedEntities)
{
bool layerInSelection = false;
for (AZ::EntityId entityId : selectedEntities)
{
if (!layerInSelection)
{
AzToolsFramework::Layers::EditorLayerComponentRequestBus::EventResult(
layerInSelection, entityId,
&AzToolsFramework::Layers::EditorLayerComponentRequestBus::Events::HasLayer);
if (layerInSelection)
{
break;
}
}
}
// Layers can't be in prefabs.
if (!layerInSelection)
{
QAction* createAction = menu->addAction(QObject::tr("Create Prefab..."));
createAction->setToolTip(QObject::tr("Creates a prefab out of the currently selected entities."));
AzToolsFramework::Layers::EditorLayerComponentRequestBus::EventResult(
layerInSelection, entityId,
&AzToolsFramework::Layers::EditorLayerComponentRequestBus::Events::HasLayer);
QObject::connect(createAction, &QAction::triggered, createAction, [this, selectedEntities] {
ContextMenu_CreatePrefab(selectedEntities);
});
if (layerInSelection)
{
break;
}
}
}
// Layers can't be in prefabs.
if (!layerInSelection)
{
QAction* createAction = menu->addAction(QObject::tr("Create Prefab..."));
createAction->setToolTip(QObject::tr("Creates a prefab out of the currently selected entities."));
QObject::connect(createAction, &QAction::triggered, createAction, [this, selectedEntities] {
ContextMenu_CreatePrefab(selectedEntities);
});
}
}
}
// Instantiate Prefab
{
QAction* instantiateAction = menu->addAction(QObject::tr("Instantiate Prefab..."));
instantiateAction->setToolTip(QObject::tr("Instantiates a prefab file in the scene."));
QObject::connect(
instantiateAction, &QAction::triggered, instantiateAction, [this] { ContextMenu_InstantiatePrefab(); });
}
menu->addSeparator();
}
// Instantiate Prefab
{
QAction* instantiateAction = menu->addAction(QObject::tr("Instantiate Prefab..."));
instantiateAction->setToolTip(QObject::tr("Instantiates a prefab file in the scene."));
QObject::connect(
instantiateAction, &QAction::triggered, instantiateAction, [this] { ContextMenu_InstantiatePrefab(); });
}
menu->addSeparator();
bool itemWasShown = false;
// Edit/Save Prefab
+6 -9
View File
@@ -15,7 +15,6 @@
#include <AzFramework/Input/Devices/Keyboard/InputDeviceKeyboard.h>
#include <AzFramework/Input/Devices/Mouse/InputDeviceMouse.h>
#include <AzFramework/Viewport/CameraInput.h>
#include <AzFramework/Windowing/WindowBus.h>
namespace UnitTest
{
@@ -68,23 +67,21 @@ namespace UnitTest
TEST_F(CameraInputFixture, BeginEndOrbitCameraConsumesCorrectEvents)
{
// set initial mouse position
const bool consumed1 = HandleEventAndUpdate(AzFramework::CursorEvent{AzFramework::ScreenPoint(5, 5)});
// begin orbit camera
const bool consumed2 = HandleEventAndUpdate(
const bool consumed1 = HandleEventAndUpdate(
AzFramework::DiscreteInputEvent{AzFramework::InputDeviceKeyboard::Key::ModifierAltL, AzFramework::InputChannel::State::Began});
// begin listening for orbit rotate (click detector) - event is not consumed
const bool consumed3 = HandleEventAndUpdate(
const bool consumed2 = HandleEventAndUpdate(
AzFramework::DiscreteInputEvent{AzFramework::InputDeviceMouse::Button::Left, AzFramework::InputChannel::State::Began});
// begin orbit rotate (mouse has moved sufficient distance to initiate)
const bool consumed4 = HandleEventAndUpdate(AzFramework::CursorEvent{AzFramework::ScreenPoint(10, 10)});
const bool consumed3 = HandleEventAndUpdate(AzFramework::HorizontalMotionEvent{5});
// end orbit (mouse up) - event is not consumed
const bool consumed5 = HandleEventAndUpdate(
const bool consumed4 = HandleEventAndUpdate(
AzFramework::DiscreteInputEvent{AzFramework::InputDeviceMouse::Button::Left, AzFramework::InputChannel::State::Ended});
const auto allConsumed = AZStd::vector<bool>{consumed1, consumed2, consumed3, consumed4, consumed5};
const auto allConsumed = AZStd::vector<bool>{consumed1, consumed2, consumed3, consumed4};
using ::testing::ElementsAre;
EXPECT_THAT(allConsumed, ElementsAre(false, true, false, true, false));
EXPECT_THAT(allConsumed, ElementsAre(true, false, true, false));
}
} // namespace UnitTest