SFML community forums

Help => General => Topic started by: KazeSonic on January 03, 2015, 01:04:15 am

Title: Software Architecture
Post by: KazeSonic on January 03, 2015, 01:04:15 am
Hi guys !

My first message here ! Sorry for the title but I had no idea what to write xD

So I'm here to learn from your critics. I'm actually doing a small video games. It's multiplayer & online game. It's going well but I have some questions for the design of the communication between the client and the server. The game is working like this :

The server handle a party of 4 players maximum. When a message is sent to the server, the answer is automatically broadcast to all players in the party.
The flow to start a game is : Main menu => create game => wait for other players if wanted or not => start the game

For each action from the client, the client needs the confirmation from the server. (i.e player1 want to move to a location he said to the server "I want to move there", the server answer the current (if move is not accepted) or the new position and broadcast it to all players in the party). A party can have 4 players maximum

Actually I'm dealing it like this:

Client : 2 threads

Main thread (MainClient) doing this :
while(run)
{
    Event();
    Dequeue_and_treat_messages();
    Update();
    Display();
}
 

The second thread (ConnectionHandler) handle the connection with the server and do this:
while(run)
{
    Receive_message()
    Queue(message);
}
 

And for the server

One thread for each client (ClientHandler) doing :
while(run)
{
    Receive_message();
    Treat_message();
}
 

and when the client start a game a new thread is created (GameHandler) to handle the game update doing:
while(run)
{
    Update_game();
}
 

That's mean in the "worst" case a maximum of 5 threads are created for one party one the server. But it will require mutex on all data to be thread safe in each data modification. To avoid this only one thread will manage the received message from the client. I'm here to get your feedback to improve this part.

I know I have different options like:
For each client
while(run)
{
   Received_Message();
   if(in_game)
   {
        Queue(message);
    }
    else //in menu
    {
        Treat_message();
    }
}

and the GameHandler
while(run)
{
    Deque_message();
    Update();
}
 

It could work but it's not really elegant. And the problem I have with this solution is for each message received  the "if" is done. I would like to avoid this.

If you have any idea / comments / what ever, feel free !

Cheers !

Title: Re: Software Architecture
Post by: eXpl0it3r on January 03, 2015, 01:35:48 am
This is the SFML forum. For general C++ or code design questions you should use communities dedicated to these kind of categories.

https://stackoverflow.com/
https://gamedev.stackexchange.com/
etc.

If you just want to throw around some ideas, you're welcome to join the official SFML IRC channel (http://www.sfml-dev.org/community.php). :)
Title: Re: Software Architecture
Post by: KazeSonic on January 03, 2015, 10:02:53 am
Mmmh, well ok !

Thanks to you.

Cheers.