Merge pull request #4287 from aws-lumberyard-dev/LYN6657_MultiplayerScriptImprovementsForDemo

LYN6657 Misc Improvements for Multiplayer Scripting
monroegm-disable-blank-issue-2
kberg-amzn 5 years ago committed by GitHub
commit 2c19abf7ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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_CE("PhysXCharacterControllerService"));
}
// 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
*

@ -909,6 +909,7 @@ enum class NetworkProperties
controller->Set{{ UpperFirst(Property.attrib['Name']) }}({{ LowerFirst(Property.attrib['Name']) }});
{% endif %}
})
{% if Property.attrib['GenerateEventBindings']|booleanTrue %}
{% if Property.attrib['Container'] == 'Vector' or Property.attrib['Container'] == 'Array' -%}
->Method("GetOn{{ UpperFirst(Property.attrib['Name']) }}ChangedEvent", [](AZ::EntityId id) -> AZ::Event<int32_t, {{ Property.attrib['Type'] }}>*
{% else %}
@ -936,6 +937,7 @@ enum class NetworkProperties
{% else %}
->Attribute(AZ::Script::Attributes::AzEventDescription, AZ::BehaviorAzEventDescription{ "On {{ UpperFirst(Property.attrib['Name']) }} Changed Event", {"New {{ Property.attrib['Type'] }}"} })
{% endif %}
{% endif %}
{% endif %}
{% endcall %}
@ -1518,7 +1520,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, {{ { "Velocity" }, { "DeltaTime" } }});
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
*

Loading…
Cancel
Save