diff --git a/Source/finders/simba.finder_bitmap.pas b/Source/finders/simba.finder_bitmap.pas index 715e5108b..6e9b0f146 100644 --- a/Source/finders/simba.finder_bitmap.pas +++ b/Source/finders/simba.finder_bitmap.pas @@ -29,9 +29,10 @@ function FindBitmapOnBuffer(var Limit: TSimpleThreadsafeLimit; SearchWidth, SearchHeight: Integer): TPointArray; var - BitmapFinderMT_Enabled: Boolean = True; - BitmapFinderMT_SliceHeight: Integer = 125; - BitmapFinderMT_SliceWidth: Integer = 250; + BitmapFinderMultithreadOpts: record + Enabled: Boolean; + SliceWidth, SliceHeight: Integer; + end; implementation @@ -47,10 +48,10 @@ function CalculateSlices(SearchWidth, SearchHeight: Integer): Integer; begin Result := 1; - if BitmapFinderMT_Enabled and (SearchWidth >= BitmapFinderMT_SliceWidth) and (SearchHeight >= (BitmapFinderMT_SliceHeight * 2)) then // not worth + if BitmapFinderMultithreadOpts.Enabled and (SearchWidth >= BitmapFinderMultithreadOpts.SliceWidth) and (SearchHeight >= (BitmapFinderMultithreadOpts.SliceHeight * 2)) then // not worth begin for I := SimbaThreadPool.ThreadCount - 1 downto 2 do - if (SearchHeight div I) > BitmapFinderMT_SliceHeight then // Each slice is at least `MatchTemplateMT_SliceHeight` pixels + if (SearchHeight div I) > BitmapFinderMultithreadOpts.SliceHeight then // Each slice is at least `MatchTemplateMT_SliceHeight` pixels Exit(I); end; @@ -274,5 +275,10 @@ function FindBitmapOnBuffer(var Limit: TSimpleThreadsafeLimit; Bitmap: TSimbaIma end; end; +initialization + BitmapFinderMultithreadOpts.Enabled := True; + BitmapFinderMultithreadOpts.SliceHeight := 125; + BitmapFinderMultithreadOpts.SliceWidth := 250; + end. diff --git a/Source/finders/simba.finder_color.pas b/Source/finders/simba.finder_color.pas index a3f789121..e173fb60a 100644 --- a/Source/finders/simba.finder_color.pas +++ b/Source/finders/simba.finder_color.pas @@ -40,9 +40,10 @@ function MatchColorsOnTarget(Target: TSimbaTarget; Bounds: TBox; Formula: EColorSpace; Color: TColor; Multipliers: TChannelMultipliers): TSingleMatrix; var - ColorFinderMT_Enabled: Boolean = True; - ColorFinderMT_SliceHeight: Integer = 125; - ColorFinderMT_SliceWidth: Integer = 250; + ColorFinderMultithreadOpts: record + Enabled: Boolean; + SliceWidth, SliceHeight: Integer; + end; implementation @@ -56,10 +57,10 @@ function CalculateSlices(SearchWidth, SearchHeight: Integer): Integer; begin Result := 1; - if ColorFinderMT_Enabled and (SearchWidth >= ColorFinderMT_SliceWidth) and (SearchHeight >= (ColorFinderMT_SliceHeight * 2)) then // not worth + if ColorFinderMultithreadOpts.Enabled and (SearchWidth >= ColorFinderMultithreadOpts.SliceWidth) and (SearchHeight >= (ColorFinderMultithreadOpts.SliceHeight * 2)) then // not worth begin for I := SimbaThreadPool.ThreadCount - 1 downto 2 do - if (SearchHeight div I) > ColorFinderMT_SliceHeight then // Each slice is at leastColorFinderMT_SliceHeight` pixels + if (SearchHeight div I) > ColorFinderMultithreadOpts.SliceHeight then // Each slice is at leastColorFinderMT_SliceHeight` pixels Exit(I); end; @@ -352,6 +353,9 @@ function MatchColorsOnTarget(Target: TSimbaTarget; Bounds: TBox; end; end; -end. - +initialization + ColorFinderMultithreadOpts.Enabled := True; + ColorFinderMultithreadOpts.SliceWidth := 125; + ColorFinderMultithreadOpts.SliceHeight := 250; +end. diff --git a/Source/matchtemplate/simba.matchtemplate.pas b/Source/matchtemplate/simba.matchtemplate.pas index a98b3ed47..d8c0cfec4 100644 --- a/Source/matchtemplate/simba.matchtemplate.pas +++ b/Source/matchtemplate/simba.matchtemplate.pas @@ -56,9 +56,10 @@ function CalculateSlices(SearchWidth, SearchHeight: Integer): Integer; function Multithread(Image, Templ: TIntegerMatrix; MatchTemplate: TMatchTemplate; Normed: Boolean): TSingleMatrix; var - MatchTemplateMT_Enabled: Boolean = True; - MatchTemplateMT_SliceHeight: Integer = 125; - MatchTemplateMT_SliceWidth: Integer = 250; + MatchTemplateMultithreadOpts: record + Enabled: Boolean; + SliceWidth, SliceHeight: Integer; + end; implementation @@ -74,10 +75,10 @@ function CalculateSlices(SearchWidth, SearchHeight: Integer): Integer; begin Result := 1; - if MatchTemplateMT_Enabled and (SearchWidth >= MatchTemplateMT_SliceWidth) and (SearchHeight >= (MatchTemplateMT_SliceHeight * 2)) then // not worth + if MatchTemplateMultithreadOpts.Enabled and (SearchWidth >= MatchTemplateMultithreadOpts.SliceWidth) and (SearchHeight >= (MatchTemplateMultithreadOpts.SliceHeight * 2)) then // not worth begin for I := SimbaThreadPool.ThreadCount - 1 downto 2 do - if (SearchHeight div I) > MatchTemplateMT_SliceHeight then // Each slice is at least `MatchTemplateMT_SliceHeight` pixels + if (SearchHeight div I) > MatchTemplateMultithreadOpts.SliceHeight then // Each slice is at least `MatchTemplateMT_SliceHeight` pixels Exit(I); end; @@ -174,4 +175,9 @@ function MatchTemplate(Image, Template: TIntegerMatrix; Formula: ETMFormula): TS end; end; +initialization + MatchTemplateMultithreadOpts.Enabled := True; + MatchTemplateMultithreadOpts.SliceWidth := 125; + MatchTemplateMultithreadOpts.SliceHeight := 250; + end. diff --git a/Source/script/imports/simba/simba.import_finder.pas b/Source/script/imports/simba/simba.import_finder.pas index 8034421f0..1ed32ce8c 100644 --- a/Source/script/imports/simba/simba.import_finder.pas +++ b/Source/script/imports/simba/simba.import_finder.pas @@ -262,11 +262,11 @@ procedure _LapeFinder_GetPixelDifference1(const Params: PParamArray; const Resul (* TFinder.GetPixelDifference ~~~~~~~~~~~~~~~~~~~~~~~~~~ -> function TFinder.GetPixelDifference(WaitTime, Tolerance: Integer; Area: TBox = [-1,-1,-1,-1]): Integer; +> function TFinder.GetPixelDifference(WaitTime, Tolerance: Single; Area: TBox = [-1,-1,-1,-1]): Integer; *) procedure _LapeFinder_GetPixelDifference2(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV begin - PInteger(Result)^ := PSimbaFinder(Params^[0])^.GetPixelDifference(PInteger(Params^[1])^, PInteger(Params^[2])^, PBox(Params^[3])^); + PInteger(Result)^ := PSimbaFinder(Params^[0])^.GetPixelDifference(PInteger(Params^[1])^, PSingle(Params^[2])^, PBox(Params^[3])^); end; (* @@ -282,11 +282,11 @@ procedure _LapeFinder_GetPixelDifferenceTPA1(const Params: PParamArray; const Re (* TFinder.GetPixelDifferenceTPA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -> function TFinder.GetPixelDifferenceTPA(WaitTime, Tolerance: Integer; Area: TBox = [-1,-1,-1,-1]): TPointArray; +> function TFinder.GetPixelDifferenceTPA(WaitTime, Tolerance: Single; Area: TBox = [-1,-1,-1,-1]): TPointArray; *) procedure _LapeFinder_GetPixelDifferenceTPA2(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV begin - PPointArray(Result)^ := PSimbaFinder(Params^[0])^.GetPixelDifferenceTPA(PInteger(Params^[1])^, PInteger(Params^[2])^, PBox(Params^[3])^); + PPointArray(Result)^ := PSimbaFinder(Params^[0])^.GetPixelDifferenceTPA(PInteger(Params^[1])^, PSingle(Params^[2])^, PBox(Params^[3])^); end; (* @@ -343,13 +343,8 @@ procedure ImportFinder(Compiler: TSimbaScript_Compiler); begin ImportingSection := 'Finder'; - addGlobalVar(ltBoolean, @ColorFinderMT_Enabled, 'ColorFinderMT_Enabled'); - addGlobalVar(ltInt32, @ColorFinderMT_SliceHeight, 'ColorFinderMT_SliceHeight'); - addGlobalVar(ltInt32, @ColorFinderMT_SliceWidth, 'ColorFinderMT_SliceWidth'); - - addGlobalVar(ltBoolean, @BitmapFinderMT_Enabled, 'BitmapFinderMT_Enabled'); - addGlobalVar(ltInt32, @BitmapFinderMT_SliceHeight, 'BitmapFinderMT_SliceHeight'); - addGlobalVar(ltInt32, @BitmapFinderMT_SliceWidth, 'BitmapFinderMT_SliceWidth'); + addGlobalVar('record Enabled: Boolean; SliceWidth, SliceHeight: Integer; end;', @ColorFinderMultithreadOpts, 'ColorFinderMultithreadOpts'); + addGlobalVar('record Enabled: Boolean; SliceWidth, SliceHeight: Integer; end;', @BitmapFinderMultithreadOpts, 'BitmapFinderMultithreadOpts'); addGlobalType([ 'record', @@ -415,9 +410,9 @@ procedure ImportFinder(Compiler: TSimbaScript_Compiler); addFinderMethod('function TFinder.GetColorsMatrix(Bounds: TBox = [-1,-1,-1,-1]): TIntegerMatrix', @_LapeFinder_GetColorsMatrix); addFinderMethod('function TFinder.GetPixelDifference(WaitTime: Integer; Area: TBox = [-1,-1,-1,-1]): Integer; overload', @_LapeFinder_GetPixelDifference1); - addFinderMethod('function TFinder.GetPixelDifference(WaitTime, Tolerance: Integer; Area: TBox = [-1,-1,-1,-1]): Integer; overload', @_LapeFinder_GetPixelDifference2); + addFinderMethod('function TFinder.GetPixelDifference(WaitTime: Integer; Tolerance: Single; Area: TBox = [-1,-1,-1,-1]): Integer; overload', @_LapeFinder_GetPixelDifference2); addFinderMethod('function TFinder.GetPixelDifferenceTPA(WaitTime: Integer; Area: TBox = [-1,-1,-1,-1]): TPointArray; overload', @_LapeFinder_GetPixelDifferenceTPA1); - addFinderMethod('function TFinder.GetPixelDifferenceTPA(WaitTime, Tolerance: Integer; Area: TBox = [-1,-1,-1,-1]): TPointArray; overload', @_LapeFinder_GetPixelDifferenceTPA2); + addFinderMethod('function TFinder.GetPixelDifferenceTPA(WaitTime: Integer; Tolerance: Single; Area: TBox = [-1,-1,-1,-1]): TPointArray; overload', @_LapeFinder_GetPixelDifferenceTPA2); addFinderMethod('function TFinder.AverageBrightness(Area: TBox = [-1,-1,-1,-1]): Integer', @_LapeFinder_AverageBrightness); addFinderMethod('function TFinder.PeakBrightness(Area: TBox = [-1,-1,-1,-1]): Integer', @_LapeFinder_PeakBrightness); diff --git a/Source/script/imports/simba/simba.import_matchtemplate.pas b/Source/script/imports/simba/simba.import_matchtemplate.pas index 2eabf8e0a..8d30ed5cc 100644 --- a/Source/script/imports/simba/simba.import_matchtemplate.pas +++ b/Source/script/imports/simba/simba.import_matchtemplate.pas @@ -72,9 +72,7 @@ procedure ImportMatchTemplate(Compiler: TSimbaScript_Compiler); begin ImportingSection := 'Match Template'; - addGlobalVar(ltBoolean, @MatchTemplateMT_Enabled, 'MatchTemplateMT_Enabled'); - addGlobalVar(ltInt32, @MatchTemplateMT_SliceHeight, 'MatchTemplateMT_SliceHeight'); - addGlobalVar(ltInt32, @MatchTemplateMT_SliceWidth, 'MatchTemplateMT_SliceWidth'); + addGlobalVar('record Enabled: Boolean; SliceWidth, SliceHeight: Integer; end;', @MatchTemplateMultithreadOpts, 'MatchTemplateMultithreadOpts'); addClass('TMatchTemplateCache'); addGlobalType('(TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF, TM_CCOEFF_NORMED, TM_SQDIFF, TM_SQDIFF_NORMED)', 'ETMFormula'); diff --git a/Source/script/simba.compiler_dump.pas b/Source/script/simba.compiler_dump.pas index a3a5d2353..f4a6534ac 100644 --- a/Source/script/simba.compiler_dump.pas +++ b/Source/script/simba.compiler_dump.pas @@ -46,11 +46,16 @@ TSimbaCompilerDump = class(TSimbaScript_Compiler) procedure addBaseDefine(Define: lpString; Value: lpString = ''); override; function addDelayedCode(ACode: lpString; AFileName: lpString = ''; AfterCompilation: Boolean = True; IsGlobal: Boolean = True): TLapeTree_Base; override; + function addGlobalFunc(Header: lpString; Value: Pointer): TLapeGlobalVar; override; function addGlobalFunc(Header: lpString; Body: TStringArray): TLapeTree_Method; override; + function addGlobalType(Typ: TLapeType; AName: lpString; ACopy: Boolean): TLapeType; override; function addGlobalType(Str: lpString; AName: lpString): TLapeType; override; + function addGlobalVar(Typ: lpString; Value: lpString; AName: lpString): TLapeGlobalVar; override; + function addGlobalVar(Typ: lpString; Value: Pointer; AName: lpString): TLapeGlobalVar; override; + function addGlobalVar(AVar: TLapeGlobalVar; AName: lpString = ''): TLapeGlobalVar; override; procedure DumpToFile(FileName: String); end; @@ -214,6 +219,19 @@ function TSimbaCompilerDump.addGlobalVar(Typ: lpString; Value: lpString; AName: Result._DocPos.FileName := ImportingSection; end; +function TSimbaCompilerDump.addGlobalVar(Typ: lpString; Value: Pointer; AName: lpString): TLapeGlobalVar; +begin + Result := inherited addGlobalVar(Typ, Value, AName); + + AddCode('var ' + AName + ': ' + Typ); +end; + +function TSimbaCompilerDump.addGlobalVar(AVar: TLapeGlobalVar; AName: lpString): TLapeGlobalVar; +begin + Result := inherited addGlobalVar(AVar, AName); + Result._DocPos.FileName := ImportingSection; +end; + procedure TSimbaCompilerDump.DumpToFile(FileName: String); var BaseType: ELapeBaseType; diff --git a/Source/script/simba.script_compiler.pas b/Source/script/simba.script_compiler.pas index 90fca8111..f9a814f50 100644 --- a/Source/script/simba.script_compiler.pas +++ b/Source/script/simba.script_compiler.pas @@ -36,8 +36,6 @@ TSimbaScript_Compiler = class(TLapeCompiler) procedure addDelayedCode(Code: TStringArray; AFileName: lpString = ''); virtual; overload; - function addGlobalVar(AVar: TLapeGlobalVar; AName: lpString = ''): TLapeGlobalVar; override; - function addGlobalFunc(Header: lpString; Body: TStringArray): TLapeTree_Method; virtual; overload; function addGlobalFunc(Header: lpString; Value: Pointer; ABI: TFFIABI): TLapeGlobalVar; virtual; overload; procedure addGlobalFuncOverride(Header: lpString; Body: TStringArray); virtual; @@ -236,11 +234,5 @@ procedure TSimbaScript_Compiler.addDelayedCode(Code: TStringArray; AFileName: lp addDelayedCode(LapeDelayedFlags + LineEnding.Join(Code), AFileName); end; -function TSimbaScript_Compiler.addGlobalVar(AVar: TLapeGlobalVar; AName: lpString): TLapeGlobalVar; -begin - Result := inherited; - Result._DocPos.FileName := ImportingSection; -end; - end. diff --git a/Source/script/simba.script_compiler_debugger.pas b/Source/script/simba.script_compiler_debugger.pas deleted file mode 100644 index 251f91747..000000000 --- a/Source/script/simba.script_compiler_debugger.pas +++ /dev/null @@ -1,107 +0,0 @@ -{ - Author: Raymond van Venetiƫ and Merlijn Wajer - Project: Simba (https://github.com/MerlijnWajer/Simba) - License: GNU General Public License (https://www.gnu.org/licenses/gpl-3.0) -} -unit simba.script_compiler_debugger; - -{$i simba.inc} - -interface - -uses - classes, sysutils, - lptypes, lpcompiler; - -type - PStringArray = ^TStringArray; - - TLapeEnterMethod = procedure(const Index: Integer) of object; - TLapeLeaveMethod = procedure(const Index: Integer; const Exception: Boolean) of object; - -procedure InitializeDebugger(Compiler: TLapeCompiler; Methods: PStringArray; OnEnterMethod: TLapeEnterMethod; OnLeaveMethod: TLapeLeaveMethod); - -implementation - -uses - lptree, lpvartypes, lpinternalmethods; - -procedure AddDebuggingMethods(Compiler: TLapeCompiler); -var - EnterMethod, LeaveMethod: TLapeTree_Invoke; - Statement: TLapeTree_Try; - IsException: TLapeTree_Operator; - I: Integer; - Name: String; - Method: TLapeTree_Method; - Methods: ^TStringArray; -begin - with Compiler do - begin - Methods := Globals['_DebuggingMethods'].Ptr; - - for I := 0 to DelayedTree.Statements.Count - 1 do - if DelayedTree.Statements[i] is TLapeTree_Method then - begin - Method := TLapeTree_Method(DelayedTree.Statements[I]); - - Name := UpperCase(Method.Method.Name); - if (Name = '') or (Method.DocPos.FileName.StartsWith('!') and Name.StartsWith('_')) then - Continue; - - if (Method.Method.VarType is TLapeType_MethodOfType) then - Name := UpperCase(TLapeType_MethodOfType(Method.Method.VarType).ObjectType.Name) + '.' + Name; - - IsException := TLapeTree_Operator.Create(op_cmp_NotEqual, Method); - IsException.Left := TLapeTree_InternalMethod_GetExceptionMessage.Create(Method); - IsException.Right := TLapeTree_String.Create('', IsException); - - EnterMethod := TLapeTree_Invoke.Create('_EnterMethod', Method); - EnterMethod.addParam(TLapeTree_Integer.Create(Length(Methods^), EnterMethod)); - - LeaveMethod := TLapeTree_Invoke.Create('_LeaveMethod', Method); - LeaveMethod.addParam(TLapeTree_Integer.Create(Length(Methods^), LeaveMethod)); - LeaveMethod.addParam(IsException); - - Method.Statements.addStatement(EnterMethod, True); - - Statement := TLapeTree_Try.Create(Method); - Statement.Body := Method.Statements; - Statement.FinallyBody := LeaveMethod; - - Method.Statements := TLapeTree_StatementList.Create(Method); - Method.Statements.addStatement(Statement); - - Methods^ += [Name]; - end; - end; -end; - -procedure Lape_EnterMethod(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} -begin - TLapeEnterMethod(PMethod(Params^[0])^)(PInteger(Params^[1])^); -end; - -procedure Lape_LeaveMethod(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} -begin - TLapeLeaveMethod(PMethod(Params^[0])^)(PInteger(Params^[1])^, PBoolean(Params^[2])^); -end; - -procedure InitializeDebugger(Compiler: TLapeCompiler; Methods: PStringArray; OnEnterMethod: TLapeEnterMethod; OnLeaveMethod: TLapeLeaveMethod); -var - EnterMethod, LeaveMethod: TLapeGlobalVar; -begin - EnterMethod := TLapeGlobalVar(Compiler.addManagedDecl(TLapeGlobalVar.Create(Compiler.getGlobalType('TMethod')))); - LeaveMethod := TLapeGlobalVar(Compiler.addManagedDecl(TLapeGlobalVar.Create(Compiler.getGlobalType('TMethod')))); - - PMethod(EnterMethod.Ptr)^ := TMethod(OnEnterMethod); - PMethod(LeaveMethod.Ptr)^ := TMethod(OnLeaveMethod); - - Compiler.AfterParsing.AddProc(@AddDebuggingMethods); - Compiler.addGlobalVar('array of String', Methods, '_DebuggingMethods'); - Compiler.addGlobalMethod('procedure _EnterMethod(const Index: Integer);', @Lape_EnterMethod, EnterMethod.Ptr); - Compiler.addGlobalMethod('procedure _LeaveMethod(const Index: Integer; Exception: Boolean);', @Lape_LeaveMethod, LeaveMethod.Ptr); -end; - -end. - diff --git a/Source/simba.finder.pas b/Source/simba.finder.pas index 461e01260..8f02f0f0e 100644 --- a/Source/simba.finder.pas +++ b/Source/simba.finder.pas @@ -61,9 +61,9 @@ TColorTolerance = record function GetColorsMatrix(Bounds: TBox): TIntegerMatrix; function GetPixelDifference(WaitTime: Integer; Area: TBox): Integer; overload; - function GetPixelDifference(WaitTime: Integer; Tolerance: Integer; Area: TBox): Integer; overload; + function GetPixelDifference(WaitTime: Integer; Tolerance: Single; Area: TBox): Integer; overload; function GetPixelDifferenceTPA(WaitTime: Integer; Area: TBox): TPointArray; overload; - function GetPixelDifferenceTPA(WaitTime: Integer; Tolerance: Integer; Area: TBox): TPointArray; overload; + function GetPixelDifferenceTPA(WaitTime: Integer; Tolerance: Single; Area: TBox): TPointArray; overload; function AverageBrightness(Area: TBox): Integer; function PeakBrightness(Area: TBox): Integer; @@ -294,7 +294,7 @@ function TSimbaFinder.GetPixelDifference(WaitTime: Integer; Area: TBox): Integer end; end; -function TSimbaFinder.GetPixelDifference(WaitTime: Integer; Tolerance: Integer; Area: TBox): Integer; +function TSimbaFinder.GetPixelDifference(WaitTime: Integer; Tolerance: Single; Area: TBox): Integer; var BitmapBefore, BitmapAfter: TSimbaImage; begin @@ -338,7 +338,7 @@ function TSimbaFinder.GetPixelDifferenceTPA(WaitTime: Integer; Area: TBox): TPoi end; end; -function TSimbaFinder.GetPixelDifferenceTPA(WaitTime: Integer; Tolerance: Integer; Area: TBox): TPointArray; +function TSimbaFinder.GetPixelDifferenceTPA(WaitTime: Integer; Tolerance: Single; Area: TBox): TPointArray; var BitmapBefore, BitmapAfter: TSimbaImage; begin