Example #1
0
        // Constructor
        public VPOManager()
        {
            // Load a DLL for each thread
            dlls      = new IntPtr[NumThreads];
            tempfiles = new string[NumThreads];

            // We must write the DLL file with a unique name for every thread,
            // because LoadLibrary will share loaded libraries with the same
            // names and LoadLibraryEx does not have a flag to force loading
            // it multiple times.
            Assembly thisasm   = Assembly.GetExecutingAssembly();
            Stream   dllstream = thisasm.GetManifestResourceStream("CodeImp.DoomBuilder.Plugins.VisplaneExplorer.Resources.vpo.dll");

            dllstream.Seek(0, SeekOrigin.Begin);
            byte[] dllbytes = new byte[dllstream.Length];
            dllstream.Read(dllbytes, 0, dllbytes.Length);
            for (int i = 0; i < dlls.Length; i++)
            {
                // Write file with unique filename
                tempfiles[i] = BuilderPlug.MakeTempFilename(".dll");
                File.WriteAllBytes(tempfiles[i], dllbytes);

                // Load it
                dlls[i] = LoadLibrary(tempfiles[i]);
                if (dlls[i] == IntPtr.Zero)
                {
                    throw new Exception("Unable to load vpo.dll");
                }
            }
        }
Example #2
0
        public override void OnInitialize()
        {
            base.OnInitialize();

            // Keep a static reference
            me = this;
        }
Example #3
0
        // This event is called when the plugin is initialized
        public override void OnInitialize()
        {
            base.OnInitialize();

            General.Actions.BindMethods(this);

            // Load interface controls
            interfaceform = new InterfaceForm();

            // Load VPO manager (manages multithreading and communication with vpo.dll)
            vpo = new VPOManager();

            // Keep a static reference
            me = this;
        }
        public override void OnMapOpenEnd()
        {
            enabled = (General.Map.DOOM || General.Map.HEXEN);
            if (enabled)
            {
                // Load interface controls
                interfaceform = new InterfaceForm();

                // Load VPO manager (manages multithreading and communication with vpo.dll)
                vpo = new VPOManager();

                // Keep a static reference
                me = this;
            }
        }
        // This is called when the plugin is terminated
        public override void Dispose()
        {
            //mxd. Active and not already disposed?
            if (!IsDisposed)
            {
                if (enabled)
                {
                    // Clean up
                    interfaceform.Dispose();
                    interfaceform = null;
                    vpo.Dispose();
                    vpo = null;

                    // Done
                    me = null;
                }

                base.Dispose();
            }
        }
Example #6
0
        // This is called when the plugin is terminated
        public override void Dispose()
        {
            //mxd. Active and not already disposed?
            if (!IsDisposed)
            {
                if (interfaceform != null)
                {
                    interfaceform.Dispose();
                    interfaceform = null;
                }

                if (vpo != null)
                {
                    vpo.Dispose();
                    vpo = null;
                }

                // Done
                me = null;

                base.Dispose();
            }
        }
        // Mode starts
        public override void OnEngage()
        {
            Cursor.Current = Cursors.WaitCursor;
            base.OnEngage();
            General.Interface.DisplayStatus(StatusType.Busy, "Setting up test environment...");

            BuilderPlug.InitVPO();             //mxd

            CleanUp();

            BuilderPlug.InterfaceForm.AddToInterface();
            BuilderPlug.InterfaceForm.OnOpenDoorsChanged += OnOpenDoorsChanged;             //mxd
            lastviewstats = BuilderPlug.InterfaceForm.ViewStats;

            // Export the current map to a temporary WAD file
            tempfile = BuilderPlug.MakeTempFilename(".wad");
            if (!General.Map.ExportToFile(tempfile))
            {
                //mxd. Abort on export fail
                Cursor.Current = Cursors.Default;
                General.Interface.DisplayStatus(StatusType.Warning, "Unable to set test environment...");
                OnCancel();
                return;
            }

            // 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
            CreateTiles();             //mxd

            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.LoadImageNow();

            // 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 = Clock.CurrentTime + 100;
            General.Interface.EnableProcessing();
            processingenabled = true;

            RedrawAllTiles();
            Cursor.Current = Cursors.Default;
            General.Interface.SetCursor(Cursors.Cross);
            General.Interface.DisplayReady();
        }
Example #8
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();
        }