mirror of
https://github.com/moparisthebest/Simba
synced 2024-11-22 09:12:19 -05:00
Fixed.
git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@99 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
parent
0f2c4af46f
commit
33b416a939
@ -1,67 +1,67 @@
|
|||||||
|
|
||||||
Sender.Comp.AddTypeS('TIntegerArray', 'Array of integer');
|
Sender.Comp.AddTypeS('TIntegerArray', 'Array of integer');
|
||||||
Sender.Comp.AddTypeS('TPointArray','Array of TPoint');
|
Sender.Comp.AddTypeS('TPointArray','Array of TPoint');
|
||||||
Sender.Comp.AddTypeS('TBmpMirrorStyle','(MirrorWidth,MirrorHeight,MirrorLine)');
|
Sender.Comp.AddTypeS('TBmpMirrorStyle','(MirrorWidth,MirrorHeight,MirrorLine)');
|
||||||
|
|
||||||
//Sender.Comp.AddTypeS('pDTM','pDTM = record p: TPointArray; c, t, asz, ash: TIntegerArray; end');
|
//Sender.Comp.AddTypeS('pDTM','pDTM = record p: TPointArray; c, t, asz, ash: TIntegerArray; end');
|
||||||
|
|
||||||
Sender.AddFunction(@ThreadSafeCall,'function ThreadSafeCall(ProcName: string; var V: TVariantArray): Variant;');
|
Sender.AddFunction(@ThreadSafeCall,'function ThreadSafeCall(ProcName: string; var V: TVariantArray): Variant;');
|
||||||
Sender.AddFunction(@psWriteln,'procedure writeln(s : string);');
|
Sender.AddFunction(@psWriteln,'procedure writeln(s : string);');
|
||||||
|
|
||||||
{ DTM }
|
{ DTM }
|
||||||
|
|
||||||
Sender.AddFunction(@ps_StringFromDTM, 'function StringFromDTM(DTMString: String): Integer;');
|
Sender.AddFunction(@ps_StringFromDTM, 'function DTMFromString(DTMString: String): Integer;');
|
||||||
Sender.AddFunction(@ps_FreeDTM, 'procedure FreeDTM(DTM: Integer);');
|
Sender.AddFunction(@ps_FreeDTM, 'procedure FreeDTM(DTM: Integer);');
|
||||||
Sender.AddFunction(@FindDTM, 'function FindDTM(DTM: Integer; var x, y: Integer; x1, y1, x2, y2: Integer): Boolean;');
|
Sender.AddFunction(@FindDTM, 'function FindDTM(DTM: Integer; var x, y: Integer; x1, y1, x2, y2: Integer): Boolean;');
|
||||||
|
|
||||||
|
|
||||||
{maths}
|
{maths}
|
||||||
sender.AddFunction(@power,'function pow(base,exponent : extended) : extended');
|
sender.AddFunction(@power,'function pow(base,exponent : extended) : extended');
|
||||||
Sender.AddFunction(@max,'function Max(a, b: Integer): Integer;');
|
Sender.AddFunction(@max,'function Max(a, b: Integer): Integer;');
|
||||||
Sender.AddFunction(@min,'function Min(a, b: Integer): Integer;');
|
Sender.AddFunction(@min,'function Min(a, b: Integer): Integer;');
|
||||||
Sender.AddFunction(@pssqr,'function Sqr(e : extended) : extended;');
|
Sender.AddFunction(@pssqr,'function Sqr(e : extended) : extended;');
|
||||||
|
|
||||||
Sender.AddFunction(@Freeze, 'function freeze:boolean;');
|
Sender.AddFunction(@Freeze, 'function freeze:boolean;');
|
||||||
Sender.AddFunction(@Unfreeze, 'function unfreeze: boolean;');
|
Sender.AddFunction(@Unfreeze, 'function unfreeze: boolean;');
|
||||||
|
|
||||||
Sender.AddFunction(@GetColor,'function GetColor(x, y: Integer): Integer;');
|
Sender.AddFunction(@GetColor,'function GetColor(x, y: Integer): Integer;');
|
||||||
Sender.AddFunction(@FindColor, 'function findcolor(var x, y: integer; color, x1, y1, x2, y2: integer): boolean;');
|
Sender.AddFunction(@FindColor, 'function findcolor(var x, y: integer; color, x1, y1, x2, y2: integer): boolean;');
|
||||||
Sender.AddFunction(@FindColorTolerance, 'function findcolortolerance(var x, y: integer; color, x1, y1, x2, y2, tol: integer): boolean;');
|
Sender.AddFunction(@FindColorTolerance, 'function findcolortolerance(var x, y: integer; color, x1, y1, x2, y2, tol: integer): boolean;');
|
||||||
Sender.AddFunction(@FindColors, 'function findcolors(var TPA: TPointArray; color, x1, y1, x2, y2: integer): boolean;');
|
Sender.AddFunction(@FindColors, 'function findcolors(var TPA: TPointArray; color, x1, y1, x2, y2: integer): boolean;');
|
||||||
Sender.AddFunction(@SimilarColors,'function SimilarColors(Col1,Col2,Tolerance : integer) : boolean');
|
Sender.AddFunction(@SimilarColors,'function SimilarColors(Col1,Col2,Tolerance : integer) : boolean');
|
||||||
Sender.AddFunction(@CountColorTolerance,'function CountColorTolerance(Color, xs, ys, xe, ye, Tolerance: Integer): Integer;');
|
Sender.AddFunction(@CountColorTolerance,'function CountColorTolerance(Color, xs, ys, xe, ye, Tolerance: Integer): Integer;');
|
||||||
Sender.AddFunction(@FindColorsTolerance,'function FindColorsTolerance(var Points: TPointArray; Color, xs, ys, xe, ye, Tolerance: Integer): Boolean;');
|
Sender.AddFunction(@FindColorsTolerance,'function FindColorsTolerance(var Points: TPointArray; Color, xs, ys, xe, ye, Tolerance: Integer): Boolean;');
|
||||||
|
|
||||||
Sender.AddFunction(@MoveMouse, 'procedure MoveMouse(x, y: integer);');
|
Sender.AddFunction(@MoveMouse, 'procedure MoveMouse(x, y: integer);');
|
||||||
Sender.AddFunction(@GetMousePos, 'procedure GetMousePos(var x, y: integer);');
|
Sender.AddFunction(@GetMousePos, 'procedure GetMousePos(var x, y: integer);');
|
||||||
|
|
||||||
Sender.AddFunction(@Wait, 'procedure wait(t: integer);');
|
Sender.AddFunction(@Wait, 'procedure wait(t: integer);');
|
||||||
Sender.AddFunction(@GetClientDimensions, 'procedure GetClientDimensions(var w, h:integer);');
|
Sender.AddFunction(@GetClientDimensions, 'procedure GetClientDimensions(var w, h:integer);');
|
||||||
Sender.AddFunction(@SetColorToleranceSpeed, 'procedure SetColorToleranceSpeed(cts: integer);');
|
Sender.AddFunction(@SetColorToleranceSpeed, 'procedure SetColorToleranceSpeed(cts: integer);');
|
||||||
Sender.AddFunction(@GetTickCount, 'function GetSystemTime: Integer;');
|
Sender.AddFunction(@GetTickCount, 'function GetSystemTime: Integer;');
|
||||||
|
|
||||||
Sender.AddFunction(@CreateBitmap,'function CreateBitmap(w,h :integer) : integer;');
|
Sender.AddFunction(@CreateBitmap,'function CreateBitmap(w,h :integer) : integer;');
|
||||||
Sender.AddFunction(@FreeBitmap,'procedure FreeBitmap(Bmp : integer);');
|
Sender.AddFunction(@FreeBitmap,'procedure FreeBitmap(Bmp : integer);');
|
||||||
Sender.AddFunction(@SaveBitmap,'procedure SaveBitmap(Bmp : integer; path : string);');
|
Sender.AddFunction(@SaveBitmap,'procedure SaveBitmap(Bmp : integer; path : string);');
|
||||||
Sender.AddFunction(@BitmapFromString,'function BitmapFromString(Width,Height : integer; Data : string): integer;');
|
Sender.AddFunction(@BitmapFromString,'function BitmapFromString(Width,Height : integer; Data : string): integer;');
|
||||||
Sender.AddFunction(@LoadBitmap,'function LoadBitmap(Path : string) : integer;');
|
Sender.AddFunction(@LoadBitmap,'function LoadBitmap(Path : string) : integer;');
|
||||||
Sender.AddFunction(@SetBitmapSize,'procedure SetBitmapSize(Bmp,NewW,NewH : integer);');
|
Sender.AddFunction(@SetBitmapSize,'procedure SetBitmapSize(Bmp,NewW,NewH : integer);');
|
||||||
Sender.AddFunction(@GetBitmapSize,'procedure GetBitmapSize(Bmp : integer; Var BmpW,BmpH : integer);');
|
Sender.AddFunction(@GetBitmapSize,'procedure GetBitmapSize(Bmp : integer; Var BmpW,BmpH : integer);');
|
||||||
Sender.AddFunction(@CreateMirroredBitmap,'function CreateMirroredBitmap(Bmp : integer) : integer;');
|
Sender.AddFunction(@CreateMirroredBitmap,'function CreateMirroredBitmap(Bmp : integer) : integer;');
|
||||||
Sender.AddFunction(@CreateMirroredBitmapEx,'function CreateMirroredBitmapEx(Bmp : integer; MirrorStyle : TBmpMirrorStyle) : integer;');
|
Sender.AddFunction(@CreateMirroredBitmapEx,'function CreateMirroredBitmapEx(Bmp : integer; MirrorStyle : TBmpMirrorStyle) : integer;');
|
||||||
Sender.AddFunction(@FastSetPixel,'procedure FastSetPixel(bmp,x,y : integer; Color : TColor);');
|
Sender.AddFunction(@FastSetPixel,'procedure FastSetPixel(bmp,x,y : integer; Color : TColor);');
|
||||||
Sender.AddFunction(@FastSetPixels,'procedure FastSetPixels(bmp : integer; TPA : TPointArray; Colors : TIntegerArray);');
|
Sender.AddFunction(@FastSetPixels,'procedure FastSetPixels(bmp : integer; TPA : TPointArray; Colors : TIntegerArray);');
|
||||||
Sender.AddFunction(@FastGetPixel,'function FastGetPixel(bmp, x,y : integer) : TColor;');
|
Sender.AddFunction(@FastGetPixel,'function FastGetPixel(bmp, x,y : integer) : TColor;');
|
||||||
Sender.AddFunction(@FastGetPixels,'function FastGetPixels(Bmp : integer; TPA : TPointArray) : TIntegerArray;');
|
Sender.AddFunction(@FastGetPixels,'function FastGetPixels(Bmp : integer; TPA : TPointArray) : TIntegerArray;');
|
||||||
Sender.AddFunction(@FastDrawClear,'procedure FastDrawClear(bmp : integer; Color : TColor)');
|
Sender.AddFunction(@FastDrawClear,'procedure FastDrawClear(bmp : integer; Color : TColor)');
|
||||||
Sender.AddFunction(@FastDrawTransparent,'procedure FastDrawTransparent(x, y: Integer; SourceBitmap, TargetBitmap: Integer);');
|
Sender.AddFunction(@FastDrawTransparent,'procedure FastDrawTransparent(x, y: Integer; SourceBitmap, TargetBitmap: Integer);');
|
||||||
Sender.AddFunction(@SetTransparentColor,'procedure SetTransparentColor(bmp : integer; Color : TColor);');
|
Sender.AddFunction(@SetTransparentColor,'procedure SetTransparentColor(bmp : integer; Color : TColor);');
|
||||||
Sender.AddFunction(@GetTransparentColor,'function GetTransparentColor(bmp: integer) : TColor;');
|
Sender.AddFunction(@GetTransparentColor,'function GetTransparentColor(bmp: integer) : TColor;');
|
||||||
Sender.AddFunction(@FastReplaceColor,'procedure FastReplaceColor(Bmp : integer; OldColor,NewColor : TColor);');
|
Sender.AddFunction(@FastReplaceColor,'procedure FastReplaceColor(Bmp : integer; OldColor,NewColor : TColor);');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ begin
|
|||||||
MFiles := TMFiles.Create;
|
MFiles := TMFiles.Create;
|
||||||
MFinder := TMFinder.Create(Self);
|
MFinder := TMFinder.Create(Self);
|
||||||
MBitmaps := TMBitmaps.Create(self);
|
MBitmaps := TMBitmaps.Create(self);
|
||||||
MDTM := MDTM.Create(self);
|
MDTM := TMDTM.Create(self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TClient.Destroy;
|
destructor TClient.Destroy;
|
||||||
|
@ -1,322 +1,322 @@
|
|||||||
unit dtm;
|
unit dtm;
|
||||||
|
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, MufasaTypes;
|
Classes, SysUtils, MufasaTypes;
|
||||||
|
|
||||||
type
|
type
|
||||||
TMDTM = class(TObject)
|
TMDTM = class(TObject)
|
||||||
constructor Create(Owner: TObject);
|
|
||||||
destructor Destroy; override;
|
function AddDTM(d: TDTM): Integer;
|
||||||
|
function AddpDTM(d: pDTM): Integer;
|
||||||
function AddDTM(d: TDTM): Integer;
|
function GetDTM(index: Integer; var dtm: pDTM): Boolean;
|
||||||
function AddpDTM(d: pDTM): Integer;
|
procedure FreeDTM(DTM: Integer);
|
||||||
function GetDTM(index: Integer; var dtm: pDTM): Boolean;
|
Function StringToDTM(S: String): pDTM;
|
||||||
procedure FreeDTM(DTM: Integer);
|
|
||||||
Function StringToDTM(S: String): pDTM;
|
function FindDTM(DTM: Integer; var x, y: Integer; x1, y1, x2,
|
||||||
|
y2: Integer): Boolean;
|
||||||
function FindDTM(DTM: Integer; var x, y: Integer; x1, y1, x2,
|
{ function FindDTMs(DTM: Integer; var Points: TPointArray; x1, y1, x2,
|
||||||
y2: Integer): Boolean;
|
y2: Integer): Boolean;
|
||||||
{ function FindDTMs(DTM: Integer; var Points: TPointArray; x1, y1, x2,
|
function FindDTMRotated(DTM: Integer; var x, y: Integer; x1, y1, x2,
|
||||||
y2: Integer): Boolean;
|
y2: Integer; sAngle, eAngle, aStep: Extended;
|
||||||
function FindDTMRotated(DTM: Integer; var x, y: Integer; x1, y1, x2,
|
var aFound: Extended): Boolean;
|
||||||
y2: Integer; sAngle, eAngle, aStep: Extended;
|
function FindDTMsRotated(DTM: Integer; var Points: TPointArray; x1,
|
||||||
var aFound: Extended): Boolean;
|
y1, x2, y2: Integer; sAngle, eAngle,
|
||||||
function FindDTMsRotated(DTM: Integer; var Points: TPointArray; x1,
|
aStep: Extended; var aFound: T2DExtendedArray)
|
||||||
y1, x2, y2: Integer; sAngle, eAngle,
|
: Boolean; }
|
||||||
aStep: Extended; var aFound: T2DExtendedArray)
|
function pFindDTM(DTM: pDTM; var x, y: Integer; x1, y1, x2, y2:
|
||||||
: Boolean; }
|
Integer): Boolean;
|
||||||
function pFindDTM(DTM: pDTM; var x, y: Integer; x1, y1, x2, y2:
|
|
||||||
Integer): Boolean;
|
constructor Create(Owner: TObject);
|
||||||
|
destructor Destroy; override;
|
||||||
private
|
private
|
||||||
|
|
||||||
Client: TObject;
|
Client: TObject;
|
||||||
|
|
||||||
// For decompressing.
|
// For decompressing.
|
||||||
BufferString: String;
|
BufferString: String;
|
||||||
|
|
||||||
DTMList: Array Of pDTM;
|
DTMList: Array Of pDTM;
|
||||||
FreeSpots: Array Of Integer;
|
FreeSpots: Array Of Integer;
|
||||||
end;
|
end;
|
||||||
const
|
const
|
||||||
dtm_Rectangle = 0;
|
dtm_Rectangle = 0;
|
||||||
dtm_Cross = 1;
|
dtm_Cross = 1;
|
||||||
dtm_DiagonalCross = 2;
|
dtm_DiagonalCross = 2;
|
||||||
dtm_Circle = 3;
|
dtm_Circle = 3;
|
||||||
dtm_Triangle = 4;
|
dtm_Triangle = 4;
|
||||||
|
|
||||||
{
|
{
|
||||||
I am not sure wether I should simply copy and paste the old DTM implementation,
|
I am not sure wether I should simply copy and paste the old DTM implementation,
|
||||||
or rewrite it from scratch.
|
or rewrite it from scratch.
|
||||||
|
|
||||||
I recall there was something partially wrong with SCAR-alike DTM conversions
|
I recall there was something partially wrong with SCAR-alike DTM conversions
|
||||||
to Mufasa DTM's...
|
to Mufasa DTM's...
|
||||||
|
|
||||||
The old DTM system problaby doesn't perform that well, but seems to be quite
|
The old DTM system problaby doesn't perform that well, but seems to be quite
|
||||||
stable and complete.
|
stable and complete.
|
||||||
|
|
||||||
If I would rewrite it from scratch, it would probably be faster, and
|
If I would rewrite it from scratch, it would probably be faster, and
|
||||||
hopefully more efficient.That won't be too hard, especially since I have
|
hopefully more efficient.That won't be too hard, especially since I have
|
||||||
direct data access now. (TClient FTW!)
|
direct data access now. (TClient FTW!)
|
||||||
|
|
||||||
Rewrite from scratch it will be, I guess.
|
Rewrite from scratch it will be, I guess.
|
||||||
And AreaShape will be turned into a {$I }, inline simply doesn't cut it.
|
And AreaShape will be turned into a {$I }, inline simply doesn't cut it.
|
||||||
|
|
||||||
~Wizz
|
~Wizz
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
uses
|
uses
|
||||||
Client, dtmutil, paszlib;
|
Client, dtmutil, paszlib;
|
||||||
|
|
||||||
type
|
type
|
||||||
TBufferByteArray = Array[0..524288] of Byte;
|
TBufferByteArray = Array[0..524287] of Byte;
|
||||||
PBufferByteArray = ^TBufferByteArray;
|
PBufferByteArray = ^TBufferByteArray;
|
||||||
|
|
||||||
constructor TMDTM.Create(Owner: TObject);
|
constructor TMDTM.Create(Owner: TObject);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
Self.Client := Owner;
|
Self.Client := Owner;
|
||||||
|
|
||||||
SetLength(DTMList, 0);
|
SetLength(DTMList, 0);
|
||||||
SetLength(FreeSpots, 0);
|
SetLength(FreeSpots, 0);
|
||||||
SetLength(BufferString, 524288);
|
SetLength(BufferString, 524288);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TMDTM.Destroy;
|
destructor TMDTM.Destroy;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
SetLength(DTMList, 0);
|
SetLength(DTMList, 0);
|
||||||
SetLength(FreeSpots, 0);
|
SetLength(FreeSpots, 0);
|
||||||
SetLength(BufferString, 0);
|
SetLength(BufferString, 0);
|
||||||
|
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function HexToInt(HexNum: string): LongInt;inline;
|
function HexToInt(HexNum: string): LongInt;inline;
|
||||||
begin
|
begin
|
||||||
Result:=StrToInt('$' + HexNum);
|
Result:=StrToInt('$' + HexNum);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMDTM.StringToDTM(S: String): pDTM;
|
function TMDTM.StringToDTM(S: String): pDTM;
|
||||||
var
|
var
|
||||||
b: PBufferByteArray;
|
b: PBufferByteArray;
|
||||||
Source : String;
|
Source : String;
|
||||||
DestLen : LongWord;
|
DestLen : longword;
|
||||||
i,ii,c : integer;
|
i,ii,c : integer;
|
||||||
begin
|
begin
|
||||||
SetLength(Result.p,0);
|
SetLength(Result.p,0);
|
||||||
SetLength(Result.c,0);
|
SetLength(Result.c,0);
|
||||||
SetLength(Result.t,0);
|
SetLength(Result.t,0);
|
||||||
SetLength(Result.asz,0);
|
SetLength(Result.asz,0);
|
||||||
SetLength(Result.ash,0);
|
SetLength(Result.ash,0);
|
||||||
ii := Length(S);
|
ii := Length(S);
|
||||||
if (ii = 0) or (ii mod 2 <> 0) then
|
if (ii = 0) or (ii mod 2 <> 0) then
|
||||||
Exit;
|
Exit;
|
||||||
ii := ii div 2;
|
ii := ii div 2;
|
||||||
SetLength(Source,ii);
|
SetLength(Source,ii);
|
||||||
for i := 1 to ii do
|
for i := 1 to ii do
|
||||||
Source[i] := Chr(HexToInt(S[i * 2 - 1] + S[i * 2]));
|
Source[i] := Chr(HexToInt(S[i * 2 - 1] + S[i * 2]));
|
||||||
DestLen := Length(Self.BufferString);
|
DestLen := Length(Self.BufferString);
|
||||||
if uncompress(PChar(Self.Bufferstring),Destlen,pchar(Source), ii) = Z_OK then
|
if uncompress(PChar(Self.Bufferstring),Destlen,pchar(Source), ii) = Z_OK then
|
||||||
begin;
|
begin;
|
||||||
if (Destlen mod 36) > 0 then
|
if (Destlen mod 36) > 0 then
|
||||||
begin;
|
begin;
|
||||||
Writeln('Invalid DTM');
|
Writeln('Invalid DTM');
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
DestLen := DestLen div 36;
|
DestLen := DestLen div 36;
|
||||||
SetLength(Result.p,DestLen);
|
SetLength(Result.p,DestLen);
|
||||||
SetLength(Result.c,DestLen);
|
SetLength(Result.c,DestLen);
|
||||||
SetLength(Result.t,DestLen);
|
SetLength(Result.t,DestLen);
|
||||||
SetLength(Result.asz,DestLen);
|
SetLength(Result.asz,DestLen);
|
||||||
SetLength(Result.ash,DestLen);
|
SetLength(Result.ash,DestLen);
|
||||||
b := @Self.Bufferstring[1];
|
b := @Self.Bufferstring[1];
|
||||||
for i := 0 to DestLen - 1 do
|
for i := 0 to DestLen - 1 do
|
||||||
begin;
|
begin;
|
||||||
c := i * 36;
|
c := i * 36;
|
||||||
Result.p[i].x := PInteger(@b^[c+1])^;
|
Result.p[i].x := PInteger(@b^[c+1])^;
|
||||||
Result.p[i].y := PInteger(@b^[c+5])^;
|
Result.p[i].y := PInteger(@b^[c+5])^;
|
||||||
Result.asz[i] := PInteger(@b^[c+12])^;
|
Result.asz[i] := PInteger(@b^[c+12])^;
|
||||||
Result.ash[i] := PInteger(@b^[c+16])^;
|
Result.ash[i] := PInteger(@b^[c+16])^;
|
||||||
Result.c[i] := PInteger(@b^[c+20])^;
|
Result.c[i] := PInteger(@b^[c+20])^;
|
||||||
Result.t[i] := PInteger(@b^[c+24])^;
|
Result.t[i] := PInteger(@b^[c+24])^;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMDTM.AddDTM(d: TDTM): Integer;
|
function TMDTM.AddDTM(d: TDTM): Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if Length(FreeSpots) > 0 then
|
if Length(FreeSpots) > 0 then
|
||||||
begin
|
begin
|
||||||
DTMList[FreeSpots[High(FreeSpots)]] := TDTMTopDTM(d);
|
DTMList[FreeSpots[High(FreeSpots)]] := TDTMTopDTM(d);
|
||||||
Result := FreeSpots[High(FreeSpots)];
|
Result := FreeSpots[High(FreeSpots)];
|
||||||
SetLength(FreeSpots, High(FreeSpots));
|
SetLength(FreeSpots, High(FreeSpots));
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
SetLength(DTMList, Length(DTMList) + 1);
|
SetLength(DTMList, Length(DTMList) + 1);
|
||||||
DTMList[High(DTMList)] := TDTMTopDTM(d);
|
DTMList[High(DTMList)] := TDTMTopDTM(d);
|
||||||
Result := High(DTMList);
|
Result := High(DTMList);
|
||||||
end;
|
end;
|
||||||
end;
|
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(d: pDTM): Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if Length(FreeSpots) > 0 then
|
if Length(FreeSpots) > 0 then
|
||||||
begin
|
begin
|
||||||
DTMList[FreeSpots[High(FreeSpots)]] := d;
|
DTMList[FreeSpots[High(FreeSpots)]] := d;
|
||||||
Result := FreeSpots[High(FreeSpots)];
|
Result := FreeSpots[High(FreeSpots)];
|
||||||
SetLength(FreeSpots, High(FreeSpots));
|
SetLength(FreeSpots, High(FreeSpots));
|
||||||
end
|
end
|
||||||
Else
|
Else
|
||||||
begin
|
begin
|
||||||
SetLength(DTMList, Length(DTMList) + 1);
|
SetLength(DTMList, Length(DTMList) + 1);
|
||||||
DTMList[High(DTMList)] := d;
|
DTMList[High(DTMList)] := d;
|
||||||
Result := High(DTMList);
|
Result := High(DTMList);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{/\
|
{/\
|
||||||
Returns the DTM (pDTM type) in the variable dtm at the given index.
|
Returns the DTM (pDTM type) in the variable dtm at the given index.
|
||||||
Returns true is succesfull, false if the dtm does not exist.
|
Returns true is succesfull, false if the dtm does not exist.
|
||||||
/\}
|
/\}
|
||||||
|
|
||||||
function TMDTM.GetDTM(index: Integer; var dtm: pDTM): Boolean;
|
function TMDTM.GetDTM(index: Integer; var dtm: pDTM): Boolean;
|
||||||
begin
|
begin
|
||||||
Result := True;
|
Result := True;
|
||||||
try
|
try
|
||||||
dtm := DTMList[index];
|
dtm := DTMList[index];
|
||||||
except
|
except
|
||||||
begin
|
begin
|
||||||
raise Exception.CreateFmt('The given DTM Index ([%d]) is invalid.',
|
raise Exception.CreateFmt('The given DTM Index ([%d]) is invalid.',
|
||||||
[index]);
|
[index]);
|
||||||
//WriteLn('DTM Index ' + IntToStr(index) + ' does not exist');
|
//WriteLn('DTM Index ' + IntToStr(index) + ' does not exist');
|
||||||
Result := False;
|
Result := False;
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{/\
|
{/\
|
||||||
Unloads the DTM at the given index from the DTM Array.
|
Unloads the DTM at the given index from the DTM Array.
|
||||||
Notes:
|
Notes:
|
||||||
Will keep track of not used index, so it is very memory efficient.
|
Will keep track of not used index, so it is very memory efficient.
|
||||||
/\}
|
/\}
|
||||||
|
|
||||||
Procedure TMDTM.FreeDTM(DTM: Integer);
|
Procedure TMDTM.FreeDTM(DTM: Integer);
|
||||||
begin
|
begin
|
||||||
try
|
try
|
||||||
SetLength(DTMList[DTM].p, 0);
|
SetLength(DTMList[DTM].p, 0);
|
||||||
SetLength(DTMList[DTM].c, 0);
|
SetLength(DTMList[DTM].c, 0);
|
||||||
SetLength(DTMList[DTM].t, 0);
|
SetLength(DTMList[DTM].t, 0);
|
||||||
SetLength(DTMList[DTM].asz, 0);
|
SetLength(DTMList[DTM].asz, 0);
|
||||||
SetLength(DTMList[DTM].ash, 0);
|
SetLength(DTMList[DTM].ash, 0);
|
||||||
except
|
except
|
||||||
//WriteLn('Invalid DTM');
|
//WriteLn('Invalid DTM');
|
||||||
end;
|
end;
|
||||||
SetLength(FreeSpots, Length(FreeSpots) + 1);
|
SetLength(FreeSpots, Length(FreeSpots) + 1);
|
||||||
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
|
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.
|
been found at in x, y and result to true.
|
||||||
}
|
}
|
||||||
function TMDTM.FindDTM(DTM: Integer; var x, y: Integer; x1, y1, x2, y2: Integer): Boolean;
|
function TMDTM.FindDTM(DTM: Integer; var x, y: Integer; x1, y1, x2, y2: Integer): Boolean;
|
||||||
var
|
var
|
||||||
temp: pDTM;
|
temp: pDTM;
|
||||||
begin
|
begin
|
||||||
if GetDTM(DTM, temp) then
|
if GetDTM(DTM, temp) then
|
||||||
Result := pFindDTM(temp, x, y, x1, y1, x2, y2)
|
Result := pFindDTM(temp, x, y, x1, y1, x2, y2)
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
x := 0;
|
x := 0;
|
||||||
y := 0;
|
y := 0;
|
||||||
Result := False;
|
Result := False;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{
|
{
|
||||||
Tries to find the given pDTM. If found will put the point the dtm has
|
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.
|
been found at in x, y and result to true.
|
||||||
}
|
}
|
||||||
|
|
||||||
function TMDTM.pFindDTM(DTM: pDTM; var x, y: Integer; x1, y1, x2, y2: Integer): Boolean;
|
function TMDTM.pFindDTM(DTM: pDTM; var x, y: Integer; x1, y1, x2, y2: Integer): Boolean;
|
||||||
|
|
||||||
var
|
var
|
||||||
mP: TPointArray;
|
mP: TPointArray;
|
||||||
I, J, H, dH: Integer;
|
I, J, H, dH: Integer;
|
||||||
Found: Boolean;
|
Found: Boolean;
|
||||||
TempTP: TPoint;
|
TempTP: TPoint;
|
||||||
RetData: TRetData;
|
RetData: TRetData;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
for I := 1 to High(DTM.p) do
|
for I := 1 to High(DTM.p) do
|
||||||
begin
|
begin
|
||||||
DTM.p[I].x := DTM.p[I].x - DTM.p[0].x;
|
DTM.p[I].x := DTM.p[I].x - DTM.p[0].x;
|
||||||
DTM.p[I].y := DTM.p[I].y - DTM.p[0].y;
|
DTM.p[I].y := DTM.p[I].y - DTM.p[0].y;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// X2 := X2 - MaxSubPointDist.X
|
// X2 := X2 - MaxSubPointDist.X
|
||||||
// Y2 := Y2 - MaxSubPointDist.Y
|
// Y2 := Y2 - MaxSubPointDist.Y
|
||||||
// X1 := X1 + MaxSubPointDist.X
|
// X1 := X1 + MaxSubPointDist.X
|
||||||
// Y1 := Y1 + MaxSubPointDist.Y
|
// Y1 := Y1 + MaxSubPointDist.Y
|
||||||
// If X2 > X1 then Exit
|
// If X2 > X1 then Exit
|
||||||
// If Y2 > Y1 then Exit
|
// If Y2 > Y1 then Exit
|
||||||
// Will make sure there are no out of bounds exceptions, and will make it faster
|
// Will make sure there are no out of bounds exceptions, and will make it faster
|
||||||
|
|
||||||
TClient(Client).MWindow.Freeze();
|
TClient(Client).MWindow.Freeze();
|
||||||
|
|
||||||
TClient(Client).MFinder.FindColorsTolerance(mP, DTM.c[Low(DTM.c)],
|
TClient(Client).MFinder.FindColorsTolerance(mP, DTM.c[Low(DTM.c)],
|
||||||
x1, y1, x2, y2, DTM.t[Low(DTM.t)]);
|
x1, y1, x2, y2, DTM.t[Low(DTM.t)]);
|
||||||
|
|
||||||
TClient(Client).MWindow.GetDimensions(H, dH);
|
TClient(Client).MWindow.GetDimensions(H, dH);
|
||||||
RetData := TClient(Client).MWindow.ReturnData(0, 0, H, dH);
|
RetData := TClient(Client).MWindow.ReturnData(0, 0, H, dH);
|
||||||
|
|
||||||
H := High(mP);
|
H := High(mP);
|
||||||
dH := High(DTM.p);
|
dH := High(DTM.p);
|
||||||
for I := 0 to H do
|
for I := 0 to H do
|
||||||
begin
|
begin
|
||||||
// Use MainPoint's AreaSize and Shape.
|
// Use MainPoint's AreaSize and Shape.
|
||||||
// for Loop on mP, depending on the AreaShape. then on all the code beneath
|
// for Loop on mP, depending on the AreaShape. then on all the code beneath
|
||||||
// this point, use the var that is retrieved from the for loop.
|
// this point, use the var that is retrieved from the for loop.
|
||||||
Found := True;
|
Found := True;
|
||||||
for J := 1 to dH do
|
for J := 1 to dH do
|
||||||
begin
|
begin
|
||||||
TempTP.X := DTM.p[J].X + mP[I].X;
|
TempTP.X := DTM.p[J].X + mP[I].X;
|
||||||
TempTP.Y := DTM.p[J].Y + mP[I].Y;
|
TempTP.Y := DTM.p[J].Y + mP[I].Y;
|
||||||
//Now would be the time to Rotate TempTP
|
//Now would be the time to Rotate TempTP
|
||||||
//If Not AreaShape(DTM.c[J], DTM.t[J], DTM.asz[J], DTM.ash[J], TempTP) then
|
//If Not AreaShape(DTM.c[J], DTM.t[J], DTM.asz[J], DTM.ash[J], TempTP) then
|
||||||
if False then
|
if False then
|
||||||
begin
|
begin
|
||||||
Found := False;
|
Found := False;
|
||||||
Break;
|
Break;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if Found then
|
if Found then
|
||||||
begin
|
begin
|
||||||
Result := True;
|
Result := True;
|
||||||
x := mP[I].X;
|
x := mP[I].X;
|
||||||
y := mP[I].Y;
|
y := mP[I].Y;
|
||||||
TClient(Client).MWindow.UnFreeze();
|
TClient(Client).MWindow.UnFreeze();
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
TClient(Client).MWindow.UnFreeze();
|
TClient(Client).MWindow.UnFreeze();
|
||||||
Result := False;
|
Result := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user