public void TryRemoveComponents(WorldApi worldApi, List <FluidComponent> components, bool rebuildEnabled)
        {
            UnityEngine.Profiling.Profiler.BeginSample("TryRemoveComponents");

            for (int i = 0; i < components.Count; i++)
            {
                FluidComponent component = components[i];

                component.UpdateLifetime(RealtimeSinceStartup);

                // cleanup components marked for rebuild
                if (rebuildEnabled && component.ToRebuild)
                {
                    component.Unsettle(component.Count * component.Viscosity);
                    component.Cleanup(worldApi);
                }

                // remove small and old components
                if (component.ToRemove)
                {
                    component.Cleanup(worldApi);
                    component.UpdateJob.ToRemove = true;
                    components.RemoveAtViaEndSwap(i--);
                }
            }

            UnityEngine.Profiling.Profiler.EndSample();
        }
Esempio n. 2
0
        // TODO speedup
        /// <summary>
        /// Validates the existing segments and updates / equalizes the outlets of this component.
        /// </summary>
        public void Execute()
        {
            UnityEngine.Profiling.Profiler.BeginSample("Update");

            FluidComponent        component = (FluidComponent)_componentPointer.Target;
            WorldApi              worldApi  = (WorldApi)_worldApiPointer.Target;
            FluidComponentManager manager   = (FluidComponentManager)_managerPointer.Target;

            int diff = component.Count;

            if (component.Viscosity > FluidComponentManager.kMaxViscosityNotEqualize && component.Outlets == null)
            {
                component.Outlets = new HashSet <VectorI3>();
            }

            UpdateSegments(worldApi, component.AllSegments, component.Outlets, ref component.Count, ref component.WaterLevel);

            diff -= component.Count;

            if (diff != 0)
            {
                component.Unsettle(diff * component.Viscosity);
            }
            else
            {
                component.DecreaseSettle();
            }

            if (component.Viscosity > FluidComponentManager.kMaxViscosityNotEqualize && component.Outlets.Count > 0)
            {
                UpdateOutlets(worldApi, component.Outlets, component.Rebuilding, component.Lifetime, ref component.WaterLevel);

                EqualizeOutlets(true, worldApi, component.Outlets, component.Viscosity);
                EqualizeOutlets(false, worldApi, component.Outlets, component.Viscosity);
            }

            UnityEngine.Profiling.Profiler.EndSample();
        }