Shuvit game master repo. http://shuvit.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MaterialManager.py 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from weakref import WeakSet
  2. import bge
  3. __all__ = ['MaterialManager']
  4. class MaterialManager(object):
  5. Scenes = WeakSet()
  6. Registry = []
  7. def __init__(self):
  8. raise NotImplemented()
  9. @classmethod
  10. def RegisterEvents(cls):
  11. scenes = bge.logic.getSceneList()
  12. for scene in scenes:
  13. if scene not in cls.Scenes:
  14. scene.pre_draw_setup.append(cls.pre_draw_setup)
  15. scene.pre_draw.append(cls.pre_draw)
  16. scene.post_draw.append(cls.post_draw)
  17. cls.Scenes.add(scene)
  18. @classmethod
  19. def Register(cls, process):
  20. cls.Registry.append(process)
  21. return process
  22. @classmethod
  23. def RunDispatchers(cls, dispatch):
  24. for process in list(cls.Registry):
  25. if process.invalid:
  26. cls.Registry.remove(process)
  27. else:
  28. try: dispatch(process)
  29. except Exception as e:
  30. cls.Registry.remove(process)
  31. process.error(e)
  32. @classmethod
  33. def pre_draw_setup(cls):
  34. cls.RegisterEvents()
  35. cls.RunDispatchers(lambda process: process.pre_draw_setup_dispatch())
  36. @classmethod
  37. def pre_draw(cls):
  38. cls.RunDispatchers(lambda process: process.pre_draw_dispatch())
  39. @classmethod
  40. def post_draw(cls):
  41. cls.RunDispatchers(lambda process: process.post_draw_dispatch())