Dump infrastructure totals when mismatch detected in CheckCaches.

desync-debugging
Jonathan G Rennison 7 years ago
parent 45b95a8323
commit e1274b420a

@ -45,6 +45,7 @@ struct CompanyInfrastructure {
uint32 GetRoadTotal() const;
uint32 GetTramTotal() const;
char *Dump(char *buffer, const char *last) const;
};
typedef Pool<Company, CompanyID, 1, MAX_COMPANIES> CompanyPool;

@ -1182,3 +1182,18 @@ uint32 CompanyInfrastructure::GetTramTotal() const
}
return total;
}
char *CompanyInfrastructure::Dump(char *buffer, const char *last) const
{
for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
if (rail[rt]) buffer += seprintf(buffer, last, "Rail: %s: %u\n", GetStringPtr(GetRailTypeInfo(rt)->strings.name), rail[rt]);
}
buffer += seprintf(buffer, last, "Signal: %u\n", signal);
buffer += seprintf(buffer, last, "Road: %u\n", road[ROADTYPE_ROAD]);
buffer += seprintf(buffer, last, "Tram: %u\n", road[ROADTYPE_TRAM]);
buffer += seprintf(buffer, last, "Water: %u\n", water);
buffer += seprintf(buffer, last, "Station: %u\n", station);
buffer += seprintf(buffer, last, "Airport: %u\n", airport);
return buffer;
}

@ -1175,6 +1175,11 @@ void CheckCaches(bool force_check)
for (const Company *c : Company::Iterate()) {
if (MemCmpT(old_infrastructure.data() + i, &c->infrastructure) != 0) {
DEBUG(desync, 0, "infrastructure cache mismatch: company %i", (int)c->index);
char buffer[4096];
old_infrastructure.Get(i)->Dump(buffer, lastof(buffer));
DEBUG(desync, 0, "Previous:\n%s", buffer);
c->infrastructure.Dump(buffer, lastof(buffer));
DEBUG(desync, 0, "Recalculated:\n%s", buffer);
}
i++;
}

Loading…
Cancel
Save