hedgewars/hwengine.pas
changeset 10015 4feced261c68
parent 10012 82dd9f0c88f7
parent 9950 2759212a27de
child 10108 c68cf030eded
equal deleted inserted replaced
10014:56d2f2d5aad8 10015:4feced261c68
    17  *)
    17  *)
    18 
    18 
    19 {$INCLUDE "options.inc"}
    19 {$INCLUDE "options.inc"}
    20 
    20 
    21 {$IFDEF WIN32}
    21 {$IFDEF WIN32}
    22 {$R hwengine.rc}
    22 {$R res/hwengine.rc}
    23 {$ENDIF}
    23 {$ENDIF}
    24 
    24 
    25 {$IFDEF HWLIBRARY}
    25 {$IFDEF HWLIBRARY}
    26 unit hwengine;
    26 unit hwengine;
    27 interface
    27 interface
    90             ScriptCall('onGameStart');
    90             ScriptCall('onGameStart');
    91             GameState:= gsGame;
    91             GameState:= gsGame;
    92             end;
    92             end;
    93         gsConfirm, gsGame, gsChat:
    93         gsConfirm, gsGame, gsChat:
    94             begin
    94             begin
    95             if not cOnlyStats then DrawWorld(Lag);
    95             if not cOnlyStats then
       
    96                 // never place between ProcessKbd and DoGameTick - bugs due to /put cmd and isCursorVisible
       
    97                 DrawWorld(Lag);
    96             DoGameTick(Lag);
    98             DoGameTick(Lag);
    97             if not cOnlyStats then ProcessVisualGears(Lag);
    99             if not cOnlyStats then ProcessVisualGears(Lag);
    98             end;
   100             end;
    99         gsExit:
   101         gsExit:
   100             begin
   102             begin
   112 {$ENDIF}
   114 {$ENDIF}
   113 
   115 
   114     if flagMakeCapture then
   116     if flagMakeCapture then
   115         begin
   117         begin
   116         flagMakeCapture:= false;
   118         flagMakeCapture:= false;
       
   119         {$IFDEF PAS2C}
       
   120         s:= '/Screenshots/hw';
       
   121         {$ELSE}
   117         s:= '/Screenshots/hw_' + FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()) + inttostr(GameTicks);
   122         s:= '/Screenshots/hw_' + FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()) + inttostr(GameTicks);
       
   123         {$ENDIF}
   118 
   124 
   119         // flash
   125         // flash
   120         playSound(sndShutter);
   126         playSound(sndShutter);
   121         ScreenFade:= sfFromWhite;
   127         ScreenFade:= sfFromWhite;
   122         ScreenFadeValue:= sfMax;
   128         ScreenFadeValue:= sfMax;
   133 end;
   139 end;
   134 
   140 
   135 ///////////////////////////////////////////////////////////////////////////////
   141 ///////////////////////////////////////////////////////////////////////////////
   136 procedure MainLoop;
   142 procedure MainLoop;
   137 var event: TSDL_Event;
   143 var event: TSDL_Event;
   138     PrevTime, CurrTime: Longword;
   144     PrevTime, CurrTime: LongWord;
   139     isTerminated: boolean;
   145     isTerminated: boolean;
   140 {$IFDEF SDL2}
   146 {$IFDEF SDL2}
   141     previousGameState: TGameState;
   147     previousGameState: TGameState;
   142 {$ELSE}
   148 {$ELSE}
   143     prevFocusState: boolean;
   149     prevFocusState: boolean;
   273         end;
   279         end;
   274 
   280 
   275         CurrTime:= SDL_GetTicks();
   281         CurrTime:= SDL_GetTicks();
   276         if PrevTime + longword(cTimerInterval) <= CurrTime then
   282         if PrevTime + longword(cTimerInterval) <= CurrTime then
   277         begin
   283         begin
   278             isTerminated := isTerminated or DoTimer(CurrTime - PrevTime);
   284             isTerminated:= isTerminated or DoTimer(CurrTime - PrevTime);
   279             PrevTime:= CurrTime
   285             PrevTime:= CurrTime;
   280         end
   286         end
   281         else SDL_Delay(1);
   287         else SDL_Delay(1);
   282         IPCCheckSock();
   288         IPCCheckSock();
       
   289 
   283     end;
   290     end;
   284 end;
   291 end;
   285 
   292 
   286 {$IFDEF USE_VIDEO_RECORDING}
   293 {$IFDEF USE_VIDEO_RECORDING}
   287 procedure RecorderMainLoop;
   294 procedure RecorderMainLoop;
   412     TryDo(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
   419     TryDo(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
   413     //ParseCommand('rotmask', true);
   420     //ParseCommand('rotmask', true);
   414 
   421 
   415 {$IFDEF USE_VIDEO_RECORDING}
   422 {$IFDEF USE_VIDEO_RECORDING}
   416     if GameType = gmtRecord then
   423     if GameType = gmtRecord then
   417         RecorderMainLoop()
   424     begin
   418     else
   425         RecorderMainLoop();
   419 {$ENDIF}
   426         freeEverything(true);
   420         MainLoop();
   427         exit;
   421 
   428     end;
       
   429 {$ENDIF}
       
   430 
       
   431     MainLoop;
   422     // clean up all the memory allocated
   432     // clean up all the memory allocated
   423     freeEverything(true);
   433     freeEverything(true);
   424 end;
   434 end;
   425 
   435 
   426 ///////////////////////////////////////////////////////////////////////////////
   436 ///////////////////////////////////////////////////////////////////////////////
   544 
   554 
   545 ///////////////////////////////////////////////////////////////////////////////
   555 ///////////////////////////////////////////////////////////////////////////////
   546 /////////////////////////////////// m a i n ///////////////////////////////////
   556 /////////////////////////////////// m a i n ///////////////////////////////////
   547 ///////////////////////////////////////////////////////////////////////////////
   557 ///////////////////////////////////////////////////////////////////////////////
   548 begin
   558 begin
       
   559 {$IFDEF PAS2C}
       
   560     // workaround for pascal's ParamStr and ParamCount
       
   561     init(argc, argv);
       
   562 {$ENDIF}
   549     preInitEverything();
   563     preInitEverything();
   550     cTagsMask:= htTeamName or htName or htHealth; // this one doesn't fit nicely w/ reset of other variables. suggestions welcome
   564     cTagsMask:= htTeamName or htName or htHealth; // this one doesn't fit nicely w/ reset of other variables. suggestions welcome
   551     GetParams();
   565     GetParams();
   552 
   566 
   553     if GameType = gmtLandPreview then
   567     if GameType = gmtLandPreview then
   554         GenLandPreview()
   568         GenLandPreview()
   555     else if GameType <> gmtSyntax then
   569     else if GameType <> gmtSyntax then
   556         Game();
   570         Game();
   557 
   571 
   558     // return 1 when engine is not called correctly
   572     // return 1 when engine is not called correctly
       
   573     {$IFDEF PAS2C}
       
   574     exit(LongInt(GameType = gmtSyntax));
       
   575     {$ELSE}
   559     halt(LongInt(GameType = gmtSyntax));
   576     halt(LongInt(GameType = gmtSyntax));
       
   577     {$ENDIF}
       
   578 
   560 {$ENDIF}
   579 {$ENDIF}
   561 end.
   580 end.