mirror of
https://github.com/moparisthebest/Simba
synced 2024-08-13 16:53:59 -04:00
Added {$H+} to units where it was missing.. Should solve some string-issues! Started with cleaning up the units a bit.. Adding 'const' where needed (all of those big record structures like DTMs should require to be passed as a const.. Saves some (unneeded) memory copying).
Settings in extensions should work now, see test extension.
This commit is contained in:
parent
e413c07d61
commit
61f3c1ce98
@ -1,6 +1,6 @@
|
|||||||
unit extensionmanager;
|
unit extensionmanager;
|
||||||
|
|
||||||
{$mode objfpc}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
unit extensionmanagergui;
|
unit extensionmanagergui;
|
||||||
|
|
||||||
{$mode objfpc}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
unit psextension;
|
unit psextension;
|
||||||
|
|
||||||
{$mode objfpc}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ uses
|
|||||||
uPSC_extctrls,uPSC_menus, //Compile libs
|
uPSC_extctrls,uPSC_menus, //Compile libs
|
||||||
uPSR_std, uPSR_controls,uPSR_classes,uPSR_graphics,uPSR_stdctrls,uPSR_forms,
|
uPSR_std, uPSR_controls,uPSR_classes,uPSR_graphics,uPSR_stdctrls,uPSR_forms,
|
||||||
uPSR_extctrls,uPSR_menus, //Runtime-libs
|
uPSR_extctrls,uPSR_menus, //Runtime-libs
|
||||||
testunit,updateform,settingssandbox//Writeln
|
testunit,updateform,settingssandbox,bitmaps//Writeln
|
||||||
;
|
;
|
||||||
|
|
||||||
function TSimbaPSExtension.HookExists(HookName: String): Boolean;
|
function TSimbaPSExtension.HookExists(HookName: String): Boolean;
|
||||||
@ -158,14 +158,14 @@ procedure TSimbaPSExtension.SIRegister_Settings(Cl: TPSPascalCompiler);
|
|||||||
begin
|
begin
|
||||||
with cl.AddClassN(nil,'TMMLSettingsSandbox') do
|
with cl.AddClassN(nil,'TMMLSettingsSandbox') do
|
||||||
begin;
|
begin;
|
||||||
RegisterMethod('function IsKey(KeyName: String): Boolean;');
|
RegisterMethod('function IsKey(const KeyName: String): Boolean;');
|
||||||
RegisterMethod('function IsDirectory(KeyName: String): Boolean;');
|
RegisterMethod('function IsDirectory(const KeyName: String): Boolean;');
|
||||||
RegisterMethod('function SetKeyValue(Keyname : string; Value : string) : boolean;');
|
RegisterMethod('function SetKeyValue(const Keyname, Value : string) : boolean;');
|
||||||
RegisterMethod('function GetKeyValue(KeyName: String): String;');
|
RegisterMethod('function GetKeyValue(const KeyName: String): String;');
|
||||||
RegisterMethod('function GetKeyValueDef(KeyName, defVal: String): String;');
|
RegisterMethod('function GetKeyValueDef(const KeyName, defVal: String): String;');
|
||||||
RegisterMethod('function ListKeys(KeyName: String): TStringArray;');
|
RegisterMethod('function ListKeys(const KeyName: String; out Keys :TStringArray): boolean;');
|
||||||
RegisterMethod('function DeleteKey(KeyName: String): Boolean;');
|
RegisterMethod('function DeleteKey(const KeyName: String): Boolean;');
|
||||||
RegisterMethod('function DeleteSubKeys(KeyName: String): Boolean;');
|
RegisterMethod('function DeleteSubKeys(const KeyName: String): Boolean;');
|
||||||
RegisterProperty('Prefix','String',iptR);
|
RegisterProperty('Prefix','String',iptR);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
unit simbasettings;
|
unit simbasettings;
|
||||||
|
|
||||||
{$mode objfpc} {$M+}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
unit virtualextension;
|
unit virtualextension;
|
||||||
|
|
||||||
{$mode objfpc}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
|
@ -21,6 +21,14 @@
|
|||||||
Settings.inc for the Mufasa Macro Library
|
Settings.inc for the Mufasa Macro Library
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function SetSettingValue(KeyName,value : string) : boolean;
|
||||||
|
begin
|
||||||
|
if CurrThread.Sett <> nil then
|
||||||
|
result:= CurrThread.Sett.SetKeyValue(KeyName,Value)
|
||||||
|
else
|
||||||
|
result:=false;
|
||||||
|
end;
|
||||||
|
|
||||||
function KeyIsSetting(KeyName: String): Boolean;
|
function KeyIsSetting(KeyName: String): Boolean;
|
||||||
begin
|
begin
|
||||||
if CurrThread.Sett <> nil then
|
if CurrThread.Sett <> nil then
|
||||||
|
@ -371,6 +371,7 @@ AddFunction(@KeyIsSetting, 'function KeyIsSetting(KeyName: String): Boolean;');
|
|||||||
AddFunction(@KeyIsDirectory, 'function KeyIsDirectory(KeyName: String): Boolean;');
|
AddFunction(@KeyIsDirectory, 'function KeyIsDirectory(KeyName: String): Boolean;');
|
||||||
AddFunction(@GetSettingValue, 'function GetSettingValue(KeyName: String): String;');
|
AddFunction(@GetSettingValue, 'function GetSettingValue(KeyName: String): String;');
|
||||||
AddFunction(@GetSettingValueDef, 'function GetSettingValueDef(KeyName, defVal: String): String;');
|
AddFunction(@GetSettingValueDef, 'function GetSettingValueDef(KeyName, defVal: String): String;');
|
||||||
|
AddFunction(@SetSettingValue,'function SetSettingValue(KeyName,value : string) : boolean;');
|
||||||
AddFunction(@ListSettings, 'function ListSettings(KeyName: String; var KeyReturn: TStringArray) : boolean;');
|
AddFunction(@ListSettings, 'function ListSettings(KeyName: String; var KeyReturn: TStringArray) : boolean;');
|
||||||
AddFunction(@DeleteSetting, 'function DeleteSetting(KeyName: String): Boolean;');
|
AddFunction(@DeleteSetting, 'function DeleteSetting(KeyName: String): Boolean;');
|
||||||
AddFunction(@DeleteSubSettings, 'function DeleteSubSettings(KeyName: String): Boolean;');
|
AddFunction(@DeleteSubSettings, 'function DeleteSubSettings(KeyName: String): Boolean;');
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
unit mmisc;
|
unit mmisc;
|
||||||
|
|
||||||
{$mode objfpc}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
unit scriptproperties;
|
unit scriptproperties;
|
||||||
|
|
||||||
{$mode objfpc}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
}
|
}
|
||||||
unit settingssandbox;
|
unit settingssandbox;
|
||||||
|
|
||||||
{$mode objfpc}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
@ -42,15 +42,14 @@ type
|
|||||||
public
|
public
|
||||||
constructor Create(sett: TMMLSettings);
|
constructor Create(sett: TMMLSettings);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
function IsKey(const KeyName: String): Boolean;
|
||||||
function IsKey(KeyName: String): Boolean;
|
function IsDirectory(const KeyName: String): Boolean;
|
||||||
function IsDirectory(KeyName: String): Boolean;
|
function SetKeyValue(const Keyname, Value : string) : boolean;
|
||||||
function SetKeyValue(Keyname : string; Value : string) : boolean;
|
function GetKeyValue(const KeyName: String): String;
|
||||||
function GetKeyValue(KeyName: String): String;
|
function GetKeyValueDef(const KeyName, defVal: String): String;
|
||||||
function GetKeyValueDef(KeyName, defVal: String): String;
|
function ListKeys(const KeyName: String; out Keys : TStringArray): boolean;
|
||||||
function ListKeys(KeyName: String; out Keys : TStringArray): boolean;
|
function DeleteKey(const KeyName: String): Boolean;
|
||||||
function DeleteKey(KeyName: String): Boolean;
|
function DeleteSubKeys(const KeyName: String): Boolean;
|
||||||
function DeleteSubKeys(KeyName: String): Boolean;
|
|
||||||
property prefix : string read GetPrefix write SetPrefix;
|
property prefix : string read GetPrefix write SetPrefix;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -80,45 +79,43 @@ begin
|
|||||||
FPrefix := s;
|
FPrefix := s;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMMLSettingsSandbox.ListKeys(KeyName: String; out Keys :TStringArray): boolean;
|
function TMMLSettingsSandbox.ListKeys(const KeyName: String; out Keys :TStringArray): boolean;
|
||||||
begin
|
begin
|
||||||
exit(ST.ListKeys(Prefix + KeyName,keys))
|
exit(ST.ListKeys(Prefix + KeyName,keys))
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMMLSettingsSandbox.GetKeyValue(KeyName: String): String;
|
function TMMLSettingsSandbox.GetKeyValue(const KeyName: String): String;
|
||||||
begin
|
begin
|
||||||
exit(ST.GetKeyValue(Prefix + KeyName))
|
exit(ST.GetKeyValue(Prefix + KeyName))
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMMLSettingsSandbox.GetKeyValueDef(KeyName, defVal: String): String;
|
function TMMLSettingsSandbox.GetKeyValueDef(const KeyName, defVal: String): String;
|
||||||
begin
|
begin
|
||||||
exit(ST.GetKeyValueDef(Prefix + KeyName, defVal))
|
exit(ST.GetKeyValueDef(Prefix + KeyName, defVal))
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMMLSettingsSandbox.IsKey(KeyName: String): Boolean;
|
function TMMLSettingsSandbox.IsKey(const KeyName: String): Boolean;
|
||||||
begin
|
begin
|
||||||
exit(ST.IsKey(Prefix + KeyName))
|
exit(ST.IsKey(Prefix + KeyName))
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMMLSettingsSandbox.IsDirectory(KeyName: String): Boolean;
|
function TMMLSettingsSandbox.IsDirectory(const KeyName: String): Boolean;
|
||||||
begin
|
begin
|
||||||
exit(ST.IsDirectory(Prefix + KeyName))
|
exit(ST.IsDirectory(Prefix + KeyName))
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMMLSettingsSandbox.SetKeyValue(Keyname: string; Value: string
|
function TMMLSettingsSandbox.SetKeyValue(const Keyname,Value: string
|
||||||
): boolean;
|
): boolean;
|
||||||
begin
|
begin
|
||||||
Writeln(KeyName);
|
|
||||||
Writeln(Value);
|
|
||||||
exit(ST.SetKeyValue(prefix + keyname,value,true));
|
exit(ST.SetKeyValue(prefix + keyname,value,true));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMMLSettingsSandbox.DeleteKey(KeyName: String): Boolean;
|
function TMMLSettingsSandbox.DeleteKey(const KeyName: String): Boolean;
|
||||||
begin
|
begin
|
||||||
exit(ST.DeleteKey(Prefix + KeyName));
|
exit(ST.DeleteKey(Prefix + KeyName));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMMLSettingsSandbox.DeleteSubKeys(KeyName: String): Boolean;
|
function TMMLSettingsSandbox.DeleteSubKeys(const KeyName: String): Boolean;
|
||||||
begin
|
begin
|
||||||
exit(ST.DeleteSubKeys(Prefix + KeyName));
|
exit(ST.DeleteSubKeys(Prefix + KeyName));
|
||||||
end;
|
end;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
unit stringutil;
|
unit stringutil;
|
||||||
|
|
||||||
{$mode objfpc}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
|
@ -60,14 +60,10 @@ implementation
|
|||||||
|
|
||||||
procedure TClient.WriteLn(s: string);
|
procedure TClient.WriteLn(s: string);
|
||||||
begin
|
begin
|
||||||
if self <> nil then
|
if (self <> nil) and Assigned(WritelnProc) then
|
||||||
begin;
|
|
||||||
if Assigned(WritelnProc) then
|
|
||||||
WritelnProc(s)
|
WritelnProc(s)
|
||||||
else
|
else
|
||||||
mDebugLn(s);
|
mDebugLn(s);
|
||||||
end else
|
|
||||||
mDebugLn(s);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Possibly pass arguments to a default window.
|
// Possibly pass arguments to a default window.
|
||||||
|
@ -32,46 +32,19 @@ uses
|
|||||||
|
|
||||||
type
|
type
|
||||||
TMDTM = class(TObject)
|
TMDTM = class(TObject)
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
|
|
||||||
public
|
|
||||||
function AddDTM(d: TDTM): Integer;
|
|
||||||
function AddpDTM(d: pDTM): Integer;
|
|
||||||
function GetDTM(index: Integer; out dtm: pDTM): Boolean;
|
|
||||||
procedure FreeDTM(DTM: Integer);
|
|
||||||
function StringToDTM(S: String): pDTM;
|
|
||||||
function SetDTMName(DTM: Integer; S: String): boolean;
|
|
||||||
|
|
||||||
|
|
||||||
{ function FindDTM(DTM: Integer; out x, y: Integer; x1, y1, x2,
|
|
||||||
y2: Integer): Boolean;
|
|
||||||
function FindDTMs(DTM: Integer; out Points: TPointArray; x1, y1, x2,
|
|
||||||
y2: Integer): Boolean;
|
|
||||||
function FindDTMRotated(DTM: Integer; out x, y: Integer; x1, y1, x2,
|
|
||||||
y2: Integer; sAngle, eAngle, aStep: Extended;
|
|
||||||
out aFound: Extended): Boolean;
|
|
||||||
function FindDTMsRotated(DTM: Integer; out Points: TPointArray; x1,
|
|
||||||
y1, x2, y2: Integer; sAngle, eAngle,
|
|
||||||
aStep: Extended; out aFound: T2DExtendedArray)
|
|
||||||
: Boolean;
|
|
||||||
function pFindDTM(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2:
|
|
||||||
Integer): Boolean;
|
|
||||||
function pFindDTMRotated(DTM: pDTM; out x, y: Integer; x1, y1, x2,
|
|
||||||
y2: Integer; sAngle, eAngle, aStep: Extended;
|
|
||||||
out aFound: Extended): Boolean;
|
|
||||||
function pFindDTMsRotated(DTM: pDTM; out Points: TPointArray; x1,
|
|
||||||
y1, x2, y2: Integer; sAngle, eAngle,
|
|
||||||
aStep: Extended; out aFound: T2DExtendedArray)
|
|
||||||
: Boolean;
|
|
||||||
}
|
|
||||||
constructor Create(Owner: TObject);
|
|
||||||
destructor Destroy; override;
|
|
||||||
private
|
private
|
||||||
Client: TObject;
|
Client: TObject;
|
||||||
DTMList: Array Of pDTM;
|
DTMList: Array Of pDTM;
|
||||||
FreeSpots: Array Of Integer;
|
FreeSpots: Array Of Integer;
|
||||||
|
public
|
||||||
|
function AddDTM(const d: TDTM): Integer;
|
||||||
|
function AddpDTM(const d: pDTM): Integer;
|
||||||
|
function GetDTM(index: Integer; out dtm: pDTM): Boolean;
|
||||||
|
procedure FreeDTM(DTM: Integer);
|
||||||
|
function StringToDTM(const S: String): pDTM;
|
||||||
|
function SetDTMName(DTM: Integer;const S: String): boolean;
|
||||||
|
constructor Create(Owner: TObject);
|
||||||
|
destructor Destroy; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -125,27 +98,20 @@ begin
|
|||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{Function AreaShape(Color, Tolerance, Size, Shape: Integer; P: TPoint) : Boolean; inline;
|
|
||||||
|
|
||||||
Begin
|
|
||||||
|
|
||||||
End;}
|
|
||||||
|
|
||||||
// Rotates the given point (p) by A (in radians) around the point defined by cx, cy.
|
// Rotates the given point (p) by A (in radians) around the point defined by cx, cy.
|
||||||
|
|
||||||
function RotatePoint(p: TPoint; angle, mx, my: Extended): TPoint; inline;
|
function RotatePoint(const p: TPoint;const angle, mx, my: Extended): TPoint; inline;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result.X := Round(mx + cos(angle) * (p.x - mx) - sin(angle) * (p.y - my));
|
Result.X := Round(mx + cos(angle) * (p.x - mx) - sin(angle) * (p.y - my));
|
||||||
Result.Y := Round(my + sin(angle) * (p.x - mx) + cos(angle) * (p.y- my));
|
Result.Y := Round(my + sin(angle) * (p.x - mx) + cos(angle) * (p.y- my));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function HexToInt(HexNum: string): LongInt;inline;
|
function HexToInt(const HexNum: string): LongInt;inline;
|
||||||
begin
|
begin
|
||||||
Result:=StrToInt('$' + HexNum);
|
Result:=StrToInt('$' + HexNum);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMDTM.StringToDTM(S: String): pDTM;
|
function TMDTM.StringToDTM(const S: String): pDTM;
|
||||||
var
|
var
|
||||||
b: PBufferByteArray;
|
b: PBufferByteArray;
|
||||||
Source : String;
|
Source : String;
|
||||||
@ -192,7 +158,7 @@ begin
|
|||||||
result.l := length(result.p);
|
result.l := length(result.p);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMDTM.AddDTM(d: TDTM): Integer;
|
function TMDTM.AddDTM(const d: TDTM): Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if Length(FreeSpots) > 0 then
|
if Length(FreeSpots) > 0 then
|
||||||
@ -213,7 +179,7 @@ end;
|
|||||||
Adds the given pDTM to the DTM Array, and returns it's index.
|
Adds the given pDTM to the DTM Array, and returns it's index.
|
||||||
/\}
|
/\}
|
||||||
|
|
||||||
function TMDTM.AddpDTM(d: pDTM): Integer;
|
function TMDTM.AddpDTM(const d: pDTM): Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if Length(FreeSpots) > 0 then
|
if Length(FreeSpots) > 0 then
|
||||||
@ -250,7 +216,7 @@ begin
|
|||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMDTM.SetDTMName(DTM: Integer; s: string): boolean;
|
function TMDTM.SetDTMName(DTM: Integer;const s: string): boolean;
|
||||||
begin
|
begin
|
||||||
try
|
try
|
||||||
DTMList[DTM].n:= s;
|
DTMList[DTM].n:= s;
|
||||||
@ -284,62 +250,6 @@ begin
|
|||||||
FreeSpots[High(FreeSpots)] := DTM;
|
FreeSpots[High(FreeSpots)] := DTM;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
Tries to find the given DTM (index). If found will put the point the dtm has
|
|
||||||
been found at in x, y and result to true.
|
|
||||||
}
|
|
||||||
{function TMDTM.FindDTM(DTM: Integer; out x, y: Integer; x1, y1, x2, y2: Integer): Boolean;
|
|
||||||
var
|
|
||||||
temp: pDTM;
|
|
||||||
begin
|
|
||||||
if GetDTM(DTM, temp) then
|
|
||||||
Result := pFindDTM(temp, x, y, x1, y1, x2, y2)
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
x := 0;
|
|
||||||
y := 0;
|
|
||||||
Result := False;
|
|
||||||
end;
|
|
||||||
end; }
|
|
||||||
|
|
||||||
{
|
|
||||||
Tries to find the given pDTM. If found will put the point the dtm has
|
|
||||||
been found at in x, y and result to true.
|
|
||||||
}
|
|
||||||
|
|
||||||
{function TMDTM.pFindDTM(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer): Boolean;
|
|
||||||
|
|
||||||
|
|
||||||
begin
|
|
||||||
|
|
||||||
end; }
|
|
||||||
|
|
||||||
{/\
|
|
||||||
Tries to find the given DTM (index). Will return true if it has found one or more
|
|
||||||
DTM's. All the occurances are stored in the Points (TPointArray)
|
|
||||||
/\}
|
|
||||||
|
|
||||||
{function TMDTM.FindDTMs(DTM: Integer; out Points: TPointArray; x1, y1, x2, y2: Integer): Boolean;
|
|
||||||
Var
|
|
||||||
temp: pDTM;
|
|
||||||
Begin
|
|
||||||
If GetDTM(DTM, temp) Then
|
|
||||||
Result := pFindDTMs(temp, Points, x1, y1, x2, y2)
|
|
||||||
Else
|
|
||||||
Begin
|
|
||||||
SetLength(Points, 0);
|
|
||||||
Result := False;
|
|
||||||
End;
|
|
||||||
End; }
|
|
||||||
|
|
||||||
{/\
|
|
||||||
Tries to find the given pDTM. Will return true if it has found one or more
|
|
||||||
DTM's. All the occurances are stored in the Points (TPointArray)
|
|
||||||
/\}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{wat}
|
{wat}
|
||||||
// Then, first find all occurances of all colours on the given client.
|
// Then, first find all occurances of all colours on the given client.
|
||||||
// Each point has a colour, and we call them C_0...C_n.
|
// Each point has a colour, and we call them C_0...C_n.
|
||||||
@ -427,12 +337,5 @@ End; }
|
|||||||
Returns all Angles in a Two Dimensional Extended array.
|
Returns all Angles in a Two Dimensional Extended array.
|
||||||
/\}
|
/\}
|
||||||
|
|
||||||
{Function TMDTM.pFindDTMsRotated(DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray): Boolean;
|
|
||||||
|
|
||||||
Begin
|
|
||||||
// Don't forget to pre calculate the rotated points at the start.
|
|
||||||
// Saves a lot of rotatepoint() calls.
|
|
||||||
End; }
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -33,13 +33,13 @@ uses
|
|||||||
|
|
||||||
Function pDTMToTDTM(Const DTM: pDTM): TDTM;
|
Function pDTMToTDTM(Const DTM: pDTM): TDTM;
|
||||||
Function tDTMTopDTM(Const DTM: TDTM): pDTM;
|
Function tDTMTopDTM(Const DTM: TDTM): pDTM;
|
||||||
Procedure PrintpDTM(aDTM : pDTM);
|
Procedure PrintpDTM(const aDTM : pDTM);
|
||||||
|
|
||||||
procedure initdtm(out d: pdtm; len: integer);
|
procedure initdtm(out d: pdtm; len: integer);
|
||||||
function ValidMainPointBox(var dtm: pDTM; const x1, y1, x2, y2: Integer): TBox;
|
function ValidMainPointBox(var dtm: pDTM; const x1, y1, x2, y2: Integer): TBox;
|
||||||
Function ValidMainPointBoxRotated(var dtm: pDTM; const x1, y1, x2, y2: Integer;
|
Function ValidMainPointBoxRotated(var dtm: pDTM; const x1, y1, x2, y2: Integer;const
|
||||||
sAngle, eAngle, aStep: Extended): TBox;
|
sAngle, eAngle, aStep: Extended): TBox;
|
||||||
function DTMConsistent(var dtm: pdtm): boolean;
|
function DTMConsistent(const dtm: pdtm): boolean;
|
||||||
procedure NormalizeDTM(var dtm: pdtm);
|
procedure NormalizeDTM(var dtm: pdtm);
|
||||||
function RotateDTM(const dtm: pdtm; angle: extended) : pdtm;
|
function RotateDTM(const dtm: pdtm; angle: extended) : pdtm;
|
||||||
function copydtm(const dtm: pdtm): pdtm;
|
function copydtm(const dtm: pdtm): pdtm;
|
||||||
@ -99,7 +99,7 @@ begin
|
|||||||
d.bp[i] := False;
|
d.bp[i] := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Procedure PrintpDTM(aDTM : pDTM);
|
Procedure PrintpDTM(const aDTM : pDTM);
|
||||||
var
|
var
|
||||||
i : integer;
|
i : integer;
|
||||||
begin;
|
begin;
|
||||||
@ -185,7 +185,7 @@ Begin
|
|||||||
End;
|
End;
|
||||||
|
|
||||||
{ TODO: Check if bounds are correct? }
|
{ TODO: Check if bounds are correct? }
|
||||||
function DTMConsistent(var dtm: pdtm): boolean;
|
function DTMConsistent(const dtm: pdtm): boolean;
|
||||||
var
|
var
|
||||||
i: integer;
|
i: integer;
|
||||||
begin
|
begin
|
||||||
@ -257,7 +257,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
Function ValidMainPointBoxRotated(var dtm: pDTM; const x1, y1, x2, y2: Integer;
|
Function ValidMainPointBoxRotated(var dtm: pDTM; const x1, y1, x2, y2: Integer;
|
||||||
sAngle, eAngle, aStep: Extended): TBox;
|
const sAngle, eAngle, aStep: Extended): TBox;
|
||||||
|
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
@ -30,7 +30,7 @@ interface
|
|||||||
|
|
||||||
{$define CheckAllBackground}//Undefine this to only check the first white point against the background (in masks).
|
{$define CheckAllBackground}//Undefine this to only check the first white point against the background (in masks).
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils,bitmaps,MufasaBase, MufasaTypes; // Types
|
colour_conv, Classes, SysUtils,bitmaps,MufasaBase, MufasaTypes; // Types
|
||||||
|
|
||||||
{ TMFinder Class }
|
{ TMFinder Class }
|
||||||
|
|
||||||
@ -43,20 +43,22 @@ uses
|
|||||||
|
|
||||||
type
|
type
|
||||||
TMFinder = class(TObject)
|
TMFinder = class(TObject)
|
||||||
constructor Create(aClient: TObject);
|
|
||||||
destructor Destroy; override;
|
|
||||||
private
|
private
|
||||||
|
Client: TObject;
|
||||||
|
Percentage : array[0..255] of Extended; //We store all the possible RGB / 255 divisions.
|
||||||
|
CachedWidth, CachedHeight : integer;
|
||||||
|
ClientTPA : TPointArray;
|
||||||
|
hueMod, satMod: Extended;
|
||||||
|
CTS: Integer;
|
||||||
|
|
||||||
Procedure UpdateCachedValues(NewWidth,NewHeight : integer);
|
Procedure UpdateCachedValues(NewWidth,NewHeight : integer);
|
||||||
procedure DefaultOperations(var xs,ys,xe,ye : integer);
|
procedure DefaultOperations(var xs,ys,xe,ye : integer);
|
||||||
//Loads the Spiral into ClientTPA (Will not cause problems)
|
//Loads the Spiral into ClientTPA (Will not cause problems)
|
||||||
procedure LoadSpiralPath(startX, startY, x1, y1, x2, y2: Integer);
|
procedure LoadSpiralPath(startX, startY, x1, y1, x2, y2: Integer);
|
||||||
public
|
public
|
||||||
function FindColorsToleranceOptimised(out Points: TPointArray; Color,
|
WarnOnly : boolean;
|
||||||
xs, ys, xe, ye, Tol: Integer): Boolean;
|
function FindColorsToleranceOptimised(out Points: TPointArray; Color,xs, ys, xe, ye, Tol: Integer): Boolean;
|
||||||
function FindColorToleranceOptimised(out x, y: Integer; Color, xs, ys,
|
function FindColorToleranceOptimised(out x, y: Integer; Color, xs, ys,xe, ye, tol: Integer): Boolean;
|
||||||
xe, ye, tol: Integer): Boolean;
|
|
||||||
function CountColorTolerance(Color, xs, ys, xe, ye, Tolerance: Integer): Integer;
|
function CountColorTolerance(Color, xs, ys, xe, ye, Tolerance: Integer): Integer;
|
||||||
function CountColor(Color, xs, ys, xe, ye: Integer): Integer;
|
function CountColor(Color, xs, ys, xe, ye: Integer): Integer;
|
||||||
function SimilarColors(Color1,Color2,Tolerance : Integer) : boolean;
|
function SimilarColors(Color1,Color2,Tolerance : Integer) : boolean;
|
||||||
@ -71,8 +73,8 @@ type
|
|||||||
function FindColoredArea(var x, y: Integer; color, xs, ys, xe, ye: Integer; MinArea: Integer): Boolean;
|
function FindColoredArea(var x, y: Integer; color, xs, ys, xe, ye: Integer; MinArea: Integer): Boolean;
|
||||||
function FindColoredAreaTolerance(var x, y: Integer; color, xs, ys, xe, ye: Integer; MinArea, tol: Integer): Boolean;
|
function FindColoredAreaTolerance(var x, y: Integer; color, xs, ys, xe, ye: Integer; MinArea, tol: Integer): Boolean;
|
||||||
//Mask
|
//Mask
|
||||||
function FindMaskTolerance(mask: TMask; out x, y: Integer; xs, ys, xe, ye: Integer; Tolerance, ContourTolerance: Integer): Boolean;
|
function FindMaskTolerance(const mask: TMask; out x, y: Integer; xs, ys, xe, ye: Integer; Tolerance, ContourTolerance: Integer): Boolean;
|
||||||
procedure CheckMask(Mask : TMask);
|
procedure CheckMask(const Mask : TMask);
|
||||||
//Bitmap functions
|
//Bitmap functions
|
||||||
function FindBitmap(bitmap: TMufasaBitmap; out x, y: Integer): Boolean;
|
function FindBitmap(bitmap: TMufasaBitmap; out x, y: Integer): Boolean;
|
||||||
function FindBitmapIn(bitmap: TMufasaBitmap; out x, y: Integer; xs, ys, xe, ye: Integer): Boolean;
|
function FindBitmapIn(bitmap: TMufasaBitmap; out x, y: Integer; xs, ys, xe, ye: Integer): Boolean;
|
||||||
@ -82,29 +84,24 @@ type
|
|||||||
function FindBitmapsSpiralTolerance(bitmap: TMufasaBitmap; x, y: Integer; out Points : TPointArray; xs, ys, xe, ye,tolerance: Integer): Boolean;
|
function FindBitmapsSpiralTolerance(bitmap: TMufasaBitmap; x, y: Integer; out Points : TPointArray; xs, ys, xe, ye,tolerance: Integer): Boolean;
|
||||||
function FindDeformedBitmapToleranceIn(bitmap: TMufasaBitmap; out x, y: Integer; xs, ys, xe, ye: Integer; tolerance: Integer; Range: Integer; AllowPartialAccuracy: Boolean; out accuracy: Extended): Boolean;
|
function FindDeformedBitmapToleranceIn(bitmap: TMufasaBitmap; out x, y: Integer; xs, ys, xe, ye: Integer; tolerance: Integer; Range: Integer; AllowPartialAccuracy: Boolean; out accuracy: Extended): Boolean;
|
||||||
|
|
||||||
function FindDTM(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer): Boolean;
|
function FindDTM(const DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer): Boolean;
|
||||||
function FindDTMs(DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2, maxToFind: Integer): Boolean;
|
function FindDTMs(DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2, maxToFind: Integer): Boolean;
|
||||||
function FindDTMRotated(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: Extended; Alternating : boolean): Boolean;
|
function FindDTMRotated(const DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: Extended; Alternating : boolean): Boolean;
|
||||||
function FindDTMsRotated(_DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray; maxToFind: Integer; Alternating : boolean): Boolean;
|
function FindDTMsRotated(DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray; maxToFind: Integer; Alternating : boolean): Boolean;
|
||||||
//Donno
|
//Donno
|
||||||
function GetColors(Coords: TPointArray): TIntegerArray;
|
function GetColors(const Coords: TPointArray): TIntegerArray;
|
||||||
// tol speeds
|
// tol speeds
|
||||||
procedure SetToleranceSpeed(nCTS: Integer);
|
procedure SetToleranceSpeed(nCTS: Integer);
|
||||||
function GetToleranceSpeed: Integer;
|
function GetToleranceSpeed: Integer;
|
||||||
procedure SetToleranceSpeed2Modifiers(nHue, nSat: Extended);
|
procedure SetToleranceSpeed2Modifiers(const nHue, nSat: Extended);
|
||||||
procedure GetToleranceSpeed2Modifiers(out hMod, sMod: Extended);
|
procedure GetToleranceSpeed2Modifiers(out hMod, sMod: Extended);
|
||||||
protected
|
constructor Create(aClient: TObject);
|
||||||
Client: TObject;
|
destructor Destroy; override;
|
||||||
Percentage : array[0..255] of Extended; //We store all the possible RGB / 255 divisions.
|
|
||||||
CachedWidth, CachedHeight : integer;
|
|
||||||
ClientTPA : TPointArray;
|
|
||||||
hueMod, satMod: Extended;
|
|
||||||
CTS: Integer;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
uses
|
uses
|
||||||
colour_conv,// For RGBToColor, etc.
|
// colour_conv,// For RGBToColor, etc.
|
||||||
Client, // For the Client Casts.
|
Client, // For the Client Casts.
|
||||||
math, //min/max
|
math, //min/max
|
||||||
tpa, //TPABounds
|
tpa, //TPABounds
|
||||||
@ -254,6 +251,7 @@ var
|
|||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
|
|
||||||
|
WarnOnly := False;
|
||||||
Self.Client := aClient;
|
Self.Client := aClient;
|
||||||
Self.CTS := 1;
|
Self.CTS := 1;
|
||||||
Self.hueMod := 0.2;
|
Self.hueMod := 0.2;
|
||||||
@ -281,7 +279,7 @@ begin
|
|||||||
Result := Self.CTS;
|
Result := Self.CTS;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMFinder.SetToleranceSpeed2Modifiers(nHue, nSat: Extended);
|
procedure TMFinder.SetToleranceSpeed2Modifiers(const nHue, nSat: Extended);
|
||||||
begin
|
begin
|
||||||
Self.hueMod := nHue;
|
Self.hueMod := nHue;
|
||||||
Self.satMod := nSat;
|
Self.satMod := nSat;
|
||||||
@ -338,34 +336,64 @@ begin
|
|||||||
SetLength(ClientTPA,NewWidth * NewHeight);
|
SetLength(ClientTPA,NewWidth * NewHeight);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure Swap(var A,B : integer);
|
||||||
|
var
|
||||||
|
c : integer;
|
||||||
|
begin
|
||||||
|
c := a;
|
||||||
|
a := b;
|
||||||
|
b := c;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TMFinder.DefaultOperations(var xs, ys, xe, ye: integer);
|
procedure TMFinder.DefaultOperations(var xs, ys, xe, ye: integer);
|
||||||
var
|
var
|
||||||
w,h : integer;
|
w,h : integer;
|
||||||
begin
|
begin
|
||||||
if xs > xe then
|
if (xs > xe) then
|
||||||
raise Exception.CreateFMT('Finder function: Xs > xe (%d,%d)',[xs,xe]);
|
if WarnOnly then
|
||||||
|
begin
|
||||||
|
TClient(Client).WriteLn(Format('Warning! You passed wrong values to a finder function: xs > xe (%d,%d). Swapping the values for now.',[xs,xe]));
|
||||||
|
swap(xs,xe);
|
||||||
|
end else
|
||||||
|
raise Exception.CreateFMT('You passed wrong values to a finder function: xs > xe (%d,%d).',[xs,xe]);
|
||||||
if ys > ye then
|
if ys > ye then
|
||||||
raise Exception.CreateFMT('Finder function: Ys > ye (%d,%d)',[ys,ye]);
|
if WarnOnly then
|
||||||
|
begin
|
||||||
|
TClient(Client).WriteLn(Format('Warning! You passed wrong values to a finder function: ys > ye (%d,%d). Swapping the values for now.',[ys,ye]));
|
||||||
|
swap(ys,ye);
|
||||||
|
end else
|
||||||
|
raise Exception.CreateFMT('You passed wrong values to a finder function: ys > ye (%d,%d).',[ys,ye]);
|
||||||
if xs < 0 then
|
if xs < 0 then
|
||||||
// xs := 0;
|
if WarnOnly then
|
||||||
raise Exception.createFMT('Any Find Function, you did not pass a ' +
|
begin
|
||||||
'correct xs: %d.', [xs]);
|
TClient(Client).WriteLn(Format('Warning! You passed a wrong xs to a finder function: %d. That is below 0, thus out of bounds. Setting the value to 0 for now.',[xs]));
|
||||||
|
xs := 0;
|
||||||
|
end else
|
||||||
|
raise Exception.createFMT('You passed a wrong xs to a finder function: %d. That is below 0, thus out of bounds.',[xs]);
|
||||||
if ys < 0 then
|
if ys < 0 then
|
||||||
// ys := 0;
|
if WarnOnly then
|
||||||
raise Exception.createFMT('Any Find Function, you did not pass a ' +
|
begin
|
||||||
'correct ys: %d.', [ys]);
|
TClient(Client).WriteLn(Format('Warning! You passed a wrong ys to a finder function: %d. That is below 0, thus out of bounds. Setting the value to 0 for now.',[ys]));
|
||||||
|
ys := 0;
|
||||||
|
end else
|
||||||
|
raise Exception.createFMT('You passed a wrong ys to a finder function: %d. That is below 0, thus out of bounds.',[ys]);
|
||||||
TClient(Self.Client).IOManager.GetDimensions(w,h);
|
TClient(Self.Client).IOManager.GetDimensions(w,h);
|
||||||
if (w <> CachedWidth) or (h <> CachedHeight) then
|
if (w <> CachedWidth) or (h <> CachedHeight) then
|
||||||
UpdateCachedValues(w,h);
|
UpdateCachedValues(w,h);
|
||||||
if xe >= w then
|
if xe >= w then
|
||||||
// xe := w-1;
|
if WarnOnly then
|
||||||
raise Exception.createFMT('Any Find Function, you did not pass a ' +
|
begin
|
||||||
'correct xe: %d.', [xe]);
|
TClient(Client).WriteLn(Format('Warning! You passed a wrong xe to a finder function: %d. The client has a width of %d, thus the xe is out of bounds. Setting the value to %d (w-1) for now.',[xe,w,w-1]));
|
||||||
|
xe := w-1;
|
||||||
|
end else
|
||||||
|
raise Exception.createFMT('You passed a wrong xe to a finder function: %d. The client has a width of %d, thus the xe is out of bounds.',[xe,w]);
|
||||||
if ye >= h then
|
if ye >= h then
|
||||||
// ye := h-1;
|
if WarnOnly then
|
||||||
raise Exception.createFMT('Any Find Function, you did not pass a ' +
|
begin
|
||||||
'correct ye: %d.', [ye]);
|
TClient(Client).WriteLn(Format('Warning! You passed a wrong ye to a finder function: %d. The client has a height of %d, thus the ye is out of bounds. Setting the value to %d (h-1) for now.',[ye,h,h-1]));
|
||||||
|
ye := h-1;
|
||||||
|
end else
|
||||||
|
raise Exception.createFMT('You passed a wrong ye to a finder function: %d. The client has a height of %d, thus the ye is out of bounds.',[ye,h]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMFinder.CountColorTolerance(Color, xs, ys, xe, ye, Tolerance: Integer): Integer;
|
function TMFinder.CountColorTolerance(Color, xs, ys, xe, ye, Tolerance: Integer): Integer;
|
||||||
@ -1181,6 +1209,7 @@ begin
|
|||||||
//Finally lets test H2
|
//Finally lets test H2
|
||||||
if Abs(H2 - H1) > HueTol then
|
if Abs(H2 - H1) > HueTol then
|
||||||
continue;
|
continue;
|
||||||
|
//We survived the checks, this point is a match!
|
||||||
hit:
|
hit:
|
||||||
ClientTPA[c].x := xx;
|
ClientTPA[c].x := xx;
|
||||||
ClientTPA[c].y := yy;
|
ClientTPA[c].y := yy;
|
||||||
@ -1323,7 +1352,7 @@ end;
|
|||||||
{ Only works with CTS 1 for now.. Since Colorsame doesn't return a boolean :-( }
|
{ Only works with CTS 1 for now.. Since Colorsame doesn't return a boolean :-( }
|
||||||
//We do not check whether every white pixel is in tol range with every other white pixel..
|
//We do not check whether every white pixel is in tol range with every other white pixel..
|
||||||
|
|
||||||
function TMFinder.FindMaskTolerance(mask: TMask; out x, y: Integer; xs,
|
function TMFinder.FindMaskTolerance(const mask: TMask; out x, y: Integer; xs,
|
||||||
ys, xe, ye: Integer; Tolerance, ContourTolerance: Integer): Boolean;
|
ys, xe, ye: Integer; Tolerance, ContourTolerance: Integer): Boolean;
|
||||||
var
|
var
|
||||||
MainRowdata : TPRGB32Array;
|
MainRowdata : TPRGB32Array;
|
||||||
@ -1400,7 +1429,7 @@ begin
|
|||||||
TClient(Client).IOManager.FreeReturnData;
|
TClient(Client).IOManager.FreeReturnData;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMFinder.CheckMask(Mask: TMask);
|
procedure TMFinder.CheckMask(const Mask: TMask);
|
||||||
begin
|
begin
|
||||||
if (Mask.W < 1) or (Mask.H < 1) or (Mask.WhiteHi < 0) or (Mask.BlackHi < 0) then
|
if (Mask.W < 1) or (Mask.H < 1) or (Mask.WhiteHi < 0) or (Mask.BlackHi < 0) then
|
||||||
raise exception.CreateFMT('Mask is invalid. Width/Height: (%d,%d). WhiteHi/BlackHi: (%d,%d)',[Mask.W,Mask.H,Mask.WhiteHi,Mask.BlackHi]);
|
raise exception.CreateFMT('Mask is invalid. Width/Height: (%d,%d). WhiteHi/BlackHi: (%d,%d)',[Mask.W,Mask.H,Mask.WhiteHi,Mask.BlackHi]);
|
||||||
@ -1875,8 +1904,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMFinder.FindDTM(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer): Boolean;
|
{
|
||||||
|
Tries to find the given DTM. If found will put the point the dtm has
|
||||||
|
been found at in x, y and result to true.
|
||||||
|
}
|
||||||
|
|
||||||
|
function TMFinder.FindDTM(const DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer): Boolean;
|
||||||
var
|
var
|
||||||
P: TPointArray;
|
P: TPointArray;
|
||||||
begin
|
begin
|
||||||
@ -2048,7 +2081,7 @@ begin
|
|||||||
Result := (pc > 0);
|
Result := (pc > 0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMFinder.FindDTMRotated(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: Extended; Alternating : boolean): Boolean;
|
function TMFinder.FindDTMRotated(const DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: Extended; Alternating : boolean): Boolean;
|
||||||
|
|
||||||
var
|
var
|
||||||
P: TPointArray;
|
P: TPointArray;
|
||||||
@ -2063,9 +2096,9 @@ begin
|
|||||||
Exit(True);
|
Exit(True);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMFinder.FindDTMsRotated(_DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray; maxToFind: Integer; Alternating : boolean): Boolean;
|
function TMFinder.FindDTMsRotated(DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray; maxToFind: Integer; Alternating : boolean): Boolean;
|
||||||
var
|
var
|
||||||
DTM: pDTM;
|
DTMRot: pDTM;
|
||||||
// Colours of DTMs
|
// Colours of DTMs
|
||||||
clR,clG,clB : array of byte;
|
clR,clG,clB : array of byte;
|
||||||
|
|
||||||
@ -2113,17 +2146,17 @@ var
|
|||||||
begin
|
begin
|
||||||
// Is the area valid?
|
// Is the area valid?
|
||||||
DefaultOperations(x1, y1, x2, y2);
|
DefaultOperations(x1, y1, x2, y2);
|
||||||
if not DTMConsistent(_dtm) then
|
if not DTMConsistent(DTM) then
|
||||||
begin
|
begin
|
||||||
raise Exception.CreateFmt('FindDTMsRotated: DTM is not consistent.', []);
|
raise Exception.CreateFmt('FindDTMsRotated: DTMRot is not consistent.', []);
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
NormalizeDTM(_dtm);
|
NormalizeDTM(DTM);
|
||||||
|
|
||||||
setlength(goodPoints, _dtm.l);
|
setlength(goodPoints, DTM.l);
|
||||||
for i := 0 to _dtm.l - 1 do
|
for i := 0 to DTM.l - 1 do
|
||||||
goodPoints[i] := not _dtm.bp[i];
|
goodPoints[i] := not DTM.bp[i];
|
||||||
|
|
||||||
// Init data structure B.
|
// Init data structure B.
|
||||||
W := x2 - x1;
|
W := x2 - x1;
|
||||||
@ -2139,18 +2172,18 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// Convert colors to there components
|
// Convert colors to there components
|
||||||
SetLength(clR,_dtm.l);
|
SetLength(clR,DTM.l);
|
||||||
SetLength(clG,_dtm.l);
|
SetLength(clG,DTM.l);
|
||||||
SetLength(clB,_dtm.l);
|
SetLength(clB,DTM.l);
|
||||||
for i := 0 to _dtm.l - 1 do
|
for i := 0 to DTM.l - 1 do
|
||||||
ColorToRGB(_dtm.c[i],clR[i],clG[i],clB[i]);
|
ColorToRGB(DTM.c[i],clR[i],clG[i],clB[i]);
|
||||||
//Compiler hints
|
//Compiler hints
|
||||||
|
|
||||||
SetLength(hh,_dtm.l);
|
SetLength(hh,DTM.l);
|
||||||
SetLength(ss,_dtm.l);
|
SetLength(ss,DTM.l);
|
||||||
SetLength(ll,_dtm.l);
|
SetLength(ll,DTM.l);
|
||||||
for i := 0 to _DTM.l - 1 do
|
for i := 0 to DTM.l - 1 do
|
||||||
ColorToHSL(_dtm.c[i],hh[i],ss[i],ll[i]);
|
ColorToHSL(DTM.c[i],hh[i],ss[i],ll[i]);
|
||||||
|
|
||||||
GetToleranceSpeed2Modifiers(hMod, sMod);
|
GetToleranceSpeed2Modifiers(hMod, sMod);
|
||||||
ccts := CTS;
|
ccts := CTS;
|
||||||
@ -2170,9 +2203,9 @@ begin
|
|||||||
s := sAngle;
|
s := sAngle;
|
||||||
while s < eAngle do
|
while s < eAngle do
|
||||||
begin
|
begin
|
||||||
dtm := RotateDTM(_dtm, s);
|
DTMRot := RotateDTM(DTM, s);
|
||||||
//Rotate the DTM, the rest is just like FindDTMs
|
//Rotate the DTMRot, the rest is just like FindDTMs
|
||||||
MA := ValidMainPointBox(DTM, x1, y1, x2, y2);
|
MA := ValidMainPointBox(DTMRot, x1, y1, x2, y2);
|
||||||
//CD starts at 0,0.. We must adjust the MA, since this is still based on the xs,ys,xe,ye box.
|
//CD starts at 0,0.. We must adjust the MA, since this is still based on the xs,ys,xe,ye box.
|
||||||
MA.x1 := MA.x1 - x1;
|
MA.x1 := MA.x1 - x1;
|
||||||
MA.y1 := MA.y1 - y1;
|
MA.y1 := MA.y1 - y1;
|
||||||
@ -2183,14 +2216,14 @@ begin
|
|||||||
for xx := MA.x1 to MA.x2 do
|
for xx := MA.x1 to MA.x2 do
|
||||||
begin
|
begin
|
||||||
//Mainpoint can have area size as well, so we must check that just like any subpoint.
|
//Mainpoint can have area size as well, so we must check that just like any subpoint.
|
||||||
for i := 0 to dtm.l - 1 do
|
for i := 0 to DTMRot.l - 1 do
|
||||||
begin //change to use other areashapes too.
|
begin //change to use other areashapes too.
|
||||||
Found := false;
|
Found := false;
|
||||||
//With area it can go out of bounds, therefore this max/min check
|
//With area it can go out of bounds, therefore this max/min check
|
||||||
StartX := max(0,xx - dtm.asz[i] + dtm.p[i].x);
|
StartX := max(0,xx - DTMRot.asz[i] + DTMRot.p[i].x);
|
||||||
StartY := max(0,yy - dtm.asz[i] + dtm.p[i].y);
|
StartY := max(0,yy - DTMRot.asz[i] + DTMRot.p[i].y);
|
||||||
EndX := Min(Ma.x2,xx + dtm.asz[i] + dtm.p[i].x);
|
EndX := Min(Ma.x2,xx + DTMRot.asz[i] + DTMRot.p[i].x);
|
||||||
EndY := Min(ma.y2,yy + dtm.asz[i] + dtm.p[i].y);
|
EndY := Min(ma.y2,yy + DTMRot.asz[i] + DTMRot.p[i].y);
|
||||||
for xxx := StartX to EndX do //The search area for the subpoint
|
for xxx := StartX to EndX do //The search area for the subpoint
|
||||||
begin
|
begin
|
||||||
for yyy := StartY to EndY do
|
for yyy := StartY to EndY do
|
||||||
@ -2201,7 +2234,7 @@ begin
|
|||||||
// Checking point i now. (Store that we matched it)
|
// Checking point i now. (Store that we matched it)
|
||||||
ch[xxx][yyy]:= ch[xxx][yyy] or (1 shl i);
|
ch[xxx][yyy]:= ch[xxx][yyy] or (1 shl i);
|
||||||
|
|
||||||
if ColorSame(ccts,dtm.t[i],clR[i],clG[i],clB[i],cd[yyy][xxx].R, cd[yyy][xxx].G, cd[yyy][xxx].B,hh[i],ss[i],ll[i],hmod,smod) then
|
if ColorSame(ccts,DTMRot.t[i],clR[i],clG[i],clB[i],cd[yyy][xxx].R, cd[yyy][xxx].G, cd[yyy][xxx].B,hh[i],ss[i],ll[i],hmod,smod) then
|
||||||
b[xxx][yyy] := b[xxx][yyy] or (1 shl i);
|
b[xxx][yyy] := b[xxx][yyy] or (1 shl i);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2252,7 +2285,7 @@ begin
|
|||||||
// raise Exception.CreateFmt('Not done yet!', []);
|
// raise Exception.CreateFmt('Not done yet!', []);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMFinder.GetColors(Coords: TPointArray): TIntegerArray;
|
function TMFinder.GetColors(const Coords: TPointArray): TIntegerArray;
|
||||||
var
|
var
|
||||||
Box : TBox;
|
Box : TBox;
|
||||||
Len, I,w,h : integer;
|
Len, I,w,h : integer;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
unit libloader;
|
unit libloader;
|
||||||
|
|
||||||
{$mode objfpc}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
unit mufasabase;
|
unit mufasabase;
|
||||||
|
|
||||||
{$mode objfpc}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
{$undefine mDebug}
|
{$undefine mDebug}
|
||||||
|
Loading…
Reference in New Issue
Block a user