From 72ea2ca1b4509364f9ab0629f8ea904ad6d55d21 Mon Sep 17 00:00:00 2001 From: bosnichd Date: Wed, 14 Jul 2021 17:44:44 -0600 Subject: [PATCH] Change the InputDeviceImplementationRequest to be addressable by an InputDevcieId to account for the situation where someone may want to swap out the implementation for a single instance of a devcie type rather than all instances of that device type (the latter can still be achieved using Broadcast instead of Event when calling the EBus method). (#2180) Signed-off-by: bosnichd --- .../Buses/Requests/InputDeviceRequestBus.h | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/Code/Framework/AzFramework/AzFramework/Input/Buses/Requests/InputDeviceRequestBus.h b/Code/Framework/AzFramework/AzFramework/Input/Buses/Requests/InputDeviceRequestBus.h index a1ec4a05f0..a122fe3133 100644 --- a/Code/Framework/AzFramework/AzFramework/Input/Buses/Requests/InputDeviceRequestBus.h +++ b/Code/Framework/AzFramework/AzFramework/Input/Buses/Requests/InputDeviceRequestBus.h @@ -205,6 +205,25 @@ namespace AzFramework class InputDeviceImplementationRequest : public AZ::EBusTraits { public: + //////////////////////////////////////////////////////////////////////////////////////////// + //! EBus Trait: requests can be addressed to a specific InputDeviceId so that they are only + //! handled by one input device that has connected to the bus using that unique id, or they + //! can be broadcast to all input devices that have connected to the bus, regardless of id. + //! Connected input devices are ordered by their local player index from lowest to highest. + static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ByIdAndOrdered; + + //////////////////////////////////////////////////////////////////////////////////////////// + //! EBus Trait: requests should be handled by only one input device connected to each id + static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; + + //////////////////////////////////////////////////////////////////////////////////////////// + //! EBus Trait: requests can be addressed to a specific InputDeviceId + using BusIdType = InputDeviceId; + + //////////////////////////////////////////////////////////////////////////////////////////// + //! EBus Trait: requests are handled by connected devices in the order of local player index + using BusIdOrderCompare = AZStd::less; + //////////////////////////////////////////////////////////////////////////////////////////// //! Alias for the EBus implementation of this interface using Bus = AZ::EBus>; @@ -214,11 +233,12 @@ namespace AzFramework using CreateFunctionType = typename InputDeviceType::Implementation*(*)(InputDeviceType&); //////////////////////////////////////////////////////////////////////////////////////////// - //! Create a custom implementation for all the existing instances of this input device type. + //! Set a custom implementation for this input device type, either for a specific instance + //! by addressing the call to an InputDeviceId, or for all existing instances by broadcast. //! Passing InputDeviceType::Implementation::Create as the argument will create the default //! device implementation, while passing nullptr will delete any existing implementation. //! \param[in] createFunction Pointer to the function that will create the implementation. - virtual void CreateCustomImplementation(CreateFunctionType createFunction) = 0; + virtual void SetCustomImplementation(CreateFunctionType createFunction) = 0; }; //////////////////////////////////////////////////////////////////////////////////////////////// @@ -238,7 +258,7 @@ namespace AzFramework AZ_INLINE InputDeviceImplementationRequestHandler(InputDeviceType& inputDevice) : m_inputDevice(inputDevice) { - InputDeviceImplementationRequest::Bus::Handler::BusConnect(); + InputDeviceImplementationRequest::Bus::Handler::BusConnect(m_inputDevice.GetInputDeviceId()); } //////////////////////////////////////////////////////////////////////////////////////////// @@ -251,8 +271,8 @@ namespace AzFramework using CreateFunctionType = typename InputDeviceType::Implementation*(*)(InputDeviceType&); //////////////////////////////////////////////////////////////////////////////////////////// - //! \ref InputDeviceImplementationRequest::CreateCustomImplementation - AZ_INLINE void CreateCustomImplementation(CreateFunctionType createFunction) override + //! \ref InputDeviceImplementationRequest::SetCustomImplementation + AZ_INLINE void SetCustomImplementation(CreateFunctionType createFunction) override { AZStd::unique_ptr newImplementation; if (createFunction)