Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: AStar Dll

  1. #1

    AStar Dll

    I created an Astar dll. and got it working with TB thanks to Eros. Its very fast and easy to use.
    Here is the sample script I use to test it on a 100x100 map. It gives me about 100 paths a second.
    Note: the array returned by 'GetRoute' is owned by the dll, don't try to free it.

    uses "CONSOLE"
    randomize
    
    DECLARE function SetupMap LIB "C:\Dev\path.DLL" ALIAS "SetupMap" (byval arrayhandle as long, byval Width as long, byval Height as long, byval Diag as long) as long
    DECLARE function FindPath LIB "C:\Dev\path.DLL" ALIAS "FindPath" (byval StartX as long, byval StartY as long, byval DestX as long, byval DestY as long) as long
    DECLARE function GetRoute LIB "C:\Dev\path.DLL" ALIAS "GetRoute" ( length as long) as long  '// its byref
     
    const _SIZE as long = 100
    dim pMapArr as long
    pMapArr = heap_alloc(_size * _size * sizeof(LONG)) '---<<<< ALLOCATE memory
    dim i,j as integer
    dim arr(_SIZE,_SIZE) as single at pMapArr
    dim a,b,c,d,e as long
    dim g as long = 1
     
    a=_SIZE
    b=_SIZE
    c=2
    
    '// Create test map with random val [0.0,1.0]
    for i = 1 to _SIZE
      for j = 1 to _SIZE
        arr(i,j) = rnd '// a value of >=1 is considered a wall, < 1 is difficulty 
      next
    next
    
    print SetupMap(pMapArr,_SIZE,_SIZE,2) , $crlf '// pass the map
    
    sleep(500)
    for g=1 to 99999
      FindPath(0,0, rnd(1,_SIZE-1), rnd(1,_SIZE-1) )
      if mod(g, 100) = 0 then printl g & " findpath calls."        '// 
    next
    
    sleep(500)
    d=GetRoute(e)                 '// [e] is length of the route, [d] is the array pointer
    print e, $crlf
    
    dim f(e) as long at d '// create an array of [e] size and point to addr [d]               
    
    waitkey
    
    Attached Files Attached Files
    Last edited by ErosOlmi; 02-11-2015 at 21:48.

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: AStar Dll

    MouseTrap,

    in order to avoid thread "invasion", I splitted you post (this one) to a new post. We usually prefer to have forum as easy as possible.
    Michael posted a thread to have some feedback about a new module. If we post in the same thread another project we will have a mess.
    I think it can be good also for your project.

    I hope you understand.
    Thanks a lot
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3

    Re: AStar Dll

    Hi,
    I didn't mean to hijack his thread.
    As his example was doing pathfinding, I was just giving away that dll I made.
    I mistook the subject of the thread to be pathfinding rather than his module..

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: AStar Dll

    Ok, perfect.

    I'm quite curious about your opinion on thinBasic. You seems very advanced so I feel you can give us a lot of precious feeling/indications about how to improve thinBasic.

    In the meantime I'm testing your script.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: AStar Dll

    MouseTrap,

    how can I get the path info?
    GetRoute returns the length of the path and a pointer but how to get the exact path from A to B?

    Thanks a lot
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #6

    Re: AStar Dll

    Oops!
    sorry i forgot to mention that. ;(
    that path is returned as a 1d array in the format of:

    X,y,X,y,X,y...

    Also the beginning of the array is the *destination. so the array is reversed in the normal way of thinking..

  7. #7

    Re: AStar Dll

    Quote Originally Posted by MouseTrap
    Hi,
    I didn't mean to hijack his thread.
    As his example was doing pathfinding, I was just giving away that dll I made.
    I mistook the subject of the thread to be pathfinding rather than his module..
    No problem. I just wanted to know if my module works ok so far.

  8. #8

    Re: AStar Dll

    ya, it worked great and i couldnt get the framerate to drop below 60 [vsync]
    is there a way to to do async rendering in the that graphics module?

    btw: if anyone wants the source of the dll, just say so.

  9. #9
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: AStar Dll

    Quote Originally Posted by MouseTrap
    that path is returned as a 1d array in the format of:

    X,y,X,y,X,y...

    Also the beginning of the array is the *destination. so the array is reversed in the normal way of thinking..
    Can you please post a little example on how to read path data back?
    I was making a script to draw the initial map and than draw the path but accessing return pointer as array seems returning always zeroes. I'm sure I'm making some error but do not know where.

    Thanks in advance.
    Ciao
    Eros

    PS: as Petr suggested, better to avoid to use DECLARE with a fixed path into DLL name. To avoid DLL hell, thinBasic adopt a special DLL path finding. You can get info on DECLARE help at http://www.thinbasic.com/public/prod...ml/declare.htm
    So just put your dll into script path or in mod\ directory or lib\ directory. thinBasic will find it.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  10. #10

    Re: AStar Dll

    Ok, here is a modified script to show the path.

    hit any key to show the path.

    uses "CONSOLE"
    randomize
    
    DECLARE function SetupMap LIB "path.DLL" ALIAS "SetupMap" (byval arrayhandle as long, byval Width as long, byval Height as long, byval Diag as long) as long
    DECLARE function FindPath LIB "path.DLL" ALIAS "FindPath" (byval StartX as long, byval StartY as long, byval DestX as long, byval DestY as long) as long
    DECLARE function GetRoute LIB "path.DLL" ALIAS "GetRoute" ( length as long) as long  '// its byref
    
    Console_SetScreenBufferSize(80,25)
     
    const _SIZE as long = 100
    dim pMapArr as long
    pMapArr = heap_alloc(_size * _size * sizeof(LONG)) '---<<<< ALLOCATE memory
    dim i,j as integer
    dim arr(_SIZE,_SIZE) as single at pMapArr
    dim a,b,c,d,e as long
    dim g as long = 1
     
    a=_SIZE
    b=_SIZE
    c=2
    
    '// Create test map with random val [0.0,1.0]
    for i = 1 to _SIZE
      for j = 1 to _SIZE
        arr(i,j) = rndf(0,1.3) '// a value of >=1 is considered a wall, < 1 is difficulty 
      next
    next
    
    print SetupMap(pMapArr,_SIZE,_SIZE,2) , $crlf '// pass the map
    
    sleep(500)
    ''for g=1 to 99999
      FindPath(1,1, 50,20)'rnd(1,_SIZE-1), rnd(1,_SIZE-1) )
    ''  if mod(g, 100) = 0 then printl g & " findpath calls."        '// call pathfinder
    ''next
    
    sleep(500)
    d=GetRoute(e)                 '// [e] is length of the route, [d] is the array pointer
    print e, $crlf
    
    dim f(e) as long at d '// create an array of [e] size and point to addr [d]               
    
    print f(1), f(2)
    
    for i= 1 to _size
      for j = 1 to _size
        console_printat(".",i,j) 
      next
    next    
    dim II as long = 1
    while ii < e
      console_printat("*",f(ii),f(ii+1))
      ii+=2
      sleep(300)
    wend
    
    waitkey
    
    Last edited by ErosOlmi; 02-11-2015 at 21:48.

Page 1 of 2 12 LastLast

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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