TestMultiplayerComponent.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #include <Tests/TestMultiplayerComponent.h>
  8. #include <AzCore/Serialization/SerializeContext.h>
  9. #include <Multiplayer/Components/NetBindComponent.h>
  10. namespace MultiplayerTest
  11. {
  12. void TestInputDriverComponent::Reflect(AZ::ReflectContext* context)
  13. {
  14. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
  15. if (serializeContext)
  16. {
  17. serializeContext->Class<TestInputDriverComponent, AZ::Component>()
  18. ->Version(1);
  19. }
  20. }
  21. void TestMultiplayerComponent::Reflect(AZ::ReflectContext* context)
  22. {
  23. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
  24. if (serializeContext)
  25. {
  26. serializeContext->Class<TestMultiplayerComponent, TestMultiplayerComponentBase>()
  27. ->Version(1);
  28. }
  29. TestMultiplayerComponentBase::Reflect(context);
  30. }
  31. void TestMultiplayerComponent::OnInit()
  32. {
  33. m_netBindComponent->AddNetworkActivatedEventHandler(m_networkActivatedHandler);
  34. }
  35. void TestMultiplayerComponent::OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
  36. {
  37. }
  38. void TestMultiplayerComponent::OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
  39. {
  40. }
  41. void TestMultiplayerComponent::OnNetworkActivated()
  42. {
  43. }
  44. TestMultiplayerComponentController::TestMultiplayerComponentController(TestMultiplayerComponent& parent)
  45. : TestMultiplayerComponentControllerBase(parent)
  46. {
  47. }
  48. void TestMultiplayerComponentController::OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
  49. {
  50. }
  51. void TestMultiplayerComponentController::OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
  52. {
  53. }
  54. void TestMultiplayerComponentController::CreateInput(Multiplayer::NetworkInput& input, [[maybe_unused]] float deltaTime)
  55. {
  56. if (auto* networkInput = input.FindComponentInput<TestMultiplayerComponentNetworkInput>(); networkInput)
  57. {
  58. networkInput->m_ownerId = GetParent().GetId();
  59. }
  60. if (const auto& component = GetParent(); component.m_createInputCallback)
  61. {
  62. component.m_createInputCallback(GetNetEntityId(), input, deltaTime);
  63. }
  64. }
  65. void TestMultiplayerComponentController::ProcessInput(Multiplayer::NetworkInput& input, [[maybe_unused]] float deltaTime)
  66. {
  67. const auto& component = GetParent();
  68. if (const auto* networkInput = input.FindComponentInput<TestMultiplayerComponentNetworkInput>(); networkInput)
  69. {
  70. AZ_Assert(
  71. networkInput->m_ownerId == component.GetId(),
  72. "Input Id doesn't match the owner component Id on entity %llu",
  73. aznumeric_cast<AZ::u64>(GetEntityId()));
  74. }
  75. if (component.m_processInputCallback)
  76. {
  77. component.m_processInputCallback(GetNetEntityId(), input, deltaTime);
  78. }
  79. }
  80. }