# HG changeset patch # User unc0rr # Date 1174331566 0 # Node ID d9b140e9d2c28ae9c7fdadb10f7c9d797561b46d # Parent d948311b33a3a83ea3512d1bae30214f41940afc Use freepascal's routines to manipulate threads diff -r d948311b33a3 -r d9b140e9d2c2 hedgewars/SDLh.pas --- a/hedgewars/SDLh.pas Sat Mar 17 18:32:17 2007 +0000 +++ b/hedgewars/SDLh.pas Mon Mar 19 19:12:46 2007 +0000 @@ -236,8 +236,6 @@ procedure SDL_WM_SetCaption(title: PChar; icon: PChar); cdecl; external SDLLibName; -function SDL_CreateThread(fn: pointer; data: pointer): PSDL_Thread; cdecl; external SDLLibName; -procedure SDL_WaitThread(thread: PSDL_Thread; status: PLongInt); cdecl; external SDLLibName; function SDL_CreateMutex: PSDL_mutex; cdecl; external SDLLibName; procedure SDL_DestroyMutex(mutex: PSDL_mutex); cdecl; external SDLLibName; function SDL_LockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName name 'SDL_mutexP'; diff -r d948311b33a3 -r d9b140e9d2c2 hedgewars/uAI.pas --- a/hedgewars/uAI.pas Sat Mar 17 18:32:17 2007 +0000 +++ b/hedgewars/uAI.pas Mon Mar 19 19:12:46 2007 +0000 @@ -25,25 +25,25 @@ implementation uses uTeams, uConsts, SDLh, uAIMisc, uGears, uAIAmmoTests, uAIActions, uMisc, - uAmmos, uConsole; + uAmmos, uConsole{$IFDEF UNIX}, cthreads{$ENDIF}; var BestActions: TActions; - ThinkThread: PSDL_Thread = nil; + ThinkThread: THandle = 0; StopThinking: boolean; CanUseAmmo: array [TAmmoType] of boolean; procedure FreeActionsList; begin {$IFDEF DEBUGFILE}AddFileLog('FreeActionsList called');{$ENDIF} -if ThinkThread <> nil then +if ThinkThread <> 0 then begin {$IFDEF DEBUGFILE}AddFileLog('Waiting AI thread to finish');{$ENDIF} StopThinking:= true; - SDL_WaitThread(ThinkThread, nil); - ThinkThread:= nil + WaitForThreadTerminate(ThinkThread, 5000); + ThinkThread:= 0 end; - with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do +with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do if Gear <> nil then if BotLevel <> 0 then begin @@ -237,7 +237,7 @@ end end; -procedure Think(Me: PGear); cdecl; +function Think(Me: Pointer): LongInt; var BackMe, WalkMe: TGear; StartTicks: Longword; begin @@ -245,9 +245,9 @@ BestActions.Count:= 0; BestActions.Pos:= 0; BestActions.Score:= Low(integer); -BackMe:= Me^; +BackMe:= PGear(Me)^; WalkMe:= BackMe; -if (Me^.State and gstAttacked) = 0 then +if (PGear(Me)^.State and gstAttacked) = 0 then if Targets.Count > 0 then begin Walk(@WalkMe); @@ -268,7 +268,8 @@ Walk(@WalkMe) end end; -Me^.State:= Me^.State and not gstHHThinking +PGear(Me)^.State:= PGear(Me)^.State and not gstHHThinking; +Think:= 0 end; procedure StartThink(Me: PGear); @@ -290,7 +291,7 @@ for a:= Low(TAmmoType) to High(TAmmoType) do CanUseAmmo[a]:= Assigned(AmmoTests[a]) and HHHasAmmo(PHedgehog(Me^.Hedgehog), a); {$IFDEF DEBUGFILE}AddFileLog('Enter Think Thread');{$ENDIF} -ThinkThread:= SDL_CreateThread(@Think, Me) +BeginThread(@Think, Me, ThinkThread) end; procedure ProcessBot;