From 5ed6620bad808381fce94f2cd67ee911b4d45bff Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Wed, 21 Mar 2007 19:19:04 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 227 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 Game/Code/Classes/ULog.pas (limited to 'Game/Code/Classes/ULog.pas') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas new file mode 100644 index 00000000..6bffa04e --- /dev/null +++ b/Game/Code/Classes/ULog.pas @@ -0,0 +1,227 @@ +unit ULog; + +interface + +uses Classes; + +type + TLog = class + BenchmarkTimeStart: array[0..7] of real; + BenchmarkTimeLength: array[0..7] of real;//TDateTime; + + FileBenchmark: TextFile; + FileBenchmarkO: boolean; // opened + FileAnalyze: TextFile; + FileAnalyzeO: boolean; // opened + FileError: TextFile; + FileErrorO: boolean; // opened + + Title: String; //Application Title + + // destuctor + destructor Free; + + // benchmark + procedure BenchmarkStart(Number: integer); + procedure BenchmarkEnd(Number: integer); + procedure LogBenchmark(Text: string; Number: integer); + + // analyze + procedure LogAnalyze(Text: string); + + // error + procedure LogError(Text: string); overload; + + //Critical Error (Halt + MessageBox) + procedure CriticalError(Text: string); + + // voice + procedure LogVoice(SoundNr: integer); + + // compability + procedure LogStatus(Log1, Log2: string); + procedure LogError(Log1, Log2: string); overload; + end; + +var + Log: TLog; + +implementation +uses UPliki, SysUtils, DateUtils, URecord, UTime, UIni, Windows; + +destructor TLog.Free; +begin + if FileBenchmarkO then CloseFile(FileBenchmark); +// if FileAnalyzeO then CloseFile(FileAnalyze); + if FileErrorO then CloseFile(FileError); +end; + +procedure TLog.BenchmarkStart(Number: integer); +begin + BenchmarkTimeStart[Number] := USTime.GetTime; //Time; +end; + +procedure TLog.BenchmarkEnd(Number: integer); +begin + BenchmarkTimeLength[Number] := USTime.GetTime {Time} - BenchmarkTimeStart[Number]; +end; + +procedure TLog.LogBenchmark(Text: string; Number: integer); +var + Minutes: integer; + Seconds: integer; + Miliseconds: integer; + + MinutesS: string; + SecondsS: string; + MilisecondsS: string; + + ValueText: string; +begin + if (ParamStr(1) = '-benchmark') then begin + if not FileBenchmarkO then begin + FileBenchmarkO := true; + AssignFile(FileBenchmark, LogPath + 'Benchmark.log'); + {$I-} + Rewrite(FileBenchmark); + if IOResult = 0 then FileBenchmarkO := true; + {$I+} + end; + + if FileBenchmarkO then begin + Miliseconds := Trunc(Frac(BenchmarkTimeLength[Number]) * 1000); + Seconds := Trunc(BenchmarkTimeLength[Number]) mod 60; + Minutes := Trunc((BenchmarkTimeLength[Number] - Seconds) / 60); +// ValueText := FloatToStr(BenchmarkTimeLength[Number]); + +{ ValueText := FloatToStr( + SecondOf(BenchmarkTimeLength[Number]) + MilliSecondOf(BenchmarkTimeLength[Number])/1000 + ); + if MinuteOf(BenchmarkTimeLength[Number]) >= 1 then + ValueText := IntToStr(MinuteOf(BenchmarkTimeLength[Number])) + ':' + ValueText; + WriteLn(FileBenchmark, Text + ': ' + ValueText + ' seconds');} + + if (Minutes = 0) and (Seconds = 0) then begin + MilisecondsS := IntToStr(Miliseconds); + ValueText := MilisecondsS + ' miliseconds'; + end; + + if (Minutes = 0) and (Seconds >= 1) then begin + MilisecondsS := IntToStr(Miliseconds); + while Length(MilisecondsS) < 3 do MilisecondsS := '0' + MilisecondsS; + + SecondsS := IntToStr(Seconds); + + ValueText := SecondsS + ',' + MilisecondsS + ' seconds'; + end; + + if Minutes >= 1 then begin + MilisecondsS := IntToStr(Miliseconds); + while Length(MilisecondsS) < 3 do MilisecondsS := '0' + MilisecondsS; + + SecondsS := IntToStr(Seconds); + while Length(SecondsS) < 2 do SecondsS := '0' + SecondsS; + + MinutesS := IntToStr(Minutes); + + ValueText := MinutesS + ':' + SecondsS + ',' + MilisecondsS + ' minutes'; + end; + + WriteLn(FileBenchmark, Text + ': ' + ValueText); + Flush(FileBenchmark); + end; + end; +end; + +procedure TLog.LogAnalyze(Text: string); +var + Seconds: integer; + Miliseconds: integer; + ValueText: string; +begin + if Ini.Debug = 1 then begin + + if not FileAnalyzeO then begin + AssignFile(FileAnalyze, LogPath + 'Analyze.log'); + {$I-} + Rewrite(FileAnalyze); + if IOResult = 0 then FileAnalyzeO := true; + {$I+} + end; + + if FileAnalyzeO then begin + WriteLn(FileAnalyze, Text); + Flush(FileAnalyze); // try to speed up + end; + + end; +end; + +procedure TLog.LogError(Text: string); +begin + if not FileErrorO then begin + FileErrorO := true; + AssignFile(FileError, LogPath + 'Error.log'); + {$I-} + Rewrite(FileError); + if IOResult = 0 then FileErrorO := true; + {$I+} + end; + + if FileErrorO then begin + WriteLn(FileError, Text); + Flush(FileError); + end; +end; + +procedure TLog.LogVoice(SoundNr: integer); +var + FileVoice: File; + FS: TFileStream; + FileName: string; + Num: integer; + BL: integer; +begin + for Num := 1 to 9999 do begin + FileName := IntToStr(Num); + while Length(FileName) < 4 do FileName := '0' + FileName; + FileName := LogPath + 'Voice' + FileName + '.raw'; + if not FileExists(FileName) then break + end; + + + FS := TFileStream.Create(FileName, fmCreate); + + for BL := 0 to High(Sound[SoundNr].BufferLong) do begin + Sound[SoundNr].BufferLong[BL].Seek(0, soBeginning); + FS.CopyFrom(Sound[SoundNr].BufferLong[BL], Sound[SoundNr].BufferLong[BL].Size); + end; + + FS.Free; +end; + +procedure TLog.LogStatus(Log1, Log2: string); +begin +//asd + LogError (Log2 + ': ' + Log1); +end; + +procedure TLog.LogError(Log1, Log2: string); +begin +//asd +end; + +procedure TLog.CriticalError(Text: string); +begin + //Write Error to Logfile: + LogError (Text); + + //Show Errormessage + Messagebox(0, PChar(Text), PChar(Title), MB_ICONERROR or MB_OK); + + //Exit Application + Halt; +end; + +end. + \ No newline at end of file -- cgit v1.2.3 From cc06446d0a651113083478fda94dfaa9a25d1d7e Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sun, 29 Apr 2007 18:29:42 +0000 Subject: Commented some Debuging Outputs in ULog Fixed a Bug in ButtonCollection that causes a Crash when UpButton is Pressed at the Last Button Added ShortCut E in MainMenu for Editor git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@150 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Game/Code/Classes/ULog.pas') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas index 6bffa04e..0b492cb3 100644 --- a/Game/Code/Classes/ULog.pas +++ b/Game/Code/Classes/ULog.pas @@ -139,7 +139,7 @@ var Miliseconds: integer; ValueText: string; begin - if Ini.Debug = 1 then begin + //if Ini.Debug = 1 then begin if not FileAnalyzeO then begin AssignFile(FileAnalyze, LogPath + 'Analyze.log'); @@ -154,7 +154,7 @@ begin Flush(FileAnalyze); // try to speed up end; - end; + //end; end; procedure TLog.LogError(Text: string); @@ -202,8 +202,9 @@ end; procedure TLog.LogStatus(Log1, Log2: string); begin -//asd - LogError (Log2 + ': ' + Log1); + //Just for Debugging + //Comment for Release + //LogAnalyze (Log2 + ': ' + Log1); end; procedure TLog.LogError(Log1, Log2: string); @@ -224,4 +225,3 @@ begin end; end. - \ No newline at end of file -- cgit v1.2.3 From 4a731514163a14bd3a9222d99707880b56772663 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Wed, 16 May 2007 19:19:35 +0000 Subject: all SongFile Loading and Saving procedures moved to UFiles. Added Some Tolerance in Song File Loading and Song Header Loading. Fix: Programm doesn't Crash anymore when a coruppted Song is loaded for Singing or Editing. Now Jump back to SongScreen and show an Error Message. Also Party Mode is not Interupted, a new Song will be selected automatically. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@197 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Game/Code/Classes/ULog.pas') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas index 0b492cb3..59e25954 100644 --- a/Game/Code/Classes/ULog.pas +++ b/Game/Code/Classes/ULog.pas @@ -47,7 +47,7 @@ var Log: TLog; implementation -uses UPliki, SysUtils, DateUtils, URecord, UTime, UIni, Windows; +uses UFiles, SysUtils, DateUtils, URecord, UTime, UIni, Windows; destructor TLog.Free; begin -- cgit v1.2.3 From dd3cc6f8e84f03f626a88741474412d36e4d18ac Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sun, 8 Jul 2007 12:00:15 +0000 Subject: Improved Error Logging and Benchmark: Write US Version, date and time to files. Added better Commandline Parameter Interpreter: More than one parameter can be used at the same time Many new, useful farameters: e.g. No error logging, Resolution change, FullScreen, DualScreen Mode, other Config File, other Score File and SongPath git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@274 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 68 +++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'Game/Code/Classes/ULog.pas') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas index 59e25954..9d20d2f1 100644 --- a/Game/Code/Classes/ULog.pas +++ b/Game/Code/Classes/ULog.pas @@ -11,13 +11,14 @@ type FileBenchmark: TextFile; FileBenchmarkO: boolean; // opened - FileAnalyze: TextFile; - FileAnalyzeO: boolean; // opened FileError: TextFile; FileErrorO: boolean; // opened Title: String; //Application Title + //Should Log Files be written + Enabled: Boolean; + // destuctor destructor Free; @@ -26,9 +27,6 @@ type procedure BenchmarkEnd(Number: integer); procedure LogBenchmark(Text: string; Number: integer); - // analyze - procedure LogAnalyze(Text: string); - // error procedure LogError(Text: string); overload; @@ -47,7 +45,7 @@ var Log: TLog; implementation -uses UFiles, SysUtils, DateUtils, URecord, UTime, UIni, Windows; +uses UFiles, SysUtils, DateUtils, URecord, UTime, UIni, Windows, UCommandLine; destructor TLog.Free; begin @@ -78,7 +76,7 @@ var ValueText: string; begin - if (ParamStr(1) = '-benchmark') then begin + if Enabled AND (Params.Benchmark) then begin if not FileBenchmarkO then begin FileBenchmarkO := true; AssignFile(FileBenchmark, LogPath + 'Benchmark.log'); @@ -86,6 +84,16 @@ begin Rewrite(FileBenchmark); if IOResult = 0 then FileBenchmarkO := true; {$I+} + + //If File is opened write Date to Benchmark File + If (FileBenchmarkO) then + begin + WriteLn(FileBenchmark, Title + ' Benchmark File'); + WriteLn(FileBenchmark, 'Date: ' + DatetoStr(Now) + ' Time: ' + TimetoStr(Now)); + WriteLn(FileBenchmark, '-------------------'); + + Flush(FileBenchmark); + end; end; if FileBenchmarkO then begin @@ -133,44 +141,34 @@ begin end; end; -procedure TLog.LogAnalyze(Text: string); -var - Seconds: integer; - Miliseconds: integer; - ValueText: string; -begin - //if Ini.Debug = 1 then begin - - if not FileAnalyzeO then begin - AssignFile(FileAnalyze, LogPath + 'Analyze.log'); - {$I-} - Rewrite(FileAnalyze); - if IOResult = 0 then FileAnalyzeO := true; - {$I+} - end; - - if FileAnalyzeO then begin - WriteLn(FileAnalyze, Text); - Flush(FileAnalyze); // try to speed up - end; - - //end; -end; - procedure TLog.LogError(Text: string); begin - if not FileErrorO then begin + if Enabled AND (not FileErrorO) then begin FileErrorO := true; AssignFile(FileError, LogPath + 'Error.log'); {$I-} Rewrite(FileError); if IOResult = 0 then FileErrorO := true; {$I+} + + //If File is opened write Date to Error File + If (FileErrorO) then + begin + WriteLn(FileError, Title + ' Error Log'); + WriteLn(FileError, 'Date: ' + DatetoStr(Now) + ' Time: ' + TimetoStr(Now)); + WriteLn(FileError, '-------------------'); + + Flush(FileError); + end; end; if FileErrorO then begin - WriteLn(FileError, Text); - Flush(FileError); + try + WriteLn(FileError, Text); + Flush(FileError); + except + FileErrorO := false; + end; end; end; @@ -225,3 +223,5 @@ begin end; end. + + -- cgit v1.2.3 From 6e7b96ca3a7d47b0441bed904a9b8bb25c3223de Mon Sep 17 00:00:00 2001 From: jaybinks Date: Wed, 12 Sep 2007 12:43:38 +0000 Subject: * added missed dependency PNGImage. * moved FUNCTION InitializePaths(), from uFiles to uMain as this is a more sane location for it. * updated files that used UFiles to point to UMain, and removed uFiles where its not needed. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@385 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'Game/Code/Classes/ULog.pas') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas index 9d20d2f1..2233ec1b 100644 --- a/Game/Code/Classes/ULog.pas +++ b/Game/Code/Classes/ULog.pas @@ -45,7 +45,17 @@ var Log: TLog; implementation -uses UFiles, SysUtils, DateUtils, URecord, UTime, UIni, Windows, UCommandLine; + +uses + Windows, + SysUtils, + DateUtils, +// UFiles, + UMain, + URecord, + UTime, +// UIni, // JB - Seems to not be needed. + UCommandLine; destructor TLog.Free; begin -- cgit v1.2.3 From 62c82114318ed04ce42617fa9ce2e179834dbda4 Mon Sep 17 00:00:00 2001 From: jaybinks Date: Wed, 19 Sep 2007 11:44:10 +0000 Subject: added UCommon ( in classes ) for lazarus... common functions needed for lazarus ( and others ) can be put in here. also this now compiles on lazarus.. ( dosnt link yet... but I dont get any critical compiler errors ) tested to compile in my delphi, and basic functionality is fine. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@395 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Game/Code/Classes/ULog.pas') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas index 2233ec1b..4a18b8e2 100644 --- a/Game/Code/Classes/ULog.pas +++ b/Game/Code/Classes/ULog.pas @@ -2,6 +2,10 @@ unit ULog; interface +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + uses Classes; type -- cgit v1.2.3 From a3904cbf6d498504bb0ab2510b50e6117d2869cc Mon Sep 17 00:00:00 2001 From: jaybinks Date: Wed, 19 Sep 2007 13:38:24 +0000 Subject: added in the lots of debug logging... sorry guys. will remove it soon enough. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@400 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Game/Code/Classes/ULog.pas') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas index 4a18b8e2..d03ad8ed 100644 --- a/Game/Code/Classes/ULog.pas +++ b/Game/Code/Classes/ULog.pas @@ -217,6 +217,8 @@ begin //Just for Debugging //Comment for Release //LogAnalyze (Log2 + ': ' + Log1); + + LogError(Log2 + ': ' + Log1); end; procedure TLog.LogError(Log1, Log2: string); -- cgit v1.2.3 From db82b7e30a1b58b56fdb4bfc6089b47200ca1da1 Mon Sep 17 00:00:00 2001 From: jaybinks Date: Thu, 20 Sep 2007 06:36:58 +0000 Subject: Ultrastar-DX now compiles in linux (using lazarus) Bass etc is commented out.. but it compiles, and im working through the runtime errors. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@408 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 496 +++++++++++++++++++++++---------------------- 1 file changed, 253 insertions(+), 243 deletions(-) (limited to 'Game/Code/Classes/ULog.pas') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas index d03ad8ed..7c93c6e9 100644 --- a/Game/Code/Classes/ULog.pas +++ b/Game/Code/Classes/ULog.pas @@ -1,243 +1,253 @@ -unit ULog; - -interface - -{$IFDEF FPC} - {$MODE Delphi} -{$ENDIF} - -uses Classes; - -type - TLog = class - BenchmarkTimeStart: array[0..7] of real; - BenchmarkTimeLength: array[0..7] of real;//TDateTime; - - FileBenchmark: TextFile; - FileBenchmarkO: boolean; // opened - FileError: TextFile; - FileErrorO: boolean; // opened - - Title: String; //Application Title - - //Should Log Files be written - Enabled: Boolean; - - // destuctor - destructor Free; - - // benchmark - procedure BenchmarkStart(Number: integer); - procedure BenchmarkEnd(Number: integer); - procedure LogBenchmark(Text: string; Number: integer); - - // error - procedure LogError(Text: string); overload; - - //Critical Error (Halt + MessageBox) - procedure CriticalError(Text: string); - - // voice - procedure LogVoice(SoundNr: integer); - - // compability - procedure LogStatus(Log1, Log2: string); - procedure LogError(Log1, Log2: string); overload; - end; - -var - Log: TLog; - -implementation - -uses - Windows, - SysUtils, - DateUtils, -// UFiles, - UMain, - URecord, - UTime, -// UIni, // JB - Seems to not be needed. - UCommandLine; - -destructor TLog.Free; -begin - if FileBenchmarkO then CloseFile(FileBenchmark); -// if FileAnalyzeO then CloseFile(FileAnalyze); - if FileErrorO then CloseFile(FileError); -end; - -procedure TLog.BenchmarkStart(Number: integer); -begin - BenchmarkTimeStart[Number] := USTime.GetTime; //Time; -end; - -procedure TLog.BenchmarkEnd(Number: integer); -begin - BenchmarkTimeLength[Number] := USTime.GetTime {Time} - BenchmarkTimeStart[Number]; -end; - -procedure TLog.LogBenchmark(Text: string; Number: integer); -var - Minutes: integer; - Seconds: integer; - Miliseconds: integer; - - MinutesS: string; - SecondsS: string; - MilisecondsS: string; - - ValueText: string; -begin - if Enabled AND (Params.Benchmark) then begin - if not FileBenchmarkO then begin - FileBenchmarkO := true; - AssignFile(FileBenchmark, LogPath + 'Benchmark.log'); - {$I-} - Rewrite(FileBenchmark); - if IOResult = 0 then FileBenchmarkO := true; - {$I+} - - //If File is opened write Date to Benchmark File - If (FileBenchmarkO) then - begin - WriteLn(FileBenchmark, Title + ' Benchmark File'); - WriteLn(FileBenchmark, 'Date: ' + DatetoStr(Now) + ' Time: ' + TimetoStr(Now)); - WriteLn(FileBenchmark, '-------------------'); - - Flush(FileBenchmark); - end; - end; - - if FileBenchmarkO then begin - Miliseconds := Trunc(Frac(BenchmarkTimeLength[Number]) * 1000); - Seconds := Trunc(BenchmarkTimeLength[Number]) mod 60; - Minutes := Trunc((BenchmarkTimeLength[Number] - Seconds) / 60); -// ValueText := FloatToStr(BenchmarkTimeLength[Number]); - -{ ValueText := FloatToStr( - SecondOf(BenchmarkTimeLength[Number]) + MilliSecondOf(BenchmarkTimeLength[Number])/1000 - ); - if MinuteOf(BenchmarkTimeLength[Number]) >= 1 then - ValueText := IntToStr(MinuteOf(BenchmarkTimeLength[Number])) + ':' + ValueText; - WriteLn(FileBenchmark, Text + ': ' + ValueText + ' seconds');} - - if (Minutes = 0) and (Seconds = 0) then begin - MilisecondsS := IntToStr(Miliseconds); - ValueText := MilisecondsS + ' miliseconds'; - end; - - if (Minutes = 0) and (Seconds >= 1) then begin - MilisecondsS := IntToStr(Miliseconds); - while Length(MilisecondsS) < 3 do MilisecondsS := '0' + MilisecondsS; - - SecondsS := IntToStr(Seconds); - - ValueText := SecondsS + ',' + MilisecondsS + ' seconds'; - end; - - if Minutes >= 1 then begin - MilisecondsS := IntToStr(Miliseconds); - while Length(MilisecondsS) < 3 do MilisecondsS := '0' + MilisecondsS; - - SecondsS := IntToStr(Seconds); - while Length(SecondsS) < 2 do SecondsS := '0' + SecondsS; - - MinutesS := IntToStr(Minutes); - - ValueText := MinutesS + ':' + SecondsS + ',' + MilisecondsS + ' minutes'; - end; - - WriteLn(FileBenchmark, Text + ': ' + ValueText); - Flush(FileBenchmark); - end; - end; -end; - -procedure TLog.LogError(Text: string); -begin - if Enabled AND (not FileErrorO) then begin - FileErrorO := true; - AssignFile(FileError, LogPath + 'Error.log'); - {$I-} - Rewrite(FileError); - if IOResult = 0 then FileErrorO := true; - {$I+} - - //If File is opened write Date to Error File - If (FileErrorO) then - begin - WriteLn(FileError, Title + ' Error Log'); - WriteLn(FileError, 'Date: ' + DatetoStr(Now) + ' Time: ' + TimetoStr(Now)); - WriteLn(FileError, '-------------------'); - - Flush(FileError); - end; - end; - - if FileErrorO then begin - try - WriteLn(FileError, Text); - Flush(FileError); - except - FileErrorO := false; - end; - end; -end; - -procedure TLog.LogVoice(SoundNr: integer); -var - FileVoice: File; - FS: TFileStream; - FileName: string; - Num: integer; - BL: integer; -begin - for Num := 1 to 9999 do begin - FileName := IntToStr(Num); - while Length(FileName) < 4 do FileName := '0' + FileName; - FileName := LogPath + 'Voice' + FileName + '.raw'; - if not FileExists(FileName) then break - end; - - - FS := TFileStream.Create(FileName, fmCreate); - - for BL := 0 to High(Sound[SoundNr].BufferLong) do begin - Sound[SoundNr].BufferLong[BL].Seek(0, soBeginning); - FS.CopyFrom(Sound[SoundNr].BufferLong[BL], Sound[SoundNr].BufferLong[BL].Size); - end; - - FS.Free; -end; - -procedure TLog.LogStatus(Log1, Log2: string); -begin - //Just for Debugging - //Comment for Release - //LogAnalyze (Log2 + ': ' + Log1); - - LogError(Log2 + ': ' + Log1); -end; - -procedure TLog.LogError(Log1, Log2: string); -begin -//asd -end; - -procedure TLog.CriticalError(Text: string); -begin - //Write Error to Logfile: - LogError (Text); - - //Show Errormessage - Messagebox(0, PChar(Text), PChar(Title), MB_ICONERROR or MB_OK); - - //Exit Application - Halt; -end; - -end. - - +unit ULog; + +interface + +{$I switches.inc} + +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + +uses Classes; + +type + TLog = class + BenchmarkTimeStart: array[0..7] of real; + BenchmarkTimeLength: array[0..7] of real;//TDateTime; + + FileBenchmark: TextFile; + FileBenchmarkO: boolean; // opened + FileError: TextFile; + FileErrorO: boolean; // opened + + Title: String; //Application Title + + //Should Log Files be written + Enabled: Boolean; + + // destuctor + destructor Free; + + // benchmark + procedure BenchmarkStart(Number: integer); + procedure BenchmarkEnd(Number: integer); + procedure LogBenchmark(Text: string; Number: integer); + + // error + procedure LogError(Text: string); overload; + + //Critical Error (Halt + MessageBox) + procedure CriticalError(Text: string); + + // voice + procedure LogVoice(SoundNr: integer); + + // compability + procedure LogStatus(Log1, Log2: string); + procedure LogError(Log1, Log2: string); overload; + end; + +var + Log: TLog; + +implementation + +uses + {$IFDEF win32} + windows, + {$ENDIF} + SysUtils, + DateUtils, +// UFiles, + UMain, + URecord, + UTime, +// UIni, // JB - Seems to not be needed. + UCommandLine; + +destructor TLog.Free; +begin + if FileBenchmarkO then CloseFile(FileBenchmark); +// if FileAnalyzeO then CloseFile(FileAnalyze); + if FileErrorO then CloseFile(FileError); +end; + +procedure TLog.BenchmarkStart(Number: integer); +begin + BenchmarkTimeStart[Number] := USTime.GetTime; //Time; +end; + +procedure TLog.BenchmarkEnd(Number: integer); +begin + BenchmarkTimeLength[Number] := USTime.GetTime {Time} - BenchmarkTimeStart[Number]; +end; + +procedure TLog.LogBenchmark(Text: string; Number: integer); +var + Minutes: integer; + Seconds: integer; + Miliseconds: integer; + + MinutesS: string; + SecondsS: string; + MilisecondsS: string; + + ValueText: string; +begin + if Enabled AND (Params.Benchmark) then begin + if not FileBenchmarkO then begin + FileBenchmarkO := true; + AssignFile(FileBenchmark, LogPath + 'Benchmark.log'); + {$I-} + Rewrite(FileBenchmark); + if IOResult = 0 then FileBenchmarkO := true; + {$I+} + + //If File is opened write Date to Benchmark File + If (FileBenchmarkO) then + begin + WriteLn(FileBenchmark, Title + ' Benchmark File'); + WriteLn(FileBenchmark, 'Date: ' + DatetoStr(Now) + ' Time: ' + TimetoStr(Now)); + WriteLn(FileBenchmark, '-------------------'); + + Flush(FileBenchmark); + end; + end; + + if FileBenchmarkO then begin + Miliseconds := Trunc(Frac(BenchmarkTimeLength[Number]) * 1000); + Seconds := Trunc(BenchmarkTimeLength[Number]) mod 60; + Minutes := Trunc((BenchmarkTimeLength[Number] - Seconds) / 60); +// ValueText := FloatToStr(BenchmarkTimeLength[Number]); + +{ ValueText := FloatToStr( + SecondOf(BenchmarkTimeLength[Number]) + MilliSecondOf(BenchmarkTimeLength[Number])/1000 + ); + if MinuteOf(BenchmarkTimeLength[Number]) >= 1 then + ValueText := IntToStr(MinuteOf(BenchmarkTimeLength[Number])) + ':' + ValueText; + WriteLn(FileBenchmark, Text + ': ' + ValueText + ' seconds');} + + if (Minutes = 0) and (Seconds = 0) then begin + MilisecondsS := IntToStr(Miliseconds); + ValueText := MilisecondsS + ' miliseconds'; + end; + + if (Minutes = 0) and (Seconds >= 1) then begin + MilisecondsS := IntToStr(Miliseconds); + while Length(MilisecondsS) < 3 do MilisecondsS := '0' + MilisecondsS; + + SecondsS := IntToStr(Seconds); + + ValueText := SecondsS + ',' + MilisecondsS + ' seconds'; + end; + + if Minutes >= 1 then begin + MilisecondsS := IntToStr(Miliseconds); + while Length(MilisecondsS) < 3 do MilisecondsS := '0' + MilisecondsS; + + SecondsS := IntToStr(Seconds); + while Length(SecondsS) < 2 do SecondsS := '0' + SecondsS; + + MinutesS := IntToStr(Minutes); + + ValueText := MinutesS + ':' + SecondsS + ',' + MilisecondsS + ' minutes'; + end; + + WriteLn(FileBenchmark, Text + ': ' + ValueText); + Flush(FileBenchmark); + end; + end; +end; + +procedure TLog.LogError(Text: string); +begin + if Enabled AND (not FileErrorO) then begin + FileErrorO := true; + AssignFile(FileError, LogPath + 'Error.log'); + {$I-} + Rewrite(FileError); + if IOResult = 0 then FileErrorO := true; + {$I+} + + //If File is opened write Date to Error File + If (FileErrorO) then + begin + WriteLn(FileError, Title + ' Error Log'); + WriteLn(FileError, 'Date: ' + DatetoStr(Now) + ' Time: ' + TimetoStr(Now)); + WriteLn(FileError, '-------------------'); + + Flush(FileError); + end; + end; + + if FileErrorO then begin + try + WriteLn(FileError, Text); + Flush(FileError); + except + FileErrorO := false; + end; + end; +end; + +procedure TLog.LogVoice(SoundNr: integer); +var + FileVoice: File; + FS: TFileStream; + FileName: string; + Num: integer; + BL: integer; +begin + for Num := 1 to 9999 do begin + FileName := IntToStr(Num); + while Length(FileName) < 4 do FileName := '0' + FileName; + FileName := LogPath + 'Voice' + FileName + '.raw'; + if not FileExists(FileName) then break + end; + + + FS := TFileStream.Create(FileName, fmCreate); + + for BL := 0 to High(Sound[SoundNr].BufferLong) do begin + Sound[SoundNr].BufferLong[BL].Seek(0, soBeginning); + FS.CopyFrom(Sound[SoundNr].BufferLong[BL], Sound[SoundNr].BufferLong[BL].Size); + end; + + FS.Free; +end; + +procedure TLog.LogStatus(Log1, Log2: string); +begin + //Just for Debugging + //Comment for Release + //LogAnalyze (Log2 + ': ' + Log1); + + LogError(Log2 + ': ' + Log1); +end; + +procedure TLog.LogError(Log1, Log2: string); +begin +//asd +end; + +procedure TLog.CriticalError(Text: string); +begin + //Write Error to Logfile: + LogError (Text); + + {$IFDEF win32} + //Show Errormessage + Messagebox(0, PChar(Text), PChar(Title), MB_ICONERROR or MB_OK); + {$ELSE} + // TODO - JB_Linux handle critical error so user can see message. + writeln( 'Critical ERROR :' ); + writeln( Text ); + {$ENDIF} + + //Exit Application + Halt; +end; + +end. + + -- cgit v1.2.3 From fdb75fa47dd72522b705e94be5a201c4e1a731cb Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Wed, 3 Oct 2007 12:43:01 +0000 Subject: New plugin SDK added Some more debug information for windows builds (Does this work in lazarus?) git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@466 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'Game/Code/Classes/ULog.pas') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas index 7c93c6e9..7e464b57 100644 --- a/Game/Code/Classes/ULog.pas +++ b/Game/Code/Classes/ULog.pas @@ -188,6 +188,11 @@ begin FileErrorO := false; end; end; + {$DEFINE DEBUG} //How can i check if this is set in *.dpr file o0 + //If Debug => Write to Console Output + {$IFDEF DEBUG} + WriteLn('Error: ' + Text); + {$ENDIF} end; procedure TLog.LogVoice(SoundNr: integer); @@ -219,10 +224,13 @@ end; procedure TLog.LogStatus(Log1, Log2: string); begin //Just for Debugging - //Comment for Release - //LogAnalyze (Log2 + ': ' + Log1); - - LogError(Log2 + ': ' + Log1); + //Comment for Release + //LogError(Log2 + ': ' + Log1); + + //If Debug => Write to Console Output + {$IFDEF DEBUG} + WriteLn(Log2 + ': ' + Log1); + {$ENDIF} end; procedure TLog.LogError(Log1, Log2: string); -- cgit v1.2.3 From 391d30716d48dc709f6444b19c008e82311623b9 Mon Sep 17 00:00:00 2001 From: eddie-0815 Date: Thu, 1 Nov 2007 19:34:40 +0000 Subject: Mac OS X version compiles and links. I hope I didn't break too many files on windows/linux. Added switches.inc to all files. Changed many IFDEFs. For Windows-only code please use MSWINDOWS instead of WIN32 now. WIN32 is also used by the Mac port. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@546 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'Game/Code/Classes/ULog.pas') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas index 7e464b57..2ce70a11 100644 --- a/Game/Code/Classes/ULog.pas +++ b/Game/Code/Classes/ULog.pas @@ -4,10 +4,6 @@ interface {$I switches.inc} -{$IFDEF FPC} - {$MODE Delphi} -{$ENDIF} - uses Classes; type @@ -191,7 +187,7 @@ begin {$DEFINE DEBUG} //How can i check if this is set in *.dpr file o0 //If Debug => Write to Console Output {$IFDEF DEBUG} - WriteLn('Error: ' + Text); + WriteLn('Error: ' + Text); {$ENDIF} end; @@ -229,7 +225,7 @@ begin //If Debug => Write to Console Output {$IFDEF DEBUG} - WriteLn(Log2 + ': ' + Log1); + WriteLn(Log2 + ': ' + Log1); {$ENDIF} end; @@ -243,7 +239,7 @@ begin //Write Error to Logfile: LogError (Text); - {$IFDEF win32} + {$IFDEF MSWINDOWS} //Show Errormessage Messagebox(0, PChar(Text), PChar(Title), MB_ICONERROR or MB_OK); {$ELSE} -- cgit v1.2.3 From 99955c78f63d1cb0d8bec666bc33953590a74c8a Mon Sep 17 00:00:00 2001 From: jaybinks Date: Thu, 1 Nov 2007 23:22:01 +0000 Subject: fixed failed builds build:USDX-LAZLIN-75 build:USDX-LAZLIN-76 for some reason we can not use {$MODE Delphi} in an included file. ( Probably because of the way the compier scopes this switch to each pas file ) ive had to revert this part of eddies changes. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@548 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Game/Code/Classes/ULog.pas') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas index 2ce70a11..7f0b82c4 100644 --- a/Game/Code/Classes/ULog.pas +++ b/Game/Code/Classes/ULog.pas @@ -2,6 +2,10 @@ unit ULog; interface +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + {$I switches.inc} uses Classes; -- cgit v1.2.3 From 3d2e9f4f029c5bb8868bb438d677c724ff6a2609 Mon Sep 17 00:00:00 2001 From: eddie-0815 Date: Thu, 22 Nov 2007 21:05:11 +0000 Subject: Added LogBuffer to dump binary data to a file. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@628 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'Game/Code/Classes/ULog.pas') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas index 7f0b82c4..ac08f2d5 100644 --- a/Game/Code/Classes/ULog.pas +++ b/Game/Code/Classes/ULog.pas @@ -45,6 +45,7 @@ type // compability procedure LogStatus(Log1, Log2: string); procedure LogError(Log1, Log2: string); overload; + procedure LogBuffer(const buf : Pointer; const bufLength : Integer; filename : string); end; var @@ -256,6 +257,24 @@ begin Halt; end; +procedure TLog.LogBuffer(const buf: Pointer; const bufLength: Integer; filename: string); +var + f : TFileStream; +begin + f := nil; + + try + f := TFileStream.Create( filename, fmCreate); + f.Write( buf^, bufLength); + f.Free; + except + on e : Exception do begin + Log.LogError('TLog.LogBuffer: Failed to log buffer into file "' + filename + '". ErrMsg: ' + e.Message); + f.Free; + end; + end; +end; + end. -- cgit v1.2.3 From a4a3643898a9f566b926bbd5fcc47c24a18be1ab Mon Sep 17 00:00:00 2001 From: tobigun Date: Wed, 5 Dec 2007 21:11:16 +0000 Subject: Sound is now Recording.Sound git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@665 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Game/Code/Classes/ULog.pas') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas index ac08f2d5..50e9bf68 100644 --- a/Game/Code/Classes/ULog.pas +++ b/Game/Code/Classes/ULog.pas @@ -214,9 +214,9 @@ begin FS := TFileStream.Create(FileName, fmCreate); - for BL := 0 to High(Sound[SoundNr].BufferLong) do begin - Sound[SoundNr].BufferLong[BL].Seek(0, soBeginning); - FS.CopyFrom(Sound[SoundNr].BufferLong[BL], Sound[SoundNr].BufferLong[BL].Size); + for BL := 0 to High(Recording.Sound[SoundNr].BufferLong) do begin + Recording.Sound[SoundNr].BufferLong[BL].Seek(0, soBeginning); + FS.CopyFrom(Recording.Sound[SoundNr].BufferLong[BL], Recording.Sound[SoundNr].BufferLong[BL].Size); end; FS.Free; -- cgit v1.2.3 From a00122fe60de966751b637477ac8e0a4fdcfbf4b Mon Sep 17 00:00:00 2001 From: jaybinks Date: Thu, 20 Dec 2007 23:59:59 +0000 Subject: removed a bunch of debugging from usdx startup. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@738 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'Game/Code/Classes/ULog.pas') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas index 50e9bf68..01eff5f4 100644 --- a/Game/Code/Classes/ULog.pas +++ b/Game/Code/Classes/ULog.pas @@ -189,8 +189,6 @@ begin FileErrorO := false; end; end; - {$DEFINE DEBUG} //How can i check if this is set in *.dpr file o0 - //If Debug => Write to Console Output {$IFDEF DEBUG} WriteLn('Error: ' + Text); {$ENDIF} @@ -230,7 +228,7 @@ begin //If Debug => Write to Console Output {$IFDEF DEBUG} - WriteLn(Log2 + ': ' + Log1); +// WriteLn(Log2 + ': ' + Log1); {$ENDIF} end; @@ -260,21 +258,21 @@ end; procedure TLog.LogBuffer(const buf: Pointer; const bufLength: Integer; filename: string); var f : TFileStream; -begin - f := nil; - - try - f := TFileStream.Create( filename, fmCreate); - f.Write( buf^, bufLength); - f.Free; - except - on e : Exception do begin - Log.LogError('TLog.LogBuffer: Failed to log buffer into file "' + filename + '". ErrMsg: ' + e.Message); - f.Free; - end; - end; -end; - +begin + f := nil; + + try + f := TFileStream.Create( filename, fmCreate); + f.Write( buf^, bufLength); + f.Free; + except + on e : Exception do begin + Log.LogError('TLog.LogBuffer: Failed to log buffer into file "' + filename + '". ErrMsg: ' + e.Message); + f.Free; + end; + end; +end; + end. -- cgit v1.2.3 From e4c30499349a0cc5b75fce7e59dc0a4abfa0a10e Mon Sep 17 00:00:00 2001 From: tobigun Date: Thu, 27 Dec 2007 12:31:21 +0000 Subject: FileErrorO is set to true to early. Even if FileError couldn't be opened it will be set to true and hence usdx tries to close and unopened fileerror-stream later which results in a segmentation fault git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@750 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Game/Code/Classes/ULog.pas') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas index 01eff5f4..fc567d54 100644 --- a/Game/Code/Classes/ULog.pas +++ b/Game/Code/Classes/ULog.pas @@ -163,7 +163,7 @@ end; procedure TLog.LogError(Text: string); begin if Enabled AND (not FileErrorO) then begin - FileErrorO := true; + //FileErrorO := true; AssignFile(FileError, LogPath + 'Error.log'); {$I-} Rewrite(FileError); -- cgit v1.2.3 From e74bd57c12f470257111c1c0530fb38f0fd34414 Mon Sep 17 00:00:00 2001 From: jaybinks Date: Sat, 12 Jan 2008 12:31:43 +0000 Subject: bunch of smaller changes... some changes to song loading... Record global changed to singleton object started implementing mic volume display in Settings-Record hope this dosnt break anything.. :P git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@789 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Game/Code/Classes/ULog.pas') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas index fc567d54..49b02c00 100644 --- a/Game/Code/Classes/ULog.pas +++ b/Game/Code/Classes/ULog.pas @@ -212,9 +212,9 @@ begin FS := TFileStream.Create(FileName, fmCreate); - for BL := 0 to High(Recording.Sound[SoundNr].BufferLong) do begin - Recording.Sound[SoundNr].BufferLong[BL].Seek(0, soBeginning); - FS.CopyFrom(Recording.Sound[SoundNr].BufferLong[BL], Recording.Sound[SoundNr].BufferLong[BL].Size); + for BL := 0 to High(AudioInputProcessor.Sound[SoundNr].BufferLong) do begin + AudioInputProcessor.Sound[SoundNr].BufferLong[BL].Seek(0, soBeginning); + FS.CopyFrom(AudioInputProcessor.Sound[SoundNr].BufferLong[BL], AudioInputProcessor.Sound[SoundNr].BufferLong[BL].Size); end; FS.Free; -- cgit v1.2.3 From 8c8037702011cbcc7f1bdc420ea1430025c573e0 Mon Sep 17 00:00:00 2001 From: tobigun Date: Fri, 25 Jan 2008 16:49:18 +0000 Subject: reenabled TLog.LogError(Log1, Log2: string). Some severe errors have not been displayed because this function was disabled. If this function should be deprecated then mark it as deprecated instead of just emptying the body of the function. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@803 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Game/Code/Classes/ULog.pas') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas index 49b02c00..c9c87a92 100644 --- a/Game/Code/Classes/ULog.pas +++ b/Game/Code/Classes/ULog.pas @@ -234,7 +234,7 @@ end; procedure TLog.LogError(Log1, Log2: string); begin -//asd + LogError(Log1 + ' ['+Log2+']'); end; procedure TLog.CriticalError(Text: string); -- cgit v1.2.3 From 2e6592ceadb3e3c910164c76595e7ae435b8823a Mon Sep 17 00:00:00 2001 From: tobigun Date: Tue, 5 Feb 2008 17:13:47 +0000 Subject: Added a SafeWriteLn()-function to support thread-safe console-output. This is used in all Log...-Methods now (not for file-output yet). Don't use WriteLn anymore from external threads (for example in SDL or Portaudio Callbacks), otherwise FPC will crash. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@826 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/ULog.pas | 642 +++++++++++++++++++++++++-------------------- 1 file changed, 364 insertions(+), 278 deletions(-) (limited to 'Game/Code/Classes/ULog.pas') diff --git a/Game/Code/Classes/ULog.pas b/Game/Code/Classes/ULog.pas index c9c87a92..542fa0b3 100644 --- a/Game/Code/Classes/ULog.pas +++ b/Game/Code/Classes/ULog.pas @@ -1,278 +1,364 @@ -unit ULog; - -interface - -{$IFDEF FPC} - {$MODE Delphi} -{$ENDIF} - -{$I switches.inc} - -uses Classes; - -type - TLog = class - BenchmarkTimeStart: array[0..7] of real; - BenchmarkTimeLength: array[0..7] of real;//TDateTime; - - FileBenchmark: TextFile; - FileBenchmarkO: boolean; // opened - FileError: TextFile; - FileErrorO: boolean; // opened - - Title: String; //Application Title - - //Should Log Files be written - Enabled: Boolean; - - // destuctor - destructor Free; - - // benchmark - procedure BenchmarkStart(Number: integer); - procedure BenchmarkEnd(Number: integer); - procedure LogBenchmark(Text: string; Number: integer); - - // error - procedure LogError(Text: string); overload; - - //Critical Error (Halt + MessageBox) - procedure CriticalError(Text: string); - - // voice - procedure LogVoice(SoundNr: integer); - - // compability - procedure LogStatus(Log1, Log2: string); - procedure LogError(Log1, Log2: string); overload; - procedure LogBuffer(const buf : Pointer; const bufLength : Integer; filename : string); - end; - -var - Log: TLog; - -implementation - -uses - {$IFDEF win32} - windows, - {$ENDIF} - SysUtils, - DateUtils, -// UFiles, - UMain, - URecord, - UTime, -// UIni, // JB - Seems to not be needed. - UCommandLine; - -destructor TLog.Free; -begin - if FileBenchmarkO then CloseFile(FileBenchmark); -// if FileAnalyzeO then CloseFile(FileAnalyze); - if FileErrorO then CloseFile(FileError); -end; - -procedure TLog.BenchmarkStart(Number: integer); -begin - BenchmarkTimeStart[Number] := USTime.GetTime; //Time; -end; - -procedure TLog.BenchmarkEnd(Number: integer); -begin - BenchmarkTimeLength[Number] := USTime.GetTime {Time} - BenchmarkTimeStart[Number]; -end; - -procedure TLog.LogBenchmark(Text: string; Number: integer); -var - Minutes: integer; - Seconds: integer; - Miliseconds: integer; - - MinutesS: string; - SecondsS: string; - MilisecondsS: string; - - ValueText: string; -begin - if Enabled AND (Params.Benchmark) then begin - if not FileBenchmarkO then begin - FileBenchmarkO := true; - AssignFile(FileBenchmark, LogPath + 'Benchmark.log'); - {$I-} - Rewrite(FileBenchmark); - if IOResult = 0 then FileBenchmarkO := true; - {$I+} - - //If File is opened write Date to Benchmark File - If (FileBenchmarkO) then - begin - WriteLn(FileBenchmark, Title + ' Benchmark File'); - WriteLn(FileBenchmark, 'Date: ' + DatetoStr(Now) + ' Time: ' + TimetoStr(Now)); - WriteLn(FileBenchmark, '-------------------'); - - Flush(FileBenchmark); - end; - end; - - if FileBenchmarkO then begin - Miliseconds := Trunc(Frac(BenchmarkTimeLength[Number]) * 1000); - Seconds := Trunc(BenchmarkTimeLength[Number]) mod 60; - Minutes := Trunc((BenchmarkTimeLength[Number] - Seconds) / 60); -// ValueText := FloatToStr(BenchmarkTimeLength[Number]); - -{ ValueText := FloatToStr( - SecondOf(BenchmarkTimeLength[Number]) + MilliSecondOf(BenchmarkTimeLength[Number])/1000 - ); - if MinuteOf(BenchmarkTimeLength[Number]) >= 1 then - ValueText := IntToStr(MinuteOf(BenchmarkTimeLength[Number])) + ':' + ValueText; - WriteLn(FileBenchmark, Text + ': ' + ValueText + ' seconds');} - - if (Minutes = 0) and (Seconds = 0) then begin - MilisecondsS := IntToStr(Miliseconds); - ValueText := MilisecondsS + ' miliseconds'; - end; - - if (Minutes = 0) and (Seconds >= 1) then begin - MilisecondsS := IntToStr(Miliseconds); - while Length(MilisecondsS) < 3 do MilisecondsS := '0' + MilisecondsS; - - SecondsS := IntToStr(Seconds); - - ValueText := SecondsS + ',' + MilisecondsS + ' seconds'; - end; - - if Minutes >= 1 then begin - MilisecondsS := IntToStr(Miliseconds); - while Length(MilisecondsS) < 3 do MilisecondsS := '0' + MilisecondsS; - - SecondsS := IntToStr(Seconds); - while Length(SecondsS) < 2 do SecondsS := '0' + SecondsS; - - MinutesS := IntToStr(Minutes); - - ValueText := MinutesS + ':' + SecondsS + ',' + MilisecondsS + ' minutes'; - end; - - WriteLn(FileBenchmark, Text + ': ' + ValueText); - Flush(FileBenchmark); - end; - end; -end; - -procedure TLog.LogError(Text: string); -begin - if Enabled AND (not FileErrorO) then begin - //FileErrorO := true; - AssignFile(FileError, LogPath + 'Error.log'); - {$I-} - Rewrite(FileError); - if IOResult = 0 then FileErrorO := true; - {$I+} - - //If File is opened write Date to Error File - If (FileErrorO) then - begin - WriteLn(FileError, Title + ' Error Log'); - WriteLn(FileError, 'Date: ' + DatetoStr(Now) + ' Time: ' + TimetoStr(Now)); - WriteLn(FileError, '-------------------'); - - Flush(FileError); - end; - end; - - if FileErrorO then begin - try - WriteLn(FileError, Text); - Flush(FileError); - except - FileErrorO := false; - end; - end; - {$IFDEF DEBUG} - WriteLn('Error: ' + Text); - {$ENDIF} -end; - -procedure TLog.LogVoice(SoundNr: integer); -var - FileVoice: File; - FS: TFileStream; - FileName: string; - Num: integer; - BL: integer; -begin - for Num := 1 to 9999 do begin - FileName := IntToStr(Num); - while Length(FileName) < 4 do FileName := '0' + FileName; - FileName := LogPath + 'Voice' + FileName + '.raw'; - if not FileExists(FileName) then break - end; - - - FS := TFileStream.Create(FileName, fmCreate); - - for BL := 0 to High(AudioInputProcessor.Sound[SoundNr].BufferLong) do begin - AudioInputProcessor.Sound[SoundNr].BufferLong[BL].Seek(0, soBeginning); - FS.CopyFrom(AudioInputProcessor.Sound[SoundNr].BufferLong[BL], AudioInputProcessor.Sound[SoundNr].BufferLong[BL].Size); - end; - - FS.Free; -end; - -procedure TLog.LogStatus(Log1, Log2: string); -begin - //Just for Debugging - //Comment for Release - //LogError(Log2 + ': ' + Log1); - - //If Debug => Write to Console Output - {$IFDEF DEBUG} -// WriteLn(Log2 + ': ' + Log1); - {$ENDIF} -end; - -procedure TLog.LogError(Log1, Log2: string); -begin - LogError(Log1 + ' ['+Log2+']'); -end; - -procedure TLog.CriticalError(Text: string); -begin - //Write Error to Logfile: - LogError (Text); - - {$IFDEF MSWINDOWS} - //Show Errormessage - Messagebox(0, PChar(Text), PChar(Title), MB_ICONERROR or MB_OK); - {$ELSE} - // TODO - JB_Linux handle critical error so user can see message. - writeln( 'Critical ERROR :' ); - writeln( Text ); - {$ENDIF} - - //Exit Application - Halt; -end; - -procedure TLog.LogBuffer(const buf: Pointer; const bufLength: Integer; filename: string); -var - f : TFileStream; -begin - f := nil; - - try - f := TFileStream.Create( filename, fmCreate); - f.Write( buf^, bufLength); - f.Free; - except - on e : Exception do begin - Log.LogError('TLog.LogBuffer: Failed to log buffer into file "' + filename + '". ErrMsg: ' + e.Message); - f.Free; - end; - end; -end; - -end. - - +unit ULog; + +interface + +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + +{$I switches.inc} + +uses + Classes; + +type + TLog = class + public + BenchmarkTimeStart: array[0..7] of real; + BenchmarkTimeLength: array[0..7] of real;//TDateTime; + + FileBenchmark: TextFile; + FileBenchmarkO: boolean; // opened + FileError: TextFile; + FileErrorO: boolean; // opened + + Title: String; //Application Title + + //Should Log Files be written + Enabled: Boolean; + + constructor Create; + + // destuctor + destructor Destroy; override; + + // benchmark + procedure BenchmarkStart(Number: integer); + procedure BenchmarkEnd(Number: integer); + procedure LogBenchmark(Text: string; Number: integer); + + // error + procedure LogError(Text: string); overload; + + //Critical Error (Halt + MessageBox) + procedure CriticalError(Text: string); + + // voice + procedure LogVoice(SoundNr: integer); + + // compability + procedure LogStatus(Log1, Log2: string); + procedure LogError(Log1, Log2: string); overload; + procedure LogBuffer(const buf : Pointer; const bufLength : Integer; filename : string); + end; + +procedure SafeWriteLn(const msg: string); inline; + +var + Log: TLog; + +implementation + +uses + {$IFDEF win32} + windows, + {$ENDIF} + SysUtils, + DateUtils, +//UFiles, + UMain, + URecord, + UTime, +//UIni, // JB - Seems to not be needed. + {$IFDEF FPC} + sdl, + {$ENDIF} + UCommandLine; + +{$IFDEF FPC} +var + MessageList: TStringList; + ConsoleHandler: TThreadID; + ConsoleMutex: PSDL_Mutex; + ConsoleCond: PSDL_Cond; +{$ENDIF} + +{$IFDEF FPC} +{* + * The console-handlers main-function. + * TODO: create a quit-event on closing. + *} +function ConsoleHandlerFunc(param: pointer): PtrInt; +var + i: integer; +begin + while true do + begin + SDL_mutexP(ConsoleMutex); + while (MessageList.Count = 0) do + SDL_CondWait(ConsoleCond, ConsoleMutex); + for i := 0 to MessageList.Count-1 do + begin + WriteLn(MessageList[i]); + end; + MessageList.Clear(); + SDL_mutexV(ConsoleMutex); + end; + result := 0; +end; +{$ENDIF} + +{* + * With FPC console output is not thread-safe. + * Using WriteLn() from external threads (like in SDL callbacks) + * will damage the heap and crash the program. + * Most probably FPC uses thread-local-data (TLS) to lock a mutex on + * the console-buffer. This does not work with external lib's threads + * because these do not have the TLS data and so it crashes while + * accessing unallocated memory. + * The solution is to create an FPC-managed thread which has the TLS data + * and use it to handle the console-output (hence it is called Console-Handler) + * It should be safe to do so, but maybe FPC requires the main-thread to access + * the console-buffer only. In this case output should be delegated to it. + * + * TODO: - check if it is safe if an FPC-managed thread different than the + * main-thread accesses the console-buffer in FPC. + * - check if Delphi's WriteLn is thread-safe. + * - check if we need to synchronize file-output too + * - Use TEvent and TCriticalSection instead of the SDL equivalents. + * Note: If those two objects use TLS they might crash FPC too. + *} +procedure SafeWriteLn(const msg: string); +begin +{$IFDEF FPC} + SDL_mutexP(ConsoleMutex); + MessageList.Add(msg); + SDL_CondSignal(ConsoleCond); + SDL_mutexV(ConsoleMutex); +{$ELSE} + WriteLn(msg); +{$ENDIF} +end; + +constructor TLog.Create; +begin +{$IFDEF FPC} + // TODO: check for the main-thread? + //GetCurrentThreadThreadId(); + MessageList := TStringList.Create(); + ConsoleMutex := SDL_CreateMutex(); + ConsoleCond := SDL_CreateCond(); + ConsoleHandler := BeginThread(@ConsoleHandlerFunc); +{$ENDIF} +end; + +destructor TLog.Destroy; +begin + if FileBenchmarkO then CloseFile(FileBenchmark); +// if FileAnalyzeO then CloseFile(FileAnalyze); + if FileErrorO then CloseFile(FileError); +end; + +procedure TLog.BenchmarkStart(Number: integer); +begin + BenchmarkTimeStart[Number] := USTime.GetTime; //Time; +end; + +procedure TLog.BenchmarkEnd(Number: integer); +begin + BenchmarkTimeLength[Number] := USTime.GetTime {Time} - BenchmarkTimeStart[Number]; +end; + +procedure TLog.LogBenchmark(Text: string; Number: integer); +var + Minutes: integer; + Seconds: integer; + Miliseconds: integer; + + MinutesS: string; + SecondsS: string; + MilisecondsS: string; + + ValueText: string; +begin + if Enabled AND (Params.Benchmark) then begin + if not FileBenchmarkO then begin + FileBenchmarkO := true; + AssignFile(FileBenchmark, LogPath + 'Benchmark.log'); + {$I-} + Rewrite(FileBenchmark); + if IOResult = 0 then FileBenchmarkO := true; + {$I+} + + //If File is opened write Date to Benchmark File + If (FileBenchmarkO) then + begin + WriteLn(FileBenchmark, Title + ' Benchmark File'); + WriteLn(FileBenchmark, 'Date: ' + DatetoStr(Now) + ' Time: ' + TimetoStr(Now)); + WriteLn(FileBenchmark, '-------------------'); + + Flush(FileBenchmark); + end; + end; + + if FileBenchmarkO then begin + Miliseconds := Trunc(Frac(BenchmarkTimeLength[Number]) * 1000); + Seconds := Trunc(BenchmarkTimeLength[Number]) mod 60; + Minutes := Trunc((BenchmarkTimeLength[Number] - Seconds) / 60); +// ValueText := FloatToStr(BenchmarkTimeLength[Number]); + +{ ValueText := FloatToStr( + SecondOf(BenchmarkTimeLength[Number]) + MilliSecondOf(BenchmarkTimeLength[Number])/1000 + ); + if MinuteOf(BenchmarkTimeLength[Number]) >= 1 then + ValueText := IntToStr(MinuteOf(BenchmarkTimeLength[Number])) + ':' + ValueText; + WriteLn(FileBenchmark, Text + ': ' + ValueText + ' seconds');} + + if (Minutes = 0) and (Seconds = 0) then begin + MilisecondsS := IntToStr(Miliseconds); + ValueText := MilisecondsS + ' miliseconds'; + end; + + if (Minutes = 0) and (Seconds >= 1) then begin + MilisecondsS := IntToStr(Miliseconds); + while Length(MilisecondsS) < 3 do MilisecondsS := '0' + MilisecondsS; + + SecondsS := IntToStr(Seconds); + + ValueText := SecondsS + ',' + MilisecondsS + ' seconds'; + end; + + if Minutes >= 1 then begin + MilisecondsS := IntToStr(Miliseconds); + while Length(MilisecondsS) < 3 do MilisecondsS := '0' + MilisecondsS; + + SecondsS := IntToStr(Seconds); + while Length(SecondsS) < 2 do SecondsS := '0' + SecondsS; + + MinutesS := IntToStr(Minutes); + + ValueText := MinutesS + ':' + SecondsS + ',' + MilisecondsS + ' minutes'; + end; + + WriteLn(FileBenchmark, Text + ': ' + ValueText); + Flush(FileBenchmark); + end; + end; +end; + +procedure TLog.LogError(Text: string); +begin + if Enabled AND (not FileErrorO) then begin + //FileErrorO := true; + AssignFile(FileError, LogPath + 'Error.log'); + {$I-} + Rewrite(FileError); + if IOResult = 0 then FileErrorO := true; + {$I+} + + //If File is opened write Date to Error File + If (FileErrorO) then + begin + WriteLn(FileError, Title + ' Error Log'); + WriteLn(FileError, 'Date: ' + DatetoStr(Now) + ' Time: ' + TimetoStr(Now)); + WriteLn(FileError, '-------------------'); + + Flush(FileError); + end; + end; + + if FileErrorO then begin + try + WriteLn(FileError, Text); + Flush(FileError); + except + FileErrorO := false; + end; + end; + {$IFDEF DEBUG} + SafeWriteLn('Error: ' + Text); + {$ENDIF} +end; + +procedure TLog.LogVoice(SoundNr: integer); +var + FileVoice: File; + FS: TFileStream; + FileName: string; + Num: integer; + BL: integer; +begin + for Num := 1 to 9999 do begin + FileName := IntToStr(Num); + while Length(FileName) < 4 do FileName := '0' + FileName; + FileName := LogPath + 'Voice' + FileName + '.raw'; + if not FileExists(FileName) then break + end; + + + FS := TFileStream.Create(FileName, fmCreate); + + for BL := 0 to High(AudioInputProcessor.Sound[SoundNr].BufferLong) do begin + AudioInputProcessor.Sound[SoundNr].BufferLong[BL].Seek(0, soBeginning); + FS.CopyFrom(AudioInputProcessor.Sound[SoundNr].BufferLong[BL], AudioInputProcessor.Sound[SoundNr].BufferLong[BL].Size); + end; + + FS.Free; +end; + +procedure TLog.LogStatus(Log1, Log2: string); +begin + //Just for Debugging + //Comment for Release + //LogError(Log2 + ': ' + Log1); + + //If Debug => Write to Console Output + {$IFDEF DEBUG} + // SafeWriteLn(Log2 + ': ' + Log1); + {$ENDIF} +end; + +procedure TLog.LogError(Log1, Log2: string); +begin + LogError(Log1 + ' ['+Log2+']'); +end; + +procedure TLog.CriticalError(Text: string); +begin + //Write Error to Logfile: + LogError (Text); + + {$IFDEF MSWINDOWS} + //Show Errormessage + Messagebox(0, PChar(Text), PChar(Title), MB_ICONERROR or MB_OK); + {$ELSE} + // TODO - JB_Linux handle critical error so user can see message. + SafeWriteLn( 'Critical ERROR :' ); + SafeWriteLn( Text ); + {$ENDIF} + + //Exit Application + Halt; +end; + +procedure TLog.LogBuffer(const buf: Pointer; const bufLength: Integer; filename: string); +var + f : TFileStream; +begin + f := nil; + + try + f := TFileStream.Create( filename, fmCreate); + f.Write( buf^, bufLength); + f.Free; + except + on e : Exception do begin + Log.LogError('TLog.LogBuffer: Failed to log buffer into file "' + filename + '". ErrMsg: ' + e.Message); + f.Free; + end; + end; +end; + +end. + + -- cgit v1.2.3