Hi!
I hope you are having good holidays, and aren't dying of a chocolate
indigestion!
I would like to begin to work on the network, but as nobody likes how it was
working in the clanlib version, i'm here to get advices!
So, if I understood everything, the right way to do it, would be to compute
all physics on the server , and then send sprites position over the network
to all the clients.
Based on this, here is what I think we should do on the code (please correct
me if I'm wrong because I want to begin quite soon :) :
* Initialisation :
Server:
1. Init the game the same way as a local game.
2. Send (to the clients) informations about map and teams chosen
3. Give to each Physical object a unique number (we will use this later
as an identification number for the object).
4. Send object list.
Client:
1. Get the informations about map/team, and init them
2. Init map, teams, interface(wind,energy bars, weapon menu...) , camera,
keyboard/mouse.
3. Get the object list.
4. Match each character in the teams with the one in the objet list to
give them to give them there corresponding identification number (ID).
(on fait la correspondance entre les joueurs(character) contenus dans les
équipes et les joueurs contenus dans la liste des objets envoyés par le
serveur)
5. Delete from the object list the character we received in 3, because
the character have already been added and initialized in 2. This way we have
the teams/character correctly initialized on the client, and we know which
character on the server correspond to which character on the client.
(on efface de la liste des objets les joueurs qu'on a reçu en 3, parce qu'on
les a déja ajoutés et initialisés en 2. De cette manière, les équipes/joueurs
sont initialisés correctement sur le client, et on peut faire la
correspondance entre chaque joueurs sur le serveur et sur le client)
* Main loop:
Server:
1. Same loop as a local game.
2. Send the events which occured during the loop. (see the list of events
below)
3. Get keyboard/mouse events from the clients.
Client:
1. Get event list and process it.
2. Draw sky/map.
3. Draw each object using there normal method (the same ::Draw() function
as in a local game).
4. Draw interface
5. Send keyboard/mouse events to the server (send the SDL_keycodes ? ).
* List of events:
- sound to play
- object related (include skins) : creation, deletion, movement, rotation
(scale / alpha ?)
- ground related : explosions information
- team/character : modification of energy, skin changement
- currently playing character/weapon : weapon changement, shoot angle
modifications, strenght bar
- game : game state (gamePLAYING, gameEND_TURN...), wind forces
modification, game messages ("the rocket left the battlefield!", ...), water
level (??), clock value(??)
If you read until there, thank you! :)
But it's not finished yet!
Looking at the list, I think i have forgotten a few things... And it seems
very intrusive (network code in the physical engine...), and it's really bad
if we have network parts all over the code...
Also, this implementation makes everything computed on the server, which
causes some problems with particles: Object particles have to be computed on
the server, because explosion particles add a force to objects they touch.
Wind particles can't be computed on the server, because their disposition is
dependant to the camera position (currently, all wind particles are displayed
where the camera is, to avoid computing particles which are out of focus)...
Which means wind particles need the physical engine running to work :/
For the implementation, I think we should keep all network specific code in
the network/ directory, and only make calls to network functions in the main
code to keep something clean enough.
The current action handler should be independant of the network, but it should
be kept, as it will be needed to add artificial intelligence in a proper way.
So a new event class is needed, which will makes some calls to the action
handler and changes positions of objects..
Haypo -> (if I remember well), In happyboom, you wrote a sort of a TCP stack
over UDP to keep the speed of UDP, and still be sure data were received
correctly. Wouldn't it be simpler and faster to use both TCP and UDP for the
connection? I mean we send position information which needs to arrive
quickly using an UDP connection, and important data(energy loss...) using a
TCP connection.
If you have any comment, feel free to send it! I never wrote any network code,
so if i'm doing big mistakes somewhere, please tell me! :)
If you're ok with all of this, maybe we should set up a wiki page to continue
this!
Thanks for reading until the end!
Lodesi
___________________________________________________________________________
Nouveau : téléphonez moins cher avec Yahoo! Messenger ! Découvez les tarifs
exceptionnels pour appeler la France et l'international.
Téléchargez sur http://fr.messenger.yahoo.com