Exposing NetworkCharacterComponent::TryMoveWithVelocity to script. Updating Multiplayer AutoComponent baseclass behavior context to Reflect itself instead of its derived (human made) component. This is so the derived class can also create behaviorcontext classes of its own if needed. Misc copyright header edit.

Signed-off-by: Gene Walters <genewalt@amazon.com>
This commit is contained in:
Gene Walters
2021-09-23 09:46:55 -07:00
parent d7e29c00c7
commit c2c18f094b
5 changed files with 48 additions and 7 deletions
@@ -19,6 +19,22 @@ namespace Physics
namespace Multiplayer
{
//! NetworkCharacterRequests
//! ComponentBus handled by NetworkCharacterComponentController.
//! Bus was created for exposing controller methods to script; C++ users should access the controller directly.
class NetworkCharacterRequests : public AZ::ComponentBus
{
public:
//! TryMoveWithVelocity
//! Will move this character entity kinematically through physical world while also ensuring the network stays in-sync.
//! Velocity will be applied over delta-time to determine the movement amount.
//! Returns this entity's world-space position after the move.
virtual AZ::Vector3 TryMoveWithVelocity(const AZ::Vector3& velocity, float deltaTime) = 0;
};
typedef AZ::EBus<NetworkCharacterRequests> NetworkCharacterRequestBus;
//! NetworkCharacterComponent
//! Provides multiplayer support for game-play player characters.
class NetworkCharacterComponent
@@ -39,6 +55,12 @@ namespace Multiplayer
incompatible.push_back(AZ_CRC_CE("NetworkRigidBodyService"));
}
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
{
NetworkCharacterComponentBase::GetRequiredServices(required);
required.push_back(AZ_CRC("PhysXCharacterControllerService", 0x428de4fa));
}
// AZ::Component
void OnInit() override {}
void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
@@ -65,18 +87,22 @@ namespace Multiplayer
//! Class provides the ability to move characters in physical space while keeping the network in-sync.
class NetworkCharacterComponentController
: public NetworkCharacterComponentControllerBase
, private NetworkCharacterRequestBus::Handler
{
public:
AZ_RTTI(NetworkCharacterComponentController, "{C91851A2-8B95-4484-9F97-BFF9D1F528A0}")
static void Reflect(AZ::ReflectContext* context);
NetworkCharacterComponentController(NetworkCharacterComponent& parent);
// NetworkCharacterComponentControllerBase
void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
// NetworkCharacterRequestBus::Handler
//! TryMoveWithVelocity
//! Will move this character entity kinematically through physical world while also ensuring the network stays in-sync.
//! Velocity will be applied over delta-time to determine the movement amount.
//! Returns this entity's world-space position after the move.
AZ::Vector3 TryMoveWithVelocity(const AZ::Vector3& velocity, float deltaTime);
AZ::Vector3 TryMoveWithVelocity(const AZ::Vector3& velocity, float deltaTime) override;
};
}
@@ -1,5 +1,6 @@
/*
* 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.
* 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
*
@@ -1518,7 +1518,7 @@ namespace {{ Component.attrib['Namespace'] }}
{{ ReflectRpcEventDescs(Component, ComponentName, 'Authority', 'Autonomous')|indent(4) -}}
{{ ReflectRpcEventDescs(Component, ComponentName, 'Authority', 'Client')|indent(4) }}
behaviorContext->Class<{{ ComponentName }}>("{{ ComponentName }}")
behaviorContext->Class<{{ ComponentBaseName }}>("{{ ComponentBaseName }}")
->Attribute(AZ::Script::Attributes::Module, "{{ LowerFirst(Component.attrib['Namespace']) }}")
->Attribute(AZ::Script::Attributes::Category, "{{ UpperFirst(Component.attrib['Namespace']) }}")
@@ -83,7 +83,7 @@ namespace Multiplayer
return physx::PxQueryHitType::eNONE;
}
void NetworkCharacterComponent::NetworkCharacterComponent::Reflect(AZ::ReflectContext* context)
void NetworkCharacterComponent::Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
if (serializeContext)
@@ -92,6 +92,7 @@ namespace Multiplayer
->Version(1);
}
NetworkCharacterComponentBase::Reflect(context);
NetworkCharacterComponentController::Reflect(context);
}
NetworkCharacterComponent::NetworkCharacterComponent()
@@ -161,6 +162,18 @@ namespace Multiplayer
return state.touchedActor != nullptr || (state.collisionFlags & physx::PxControllerCollisionFlag::eCOLLISION_DOWN) != 0;
}
void NetworkCharacterComponentController::Reflect(AZ::ReflectContext* context)
{
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->EBus<NetworkCharacterRequestBus>("NetworkCharacterRequestBus")
->Event("TryMoveWithVelocity", &NetworkCharacterRequestBus::Events::TryMoveWithVelocity);
behaviorContext->Class<NetworkCharacterComponentController>("NetworkCharacterComponentController")
->RequestBus("NetworkCharacterRequestBus");
}
}
NetworkCharacterComponentController::NetworkCharacterComponentController(NetworkCharacterComponent& parent)
: NetworkCharacterComponentControllerBase(parent)
{
@@ -169,12 +182,12 @@ namespace Multiplayer
void NetworkCharacterComponentController::OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
{
;
NetworkCharacterRequestBus::Handler::BusConnect(GetEntity()->GetId());
}
void NetworkCharacterComponentController::OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
{
;
NetworkCharacterRequestBus::Handler::BusDisconnect(GetEntity()->GetId());
}
AZ::Vector3 NetworkCharacterComponentController::TryMoveWithVelocity(const AZ::Vector3& velocity, [[maybe_unused]] float deltaTime)
@@ -1,5 +1,6 @@
/*
* 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.
* 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
*