SRL Archive - Suggestions

Exportable types to plugins


marpis

2010-12-23 04:33:35

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.

TomTuff

2010-12-23 05:38:06

this is gonna sound nooby, but how does a plugin make things go faster? :o

offtopic: how does it work?!?

Wizzup?

2010-12-23 07:45:55

From: TomTuff
this is gonna sound nooby, but how does a plugin make things go faster? :o

offtopic: how does it work?!?


The code you write in Simba is ``interpreted'' by the machine. Just assume that interpreting is a lot slower than ``compiling code to machine code''. Machine code can be executed directly. A plugin is native machine code. Code interpreted in Simba is not. Plugins are about 1000 times faster.

Dgby714

2010-12-23 09:13:25

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/8

To 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.

Wizzup?

2010-12-23 09:35:13

Note that what Dgby just posted is his patch to add support for this. This is not yet in 750.

marpis

2010-12-24 04:37:12

From: Dgby714
https://github.com/MerlijnWajer/Simba/pull/8

To 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.


Thanks a lot! I'll try this as soon as I get home from my parents.
I didn't think of that solution because I thought it would give me an error about double-declared types.

Merry christmas! :)

Dgby714

2010-12-24 04:52:50

From: marpis
Thanks a lot! I'll try this as soon as I get home from my parents.
I didn't think of that solution because I thought it would give me an error about double-declared types.

Merry christmas! :)


You will have to compile Simba yourself for the time being the patch is now in the Simba repo but is not in the public version of Simba, I hear Wizzup will be releasing another version soon so it might be in that one.

marpis

2010-12-24 05:46:03

From: Dgby714
You will have to compile Simba yourself for the time being the patch is now in the Simba repo but is not in the public version of Simba, I hear Wizzup will be releasing another version soon so it might be in that one.


Ahh, ok I was too hasty of excitement. I'll wait til ray or wizz put your patch to official simba :) I probably wouldn't know how to compile it myself

Dgby714

2010-12-24 06:14:35

From: marpis
Ahh, ok I was too hasty of excitement. I'll wait til ray or wizz put your patch to official simba :) I probably wouldn't know how to compile it myself


If you'd like to get your plugin all ready and tested, You can use mopars latest hourly.

Wizzup?

2011-01-09 06:54:04

Marpis, tried it with 0.95RC yet?