• entries
271
969
• views
189851

# Networking is..... Fun? Part II

81 views

Hey everyone!

Today I don't have a new screen for you guys, but I will talk about how the networking works for our Space Strategy Game(SSG), and how easy RakNet is to use.

First off, the big advantage we have by making this game turn-based, is the fact that nothing really happens real-time (except for chatting, animations,etc). This was made apparent early in the designing stage of the game's "engine", when I found that instead of sending packets of information constantly, I could just send small "event" packets when a player did something(ie. Clicked the mouse, Moved a Ship, etc). For example, the code that is called when the player clicks the left mouse button to move a ship looks like this:

if(focus && canDo && !acted && tilemap[selectedtilex][selectedtiley].hasShip && !tilemap[pointingtilex][pointingtiley].hasShip ){SSGNet::C_SendMovePacket(client, selectedtilex,selectedtiley,pointingtilex,pointingtiley); }

You may notice that this code doesn't actually have any functions in it that move a ship. That's because even though the changes are local, they go to the server first, which then rebroadcasts them to all the clients, who then react by performing the action described in the packet. This allows all of the clients to remain semi-synchronized.

Speaking of packets, RakNet has this really cool feature built into it called BitStreams. In order to send information, you create a new BitStream, and then give it a packet "type", then you can just put whatever info you want into the Stream and it gets sent off the the server or client. Here's an example of the code that sends a move ship event message:

BitStream dataStream;                dataStream.Write(MOVE_SHIP_ID);        dataStream.Write(x);//Current Ship X        dataStream.Write(y);//Current Ship Y        dataStream.Write(x2);//Destination X        dataStream.Write(y2);//Destination Y                client->Send(&dataStream, HIGH_PRIORITY, RELIABLE_ORDERED, 0);

The information then gets pulled out of the packet at the other end. RakNet does all of this for you, which lets you focus on writing high-level game code, not low level UDP stuff.

Anyways, I'm not having much luck articulating myself very well tonight, so sorry if I just wrote a bunch of "Duh" things down, but the bottom line is, if you want to focus on writing game code and not networking code, go for RakNet. It may not teach you as much about networking in the end, but I think the morale boost of seeing your game running over a network within 2 hours is worth the lost knowledge.

In other news, Mark is busy drawing up a ship for the third faction in the game. It will be interesting to see if he can consistently draw ships in three different styles, and not end up repeating himself. Anywho, He should be done soon, and I'll put a picture up as soon as he does, but until then, look at these older pictures of ships he done with.

Old Picture #1

Old Picture #2

Peace Out!

There are no comments to display.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account