Пример #1
0
 void updateProxies()
 {
     for (int i = 0; i < count; i++)
     {
         FluidProxy proxy = proxyBuffer [i];
         Vector2    p     = proxy.fp.position;
         proxy.tag = computeTag(inverseDiameter * p.x, inverseDiameter * p.y);
     }
 }
Пример #2
0
        public FluidParticle createParticle(FluidParticleDef def)
        {
            if (count >= fluidSystemDef.maxCount)
            {
                return(null);
            }
            count++;

            FluidParticle fp = new FluidParticle();

            particleBuffer.Add(fp);
            setParticleFlags(fp, def.flags);
            fp.position            = def.position;
            fp.prevPosition        = def.position;
            fp.velocity            = def.velocity;
            fp.weight              = 0;
            fp.force               = Vector2.zero;
            fp.mass                = def.mass;
            fp.staticPressure      = 0;
            fp.depth               = 0;
            fp.color               = def.color;
            fp.foamColor           = def.foamColor;
            fp.foamWeightThreshold = def.foamWeightThreshold;
            fp.temperature         = def.temperature;
            fp.freezingTemperature = def.freezingTemperature;
            fp.boilingTemperature  = def.boilingTemperature;

            FluidProxy proxy = new FluidProxy();

            proxyBuffer.Add(proxy);
            proxy.fp = fp;

//		bool finiteLifetime = def.lifetime > 0;
//		if (m_expirationTimeBuffer.data || finiteLifetime)
//		{
//			SetParticleLifetime(index, finiteLifetime ? def.lifetime :
//			                    ExpirationTimeToLifetime(
//				-GetQuantizedTimeElapsed()));
//			// Add a reference to the newly added particle to the end of the
//			// queue.
//			m_indexByExpirationTimeBuffer.data[index] = index;
//		}

            return(fp);
        }
Пример #3
0
        void findContacts()
        {
            contactBuffer.Clear();
            for (int a = 0, c = 0; a < count; a++)
            {
                FluidProxy proxy    = proxyBuffer [a];
                int        rightTag = computeRelativeTag(proxy.tag, 1, 0);
                for (int b = a + 1; b < count; b++)
                {
                    if (rightTag < proxyBuffer [b].tag)
                    {
                        break;
                    }
                    addContact(proxy.fp, proxyBuffer [b].fp);
                }

                int bottomLeftTag = computeRelativeTag(proxy.tag, -1, 1);
                for (; c < count; c++)
                {
                    if (bottomLeftTag <= proxyBuffer [c].tag)
                    {
                        break;
                    }
                }

                int bottomRightTag = computeRelativeTag(proxy.tag, 1, 1);
                for (int b = c; b < count; b++)
                {
                    if (bottomRightTag < proxyBuffer [b].tag)
                    {
                        break;
                    }
                    addContact(proxy.fp, proxyBuffer [b].fp);
                }
            }
        }
Пример #4
0
        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;
//		}
        }