added a switch USE_SDLTHREADS
authorXeli
Mon, 28 Nov 2011 17:37:43 +0100
changeset 6460 e3cc8ec51cd3
parent 6458 eadb2db1ae83
child 6462 0758fbec9b9f
added a switch USE_SDLTHREADS
hedgewars/options.inc
hedgewars/uAI.pas
--- a/hedgewars/options.inc	Mon Nov 28 16:21:35 2011 +0100
+++ b/hedgewars/options.inc	Mon Nov 28 17:37:43 2011 +0100
@@ -34,6 +34,7 @@
   {$DEFINE GLunit:=gles11}
   {$DEFINE MOBILE}
   {$DEFINE Java_Prefix := 'Java_org_hedgewars_hedgeroid_EngineProtocol_PascalExports_'}
+  {$DEFINE USE_SDLTHREADS}
 {$ENDIF}
 
 {$IFDEF IPHONEOS}
--- a/hedgewars/uAI.pas	Mon Nov 28 16:21:35 2011 +0100
+++ b/hedgewars/uAI.pas	Mon Nov 28 17:37:43 2011 +0100
@@ -30,13 +30,17 @@
 
 implementation
 uses uConsts, SDLh, uAIMisc, uAIAmmoTests, uAIActions,
-     uAmmos, SysUtils{$IFDEF UNIX}{$IFNDEF ANDROID}, cthreads{$ENDIF}{$ENDIF}, uTypes,
+     uAmmos, SysUtils{$IFNDEF USE_SDLTHREADS} {$IFDEF UNIX}, cthreads{$ENDIF} {$ENDIF}, uTypes,
      uVariables, uCommands, uUtils, uDebug;
 
 var BestActions: TActions;
     CanUseAmmo: array [TAmmoType] of boolean;
     StopThinking: boolean;
+{$IFDEF USE_SDL_THREADS} 
     ThinkThread: PSDL_Thread = nil;
+{$ELSE}
+    ThinkThread: TThreadID;
+{$ENDIF}
     hasThread: LongInt;
 
 procedure FreeActionsList;
@@ -117,8 +121,11 @@
        with CurrentHedgehog^ do
             a:= CurAmmoType;
        aa:= a;
+{$IFDEF USE_SDLTHREADS}
        SDL_delay(0);    //ThreadSwitch was only a hint
-       
+{$ELSE}
+       ThreadSwitch();
+{$ENDIF}       
        repeat
         if (CanUseAmmo[a]) and
            ((not isMoved) or ((AmmoTests[a].flags and amtest_OnTurn) = 0)) then
@@ -365,11 +372,10 @@
 
 FillBonuses((Me^.State and gstAttacked) <> 0);
 AddFileLog('Enter Think Thread');
-{$IFDEF IPHONEOS}
-//TODO: sdl_thread works on device but crashes in simulator, most likely because of outdated toolchain
+{$IFDEF USE_SDLTHREADS}
+ThinkThread := SDL_CreateThread(@Think{$IFDEF SDL13}, nil{$ENDIF}, Me);
+{$ELSE}
 BeginThread(@Think, Me, ThinkThread);
-{$ELSE}
-ThinkThread := SDL_CreateThread(@Think{$IFDEF SDL13}, nil{$ENDIF}, Me);
 {$ENDIF}
 AddFileLog('Thread started');
 end;