summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacksonmj <mj-pt@jacksonmj.co.uk>2011-05-29 00:31:31 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-05-29 12:38:53 (GMT)
commit4fd97b93b4d9d86eedcb218f972e6726fd708fbc (patch)
tree9ffcd111ef081325923f4149e0bcec1d52b78a27 /src
parent7750cf8ccd01643d24af1e5b8b275ed6a1b15f7e (diff)
downloadpowder-4fd97b93b4d9d86eedcb218f972e6726fd708fbc.zip
powder-4fd97b93b4d9d86eedcb218f972e6726fd708fbc.tar.gz
Large speed improvement for QRTZ
Also prevent growing when sparked.
Diffstat (limited to 'src')
-rw-r--r--src/elements/qrtz.c74
-rw-r--r--src/elements/sprk.c1
2 files changed, 41 insertions, 34 deletions
diff --git a/src/elements/qrtz.c b/src/elements/qrtz.c
index f8312c1..cf22925 100644
--- a/src/elements/qrtz.c
+++ b/src/elements/qrtz.c
@@ -12,20 +12,22 @@ int update_QRTZ(UPDATE_FUNC_ARGS) {
part_change_type(i,x,y,PT_PQRT);
}
}
- //new QRTZ growth
- for (rx=-2; rx<3 && parts[i].ctype!=-1; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if ((r>>8)>=NPART || !r)
- continue;
- else if ((r&0xFF)==PT_SLTW && (1>rand()%2500))
+ // absorb SLTW
+ if (parts[i].ctype!=-1)
+ for (rx=-2; rx<3; rx++)
+ for (ry=-2; ry<3; ry++)
+ if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
{
- kill_part(r>>8);
- parts[i].ctype ++;
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ else if ((r&0xFF)==PT_SLTW && (1>rand()%2500))
+ {
+ kill_part(r>>8);
+ parts[i].ctype ++;
+ }
}
- }
+ // grow if absorbed SLTW
if (parts[i].ctype>0)
{
for ( trade = 0; trade<5; trade ++)
@@ -38,15 +40,15 @@ int update_QRTZ(UPDATE_FUNC_ARGS) {
if ((r>>8)<NPART && !r && parts[i].ctype!=0)
{
np = create_part(-1,x+rx,y+ry,PT_QRTZ);
- if (np>0)
+ if (np>-1)
{
parts[np].tmp = parts[i].tmp;
- parts[i].ctype = 0;
+ parts[i].ctype--;
if (5>rand()%10)
{
parts[np].ctype=-1;//dead qrtz
}
- else if (1>rand()%15)
+ else if (!parts[i].ctype && 1>rand()%15)
{
parts[i].ctype=-1;
}
@@ -57,29 +59,33 @@ int update_QRTZ(UPDATE_FUNC_ARGS) {
}
}
}
- for ( trade = 0; trade<9; trade ++)
+ // diffuse absorbed SLTW
+ if (parts[i].ctype>0)
{
- rx = rand()%5-2;
- ry = rand()%5-2;
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
+ for ( trade = 0; trade<9; trade ++)
{
- r = pmap[y+ry][x+rx];
- if ((r>>8)>=NPART || !r)
- continue;
- if ((r&0xFF)==t && (parts[i].ctype>parts[r>>8].ctype) && parts[i].ctype>0 && parts[r>>8].ctype>=0 )//diffusion
+ rx = rand()%5-2;
+ ry = rand()%5-2;
+ if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
{
- tmp = parts[i].ctype - parts[r>>8].ctype;
- if (tmp ==1)
- {
- parts[r>>8].ctype ++;
- parts[i].ctype --;
- trade = 9;
- }
- if (tmp>0)
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==t && (parts[i].ctype>parts[r>>8].ctype) && parts[r>>8].ctype>=0 )//diffusion
{
- parts[r>>8].ctype += tmp/2;
- parts[i].ctype -= tmp/2;
- trade = 9;
+ tmp = parts[i].ctype - parts[r>>8].ctype;
+ if (tmp ==1)
+ {
+ parts[r>>8].ctype ++;
+ parts[i].ctype --;
+ break;
+ }
+ if (tmp>0)
+ {
+ parts[r>>8].ctype += tmp/2;
+ parts[i].ctype -= tmp/2;
+ break;
+ }
}
}
}
diff --git a/src/elements/sprk.c b/src/elements/sprk.c
index ae7e76b..004d6e8 100644
--- a/src/elements/sprk.c
+++ b/src/elements/sprk.c
@@ -11,6 +11,7 @@ int update_SPRK(UPDATE_FUNC_ARGS) {
if (!ct)
ct = PT_METL;
part_change_type(i,x,y,ct);
+ parts[i].ctype = PT_NONE;
parts[i].life = 4;
if (ct == PT_WATR)
parts[i].life = 64;