/// <summary> /// Konstruktor, spusti inicializaci D3D /// </summary> /// <param name="form">Objekt tridy Form, kam se ma vykreslovat</param> /// <param name="windowed">Je true, pokud aplikace bude spusteni v okenim rezimu, jinak bude spustena ve fullscreenu</param> public GraphicCore(Program form, bool windowed) { Logger.AddInfo("Graphic core init"); this.windowed = windowed; this.form = form; form.Size = this.WindowResolution; initializator = new Initializator(form); initializator.SetResolution(false, form.Size.Width, form.Size.Height); if (currentDetail == SceneManager.DetailLevel.High || currentDetail == SceneManager.DetailLevel.UltraHigh || Settings.Default.ForceVSync) { initializator.SetVSync(true); } initializator.ReInit(); device = initializator.GetDevice(); Microsoft.DirectX.Direct3D.AdapterDetails adapter = new Microsoft.DirectX.Direct3D.AdapterDetails(); Logger.AddInfo("Info: " + System.Environment.OSVersion.ToString() + "<br/> " + this.device.DisplayMode + "<br/>" + adapter.ToString()); sceneManager = new SceneManager(device, Camera.GetCameraInstance()); #region Nastaveni kvality shadow map int shadowMapDimension = Settings.Default.MediumShadowMapDimension; if (currentDetail == SceneManager.DetailLevel.Low) { shadowMapDimension = (int)(shadowMapDimension * 0.5f); } else if (currentDetail == SceneManager.DetailLevel.High) { shadowMapDimension *= 2; } #endregion shadowMap = new RenderToTexture(device, shadowMapDimension, shadowMapDimension, Format.R32F, true, DepthFormat.D24X8); collisionMap = new RenderToTexture(device, 128, 128, Format.A8R8G8B8, true, DepthFormat.D16); DeviceReset(); }
/// <summary> /// Funkce nainicializuje jednotlive podsystemy a spusti herni smycku /// </summary> public void InitCore() { VideoManager video = new VideoManager(this, false); video.LoadVideo(@"Resources/Videos/logo2.avi", true); Logger.InitLogger(); Logger.bWriteToOutput = true; Logger.AddInfo("Inicializace"); graphic = new WRG.GraphicCore(this, true); multimediaManager = new SoundManager(this); if (Properties.Settings.Default.EnableMusic) { multimediaManager.AddToPlayList(@"Resources/Music/"); } multimediaManager.PlayMusic(); video.PlayVideo(); input = Input.GetInputInstance(this); input.SetCooperative(Microsoft.DirectX.DirectInput.CooperativeLevelFlags.Background | Microsoft.DirectX.DirectInput.CooperativeLevelFlags.NonExclusive); menu = new MenuManager(WRG.GraphicCore.GetInitializator().GetDevice()); #region Init Tests if (graphic == null) { Logger.AddError(global::WiccanRede.Properties.Resources.Graphic_Core_Init_Error); return; } if (input == null) { Logger.AddError(global::WiccanRede.Properties.Resources.Input_Core_Init_Error); return; } #endregion this.Show(); resourceLoadThread = new Thread(graphic.ResourcesLoad); resourceLoadThread.Start(); List <Input.Action> actions = null; startTime = Environment.TickCount; input.Start(); int lastTime = 0; while (resourceLoadThread.ThreadState != ThreadState.Stopped) { graphic.ResourceProgressRender(); Application.DoEvents(); Thread.Sleep(200); } video.StopVideo(); video.Dispose(); this.windowRect = new System.Drawing.Rectangle(this.Location, this.Size); Cursor.Position = PointToScreen(new System.Drawing.Point(0, 0)); Cursor.Clip = windowRect; Cursor.Hide(); SetCore(); WRG.Initializator init = WRG.GraphicCore.GetInitializator(); while (!exit && this.Created) { milisecondsElapsed = (Environment.TickCount - startTime); int frametime = milisecondsElapsed - lastTime; WRG.CameraDriver.SetTime(frametime); actions = input.Update(true); if (game != null) { List <WiccanRede.AI.NpcInfo> npcs = game.GetAllNpcInfo(); //je hrac mrtvy? if (npcs[npcs.Count - 1].Status.hp <= 0 && this.menu.MenuState != MenuResult.Restart) { this.menu.UpdateState("Gameover"); this.drawMenu = true; } else if (this.menu.MenuState == MenuResult.Restart) { this.menu.UpdateState("MainMenu"); this.menu.MenuState = MenuResult.New; Restart(); } //je konec hry? if (game.GetCurrentGameState().Name == "Final") { this.menu.UpdateState("ToBeContinued"); this.drawMenu = true; } } if (this.Focused) { Cursor.Clip = this.windowRect; if (init.IsFullscreen()) { Cursor.Clip = System.Drawing.Rectangle.Empty; } } else { Cursor.Clip = System.Drawing.Rectangle.Empty; } if (this.drawMenu) { Cursor.Show(); init.GetDevice().BeginScene(); MenuResult result = this.menu.Update(this.PointToClient(MousePosition), (actions.Contains(Input.Action.Action1))); init.GetDevice().EndScene(); init.GetDevice().Present(); if (result == MenuResult.Pub) { this.drawMenu = false; this.menu.UpdateState("MainMenu"); this.menu.CurrentMenuResult = MenuResult.None; } else if (result == MenuResult.New) { this.drawMenu = false; this.menu.UpdateState("MainMenu"); this.menu.CurrentMenuResult = MenuResult.New; } else if (result == MenuResult.Exit || actions.Contains(Input.Action.Exit)) { this.exit = true; } System.Threading.Thread.Sleep(20); Cursor.Hide(); } else { action1Stoper -= frametime; action2Stoper -= frametime; ProcessActions(actions); graphic.Render(milisecondsElapsed); if (game == null) { game = WiccanRede.Game.GameManager.GetInstance(); graphic.FirstTimeRender(); } try { game.Update((float)(frametime) / 1000f); } catch (Exception ex) { Logger.AddError(ex.Message); } } Application.DoEvents(); lastTime = milisecondsElapsed; } Logging.Logger.Save(); graphic.Dispose(); multimediaManager.Dispose(); }