Ejemplo n.º 1
0
        private void UpdateModuleBuilders(MyObjectBuilder_ProceduralEnvironmentSector moduleData)
        {
            m_moduleData.Clear();

            if (moduleData == null)
            {
                return;
            }

            for (int i = 0; i < moduleData.SavedModules.Length; i++)
            {
                var mod = moduleData.SavedModules[i];

                var def = MyDefinitionManager.Static.GetDefinition <MyProceduralEnvironmentModuleDefinition>(mod.ModuleId);

                if (def != null)
                {
                    m_moduleData.Add(def.ModuleType, mod.Builder);

                    ModuleData module;
                    if (m_modules.TryGetValue(def.ModuleType, out module))
                    {
                        module.Module.Init(this, mod.Builder);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override MyObjectBuilder_EnvironmentSector GetObjectBuilder()
        {
            List <MyObjectBuilder_ProceduralEnvironmentSector.Module> modulesToSave = new List <MyObjectBuilder_ProceduralEnvironmentSector.Module>(m_modules.Count);

            foreach (var module in m_modules.Values)
            {
                var builder = module.Module.GetObjectBuilder();
                if (builder != null)
                {
                    modulesToSave.Add(new MyObjectBuilder_ProceduralEnvironmentSector.Module()
                    {
                        ModuleId = module.Definition,
                        Builder  = builder
                    });
                }
            }

            if (modulesToSave.Count > 0)
            {
                modulesToSave.Capacity = modulesToSave.Count;
                var sector = new MyObjectBuilder_ProceduralEnvironmentSector
                {
                    SavedModules = modulesToSave.GetInternalArray(),
                    SectorId     = Id
                };

                return(sector);
            }

            return(null);
        }
Ejemplo n.º 3
0
        public MyProceduralLogicalSector(MyProceduralEnvironmentProvider provider, int x, int y, int localLod, MyObjectBuilder_ProceduralEnvironmentSector moduleData)
        {
            Provider = provider;

            Owner = provider.Owner;

            X   = x;
            Y   = y;
            Lod = localLod;

            provider.GeSectorWorldParameters(x, y, localLod * provider.LodFactor, out WorldPos, out BasisX, out BasisY);

            m_environment = (MyProceduralEnvironmentDefinition)provider.Owner.EnvironmentDefinition;

            m_itemPositionRng = new MyRandom(provider.GetSeed() ^ ((x * 377 + y) * 377 + Lod));

            // Area of the scanning surface:
            // We know that the norm of the cross product of two vectors is the are of the parallelogram delimited by them.
            // Since the basis surface is the union of the parallelograms delimited by basis and it's sign permutations
            // we have that the are is 4 times the norm of the cross product.

            double area = Vector3.Cross(BasisX, BasisY).Length() * 4;

            m_itemCountTotal = (int)(area * m_environment.ItemDensity);

            //if (localLod != 0) m_itemCountTotal = m_itemCountTotal;

            m_scanHelper = new ProgressiveScanHelper(m_itemCountTotal, localLod * provider.LodFactor);

            Bounds = Owner.GetBoundingShape(ref WorldPos, ref BasisX, ref BasisY);

            m_items = new List <ItemInfo>();

            m_totalSpawned = 0;

            UpdateModuleBuilders(moduleData);
        }