Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualSchoening

Posted 28 October 2012 - 06:51 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.

#3Schoening

Posted 28 October 2012 - 06:50 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.

#2Schoening

Posted 28 October 2012 - 06:46 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];}};[/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.

#1Schoening

Posted 28 October 2012 - 06:41 AM

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];}};[/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.

PARTNERS