Daily Archive for November 27th, 2009

OpenGBH networking prototype

I’ve been working on networking, and I got first networking prototype ready. Right now only psuedo-AI pedestrian synchronizing is working – but it’s working really nicely. I set update rate to about 0.2 seconds (5 packets per second), and it was still really smooth, even when I randomly moved their target (you couldn’t actually see any lag with that, and it corresponds to 200 msec or less ping).

I attached rendering to dedicated server, so you can see what’s going on there. Clients are not yet synchronized, so when they move, they jump around crazily:
opengta2_clientserver

The networking is now done via callbacks and messages. You can send a new networked message to specific player like this:
Network_Message* Msg = Clients[0]->Connection->NewMessage();
Msg->Start(NETMESSAGE_NEWCLIENT);
Msg->SendInt(Clients[0]->PlayerPed);
Msg->End();

And on the client side he will receive this callback:
void netCallback_NEWCLIENT(Network_Connection* Connection, Network_Message* Msg) {
Clients.LocalClient = Msg->ReadInt();
}

It is roughly like that. Networking is going to be thread safe (it’s designed to allow for several threads, but not currently protected against threading collisions yet). If you want networking layer like that, you can freely take the files from OpenGTA2, and change them for your project (they are stored in only two files, network.h and network.cpp).