Exemplo n.º 1
0
 public static void SetMainNode( Node node )
 {
     MainNode = node;
 }
Exemplo n.º 2
0
        public static void Run( ILauncher launcher, Node mainNode, IGameLooper gameLooper = null, Type gameTimeType = null )
        {
            Launcher = launcher;
            MainNode = mainNode;

            if ( gameLooper == null )
                GameLooper = new PlainGameLooper ();
            else
                GameLooper = gameLooper;

            int elapsedUpdateTimeStep = 0, elapsedDrawTimeStep = 0;
            int lastUpdateTimeStep = Environment.TickCount, lastDrawTimeStep = Environment.TickCount;

            GameTime updateGameTime, drawGameTime;
            if ( gameTimeType == null ) { updateGameTime = new GameTime (); drawGameTime = new GameTime (); }
            else { updateGameTime = Activator.CreateInstance ( gameTimeType ) as GameTime; drawGameTime = Activator.CreateInstance ( gameTimeType ) as GameTime; }

            thisThread = Thread.CurrentThread;

            launcher.Initialize ();
            Window.Show ();
            mainNode.Intro ();
            isRunningMode = true;
            GameLooper.Run (
                () =>
                {
                    if ( AudioDevice != null )
                        AudioDevice.Update ();

                    if ( elapsedUpdateTimeStep >= fixedUpdateTimeStep )
                    {
                        updateGameTime.Update ();
                        mainNode.Update ( updateGameTime );
                        elapsedUpdateTimeStep -= fixedUpdateTimeStep;
                    }
                    else
                    {
                        int temp = Environment.TickCount;
                        elapsedUpdateTimeStep += ( temp - lastUpdateTimeStep );
                        lastUpdateTimeStep = temp;
                    }
                },
                () =>
                {
                    if ( invokedMethod.Count > 0 )
                    {
                        foreach ( Action action in invokedMethod.ToArray () )
                        {
                            action ();
                            invokeSpinLock.Enter ();
                            invokedMethod.Remove ( action );
                            invokeSpinLock.Exit ();
                        }
                    }

                    if ( elapsedDrawTimeStep >= fixedDrawTimeStep )
                    {
                        drawGameTime.Update ();
                        mainNode.Draw ( drawGameTime );
                        elapsedDrawTimeStep -= fixedDrawTimeStep;
                    }
                    else
                    {
                        int temp = Environment.TickCount;
                        elapsedDrawTimeStep += ( temp - lastDrawTimeStep );
                        lastDrawTimeStep = temp;
                    }
                    Window.DoEvents ();
                },
                ref isRunningMode
            );

            mainNode.Outro ();
            launcher.Dispose ();
        }
Exemplo n.º 3
0
        public Node Add( Node node, params object [] args )
        {
            if ( node == null ) return null;

            node.Parent = this;
            node.Intro ( args );

            spinlock.Enter ();
            children.Add ( node );
            if ( !IsManuallyChildrenCacheMode )
                childrenArray = children.ToArray ();
            spinlock.Exit ();
            return node;
        }
Exemplo n.º 4
0
        public void Remove( Node node )
        {
            if ( node == null ) return;

            spinlock.Enter ();
            children.Remove ( node );
            if ( !IsManuallyChildrenCacheMode )
                childrenArray = children.ToArray ();
            spinlock.Exit ();

            node.Outro ();
            node.Parent = null;
        }
Exemplo n.º 5
0
        public bool InitializeWindow( string gameName, Image coverImage,
			ILauncher [] launchers, IGameLooper [] gameLoopers, Node [] mainNodes )
        {
            throw new NotImplementedException ();
        }
Exemplo n.º 6
0
        public bool InitializeWindow( string gameName, Image coverImage,
			ILauncher [] launchers, IGameLooper [] gameLoopers, Node [] mainNodes )
        {
            window = new Form ();

            window.Text = gameName;
            window.BackColor = Color.White;
            window.ClientSize = new Size ( 400, 260 );
            window.FormBorderStyle = FormBorderStyle.FixedDialog;
            window.StartPosition = FormStartPosition.CenterScreen;
            window.MaximizeBox = false;
            window.MinimizeBox = true;
            window.ShowInTaskbar = false;

            PictureBox cover = new PictureBox ();
            cover.Image = coverImage ?? Image.FromStream (
                Assembly.GetExecutingAssembly ().GetManifestResourceStream ( "Daramkun.Misty.Resources.DefaultCover.png" )
            );
            cover.Bounds = new Rectangle ( 0, 0, 400, 100 );
            window.Controls.Add ( cover );

            Label pafLabel = new Label () { Text = "&PAF:", Bounds = new Rectangle ( 10, 120, 60, 24 ) };
            window.Controls.Add ( pafLabel );

            ComboBox pafComboBox = new ComboBox () { DropDownStyle = ComboBoxStyle.DropDownList, Bounds = new Rectangle ( 70, 116, 310, 24 ) };
            foreach ( ILauncher launcher in launchers )
                pafComboBox.Items.Add ( launcher.ToString () );
            if ( pafComboBox.Items.Count >= 1 )
                pafComboBox.SelectedIndex = 0;
            if ( pafComboBox.Items.Count <= 1 )
                pafComboBox.Enabled = false;
            window.Controls.Add ( pafComboBox );

            Label glLabel = new Label () { Text = "&Looper:", Bounds = new Rectangle ( 10, 160, 60, 24 ) };
            window.Controls.Add ( glLabel );

            ComboBox glComboBox = new ComboBox () { DropDownStyle = ComboBoxStyle.DropDownList, Bounds = new Rectangle ( 70, 156, 310, 24 ) };
            foreach ( IGameLooper gl in gameLoopers )
                glComboBox.Items.Add ( gl.ToString () );
            if ( glComboBox.Items.Count >= 1 )
                glComboBox.SelectedIndex = 0;
            if ( glComboBox.Items.Count <= 1 )
                glComboBox.Enabled = false;
            window.Controls.Add ( glComboBox );

            Label nodeLabel = new Label () { Text = "&Game:", Bounds = new Rectangle ( 10, 200, 60, 24 ) };
            window.Controls.Add ( nodeLabel );

            ComboBox nodeComboBox = new ComboBox () { DropDownStyle = ComboBoxStyle.DropDownList, Bounds = new Rectangle ( 70, 196, 310, 24 ) };
            foreach ( Node node in mainNodes )
                nodeComboBox.Items.Add ( node.ToString () );
            if ( nodeComboBox.Items.Count >= 1 )
                nodeComboBox.SelectedIndex = 0;
            if ( nodeComboBox.Items.Count <= 1 )
                nodeComboBox.Enabled = false;
            window.Controls.Add ( nodeComboBox );

            Button acceptButton = new Button () { Text = "&Run", Bounds = new Rectangle ( 120, 226, 80, 24 ) };
            acceptButton.Click += ( object sender, EventArgs e ) =>
            {
                if ( pafComboBox.SelectedIndex < 0 )
                {
                    MessageBox.Show ( "Please select a Platform Abstraction Framework." );
                    return;
                }
                if ( nodeComboBox.SelectedIndex < 0 )
                {
                    MessageBox.Show ( "Please select a Game." );
                    return;
                }

                IsClickedOK = true;
                SelectedPAF = pafComboBox.SelectedIndex;
                SelectedGameLooper = glComboBox.SelectedIndex;
                SelectedMainNode = nodeComboBox.SelectedIndex;
                window.Close ();
            };
            window.Controls.Add ( acceptButton );

            Button cancelButton = new Button () { Text = "E&xit", Bounds = new Rectangle ( 210, 226, 80, 24 ) };
            cancelButton.Click += ( object sender, EventArgs e ) =>
            {
                IsClickedOK = false;
                window.Close ();
            };
            window.Controls.Add ( cancelButton );

            window.AcceptButton = acceptButton;
            window.CancelButton = cancelButton;

            return true;
        }