Exemplo n.º 1
0
        public override unsafe void ProcessItems(Dictionary <short, MyLodEnvironmentItemSet> items, List <MySurfaceParams> surfaceParamsPerLod, int[] surfaceParamLodOffsets, int changedLodMin, int changedLodMax)
        {
            m_minScannedLod = changedLodMin;

            using (var batch = new MyEnvironmentModelUpdateBatch(Sector))
                foreach (var group in items)
                {
                    MyRuntimeEnvironmentItemInfo it;
                    Sector.GetItemDefinition((ushort)group.Key, out it);
                    MyDefinitionId modelCollection = new MyDefinitionId(typeof(MyObjectBuilder_PhysicalModelCollectionDefinition), it.Subtype);

                    MyPhysicalModelCollectionDefinition modelCollectionDef = MyDefinitionManager.Static.GetDefinition <MyPhysicalModelCollectionDefinition>(modelCollection);
                    if (modelCollectionDef != null)
                    {
                        var info = group.Value;
                        int offt = info.LodOffsets[changedLodMin];

                        for (int i = offt; i < info.Items.Count; ++i)
                        {
                            var position = info.Items[i];

                            if (m_disabledItems.Contains(position) || IsObstructed(position))
                            {
                                continue;
                            }
                            var modelDef = modelCollectionDef.Items.Sample(MyHashRandomUtils.UniformFloatFromSeed(position));

                            batch.Add(modelDef, position);
                        }
                    }
                }
        }
Exemplo n.º 2
0
        public Vector3 GetRandomPerpendicularVector(ref Vector3 axis, int seed)
        {
            Vector3 tangent = Vector3.CalculatePerpendicularVector(axis);
            Vector3 bitangent; Vector3.Cross(ref axis, ref tangent, out bitangent);
            double  angle = MyHashRandomUtils.UniformFloatFromSeed(seed) * 2 * MathHelper.Pi;

            return((float)Math.Cos(angle) * tangent + (float)Math.Sin(angle) * bitangent);
        }
Exemplo n.º 3
0
        private void AddVoxelMaps()
        {
            if (m_voxelMaps.Count > 0)
            {
                return;
            }

            foreach (var map in m_voxelMapsToAdd)
            {
                MyVoxelMap existingStone;

                // Handle when the stone was already modified and is sent by the server.
                if (MyEntities.TryGetEntityById(map.EntityId, out existingStone))
                {
                    if (!existingStone.Save)
                    {
                        // It's just still on the different lod sector.
                        RegisterVoxelMap(map.Item, existingStone);
                    }
                    else
                    {
                        // it was saved and we don't know about it, baad
                        if (existingStone != null && existingStone.StorageName == map.Name)
                        {
                            Debug.Assert(false, "Storage was already sent but sector did not know about the modified item.");
                        }
                        else
                        {
                            Debug.Assert(false, "Voxel stone entity Id collisioncollision.");
                        }
                    }
                    continue;
                }

                var mod = MyDefinitionManager.Static.GetDefinition <MyVoxelMaterialModifierDefinition>(map.Modifier);
                Dictionary <byte, byte> ops = null;

                //if there is modifier pick one based on chance
                if (mod != null)
                {
                    ops = mod.Options.Sample(MyHashRandomUtils.UniformFloatFromSeed(map.Item)).Changes;
                }

                AddVoxelMap(map.Item, map.Storage.SubtypeName, map.Matrix, map.Name, map.EntityId, ops);
            }
        }
        public virtual void ProcessItems(Dictionary <short, MyLodEnvironmentItemSet> items, List <MySurfaceParams> surfaceParamsPerLod, int[] surfaceParamLodOffsets, int changedLodMin, int changedLodMax)
        {
            using (var batch = new MyEnvironmentModelUpdateBatch(Sector))
                foreach (var group in items)
                {
                    MyRuntimeEnvironmentItemInfo it;
                    Sector.GetItemDefinition((ushort)group.Key, out it);
                    MyDefinitionId modelCollection = new MyDefinitionId(typeof(MyObjectBuilder_PhysicalModelCollectionDefinition), it.Subtype);

                    MyPhysicalModelCollectionDefinition modelCollectionDef = MyDefinitionManager.Static.GetDefinition <MyPhysicalModelCollectionDefinition>(modelCollection);
                    if (modelCollectionDef != null)
                    {
                        foreach (var position in group.Value.Items)
                        {
                            var sample   = MyHashRandomUtils.UniformFloatFromSeed(position);
                            var modelDef = modelCollectionDef.Items.Sample(sample);

                            batch.Add(modelDef, position);
                        }
                    }
                }
        }
Exemplo n.º 5
0
        private MyRuntimeEnvironmentItemInfo GetItemForPosition(ref MySurfaceParams surface, int lod)
        {
            var key = new MyBiomeMaterial(surface.Biome, surface.Material);

            m_candidates.Clear();

            List <MyEnvironmentItemMapping> ruleset;

            if (m_environment.MaterialEnvironmentMappings.TryGetValue(key, out ruleset))
            {
                foreach (var rule in ruleset)
                {
                    var sampler = rule.Sampler(lod);
                    if (sampler != null && rule.Rule.Check(surface.HeightRatio, surface.Latitude, surface.Longitude, surface.Normal.Z))
                    {
                        m_candidates.Add(sampler);
                    }
                }
            }

            var seed = surface.Position.GetHashCode();

            float sample = MyHashRandomUtils.UniformFloatFromSeed(seed);

            switch (m_candidates.Count)
            {
            case 0:
                return(null);

            case 1:
                return(m_candidates[0].Sample(sample));

            default:
                return(m_candidates[(int)(MyHashRandomUtils.UniformFloatFromSeed(~seed) * m_candidates.Count)].Sample(sample));
            }
        }