1

i'm developing a 2d game , rts game, is sort of like COC (Clash of Clans). cool mobile game,huh. but i run into some problem with path-finding, as usual,i do path-finding algorithm once every agent was placed somewhere in screen by finger-touch,but in some case, this incur performance penalty, and your mobile phone will be very hot as your agents increase suddenly and simultaneously.

actually,no matter what path-finding i use,e.g a*,dijkstra, or something special(maybe optimal),which is always time-comsuming process throughout the whole game loop ,especially massive agents on less powerfull mobile cpu. as far as i know, some game like this, shortest path is not the focus (will people care about the path agent walk through intentionally?) instead of efficient and naturally path-finding. so my mind come up with some solutions,maybe impractical.

solution 1 : use some cheaper path-finding algorithm, could be graph related or somethingelse because shortest path doesn't matter.

solution 2 : put some limits on ai module to process agent for path-finding, e.g upper limit to path-finding algorithm calls at interval,that is,just one or two agents of the those agents got planning, let rest of them plann after several game frames. as you know ,its drawback is obvious.

the above is what i thougt. hope your game dev disciplined guys give me brilliant idea , tricks, i'll appricate. thank you very much.

EDIT: here is my related pseudo code,and procedure cresspond to my game logic. //inside logic thread procedure putonagent if (need to put agent on world space) //do standard a* path-finding for an agent path_list=do_aStar_path_finding(attacktargetpos,startpos); and then enqueue path_list; ...... end the path_list's queue finally used by visual agents for stepping forward. any hints?

qxsl2000
  • 74
  • 5
  • The question is too broad. If you posted your code we may be able to pinpoint some optimizations, although you should post that on Code Review: http://codereview.stackexchange.com – CodeSmile Aug 30 '14 at 16:46

1 Answers1

1

Look up "Hierarchical pathfinding" Say you're driving to a city far away, you don't plan the entire path before you get in the car!

Pathfinding is usually done in steps, like it's not one function call, after N iterations it'll return (and indicate it's not complete) so it can be run at the next available time. Basically rather than a function with locals think operator() and state variables as members of a class.

To make it fast you can make the heuristic crap with A* pathfinding, suppose I use a heuristic of 10* the distance-as-the-crow-flies, it may not find the shortest path but it will have a strong preference for heading towards the target rather than "fanning out" and exploring further around the closed region.

Alec Teal
  • 5,770
  • 3
  • 23
  • 50
  • really so sorry about this post. it's been long time.cause the stackoverflow was blocked somehow in my country.:| – qxsl2000 Nov 27 '14 at 03:42