MultiplayerCompressionSystemComponent.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 <AzCore/Interface/Interface.h>
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <AzCore/Serialization/EditContext.h>
  11. #include <AzCore/std/smart_ptr/make_shared.h>
  12. #include <AzNetworking/Framework/INetworking.h>
  13. #include "MultiplayerCompressionSystemComponent.h"
  14. #include "LZ4Compressor.h"
  15. #include "MultiplayerCompressionFactory.h"
  16. namespace MultiplayerCompression
  17. {
  18. void MultiplayerCompressionSystemComponent::Reflect(AZ::ReflectContext* context)
  19. {
  20. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  21. {
  22. serialize->Class<MultiplayerCompressionSystemComponent, AZ::Component>()
  23. ->Version(0)
  24. ;
  25. if (AZ::EditContext* ec = serialize->GetEditContext())
  26. {
  27. ec->Class<MultiplayerCompressionSystemComponent>("MultiplayerCompression", "Provides packet compression via an open source library for the Multiplayer Gem")
  28. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  29. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  30. ;
  31. }
  32. }
  33. }
  34. void MultiplayerCompressionSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  35. {
  36. provided.push_back(AZ_CRC_CE("MultiplayerCompressionService"));
  37. }
  38. void MultiplayerCompressionSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  39. {
  40. incompatible.push_back(AZ_CRC_CE("MultiplayerCompressionService"));
  41. }
  42. MultiplayerCompressionSystemComponent::MultiplayerCompressionSystemComponent()
  43. {
  44. m_multiplayerCompressionFactory = new MultiplayerCompressionFactory();
  45. AZ::Interface<AzNetworking::INetworking>::Get()->RegisterCompressorFactory(m_multiplayerCompressionFactory);
  46. }
  47. MultiplayerCompressionSystemComponent::~MultiplayerCompressionSystemComponent()
  48. {
  49. AZ::Interface<AzNetworking::INetworking>::Get()->UnregisterCompressorFactory(m_multiplayerCompressionFactory->GetFactoryName());
  50. delete m_multiplayerCompressionFactory;
  51. }
  52. }