Skip to content

Eliminate Game_Map and Game_Battle global state #2278

@mateofio

Description

@mateofio

These are 2 singletons which store a lot of random state in unmanaged global variables.

Instead of having these 2 namespaces full of junk, I suggest we fold all of this into Scene_Map and Scene_Battle. This will ensure when these scenes are recycled, all the globals get reset properly. It also simplifes our code to have 1 place to find these things.

We'll still need globally scoped access to map and battle data. So we'll need a fast way to access these scenes.

One suggestion I was thinking of.

  • For each scene type, have a global std::unique_ptr<Scene_Type> Scene_Type::instance variable. These means we can't have multiple scenes of the same type on the stack, but we don't ever need that anway.
  • Wrap this up with global acessors:
    • GetScene() which returns a reference and fails if the scene is not active. This is for code which should never run when the scene is not created.
    • GetScenePtr() which returns a pointer and can be used when scene is active or not.
  • Modify the scene stack to just store a stack of raw pointers, pointing to these.

We could potentially still have these Game_Map and Game_Battle namespaces as accessors for this stuff, but the data would all be stored in the scene.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions