At first, I would pass the input engine over to objects that need it, for example the Player. Every time I create a player, i would pass the input engine over to it, like this:
player1->inputEngine = inputEngine;
You have bigger issues than the use of statics.
People think of input as events because in event-based applications they are.
Games are not event-based (there are of course events in games etc., but they are not event-based like applications are), and input in games is not an event.
You don’t press a key and then directly send that to a character and make it jump.
You collect input events into a queue and then the game manager reads them on each cycle, and then at a specific point inside the game loop
you handle inputs and the jumping of the character. Additionally, letting the player character handle its own input is flawed; the character then needs to know more about its surroundings than it otherwise should. For example, if the character is in the air it should not be able to jump again. Now the character class needs to know about the physics engine to get information as to whether or not it is on the ground to decide if jumping is possible.The character is a slave to the physics engine, not the other way around.
Note of course that that does not mean the physics engine knows what a character is, it just understands certain properties that the character has and a higher-level class (such as the engine itself) gets just that data from the character class and feeds it to the physics engine.
Handling input is done at a much higher level than at the character’s level. The higher-level game class knows what characters are and what physics is and what the game rules are (hence it is the game
class). I want to reiterate, the game class knows what the game rules are
. The game class decides if the character is able to jump in its current situation and it is what contacts the physics engine and possibly other modules (maybe the player can’t jump while a certain light is on or when a sound is playing) before deciding, “Okay, you can jump.”
With your proposed design, the character class would be absolutely monolithic, knowing about the physics engine, world lights, and sound engine, when really all it needs to be is a normal game entity with a health bar.
Edited by L. Spiro, 30 November 2013 - 09:49 AM.
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums