Dynamic A* Pathfinding 3.2

Advanced game related topics
Heathen
Enthusiast
Enthusiast
Posts: 498
Joined: Tue Sep 27, 2005 6:54 pm
Location: At my pc coding..

Post by Heathen »

Sorry guys, forgot to update the example. My brain wasn't working this morning :P

Anyhow, it's been updated.


PS: I want to rewrite the example, it's quite sloppy right now.
I love Purebasic.
untune
User
User
Posts: 56
Joined: Sun Jul 06, 2008 10:07 pm
Location: Bolton, UK

Post by untune »

Heathen wrote:Sorry guys, forgot to update the example. My brain wasn't working this morning :P

Anyhow, it's been updated.


PS: I want to rewrite the example, it's quite sloppy right now.
Runs fine now, great work :D
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4326
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

Thats it! Nice!!! 8)
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

Post by superadnim »

Question: why did you use .c (character) instead of .b for the speed field on the player structure? you also seem to use .c for a lot of things, know that if I compile as unicode those characters will be 2 bytes long and not 1 byte as .b is. I know they're unsigned but what's wrong with using .b? :? If it's due to the debugging "issue" then do & $FF and it should debug just fine, shouldn't it?.

Aside from that I loved the updated code - I just wanted to point that out though :)

Code: Select all

Macro DebugB(_var_) : Debug _var_ & $FF : EndMacro

Define.b var = 231

Debug var
DebugB(var)
Oh, another question: is it faster or slower than before?. I remember you were using PB arrays before the dynamic code, any possibility of a benchmark? :D

:lol: should I bash the keyboard and give up?
:?
Heathen
Enthusiast
Enthusiast
Posts: 498
Joined: Tue Sep 27, 2005 6:54 pm
Location: At my pc coding..

Post by Heathen »

There isn't too much of a speed difference in the newest version, if anything, it will be slightly faster because of some small optimizations I made, this was mostly a bug fix update. I'll remove most of the chars, I don't remember why I used them, besides the priority array which I wanted to be from 0-255.
I love Purebasic.
Heathen
Enthusiast
Enthusiast
Posts: 498
Joined: Tue Sep 27, 2005 6:54 pm
Location: At my pc coding..

Post by Heathen »

Small update: Replaced chars with bytes.
I love Purebasic.
User avatar
zxtunes.com
Enthusiast
Enthusiast
Posts: 375
Joined: Wed Apr 23, 2008 7:51 am
Location: Saint-Petersburg, Russia
Contact:

Post by zxtunes.com »

Too hard Example. Only for advanced porgramers. :(
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Post by Inner »

how would this work in 3D?
Heathen
Enthusiast
Enthusiast
Posts: 498
Joined: Tue Sep 27, 2005 6:54 pm
Location: At my pc coding..

Post by Heathen »

zxtunes.com wrote:Too hard Example. Only for advanced porgramers. :(
Yes, the example is pretty sloppy and a bit bloated. The engine itself is pretty straightforward though. I may write a more simple example.
inner wrote: how would this work in 3D?
This engine is 2d only.
I love Purebasic.
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Post by Inner »

Heathen wrote:
inner wrote: how would this work in 3D?
This engine is 2d only.
It could work in 3d you'd just lose your Z axis, which you could fake by having the object detect ground level on the Z axis, or am I over reaching here?
Heathen
Enthusiast
Enthusiast
Posts: 498
Joined: Tue Sep 27, 2005 6:54 pm
Location: At my pc coding..

Post by Heathen »

Inner wrote:
Heathen wrote:
inner wrote: how would this work in 3D?
This engine is 2d only.
It could work in 3d you'd just lose your Z axis, which you could fake by having the object detect ground level on the Z axis, or am I over reaching here?
Yes of course, you can technically use it in any environment, I meant that there's no support for the Z axis. Although, adding the third axis in the form of 2d 'layers' or 'floors' should be fairly trivial. I'll probably end up adding that in the future since the game I've been making with this will need it eventually.
I love Purebasic.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4326
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

Great Job! I think this is very useful!:D
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
AndyLy
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Jan 04, 2011 11:50 am
Location: GRI

Re: Dynamic A* Pathfinding 3.2

Post by AndyLy »

Also decided to try this method, but in the example of a lot of unnecessary.
Wrote a simple example, for myself, to see how it works. Maybe someone will need it.

Code: Select all

InitSprite()
XIncludeFile "pathfinding.pbi"
#tilesize = 20: #width = 35: #height = 30
Global Dim blocked.c(#width-1,#height-1): For i=1 To 200: blocked(Random(#width-1),Random(#height-1))=1: Next
pathfind.pathfinding_structure
pathfind\Width = #width: pathfind\height = #height: pathfind\blocked = @blocked()
mnstrX=0: mnstrY=0: blocked(mnstrX,mnstrY)=0
plrX=20: plrY=15: blocked(plrX,plrY)=0

path=get_path(mnstrX,mnstrY,plrX,plrY,pathfind): pathsize = path_get_size(path)

OpenWindow(0,0,0,640,480,"Example",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0),0,0,WindowWidth(0),WindowHeight(0),0,0,0)
 Repeat: StartDrawing(ScreenOutput()): DrawingMode(4)
     For i=0 To #height-1: For j=0 To #width-1: If blocked(j,i)=1: col=#White: Else: col=#Gray: EndIf
          Box(j*#tilesize,i*#tilesize,#tilesize,#tilesize,col): Next: Next
     For i=0 To pathsize-1: Box(path_get_x(path,i)*#tilesize,path_get_y(path,i)*#tilesize,#tilesize,#tilesize,#Red): Next
     Box(mnstrX*#tilesize,mnstrY*#tilesize,#tilesize,#tilesize,#Yellow): Box(plrX*#tilesize,plrY*#tilesize,#tilesize,#tilesize,#Green)
 StopDrawing()
FlipBuffers()
event = WaitWindowEvent(1)
Until event = #PB_Event_CloseWindow
'Happiness for everybody, free, and no one will go away unsatisfied!'
SMsF town: http://www.youtube.com/watch?v=g6RRKYf_Pd0
SMf locations module (Ogre). Game video: http://www.youtube.com/watch?v=ZlhBgPJhAxI
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: Dynamic A* Pathfinding 3.2

Post by Fig »

Hi,

Could you explain what you mean by "dynamic" ?

thx
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: Dynamic A* Pathfinding 3.2

Post by Fig »

Is anybody can answer my question please ?

Does your dynamic pathfinding means you use a reservation table for cooperative pathfinding of multi-agents to prevent collisions ?
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
Post Reply