Sign in to follow this  

JavaScript Pathfinding - Split into several "Ticks"

This topic is 1907 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[i](Sorry, First Post, Please move to Game Programming if needed)[/i]

I want to run Astar for my Pathfinding on every Unit.


I would like to reduce possible lag by only using it for X amount of units per game tick.

So that the [b]"For each Unit"[/b] loop does not run pathfinder for every unit before it goes on to the next function.

Instead it should only find the Path of a few Units each time the [b]Game Loop[/b] is at the Pathfinding Function again.


I am pretty sure I gotta run this with a Start-Stop Variables. But I don't know how that should look.

Here is a Quick Doodle how it might look:

[source lang="jscript"]var Unit = new Array(500);
var arrayStart=0;
var arrayStop=0;

"GameLoop"
{

// Checks If at start of Array
if (arrayStart = 0)
{
arrayStop = 50;
}
// Not the first unit. Set starting point to last Pathfind
else
{
arrayStart = arrayStop;
arrayStop = arrayStop + 50;
}

for (var count = arrayStart; count < arrayStop; count++)
{
"Pathfinder Function" Unit[count];
}
arrayStart = count;

};[/source]

Unless JavaScript [b]if [/b]functions are executed in a different manner, I would like to know if this is a viable solution, or if you got better ones. Edited by Schoening

Share this post


Link to post
Share on other sites
[quote name='Schoening' timestamp='1351428105' post='4994682']
I would like to reduce possible lag by only using it for X amount of units per game tick.
[/quote]

When you say "possible lag", that would suggest that you haven't yet verified it. I'd say verify that there is unacceptable lag in that loop first.
If you're always stopping the algorithm before it's done, how does that affect the rest of your artificial intelligence?

Share this post


Link to post
Share on other sites
[quote name='EmployeeNumber8' timestamp='1351444383' post='4994767']
When you say "possible lag", that would suggest that you haven't yet verified it. I'd say verify that there is unacceptable lag in that loop first.
[/quote]

Unacceptable Lag or not, I would still like to learn how to apply this.

[quote name='EmployeeNumber8' timestamp='1351444383' post='4994767']
If you're always stopping the algorithm before it's done, how does that affect the rest of your artificial intelligence?
[/quote]

I would only stop the algorythm for a few miliseconds. Instead of stoping the entire script for who knows how long..

I am going to do it the normal way, but I would still like some ideas on how to split it. Edited by Schoening

Share this post


Link to post
Share on other sites
Sign in to follow this