コード例 #1
0
        //mxd
        private void CreateTiles()
        {
            Point               lt        = TileForPoint(mapbounds.Left - Tile.TILE_SIZE, mapbounds.Top - Tile.TILE_SIZE);
            Point               rb        = TileForPoint(mapbounds.Right + Tile.TILE_SIZE, mapbounds.Bottom + Tile.TILE_SIZE);
            Rectangle           tilesrect = new Rectangle(lt.X, lt.Y, rb.X - lt.X, rb.Y - lt.Y);
            NearestLineBlockmap blockmap  = new NearestLineBlockmap(tilesrect);

            for (int x = tilesrect.X; x <= tilesrect.Right; x += Tile.TILE_SIZE)
            {
                for (int y = tilesrect.Y; y <= tilesrect.Bottom; y += Tile.TILE_SIZE)
                {
                    // If the tile is obviously outside the map, don't create it
                    Vector2D pc         = new Vector2D(x + (Tile.TILE_SIZE >> 1), y + (Tile.TILE_SIZE >> 1));
                    Linedef  ld         = MapSet.NearestLinedef(blockmap.GetBlockAt(pc).Lines, pc);
                    double   distancesq = ld.DistanceToSq(pc, true);
                    if (distancesq > (Tile.TILE_SIZE * Tile.TILE_SIZE))
                    {
                        double side = ld.SideOfLine(pc);
                        if ((side > 0.0f) && (ld.Back == null))
                        {
                            continue;
                        }
                    }

                    Point tp = new Point(x, y);
                    tiles.Add(tp, new Tile(tp));
                }
            }
        }
コード例 #2
0
ファイル: LuaLinedef.cs プロジェクト: volte/doombuilderx
        public float DistanceToSq(LuaVector2D p, bool bounded)
        {
            if (linedef.IsDisposed)
            {
                throw new ScriptRuntimeException("Linedef has been disposed, can't DistanceToSq.");
            }

            return(linedef.DistanceToSq(p.vec, bounded));
        }
コード例 #3
0
        // Mode starts
        public override void OnEngage()
        {
            Cursor.Current = Cursors.WaitCursor;
            base.OnEngage();
            General.Interface.DisplayStatus(StatusType.Busy, "Setting up test environment...");

            CleanUp();

            BuilderPlug.InterfaceForm.AddToInterface();
            lastviewstats = BuilderPlug.InterfaceForm.ViewStats;

            // Export the current map to a temporary WAD file
            tempfile = BuilderPlug.MakeTempFilename(".wad");
            General.Map.ExportToFile(tempfile);

            // Load the map in VPO_DLL
            BuilderPlug.VPO.Start(tempfile, General.Map.Options.LevelName);

            // Determine map boundary
            mapbounds = Rectangle.Round(MapSet.CreateArea(General.Map.Map.Vertices));

            // Create tiles for all points inside the map
            Point               lt        = TileForPoint(mapbounds.Left - Tile.TILE_SIZE, mapbounds.Top - Tile.TILE_SIZE);
            Point               rb        = TileForPoint(mapbounds.Right + Tile.TILE_SIZE, mapbounds.Bottom + Tile.TILE_SIZE);
            Rectangle           tilesrect = new Rectangle(lt.X, lt.Y, rb.X - lt.X, rb.Y - lt.Y);
            NearestLineBlockmap blockmap  = new NearestLineBlockmap(tilesrect);

            for (int x = tilesrect.X; x <= tilesrect.Right; x += Tile.TILE_SIZE)
            {
                for (int y = tilesrect.Y; y <= tilesrect.Bottom; y += Tile.TILE_SIZE)
                {
                    // If the tile is obviously outside the map, don't create it
                    Vector2D pc         = new Vector2D(x + (Tile.TILE_SIZE >> 1), y + (Tile.TILE_SIZE >> 1));
                    Linedef  ld         = MapSet.NearestLinedef(blockmap.GetBlockAt(pc).Lines, pc);
                    float    distancesq = ld.DistanceToSq(pc, true);
                    if (distancesq > (Tile.TILE_SIZE * Tile.TILE_SIZE))
                    {
                        float side = ld.SideOfLine(pc);
                        if ((side > 0.0f) && (ld.Back == null))
                        {
                            continue;
                        }
                    }

                    Point tp = new Point(x, y);
                    tiles.Add(tp, new Tile(tp));
                }
            }

            QueuePoints(0);

            // Make an image to draw on.
            // The BitmapImage for Doom Builder's resources must be Format32bppArgb and NOT using color correction,
            // otherwise DB will make a copy of the bitmap when LoadImage() is called! This is normally not a problem,
            // but we want to keep drawing to the same bitmap.
            int width  = General.NextPowerOf2(General.Interface.Display.ClientSize.Width);
            int height = General.NextPowerOf2(General.Interface.Display.ClientSize.Height);

            canvas = new Bitmap(width, height, PixelFormat.Format32bppArgb);
            image  = new DynamicBitmapImage(canvas, "_CANVAS_");
            image.UseColorCorrection = false;
            image.MipMapLevels       = 1;
            image.LoadImage();
            image.CreateTexture();

            // Make custom presentation
            CustomPresentation p = new CustomPresentation();

            p.AddLayer(new PresentLayer(RendererLayer.Overlay, BlendingMode.Mask, 1f, false));
            p.AddLayer(new PresentLayer(RendererLayer.Grid, BlendingMode.Mask));
            p.AddLayer(new PresentLayer(RendererLayer.Geometry, BlendingMode.Alpha, 1f, true));
            renderer.SetPresentation(p);

            // Setup processing
            nextupdate = DateTime.Now + new TimeSpan(0, 0, 0, 0, 100);
            General.Interface.EnableProcessing();
            processingenabled = true;

            RedrawAllTiles();
            Cursor.Current = Cursors.Default;
            General.Interface.SetCursor(Cursors.Cross);
            General.Interface.DisplayReady();
        }
コード例 #4
0
        // This makes sure we are updated with the source linedef information
        public override void Update()
        {
            if (l.Front == null || l.Back == null)
            {
                return;                                               //mxd
            }
            // Find the vertex furthest from the line
            Vertex foundv    = null;
            float  founddist = -1.0f;

            foreach (Sidedef sd in data.Sector.Sidedefs)
            {
                Vertex v = sd.IsFront ? sd.Line.Start : sd.Line.End;
                float  d = l.DistanceToSq(v.Position, false);
                if (d > founddist)
                {
                    foundv    = v;
                    founddist = d;
                }
            }

            if (foundv == null)
            {
                return;                            //mxd
            }
            bool updatesides = false;

            // Align floor with back of line
            if ((l.Args[0] == 1) && (l.Front.Sector == data.Sector))
            {
                Vector3D v1 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Back.Sector.FloorHeight);
                Vector3D v2 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Back.Sector.FloorHeight);
                Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, data.Sector.FloorHeight);
                data.Floor.plane = (l.SideOfLine(v3) < 0.0f ? new Plane(v1, v2, v3, true) : new Plane(v2, v1, v3, true));

                //mxd. Update only when actually changed
                if (storedfloor != data.Floor.plane)
                {
                    storedfloor = data.Floor.plane;
                    updatesides = true;
                }
            }
            // Align floor with front of line
            else if ((l.Args[0] == 2) && (l.Back.Sector == data.Sector))
            {
                Vector3D v1 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Front.Sector.FloorHeight);
                Vector3D v2 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Front.Sector.FloorHeight);
                Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, data.Sector.FloorHeight);
                data.Floor.plane = (l.SideOfLine(v3) < 0.0f ? new Plane(v1, v2, v3, true) : new Plane(v2, v1, v3, true));

                //mxd. Update only when actually changed
                if (storedfloor != data.Floor.plane)
                {
                    storedfloor = data.Floor.plane;
                    updatesides = true;
                }
            }

            // Align ceiling with back of line
            if ((l.Args[1] == 1) && (l.Front.Sector == data.Sector))
            {
                Vector3D v1 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Back.Sector.CeilHeight);
                Vector3D v2 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Back.Sector.CeilHeight);
                Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, data.Sector.CeilHeight);
                data.Ceiling.plane = (l.SideOfLine(v3) > 0.0f ? new Plane(v1, v2, v3, false) : new Plane(v2, v1, v3, false));

                //mxd. Update only when actually changed
                if (storedceiling != data.Ceiling.plane)
                {
                    storedceiling = data.Ceiling.plane;
                    updatesides   = true;
                }
            }
            // Align ceiling with front of line
            else if ((l.Args[1] == 2) && (l.Back.Sector == data.Sector))
            {
                Vector3D v1 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Front.Sector.CeilHeight);
                Vector3D v2 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Front.Sector.CeilHeight);
                Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, data.Sector.CeilHeight);
                data.Ceiling.plane = (l.SideOfLine(v3) > 0.0f ? new Plane(v1, v2, v3, false) : new Plane(v2, v1, v3, false));

                //mxd. Update only when actually changed
                if (storedceiling != data.Ceiling.plane)
                {
                    storedceiling = data.Ceiling.plane;
                    updatesides   = true;
                }
            }

            //mxd. Update outer sidedef geometry
            if (updatesides)
            {
                UpdateSectorSides(data.Sector);

                // Update sectors with PlaneCopySlope Effect...
                List <SectorData> toupdate = new List <SectorData>();
                foreach (Sector s in data.UpdateAlso.Keys)
                {
                    SectorData osd = data.Mode.GetSectorDataEx(s);
                    if (osd == null)
                    {
                        continue;
                    }
                    foreach (SectorEffect e in osd.Effects)
                    {
                        if (e is EffectPlaneCopySlope)
                        {
                            toupdate.Add(osd);
                            break;
                        }
                    }
                }

                // Do it in 2 steps, because SectorData.Reset() may change SectorData.UpdateAlso collection...
                foreach (SectorData sd in toupdate)
                {
                    // Update PlaneCopySlope Effect...
                    sd.Reset(false);

                    // Update outer sides...
                    UpdateSectorSides(sd.Sector);
                }
            }
        }
コード例 #5
0
ファイル: EffectLineSlope.cs プロジェクト: volte/doombuilderx
        // This makes sure we are updated with the source linedef information
        public override void Update()
        {
            Linedef l = linedef;

            // Find the vertex furthest from the line
            Vertex foundv    = null;
            float  founddist = -1.0f;

            foreach (Sidedef sd in data.Sector.Sidedefs)
            {
                Vertex v = sd.IsFront ? sd.Line.Start : sd.Line.End;
                float  d = l.DistanceToSq(v.Position, false);
                if (d > founddist)
                {
                    foundv    = v;
                    founddist = d;
                }
            }

            // Align floor with back of line
            if ((l.Args[0] == 1) && (l.Front.Sector == data.Sector) && (l.Back != null))
            {
                Vector3D v1 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Back.Sector.FloorHeight);
                Vector3D v2 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Back.Sector.FloorHeight);
                Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, data.Sector.FloorHeight);
                if (l.SideOfLine(v3) < 0.0f)
                {
                    data.Floor.plane = new Plane(v1, v2, v3, true);
                }
                else
                {
                    data.Floor.plane = new Plane(v2, v1, v3, true);
                }
                SectorData sd = data.Mode.GetSectorData(l.Back.Sector);
                sd.AddUpdateSector(data.Sector, true);
            }
            // Align floor with front of line
            else if ((l.Args[0] == 2) && (l.Back.Sector == data.Sector) && (l.Front != null))
            {
                Vector3D v1 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Front.Sector.FloorHeight);
                Vector3D v2 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Front.Sector.FloorHeight);
                Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, data.Sector.FloorHeight);
                if (l.SideOfLine(v3) < 0.0f)
                {
                    data.Floor.plane = new Plane(v1, v2, v3, true);
                }
                else
                {
                    data.Floor.plane = new Plane(v2, v1, v3, true);
                }
                SectorData sd = data.Mode.GetSectorData(l.Front.Sector);
                sd.AddUpdateSector(data.Sector, true);
            }

            // Align ceiling with back of line
            if ((l.Args[1] == 1) && (l.Front.Sector == data.Sector) && (l.Back != null))
            {
                Vector3D v1 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Back.Sector.CeilHeight);
                Vector3D v2 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Back.Sector.CeilHeight);
                Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, data.Sector.CeilHeight);
                if (l.SideOfLine(v3) > 0.0f)
                {
                    data.Ceiling.plane = new Plane(v1, v2, v3, false);
                }
                else
                {
                    data.Ceiling.plane = new Plane(v2, v1, v3, false);
                }
                SectorData sd = data.Mode.GetSectorData(l.Back.Sector);
                sd.AddUpdateSector(data.Sector, true);
            }
            // Align ceiling with front of line
            else if ((l.Args[1] == 2) && (l.Back.Sector == data.Sector) && (l.Front != null))
            {
                Vector3D v1 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Front.Sector.CeilHeight);
                Vector3D v2 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Front.Sector.CeilHeight);
                Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, data.Sector.CeilHeight);
                if (l.SideOfLine(v3) > 0.0f)
                {
                    data.Ceiling.plane = new Plane(v1, v2, v3, false);
                }
                else
                {
                    data.Ceiling.plane = new Plane(v2, v1, v3, false);
                }
                SectorData sd = data.Mode.GetSectorData(l.Front.Sector);
                sd.AddUpdateSector(data.Sector, true);
            }
        }