TestMultiplayerComponent.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #pragma once
  8. #include <Tests/AutoGen/TestMultiplayerComponent.AutoComponent.h>
  9. namespace MultiplayerTest
  10. {
  11. // Dummy class for satisfying "MultiplayerInputDriver" component dependency
  12. class TestInputDriverComponent : public AZ::Component
  13. {
  14. public:
  15. AZ_COMPONENT(TestInputDriverComponent, "{C3877905-3B61-45AE-A636-9845C3AAA39D}");
  16. static void Reflect(AZ::ReflectContext* context);
  17. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  18. {
  19. provided.emplace_back(AZ_CRC_CE("MultiplayerInputDriver"));
  20. }
  21. void Activate() override {}
  22. void Deactivate() override {}
  23. };
  24. // Test multiplayer component with ability to create and process network input
  25. class TestMultiplayerComponent
  26. : public TestMultiplayerComponentBase
  27. {
  28. public:
  29. AZ_MULTIPLAYER_COMPONENT(MultiplayerTest::TestMultiplayerComponent, s_testMultiplayerComponentConcreteUuid, MultiplayerTest::TestMultiplayerComponentBase);
  30. static void Reflect(AZ::ReflectContext* context);
  31. void OnInit() override;
  32. void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
  33. void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
  34. void OnNetworkActivated() override;
  35. AZStd::function<void(Multiplayer::NetEntityId, Multiplayer::NetworkInput& input, float deltaTime)> m_createInputCallback;
  36. AZStd::function<void(Multiplayer::NetEntityId, Multiplayer::NetworkInput& input, float deltaTime)> m_processInputCallback;
  37. };
  38. // Multiplayer controller for the test component
  39. class TestMultiplayerComponentController
  40. : public TestMultiplayerComponentControllerBase
  41. {
  42. public:
  43. TestMultiplayerComponentController(TestMultiplayerComponent& parent);
  44. //! TestMultiplayerComponentControllerBase
  45. void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
  46. void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
  47. //! MultiplayerController interface
  48. void CreateInput(Multiplayer::NetworkInput& input, float deltaTime) override;
  49. void ProcessInput(Multiplayer::NetworkInput& input, float deltaTime) override;
  50. };
  51. }