class MeshManager(ResourceManager): """MeshManager Event: Mesh Loaded(filename) """ def __init__(self, **argd): ResourceManager.__init__(self, **argd) self.autoRemove(self.window.bind("Clear Mesh", self.clear)) def LoadResource(self, *key): if not key or not key[0]: raise ValueError, "filename is a zero string" mesh = self.window.render.CMesh() assert mesh fp, fn = os.path.split(key[0]) fp += r'/' succ = mesh.Load(unicode(fp), unicode(fn)) if not succ: raise Exception self.window.render.RefreshTextures() return mesh def GetMesh(self, filename): return ResourceManager.GetResource(self, filename) ############################################################################################### koan.optimize(MeshManager)
############################################################################################### class EffectManager(ResourceManager): """EffectManager Event: Effect Loaded(filename) """ def __init__(self, **argd): ResourceManager.__init__(self, **argd) self.autoRemove(self.window.bind("Clear Effect", self.clear)) def LoadResource(self, *key): if not key or not key[0]: raise ValueError, "filename is a zero string" effect = self.window.render.CEffect(self.window.render) assert effect succ = effect.CreateFromFile(unicode(key[0])) if not succ: raise Exception return effect def GetEffect(self, filename): return ResourceManager.GetResource(self, filename) ############################################################################################### koan.optimize(EffectManager)
idx = bisect.bisect(self.period, prec) - 1 dlen = self.period[idx + 1] - self.period[idx] dcur = prec - self.period[idx] if not dlen == 0: newPrec = float(dcur) / float(dlen) else: newPrec = 1 v0 = self.value[idx] v1 = self.value[idx + 1] return v0 + float(v1 - v0) * newPrec koan.optimize(Linear.map) class Log: """ Log Interpolator Value """ e_1 = math.e - 1.0 def __init__(self, e, fromValue, toValue): self.fromValue = fromValue self.toValue = toValue self.e = e def print_debug(self): print self.fromValue, self.toValue def map(self, prec):
def GetAnimatedTexture(self, *key): if self.resMap.has_key(key): txt = self.resMap[key][0] else: try: txt = self.LoadAnimatedTexture(*key) except: txt = None self.resMap[key] = txt, koan.GetTime(), self.window.frameNumber return txt def clear(self, *key): self.window.dirty = True if len(key) == 3 and key[1] == 0 and key[2] == 0: for i in self.resMap.keys(): if i[0] == key[0]: self.resMap[i] = None del self.resMap[i] else: for i in self.resMap.keys(): if i[0] == key[0]: self.resMap[i] = None del self.resMap[i] ############################################################################################### koan.optimize(StringTextureManager) koan.optimize(ImageTextureManager)
import koan from resourcemgr import ResourceManager ############################################################################################### class EffectManager(ResourceManager): """EffectManager Event: Effect Loaded(filename) """ def __init__(self, **argd): ResourceManager.__init__(self, **argd) self.autoRemove(self.window.bind("Clear Effect", self.clear)) def LoadResource(self, *key): if not key or not key[0]: raise ValueError, "filename is a zero string" effect = self.window.render.CEffect(self.window.render) assert effect succ = effect.CreateFromFile(unicode(key[0])) if not succ: raise Exception return effect def GetEffect(self,filename): return ResourceManager.GetResource(self, filename) ############################################################################################### koan.optimize(EffectManager)