- serialize sound IDs as index, not name.

The name is not unique. This really needs something better.
This commit is contained in:
Christoph Oelckers 2020-02-23 17:11:54 +01:00
parent 935a880b63
commit e28de10c00
2 changed files with 45 additions and 1 deletions

View file

@ -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;

View file

@ -270,4 +270,39 @@ FSerializer &Serialize(FSerializer &arc, const char *key, TFlags<T, TT> &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<SaveRecord*> 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