internal override void Run()
        {
            Debug.Assert(InitCallback != null, $"{nameof(InitCallback)} is null");
            Debug.Assert(RunCallback != null, $"{nameof(RunCallback)} is null");

            // Initialize the init callback
            InitCallback();

            var runCallback = new SDLMessageLoop.RenderCallback(RunCallback);

            // Run the rendering loop
            try
            {
                SDLMessageLoop.Run(window, () =>
                {
                    if (Exiting)
                    {
                        Destroy();
                        return;
                    }

                    runCallback();
                });
            }
            finally
            {
                ExitCallback?.Invoke();
            }
        }
Example #2
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>
        /// <exception cref="System.ArgumentNullException">form
        /// or
        /// renderCallback</exception>
        public static void Run(Window form, RenderCallback renderCallback)
        {
            if (form == null)
            {
                throw new ArgumentNullException(nameof(form));
            }
            if (renderCallback == null)
            {
                throw new ArgumentNullException(nameof(renderCallback));
            }

            form.Show();
            using (var renderLoop = new SDLMessageLoop(form))
            {
                while (renderLoop.NextFrame())
                {
                    renderCallback();
                }
            }
        }
Example #3
0
        internal override void Run()
        {
            Debug.Assert(InitCallback != null, $"{nameof(InitCallback)} is null");
            Debug.Assert(RunCallback != null, $"{nameof(RunCallback)} is null");

            // Initialize the init callback
            InitCallback();

            var context = (GameContextSDL)GameContext;

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

                        runCallback();
                    });
                }
                finally
                {
                    ExitCallback?.Invoke();
                }
            }
        }