Exemple #1
0
        /// <summary>
        /// Should be called when a map is loaded. Sets up visgroups, object ids, gamedata, and textures.
        /// </summary>
        public void PostLoadProcess(GameData.GameData gameData, Func <string, ITexture> textureAccessor, Func <string, float> textureOpacity)
        {
            PartialPostLoadProcess(gameData, textureAccessor, textureOpacity);

            var all = WorldSpawn.FindAll();

            // Set maximum ids
            var maxObjectId = all.Max(x => x.ID);
            var faces       = all.OfType <Solid>().SelectMany(x => x.Faces).ToList();
            var maxFaceId   = faces.Any() ? faces.Max(x => x.ID) : 0;

            IDGenerator.Reset(maxObjectId, maxFaceId);

            // todo visgroups
            // WorldSpawn.ForEach(x => x.IsVisgroupHidden, x => x.IsVisgroupHidden = true, true);

            // Auto visgroup
            var auto      = AutoVisgroup.GetDefaultAutoVisgroup();
            var quickHide = new AutoVisgroup {
                ID = int.MinValue, IsHidden = true, Name = "Autohide", Parent = auto, Visible = false
            };

            auto.Children.Add(quickHide);
            Visgroups.Add(auto);
            UpdateAutoVisgroups(all, false);

            // Purge empty groups
            foreach (var emptyGroup in WorldSpawn.Find(x => x is Group && !x.HasChildren))
            {
                emptyGroup.SetParent(null);
            }
        }
Exemple #2
0
 /// <summary>
 /// Get the visgroups for this object.
 /// </summary>
 /// <param name="inherit">True to include inherited visgroups</param>
 /// <returns>The list of visgroups</returns>
 public IEnumerable <int> GetVisgroups(bool inherit)
 {
     if (!inherit || Parent == null)
     {
         return(Visgroups);
     }
     return(Visgroups.Union(Parent.GetVisgroups(true)));
 }
Exemple #3
0
 public void GetObjectData(SerializationInfo info, StreamingContext context)
 {
     info.AddValue("Version", Version);
     info.AddValue("Visgroups", Visgroups.ToArray());
     info.AddValue("Cameras", Cameras.ToArray());
     info.AddValue("ActiveCameraID", Cameras.IndexOf(ActiveCamera));
     info.AddValue("WorldSpawn", WorldSpawn);
     info.AddValue("IDGenerator", IDGenerator);
 }
Exemple #4
0
 public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
 {
     info.AddValue("ID", ID);
     info.AddValue("ClassName", ClassName);
     info.AddValue("Visgroups", String.Join(",", Visgroups.Select(x => x.ToString(CultureInfo.InvariantCulture))));
     info.AddValue("AutoVisgroups", String.Join(",", AutoVisgroups.Select(x => x.ToString(CultureInfo.InvariantCulture))));
     info.AddValue("Colour", Colour.ToArgb());
     info.AddValue("Children", GetChildren().ToArray());
 }
Exemple #5
0
        public IEnumerable <MapFeature> GetUsedFeatures()
        {
            var all = WorldSpawn.FindAll();

            // Too generic: this should be assumed
            // yield return MapFeature.Worldspawn;

            if (all.Any(x => x is Solid))
            {
                yield return(MapFeature.Solids);
            }

            if (all.Any(x => x is Entity))
            {
                yield return(MapFeature.Entities);
            }

            if (all.Any(x => x is Group))
            {
                yield return(MapFeature.Groups);
            }

            if (all.OfType <Solid>().Any(x => x.Faces.Any(y => y is Displacement)))
            {
                yield return(MapFeature.Displacements);
            }

            // Not implemented yet
            // yield return MapFeature.Instances;

            if (Visgroups.Any())
            {
                yield return(MapFeature.SingleVisgroups);
            }

            if (all.Any(x => x.Visgroups.Count > 1))
            {
                yield return(MapFeature.MultipleVisgroups);
            }

            // If we have more than one camera, we care about losing them
            if (Cameras.Count > 1)
            {
                yield return(MapFeature.Cameras);
            }

            // Not important enough to care about:
            // yield return MapFeature.Colours;
            // yield return MapFeature.CordonBounds;
            // yield return MapFeature.ViewSettings;
        }
Exemple #6
0
        protected void PasteBase(MapObject o, IDGenerator generator, bool performUnclone = false)
        {
            Visgroups.Clear();
            AutoVisgroups.Clear();
            Children.Clear();

            if (performUnclone && o.ID != ID)
            {
                var parent = Parent;
                var setPar = Parent != null && Parent.Children.ContainsKey(ID) && Parent.Children[ID] == this;
                if (setPar)
                {
                    SetParent(null);
                }
                ID = o.ID;
                if (setPar)
                {
                    SetParent(parent);
                }
            }
            ClassName = o.ClassName;
            Visgroups.AddRange(o.Visgroups);
            AutoVisgroups.AddRange(o.AutoVisgroups);
            Parent           = o.Parent;
            Colour           = o.Colour;
            IsSelected       = o.IsSelected;
            IsCodeHidden     = o.IsCodeHidden;
            IsRenderHidden2D = o.IsRenderHidden2D;
            IsRenderHidden3D = o.IsRenderHidden3D;
            IsVisgroupHidden = o.IsVisgroupHidden;
            BoundingBox      = o.BoundingBox.Clone();
            MetaData         = o.MetaData.Clone();

            var children = o.GetChildren().Select(x => performUnclone ? x.Clone() : x.Copy(generator));

            foreach (var c in children)
            {
                c.SetParent(this);
            }
        }
Exemple #7
0
 /// <summary>
 /// Returns true if this object is in the given visgroup.
 /// </summary>
 /// <param name="visgroup">The visgroup to check</param>
 /// <returns>True if this object is in the visgroup</returns>
 public bool IsInVisgroup(int visgroup)
 {
     return(Visgroups.Contains(visgroup));
 }