MultiplayerComponent.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/Components/MultiplayerComponent.h>
  9. #include <Multiplayer/Components/NetBindComponent.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. namespace Multiplayer
  12. {
  13. MultiplayerComponent::MultiplayerComponent()
  14. : m_networkActivatedHandler([this]() { OnNetworkActivated(); })
  15. {
  16. ;
  17. }
  18. void MultiplayerComponent::Reflect(AZ::ReflectContext* context)
  19. {
  20. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
  21. if (serializeContext)
  22. {
  23. serializeContext->Class<MultiplayerComponent, AZ::Component>()
  24. ->Version(1);
  25. }
  26. }
  27. void MultiplayerComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  28. {
  29. required.push_back(AZ_CRC_CE("NetBindService"));
  30. }
  31. const NetBindComponent* MultiplayerComponent::GetNetBindComponent() const
  32. {
  33. return m_netBindComponent;
  34. }
  35. NetBindComponent* MultiplayerComponent::GetNetBindComponent()
  36. {
  37. return m_netBindComponent;
  38. }
  39. NetEntityId MultiplayerComponent::GetNetEntityId() const
  40. {
  41. return m_netBindComponent ? m_netBindComponent->GetNetEntityId() : InvalidNetEntityId;
  42. }
  43. bool MultiplayerComponent::IsNetEntityRoleAuthority() const
  44. {
  45. return m_netBindComponent ? m_netBindComponent->IsNetEntityRoleAuthority() : false;
  46. }
  47. bool MultiplayerComponent::IsNetEntityRoleAutonomous() const
  48. {
  49. return m_netBindComponent ? m_netBindComponent->IsNetEntityRoleAutonomous() : false;
  50. }
  51. bool MultiplayerComponent::IsNetEntityRoleServer() const
  52. {
  53. return m_netBindComponent ? m_netBindComponent->IsNetEntityRoleServer() : false;
  54. }
  55. bool MultiplayerComponent::IsNetEntityRoleClient() const
  56. {
  57. return m_netBindComponent ? m_netBindComponent->IsNetEntityRoleClient() : false;
  58. }
  59. ConstNetworkEntityHandle MultiplayerComponent::GetEntityHandle() const
  60. {
  61. const NetBindComponent* netBindComponent = GetNetBindComponent();
  62. return netBindComponent ? netBindComponent->GetEntityHandle() : ConstNetworkEntityHandle();
  63. }
  64. NetworkEntityHandle MultiplayerComponent::GetEntityHandle()
  65. {
  66. NetBindComponent* netBindComponent = GetNetBindComponent();
  67. return netBindComponent ? netBindComponent->GetEntityHandle() : NetworkEntityHandle();
  68. }
  69. void MultiplayerComponent::MarkDirty()
  70. {
  71. NetBindComponent* netBindComponent = GetNetBindComponent();
  72. if (netBindComponent != nullptr)
  73. {
  74. netBindComponent->MarkDirty();
  75. }
  76. }
  77. }