Hi,

----- Kurosu <kur...@free.fr> a écrit :
> Might be interesting to check how much time each idea actually takes: it 
> might not be the 1ms it checks.
> It also seems that process is not running in its own thread (so that it does 
> not freeze the display), but rather serially:
> MainLoop -> InputRefresh -> AIRefresh -> if runtime < limit, check idea (l111 
> in ai/ai_stupid_player.cpp).
> 
> The last part also underlines that it may actually take more than the limit 
> and is actually not bounded:
> - start, wallclock is 0ms
> - check one idea, ends at 0.2s so stop (but we still took 200ms instead of 
> 1ms)

The Maemo developper validated this: there are often ideas taking 20-100ms. The 
effect is even worse: this causes the game to miss its deadline for a frame, 
and simply skip displaying any. As this accumulates, for the whole duration of 
the AI thinking, there are no frames displayed.

While this is the consequence of the AI taking too much time, it can still be 
worked around. The Maemo developper proposed the attached patch, which is a 
good failsafe mechanism in my opinion. Per his comment, game thus drops from 20 
to maybe 5-10, but that's instead of 0, for the 2-3 seconds the AI takes to 
make its move.

I will probably integrate it tonight and, instead of hunting Doubles, find the 
places in the AI code that could be improved.

Christophe
Index: src/game/game.cpp
===================================================================
--- src/game/game.cpp	(revision 7758)
+++ src/game/game.cpp	(working copy)
@@ -480,7 +480,6 @@
 
   // Keyboard, Joystick and mouse refresh
   Mouse::GetInstance()->Refresh();
-  ActiveTeam().RefreshAI();
   GameMessages::GetInstance()->Refresh();
 
   if (!IsGameFinished())
@@ -704,6 +703,8 @@
 
 void Game::MainLoop()
 {
+  static bool draw = true;
+
   if (!Time::GetInstance()->IsWaitingForUser()) {
     // If we are waiting for the network then we have already done those steps.
     if (!Time::GetInstance()->IsWaitingForNetwork()) {
@@ -743,6 +744,8 @@
     StatStart("Game:RefreshInput()");
     RefreshInput();
     StatStop("Game:RefreshInput()");
+    if (draw)
+      ActiveTeam().RefreshAI();
     ActionHandler::GetInstance()->ExecFrameLessActions();
 
     bool is_turn_master = Network::GetInstance()->IsTurnMaster();
@@ -783,7 +786,7 @@
   }
 
   // try to adjust to max Frame by seconds
-  bool draw = time_of_next_frame < SDL_GetTicks();
+  draw = time_of_next_frame < SDL_GetTicks();
   // Only display if the physic engine isn't late
   draw = draw && !(Time::GetInstance()->CanBeIncreased() && !Time::GetInstance()->IsWaiting());
 #ifdef USE_VALGRIND
_______________________________________________
Wormux-dev mailing list
Wormux-dev@gna.org
https://mail.gna.org/listinfo/wormux-dev

Répondre à