Game Development Reference
In-Depth Information
Command Interpreter
A game logic needs to respond to external commands. For a human playing a racing
game, these commands will send input to the game logic
s representation of the car:
acceleration, braking, and steering. An AI process will do exactly the same thing.
External entities, such as a human holding a gamepad or an AI process using a
command-based interface, can communicate to the game logic with exactly the same
commands.
You might ask why this is necessary. In any racing game, there should be someplace
in the code that says
'
or something like
that. I know it seems like a lot of extra work, but that breaks the separation between
game logic and game views that I have found to be so important when creating
games.
What should happen is this: The game view presents an interface to the human
player that changes the
If button A is down, set emergency brake
Button A is pressed
state into a game command,
Set
Emergency Brake.
s
the rub: The code that actually sets the emergency brake state on the data structure
representing the car is actually in the game logic. This code only sets the emergency
brake in response to a command
That game command is then sent to the game logic, but here
'
not through a direct tweak to the m_bIsEmer-
gencyBrakeOn member of a class somewhere.
I can hear you whining about this, and I
m not even sitting near you. Let me try to
show you how cool this is before you call me a complete freak.
If your game logic can accept commands through an event-based interface instead of
direct API calls to game logic classes, you can create a programming language for
your own game, just like you see in so many games that have heavy mod hooks like
Unreal. The command interpreter you use for your game will probably have an ultra-
efficient low level, but there
'
s nothing keeping you from coding a higher level inter-
face that accepts console input. Then you could actually type something that would
get sent right to the scripting interpreter, such as SetCarProperty(2, E_BRAKE_
PROPERTY, true) , and guess what will happen? Car two will lock up the tires and
go spinning out of control, all at your command.
'
Unreal
'
s Command Console
Ion Storm
s core code base was basically UnrealWarfare, a modified version
of Unreal 2, and thus had an amazing console command system that could
be used to control almost anything. You could add or remove properties,
move actors, make AIs blind, deaf, dumb, or even all three. The console
system could even take input from a file, creating a weird meta-
programming language for the game. Believe me,
'
it was nice to have
 
 
Search WWH ::




Custom Search