public MyDecalsForVoxelsTriangleBuffer GetTrianglesBuffer(MyRenderVoxelCell voxelMap, MyDecalTexturesEnum decalTexture) { MyDecalsForVoxelsDictionaryKey key = new MyDecalsForVoxelsDictionaryKey(voxelMap.ID, decalTexture); MyDecalsForVoxelsTriangleBuffer outValue; if (m_triangleBuffersByKey.TryGetValue(key, out outValue) == true) { // Combination of cell/texture was found in dictionary, so we can return in right now return(outValue); } else { if (m_triangleBuffersByKey.Count >= m_capacity) { // We are full, can't place decal on a new cell/texture. Need to wait for next CheckBufferFull. return(null); } else { // This is first time we want to place decal to this cell/texture, so here we allocate and initialize buffer MyDecalsForVoxelsTriangleBuffer newBuffer = m_freeTriangleBuffers.Pop(); m_triangleBuffersByKey.Add(key, newBuffer); m_usedTriangleBuffers.Enqueue(newBuffer); newBuffer.Start(voxelMap, decalTexture); return(newBuffer); } } }
// We can't just erase decal triangles. We need to push them back into 'free triangles stack'. So we do it here. public void Clear(bool destroy = false) { while (m_trianglesQueue.Count > 0) { MyDecalTriangle fadedoutTriangle = m_trianglesQueue.Dequeue(); fadedoutTriangle.Close(); m_freeTriangles.Push(fadedoutTriangle); } if (destroy) { VoxelCell = null; } }
// Because this class is reused in buffers, it isn't really initialized by constructor. We make real initialization here. public void Start(MyRenderVoxelCell voxelMap, MyDecalTexturesEnum decalTexture) { VoxelCell = voxelMap; DecalTexture = decalTexture; m_status = MyDecalsBufferState.READY; m_fadingOutStartTime = 0; /* if (MyDecals.IsLargeTexture(decalTexture) == true) { m_capacityAfterStart = MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER_LARGE; m_fadingOutStartLimit = (int)(m_capacityAfterStart * MyDecalsConstants.TEXTURE_LARGE_FADING_OUT_START_LIMIT_PERCENT); m_fadingOutMinimalTriangleCount = (int)(m_capacityAfterStart * MyDecalsConstants.TEXTURE_LARGE_FADING_OUT_MINIMAL_TRIANGLE_COUNT_PERCENT); MaxNeighbourTriangles = MyDecalsConstants.TEXTURE_LARGE_MAX_NEIGHBOUR_TRIANGLES; } else*/ { m_capacityAfterStart = MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER_SMALL; m_fadingOutStartLimit = (int)(m_capacityAfterStart * MyDecalsConstants.TEXTURE_SMALL_FADING_OUT_START_LIMIT_PERCENT); m_fadingOutMinimalTriangleCount = (int)(m_capacityAfterStart * MyDecalsConstants.TEXTURE_SMALL_FADING_OUT_MINIMAL_TRIANGLE_COUNT_PERCENT); MaxNeighbourTriangles = MyDecalsConstants.TEXTURE_SMALL_MAX_NEIGHBOUR_TRIANGLES; } }
// Because this class is reused in buffers, it isn't really initialized by constructor. We make real initialization here. public void Start(MyRenderVoxelCell voxelMap, MyDecalTexturesEnum decalTexture) { VoxelCell = voxelMap; DecalTexture = decalTexture; m_status = MyDecalsBufferState.READY; m_fadingOutStartTime = 0; /* * if (MyDecals.IsLargeTexture(decalTexture) == true) * { * m_capacityAfterStart = MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER_LARGE; * m_fadingOutStartLimit = (int)(m_capacityAfterStart * MyDecalsConstants.TEXTURE_LARGE_FADING_OUT_START_LIMIT_PERCENT); * m_fadingOutMinimalTriangleCount = (int)(m_capacityAfterStart * MyDecalsConstants.TEXTURE_LARGE_FADING_OUT_MINIMAL_TRIANGLE_COUNT_PERCENT); * MaxNeighbourTriangles = MyDecalsConstants.TEXTURE_LARGE_MAX_NEIGHBOUR_TRIANGLES; * } * else*/ { m_capacityAfterStart = MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER_SMALL; m_fadingOutStartLimit = (int)(m_capacityAfterStart * MyDecalsConstants.TEXTURE_SMALL_FADING_OUT_START_LIMIT_PERCENT); m_fadingOutMinimalTriangleCount = (int)(m_capacityAfterStart * MyDecalsConstants.TEXTURE_SMALL_FADING_OUT_MINIMAL_TRIANGLE_COUNT_PERCENT); MaxNeighbourTriangles = MyDecalsConstants.TEXTURE_SMALL_MAX_NEIGHBOUR_TRIANGLES; } }
// We can't just erase decal triangles. We need to push them back into 'free triangles stack'. So we do it here. public void Clear(bool destroy = false) { while (m_trianglesQueue.Count > 0) { MyDecalTriangle fadedoutTriangle = m_trianglesQueue.Dequeue(); fadedoutTriangle.Close(); m_freeTriangles.Push(fadedoutTriangle); } if (destroy) VoxelCell = null; }
// Blends-out triangles affected by explosion (radius + some safe delta). Triangles there have zero alpha are flaged to not-draw at all. public static void HideTrianglesAfterExplosion(MyRenderVoxelCell voxelCell, ref BoundingSphere explosionSphere) { MyRender.GetRenderProfiler().StartProfilingBlock("MyDecals::HideTrianglesAfterExplosion"); m_decalsForVoxels.HideTrianglesAfterExplosion(voxelCell.ID, ref explosionSphere); MyRender.GetRenderProfiler().EndProfilingBlock(); }