It assumes that you're reasonably familiar with r_part.c, or at least with the general layout of it, and it's not going to teach you how to program, but otherwise it's pure copy-and-paste.
At the top of the file:
Code: Select all
#define PARTICLE_BATCH_SIZE 2048
#define PARTICLE_EXTRA_SIZE 1024
Code: Select all
void R_InitParticles (void)
{
}
Code: Select all
void R_ClearParticles (void)
{
int i;
free_particles = (particle_t *) Hunk_AllocName (PARTICLE_BATCH_SIZE * sizeof (particle_t), "particles");
active_particles = NULL;
for (i = 0; i < PARTICLE_BATCH_SIZE; i++)
free_particles[i].next = &free_particles[i + 1];
free_particles[PARTICLE_BATCH_SIZE - 1].next = NULL;
}
Code: Select all
particle_t *R_NewParticle (void)
{
particle_t *p;
int i;
if (free_particles)
{
// just take from the free list
p = free_particles;
free_particles = p->next;
p->next = active_particles;
active_particles = p;
return p;
}
else
{
// alloc some more free particles
free_particles = (particle_t *) Hunk_AllocName (PARTICLE_EXTRA_SIZE * sizeof (particle_t), "particles");
// link them up
for (i = 0; i < PARTICLE_EXTRA_SIZE; i++)
free_particles[i].next = &free_particles[i + 1];
// finish the link
free_particles[PARTICLE_EXTRA_SIZE - 1].next = NULL;
// call recursively to return the first new free particle
return R_NewParticle ();
}
}
Code: Select all
if (!free_particles)
return;
p = free_particles;
free_particles = p->next;
p->next = active_particles;
active_particles = p;
Code: Select all
p = R_NewParticle ();
Now you can allocate as many particles as you want until you run out of memory. And because the hunk is cleared between maps, any extra won't carry over.