Game Development Reference
In-Depth Information
possible for a programmer to make a cheat program that eliminates the other play-
ers. Cheating will be discussed in further detail later in this chapter.
Because of the authoritative nature of the server, implementing gameplay code for
a server/ client game is more complex than in a single-player game. In a single-
player game, ifthespacebar firesamissile, thesame codethat detects thespacebar
can create and fire a missile. But in a server/client game, the spacebar code must
create a fire request packet that is sent to the server, and then the server notifies all
the other players about the existence of the missile.
Because it's a dramatically different approach, for games that intend to support
both multiplayer and single-player modes, the best practice is to implement single
player as a special case of multiplayer. This is done by default in many game en-
gines, including the id Software engines. What this means is that single-player
mode actually has the game running a separate server and client on the same ma-
chine at once. The advantage of making single player a special case of multi-
player is that any gameplay code that works in single player should also work in
multiplayer. Otherwise, a network programmer may have to spend a great deal of
time converting client-authoritative gameplay code to work in a server-authoritat-
ive setting.
If we go back to our sample dodge ball game, let's imagine we want players to be
able to lead targets. That is to say, they need some way of knowing in which dir-
ection the opposing players are travelling in order to make an educated throw that
they expect to hit the target with. In the best case, a client can expect to receive up-
datesregardingthepositionofopposingplayersfromtheserveronceeveryquarter
of a second. Now imagine if the client only updated the positions of the oppon-
ents when the new position data is received from the server. That would mean that
every quarter of a second, the opposing players are going to teleport to a new loc-
ation. Imagine trying to aim a dodge ball in this scenario—it sure doesn't sound
like a very satisfying game to play!
To combat this, most games will implement some sort of client prediction , or
the client making educated guesses of what happens in between updates from the
server. In the case of movement, the way client prediction could work is that the
server could send the position of the opposing players as well as the velocity of the
opposing players. Then, for the frames between the server updates, the client can
extrapolate the position of the opposing players based on their last known position
and velocity, as demonstrated in Figure 12.8 .
Search WWH ::




Custom Search