Moving NetworkHitVolumesComponent and NetworkRigidBodyComponent to the MultiplayerGem

Signed-off-by: Gene Walters <genewalt@amazon.com>
This commit is contained in:
Gene Walters
2021-09-13 15:00:42 -07:00
parent c3e285cff7
commit 28ca59ae61
9 changed files with 565 additions and 1 deletions
@@ -0,0 +1,89 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <Source/AutoGen/NetworkHitVolumesComponent.AutoComponent.h>
#include <Multiplayer/Components/NetBindComponent.h>
#include <Integration/ActorComponentBus.h>
#include <AzCore/Component/TransformBus.h>
namespace Physics
{
class CharacterRequests;
class CharacterHitDetectionConfiguration;
}
namespace Multiplayer
{
class NetworkHitVolumesComponent
: public NetworkHitVolumesComponentBase
, private EMotionFX::Integration::ActorComponentNotificationBus::Handler
{
public:
struct AnimatedHitVolume final
{
AnimatedHitVolume
(
AzNetworking::ConnectionId connectionId,
Physics::CharacterRequests* character,
const char* hitVolumeName,
const Physics::ColliderConfiguration* colliderConfig,
const Physics::ShapeConfiguration* shapeConfig,
const uint32_t jointIndex
);
~AnimatedHitVolume() = default;
void UpdateTransform(const AZ::Transform& transform);
void SyncToCurrentTransform();
Multiplayer::RewindableObject<AZ::Transform, Multiplayer::RewindHistorySize> m_transform;
AZStd::shared_ptr<Physics::Shape> m_physicsShape;
// Cached so we don't have to do subsequent lookups by name
const Physics::ColliderConfiguration* m_colliderConfig = nullptr;
const Physics::ShapeConfiguration* m_shapeConfig = nullptr;
AZ::Transform m_colliderOffSetTransform;
const AZ::u32 m_jointIndex = 0;
};
AZ_MULTIPLAYER_COMPONENT(Multiplayer::NetworkHitVolumesComponent, s_networkHitVolumesComponentConcreteUuid, Multiplayer::NetworkHitVolumesComponentBase);
static void Reflect(AZ::ReflectContext* context);
NetworkHitVolumesComponent();
void OnInit() override;
void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
private:
void OnPreRender(float deltaTime, float blendFactor);
void OnTransformUpdate(const AZ::Transform& transform);
void OnSyncRewind();
void CreateHitVolumes();
void DestroyHitVolumes();
//! ActorComponentNotificationBus::Handler
//! @{
void OnActorInstanceCreated(EMotionFX::ActorInstance* actorInstance) override;
void OnActorInstanceDestroyed(EMotionFX::ActorInstance* actorInstance) override;
//! @}
Physics::CharacterRequests* m_physicsCharacter = nullptr;
EMotionFX::Integration::ActorComponentRequests* m_actorComponent = nullptr;
const Physics::CharacterColliderConfiguration* m_hitDetectionConfig = nullptr;
AZStd::vector<AnimatedHitVolume> m_animatedHitVolumes;
Multiplayer::EntitySyncRewindEvent::Handler m_syncRewindHandler;
Multiplayer::EntityPreRenderEvent::Handler m_preRenderHandler;
AZ::TransformChangedEvent::Handler m_transformChangedHandler;
};
}
@@ -0,0 +1,68 @@
/*
* 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
*
*/
#pragma once
#include <Source/AutoGen/NetworkRigidBodyComponent.AutoComponent.h>
#include <AzCore/Component/TransformBus.h>
#include <Multiplayer/Components/NetBindComponent.h>
namespace Physics
{
class RigidBodyRequests;
}
namespace Multiplayer
{
//! Bus for requests to the network rigid body component.
class NetworkRigidBodyRequests : public AZ::ComponentBus
{
};
using NetworkRigidBodyRequestBus = AZ::EBus<NetworkRigidBodyRequests>;
class NetworkRigidBodyComponent final
: public NetworkRigidBodyComponentBase
, private NetworkRigidBodyRequestBus::Handler
{
friend class NetworkRigidBodyComponentController;
public:
AZ_MULTIPLAYER_COMPONENT(
Multiplayer::NetworkRigidBodyComponent, s_networkRigidBodyComponentConcreteUuid, Multiplayer::NetworkRigidBodyComponentBase);
static void Reflect(AZ::ReflectContext* context);
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
NetworkRigidBodyComponent();
void OnInit() override;
void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
private:
void OnTransformUpdate(const AZ::Transform& worldTm);
void OnSyncRewind();
Multiplayer::EntitySyncRewindEvent::Handler m_syncRewindHandler;
AZ::TransformChangedEvent::Handler m_transformChangedHandler;
Physics::RigidBodyRequests* m_physicsRigidBodyComponent = nullptr;
Multiplayer::RewindableObject<AZ::Transform, Multiplayer::RewindHistorySize> m_transform;
};
class NetworkRigidBodyComponentController
: public NetworkRigidBodyComponentControllerBase
{
public:
NetworkRigidBodyComponentController(NetworkRigidBodyComponent& parent);
void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
void HandleSendApplyImpulse(AzNetworking::IConnection* invokingConnection, const AZ::Vector3& impulse, const AZ::Vector3& worldPoint) override;
};
} // namespace Multiplayer