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

Refactor Missile direction/frame group handling #7878

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kphoenix137
Copy link
Collaborator

PR Description: Clarify and Encapsulate Missile Frame Group Handling

Problem

The Missile struct contains a member _mimfnum, originally defined as an int, which is used inconsistently across the codebase in three distinct ways:

  • As a raw int (e.g., for animation frame group selection)
  • As Direction (8-directional enum)
  • As Direction16 (16-directional enum, used for finer visual rotation)

This loose usage made the intent behind _mimfnum ambiguous and error-prone, requiring frequent manual casting and encouraging magic numbers.


Solution

This PR improves encapsulation and usability of _mimfnum by:

  • Making _mimfnum a private member of Missile
  • Introducing explicit getters and setters to clarify usage:
    • setDirection(Direction)
    • setDirection(Direction16)
    • getDirection(), getDirection16()
    • setFrameGroupRaw(int)
    • getFrameGroupRaw()
    • setFrameGroup<Enum>() and getFrameGroup<Enum>()
    • setDefaultFrameGroup() (shorthand for setFrameGroupRaw(0))

Benefits

  • Improved readability – Call sites now express intent clearly, e.g., missile.setDirection(Direction::SouthEast)
  • Type safety – Template-based frame group accessors eliminate the need for static_casts at call sites
  • Encapsulation – Prevents accidental misuse or incorrect assignments to _mimfnum
  • More intuitive code – Developers working with missiles can reason about visuals/direction/frame groups more easily

Example Usage

Before:

missile._mimfnum = static_cast<int>(Direction::South);

After:

missile.setDirection(Direction::South);

Or for custom frame groups:

missile.setFrameGroup<GuardianFrame>(GuardianFrame::Attack);

This refactor lays a strong foundation for extending missile behavior safely and clearly while preserving compatibility with save/load systems that still require reading and writing _mimfnum as an int.

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