Integrating latest 47acbe8
This commit is contained in:
-45
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/EBus/EBus.h>
|
||||
#include <AzNetworking/Framework/ICompressor.h>
|
||||
|
||||
namespace AzNetworking
|
||||
{
|
||||
class ICompressorFactory;
|
||||
}
|
||||
|
||||
namespace MultiplayerCompression
|
||||
{
|
||||
class MultiplayerCompressionRequests
|
||||
: public AZ::EBusTraits
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// EBusTraits overrides
|
||||
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
|
||||
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Fetch the string Name of this Compressor
|
||||
virtual AZStd::string GetCompressorName() = 0;
|
||||
|
||||
// Fetch the CompressorType used to identify this Compressor
|
||||
virtual AzNetworking::CompressorType GetCompressorType() = 0;
|
||||
|
||||
// Fetch a CompressionFactory that can serve a shared_ptr Compressor
|
||||
virtual AZStd::shared_ptr<AzNetworking::ICompressorFactory> GetCompressionFactory() = 0;
|
||||
};
|
||||
using MultiplayerCompressionRequestBus = AZ::EBus<MultiplayerCompressionRequests>;
|
||||
} // namespace MultiplayerCompression
|
||||
@@ -21,4 +21,9 @@ namespace MultiplayerCompression
|
||||
{
|
||||
return AZStd::make_unique<LZ4Compressor>();
|
||||
}
|
||||
|
||||
AZ::Name MultiplayerCompressionFactory::GetFactoryName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,15 @@ namespace MultiplayerCompression
|
||||
: public AzNetworking::ICompressorFactory
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Instantiate a new compressor
|
||||
*/
|
||||
//! Instantiate a new compressor
|
||||
//! @return A unique_ptr to a new Compressor
|
||||
AZStd::unique_ptr<AzNetworking::ICompressor> Create() override;
|
||||
|
||||
//! Gets the AZ Name of this compressor factory
|
||||
//! @return the AZ Name of this compressor factory
|
||||
AZ::Name GetFactoryName() const override;
|
||||
|
||||
private:
|
||||
const AZ::Name m_name = AZ::Name("MultiplayerCompressor");
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzCore/std/smart_ptr/make_shared.h>
|
||||
#include <AzNetworking/Framework/INetworking.h>
|
||||
|
||||
#include "MultiplayerCompressionSystemComponent.h"
|
||||
#include "LZ4Compressor.h"
|
||||
@@ -49,35 +51,15 @@ namespace MultiplayerCompression
|
||||
incompatible.push_back(AZ_CRC("MultiplayerCompressionService"));
|
||||
}
|
||||
|
||||
void MultiplayerCompressionSystemComponent::Init()
|
||||
MultiplayerCompressionSystemComponent::MultiplayerCompressionSystemComponent()
|
||||
{
|
||||
m_multiplayerCompressionFactory = AZStd::make_shared<MultiplayerCompressionFactory>();
|
||||
m_multiplayerCompressionFactory = new MultiplayerCompressionFactory();
|
||||
AZ::Interface<AzNetworking::INetworking>::Get()->RegisterCompressorFactory(m_multiplayerCompressionFactory);
|
||||
}
|
||||
|
||||
void MultiplayerCompressionSystemComponent::Activate()
|
||||
MultiplayerCompressionSystemComponent::~MultiplayerCompressionSystemComponent()
|
||||
{
|
||||
MultiplayerCompressionRequestBus::Handler::BusConnect();
|
||||
}
|
||||
|
||||
void MultiplayerCompressionSystemComponent::Deactivate()
|
||||
{
|
||||
MultiplayerCompressionRequestBus::Handler::BusDisconnect();
|
||||
|
||||
m_multiplayerCompressionFactory.reset();
|
||||
}
|
||||
|
||||
AZStd::string MultiplayerCompressionSystemComponent::GetCompressorName()
|
||||
{
|
||||
return CompressorName;
|
||||
}
|
||||
|
||||
AzNetworking::CompressorType MultiplayerCompressionSystemComponent::GetCompressorType()
|
||||
{
|
||||
return CompressorType;
|
||||
}
|
||||
|
||||
AZStd::shared_ptr<AzNetworking::ICompressorFactory> MultiplayerCompressionSystemComponent::GetCompressionFactory()
|
||||
{
|
||||
return m_multiplayerCompressionFactory;
|
||||
AZ::Interface<AzNetworking::INetworking>::Get()->UnregisterCompressorFactory(m_multiplayerCompressionFactory->GetFactoryName());
|
||||
delete m_multiplayerCompressionFactory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include <AzCore/Component/Component.h>
|
||||
#include <AzCore/std/containers/unordered_set.h>
|
||||
|
||||
#include <MultiplayerCompression/MultiplayerCompressionBus.h>
|
||||
#include <MultiplayerCompressionFactory.h>
|
||||
|
||||
namespace MultiplayerCompression
|
||||
@@ -26,32 +25,25 @@ namespace MultiplayerCompression
|
||||
*/
|
||||
class MultiplayerCompressionSystemComponent
|
||||
: public AZ::Component
|
||||
, protected MultiplayerCompressionRequestBus::Handler
|
||||
{
|
||||
public:
|
||||
AZ_COMPONENT(MultiplayerCompressionSystemComponent, "{C3099AC9-47A6-41D2-8928-F38F904BAC1B}");
|
||||
|
||||
MultiplayerCompressionSystemComponent();
|
||||
~MultiplayerCompressionSystemComponent() override;
|
||||
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
|
||||
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
|
||||
|
||||
protected:
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// MultiplayerCompressionRequestBus interface implementation
|
||||
AZStd::string GetCompressorName() override;
|
||||
AzNetworking::CompressorType GetCompressorType() override;
|
||||
AZStd::shared_ptr<AzNetworking::ICompressorFactory> GetCompressionFactory() override;
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// AZ::Component interface implementation
|
||||
void Init() override;
|
||||
void Activate() override;
|
||||
void Deactivate() override;
|
||||
void Init() override {}
|
||||
void Activate() override {}
|
||||
void Deactivate() override {}
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private:
|
||||
AZStd::shared_ptr<MultiplayerCompressionFactory> m_multiplayerCompressionFactory;
|
||||
MultiplayerCompressionFactory* m_multiplayerCompressionFactory;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -13,9 +13,11 @@
|
||||
#include <lz4.h>
|
||||
#include <AzCore/UnitTest/TestTypes.h>
|
||||
|
||||
#include <MultiplayerCompression/MultiplayerCompressionBus.h>
|
||||
#include <LZ4Compressor.h>
|
||||
|
||||
#include <AzCore/Compression/Compression.h>
|
||||
#include <AzNetworking/DataStructures/ByteBuffer.h>
|
||||
#include <AzNetworking/Serialization/NetworkInputSerializer.h>
|
||||
#include <AzTest/AzTest.h>
|
||||
|
||||
class MultiplayerCompressionTest
|
||||
@@ -23,8 +25,6 @@ class MultiplayerCompressionTest
|
||||
{
|
||||
protected:
|
||||
|
||||
static const int MAX_BUFFER_SIZE = 512;
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
AllocatorsTestFixture::SetUp();
|
||||
@@ -38,30 +38,24 @@ protected:
|
||||
|
||||
TEST_F(MultiplayerCompressionTest, MultiplayerCompression_CompressTest)
|
||||
{
|
||||
// [SPEC-3870] Revisit this test once higher level layers are implemented to see if it can be repurposed
|
||||
/*
|
||||
GridMate::WriteBufferDynamic wb(AzNetworking::EndianType::IgnoreEndian);
|
||||
AzNetworking::UdpPacketEncodingBuffer buffer;
|
||||
buffer.Resize(buffer.GetCapacity());
|
||||
|
||||
// Setup and marshal a highly compressable buffer for LZ4
|
||||
AZStd::chrono::system_clock::time_point startTime = AZStd::chrono::system_clock::now();
|
||||
GridMate::Marshaler<int> marshaler;
|
||||
for (int i = 0; i < MAX_BUFFER_SIZE; ++i)
|
||||
{
|
||||
marshaler.Marshal(wb, 1);
|
||||
}
|
||||
const AZ::u64 marshalTime = (AZStd::chrono::system_clock::now() - startTime).count();
|
||||
memset(buffer.GetBuffer(), 255, buffer.GetCapacity());
|
||||
|
||||
size_t maxCompressedSize = wb.Size() + 32U;
|
||||
size_t maxCompressedSize = buffer.GetSize() + 32U;
|
||||
size_t compressedSize = -1;
|
||||
size_t uncompressedSize = -1;
|
||||
size_t consumedSize = -1;
|
||||
char* pCompressedBuffer = new char[maxCompressedSize];
|
||||
char* pDecompressedBuffer = new char[wb.Size()];
|
||||
char* pDecompressedBuffer = new char[buffer.GetSize()];
|
||||
|
||||
//Run and test compress
|
||||
MultiplayerCompression::LZ4Compressor lz4Compressor;
|
||||
startTime = AZStd::chrono::system_clock::now();
|
||||
AzNetworking::CompressorError compressStatus = lz4Compressor.Compress(wb.Get(), wb.Size(), pCompressedBuffer, maxCompressedSize, compressedSize);
|
||||
AzNetworking::CompressorError compressStatus = lz4Compressor.Compress(buffer.GetBuffer(), buffer.GetSize(), pCompressedBuffer, maxCompressedSize, compressedSize);
|
||||
const AZ::u64 compressTime = (AZStd::chrono::system_clock::now() - startTime).count();
|
||||
|
||||
ASSERT_TRUE(compressStatus == AzNetworking::CompressorError::Ok);
|
||||
@@ -69,24 +63,13 @@ TEST_F(MultiplayerCompressionTest, MultiplayerCompression_CompressTest)
|
||||
|
||||
//Run and test decompress
|
||||
startTime = AZStd::chrono::system_clock::now();
|
||||
AzNetworking::CompressorError decompressStatus = lz4Compressor.Decompress(pCompressedBuffer, compressedSize, pDecompressedBuffer, wb.Size(), consumedSize, uncompressedSize);
|
||||
AzNetworking::CompressorError decompressStatus = lz4Compressor.Decompress(pCompressedBuffer, compressedSize, pDecompressedBuffer, buffer.GetSize(), consumedSize, uncompressedSize);
|
||||
const AZ::u64 decompressTime = (AZStd::chrono::system_clock::now() - startTime).count();
|
||||
|
||||
ASSERT_TRUE(decompressStatus == AzNetworking::CompressorError::Ok);
|
||||
EXPECT_TRUE(uncompressedSize = wb.Size());
|
||||
EXPECT_TRUE(memcmp(pDecompressedBuffer, wb.Get(), uncompressedSize) == 0);
|
||||
EXPECT_TRUE(uncompressedSize = buffer.GetSize());
|
||||
EXPECT_TRUE(memcmp(pDecompressedBuffer, buffer.GetBuffer(), uncompressedSize) == 0);
|
||||
|
||||
|
||||
GridMate::ReadBuffer rb(GridMate::EndianType::IgnoreEndian, pDecompressedBuffer, wb.Size());
|
||||
|
||||
//Calculate unmarshal time for data's sake
|
||||
startTime = AZStd::chrono::system_clock::now();
|
||||
for (int i = 0; i < MAX_BUFFER_SIZE; ++i)
|
||||
{
|
||||
int testVal1;
|
||||
marshaler.Unmarshal(testVal1, rb);
|
||||
EXPECT_TRUE(testVal1 == 1);
|
||||
}
|
||||
const AZ::u64 unmarshalTime = (AZStd::chrono::system_clock::now() - startTime).count();
|
||||
|
||||
delete [] pCompressedBuffer;
|
||||
@@ -95,15 +78,10 @@ TEST_F(MultiplayerCompressionTest, MultiplayerCompression_CompressTest)
|
||||
//Expected [Profile]: Uncompressed Size: 2048 B Compressed Size: 21 B
|
||||
AZ_TracePrintf("Multiplayer Compression Test", "Uncompressed Size:(%llu B) Compressed Size:(%llu B) \n", uncompressedSize, compressedSize);
|
||||
//Expected [Profile]: Marshal Time : 84 mcs Unmarshal Time : 98 mcs Compress Time : 182 mcs Decompress Time : 7 mcs (times will vary with hardware)
|
||||
AZ_TracePrintf("Multiplayer Compression Test", "Marshal Time:(%llu mcs) Unmarshal Time:(%llu mcs) Compress Time:(%llu mcs) Decompress Time:(%llu mcs) \n", marshalTime, unmarshalTime, compressTime, decompressTime);
|
||||
*/
|
||||
AZ_TracePrintf("Multiplayer Compression Test", "Compress Time:(%llu mcs) Decompress Time:(%llu mcs) \n", compressTime, decompressTime);
|
||||
}
|
||||
|
||||
#if AZ_TRAIT_DISABLE_FAILED_MULTIPLAYER_COMPRESSION_TESTS
|
||||
TEST_F(MultiplayerCompressionTest, DISABLED_MultiplayerCompression_OversizeTest)
|
||||
#else
|
||||
TEST_F(MultiplayerCompressionTest, MultiplayerCompression_OversizeTest)
|
||||
#endif
|
||||
{
|
||||
size_t badInputSize = LZ4_MAX_INPUT_SIZE + 1;
|
||||
size_t bufferSize = 4;
|
||||
@@ -122,11 +100,7 @@ TEST_F(MultiplayerCompressionTest, MultiplayerCompression_OversizeTest)
|
||||
delete [] pBuffer;
|
||||
}
|
||||
|
||||
#if AZ_TRAIT_DISABLE_FAILED_MULTIPLAYER_COMPRESSION_TESTS
|
||||
TEST_F(MultiplayerCompressionTest, DISABLED_MultiplayerCompressionTest_UndersizeTest)
|
||||
#else
|
||||
TEST_F(MultiplayerCompressionTest, MultiplayerCompressionTest_UndersizeTest)
|
||||
#endif
|
||||
{
|
||||
size_t badInputSize = LZ4_MAX_INPUT_SIZE + 1;
|
||||
size_t bufferSize = 4;
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#
|
||||
|
||||
set(FILES
|
||||
Include/MultiplayerCompression/MultiplayerCompressionBus.h
|
||||
Source/LZ4Compressor.cpp
|
||||
Source/LZ4Compressor.h
|
||||
Source/MultiplayerCompressionFactory.cpp
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"gem_name": "MultiplayerCompression",
|
||||
"GemFormatVersion": 4,
|
||||
"Uuid": "1d353c8ca3c74ed193fd6c6783ae41cc",
|
||||
"Name": "MultiplayerCompression",
|
||||
|
||||
Reference in New Issue
Block a user