Browse Source

Optimize `find_key` by using a hash map

pull/109/head
Adam Johnson 6 years ago
parent
commit
9601d6e28b
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 15
      korman/exporter/manager.py

15
korman/exporter/manager.py

@ -51,6 +51,7 @@ class ExportManager:
self._nodes = {} self._nodes = {}
self._pages = {} self._pages = {}
self._keys = {}
# cheap inheritance # cheap inheritance
for i in dir(self.mgr): for i in dir(self.mgr):
@ -63,6 +64,12 @@ class ExportManager:
self._age_info = info self._age_info = info
self.mgr.AddAge(info) self.mgr.AddAge(info)
def AddObject(self, location, obj):
"""Overloads the plResManager AddObject so we can insert the object into our hashtable"""
key = obj.key
self._keys[(location, obj.__class__, key.name)] = key
self.mgr.AddObject(location, obj)
def add_object(self, pl, name=None, bl=None, loc=None, so=None): def add_object(self, pl, name=None, bl=None, loc=None, so=None):
"""Automates adding a converted Blender object to our Plasma Resource Manager""" """Automates adding a converted Blender object to our Plasma Resource Manager"""
assert (bl or loc or so) assert (bl or loc or so)
@ -85,7 +92,7 @@ class ExportManager:
name = so.key.name name = so.key.name
pl = pl(name) pl = pl(name)
self.mgr.AddObject(location, pl) self.AddObject(location, pl)
node = self._nodes[location] node = self._nodes[location]
if node: # All objects must be in the scene node if node: # All objects must be in the scene node
if isinstance(pl, plSceneObject): if isinstance(pl, plSceneObject):
@ -191,11 +198,7 @@ class ExportManager:
else: else:
name = so.key.name name = so.key.name
index = plFactory.ClassIndex(pClass.__name__) return self._keys.get((location, pClass, name), None)
for key in self.mgr.getKeys(location, index):
if name == key.name:
return key
return None
def find_create_object(self, pClass, bl=None, name=None, so=None): def find_create_object(self, pClass, bl=None, name=None, so=None):
key = self.find_key(pClass, bl, name, so) key = self.find_key(pClass, bl, name, so)

Loading…
Cancel
Save