summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacksonmj <mj-pt@jacksonmj.co.uk>2011-08-09 21:59:04 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-08-10 23:38:56 (GMT)
commit1713604233a4090f7f73ba86c33e72dd3c44d13c (patch)
tree4cffce37172552bf1511ebf9026352782495dcdb /src
parent61bbc36cfaca3640b86dfe0bc21e02eab5a32d80 (diff)
downloadpowder-1713604233a4090f7f73ba86c33e72dd3c44d13c.zip
powder-1713604233a4090f7f73ba86c33e72dd3c44d13c.tar.gz
Skip unused particles at end of parts[]
Diffstat (limited to 'src')
-rw-r--r--src/graphics.c2
-rw-r--r--src/main.c2
-rw-r--r--src/powder.c23
3 files changed, 18 insertions, 9 deletions
diff --git a/src/graphics.c b/src/graphics.c
index 5a1061e..4be05a6 100644
--- a/src/graphics.c
+++ b/src/graphics.c
@@ -1654,7 +1654,7 @@ void draw_parts(pixel *vid)
blendpixel(vid, nx, ny, 100, 100, 100, 80);
}
}
- for (i = 0; i<NPART; i++) {
+ for (i = 0; i<=parts_lastActiveIndex; i++) {
#ifdef OpenGL
if (cmode == CM_FANCY) //If fancy mode
{
diff --git a/src/main.c b/src/main.c
index db9a0b8..c2653a5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -546,6 +546,7 @@ int parse_save(void *save, int size, int replace, int x0, int y0, unsigned char
int nf=0, new_format = 0, ttv = 0;
particle *parts = partsptr;
int *fp = malloc(NPART*sizeof(int));
+ parts_lastActiveIndex = NPART-1;
//New file header uses PSv, replacing fuC. This is to detect if the client uses a new save format for temperatures
//This creates a problem for old clients, that display and "corrupt" error instead of a "newer version" error
@@ -1129,6 +1130,7 @@ void clear_sim(void)
memset(signs, 0, sizeof(signs));
memset(parts, 0, sizeof(particle)*NPART);
pfree = -1;
+ parts_lastActiveIndex = NPART-1;
memset(pmap, 0, sizeof(pmap));
memset(pv, 0, sizeof(pv));
memset(vx, 0, sizeof(vx));
diff --git a/src/powder.c b/src/powder.c
index f95c8e7..4068e3c 100644
--- a/src/powder.c
+++ b/src/powder.c
@@ -779,6 +779,8 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a
else
i = p;
+ if (i>parts_lastActiveIndex) parts_lastActiveIndex = i;
+
parts[i].dcolour = 0;
if (t==PT_GLAS)
{
@@ -1254,7 +1256,7 @@ int nearest_part(int ci, int t)
int i = 0;
int cx = (int)parts[ci].x;
int cy = (int)parts[ci].y;
- for (i=0; i<NPART; i++)
+ for (i=0; i<=parts_lastActiveIndex; i++)
{
if (parts[i].type==t&&!parts[i].life&&i!=ci)
{
@@ -1578,7 +1580,7 @@ void update_particles_i(pixel *vid, int start, int inc)
wireless[q][1] = 0;
}
//the main particle loop function, goes over all particles.
- for (i=start; i<(NPART-starti); i+=inc)
+ for (i=0; i<=parts_lastActiveIndex; i++)
if (parts[i].type)
{
lx = parts[i].x;
@@ -2404,10 +2406,13 @@ movedone:
}
}
+int parts_lastActiveIndex = NPART-1;
void update_particles(pixel *vid)//doesn't update the particles themselves, but some other things
{
int i, j, x, y, t, nx, ny, r, cr,cg,cb, l = -1;
float lx, ly;
+ int lastPartUsed = 0;
+ int lastPartUnused = -1;
#ifdef MT
int pt = 0, pc = 0;
pthread_t *InterThreads;
@@ -2415,11 +2420,9 @@ void update_particles(pixel *vid)//doesn't update the particles themselves, but
memset(pmap, 0, sizeof(pmap));
memset(photons, 0, sizeof(photons));
- r = rand()%2;
NUM_PARTS = 0;
- for (j=0; j<NPART; j++)//the particle loop that resets the pmap/photon maps every frame, to update them.
+ for (i=0; i<=parts_lastActiveIndex; i++)//the particle loop that resets the pmap/photon maps every frame, to update them.
{
- i = r ? (NPART-1-j) : j;
if (parts[i].type)
{
t = parts[i].type;
@@ -2432,15 +2435,19 @@ void update_particles(pixel *vid)//doesn't update the particles themselves, but
else
pmap[y][x] = t|(i<<8);
}
+ lastPartUsed = i;
NUM_PARTS ++;
}
else
{
- parts[i].life = l;
- l = i;
+ if (lastPartUnused<0) pfree = i;
+ else parts[lastPartUnused].life = i;
+ lastPartUnused = i;
}
}
- pfree=l;
+ if (parts_lastActiveIndex>=NPART-1) parts[lastPartUnused].life = -1;
+ else parts[lastPartUnused].life = parts_lastActiveIndex+1;
+ parts_lastActiveIndex = lastPartUsed;
for (y=0; y<YRES/CELL; y++)
{
for (x=0; x<XRES/CELL; x++)