mirror of
https://github.com/moparisthebest/Simba
synced 2024-12-22 23:38:50 -05:00
Needs less sleep coding
git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@552 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
parent
d2d41920d0
commit
e5854f3eab
@ -65,6 +65,7 @@ var
|
||||
dtm: pdtm;
|
||||
p:tpointarray;
|
||||
bmp: TMufasaBitmap;
|
||||
aa: T2DExtendedArray;
|
||||
|
||||
begin
|
||||
// quick check parameters
|
||||
@ -84,74 +85,64 @@ begin
|
||||
|
||||
{ add your program here }
|
||||
C := TClient.Create('.');
|
||||
|
||||
bmp := TMufasaBitmap.Create;
|
||||
//bmp.LoadFromFile('/home/merlijn/Programs/mufasa/pics/smallchars.bmp');
|
||||
bmp.LoadFromFile('/home/merlijn/Programs/mufasa/pics/UpChars.bmp');
|
||||
C.IOManager.SetTarget(bmp);
|
||||
C.MOCR.InitTOCR('/home/merlijn/Programs/mufasa/trunk/Fonts/');
|
||||
// small chars
|
||||
t := GetTickCount;
|
||||
for i := 0 to 100 do
|
||||
C.MOCR.GetTextAt(0,0,0,3,2,65278,2,100,'UpChars');
|
||||
//C.MOCR.GetTextAt(0,0,1,3,2,0,0,100,'SmallChars');
|
||||
writeln(floattostr((gettickcount - t) / 100.0) + ' ms');
|
||||
writeln(C.MOCR.GetTextAt(0,0,0,3,2,65278,2,100,'UpChars'));
|
||||
//writeln(C.MOCR.GetTextAt(0,0,1,3,2,0,0,100,'SmallChars'));
|
||||
|
||||
|
||||
{ bmp := C.MOCR.TextToFontBitmap('Welcome to RuneScape.', 'SmallChars');
|
||||
|
||||
|
||||
bmp.SaveToFile('/tmp/wat.bmp'); }
|
||||
|
||||
{ bmp := TMufasaBitmap.Create;
|
||||
bmp.SetSize(CW,CH);
|
||||
Writeln(Format('Client W/H: %d, %d', [CW, CH]));
|
||||
FillChar(bmp.FData[0],sizeof(trgb32)*CW*CH, 0);
|
||||
Randomize;
|
||||
for i := 0 to 500 do
|
||||
bmp.fastsetpixel(random(CW), random(CH), 255); }
|
||||
{ bmp.FastSetPixel(8,8,255);
|
||||
bmp.FastSetPixel(9,9,255);
|
||||
bmp.FastSetPixel(7,7,255);
|
||||
bmp.FastSetPixel(9,8,255);
|
||||
bmp.FastSetPixel(8,9,255); }
|
||||
// C.MWindow.SetTarget(bmp);
|
||||
{for i := 0 to 2000 do
|
||||
bmp.fastsetpixel(random(CW), random(CH), 255); }
|
||||
|
||||
bmp.FastSetPixel(50,50,255);
|
||||
bmp.FastSetPixel(45,45,255);
|
||||
// bmp.FastSetPixel(7,7,255);
|
||||
// bmp.FastSetPixel(9,8,255);
|
||||
// bmp.FastSetPixel(8,9,255);
|
||||
bmp.savetofile('/tmp/wat.bmp');
|
||||
|
||||
C.IOManager.SetTarget(bmp);
|
||||
|
||||
|
||||
{ initdtm(dtm, 5);
|
||||
initdtm(dtm, 2);
|
||||
dtm.p[0] := Point(2, 2);
|
||||
dtm.p[1] := Point(-3, -3);
|
||||
dtm.p[2] := Point(0, 0);
|
||||
{ dtm.p[2] := Point(0, 0);
|
||||
dtm.p[3] := Point(1, 1);
|
||||
dtm.p[4] := Point(3, 3);
|
||||
dtm.p[4] := Point(3, 3); }
|
||||
dtm.c[0] := 255;
|
||||
dtm.t[0] := 0;
|
||||
dtm.asz[1] := 1;
|
||||
dtm.ash[1] := dtm_Rectangle; }
|
||||
|
||||
{ dtm := randomdtm(10);
|
||||
dtm.c[1] := 255;
|
||||
dtm.t[1] := 0;
|
||||
dtm.asz[1] := 0;
|
||||
dtm.ash[1] := dtm_Rectangle;
|
||||
|
||||
//dtm := randomdtm(1);
|
||||
|
||||
// setlength(p, 1);
|
||||
C.MFinder.SetToleranceSpeed(1);
|
||||
C.MFinder.SetToleranceSpeed(1);
|
||||
|
||||
time := GetTickCount;
|
||||
for i := 0 to 100 do
|
||||
for i := 0 to 0 do
|
||||
begin
|
||||
setlength(p,0);
|
||||
C.MFinder.FindDTMs(dtm, p, 0, 0,CW-1, CH-1, 0);
|
||||
C.MFinder.FindDTMsRotated(dtm, p, 0, 0,CW-1, CH-1, 0.0, Pi / 4.0, Pi / 10.0, aa, 0);
|
||||
//C.MFinder.FindDTMs(dtm, p, 0, 0,CW-1, CH-1, 0);
|
||||
end;
|
||||
writeln(inttostr(gettickcount - time) + 'ms');
|
||||
writeln(inttostr(length(p))+ ' points found');
|
||||
for i := 0 to high(p) do
|
||||
writeln(format('P[%d]: (%d, %d)', [i,p[i].x,p[i].y]));
|
||||
setlength(p,0);
|
||||
|
||||
PrintpDTM(tdtmtopDTM(pDTMToTDTM(dtm))); }
|
||||
PrintpDTM(tdtmtopDTM(pDTMToTDTM(dtm)));
|
||||
|
||||
{for i := 0 to high(p) do
|
||||
writeln(format('%d: (%d, %d)', [i, p[i].x, p[i].y])); }
|
||||
for i := 0 to high(p) do
|
||||
writeln(format('%d: (%d, %d)', [i, p[i].x, p[i].y]));
|
||||
|
||||
|
||||
//bmp.OnDestroy:=nil;
|
||||
bmp.OnDestroy:=nil;
|
||||
//bmp.Free;
|
||||
bmp.Free;
|
||||
C.Free;
|
||||
@ -182,6 +173,8 @@ var
|
||||
|
||||
{$IFDEF WINDOWS}{$R project1.rc}{$ENDIF}
|
||||
|
||||
{$R project1.res}
|
||||
|
||||
begin
|
||||
Application:=MufasaTests.Create(nil);
|
||||
Application.Title:='My Application';
|
||||
@ -189,6 +182,25 @@ begin
|
||||
Application.Free;
|
||||
end.
|
||||
|
||||
{ bmp := TMufasaBitmap.Create;
|
||||
//bmp.LoadFromFile('/home/merlijn/Programs/mufasa/pics/smallchars.bmp');
|
||||
bmp.LoadFromFile('/home/merlijn/Programs/mufasa/pics/UpChars.bmp');
|
||||
C.IOManager.SetTarget(bmp);
|
||||
C.MOCR.InitTOCR('/home/merlijn/Programs/mufasa/trunk/Fonts/');
|
||||
// small chars
|
||||
t := GetTickCount;
|
||||
for i := 0 to 100 do
|
||||
C.MOCR.GetTextAt(0,0,0,3,2,65278,2,100,'UpChars');
|
||||
//C.MOCR.GetTextAt(0,0,1,3,2,0,0,100,'SmallChars');
|
||||
writeln(floattostr((gettickcount - t) / 100.0) + ' ms');
|
||||
writeln(C.MOCR.GetTextAt(0,0,0,3,2,65278,2,100,'UpChars')); }
|
||||
//writeln(C.MOCR.GetTextAt(0,0,1,3,2,0,0,100,'SmallChars'));
|
||||
|
||||
|
||||
{ bmp := C.MOCR.TextToFontBitmap('Welcome to RuneScape.', 'SmallChars');
|
||||
|
||||
|
||||
bmp.SaveToFile('/tmp/wat.bmp'); }
|
||||
|
||||
{ {$WARNING Change This Path!}
|
||||
C.MOCR.InitTOCR('/home/merlijn/Programs/mufasa/Fonts/');
|
||||
|
@ -28,7 +28,7 @@ unit dtmutil;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, MufasaTypes, tpa;
|
||||
Classes, SysUtils, MufasaTypes;
|
||||
|
||||
|
||||
Function pDTMToTDTM(Const DTM: pDTM): TDTM;
|
||||
@ -54,6 +54,24 @@ const
|
||||
implementation
|
||||
uses math;
|
||||
|
||||
Function RotatePoints_(Var P: TPointArray; A, cx, cy: Extended): TPointArray ;
|
||||
|
||||
Var
|
||||
I, L: Integer;
|
||||
CosA,SinA : extended;
|
||||
|
||||
Begin
|
||||
L := High(P);
|
||||
CosA := Cos(a);
|
||||
SinA := Sin(a);
|
||||
For I := 0 To L Do
|
||||
Begin
|
||||
P[I].X := Trunc(cx + CosA * (p[i].x - cx) - SinA * (p[i].y - cy));
|
||||
P[I].Y := Trunc(cy + SinA * (p[i].x - cx) + CosA * (p[i].y - cy));
|
||||
End;
|
||||
// I recon it's faster than Point().
|
||||
End;
|
||||
|
||||
// macro
|
||||
procedure initdtm(out d: pdtm; len: integer);
|
||||
var
|
||||
@ -204,8 +222,9 @@ procedure NormalizeDTM(var dtm: pdtm);
|
||||
var
|
||||
i:integer;
|
||||
begin
|
||||
for i := 0 to dtm.l do
|
||||
for i := 1 to dtm.l do
|
||||
dtm.p[i] := dtm.p[i] - dtm.p[0];
|
||||
dtm.p[0] := dtm.p[0] - dtm.p[0];
|
||||
end;
|
||||
|
||||
Function ValidMainPointBox(var dtm: pDTM; const x1, y1, x2, y2: Integer): TBox;
|
||||
@ -271,10 +290,13 @@ end;
|
||||
|
||||
procedure RotateDTM(var dtm: pdtm; angle: extended);
|
||||
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
if length(dtm.p) = 0 then
|
||||
raise Exception.Create('RotateDTM, no points in DTM.');
|
||||
RotatePoints(dtm.p, angle, dtm.p[0].x, dtm.p[0].y);
|
||||
|
||||
RotatePoints_(dtm.p, angle, dtm.p[0].x, dtm.p[0].y);
|
||||
end;
|
||||
|
||||
function copydtm(const dtm: pdtm): pdtm;
|
||||
|
@ -1977,7 +1977,7 @@ begin
|
||||
for yyy := yy - dtm.asz[i] + dtm.p[i].y to yy + dtm.asz[i]+ dtm.p[i].y do
|
||||
begin
|
||||
// If we have not checked this point, check it now.
|
||||
if ch[xxx][yyy+1] and (1 shl i) = 0 then
|
||||
if ch[xxx][yyy] and (1 shl i) = 0 then
|
||||
begin
|
||||
// Checking point i now. (Store that we matched it)
|
||||
ch[xxx][yyy]:= ch[xxx][yyy] or (1 shl i);
|
||||
@ -2054,20 +2054,15 @@ var
|
||||
|
||||
|
||||
begin
|
||||
raise Exception.CreateFmt('Not done yet!', []);
|
||||
if not DTMConsistent(_dtm) then
|
||||
begin
|
||||
raise Exception.CreateFmt('FindDTMsRotated: DTM is not consistent.', []);
|
||||
Exit;
|
||||
end;
|
||||
|
||||
// Get the area we should search in for the Main Point.
|
||||
//writeln(Format('%d, %d, %d, %d', [x1,y1,x2,y2]));
|
||||
MA := ValidMainPointBox(_DTM, x1, y1, x2, y2);
|
||||
NormalizeDTM(_dtm);
|
||||
|
||||
//writeln(Format('%d, %d, %d, %d', [MA.x1,MA.y1,MA.x2,MA.y2]));
|
||||
|
||||
DefaultOperations(MA.x1, MA.y1, MA.x2, MA.y2);
|
||||
DefaultOperations(x1, y1, x2, y2);
|
||||
DTM := copydtm(_DTM);
|
||||
|
||||
setlength(goodPoints, dtm.l);
|
||||
@ -2101,6 +2096,8 @@ begin
|
||||
while s < eAngle do
|
||||
begin
|
||||
RotateDTM(dtm, s);
|
||||
MA := ValidMainPointBox(DTM, x1, y1, x2, y2);
|
||||
|
||||
for yy := MA.y1 -y1 to MA.y2 - y1 do
|
||||
for xx := MA.x1 -x1 to MA.x2 - x1 do
|
||||
begin
|
||||
@ -2117,8 +2114,9 @@ begin
|
||||
for xxx := xx - dtm.asz[i] + dtm.p[i].x to xx + dtm.asz[i] + dtm.p[i].x do
|
||||
for yyy := yy - dtm.asz[i] + dtm.p[i].y to yy + dtm.asz[i]+ dtm.p[i].y do
|
||||
begin
|
||||
writeln(format('xxx,yyy: %d, %d', [xxx,yyy]));
|
||||
// If we have not checked this point, check it now.
|
||||
if ch[xxx][yyy+1] and (1 shl i) = 0 then
|
||||
if ch[xxx][yyy] and (1 shl i) = 0 then
|
||||
begin
|
||||
// Checking point i now. (Store that we matched it)
|
||||
ch[xxx][yyy]:= ch[xxx][yyy] or (1 shl i);
|
||||
@ -2135,6 +2133,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
//writeln(Format('Found point: (%d, %d)', [xx,yy]));
|
||||
|
||||
Inc(pc);
|
||||
setlength(Points,pc);
|
||||
Points[pc-1] := Point(xx + x1, yy + y1);
|
||||
@ -2149,8 +2148,9 @@ begin
|
||||
s := s + aStep;
|
||||
ac := 0;
|
||||
end;
|
||||
|
||||
TheEnd:
|
||||
TClient(Client).IOManager.FreeReturnData;
|
||||
TClient(Client).IOManager.FreeReturnData;
|
||||
|
||||
{ Don't forget to pre calculate the rotated points at the start.
|
||||
Saves a lot of rotatepoint() calls. }
|
||||
|
Loading…
Reference in New Issue
Block a user