Skip unused particles at end of parts[]
This commit is contained in:
parent
61bbc36cfa
commit
1713604233
@ -948,6 +948,7 @@ extern int airMode;
|
|||||||
|
|
||||||
extern particle *parts;
|
extern particle *parts;
|
||||||
extern particle *cb_parts;
|
extern particle *cb_parts;
|
||||||
|
extern int parts_lastActiveIndex;
|
||||||
|
|
||||||
extern unsigned char bmap[YRES/CELL][XRES/CELL];
|
extern unsigned char bmap[YRES/CELL][XRES/CELL];
|
||||||
extern unsigned char emap[YRES/CELL][XRES/CELL];
|
extern unsigned char emap[YRES/CELL][XRES/CELL];
|
||||||
|
@ -1654,7 +1654,7 @@ void draw_parts(pixel *vid)
|
|||||||
blendpixel(vid, nx, ny, 100, 100, 100, 80);
|
blendpixel(vid, nx, ny, 100, 100, 100, 80);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i<NPART; i++) {
|
for (i = 0; i<=parts_lastActiveIndex; i++) {
|
||||||
#ifdef OpenGL
|
#ifdef OpenGL
|
||||||
if (cmode == CM_FANCY) //If fancy mode
|
if (cmode == CM_FANCY) //If fancy mode
|
||||||
{
|
{
|
||||||
|
@ -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;
|
int nf=0, new_format = 0, ttv = 0;
|
||||||
particle *parts = partsptr;
|
particle *parts = partsptr;
|
||||||
int *fp = malloc(NPART*sizeof(int));
|
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
|
//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
|
//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(signs, 0, sizeof(signs));
|
||||||
memset(parts, 0, sizeof(particle)*NPART);
|
memset(parts, 0, sizeof(particle)*NPART);
|
||||||
pfree = -1;
|
pfree = -1;
|
||||||
|
parts_lastActiveIndex = NPART-1;
|
||||||
memset(pmap, 0, sizeof(pmap));
|
memset(pmap, 0, sizeof(pmap));
|
||||||
memset(pv, 0, sizeof(pv));
|
memset(pv, 0, sizeof(pv));
|
||||||
memset(vx, 0, sizeof(vx));
|
memset(vx, 0, sizeof(vx));
|
||||||
|
23
src/powder.c
23
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
|
else
|
||||||
i = p;
|
i = p;
|
||||||
|
|
||||||
|
if (i>parts_lastActiveIndex) parts_lastActiveIndex = i;
|
||||||
|
|
||||||
parts[i].dcolour = 0;
|
parts[i].dcolour = 0;
|
||||||
if (t==PT_GLAS)
|
if (t==PT_GLAS)
|
||||||
{
|
{
|
||||||
@ -1254,7 +1256,7 @@ int nearest_part(int ci, int t)
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
int cx = (int)parts[ci].x;
|
int cx = (int)parts[ci].x;
|
||||||
int cy = (int)parts[ci].y;
|
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)
|
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;
|
wireless[q][1] = 0;
|
||||||
}
|
}
|
||||||
//the main particle loop function, goes over all particles.
|
//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)
|
if (parts[i].type)
|
||||||
{
|
{
|
||||||
lx = parts[i].x;
|
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
|
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;
|
int i, j, x, y, t, nx, ny, r, cr,cg,cb, l = -1;
|
||||||
float lx, ly;
|
float lx, ly;
|
||||||
|
int lastPartUsed = 0;
|
||||||
|
int lastPartUnused = -1;
|
||||||
#ifdef MT
|
#ifdef MT
|
||||||
int pt = 0, pc = 0;
|
int pt = 0, pc = 0;
|
||||||
pthread_t *InterThreads;
|
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(pmap, 0, sizeof(pmap));
|
||||||
memset(photons, 0, sizeof(photons));
|
memset(photons, 0, sizeof(photons));
|
||||||
r = rand()%2;
|
|
||||||
NUM_PARTS = 0;
|
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)
|
if (parts[i].type)
|
||||||
{
|
{
|
||||||
t = parts[i].type;
|
t = parts[i].type;
|
||||||
@ -2432,15 +2435,19 @@ void update_particles(pixel *vid)//doesn't update the particles themselves, but
|
|||||||
else
|
else
|
||||||
pmap[y][x] = t|(i<<8);
|
pmap[y][x] = t|(i<<8);
|
||||||
}
|
}
|
||||||
|
lastPartUsed = i;
|
||||||
NUM_PARTS ++;
|
NUM_PARTS ++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
parts[i].life = l;
|
if (lastPartUnused<0) pfree = i;
|
||||||
l = 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 (y=0; y<YRES/CELL; y++)
|
||||||
{
|
{
|
||||||
for (x=0; x<XRES/CELL; x++)
|
for (x=0; x<XRES/CELL; x++)
|
||||||
|
Loading…
Reference in New Issue
Block a user