internal GraphicsContext(GraphicsAdapter graphicsAdapter, IGraphicsSurface graphicsSurface) { _graphicsAdapter = graphicsAdapter; _graphicsSurface = graphicsSurface; _acquireNextImageSemaphore = new ResettableLazy <ulong>(CreateAcquireNextImageSemaphore); _commandBuffers = new ResettableLazy <IntPtr[]>(CreateCommandBuffers); _commandPool = new ResettableLazy <ulong>(CreateCommandPool); _device = new ResettableLazy <IntPtr>(CreateDevice); _deviceQueue = new ResettableLazy <IntPtr>(CreateDeviceQueue); _fences = new ResettableLazy <ulong[]>(CreateFences); _frameBuffers = new ResettableLazy <ulong[]>(CreateFrameBuffers); _graphicsQueueFamilyIndex = new ResettableLazy <uint>(FindGraphicsQueueFamilyIndex); _queueSubmitSemaphore = new ResettableLazy <ulong>(CreateQueueSubmitSemaphore); _renderPass = new ResettableLazy <ulong>(CreateRenderPass); _surface = new ResettableLazy <ulong>(CreateSurface); _swapChain = new ResettableLazy <ulong>(CreateSwapChain); _swapChainImageViews = new ResettableLazy <ulong[]>(CreateSwapChainImageViews); _ = _state.Transition(to: Initialized); // Do event hookups after we are in the initialized state, since an event could // technically fire while the constructor is still running. _graphicsSurface.SizeChanged += HandleGraphicsSurfaceSizeChanged; }
private void SampleGraphicsControl_GraphicsContextCreated(object sender, GraphicsControlEventArgs e) { GraphicsContext ctx = e.Context; IGraphicsSurface framebuffer = e.Framebuffer; #if DEBUG _GeometryClipmapObject = new GeometryClipmapObject(9, 7, _BlockUnit); #else _GeometryClipmapObject = new GeometryClipmapObject(9, 8, _BlockUnit); #endif string workingDir = Directory.GetCurrentDirectory(); _GeometryClipmapObject.SetTerrainElevationFactory(Path.Combine(workingDir, @"..\..\..\Data\Terrain.vrt"), 45.5, 10.5); _GeometryClipmapScene = new SceneGraph(); _GeometryClipmapScene.AddChild(new SceneGraphCameraObject()); _GeometryClipmapScene.AddChild(_GeometryClipmapObject); _GeometryClipmapScene.Create(ctx); // Set projection _GeometryClipmapScene.CurrentView.ProjectionMatrix = new PerspectiveProjectionMatrix( _ViewFov / (float)Screen.PrimaryScreen.Bounds.Width * (float)Screen.PrimaryScreen.Bounds.Height, (float)ClientSize.Width / (float)ClientSize.Height, 1.0f, _ViewDepth );; // Clear color // framebuffer.SetClearColor(new ColorRGBAF(0.0f, 0.0f, 0.0f)); }
/// <summary>Initializes a new instance of the <see cref="GraphicsDevice" /> class.</summary> /// <param name="graphicsAdapter">The underlying graphics adapter for the device.</param> /// <param name="graphicsSurface">The graphics surface on which the device can render.</param> /// <exception cref="ArgumentNullException"><paramref name="graphicsAdapter" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException"><paramref name="graphicsSurface" /> is <c>null</c>.</exception> protected GraphicsDevice(GraphicsAdapter graphicsAdapter, IGraphicsSurface graphicsSurface) { ThrowIfNull(graphicsAdapter, nameof(graphicsAdapter)); ThrowIfNull(graphicsSurface, nameof(graphicsSurface)); _graphicsAdapter = graphicsAdapter; _graphicsSurface = graphicsSurface; }
/// <summary>Initializes a new instance of the <see cref="GraphicsDevice" /> class.</summary> /// <param name="adapter">The underlying adapter for the device.</param> /// <param name="surface">The surface on which the device can render.</param> /// <exception cref="ArgumentNullException"><paramref name="adapter" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException"><paramref name="surface" /> is <c>null</c>.</exception> protected GraphicsDevice(GraphicsAdapter adapter, IGraphicsSurface surface) { ThrowIfNull(adapter, nameof(adapter)); ThrowIfNull(surface, nameof(surface)); _adapter = adapter; _surface = surface; }
public LayerManager(IGraphicsSurface surfaceInfo, Action<GraphicsProfiler> graphicsUpdateCallback) : base(surfaceInfo, graphicsUpdateCallback) { modifiers = new GenericModifier(this, this); activeLayers = new SortedContainer<Layer>(); InsertionPolicy = InsertionPolicy.BringToFront; }
private Graphics frameGraphics; // graphics object used to draw directly on the frame data #endregion Fields #region Constructors protected GraphicsManager(IGraphicsSurface surfaceInfo, Action<GraphicsProfiler> graphicsUpdateCallback) { profiler = new GraphicsProfiler(); this.surfaceInfo = surfaceInfo; this.graphicsUpdateCallback = graphicsUpdateCallback; PerformResize(); ImageProcessingApi.SetMultiThreadingStatus("AlphaBlend32bgra_32bgra", 0); }
private void GraphicsControl_Draw(object sender, GraphicsControlEventArgs e) { GraphicsContext ctx = e.Context; IGraphicsSurface fb = e.Framebuffer; Gl.Viewport(0, 0, (int)fb.Width, (int)fb.Height); Gl.Clear(ClearBufferMask.ColorBufferBit); ctx.Bind(_Program); _Program.SetUniform(ctx, "hal_ModelViewProjection", new OrthoProjectionMatrix(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f)); _VertexArray.Draw(ctx, _Program); }
/// <summary> /// /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="surface"></param> /// <param name="rectangle"></param> /// <param name="flags"></param> public void BltFast(int x, int y, IGraphicsSurface surface, ref Rectangle rectangle, BltFastFlags flags) { RECT innerRect = new RECT { Left = rectangle.Left, Top = rectangle.Top, Right = rectangle.Right, Bottom = rectangle.Bottom }; Surface.BltFast(x, y, ((DirectDrawSurface)surface).Surface, ref innerRect, (CONST_DDBLTFASTFLAGS)((int)flags)); rectangle = Rectangle.FromLTRB(innerRect.Left, innerRect.Top, innerRect.Right, innerRect.Bottom); }
/// <summary> /// Construct a GraphicsControlEventArgs. /// </summary> /// <param name="ctx"> /// The <see cref="GraphicsContext"/> used for the <see cref="GraphicsControl"/>. /// </param> /// <param name="framebuffer"> /// The <see cref="IGraphicsSurface"/> holding the drawing operation result. /// </param> public GraphicsControlEventArgs(GraphicsContext ctx, IGraphicsSurface framebuffer) { if (ctx == null) { throw new ArgumentNullException("ctx"); } if (framebuffer == null) { throw new ArgumentNullException("framebuffer"); } Context = ctx; Framebuffer = framebuffer; }
internal D3D12GraphicsDevice(D3D12GraphicsAdapter graphicsAdapter, IGraphicsSurface graphicsSurface, int graphicsContextCount) : base(graphicsAdapter, graphicsSurface) { _idleGraphicsFence = new D3D12GraphicsFence(this); _d3d12CommandQueue = new ValueLazy <Pointer <ID3D12CommandQueue> >(CreateD3D12CommandQueue); _d3d12Device = new ValueLazy <Pointer <ID3D12Device> >(CreateD3D12Device); _d3d12RenderTargetDescriptorHeap = new ValueLazy <Pointer <ID3D12DescriptorHeap> >(CreateD3D12RenderTargetDescriptorHeap); _dxgiSwapChain = new ValueLazy <Pointer <IDXGISwapChain3> >(CreateDxgiSwapChain); _graphicsContexts = CreateGraphicsContexts(this, graphicsContextCount); _ = _state.Transition(to: Initialized); WaitForIdleGraphicsFence.Reset(); graphicsSurface.SizeChanged += OnGraphicsSurfaceSizeChanged;
/// <summary> /// Removes the surface associated with the given key. /// </summary> /// <param name="key">The key of the surface to remove.</param> /// <returns>The DirectDrawSurface being removed.</returns> internal IGraphicsSurface Remove(string key) { IGraphicsSurface ddSurface = null; if (string.IsNullOrEmpty(key)) { return(null); } if (_sprites.ContainsKey(key)) { ddSurface = (IGraphicsSurface)_sprites[key]; _sprites.Remove(key); } return(ddSurface); }
private void SampleGraphicsControl_Render(object sender, GraphicsControlEventArgs e) { GraphicsContext ctx = e.Context; IGraphicsSurface framebuffer = e.Framebuffer; // Update position KeyTimer_Tick(); // Define view _GeometryClipmapScene.CurrentView.LocalModel.SetIdentity(); _GeometryClipmapScene.CurrentView.LocalModel.Translate(_ViewPosition); _GeometryClipmapScene.CurrentView.LocalModel.RotateY(_ViewAzimuth); _GeometryClipmapScene.CurrentView.LocalModel.RotateX(_ViewElevation); // Draw geometry clipmap _GeometryClipmapScene.Draw(ctx); SampleGraphicsControl.Invalidate(); }
internal D3D12GraphicsDevice(D3D12GraphicsAdapter adapter, IGraphicsSurface surface, int contextCount) : base(adapter, surface) { _idleFence = new D3D12GraphicsFence(this); _d3d12CommandQueue = new ValueLazy <Pointer <ID3D12CommandQueue> >(CreateD3D12CommandQueue); _d3d12Device = new ValueLazy <Pointer <ID3D12Device> >(CreateD3D12Device); _d3d12Options = new ValueLazy <D3D12_FEATURE_DATA_D3D12_OPTIONS>(GetD3D12Options); _d3d12RenderTargetDescriptorHeap = new ValueLazy <Pointer <ID3D12DescriptorHeap> >(CreateD3D12RenderTargetDescriptorHeap); _dxgiSwapChain = new ValueLazy <Pointer <IDXGISwapChain3> >(CreateDxgiSwapChain); _memoryAllocator = new ValueLazy <D3D12GraphicsMemoryAllocator>(CreateMemoryAllocator); _cbvSrvUavDescriptorHandleIncrementSize = new ValueLazy <uint>(GetCbvSrvUavDescriptorHandleIncrementSize); _contexts = CreateContexts(this, contextCount); _ = _state.Transition(to: Initialized); WaitForIdleGraphicsFence.Reset(); surface.SizeChanged += OnGraphicsSurfaceSizeChanged;
internal VulkanGraphicsDevice(VulkanGraphicsAdapter graphicsAdapter, IGraphicsSurface graphicsSurface, int graphicsContextCount) : base(graphicsAdapter, graphicsSurface) { _presentCompletionGraphicsFence = new VulkanGraphicsFence(this); _vulkanCommandQueue = new ValueLazy <VkQueue>(GetVulkanCommandQueue); _vulkanCommandQueueFamilyIndex = new ValueLazy <uint>(GetVulkanCommandQueueFamilyIndex); _vulkanDevice = new ValueLazy <VkDevice>(CreateVulkanDevice); _vulkanRenderPass = new ValueLazy <VkRenderPass>(CreateVulkanRenderPass); _vulkanSurface = new ValueLazy <VkSurfaceKHR>(CreateVulkanSurface); _vulkanSwapchain = new ValueLazy <VkSwapchainKHR>(CreateVulkanSwapchain); _vulkanSwapchainImages = new ValueLazy <VkImage[]>(GetVulkanSwapchainImages); _graphicsContexts = CreateGraphicsContexts(this, graphicsContextCount); _ = _state.Transition(to: Initialized); PresentCompletionGraphicsFence.Reset(); graphicsSurface.SizeChanged += OnGraphicsSurfaceSizeChanged;
/// <summary> /// /// </summary> /// <param name="destRect"></param> /// <param name="surface"></param> /// <param name="srcRect"></param> /// <param name="flags"></param> public void Blt(ref Rectangle destRect, IGraphicsSurface surface, ref Rectangle srcRect, BltFlags flags) { var innerDestRect = new RECT { Left = destRect.Left, Top = destRect.Top, Right = destRect.Right, Bottom = destRect.Bottom }; var innerSrcRect = new RECT { Left = srcRect.Left, Top = srcRect.Top, Right = srcRect.Right, Bottom = srcRect.Bottom }; _surface.Blt(ref innerDestRect, _surface, ref innerSrcRect, (CONST_DDBLTFLAGS)((int)flags)); destRect = Rectangle.FromLTRB(innerDestRect.Left, innerDestRect.Top, innerDestRect.Right, innerDestRect.Bottom); srcRect = Rectangle.FromLTRB(innerSrcRect.Left, innerSrcRect.Top, innerSrcRect.Right, innerSrcRect.Bottom); }
/// <summary> /// Adds a new string to the text surface manager. This creates /// the associated text surface so that text can be rendered with /// a fast Blt rather than with a DrawText call. Note that caching /// could be done in a much more efficient manner and some text /// surfaces will have identical contents. /// </summary> /// <param name="key">The string to add.</param> internal void Add(string key) { if (string.IsNullOrEmpty(key)) { return; } var text = key; if (text.Length > 16) { text = text.Substring(0, 16); text += "..."; } // Set up the surface IGraphicsSurface ddSurface = GraphicsEngine.Current.CreateSurface(StandardFontRect.Right, StandardFontRect.Bottom); ddSurface.TransparencyKey = new ColorKey(DirectDrawSurface.MagentaColorKey); var rect = new Rectangle(); // Color in the back and add the text ddSurface.BltColorFill(ref rect, DirectDrawSurface.MagentaColorKey.low); ddSurface.SetForeColor(0); using (var font = new Font("Verdana", 6.75f, FontStyle.Regular)) { IntPtr dcHandle = ddSurface.GetDC(); using (var graphics = Graphics.FromHdc(dcHandle)) { graphics.DrawString(text, font, Brushes.Black, 1, 1); graphics.DrawString(text, font, Brushes.WhiteSmoke, 0, 0); } ddSurface.ReleaseDC(dcHandle); } sprites.Add(key, ddSurface); }
internal GraphicsContext(GraphicsAdapter graphicsAdapter, IGraphicsSurface graphicsSurface) { _graphicsAdapter = graphicsAdapter; _graphicsSurface = graphicsSurface; _commandAllocators = new ResettableLazy <ID3D12CommandAllocator *[]>(CreateCommandAllocators); _commandQueue = new ResettableLazy <IntPtr>(CreateCommandQueue); _device = new ResettableLazy <IntPtr>(CreateDevice); _fences = new ResettableLazy <ID3D12Fence *[]>(CreateFences); _fenceEvents = new ResettableLazy <IntPtr[]>(CreateFenceEvents); _fenceValues = new ResettableLazy <ulong[]>(CreateFenceValues); _graphicsCommandLists = new ResettableLazy <ID3D12GraphicsCommandList *[]>(CreateGraphicsCommandLists); _renderTargets = new ResettableLazy <ID3D12Resource *[]>(CreateRenderTargets); _renderTargetsHeap = new ResettableLazy <IntPtr>(CreateRenderTargetsHeap); _swapChain = new ResettableLazy <IntPtr>(CreateSwapChain); _ = _state.Transition(to: Initialized); // Do event hookups after we are in the initialized state, since an event could // technically fire while the constructor is still running. _graphicsSurface.SizeChanged += HandleGraphicsSurfaceSizeChanged; }
/// <summary>Creates a new <see cref="IGraphicsContext" />.</summary> /// <param name="graphicsSurface">The <see cref="IGraphicsSurface" /> on which the graphics context can draw.</param> /// <returns>A new <see cref="IGraphicsContext" /> which utilizes the current instance and which can draw on <paramref name="graphicsSurface" />.</returns> /// <exception cref="ArgumentNullException"><paramref name="graphicsSurface" /> is <c>null</c>.</exception> /// <exception cref="ObjectDisposedException">The instance has already been disposed.</exception> public IGraphicsContext CreateGraphicsContext(IGraphicsSurface graphicsSurface) { _state.ThrowIfDisposedOrDisposing(); ThrowIfNull(graphicsSurface, nameof(graphicsSurface)); return(new GraphicsContext(this, graphicsSurface)); }
/// <summary> /// Method used to create the necessary surfaces required for windowed /// mode. /// </summary> /// <returns>True if the surfaces are created, otherwise false.</returns> public bool CreateWindowedSurfaces() { _screenSurface = GraphicsEngine.Current.CreatePrimarySurface(Handle, false, false); if (_screenSurface != null) { Trace.WriteLine("Primary Surface InVideo? " + _screenSurface.InVideo); var workSurfaceWidth = Math.Min(Width, _actualsize.Right); var workSurfaceHeight = Math.Min(Height, _actualsize.Bottom); _backBufferSurface = GraphicsEngine.Current.CreateWorkSurface(workSurfaceWidth, workSurfaceHeight); Trace.WriteLine("Back Buffer Surface InVideo? " + _backBufferSurface.InVideo); _backgroundSurface = GraphicsEngine.Current.CreateWorkSurface(workSurfaceWidth, workSurfaceHeight); Trace.WriteLine("Background Surface InVideo? " + _backgroundSurface.InVideo); _stagingSurface = GraphicsEngine.Current.CreateWorkSurface(workSurfaceWidth, workSurfaceHeight); Trace.WriteLine("Staging Surface InVideo? " + _stagingSurface.InVideo); } if (!_screenSurface.InVideo || !_backBufferSurface.InVideo || !_backgroundSurface.InVideo || !_stagingSurface.InVideo) { videomemory = false; drawtext = true; // For now, turn this to false for a perf increase on slower machines } ResetTerrarium(); ClearBackground(); return true; }
/// <summary> /// Creates the surfaces required for full screen operation. /// </summary> /// <returns>True if the surfaces are initialized, false otherwise.</returns> public bool CreateFullScreenSurfaces() { if (doubleBuffer) { _screenSurface = GraphicsEngine.Current.CreatePrimarySurface(Handle, true, false); if (_screenSurface != null) { _backBufferSurface = GraphicsEngine.Current.CreateWorkSurface(640, 480); } ClearBackground(); } else { _screenSurface = GraphicsEngine.Current.CreatePrimarySurface(Handle, true, true); if (_screenSurface != null) { _backBufferSurface = _screenSurface.GetBackBufferSurface(); } } ResetTerrarium(); return true; }
/// <summary> /// Reinitialize all surfaces after they have been lost. /// This method invokes the garbage collector to make sure /// that any COM references have been cleaned up, else surface /// renewal won't work correctly. /// </summary> private void ReInitSurfaces() { _screenSurface = null; _backBufferSurface = null; _backgroundSurface = null; _stagingSurface = null; tsm.Clear(); tfm.Clear(); GC.Collect(2); GC.WaitForPendingFinalizers(); if (fullscreen) { CreateFullScreenSurfaces(); } else { CreateWindowedSurfaces(); } }
/// <summary> /// /// </summary> /// <param name="destRect"></param> /// <param name="surface"></param> /// <param name="srcRect"></param> /// <param name="flags"></param> public void Blt(ref Rectangle destRect, IGraphicsSurface surface, ref Rectangle srcRect, BltFlags flags) { RECT innerDestRect = new RECT { Left = destRect.Left, Top = destRect.Top, Right = destRect.Right, Bottom = destRect.Bottom }; RECT innerSrcRect = new RECT { Left = srcRect.Left, Top = srcRect.Top, Right = srcRect.Right, Bottom = srcRect.Bottom }; Surface.Blt(ref innerDestRect, ((DirectDrawSurface) surface).Surface, ref innerSrcRect, (CONST_DDBLTFLAGS)((int)flags)); destRect = Rectangle.FromLTRB(innerDestRect.Left, innerDestRect.Top, innerDestRect.Right, innerDestRect.Bottom); srcRect = Rectangle.FromLTRB(innerSrcRect.Left, innerSrcRect.Top, innerSrcRect.Right, innerSrcRect.Bottom); }
/// <inheritdoc /> public override D3D12GraphicsDevice CreateDevice(IGraphicsSurface surface, int contextCount) { _state.ThrowIfDisposedOrDisposing(); return(new D3D12GraphicsDevice(this, surface, contextCount)); }
/// <summary>Creates a new <see cref="IGraphicsContext" />.</summary> /// <param name="graphicsSurface">The <see cref="IGraphicsSurface" /> on which the graphics context can draw.</param> /// <returns>A new <see cref="IGraphicsContext" /> which utilizes the current instance and which can draw on <paramref name="graphicsSurface" />.</returns> /// <exception cref="ArgumentNullException"><paramref name="graphicsSurface" /> is <c>null</c>.</exception> public IGraphicsContext CreateGraphicsContext(IGraphicsSurface graphicsSurface) { ThrowIfNull(graphicsSurface, nameof(graphicsSurface)); return(new GraphicsContext(this, graphicsSurface)); }
/// <summary>Creates a new graphics device which utilizes the adapter to render to a surface.</summary> /// <param name="surface">The surface to which the context can render.</param> /// <param name="contextCount">The number of contexts the device should maintain.</param> /// <returns>A new graphics device which utilizes the the adapter to render to <paramref name="surface" />.</returns> /// <exception cref="ArgumentNullException"><paramref name="surface" /> is <c>null</c>.</exception> /// <exception cref="ObjectDisposedException">The adapter has been disposed.</exception> public abstract GraphicsDevice CreateDevice(IGraphicsSurface surface, int contextCount);
/// <inheritdoc cref="CreateDevice(IGraphicsSurface, int)" /> public VulkanGraphicsDevice CreateVulkanGraphicsDevice(IGraphicsSurface surface, int contextCount) { ThrowIfDisposedOrDisposing(_state, nameof(VulkanGraphicsAdapter)); return(new VulkanGraphicsDevice(this, surface, contextCount)); }
/// <inheritdoc cref="CreateDevice(IGraphicsSurface, int)" /> public VulkanGraphicsDevice CreateVulkanGraphicsDevice(IGraphicsSurface surface, int contextCount) { _state.ThrowIfDisposedOrDisposing(); return(new VulkanGraphicsDevice(this, surface, contextCount)); }
/// <summary>Creates a new graphics device which utilizes the adapter to render to a graphics surface.</summary> /// <param name="graphicsSurface">The graphics surface to which the context can render.</param> /// <param name="graphicsContextCount">The number of graphics contexts the device should maintain.</param> /// <returns>A new graphics device which utilizes the the adapter to render to <paramref name="graphicsSurface" />.</returns> /// <exception cref="ArgumentNullException"><paramref name="graphicsSurface" /> is <c>null</c>.</exception> /// <exception cref="ObjectDisposedException">The adapter has been disposed.</exception> public abstract GraphicsDevice CreateGraphicsDevice(IGraphicsSurface graphicsSurface, int graphicsContextCount);
/// <inheritdoc cref="CreateGraphicsDevice(IGraphicsSurface, int)" /> public D3D12GraphicsDevice CreateD3D12GraphicsDevice(IGraphicsSurface graphicsSurface, int graphicsContextCount) { _state.ThrowIfDisposedOrDisposing(); return(new D3D12GraphicsDevice(this, graphicsSurface, graphicsContextCount)); }
/// <inheritdoc /> public override GraphicsDevice CreateGraphicsDevice(IGraphicsSurface graphicsSurface, int graphicsContextCount) => CreateD3D12GraphicsDevice(graphicsSurface, graphicsContextCount);
/// <inheritdoc /> public override D3D12GraphicsDevice CreateDevice(IGraphicsSurface surface, int contextCount) { ThrowIfDisposedOrDisposing(_state, nameof(D3D12GraphicsAdapter)); return(new D3D12GraphicsDevice(this, surface, contextCount)); }
/// <summary> /// Paint sprites on the given surface. This method is the meat /// of the graphics engine. Normally, creatures are painted to /// the work surface using this method. To increase performance plants /// are rendered to the background surface only once every 10 frames. /// Lots of work happening in this function so either read through the /// code or examine the Terrarium Graphics Engine whitepaper for more /// information. /// </summary> /// <param name="surf">The surface to render to.</param> /// <param name="PlantsOnly">True to render plants, false to render animals.</param> private void PaintSprites(IGraphicsSurface surf, bool PlantsOnly) { #if TRACE Profiler.Start("TerrariumDirectDrawGameView.PaintSprites()"); #endif if (wv == null) { return; } if (tfm.Count > 100) { tfm.Clear(); } var TeleporterZIndices = TeleporterZIndex(); var lastTeleporterZIndex = 0; foreach (OrganismState orgState in wv.State.ZOrderedOrganisms) { if (orgState.RenderInfo != null) { var tsSprite = (TerrariumSprite) orgState.RenderInfo; if ((PlantsOnly && !(orgState.Species is PlantSpecies)) || (!PlantsOnly && orgState.Species is PlantSpecies)) { continue; } if (orgState.Species is AnimalSpecies) { tsSprite.AdvanceFrame(); orgState.RenderInfo = tsSprite; } if (!videomemory && skipframe) { continue; } TerrariumSpriteSurface workTss = null; if (workTss == null && tsSprite.SpriteKey != null) { workTss = tsm[tsSprite.SpriteKey, orgState.Radius, (orgState.Species is AnimalSpecies)]; } if (workTss == null && tsSprite.SkinFamily != null) { workTss = tsm[tsSprite.SkinFamily, orgState.Radius, (orgState.Species is AnimalSpecies)]; } if (workTss == null) { if (orgState.Species is AnimalSpecies) { workTss = tsm["ant", orgState.Radius, (orgState.Species is AnimalSpecies)]; } else { workTss = tsm["plant", orgState.Radius, (orgState.Species is AnimalSpecies)]; } } if (workTss != null) { var direction = orgState.ActualDirection; var radius = orgState.Radius; var framedir = 1; var workSurface = workTss.GetClosestSurface((radius*2)); radius = workSurface.FrameWidth; if (direction >= 68 && direction < 113) { framedir = 1; } else if (direction >= 113 && direction < 158) { framedir = 2; } else if (direction >= 158 && direction < 203) { framedir = 3; } else if (direction >= 203 && direction < 248) { framedir = 4; } else if (direction >= 248 && direction < 293) { framedir = 5; } else if (direction >= 293 && direction < 338) { framedir = 6; } else if (direction >= 338 && direction < 23) { framedir = 7; } else { framedir = 8; } var dest = new Rectangle((int) tsSprite.XPosition - (_viewsize.Left + (radius >> 1)), (int) tsSprite.YPosition - (_viewsize.Top + (radius >> 1)), (int) tsSprite.XPosition - (_viewsize.Left + (radius >> 1)) + radius, (int) tsSprite.YPosition - (_viewsize.Top + (radius >> 1)) + radius); if (updateMiniMap) { var miniMapX = (int) (tsSprite.XPosition*miniMap.Width)/_actualsize.Right; miniMapX = (miniMapX > (miniMap.Width - 1)) ? (miniMap.Width - 1) : miniMapX; var miniMapY = (int) (tsSprite.YPosition*miniMap.Height)/_actualsize.Bottom; miniMapY = (miniMapY > (miniMap.Height - 1)) ? (miniMap.Height - 1) : miniMapY; var brushColor = Color.Fuchsia; if (orgState.Species.GetType() == typeof (PlantSpecies)) { brushColor = Color.Lime; } else if (orgState.IsAlive == false) { brushColor = Color.Black; } else { var orgSpecies = (Species) orgState.Species; if (orgSpecies.MarkingColor == KnownColor.Green || orgSpecies.MarkingColor == KnownColor.Black) { brushColor = Color.Red; } else { brushColor = Color.FromKnownColor(orgSpecies.MarkingColor); } } Brush orgBrush = new SolidBrush(brushColor); var miniMapGraphics = Graphics.FromImage(miniMap); miniMapGraphics.FillRectangle(orgBrush, miniMapX, miniMapY, 12, 12); miniMapGraphics.Dispose(); orgBrush.Dispose(); //this.miniMap.SetPixel( // miniMapX, // miniMapY, // (orgState.Species is PlantSpecies) ? Color.Green : (!orgState.IsAlive) ? Color.Black : (((Species) orgState.Species).MarkingColor == KnownColor.Green || ((Species) orgState.Species).MarkingColor == KnownColor.Black) ? Color.Red : Color.FromKnownColor(((Species) orgState.Species).MarkingColor)); } DirectDrawClippedRect ddClipRect; if (orgState.Species is PlantSpecies) { ddClipRect = workSurface.GrabSprite((int) tsSprite.CurFrame, 0, dest, _clipRect); } else { if (tsSprite.PreviousAction == DisplayAction.NoAction || tsSprite.PreviousAction == DisplayAction.Reproduced || tsSprite.PreviousAction == DisplayAction.Teleported || tsSprite.PreviousAction == DisplayAction.Dead) { if (tsSprite.PreviousAction == DisplayAction.Dead) { ddClipRect = workSurface.GrabSprite( 9, ((int) DisplayAction.Died) + framedir, dest, _clipRect); } else { ddClipRect = workSurface.GrabSprite(0, ((int) DisplayAction.Moved) + framedir, dest, _clipRect); } } else { ddClipRect = workSurface.GrabSprite((int) tsSprite.CurFrame, ((int) tsSprite.PreviousAction) + framedir, dest, _clipRect); } } if (!ddClipRect.Invisible) { if (!PlantsOnly) { RenderTeleporter(lastTeleporterZIndex, (int) tsSprite.YPosition); lastTeleporterZIndex = (int) tsSprite.YPosition; } surf.BltFast(ddClipRect.Destination.Left, ddClipRect.Destination.Top, workSurface.SpriteSurface, ref ddClipRect.Source, BltFastFlags.SrcColorKey); if (drawtext && !PlantsOnly) { var textSurface = tfm[((Species) orgState.Species).Name]; if (textSurface != null && textSurface.Surface != null) { surf.BltFast(ddClipRect.Destination.Left, ddClipRect.Destination.Top - 14, textSurface, ref TerrariumTextSurfaceManager.StandardFontRect, BltFastFlags.SrcColorKey); } } if (!ddClipRect.ClipLeft && !ddClipRect.ClipRight && !ddClipRect.ClipTop && !ddClipRect.ClipBottom) { if (drawDestinationLines) { if (orgState.CurrentMoveToAction != null) { var start = orgState.Position; var end = orgState.CurrentMoveToAction.MovementVector.Destination; ((DirectDrawSurface)surf).Surface.SetForeColor(0); ((DirectDrawSurface)surf).Surface.DrawLine(start.X - _viewsize.Left, start.Y - _viewsize.Top, end.X - _viewsize.Left, end.Y - _viewsize.Top); } } if (drawBoundingBox) { var boundingBox = GetBoundsOfState(orgState); ((DirectDrawSurface)surf).Surface.SetForeColor(0); ((DirectDrawSurface)surf).Surface.DrawBox( boundingBox.Left - _viewsize.Left, boundingBox.Top - _viewsize.Top, (boundingBox.Right + 1) - _viewsize.Left, (boundingBox.Bottom + 1) - _viewsize.Top ); } if (tsSprite.Selected) { ((DirectDrawSurface)surf).Surface.SetForeColor(0); ((DirectDrawSurface)surf).Surface.DrawBox(ddClipRect.Destination.Left, ddClipRect.Destination.Top, ddClipRect.Destination.Right, ddClipRect.Destination.Bottom); // red Maybe we want some cool graphic here though var lineheight = (int) ((ddClipRect.Destination.Bottom - ddClipRect.Destination.Top)* orgState.PercentEnergy); ((DirectDrawSurface)surf).Surface.SetForeColor(63488); ((DirectDrawSurface)surf).Surface.DrawLine(ddClipRect.Destination.Left - 1, ddClipRect.Destination.Top, ddClipRect.Destination.Left - 1, ddClipRect.Destination.Top + lineheight); //green Maybe we want some cool graphic here though (or an actual bar?) lineheight = (int) ((ddClipRect.Destination.Bottom - ddClipRect.Destination.Top)* orgState.PercentInjured); ((DirectDrawSurface)surf).Surface.SetForeColor(2016); ((DirectDrawSurface)surf).Surface.DrawLine(ddClipRect.Destination.Right + 1, ddClipRect.Destination.Top, ddClipRect.Destination.Right + 1, ddClipRect.Destination.Top + lineheight); } } } } } } RenderTeleporter(lastTeleporterZIndex, _actualsize.Bottom); #if TRACE Profiler.End("TerrariumDirectDrawGameView.PaintSprites()"); #endif }
/// <inheritdoc /> public override GraphicsDevice CreateDevice(IGraphicsSurface surface, int contextCount) => CreateVulkanGraphicsDevice(surface, contextCount);