public override void BeforeDispose() { if (_toolbarUi != null) { _toolbarUi.Dispose(); } if (_spriteRender != null) { _spriteRender.Dispose(); } if (_crosshair != null) { _crosshair.Dispose(); } if (_font != null) { _font.Dispose(); } if (_tooltip != null) { _tooltip.Dispose(); } if (_weatherContainer != null) { _weatherContainer.Dispose(); } if (_energyBar != null) { _energyBar.Dispose(); } if (_d3DEngine != null) { _d3DEngine.ScreenSize_Updated -= D3DEngineViewPortUpdated; } }
public static void ClearUnusedTextures() { int count = 0; long ticks = CoreGame.Ticks - 3000; for (int i = 0; i < _usedIndex.Count; i++) { int g = _usedIndex[i]; SpriteTexture texture = _textmapDictionary[g]; //ref SpriteTexture texture = ref _textmapCache[_usedIndex[i]]; if (texture.Ticks < ticks) { texture.Dispose(); // texture = null; _usedIndex.RemoveAt(i--); _textmapDictionary.Remove(g); if (++count >= 20) { break; } } } }
public override void Update(double totalMS, double frameMS) { _frameMS = frameMS; if (_gumpTexture == null || _gumpTexture.IsDisposed || _useLargeMap != _miniMap_LargeFormat || _forceUpdate) { _useLargeMap = _miniMap_LargeFormat; if (_gumpTexture != null) { _gumpTexture.Dispose(); } _gumpTexture = IO.Resources.Gumps.GetGumpTexture(_useLargeMap ? (ushort)5011 : (ushort)5010); Width = _gumpTexture.Width; Height = _gumpTexture.Height; CreateMiniMapTexture(); if (_forceUpdate) { _forceUpdate = false; } } if (_gumpTexture != null) { _gumpTexture.Ticks = (long)totalMS; } if (_mapTexture != null) { _mapTexture.Ticks = (long)totalMS; } }
public void Dispose() { if (VertexBuffer != null && !VertexBuffer.Disposed) { VertexBuffer.Dispose(); } if (VertexInputLayout != null && !VertexInputLayout.Disposed) { VertexInputLayout.Dispose(); } if (SpriteEffect != null && !SpriteEffect.Disposed) { SpriteEffect.Dispose(); } if (SpriteTexture != null && !SpriteTexture.Disposed) { SpriteTexture.Dispose(); } if (mapedBitmap != null) { mapedBitmap.Dispose(); } if (mapedGraphic != null) { mapedGraphic.Dispose(); } }
/// <summary> /// テクスチャを更新する必要が有る場合更新する /// レンダリングと同一タイミングで呼び出すこと。 /// </summary> public void Update() { if (NeedRedraw) { using (MemoryStream ms = new MemoryStream()) { lock (mapedBitmap) { mapedBitmap.Save(ms, ImageFormat.Tiff); } ms.Seek(0, SeekOrigin.Begin); try { if (SpriteTexture != null) { lock (SpriteTexture) { SpriteTexture.Dispose(); SpriteTexture = ShaderResourceView.FromStream(Context.DeviceManager.Device, ms, (int)ms.Length); } } else { SpriteTexture = ShaderResourceView.FromStream(Context.DeviceManager.Device, ms, (int)ms.Length); } } catch (Direct3D11Exception) { //終了時になぜかスローされる。とりあえず無視 } } NeedRedraw = false; } }
public static void ClearUnusedTextures() { int count = 0; for (int i = 0; i < _usedIndex.Count; i++) { int g = _usedIndex[i]; SpriteTexture texture = _gumpDictionary[g]; //ref SpriteTexture texture = ref _gumpCache[_usedIndex[i]]; if (texture == null || texture.IsDisposed) { _usedIndex.RemoveAt(i--); } else if (CoreGame.Ticks - texture.Ticks >= 3000) { texture.Dispose(); //texture = null; _usedIndex.RemoveAt(i--); _gumpDictionary.Remove(g); if (++count >= 5) { break; } } } }
public static void ClearUnusedTextures() { int count = 0; long ticks = CoreGame.Ticks - Constants.CLEAR_TEXTURES_DELAY; for (int i = 0; i < _usedIndex.Count; i++) { int g = _usedIndex[i]; SpriteTexture texture = _gumpDictionary[g]; //ref SpriteTexture texture = ref _gumpCache[_usedIndex[i]]; if (texture.Ticks < ticks) { texture.Dispose(); //texture = null; _usedIndex.RemoveAt(i--); _gumpDictionary.Remove(g); if (++count >= Constants.MAX_GUMP_OBJECT_REMOVED_BY_GARBAGE_COLLECTOR) { break; } } } }
public void Dispose() { if (StShadow != null) { StShadow.Dispose(); StLogo.Dispose(); StGameName.Dispose(); StCubesPattern.Dispose(); StLinenPattern.Dispose(); StInputBackground.Dispose(); StButtonBackground.Dispose(); StButtonBackgroundDown.Dispose(); StButtonBackgroundHover.Dispose(); FontBebasNeue50.Dispose(); FontBebasNeue35.Dispose(); FontBebasNeue25.Dispose(); FontBebasNeue17.Dispose(); } if (StInventoryEquipmentSlot != null) { StInventoryEquipmentSlot.Dispose(); StInventoryEquipmentSlotHover.Dispose(); StInventoryInfo.Dispose(); StInventorySlot.Dispose(); StInventorySlotHover.Dispose(); } }
public override void BeforeDispose() { if (_iconsTextureArray != null) { _iconsTextureArray.Dispose(); } if (_iconTextureArray != null) { _iconTextureArray.Dispose(); } }
public static void Clear() { for (int i = 0; i < _usedIndex.Count; i++) { int g = _usedIndex[i]; SpriteTexture texture = _gumpDictionary[g]; texture.Dispose(); _usedIndex.RemoveAt(i--); _gumpDictionary.Remove(g); } }
public static void ClearUnusedTextures() { int count = 0; long ticks = Engine.Ticks - Constants.CLEAR_TEXTURES_DELAY; for (int i = 0; i < _usedIndex.Count; i++) { int g = _usedIndex[i]; SpriteTexture texture = _artDictionary[g]; if (texture.Ticks < ticks) { texture.Dispose(); _usedIndex.RemoveAt(i--); _artDictionary.Remove(g); if (++count >= Constants.MAX_ART_OBJECT_REMOVED_BY_GARBAGE_COLLECTOR) { break; } } } count = 0; for (int i = 0; i < _usedIndexLand.Count; i++) { int g = _usedIndexLand[i]; SpriteTexture texture = _landDictionary[g]; if (texture.Ticks < ticks) { texture.Dispose(); _usedIndexLand.RemoveAt(i--); _landDictionary.Remove(g); if (++count >= Constants.MAX_ART_OBJECT_REMOVED_BY_GARBAGE_COLLECTOR) { break; } } } }
public override void Dispose() { _texture?.Dispose(); base.Dispose(); }
private List <Texture2D> Create3DBlockIcons(DeviceContext context, ShaderResourceView cubesTexture, int iconSize) { List <Texture2D> createdIconsTexture = new List <Texture2D>(); SpriteRenderer spriteRenderer = new SpriteRenderer(_d3DEngine, Path.Combine(ClientSettings.PathRoot, @"Effects\Sprites\Sprites2.hlsl")); //Get the "Block" mesh that will be used to draw the various blocks. IMeshFactory meshfactory = new MilkShape3DMeshFactory(); Mesh meshBluePrint; int textureSize = iconSize; meshfactory.LoadMesh(ClientSettings.PathRoot + @"\Meshes\block.txt", out meshBluePrint, 0); //Create Vertex/Index Buffer to store the loaded mesh. VertexBuffer <VertexMesh> vb = new VertexBuffer <VertexMesh>(_d3DEngine.Device, meshBluePrint.Vertices.Length, SharpDX.Direct3D.PrimitiveTopology.TriangleList, "Block VB"); IndexBuffer <ushort> ib = new IndexBuffer <ushort>(_d3DEngine.Device, meshBluePrint.Indices.Length, "Block IB"); //Create the render texture RenderedTexture2D texture = ToDispose(new RenderedTexture2D(_d3DEngine, textureSize, textureSize, SharpDX.DXGI.Format.R8G8B8A8_UNorm) { BackGroundColor = new Color4(0, 0, 0, 0) }); Texture2DDescription SpriteTextureDesc = new Texture2DDescription() { Width = 1, Height = 1, MipLevels = 1, ArraySize = 1, Format = Format.R32G32B32A32_Float, SampleDescription = new SampleDescription() { Count = 1 }, Usage = ResourceUsage.Dynamic, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.Write }; Texture2D sTexture = new Texture2D(_d3DEngine.Device, SpriteTextureDesc); DataStream dataStream; DataBox data = context.MapSubresource(sTexture, 0, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out dataStream); dataStream.Position = 0; dataStream.Write <Vector4>(new Vector4(1.0f, 1.0f, 1.0f, 1.0f)); //Ecrire dans la texture dataStream.Position = 0; context.UnmapSubresource(sTexture, 0); dataStream.Dispose(); SpriteTexture spriteTexture = new SpriteTexture(sTexture); spriteTexture.ScreenPosition = new Rectangle(spriteTexture.ScreenPosition.X, spriteTexture.ScreenPosition.Y, textureSize, textureSize); sTexture.Dispose(); //Create the Shadder used to render on the texture. HLSLIcons shader = new HLSLIcons(_d3DEngine.Device, ClientSettings.EffectPack + @"Entities/Icons.hlsl", VertexMesh.VertexDeclaration); //Compute projection + View matrix float aspectRatio = textureSize / textureSize; Matrix projection; Matrix.PerspectiveFovLH((float)Math.PI / 3.6f, aspectRatio, 0.5f, 100f, out projection); Matrix view = Matrix.LookAtLH(new Vector3(0, 0, -1.9f), Vector3.Zero, Vector3.UnitY); Matrix WorldScale; Dictionary <int, int> MaterialChangeMapping = new Dictionary <int, int>(); MaterialChangeMapping.Add(0, 0); //Change the Back Texture Id MaterialChangeMapping.Add(1, 0); //Change the Front Texture Id MaterialChangeMapping.Add(2, 0); //Change the Bottom Texture Id MaterialChangeMapping.Add(3, 0); //Change the Top Texture Id MaterialChangeMapping.Add(4, 0); //Change the Left Texture Id MaterialChangeMapping.Add(5, 0); //Change the Right Texture Id _cubeIconIndexes = new Dictionary <byte, byte>(); //Create a texture for each cubes existing ! foreach (BlockProfile profile in _visualWorldParameters.WorldParameters.Configuration.GetAllCubesProfiles()) { //Don't create "Air" cube if (profile.Id == WorldConfiguration.CubeId.Air) { continue; } //Create the new Material MeshMapping //Here the key parameter is the ID name given to the texture inside the file model. //In our case the model loaded has these Materials/texture Ids : // 0 = Back // 1 = Front // 2 = Bottom // 3 = Top // 4 = Left // 5 = Right //The value attached to it is simply the TextureID from the texture array to use. MaterialChangeMapping[0] = profile.Textures == null ? 0 : profile.Tex_Back.TextureArrayId; //Change the Back Texture Id MaterialChangeMapping[1] = profile.Textures == null ? 0 : profile.Tex_Front.TextureArrayId; //Change the Front Texture Id MaterialChangeMapping[2] = profile.Textures == null ? 0 : profile.Tex_Bottom.TextureArrayId; //Change the Bottom Texture Id MaterialChangeMapping[3] = profile.Textures == null ? 0 : profile.Tex_Top.TextureArrayId; //Change the Top Texture Id MaterialChangeMapping[4] = profile.Textures == null ? 0 : profile.Tex_Left.TextureArrayId; //Change the Left Texture Id MaterialChangeMapping[5] = profile.Textures == null ? 0 : profile.Tex_Right.TextureArrayId; //Change the Right Texture Id Mesh mesh = meshBluePrint.Clone(MaterialChangeMapping); //Stored the mesh data inside the buffers vb.SetData(context, mesh.Vertices); ib.SetData(context, mesh.Indices); //Begin Drawing texture.Begin(context); RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Enabled, DXStates.DepthStencils.DepthDisabled); //Set sampler shader.SamplerDiffuse.Value = RenderStatesRepo.GetSamplerState(DXStates.Samplers.UVWrap_MinMagMipLinear); shader.Begin(context); shader.CBPerFrame.Values.DiffuseLightDirection = new Vector3(-0.8f, -0.9f, 1.5f) * -1; shader.CBPerFrame.Values.View = Matrix.Transpose(view); shader.CBPerFrame.Values.Projection = Matrix.Transpose(projection); shader.CBPerFrame.IsDirty = true; if (profile.YBlockOffset > 0) { WorldScale = Matrix.Scaling(1, (float)(1.0f - profile.YBlockOffset), 1); } else { WorldScale = Matrix.Identity; } shader.CBPerDraw.Values.World = Matrix.Transpose(WorldScale * Matrix.RotationY(MathHelper.PiOver4) * Matrix.RotationX(-MathHelper.Pi / 5)); shader.CBPerDraw.IsDirty = true; shader.DiffuseTexture.Value = cubesTexture; shader.Apply(context); //Set the buffer to the device vb.SetToDevice(context, 0); ib.SetToDevice(context, 0); //Draw things here. context.DrawIndexed(ib.IndicesCount, 0, 0); //Draw a sprite for lighting block if (profile.IsEmissiveColorLightSource) { spriteRenderer.Begin(true, context); ByteColor color = new ByteColor(profile.EmissiveColor.R, profile.EmissiveColor.G, profile.EmissiveColor.B, (byte)127); spriteRenderer.Draw(spriteTexture, ref spriteTexture.ScreenPosition, ref color); spriteRenderer.EndWithCustomProjection(context, ref texture.Projection2D); } //End Drawing texture.End(context, false); var tex2d = texture.CloneTexture(context, ResourceUsage.Default); //Create Shadow around Icon object displayed if (!profile.IsEmissiveColorLightSource) { tex2d = DrawOuterShadow(context, texture, tex2d); } createdIconsTexture.Add(tex2d); _cubeIconIndexes.Add(profile.Id, (byte)(createdIconsTexture.Count - 1)); } //Reset device Default render target _d3DEngine.SetRenderTargetsAndViewPort(context); //Dispose temp resource. spriteTexture.Dispose(); shader.Dispose(); vb.Dispose(); ib.Dispose(); spriteRenderer.Dispose(); return(createdIconsTexture); }