MultiplayerSampleSystemComponent.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 <Source/UserSettings/MultiplayerSampleUserSettings.h>
  18. #include <Multiplayer/Components/NetBindComponent.h>
  19. #include <AzFramework/Scene/Scene.h>
  20. #include <Atom/RPI.Public/Scene.h>
  21. namespace MultiplayerSample
  22. {
  23. using namespace AzNetworking;
  24. void MultiplayerSampleSystemComponent::Reflect(AZ::ReflectContext* context)
  25. {
  26. ReflectWeaponEnums(context);
  27. GatherParams::Reflect(context);
  28. HitEffect::Reflect(context);
  29. HitEntity::Reflect(context);
  30. HitEvent::Reflect(context);
  31. WeaponParams::Reflect(context);
  32. GameEffect::Reflect(context);
  33. GemSpawnable::Reflect(context);
  34. GemWeightChance::Reflect(context);
  35. RoundSpawnTable::Reflect(context);
  36. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  37. {
  38. serialize->Class<MultiplayerSampleSystemComponent, AZ::Component>()
  39. ->Version(0);
  40. if (AZ::EditContext* ec = serialize->GetEditContext())
  41. {
  42. ec->Class<MultiplayerSampleSystemComponent>("MultiplayerSample", "[Description of functionality provided by this System Component]")
  43. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  44. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System"))
  45. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  46. ;
  47. }
  48. }
  49. if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  50. {
  51. // This will put these methods into the 'azlmbr.atomtools.general' module
  52. auto addGeneral = [](AZ::BehaviorContext::GlobalMethodBuilder methodBuilder)
  53. {
  54. methodBuilder->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  55. ->Attribute(AZ::Script::Attributes::Category, "MultiplayerSample")
  56. ->Attribute(AZ::Script::Attributes::Module, "MultiplayerSample.general");
  57. };
  58. addGeneral(behaviorContext->Method(
  59. "GetRenderSceneIdByName", &MultiplayerSampleSystemComponent::GetRenderSceneIdByName, nullptr,
  60. "Gets an RPI scene ID based on the name of the AzFramework Scene."));
  61. }
  62. }
  63. void MultiplayerSampleSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  64. {
  65. provided.push_back(AZ_CRC_CE("MultiplayerSampleService"));
  66. }
  67. void MultiplayerSampleSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  68. {
  69. incompatible.push_back(AZ_CRC_CE("MultiplayerSampleService"));
  70. }
  71. void MultiplayerSampleSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  72. {
  73. required.push_back(AZ_CRC_CE("NetworkingService"));
  74. required.push_back(AZ_CRC_CE("MultiplayerService"));
  75. }
  76. void MultiplayerSampleSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  77. {
  78. // We're dependent on this to start first so that we can apply the MSAA setting at the correct point in the boot process.
  79. // If we're ever able to apply the MSAA setting at runtime, this can get removed, along with the call to ApplyMsaaSetting().
  80. dependent.push_back(AZ_CRC_CE("AzFrameworkConfigurationSystemComponentService"));
  81. }
  82. void MultiplayerSampleSystemComponent::Init()
  83. {
  84. ;
  85. }
  86. void MultiplayerSampleSystemComponent::Activate()
  87. {
  88. //! Register our gems multiplayer components to assign NetComponentIds
  89. RegisterMultiplayerComponents();
  90. // Tell the user settings that this is the correct point in the boot process to apply the MSAA setting.
  91. MultiplayerSampleUserSettingsRequestBus::Broadcast(
  92. &MultiplayerSampleUserSettingsRequestBus::Events::ApplyMsaaSetting);
  93. }
  94. void MultiplayerSampleSystemComponent::Deactivate()
  95. {
  96. }
  97. AZ::Uuid MultiplayerSampleSystemComponent::GetRenderSceneIdByName(const AZStd::string& name)
  98. {
  99. AZStd::shared_ptr<AzFramework::Scene> scene = AzFramework::SceneSystemInterface::Get()->GetScene(name);
  100. if (scene)
  101. {
  102. AZ::RPI::ScenePtr renderScene = *scene->FindSubsystemInScene<AZ::RPI::ScenePtr>();
  103. if (renderScene)
  104. {
  105. return renderScene->GetId();
  106. }
  107. }
  108. return AZ::Uuid::CreateInvalid();
  109. }
  110. }