www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: fireside on March 04, 2008, 06:25:13 pm

Title: Java suggestion needed
Post by: fireside on March 04, 2008, 06:25:13 pm
I was wondering if someone would have a suggestion for this.  My gravity objects will have an active property.  When the object is active, I want it to be tested in the game loop for gravity, but not tested when it is not active.  So, what I have in mind, but am not sure how to implement, is a container for active objects.  This would be accessible from the main game loop.  The gravity objects would add themselves to this container when they are active and remove themselves when they are not active.  How could I make these objects have access to the container in the main class?   
Title: Re: Java suggestion needed
Post by: EgonOlsen on March 04, 2008, 07:34:35 pm
Personally, i prefer to keep those objects inside the container all the time, i.e. the container has a kind of process()-method that does the work on active ones and ignores inactives ones. If you store them in one list, iterate over them and do something if they are active or if you keep two lists in the container, one with all active, one with all inactive objects, is up to you. I usually prefer one list that stores them all, as long as this isn't a performance problem (what it isn't for just a few dozen objects).
I'm not saying that this is the best solution...it's just what i'm used to and what you can find in my sources (for example in the ParticleManager in the "advanced example" available in the download section).

Another solution: Make the container dumber and the objects more clever, i.e. let the container simply call a process()-method on each object and  let the object do the work. This approach may be more OO, because it keeps work that belongs to a single object inside the object. However, it's not what i'm usually doing in games programming.