Digital Dave

Musings on projects, business and life.

Icon

Snowball Fight: Milestone I Complete

Well, I’ve completed my initial ‘base’ task for my networking project. The big concern for the project was to at least have it to where I could have two players running around simultaneously. This, alone, should easily net me an A on the project. There are still people who have yet to start on a final project. Call me an over-achiever, but I enjoy myself some game dev time. >;)

I’ll need to do some testing with somebody to make sure that what I’ve got works well from two different locations. Running it on my poor laptop isn’t netting me the results that I need, and that’s probably because when I fire up the server, I have 2 threads running. Firing up a client, nets 1 thread. Add that with two games, utilizing SDL, and you’ve got yourself a ‘lag fest’ consuming tons of system resources, even over the local host. I’m pretty confident that the code is well enough to maintain a constant stream of data back and forth, without all of this other processes going on, but we’ll see.

Essentially, my logic goes something like this.

I have a ‘PlayerPosPacket’ structure that consists of the x, y, avatarNumber, playerNumber, and the totalPlayers (maintained by the server packet) for each player connected.

With that in hand, I can easily pack up the players data points from the current player objects, send it on to the server, the server can unpack it, re-assign the new values to the objects, repack the new values (catching any updated movements), and send it back to the client with the updated structure. And the process revolves just like that.

I would post code, but the project hasn’t been turned in yet and I don’t want to violate any school rules in the rare case somebody finds this blog. I’ll save ‘code-and-show’ until the end of next week.

After I do some testing, I’ll be sitting down to write down the tasks that I want to complete by Christmas Eve, doing some housekeeping on the code base, and moving on to throwing objects.

Category: academic, Coding

Tagged: , , ,

  • http://skirmish.dreamhosters.com/devlog/ Stephen

    Hey David — it’s been a while since I’ve commented, but it looks like you’ve been making some solid progress. :)

    A couple of comments about your networking: what is the difference between avatar# and player#? Are both really needed? Also, it should go without saying, and I’m sure you’re already doing so, but make sure that you’re using the smallest possible data types in your packets (ie. no reason to use 32-bit INTs for any of those fields). In terms of further optimization (and somewhat security-related) you may want to consider having the clients send their coordinates as an *offset* from the last position that they broadcasted, rather than trusting the client to report a truthful absolute position in the world. With an offset, not only are you taking away the client’s ability to cheat and teleport, but you can also get away with using a smallest data-type for the X and Y, like a CHAR, since a player’s offset between updates typically won’t go past -128-127.

    Keep up the progress! I’m looking forward to playing a round or two against you when it’s done. ;)

  • http://skirmish.dreamhosters.com/devlog/ Stephen

    Hey David — it’s been a while since I’ve commented, but it looks like you’ve been making some solid progress. :)

    A couple of comments about your networking: what is the difference between avatar# and player#? Are both really needed? Also, it should go without saying, and I’m sure you’re already doing so, but make sure that you’re using the smallest possible data types in your packets (ie. no reason to use 32-bit INTs for any of those fields). In terms of further optimization (and somewhat security-related) you may want to consider having the clients send their coordinates as an *offset* from the last position that they broadcasted, rather than trusting the client to report a truthful absolute position in the world. With an offset, not only are you taking away the client’s ability to cheat and teleport, but you can also get away with using a smallest data-type for the X and Y, like a CHAR, since a player’s offset between updates typically won’t go past -128-127.

    Keep up the progress! I’m looking forward to playing a round or two against you when it’s done. ;)

  • http://www.david-mcgraw.com david.mcgraw

    Hi Stephen!

    You are absolutely right about data packet size. Right now I was more concerned with getting the thing working then on the actual data management portion of it. Easy fix though, because a lot of that is wasted space.

    avatarNumber is the number I use to depict the actual avatar is being used from my sprite sheet, essentially the color of their jacket. This only needs to be a value between 0 and 6, so this can easily be a Char value.

    playerNumber is… is… Now that I think about it… A waste of space, and not needed. Just changed a portion of my code and ran a test, and it works fine without it.

    I’ll also take a look at using an offset system this evening, and doing some testing.

    I appreciate your feedback, Stephen. It’s nice to discuss this stuff with somebody, because I’m overlooking some basic things. Thanks.

  • http://www.david-mcgraw.com david.mcgraw

    Hi Stephen!

    You are absolutely right about data packet size. Right now I was more concerned with getting the thing working then on the actual data management portion of it. Easy fix though, because a lot of that is wasted space.

    avatarNumber is the number I use to depict the actual avatar is being used from my sprite sheet, essentially the color of their jacket. This only needs to be a value between 0 and 6, so this can easily be a Char value.

    playerNumber is… is… Now that I think about it… A waste of space, and not needed. Just changed a portion of my code and ran a test, and it works fine without it.

    I’ll also take a look at using an offset system this evening, and doing some testing.

    I appreciate your feedback, Stephen. It’s nice to discuss this stuff with somebody, because I’m overlooking some basic things. Thanks.

David McGraw

Founder of iGotIt Games. Trader. Runner. Warrior. Motivator.