1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 17:26:02 +08:00

Modify node culling to use node dimensions directly instead of (slowly) fetching NodeEditor first.

This commit is contained in:
-rava 2018-08-30 05:05:43 +03:00
parent 372c968c85
commit 2f4ef6f5c3
2 changed files with 9 additions and 10 deletions

View File

@ -319,12 +319,10 @@ namespace XNodeEditor {
if (n >= graph.nodes.Count) return; if (n >= graph.nodes.Count) return;
XNode.Node node = graph.nodes[n]; XNode.Node node = graph.nodes[n];
NodeEditor nodeEditor = NodeEditor.GetEditor(node);
// Culling // Culling
if (e.type == EventType.Layout) { if (e.type == EventType.Layout) {
// Cull unselected nodes outside view // Cull unselected nodes outside view
if (!Selection.Contains(node) && ShouldBeCulled(nodeEditor)) { if (!Selection.Contains(node) && ShouldBeCulled(node)) {
culledNodes.Add(node); culledNodes.Add(node);
continue; continue;
} }
@ -334,6 +332,8 @@ namespace XNodeEditor {
_portConnectionPoints = _portConnectionPoints.Where(x => x.Key.node != node).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); _portConnectionPoints = _portConnectionPoints.Where(x => x.Key.node != node).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
} }
NodeEditor nodeEditor = NodeEditor.GetEditor(node);
NodeEditor.portPositions = new Dictionary<XNode.NodePort, Vector2>(); NodeEditor.portPositions = new Dictionary<XNode.NodePort, Vector2>();
//Get node position //Get node position
@ -432,13 +432,13 @@ namespace XNodeEditor {
} }
} }
/// <summary> Returns true if outside window area </summary> private bool ShouldBeCulled(XNode.Node node) {
private bool ShouldBeCulled(XNodeEditor.NodeEditor nodeEditor) {
Vector2 nodePos = GridToWindowPositionNoClipped(nodeEditor.target.position); Vector2 nodePos = GridToWindowPositionNoClipped(node.position);
if (nodePos.x / _zoom > position.width) return true; // Right if (nodePos.x / _zoom > position.width) return true; // Right
else if (nodePos.y / _zoom > position.height) return true; // Bottom else if (nodePos.y / _zoom > position.height) return true; // Bottom
else if (nodeSizes.ContainsKey(nodeEditor.target)) { else if (nodeSizes.ContainsKey(node)) {
Vector2 size = nodeSizes[nodeEditor.target]; Vector2 size = nodeSizes[node];
if (nodePos.x + size.x < 0) return true; // Left if (nodePos.x + size.x < 0) return true; // Left
else if (nodePos.y + size.y < 0) return true; // Top else if (nodePos.y + size.y < 0) return true; // Top
} }

View File

@ -1,8 +1,7 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 756276bfe9a0c2f4da3930ba1964f58d guid: 756276bfe9a0c2f4da3930ba1964f58d
timeCreated: 1505420917
licenseType: Free
MonoImporter: MonoImporter:
externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0