Saveload: Use template function to implement SlAutolength
This commit is contained in:
@@ -491,7 +491,7 @@ static void Save_PLYR()
|
|||||||
{
|
{
|
||||||
for (Company *c : Company::Iterate()) {
|
for (Company *c : Company::Iterate()) {
|
||||||
SlSetArrayIndex(c->index);
|
SlSetArrayIndex(c->index);
|
||||||
SlAutolength((AutolengthProc*)SaveLoad_PLYR, c);
|
SlAutolength(SaveLoad_PLYR, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -336,7 +336,7 @@ static void Save_LGRP()
|
|||||||
FilterDescs();
|
FilterDescs();
|
||||||
for (LinkGraph *lg : LinkGraph::Iterate()) {
|
for (LinkGraph *lg : LinkGraph::Iterate()) {
|
||||||
SlSetArrayIndex(lg->index);
|
SlSetArrayIndex(lg->index);
|
||||||
SlAutolength((AutolengthProc*)DoSave_LGRP, lg);
|
SlAutolength(DoSave_LGRP, lg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,7 +348,7 @@ static void Save_LGRJ()
|
|||||||
FilterDescs();
|
FilterDescs();
|
||||||
for (LinkGraphJob *lgj : LinkGraphJob::Iterate()) {
|
for (LinkGraphJob *lgj : LinkGraphJob::Iterate()) {
|
||||||
SlSetArrayIndex(lgj->index);
|
SlSetArrayIndex(lgj->index);
|
||||||
SlAutolength((AutolengthProc*)DoSave_LGRJ, lgj);
|
SlAutolength(DoSave_LGRJ, lgj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -364,14 +364,13 @@ static void Save_ORDL()
|
|||||||
SetupDescs_ORDL();
|
SetupDescs_ORDL();
|
||||||
for (OrderList *list : OrderList::Iterate()) {
|
for (OrderList *list : OrderList::Iterate()) {
|
||||||
SlSetArrayIndex(list->index);
|
SlSetArrayIndex(list->index);
|
||||||
SlAutolength([](void *data) {
|
SlAutolength([&]() {
|
||||||
OrderList *list = static_cast<OrderList *>(data);
|
|
||||||
SlObjectSaveFiltered(list, _filtered_ordl_desc);
|
SlObjectSaveFiltered(list, _filtered_ordl_desc);
|
||||||
SlWriteUint32(list->GetScheduledDispatchScheduleCount());
|
SlWriteUint32(list->GetScheduledDispatchScheduleCount());
|
||||||
for (DispatchSchedule &ds : list->GetScheduledDispatchScheduleSet()) {
|
for (DispatchSchedule &ds : list->GetScheduledDispatchScheduleSet()) {
|
||||||
SaveDispatchSchedule(ds);
|
SaveDispatchSchedule(ds);
|
||||||
}
|
}
|
||||||
}, list);
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -458,14 +457,13 @@ void Save_BKOR()
|
|||||||
|
|
||||||
for (OrderBackup *ob : OrderBackup::Iterate()) {
|
for (OrderBackup *ob : OrderBackup::Iterate()) {
|
||||||
SlSetArrayIndex(ob->index);
|
SlSetArrayIndex(ob->index);
|
||||||
SlAutolength([](void *data) {
|
SlAutolength([&]() {
|
||||||
OrderBackup *ob = static_cast<OrderBackup *>(data);
|
|
||||||
SlObject(ob, GetOrderBackupDescription());
|
SlObject(ob, GetOrderBackupDescription());
|
||||||
SlWriteUint32((uint)ob->dispatch_schedules.size());
|
SlWriteUint32((uint)ob->dispatch_schedules.size());
|
||||||
for (DispatchSchedule &ds : ob->dispatch_schedules) {
|
for (DispatchSchedule &ds : ob->dispatch_schedules) {
|
||||||
SaveDispatchSchedule(ds);
|
SaveDispatchSchedule(ds);
|
||||||
}
|
}
|
||||||
}, ob);
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -40,7 +40,7 @@ static void Save_PLAN()
|
|||||||
{
|
{
|
||||||
for (Plan *p : Plan::Iterate()) {
|
for (Plan *p : Plan::Iterate()) {
|
||||||
SlSetArrayIndex(p->index);
|
SlSetArrayIndex(p->index);
|
||||||
SlAutolength((AutolengthProc*) RealSave_PLAN, p);
|
SlAutolength(RealSave_PLAN, p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2383,19 +2383,17 @@ void SlGlobList(const SaveLoadTable &slt)
|
|||||||
SlObject(nullptr, slt);
|
SlObject(nullptr, slt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void SlAutolengthSetup()
|
||||||
* Do something of which I have no idea what it is :P
|
|
||||||
* @param proc The callback procedure that is called
|
|
||||||
* @param arg The variable that will be used for the callback procedure
|
|
||||||
*/
|
|
||||||
void SlAutolength(AutolengthProc *proc, void *arg)
|
|
||||||
{
|
{
|
||||||
assert(_sl.action == SLA_SAVE);
|
assert(_sl.action == SLA_SAVE);
|
||||||
assert(_sl.need_length == NL_WANTLENGTH);
|
assert(_sl.need_length == NL_WANTLENGTH);
|
||||||
|
|
||||||
_sl.need_length = NL_NONE;
|
_sl.need_length = NL_NONE;
|
||||||
_sl.dumper->StartAutoLength();
|
_sl.dumper->StartAutoLength();
|
||||||
proc(arg);
|
}
|
||||||
|
|
||||||
|
void SlAutolengthCompletion()
|
||||||
|
{
|
||||||
auto result = _sl.dumper->StopAutoLength();
|
auto result = _sl.dumper->StopAutoLength();
|
||||||
/* Setup length */
|
/* Setup length */
|
||||||
_sl.need_length = NL_WANTLENGTH;
|
_sl.need_length = NL_WANTLENGTH;
|
||||||
|
@@ -83,7 +83,6 @@ bool IsNetworkServerSave();
|
|||||||
bool IsScenarioSave();
|
bool IsScenarioSave();
|
||||||
|
|
||||||
typedef void ChunkSaveLoadProc();
|
typedef void ChunkSaveLoadProc();
|
||||||
typedef void AutolengthProc(void *arg);
|
|
||||||
|
|
||||||
void SlUnreachablePlaceholder();
|
void SlUnreachablePlaceholder();
|
||||||
|
|
||||||
@@ -980,12 +979,27 @@ void WriteValue(void *ptr, VarType conv, int64_t val);
|
|||||||
void SlSetArrayIndex(uint index);
|
void SlSetArrayIndex(uint index);
|
||||||
int SlIterateArray();
|
int SlIterateArray();
|
||||||
|
|
||||||
void SlAutolength(AutolengthProc *proc, void *arg);
|
|
||||||
size_t SlGetFieldLength();
|
size_t SlGetFieldLength();
|
||||||
void SlSetLength(size_t length);
|
void SlSetLength(size_t length);
|
||||||
size_t SlCalcObjMemberLength(const void *object, const SaveLoad &sld);
|
size_t SlCalcObjMemberLength(const void *object, const SaveLoad &sld);
|
||||||
size_t SlCalcObjLength(const void *object, const SaveLoadTable &slt);
|
size_t SlCalcObjLength(const void *object, const SaveLoadTable &slt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run proc, automatically prepending the written length
|
||||||
|
* @param proc The callback procedure that is called
|
||||||
|
* @param args Any
|
||||||
|
*/
|
||||||
|
template <typename F, typename... Args>
|
||||||
|
void SlAutolength(F proc, Args... args)
|
||||||
|
{
|
||||||
|
extern void SlAutolengthSetup();
|
||||||
|
extern void SlAutolengthCompletion();
|
||||||
|
|
||||||
|
SlAutolengthSetup();
|
||||||
|
proc(std::forward<Args>(args)...);
|
||||||
|
SlAutolengthCompletion();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run proc, saving result in the autolength temp buffer
|
* Run proc, saving result in the autolength temp buffer
|
||||||
* @param proc The callback procedure that is called
|
* @param proc The callback procedure that is called
|
||||||
|
@@ -622,7 +622,7 @@ static void Save_STNN()
|
|||||||
/* Write the stations */
|
/* Write the stations */
|
||||||
for (BaseStation *st : BaseStation::Iterate()) {
|
for (BaseStation *st : BaseStation::Iterate()) {
|
||||||
SlSetArrayIndex(st->index);
|
SlSetArrayIndex(st->index);
|
||||||
SlAutolength((AutolengthProc*)RealSave_STNN, st);
|
SlAutolength(RealSave_STNN, st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -317,7 +317,7 @@ static void Save_TOWN()
|
|||||||
SetupDescs_TOWN();
|
SetupDescs_TOWN();
|
||||||
for (Town *t : Town::Iterate()) {
|
for (Town *t : Town::Iterate()) {
|
||||||
SlSetArrayIndex(t->index);
|
SlSetArrayIndex(t->index);
|
||||||
SlAutolength((AutolengthProc*)RealSave_Town, t);
|
SlAutolength(RealSave_Town, t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1316,7 +1316,7 @@ void Save_VENC()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SlAutolength([](void *) {
|
SlAutolength([]() {
|
||||||
int types[4] = {};
|
int types[4] = {};
|
||||||
int total = 0;
|
int total = 0;
|
||||||
for (Vehicle *v : Vehicle::Iterate()) {
|
for (Vehicle *v : Vehicle::Iterate()) {
|
||||||
@@ -1377,7 +1377,7 @@ void Save_VENC()
|
|||||||
SlWriteUint32(a->index);
|
SlWriteUint32(a->index);
|
||||||
SlWriteUint16(a->acache.cached_max_range);
|
SlWriteUint16(a->acache.cached_max_range);
|
||||||
}
|
}
|
||||||
}, nullptr);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Load_VENC()
|
void Load_VENC()
|
||||||
@@ -1610,7 +1610,7 @@ void Save_VLKA()
|
|||||||
for (Train *t : Train::Iterate()) {
|
for (Train *t : Train::Iterate()) {
|
||||||
if (t->lookahead != nullptr) {
|
if (t->lookahead != nullptr) {
|
||||||
SlSetArrayIndex(t->index);
|
SlSetArrayIndex(t->index);
|
||||||
SlAutolength((AutolengthProc*) RealSave_VLKA, t->lookahead.get());
|
SlAutolength(RealSave_VLKA, t->lookahead.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user