c# - Where/how to store cost for multiple objects without copy/clone? -


i have a* implemented in c# pointa , pointb being tile objects with. x, y, walkable, neighbours (size 8 list), cost.

my issue on backend online game server, , tile maps shared between monsters. don't want copy grid each monster trying move.

for example map looks like:

 tile[] tiles;   public this[int x, int y]  {   {return tiles[x + y * sizey];}  }  

before cloning tiles copy before each monster wanted calculate move. noticed using crap-load of memory. should store cost in a-star calculation assigned each tile (without copying grid)?

if array going sparse, i.e. a* looks in small region of map, represent map (e.g. dictionary in c#) of index value.

you consider priority queue of potential candidate objects, each of contains location, cost, heuristic value , reference previous candidate, , forget array completely.

although array of primitives should quite bit smaller array of objects of same length. make sure didn't make few copies (assuming you're not doing few in parallel), aren't overreacting memory used, , take account memory used elsewhere. keep in mind updating values in array should take less time creating new 1 , populating values there.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -