Mercurial > touhou
comparison pytouhou/resource/loader.py @ 504:69c73023f7a0
Make ANM garbage collectable.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 23 Oct 2013 18:24:17 +0200 |
parents | c9433188ffdb |
children | 6b76c9ba3975 |
comparison
equal
deleted
inserted
replaced
503:c622eaf64428 | 504:69c73023f7a0 |
---|---|
99 class Loader(object): | 99 class Loader(object): |
100 def __init__(self, game_dir=None): | 100 def __init__(self, game_dir=None): |
101 self.exe_files = [] | 101 self.exe_files = [] |
102 self.game_dir = game_dir | 102 self.game_dir = game_dir |
103 self.known_files = {} | 103 self.known_files = {} |
104 self.instanced_anms = {} #TODO: remove it someday. | 104 self.instanced_anms = {} # Cache for the textures. |
105 self.loaded_anms = [] # For the double loading warnings. | |
105 | 106 |
106 | 107 |
107 def scan_archives(self, paths_lists): | 108 def scan_archives(self, paths_lists): |
108 for paths in paths_lists: | 109 for paths in paths_lists: |
109 def _expand_paths(): | 110 def _expand_paths(): |
134 content = archive.extract(name) | 135 content = archive.extract(name) |
135 return BytesIO(content) | 136 return BytesIO(content) |
136 | 137 |
137 | 138 |
138 def get_anm(self, name): | 139 def get_anm(self, name): |
139 if name not in self.instanced_anms: | 140 if name in self.loaded_anms: |
140 file = self.get_file(name) | 141 logger.warn('ANM0 %s already loaded', name) |
141 self.instanced_anms[name] = ANM0.read(file) | 142 file = self.get_file(name) |
142 return self.instanced_anms[name] | 143 anm = ANM0.read(file) |
144 self.instanced_anms[name] = anm | |
145 self.loaded_anms.append(name) | |
146 return anm | |
143 | 147 |
144 | 148 |
145 def get_stage(self, name): | 149 def get_stage(self, name): |
146 file = self.get_file(name) | 150 file = self.get_file(name) |
147 return Stage.read(file) #TODO: modular | 151 return Stage.read(file) #TODO: modular |