ID:268154
 
Well, in one of my games, I need to know the accessable turfs you are able to go to by stepping only a set amount of times non-diagonally. I made it so an object steps to areas with intelligence, so I used Deadron's PathFinding library. The thing is, it is super slow. Since PathFinding uses lots of procedures, it has to do it all the time. Otherwise, if I use a dumb "walk_to"er, there'd be no problem. Is there any way to speed things up, without it being really stupid? (And yes, I have read the forums and checked hub entries for different solutions.) Here's what I have now.

Thanks in advance,
~~> Dragon Lord
Unknown Person wrote:
> proc/advance_basewalkto2(atom/movable/A, atom/B, sleeptime)
> while(A&&B&&sleeptime)
> sleeptime --
> A.base_StepTowards(B)
> if(A in B)
> return 1
> sleep(sleeptime)
> return 0
>


I don't think "sleep(sleeptime)" is what you want there. If you call the proc with a sleeptime of 10, A takes a step, sleeps 9 ticks, steps, sleeps 8 ticks, steps, sleeps 7 ticks, etc. so it takes 45 ticks (4.5 seconds) to return if it can't reach B in 10 steps.

Change that line to "sleep()" and it will only sleep if the CPU is in heavy use, probably returning the results within the same tick for short checks.

Another note, "if(A.loc == B)" takes less processor power than "if(A in B)", because checking "in" requires the program to loop through B.contents to see if A is there. The loc check is a single simple comparison no matter how many atoms are in B.
In response to Shadowdarke
Shadowdarke wrote:
Unknown Person wrote:
> > proc/advance_basewalkto2(atom/movable/A, atom/B, sleeptime)
> > while(A&&B&&sleeptime)
> > sleeptime --
> > A.base_StepTowards(B)
> > if(A in B)
> > return 1
> > sleep(sleeptime)
> > return 0
> >

I don't think "sleep(sleeptime)" is what you want there. If you call the proc with a sleeptime of 10, A takes a step, sleeps 9 ticks, steps, sleeps 8 ticks, steps, sleeps 7 ticks, etc. so it takes 45 ticks (4.5 seconds) to return if it can't reach B in 10 steps.

Thanks, I forgot to delete that part from the origional one.

Change that line to "sleep()" and it will only sleep if the CPU is in heavy use, probably returning the results within the same tick for short checks.

This'll help a lot also.

Another note, "if(A.loc == B)" takes less processor power than "if(A in B)", because checking "in" requires the program to loop through B.contents to see if A is there. The loc check is a single simple comparison no matter how many atoms are in B.

That'll also help a lot.


Thanks, Shadowdarke. It's way faster now. If any other comments could make it even faster (:D), it'd be appreciated.

~~> Dragon Lord
One thing you're doing wrong is using newlist() where it doesn't belong. You should be using list() there.

Lummox JR