Networking is..... Fun? Part II

Published February 05, 2006
Advertisement
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!
Previous Entry Networking is..... Fun?
Next Entry New Piktars!
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

!

1181 views

'Roids

1598 views

Post Dva

1345 views

Untitled

1181 views

I'm a sad panda...

2198 views

Untitled

1088 views

Progress

1134 views

Angels 2X!!!!!

1552 views

T3H Progress!

1374 views

ZOMG!!!!

1257 views
Advertisement