Browse Source

Fix poor draw performance resulting from +Node.

pull/161/head v0.09
Adam Johnson 5 years ago
parent
commit
f67f2da822
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 28
      korman/nodes/node_core.py
  2. 2
      korman/nodes/node_python.py

28
korman/nodes/node_core.py

@ -15,7 +15,9 @@
import abc import abc
import bpy import bpy
from bpy.props import *
from PyHSPlasma import * from PyHSPlasma import *
import time
from ..exporter import ExportError from ..exporter import ExportError
@ -418,7 +420,7 @@ class PlasmaNodeSocketBase:
def draw_add_operator(self, context, layout, node): def draw_add_operator(self, context, layout, node):
row = layout.row() row = layout.row()
row.enabled = any(node.generate_valid_links_for(context, self, self.is_output)) row.enabled = self.has_possible_links
row.operator_context = "INVOKE_DEFAULT" row.operator_context = "INVOKE_DEFAULT"
add_op = row.operator("node.plasma_create_link_node", text="", icon="ZOOMIN") add_op = row.operator("node.plasma_create_link_node", text="", icon="ZOOMIN")
add_op.node_name = node.name add_op.node_name = node.name
@ -434,10 +436,34 @@ class PlasmaNodeSocketBase:
def draw_content(self, context, layout, node, text): def draw_content(self, context, layout, node, text):
layout.label(text) layout.label(text)
def _has_possible_links(self):
tval = time.monotonic()
if (tval - self.possible_links_update_time) > 2:
# Danger: hax!
# We don't want to unleash errbody at exactly the same time. The good news is that
# ***CURRENTLY*** the only way for the result to change is for a new PY file to be
# loaded. So, only check in that case.
hval = str(hash((i for i in bpy.data.texts)))
if hval != self.possible_links_texts_hash:
self.has_possible_links_value = any(self.node.generate_valid_links_for(bpy.context,
self,
self.is_output))
self.possible_links_texts_hash = hval
self.possible_links_update_time = tval
return self.has_possible_links_value
@property @property
def is_used(self): def is_used(self):
return bool(self.links) return bool(self.links)
@classmethod
def register(cls):
cls.has_possible_links = BoolProperty(options={"HIDDEN", "SKIP_SAVE"},
get=cls._has_possible_links)
cls.has_possible_links_value = BoolProperty(options={"HIDDEN", "SKIP_SAVE"})
cls.possible_links_update_time = FloatProperty(options={"HIDDEN", "SKIP_SAVE"})
cls.possible_links_texts_hash = StringProperty(options={"HIDDEN", "SKIP_SAVE"})
class PlasmaNodeSocketInputGeneral(PlasmaNodeSocketBase, bpy.types.NodeSocket): class PlasmaNodeSocketInputGeneral(PlasmaNodeSocketBase, bpy.types.NodeSocket):
"""A general input socket that will steal the output's color""" """A general input socket that will steal the output's color"""

2
korman/nodes/node_python.py

@ -338,10 +338,8 @@ class PlasmaPythonFileNode(PlasmaVersionedNode, bpy.types.Node):
valid_link_nodes = socket_def.get("valid_link_nodes") valid_link_nodes = socket_def.get("valid_link_nodes")
valid_link_sockets = socket_def.get("valid_link_sockets") valid_link_sockets = socket_def.get("valid_link_sockets")
if valid_link_nodes is not None and self.bl_idname not in valid_link_nodes: if valid_link_nodes is not None and self.bl_idname not in valid_link_nodes:
print(socket_name, self.bl_idname, valid_link_nodes)
continue continue
if valid_link_sockets is not None and "PlasmaPythonFileNodeSocket" not in valid_link_sockets: if valid_link_sockets is not None and "PlasmaPythonFileNodeSocket" not in valid_link_sockets:
print(socket_name, "PlasmaPythonFileNodeSocket", valid_link_sockets)
continue continue
yield { "node_idname": i.bl_idname, yield { "node_idname": i.bl_idname,

Loading…
Cancel
Save