Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,68 @@
#
# 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.
#
set(LY_ENABLE_MULTIPLAYER_COMPRESSION OFF CACHE BOOL "Enables usage of Multiplayer Compressor.")
ly_add_target(
NAME MultiplayerCompression.Static STATIC
NAMESPACE Gem
FILES_CMAKE
multiplayercompression_files.cmake
INCLUDE_DIRECTORIES
PRIVATE
Source
PUBLIC
Include
BUILD_DEPENDENCIES
PUBLIC
3rdParty::lz4
AZ::AzNetworking
AZ::AzCore
)
ly_add_target(
NAME MultiplayerCompression ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
NAMESPACE Gem
OUTPUT_NAME Gem.MultiplayerCompression.1d353c8ca3c74ed193fd6c6783ae41cc.v0.1.0
FILES_CMAKE
multiplayercompression_shared_files.cmake
INCLUDE_DIRECTORIES
PRIVATE
Source
PUBLIC
Include
BUILD_DEPENDENCIES
PRIVATE
Gem::MultiplayerCompression.Static
)
################################################################################
# Tests
################################################################################
if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
ly_add_target(
NAME MultiplayerCompression.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
NAMESPACE Gem
FILES_CMAKE
multiplayercompression_tests_files.cmake
INCLUDE_DIRECTORIES
PRIVATE
Source
Tests
BUILD_DEPENDENCIES
PRIVATE
AZ::AzTest
Gem::MultiplayerCompression.Static
)
ly_add_googletest(
NAME Gem::MultiplayerCompression.Tests
)
endif()
@@ -0,0 +1,45 @@
/*
* 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
@@ -0,0 +1,105 @@
/*
* 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.
*
*/
#include "LZ4Compressor.h"
#include <lz4.h>
#include <lz4hc.h>
namespace MultiplayerCompression
{
size_t LZ4Compressor::GetMaxChunkSize(size_t maxCompSize) const
{
return maxCompSize;
}
size_t LZ4Compressor::GetMaxCompressedBufferSize(size_t uncompSize) const
{
return LZ4_compressBound(uncompSize);
}
AzNetworking::CompressorError LZ4Compressor::Compress
(
const void* uncompData,
size_t uncompSize,
void* compData,
[[maybe_unused]] size_t compDataSize,
size_t& compSize
)
{
if (uncompData == nullptr)
{
// LZ4 actually never checks for this
AZ_Warning("Multiplayer Compressor", false, "Input buffer is uninitialized");
return AzNetworking::CompressorError::Uninitialized;
}
if (compData == nullptr)
{
// LZ4 actually never checks for this
AZ_Warning("Multiplayer Compressor", false, "Output buffer is uninitialized");
return AzNetworking::CompressorError::Uninitialized;
}
const int compWorstCaseSize = LZ4_compressBound(uncompSize);
if (compWorstCaseSize == 0)
{
AZ_Warning("Multiplayer Compressor", false, "Input size (%lu) passed to Compress() is greater than max allowed (%lu)", uncompSize, LZ4_MAX_INPUT_SIZE);
return AzNetworking::CompressorError::InsufficientBuffer;
}
AZ_Warning("Multiplayer Compressor", compDataSize >= compWorstCaseSize, "Outbuffer size (%lu B) passed to Compress() is less than estimated worst case (%lu B)", compDataSize, compWorstCaseSize);
// Note that this returns a non-negative int so we are narrowing into a size_t here
compSize = LZ4_compressHC(reinterpret_cast<const char*>(uncompData), reinterpret_cast<char*>(compData), uncompSize);
if (compSize == 0)
{
// LZ4_compressHC returns a zero value for corrupt data and insufficient buffer
AZ_Warning("Multiplayer Compressor", false, "Compression failed for uncompSize:(%lu B) compDataSize:(%lu B) compSize:(%lu B)", uncompSize, compDataSize, compSize);
return AzNetworking::CompressorError::CorruptData;
}
return AzNetworking::CompressorError::Ok;
}
AzNetworking::CompressorError LZ4Compressor::Decompress(const void* compData, size_t compDataSize, void* uncompData, size_t uncompDataSize, size_t& consumedSizeOut, size_t& uncompSizeOut)
{
if (uncompData == nullptr)
{
// LZ4 actually never checks for this
AZ_Warning("Multiplayer Compressor", false, "Input buffer is uninitialized");
return AzNetworking::CompressorError::Uninitialized;
}
if (compData == nullptr)
{
// LZ4 actually never checks for this
AZ_Warning("Multiplayer Compressor", false, "Output buffer is uninitialized");
return AzNetworking::CompressorError::Uninitialized;
}
const int uncompSize = LZ4_decompress_safe(reinterpret_cast<const char*>(compData), reinterpret_cast<char*>(uncompData), compDataSize, uncompDataSize);
consumedSizeOut = compDataSize;
if (uncompSize < 0)
{
// LZ4_decompress_safe returns a negative value for corrupt data and insufficient buffer
AZ_Warning("Multiplayer Compressor", false, "Decompression failed for compDataSize:(%lu B) uncompDataSize:(%lu B) uncompSize:(%d B)", compDataSize, uncompDataSize, uncompSize);
return AzNetworking::CompressorError::CorruptData;
}
// Assign into the outbound size_t after validating the negative error case
uncompSizeOut = uncompSize;
return AzNetworking::CompressorError::Ok;
}
}
@@ -0,0 +1,46 @@
/*
* 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/Memory/SystemAllocator.h>
#include <AzNetworking/Framework/ICompressor.h>
namespace MultiplayerCompression
{
static const char* CompressorName = "LZ4";
static const AzNetworking::CompressorType CompressorType = aznumeric_cast<AzNetworking::CompressorType>(static_cast<AZ::u32>(AZ::Crc32(CompressorName)));
/**
* Implements an LZ4 Compressor against GridMate's Compressor interface for use with the Multiplayer Gem.
* Handles edge and error cases specific to LZ4 that are otherwise not covered in GridMate Carrier
* (where a Compressor is applied).
*/
class LZ4Compressor
: public AzNetworking::ICompressor
{
public:
AZ_CLASS_ALLOCATOR(LZ4Compressor, AZ::SystemAllocator, 0);
LZ4Compressor() = default;
const char* GetName() const { return CompressorName; }
AzNetworking::CompressorType GetType() const { return CompressorType; };
bool Init() { return true; }
size_t GetMaxChunkSize(size_t maxCompSize) const;
size_t GetMaxCompressedBufferSize(size_t uncompSize) const;
AzNetworking::CompressorError Compress(const void* uncompData, size_t uncompSize, void* compData, size_t compDataSize, size_t& compSize);
AzNetworking::CompressorError Decompress(const void* compData, size_t compDataSize, void* uncompData, size_t uncompDataSize, size_t& consumedSize, size_t& uncompSize);
};
}
@@ -0,0 +1,24 @@
/*
* 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.
*
*/
#include "MultiplayerCompressionFactory.h"
#include "LZ4Compressor.h"
#include <AzCore/std/smart_ptr/unique_ptr.h>
namespace MultiplayerCompression
{
AZStd::unique_ptr<AzNetworking::ICompressor> MultiplayerCompressionFactory::Create()
{
return AZStd::make_unique<LZ4Compressor>();
}
}
@@ -0,0 +1,30 @@
/*
* 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/Component/Component.h>
#include <AzCore/std/smart_ptr/unique_ptr.h>
#include <AzNetworking/Framework/ICompressor.h>
namespace MultiplayerCompression
{
class MultiplayerCompressionFactory
: public AzNetworking::ICompressorFactory
{
public:
/*
* Instantiate a new compressor
*/
AZStd::unique_ptr<AzNetworking::ICompressor> Create() override;
};
}
@@ -0,0 +1,51 @@
/*
* 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.
*
*/
#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/Module/Module.h>
#include "MultiplayerCompressionSystemComponent.h"
namespace MultiplayerCompression
{
class MultiplayerCompressionModule
: public AZ::Module
{
public:
AZ_RTTI(MultiplayerCompressionModule, "{939AFA0D-CFBC-4910-88F3-A0CF429307E4}", AZ::Module);
AZ_CLASS_ALLOCATOR(MultiplayerCompressionModule, AZ::SystemAllocator, 0);
MultiplayerCompressionModule()
: AZ::Module()
{
// Push results of MultiplayerCompressionSystemComponent::CreateDescriptor() into m_descriptors here.
m_descriptors.insert(m_descriptors.end(), {
MultiplayerCompressionSystemComponent::CreateDescriptor(),
});
}
/**
* Add required SystemComponents to the SystemEntity.
*/
AZ::ComponentTypeList GetRequiredSystemComponents() const override
{
return AZ::ComponentTypeList{
azrtti_typeid<MultiplayerCompressionSystemComponent>(),
};
}
};
}
// DO NOT MODIFY THIS LINE UNLESS YOU RENAME THE GEM
// The first parameter should be GemName_GemIdLower
// The second should be the fully qualified name of the class above
AZ_DECLARE_MODULE_CLASS(MultiplayerCompression_1d353c8ca3c74ed193fd6c6783ae41cc, MultiplayerCompression::MultiplayerCompressionModule)
@@ -0,0 +1,83 @@
/*
* 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.
*
*/
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include "MultiplayerCompressionSystemComponent.h"
#include "LZ4Compressor.h"
#include "MultiplayerCompressionFactory.h"
namespace MultiplayerCompression
{
void MultiplayerCompressionSystemComponent::Reflect(AZ::ReflectContext* context)
{
if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
{
serialize->Class<MultiplayerCompressionSystemComponent, AZ::Component>()
->Version(0)
;
if (AZ::EditContext* ec = serialize->GetEditContext())
{
ec->Class<MultiplayerCompressionSystemComponent>("MultiplayerCompression", "Provides packet compression via an open source library for the Multiplayer Gem")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System"))
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
;
}
}
}
void MultiplayerCompressionSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(AZ_CRC("MultiplayerCompressionService"));
}
void MultiplayerCompressionSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
{
incompatible.push_back(AZ_CRC("MultiplayerCompressionService"));
}
void MultiplayerCompressionSystemComponent::Init()
{
m_multiplayerCompressionFactory = AZStd::make_shared<MultiplayerCompressionFactory>();
}
void MultiplayerCompressionSystemComponent::Activate()
{
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;
}
}
@@ -0,0 +1,57 @@
/*
* 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/Component/Component.h>
#include <AzCore/std/containers/unordered_set.h>
#include <MultiplayerCompression/MultiplayerCompressionBus.h>
#include <MultiplayerCompressionFactory.h>
namespace MultiplayerCompression
{
/**
* System component whose sole purpose is to own a compression factory and expose it via EBUS
* so GridMate/Multiplayer Gem can easily ingest the compressor.
*/
class MultiplayerCompressionSystemComponent
: public AZ::Component
, protected MultiplayerCompressionRequestBus::Handler
{
public:
AZ_COMPONENT(MultiplayerCompressionSystemComponent, "{C3099AC9-47A6-41D2-8928-F38F904BAC1B}");
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;
////////////////////////////////////////////////////////////////////////
private:
AZStd::shared_ptr<MultiplayerCompressionFactory> m_multiplayerCompressionFactory;
};
}
@@ -0,0 +1,163 @@
/*
* 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.
*
*/
#include <lz4.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <MultiplayerCompression/MultiplayerCompressionBus.h>
#include <LZ4Compressor.h>
#include <AzCore/Compression/Compression.h>
#include <AzTest/AzTest.h>
class MultiplayerCompressionTest
: public UnitTest::AllocatorsTestFixture
{
protected:
static const int MAX_BUFFER_SIZE = 512;
void SetUp() override
{
AllocatorsTestFixture::SetUp();
}
void TearDown() override
{
AllocatorsTestFixture::TearDown();
}
};
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);
// 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();
size_t maxCompressedSize = wb.Size() + 32U;
size_t compressedSize = -1;
size_t uncompressedSize = -1;
size_t consumedSize = -1;
char* pCompressedBuffer = new char[maxCompressedSize];
char* pDecompressedBuffer = new char[wb.Size()];
//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);
const AZ::u64 compressTime = (AZStd::chrono::system_clock::now() - startTime).count();
ASSERT_TRUE(compressStatus == AzNetworking::CompressorError::Ok);
EXPECT_TRUE(compressedSize < maxCompressedSize);
//Run and test decompress
startTime = AZStd::chrono::system_clock::now();
AzNetworking::CompressorError decompressStatus = lz4Compressor.Decompress(pCompressedBuffer, compressedSize, pDecompressedBuffer, wb.Size(), 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);
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;
delete [] pDecompressedBuffer;
//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);
*/
}
#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;
char* badInput = new char[badInputSize];
char* pBuffer = new char[bufferSize];
size_t compressedSize = 0;
size_t consumedSize = 0;
size_t uncompressedSize = 0;
MultiplayerCompression::LZ4Compressor lz4Compressor;
AzNetworking::CompressorError compressStatus = lz4Compressor.Compress(badInput, badInputSize, pBuffer, bufferSize, compressedSize);
EXPECT_TRUE(compressStatus == AzNetworking::CompressorError::InsufficientBuffer);
delete [] badInput;
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;
char* badInput = new char[badInputSize];
char* pBuffer = new char[bufferSize];
size_t compressedSize = 0;
size_t consumedSize = 0;
size_t uncompressedSize = 0;
MultiplayerCompression::LZ4Compressor lz4Compressor;
AzNetworking::CompressorError decompressStatus = lz4Compressor.Decompress(badInput, badInputSize, pBuffer, bufferSize, consumedSize, uncompressedSize);
EXPECT_TRUE(decompressStatus == AzNetworking::CompressorError::CorruptData);
delete [] badInput;
delete [] pBuffer;
}
TEST_F(MultiplayerCompressionTest, MultiplayerCompressionTest_NullTest)
{
size_t compressedSize = 0;
size_t consumedSize = 0;
size_t uncompressedSize = 0;
MultiplayerCompression::LZ4Compressor lz4Compressor;
AzNetworking::CompressorError compressStatus = lz4Compressor.Compress(nullptr, 4, nullptr, 4, compressedSize);
EXPECT_TRUE(compressStatus == AzNetworking::CompressorError::Uninitialized);
AzNetworking::CompressorError decompressStatus = lz4Compressor.Decompress(nullptr, 4, nullptr, 4, consumedSize, uncompressedSize);
EXPECT_TRUE(decompressStatus == AzNetworking::CompressorError::Uninitialized);
}
AZ_UNIT_TEST_HOOK(DEFAULT_UNIT_TEST_ENV);
@@ -0,0 +1,22 @@
{
"none": {
"Source": [
"Source/MultiplayerCompression_precompiled.cpp",
"Source/MultiplayerCompression_precompiled.h"
]
},
"auto": {
"Include": [
"Include/MultiplayerCompression/MultiplayerCompressionBus.h"
],
"Source": [
"Source/LZ4Compressor.cpp",
"Source/LZ4Compressor.h",
"Source/MultiplayerCompressionFactory.cpp",
"Source/MultiplayerCompressionFactory.h",
"Source/MultiplayerCompressionModule.cpp",
"Source/MultiplayerCompressionSystemComponent.cpp",
"Source/MultiplayerCompressionSystemComponent.h"
]
}
}
@@ -0,0 +1,20 @@
#
# 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.
#
set(FILES
Include/MultiplayerCompression/MultiplayerCompressionBus.h
Source/LZ4Compressor.cpp
Source/LZ4Compressor.h
Source/MultiplayerCompressionFactory.cpp
Source/MultiplayerCompressionFactory.h
Source/MultiplayerCompressionSystemComponent.cpp
Source/MultiplayerCompressionSystemComponent.h
)
@@ -0,0 +1,14 @@
#
# 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.
#
set(FILES
Source/MultiplayerCompressionModule.cpp
)
@@ -0,0 +1,7 @@
{
"auto": {
"Tests": [
"Tests/MultiplayerCompressionTest.cpp"
]
}
}
@@ -0,0 +1,14 @@
#
# 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.
#
set(FILES
Tests/MultiplayerCompressionTest.cpp
)
+23
View File
@@ -0,0 +1,23 @@
########################################################################################
# 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.
#
########################################################################################
def build(bld):
bld.DefineGem(
# Add custom build options here
includes = [bld.Path('Code/CryEngine/CryAction'),
bld.Path('Code/CryEngine/CryCommon')],
export_includes = [bld.Path('Gems/MultiplayerCompression/Code/Include')],
uselib = ['LZ4'],
defines = ['ENABLE_MULTIPLAYER_COMPRESSION'],
file_list = ['multiplayercompression.waf_files'],
)