From e28de10c00eee3a7bc0b5a9b6058bc1b276fa301 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 23 Feb 2020 17:11:54 +0100 Subject: [PATCH] - serialize sound IDs as index, not name. The name is not unique. This really needs something better. --- source/common/serializer.cpp | 11 ++++++++++- source/common/serializer.h | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/source/common/serializer.cpp b/source/common/serializer.cpp index 861cdd7d2..720b1e237 100644 --- a/source/common/serializer.cpp +++ b/source/common/serializer.cpp @@ -1470,12 +1470,18 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FName &value, FName *d //========================================================================== // -// +// Note that the sound name here is not reliable because it's a file name, not a unique alias. +// Currently the index is the only means to retrieve the sound on loading. // //========================================================================== FSerializer &Serialize(FSerializer &arc, const char *key, FSoundID &sid, FSoundID *def) { +#if 1 + int id = sid; + Serialize(arc, key, sid, def); + if (arc.isReading()) sid = FSoundID(id); +#else if (arc.isWriting()) { if (!arc.w->inObject() || def == nullptr || sid != *def) @@ -1508,6 +1514,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FSoundID &sid, FSoundI } } } +#endif return arc; } @@ -1610,3 +1617,5 @@ FSerializer &Serialize(FSerializer &arc, const char *key, NumericValue &value, N } return arc; } + +SaveRecords saveRecords; diff --git a/source/common/serializer.h b/source/common/serializer.h index 5bd8abb0e..8870765ac 100644 --- a/source/common/serializer.h +++ b/source/common/serializer.h @@ -270,4 +270,39 @@ FSerializer &Serialize(FSerializer &arc, const char *key, TFlags &flags, return Serialize(arc, key, flags.Value, def? &def->Value : nullptr); } +// Automatic save record registration + +struct SaveRecord +{ + const char* GameModule; + void (*Handler)(FSerializer& arc); + + SaveRecord(const char* nm, void (*handler)(FSerializer& arc)); +}; + +struct SaveRecords +{ + TArray records; + + void RunHandlers(const char* gameModule, FSerializer& arc) + { + for (auto record : records) + { + if (!strcmp(gameModule, record->GameModule)) + { + record->Handler(arc); + } + } + } +}; + +extern SaveRecords saveRecords; + +inline SaveRecord::SaveRecord(const char* nm, void (*handler)(FSerializer& arc)) +{ + GameModule = nm; + Handler = handler; + saveRecords.records.Push(this); +} + #endif