So what's about introducing a new action that will synchronize time across 
every players on internet ? Let's say we synchronize every second ? every half 
second ?

We will hold the game timer until we receive an action in the future and then 
we will continue until we reach a new action in the future.

in action_handler.cpp :
void ActionHandler::ExecActions()
{
  assert(mutex!=NULL);
  while (queue.size() != 0)
  {
    SDL_LockMutex(mutex);
    Action *action = queue.front();
+    // Actuate max time available
+    Time::GetInstance()->SetMaxTime(action->GetTimestamp());
    // If action is in the future, wait for next refresh
    if(action->GetTimestamp() > Time::GetInstance()->Read()) {
      SDL_UnlockMutex(mutex);
      return;
    }
    queue.pop_front();
    SDL_UnlockMutex(mutex);
    Exec (action);
    delete action;
  }
}

in game_loop.cpp :
void GameLoop::Run()
{
  int delay = 0;
  uint time_of_next_frame = SDL_GetTicks();
+  uint previous_time_frame = 0;
  // loop until game is finished
  do
  {
    Game::GetInstance()->SetEndOfGameStatus( false );
+    // Refresh clock value
+    RefreshClock();
+    // If the clock has been refresh, computing a loop
+    if(Time::GetInstance()->Read() > previous_time_frame) {
      // one loop
      StatStart("GameLoop:Refresh()");
      Refresh();
      StatStop("GameLoop:Refresh()");
+       previous_time_frame = Time::GetInstance()->Read();
+    }

    // try to adjust to max Frame by seconds
    time_of_next_frame += Time::GetInstance()->GetDelta();
    if (time_of_next_frame > SDL_GetTicks()) {
      StatStart("GameLoop:Draw()");
      CallDraw ();
      // How many frame by seconds ?
      fps.Refresh();
      StatStop("GameLoop:Draw()");
    }
    delay = time_of_next_frame - SDL_GetTicks();
    if (delay >= SDL_TIMESLICE)
      SDL_Delay(delay);
  } while( !Game::GetInstance()->GetEndOfGameStatus() );
}

Well, just a reflexion. Will probably need much more things to do ...

Drayan

-----Message d'origine-----
De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] la
part de Laurent Defert
Envoyé : vendredi 17 novembre 2006 11:52
À : Discution sur le développement de Wormux.
Objet : Re: [Wormux-dev] time synchronisation in Network


Hi!

I think rewinding the clock is not a good idea.. It would introduce problems if 
the status of an object change while we rewind the clock, or we would need to 
monitor every event and provide methods to revert them.
For example:
t=0 : we get an action_jump with a time stamp (ts) = 0 ->the character jump
t=1 : the character is floating in the air during the jump
t=2 : the character reach the ground
t=3 : we receive an action shoot with a ts = 1 -> if we revert the clock we 
need a way u put the character back in the air

To handle this, I think the playing computer should sent events to validate how 
much time have passed on his computer. This will introduce a bit of lag on 
distant computer, but that will happen mostly only at the beginning of its turn 
!

Lodesi

On Fri, Nov 17, 2006 at 11:30:25AM +0100, PERRE Y          SiseProIsaTig wrote:
> Hi all,
> 
> I would like to talk with you about a thought about time handling in Wormux. 
> I think we need to synchronize time each time we receive a new action. It's 
> quite easy doing it as we receive the timestamp each time we execute an 
> action. Something like :
> 
> void ActionHandler::ExecActions()
> {
>   assert(mutex!=NULL);
>   while (queue.size() != 0)
>   {
>     SDL_LockMutex(mutex);
>     Action *action = queue.front();
>     // If action is in the future, wait for next refresh
>     if(action->GetTimestamp() > Time::GetInstance()->Read()) {
>       SDL_UnlockMutex(mutex);
> +      return; // Maybe continue instead ?
>     }
>     // Synchronize game with time receive in action to avoid desync.
> +    Time::GetInstance()->SetTimestamp(action->GetTimestamp());
>     queue.pop_front();
>     SDL_UnlockMutex(mutex);
>     Exec (action);
>     delete action;
>   }
> }
> 
> It's shall introduce some drawback (in particle handling for example) but I 
> think it's the only solution if we want to be sure that every player on the 
> internet execute the action with the same context at the same time. As a 
> simple solution, I think we may need to introduce another call in Time class 
> for time in particle not sync with other players.
> 
> I would like some feedback about this idea and if it sounds crazy or not.
> 
> Regards,
> 
> Drayan
> 
> 
> =======================================================
> 
> Ce message et toutes les pieces jointes (ci-apres le "message") 
> sont confidentiels et etablis a l'intention exclusive de ses destinataires.
> Toute utilisation ou diffusion non autorisee est interdite. 
> Tout message electronique est susceptible d'alteration. 
> La SOCIETE GENERALE et ses filiales declinent toute responsabilite
> au titre de ce message s'il a ete altere, deforme ou falsifie.
>                                        
> =======================================================
> 
> This message and any attachments (the "message") are confidential
> and intended solely for the addressees.
> Any unauthorized use or dissemination is prohibited. 
> E-mails are susceptible to alteration.   
> Neither SOCIETE GENERALE nor any of its subsidiaries or affiliates
> shall be liable for the message if altered, changed or falsified. 
> 
> =======================================================
> 
> _______________________________________________
> Wormux-dev mailing list
> Wormux-dev@gna.org
> https://mail.gna.org/listinfo/wormux-dev

-- 

_______________________________________________
Wormux-dev mailing list
Wormux-dev@gna.org
https://mail.gna.org/listinfo/wormux-dev

_______________________________________________
Wormux-dev mailing list
Wormux-dev@gna.org
https://mail.gna.org/listinfo/wormux-dev

Répondre à