void ForeachConnectedNode(AbstractMaterialNode node, PropagationDirection dir, Action <AbstractMaterialNode> action) { using (var tempEdges = PooledList <IEdge> .Get()) using (var tempSlots = PooledList <MaterialSlot> .Get()) { // Loop through all nodes that the node feeds into. if (dir == PropagationDirection.Downstream) { node.GetOutputSlots(tempSlots); } else { node.GetInputSlots(tempSlots); } foreach (var slot in tempSlots) { // get the edges out of each slot tempEdges.Clear(); // and here we serialize another list, ouch! m_Graph.GetEdges(slot.slotReference, tempEdges); foreach (var edge in tempEdges) { // We look at each node we feed into. var connectedSlot = (dir == PropagationDirection.Downstream) ? edge.inputSlot : edge.outputSlot; var connectedNode = connectedSlot.node; action(connectedNode); } } } }
void CollectPreviewProperties(PooledList <PreviewProperty> perMaterialPreviewProperties) { using (CollectPreviewPropertiesMarker.Auto()) using (var tempCollectNodes = PooledHashSet <AbstractMaterialNode> .Get()) using (var tempPreviewProps = PooledList <PreviewProperty> .Get()) { // we only collect properties from nodes upstream of something we want to draw // TODO: we could go a step farther and only collect properties from nodes we know have changed their value // but that's not something we currently track... PropagateNodes(m_NodesToDraw, PropagationDirection.Upstream, tempCollectNodes); foreach (var propNode in tempCollectNodes) { propNode.CollectPreviewMaterialProperties(tempPreviewProps); } foreach (var prop in m_Graph.properties) { tempPreviewProps.Add(prop.GetPreviewMaterialProperty()); } foreach (var previewProperty in tempPreviewProps) { previewProperty.SetValueOnMaterialPropertyBlock(m_SharedPreviewPropertyBlock); // virtual texture assignments must be pushed to the materials themselves (MaterialPropertyBlocks not supported) if ((previewProperty.propType == PropertyType.VirtualTexture) && (previewProperty.vtProperty?.value?.layers != null)) { perMaterialPreviewProperties.Add(previewProperty); } } } }
private readonly unsafe PooledList <Move> LoadNonCaptures() { var result = PooledList <Move> .Get(32); for (Bitboard ss = _bbs.Occupies[(int)_activeSide]; !ss.IsZero; ss = ss.ClearNext()) { var source = ss.NextLocation(); var piece = _board[source].Piece; for (Bitboard ds = GetNonCaptureDestinations(source); !ds.IsZero; ds = ds.ClearNext()) { var destination = ds.NextLocation(); bool isPromotion = (piece.Kind == PieceKind.Pawn && source.Rank == SeventhRank(_activeSide)); if (isPromotion) { result.Add(new Move(source, destination, promotionKind: PieceKind.Queen)); result.Add(new Move(source, destination, promotionKind: PieceKind.Knight)); result.Add(new Move(source, destination, promotionKind: PieceKind.Rook)); result.Add(new Move(source, destination, promotionKind: PieceKind.Bishop)); } else { result.Add(new Move(source, destination)); } } } return(result); }
void CollectPreviewProperties() { using (CollectPreviewPropertiesMarker.Auto()) using (var tempCollectNodes = PooledHashSet <AbstractMaterialNode> .Get()) using (var tempPreviewProps = PooledList <PreviewProperty> .Get()) { // we only collect properties from nodes upstream of something we want to draw // TODO: we could go a step farther and only collect properties from nodes we know have changed their value // but that's not something we currently track... PropagateNodes(m_NodesToDraw, PropagationDirection.Upstream, tempCollectNodes); foreach (var propNode in tempCollectNodes) { propNode.CollectPreviewMaterialProperties(tempPreviewProps); } foreach (var prop in m_Graph.properties) { tempPreviewProps.Add(prop.GetPreviewMaterialProperty()); } foreach (var previewProperty in tempPreviewProps) { previewProperty.SetValueOnMaterialPropertyBlock(m_SharedPreviewPropertyBlock); } } }
public void Add_ExceedsCapacity_ResizesProperly() { using var list = PooledList <int> .Get(16); for (int i = 0; i < 100; i++) { list.Add(i); } Assert.Equal(100, list.Count); for (int i = 0; i < 100; i++) { Assert.Equal(i, list[i]); } }
public bool RequiresMeshUV(UVChannel channel, ShaderStageCapability stageCapability) { if (Dimension != NoiseDimension.D2) { return(false); } using (var tempSlots = PooledList <MaterialSlot> .Get()) { GetInputSlots(tempSlots); foreach (var slot in tempSlots) { if (slot.RequiresMeshUV(channel)) { return(true); } } return(false); } }
public void RenderPreviews(bool requestShaders = true) { using (RenderPreviewsMarker.Auto()) using (var renderList2D = PooledList <PreviewRenderData> .Get()) using (var renderList3D = PooledList <PreviewRenderData> .Get()) using (var perMaterialPreviewProperties = PooledList <PreviewProperty> .Get()) { if (requestShaders) { UpdateShaders(); } UpdateTimedNodeList(); PropagateNodes(m_NodesToDraw, PropagationDirection.Downstream, m_NodesToDraw); m_NodesToDraw.UnionWith(m_TimedNodes); if (m_NodesToDraw.Count <= 0) { return; } CollectPreviewProperties(perMaterialPreviewProperties); // setup other global properties var time = Time.realtimeSinceStartup; var timeParameters = new Vector4(time, Mathf.Sin(time), Mathf.Cos(time), 0.0f); m_SharedPreviewPropertyBlock.SetVector("_TimeParameters", timeParameters); using (PrepareNodesMarker.Auto()) { foreach (var node in m_NodesToDraw) { if (node == null || !node.hasPreview || !node.previewExpanded) { continue; } var renderData = GetPreviewRenderData(node); if (renderData == null) // non-active output nodes can have NULL render data (no preview) { continue; } if ((renderData.shaderData.shader == null) || (renderData.shaderData.mat == null)) { // avoid calling NotifyPreviewChanged repeatedly if (renderData.texture != null) { renderData.texture = null; renderData.NotifyPreviewChanged(); } continue; } if (renderData.shaderData.hasError) { renderData.texture = m_ErrorTexture; renderData.NotifyPreviewChanged(); continue; } if (renderData.previewMode == PreviewMode.Preview2D) { renderList2D.Add(renderData); } else { renderList3D.Add(renderData); } } } EditorUtility.SetCameraAnimateMaterialsTime(m_SceneResources.camera, time); m_SceneResources.light0.enabled = true; m_SceneResources.light0.intensity = 1.0f; m_SceneResources.light0.transform.rotation = Quaternion.Euler(50f, 50f, 0); m_SceneResources.light1.enabled = true; m_SceneResources.light1.intensity = 1.0f; m_SceneResources.camera.clearFlags = CameraClearFlags.Color; // Render 2D previews m_SceneResources.camera.transform.position = -Vector3.forward * 2; m_SceneResources.camera.transform.rotation = Quaternion.identity; m_SceneResources.camera.orthographicSize = 0.5f; m_SceneResources.camera.orthographic = true; foreach (var renderData in renderList2D) { RenderPreview(renderData, m_SceneResources.quad, Matrix4x4.identity, perMaterialPreviewProperties); } // Render 3D previews m_SceneResources.camera.transform.position = -Vector3.forward * 5; m_SceneResources.camera.transform.rotation = Quaternion.identity; m_SceneResources.camera.orthographic = false; foreach (var renderData in renderList3D) { RenderPreview(renderData, m_SceneResources.sphere, Matrix4x4.identity, perMaterialPreviewProperties); } var renderMasterPreview = masterRenderData != null && m_NodesToDraw.Contains(masterRenderData.shaderData.node); if (renderMasterPreview && masterRenderData.shaderData.mat != null) { if (m_NewMasterPreviewSize.HasValue) { if (masterRenderData.renderTexture != null) { Object.DestroyImmediate(masterRenderData.renderTexture, true); } masterRenderData.renderTexture = new RenderTexture((int)m_NewMasterPreviewSize.Value.x, (int)m_NewMasterPreviewSize.Value.y, 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default) { hideFlags = HideFlags.HideAndDontSave }; masterRenderData.renderTexture.Create(); masterRenderData.texture = masterRenderData.renderTexture; m_NewMasterPreviewSize = null; } var mesh = m_Graph.previewData.serializedMesh.mesh ? m_Graph.previewData.serializedMesh.mesh : m_SceneResources.sphere; var previewTransform = Matrix4x4.Rotate(m_Graph.previewData.rotation); var scale = m_Graph.previewData.scale; previewTransform *= Matrix4x4.Scale(scale * Vector3.one * (Vector3.one).magnitude / mesh.bounds.size.magnitude); previewTransform *= Matrix4x4.Translate(-mesh.bounds.center); RenderPreview(masterRenderData, mesh, previewTransform, perMaterialPreviewProperties); } m_SceneResources.light0.enabled = false; m_SceneResources.light1.enabled = false; foreach (var renderData in renderList2D) { renderData.NotifyPreviewChanged(); } foreach (var renderData in renderList3D) { renderData.NotifyPreviewChanged(); } if (renderMasterPreview) { masterRenderData.NotifyPreviewChanged(); } m_NodesToDraw.Clear(); } }
private readonly unsafe PooledList <Move> LoadCaptures() { var opposingSide = _activeSide.Flip(); Bitboard occupied = _bbs.Occupies[0] | _bbs.Occupies[1]; var result = PooledList <Move> .Get(16); // Loop over all pieces that can be captured, from most to least valuable for (var victimKind = PieceKind.Queen; victimKind >= PieceKind.Pawn; victimKind--) { var victim = new Piece(opposingSide, victimKind); for (Bitboard ds = _bbs.PiecePlacement[victim.ToIndex()]; !ds.IsZero; ds = ds.ClearNext()) { var destination = ds.NextLocation(); Debug.Assert(_board[destination].HasPiece && _board[destination].Piece == victim); // Loop over all pieces that can capture at `destination`, from least to most valuable Bitboard activeAttacks = _bbs.Attacks[(int)_activeSide]; if (activeAttacks[destination]) { for (var aggKind = PieceKind.Pawn; aggKind <= PieceKind.King; aggKind++) { var agg = new Piece(_activeSide, aggKind); for (Bitboard ss = _bbs.PiecePlacement[agg.ToIndex()]; !ss.IsZero; ss = ss.ClearNext()) { var source = ss.NextLocation(); Debug.Assert(_board[source].HasPiece && _board[source].Piece == agg); var sourceAttacks = GetAttackBitboard(_board[source].Piece, source, occupied); if (sourceAttacks[destination]) { bool isPromotion = (aggKind == PieceKind.Pawn && source.Rank == SeventhRank(_activeSide)); if (isPromotion) { result.Add(new Move(source, destination, promotionKind: PieceKind.Queen)); result.Add(new Move(source, destination, promotionKind: PieceKind.Knight)); result.Add(new Move(source, destination, promotionKind: PieceKind.Rook)); result.Add(new Move(source, destination, promotionKind: PieceKind.Bishop)); } else { result.Add(new Move(source, destination)); } } } } } // En passant captures need to be handled specially if (_enPassantTarget is Location epTarget) { bool canBeCapturedEp = (destination == epTarget.Up(ForwardStep(opposingSide))); if (canBeCapturedEp) { Debug.Assert(victimKind == PieceKind.Pawn); Bitboard pawnPlacement = _bbs.PiecePlacement[new Piece(_activeSide, PieceKind.Pawn).ToIndex()]; if (destination.File > File.FileA && pawnPlacement[destination.Left(1)]) { result.Add(new Move(destination.Left(1), epTarget)); } if (destination.File < File.FileH && pawnPlacement[destination.Right(1)]) { result.Add(new Move(destination.Right(1), epTarget)); } } } } } return(result); }