SequenceAgentComponentBus.h 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/Component/ComponentBus.h>
  10. #include <AzCore/EBus/EBus.h>
  11. #include <AzCore/std/string/string.h>
  12. #include <Maestro/Bus/SequenceComponentBus.h>
  13. namespace Maestro
  14. {
  15. /*!
  16. * SequenceAgentComponentRequests EBus Interface
  17. * Messages serviced by SequenceAgentComponents.
  18. *
  19. * The EBus is Id'ed on a pair of SequenceEntityId, SequenceAgentEntityId
  20. */
  21. //
  22. // SequenceComponents broadcast to SequenceAgentComponents via a pair of Ids:
  23. // sequenceEntityId, sequenceAgentEntityId
  24. using SequenceAgentEventBusId = AZStd::pair<AZ::EntityId, AZ::EntityId>; // SequenceComponenet Entity Id, SequenceAgent EntityId
  25. class SequenceAgentComponentBus
  26. : public AZ::EBusTraits
  27. {
  28. public:
  29. virtual ~SequenceAgentComponentBus() = default;
  30. //////////////////////////////////////////////////////////////////////////
  31. // EBusTraits overrides
  32. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
  33. typedef SequenceAgentEventBusId BusIdType;
  34. //////////////////////////////////////////////////////////////////////////
  35. };
  36. class SequenceAgentComponentRequests
  37. : public SequenceAgentComponentBus
  38. {
  39. public:
  40. using AnimatablePropertyAddress = Maestro::SequenceComponentRequests::AnimatablePropertyAddress;
  41. using AnimatedValue = Maestro::SequenceComponentRequests::AnimatedValue;
  42. //////////////////////////////////////////////////////////////////////////
  43. // EBusTraits overrides - application is a singleton
  44. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; // Only one component on a entity can implement the events
  45. //////////////////////////////////////////////////////////////////////////
  46. //! Called when a SequenceComponent is connected
  47. virtual void ConnectSequence(const AZ::EntityId& sequenceEntityId) = 0;
  48. //! Called when a SequenceComponent is disconnected
  49. virtual void DisconnectSequence() = 0;
  50. //! Get the value for an animated float property at the given address on the same entity as the agent.
  51. //! @param returnValue holds the value to get - this must be instance of one of the concrete subclasses of AnimatedValue, corresponding to the type of the property referenced by the animatedAdresss
  52. //! @param animatedAddress identifies the component and property to be set
  53. virtual void GetAnimatedPropertyValue(AnimatedValue& returnValue, const AnimatablePropertyAddress& animatableAddress) = 0;
  54. //! Set the value for an animated property at the given address on the same entity as the agent
  55. //! @param animatedAddress identifies the component and property to be set
  56. //! @param value the value to set - this must be instance of one of the concrete subclasses of AnimatedValue, corresponding to the type of the property referenced by the animatedAdresss
  57. //! @return true if the value was changed.
  58. virtual bool SetAnimatedPropertyValue(const AnimatablePropertyAddress& animatableAddress, const AnimatedValue& value) = 0;
  59. //! Returns the Uuid of the type that the 'getter' returns for this animatableAddress
  60. virtual AZ::Uuid GetAnimatedAddressTypeId(const Maestro::SequenceComponentRequests::AnimatablePropertyAddress& animatableAddress) = 0;
  61. //! Track View will expect some components (those using AZ::Data::AssetBlends as a virtual property) to supply a GetAssetDuration event
  62. //! so Track View can query the duration of an asset (like a motion) without having any knowledge of that that asset is.
  63. virtual void GetAssetDuration(AnimatedValue& returnValue, AZ::ComponentId componentId, const AZ::Data::AssetId& assetId) = 0;
  64. };
  65. using SequenceAgentComponentRequestBus = AZ::EBus<SequenceAgentComponentRequests>;
  66. } // namespace Maestro
  67. namespace AZStd
  68. {
  69. template <>
  70. struct hash < Maestro::SequenceAgentEventBusId >
  71. {
  72. inline size_t operator()(const Maestro::SequenceAgentEventBusId& eventBusId) const
  73. {
  74. AZStd::hash<AZ::EntityId> entityIdHasher;
  75. size_t retVal = entityIdHasher(eventBusId.first);
  76. AZStd::hash_combine(retVal, eventBusId.second);
  77. return retVal;
  78. }
  79. };
  80. }