예제 #1
0
        private void UpdateFloraAndPhysics()
        {
            BoundingBoxD box = this.PositionComp.WorldAABB;

            box.Min -= PHYSICS_SECTOR_SIZE_METERS;
            box.Max += PHYSICS_SECTOR_SIZE_METERS;
            m_entities.Clear();
            m_sectorsToKeep.Clear();

            MyGamePruningStructure.GetAllTopMostEntitiesInBox <MyEntity>(ref box, m_entities);
            Vector3I increment = m_storage.Size / (m_numCells + 1);

            ProfilerShort.Begin("Myplanet::update physics");
            foreach (var entity in m_entities)
            {
                if (entity.MarkedForClose || entity is MyPlanet || entity is MyVoxelMap)
                {
                    continue;
                }

                Vector3D position = entity.PositionComp.GetPosition();
                double   distance = (WorldMatrix.Translation - position).Length();
                if (IsInRange(position) == false)
                {
                    continue;
                }

                var predictionOffset = ComputePredictionOffset(entity);

                if (CanSpawnFlora)
                {
                    ProfilerShort.Begin("Myplanet:: spawn flora");
                    if ((predictionOffset.LengthSquared() > 0.03 || entity == MySession.LocalCharacter) && distance > m_planetInitValues.MinimumSurfaceRadius)
                    {
                        SpawnFlora(position);
                    }
                    ProfilerShort.End();
                }

                var shapeBox = entity.PositionComp.WorldAABB;
                shapeBox.Inflate(MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_METRES);
                shapeBox.Translate(predictionOffset);
                GeneratePhysicalShapeForBox(ref increment, ref shapeBox);
            }

            if (m_entities.Count < 1 && m_hasGeneratedTexture == true)
            {
                m_storage.DataProvider.ReleaseNoiseHelpTexture();
                m_hasGeneratedTexture = false;
            }

            ProfilerShort.End();
        }
예제 #2
0
        private void UpdateFloraAndPhysics()
        {
            BoundingBoxD box = this.PositionComp.WorldAABB;

            box.Min -= PHYSICS_SECTOR_SIZE_METERS;
            box.Max += PHYSICS_SECTOR_SIZE_METERS;
            m_entities.Clear();
            m_sectorsToKeep.Clear();

            MyGamePruningStructure.GetAllTopMostEntitiesInBox <MyEntity>(ref box, m_entities);
            Vector3I increment = m_storage.Size / (m_numCells + 1);

            ProfilerShort.Begin("Myplanet::update physics");
            foreach (var entity in m_entities)
            {
                if (entity.MarkedForClose || entity is MyPlanet || entity is MyVoxelMap)
                {
                    continue;
                }

                Vector3D position = entity.PositionComp.GetPosition();
                double   distance = (WorldMatrix.Translation - position).Length();
                if (IsInRange(position) == false)
                {
                    continue;
                }

                var predictionOffset = ComputePredictionOffset(entity);

                if (CanSpawnFlora)
                {
                    ProfilerShort.Begin("Myplanet:: spawn flora");
                    SpawnFlora(position);
                    ProfilerShort.End();
                }

                var shapeBox = entity.PositionComp.WorldAABB;
                shapeBox.Inflate(MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_METRES);
                shapeBox.Translate(predictionOffset);
                GeneratePhysicalShapeForBox(ref increment, ref shapeBox);
            }

            ProfilerShort.End();
        }
예제 #3
0
        public override void UpdateAfterSimulation100()
        {
            base.UpdateAfterSimulation100();

            if (CanSpawnFlora && MySession.LocalHumanPlayer != null)
            {
                Vector3D playerPosition = MySession.LocalHumanPlayer.GetPosition();
                if (IsInRange(playerPosition) && !MySandboxGame.IsDedicated)
                {
                    GenerateFloraGraphics(playerPosition);
                }
            }

            m_sectorsToRemove.Clear();
            if (m_physicsShapes != null)
            {
                foreach (var physicsShape in m_physicsShapes)
                {
                    m_entities.Clear();
                    BoundingBoxD box = physicsShape.Value.PositionComp.WorldAABB;
                    box.Min -= 2.0 * box.HalfExtents;
                    box.Max += 2.0 * box.HalfExtents;

                    MyGamePruningStructure.GetAllTopMostEntitiesInBox <MyEntity>(ref box, m_entities);

                    if (m_entities.Count < 2)
                    {
                        m_sectorsToRemove.Add(physicsShape.Key);
                    }
                }
            }

            foreach (var shapeToRemove in m_sectorsToRemove)
            {
                MyVoxelPhysics physics;
                if (m_physicsShapes.TryGetValue(shapeToRemove, out physics))
                {
                    physics.Close();
                }
                m_physicsShapes.Remove(shapeToRemove);
            }
            m_sectorsToRemove.Clear();
        }