hedgewars/hwengine.pas
changeset 3063 0092dc37fbd6
parent 3058 2ebc20485344
child 3064 7458ec3666c3
equal deleted inserted replaced
3062:62eb6095497b 3063:0092dc37fbd6
    57     uFloat in 'uFloat.pas',
    57     uFloat in 'uFloat.pas',
    58     uStats in 'uStats.pas',
    58     uStats in 'uStats.pas',
    59     uChat in 'uChat.pas',
    59     uChat in 'uChat.pas',
    60     uLandTexture in 'uLandTexture.pas',
    60     uLandTexture in 'uLandTexture.pas',
    61     uScript in 'uScript.pas',
    61     uScript in 'uScript.pas',
    62     {$IFDEF IPHONEOS}PascalExports in 'PascalExports.pas',{$ENDIF}
       
    63     sysutils;
    62     sysutils;
    64 
    63 
    65 // also: GSHandlers.inc
    64 // also: GSHandlers.inc
    66 //       CCHandlers.inc
    65 //       CCHandlers.inc
    67 //       HHHandlers.inc
    66 //       HHHandlers.inc
    68 //       SinTable.inc
    67 //       SinTable.inc
    69 //       proto.inc
    68 //       proto.inc
    70 
    69 
    71 {$IFDEF HWLIBRARY}
    70 {$IFDEF HWLIBRARY}
    72 type arrayofpchar = array[0..7] of PChar;
    71 type arrayofpchar = array[0..7] of PChar;
       
    72 var isTerminated: boolean = false;
       
    73     alsoShutdownFrontend: boolean = false;
    73 
    74 
    74 procedure initEverything;
    75 procedure initEverything;
    75 procedure freeEverything;
    76 procedure freeEverything;
    76 
    77 
    77 implementation
    78 implementation
   159     ControllerClose();
   160     ControllerClose();
   160     SendKB();
   161     SendKB();
   161     CloseIPC();
   162     CloseIPC();
   162     TTF_Quit();
   163     TTF_Quit();
   163     SDL_Quit();
   164     SDL_Quit();
       
   165     isTerminated:= false;
   164 end;
   166 end;
   165 
   167 
   166 ///////////////////
   168 ///////////////////
   167 procedure MainLoop; 
   169 procedure MainLoop; 
   168 var PrevTime, CurrTime: Longword;
   170 var PrevTime, CurrTime: Longword;
   169     {$IFNDEF IPHONEOS}event: TSDL_Event;{$ENDIF}
   171     {$IFNDEF IPHONEOS}event: TSDL_Event;{$ENDIF}
   170 begin
   172 begin
   171     PrevTime:= SDL_GetTicks;
   173     PrevTime:= SDL_GetTicks;
   172     repeat
   174     while isTerminated = false do
       
   175     begin
   173 {$IFNDEF IPHONEOS}
   176 {$IFNDEF IPHONEOS}
   174 // have to remove this cycle because otherwise it segfaults at exit
   177 // have to remove this cycle because otherwise it segfaults at exit
   175         while SDL_PollEvent(@event) <> 0 do
   178         while SDL_PollEvent(@event) <> 0 do
   176         begin
   179         begin
   177             case event.type_ of
   180             case event.type_ of
   192                 SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false);
   195                 SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false);
   193                 SDL_QUITEV: isTerminated:= true
   196                 SDL_QUITEV: isTerminated:= true
   194             end; // end case event.type_ of
   197             end; // end case event.type_ of
   195         end; // end while SDL_PollEvent(@event) <> 0 do
   198         end; // end while SDL_PollEvent(@event) <> 0 do
   196 {$ENDIF}
   199 {$ENDIF}
   197         CurrTime:= SDL_GetTicks;
   200         if isTerminated = false then
   198         if PrevTime + cTimerInterval <= CurrTime then
       
   199         begin
   201         begin
   200             DoTimer(CurrTime - PrevTime);
   202             CurrTime:= SDL_GetTicks;
   201             PrevTime:= CurrTime
   203             if PrevTime + cTimerInterval <= CurrTime then
   202         end else SDL_Delay(1);
   204             begin
   203         if isTerminated = false then IPCCheckSock();
   205                 DoTimer(CurrTime - PrevTime);
   204     until isTerminated;
   206                 PrevTime:= CurrTime
       
   207             end 
       
   208             else SDL_Delay(1);
       
   209             IPCCheckSock();
       
   210         end;
       
   211     end;
   205 end;
   212 end;
   206 
   213 
   207 /////////////////////////
   214 /////////////////////////
   208 procedure ShowMainWindow;
   215 procedure ShowMainWindow;
   209 begin
   216 begin
   301 
   308 
   302     ParseCommand('rotmask', true);
   309     ParseCommand('rotmask', true);
   303 
   310 
   304     MainLoop();
   311     MainLoop();
   305     OnDestroy();
   312     OnDestroy();
       
   313     if alsoShutdownFrontend then
       
   314     begin
       
   315         alsoShutdownFrontend:= false;
       
   316         halt;
       
   317     end;
   306 end;
   318 end;
   307 
   319 
   308 procedure initEverything;
   320 procedure initEverything;
   309 begin
   321 begin
   310     uConsts.initModule;
   322     uConsts.initModule;
   566     Randomize();
   578     Randomize();
   567 
   579 
   568     if GameType = gmtLandPreview then
   580     if GameType = gmtLandPreview then
   569         begin
   581         begin
   570         GenLandPreview();
   582         GenLandPreview();
   571         // freeEverything()    TODO - Koda, please check if this is needed here. 
   583         freeEverything(); 
   572         end
   584         end
   573     else if GameType = gmtSyntax then DisplayUsage()
   585     else if GameType = gmtSyntax then DisplayUsage()
   574     else Game();
   586     else Game();
   575     
   587     
   576     freeEverything;
   588     freeEverything;