3
0

NetworkInputChild.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 <Multiplayer/NetworkInput/NetworkInputChild.h>
  9. #include <Multiplayer/IMultiplayer.h>
  10. #include <AzNetworking/Serialization/ISerializer.h>
  11. namespace Multiplayer
  12. {
  13. NetworkInputChild::NetworkInputChild(const ConstNetworkEntityHandle& entityHandle)
  14. : m_owner(entityHandle)
  15. {
  16. Attach(m_owner);
  17. }
  18. NetworkInputChild& NetworkInputChild::operator= (const NetworkInputChild& rhs)
  19. {
  20. m_owner = rhs.m_owner;
  21. m_networkInput = rhs.m_networkInput;
  22. return *this;
  23. }
  24. bool NetworkInputChild::operator== (const NetworkInputChild& rhs) const
  25. {
  26. return m_owner == rhs.m_owner && m_networkInput.m_inputId == rhs.m_networkInput.m_inputId;
  27. }
  28. bool NetworkInputChild::operator!= (const NetworkInputChild& rhs) const
  29. {
  30. return !(m_owner == rhs.m_owner);
  31. }
  32. void NetworkInputChild::Attach(const ConstNetworkEntityHandle& entityHandle)
  33. {
  34. m_owner = entityHandle;
  35. NetBindComponent* netBindComponent = entityHandle.GetNetBindComponent();
  36. if (netBindComponent)
  37. {
  38. m_networkInput.AttachNetBindComponent(netBindComponent);
  39. }
  40. }
  41. const ConstNetworkEntityHandle& NetworkInputChild::GetOwner() const
  42. {
  43. return m_owner;
  44. }
  45. const NetworkInput& NetworkInputChild::GetNetworkInput() const
  46. {
  47. return m_networkInput;
  48. }
  49. NetworkInput& NetworkInputChild::GetNetworkInput()
  50. {
  51. return m_networkInput;
  52. }
  53. bool NetworkInputChild::Serialize(AzNetworking::ISerializer& serializer)
  54. {
  55. NetEntityId ownerId = m_owner.GetNetEntityId();
  56. serializer.Serialize(ownerId, "OwnerId");
  57. if (serializer.GetSerializerMode() == AzNetworking::SerializerMode::WriteToObject)
  58. {
  59. m_owner = GetNetworkEntityManager()->GetEntity(ownerId);
  60. }
  61. serializer.Serialize(m_networkInput, "NetworkInput");
  62. return serializer.IsValid();
  63. }
  64. }