Skip to content

Commit

Permalink
Add: pathfinder and cacheclear count
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuXarick committed Jun 8, 2022
1 parent 0d37568 commit d9f5548
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/date.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
#include "newgrf_profiling.h"
#include "widgets/statusbar_widget.h"

#include "console_func.h"
#include "safeguards.h"



Year _cur_year; ///< Current year, starting at 0
Month _cur_month; ///< Current month (0..11)
Date _date; ///< Current date in days (day counter)
Expand Down Expand Up @@ -301,5 +304,10 @@ void IncreaseDate()
if (new_month) OnNewMonth();

/* yes, call various yearly loops */
if (new_year) OnNewYear();
if (new_year) {
IConsolePrint(CC_HELP, "_cur_year = {} , _pathfinder_calls = {} , _cacheclear_calls_reverse = {} , _cacheclear_calls_pathfind = {}",
_cur_year, _pathfinder_calls, _cacheclear_calls_reverse, _cacheclear_calls_pathfind);
_pathfinder_calls = _cacheclear_calls_reverse = _cacheclear_calls_pathfind = 0;
OnNewYear();
}
}
8 changes: 8 additions & 0 deletions src/openttd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,15 @@ extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMP
extern void ShowOSErrorBox(const char *buf, bool system);
extern std::string _config_file;


bool _save_config = false;
bool _request_newgrf_scan = false;
NewGRFScanCallback *_request_newgrf_scan_callback = nullptr;

int _pathfinder_calls = 0;
int _cacheclear_calls_reverse = 0;
int _cacheclear_calls_pathfind = 0;

/**
* Error handling for fatal user errors.
* @param s the string to print.
Expand Down Expand Up @@ -982,6 +987,9 @@ bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileTy

void SwitchToMode(SwitchMode new_mode)
{
_pathfinder_calls = 0;
_cacheclear_calls_reverse = 0;
_cacheclear_calls_pathfind = 0;
/* If we are saving something, the network stays in its current state */
if (new_mode != SM_SAVE_GAME) {
/* If the network is active, make it not-active */
Expand Down
4 changes: 4 additions & 0 deletions src/openttd.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@ void SwitchToMode(SwitchMode new_mode);

bool RequestNewGRFScan(struct NewGRFScanCallback *callback = nullptr);

extern int _pathfinder_calls;
extern int _cacheclear_calls_reverse;
extern int _cacheclear_calls_pathfind;

#endif /* OPENTTD_H */
9 changes: 8 additions & 1 deletion src/roadveh_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,10 @@ static Trackdir RoadFindPathToDest(RoadVehicle *v, TileIndex tile, DiagDirection
trackdirs &= DiagdirReachesTrackdirs(enterdir);
if (trackdirs == TRACKDIR_BIT_NONE) {
/* If vehicle expected a path, it no longer exists, so invalidate it. */
if (!v->path.empty()) v->path.clear();
if (!v->path.empty()) {
v->path.clear();
_cacheclear_calls_reverse++;
}
/* No reachable tracks, so we'll reverse */
return_track(_road_reverse_table[enterdir]);
}
Expand Down Expand Up @@ -960,6 +963,7 @@ static Trackdir RoadFindPathToDest(RoadVehicle *v, TileIndex tile, DiagDirection
if (!v->path.empty() && v->path.tile.front() == tile) {
/* Vehicle expected a choice here, invalidate its path. */
v->path.clear();
_cacheclear_calls_reverse++;
}
return_track(FindFirstBit2x64(trackdirs));
}
Expand All @@ -969,6 +973,7 @@ static Trackdir RoadFindPathToDest(RoadVehicle *v, TileIndex tile, DiagDirection
if (v->path.tile.front() != tile) {
/* Vehicle didn't expect a choice here, invalidate its path. */
v->path.clear();
_cacheclear_calls_pathfind++;
} else {
Trackdir trackdir = v->path.td.front();

Expand All @@ -980,6 +985,7 @@ static Trackdir RoadFindPathToDest(RoadVehicle *v, TileIndex tile, DiagDirection

/* Vehicle expected a choice which is no longer available. */
v->path.clear();
_cacheclear_calls_pathfind++;
}
}

Expand All @@ -989,6 +995,7 @@ static Trackdir RoadFindPathToDest(RoadVehicle *v, TileIndex tile, DiagDirection

default: NOT_REACHED();
}
_pathfinder_calls++;
v->HandlePathfindingResult(path_found);

found_best_track:;
Expand Down

0 comments on commit d9f5548

Please sign in to comment.