From: marpis
You can see my pluginproblems here:
http://villavu.com/forum/forumdisplay.php?f=384
Wizzup said this is because Simba can't export T3DIntegerArray.
As soon as that's possible, I have a complete 100% color based world positioner and soon a walker too. Meaning, I already have a working method of getting your tile with color, its just sooo slow it needs a plugin.
https://github.com/MerlijnWajer/Simba/pull/8To Export T3DIntegerArray:
function GetTypeCount(): Integer; stdcall; export;
begin
Result := 1;
end;
function GetTypeInfo(x: Integer; var sType, sTypeDef: string): integer; stdcall;
begin
case x of
0: begin
sType := 'T3DIntegerArray';
sTypeDef := 'array of array of TIntegerArray;';
end;
else
Result := -1;
end;
end;
exports GetTypeCount;
exports GetTypeInfo;
Really simple!
Here's Galaleo: (It compiles with that patch and hopefully runs)
Note: For some reason Galileo_ColorBoxesMatch always reported True with you previous code, I changed it to this and it now works.
library Galaleo;
{$mode objfpc}{$H+}
uses
Classes, sysutils;
type
TIntegerArray = array of integer;
T3DIntegerArray = array of array of TIntegerArray;
function Galileo_ColorBoxesMatch(B1, B2: TIntegerArray; Tol: extended): boolean; register;
begin
Result := (B1[0] >= Round(B2[0] * (1.0 - Tol))) and
(B1[0] <= Round(B2[0] * (1.0 + Tol))) and
(B1[1] >= Round(B2[1] * (1.0 - Tol))) and
(B1[1] <= Round(B2[1] * (1.0 + Tol))) and
(B1[2] >= Round(B2[2] * (1.0 - Tol))) and
(B1[2] <= Round(B2[2] * (1.0 + Tol)));
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 GetTypeCount(): Integer; stdcall; export;
begin
Result := 1;
end;
function GetTypeInfo(x: Integer; var sType, sTypeDef: string): integer; stdcall;
begin
case x of
0: begin
sType := 'T3DIntegerArray';
sTypeDef := 'array of array of TIntegerArray;';
end;
else
Result := -1;
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, 'function Galileo_ColorBoxesMatch(B1, B2: TIntegerArray; tol: extended): boolean;');
end;
1:
begin
ProcAddr := @Galileo_FindMapInMapExx;
StrPCopy(ProcDef, 'function 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 GetTypeCount;
exports GetTypeInfo;
exports GetFunctionCount;
exports GetFunctionInfo;
exports GetFunctionCallingConv;
begin
end.