Add cache checking of water regions
This commit is contained in:
@@ -16,6 +16,7 @@ enum CheckCachesFlags : uint32_t {
|
|||||||
CHECK_CACHE_NONE = 0,
|
CHECK_CACHE_NONE = 0,
|
||||||
CHECK_CACHE_GENERAL = 1 << 0,
|
CHECK_CACHE_GENERAL = 1 << 0,
|
||||||
CHECK_CACHE_INFRA_TOTALS = 1 << 1,
|
CHECK_CACHE_INFRA_TOTALS = 1 << 1,
|
||||||
|
CHECK_CACHE_WATER_REGIONS = 1 << 2,
|
||||||
CHECK_CACHE_ALL = UINT16_MAX,
|
CHECK_CACHE_ALL = UINT16_MAX,
|
||||||
CHECK_CACHE_EMIT_LOG = 1 << 16,
|
CHECK_CACHE_EMIT_LOG = 1 << 16,
|
||||||
};
|
};
|
||||||
|
@@ -2052,6 +2052,11 @@ void CheckCaches(bool force_check, std::function<void(const char *)> log, CheckC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flags & CHECK_CACHE_WATER_REGIONS) {
|
||||||
|
extern void WaterRegionCheckCaches(std::function<void(const char *)> log);
|
||||||
|
WaterRegionCheckCaches(log);
|
||||||
|
}
|
||||||
|
|
||||||
if ((flags & CHECK_CACHE_EMIT_LOG) && !saved_messages.empty()) {
|
if ((flags & CHECK_CACHE_EMIT_LOG) && !saved_messages.empty()) {
|
||||||
InconsistencyExtraInfo info;
|
InconsistencyExtraInfo info;
|
||||||
info.check_caches_result = std::move(saved_messages);
|
info.check_caches_result = std::move(saved_messages);
|
||||||
|
@@ -260,6 +260,17 @@ public:
|
|||||||
{
|
{
|
||||||
return this->wr.tile_patch_labels != nullptr;
|
return this->wr.tile_patch_labels != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TWaterRegionPatchLabelArray CopyPatchLabelArray() const
|
||||||
|
{
|
||||||
|
TWaterRegionPatchLabelArray out;
|
||||||
|
if (this->HasPatchStorage()) {
|
||||||
|
out = *this->wr.tile_patch_labels;
|
||||||
|
} else {
|
||||||
|
out.fill(this->NumberOfPatches() == 0 ? INVALID_WATER_REGION_PATCH : 1);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<WaterRegion> _water_regions;
|
std::vector<WaterRegion> _water_regions;
|
||||||
@@ -472,3 +483,41 @@ uint GetWaterRegionTileDebugColourIndex(TileIndex tile)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WaterRegionCheckCaches(std::function<void(const char *)> log)
|
||||||
|
{
|
||||||
|
char cclog_buffer[1024];
|
||||||
|
#define CCLOG(...) { \
|
||||||
|
char *cc_log_pos = cclog_buffer + seprintf(cclog_buffer, lastof(cclog_buffer), "Region: %u x %u to %u x %u: ", \
|
||||||
|
x * WATER_REGION_EDGE_LENGTH, y * WATER_REGION_EDGE_LENGTH, (x * WATER_REGION_EDGE_LENGTH) + WATER_REGION_EDGE_MASK, (y * WATER_REGION_EDGE_LENGTH) + WATER_REGION_EDGE_MASK); \
|
||||||
|
seprintf(cc_log_pos, lastof(cclog_buffer), __VA_ARGS__); \
|
||||||
|
DEBUG(desync, 0, "%s", cclog_buffer); \
|
||||||
|
if (log) log(cclog_buffer); \
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint32_t size_x = GetWaterRegionMapSizeX();
|
||||||
|
const uint32_t size_y = GetWaterRegionMapSizeY();
|
||||||
|
for (uint32_t y = 0; y < size_y; y++) {
|
||||||
|
for (uint32_t x = 0; x < size_x; x++) {
|
||||||
|
WaterRegionReference wr = GetWaterRegionRef(x, y);
|
||||||
|
if (!wr.IsInitialized()) continue;
|
||||||
|
|
||||||
|
const bool old_has_cross_region_aqueducts = wr.HasCrossRegionAqueducts();
|
||||||
|
const int old_number_of_patches = wr.NumberOfPatches();
|
||||||
|
const TWaterRegionPatchLabelArray old_patch_labels = wr.CopyPatchLabelArray();
|
||||||
|
|
||||||
|
wr.ForceUpdate();
|
||||||
|
|
||||||
|
if (old_has_cross_region_aqueducts != wr.HasCrossRegionAqueducts()) {
|
||||||
|
CCLOG("Has cross region aqueducts mismatch: %u -> %u", old_has_cross_region_aqueducts, wr.HasCrossRegionAqueducts());
|
||||||
|
}
|
||||||
|
if (old_number_of_patches != wr.NumberOfPatches()) {
|
||||||
|
CCLOG("Number of patches mismatch: %u -> %u", old_number_of_patches, wr.NumberOfPatches());
|
||||||
|
}
|
||||||
|
if (old_patch_labels != wr.CopyPatchLabelArray()) {
|
||||||
|
CCLOG("Patch label mismatch");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#undef CCLOG
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user