Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce cross-file dependencies with forward declarations #1862

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from

Conversation

lolbot-iichan
Copy link
Contributor

@lolbot-iichan lolbot-iichan commented Feb 20, 2025

I noticed that editing some headers forces rebuilding almost whole project. This makes hard to make any refactoring.
Tested this theory by running gcc -MM -MG for cpp files and found out that there are 8300+ header imports for 200 cpp files.

Current PR suggest some quick changes that helps reduce the number of imports by 15% by using forward declarations.
Please, review commit-by-commit, not file-by-file.

There are many files changed, but almast all the changes are:

  • enum is declared to extend some given type like enum SomeType: unsigned char
  • include removed from header, forward declaration added instead
  • include added to some cpp files that actually required the enum
  • some extra includes added to some cpp files that worked automagically and broke after editing a header

Other then that there are a few changes:

  • renamed enum class CScoreboard::SortType that was a member of a class to enum class ScoreboardSortType, so that it would be possible to use forward declaration
  • removed default value for second StartTaskPen arg to avoid using enum element in header.
  • removed member initialization at struct WheelTrace, since they are always initialized in cpp file anyway, to avoid using enum element in header.

Top 20 header import before this PR:

    110  math/const.h
    115  graphics/engine/particle.h
    118  graphics/engine/engine.h
    124  graphics/core/renderers.h
    124  graphics/core/texture.h
    127  graphics/engine/camera.h
    129  common/error.h
    130  object/interface/trace_drawing_object.h
    132  object/object_interface_type.h
    134  graphics/core/vertex.h
    135  graphics/core/type.h
    136  common/timeutils.h
    136  object/object_type.h
    136  sound/sound_type.h
    137  math/sphere.h
    141  common/logger.h
    149  common/event.h
    150  common/key.h
    169  graphics/core/color.h
    179  common/singleton.h

Top 20 header import after this PR:

     90  object/object_create_params.h
     90  object/old_object_interface.h
     91  graphics/engine/camera.h
     92  object/object_interface_type.h
    105  math/const.h
    105  sound/sound_type.h
    118  graphics/engine/engine.h
    124  graphics/core/renderers.h
    124  graphics/core/texture.h
    128  common/error.h
    134  graphics/core/vertex.h
    135  graphics/core/type.h
    136  common/timeutils.h
    136  object/object_type.h
    137  math/sphere.h
    140  common/logger.h
    149  common/event.h
    150  common/key.h
    169  graphics/core/color.h
    178  common/singleton.h

@lolbot-iichan lolbot-iichan force-pushed the dev-forward-declarations branch 4 times, most recently from 93a4e61 to c4e904c Compare March 2, 2025 14:41
@lolbot-iichan lolbot-iichan force-pushed the dev-forward-declarations branch from c4e904c to a64b9af Compare March 2, 2025 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants