Update read and write streaming api to use the newest format
This commit is contained in:
@@ -14,22 +14,21 @@
|
||||
class GameplayGlobalsUpgrader : public BinaryAssetUpgrader
|
||||
{
|
||||
public:
|
||||
|
||||
GameplayGlobalsUpgrader()
|
||||
{
|
||||
static const Upgrader upgraders[] =
|
||||
const Upgrader upgraders[] =
|
||||
{
|
||||
{ 1, 2, &Upgrade_1_To_2 },
|
||||
{ 1, 2, &Upgrade_1_To_2 }, // [Deprecated on 31.07.2020, expires on 31.07.2022]
|
||||
};
|
||||
setup(upgraders, ARRAY_COUNT(upgraders));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static bool Upgrade_1_To_2(AssetMigrationContext& context)
|
||||
{
|
||||
// [Deprecated on 31.07.2020, expires on 31.07.2022]
|
||||
PRAGMA_DISABLE_DEPRECATION_WARNINGS
|
||||
ASSERT(context.Input.SerializedVersion == 1 && context.Output.SerializedVersion == 2);
|
||||
|
||||
if (context.AllocateChunk(0))
|
||||
return true;
|
||||
auto& data = context.Input.Header.Chunks[0]->Data;
|
||||
@@ -41,13 +40,14 @@ private:
|
||||
String name;
|
||||
for (int32 i = 0; i < count; i++)
|
||||
{
|
||||
stream.ReadString(&name, 71);
|
||||
stream.Read(name, 71);
|
||||
CommonValue commonValue;
|
||||
stream.ReadCommonValue(&commonValue);
|
||||
Variant variant(commonValue);
|
||||
output.WriteVariant(variant);
|
||||
}
|
||||
context.Output.Header.Chunks[0]->Data.Copy(output.GetHandle(), output.GetPosition());
|
||||
PRAGMA_ENABLE_DEPRECATION_WARNINGS
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -170,11 +170,11 @@ bool GameplayGlobals::Save(const StringView& path)
|
||||
|
||||
// Save to bytes
|
||||
MemoryWriteStream stream(1024);
|
||||
stream.WriteInt32(Variables.Count());
|
||||
stream.Write(Variables.Count());
|
||||
for (auto& e : Variables)
|
||||
{
|
||||
stream.WriteString(e.Key, 71);
|
||||
stream.WriteVariant(e.Value.DefaultValue);
|
||||
stream.Write(e.Key, 71);
|
||||
stream.Write(e.Value.DefaultValue);
|
||||
}
|
||||
|
||||
// Set chunk data
|
||||
@@ -226,14 +226,14 @@ Asset::LoadResult GameplayGlobals::load()
|
||||
|
||||
// Load all variables
|
||||
int32 count;
|
||||
stream.ReadInt32(&count);
|
||||
stream.Read(count);
|
||||
Variables.EnsureCapacity(count);
|
||||
String name;
|
||||
for (int32 i = 0; i < count; i++)
|
||||
{
|
||||
stream.ReadString(&name, 71);
|
||||
stream.Read(name, 71);
|
||||
auto& e = Variables[name];
|
||||
stream.ReadVariant(&e.DefaultValue);
|
||||
stream.Read(e.DefaultValue);
|
||||
e.Value = e.DefaultValue;
|
||||
}
|
||||
if (stream.HasError())
|
||||
|
||||
Reference in New Issue
Block a user