LocalUserSystemComponent.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <LocalUser/LocalUserRequestBus.h>
  10. #include <AzCore/Component/Component.h>
  11. #include <AzCore/std/smart_ptr/unique_ptr.h>
  12. ////////////////////////////////////////////////////////////////////////////////////////////////////
  13. namespace LocalUser
  14. {
  15. ////////////////////////////////////////////////////////////////////////////////////////////////
  16. //! A system component providing functionality for mapping local user ids to local player slots,
  17. //! and managing local user profiles. Please note that while some platforms have no concept of a
  18. //! local user profile, the functionality for assigning local user ids to local player slots can
  19. //! still be used because local user ids are represented instead by unique input device indices.
  20. class LocalUserSystemComponent : public AZ::Component
  21. , public LocalUserRequestBus::Handler
  22. {
  23. public:
  24. ////////////////////////////////////////////////////////////////////////////////////////////
  25. // AZ::Component Setup
  26. AZ_COMPONENT(LocalUserSystemComponent, "{D22DBCC8-9F44-47F6-86CA-0BE1F52D1727}");
  27. ////////////////////////////////////////////////////////////////////////////////////////////
  28. //! \ref AZ::ComponentDescriptor::Reflect
  29. static void Reflect(AZ::ReflectContext* context);
  30. ////////////////////////////////////////////////////////////////////////////////////////////
  31. //! \ref AZ::ComponentDescriptor::GetProvidedServices
  32. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  33. ////////////////////////////////////////////////////////////////////////////////////////////
  34. //! \ref AZ::ComponentDescriptor::GetIncompatibleServices
  35. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  36. ////////////////////////////////////////////////////////////////////////////////////////////
  37. //! Constructor
  38. LocalUserSystemComponent();
  39. ////////////////////////////////////////////////////////////////////////////////////////////
  40. //! Default destructor
  41. ~LocalUserSystemComponent() override = default;
  42. protected:
  43. ////////////////////////////////////////////////////////////////////////////////////////////
  44. //! \ref AZ::Component::Activate
  45. void Activate() override;
  46. ////////////////////////////////////////////////////////////////////////////////////////////
  47. //! \ref AZ::Component::Deactivate
  48. void Deactivate() override;
  49. ////////////////////////////////////////////////////////////////////////////////////////////
  50. //! \ref LocalUser::LocalUserRequests::FindLocalUserProfile
  51. AZStd::shared_ptr<LocalUserProfile> FindLocalUserProfile(AzFramework::LocalUserId localUserId) override;
  52. ////////////////////////////////////////////////////////////////////////////////////////////
  53. //! \ref LocalUser::LocalUserRequests::GetMaxLocalUsers
  54. AZ::u32 GetMaxLocalUsers() const override;
  55. ////////////////////////////////////////////////////////////////////////////////////////////
  56. //! \ref LocalUser::LocalUserRequests::IsLocalUserSignedIn
  57. bool IsLocalUserSignedIn(AzFramework::LocalUserId localUserId) override;
  58. ////////////////////////////////////////////////////////////////////////////////////////////
  59. //! \ref LocalUser::LocalUserRequests::GetLocalUserName
  60. AZStd::string GetLocalUserName(AzFramework::LocalUserId localUserId) override;
  61. ////////////////////////////////////////////////////////////////////////////////////////////
  62. //! \ref LocalUser::LocalUserRequests::AssignLocalUserIdToLocalPlayerSlot
  63. AZ::u32 AssignLocalUserIdToLocalPlayerSlot(AzFramework::LocalUserId localUserId,
  64. AZ::u32 localPlayerSlot = LocalPlayerSlotAny) override;
  65. ////////////////////////////////////////////////////////////////////////////////////////////
  66. //! \ref LocalUser::LocalUserRequests::RemoveLocalUserIdFromLocalPlayerSlot
  67. AZ::u32 RemoveLocalUserIdFromLocalPlayerSlot(AzFramework::LocalUserId localUserId) override;
  68. ////////////////////////////////////////////////////////////////////////////////////////////
  69. //! \ref LocalUser::LocalUserRequests::GetLocalUserIdAssignedToLocalPlayerSlot
  70. AzFramework::LocalUserId GetLocalUserIdAssignedToLocalPlayerSlot(AZ::u32 localPlayerSlot) override;
  71. ////////////////////////////////////////////////////////////////////////////////////////////
  72. //! \ref LocalUser::LocalUserRequests::GetLocalPlayerSlotOccupiedByLocalUserId
  73. AZ::u32 GetLocalPlayerSlotOccupiedByLocalUserId(AzFramework::LocalUserId localUserId) override;
  74. ////////////////////////////////////////////////////////////////////////////////////////////
  75. //! \ref LocalUser::LocalUserRequests::ClearAllLocalUserIdToLocalPlayerSlotAssignments
  76. void ClearAllLocalUserIdToLocalPlayerSlotAssignments() override;
  77. public:
  78. ////////////////////////////////////////////////////////////////////////////////////////////
  79. //! Base class for platform specific implementations of the local user system component
  80. class Implementation
  81. {
  82. public:
  83. ////////////////////////////////////////////////////////////////////////////////////////
  84. // Allocator
  85. AZ_CLASS_ALLOCATOR(Implementation, AZ::SystemAllocator);
  86. ////////////////////////////////////////////////////////////////////////////////////////
  87. //! Default factory create function
  88. //! \param[in] localUserSystemComponent Reference to the parent being implemented
  89. static Implementation* Create();
  90. ////////////////////////////////////////////////////////////////////////////////////////
  91. //! Constructor
  92. //! \param[in] localUserSystemComponent Reference to the parent being implemented
  93. Implementation() {}
  94. ////////////////////////////////////////////////////////////////////////////////////////
  95. // Disable copying
  96. AZ_DISABLE_COPY_MOVE(Implementation);
  97. ////////////////////////////////////////////////////////////////////////////////////////
  98. //! Default destructor
  99. virtual ~Implementation() = default;
  100. ////////////////////////////////////////////////////////////////////////////////////////
  101. //! Finds a specific local user profile based on their local user id.
  102. //! \param[in] localUserId The local user id of the local user profile to retrieve.
  103. //! \return A shared pointer to the local user profile if found, otherwise an empty one.
  104. virtual AZStd::shared_ptr<LocalUserProfile> FindLocalUserProfile(AzFramework::LocalUserId localUserId) = 0;
  105. ////////////////////////////////////////////////////////////////////////////////////////
  106. //! Query the maximum number of local uses that can be signed in concurrently.
  107. //! \return The maximum number of local uses that can be signed in concurrently.
  108. virtual AZ::u32 GetMaxLocalUsers() const = 0;
  109. ////////////////////////////////////////////////////////////////////////////////////////
  110. //! Query whether a local user id is signed in.
  111. //! \param[in] localUserId The local user id to query.
  112. //! \return True if localUserId is signed in, false otherwise.
  113. virtual bool IsLocalUserSignedIn(AzFramework::LocalUserId localUserId) = 0;
  114. ////////////////////////////////////////////////////////////////////////////////////////
  115. //! Get the user name associated with a local user id.
  116. //! \param[in] localUserId The local user id to query.
  117. //! \return The user name that is associated with localUserId.
  118. virtual AZStd::string GetLocalUserName(AzFramework::LocalUserId localUserId) = 0;
  119. };
  120. private:
  121. ////////////////////////////////////////////////////////////////////////////////////////////
  122. //! Private pointer to the platform specific implementation
  123. AZStd::unique_ptr<Implementation> m_pimpl;
  124. ////////////////////////////////////////////////////////////////////////////////////////////
  125. //! An array of local user ids indexed by their assigned local player slot
  126. AzFramework::LocalUserId m_localUserIdsByLocalPlayerSlot[LocalPlayerSlotMax];
  127. };
  128. } // namespace LocalUser