Game Engine Architecture

(Ben Green) #1
361

8.5.5. Managing Multiple HIDs for Multiple Players


Most game machines allow two or more HIDs to be att ached for multiplayer
games. The engine must keep track of which devices are currently att ached
and route each one’s inputs to the appropriate player in the game. This implies
that we need some way of mapping controllers to players. This might be as
simple as a one-to-one mapping between controller index and player index,
or it might be something more sophisticated, such as assigning controllers to
players at the time the user hits the Start butt on.
Even in a single-player game with only one HID, the engine needs to be
robust to various exceptional conditions, such as the controller being acciden-
tally unplugged or running out of batt eries. When a controller’s connection
is lost, most games pause gameplay, display a message, and wait for the con-
troller to be reconnected. Some multiplayer games suspend or temporarily
remove the avatar corresponding to a removed controller, but allow the other
players to continue playing the game; the removed/suspended avatar might
reactivate when the controller is reconnected.
On systems with batt ery-operated HIDs, the game or the operating sys-
tem is responsible for detecting low-batt ery conditions. In response, the play-
er is usually warned in some way, for example via an unobtrusive on-screen
message and/or a sound eff ect.


8.5.6. Cross-Platform HID Systems


Many game engines are cross-platform. One way to handle HID inputs and
outputs in such an engine would be to sprinkle conditional compilation di-
rectives all over the code, wherever interactions with the HID take place, as
shown below. This is clearly not an ideal solution, but it does work.


#if TARGET_XBOX360
if (ButtonsJustWentDown(XB360_BUTTONMASK_A))
#elifTARGET_PS3
if (ButtonsJustWentDown(PS3_BUTTONMASK_TRIANGLE))
#elifTARGET_WII
if (ButtonsJustWentDown(WII_BUTTONMASK_A))
#endif
{
// do something...
}

A bett er solution is to provide some kind of hardware abstraction layer, there-
by insulating the game code from hardware-specifi c details.
If we’re lucky, we can abstract most of the diff erences beween the HIDs
on the diff erent platforms by a judicious choice of abstract butt on and axis


8.5. Game Engine HID Systems

Free download pdf