Process Manager
Once again, I gained inspiration for this system from Game Coding Complete. A process is defined as anything that has the ability to change the state of an object. The idea is that all game logic will be defined in processes. In my code I have a base class named Process from which all processes must derive from. The class has two main virtual functions, VInitialize and VUpdate. VInitialize is called when the process first starts processing while VUpdate is called each time through the main loop.
An example of a process would be a physics process. The job of the physics process is to change the state of the world based on certain game events. So for example, the physics process receives an event telling it to move a player left. The physics process, using logic defined in its physics engine, determines the new position of the player and sends an event to the player object notifiying it of its new position.
As you can see, this allows for a clear separation between game logic and game rendering. The rendered player object doesn't know or really care how it moves, it just needs to know where it is so it can render it there. This also provides a clear separation between game logic and user input. From the example above, I just sent a move player left event, not a key A was pressed on the keyboard event. The physics process doesn't care why or who is moving the player left, it just knows it needs to move the player left. It also doesn't care who the player is. It doesn't know whether it is a human player or an AI player.
The job of the process manager is pretty straight forward. Any process that needs to run needs to be attached to the process manager. Each time through the main loop, the process manager's Process method is called in which it goes through all the processes that are attached and calls their VUpdate method.
Input Processor
The input processor is the system that handles all the raw input from the user. My engine supports three types of input devices: keyboard, mouse, and gamepad. I use DirectInput to set up and retrieve the state of all the devices.
Direct input can be a bit cumbersome at times. For example, it takes 5 different DirectInput calls to setup and acquire a keyboard or mouse respectively. First you must create the device which gives you a pointer to access the devices settings and state. Next you set the data format which is the format of the data returned when you get the device's state. Then you have to set the cooperative level, telling Windows how to behave when the game window does not have focus. Now, if you want to set up buffered input rather than just getting the current state of the device, which you will want because it is possible to for example hit multiple keys between two frames, you have to describe the buffer to direct input. Once all of that is set up, you have to acquire the device, which gives you control over the device, until windows takes back control of the device which can happen if your game loses the focus such as the player hits alt-tab, in which case you have to reaquire the device in order to use it again.
What's really frustrating about all that is the DirectInput api hasn't really changed in several years. The last release was DirectInput 8.0 which came out with DirectX 8 which is now in 11.0! You would think it wouldn't take too much work to clean up and simplify. And I haven't even gotten into game pad support!
Microsoft introduced a new input api called XInput which handles input from Xbox 360 controller, and only Xbox 360 controllers. The XInput api is rather simple, but if you want to use any gamepad and still use XInput, you have to determine which connected gamepads support XInput, which currently there is no api call to determine that. The only solution Microsoft offers is this one. Their method goes through all the devices connected to the computer and tries to figure out if it is a Xbox controller. The problem here is that it is looking for a specific device id which only the official xbox controllers have. So if you're cheap like me and have a third party controller because you thought paying full price for a wired controller was silly, then this method won't work for you.
So enough on my DirectInput rant. What does the input processor do besides process input?!? Seeing as how ugly directInput can be, the input processor allows me to seperate all raw input from the rest of the game engine. Instead of my game logic interpreting raw input, I create events for each input I receive. The following is the list of events the input processor can trigger:
- KeyboardEvent - The state of a keyboard button has changed, either being pressed or released
- MouseButtonEvent - The state of a mouse button has changed, either bing pressed or released
- MouseMovedEvent - The mouse has moved
- GamepadTriggerEvent - The state of the trigger on a gamepad has changed
- GamepadButtonEvent - The state of a gamepad button has changed
- GamepadDirectionpadEvent - The state of a gamepad direction pad has changed
- GamepadThumbstickEvent - The state of a gamepad thumbstick has changed
It really feels like my engine is starting to come together. My next step will be to implement a game state system. More info on that to come.

