diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c3ef71917a..450e7078f4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -157,6 +157,8 @@ add_files( engine_type.h error.h error_gui.cpp + event_logs.cpp + event_logs.h fileio.cpp fileio_func.h fileio_type.h diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index cbaa442928..52b2bc4afc 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -55,6 +55,7 @@ #include "debug_settings.h" #include "debug_desync.h" #include "scope_info.h" +#include "event_logs.h" #include #include "safeguards.h" diff --git a/src/crashlog.cpp b/src/crashlog.cpp index db68d5dd7e..63212d29a4 100644 --- a/src/crashlog.cpp +++ b/src/crashlog.cpp @@ -31,6 +31,7 @@ #include "command_func.h" #include "thread.h" #include "debug_desync.h" +#include "event_logs.h" #include "ai/ai_info.hpp" #include "game/game.hpp" diff --git a/src/disaster_vehicle.cpp b/src/disaster_vehicle.cpp index 3c234e499e..e218fc7bf3 100644 --- a/src/disaster_vehicle.cpp +++ b/src/disaster_vehicle.cpp @@ -46,6 +46,7 @@ #include "core/random_func.hpp" #include "core/backup_type.hpp" #include "core/checksum_func.hpp" +#include "event_logs.h" #include "table/strings.h" diff --git a/src/economy.cpp b/src/economy.cpp index 522927041d..501db7006d 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -55,6 +55,7 @@ #include "scope_info.h" #include "pathfinder/yapf/yapf_cache.h" #include "debug_desync.h" +#include "event_logs.h" #include "table/strings.h" #include "table/pricebase.h" diff --git a/src/event_logs.cpp b/src/event_logs.cpp new file mode 100644 index 0000000000..10bab41261 --- /dev/null +++ b/src/event_logs.cpp @@ -0,0 +1,37 @@ +/* + * 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 . + */ + +/** @file event_logs.cpp Functions related to event logging. */ + +#include "stdafx.h" +#include "event_logs.h" +#include "string_func.h" + +#include "safeguards.h" + +GameEventFlags _game_events_since_load; +GameEventFlags _game_events_overall; + +time_t _game_load_time; + +char *DumpGameEventFlags(GameEventFlags events, char *b, const char *last) +{ + if (b <= last) *b = 0; + auto dump = [&](char c, GameEventFlags ev) { + if (events & ev) b += seprintf(b, last, "%c", c); + }; + dump('d', GEF_COMPANY_DELETE); + dump('m', GEF_COMPANY_MERGE); + dump('n', GEF_RELOAD_NEWGRF); + dump('t', GEF_TBTR_REPLACEMENT); + dump('D', GEF_DISASTER_VEH); + dump('c', GEF_TRAIN_CRASH); + dump('i', GEF_INDUSTRY_CREATE); + dump('j', GEF_INDUSTRY_DELETE); + dump('v', GEF_VIRT_TRAIN); + return b; +} diff --git a/src/event_logs.h b/src/event_logs.h new file mode 100644 index 0000000000..2cbf6b2dff --- /dev/null +++ b/src/event_logs.h @@ -0,0 +1,42 @@ +/* + * 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 . + */ + +/** @file event_logs.h Functions related to event logging. */ + +#ifndef EVENT_LOGS_H +#define EVENT_LOGS_H + +#include "core/enum_type.hpp" +#include + +enum GameEventFlags : uint32 { + GEF_COMPANY_DELETE = 1 << 0, ///< (d) A company has been deleted + GEF_COMPANY_MERGE = 1 << 1, ///< (m) A company has been bought by another + GEF_RELOAD_NEWGRF = 1 << 2, ///< (n) ReloadNewGRFData() has been called + GEF_TBTR_REPLACEMENT = 1 << 3, ///< (t) CMD_TEMPLATE_REPLACE_VEHICLE has been called + GEF_DISASTER_VEH = 1 << 4, ///< (D) A disaster vehicle exists or has been created + GEF_TRAIN_CRASH = 1 << 5, ///< (c) A train crash has occurred + GEF_INDUSTRY_CREATE = 1 << 6, ///< (i) An industry has been created (in game) + GEF_INDUSTRY_DELETE = 1 << 7, ///< (j) An industry has been deleted (in game) + GEF_VIRT_TRAIN = 1 << 8, ///< (v) A virtual train has been created +}; +DECLARE_ENUM_AS_BIT_SET(GameEventFlags) + +extern GameEventFlags _game_events_since_load; +extern GameEventFlags _game_events_overall; + +inline void RegisterGameEvents(GameEventFlags events) +{ + _game_events_since_load |= events; + _game_events_overall |= events; +} + +char *DumpGameEventFlags(GameEventFlags events, char *b, const char *last); + +extern time_t _game_load_time; + +#endif /* EVENT_LOGS_H */ diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 59a1d9a399..dc6c9b6e71 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -43,6 +43,7 @@ #include "error.h" #include "cmd_helper.h" #include "string_func.h" +#include "event_logs.h" #include "table/strings.h" #include "table/industry_land.h" diff --git a/src/misc.cpp b/src/misc.cpp index 58eb04cb0d..2b4120a14c 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -38,6 +38,7 @@ #include "zoning.h" #include "cargopacket.h" #include "tbtr_template_vehicle_func.h" +#include "event_logs.h" #include "safeguards.h" diff --git a/src/openttd.cpp b/src/openttd.cpp index a61fe0bc8b..6e96cfbae7 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -80,6 +80,7 @@ #include "tbtr_template_vehicle_func.h" #include "debug_settings.h" #include "debug_desync.h" +#include "event_logs.h" #include "linkgraph/linkgraphschedule.h" #include "tracerestrict.h" @@ -114,11 +115,6 @@ bool _save_config = false; bool _request_newgrf_scan = false; NewGRFScanCallback *_request_newgrf_scan_callback = nullptr; -GameEventFlags _game_events_since_load; -GameEventFlags _game_events_overall; - -time_t _game_load_time; - SimpleChecksum64 _state_checksum; /** @@ -2021,21 +2017,3 @@ void GameLoop() SoundDriver::GetInstance()->MainLoop(); MusicLoop(); } - -char *DumpGameEventFlags(GameEventFlags events, char *b, const char *last) -{ - if (b <= last) *b = 0; - auto dump = [&](char c, GameEventFlags ev) { - if (events & ev) b += seprintf(b, last, "%c", c); - }; - dump('d', GEF_COMPANY_DELETE); - dump('m', GEF_COMPANY_MERGE); - dump('n', GEF_RELOAD_NEWGRF); - dump('t', GEF_TBTR_REPLACEMENT); - dump('D', GEF_DISASTER_VEH); - dump('c', GEF_TRAIN_CRASH); - dump('i', GEF_INDUSTRY_CREATE); - dump('j', GEF_INDUSTRY_DELETE); - dump('v', GEF_VIRT_TRAIN); - return b; -} diff --git a/src/openttd.h b/src/openttd.h index 61296d2ca1..c183bcf7e8 100644 --- a/src/openttd.h +++ b/src/openttd.h @@ -79,32 +79,6 @@ DECLARE_ENUM_AS_BIT_SET(PauseMode) /** The current pause mode */ extern PauseMode _pause_mode; -enum GameEventFlags : uint32 { - GEF_COMPANY_DELETE = 1 << 0, ///< (d) A company has been deleted - GEF_COMPANY_MERGE = 1 << 1, ///< (m) A company has been bought by another - GEF_RELOAD_NEWGRF = 1 << 2, ///< (n) ReloadNewGRFData() has been called - GEF_TBTR_REPLACEMENT = 1 << 3, ///< (t) CMD_TEMPLATE_REPLACE_VEHICLE has been called - GEF_DISASTER_VEH = 1 << 4, ///< (D) A disaster vehicle exists or has been created - GEF_TRAIN_CRASH = 1 << 5, ///< (c) A train crash has occurred - GEF_INDUSTRY_CREATE = 1 << 6, ///< (i) An industry has been created (in game) - GEF_INDUSTRY_DELETE = 1 << 7, ///< (j) An industry has been deleted (in game) - GEF_VIRT_TRAIN = 1 << 8, ///< (v) A virtual train has been created -}; -DECLARE_ENUM_AS_BIT_SET(GameEventFlags) - -extern GameEventFlags _game_events_since_load; -extern GameEventFlags _game_events_overall; - -inline void RegisterGameEvents(GameEventFlags events) -{ - _game_events_since_load |= events; - _game_events_overall |= events; -} - -char *DumpGameEventFlags(GameEventFlags events, char *b, const char *last); - -extern time_t _game_load_time; - void AskExitGame(); void AskExitToGameMenu(); diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index f03f999a21..65d0c57c4f 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -67,6 +67,7 @@ #include "../animated_tile.h" #include "../company_func.h" #include "../infrastructure_func.h" +#include "../event_logs.h" #include "saveload_internal.h" diff --git a/src/saveload/misc_sl.cpp b/src/saveload/misc_sl.cpp index af7e8c4207..ce50cc5d8d 100644 --- a/src/saveload/misc_sl.cpp +++ b/src/saveload/misc_sl.cpp @@ -18,6 +18,7 @@ #include "../fios.h" #include "../road_type.h" #include "../core/checksum_func.hpp" +#include "../event_logs.h" #include "saveload.h" diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index df8650374c..e17d75bd46 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -45,6 +45,7 @@ #include "core/checksum_func.hpp" #include "debug_settings.h" #include "train_speed_adaptation.h" +#include "event_logs.h" #include "table/strings.h" #include "table/train_cmd.h"