Add flags field to CheckCaches for which checks to run

Add header file for CheckCaches
pull/326/head
Jonathan G Rennison 3 years ago
parent c408007575
commit 5ed7aee8d3

@ -118,6 +118,7 @@ add_files(
date_type.h
debug.cpp
debug.h
debug_desync.h
debug_settings.h
dedicated.cpp
departures.cpp

@ -37,6 +37,7 @@
#include "zoning.h"
#include "tbtr_template_vehicle_func.h"
#include "widgets/statusbar_widget.h"
#include "debug_desync.h"
#include "table/strings.h"
@ -937,7 +938,6 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
InvalidateWindowData(WC_CLIENT_LIST, 0);
InvalidateWindowClassesData(WC_DEPARTURES_BOARD, 0);
extern void CheckCaches(bool force_check, std::function<void(const char *)> log);
CheckCaches(true, nullptr);
break;
}

@ -53,6 +53,7 @@
#include "linkgraph/linkgraphjob.h"
#include "base_media_base.h"
#include "debug_settings.h"
#include "debug_desync.h"
#include <time.h>
#include "safeguards.h"
@ -2687,7 +2688,6 @@ DEF_CONSOLE_CMD(ConCheckCaches)
if (broadcast) {
DoCommandP(0, 0, 0, CMD_DESYNC_CHECK);
} else {
extern void CheckCaches(bool force_check, std::function<void(const char *)> log);
CheckCaches(true, nullptr);
}

@ -30,6 +30,7 @@
#include "scope_info.h"
#include "command_func.h"
#include "thread.h"
#include "debug_desync.h"
#include "ai/ai_info.hpp"
#include "game/game.hpp"
@ -522,7 +523,6 @@ char *CrashLog::FillDesyncCrashLog(char *buffer, const char *last, const DesyncE
buffer = DumpDesyncMsgLog(buffer, last);
bool have_cache_log = false;
extern void CheckCaches(bool force_check, std::function<void(const char *)> log);
CheckCaches(true, [&](const char *str) {
if (!have_cache_log) buffer += seprintf(buffer, last, "CheckCaches:\n");
buffer += seprintf(buffer, last, " %s\n", str);

@ -0,0 +1,25 @@
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file debug_desync.h Desync debugging. */
#ifndef DEBUG_DESYNC_H
#define DEBUG_DESYNC_H
#include <functional>
enum CheckCachesFlags : uint32 {
CHECK_CACHE_NONE = 0,
CHECK_CACHE_GENERAL = 1 << 0,
CHECK_CACHE_INFRA_TOTALS = 1 << 1,
CHECK_CACHE_ALL = UINT32_MAX,
};
DECLARE_ENUM_AS_BIT_SET(CheckCachesFlags)
extern void CheckCaches(bool force_check, std::function<void(const char *)> log = nullptr, CheckCachesFlags flags = CHECK_CACHE_ALL);
#endif /* DEBUG_DESYNC_H */

@ -54,6 +54,7 @@
#include "tbtr_template_vehicle_func.h"
#include "scope_info.h"
#include "pathfinder/yapf/yapf_cache.h"
#include "debug_desync.h"
#include "table/strings.h"
#include "table/pricebase.h"
@ -2287,7 +2288,6 @@ static void DoAcquireCompany(Company *c)
delete c;
extern void CheckCaches(bool force_check, std::function<void(const char *)> log);
CheckCaches(true, nullptr);
}

@ -79,6 +79,7 @@
#include "core/checksum_func.hpp"
#include "tbtr_template_vehicle_func.h"
#include "debug_settings.h"
#include "debug_desync.h"
#include "linkgraph/linkgraphschedule.h"
#include "tracerestrict.h"
@ -1358,7 +1359,7 @@ void WriteVehicleInfo(char *&p, const char *last, const Vehicle *u, const Vehicl
* the cached value and what the value would
* be when calculated from the 'base' data.
*/
void CheckCaches(bool force_check, std::function<void(const char *)> log)
void CheckCaches(bool force_check, std::function<void(const char *)> log, CheckCachesFlags flags)
{
if (!force_check) {
int desync_level = _debug_desync_level;
@ -1398,6 +1399,7 @@ void CheckCaches(bool force_check, std::function<void(const char *)> log)
} \
}
if (flags & CHECK_CACHE_GENERAL) {
/* Check the town caches. */
std::vector<TownCache> old_town_caches;
std::vector<StationList> old_town_stations_nears;
@ -1472,7 +1474,9 @@ void CheckCaches(bool force_check, std::function<void(const char *)> log)
}
i++;
}
}
if (flags & CHECK_CACHE_INFRA_TOTALS) {
/* Check company infrastructure cache. */
std::vector<CompanyInfrastructure> old_infrastructure;
for (const Company *c : Company::Iterate()) old_infrastructure.push_back(c->infrastructure);
@ -1480,7 +1484,7 @@ void CheckCaches(bool force_check, std::function<void(const char *)> log)
extern void AfterLoadCompanyStats();
AfterLoadCompanyStats();
i = 0;
uint i = 0;
for (const Company *c : Company::Iterate()) {
if (MemCmpT(old_infrastructure.data() + i, &c->infrastructure) != 0) {
CCLOG("infrastructure cache mismatch: company %i", (int)c->index);
@ -1498,7 +1502,9 @@ void CheckCaches(bool force_check, std::function<void(const char *)> log)
}
i++;
}
}
if (flags & CHECK_CACHE_GENERAL) {
/* Strict checking of the road stop cache entries */
for (const RoadStop *rs : RoadStop::Iterate()) {
if (IsStandardRoadStopTile(rs->xy)) continue;
@ -1755,6 +1761,7 @@ void CheckCaches(bool force_check, std::function<void(const char *)> log)
} else {
CCLOG("Order destination refcount map not valid");
}
}
#undef CCLOGV
#undef CCLOG

Loading…
Cancel
Save