AnimatedHitVolumesComponent.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * 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.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #pragma once
  8. #include <Source/AutoGen/AnimatedHitVolumesComponent.AutoComponent.h>
  9. #include <Multiplayer/Components/NetBindComponent.h>
  10. #include <Integration/ActorComponentBus.h>
  11. namespace Physics
  12. {
  13. class CharacterRequests;
  14. class CharacterHitDetectionConfiguration;
  15. }
  16. namespace MultiplayerSample
  17. {
  18. class AnimatedHitVolumesComponent
  19. : public AnimatedHitVolumesComponentBase
  20. , private EMotionFX::Integration::ActorComponentNotificationBus::Handler
  21. {
  22. public:
  23. struct AnimatedHitVolume final
  24. {
  25. AnimatedHitVolume
  26. (
  27. AzNetworking::ConnectionId connectionId,
  28. Physics::CharacterRequests* character,
  29. const char* hitVolumeName,
  30. const Physics::ColliderConfiguration* colliderConfig,
  31. const Physics::ShapeConfiguration* shapeConfig,
  32. const uint32_t jointIndex
  33. );
  34. ~AnimatedHitVolume() = default;
  35. void UpdateTransform(const AZ::Transform& transform);
  36. void SyncToCurrentTransform();
  37. Multiplayer::RewindableObject<AZ::Transform, Multiplayer::RewindHistorySize> m_transform;
  38. AZStd::shared_ptr<Physics::Shape> m_physicsShape;
  39. // Cached so we don't have to do subsequent lookups by name
  40. const Physics::ColliderConfiguration* m_colliderConfig = nullptr;
  41. const Physics::ShapeConfiguration* m_shapeConfig = nullptr;
  42. AZ::Transform m_colliderOffSetTransform;
  43. const AZ::u32 m_jointIndex = 0;
  44. };
  45. AZ_MULTIPLAYER_COMPONENT(MultiplayerSample::AnimatedHitVolumesComponent, s_animatedHitVolumesComponentConcreteUuid, MultiplayerSample::AnimatedHitVolumesComponentBase);
  46. static void Reflect(AZ::ReflectContext* context);
  47. AnimatedHitVolumesComponent();
  48. void OnInit() override;
  49. void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
  50. void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
  51. private:
  52. void OnPreRender(float deltaTime, float blendFactor);
  53. void OnTransformUpdate(const AZ::Transform& transform);
  54. void OnSyncRewind();
  55. void CreateHitVolumes();
  56. void DestroyHitVolumes();
  57. //! ActorComponentNotificationBus::Handler
  58. //! @{
  59. void OnActorInstanceCreated(EMotionFX::ActorInstance* actorInstance) override;
  60. void OnActorInstanceDestroyed(EMotionFX::ActorInstance* actorInstance) override;
  61. //! @}
  62. Physics::CharacterRequests* m_physicsCharacter = nullptr;
  63. EMotionFX::Integration::ActorComponentRequests* m_actorComponent = nullptr;
  64. const Physics::CharacterColliderConfiguration* m_hitDetectionConfig = nullptr;
  65. AZStd::vector<AnimatedHitVolume> m_animatedHitVolumes;
  66. Multiplayer::EntitySyncRewindEvent::Handler m_syncRewindHandler;
  67. Multiplayer::EntityPreRenderEvent::Handler m_preRenderHandler;
  68. };
  69. }