NullReplicationWindow.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/ReplicationWindows/NullReplicationWindow.h>
  9. #include <Source/AutoGen/Multiplayer.AutoPackets.h>
  10. namespace Multiplayer
  11. {
  12. NullReplicationWindow::NullReplicationWindow(AzNetworking::IConnection* connection)
  13. : m_connection(connection)
  14. {
  15. ;
  16. }
  17. bool NullReplicationWindow::ReplicationSetUpdateReady()
  18. {
  19. return true;
  20. }
  21. const ReplicationSet& NullReplicationWindow::GetReplicationSet() const
  22. {
  23. return m_emptySet;
  24. }
  25. uint32_t NullReplicationWindow::GetMaxProxyEntityReplicatorSendCount() const
  26. {
  27. return 0;
  28. }
  29. bool NullReplicationWindow::IsInWindow([[maybe_unused]] const ConstNetworkEntityHandle& entityHandle, NetEntityRole& outNetworkRole) const
  30. {
  31. outNetworkRole = NetEntityRole::InvalidRole;
  32. return false;
  33. }
  34. bool NullReplicationWindow::AddEntity([[maybe_unused]] AZ::Entity* entity)
  35. {
  36. return false;
  37. }
  38. void NullReplicationWindow::RemoveEntity([[maybe_unused]] AZ::Entity* entity)
  39. {
  40. ;
  41. }
  42. void NullReplicationWindow::UpdateWindow()
  43. {
  44. ;
  45. }
  46. AzNetworking::PacketId NullReplicationWindow::SendEntityUpdateMessages(NetworkEntityUpdateVector& entityUpdateVector)
  47. {
  48. MultiplayerPackets::EntityUpdates entityUpdatePacket;
  49. entityUpdatePacket.SetHostTimeMs(GetNetworkTime()->GetHostTimeMs());
  50. entityUpdatePacket.SetHostFrameId(GetNetworkTime()->GetHostFrameId());
  51. entityUpdatePacket.SetEntityMessages(entityUpdateVector);
  52. return m_connection->SendUnreliablePacket(entityUpdatePacket);
  53. }
  54. void NullReplicationWindow::SendEntityRpcs(NetworkEntityRpcVector& entityRpcVector, bool reliable)
  55. {
  56. MultiplayerPackets::EntityRpcs entityRpcsPacket;
  57. entityRpcsPacket.SetEntityRpcs(entityRpcVector);
  58. if (reliable)
  59. {
  60. m_connection->SendReliablePacket(entityRpcsPacket);
  61. }
  62. else
  63. {
  64. m_connection->SendUnreliablePacket(entityRpcsPacket);
  65. }
  66. }
  67. void NullReplicationWindow::SendEntityResets(const NetEntityIdSet& resetIds)
  68. {
  69. MultiplayerPackets::RequestReplicatorReset entityResetPacket;
  70. for (NetEntityId entityId : resetIds)
  71. {
  72. if (entityResetPacket.GetEntityIds().full())
  73. {
  74. m_connection->SendUnreliablePacket(entityResetPacket);
  75. entityResetPacket.ModifyEntityIds().clear();
  76. }
  77. entityResetPacket.ModifyEntityIds().push_back(entityId);
  78. }
  79. if (!entityResetPacket.GetEntityIds().empty())
  80. {
  81. m_connection->SendUnreliablePacket(entityResetPacket);
  82. }
  83. }
  84. void NullReplicationWindow::DebugDraw() const
  85. {
  86. // Nothing to draw
  87. }
  88. }