PropertySubscriber.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #include <Source/NetworkEntity/EntityReplication/PropertySubscriber.h>
  9. #include <Multiplayer/NetworkEntity/EntityReplication/EntityReplicationManager.h>
  10. #include <Multiplayer/Components/NetBindComponent.h>
  11. namespace Multiplayer
  12. {
  13. PropertySubscriber::PropertySubscriber(EntityReplicationManager& replicationManager, NetBindComponent* netBindComponent)
  14. : m_replicationManager(replicationManager)
  15. , m_netBindComponent(netBindComponent)
  16. {
  17. ;
  18. }
  19. AzNetworking::PacketId PropertySubscriber::GetLastReceivedPacketId() const
  20. {
  21. return m_lastReceivedPacketId;
  22. }
  23. bool PropertySubscriber::IsDeleting() const
  24. {
  25. return m_markForRemovalTimeMs > AZ::Time::ZeroTimeMs;
  26. }
  27. bool PropertySubscriber::IsDeleted() const
  28. {
  29. return m_markForRemovalTimeMs < m_replicationManager.GetFrameTimeMs();
  30. }
  31. void PropertySubscriber::SetDeleting()
  32. {
  33. m_markForRemovalTimeMs = AZ::TimeMs(m_replicationManager.GetFrameTimeMs() + m_replicationManager.GetResendTimeoutTimeMs());
  34. }
  35. bool PropertySubscriber::IsPacketIdValid(AzNetworking::PacketId packetId) const
  36. {
  37. return m_lastReceivedPacketId == AzNetworking::InvalidPacketId || packetId > m_lastReceivedPacketId;
  38. }
  39. bool PropertySubscriber::HandlePropertyChangeMessage(AzNetworking::PacketId packetId, AzNetworking::ISerializer* serializer, bool notifyChanges)
  40. {
  41. AZ_Assert(IsPacketIdValid(packetId), "Packet expected to be valid");
  42. m_lastReceivedPacketId = packetId;
  43. return m_netBindComponent->HandlePropertyChangeMessage(*serializer, notifyChanges);
  44. }
  45. }