MultiplayerController.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/MultiplayerController.h>
  9. #include <Multiplayer/Components/MultiplayerComponent.h>
  10. #include <Multiplayer/Components/NetBindComponent.h>
  11. namespace Multiplayer
  12. {
  13. MultiplayerController::MultiplayerController(MultiplayerComponent& owner)
  14. : m_owner(owner)
  15. {
  16. ;
  17. }
  18. NetEntityId MultiplayerController::GetNetEntityId() const
  19. {
  20. return m_owner.GetNetEntityId();
  21. }
  22. bool MultiplayerController::IsNetEntityRoleAuthority() const
  23. {
  24. return GetNetBindComponent() ? GetNetBindComponent()->IsNetEntityRoleAuthority() : false;
  25. }
  26. bool MultiplayerController::IsNetEntityRoleAutonomous() const
  27. {
  28. return GetNetBindComponent() ? GetNetBindComponent()->IsNetEntityRoleAutonomous() : false;
  29. }
  30. AZ::Entity* MultiplayerController::GetEntity() const
  31. {
  32. return m_owner.GetEntity();
  33. }
  34. AZ::EntityId MultiplayerController::GetEntityId() const
  35. {
  36. return m_owner.GetEntityId();
  37. }
  38. ConstNetworkEntityHandle MultiplayerController::GetEntityHandle() const
  39. {
  40. return m_owner.GetEntityHandle();
  41. }
  42. NetworkEntityHandle MultiplayerController::GetEntityHandle()
  43. {
  44. return m_owner.GetEntityHandle();
  45. }
  46. const NetBindComponent* MultiplayerController::GetNetBindComponent() const
  47. {
  48. return m_owner.GetNetBindComponent();
  49. }
  50. NetBindComponent* MultiplayerController::GetNetBindComponent()
  51. {
  52. return m_owner.GetNetBindComponent();
  53. }
  54. const MultiplayerComponent& MultiplayerController::GetOwner() const
  55. {
  56. return m_owner;
  57. }
  58. MultiplayerComponent& MultiplayerController::GetOwner()
  59. {
  60. return m_owner;
  61. }
  62. bool MultiplayerController::IsProcessingInput() const
  63. {
  64. return GetNetBindComponent()->IsProcessingInput();
  65. }
  66. MultiplayerController* MultiplayerController::FindController(const AZ::Uuid& typeId, const NetworkEntityHandle& entityHandle) const
  67. {
  68. if (const AZ::Entity* entity = entityHandle.GetEntity())
  69. {
  70. MultiplayerComponent* component = azrtti_cast<MultiplayerComponent*>(entity->FindComponent(typeId));
  71. if (component != nullptr)
  72. {
  73. return component->GetController();
  74. }
  75. }
  76. return nullptr;
  77. }
  78. }