/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #include #include #include #include #include #include #include //////////////////////////////////////////////////////////////////////////////////////////////////// namespace BarrierInput { //////////////////////////////////////////////////////////////////////////////////////////////// template void OnBarrierConnectionCVarChanged(const T&) { BarrierInputConnectionNotificationBus::Broadcast(&BarrierInputConnectionNotifications::OnBarrierConnectionCVarChanged); } //////////////////////////////////////////////////////////////////////////////////////////////// AZ_CVAR(AZ::CVarFixedString, barrier_clientScreenName, "", OnBarrierConnectionCVarChanged, AZ::ConsoleFunctorFlags::DontReplicate, "The Barrier screen name assigned to this client."); //////////////////////////////////////////////////////////////////////////////////////////////// AZ_CVAR(AZ::CVarFixedString, barrier_serverHostName, "", OnBarrierConnectionCVarChanged, AZ::ConsoleFunctorFlags::DontReplicate, "The IP or hostname of the Barrier server to connect to."); //////////////////////////////////////////////////////////////////////////////////////////////// AZ_CVAR(AZ::u32, barrier_connectionPort, BarrierClient::DEFAULT_BARRIER_CONNECTION_PORT_NUMBER, OnBarrierConnectionCVarChanged, AZ::ConsoleFunctorFlags::DontReplicate, "The port number over which to connect to the Barrier server."); //////////////////////////////////////////////////////////////////////////////////////////////// void BarrierInputSystemComponent::Reflect(AZ::ReflectContext* context) { if (AZ::SerializeContext* serialize = azrtti_cast(context)) { serialize->Class() ->Version(0); if (AZ::EditContext* ec = serialize->GetEditContext()) { ec->Class("BarrierInput", "Provides functionality related to Barrier input.") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System")) ->Attribute(AZ::Edit::Attributes::AutoExpand, true) ; } } } //////////////////////////////////////////////////////////////////////////////////////////////// void BarrierInputSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { provided.push_back(AZ_CRC("BarrierInputService")); } //////////////////////////////////////////////////////////////////////////////////////////////// void BarrierInputSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) { incompatible.push_back(AZ_CRC("BarrierInputService")); } //////////////////////////////////////////////////////////////////////////////////////////////// void BarrierInputSystemComponent::Activate() { TryCreateBarrierClientAndInputDeviceImplementations(); BarrierInputConnectionNotificationBus::Handler::BusConnect(); } //////////////////////////////////////////////////////////////////////////////////////////////// void BarrierInputSystemComponent::Deactivate() { BarrierInputConnectionNotificationBus::Handler::BusDisconnect(); DestroyBarrierClientAndInputDeviceImplementations(); } //////////////////////////////////////////////////////////////////////////////////////////////// void BarrierInputSystemComponent::OnBarrierConnectionCVarChanged() { TryCreateBarrierClientAndInputDeviceImplementations(); } //////////////////////////////////////////////////////////////////////////////////////////////// void BarrierInputSystemComponent::TryCreateBarrierClientAndInputDeviceImplementations() { // Destroy any existing Barrier client and input device implementations. DestroyBarrierClientAndInputDeviceImplementations(); const AZ::CVarFixedString barrierClientScreenNameCVar = static_cast(barrier_clientScreenName); const AZ::CVarFixedString barrierServerHostNameCVar = static_cast(barrier_serverHostName); const AZ::u32 barrierConnectionPort = static_cast(barrier_connectionPort); if (!barrierClientScreenNameCVar.empty() && !barrierServerHostNameCVar.empty() && barrierConnectionPort) { // Enable the Barrier keyboard/mouse input device implementations. AzFramework::InputDeviceImplementationRequest::Bus::Event( AzFramework::InputDeviceKeyboard::Id, &AzFramework::InputDeviceImplementationRequest::SetCustomImplementation, BarrierInput::InputDeviceKeyboardBarrier::Create); AzFramework::InputDeviceImplementationRequest::Bus::Event( AzFramework::InputDeviceMouse::Id, &AzFramework::InputDeviceImplementationRequest::SetCustomImplementation, BarrierInput::InputDeviceMouseBarrier::Create); // Create the Barrier client instance. m_barrierClient = AZStd::make_unique(barrierClientScreenNameCVar.c_str(), barrierServerHostNameCVar.c_str(), barrierConnectionPort); } } //////////////////////////////////////////////////////////////////////////////////////////////// void BarrierInputSystemComponent::DestroyBarrierClientAndInputDeviceImplementations() { if (m_barrierClient) { // Destroy the Barrier client instance. m_barrierClient.reset(); // Reset to the default keyboard/mouse input device implementations. AzFramework::InputDeviceImplementationRequest::Bus::Event( AzFramework::InputDeviceKeyboard::Id, &AzFramework::InputDeviceImplementationRequest::SetCustomImplementation, AzFramework::InputDeviceKeyboard::Implementation::Create); AzFramework::InputDeviceImplementationRequest::Bus::Event( AzFramework::InputDeviceMouse::Id, &AzFramework::InputDeviceImplementationRequest::SetCustomImplementation, AzFramework::InputDeviceMouse::Implementation::Create); } } } // namespace BarrierInput