Fast way to determine if position is occupied (and ideally, terrain)



  • It would be nice if there was a fast way to determine if a room position was unoccupied (available to be moved onto). Room.lookAt() is really slow, and even just Room.lookForAt('terrain') to determine if a wall is present is too slow to use at scale for pathfinding routes even a single move long.

    I assume you must have some accelerated backend way of doing this withing findPath, if so it would be awesome to expose that to the API.



  • don't do it every tick, do terrain once and store it in memory, do structures and others every X ticks.



  • I actually do store the result for cells which have been previously requested. Doing it for every cell of every room would be a lot -- 2500 cells per room, times 10 rooms..I'd have to write a procedure for spreading the init out over many ticks, because I wouldn't be able to do even one room in one tick..and then pack it into a really efficient storage format, one byte per cell max. It's all doable, but seems like an unnecessary pain in the butt. The goal is for this to be fun, right?



  • One byte per cell for terrain? You need only 2 bits - http://jsfiddle.net/e34gbs4h/4/


  • Dev Team

    Doing it for every cell of every room would be a lot -- 2500 cells per room, times 10 rooms

    Try Room.lookAtArea instead, it is much faster.



  • Wow, OK, yeah, doing lookForAtArea('terrain', 0,0,49,49) is super fast. Even lookAt for the whole room is much faster than I expected. Thanks!

    I'm curious to hear from other players, do you just lookAt the whole room at the beginning vs. using various individual look/find calls?



  • nugarin, I notice in your example that you avoid lookForAtArea because of it being buggy, which I had also experienced -- does anyone know if those bugs have been fixed yet?



  • Not sure if it has been fixed, but problem with lookForAtArea(WHAT,..) is that it returns only the one item of the same type on a given cell - at least it used to.
    This obviously can't work for structures. One would think that it would be OK for terrain, but I've seen map tiles that have a wall and a swamp on the same tile - lookForAtArea('terrain',...) returns one of them, so you'd treat the cell walkable, while it's not, or the other way aroun.