hedgewars/uAI.pas
changeset 6415 af2047bb4f70
parent 6395 bb04d7a9f7e2
parent 6346 db58a42bb5e7
child 6416 850b8dd3e6df
--- a/hedgewars/uAI.pas	Wed Nov 23 20:12:16 2011 +0300
+++ b/hedgewars/uAI.pas	Thu Nov 24 16:18:45 2011 +0100
@@ -30,13 +30,13 @@
 
 implementation
 uses uConsts, SDLh, uAIMisc, uAIAmmoTests, uAIActions,
-     uAmmos, SysUtils{$IFDEF UNIX}, cthreads{$ENDIF}, uTypes,
+     uAmmos, SysUtils{$IFDEF UNIX}{$IFNDEF ANDROID}, cthreads{$ENDIF}{$ENDIF}, uTypes,
      uVariables, uCommands, uUtils, uDebug;
 
 var BestActions: TActions;
     CanUseAmmo: array [TAmmoType] of boolean;
     StopThinking: boolean;
-    ThinkThread: TThreadID;
+    ThinkThread: PSDL_Thread = nil;
     hasThread: LongInt;
 
 procedure FreeActionsList;
@@ -117,8 +117,7 @@
        with CurrentHedgehog^ do
             a:= CurAmmoType;
        aa:= a;
-       
-       ThreadSwitch();
+       SDL_delay(0);    //ThreadSwitch was only a hint
        
        repeat
         if (CanUseAmmo[a]) and
@@ -366,7 +365,14 @@
 
 FillBonuses((Me^.State and gstAttacked) <> 0);
 AddFileLog('Enter Think Thread');
-BeginThread(@Think, Me, ThinkThread)
+{$IFDEF IPHONEOS}
+//TODO: sdl_thread works on device but crashes in simulator, most likely because of outdated toolchain
+BeginThread(@Think, Me, ThinkThread);
+{$ELSE}
+ThinkThread := SDL_CreateThread(@Think{$IFDEF SDL13}, nil{$ENDIF}, Me);
+{$ENDIF}
+{$ENDIF}
+AddFileLog('Thread started');
 end;
 
 procedure ProcessBot;
@@ -397,6 +403,7 @@
 procedure initModule;
 begin
     hasThread:= 0;
+    ThinkThread:= ThinkThread;
 end;
 
 procedure freeModule;