Merge branch 'main' into ly-as-sdk/LYN-2948

# Conflicts:
#	CMakeLists.txt
This commit is contained in:
pappeste
2021-05-10 14:36:20 -07:00
421 changed files with 13429 additions and 27863 deletions
@@ -14,6 +14,7 @@
#include <AzCore/Component/Entity.h>
#include <AzCore/Component/ComponentApplicationBus.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Interface/Interface.h>
#include <AzCore/Math/Sfmt.h>
#include <AzCore/Math/Crc.h>
@@ -173,7 +174,11 @@ namespace AZ
//=========================================================================
void ComponentDescriptor::ReleaseDescriptor()
{
EBUS_EVENT(ComponentApplicationBus, UnregisterComponentDescriptor, this);
AZ::ComponentApplicationRequests* componentApplication = AZ::Interface<AZ::ComponentApplicationRequests>::Get();
if (componentApplication != nullptr)
{
componentApplication->UnregisterComponentDescriptor(this);
}
delete this;
}
} // namespace AZ
@@ -526,6 +526,11 @@ namespace AZ
// are destroyed
m_commandLine = {};
m_entityAddedEvent.DisconnectAllHandlers();
m_entityRemovedEvent.DisconnectAllHandlers();
m_entityActivatedEvent.DisconnectAllHandlers();
m_entityDeactivatedEvent.DisconnectAllHandlers();
DestroyAllocator();
}
@@ -980,6 +985,26 @@ namespace AZ
handler.Connect(m_entityRemovedEvent);
}
void ComponentApplication::RegisterEntityActivatedEventHandler(EntityActivatedEvent::Handler& handler)
{
handler.Connect(m_entityActivatedEvent);
}
void ComponentApplication::RegisterEntityDeactivatedEventHandler(EntityDeactivatedEvent::Handler& handler)
{
handler.Connect(m_entityDeactivatedEvent);
}
void ComponentApplication::SignalEntityActivated(AZ::Entity* entity)
{
m_entityActivatedEvent.Signal(entity);
}
void ComponentApplication::SignalEntityDeactivated(AZ::Entity* entity)
{
m_entityDeactivatedEvent.Signal(entity);
}
//=========================================================================
// AddEntity
// [5/30/2012]
@@ -204,6 +204,10 @@ namespace AZ
void UnregisterComponentDescriptor(const ComponentDescriptor* descriptor) override final;
void RegisterEntityAddedEventHandler(EntityAddedEvent::Handler& handler) override final;
void RegisterEntityRemovedEventHandler(EntityRemovedEvent::Handler& handler) override final;
void RegisterEntityActivatedEventHandler(EntityActivatedEvent::Handler& handler) override final;
void RegisterEntityDeactivatedEventHandler(EntityDeactivatedEvent::Handler& handler) override final;
void SignalEntityActivated(Entity* entity) override final;
void SignalEntityDeactivated(Entity* entity) override final;
bool AddEntity(Entity* entity) override;
bool RemoveEntity(Entity* entity) override;
bool DeleteEntity(const EntityId& id) override;
@@ -382,6 +386,8 @@ namespace AZ
AZStd::unique_ptr<SettingsRegistryInterface> m_settingsRegistry;
EntityAddedEvent m_entityAddedEvent;
EntityRemovedEvent m_entityRemovedEvent;
EntityAddedEvent m_entityActivatedEvent;
EntityRemovedEvent m_entityDeactivatedEvent;
AZ::IConsole* m_console{};
Descriptor m_descriptor;
bool m_isStarted{ false };
@@ -72,6 +72,8 @@ namespace AZ
using EntityAddedEvent = AZ::Event<AZ::Entity*>;
using EntityRemovedEvent = AZ::Event<AZ::Entity*>;
using EntityActivatedEvent = AZ::Event<AZ::Entity*>;
using EntityDeactivatedEvent = AZ::Event<AZ::Entity*>;
//! Interface that components can use to make requests of the main application.
class ComponentApplicationRequests
@@ -102,6 +104,22 @@ namespace AZ
//! @param handler the event handler to signal.
virtual void RegisterEntityRemovedEventHandler(EntityRemovedEvent::Handler& handler) = 0;
//! Registers an event handler that will be signalled whenever an entity is added.
//! @param handler the event handler to signal.
virtual void RegisterEntityActivatedEventHandler(EntityActivatedEvent::Handler& handler) = 0;
//! Registers an event handler that will be signalled whenever an entity is removed.
//! @param handler the event handler to signal.
virtual void RegisterEntityDeactivatedEventHandler(EntityDeactivatedEvent::Handler& handler) = 0;
//! Signals that the provided entity has been activated.
//! @param entity the entity being activated.
virtual void SignalEntityActivated(AZ::Entity* entity) = 0;
//! Signals that the provided entity has been deactivated.
//! @param entity the entity being deactivated.
virtual void SignalEntityDeactivated(AZ::Entity* entity) = 0;
//! Adds an entity to the application's registry.
//! Calling Init() on an entity automatically performs this operation.
//! @param entity A pointer to the entity to add to the application's registry.
@@ -112,7 +112,11 @@ namespace AZ
{
EBUS_EVENT(EntitySystemBus, OnEntityDestruction, m_id);
EBUS_EVENT_ID(m_id, EntityBus, OnEntityDestruction, m_id);
EBUS_EVENT(ComponentApplicationBus, RemoveEntity, this);
AZ::ComponentApplicationRequests* componentApplication = AZ::Interface<AZ::ComponentApplicationRequests>::Get();
if (componentApplication != nullptr)
{
componentApplication->RemoveEntity(this);
}
m_stateEvent.Signal(State::Init, State::Destroying);
}
@@ -216,12 +220,22 @@ namespace AZ
EBUS_EVENT_ID(m_id, EntityBus, OnEntityActivated, m_id);
EBUS_EVENT(EntitySystemBus, OnEntityActivated, m_id);
AZ::ComponentApplicationRequests* componentApplication = AZ::Interface<AZ::ComponentApplicationRequests>::Get();
if (componentApplication != nullptr)
{
componentApplication->SignalEntityActivated(this);
}
}
void Entity::Deactivate()
{
AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::AzCore);
AZ::ComponentApplicationRequests* componentApplication = AZ::Interface<AZ::ComponentApplicationRequests>::Get();
if (componentApplication != nullptr)
{
componentApplication->SignalEntityDeactivated(this);
}
EBUS_EVENT_ID(m_id, EntityBus, OnEntityDeactivated, m_id);
EBUS_EVENT(EntitySystemBus, OnEntityDeactivated, m_id);
@@ -126,9 +126,11 @@ namespace AZ
char buffer[MaxLogBufferSize];
const AZStd::size_t length = azvsnprintf(buffer, MaxLogBufferSize, format, args);
buffer[AZStd::min<AZStd::size_t>(length, MaxLogBufferSize - 2)] = '\n';
buffer[AZStd::min<AZStd::size_t>(length + 1, MaxLogBufferSize - 1)] = '\0';
m_logEvent.Signal(level, buffer, file, function, line);
// Force a new-line before calling the AZ::Debug::Trace functions, as they assume a newline is present
buffer[AZStd::min<AZStd::size_t>(length + 1, MaxLogBufferSize - 2)] = '\n';
switch (level)
{
case LogLevel::Warn:
@@ -142,8 +144,6 @@ namespace AZ
AZ::Debug::Trace::Output("Logger", buffer);
break;
}
m_logEvent.Signal(level, buffer, file, function, line);
}
void LoggerSystemComponent::SetLevel(const AZ::ConsoleCommandContainer& arguments)
@@ -233,6 +233,14 @@ namespace AZ
AZ_Assert(handler->m_event == this, "Entry event does not match");
handler->Disconnect();
}
// Free up any owned memory
AZStd::vector<Handler*> freeHandlers;
m_handlers.swap(freeHandlers);
AZStd::vector<Handler*> freeAdds;
m_addList.swap(freeAdds);
AZStd::stack<size_t> freeFree;
m_freeList.swap(freeFree);
}
+10 -9
View File
@@ -13,16 +13,17 @@
#pragma once
#include <AzCore/base.h>
#include <AzCore/std/math.h>
#include <AzCore/std/typetraits/conditional.h>
#include <AzCore/std/typetraits/is_integral.h>
#include <AzCore/std/typetraits/is_signed.h>
#include <AzCore/std/typetraits/is_unsigned.h>
#include <AzCore/std/utils.h>
#include <math.h>
#include <float.h>
#include <limits>
#include <cmath>
#include <math.h>
#include <utility>
#include <AzCore/std/typetraits/conditional.h>
#include <AzCore/std/typetraits/is_integral.h>
// We have a separate inline define for math functions.
// The performance of these functions is very sensitive to inlining, and some compilers don't deal well with this.
@@ -308,12 +309,12 @@ namespace AZ
AZ_MATH_INLINE bool IsClose(float a, float b, float tolerance = Constants::Tolerance)
{
return (fabsf(a - b) <= tolerance);
return (AZStd::abs(a - b) <= tolerance);
}
AZ_MATH_INLINE bool IsClose(double a, double b, double tolerance = Constants::Tolerance)
{
return (fabs(a - b) <= tolerance);
return (AZStd::abs(a - b) <= tolerance);
}
//! Returns x >= 0.0f ? 1.0f : -1.0f.
@@ -402,12 +403,12 @@ namespace AZ
AZ_MATH_INLINE float GetAbs(float a)
{
return fabsf(a);
return AZStd::abs(a);
}
AZ_MATH_INLINE double GetAbs(double a)
{
return std::abs(a);
return AZStd::abs(a);
}
AZ_MATH_INLINE float GetMod(float a, float b)
@@ -441,7 +442,7 @@ namespace AZ
template<typename T>
AZ_MATH_INLINE bool IsCloseMag(T x, T y, T epsilonValue = std::numeric_limits<T>::epsilon())
{
return (std::fabs(x - y) <= epsilonValue * GetMax<T>(GetMax<T>(T(1.0), std::fabs(x)), std::fabs(y)));
return (AZStd::abs(x - y) <= epsilonValue * GetMax<T>(GetMax<T>(T(1.0), AZStd::abs(x)), AZStd::abs(y)));
}
//! ClampIfCloseMag(x, y, epsilon) returns y when x and y are within epsilon of each other (taking magnitude into account). Otherwise returns x.
@@ -53,6 +53,10 @@ namespace AZ
//! RemoveableByUser : A bool which determines if the component can be removed by the user.
//! Setting this to false prevents the user from removing this component. Default behavior is removeable by user.
const static AZ::Crc32 RemoveableByUser = AZ_CRC("RemoveableByUser", 0x32c7fd50);
//! An int which, if specified, causes a component to be forced to a particular position in the sorted list of
//! components on an entity, and prevents dragging or moving operations which would affect that position.
const static AZ::Crc32 FixedComponentListIndex = AZ_CRC_CE("FixedComponentListIndex");
const static AZ::Crc32 AppearsInAddComponentMenu = AZ_CRC("AppearsInAddComponentMenu", 0x53790e31);
const static AZ::Crc32 ForceAutoExpand = AZ_CRC("ForceAutoExpand", 0x1a5c79d2); // Ignores expansion state set by user, enforces expansion.
const static AZ::Crc32 AutoExpand = AZ_CRC("AutoExpand", 0x306ff5c0); // Expands automatically unless user changes expansion state.
@@ -33,6 +33,10 @@ namespace UnitTest
MOCK_METHOD1(UnregisterComponentDescriptor, void (const AZ::ComponentDescriptor*));
MOCK_METHOD1(RegisterEntityAddedEventHandler, void(AZ::EntityAddedEvent::Handler&));
MOCK_METHOD1(RegisterEntityRemovedEventHandler, void(AZ::EntityRemovedEvent::Handler&));
MOCK_METHOD1(RegisterEntityActivatedEventHandler, void(AZ::EntityActivatedEvent::Handler&));
MOCK_METHOD1(RegisterEntityDeactivatedEventHandler, void(AZ::EntityDeactivatedEvent::Handler&));
MOCK_METHOD1(SignalEntityActivated, void(AZ::Entity*));
MOCK_METHOD1(SignalEntityDeactivated, void(AZ::Entity*));
MOCK_METHOD1(RemoveEntity, bool (AZ::Entity*));
MOCK_METHOD1(DeleteEntity, bool (const AZ::EntityId&));
MOCK_METHOD1(GetEntityName, AZStd::string (const AZ::EntityId&));
+6 -1
View File
@@ -169,5 +169,10 @@ namespace AZ::Utils
template AZ::Outcome<AZStd::vector<int8_t>, AZStd::string> ReadFile(AZStd::string_view filePath, size_t maxFileSize);
template AZ::Outcome<AZStd::vector<uint8_t>, AZStd::string> ReadFile(AZStd::string_view filePath, size_t maxFileSize);
AZ::IO::FixedMaxPathString GetO3deManifestDirectory()
{
AZ::IO::FixedMaxPath path = GetHomeDirectory();
path /= ".o3de";
return path.Native();
}
}
@@ -88,6 +88,9 @@ namespace AZ
//! Retrieves the project name from the settings registry
AZ::SettingsRegistryInterface::FixedValueString GetProjectName();
//! Retrieves the full directory to the Home directory, i.e. "<userhome> or overrideHomeDirectory"
AZ::IO::FixedMaxPathString GetHomeDirectory();
//! Retrieves the full directory to the O3DE manifest directory, i.e. "<userhome>/.o3de"
AZ::IO::FixedMaxPathString GetO3deManifestDirectory();
@@ -31,6 +31,7 @@ set(FILES
iterator.h
limits.h
numeric.h
math.h
optional.h
ratio.h
reference_wrapper.h
+20
View File
@@ -0,0 +1,20 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <cmath>
namespace AZStd
{
using std::abs;
}
@@ -14,7 +14,7 @@
namespace AZ::Utils
{
AZ::IO::FixedMaxPathString GetO3deManifestDirectory()
AZ::IO::FixedMaxPathString GetHomeDirectory()
{
return {};
}
@@ -25,8 +25,19 @@ namespace AZ
void NativeErrorMessageBox(const char*, const char*) {}
AZ::IO::FixedMaxPathString GetO3deManifestDirectory()
AZ::IO::FixedMaxPathString GetHomeDirectory()
{
constexpr AZStd::string_view overrideHomeDirKey = "/Amazon/Settings/override_home_dir";
AZ::IO::FixedMaxPathString overrideHomeDir;
if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr)
{
if (settingsRegistry->Get(overrideHomeDir, overrideHomeDirKey))
{
AZ::IO::FixedMaxPath path{overrideHomeDir};
return path.Native();
}
}
if (const char* homePath = std::getenv("HOME"); homePath != nullptr)
{
AZ::IO::FixedMaxPath path{homePath};
@@ -22,15 +22,25 @@ namespace AZ::Utils
::MessageBox(0, message, title, MB_OK | MB_ICONERROR);
}
AZ::IO::FixedMaxPathString GetO3deManifestDirectory()
AZ::IO::FixedMaxPathString GetHomeDirectory()
{
constexpr AZStd::string_view overrideHomeDirKey = "/Amazon/Settings/override_home_dir";
AZ::IO::FixedMaxPathString overrideHomeDir;
if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr)
{
if (settingsRegistry->Get(overrideHomeDir, overrideHomeDirKey))
{
AZ::IO::FixedMaxPath path{overrideHomeDir};
return path.Native();
}
}
char userProfileBuffer[AZ::IO::MaxPathLength]{};
size_t variableSize = 0;
auto err = getenv_s(&variableSize, userProfileBuffer, AZ::IO::MaxPathLength, "USERPROFILE");
if (!err)
{
AZ::IO::FixedMaxPath path{ userProfileBuffer };
path /= ".o3de";
return path.Native();
}
@@ -49,9 +49,13 @@ namespace UnitTest
// ComponentApplicationBus
AZ::ComponentApplication* GetApplication() override { return nullptr; }
void RegisterComponentDescriptor(const AZ::ComponentDescriptor*) override {}
void UnregisterComponentDescriptor(const AZ::ComponentDescriptor*) override {}
void RegisterEntityAddedEventHandler(AZ::EntityAddedEvent::Handler&) override {}
void RegisterEntityRemovedEventHandler(AZ::EntityRemovedEvent::Handler&) override {}
void UnregisterComponentDescriptor(const AZ::ComponentDescriptor*) override {}
void RegisterEntityActivatedEventHandler(AZ::EntityActivatedEvent::Handler&) override {}
void RegisterEntityDeactivatedEventHandler(AZ::EntityDeactivatedEvent::Handler&) override {}
void SignalEntityActivated(AZ::Entity*) override {}
void SignalEntityDeactivated(AZ::Entity*) override {}
bool AddEntity(AZ::Entity*) override { return true; }
bool RemoveEntity(AZ::Entity*) override { return true; }
bool DeleteEntity(const AZ::EntityId&) override { return true; }
@@ -1232,6 +1232,10 @@ namespace UnitTest
void UnregisterComponentDescriptor(const ComponentDescriptor*) override { }
void RegisterEntityAddedEventHandler(EntityAddedEvent::Handler&) override { }
void RegisterEntityRemovedEventHandler(EntityRemovedEvent::Handler&) override { }
void RegisterEntityActivatedEventHandler(EntityActivatedEvent::Handler&) override { }
void RegisterEntityDeactivatedEventHandler(EntityDeactivatedEvent::Handler&) override { }
void SignalEntityActivated(Entity*) override { }
void SignalEntityDeactivated(Entity*) override { }
bool AddEntity(Entity*) override { return false; }
bool RemoveEntity(Entity*) override { return false; }
bool DeleteEntity(const EntityId&) override { return false; }
@@ -1252,6 +1256,7 @@ namespace UnitTest
m_serializeContext.reset(aznew AZ::SerializeContext());
ComponentApplicationBus::Handler::BusConnect();
AZ::Interface<AZ::ComponentApplicationRequests>::Register(this);
AZ::AllocatorInstance<AZ::PoolAllocator>::Create();
AZ::AllocatorInstance<AZ::ThreadPoolAllocator>::Create();
@@ -1270,6 +1275,7 @@ namespace UnitTest
AZ::AllocatorInstance<AZ::ThreadPoolAllocator>::Destroy();
AZ::AllocatorInstance<AZ::PoolAllocator>::Destroy();
AZ::Interface<AZ::ComponentApplicationRequests>::Unregister(this);
ComponentApplicationBus::Handler::BusDisconnect();
}