Make Position easy to understand at a glance.
Right now Position is doing too many things at once:
- raw rectangle storage
- parent-relative positioning
- parent-relative scaling
- cached recalculation
- debug drawing
The target for this phase is not to redesign the whole system. The target is to make it smaller, clearer, and less surprising without breaking the current framework behavior.
Files directly in scope:
Files likely affected:
For this phase:
- keep behavior unless behavior is obviously accidental
- prefer removing confusion over adding abstraction
- do not rename everything at once
- compile after each meaningful change
Current issues:
Positionincludes state.h in the header only because it hasdraw(...)draw(...)makes geometry depend on renderingrectis public, which weakens the abstraction- parent-relative logic is not easy to infer quickly
- the file contains some naming/comments that reflect history more than clear current intent
After this phase, Position should:
- represent geometry and attachment only
- not render itself
- not include rendering/game state headers in the header
- keep current parent-relative behavior working
- be easier to read without chasing unrelated code
Position should not know how to render debug rectangles.
- Remove
draw(State* state)declaration from position.h - Remove
draw(...)implementation from position.cpp - Remove
#include <game/state.h>from position.h - Remove camera.h include from position.cpp if it becomes unused
This gives an immediate simplification:
- geometry no longer depends on renderer/state
- header becomes lighter
- class purpose becomes clearer
Compile:
src/game/position.cppsrc/game/object.cppsrc/game/unit.cpp
Then build:
- Klad1 target
Position no longer contains any rendering/debug behavior.
Reduce the amount of raw internal state exposed.
- Review whether
rectcan become private - If current code still needs direct access:
- add/keep
getPosition() - add minimal specific accessors instead of exposing internals
- Update call sites if needed
Public rect makes it harder to know whether Position is meant to be a real abstraction or just a struct.
Do not force this if too many active files still depend on raw rect.
If needed, postpone full privacy and just document this as a later follow-up.
Compile:
src/game/position.cppsrc/game/object.cppsrc/game/map.cppor laterworld.cppsrc/game/unit.cppsrc/klad1/player.cpp
Then build:
- Klad1 target
Either:
rectis private
or:
- we have a clear note that privacy is postponed because active code still relies on it
Keep current relative behavior, but make it easier to understand.
- Review constructor overloads
- Make the two modes obvious:
- standalone position
- parent-attached position
- Improve local naming in implementation if needed
- for example make parent-relative logic read more directly
- Remove stale comments that explain old experiments rather than current behavior
This is the most confusing part of the file for a reader.
Do not redesign the math unless necessary in this phase. The first priority is readability, not changing layout semantics.
Compile:
src/game/position.cppsrc/game/object.cppsrc/game/unit.cppsrc/klad1/player.cppsrc/klad1/bridge.cpp
Then build:
- Klad1 target
A reader can tell what each constructor mode is for without deep inference.
Make the cached recalculation logic easier to follow.
- Review:
needsUpdatereadysetRequiresUpdate()recalculateIfNeeded()
- Simplify naming if helpful
- Remove any redundant state transitions
- Keep the behavior that current
Object/Unitcode relies on
This is another place where the file feels more magical than it should.
Compile:
src/game/position.cppsrc/game/object.cppsrc/game/unit.cpp
Then build:
- Klad1 target
Cache/update flow is understandable without tracing every setter mentally.
After simplifying Position, make sure Object still uses it cleanly.
- Re-check object.cpp
- Confirm:
setPositionaddPositionsetSize- child position creation are still coherent
- Make only small alignment edits here if needed
Object is the main consumer of Position, so Phase 2 is not complete unless that integration still reads well.
Compile:
src/game/object.cppsrc/game/unit.cppsrc/game/scene.cpp
Then build:
- Klad1 target
Object + Position still work together cleanly after the cleanup.
Ask these questions:
- Can
Positionbe explained in one short sentence now? - Does it still mix rendering concerns into geometry?
- Are constructor modes easier to tell apart?
- Did we reduce header coupling?
- Did we avoid changing behavior unnecessarily?
If any answer is bad, do one more small cleanup before ending the phase.
Build:
- Klad1 target
Optional runtime smoke test:
- launch Klad1
- verify startup
- verify player still renders and moves
After this phase, we should have:
- a smaller
Position - cleaner header dependencies
- no rendering logic inside geometry
- no behavior regressions in Klad1
This phase does not aim to finish all Position redesign.
It aims to make the file understandable and less surprising without destabilizing the framework.