Results 1 to 3 of 3

Thread: Function in plugin gives false results?

  1. #1
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default Function in plugin gives false results?

    Here's my plugin:
    Simba Code:
    library GALILEO;

    {$mode objfpc}{$H+}

    uses
      Classes, sysutils
      { you can add units after this };

    type
      TIntegerArray = Array of Integer;
      T3DIntegerArray = Array of Array of Array of Integer;


    function G_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))) and
           (B1[1] >= Round(B2[1]*(1-tol))) and (B1[1] <= Round(B2[1]*(1+tol))) and
             (B1[2] >= Round(B2[2]*(1-tol))) and (B1[2] <= Round(B2[2]*(1+tol))) then
             begin
               Result := True;
               Exit;
             end;
    end;

    procedure G_FindMapInMapEx(var fx, fy: integer; LargeMap, SmallMap: T3DIntegerArray; tol: extended); register;
    var
      x, y, HighX, HighY: integer;
      xx, yy: integer;
      Matching, BestMatch: integer;
    begin
      fX := -1;
      fY := -1;
      BestMatch := 0;
      HighX := High(LargeMap) - 19;
      HighY := High(LargeMap[0]) - 19;

      for x := 0 to HighX do
        for y := 0 to HighY do
        begin
          Matching := 0;
          for xx := 0 to 19 do
            for yy := 0 to 19 do
              if G_ColorBoxesMatch(LargeMap[x+xx][y+yy], SmallMap[xx][yy], tol) then
                Inc(Matching);

          if Matching > BestMatch then
          begin
            BestMatch := Matching;
            fX := x*5 + 50;  // cause we want the center
            fY := y*5 + 50;
          end;

        end;
    end;


    //////  TYPES //////////////////////////////////////////////////////////////////

    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 Array of Integer;';
          end;
        else
          Result := -1;
      end;
    end;




    //////  EXPORTING  /////////////////////////////////////////////////////////////
    function GetFunctionCount(): Integer; stdcall; export;
    begin
      Result := 2;
    end;

    function GetFunctionCallingConv(x : Integer) : Integer; stdcall; export;
    begin
      Result := 0;
      case x of
         0..1 : Result := 1;
      end;
    end;

    function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall; export;
    begin
      case x of
        0:
          begin
            ProcAddr := @G_ColorBoxesMatch;
            StrPCopy(ProcDef, 'function G_ColorBoxesMatch(B1, B2: TIntegerArray; tol: extended): boolean;');
          end;
        1:
          begin
            ProcAddr := @G_FindMapInMapEx;
            StrPCopy(ProcDef, 'procedure G_FindMapInMapEx(var fx, fy: integer; LargeMap, SmallMap: T3DIntegerArray; tol: extended);');
          end;
      else
        x := -1;
      end;
      Result := x;
    end;



    exports GetTypeCount;
    exports GetTypeInfo;
    exports GetFunctionCount;
    exports GetFunctionInfo;
    exports GetFunctionCallingConv;


    {$IFDEF WINDOWS}{$R GALILEO.rc}{$ENDIF}

    begin
    end.

    and the problem is that G_FindMapInMapEx keeps resulting (50, 50) as fx, fy, which means that it "finds" us at (0, 0) and then adds the 50 as constants. See the code and you'll understand.

    Regardless of the Minimap parameter values, it does the same. What to do?
    The problem could be, that ColorBoxesMatch always results True. If that is the case, why is that and how to solve the problem?
    Last edited by marpis; 01-12-2011 at 10:19 PM.

  2. #2
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Perhaps initialize Result to False in the beginning of the ColorBoxesMatch function?
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  3. #3
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Nava2 View Post
    Perhaps initialize Result to False in the beginning of the ColorBoxesMatch function?
    Oh, you're right, gotta try that tomorrow
    EDIT: Yeah that was it!
    Last edited by marpis; 01-13-2011 at 06:49 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •