Jump to content

  • Log In with Google      Sign In   
  • Create Account

JavaScript Pathfinding - Split into several "Ticks"


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Schoening   Members   -  Reputation: 141

Like
1Likes
Like

Posted 28 October 2012 - 06:41 AM

(Sorry, First Post, Please move to Game Programming if needed)

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 "For each Unit" 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 Game Loop 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 Arrayif (arrayStart = 0){arrayStop = 50;}// Not the first unit. Set starting point to last Pathfindelse{arrayStart = arrayStop;arrayStop = arrayStop + 50;}for (var count = arrayStart; count < arrayStop; count++){"Pathfinder Function" Unit[count];}arrayStart = count;};[/source]

Unless JavaScript if 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, 28 October 2012 - 06:51 AM.


Sponsor:

#2 EmployeeNumber8   Crossbones+   -  Reputation: 1103

Like
0Likes
Like

Posted 28 October 2012 - 11:13 AM

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


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?

#3 Schoening   Members   -  Reputation: 141

Like
0Likes
Like

Posted 28 October 2012 - 12:08 PM

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.


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

If you're always stopping the algorithm before it's done, how does that affect the rest of your artificial intelligence?


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, 28 October 2012 - 05:45 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS