Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Software Architecture  (Read 1284 times)

0 Members and 1 Guest are viewing this topic.

KazeSonic

  • Newbie
  • *
  • Posts: 6
    • View Profile
Software Architecture
« 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:
  • Use selector when the Owner of the party start the game to merge all connection into one thread but it could complexify the code and it could be horrible to handle the disconnection in game or the end of the game to re-create thread for each client etc...
  • My second option is to use message queue like for the client. It could be:
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.
  • Third solution, use the second solution with functor but i'm not really comfortable with it.

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

Cheers !

« Last Edit: January 03, 2015, 01:06:15 am by KazeSonic »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Software Architecture
« Reply #1 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. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

KazeSonic

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Software Architecture
« Reply #2 on: January 03, 2015, 10:02:53 am »
Mmmh, well ok !

Thanks to you.

Cheers.

 

anything