Saturday 13 June 2009

Cross platform controls

I've been working hard getting the controls sorted for both PC and the Xbox 360 game code base. Our project will be written firstly on a PC but with every bit of logic being the same regardless of platform, only the controls should change when the game is ported to the Xbox (to account for the Xbox 360 controller). XNA studio allows for the use of "#if XBOX" and "#if !XBOX" pre-processor directives which instruct the compiler to compile specific bits of code, leaving out code not related to the target platform. In theory, the use of pre-processor directives means that we can code for both the Xbox and PC platforms at the same time, and when the code is compiled, only the relevant code actually makes it into the executable for that platform.

Being a software engineer by trade, I like to enforce standards of cleanliness in code (in addition to comments, whitespace, naming conventions, etc). Given he fact that we're writing the game for two platforms at once, I've decided to move the input handling from the main game class to a separate class which will contain these pre-processor directives. Granted this means that this class will be messy, but at least it keeps any calling class cleaner in terms of the code it has to call, because there is only one method to call which handles the input from any outside class.

Another way we're going to keep all game engine implementation the same regardless of platform is by wrapping every operation of the engine in a separate method, no matter how small. This may cause more work initially, but if the game input class calls a method called "MoveCamaraLeft" regardless of the platform being use, we can be stringent about what the game engine will do. This will of course make our game debugging easier too.

No comments:

Post a Comment