Added setreg option for network spawnables serialization format
Signed-off-by: Sergey Pereslavtsev <pereslav@amazon.com>
This commit is contained in:
@@ -33,8 +33,10 @@ namespace Multiplayer
|
||||
mpTools->SetDidProcessNetworkPrefabs(false);
|
||||
}
|
||||
|
||||
context.ListPrefabs([&context](AZStd::string_view prefabName, PrefabDom& prefab) {
|
||||
ProcessPrefab(context, prefabName, prefab);
|
||||
AZ::DataStream::StreamType serializationFormat = GetAzSerializationFormat();
|
||||
|
||||
context.ListPrefabs([&context, serializationFormat](AZStd::string_view prefabName, PrefabDom& prefab) {
|
||||
ProcessPrefab(context, prefabName, prefab, serializationFormat);
|
||||
});
|
||||
|
||||
if (mpTools && !context.GetProcessedObjects().empty())
|
||||
@@ -47,7 +49,15 @@ namespace Multiplayer
|
||||
{
|
||||
if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context); serializeContext != nullptr)
|
||||
{
|
||||
serializeContext->Class<NetworkPrefabProcessor, PrefabProcessor>()->Version(2);
|
||||
serializeContext->Enum<SerializationFormats>()
|
||||
->Value("Binary", SerializationFormats::Binary)
|
||||
->Value("Text", SerializationFormats::Text)
|
||||
;
|
||||
|
||||
serializeContext->Class<NetworkPrefabProcessor, PrefabProcessor>()
|
||||
->Version(3)
|
||||
->Field("SerializationFormat", &NetworkPrefabProcessor::m_serializationFormat)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +140,7 @@ namespace Multiplayer
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkPrefabProcessor::ProcessPrefab(PrefabProcessorContext& context, AZStd::string_view prefabName, PrefabDom& prefab)
|
||||
void NetworkPrefabProcessor::ProcessPrefab(PrefabProcessorContext& context, AZStd::string_view prefabName, PrefabDom& prefab, AZ::DataStream::StreamType serializationFormat)
|
||||
{
|
||||
using namespace AzToolsFramework::Prefab;
|
||||
|
||||
@@ -144,10 +154,10 @@ namespace Multiplayer
|
||||
AZStd::string uniqueName = prefabName;
|
||||
uniqueName += ".network.spawnable";
|
||||
|
||||
auto serializer = [](AZStd::vector<uint8_t>& output, const ProcessedObjectStore& object) -> bool {
|
||||
auto serializer = [serializationFormat](AZStd::vector<uint8_t>& output, const ProcessedObjectStore& object) -> bool {
|
||||
AZ::IO::ByteContainerStream stream(&output);
|
||||
auto& asset = object.GetAsset();
|
||||
return AZ::Utils::SaveObjectToStream(stream, AZ::DataStream::ST_BINARY, &asset, asset.GetType());
|
||||
return AZ::Utils::SaveObjectToStream(stream, serializationFormat, &asset, asset.GetType());
|
||||
};
|
||||
|
||||
auto&& [object, networkSpawnable] =
|
||||
@@ -218,4 +228,14 @@ namespace Multiplayer
|
||||
|
||||
context.GetProcessedObjects().push_back(AZStd::move(object));
|
||||
}
|
||||
|
||||
AZ::DataStream::StreamType NetworkPrefabProcessor::GetAzSerializationFormat() const
|
||||
{
|
||||
if (m_serializationFormat == SerializationFormats::Text)
|
||||
{
|
||||
return AZ::DataStream::StreamType::ST_JSON;
|
||||
}
|
||||
|
||||
return AZ::DataStream::StreamType::ST_BINARY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <AzToolsFramework/Prefab/Spawnable/PrefabProcessor.h>
|
||||
#include <AzCore/Serialization/ObjectStream.h>
|
||||
|
||||
namespace AzToolsFramework::Prefab::PrefabConversionUtils
|
||||
{
|
||||
@@ -33,7 +34,23 @@ namespace Multiplayer
|
||||
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
//! The format the network spawnables are going to be stored in.
|
||||
enum class SerializationFormats
|
||||
{
|
||||
Binary, //!< Binary is generally preferable for performance.
|
||||
Text //!< Store in text format which is usually slower but helps with debugging.
|
||||
};
|
||||
|
||||
AZ::DataStream::StreamType GetAzSerializationFormat() const;
|
||||
|
||||
protected:
|
||||
static void ProcessPrefab(PrefabProcessorContext& context, AZStd::string_view prefabName, PrefabDom& prefab);
|
||||
static void ProcessPrefab(PrefabProcessorContext& context, AZStd::string_view prefabName, PrefabDom& prefab, AZ::DataStream::StreamType serializationFormat);
|
||||
|
||||
SerializationFormats m_serializationFormat = SerializationFormats::Binary;
|
||||
};
|
||||
}
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
AZ_TYPE_INFO_SPECIALIZE(Multiplayer::NetworkPrefabProcessor::SerializationFormats, "{F69B49EB-9D67-4D9C-99E7-DFA35D4ACCD2}");
|
||||
}
|
||||
|
||||
@@ -18,8 +18,14 @@
|
||||
"GameObjectCreation":
|
||||
[
|
||||
{ "$type": "AzToolsFramework::Prefab::PrefabConversionUtils::EditorInfoRemover" },
|
||||
{ "$type": "Multiplayer::NetworkPrefabProcessor" },
|
||||
{ "$type": "AzToolsFramework::Prefab::PrefabConversionUtils::PrefabCatchmentProcessor" }
|
||||
{
|
||||
"$type": "Multiplayer::NetworkPrefabProcessor",
|
||||
"SerializationFormat": "Binary" // Options are "Binary" (default) or "Text". Prefer "Binary" for performance.
|
||||
},
|
||||
{
|
||||
"$type": "AzToolsFramework::Prefab::PrefabConversionUtils::PrefabCatchmentProcessor",
|
||||
"SerializationFormat": "Binary" // Options are "Binary" (default) or "Text". Prefer "Binary" for performance.
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user