[as3]Making calculations step by step

12 posts

 In my game i have multiple objects, which use pathfinding almost always. If i have at least 15 of them, game is almost unplayable – pathfinding calculations are always freezing it for little time, but it is annoying. A book suggests making an array of calculations and an object(a class), which will go through that array and make some calculations on each element of array. That way everything shall go smoothly and without freezes, as ammount of calculations shall be limited to the number where it wont freeze. Now, for the questions: 1)What is a good ammount of calculations which game can do without freezing? How can i find it? Obviously, some processors are faster and some are slower, so is there any way to adjust it for each processor? 2)Is it the good way to solve the problem of freezes or is there a better solution? Or did i get the idea wrong and i shall do something else there? I have a hard time understanding how you can have your game freeze with 15 objects doing some pathfinding. It’s not the sort of problem you should be running into before you have hundreds of hundreds of objects. While there are techniques for doing the calculations “step by step” across several frames, I would instead advice you to find out why the pathfinding is taking up so much resources. Are you continuously recalculating the path every frame? If so, saving the results into the object would lessen the burden several hundred times over. Well, i tested it on a small space, where all of 15 objects would block each others path. Even with them waiting few seconds(to check if path is clear again) before calculating path again they have to run pathfinding algorythm oftenly. So that can be counted as path being countinuously recalculating. Even if this is an error, there will be problems with hundreds of them. Can you help me on that topic? Are you using an array as your map? Post the path-finding parts of your code here (or pastebin it), and we will see what is taking such a heavy tax. ` function PathFind(x1, y1, x2, y2, w2, h2) { var curc = Global.map[x1][y1]; var dest = Global.map[x2][y2]; var firstc = curc; var f; var g; var h; var maxd = Global.Dist(x1,y1,x2,y2); var scan = 0; w1 = w2; h1 = h2; opened = []; closed = []; curc.g = Global.map[x1][y1].Occupied.length; curc.f = ManH(x1,y1,x2,y2); curc.h = curc.f while (curc!=dest) {; scan++; GetNei(curc.x, curc.y); for (var i = 0; i