summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-06-12 19:05:59 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-06-12 19:05:59 (GMT)
commita3a8ef7f7ae85fd6dba9de8759ff1d0ba7f2b648 (patch)
tree66dbc77a3bc3ab8a7b60721d1a05861563a08ffb
parent2e1780ce4e223b1fb78e8537f80d0eef73ef7864 (diff)
downloadpowder-a3a8ef7f7ae85fd6dba9de8759ff1d0ba7f2b648.zip
powder-a3a8ef7f7ae85fd6dba9de8759ff1d0ba7f2b648.tar.gz
TPT: Soap bubbles are easily formed now.
-rw-r--r--src/simulation/elements/SOAP.cpp64
1 files changed, 31 insertions, 33 deletions
diff --git a/src/simulation/elements/SOAP.cpp b/src/simulation/elements/SOAP.cpp
index f66334e..d8edab4 100644
--- a/src/simulation/elements/SOAP.cpp
+++ b/src/simulation/elements/SOAP.cpp
@@ -46,6 +46,27 @@ Element_SOAP::Element_SOAP()
Graphics = NULL;
}
+//#TPT-Directive ElementHeader Element_SOAP static int attach(Particle * parts, int i1, int i2)
+void attach(Particle * parts, int i1, int i2)
+{
+ if (!(parts[i2].ctype&4))
+ {
+ parts[i1].ctype |= 2;
+ parts[i1].tmp = i2;
+
+ parts[i2].ctype |= 4;
+ parts[i2].tmp2 = i1;
+ }
+ else if (!(parts[i2].ctype&2))
+ {
+ parts[i1].ctype |= 4;
+ parts[i1].tmp2= i2;
+
+ parts[i2].ctype |= 2;
+ parts[i2].tmp = i1;
+ }
+}
+
//#TPT-Directive ElementHeader Element_SOAP static int update(UPDATE_FUNC_ARGS)
int Element_SOAP::update(UPDATE_FUNC_ARGS)
@@ -58,7 +79,7 @@ int Element_SOAP::update(UPDATE_FUNC_ARGS)
//0x02 - first mate yes/no
//0x04 - "back" mate yes/no
- if ((parts[i].ctype&1) == 1)
+ if (parts[i].ctype&1)
{
if (parts[i].temp>0)
{
@@ -72,13 +93,13 @@ int Element_SOAP::update(UPDATE_FUNC_ARGS)
while((parts[target].ctype&6) != 6 && (parts[target].ctype&6))
{
- if ((parts[target].ctype&2) == 2)
+ if (parts[target].ctype&2)
{
target = parts[target].tmp;
sim->detach(target);
}
- if ((parts[target].ctype&4) == 4)
+ if (parts[target].ctype&4)
{
target = parts[target].tmp2;
sim->detach(target);
@@ -99,7 +120,7 @@ int Element_SOAP::update(UPDATE_FUNC_ARGS)
parts[i].vx *= 0.5f;
}
- if((parts[i].ctype&2) != 2)
+ if(parts[i].ctype&2)
{
for (rx=-2; rx<3; rx++)
for (ry=-2; ry<3; ry++)
@@ -109,29 +130,8 @@ int Element_SOAP::update(UPDATE_FUNC_ARGS)
if (!r)
continue;
- if ((parts[r>>8].type == PT_SOAP) && ((parts[r>>8].ctype&1) == 1)
- && ((parts[r>>8].ctype&4) != 4))
- {
- if ((parts[r>>8].ctype&2) == 2)
- {
- parts[i].tmp = r>>8;
- parts[r>>8].tmp2 = i;
-
- parts[i].ctype |= 2;
- parts[r>>8].ctype |= 4;
- }
- else
- {
- if ((parts[i].ctype&2) != 2)
- {
- parts[i].tmp = r>>8;
- parts[r>>8].tmp2 = i;
-
- parts[i].ctype |= 2;
- parts[r>>8].ctype |= 4;
- }
- }
- }
+ if ((parts[r>>8].type == PT_SOAP) && (parts[r>>8].ctype&1) && !(parts[r>>8].ctype&4))
+ attach(parts, i, r>>8);
}
}
else
@@ -149,9 +149,7 @@ int Element_SOAP::update(UPDATE_FUNC_ARGS)
{
if (sim->bmap[(y+ry)/CELL][(x+rx)/CELL]
|| (r && sim->elements[r&0xFF].State != ST_GAS
- && (r&0xFF) != PT_SOAP && (r&0xFF) != PT_GLAS)
- || (parts[r>>8].ctype == 0 && (r&0xFF) == PT_SOAP
- && (abs(parts[r>>8].vx)<2 || abs(parts[r>>8].vy)<2)))
+ && (r&0xFF) != PT_SOAP && (r&0xFF) != PT_GLAS))
{
sim->detach(i);
continue;
@@ -183,7 +181,7 @@ int Element_SOAP::update(UPDATE_FUNC_ARGS)
}
}
- if((parts[i].ctype&2) == 2)
+ if(parts[i].ctype&2)
{
float d, dx, dy;
@@ -198,8 +196,8 @@ int Element_SOAP::update(UPDATE_FUNC_ARGS)
parts[i].vx += dx*d;
parts[i].vy += dy*d;
- if (((parts[parts[i].tmp].ctype&2) == 2) && ((parts[parts[i].tmp].ctype&1) == 1)
- && ((parts[parts[parts[i].tmp].tmp].ctype&2) == 2) && ((parts[parts[parts[i].tmp].tmp].ctype&1) == 1))
+ if ((parts[parts[i].tmp].ctype&2) && (parts[parts[i].tmp].ctype&1)
+ && (parts[parts[parts[i].tmp].tmp].ctype&2) && (parts[parts[parts[i].tmp].tmp].ctype&1))
{
int ii;