Esempio n. 1
0
        private async void UpdateVisibility(bool keepFocus)
        {
            if (_updating)
            {
                return;
            }

            _updating = true;
            await Task.Delay(1);

            if (_child != null)
            {
                var val = _visible && (_parent.Focused || _child.IsActive) ? Visibility.Visible : Visibility.Hidden;
                if (val != _child.Visibility)
                {
                    _child.Visibility = val;

                    if (val == Visibility.Visible)
                    {
                        _child.Topmost = false;
                        _child.Topmost = true;
                    }

                    if (keepFocus)
                    {
                        await Task.Delay(1);

                        _parent.Focus();
                        _parent.Activate();
                    }
                }
            }

            _updating = false;
        }
Esempio n. 2
0
        public bool Initialize(out string errorMsg)
        {
            try
            {
                errorMsg = null;

                List <ModeDescription> adapterModes = new List <ModeDescription>();
                _dx11factory = new Factory1();

                using (Adapter1 adapter = _dx11factory.GetAdapter1(0))
                {
                    using (Output output = adapter.Outputs[0])
                    {
                        IsB8G8R8A8_UNormSupport = false;
                        foreach (var mode in output.GetDisplayModeList(Format.B8G8R8A8_UNorm, DisplayModeEnumerationFlags.Interlaced))
                        {
                            IsB8G8R8A8_UNormSupport = true;
                            adapterModes.Add(mode);
                        }

                        MainAdapter = adapter.Description.Description;
                        logger.Info("GPU found : {0}", MainAdapter);
                        //GetResource Level
                        FeatureLevel maxSupportLevel = Device.GetSupportedFeatureLevel(adapter);
                        logger.Info("Maximum supported DirectX11 level = {0}", maxSupportLevel.ToString());

                        if (maxSupportLevel == FeatureLevel.Level_9_1 ||
                            maxSupportLevel == FeatureLevel.Level_9_2 ||
                            maxSupportLevel == FeatureLevel.Level_9_3)
                        {
                            errorMsg = "Your graphical card doesn't support at minimum DirectX 10 feature, current feature : " + maxSupportLevel.ToString();
                            return(false);
                        }

                        int DedicatedGPU = adapter.Description.DedicatedVideoMemory / (1024 * 1024);
                        if (DedicatedGPU < 0)
                        {
                            DedicatedGPU = 0;
                        }
                        int DedicatedSystem = adapter.Description.DedicatedSystemMemory / (1024 * 1024);
                        if (DedicatedSystem < 0)
                        {
                            DedicatedSystem = 0;
                        }
                        int SharedSystem = adapter.Description.SharedSystemMemory / (1024 * 1024);
                        if (SharedSystem < 0)
                        {
                            SharedSystem = 0;
                        }

                        logger.Info("GPU Memory : Dedicated from GPU : {0}MB, Shared : {1}MB, Dedicated from System : {2}MB. Total : {3}MB", DedicatedGPU, DedicatedSystem, SharedSystem, DedicatedGPU + DedicatedSystem + SharedSystem);
                        logger.Info("B8G8R8A8_UNormSupport compatibility = {0}", IsB8G8R8A8_UNormSupport);

#if DEBUG
                        foreach (var mode in adapterModes)
                        {
                            logger.Trace("[{1}:{2}], format : {0}, RefreshRate : {3}hz, Scaling : {4}, ScanlineMode : {5}", mode.Format, mode.Width, mode.Height, (float)mode.RefreshRate.Numerator / mode.RefreshRate.Denominator, mode.Scaling, mode.ScanlineOrdering);
                        }
#endif
                    }
                }

                RefreshResources();

                GetMSAAQualities(Format.B8G8R8A8_UNorm);

                //Remove the some built-in fonctionnality of DXGI
                _dx11factory.MakeWindowAssociation(_renderForm.Handle, WindowAssociationFlags.IgnoreAll | WindowAssociationFlags.IgnoreAltEnter);

                _renderForm.ResizeBegin += _renderForm_ResizeBegin;
                _renderForm.ResizeEnd   += _renderForm_ResizeEnd;
                _renderForm.Resize      += _renderForm_Resize;
                _renderForm.LostFocus   += GameWindow_LostFocus;
                _renderForm.GotFocus    += GameWindow_GotFocus;

                _renderForm.Show();
                _renderForm.Focus();
                _renderForm.TopMost = true;
                HasFocus            = true;
                _renderForm.TopMost = false;

                return(true);
            }
            catch (Exception e)
            {
                errorMsg = e.Message;
                return(false);
            }
        }
Esempio n. 3
0
        static void Main()
        {
            MainForm parent = new MainForm();
            RenderForm form = new RenderForm("SlimDX - MiniTri Direct3D9 Sample");
            form.Location = new Point(8, 24);
            form.TopLevel = false;
            parent.Controls.Add(form);
            parent.Size = new Size(900, 600);
            form.ClientSize = new Size((GameTypes.MAP_WIDTH*GameTypes.SPRITE_WIDTH), (GameTypes.MAP_HEIGHT*GameTypes.SPRITE_HEIGHT));
            parent.Controls.Add(new Button());
            parent.Show();

            //Icon ico = new Icon("assets//textures//icon.bmp");

            form.Click += new EventHandler(form_Click);
            form.MouseMove += new MouseEventHandler(form_MouseMove);
            form.MouseLeave += new EventHandler(form_MouseLeave);
            form.MouseEnter += new EventHandler(form_MouseEnter);
            form.KeyDown += new KeyEventHandler(form_KeyDown);
            form.KeyUp += new KeyEventHandler(form_KeyUp);
            form.LostFocus += new EventHandler(form_LostFocus);
            form.Focus();

            parent.KeyDown += new KeyEventHandler(form_KeyDown);
            parent.KeyUp += new KeyEventHandler(form_KeyUp);

            form.FormBorderStyle = FormBorderStyle.None;

            Device device = new Device(new Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters()
            {
                BackBufferWidth = form.ClientSize.Width,
                BackBufferHeight = form.ClientSize.Height
            });

            Maze testmaze = new Maze();
            testmaze.Initialize();
            testmaze.Generate();
            int[,] walkable = new int[GameTypes.MAP_WIDTH, GameTypes.MAP_WIDTH];
            walkable = testmaze.getWalkableArray();

            TextureManager.Instance.init(device);
            GameEngine.Instance.init();
            WindowManager.Instance.Main = parent;
            WindowManager.Instance.Slim = form;

            GameEngine.Instance.LifeTimer.Start();
            GameEngine.Instance.FPSTimer.Start();
            GameEngine.Instance.TestSpriteTimer.Start();

            PathFinding.Instance.init(GameTypes.MAP_WIDTH,GameTypes.MAP_HEIGHT);

            GameEngine.Instance.testvec = new Vector3(5 * 32, 5 * 632, 0);

            Enemy e = new Enemy(GameTypes.ENEMY_UNI);
            e.StackTest();

            GameEngine.Instance.testEnemy = new Enemy(GameTypes.ENEMY_UNI);
            GameEngine.Instance.Enemies = new System.Collections.Generic.List<Enemy>();

            GameEngine.Instance.LifeTimer.Stop();
            //for (int i = 0; i < 10; i++)
            //{
            //    Enemy enemy = new Enemy(GameTypes.ENEMY_UNI);
            //    enemy.BirthTime = (float)GameEngine.Instance.LifeTimer.Elapsed + i;
            //    GameEngine.Instance.Enemies.Add(enemy);
            //}

            //close some nodes
            //PathFinding.Instance.Nodes[4 + 10].Walkable = false;
            //PathFinding.Instance.Nodes[4 + 20].Walkable = false;
            //PathFinding.Instance.Nodes[4 + 30].Walkable = false;
            //PathFinding.Instance.Nodes[4 + 40].Walkable = false;
            //PathFinding.Instance.Nodes[4 + 50].Walkable = false;
            //PathFinding.Instance.Nodes[4 + 60].Walkable = false;
            //PathFinding.Instance.Nodes[4 + 70].Walkable = false;
            //PathFinding.Instance.Nodes[4 + 80].Walkable = false;

            for (int y = 0; y < GameTypes.MAP_HEIGHT; y++)
            {
                for (int x = 0; x < GameTypes.MAP_WIDTH; x++)
                {
                    if (walkable[x, y] == 0 || y == GameTypes.MAP_HEIGHT - 1)
                    {
                        PathFinding.Instance.GetNode(x, y).Walkable = false;
                    }
                }
            }

            PathFinding.Instance.GetNode(GameTypes.PLAYER_START_COORDS).Walkable = true;

            GameEngine.Instance.SpawnEnemy(GameEngine.Instance.PlayerLevel);
            GameEngine.Instance.PlaceShiny();

            WindowManager.Instance.Main.lblScore.Text = "SCORE: " + GameEngine.Instance.PlayerScore.ToString();
            WindowManager.Instance.Main.lblLife.Text = "LIFE";
            WindowManager.Instance.Main.ShowLife();
            WindowManager.Instance.Main.lblHiscore.Text = "HI-SCORE  " + GameEngine.Instance.HiScore.ToString();

            MessagePump.Run(form, () =>
            {
                if (!GameEngine.Instance.PauseRendering)
                {
                    int score = GameEngine.Instance.PlayerScore;
                    int life = GameEngine.Instance.PlayerLife;
                    int hiscore = GameEngine.Instance.HiScore;

                    //Time to spawn?
                    GameEngine.Instance.SpawnTimer.Stop();
                    if ((float)GameEngine.Instance.SpawnTimer.Elapsed >= GameEngine.Instance.SpawnFrequency)
                    {
                        GameEngine.Instance.SpawnEnemy(GameEngine.Instance.PlayerLevel);
                        if((GameEngine.Instance.SpawnFrequency - GameTypes.GAME_SPAWN_SPEEDUP_RATE >= GameTypes.GAME_SPAWN_MIN_FREQ))
                            GameEngine.Instance.SpawnFrequency -= GameTypes.GAME_SPAWN_SPEEDUP_RATE;

                        for(int i =0;i<GameTypes.GAME_LEVEL_FREQ.Length;i++)
                            if(GameEngine.Instance.SpawnFrequency <= GameTypes.GAME_LEVEL_FREQ[i])
                                GameEngine.Instance.PlayerLevel = i;

                        GameEngine.Instance.SpawnTimer.Start();
                    }
                    else
                    {
                        //if (GameEngine.Instance.Enemies.Count == 1)
                          //  GameEngine.Instance.SpawnEnemy(GameEngine.Instance.PlayerLevel);
                    }

                    GameEngine.Instance.LifeTimer.Stop();
                    float time = (float)GameEngine.Instance.LifeTimer.Elapsed;
                    float fps = (float)GameEngine.Instance.FPSTimer.FPS;
                    float ticks = (float)GameEngine.Instance.LifeTimer.GetTicks(0.017f);
                    WindowManager.Instance.Main.showelapsed(time, fps, ticks);

                    device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                    device.BeginScene();

                    //draw maze

                    TextureManager.Instance.spritey.Begin(SpriteFlags.AlphaBlend | SpriteFlags.DoNotAddRefTexture);
                    for (int y = 0; y < GameTypes.MAP_HEIGHT; y++)
                    {
                        for (int x = 0; x < GameTypes.MAP_WIDTH; x++)
                        {
                            if (PathFinding.Instance.GetNode(x, y).Walkable)
                                TextureManager.Instance.spritey.Draw(TextureManager.Instance.ddsTestTile, new Rectangle(0, 0, 32, 32), new Vector3(0, 0, 0), new Vector3(x * 32, y * 32, 0), new Color4(Color.White));
                            else
                                TextureManager.Instance.spritey.Draw(TextureManager.Instance.ddsTestTileOut, new Rectangle(0, 0, 32, 32), new Vector3(0, 0, 0), new Vector3(x * 32, y * 32, 0), new Color4(Color.White));
                        }
                    }

                    //draw shiny
                    TextureManager.Instance.spritey.Draw(TextureManager.Instance.pngShiny, new Rectangle(0, 0, 32, 32), new Vector3(0, 0, 0), new Vector3(GameEngine.Instance.ShinyLocation.X*32,GameEngine.Instance.ShinyLocation.Y*32,0), new Color4(Color.White));

                    //sprite update
                    GameEngine.Instance.TestSpriteTimer.Stop();
                    if (GameEngine.Instance.TestSpriteTimer.Elapsed > 0.017)
                    {
                        GameEngine.Instance.ThePlayer.Update();
                        //GameEngine.Instance.testvec.X += 0.5f;
                        //GameEngine.Instance.testEnemy.UpdateMove();

                        // move enemies
                        foreach (Enemy enemy in GameEngine.Instance.Enemies)
                        {
                            if (enemy.Active)
                                enemy.UpdateMove();
                            else
                            {
                                if (GameEngine.Instance.LifeTimer.Elapsed > enemy.BirthTime)
                                    enemy.Active = true;
                            }
                        }
                        //move player
                        GameEngine.Instance.ThePlayer.Move(GameEngine.Instance.KEYS_DOWN);

                        GameEngine.Instance.TestSpriteTimer.Start();
                    }

                    //Draw enemies
                    GameEngine.Instance.Enemies.Sort(delegate(Enemy e1, Enemy e2)
                    {
                        if (e1.Position.Y != e2.Position.Y)
                            return e1.Position.Y.CompareTo(e2.Position.Y);
                        else
                            return e1.BirthTime.CompareTo(e2.BirthTime);
                    });
                    bool playerDrawn = false;
                    bool playerShadowDrawn = false;

                    //SHADOWS first
                    foreach (Enemy enemy in GameEngine.Instance.Enemies)
                    {
                        if (enemy.Active)
                        {
                            if (!playerShadowDrawn && enemy.Position.Y > GameEngine.Instance.ThePlayer.Location.Y)
                            {
                                TextureManager.Instance.spritey.Draw(TextureManager.Instance.pngDropShadow, new Rectangle(0, 0, 32, 32),
                                    new Vector3(0, 0, 0), GameEngine.Instance.ThePlayer.Location, new Color4(Color.White));
                                playerShadowDrawn = true;
                            }

                            if (PathFinding.Instance.GetNode(enemy.LastPoint).Walkable && PathFinding.Instance.GetNode(enemy.NextPoint).Walkable)
                            {
                                TextureManager.Instance.spritey.Draw(TextureManager.Instance.pngDropShadow, new Rectangle(0, 0, 32, 32),
                                    new Vector3(0, 0, 0), enemy.Position, new Color4(Color.White));
                            }
                        }
                    }
                    if (!playerShadowDrawn)
                    {
                        TextureManager.Instance.spritey.Draw(TextureManager.Instance.pngDropShadow, new Rectangle(0, 0, 32, 32),
                                new Vector3(0, 0, 0), GameEngine.Instance.ThePlayer.Location, new Color4(Color.White));
                    }

                    //DRAW ENEMIES
                    foreach (Enemy enemy in GameEngine.Instance.Enemies)
                    {
                        if (enemy.Active)
                        {
                            if (!playerDrawn && enemy.Position.Y > GameEngine.Instance.ThePlayer.Location.Y)
                            {
                                TextureManager.Instance.spritey.Draw(TextureManager.Instance.tgaEnemies, GameEngine.Instance.ThePlayer.RenderRect,
                                    new Vector3(0, 0, 0), GameEngine.Instance.ThePlayer.LocationDraw, new Color4(Color.White));
                                playerDrawn = true;
                            }

                            if (PathFinding.Instance.GetNode(enemy.LastPoint).Walkable && PathFinding.Instance.GetNode(enemy.NextPoint).Walkable)
                            {
                                TextureManager.Instance.spritey.Draw(TextureManager.Instance.tgaEnemies, enemy.RenderRect,
                                    new Vector3(0, 0, 0), enemy.Position, new Color4(Color.White));
                            }
                        }
                    }

                    //Draw PLAYER if at bottom of screen
                    if (!playerDrawn)
                    {
                        TextureManager.Instance.spritey.Draw(TextureManager.Instance.tgaEnemies, GameEngine.Instance.ThePlayer.RenderRect,
                                    new Vector3(0, 0, 0), GameEngine.Instance.ThePlayer.LocationDraw, new Color4(Color.White));
                    }

                    //Draw mouseover effect
                    if (WindowManager.Instance.MouseOverDX)
                    {
                        TextureManager.Instance.spritey.Draw(TextureManager.Instance.ddsMouseover, new Rectangle(0, 0, 32, 32), new Vector3(0, 0, 0),
                            new Vector3(WindowManager.Instance.mouseGridLocation.X * GameTypes.SPRITE_WIDTH, WindowManager.Instance.mouseGridLocation.Y * GameTypes.SPRITE_HEIGHT, 0),
                            new Color4(Color.White));
                        TextureManager.Instance.spritey.Draw(TextureManager.Instance.pngMouse, new Rectangle(0, 0, 32, 32), new Vector3(16, 16, 0),
                            new Vector3(WindowManager.Instance.mouseVector.X, WindowManager.Instance.mouseVector.Y, 0),
                            new Color4(Color.White));
                    }

                    TextureManager.Instance.spritey.End();

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

                    //WindowManager.Instance.Main.showkeys();

                    GameEngine.Instance.CheckCollisions();

                    if(score != GameEngine.Instance.PlayerScore)
                        WindowManager.Instance.Main.lblScore.Text = "SCORE: " + GameEngine.Instance.PlayerScore.ToString();
                    if (life != GameEngine.Instance.PlayerLife)
                    {
                        WindowManager.Instance.Main.lblLife.Text = "LIFE";
                        WindowManager.Instance.Main.ShowLife();
                    }
                    if (hiscore != GameEngine.Instance.HiScore)
                        WindowManager.Instance.Main.lblHiscore.Text = "HI-SCORE  " + GameEngine.Instance.HiScore.ToString();
                }
            });

            foreach (var item in ObjectTable.Objects)
                item.Dispose();
        }