liveIconRendererQueue.py (3028B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\cosmetics\client\liveIconRendererQueue.py 2 from __future__ import absolute_import 3 import uthread2 4 import os 5 import blue 6 import trinity 7 from cosmetics.client.iconGenerator import IconGenerator 8 from evegraphics.settings import DEVICE_HIGH_END, DEVICE_MID_RANGE, DEVICE_LOW_END 9 from evegraphics.settings import GetDeviceClassification 10 from logging import getLogger 11 from .liveIconCacheUtils import create_cache_directory 12 log = getLogger(__name__) 13 _DEVICE_SETTING_DELAY_MAPPING = {DEVICE_HIGH_END: 60, 14 DEVICE_MID_RANGE: 110, 15 DEVICE_LOW_END: 160} 16 17 class LiveIconRenderQueue(object): 18 __instance__ = None 19 __notifyevents__ = ['OnGraphicSettingsChanged'] 20 21 @staticmethod 22 def get_instance(): 23 if LiveIconRenderQueue.__instance__ is None: 24 LiveIconRenderQueue.__instance__ = LiveIconRenderQueue() 25 return LiveIconRenderQueue.__instance__ 26 27 @staticmethod 28 def get_artificial_delay(): 29 classification = GetDeviceClassification() 30 delay = _DEVICE_SETTING_DELAY_MAPPING.get(classification, None) 31 return delay or 100 32 33 def __init__(self): 34 self.queue = [] 35 self.queue_thread = None 36 self._icon_generator = None 37 self.skin_design = None 38 sm.RegisterNotify(self) 39 create_cache_directory() 40 41 def OnGraphicSettingsChanged(self, *args): 42 self._icon_generator = None 43 44 def add_to_queue(self, function): 45 log.info('LIVE ICONS - Add to queue') 46 self.queue.insert(0, function) 47 if not self.queue_thread: 48 log.info('LIVE ICONS - Start queue') 49 self.queue_thread = uthread2.start_tasklet(self.render_queue_thread) 50 51 def remove_from_queue(self, function): 52 log.info('LIVE ICONS - Remove from queue') 53 if function in self.queue: 54 self.queue.remove(function) 55 56 def render_queue_thread(self): 57 artificial_delay = self.get_artificial_delay() 58 try: 59 while len(self.queue) > 0: 60 current_action = self.queue.pop() 61 if callable(current_action): 62 current_action() 63 blue.synchro.Sleep(artificial_delay) 64 65 finally: 66 self.queue = [] 67 self.queue_thread = None 68 69 def get_icon_generator(self, width, height, skin_design, bg_texture_path): 70 if not self._icon_generator: 71 self._icon_generator = self._construct_icon_generator(width, height, skin_design, bg_texture_path) 72 return self._icon_generator 73 74 def _construct_icon_generator(self, width, height, skin_design, bg_texture_path): 75 log.info('LIVE ICONS - Construct icon generator of {width}x{height}'.format(width=width, height=height)) 76 ss = 1 77 if trinity.GetShaderModel() == 'SM_3_0_DEPTH': 78 ss = 2 79 w = width * ss 80 h = height * ss 81 return IconGenerator(width=w, height=h, skin_design=skin_design, bg_texture_path=bg_texture_path)