Esempio n. 1
0
        // This sets the Lower Unpegged flag
        public virtual void ApplyLowerUnpegged(bool set)
        {
            if (!set)
            {
                // Remove flag
                mode.CreateUndo("Remove lower-unpegged setting");
                mode.SetActionResult("Removed lower-unpegged setting.");
                this.Sidedef.Line.SetFlag(General.Map.Config.LowerUnpeggedFlag, false);
            }
            else
            {
                // Add flag
                mode.CreateUndo("Set lower-unpegged setting");
                mode.SetActionResult("Set lower-unpegged setting.");
                this.Sidedef.Line.SetFlag(General.Map.Config.LowerUnpeggedFlag, true);
            }

            // Update sidedef geometry
            VisualSidedefParts parts = Sector.GetSidedefParts(Sidedef);

            parts.SetupAllParts();

            // Update other sidedef geometry
            if (Sidedef.Other != null)
            {
                BaseVisualSector othersector = (BaseVisualSector)mode.GetVisualSector(Sidedef.Other.Sector);
                parts = othersector.GetSidedefParts(Sidedef.Other);
                parts.SetupAllParts();
            }
        }
Esempio n. 2
0
        // Flood-fill textures
        public virtual void OnTextureFloodfill()
        {
            if (BuilderPlug.Me.CopiedTexture != null)
            {
                string oldtexture     = GetTextureName();
                long   oldtexturelong = Lump.MakeLongName(oldtexture);
                string newtexture     = BuilderPlug.Me.CopiedTexture;
                if (newtexture != oldtexture)
                {
                    mode.CreateUndo("Flood-fill textures with " + newtexture);
                    mode.SetActionResult("Flood-filled textures with " + newtexture + ".");

                    mode.Renderer.SetCrosshairBusy(true);
                    General.Interface.RedrawDisplay();

                    // Get the texture
                    ImageData newtextureimage = General.Map.Data.GetTextureImage(newtexture);
                    if (newtextureimage != null)
                    {
                        if (mode.IsSingleSelection)
                        {
                            // Clear all marks, this will align everything it can
                            General.Map.Map.ClearMarkedSidedefs(false);
                        }
                        else
                        {
                            // Limit the alignment to selection only
                            General.Map.Map.ClearMarkedSidedefs(true);
                            List <Sidedef> sides = mode.GetSelectedSidedefs();
                            foreach (Sidedef sd in sides)
                            {
                                sd.Marked = false;
                            }
                        }

                        // Do the alignment
                        Tools.FloodfillTextures(this.Sidedef, oldtexturelong, newtextureimage, false);

                        // Get the changed sidedefs
                        List <Sidedef> changes = General.Map.Map.GetMarkedSidedefs(true);
                        foreach (Sidedef sd in changes)
                        {
                            // Update the parts for this sidedef!
                            if (mode.VisualSectorExists(sd.Sector))
                            {
                                BaseVisualSector   vs    = (mode.GetVisualSector(sd.Sector) as BaseVisualSector);
                                VisualSidedefParts parts = vs.GetSidedefParts(sd);
                                parts.SetupAllParts();
                            }
                        }

                        General.Map.Data.UpdateUsedTextures();
                        mode.Renderer.SetCrosshairBusy(false);
                        mode.ShowTargetInfo();
                    }
                }
            }
        }
Esempio n. 3
0
 //mxd
 private void UpdateSectorSides(Sector s)
 {
     foreach (Sidedef side in s.Sidedefs)
     {
         if (side.Other != null && side.Other.Sector != null && data.Mode.VisualSectorExists(side.Other.Sector))
         {
             BaseVisualSector vs = (BaseVisualSector)data.Mode.GetVisualSector(side.Other.Sector);
             vs.GetSidedefParts(side.Other).SetupAllParts();
         }
     }
 }
Esempio n. 4
0
        // Auto-align texture X offsets
        public virtual void OnTextureAlign(bool alignx, bool aligny)
        {
            mode.CreateUndo("Auto-align textures");
            mode.SetActionResult("Auto-aligned textures.");

            // Make sure the texture is loaded (we need the texture size)
            if (!base.Texture.IsImageLoaded)
            {
                base.Texture.LoadImage();
            }

            if (mode.IsSingleSelection)
            {
                // Clear all marks, this will align everything it can
                General.Map.Map.ClearMarkedSidedefs(false);
            }
            else
            {
                // Limit the alignment to selection only
                General.Map.Map.ClearMarkedSidedefs(true);
                List <Sidedef> sides = mode.GetSelectedSidedefs();
                foreach (Sidedef sd in sides)
                {
                    sd.Marked = false;
                }
            }

            // Do the alignment
            Tools.AutoAlignTextures(this.Sidedef, base.Texture, alignx, aligny, false);

            // Get the changed sidedefs
            List <Sidedef> changes = General.Map.Map.GetMarkedSidedefs(true);

            foreach (Sidedef sd in changes)
            {
                // Update the parts for this sidedef!
                if (mode.VisualSectorExists(sd.Sector))
                {
                    BaseVisualSector   vs    = (mode.GetVisualSector(sd.Sector) as BaseVisualSector);
                    VisualSidedefParts parts = vs.GetSidedefParts(sd);
                    parts.SetupAllParts();
                }
            }
        }
Esempio n. 5
0
        //mxd
        protected override void UpdateSkyRenderFlag()
        {
            bool isrenderedassky = renderassky;

            renderassky = (level.sector.CeilTexture == General.Map.Config.SkyFlatName);
            if (isrenderedassky != renderassky && Sector.Sides != null)
            {
                // Upper/middle geometry may need updating...
                foreach (Sidedef side in level.sector.Sidedefs)
                {
                    VisualSidedefParts parts = Sector.GetSidedefParts(side);
                    if (parts.upper != null)
                    {
                        parts.upper.UpdateSkyRenderFlag();
                    }
                    else if (parts.middlesingle != null)
                    {
                        parts.middlesingle.UpdateSkyRenderFlag();
                    }

                    // On the other side as well...
                    if (side.Other != null && side.Other.Sector != null &&
                        side.Other.Sector.CeilTexture == General.Map.Config.SkyFlatName)
                    {
                        BaseVisualSector other = (BaseVisualSector)mode.GetVisualSector(side.Other.Sector);
                        if (other != null && other.Sides != null)
                        {
                            parts = other.GetSidedefParts(side.Other);
                            if (parts.upper != null)
                            {
                                parts.upper.UpdateSkyRenderFlag();
                            }
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        //mxd
        public bool Setup(SectorLevel level, Effect3DFloor extrafloor, bool innerside)
        {
            Sector   s = level.sector;
            Vector2D texscale;

            this.innerside = innerside;             //mxd

            base.Setup(level, extrafloor);

            // Fetch ZDoom fields
            float    rotate = Angle2D.DegToRad(s.Fields.GetValue("rotationceiling", 0.0f));
            Vector2D offset = new Vector2D(s.Fields.GetValue("xpanningceiling", 0.0f),
                                           s.Fields.GetValue("ypanningceiling", 0.0f));
            Vector2D scale = new Vector2D(s.Fields.GetValue("xscaleceiling", 1.0f),
                                          s.Fields.GetValue("yscaleceiling", 1.0f));

            //Load ceiling texture
            if (s.LongCeilTexture != MapSet.EmptyLongName)
            {
                base.Texture = General.Map.Data.GetFlatImage(s.LongCeilTexture);
                if (base.Texture == null || base.Texture is UnknownImage)
                {
                    base.Texture         = General.Map.Data.UnknownTexture3D;
                    setuponloadedtexture = s.LongCeilTexture;
                }
                else if (!base.Texture.IsImageLoaded)
                {
                    setuponloadedtexture = s.LongCeilTexture;
                }
            }
            else
            {
                // Use missing texture
                base.Texture         = General.Map.Data.MissingTexture3D;
                setuponloadedtexture = 0;
            }

            // Determine texture scale
            if (base.Texture.IsImageLoaded)
            {
                texscale = new Vector2D(1.0f / base.Texture.ScaledWidth, 1.0f / base.Texture.ScaledHeight);
            }
            else
            {
                texscale = new Vector2D(1.0f / 64.0f, 1.0f / 64.0f);
            }

            // Determine brightness
            byte alpha = (byte)General.Clamp(level.alpha, 0, 255);
            int  color = PixelColor.FromInt(level.color).WithAlpha(alpha).ToInt();
            int  targetbrightness;

            if (extrafloor != null && !extrafloor.VavoomType && !level.disablelighting)
            {
                //mxd. Top extrafloor level should calculate fogdensity from the brightness of the level above it
                if (!innerside)
                {
                    targetbrightness = 0;
                    SectorData sd = mode.GetSectorData(this.Sector.Sector);
                    for (int i = 0; i < sd.LightLevels.Count - 1; i++)
                    {
                        if (sd.LightLevels[i] == level)
                        {
                            targetbrightness = sd.LightLevels[i + 1].brightnessbelow;
                            break;
                        }
                    }
                }
                //mxd. Inner extrafloor ceilings must be colored using control sector's color and brightness
                else
                {
                    targetbrightness = level.brightnessbelow;
                    SectorData sd = mode.GetSectorData(this.Sector.Sector);
                    for (int i = 0; i < sd.LightLevels.Count; i++)
                    {
                        if (sd.LightLevels[i] == level)
                        {
                            if (i > 0)
                            {
                                color = PixelColor.FromInt(sd.LightLevels[i - 1].color).WithAlpha(alpha).ToInt();
                            }
                            break;
                        }
                    }
                }
            }
            else
            {
                targetbrightness = level.brightnessbelow;
            }

            //mxd. Determine fog density
            fogfactor = CalculateFogFactor(targetbrightness);

            // Make vertices
            ReadOnlyCollection <Vector2D> triverts = Sector.Sector.Triangles.Vertices;

            WorldVertex[] verts = new WorldVertex[triverts.Count];
            for (int i = 0; i < triverts.Count; i++)
            {
                // Color shading
                verts[i].c = color;                 //mxd

                // Vertex coordinates
                verts[i].x = triverts[i].x;
                verts[i].y = triverts[i].y;
                verts[i].z = level.plane.GetZ(triverts[i]);

                // Texture coordinates
                Vector2D pos = triverts[i];
                pos        = pos.GetRotated(rotate);
                pos.y      = -pos.y;
                pos        = (pos + offset) * scale * texscale;
                verts[i].u = pos.x;
                verts[i].v = pos.y;
            }

            // The sector triangulation created clockwise triangles that
            // are right up for the floor. For the ceiling we must flip
            // the triangles upside down.
            if (extrafloor == null || extrafloor.VavoomType || innerside)
            {
                SwapTriangleVertices(verts);
            }

            // Determine render pass
            if (extrafloor != null)
            {
                if (extrafloor.Sloped3dFloor)                //mxd
                {
                    this.RenderPass = RenderPass.Mask;
                }
                else if (extrafloor.RenderAdditive)                //mxd
                {
                    this.RenderPass = RenderPass.Additive;
                }
                else if (level.alpha < 255)
                {
                    this.RenderPass = RenderPass.Alpha;
                }
                else
                {
                    this.RenderPass = RenderPass.Mask;
                }
            }
            else
            {
                this.RenderPass = RenderPass.Solid;
            }

            //mxd. Update sky render flag
            bool isrenderedassky = renderassky;

            renderassky = (level.sector.CeilTexture == General.Map.Config.SkyFlatName);
            if (isrenderedassky != renderassky && Sector.Sides != null)
            {
                // Upper sidedef geometry may need updating...
                foreach (Sidedef side in level.sector.Sidedefs)
                {
                    VisualSidedefParts parts = Sector.GetSidedefParts(side);

                    // Upper side can exist in either our, or the neightbouring sector, right?
                    if (parts.upper != null && parts.upper.Triangles > 0)
                    {
                        parts.upper.UpdateSkyRenderFlag();
                    }
                    else if (side.Other != null && side.Other.Sector != null && side.Other.Sector.CeilTexture == General.Map.Config.SkyFlatName)
                    {
                        // Update upper side of the neightbouring sector
                        BaseVisualSector other = (BaseVisualSector)mode.GetVisualSector(side.Other.Sector);
                        if (other != null && other.Sides != null)
                        {
                            parts = other.GetSidedefParts(side.Other);
                            if (parts.upper != null && parts.upper.Triangles > 0)
                            {
                                parts.upper.UpdateSkyRenderFlag();
                            }
                        }
                    }
                }
            }

            // Apply vertices
            base.SetVertices(verts);
            return(verts.Length > 0);
        }
Esempio n. 7
0
        // This usually happens when geometry is changed by undo, redo, cut or paste actions
        // and uses the marks to check what needs to be reloaded.
        protected override void ResourcesReloadedPartial()
        {
            bool sectorsmarked = false;

            if (General.Map.UndoRedo.GeometryChanged)
            {
                // Let the core do this (it will just dispose the sectors that were changed)
                base.ResourcesReloadedPartial();
            }
            else
            {
                // Neighbour sectors must be updated as well
                foreach (Sector s in General.Map.Map.Sectors)
                {
                    if (s.Marked)
                    {
                        sectorsmarked = true;
                        foreach (Sidedef sd in s.Sidedefs)
                        {
                            sd.Marked = true;
                            if (sd.Other != null)
                            {
                                sd.Other.Marked = true;
                            }
                        }
                    }
                }

                // Go for all sidedefs to update
                foreach (Sidedef sd in General.Map.Map.Sidedefs)
                {
                    if (sd.Marked && VisualSectorExists(sd.Sector))
                    {
                        BaseVisualSector   vs    = (BaseVisualSector)GetVisualSector(sd.Sector);
                        VisualSidedefParts parts = vs.GetSidedefParts(sd);
                        parts.SetupAllParts();
                    }
                }

                // Go for all sectors to update
                foreach (Sector s in General.Map.Map.Sectors)
                {
                    if (s.Marked && VisualSectorExists(s))
                    {
                        BaseVisualSector vs = (BaseVisualSector)GetVisualSector(s);
                        vs.Floor.Setup();
                        vs.Ceiling.Setup();
                    }
                }

                if (!sectorsmarked)
                {
                    // No sectors or geometry changed. So we only have
                    // to update things when they have changed.
                    foreach (KeyValuePair <Thing, VisualThing> vt in allthings)
                    {
                        if (vt.Key.Marked)
                        {
                            (vt.Value as BaseVisualThing).Rebuild();
                        }
                    }
                }
                else
                {
                    // Things depend on the sector they are in and because we can't
                    // easily determine which ones changed, we dispose all things
                    foreach (KeyValuePair <Thing, VisualThing> vt in allthings)
                    {
                        vt.Value.Dispose();
                    }

                    // Apply new lists
                    allthings = new Dictionary <Thing, VisualThing>(allthings.Count);
                }

                // Clear visibility collections
                visiblesectors.Clear();
                visibleblocks.Clear();
                visiblegeometry.Clear();
                visiblethings.Clear();

                // Make new blockmap
                if (sectorsmarked || General.Map.UndoRedo.PopulationChanged)
                {
                    FillBlockMap();
                }

                // Visibility culling (this re-creates the needed resources)
                DoCulling();
            }

            // Determine what we're aiming at now
            PickTarget();
        }