looks like i need to speed up terrain collision checks in Caveman 3.0.
game description:
http://www.gamedev.net/blog/1730/entry-2258672-caveman-v30-general-desciption/
right now, it checks the world map to get the terrain type(s) present, then checks for collisions for the terrain type(s).
example:
i'm testing with a savegame. the terrain is non-tropical savanna with rocks and a creek.
movement collision checks test each entity vs a sparse matrix list of rocks, a sparse matrix list of trees, and a list of world objects (big stuff like shelters, lean-to's, bedding, fires, etc). each rock in turn is tested vs the creek and skipped if its in the creek, same with trees. trees are also tested vs world objects (no trees in huts!). needless to say, iterating through all these lists is SLOOOOW! <g>
so i'm thinking of using collision maps. due to the size of the game world, they would have to be generated on the fly as needed the way terrain chunks are. so collision maps would be generated on the fly as needed, and stored in a cache, with LRU discard.
the resolution defined for the map will determine the resolution of collision detection possible. in the game i use a scale of 1 d3d unit = 1 foot. so i figure i can get away with a collision map with a scale of 1 unit = 1 foot.
so then i choose a size for collision maps, say 300x300, the size i use for terrain chunks. when i need a map, i go through the world map data and add the rocks, trees, shelters, etc to the collision map. a zero indicates clear, a non zero value indicates some type of object, and the value tells you what kind or which object. testing for collisions is simply a matter of checking the collision map for non zero values in the squares of interest.
new collision maps would only need to be generated when entities and or the player moved far away (about 300 feet). caching of 20 or so maps would keep the number of regens to a minimum.
but how to handle edge cases when an object is at the edge of one map but its radius extends into the next map? just have to code for it?
all this seems a bit complex, but it seems to be the best solution. any alternatives come to mind?
a quick search of the literature online came down to basically subdivision or grids, and grids seemed faster.
timing tests have isolated terrain collision checks as the primary bottleneck in the new AI. the goal is to have 100+ entities active in a small area all mulling about. I'm currently using large herds of 40 or so hippidions (proto-horses) for the testing.
terrain collision checks right now are on the order of 2000+ ticks per moving entity. pretty much all the rest clocks in in the single or double digits for ticks.
any suggestions or advise would be appreciated. i figured out collision maps a while ago (except for edge cases with multiple tiled maps), but have never used them before in a game (at least that i recall - been doing this a long time...).
a quick check of the code reveals that in the test case above, a single entity is currently checked for collisions with 260 trees and 1300 rocks in an 800x800 sparse matrix "plant map".