1

i heard this phrase quite often to "send the game state or simulation state " in network game/simulation realm and my question is stem from that and i really need to know how? .

I m working on real time network physics simulation, my question is only that : *How simulation state can be transfer from server to client*? (the least simulation state are the coordinates X,Y of simulated bodies=))

Possible scenario: taking the example of simple ball simulation, the server is moving the multiple balls and should send coordinates of each ball to client for drawing and updating simulation, and each ball should move according to its received coordinates from the sever.

thanks,

jibbylala

P.S: please don't mention any string based solution i am looking for generic mechanism which can be applicable on different Physics simulation.

static void main
  • 728
  • 2
  • 9
  • 34

1 Answers1

1

In fast paced action games, the state of dynamic objects is sent constantly in structures. By state I mean it is usually position and rotation. Depending on model's architecture, it can be server constantly pushing the states, or sending the change in state when it occurs. More often the first one. When the state is not received in some period of time the game lag occurs. The state can also have parameters such as velocity, acceleration, etc. really depends on game and on how you want to handle game events. Lets say we are writing simple 2D game with flying ships on surface then the state could be a simple class in java like:

class ShipState{ 
      public float x; 
      public float y; 
      public float angle;
}

The netcode in game takes care of transporting these structures. Games usually have their own protocol built on top of TCP/IP and UDP to handle everything, since there is lot of different type of information going both ways in real games, not just physical state. If you are serious about your project, you should really look into networking libraries. I strongly doubt there is anything really good, since JAVA is not very popular on this frontier. Single google request brought up this Kryo library which seems pretty good. You could also probably look into netty, which is a very solid general purpose networking library. If I was to write a netcode for game in Java I would just go and dig up open source game networking libraries written in C/C++, such as Enet to get some ideas.

Getting to the bottom of your question, regarding the ball simulation on server, it is as simple as server sending ball coordinates and clients receiving those. If you are not sure how it is done, you probably want to look at these tutorials. And other general Java networking tutorials. Good luck!

m0s
  • 4,250
  • 9
  • 41
  • 64
  • 1
    I'd like to point out that being a physics simulation, you can also provide a `double speed; double xVector; double yVector;` to represent it's current velocity (speed and direction.) This will reduce the number of required state updates by the server. The x and y can be updated based on the velocity, so you only need to be updated when the velocity changes. – corsiKa Mar 24 '11 at 22:41
  • m0s wrote:"The netcode in game takes care of transporting these structures", No that's wasn't my question,... i know netcode in game take care but question was HOW, if someone don't want to use some library =) – static void main Mar 24 '11 at 23:07
  • @Static Void Main - the answer to how part is in the last link in the tutorials. Also your how is little ambiguous. You could ask "How to send data over TCP/IP?" or "How to build a basic client/server program in Java?" or "How to design a low latency game networking protocol?" I don't mean to be boring, I just truly don't understand which part exactly are you stuck on. And to answer your question in comment, if you don't want to use some library you will have to write your own library :D It is not a very simple task you have. – m0s Mar 25 '11 at 00:06
  • i hope this post will help knowing my intention: http://www.coderanch.com/t/531394/Streams/java/Sending-Receiving-object-references-or – static void main Mar 25 '11 at 16:23
  • @Static Void Main Yes using strings for this is not a very good idea. From what I understand from your explanation on coderanch.com you have your engine running, and you have set up basic network connection. Now you can send objects through stream, check out this question: http://stackoverflow.com/questions/1453028/how-to-send-and-receive-serialized-object-in-socket-channel The answer is exactly what you need for sending the state objects through network. Your clients need to dispatch the packets in your simulation's main loop and update the state of objects, then do the rendering if needed. – m0s Mar 25 '11 at 20:19