Beispiel #1
0
        protected override void UnloadData()
        {
            if (!MyFakes.ENABLE_ASTEROID_FIELDS)
            {
                return;
            }
            MySandboxGame.Log.WriteLine("Unloading Procedural World Generator");
            m_densityFunctions.Clear();

            m_cellsTree.Clear();
            m_trackedEntities.Clear();
            m_cells.Clear();

            Debug.Assert(m_tempObjectSeedList.Count == 0, "temp list is not empty!");
            m_tempObjectSeedList.Clear();

            Debug.Assert(m_tempProceduralCellsList.Count == 0, "temp list is not empty!");
            m_tempProceduralCellsList.Clear();

            Debug.Assert(m_tmpClusterBoxes.Count == 0, "temp list is not empty!");
            m_tmpClusterBoxes.Clear();

            Debug.Assert(m_tmpVoxelMapsList.Count == 0, "temp list is not empty!");
            m_tmpVoxelMapsList.Clear();

            Debug.Assert(m_dirtyCellsToRemove.Count == 0, "temp list is not empty!");
            m_dirtyCellsToRemove.Clear();

            Debug.Assert(m_dirtyCells.Count == 0, "temp list is not empty!");
            m_dirtyCells.Clear();

            m_dirtyCellsToAdd.Clear(); // this can have some cells if the unload happened after removing tracked entity

            Static = null;
        }
Beispiel #2
0
        public override void LoadData()
        {
            Static = this;
            if (!MyFakes.ENABLE_ASTEROID_FIELDS)
            {
                return;
            }

            var settings = MySession.Static.Settings;

            if (settings.ProceduralDensity == 0f)
            {
                m_densityFunctions.Clear();
                MySandboxGame.Log.WriteLine("Skip Procedural World Generator");
                return;
            }

            m_seed          = settings.ProceduralSeed;
            m_objectDensity = settings.ProceduralDensity * 2 - 1; // must be -1..1
            MySandboxGame.Log.WriteLine(string.Format("Loading Procedural World Generator: Seed = '{0}' = {1}, Density = {2}", settings.ProceduralSeed, m_seed, settings.ProceduralDensity));

            using (MyRandom.Instance.PushSeed(m_seed))
            {
                m_densityFunctions.Add(new MyAsteroidInfiniteDensityFunction(MyRandom.Instance, 0.003));
            }

            m_seedTypeProbabilitySum = 0;
            foreach (var probability in m_seedTypeProbability.Values)
            {
                m_seedTypeProbabilitySum += probability;
            }
            Debug.Assert(m_seedTypeProbabilitySum != 0);

            m_seedClusterTypeProbabilitySum = 0;
            foreach (var probability in m_seedClusterTypeProbability.Values)
            {
                m_seedClusterTypeProbabilitySum += probability;
            }
            Debug.Assert(m_seedClusterTypeProbabilitySum != 0);
        }
        protected override void UnloadData()
        {
            if (!MyFakes.ENABLE_ASTEROID_FIELDS)
                return;
            MySandboxGame.Log.WriteLine("Unloading Procedural World Generator");
            m_densityFunctions.Clear();

            m_cellsTree.Clear();
            m_trackedEntities.Clear();
            m_cells.Clear();

            Debug.Assert(m_tempObjectSeedList.Count == 0, "temp list is not empty!");
            m_tempObjectSeedList.Clear();

            Debug.Assert(m_tempProceduralCellsList.Count == 0, "temp list is not empty!");
            m_tempProceduralCellsList.Clear();

            Debug.Assert(m_tmpClusterBoxes.Count == 0, "temp list is not empty!");
            m_tmpClusterBoxes.Clear();

            Debug.Assert(m_tmpVoxelMapsList.Count == 0, "temp list is not empty!");
            m_tmpVoxelMapsList.Clear();

            Debug.Assert(m_dirtyCellsToRemove.Count == 0, "temp list is not empty!");
            m_dirtyCellsToRemove.Clear();

            Debug.Assert(m_dirtyCells.Count == 0, "temp list is not empty!");
            m_dirtyCells.Clear();

            m_dirtyCellsToAdd.Clear(); // this can have some cells if the unload happened after removing tracked entity

            Static = null;
        }
        public override void LoadData()
        {
            Static = this;
            if (!MyFakes.ENABLE_ASTEROID_FIELDS)
                return;

            var settings = MySession.Static.Settings;
            if (settings.ProceduralDensity == 0f)
            {
                m_densityFunctions.Clear();
                MySandboxGame.Log.WriteLine("Skip Procedural World Generator");
                return;
            }

            m_seed = settings.ProceduralSeed;
            m_objectDensity = settings.ProceduralDensity * 2 - 1; // must be -1..1
            MySandboxGame.Log.WriteLine(string.Format("Loading Procedural World Generator: Seed = '{0}' = {1}, Density = {2}", settings.ProceduralSeed, m_seed, settings.ProceduralDensity));

            using (MyRandom.Instance.PushSeed(m_seed))
            {
                m_densityFunctions.Add(new MyAsteroidInfiniteDensityFunction(MyRandom.Instance, 0.003));
            }

            m_seedTypeProbabilitySum = 0;
            foreach (var probability in m_seedTypeProbability.Values)
            {
                m_seedTypeProbabilitySum += probability;
            }
            Debug.Assert(m_seedTypeProbabilitySum != 0);

            m_seedClusterTypeProbabilitySum = 0;
            foreach (var probability in m_seedClusterTypeProbability.Values)
            {
                m_seedClusterTypeProbabilitySum += probability;
            }
            Debug.Assert(m_seedClusterTypeProbabilitySum != 0);
        }
        public static bool PlaceEncounterToWorld(BoundingBoxD boundingVolume, int seed, MyAsteroidCellGenerator.MyObjectSeedType seedType)
        {
            if (MySession.Static.Settings.EnableEncounters == false)
            {
                return false;
            }

            Vector3D placePosition = boundingVolume.Center;
            m_random.SetSeed(seed);

            if (m_spawnGroups.Count == 0)
            {
                m_spawnGroupsNoVoxels.Clear();
                var allSpawnGroups = MyDefinitionManager.Static.GetSpawnGroupDefinitions();
                foreach (var spawnGroup in allSpawnGroups)
                {
                    if (spawnGroup.IsEncounter)
                    {
                        m_spawnGroups.Add(spawnGroup);
                        if (spawnGroup.Voxels.Count == 0)
                        {
                            m_spawnGroupsNoVoxels.Add(spawnGroup);
                        }
                    }
                }
            }

            if (m_spawnGroups.Count > 0)
            {
                m_randomEncounters.Clear();
                m_placePositions.Clear();
                m_encountersId.Clear();
                int numEncoutersToPlace = seedType == MyAsteroidCellGenerator.MyObjectSeedType.EncounterMulti ? 2 : 1;
                List<MySpawnGroupDefinition> currentSpawnGroup = seedType == MyAsteroidCellGenerator.MyObjectSeedType.EncounterMulti ? m_spawnGroupsNoVoxels : m_spawnGroups;

                for (int i = 0; i < numEncoutersToPlace; ++i)
                {
                    MyEncounterId encounterPosition = new MyEncounterId(boundingVolume, seed, i);
                    if (true == m_savedEncounters.Contains(encounterPosition))
                    {
                        continue;
                    }
                    m_randomEncounters.Add(PickRandomEncounter(currentSpawnGroup));
                    Vector3D newPosition = placePosition + (i == 0 ? -1 : 1) * GetEncounterBoundingBox(currentSpawnGroup[m_randomEncounters[m_randomEncounters.Count - 1]]).HalfExtents;
                    Vector3D savedPosition = Vector3D.Zero;
                    if (true == m_movedOnlyEncounters.Dictionary.TryGetValue(encounterPosition, out savedPosition))
                    {
                        newPosition = savedPosition;
                    }
                    encounterPosition.PlacePosition = newPosition;

                    m_encountersId.Add(encounterPosition);

                    m_placePositions.Add(newPosition);
                }

                //first place voxels becaose voxel needs to be created even on client and if grids were created first
                //entity ids woudn't match
                for (int i = 0; i < m_randomEncounters.Count; ++i)
                {
                    foreach (var selectedVoxel in currentSpawnGroup[m_randomEncounters[i]].Voxels)
                    {
                        var filePath = MyWorldGenerator.GetVoxelPrefabPath(selectedVoxel.StorageName);

                        var storage = MyStorageBase.LoadFromFile(filePath);
                        storage.DataProvider = MyCompositeShapeProvider.CreateAsteroidShape(0, 1.0f, MySession.Static.Settings.VoxelGeneratorVersion);
                        IMyEntity voxel = MyWorldGenerator.AddVoxelMap(String.Format("Asteroid_{0}_{1}_{2}", m_entityToEncounterConversion.Count, seed, m_random.Next()), storage, m_placePositions[i] + selectedVoxel.Offset);
                        voxel.Save = false;
                        voxel.OnPhysicsChanged += OnCreatedEntityChanged;
                        m_entityToEncounterConversion[voxel] = m_encountersId[i];
                    }
                }

                if (Sync.IsServer == true)
                {
                    for (int i = 0; i < m_randomEncounters.Count; ++i)
                    {
                        SpawnEncouter(m_encountersId[i], m_placePositions[i], currentSpawnGroup, m_randomEncounters[i]);
                    }
                }
            }

            return true;
        }