I have a "Stage" class which act sort of like a context object and contains every service and module that will be used in the same level. Most services live and die with the stage, but some are reference to upper services in the game. The stage also contains a list of entities who will use the services.
Entities come in vast varieties and each uses different services, so I pass the Stage object in their constructor and let them decide what to use.
Some entities need to load a sprite, which will be cached for later use in the same stage:
Some entities need to check for map collisions:
Some entities need to override camera control:
This works, but every time I add a new service to Stage, every entity needs to be recompiled as they all depend on Stage, which is somehow annoying.
I also have a factory which maintains a map of every entity and its "Key", so I can read and create entities from a file. The factory have to call functions with same signatures, such as
Entity *Create(Stage *stage);
so passing individual service a certain entity need to its constructor don't seems feasible.
I have written several games, and they all end up having a huge class containing everything anyone might need. Is there a better solution to this?
I have looked into the service locator pattern but I'm not sure it is the right solution like this:
Singletons won't work because there might be more than one Stage (split screen 2P, etc...)
AzureBlazeMember Since 27 Apr 2011
Offline Last Active Today, 05:24 AM
- Group Members
- Active Posts 9
- Profile Views 1,313
- Submitted Links 0
- Member Title Member
- Age Age Unknown
- Birthday Birthday Unknown