NEW PROBLEM
Now I try to only do the math parts with the dll, so I leave the bitmaps to Simba.
This is the final code:
Simba Code:
library Galileo;
{$mode objfpc}{$H+}
uses
Classes, sysutils;
type
TIntegerArray = Array of Integer;
T3DIntegerArray = Array of Array of Array of Integer;
function Galileo_ColorBoxesMatch(B1, B2: TIntegerArray; tol: extended): boolean; register;
begin
if (B1[0] >= Round(B2[0]*(1-tol))) and (B1[0] <= Round(B2[0]*(1+tol))) then
if (B1[1] >= Round(B2[1]*(1-tol))) and (B1[1] <= Round(B2[1]*(1+tol))) then
if (B1[2] >= Round(B2[2]*(1-tol))) and (B1[2] <= Round(B2[2]*(1+tol))) then
begin
Result := True;
Exit;
end;
end;
function Galileo_FindMapInMapExx(LargeMap, SmallMap: T3DIntegerArray; SideLength: integer; tol: extended; MaxFails: integer): TPoint; register;
var
x, y, HighX, HighY: integer;
xx, yy: integer;
Matching: integer;
begin
Result := Point(-1, -1);
HighX := High(LargeMap);
HighY := High(LargeMap[0]);
for x := 0 to HighX do
for y := 0 to HighY do
if Galileo_ColorBoxesMatch(LargeMap[x][y], SmallMap[0][0], tol) then
begin
Matching := 0;
try
// top left matches, let's compare the others
for xx := 0 to 19 do
for yy := 0 to 19 do
if Galileo_ColorBoxesMatch(LargeMap[x+xx][y+yy], SmallMap[xx][yy], tol) then
Inc(Matching);
//writeln('matching: '+inttostr(matching));
if Matching >= (400 - MaxFails) then // 20*20 = 400
begin
Result.X := (x + 10)*Sidelength; // +10 cause we want the center
Result.Y := (y + 10)*Sidelength;
Exit;
end;
except
end;
end;
end;
function Galileo_FindMapInMapLoop(SmallMap, LargeMap: T3DIntegerArray; sidelength: integer; mintol, maxtol, tolstep: extended; minfails, maxfails, failsstep: integer): TPoint; register;
var
fails: integer;
tol: extended;
begin
tol := mintol;
while (tol < maxtol) do
begin
fails := minfails;
while (fails < maxfails) do
begin
Result := Galileo_FindMapInMapExx(LargeMap, SmallMap, sidelength, tol, fails);
if (Result.X > 0) and (Result.Y > 0) then
Exit;
fails := fails + failsstep;
end;
tol := tol + tolstep;
end;
end;
//////
function GetFunctionCount(): Integer; stdcall; export;
begin
Result := 3;
end;
function GetFunctionCallingConv(x : Integer) : Integer; stdcall; export;
begin
Result := 0;
case x of
0..2 : Result := 1;
end;
end;
function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall; export;
begin
case x of
0:
begin
ProcAddr := @Galileo_ColorBoxesMatch;
StrPCopy(ProcDef, 'Galileo_ColorBoxesMatch(B1, B2: TIntegerArray; tol: extended): boolean;');
end;
1:
begin
ProcAddr := @Galileo_FindMapInMapExx;
StrPCopy(ProcDef, 'Galileo_FindMapInMapExx(LargeMap, SmallMap: T3DIntegerArray; SideLength: integer; tol: extended; MaxFails: integer): TPoint;');
end;
2:
begin
ProcAddr := @Galileo_FindMapInMapLoop;
StrPCopy(ProcDef, 'function Galileo_FindMapInMapLoop(SmallMap, LargeMap: T3DIntegerArray; sidelength: integer; mintol, maxtol, tolstep: extended; minfails, maxfails, failsstep: integer): TPoint;');
end;
else
x := -1;
end;
Result := x;
end;
exports GetFunctionCount;
exports GetFunctionInfo;
exports GetFunctionCallingConv;
begin
end.
And it compiles & builds successfully, but when I try to load the plugin in Simba, it says (again)
Code:
[Error] (2:1): Unable to register function Galileo_ColorBoxesMatch(B1, B2: TIntegerArray; tol: extended): boolean; at line 1
Damn I'm so close but yet so far!