Game Development Reference
In-Depth Information
break;
}
default:
GCC_ERROR(
Unknown message type.
);
}
}
}
You
ve created a little handshaking. There are two types of messages in
this simple design. The first is a normal event, in which case the packet is sent on to
CreateEvent() . The second is a special case message from the server that tells the
local client what its socket ID is. This is how different clients, all playing the same
multiplayer game, tell each other apart, because their server socket IDs must all be
unique. If they didn
'
ll see that I
'
t do this, it would be difficult for the server to know which
actor is controlled by which remote player, or which player
'
'
s score to tally when
there is a successful kill.
The CreateEvent() method looks in the stream for an event type, which is sent in
string format. The event type is used to create a new event object, which then uses
the stream to initialize itself.
void RemoteEventSocket::CreateEvent(std::istrstream &in)
{
EventType eventType;
in >> eventType;
IEventDataPtr pEvent(CREATE_EVENT(eventType));
if (pEvent)
{
pEvent->VDeserialize(in);
IEventManager::Get()->VQueueEvent(pEvent);
}
else
{
GCC_ERROR(
ERROR Unknown event type from remote: 0x
+
ToStr(eventType, 16));
}
}
This event was generated on a remote machine, sent over the network, re-created from
the bit stream, and put back together again just like Dr. McCoy in a transporter beam.
Recipients of the event really have no idea it was generated from afar and sent across
the Internet. You
ll notice some nice trickery with a call to CREATE_EVENT .This
method uses a very useful template class, GenericObjectFactory . Its purpose is to
take some kind of unique identifier and call the constructor of a class that matches that
identifier. The source code for this class is in the companion source code to this topic,
'
Search WWH ::




Custom Search