FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   Working with rapidly changing numbers of objects?
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Working with rapidly changing numbers of objects?  (Read 529 times)
Elrick

4892360348923603
Working with rapidly changing numbers of objects?
« on: Apr 29th, 2003, 5:13am »

Okay, here's the plan:  I'm going to be placing circular objects randomly on the screen.  Each frame, these need to call a function, so I'll be storing them in an array, and looping through to update them.  Howver, the circles will also be randomly disappearing, after which they no longer need to update.
 
Now, two problems:  Is there an uber-efficient way to 'skip over' the ones that have disappeared (such as deleting them and reconstructing them when needed again?), and, because I don't know how many there will be total, how do I create the array to store them?
 
I have a few ideas I'm going to toy with, but I'd love some input.
 
EDIT:  Well, I found a post on dynamically enlarging arrays..  Still trying methods of the skipping.  This is what I'm doing for now:
 
Each circle object has a property, active, and it only runs it's updating instructions if active is true.  When a new circle is being created, a loop runs through all the created circles, takes the first one that is inactive, and modifies it to suit the purpose.  If none are inactive, it creates a new one.  Phew!
 
Still open to suggestions.
 
EDIT:  Okay, that worked great.. so, never mind!
 
~Graham
« Last Edit: Apr 30th, 2003, 4:23am by Elrick »  
fry


WWW
Re: Working with rapidly changing numbers of objec
« Reply #1 on: May 1st, 2003, 5:09am »

for maximum speed, use that growable array code posted elsewhere on the board, and keep two arrays. one of the 'in-use' objects to iterate over, and the other with the 'dead' objects.  
 
sometimes--for instance in an n-squared loop where everything in the list is compared against everything else--it will be inefficient to check if each is 'inactive', since the largest time cost will be traversing the array. that make sense? (sorry, end of the day)
 
Pages: 1 

« Previous topic | Next topic »