/// <summary>
        ///     The domain unload event.
        /// </summary>
        /// <param name="sender">
        ///     The sender.
        /// </param>
        /// <param name="eventArgs">
        ///     The event args.
        /// </param>
        private static void OnDomainUnload(object sender, EventArgs eventArgs)
        {
            if (Font != null)
            {
                Font.OnLostDevice();
                Font.Dispose();
                Font = null;
            }

            if (FontBold != null)
            {
                FontBold.OnLostDevice();
                FontBold.Dispose();
                FontBold = null;
            }

            if (FontBoldItalic != null)
            {
                FontBoldItalic.OnLostDevice();
                FontBoldItalic.Dispose();
                FontBoldItalic = null;
            }

            if (FontItalic != null)
            {
                FontItalic.OnLostDevice();
                FontItalic.Dispose();
                FontItalic = null;
            }
        }
Exemple #2
0
        public void Dispose()
        {
            Font?.Dispose();
            GC.SuppressFinalize(this);

            Drawing.OnPreReset  -= Drawing_OnPreReset;
            Drawing.OnPostReset -= Drawing_OnPostReset;
        }
Exemple #3
0
        public void Dispose()
        {
            Font?.Dispose();
            GC.SuppressFinalize(this);

            Drawing.OnPreReset  -= Drawing_OnPreReset;
            Drawing.OnPostReset -= Drawing_OnPostReset;
            AppDomain.CurrentDomain.DomainUnload -= CurrentDomain_DomainUnload;
        }
 /// <summary>
 /// Fired when the AppDomain is unloaded.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="eventArgs">The <see cref="EventArgs"/> instance containing the event data.</param>
 private static void CurrentDomainOnDomainUnload(object sender, EventArgs eventArgs)
 {
     BoxLine.OnLostDevice();
     Text.OnLostDevice();
     sprite.OnLostDevice();
     sprite.Dispose();
     Text.Dispose();
     BoxLine.Dispose();
 }
Exemple #5
0
        public void DisposeDeviceResources()
        {
            if (tx != null)
            {
                tx.Dispose();
                tx = null;
            }
            if (tcircle != null)
            {
                tcircle.Dispose();
                tcircle = null;
            }
            if (tecircle != null)
            {
                tecircle.Dispose();
                tecircle = null;
            }
            if (hvcursor != null)
            {
                hvcursor.Dispose();
                hvcursor = null;
            }
            if (vcursor != null)
            {
                vcursor.Dispose();
                vcursor = null;
            }
            if (hcursor != null)
            {
                hcursor.Dispose();
                hcursor = null;
            }

            if (font != null)
            {
                font.Dispose();
                font = null;
            }
            if (fontBold != null)
            {
                fontBold.Dispose();
                fontBold = null;
            }

            if (sprite != null)
            {
                sprite.Dispose();
                sprite = null;
            }
            if (sprite2 != null)
            {
                sprite2.Dispose();
                sprite2 = null;
            }
        }
Exemple #6
0
        public void DisposeDeviceResources()
        {
            if (tx != null)
            {
                tx.Dispose();
                tx = null;
            }
            if (hvcursor != null)
            {
                hvcursor.Dispose();
                hvcursor = null;
            }
            if (vcursor != null)
            {
                vcursor.Dispose();
                vcursor = null;
            }
            if (hcursor != null)
            {
                hcursor.Dispose();
                hcursor = null;
            }

            if (FontDX != null)
            {
                FontDX.Dispose();
                FontDX = null;
            }
            if (FontDX_Bold != null)
            {
                FontDX_Bold.Dispose();
                FontDX_Bold = null;
            }

            if (sprite != null)
            {
                sprite.Dispose();
                sprite = null;
            }
            if (sprite2 != null)
            {
                sprite2.Dispose();
                sprite2 = null;
            }
            if (tx_ellipses != null)
            {
                foreach (var tx_ellipse in tx_ellipses)
                {
                    tx_ellipses[tx_ellipse.Key].Dispose();
                }
                tx_ellipses.Clear();
                tx_ellipses = null;
            }
        }
        public static void Init()
        {
            text = new Font(
                Drawing.Direct3DDevice9,
                new FontDescription
                {
                    FaceName = "Tahoma",
                    Height = 15,
                    OutputPrecision = FontPrecision.Default,
                    Quality = FontQuality.Antialiased
                });

            AppDomain.CurrentDomain.DomainUnload += (sender, argss) => text.Dispose();
        }
Exemple #8
0
        /// <summary>
        ///     The domain unload event.
        /// </summary>
        /// <param name="sender">
        ///     The sender.
        /// </param>
        /// <param name="eventArgs">
        ///     The event args.
        /// </param>
        private static void OnDomainUnload(object sender, EventArgs eventArgs)
        {
            if (Line != null)
            {
                Line.OnLostDevice();
                Line.Dispose();
                Line = null;
            }

            if (Font != null)
            {
                Font.OnLostDevice();
                Font.Dispose();
                Font = null;
            }

            /*
             * if (FontBold != null)
             * {
             *  FontBold.OnLostDevice();
             *  FontBold.Dispose();
             *  FontBold = null;
             * }
             *
             * if (FontBoldItalic != null)
             * {
             *  FontBoldItalic.OnLostDevice();
             *  FontBoldItalic.Dispose();
             *  FontBoldItalic = null;
             * }
             *
             * if (FontItalic != null)
             * {
             *  FontItalic.OnLostDevice();
             *  FontItalic.Dispose();
             *  FontItalic = null;
             * }
             */
        }
        static void Main()
        {
            var worldSize = new Size2(1024, 768);
            var renderSize = new Size2(1920, 1080);
            const bool windowed = true;

            const int numParticles = 1000000;
            const int numEmitters = 5;
            const int budget = numParticles / numEmitters;

            var form = new RenderForm("Mercury Particle Engine - SharpDX.Direct3D9 Sample")
            {
                Size = new System.Drawing.Size(renderSize.Width, renderSize.Height)
            };

            var direct3d = new Direct3D();
            var device = new Device(direct3d, 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters(renderSize.Width, renderSize.Height) { PresentationInterval = PresentInterval.Immediate, Windowed = windowed });

            var view = new Matrix(
                1.0f, 0.0f, 0.0f, 0.0f,
                0.0f, -1.0f, 0.0f, 0.0f,
                0.0f, 0.0f, -1.0f, 0.0f,
                0.0f, 0.0f, 0.0f, 1.0f);
            var proj = Matrix.OrthoOffCenterLH(worldSize.Width * -0.5f, worldSize.Width * 0.5f, worldSize.Height * 0.5f, worldSize.Height * -0.5f, 0f, 1f);
            var wvp = Matrix.Identity * view * proj;

            var emitters = new Emitter[numEmitters];

            for (int i = 0; i < numEmitters; i++)
            {
                emitters[i] = new Emitter(budget, TimeSpan.FromSeconds(600), Profile.BoxFill(worldSize.Width, worldSize.Height))
                {
                    Parameters = new ReleaseParameters
                    {
                        Colour = new Colour(220f, 0.7f, 0.1f),
                        Opacity = 1f,
                        Quantity = budget,
                        Speed = 0f,
                        Scale = 1f,
                        Rotation = 0f,
                        Mass = new RangeF(8f, 12f)
                    },
                    BlendMode = BlendMode.Add,
                    ReclaimInterval = 600f
                };

                emitters[i].Modifiers.Add(new DragModifier
                {
                    DragCoefficient = .47f,
                    Density         = .15f
                }, 15f);
                emitters[i].Modifiers.Add(new VortexModifier
                {
                    Position = Coordinate.Origin,
                    Mass = 200f,
                    MaxSpeed = 1000f
                }, 30f);
                emitters[i].Modifiers.Add(new VelocityHueModifier
                {
                    StationaryHue = 220f,
                    VelocityHue = 300f,
                    VelocityThreshold = 800f
                }, 15f);
                emitters[i].Modifiers.Add(new ContainerModifier
                        {
                            RestitutionCoefficient = 0.75f,
                            Position = Coordinate.Origin,
                            Width    = worldSize.Width,
                            Height   = worldSize.Height
                        }, 30f);
                emitters[i].Modifiers.Add(new MoveModifier(), 60f);
            };

            var renderer = new PointSpriteRenderer(device, budget)
            {
            //                EnableFastFade = true
            };

            var texture = Texture.FromFile(device, "Pixel.dds");

            var fontDescription = new FontDescription
            {
                Height         = 16,
                FaceName       = "Consolas",
                PitchAndFamily = FontPitchAndFamily.Mono,
                Quality        = FontQuality.Draft
            };

            var font = new Font(device, fontDescription);

            var totalTimer = Stopwatch.StartNew();
            var updateTimer = new Stopwatch();
            var renderTimer = new Stopwatch();

            var totalTime = 0f;

            foreach (var emitter in emitters)
            {
                emitter.Trigger(Coordinate.Origin);
            }

            float updateTime = 0f;

            RenderLoop.Run(form, () =>
                {
                    // ReSharper disable AccessToDisposedClosure
                    var frameTime = ((float)totalTimer.Elapsed.TotalSeconds) - totalTime;
                    totalTime = (float)totalTimer.Elapsed.TotalSeconds;

                    var mousePosition = form.PointToClient(RenderForm.MousePosition);

                    Task.WaitAll(
                        Task.Factory.StartNew(() =>
                        {
                            var mouseVector = new Vector3(mousePosition.X, mousePosition.Y, 0f);
                            var unprojected = Vector3.Unproject(mouseVector, 0, 0, renderSize.Width, renderSize.Height, 0f, 1f, wvp);

                            Parallel.ForEach(emitters, emitter => ((VortexModifier)emitter.Modifiers.ElementAt(1)).Position = new Coordinate(unprojected.X, unprojected.Y));

                            updateTimer.Restart();
                            Parallel.ForEach(emitters, emitter => emitter.Update(frameTime));
                            updateTimer.Stop();
                            updateTime = (float)updateTimer.Elapsed.TotalSeconds;
                            _updateTimes.Add(updateTime);
                        }),
                        Task.Factory.StartNew(() =>
                        {
                            device.Clear(ClearFlags.Target, Color.Black, 1f, 0);
                            device.BeginScene();

                            renderTimer.Restart();
                            for (int i = 0; i < numEmitters; i++)
                            {
                                renderer.Render(emitters[i], wvp, texture);
                            }
                            renderTimer.Stop();
                            var renderTime = (float)renderTimer.Elapsed.TotalSeconds;

                            var totalUpdateTime = 0f;
            //	                        foreach (var time in _updateTimes)
            //	                        {
            //		                        totalUpdateTime += time;
            //	                        }
            //	                        totalUpdateTime /= _updateTimes.Count;
            //
            //							if(_updateTimes.Count > 100)
            //								_updateTimes.RemoveAt(0);

                            font.DrawText(null, String.Format("Time:        {0}", totalTimer.Elapsed), 0, 0, Color.White);
                            font.DrawText(null, String.Format("Particles:   {0:n0}", emitters[0].ActiveParticles * numEmitters), 0, 16, Color.White);
                            font.DrawText(null, String.Format("Update:      {0:n4} ({1,8:P2})", updateTime, updateTime / 0.01666666f), 0, 32, Color.White);
                            font.DrawText(null, String.Format("Render:      {0:n4} ({1,8:P2})", renderTime, renderTime / 0.01666666f), 0, 48, Color.White);

                            device.EndScene();
                            device.Present();
                        })
                    );

                    if (Keyboard.IsKeyDown(Key.Escape))
                        Environment.Exit(0);
            // ReSharper restore AccessToDisposedClosure
                });

            form.Dispose();
            font.Dispose();
            device.Dispose();
            direct3d.Dispose();
        }
Exemple #10
0
 void CurrentDomain_DomainUnload(object sender, EventArgs e)
 {
     Text.Dispose();
 }
Exemple #11
0
 private void DomainUnload(object sender, EventArgs eventArgs)
 {
     SmallText.Dispose();
     Sprite.Dispose();
 }
Exemple #12
0
 private static void CurrentDomainOnDomainUnload(object sender, EventArgs eventArgs)
 {
     Text.Dispose();
     TextLittle.Dispose();
 }
Exemple #13
0
        public void DisposeDeviceResources(int type = 0)
        {
            if (tx != null)
            {
                tx.Dispose();
                tx = null;
            }
            if (tcircle != null)
            {
                tcircle.Dispose();
                tcircle = null;
            }
            if (tecircle != null)
            {
                tecircle.Dispose();
                tecircle = null;
            }
            if (hvcursor != null)
            {
                hvcursor.Dispose();
                hvcursor = null;
            }
            if (vcursor != null)
            {
                vcursor.Dispose();
                vcursor = null;
            }
            if (hcursor != null)
            {
                hcursor.Dispose();
                hcursor = null;
            }

            if (font != null)
            {
                font.Dispose();
                font = null;
            }
            if (fontBold != null)
            {
                fontBold.Dispose();
                fontBold = null;
            }

            if (sprite != null || type == 1)
            {
                sprite.Dispose();
                sprite = null;
            }
            if (sprite2 != null || type == 1)
            {
                sprite2.Dispose();
                sprite2 = null;
            }

            if (_parent != null && type == 1)
            {
                _parent.DisposeTextures();
                _parent = null;
            }
            if (_device != null && type == 1)
            {
                _device.Dispose();
                _device = null;
            }
            if (direct3d != null && type == 1)
            {
                direct3d.Dispose();
                direct3d = null;
            }
        }
        /// <summary>
        /// Called when graphics resources need to be unloaded. Override this method to unload any game-specific graphics resources.
        /// </summary>
        public override void UnloadContent()
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyMinerGame::UnloadContent");
            MyMwcLog.WriteLine("MyMinerGame.UnloadContent() - START");
            MyMwcLog.IncreaseIndent();

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

            if (DefaultSurface != null)
            {
                DefaultSurface.Dispose();
                DefaultSurface = null;
            }
            if (DefaultDepth != null)
            {
                DefaultDepth.Dispose();
                DefaultDepth = null;
            }

            // GUI
            MyGuiManager.UnloadContent();

            MyRender.UnloadContent();

            MyTextureManager.UnloadContent();
            MyModels.UnloadContent();

            // Global content
            //Content.Unload();

            // Render
            MySunGlare.UnloadContent();

            MyDebugDrawCachedLines.UnloadContent();
            MyDebugDraw.UnloadContent();

            //MyRender.UnloadContent(); //it is unloaded in gui gameplay screen

            MyMwcLog.DecreaseIndent();
            MyMwcLog.WriteLine("MyMinerGame.UnloadContent() - END");

            GraphicsDevice.SetStreamSource(0, null, 0, 0);
            GraphicsDevice.Indices           = null;
            GraphicsDevice.VertexDeclaration = null;
            GraphicsDevice.PixelShader       = null;
            GraphicsDevice.VertexShader      = null;
            for (int i = 0; i < 16; i++)
            {
                GraphicsDevice.SetTexture(i, null);
            }

            base.UnloadContent();

            GC.Collect();

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
        }
Exemple #15
0
 private static void CurrentDomainDomainUnload(object sender, EventArgs e)
 {
     text.Dispose();
 }
Exemple #16
0
 public void Dispose()
 {
     _Font.Dispose();
 }