The state context
In general, every screen will need to display some text or sprites, draw to the screen, among other common things. Due to this fact, and to avoid unnecessary memory wasting by loading the same texture or font to memory in multiple places, we introduced the State::Context
structure. It works as a holder of shared objects between all states of our game.
Essentially, every state will now have access to the getContext()
method, which itself contains the pointer to the window used to draw its objects and resource holders such as font and texture managers. Here's the declaration of the structure:
struct Context { Context(sf::RenderWindow& window, TextureHolder& textures, FontHolder& fonts, Player& player); sf::RenderWindow* window; TextureHolder* textures; FontHolder* fonts; Player* player; };
The usefulness of...