I fully agree with you. In my particle system which involves the use of
STL's linked-list templates, I pre-allocate a big amount of particles when
the client.dll is loaded. When a particle is allocated I just pick
an unused particle from the pre-allocated array and append it to the
linked-list. If a particle is freed I just mark it as unused and save the
pointer, so on an allocation I can use it instantly without iterating
through the particle array to find a free one. This works very well and I
can have tons of particles. The memory allocation/deallocation is a _very_
important spot. I got a speed increase of about 100% (or even more) when I
decided to use a pre-allocated array in combination with the linked-list.
Only thing that makes it still slower than I want it, is the iteration that
occurs most of the time to find a free particle in the array. Just think of
_not_ doing it this way:

for (int i=0;i<MAX_PARTICLES;i++)
{
         if ( !m_pMyArray[i]->bInUse )
                 return &m_pMyArray[i];
}

as this takes the program to offset into the array everytime the inner loop
is executed (therefore MAX_PARTICLES times) and it probably occurs
several times a frame (and as you can imagine this can be pretty much).
Therefore rather use this:

CParticle* p = &m_pMyArray[0];
CParticle* pLastElement = &m_pMyArray[MAX_PARTICLES-1];
while ( p < pLastElement && p->bInUse ) p++;

This eleminates the offsetting into the array and still won't crash if we
reach the maximum particle count (given you do some more error checking later).

That's just my two cent.

P.S.:   If anyone has a good idea on how to improve the allocation of
         an entire bunch of particles from the array (say I want
200     particles allocated at once), then please let me know.

At 11:12 AM 6/28/02 +0100, Cruise wrote:
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: MD5
>
>Arriving late as usual...
>
>Why do linked lists equal run-time allocation and de-allocation? Well,
>yeah, ok, at /some/ point during execution you're going to have a
>create some particles...but if you create a number of them at the
>start, and just use those, then you're not constantly assigning and
>freeing memory, there's no fragmentation, and you still get the fast
>inserts.
>
>A couple of comments I've seen suggest this how people are doing (as I
>do). You have two lists. Active particles, unused particles. At start
>up, you create MAX_PARTICLES particles and dump them all in the unused
>list.
>
>Whenever you need a particle, you simply move it from unused to
>active. To render, iterate through the active list. No memory
>nastiness required. When your program quits, clean up.
>
>Yes, you're limited to a fixed number of particles, but you would be
>with static allocation anyway, and with a bit of experimentation, you
>can find a number that's not too wasteful without noticeably depriving
>your effects of particles.
>
>As is often the case, "somewhere" in between is the best solution :P
>
> > I don't have the time to get into this argument, but there is a reason that
> > games like Half-life\QuakeX prefer static allocation; speed!  There is no
> > reason you need infinite particles.
>
> > Basically this boils down to the good 'ol speed vs. memory
> argument.  People
> > have argued this for decades.
>
> > I would, however, argue that linked lists would be the better choice though
> > if you were developing on a restrictive platform where memory is limited.
> > Of course you could just limit the max_particles to a very small size! See
> > what I mean! ;}
>
> > Scott Velasquez
> > Programmer
> > Gearbox Software (www.gearboxsoftware.com)
> > ------------------------------------------
> > re·cur·sion n.: See Recursion.
> > ------------------------------------------
>
>
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED]]On Behalf Of Miguel Aleman
> > Sent: Thursday, June 27, 2002 3:01 PM
> > To: [EMAIL PROTECTED]
> > Subject: Re: [hlcoders] Particle System
>
>
> > Linked lists are the best way I know of to do a particle engine.
>
> > You save processor time during allocation of new particles and even more
> > during deallocation. The ability to have virtually infinite particles is
> > also a plus.
>
> > ----- Original Message -----
> > From: "Tom" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Thursday, June 27, 2002 1:56 AM
> > Subject: Re: [hlcoders] Particle System
>
>
> >> linked lists may be to slow for a particle engine
> >>
> >> ----- Original Message -----
> >> From: "Yacketta, Ronald" <[EMAIL PROTECTED]>
> >> To: <[EMAIL PROTECTED]>
> >> Sent: Thursday, June 27, 2002 12:24 AM
> >> Subject: RE: [hlcoders] Particle System
> >>
> >>
> >> > I am writing my own :)
> >> >
> >> > Just looking to peek at others work to see how things were/are done and
> >> > for some ideas.
> >> > Mine is using STL vice a stock home grown linked list
> >> >
> >> > -Ron
> >> >
> >> > -----Original Message-----
> >> > From: [EMAIL PROTECTED]
> >> > [mailto:[EMAIL PROTECTED]] On Behalf Of Miguel
> >> > Aleman
> >> > Sent: Wednesday, June 26, 2002 7:20 PM
> >> > To: [EMAIL PROTECTED]
> >> > Subject: Re: [hlcoders] Particle System
> >> >
> >> >
> >> > Check out NeHe on gamedev.net (www.gamedev.net/nehe) for a particle
> >> > system tutorial. Its in OpenGL, but its easy to change to TriAPI. Get
> >> > comfortable with it and then you can write your own.
> >> >
> >> > ----- Original Message -----
> >> > From: "Yacketta, Ronald" <[EMAIL PROTECTED]>
> >> > To: <[EMAIL PROTECTED]>
> >> > Sent: Wednesday, June 26, 2002 6:03 PM
> >> > Subject: RE: [hlcoders] Particle System
> >> >
> >> >
> >> > > I was just looking for a working particle system that I could use for
> >> > > ideas and to answer some of my own questions from, I am in no way
> >> > > looking to use someone else's engine. I am in the mist of my own
> >> > > creation and just need something to peek at
> >> > >
> >> > > -Ron
> >> > >
> >> > > -----Original Message-----
> >> > > From: [EMAIL PROTECTED]
> >> > > [mailto:[EMAIL PROTECTED]] On Behalf Of Persuter
> >> > > Sent: Wednesday, June 26, 2002 5:35 PM
> >> > > To: [EMAIL PROTECTED]
> >> > > Subject: RE: [hlcoders] Particle System
> >> > >
> >> > >
> >> > > Ron: what exactly is your question? The particle system recently
> >> > > discussed, I believe, was mine, which is available for any mod that
> >> > > wants it. It is currently being used in Quest, Hostile Intent, and
> >> > > something by C4 Software.
> >> > >
> >> > > Persuter
> >> > >
> >> > > > -----Original Message-----
> >> > > > From: [EMAIL PROTECTED] [mailto:hlcoders-
> >> > > > [EMAIL PROTECTED]] On Behalf Of Yacketta, Ronald
> >> > > > Sent: Tuesday, June 25, 2002 9:25 PM
> >> > > > To: [EMAIL PROTECTED]
> >> > > > Subject: [hlcoders] Particle System
> >> > > >
> >> > > > Folks,
> >> > > >
> >> > > > I recall a recent conversation regarding the use / tutorial etc
> >> > > someone
> >> > > > had of a particle system for HL. I went searching my .pst's and
> >> > > > could not find a reference nor in the HL archives.
> >> > > >
> >> > > > Might someone know of a POC (Point Of Contact) for the particle
> >> > > > system
> >> > >
> >> > > > that was discussed?
> >> > > >
> >> > > > Regards,
> >> > > > Ron
> >> > > > _______________________________________________
> >> > > > To unsubscribe, edit your list preferences, or view the list
> >> > > > archives,
> >> > >
> >> > > > please visit:
> >> > > > http://list.valvesoftware.com/mailman/listinfo/hlcoders
> >> > >
> >> > > _______________________________________________
> >> > > To unsubscribe, edit your list preferences, or view the list archives,
> >> >
> >> > > please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders
> >> > > _______________________________________________
> >> > > To unsubscribe, edit your list preferences, or view the list archives,
> >> > please visit:
> >> > > http://list.valvesoftware.com/mailman/listinfo/hlcoders
> >> > >
> >> > >
> >> >
> >> > _______________________________________________
> >> > To unsubscribe, edit your list preferences, or view the list archives,
> >> > please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders
> >> > _______________________________________________
> >> > To unsubscribe, edit your list preferences, or view the list archives,
> >> please visit:
> >> > http://list.valvesoftware.com/mailman/listinfo/hlcoders
> >> >
> >> >
> >>
> >> _______________________________________________
> >> To unsubscribe, edit your list preferences, or view the list archives,
> > please visit:
> >> http://list.valvesoftware.com/mailman/listinfo/hlcoders
> >>
> >>
>
> > _______________________________________________
> > To unsubscribe, edit your list preferences, or view the list archives,
> > please visit:
> > http://list.valvesoftware.com/mailman/listinfo/hlcoders
>
>
>
> > _______________________________________________
> > To unsubscribe, edit your list preferences, or view the list archives,
> please visit:
> > http://list.valvesoftware.com/mailman/listinfo/hlcoders
>
>
>
>[ cruise / www.casual-tempest.net / www.transference.org ]
>
>-----BEGIN PGP SIGNATURE-----
>Version: 2.6
>
>iQCVAwUAPRw2oPdi0Z5STRufAQG+SQP/egXiIQ7e/u93L0i1j1Wysu6SSC15wWOV
>1FeTfJVf29b8P0XX3cKtCVH5dQeu6BdeMzJTA1saOGdZ6htaJKiklWi4b/mOCKVS
>0J6t7xad7UDfdbyg6rDois3kHJIBFAIC/8P0IHcuH0PGnu+zy3GyLYKl1DgGmY8Z
>rCS5b0sOSPY=
>=PfN/
>-----END PGP SIGNATURE-----
>
>_______________________________________________
>To unsubscribe, edit your list preferences, or view the list archives,
>please visit:
>http://list.valvesoftware.com/mailman/listinfo/hlcoders

_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to