From 461b73e21bc84c4e630cb84be3bb80d0466ae7f5 Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 20 Apr 2025 19:14:28 +0200 Subject: [PATCH] Codefix: stdafx.h and safeguards.h should be the first and last include in every source file, and not appear in any header file. --- src/core/kdtree.hpp | 2 -- src/error.cpp | 1 + src/framerate_gui.cpp | 2 ++ src/framerate_type.h | 1 - src/music/fluidsynth.cpp | 1 + src/music/midi.h | 2 -- src/music/midifile.cpp | 4 ++++ src/music/midifile.hpp | 1 - src/newgrf_profiling.cpp | 3 +++ src/newgrf_profiling.h | 1 - src/os/macosx/string_osx.cpp | 1 + src/pathfinder/water_regions.cpp | 1 + src/pathfinder/yapf/yapf_ship_regions.h | 1 - src/spritecache_internal.h | 2 -- src/spriteloader/sprite_file.cpp | 1 + src/tests/bitmath_func.cpp | 2 ++ src/tests/enum_over_optimisation.cpp | 2 ++ src/tests/landscape_partial_pixel_z.cpp | 2 ++ src/tests/math_func.cpp | 2 ++ src/tests/mock_fontcache.h | 2 -- src/tests/mock_spritecache.cpp | 2 ++ src/tests/string_func.cpp | 2 ++ src/tests/test_network_crypto.cpp | 2 ++ src/tests/test_script_admin.cpp | 2 ++ src/tests/test_window_desc.cpp | 2 ++ src/timer/timer_game_calendar.h | 1 - src/timer/timer_manager.h | 2 -- src/video/video_driver.cpp | 2 ++ src/viewport_sprite_sorter.h | 1 - 29 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/core/kdtree.hpp b/src/core/kdtree.hpp index 8d24077f34..f0bf8896d2 100644 --- a/src/core/kdtree.hpp +++ b/src/core/kdtree.hpp @@ -10,8 +10,6 @@ #ifndef KDTREE_HPP #define KDTREE_HPP -#include "../stdafx.h" - /** * K-dimensional tree, specialised for 2-dimensional space. * This is not intended as a primary storage of data, but as an index into existing data. diff --git a/src/error.cpp b/src/error.cpp index cd56785942..2278391e92 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -9,6 +9,7 @@ #include "stdafx.h" #include "error_func.h" +#include "safeguards.h" [[noreturn]] void NOT_REACHED(const std::source_location location) { diff --git a/src/framerate_gui.cpp b/src/framerate_gui.cpp index d69bf9941f..29edcc1559 100644 --- a/src/framerate_gui.cpp +++ b/src/framerate_gui.cpp @@ -7,6 +7,8 @@ /** @file framerate_gui.cpp GUI for displaying framerate/game speed information. */ +#include "stdafx.h" + #include "framerate_type.h" #include #include "gfx_func.h" diff --git a/src/framerate_type.h b/src/framerate_type.h index 3697a545d9..8530fc9072 100644 --- a/src/framerate_type.h +++ b/src/framerate_type.h @@ -35,7 +35,6 @@ #ifndef FRAMERATE_TYPE_H #define FRAMERATE_TYPE_H -#include "stdafx.h" #include "core/enum_type.hpp" /** diff --git a/src/music/fluidsynth.cpp b/src/music/fluidsynth.cpp index 4ffd90e620..3093a8d5b5 100644 --- a/src/music/fluidsynth.cpp +++ b/src/music/fluidsynth.cpp @@ -16,6 +16,7 @@ #include #include "../mixer.h" #include +#include "../safeguards.h" static struct { fluid_settings_t *settings; ///< FluidSynth settings handle diff --git a/src/music/midi.h b/src/music/midi.h index ee3fe69a17..cda9192696 100644 --- a/src/music/midi.h +++ b/src/music/midi.h @@ -10,8 +10,6 @@ #ifndef MUSIC_MIDI_H #define MUSIC_MIDI_H -#include "../stdafx.h" - /** Header of a Stanard MIDI File */ struct SMFHeader { uint16_t format; diff --git a/src/music/midifile.cpp b/src/music/midifile.cpp index 9cc3cd8840..5c7441b919 100644 --- a/src/music/midifile.cpp +++ b/src/music/midifile.cpp @@ -7,6 +7,8 @@ /* @file midifile.cpp Parser for standard MIDI files */ +#include "../stdafx.h" + #include "midifile.hpp" #include "../fileio_func.h" #include "../fileio_type.h" @@ -21,6 +23,8 @@ #include "table/strings.h" +#include "../safeguards.h" + /* SMF reader based on description at: http://www.somascape.org/midi/tech/mfile.html */ diff --git a/src/music/midifile.hpp b/src/music/midifile.hpp index 1293a5a08c..dd6eb37a83 100644 --- a/src/music/midifile.hpp +++ b/src/music/midifile.hpp @@ -10,7 +10,6 @@ #ifndef MUSIC_MIDIFILE_HPP #define MUSIC_MIDIFILE_HPP -#include "../stdafx.h" #include "../fileio_type.h" #include "midi.h" diff --git a/src/newgrf_profiling.cpp b/src/newgrf_profiling.cpp index 4e0cfec0f9..d968bf99c3 100644 --- a/src/newgrf_profiling.cpp +++ b/src/newgrf_profiling.cpp @@ -7,6 +7,8 @@ /** @file newgrf_profiling.cpp Profiling of NewGRF action 2 handling. */ +#include "stdafx.h" + #include "newgrf_profiling.h" #include "fileio_func.h" #include "string_func.h" @@ -18,6 +20,7 @@ #include +#include "safeguards.h" std::vector _newgrf_profilers; diff --git a/src/newgrf_profiling.h b/src/newgrf_profiling.h index b08f7bda3a..fb7887d63e 100644 --- a/src/newgrf_profiling.h +++ b/src/newgrf_profiling.h @@ -10,7 +10,6 @@ #ifndef NEWGRF_PROFILING_H #define NEWGRF_PROFILING_H -#include "stdafx.h" #include "timer/timer_game_calendar.h" #include "newgrf.h" #include "newgrf_callbacks.h" diff --git a/src/os/macosx/string_osx.cpp b/src/os/macosx/string_osx.cpp index 1487884e81..48b25e556c 100644 --- a/src/os/macosx/string_osx.cpp +++ b/src/os/macosx/string_osx.cpp @@ -18,6 +18,7 @@ #include "macos.h" #include +#include "../../safeguards.h" /* CTRunDelegateCreate is supported since MacOS X 10.5, but was only included in the SDKs starting with the 10.9 SDK. */ diff --git a/src/pathfinder/water_regions.cpp b/src/pathfinder/water_regions.cpp index f2e1753e9d..10597c0cef 100644 --- a/src/pathfinder/water_regions.cpp +++ b/src/pathfinder/water_regions.cpp @@ -19,6 +19,7 @@ #include "../ship.h" #include "../debug.h" #include "../3rdparty/fmt/ranges.h" +#include "../safeguards.h" using TWaterRegionTraversabilityBits = uint16_t; constexpr TWaterRegionPatchLabel FIRST_REGION_LABEL = 1; diff --git a/src/pathfinder/yapf/yapf_ship_regions.h b/src/pathfinder/yapf/yapf_ship_regions.h index 8b75773cc8..dc488754b4 100644 --- a/src/pathfinder/yapf/yapf_ship_regions.h +++ b/src/pathfinder/yapf/yapf_ship_regions.h @@ -10,7 +10,6 @@ #ifndef YAPF_SHIP_REGIONS_H #define YAPF_SHIP_REGIONS_H -#include "../../stdafx.h" #include "../../tile_type.h" #include "../water_regions.h" diff --git a/src/spritecache_internal.h b/src/spritecache_internal.h index 76f8aac7b2..946f8bfbc5 100644 --- a/src/spritecache_internal.h +++ b/src/spritecache_internal.h @@ -10,8 +10,6 @@ #ifndef SPRITECACHE_INTERNAL_H #define SPRITECACHE_INTERNAL_H -#include "stdafx.h" - #include "core/math_func.hpp" #include "gfx_type.h" #include "spriteloader/spriteloader.hpp" diff --git a/src/spriteloader/sprite_file.cpp b/src/spriteloader/sprite_file.cpp index e4bc055ec4..a374d7969f 100644 --- a/src/spriteloader/sprite_file.cpp +++ b/src/spriteloader/sprite_file.cpp @@ -9,6 +9,7 @@ #include "../stdafx.h" #include "sprite_file_type.hpp" +#include "../safeguards.h" /** Signature of a container version 2 GRF. */ extern const std::array _grf_cont_v2_sig = {'G', 'R', 'F', 0x82, 0x0D, 0x0A, 0x1A, 0x0A}; diff --git a/src/tests/bitmath_func.cpp b/src/tests/bitmath_func.cpp index fa89f14252..347fa55e85 100644 --- a/src/tests/bitmath_func.cpp +++ b/src/tests/bitmath_func.cpp @@ -13,6 +13,8 @@ #include "../core/bitmath_func.hpp" +#include "../safeguards.h" + TEST_CASE("SetBitIterator tests") { auto test_case = [&](auto input, std::initializer_list expected) { diff --git a/src/tests/enum_over_optimisation.cpp b/src/tests/enum_over_optimisation.cpp index bdb3c6a9a4..1ec718f228 100644 --- a/src/tests/enum_over_optimisation.cpp +++ b/src/tests/enum_over_optimisation.cpp @@ -17,6 +17,8 @@ #include "../3rdparty/catch2/catch.hpp" +#include "../safeguards.h" + enum TestEnum : int8_t { ZERO, ONE, diff --git a/src/tests/landscape_partial_pixel_z.cpp b/src/tests/landscape_partial_pixel_z.cpp index ec8c8f79db..1e890cd45a 100644 --- a/src/tests/landscape_partial_pixel_z.cpp +++ b/src/tests/landscape_partial_pixel_z.cpp @@ -14,6 +14,8 @@ #include "../landscape.h" #include "../slope_func.h" +#include "../safeguards.h" + /** * Check whether the addition of two slope's GetPartialPixelZ values results in * the GetPartialPixelZ values of the expected slope. diff --git a/src/tests/math_func.cpp b/src/tests/math_func.cpp index 1f53d005b7..a5542f1d87 100644 --- a/src/tests/math_func.cpp +++ b/src/tests/math_func.cpp @@ -13,6 +13,8 @@ #include "../core/math_func.hpp" +#include "../safeguards.h" + TEST_CASE("DivideApproxTest - Negative") { CHECK(-2 == DivideApprox(-5, 2)); diff --git a/src/tests/mock_fontcache.h b/src/tests/mock_fontcache.h index 1a43cd1821..5ae4103f65 100644 --- a/src/tests/mock_fontcache.h +++ b/src/tests/mock_fontcache.h @@ -10,8 +10,6 @@ #ifndef MOCK_FONTCACHE_H #define MOCK_FONTCACHE_H -#include "../stdafx.h" - #include "../fontcache.h" #include "../string_func.h" diff --git a/src/tests/mock_spritecache.cpp b/src/tests/mock_spritecache.cpp index 18ff34c872..e002f56b5a 100644 --- a/src/tests/mock_spritecache.cpp +++ b/src/tests/mock_spritecache.cpp @@ -15,6 +15,8 @@ #include "../spritecache_internal.h" #include "../table/sprites.h" +#include "../safeguards.h" + static bool MockLoadNextSprite(SpriteID load_index) { static UniquePtrSpriteAllocator allocator; diff --git a/src/tests/string_func.cpp b/src/tests/string_func.cpp index 1b05786a9e..fb88f77a13 100644 --- a/src/tests/string_func.cpp +++ b/src/tests/string_func.cpp @@ -18,6 +18,8 @@ #include "table/strings.h" +#include "../safeguards.h" + /**** String compare/equals *****/ TEST_CASE("StrCompareIgnoreCase - std::string") diff --git a/src/tests/test_network_crypto.cpp b/src/tests/test_network_crypto.cpp index be28d486d5..a1acb4e1db 100644 --- a/src/tests/test_network_crypto.cpp +++ b/src/tests/test_network_crypto.cpp @@ -16,6 +16,8 @@ #include "../network/core/packet.h" #include "../string_func.h" +#include "../safeguards.h" + /* The length of the hexadecimal representation of a X25519 key must fit in the key length. */ static_assert(NETWORK_SECRET_KEY_LENGTH >= X25519_KEY_SIZE * 2 + 1); static_assert(NETWORK_PUBLIC_KEY_LENGTH >= X25519_KEY_SIZE * 2 + 1); diff --git a/src/tests/test_script_admin.cpp b/src/tests/test_script_admin.cpp index c286e6293a..b498ca2200 100644 --- a/src/tests/test_script_admin.cpp +++ b/src/tests/test_script_admin.cpp @@ -22,6 +22,8 @@ #include +#include "../safeguards.h" + /** * A controller to start enough so we can use Squirrel for testing. * diff --git a/src/tests/test_window_desc.cpp b/src/tests/test_window_desc.cpp index 0f4305c69a..ce50dc41d1 100644 --- a/src/tests/test_window_desc.cpp +++ b/src/tests/test_window_desc.cpp @@ -15,6 +15,8 @@ #include "../window_gui.h" +#include "../safeguards.h" + /** * List of WindowDescs. Defined in window.cpp but not exposed as this unit-test is the only other place that needs it. * WindowDesc is a self-registering class so all WindowDescs will be included in the list. diff --git a/src/timer/timer_game_calendar.h b/src/timer/timer_game_calendar.h index 602d96e429..19eb1b1d93 100644 --- a/src/timer/timer_game_calendar.h +++ b/src/timer/timer_game_calendar.h @@ -10,7 +10,6 @@ #ifndef TIMER_GAME_CALENDAR_H #define TIMER_GAME_CALENDAR_H -#include "../stdafx.h" #include "../core/strong_typedef_type.hpp" #include "timer_game_common.h" diff --git a/src/timer/timer_manager.h b/src/timer/timer_manager.h index 92e45ccc17..e6e5b6eed1 100644 --- a/src/timer/timer_manager.h +++ b/src/timer/timer_manager.h @@ -11,8 +11,6 @@ #ifndef TIMER_MANAGER_H #define TIMER_MANAGER_H -#include "../stdafx.h" - template class BaseTimer; diff --git a/src/video/video_driver.cpp b/src/video/video_driver.cpp index 32d6ed9725..ba0997b3d9 100644 --- a/src/video/video_driver.cpp +++ b/src/video/video_driver.cpp @@ -22,6 +22,8 @@ #include "../window_func.h" #include "video_driver.hpp" +#include "../safeguards.h" + bool _video_hw_accel; ///< Whether to consider hardware accelerated video drivers on startup. bool _video_vsync; ///< Whether we should use vsync (only if active video driver supports HW acceleration). diff --git a/src/viewport_sprite_sorter.h b/src/viewport_sprite_sorter.h index e277ff3708..7f8b8daf44 100644 --- a/src/viewport_sprite_sorter.h +++ b/src/viewport_sprite_sorter.h @@ -7,7 +7,6 @@ /** @file viewport_sprite_sorter.h Types related to sprite sorting. */ -#include "stdafx.h" #include "gfx_type.h" #ifndef VIEWPORT_SPRITE_SORTER_H