void updateAllParticleFlags() { allParticleFlags = 0; for (int i = 0; i < count; i++) { allParticleFlags |= particleBuffer [i].flags; } needsUpdateAllParticleFlags = false; }
public void destroyParticle(FluidParticle fp, bool callDestructionListener) { FluidParticleType flags = FluidParticleType.ZombieParticle; if (callDestructionListener) { flags |= FluidParticleType.DestructionListenerParticle; } setParticleFlags(fp, fp.flags | flags); }
void setParticleFlags(FluidParticle fp, FluidParticleType newFlags) { if ((fp.flags & ~newFlags) > 0) { needsUpdateAllParticleFlags = true; } if ((~allParticleFlags & newFlags) > 0) { allParticleFlags |= newFlags; } fp.flags = newFlags; }
// int m_groupCount; // b2ParticleGroup* m_groupList; void Awake() { paused = false; timestamp = 0; allParticleFlags = FluidParticleType.WaterParticle; needsUpdateAllParticleFlags = false; //allGroupFlags = 0; //needsUpdateAllGroupFlags = false; hasForce = false; iterationIndex = 0; inverseDensity = 1 / fluidSystemDef.density; particleDiameter = fluidSystemDef.radius * 2; squaredDiameter = particleDiameter * particleDiameter; inverseDiameter = 1 / particleDiameter; count = 0; particleBuffer = new List <FluidParticle> (fluidSystemDef.maxCount); proxyBuffer = new List <FluidProxy> (fluidSystemDef.maxCount); contactBuffer = new List <FluidParticleContact> (fluidSystemDef.maxCount * 4); bodyContactBuffer = new List <FluidParticleBodyContact> (fluidSystemDef.maxCount * 4); triggerContactBuffer = new List <FluidParticleBodyContact> (fluidSystemDef.maxCount * 4); }
void solveZombie() { // removes particles with zombie flag allParticleFlags = 0; for (int i = count - 1; i >= 0; i--) { FluidProxy proxy = proxyBuffer [i]; if ((proxy.fp.flags & FluidParticleType.ZombieParticle) > 0) { // b2DestructionListener * const destructionListener = // m_world->m_destructionListener; // if ((flags & b2_destructionListenerParticle) && // destructionListener) // { // destructionListener->SayGoodbye(this, i); // } // Destroy particle handle. // if (m_handleIndexBuffer.data) // { // b2ParticleHandle * const handle = m_handleIndexBuffer.data[i]; // if (handle) // { // handle->SetIndex(b2_invalidParticleIndex); // m_handleIndexBuffer.data[i] = NULL; // m_handleAllocator.Free(handle); // } // } // newIndices[i] = b2_invalidParticleIndex; particleBuffer.Remove(proxy.fp); proxyBuffer.Remove(proxy); count--; } else { allParticleFlags |= proxy.fp.flags; } } needsUpdateAllParticleFlags = false; // update contacts // for (int32 k = 0; k < m_contactBuffer.GetCount(); k++) // { // b2ParticleContact& contact = m_contactBuffer[k]; // contact.SetIndices(newIndices[contact.GetIndexA()], // newIndices[contact.GetIndexB()]); // } // m_contactBuffer.RemoveIf(Test::IsContactInvalid); // // update particle-body contacts // for (int32 k = 0; k < m_bodyContactBuffer.GetCount(); k++) // { // b2ParticleBodyContact& contact = m_bodyContactBuffer[k]; // contact.index = newIndices[contact.index]; // } // m_bodyContactBuffer.RemoveIf(Test::IsBodyContactInvalid); // // // update pairs // for (int32 k = 0; k < m_pairBuffer.GetCount(); k++) // { // b2ParticlePair& pair = m_pairBuffer[k]; // pair.indexA = newIndices[pair.indexA]; // pair.indexB = newIndices[pair.indexB]; // } // m_pairBuffer.RemoveIf(Test::IsPairInvalid); // // // update triads // for (int32 k = 0; k < m_triadBuffer.GetCount(); k++) // { // b2ParticleTriad& triad = m_triadBuffer[k]; // triad.indexA = newIndices[triad.indexA]; // triad.indexB = newIndices[triad.indexB]; // triad.indexC = newIndices[triad.indexC]; // } // m_triadBuffer.RemoveIf(Test::IsTriadInvalid); // // // Update lifetime indices. // if (m_indexByExpirationTimeBuffer.data) // { // int32 writeOffset = 0; // for (int32 readOffset = 0; readOffset < m_count; readOffset++) // { // const int32 newIndex = newIndices[ // m_indexByExpirationTimeBuffer.data[readOffset]]; // if (newIndex != b2_invalidParticleIndex) // { // m_indexByExpirationTimeBuffer.data[writeOffset++] = newIndex; // } // } // } // // // update groups // for (b2ParticleGroup* group = m_groupList; group; group = group->GetNext()) // { // int32 firstIndex = newCount; // int32 lastIndex = 0; // bool modified = false; // for (int32 i = group->m_firstIndex; i < group->m_lastIndex; i++) // { // int32 j = newIndices[i]; // if (j >= 0) { // firstIndex = b2Min(firstIndex, j); // lastIndex = b2Max(lastIndex, j + 1); // } else { // modified = true; // } // } // if (firstIndex < lastIndex) // { // group->m_firstIndex = firstIndex; // group->m_lastIndex = lastIndex; // if (modified) // { // if (group->m_groupFlags & b2_solidParticleGroup) // { // SetGroupFlags(group, // group->m_groupFlags | // b2_particleGroupNeedsUpdateDepth); // } // } // } // else // { // group->m_firstIndex = 0; // group->m_lastIndex = 0; // if (!(group->m_groupFlags & b2_particleGroupCanBeEmpty)) // { // SetGroupFlags(group, // group->m_groupFlags | b2_particleGroupWillBeDestroyed); // } // } // } // destroy bodies with no particles // for (b2ParticleGroup* group = m_groupList; group;) // { // b2ParticleGroup* next = group->GetNext(); // if (group->m_groupFlags & b2_particleGroupWillBeDestroyed) // { // DestroyParticleGroup(group); // } // group = next; // } }