This project has moved. For the latest updates, please go here.

Tile Map and Static Bodies

Jan 31, 2012 at 8:03 PM

I have a large tile map of tiles where each tile is a farseer static body rectangle. I also have NPC's that are offscreen that are doing things and need to check for collision. However, I think it is impossible to load this many farseer static bodies at once. What is the amount of static bodies that can be reasonably loaded and iterated through for collision? My tilemap is 10,000 x 10,000, and I doubt I can load that many static bodies in farseer. And is there a way to make farseer dynamic bodies have simple collision with non-farseer objects(my tile map), so that I don't even have to have static bodies? Thanks.

Jan 31, 2012 at 9:55 PM

That map is huge. I mean even if it were possible to simulate it it's 100M objects! If each has 100b of state information (think also rendering, sprites) how much memory would that take? 10Gb...

Static bodies are pretty fast but I can tell you in my current project on a decent PC 300 dynamic bodies each with 3 joints already prove too much to handle so we're way off scale.

I don't exactly what your situation is from a brief description but it seems you need to implement some form of dynamic paging system where each actor only interacts with a small space that is dynamically loaded. For example create a separate world 10x10 tiles around the actor (pc or NPC) and let it move around the tilemap as the actor moves destroying the bodies that go out of range and creating new ones in the proximity. Won't be that hard to implement with some careful thought. Even faster if your tilemap is made of 10 unique configurations then precreate a pool of objects far away and just teleport them dynamically (Body->Position) when they come in sight.

For a complex paging system I could point you to the excellent Ogre Paged Geometry which has some great ideas implemented and working beautifully for 3D forests with huge amount of trees (we're talking milions). 

P.S: you can't have collision with non-physics entities i.e. objects that are not made known to the physics engine. 

Jan 31, 2012 at 11:31 PM
Edited Jan 31, 2012 at 11:32 PM

If Position+LinearVelocity is on a blocked place, reduce the LinearVelocity vector. You don't even need to iteratively reduce the vector until you reach an 'unblocked' space, instead snapping the LinearVelocity based on gridwidth/height.

Feb 1, 2012 at 4:35 PM

Thanks for the replies. That was the system I was thinking of doing jerrysb. I wasn't sure if that was an insane idea though, so I'm glad I wasn't too far off base. And that makes sense as well, fnorder. Thank you very much for all the replies, I really appreciate it. 


One last thing, if dynamic bodies go from moving to static, do they stop taking up any processing time? Is it possible to have a lot of dynamic bodies that became inactive and still have the program be fast, as long as you don't have a lot of active dynamic bodies? Thank you.

Feb 1, 2012 at 9:15 PM

If bodies are not awake they get excluded from any calculations so their cost is only because they occupy space in the data structures that are iterated over.