Creating a shared context involves a number of steps:
- Writing the shared context and adding references to the classes we want shared.
- Ensuring every object has access to the shared context.
- Removing any local references that components currently store and instead using the references in the shared context.
- Removing any setters/mutators from components for classes that are now included in the shared context.
- Input: we want any component to be able to query the keyboard state.
- ObjectCollection: we want any component to be able to add other objects to the game, such as our projectile attack component creating new arrow objects.
- WorkingDirectory: to retrieve anything from the disk we first need to retrieve the location of the asset.
- TextureAllocator: some of our components (like our projectile attack) can add textures to objects.
- Window: any component that acts as a camera or interacts with the player’s view will require access to the Window class.
Now that we’ve decided which classes we want to include we can write the SharedContext class.
Because we’ve made numerous small changes to the SceneGame::OnCreate function over the course of this tutorial you may want to refer to the implementation in the Github repo to make sure that your code matches mine.