public EntityStatic(byte type, Direction direction, BehaviorFlags flags) { Type = type; Direction = direction; Flags = flags; }
public LevelBotSubMemento() { // NB: Not all LevelBot settings are in LevelBotSettings--some are in the // LevelBot itself. _behaviorFlags = LevelBot.BehaviorFlags; _shouldUseSpiritHealer = LevelBot.ShouldUseSpiritHealer; // Settings associated with Levelbot... _settings = LevelbotSettings.Instance.GetXML(); }
public override void OnStart() { // This reports problems, and stops BT processing if there was a problem with attributes... // We had to defer this action, as the 'profile line number' is not available during the element's // constructor call. OnStart_HandleAttributeProblem(); _originalBehaviorFlags = LevelBot.BehaviorFlags; // If the quest is complete, this behavior is already done... // So we don't want to falsely inform the user of things that will be skipped. if (!IsDone) { this.UpdateGoalText(QuestId); } }
public override void PreCollisionTestUpdate(GameThing thing) { Movement movement = thing.Movement; GameActor.State state = thing.CurrentState; float secs = Time.GameTimeFrameSeconds; Vector3 collisionCenter = Vector3.Transform(CruiseMissile.XmlActor.CollisionCenter, movement.LocalMatrix); // No need to update if we're paused. if ((secs > 0.0f) && (state == GameThing.State.Active)) { // Have we outlived our life? if (Time.GameTimeTotalSeconds >= DeathTime) { VanishWithoutHittingAnything(); } else { // If the target has been killed, then have the missile go straight off the world's edge and explode. if (targetObject != null && targetObject.CurrentState == GameThing.State.Inactive) { targetObject = null; behavior &= ~BehaviorFlags.Homing; // Create new target position since we're no longer following a target. float time = (float)(DeathTime - Time.GameTimeTotalSeconds); float shotRange = time * Speed; targetPosition = collisionCenter + movement.Facing * shotRange * 2.0f; } UpdateMovement(thing, secs); CheckCollisions(movement); } } } // end of PreCollisionTestUpdate()
/// <summary> /// Updates the string which describes the device /// </summary> private void UpdateDeviceStats(DeviceType deviceType, CreateFlags behaviorFlags, AdapterDetails info) { if (State.AreStatsHidden) return; // Do nothing if stats are hidden // Get the behavior flags BehaviorFlags flags = new BehaviorFlags(behaviorFlags); // Store device information System.Text.StringBuilder builder = new System.Text.StringBuilder(); // Append device type builder.Append(deviceType.ToString()); // Append other types based on flags if (flags.HardwareVertexProcessing && flags.PureDevice) { if (deviceType == DeviceType.Hardware) builder.Append(" (pure hw vp)"); else builder.Append(" (simulated pure hw vp)"); } else if (flags.HardwareVertexProcessing) { if (deviceType == DeviceType.Hardware) builder.Append(" (hw vp)"); else builder.Append(" (simulated hw vp)"); } else if (flags.MixedVertexProcessing) { if (deviceType == DeviceType.Hardware) builder.Append(" (mixed vp)"); else builder.Append(" (simulated mixed vp)"); } else if (flags.SoftwareVertexProcessing) { builder.Append(" (sw vp)"); } // now add the description builder.Append(": "); builder.Append(info.Description); // Store the device stats string State.DeviceStats = builder.ToString(); }
/// <summary>Called when the back buffer format changes</summary> private void OnBackBufferChanged(object sender, System.EventArgs e) { ComboBox cb = sender as ComboBox; globalSettings.presentParams.BackBufferFormat = (Format)backBufferCombo.GetSelectedData(); // Store formats Format adapterFormat = globalSettings.AdapterFormat; Format backFormat = globalSettings.presentParams.BackBufferFormat; EnumDeviceInformation edi = GetCurrentDeviceInfo(); // Get possible vertex processing bool isAllowSoftware = Enumeration.IsSoftwareVertexProcessingPossible; bool isAllowHardware = Enumeration.IsHardwareVertexProcessingPossible; bool isAllowPure = Enumeration.IsPureHardwareVertexProcessingPossible; bool isAllowMixed = Enumeration.IsMixedVertexProcessingPossible; foreach (EnumDeviceSettingsCombo edsc in edi.deviceSettingsList) { if (edsc.IsWindowed == globalSettings.presentParams.Windowed && edsc.AdapterFormat == adapterFormat && edsc.BackBufferFormat == backFormat) { // Clear the depth stencil buffer depthStencilCombo.Clear(); depthStencilCombo.IsEnabled = (globalSettings.presentParams.EnableAutoDepthStencil); if (globalSettings.presentParams.EnableAutoDepthStencil) { foreach (Format f in edsc.depthStencilFormatList) { if (!depthStencilCombo.ContainsItem(f.ToString())) { depthStencilCombo.AddItem(f.ToString(), f); } } depthStencilCombo.SetSelectedByData(globalSettings.presentParams.AutoDepthStencilFormat); } else { if (!depthStencilCombo.ContainsItem("(not used)")) { depthStencilCombo.AddItem("(not used)", null); } } OnDepthStencilChanged(depthStencilCombo, e); // Now remove all the vertex processing information vertexCombo.Clear(); if (isAllowPure) { AddVertexProcessing(CreateFlags.PureDevice); } if (isAllowHardware) { AddVertexProcessing(CreateFlags.HardwareVertexProcessing); } if (isAllowSoftware) { AddVertexProcessing(CreateFlags.SoftwareVertexProcessing); } if (isAllowMixed) { AddVertexProcessing(CreateFlags.MixedVertexProcessing); } // Select the right one BehaviorFlags flags = new BehaviorFlags(globalSettings.BehaviorFlags); if (flags.PureDevice) { vertexCombo.SetSelectedByData(CreateFlags.PureDevice); } else if (flags.HardwareVertexProcessing) { vertexCombo.SetSelectedByData(CreateFlags.HardwareVertexProcessing); } else if (flags.SoftwareVertexProcessing) { vertexCombo.SetSelectedByData(CreateFlags.SoftwareVertexProcessing); } else if (flags.MixedVertexProcessing) { vertexCombo.SetSelectedByData(CreateFlags.MixedVertexProcessing); } OnVertexProcessingChanged(vertexCombo, e); // Now present intervals presentCombo.Clear(); foreach (PresentInterval pf in edsc.presentIntervalList) { if (!presentCombo.ContainsItem(pf.ToString())) { presentCombo.AddItem(pf.ToString(), pf); } } presentCombo.SetSelectedByData(globalSettings.presentParams.PresentationInterval); OnPresentIntervalChanged(presentCombo, e); } } }
/// <summary>Changes the UI defaults to the current device settings</summary> public void Refresh() { // Get some information globalSettings = parent.DeviceSettings.Clone(); System.Drawing.Rectangle client = parent.WindowClientRectangle; windowWidth = (uint)client.Width; windowHeight = (uint)client.Height; // Fill the UI with the current settings if (!deviceCombo.ContainsItem(globalSettings.DeviceType.ToString())) { deviceCombo.AddItem(globalSettings.DeviceType.ToString(), globalSettings.DeviceType.ToString()); } SetWindowed(globalSettings.presentParams.Windowed); clipBox.IsChecked = ((globalSettings.presentParams.PresentFlag & PresentFlag.DeviceClip) != 0); if (!adapterFormatCombo.ContainsItem(globalSettings.AdapterFormat.ToString())) { adapterFormatCombo.AddItem(globalSettings.AdapterFormat.ToString(), globalSettings.AdapterFormat); } AddResolution((short)globalSettings.presentParams.BackBufferWidth, (short)globalSettings.presentParams.BackBufferHeight); AddRefreshRate(globalSettings.presentParams.FullScreenRefreshRateInHz); if (!backBufferCombo.ContainsItem(globalSettings.presentParams.BackBufferFormat.ToString())) { backBufferCombo.AddItem(globalSettings.presentParams.BackBufferFormat.ToString(), globalSettings.presentParams.BackBufferFormat); } if (!depthStencilCombo.ContainsItem(globalSettings.presentParams.AutoDepthStencilFormat.ToString())) { depthStencilCombo.AddItem(globalSettings.presentParams.AutoDepthStencilFormat.ToString(), globalSettings.presentParams.AutoDepthStencilFormat); } if (!multiSampleTypeCombo.ContainsItem(globalSettings.presentParams.MultiSample.ToString())) { multiSampleTypeCombo.AddItem(globalSettings.presentParams.MultiSample.ToString(), globalSettings.presentParams.MultiSample); } if (!multiSampleQualityCombo.ContainsItem(globalSettings.presentParams.MultiSampleQuality.ToString())) { multiSampleQualityCombo.AddItem(globalSettings.presentParams.MultiSampleQuality.ToString(), globalSettings.presentParams.MultiSampleQuality); } if (!presentCombo.ContainsItem(globalSettings.presentParams.PresentationInterval.ToString())) { presentCombo.AddItem(globalSettings.presentParams.PresentationInterval.ToString(), globalSettings.presentParams.PresentationInterval); } if (!textureFilterCombo.ContainsItem(globalSettings.TextureFilter.ToString())) { textureFilterCombo.AddItem(globalSettings.TextureFilter.ToString(), globalSettings.TextureFilter); } BehaviorFlags flags = new BehaviorFlags(globalSettings.BehaviorFlags); if (flags.PureDevice) { AddVertexProcessing(CreateFlags.PureDevice); } else if (flags.HardwareVertexProcessing) { AddVertexProcessing(CreateFlags.HardwareVertexProcessing); } else if (flags.SoftwareVertexProcessing) { AddVertexProcessing(CreateFlags.SoftwareVertexProcessing); } else if (flags.MixedVertexProcessing) { AddVertexProcessing(CreateFlags.MixedVertexProcessing); } // Get the adapters list from Enumeration object ArrayList adapterInfoList = Enumeration.AdapterInformationList; if (adapterInfoList.Count == 0) { throw new NoCompatibleDevicesException(); } adapterCombo.Clear(); // Add all of the adapters for (int iAdapter = 0; iAdapter < adapterInfoList.Count; iAdapter++) { EnumAdapterInformation adapterInfo = adapterInfoList[iAdapter] as EnumAdapterInformation; if (!adapterCombo.ContainsItem(adapterInfo.UniqueDescription)) { adapterCombo.AddItem(adapterInfo.UniqueDescription, iAdapter); } } adapterCombo.SetSelectedByData(globalSettings.AdapterOrdinal); // The adapter changed, call the handler OnAdapterChanged(adapterCombo, System.EventArgs.Empty); Dialog.SetRefreshTime((float)FrameworkTimer.GetTime()); }
/// <summary> /// Initialize the graphics environment /// </summary> public void InitializeEnvironment() { GraphicsAdapterInfo adapterInfo = graphicsSettings.AdapterInfo; GraphicsDeviceInfo deviceInfo = graphicsSettings.DeviceInfo; try { Log.Info("d3dapp: Graphic adapter '{0}' is using driver version '{1}'", adapterInfo.AdapterDetails.Description.Trim(), adapterInfo.AdapterDetails.DriverVersion.ToString()); Log.Info("d3dapp: Pixel shaders supported: {0} (Version: {1}), Vertex shaders supported: {2} (Version: {3})", deviceInfo.Caps.PixelShaderCaps.NumberInstructionSlots, deviceInfo.Caps.PixelShaderVersion.ToString(), deviceInfo.Caps.VertexShaderCaps.NumberTemps, deviceInfo.Caps.VertexShaderVersion.ToString()); } catch (Exception lex) { Log.Warn("d3dapp: Error logging graphic device details - {0}", lex.Message); } // Set up the presentation parameters, we start in none exclusive mode BuildPresentParamsFromSettings(true); if (deviceInfo.Caps.PrimitiveMiscCaps.IsNullReference) { // Warn user about null ref device that can't render anything HandleSampleException(new NullReferenceDeviceException(), ApplicationMessage.None); } CreateFlags createFlags = new CreateFlags(); if (graphicsSettings.VertexProcessingType == VertexProcessingType.Software) { createFlags = CreateFlags.SoftwareVertexProcessing; } else if (graphicsSettings.VertexProcessingType == VertexProcessingType.Mixed) { createFlags = CreateFlags.MixedVertexProcessing; } else if (graphicsSettings.VertexProcessingType == VertexProcessingType.Hardware) { createFlags = CreateFlags.HardwareVertexProcessing; } else if (graphicsSettings.VertexProcessingType == VertexProcessingType.PureHardware) { createFlags = CreateFlags.HardwareVertexProcessing; // | CreateFlags.PureDevice; } else { throw new ApplicationException(); } // Make sure to allow multithreaded apps if we need them presentParams.ForceNoMultiThreadedFlag = !isMultiThreaded; try { // Create the device if (GUIGraphicsContext.IsDirectX9ExUsed()) { // Vista or later, use DirectX9 Ex device Log.Info("Creating DirectX9 Ex device"); CreateDirectX9ExDevice(createFlags); } else { Log.Info("Creating DirectX9 device"); GUIGraphicsContext.DX9Device = new Device(graphicsSettings.AdapterOrdinal, graphicsSettings.DevType, windowed ? ourRenderTarget : this, createFlags | CreateFlags.MultiThreaded | CreateFlags.FpuPreserve, presentParams); } // Cache our local objects //renderState = GUIGraphicsContext.DX9Device.RenderState; //sampleState = GUIGraphicsContext.DX9Device.SamplerState; //textureStates = GUIGraphicsContext.DX9Device.TextureState; // When moving from fullscreen to windowed mode, it is important to // adjust the window size after recreating the device rather than // beforehand to ensure that you get the window size you want. For // example, when switching from 640x480 fullscreen to windowed with // a 1000x600 window on a 1024x768 desktop, it is impossible to set // the window size to 1000x600 until after the display mode has // changed to 1024x768, because windows cannot be larger than the // desktop. if (windowed) { // Make sure main window isn't topmost, so error message is visible Size currentClientSize = this.ClientSize; this.Size = this.ClientSize; this.SendToBack(); this.BringToFront(); this.ClientSize = currentClientSize; this.TopMost = alwaysOnTop; } // Store device Caps graphicsCaps = GUIGraphicsContext.DX9Device.DeviceCaps; behavior = createFlags; StringBuilder sb = new StringBuilder(); // Store device description if (deviceInfo.DevType == DeviceType.Reference) { sb.Append("REF"); } else if (deviceInfo.DevType == DeviceType.Hardware) { sb.Append("HAL"); } else if (deviceInfo.DevType == DeviceType.Software) { sb.Append("SW"); } BehaviorFlags behaviorFlags = new BehaviorFlags(createFlags); if ((behaviorFlags.HardwareVertexProcessing) && (behaviorFlags.PureDevice)) { if (deviceInfo.DevType == DeviceType.Hardware) { sb.Append(" (pure hw vp)"); } else { sb.Append(" (simulated pure hw vp)"); } } else if (behaviorFlags.HardwareVertexProcessing) { if (deviceInfo.DevType == DeviceType.Hardware) { sb.Append(" (hw vp)"); } else { sb.Append(" (simulated hw vp)"); } } else if (behaviorFlags.MixedVertexProcessing) { if (deviceInfo.DevType == DeviceType.Hardware) { sb.Append(" (mixed vp)"); } else { sb.Append(" (simulated mixed vp)"); } } else if (behaviorFlags.SoftwareVertexProcessing) { sb.Append(" (sw vp)"); } if (deviceInfo.DevType == DeviceType.Hardware) { sb.Append(": "); sb.Append(adapterInfo.AdapterDetails.Description); } // Set device stats string deviceStats = sb.ToString(); // Set up the fullscreen cursor if (showCursorWhenFullscreen && !windowed) { Cursor ourCursor = this.Cursor; GUIGraphicsContext.DX9Device.SetCursor(ourCursor, true); GUIGraphicsContext.DX9Device.ShowCursor(true); } // Confine cursor to fullscreen window if (clipCursorWhenFullscreen && !windowed) { Rectangle rcWindow = this.ClientRectangle; } // Setup the event handlers for our device GUIGraphicsContext.DX9Device.DeviceLost += new EventHandler(this.OnDeviceLost); GUIGraphicsContext.DX9Device.DeviceReset += new EventHandler(this.OnDeviceReset); //GUIGraphicsContext.DX9Device.Disposing += new System.EventHandler(this.OnDeviceDisposing); //GUIGraphicsContext.DX9Device.DeviceResizing += new System.ComponentModel.CancelEventHandler(this.EnvironmentResized); // Initialize the app's device-dependent objects try { InitializeDeviceObjects(); //OnDeviceReset(null, null); active = true; } catch (Exception ex) { Log.Error("D3D: InitializeDeviceObjects - Exception: {0}", ex.ToString()); // Cleanup before we try again //OnDeviceLost(null, null); //OnDeviceDisposing(null, null); GUIGraphicsContext.DX9Device.Dispose(); GUIGraphicsContext.DX9Device = null; if (this.Disposing) { return; } } } catch (Exception ex) { Log.Error(ex); // If that failed, fall back to the reference rasterizer if (deviceInfo.DevType == DeviceType.Hardware) { if (FindBestWindowedMode(false, true)) { windowed = true; // Make sure main window isn't topmost, so error message is visible Size currentClientSize = this.ClientSize; this.Size = this.ClientSize; this.SendToBack(); this.BringToFront(); this.ClientSize = currentClientSize; this.TopMost = alwaysOnTop; // Let the user know we are switching from HAL to the reference rasterizer HandleSampleException(null, ApplicationMessage.WarnSwitchToRef); InitializeEnvironment(); } } } }
/// <summary>Called when the back buffer format changes</summary> private void OnBackBufferChanged(object sender, EventArgs e) { ComboBox cb = sender as ComboBox; globalSettings.presentParams.BackBufferFormat = (Format)backBufferCombo.GetSelectedData(); // Store formats Format adapterFormat = globalSettings.AdapterFormat; Format backFormat = globalSettings.presentParams.BackBufferFormat; EnumDeviceInformation edi = GetCurrentDeviceInfo(); // Get possible vertex processing bool isAllowSoftware = Enumeration.IsSoftwareVertexProcessingPossible; bool isAllowHardware = Enumeration.IsHardwareVertexProcessingPossible; bool isAllowPure = Enumeration.IsPureHardwareVertexProcessingPossible; bool isAllowMixed = Enumeration.IsMixedVertexProcessingPossible; foreach(EnumDeviceSettingsCombo edsc in edi.deviceSettingsList) { if (edsc.IsWindowed == globalSettings.presentParams.Windowed && edsc.AdapterFormat == adapterFormat && edsc.BackBufferFormat == backFormat) { // Clear the depth stencil buffer depthStencilCombo.Clear(); depthStencilCombo.IsEnabled = (globalSettings.presentParams.EnableAutoDepthStencil); if (globalSettings.presentParams.EnableAutoDepthStencil) { foreach(Format f in edsc.depthStencilFormatList) { if (!depthStencilCombo.ContainsItem(f.ToString())) depthStencilCombo.AddItem(f.ToString(), f); } depthStencilCombo.SetSelectedByData(globalSettings.presentParams.AutoDepthStencilFormat); } else { if (!depthStencilCombo.ContainsItem("(not used)") ) depthStencilCombo.AddItem("(not used)", null); } OnDepthStencilChanged(depthStencilCombo, e); // Now remove all the vertex processing information vertexCombo.Clear(); if (isAllowPure) AddVertexProcessing(CreateFlags.PureDevice); if (isAllowHardware) AddVertexProcessing(CreateFlags.HardwareVertexProcessing); if (isAllowSoftware) AddVertexProcessing(CreateFlags.SoftwareVertexProcessing); if (isAllowMixed) AddVertexProcessing(CreateFlags.MixedVertexProcessing); // Select the right one BehaviorFlags flags = new BehaviorFlags(globalSettings.BehaviorFlags); if (flags.PureDevice) vertexCombo.SetSelectedByData(CreateFlags.PureDevice); else if (flags.HardwareVertexProcessing) vertexCombo.SetSelectedByData(CreateFlags.HardwareVertexProcessing); else if (flags.SoftwareVertexProcessing) vertexCombo.SetSelectedByData(CreateFlags.SoftwareVertexProcessing); else if (flags.MixedVertexProcessing) vertexCombo.SetSelectedByData(CreateFlags.MixedVertexProcessing); OnVertexProcessingChanged(vertexCombo, e); // Now present intervals presentCombo.Clear(); foreach(PresentInterval pf in edsc.presentIntervalList) { if (!presentCombo.ContainsItem(pf.ToString())) presentCombo.AddItem(pf.ToString(), pf); } presentCombo.SetSelectedByData(globalSettings.presentParams.PresentationInterval); OnPresentIntervalChanged(presentCombo, e); } } }
/// <summary>Changes the UI defaults to the current device settings</summary> public void Refresh() { // Get some information globalSettings = parent.DeviceSettings.Clone(); System.Drawing.Rectangle client = parent.WindowClientRectangle; windowWidth = (uint)client.Width; windowHeight = (uint)client.Height; // Fill the UI with the current settings if (!deviceCombo.ContainsItem(globalSettings.DeviceType.ToString())) deviceCombo.AddItem(globalSettings.DeviceType.ToString(), globalSettings.DeviceType.ToString()); SetWindowed(globalSettings.presentParams.Windowed); clipBox.IsChecked = ((globalSettings.presentParams.PresentFlag & PresentFlag.DeviceClip) != 0); if (!adapterFormatCombo.ContainsItem(globalSettings.AdapterFormat.ToString())) adapterFormatCombo.AddItem(globalSettings.AdapterFormat.ToString(), globalSettings.AdapterFormat); AddResolution((short)globalSettings.presentParams.BackBufferWidth, (short)globalSettings.presentParams.BackBufferHeight); AddRefreshRate(globalSettings.presentParams.FullScreenRefreshRateInHz); if (!backBufferCombo.ContainsItem(globalSettings.presentParams.BackBufferFormat.ToString())) backBufferCombo.AddItem(globalSettings.presentParams.BackBufferFormat.ToString(), globalSettings.presentParams.BackBufferFormat); if (!depthStencilCombo.ContainsItem(globalSettings.presentParams.AutoDepthStencilFormat.ToString())) depthStencilCombo.AddItem(globalSettings.presentParams.AutoDepthStencilFormat.ToString(), globalSettings.presentParams.AutoDepthStencilFormat); if (!multiSampleTypeCombo.ContainsItem(globalSettings.presentParams.MultiSample.ToString())) multiSampleTypeCombo.AddItem(globalSettings.presentParams.MultiSample.ToString(), globalSettings.presentParams.MultiSample); if (!multiSampleQualityCombo.ContainsItem(globalSettings.presentParams.MultiSampleQuality.ToString())) multiSampleQualityCombo.AddItem(globalSettings.presentParams.MultiSampleQuality.ToString(), globalSettings.presentParams.MultiSampleQuality); if (!presentCombo.ContainsItem(globalSettings.presentParams.PresentationInterval.ToString())) presentCombo.AddItem(globalSettings.presentParams.PresentationInterval.ToString(), globalSettings.presentParams.PresentationInterval); BehaviorFlags flags = new BehaviorFlags(globalSettings.BehaviorFlags); if (flags.PureDevice) AddVertexProcessing(CreateFlags.PureDevice); else if (flags.HardwareVertexProcessing) AddVertexProcessing(CreateFlags.HardwareVertexProcessing); else if (flags.SoftwareVertexProcessing) AddVertexProcessing(CreateFlags.SoftwareVertexProcessing); else if (flags.MixedVertexProcessing) AddVertexProcessing(CreateFlags.MixedVertexProcessing); // Get the adapters list from Enumeration object ArrayList adapterInfoList = Enumeration.AdapterInformationList; if (adapterInfoList.Count == 0) throw new NoCompatibleDevicesException(); adapterCombo.Clear(); // Add all of the adapters for (int iAdapter = 0; iAdapter < adapterInfoList.Count; iAdapter++) { EnumAdapterInformation adapterInfo = adapterInfoList[iAdapter] as EnumAdapterInformation; if (!adapterCombo.ContainsItem(adapterInfo.UniqueDescription)) adapterCombo.AddItem(adapterInfo.UniqueDescription, iAdapter); } adapterCombo.SetSelectedByData(globalSettings.AdapterOrdinal); // The adapter changed, call the handler OnAdapterChanged(adapterCombo, EventArgs.Empty); Dialog.SetRefreshTime((float)FrameworkTimer.GetTime()); }
/// <summary> /// Initialize the graphics environment /// </summary> public void InitializeEnvironment() { GraphicsAdapterInfo adapterInfo = graphicsSettings.AdapterInfo; GraphicsDeviceInfo deviceInfo = graphicsSettings.DeviceInfo; windowed = graphicsSettings.IsWindowed; // Set up the presentation parameters BuildPresentParamsFromSettings(); if (deviceInfo.Caps.PrimitiveMiscCaps.IsNullReference) { // Warn user about null ref device that can't render anything HandleSampleException(new NullReferenceDeviceException(), ApplicationMessage.None); } CreateFlags createFlags = new CreateFlags(); if (graphicsSettings.VertexProcessingType == VertexProcessingType.Software) createFlags = CreateFlags.SoftwareVertexProcessing; else if (graphicsSettings.VertexProcessingType == VertexProcessingType.Mixed) createFlags = CreateFlags.MixedVertexProcessing; else if (graphicsSettings.VertexProcessingType == VertexProcessingType.Hardware) createFlags = CreateFlags.HardwareVertexProcessing; else if (graphicsSettings.VertexProcessingType == VertexProcessingType.PureHardware) { createFlags = CreateFlags.HardwareVertexProcessing; } else throw new ApplicationException(); #if (DX9) #else // Make sure to allow multithreaded apps if we need them presentParams.ForceNoMultiThreadedFlag = !isMultiThreaded; #endif try { // Create the device device = new Device(graphicsSettings.AdapterOrdinal, graphicsSettings.DevType, windowed ? ourRenderTarget : this , createFlags, presentParams); // Cache our local objects renderState = device.RenderState; sampleState = device.SamplerState; textureStates = device.TextureState; // When moving from fullscreen to windowed mode, it is important to // adjust the window size after recreating the device rather than // beforehand to ensure that you get the window size you want. For // example, when switching from 640x480 fullscreen to windowed with // a 1000x600 window on a 1024x768 desktop, it is impossible to set // the window size to 1000x600 until after the display mode has // changed to 1024x768, because windows cannot be larger than the // desktop. if (windowed) { // Make sure main window isn't topmost, so error message is visible System.Drawing.Size currentClientSize = this.ClientSize; this.Size = this.ClientSize; this.SendToBack(); this.BringToFront(); this.ClientSize = currentClientSize; } // Store device Caps graphicsCaps = device.DeviceCaps; behavior = createFlags; System.Text.StringBuilder sb = new System.Text.StringBuilder(); // Store device description if (deviceInfo.DevType == DeviceType.Reference) sb.Append("REF"); else if (deviceInfo.DevType == DeviceType.Hardware) sb.Append("HAL"); else if (deviceInfo.DevType == DeviceType.Software) sb.Append("SW"); BehaviorFlags behaviorFlags = new BehaviorFlags(createFlags); if ((behaviorFlags.HardwareVertexProcessing) && (behaviorFlags.PureDevice)) { if (deviceInfo.DevType == DeviceType.Hardware) sb.Append(" (pure hw vp)"); else sb.Append(" (simulated pure hw vp)"); } else if (behaviorFlags.HardwareVertexProcessing) { if (deviceInfo.DevType == DeviceType.Hardware) sb.Append(" (hw vp)"); else sb.Append(" (simulated hw vp)"); } else if (behaviorFlags.MixedVertexProcessing) { if (deviceInfo.DevType == DeviceType.Hardware) sb.Append(" (mixed vp)"); else sb.Append(" (simulated mixed vp)"); } else if (behaviorFlags.SoftwareVertexProcessing) { sb.Append(" (sw vp)"); } if (deviceInfo.DevType == DeviceType.Hardware) { sb.Append(": "); sb.Append(adapterInfo.AdapterDetails.Description); } // Set device stats string deviceStats = sb.ToString(); // Set up the fullscreen cursor if (showCursorWhenFullscreen && !windowed) { System.Windows.Forms.Cursor ourCursor = this.Cursor; device.SetCursor(ourCursor, true); device.ShowCursor(true); } // Confine cursor to fullscreen window if (clipCursorWhenFullscreen) { if (!windowed) { System.Drawing.Rectangle rcWindow = this.ClientRectangle; } } // Setup the event handlers for our device device.DeviceLost += new System.EventHandler(this.InvalidateDeviceObjects); device.DeviceReset += new System.EventHandler(this.RestoreDeviceObjects); device.Disposing += new System.EventHandler(this.DeleteDeviceObjects); device.DeviceResizing += new System.ComponentModel.CancelEventHandler(this.EnvironmentResized); // Initialize the app's device-dependent objects try { InitializeDeviceObjects(); RestoreDeviceObjects(null, null); active = true; return; } catch { // Cleanup before we try again InvalidateDeviceObjects(null, null); DeleteDeviceObjects(null, null); device.Dispose(); device = null; if (this.Disposing) return; } } catch { // If that failed, fall back to the reference rasterizer if (deviceInfo.DevType == DeviceType.Hardware) { if (FindBestWindowedMode(false, true)) { windowed = true; // Make sure main window isn't topmost, so error message is visible System.Drawing.Size currentClientSize = this.ClientSize; this.Size = this.ClientSize; this.SendToBack(); this.BringToFront(); this.ClientSize = currentClientSize; // Let the user know we are switching from HAL to the reference rasterizer HandleSampleException(null, ApplicationMessage.WarnSwitchToRef); InitializeEnvironment(); } } } }
public void InitializeEnvironment() { GraphicsAdapterInfo adapterInfo = graphicsSettings.AdapterInfo; GraphicsDeviceInfo deviceInfo = graphicsSettings.DeviceInfo; windowed = graphicsSettings.IsWindowed; // Set up the presentation parameters BuildPresentParamsFromSettings(); //if (deviceInfo.Caps.PrimitiveMiscCaps.IsNullReference) //{ // // Warn user about null ref device that can't render anything // HandleSampleException(new NullReferenceDeviceException(), ApplicationMessage.None); //} CreateFlags createFlags = new CreateFlags(); switch (graphicsSettings.VertexProcessingType) { case VertexProcessingType.Software: { createFlags = CreateFlags.SoftwareVertexProcessing; break; } case VertexProcessingType.Mixed: { createFlags = CreateFlags.MixedVertexProcessing; break; } case VertexProcessingType.Hardware: { createFlags = CreateFlags.HardwareVertexProcessing; break; } case VertexProcessingType.PureHardware: { createFlags = CreateFlags.HardwareVertexProcessing | CreateFlags.PureDevice; break; } default: throw new ApplicationException(); } createFlags |= CreateFlags.MultiThreaded; try { // Create the device device = new Device(graphicsSettings.AdapterOrdinal, graphicsSettings.DevType, presentParams.DeviceWindow, createFlags, presentParams); // Cache our local objects //renderState = device.RenderState; //sampleState = device.SamplerState; //textureStates = device.TextureState; // When moving from fullscreen to windowed mode, it is important to // adjust the window size after recreating the device rather than // beforehand to ensure that you get the window size you want. For // example, when switching from 640x480 fullscreen to windowed with // a 1000x600 window on a 1024x768 desktop, it is impossible to set // the window size to 1000x600 until after the display mode has // changed to 1024x768, because windows cannot be larger than the // desktop. if (windowed) { // Make sure main window isn't topmost, so error message is visible System.Drawing.Size currentClientSize = presentParams.DeviceWindow.ClientSize; presentParams.DeviceWindow.Size = presentParams.DeviceWindow.ClientSize; presentParams.DeviceWindow.ClientSize = currentClientSize; presentParams.DeviceWindow.SendToBack(); presentParams.DeviceWindow.BringToFront(); } device.Transform.World = Matrix.Identity; // Store device Caps graphicsCaps = device.DeviceCaps; behavior = createFlags; // Store device description if (deviceInfo.DevType == DeviceType.Reference) { deviceStats = "REF"; } else if (deviceInfo.DevType == DeviceType.Hardware) { deviceStats = "HAL"; } else if (deviceInfo.DevType == DeviceType.Software) { deviceStats = "SW"; } BehaviorFlags behaviorFlags = new BehaviorFlags(createFlags); if ((behaviorFlags.HardwareVertexProcessing) && (behaviorFlags.PureDevice)) { if (deviceInfo.DevType == DeviceType.Hardware) { deviceStats += " (pure hw vp)"; } else { deviceStats += " (simulated pure hw vp)"; } } else if ((behaviorFlags.HardwareVertexProcessing)) { if (deviceInfo.DevType == DeviceType.Hardware) { deviceStats += " (hw vp)"; } else { deviceStats += " (simulated hw vp)"; } } else if (behaviorFlags.MixedVertexProcessing) { if (deviceInfo.DevType == DeviceType.Hardware) { deviceStats += " (mixed vp)"; } else { deviceStats += " (simulated mixed vp)"; } } else if (behaviorFlags.SoftwareVertexProcessing) { deviceStats += " (sw vp)"; } if (deviceInfo.DevType == DeviceType.Hardware) { deviceStats += ": "; deviceStats += adapterInfo.AdapterDetails.Description; } // Set up the fullscreen cursor if (showCursorWhenFullscreen && !windowed) { System.Windows.Forms.Cursor ourCursor = presentParams.DeviceWindow.Cursor; device.SetCursor(ourCursor, true); device.ShowCursor(true); } // Confine cursor to fullscreen window if (clipCursorWhenFullscreen) { if (!windowed) { System.Drawing.Rectangle rcWindow = presentParams.DeviceWindow.ClientRectangle; } } // Setup the event handlers for our device device.DeviceLost += new System.EventHandler(this.OnInvalidateDeviceObjects); device.DeviceReset += new System.EventHandler(this.OnRestoreDeviceObjects); device.Disposing += new System.EventHandler(this.OnDeleteDeviceObjects); device.DeviceResizing += new System.ComponentModel.CancelEventHandler(this.EnvironmentResized); // Initialize the app's device-dependent objects try { if (InitializeDeviceObjects != null) { InitializeDeviceObjects(); } OnRestoreDeviceObjects(null, null); active = true; return; } catch { // Cleanup before we try again OnInvalidateDeviceObjects(null, null); OnDeleteDeviceObjects(null, null); device.Dispose(); device = null; if (presentParams.DeviceWindow.Disposing) { return; } } } catch { // If that failed, fall back to the reference rasterizer if (deviceInfo.DevType == DeviceType.Hardware) { if (FindBestWindowedMode(false, true)) { windowed = true; // Make sure main window isn't topmost, so error message is visible System.Drawing.Size currentClientSize = presentParams.DeviceWindow.ClientSize; presentParams.DeviceWindow.Size = presentParams.DeviceWindow.ClientSize; presentParams.DeviceWindow.ClientSize = currentClientSize; presentParams.DeviceWindow.SendToBack(); presentParams.DeviceWindow.BringToFront(); //// Let the user know we are switching from HAL to the reference rasterizer //HandleSampleException(null, ApplicationMessage.WarnSwitchToRef); InitializeEnvironment(); } } } }
/// Initializes the DirectX environment. private void InitializeEnvironment() { GraphicsDeviceInfo deviceInfo = this.settings.DeviceInfo; this.windowed = this.settings.IsWindowed; // Set up the presentation parameters BuildPresentParametersFromSettings(); if (deviceInfo.Caps.PrimitiveMiscCapabilities.IsNullReference) { // Warn user about null ref device that can't render anything //TODO: implement } CreateFlags createFlags = new CreateFlags(); if (this.settings.VertexProcessingType == VertexProcessingType.Software) { createFlags = CreateFlags.SoftwareVertexProcessing; } else if (this.settings.VertexProcessingType == VertexProcessingType.Mixed) { createFlags = CreateFlags.MixedVertexProcessing; } else if (this.settings.VertexProcessingType == VertexProcessingType.Hardware) { createFlags = CreateFlags.HardwareVertexProcessing; } else if (this.settings.VertexProcessingType == VertexProcessingType.PureHardware) { createFlags = CreateFlags.HardwareVertexProcessing | CreateFlags.PureDevice; } try { // Create the device this.localDevice = new D3D.Device(this.settings.AdapterOrdinal, this.settings.DevType, this.owner.Handle, createFlags, this.parameters); // Cache our local objects //this.renderState = this.localDevice.RenderState; //this.sampleState = this.localDevice.SamplerState; //this.textureStates = this.localDevice.TextureState; // When moving from fullscreen to windowed mode, it is important to // adjust the window size after recreating the device rather than // beforehand to ensure that you get the window size you want. For // example, when switching from 640x480 fullscreen to windowed with // a 1000x600 window on a 1024x768 desktop, it is impossible to set // the window size to 1000x600 until after the display mode has // changed to 1024x768, because windows cannot be larger than the // desktop. if (this.windowed) { // Make sure main window isn't topmost, so error message is visible System.Drawing.Size currentClientSize = this.owner.ClientSize; this.owner.Size = this.owner.ClientSize; this.owner.ClientSize = currentClientSize; this.owner.SendToBack(); this.owner.BringToFront(); } BehaviorFlags behaviorFlags = new BehaviorFlags(createFlags); this.localDevice.DeviceReset += new System.EventHandler(this.RestoreDeviceObjects); // Initialize the app's device-dependent objects try { //InitializeDeviceObjects(); RestoreDeviceObjects(null, null); this.active = true; return; } catch { this.localDevice.Dispose(); this.localDevice = null; return; } } catch { // If that failed, fall back to the reference rasterizer if (deviceInfo.DevType == D3D.DeviceType.Hardware) { if (FindBestWindowedMode(false, true)) { this.windowed = true; // Make sure main window isn't topmost, so error message is visible System.Drawing.Size currentClientSize = this.owner.ClientSize; this.owner.Size = this.owner.ClientSize; this.owner.ClientSize = currentClientSize; this.owner.SendToBack(); this.owner.BringToFront(); // Let the user know we are switching from HAL to the reference rasterizer //HandleSampleException( null, ApplicationMessage.WarnSwitchToRef); InitializeEnvironment(); } } } }