From faf4cdc0f4683f645c434a1582c925f1b0640921 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 31 May 2018 18:36:12 +0100 Subject: [PATCH 1/2] Scope info: Add station/waypoint info dumper --- src/scope_info.cpp | 27 +++++++++++++++++++++++++++ src/scope_info.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/src/scope_info.cpp b/src/scope_info.cpp index 19fa67c905..6410ad231d 100644 --- a/src/scope_info.cpp +++ b/src/scope_info.cpp @@ -15,6 +15,8 @@ #include "strings_func.h" #include "company_base.h" #include "vehicle_base.h" +#include "station_base.h" +#include "waypoint_base.h" #include "table/strings.h" #include "safeguards.h" @@ -78,4 +80,29 @@ const char *scope_dumper::VehicleInfo(const Vehicle *v) return this->buffer; } +const char *scope_dumper::StationInfo(const BaseStation *st) +{ + char *b = this->buffer; + const char *last = lastof(this->buffer); + + if (st) { + const bool waypoint = Waypoint::IsExpected(st); + b += seprintf(b, last, "%s: %u: ", waypoint ? "waypoint" : "station", st->index); + b = GetString(b, waypoint ? STR_WAYPOINT_NAME : STR_STATION_NAME, last); + b += seprintf(b, last, ", c:%d, facil: ", (int) st->owner); + auto dump_facil = [&](char c, StationFacility flag) { + if (st->facilities & flag) b += seprintf(b, last, "%c", c); + }; + dump_facil('R', FACIL_TRAIN); + dump_facil('T', FACIL_TRUCK_STOP); + dump_facil('B', FACIL_BUS_STOP); + dump_facil('A', FACIL_AIRPORT); + dump_facil('D', FACIL_DOCK); + dump_facil('W', FACIL_WAYPOINT); + } else { + b += seprintf(b, last, "station/waypoint: NULL"); + } + return this->buffer; +} + #endif diff --git a/src/scope_info.h b/src/scope_info.h index 89ed4f6571..4cc772ff1d 100644 --- a/src/scope_info.h +++ b/src/scope_info.h @@ -17,6 +17,7 @@ #include struct Vehicle; +struct BaseStation; extern std::vector> _scope_stack; @@ -61,6 +62,7 @@ int WriteScopeLog(char *buf, const char *last); struct scope_dumper { const char *CompanyInfo(int company_id); const char *VehicleInfo(const Vehicle *v); + const char *StationInfo(const BaseStation *st); private: char buffer[256]; From bb8c18b017707b73058babf227565001f4f40f3b Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 31 May 2018 18:37:08 +0100 Subject: [PATCH 2/2] Add scope info logging to LoadUnloadStation --- src/scope_info.cpp | 4 +++- src/vehicle.cpp | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/scope_info.cpp b/src/scope_info.cpp index 6410ad231d..c6d80fe475 100644 --- a/src/scope_info.cpp +++ b/src/scope_info.cpp @@ -87,7 +87,8 @@ const char *scope_dumper::StationInfo(const BaseStation *st) if (st) { const bool waypoint = Waypoint::IsExpected(st); - b += seprintf(b, last, "%s: %u: ", waypoint ? "waypoint" : "station", st->index); + b += seprintf(b, last, "%s: %u: (", waypoint ? "waypoint" : "station", st->index); + SetDParam(0, st->index); b = GetString(b, waypoint ? STR_WAYPOINT_NAME : STR_STATION_NAME, last); b += seprintf(b, last, ", c:%d, facil: ", (int) st->owner); auto dump_facil = [&](char c, StationFacility flag) { @@ -99,6 +100,7 @@ const char *scope_dumper::StationInfo(const BaseStation *st) dump_facil('A', FACIL_AIRPORT); dump_facil('D', FACIL_DOCK); dump_facil('W', FACIL_WAYPOINT); + b += seprintf(b, last, ")"); } else { b += seprintf(b, last, "station/waypoint: NULL"); } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 1645a380cf..0644add6dc 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -951,8 +951,11 @@ void CallVehicleTicks() RunVehicleDayProc(); - Station *st; - FOR_ALL_STATIONS(st) LoadUnloadStation(st); + { + Station *st = nullptr; + SCOPE_INFO_FMT([&st], "CallVehicleTicks: LoadUnloadStation: %s", scope_dumper().StationInfo(st)); + FOR_ALL_STATIONS(st) LoadUnloadStation(st); + } Vehicle *v = NULL; SCOPE_INFO_FMT([&v], "CallVehicleTicks: %s", scope_dumper().VehicleInfo(v));