First of all … Hi :),
My name is chillum and i’m studying informatics on the University of Kassel / Germany.
I just found this Forum and i’ve read a few hours this night,
its just great :).
If my english might sound weird in the following post, i excuse me in advance, it’s pretty late and i’m damn tired atm, but i just want to get some opinions as soon as possible
I’ll begin why i’m interested in the network part of a multiplayer game
Yesterday I got an exercise to program a simple server/client chat with chatrooms, so i played with sockets and PrintStreams and so on.
After a few hours of reading and gathering of implementations types, i choosed the Multithreaded version and
finished it yesterday. It wasn’t that hard. All runs fine.
It’s based on a server with a thread, which listens for clients.
if a client connects, it opens a own new Thread on the server specially for one client.
This thread listens for an incoming String, processes it and send an answer back to the client.
Like I said, all runs fine, but i’m not happy about the processing of the incoming data.
It’s only based on Strings and a wild bunch of if/else operations, which check if the user wants to create a room or something like that.
Now the game part :
Today i played a cannon-fodder like game, where 2 players play on the same keyboard and i felt to build a clone, but only with a multiplayer part and some “cool” modifications and new features ;). There will be 2 player objects with a bunch of AI-comrades and even more Monsters, which have to be killed. I think there will be ~100 Objects on the GameField PLUS temporary objects like Bullets, Addons and so on.
And here the network part kicks in. My first idea was using the String Style Method, like in the chat-programm.
But then i thought at the amount of if/else operations and couldn’t believe that this will be any kind of elegant or fun.
So i found the class ObjectStream and thought it should be much better to pass objects directly, if a monster position changes, the server sends the monster object with the new status/position to the client, and the client replaces his monster object with the new one.
But this could be very slow, i thought. So i searched a lot more and found RMI … i thought PERFECT … got a Bingo Sample from SUN to work and then realized, way to complicated for the first steps in game networking.
Now, late at night i had the idea to create an Object for every possible action in the game. E.g. MOVE …
so i don’t need to pass the whole monster or player object with all his data, but a special fitted object which only contains the changes, that should be made.
For Example:
class Player , which basically contains of
int ID;
int x,y; // coordinates on the screen
Weapon weapon; //current weapon
then i create a
class move, which contains only the changes occuring during movement
int id; //which object should be moved ?
int x,y; // to which position it wants to be moved or how many pixel refering to its old position
So when the player wants to move (or movement key is pressed )
a new move object is created and the constructor Move(id,x,y) is called.
eg Move doMove = new Move(id,x,y);
then:
out.writeObject(doMove); //or something like that, don’t worked with ObjectStreams before
the server gets the object, identifies it with isTypeOf and handles it.
The server reads out the id, and changes the x,y values of his Object with this id.
then he creates an own move object with the same id and sends it back to the client, which updates
his object.
I hope its clear what i mean :P.
Could this type of networking work with an max. object count of ~300 ?
Or should i use only functions which will code the performed action in a
String instead of doAction-Objects ?
I would prefer the Object approach , it just fells … ehrmnn … right
Hope this wasnt too confusing at all
And thanks for reading
Good Night/Morning all ;D