Skip to content

Commit

Permalink
Merge pull request #5309 from Web-eWorks/header-spaghetti
Browse files Browse the repository at this point in the history
Refactor Header #include Knots
  • Loading branch information
Webster Sheets authored Aug 26, 2023
2 parents 4dd7fc8 + 3524247 commit fb1c588
Show file tree
Hide file tree
Showing 193 changed files with 1,388 additions and 1,145 deletions.
16 changes: 15 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ if (MSVC)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP /wd4506")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /wd4506")

# Disable warnings to avoid MSVC spam (moved from libs.h):
# #pragma warning(disable : 4244) // "conversion from x to x: possible loss of data"
# #pragma warning(disable : 4800) // int-to-bool "performance warning"
# #pragma warning(disable : 4355) // 'this' used in base member initializer list
# #pragma warning(disable : 4351) // new behavior [after vs2003!]: elements of array 'array' will be default initialized
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4244 /wd4800 /wd4355 /wd4351")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4800 /wd4355 /wd4351")

add_definitions(-DNOMINMAX)
endif (MSVC)

if (APPLE)
Expand All @@ -63,6 +73,11 @@ if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS_DEBUG "-g -Og")
endif (CMAKE_COMPILER_IS_GNUCXX)

option(USE_TIME_TRACE "Use -ftime-trace to profile compile times (requires Clang)" OFF)
if (USE_TIME_TRACE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftime-trace")
endif()

include(CheckSymbolExists)
check_symbol_exists(feclearexcept "fenv.h" HAS_FECLEAREXCEPT)
check_symbol_exists(feenableexcept "fenv.h" HAS_FEENABLEEXCEPT)
Expand Down Expand Up @@ -309,7 +324,6 @@ add_executable(savegamedump
src/savegamedump.cpp
src/JsonUtils.cpp
src/FileSystem.cpp
src/utils.cpp
src/StringF.cpp
src/DateTime.cpp
src/Lang.cpp
Expand Down
32 changes: 32 additions & 0 deletions ClangBuildAnalyzer.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# How many of most expensive things are reported?
[counts]

# files that took most time to parse
fileParse = 10
# files that took most time to generate code for
fileCodegen = 10
# functions that took most time to generate code for
function = 30
# header files that were most expensive to include
header = 10
# for each expensive header, this many include paths to it are shown
headerChain = 10
# templates that took longest to instantiate
template = 30


# Minimum times (in ms) for things to be recorded into trace
[minTimes]

# parse/codegen for a file
file = 10


[misc]

# Maximum length of symbol names printed; longer names will get truncated
maxNameLength = 70

# Only print "root" headers in expensive header report, i.e.
# only headers that are directly included by at least one source file
onlyRootHeaders = true
12 changes: 12 additions & 0 deletions scripts/analyze-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Simple automation script to run ClangBuildAnalyzer over the pioneer codebase
# and generate reports.
# Requires a clean build with the -DUSE_TIME_TRACE=1 cmake option passed to
# ./bootstrap, and should be run in the top-level directory of the pioneer repo

ANALYZER="$1"
if [ -z "$ANALYZER" ]; then
ANALYZER="ClangBuildAnalyzer"
fi

$ANALYZER --all build/ build/build-pioneer-trace.bin 2&>/dev/null
$ANALYZER --analyze build/build-pioneer-trace.bin > build/build-pioneer-trace-$(date +%F-%T).txt
2 changes: 1 addition & 1 deletion src/Aabb.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#ifndef _AABB_H
#define _AABB_H

#include "libs.h"
#include "vector3.h"

struct Aabb {
vector3d min, max;
Expand Down
1 change: 1 addition & 0 deletions src/Background.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "graphics/VertexBuffer.h"
#include "perlin.h"
#include "profiler/Profiler.h"
#include "utils.h"

#include <SDL_stdinc.h>
#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion src/Beam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "Frame.h"
#include "Game.h"
#include "GameSaveError.h"
#include "Json.h"
#include "JsonUtils.h"
#include "Pi.h"
#include "Planet.h"
#include "Player.h"
Expand Down
2 changes: 2 additions & 0 deletions src/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "CargoBody.h"
#include "Frame.h"
#include "GameSaveError.h"
#include "JsonUtils.h"
#include "HyperspaceCloud.h"
#include "Missile.h"
#include "Planet.h"
Expand All @@ -16,6 +17,7 @@
#include "Space.h"
#include "SpaceStation.h"
#include "Star.h"
#include "core/Log.h"
#include "lua/LuaEvent.h"

Body::Body() :
Expand Down
1 change: 1 addition & 0 deletions src/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "FrameId.h"
#include "lua/PropertiedObject.h"
#include "matrix3x3.h"
#include "matrix4x4.h"
#include "vector3.h"
#include <string>

Expand Down
5 changes: 5 additions & 0 deletions src/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@

#include "Color.h"
#include "FrameId.h"
#include "RefCounted.h"
#include "graphics/Frustum.h"
#include "graphics/Light.h"
#include "matrix4x4.h"
#include "vector3.h"

#include <list>
#include <memory>
#include <vector>

class Body;
class Frame;

Expand Down
1 change: 1 addition & 0 deletions src/CargoBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "Game.h"
#include "GameSaveError.h"
#include "JsonUtils.h"
#include "Pi.h"
#include "Sfx.h"
#include "Ship.h"
Expand Down
1 change: 0 additions & 1 deletion src/CargoBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#define _CARGOBODY_H

#include "DynamicBody.h"
#include "libs.h"
#include "lua/LuaRef.h"

namespace Graphics {
Expand Down
1 change: 1 addition & 0 deletions src/CityOnPlanet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "scenegraph/Animation.h"
#include "scenegraph/ModelSkin.h"
#include "scenegraph/SceneGraph.h"
#include "utils.h"

#include "utils.h"

Expand Down
3 changes: 2 additions & 1 deletion src/CityOnPlanet.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "FrameId.h"
#include "Random.h"
#include "JsonFwd.h"
#include "matrix4x4.h"

#include <set>

Expand All @@ -25,7 +26,7 @@ namespace Graphics {
} // namespace Graphics

namespace FileSystem {
struct FileInfo;
class FileInfo;
} // namespace FileSystem

namespace SceneGraph {
Expand Down
1 change: 1 addition & 0 deletions src/CollMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "scenegraph/Serializer.h"
#include "collider/GeomTree.h"
#include "profiler/Profiler.h"

//This simply stores the collision GeomTrees
//and AABB.
Expand Down
2 changes: 2 additions & 0 deletions src/CollMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "Aabb.h"
#include "RefCounted.h"

#include <vector>

class GeomTree;

namespace Serializer {
Expand Down
2 changes: 2 additions & 0 deletions src/Color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "Color.h"
#include "lua/LuaUtils.h"

#include <cassert>

const Color4f Color4f::BLACK = Color4f(0.0f, 0.0f, 0.0f, 1.0f);
const Color4f Color4f::WHITE = Color4f(1.0f, 1.0f, 1.0f, 1.0f);
const Color4f Color4f::RED = Color4f(1.0f, 0.0f, 0.0f, 1.0f);
Expand Down
4 changes: 3 additions & 1 deletion src/Cutscene.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#ifndef _CUTSCENE_H
#define _CUTSCENE_H

#include "Color.h"
#include "graphics/Light.h"
#include "graphics/Renderer.h"
#include "libs.h"

#include <vector>

namespace SceneGraph {
class Model;
Expand Down
11 changes: 6 additions & 5 deletions src/DateTime.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright © 2008-2022 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

#include "DateTime.h"

#include "libs.h"
#include <stdio.h>
#include <cassert>
#include <cstdint>
#include <tuple>
Expand Down Expand Up @@ -96,11 +97,11 @@ Time::DateTime::DateTime(double gameTime) :
void Time::DateTime::GetDateParts(int *out_year, int *out_month, int *out_day) const
{
if (out_year || out_month || out_day) {
static_assert(Time::Day > (Sint64(1) << 32),
static_assert(Time::Day > (int64_t(1) << 32),
"code below assumes that the 'date' part of a 64-bit timestamp fits in 32 bits");

// number of days from the epoch to the beginning of the stored date
int days = divmod_euclid(m_timestamp, Sint64(Time::Day)).first;
int days = divmod_euclid(m_timestamp, int64_t(Time::Day)).first;

// work out how many completed cycles, centuries, 'quads' and years we've measured since the epoch
// computed such that n400 may be negative, but all other values must be positive
Expand Down Expand Up @@ -149,7 +150,7 @@ void Time::DateTime::GetDateParts(int *out_year, int *out_month, int *out_day) c
void Time::DateTime::GetTimeParts(int *out_hour, int *out_minute, int *out_second, int *out_microsecond) const
{
if (out_hour || out_minute || out_second || out_microsecond) {
const Sint64 tstamp = divmod_euclid(m_timestamp, Sint64(Time::Day)).second;
const int64_t tstamp = divmod_euclid(m_timestamp, int64_t(Time::Day)).second;
assert(tstamp >= 0);

if (out_microsecond) {
Expand Down
2 changes: 1 addition & 1 deletion src/DynamicBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "FixedGuns.h"
#include "Frame.h"
#include "GameSaveError.h"
#include "Json.h"
#include "JsonUtils.h"
#include "Planet.h"
#include "Space.h"
#include "collider/CollisionContact.h"
Expand Down
1 change: 0 additions & 1 deletion src/FaceParts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "JobQueue.h"
#include "Pi.h"
#include "SDLWrappers.h"
#include "libs.h"
#include "utils.h"

namespace {
Expand Down
3 changes: 2 additions & 1 deletion src/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

#include "FileSystem.h"
#include "StringRange.h"
#include "libs.h"

#include <algorithm>
#include <cassert>
#include <iterator>
#include <map>
#include <sstream>
#include <stdexcept>

Expand Down
3 changes: 2 additions & 1 deletion src/FixedGuns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#include "Beam.h"
#include "DynamicBody.h"
#include "GameSaveError.h"
#include "JsonUtils.h"
#include "MathUtil.h"
#include "Projectile.h"
#include "Quaternion.h"
#include "StringF.h"
#include "libs.h"
#include "scenegraph/Tag.h"
#include "vector3.h"

Expand Down
2 changes: 1 addition & 1 deletion src/FixedGuns.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#ifndef FIXEDGUNS_H
#define FIXEDGUNS_H

#include "Json.h"
#include "JsonFwd.h"
#include "Projectile.h"
#include "scenegraph/Model.h"
#include "vector3.h"
Expand Down
1 change: 1 addition & 0 deletions src/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Frame.h"

#include "GameSaveError.h"
#include "Json.h"
#include "JsonUtils.h"
#include "Sfx.h"
#include "Space.h"
Expand Down
1 change: 1 addition & 0 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "FileSystem.h"
#include "GameLog.h"
#include "GameSaveError.h"
#include "JsonUtils.h"
#include "HyperspaceCloud.h"
#include "MathUtil.h"
#include "collider/CollisionSpace.h"
Expand Down
11 changes: 3 additions & 8 deletions src/GameLog.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
// Copyright © 2008-2022 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

#include "GameLog.h"
#include "Game.h"
#include "Pi.h"
#include "StringF.h"
#include "graphics/Renderer.h"
#include "graphics/VertexArray.h"
#include "lua/Lua.h"

void GameLog::Add(const std::string &msg)
{

// m_messages.push_back(Message(msg, 0));
Add("", msg, GameLog::Priority::PRIORITY_NORMAL);
// while (m_messages.size() > MAX_MESSAGES) m_messages.pop_front();
}

void GameLog::Add(const std::string &from, const std::string &msg, GameLog::Priority priority)
Expand Down
5 changes: 4 additions & 1 deletion src/GameLog.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright © 2008-2022 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

#ifndef _GAMELOG_H
#define _GAMELOG_H

#include "libs.h"
#include <string>

/*
* For storing all in-game log messages
Expand Down
1 change: 1 addition & 0 deletions src/GeoPatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "graphics/Types.h"
#include "graphics/VertexBuffer.h"
#include "perlin.h"
#include "profiler/Profiler.h"
#include "vcacheopt/vcacheopt.h"
#include <algorithm>
#include <deque>
Expand Down
2 changes: 1 addition & 1 deletion src/GeoPatchJobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "GeoPatchJobs.h"

#include "GeoSphere.h"
#include "libs.h"
#include "MathUtil.h"
#include "perlin.h"
#include "profiler/Profiler.h"

Expand Down
2 changes: 1 addition & 1 deletion src/HyperspaceCloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "Game.h"
#include "GameSaveError.h"
#include "Json.h"
#include "JsonUtils.h"
#include "Lang.h"
#include "Pi.h"
#include "Player.h"
Expand Down
Loading

0 comments on commit fb1c588

Please sign in to comment.