This project has moved and is read-only. For the latest updates, please go here.

Pre-definition vs. Re-definition

Apr 28, 2009 at 2:54 AM
Hey guys,
I gotta say I'm quite impressed by what you're all doing here.  I've been following Farseer from the shadows for some time now and I'm glad to see the community is still going strong!  I have a question or two I was hoping you might be able to answer...

I've been working on a side-scroller shoot 'em up and I'm trying to set it up so that there are as few restrictions as possible in what type of objects the player might come across.  For example, when an enemy is encountered, it could be a tiny one, a huge one, a square one, etc, etc. or when a bullet is fired it could be a bullet, a bomb, a beam, etc. etc.  Each of these might have any range of physics sizes and properties required.  What I'm wondering, is how best to implement the physics for an approach like this.  I've been thinking about it and I can think of a couple ways to go about it...

I think the most convenient way would be to Pool enemies, bullets, etc with predefined physics entities.  But when they're drawn from the Pool, they would need to be resized and reconfigured according to their relative specifications.  Would there be any problem with feeding a Geom a new Body and set of Vertices each time a new object instance is needed?  To be more concise... is it possible to re-define a Body/Geom on the fly without problems, and if so, is it better or worse than creating entirely new ones on the fly?

The other approach I could see working would be to decide before hand that you might have 100 large enemies, 50 tiny ones, 125 square ones, whatever, and then to Pool and predefine the physics entities for each of them... drawing upon them as needed.  This would alleviate much of the guesswork, but it seems to me like it could be a waste of space or restrictive perhaps.

Anyways, your thoughts and suggestions would be much appreciated.
Apr 28, 2009 at 3:00 AM
What you could also do is have your enemies appear randomly by dumping them all into a big pool and whatever you pull out 1 by 1 is what the player faces next. This probably wouldnt work with weapons but it seems like a start.
Apr 28, 2009 at 3:35 AM
Thanks for the quick reply.  I'd considered this, but for the purpose of the game context I'm interested in particular enemies appearing in certain areas/at certain times.  Are you suggesting I try and figure out all possibilities of encounters when the level loads and just call on them as needed then, rather than worry about a smaller amount of physics objects being reused?  I can set up either way, I'm just trying to figure out what the best approach might be... if there even is a best approach.
Apr 28, 2009 at 6:54 AM
Edited Apr 28, 2009 at 7:29 AM
Well the only solution i can think of then is to have separate pools of enemies which you pull out of. I'm gonna see if i can build a segmented pool (where you can put in and pull out various types), ill get back to you. Edit: Sorry it seems that i know less about generics than i thought. Multiple pools would be the way to go.
Apr 28, 2009 at 5:54 PM
I did some preliminary work on this last night trying to investigate what kind of limitations the physics engine gave me.  Surprisingly, I was able to predefine a set count of bullets and enemies with placeholder associated physics, all disabled initially, but call them out of the pool as needed.  I have quite a bit more work and investigation to go yet... but I'll keep you posted as to how it pans out should anyone else need a similar approach in the future.