Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,37 @@
/*
* 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 <AzCore/base.h>
#include <limits>
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace LocalUser
{
////////////////////////////////////////////////////////////////////////////////////////////////
//! Constant representing the max local player slot
static const AZ::u32 LocalPlayerSlotMax = 4;
////////////////////////////////////////////////////////////////////////////////////////////////
//! Constant representing any local player slot
static const AZ::u32 LocalPlayerSlotAny = std::numeric_limits<AZ::u32>::max();
////////////////////////////////////////////////////////////////////////////////////////////////
//! Constant representing no local player slot
static const AZ::u32 LocalPlayerSlotNone = std::numeric_limits<AZ::u32>::max() - 1;
////////////////////////////////////////////////////////////////////////////////////////////////
//! Constant representing the primary local player slot
static const AZ::u32 LocalPlayerSlotPrimary = 0;
} // namespace LocalUser
@@ -0,0 +1,63 @@
/*
* 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 <LocalUser/LocalPlayerSlot.h>
#include <LocalUser/LocalUserProfile.h>
#include <AzCore/EBus/EBus.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace LocalUser
{
////////////////////////////////////////////////////////////////////////////////////////////////
//! EBus interface used to listen for notifications related to assignment of local user ids to
//! local player slots in addition to notifications related to individual local user profiles.
class LocalUserNotifications : public AZ::EBusTraits
{
public:
////////////////////////////////////////////////////////////////////////////////////////////
//! EBus Trait: local user notifications are addressed to a single address
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
////////////////////////////////////////////////////////////////////////////////////////////
//! EBus Trait: local user notifications can be handled by multiple listeners
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
////////////////////////////////////////////////////////////////////////////////////////////
//! Override to be notified when a local user signs into the system
//! \param[in] localUserId The local user id that signed into the system
virtual void OnLocalUserSignedIn([[maybe_unused]] AzFramework::LocalUserId localUserId) {}
////////////////////////////////////////////////////////////////////////////////////////////
//! Override to be notified when a local user signs out of the system
//! \param[in] localUserId The local user id that signed out of the system
virtual void OnLocalUserSignedOut([[maybe_unused]] AzFramework::LocalUserId localUserId) {}
////////////////////////////////////////////////////////////////////////////////////////////
//! Override to be notified when a local user id is assigned to a local player slot
//! \param[in] localUserId The local user id that was assigned to a local player slot.
//! \param[in] newLocalPlayerSlot The local player slot that the local user id now occupies.
//! \param[in] previousLocalPlayerSlot The local player slot that the local user id previously occupied, or LocalPlayerSlotNone.
virtual void OnLocalUserIdAssignedToLocalPlayerSlot([[maybe_unused]] AzFramework::LocalUserId localUserId,
[[maybe_unused]] AZ::u32 newLocalPlayerSlot,
[[maybe_unused]] AZ::u32 previousLocalPlayerSlot = LocalPlayerSlotNone) {}
////////////////////////////////////////////////////////////////////////////////////////////
//! Override to be notified when a local user id is removed from a local player slot
//! \param[in] localUserId The local user id that was removed from a local player slot.
//! \param[in] localPlayerSlot The local player slot that the local user id was removed from.
virtual void OnLocalUserIdRemovedFromLocalPlayerSlot([[maybe_unused]] AzFramework::LocalUserId localUserId,
[[maybe_unused]] AZ::u32 localPlayerSlot) {}
};
using LocalUserNotificationBus = AZ::EBus<LocalUserNotifications>;
} // namespace LocalUser
@@ -0,0 +1,66 @@
/*
* 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 <AzFramework/Input/User/LocalUserId.h>
#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <AzCore/std/string/string.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace LocalUser
{
////////////////////////////////////////////////////////////////////////////////////////////////
//! Abstract class that represents a local user profile, uniquely identified by a local user id.
//! Please note that on some platforms there does not exist any concept of a local user profile.
class LocalUserProfile
{
public:
////////////////////////////////////////////////////////////////////////////////////////////
// Allocator
AZ_CLASS_ALLOCATOR(LocalUserProfile, AZ::SystemAllocator, 0);
////////////////////////////////////////////////////////////////////////////////////////////
// Type Info
AZ_RTTI(LocalUserProfile, "{2A681065-FA77-46CF-9533-04D6C5C5EAF0}");
////////////////////////////////////////////////////////////////////////////////////////////
//! Constructor
//! \param[in] localUserId The local user id that uniquely identifies the local user profile
explicit LocalUserProfile(AzFramework::LocalUserId locaUserId) : m_locaUserId(locaUserId) {}
////////////////////////////////////////////////////////////////////////////////////////////
//! Default destructor
virtual ~LocalUserProfile() = default;
////////////////////////////////////////////////////////////////////////////////////////////
//! Get the local user id that uniquely identifies this local user profile on the system.
//! \return The local user id that uniquely identifies this local user profile on the system.
inline AzFramework::LocalUserId GetLocalUserId() const { return m_locaUserId; }
////////////////////////////////////////////////////////////////////////////////////////////
//! Query whether this local user profile is currently signed in.
//! \return True if this local user profile is currently signed in, false otherwise.
virtual bool IsSignedIn() const = 0;
////////////////////////////////////////////////////////////////////////////////////////////
//! Query the user name associated with this local user profile.
//! \return A UTF-8 string containing this local user's user name.
virtual AZStd::string GetUserName() const = 0;
private:
////////////////////////////////////////////////////////////////////////////////////////////
//! The local user id that uniquely identifies this local user profile.
const AzFramework::LocalUserId m_locaUserId = AzFramework::LocalUserIdNone;
};
} // namespace LocalUser
@@ -0,0 +1,168 @@
/*
* 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 <LocalUser/LocalPlayerSlot.h>
#include <LocalUser/LocalUserProfile.h>
#include <AzCore/EBus/EBus.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace LocalUser
{
////////////////////////////////////////////////////////////////////////////////////////////////
//! EBus interface used to make queries/requests related to the assignment of local user ids to
//! local player slots, along with queries/requests related to individual local user profiles.
//!
//! Please note that while some platforms have no concept of a local user profile (in which case
//! GetLocalUserProfile will always return null), most other functions will remain valid because
//! on those platforms local user ids can be represented instead by unique input device indices.
class LocalUserRequests : public AZ::EBusTraits
{
public:
////////////////////////////////////////////////////////////////////////////////////////////
//! EBus Trait: requests can only be sent to and addressed by a single instance (singleton)
///@{
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
///@}
////////////////////////////////////////////////////////////////////////////////////////////
//! Convenience function to get the local user id that is assigned to the primary local slot.
//! \return The local user id that is assigned to the primary local slot, or LocalUserIdNone.
static AzFramework::LocalUserId GetPrimaryLocalUserId();
////////////////////////////////////////////////////////////////////////////////////////////
//! Convenience function to get the local user id that is assigned to a specified local slot.
//! \param[in] localPlayerSlot The local player slot to query.
//! \return The local user id that is assigned to localPlayerSlot, or LocalUserIdNone.
static AzFramework::LocalUserId GetLocalUserIdAt(AZ::u32 localPlayerSlot);
////////////////////////////////////////////////////////////////////////////////////////////
//! Convenience function to get the local user profile assigned to the primary local slot.
//! \return A shared pointer to the local user profile if found, otherwise an empty one.
static AZStd::shared_ptr<LocalUserProfile> GetPrimaryLocalUserProfile();
////////////////////////////////////////////////////////////////////////////////////////////
//! Convenience function to get a specific local user profile based on their local user id.
//! \param[in] localUserId The local user id of the local user profile to retrieve.
//! \return A shared pointer to the local user profile if found, otherwise an empty one.
static AZStd::shared_ptr<LocalUserProfile> GetLocalUserProfile(AzFramework::LocalUserId localUserId);
////////////////////////////////////////////////////////////////////////////////////////////
//! Convenience function to get the specific local user profile assigned to a local slot.
//! \param[in] localPlayerSlot The local player slot to query.
//! \return A shared pointer to the local user profile if found, otherwise an empty one.
static AZStd::shared_ptr<LocalUserProfile> GetLocalUserProfileAt(AZ::u32 localPlayerSlot);
////////////////////////////////////////////////////////////////////////////////////////////
//! Finds a specific local user profile based on their local user id.
//! \param[in] localUserId The local user id of the local user profile to retrieve.
//! \return A shared pointer to the local user profile if found, otherwise an empty one.
virtual AZStd::shared_ptr<LocalUserProfile> FindLocalUserProfile(AzFramework::LocalUserId localUserId) = 0;
////////////////////////////////////////////////////////////////////////////////////////////
//! Query the maximum number of local uses that can be signed into the system concurrently.
//! \return The maximum number of local uses that can be signed into the system concurrently.
virtual AZ::u32 GetMaxLocalUsers() const = 0;
////////////////////////////////////////////////////////////////////////////////////////////
//! Query whether a local user id is signed in. Please note that a user can be assigned to a
//! local player slot but signed out, or signed in but not assigned to a local player slot.
//!
//! On platforms with no concept of a local user profile, local user ids are instead unique
//! input device indices, so while it may seem counter-intuitive this may still return true.
//!
//! \param[in] localUserId The local user id to query.
//! \return True if localUserId is signed in, false otherwise.
virtual bool IsLocalUserSignedIn(AzFramework::LocalUserId localUserId) = 0;
////////////////////////////////////////////////////////////////////////////////////////////
//! Get the user name associated with a local user id. Platforms that have no concept of a
//! local user profile will return "Player N" where "N" is the local player slot currently
//! occupied by localUserId, or an empty string if they don't currently occupy a local slot.
//! \param[in] localUserId The local user id to query.
//! \return The user name that is associated with localUserId.
virtual AZStd::string GetLocalUserName(AzFramework::LocalUserId localUserId) = 0;
////////////////////////////////////////////////////////////////////////////////////////////
//! Assign a local user id into a local player slot.
//! \param[in] localUserId The local user id to assign into a local player slot.
//! \param[in] localPlayerSlot The local player slot to assign the local user id into.
//! LocalPlayerSlotAny uses the first available local slot.
//! \return The local player slot that localUserId was assigned to, or LocalPlayerSlotNone.
virtual AZ::u32 AssignLocalUserIdToLocalPlayerSlot(AzFramework::LocalUserId localUserId,
AZ::u32 localPlayerSlot = LocalPlayerSlotAny) = 0;
////////////////////////////////////////////////////////////////////////////////////////////
//! Remove a local user id from a local player slot.
//! \param[in] localUserId The local user id to remove from a local player slot.
//! \return The local player slot that localUserId was removed from, or LocalPlayerSlotNone.
virtual AZ::u32 RemoveLocalUserIdFromLocalPlayerSlot(AzFramework::LocalUserId localUserId) = 0;
////////////////////////////////////////////////////////////////////////////////////////////
//! Get the local user id that is assigned to a local player slot.
//! \param[in] localPlayerSlot The local player slot query.
//! \return The local user id that is assigned to localPlayerSlot, or LocalUserIdNone.
virtual AzFramework::LocalUserId GetLocalUserIdAssignedToLocalPlayerSlot(AZ::u32 localPlayerSlot) = 0;
////////////////////////////////////////////////////////////////////////////////////////////
//! Get the local player slot that a local user id is assigned to.
//! \param[in] localUserId The local user id to query.
//! \return The local player slot that has localUserId assigned, or LocalPlayerSlotNone.
virtual AZ::u32 GetLocalPlayerSlotOccupiedByLocalUserId(AzFramework::LocalUserId localUserId) = 0;
////////////////////////////////////////////////////////////////////////////////////////////
//! Clears all previously assigned local user id to local player slot associations.
virtual void ClearAllLocalUserIdToLocalPlayerSlotAssignments() = 0;
};
using LocalUserRequestBus = AZ::EBus<LocalUserRequests>;
////////////////////////////////////////////////////////////////////////////////////////////////
inline AzFramework::LocalUserId LocalUserRequests::GetPrimaryLocalUserId()
{
return GetLocalUserIdAt(LocalPlayerSlotPrimary);
}
////////////////////////////////////////////////////////////////////////////////////////////////
inline AzFramework::LocalUserId LocalUserRequests::GetLocalUserIdAt(AZ::u32 localPlayerSlot)
{
AzFramework::LocalUserId localUserId = AzFramework::LocalUserIdNone;
LocalUserRequestBus::BroadcastResult(localUserId,
&LocalUserRequests::GetLocalUserIdAssignedToLocalPlayerSlot,
localPlayerSlot);
return localUserId;
}
////////////////////////////////////////////////////////////////////////////////////////////////
inline AZStd::shared_ptr<LocalUserProfile> LocalUserRequests::GetPrimaryLocalUserProfile()
{
return GetLocalUserProfileAt(LocalPlayerSlotPrimary);
}
////////////////////////////////////////////////////////////////////////////////////////////////
inline AZStd::shared_ptr<LocalUserProfile> LocalUserRequests::GetLocalUserProfile(AzFramework::LocalUserId localUserId)
{
AZStd::shared_ptr<LocalUserProfile> localUserProfile;
LocalUserRequestBus::BroadcastResult(localUserProfile,
&LocalUserRequests::FindLocalUserProfile,
localUserId);
return localUserProfile;
}
////////////////////////////////////////////////////////////////////////////////////////////////
inline AZStd::shared_ptr<LocalUserProfile> LocalUserRequests::GetLocalUserProfileAt(AZ::u32 localPlayerSlot)
{
const AzFramework::LocalUserId localUserId = GetLocalUserIdAt(localPlayerSlot);
return localUserId != AzFramework::LocalUserIdNone ? GetLocalUserProfile(localUserId) : nullptr;
}
} // namespace LocalUser