hedgewars/uUtils.pas
changeset 14892 444ed0622348
parent 14080 af203fb307a7
child 14895 d4a19bf6687e
equal deleted inserted replaced
14891:e72d8c2299dd 14892:444ed0622348
   109 procedure initModule(isNotPreview: boolean);
   109 procedure initModule(isNotPreview: boolean);
   110 procedure freeModule;
   110 procedure freeModule;
   111 
   111 
   112 
   112 
   113 implementation
   113 implementation
   114 uses {$IFNDEF PAS2C}typinfo, {$ENDIF}Math, uConsts, uVariables, uPhysFSLayer, uDebug;
   114 uses {$IFNDEF PAS2C}typinfo, SDLh, {$ENDIF}Math, uConsts, uVariables, uPhysFSLayer, uDebug;
   115 
   115 
   116 {$IFDEF DEBUGFILE}
   116 {$IFDEF DEBUGFILE}
   117 var logFile: PFSFile;
   117 var logFile: PFSFile;
   118 {$IFDEF USE_VIDEO_RECORDING}
   118 {$IFDEF USE_VIDEO_RECORDING}
   119     logMutex: TRTLCriticalSection; // mutex for debug file
   119     logMutex: PSDL_mutex; // mutex for debug file
   120 {$ENDIF}
   120 {$ENDIF}
   121 {$ENDIF}
   121 {$ENDIF}
   122 var CharArray: array[0..255] of Char;
   122 var CharArray: array[0..255] of Char;
   123 
   123 
   124 // All leading/tailing characters with ordinal values less than or equal to 32 (a space) are stripped.
   124 // All leading/tailing characters with ordinal values less than or equal to 32 (a space) are stripped.
   504 begin
   504 begin
   505 // s:= s;
   505 // s:= s;
   506 {$IFDEF DEBUGFILE}
   506 {$IFDEF DEBUGFILE}
   507 
   507 
   508 {$IFDEF USE_VIDEO_RECORDING}
   508 {$IFDEF USE_VIDEO_RECORDING}
   509 EnterCriticalSection(logMutex);
   509 if SDL_LockMutex(logMutex) <> 0 then
       
   510     OutError('Logging mutex could not be locked!', true);
   510 {$ENDIF}
   511 {$ENDIF}
   511 if logFile <> nil then
   512 if logFile <> nil then
   512     pfsWriteLn(logFile, inttostr(GameTicks)  + ': ' + s)
   513     pfsWriteLn(logFile, inttostr(GameTicks)  + ': ' + s)
   513 else
   514 else
   514     WriteLn(stdout, inttostr(GameTicks)  + ': ' + s);
   515     WriteLn(stdout, inttostr(GameTicks)  + ': ' + s);
   515 
   516 
   516 {$IFDEF USE_VIDEO_RECORDING}
   517 {$IFDEF USE_VIDEO_RECORDING}
   517 LeaveCriticalSection(logMutex);
   518 if SDL_UnlockMutex(logMutex) <> 0 then
       
   519     OutError('Logging mutex could not be unlocked!', true);
   518 {$ENDIF}
   520 {$ENDIF}
   519 
   521 
   520 {$ENDIF}
   522 {$ENDIF}
   521 end;
   523 end;
   522 
   524 
   524 begin
   526 begin
   525 s:= s;
   527 s:= s;
   526 {$IFNDEF PAS2C}
   528 {$IFNDEF PAS2C}
   527 {$IFDEF DEBUGFILE}
   529 {$IFDEF DEBUGFILE}
   528 {$IFDEF USE_VIDEO_RECORDING}
   530 {$IFDEF USE_VIDEO_RECORDING}
   529 EnterCriticalSection(logMutex);
   531 if SDL_LockMutex(logMutex) <> 0 then
       
   532     OutError('Logging mutex could not be locked!', true);
   530 {$ENDIF}
   533 {$ENDIF}
   531 // TODO: uncomment next two lines
   534 // TODO: uncomment next two lines
   532 // write(logFile, s);
   535 // write(logFile, s);
   533 // flush(logFile);
   536 // flush(logFile);
   534 {$IFDEF USE_VIDEO_RECORDING}
   537 {$IFDEF USE_VIDEO_RECORDING}
   535 LeaveCriticalSection(logMutex);
   538 if SDL_UnlockMutex(logMutex) <> 0 then
       
   539     OutError('Logging mutex could not be unlocked!', true);
   536 {$ENDIF}
   540 {$ENDIF}
   537 {$ENDIF}
   541 {$ENDIF}
   538 {$ENDIF}
   542 {$ENDIF}
   539 end;
   543 end;
   540 
   544 
   762         logfileBase:= 'preview_pas2c';
   766         logfileBase:= 'preview_pas2c';
   763         {$ELSE}
   767         {$ELSE}
   764         logfileBase:= 'preview';
   768         logfileBase:= 'preview';
   765         {$ENDIF}
   769         {$ENDIF}
   766 {$IFDEF USE_VIDEO_RECORDING}
   770 {$IFDEF USE_VIDEO_RECORDING}
   767     InitCriticalSection(logMutex);
   771     logMutex:= SDL_CreateMutex();
       
   772     if (logMutex = nil) then
       
   773         OutError('Could not create mutex for logging', true);
   768 {$ENDIF}
   774 {$ENDIF}
   769     if not pfsExists('/Logs') then
   775     if not pfsExists('/Logs') then
   770         pfsMakeDir('/Logs');
   776         pfsMakeDir('/Logs');
   771     // if log is locked, write to the next one
   777     // if log is locked, write to the next one
   772     i:= 0;
   778     i:= 0;
   807     pfsClose(logFile);
   813     pfsClose(logFile);
   808     end
   814     end
   809 else
   815 else
   810     WriteLn(stdout, 'halt at ' + inttostr(GameTicks) + ' ticks. TurnTimeLeft = ' + inttostr(TurnTimeLeft));
   816     WriteLn(stdout, 'halt at ' + inttostr(GameTicks) + ' ticks. TurnTimeLeft = ' + inttostr(TurnTimeLeft));
   811 {$IFDEF USE_VIDEO_RECORDING}
   817 {$IFDEF USE_VIDEO_RECORDING}
   812     DoneCriticalSection(logMutex);
   818     SDL_DestroyMutex(logMutex);
   813 {$ENDIF}
   819 {$ENDIF}
   814 {$ENDIF}
   820 {$ENDIF}
   815 end;
   821 end;
   816 
   822 
   817 end.
   823 end.