示例#1
0
        internal override void Run()
        {
            Debug.Assert(InitCallback != null);
            Debug.Assert(RunCallback != null);

            // Initialize the init callback
            InitCallback();

            if (GameContext.IsUserManagingRun)
            {
                GameContext.RunCallback  = RunCallback;
                GameContext.ExitCallback = ExitCallback;
            }
            else
            {
                var runCallback = new WindowsMessageLoop.RenderCallback(RunCallback);
                // Run the rendering loop
                try
                {
                    WindowsMessageLoop.Run(Control, () =>
                    {
                        if (Exiting)
                        {
                            if (Control != null)
                            {
                                Control.Dispose();
                                Control = null;
                            }
                            return;
                        }

                        runCallback();
                    });
                }
                finally
                {
                    if (ExitCallback != null)
                    {
                        ExitCallback();
                    }
                }
            }
        }
        internal override void Run()
        {
            Debug.Assert(InitCallback != null);
            Debug.Assert(RunCallback != null);

            // Initialize the init callback
            InitCallback();

            Debug.Assert(GameContext is GameContextWinforms, "There is only one possible descendant of GameContext<Control>.");
            var context = (GameContextWinforms)GameContext;

            if (context.IsUserManagingRun)
            {
                context.RunCallback  = RunCallback;
                context.ExitCallback = ExitCallback;
            }
            else
            {
                var runCallback = new WindowsMessageLoop.RenderCallback(RunCallback);
                // Run the rendering loop
                try
                {
                    WindowsMessageLoop.Run(Control, () =>
                    {
                        if (Exiting)
                        {
                            Destroy();
                            return;
                        }

                        runCallback();
                    });
                }
                finally
                {
                    if (ExitCallback != null)
                    {
                        ExitCallback();
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Runs the specified main loop for the specified windows form.
        /// </summary>
        /// <param name="form">The form.</param>
        /// <param name="renderCallback">The rendering callback.</param>
        /// <param name="useApplicationDoEvents">if set to <c>true</c> indicating whether the render loop should use the default <see cref="Application.DoEvents"/> instead of a custom window message loop lightweight for GC. Default is false.</param>
        /// <exception cref="System.ArgumentNullException">form
        /// or
        /// renderCallback</exception>
        public static void Run(Control form, RenderCallback renderCallback, bool useApplicationDoEvents = false)
        {
            if (form == null)
            {
                throw new ArgumentNullException("form");
            }
            if (renderCallback == null)
            {
                throw new ArgumentNullException("renderCallback");
            }

            form.Show();
            using (var renderLoop = new WindowsMessageLoop(form)
            {
                UseApplicationDoEvents = useApplicationDoEvents
            })
            {
                while (renderLoop.NextFrame())
                {
                    renderCallback();
                }
            }
        }
示例#4
0
        /// <summary>
        /// Runs the specified main loop for the specified windows form.
        /// </summary>
        /// <param name="form">The form.</param>
        /// <param name="renderCallback">The rendering callback.</param>
        /// <param name="useApplicationDoEvents">if set to <c>true</c> indicating whether the render loop should use the default <see cref="Application.DoEvents"/> instead of a custom window message loop lightweight for GC. Default is false.</param>
        /// <exception cref="System.ArgumentNullException">form
        /// or
        /// renderCallback</exception>
        public static void Run(Control form, RenderCallback renderCallback, bool useApplicationDoEvents = false)
        {
            if(form == null) throw new ArgumentNullException("form");
            if(renderCallback == null) throw new ArgumentNullException("renderCallback");

            form.Show();
            using (var renderLoop = new WindowsMessageLoop(form) { UseApplicationDoEvents = useApplicationDoEvents })
            {
                while(renderLoop.NextFrame())
                {
                    renderCallback();
                }
            }
        }