Skip to content

Commit

Permalink
add user_dict for caching (#4501)
Browse files Browse the repository at this point in the history
* add user_dict for caching

* add description in docs

* doc syntax fix

* what line?
  • Loading branch information
zeffii committed May 31, 2022
1 parent d1eaad1 commit 42f3dfb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
9 changes: 9 additions & 0 deletions docs/nodes/script/script1_lite.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ Features
- You must declare an input socket, but outputs are optional.
- You can set defaults for input numbers, vectors, and list sockets.
- You can set the level of nestedness; means you don't need to unwrap/index stuff via code
- You can use a dictionary per node instance, this allows you to store any data that can be produced at runtime. Get a `dict` and store states using these functions ::

# here self refers to the node and will be available at runtime.
dict = self.get_user_dict()
self.reset_user_dict() # takes a boolean parameter "hard" to wipe the
... # dictionaries at the class-level (all instances)
... # hard=True is useful for debugging.


- You can append a UI drawing function to the default drawing function of SNLite, in case you want to display a variety of UI elements from anywhere in Blender in one place.
- has the option to **auto inject** the list of variable references as **parameters** much like javascript does for **arguments** inside a function. In essence implemented like this ::

Expand Down
18 changes: 15 additions & 3 deletions nodes/script/script1_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,24 @@ def make_operator(self, new_func_name, force=False):
script_name: StringProperty()
script_str: StringProperty()
node_dict = {}
user_dict = {}

halt_updates: BoolProperty(name="snlite halting token")

def get_user_dict(self):
if not self.user_dict.get(hash(self)):
self.user_dict[hash(self)] = {}
return self.user_dict[hash(self)]

def reset_user_dict(self, hard=False):
if hard:
# will reset all user_dicts in all instances of snlite.
# you probably don't want to do this, but for debugging it can be useful.
self.user_dict = {}

self.user_dict[hash(self)] = {}


def updateNode2(self, context):
if not self.halt_updates:
updateNode(self, context)
Expand Down Expand Up @@ -288,9 +303,6 @@ def update_sockets(self):

return True




def sv_init(self, context):
self.use_custom_color = False

Expand Down

0 comments on commit 42f3dfb

Please sign in to comment.