MultiplayerSampleSystemComponent.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 "MultiplayerSampleSystemComponent.h"
  8. #include <AzCore/Console/ILogger.h>
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <AzCore/Serialization/EditContext.h>
  11. #include <AzCore/Serialization/EditContextConstants.inl>
  12. #include <Source/AutoGen/AutoComponentTypes.h>
  13. #include <Source/Weapons/WeaponTypes.h>
  14. #include <Source/Components/NetworkStressTestComponent.h>
  15. #include <Source/Components/NetworkAiComponent.h>
  16. #include <Source/Effects/GameEffect.h>
  17. #include <Multiplayer/Components/NetBindComponent.h>
  18. #include <AzFramework/Scene/Scene.h>
  19. #include <Atom/RPI.Public/Scene.h>
  20. namespace MultiplayerSample
  21. {
  22. using namespace AzNetworking;
  23. void MultiplayerSampleSystemComponent::Reflect(AZ::ReflectContext* context)
  24. {
  25. ReflectWeaponEnums(context);
  26. GatherParams::Reflect(context);
  27. HitEffect::Reflect(context);
  28. HitEntity::Reflect(context);
  29. HitEvent::Reflect(context);
  30. WeaponParams::Reflect(context);
  31. GameEffect::Reflect(context);
  32. GemSpawnable::Reflect(context);
  33. GemWeightChance::Reflect(context);
  34. RoundSpawnTable::Reflect(context);
  35. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  36. {
  37. serialize->Class<MultiplayerSampleSystemComponent, AZ::Component>()
  38. ->Version(0);
  39. if (AZ::EditContext* ec = serialize->GetEditContext())
  40. {
  41. ec->Class<MultiplayerSampleSystemComponent>("MultiplayerSample", "[Description of functionality provided by this System Component]")
  42. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  43. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System"))
  44. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  45. ;
  46. }
  47. }
  48. if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  49. {
  50. // This will put these methods into the 'azlmbr.atomtools.general' module
  51. auto addGeneral = [](AZ::BehaviorContext::GlobalMethodBuilder methodBuilder)
  52. {
  53. methodBuilder->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  54. ->Attribute(AZ::Script::Attributes::Category, "MultiplayerSample")
  55. ->Attribute(AZ::Script::Attributes::Module, "MultiplayerSample.general");
  56. };
  57. addGeneral(behaviorContext->Method(
  58. "GetRenderSceneIdByName", &MultiplayerSampleSystemComponent::GetRenderSceneIdByName, nullptr,
  59. "Gets an RPI scene ID based on the name of the AzFramework Scene."));
  60. }
  61. }
  62. void MultiplayerSampleSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  63. {
  64. provided.push_back(AZ_CRC_CE("MultiplayerSampleService"));
  65. }
  66. void MultiplayerSampleSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  67. {
  68. incompatible.push_back(AZ_CRC_CE("MultiplayerSampleService"));
  69. }
  70. void MultiplayerSampleSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  71. {
  72. required.push_back(AZ_CRC_CE("NetworkingService"));
  73. required.push_back(AZ_CRC_CE("MultiplayerService"));
  74. }
  75. void MultiplayerSampleSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  76. {
  77. AZ_UNUSED(dependent);
  78. }
  79. void MultiplayerSampleSystemComponent::Init()
  80. {
  81. ;
  82. }
  83. void MultiplayerSampleSystemComponent::Activate()
  84. {
  85. //! Register our gems multiplayer components to assign NetComponentIds
  86. RegisterMultiplayerComponents();
  87. }
  88. void MultiplayerSampleSystemComponent::Deactivate()
  89. {
  90. }
  91. AZ::Uuid MultiplayerSampleSystemComponent::GetRenderSceneIdByName(const AZStd::string& name)
  92. {
  93. AZStd::shared_ptr<AzFramework::Scene> scene = AzFramework::SceneSystemInterface::Get()->GetScene(name);
  94. if (scene)
  95. {
  96. AZ::RPI::ScenePtr renderScene = *scene->FindSubsystemInScene<AZ::RPI::ScenePtr>();
  97. if (renderScene)
  98. {
  99. return renderScene->GetId();
  100. }
  101. }
  102. return AZ::Uuid::CreateInvalid();
  103. }
  104. }