Example #1
0
        public static void Run( ILauncher launcher, Node mainNode, Action initializeEvent = null, params object [] args )
        {
            IWindow window = null; IGraphicsDevice graphicsDevice = null; IAudioDevice audioDevice = null;

            Launcher = launcher;

            try
            {
                launcher.LauncherInitialize ( out window, out graphicsDevice, out audioDevice );
            }
            catch ( Exception e ) { if ( !SkipInitializeException ) throw new Exception ( "Initialization Exception", e ); }
            Window = window;
            GraphicsDevice = graphicsDevice;
            AudioDevice = audioDevice;

            if ( initializeEvent != null )
                initializeEvent ();

            MainNode = mainNode;

            TimeSpan elapsedUpdateTimeStep = new TimeSpan (),
                elapsedDrawTimeStep = new TimeSpan ();
            TimeSpan lastUpdateTimeStep = TimeSpan.FromMilliseconds ( Environment.TickCount ),
                lastDrawTimeStep = TimeSpan.FromMilliseconds ( Environment.TickCount );

            GameTime updateGameTime = new GameTime (), drawGameTime = new GameTime ();

            launcher.LauncherRun ( new LauncherArgument ()
            {
                Initialize = () =>
                {
                    if ( mainNode != null )
                        mainNode.Intro ( args );
                },
                UpdateLogic = () =>
                {
                    if ( elapsedUpdateTimeStep >= FixedUpdateTimeStep || FixedUpdateTimeStep.TotalMilliseconds == 0 )
                    {
                        updateGameTime.Update ();
                        if ( mainNode != null )
                            mainNode.Update ( updateGameTime );
                        elapsedUpdateTimeStep -= FixedUpdateTimeStep;
                    }
                    else
                    {
                        TimeSpan temp = TimeSpan.FromMilliseconds ( Environment.TickCount );
                        elapsedUpdateTimeStep += ( temp - lastUpdateTimeStep );
                        lastUpdateTimeStep = temp;
                    }
                },
                DrawLogic = () =>
                {
                    if ( LiqueurSystem.AudioDevice != null )
                        LiqueurSystem.AudioDevice.Update ();

                    if ( elapsedDrawTimeStep >= FixedDrawTimeStep || FixedDrawTimeStep.TotalMilliseconds == 0 )
                    {
                        drawGameTime.Update ();
                        if ( mainNode != null )
                            mainNode.Draw ( drawGameTime );
                        LiqueurSystem.GraphicsDevice.SwapBuffer ();
                        elapsedDrawTimeStep -= FixedDrawTimeStep;
                    }
                    else
                    {
                        TimeSpan temp = TimeSpan.FromMilliseconds ( Environment.TickCount );
                        elapsedDrawTimeStep += ( temp - lastDrawTimeStep );
                        lastDrawTimeStep = temp;
                    }
                },
                Resize = () =>
                {
                    if ( mainNode != null && mainNode is IWindowEvent )
                        ( mainNode as IWindowEvent ).WindowResize ();
                },
                Activated = () =>
                {
                    if ( mainNode != null && mainNode is IWindowEvent )
                        ( mainNode as IWindowEvent ).WindowActivated ();
                },
                Deactivated = () =>
                {
                    if ( mainNode != null && mainNode is IWindowEvent )
                        ( mainNode as IWindowEvent ).WindowDeactivated ();
                }
            } );
        }