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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - KazeSonic

Pages: [1]
1
General / Re: Question about event
« on: January 23, 2015, 08:10:56 am »
mmh the question now is more, how could I easily avoid the use of macros ^^. It's something that scared me. I want to do a game as fair as possible. I'm doing some search before the development of the solution that's why I'm here ^^ to have a better understanding on it and to get your point of view on that question.

My game loop is exactly like that more ore less. But what you were talking about the heavy stuff was interesting . I was thinking of how could you do a heavy stuff related to an event outside the event loop ^^. that's it.

Cheers

2
General / Re: Question about event
« on: January 22, 2015, 11:19:28 pm »
I understand what you're talking about eXpl0it3r but I'm not really sure how to deal it. Are you meaning something like that?

sf::RenderWindow window(parameters)

while(window.isOpen()
{
    while(window.pollEvent(Event)
        queue_event(Event);

    while(deque_event(event))
        doHeavyStuff();
}
 

3
General / Re: Question about event
« on: January 22, 2015, 01:45:36 pm »
Thanks guyz for your answers!

You're confirm what I was thinking. Of course I know I'm not superman (uhu!) but in fact I think it's possible to be stuck in the event loop. It could be easy done with macros only if, of course, you trigger an event faster than the cpu could "dequeued" it.

Now let's suppose game (like Street fighter), 2 players are fighting one against the other. If they press "A" to Attack the opponent, the last one will lose 1 HP. Both players have 100 HP and the game is over when one of them reach 0 HP.

We can confirm that the player who will win will be the one who pressed (like a retarded) "A" faster than the other one. But know let's suppose one of them "cheat" and use a macro.
Let's program it as : do { press "A", release "A" } every 10 ms when press F1 for example and then when I press F1 once again stop it. He could kill his opponent in 1 sec.

My question was in fact to understand clearly the behavior of events in SFML in order to prevent a user to use macro.

@Hapax: Let's take my previous example this:

sf::RenderWindow window(parameters)

while(window.isOpen()
{
    while(window.pollEvent(Event)
    {
        doSomething();
    }

    doSomethingElse();
}
 

If doSomethingElse() takes a "long" time to be done, it will also slow down event response time. So does it really matter if "heavy" code is done outside? In any case, what could you propose to avoid this?

Cheers

4
General / Question about event
« on: January 22, 2015, 12:05:16 am »
Hi guys !

I have a (probably stupid) question about the event. Let's suppose this:

sf::RenderWindow window(parameters)

while(window.isOpen()
{
    while(window.pollEvent(Event)
    {
        doSomething();
    }

    doSomethingElse();
}
 

Ok, now without any surpise, pollEvent will dequeue all queued event. Now suppose I'm superman and I can trigger an event faster than light. The result will be that I will be stuck in the pollEvent loop. Now suppose a stupid superman and a only press the same key. Will I be still stuck in the pollEvent loop?

I think the logical answer will be yes but just be sure ^^

Cheers !

5
General / Re: Software Architecture
« on: January 03, 2015, 10:02:53 am »
Mmmh, well ok !

Thanks to you.

Cheers.

6
General / 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 !


Pages: [1]
anything