Skip to content

Commit 7af7776

Browse files
committed
Add per-channel caching to render()
1 parent dfd6182 commit 7af7776

File tree

1 file changed

+59
-14
lines changed

1 file changed

+59
-14
lines changed

fixture.py

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -941,14 +941,26 @@ def process_channels(self, dmx_mode_channels, channels):
941941

942942
# create a link from channel function to a mode_master channel:
943943
for dmx_channel in channels:
944+
modemasters_exist = False
944945
for ch_function in dmx_channel.channel_functions:
945946
if ch_function.mode_master != "":
946947
for ch in channels:
947-
# we might have to search in both dmx and virtual
948948
if ch.name_ == ch_function.mode_master:
949+
modemasters_exist = True
949950
ch_function.mm_dmx_break = ch.dmx_break
950951
ch_function.mm_offsets = ch.offsets
951952
ch_function.mm_offsets_bytes = ch.offsets_bytes
953+
if not modemasters_exist:
954+
# create some caching of dmx channel data
955+
# we ignore channels with mode dependencies
956+
# as checking for the cache and then finding that we need
957+
# to re-calculate the value anyways is probably more expensive
958+
dmx_channel["cached_channel"] = {
959+
"dmx_value": -1,
960+
"attribute": None,
961+
"value": -1,
962+
"index": -1,
963+
}
952964

953965
# Interface Methods #
954966

@@ -1282,20 +1294,53 @@ def render(self, skip_cache=False, current_frame=None):
12821294
dmx_value_fine = dmx_data[channel.dmx_break][channel.offsets[1]]
12831295
dmx_value_final = (dmx_value_coarse << 8) | dmx_value_fine
12841296

1285-
DMX_Log.log.debug(
1286-
(
1287-
"start function search",
1288-
channel.name_,
1289-
channel.offsets,
1290-
channel.offsets_bytes,
1297+
skip_attr_search = False
1298+
if "cached_channel" in channel:
1299+
cached_dmx = channel["cached_channel"].get("dmx_value")
1300+
cached_attr = channel["cached_channel"].get("attribute", None)
1301+
cached_value = channel["cached_channel"].get("value")
1302+
cached_slot = channel["cached_channel"].get("index")
1303+
1304+
if dmx_value_final == int(cached_dmx) and cached_attr is not None:
1305+
skip_attr_search = True
1306+
channel_function_attribute = cached_attr
1307+
channel_function_physical_value = cached_value
1308+
channel_set_wheel_slot = cached_slot
1309+
DMX_Log.log.debug(
1310+
(
1311+
"use cached data",
1312+
channel.name_,
1313+
channel_function_attribute,
1314+
channel_function_physical_value,
1315+
channel_set_wheel_slot,
1316+
)
1317+
)
1318+
1319+
if not skip_attr_search and self.use_fixtures_channel_functions:
1320+
DMX_Log.log.debug(
1321+
("search for fresh attribute data", channel.attribute)
12911322
)
1292-
)
1323+
DMX_Log.log.debug(
1324+
(
1325+
"start function search",
1326+
channel.name_,
1327+
channel.offsets,
1328+
channel.offsets_bytes,
1329+
)
1330+
)
1331+
1332+
(
1333+
channel_function_attribute,
1334+
channel_function_physical_value,
1335+
channel_set_wheel_slot,
1336+
) = channel.get_function_attribute_data(dmx_value_final, dmx_data)
12931337

1294-
(
1295-
channel_function_attribute,
1296-
channel_function_physical_value,
1297-
channel_set_wheel_slot,
1298-
) = channel.get_function_attribute_data(dmx_value_final, dmx_data)
1338+
if "cached_channel" in channel:
1339+
DMX_Log.log.debug(("set cached data", channel.attribute))
1340+
channel["cached_channel"]["dmx_value"] = dmx_value_final
1341+
channel["cached_channel"]["attribute"] = channel_function_attribute
1342+
channel["cached_channel"]["value"] = channel_function_physical_value
1343+
channel["cached_channel"]["index"] = channel_set_wheel_slot or -1
12991344

13001345
if not self.use_fixtures_channel_functions:
13011346
channel_function = dmx.get_default_channel_function_by_attribute(
@@ -2121,7 +2166,7 @@ def updateRotation(self, geometry=None, x=None, y=None, z=None, current_frame=No
21212166
)
21222167

21232168
def updatePanTiltViaTarget(self, pan, tilt, current_frame):
2124-
DMX_Log.log.info("Updating pan tilt")
2169+
DMX_Log.log.info(("Updating pan tilt", pan, tilt))
21252170

21262171
base = self.objects["Root"].object
21272172
pan = pan + base.rotation_euler[2] # take base z rotation into consideration

0 commit comments

Comments
 (0)