PDA

View Full Version : Sprite list


StealthyCoin
2007.06.29, 06:08 PM
Right now I am sending my list of sprites to all the clients this causes some jitters even when host/client are both on localhost. Instead I want to send only the information necessary. Im not sure what I should let the client handle and what the host should handle.
First the lists of sprites might not always be in the same order so I think some kind of sprite ID thing is in order, so i'll need a SpriteFactory class.
Then I could send messages like:
"SpriteID:384 x:37 y:493 animation:left"
Should I let each client handle the length of time the animation has been going, or should I add something like "animTime:63"?

I haven't found many articles on networking at all, so my whole game thus far has been repeated guess/fail.

Anyway I guess the question is how should i break down my sprite list to send in a smaller format. I suppose when i add a sprite i'll have to send the whole sprite over. But I shouldn't have to send every sprite every frame like I am doing now.
[/LIST]

Fenris
2007.06.30, 04:22 PM
Just a clarification - what do you mean by sprite in this case? Does it include bitmap data? Or just an identifier?

Either way, you should probably devise a binary format for your messages (don't forget to do them in network order (http://en.wikipedia.org/wiki/Endianness#Endianness_in_networking)) since every byte shaved off a packet is a win.

Then, it also depends on the nature of your gameplay - is it real-time or turn-based? Please tell us more about your game. :)

StealthyCoin
2007.06.30, 10:15 PM
realtime 2d Tank game with Ari Feldman's sprites. Yes the tank sprite has about 36 images in it, thats... way way too much to send.
I started making a Message class to handle all transactions, and I have it setup where when you create a sprite it gets an ID. Now Im figuring out what the client should do and what the server should do.
Server is obviously in charge of moving them and checking collisions. Should the host be in charge of keeping Animation times? Or should each host update the animations independently, as long as the host tells them which animation is being used it should be fine right?

Fenris
2007.07.01, 05:55 AM
First off, I'm not sure why you would want to send the actual bitmaps - they should be stored on the client side. The server could send an initial message along the ways of: create tank with bitmap #3 with ID #44 @ position 300, 220. The client would then load bitmap #3 (whichever that is - the server and client should be able to agree on this) and assign ID 44 to it.

Next, what you want to do is have the clients send input commands to the server. The server takes the commands, runs them and then broadcasts which sprites have changed direction, fired a bullet or whatever. This is called a "delta packet", since it only sends the changes made to the world since the last packet.

The client then runs the simulation with these parameters. However, this is bound to get out of sync eventually, since latency, packet loss and timing issues will make everyone's version of the world change.

That's why you will also send "state packets" - packets that contain the entire simulation state. You send positions, directions and speeds of every interesting thing in your simulation: all the tanks, all the bullets, all the building healths - the works. This packet should be send once every two or three seconds.

The idea is that the server sends the correct world, and the client runs with it for a while. The server corrects all errors after a while, and this is repeated for the duration of the game.

Then, in order to be really fancy, you should run timestamps on all the packets, so that when a "bullet fired" packet comes, you can see how long ago it was originally sent, and take that into account in your simulation.

Keep asking! :)

StealthyCoin
2007.07.01, 04:42 PM
Awesome, thanks for that info, never would have figured that out myself. The reason I am currently sending the whole game world is because I am impatient and wanted to see results right away. What easier way then to send the whole game world images and all.

I can't imagine this going smoothly the first time so i'll probably have more questions.

nich
2007.07.01, 08:37 PM
possibly a bit advanced for your project, but always a good reference:
http://unreal.epicgames.com/Network.htm

OneSadCookie
2007.07.01, 08:44 PM
The other standard link:
http://trac.bookofhook.com/bookofhook/trac.cgi/wiki/Quake3Networking

These come up every time, why don't people search the forums?

AnotherJake
2007.07.01, 10:22 PM
These come up every time, why don't people search the forums?
[sensless boring rattle] I think it's kind of funny how so many people will spend thousands of hours programming but shy away from spending a few minutes here and there to plug in a search term or two from time to time. I guess a lot of programmers just haven't figured out yet that programming is *at least* 10-25% constant learning for the duration of their career (or hobby), even after they've kinda figured out what they're trying to do. I've spent so much time searching for stuff that I've run across my own threads on the front page or two of a general Google search from time to time -- you know you're really screwed when that happens! At that point I would generally advocate posting a question, but I've found that you can almost always squeeze it a little more and eventually some little bit of info will drip out to offer a hint. [/sensless boring rattle]

Anyway, all that being said, still it's kind of nice to catch the same old links being put up from time to time. Sometimes something new pops up. It's almost like a group sanity check I suppose. Plus, I just realized that *some* of that mumbo-jumbo in those two pages is actually starting to make at least a glimmer of sense to me now, and if I hadn't seen them again on the new posts page I wouldn't have bothered to look again. :)

StealthyCoin
2007.07.02, 03:03 PM
I did search, I just didn't quite know what I was searching for so nothing useful came up. Essentially searched for networking in the networking section. And I live on google.
I only ask a question every year and a half, you can be pretty sure I use google quite liberally.
Thanks for the links.

AnotherJake
2007.07.02, 03:22 PM
I did search, I just didn't quite know what I was searching for so nothing useful came up. Essentially searched for networking in the networking section. And I live on google.
I only ask a question every year and a half, you can be pretty sure I use google quite liberally.
Sorry about that. I wasn't actually targetting my comments directly at you (although it certainly looks that way in retrospect, whoops). :)

wyrmmage
2007.07.08, 02:59 PM
there's a nice sticky at the top of the forum that will answer most questions you might have, too (even if the articles are a bit long...) :)
-wyrmmage

AmirCicak
2007.11.24, 06:57 AM
Yes maybe they are too long :). But is good to use search first.