From 4689f868210fef1f7615ca16bafdfa7f25dd74a3 Mon Sep 17 00:00:00 2001 From: Zachary Pavlov Date: Wed, 25 Oct 2006 22:36:44 +0000 Subject: [PATCH] fix for loader --- direct/src/showbase/Loader.py | 30 ++++++++++-------------------- direct/src/showbase/PythonUtil.py | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/direct/src/showbase/Loader.py b/direct/src/showbase/Loader.py index 94ca4b2c3d..227921abee 100644 --- a/direct/src/showbase/Loader.py +++ b/direct/src/showbase/Loader.py @@ -12,13 +12,14 @@ import types # phase phaseChecker = None + class Loader(DirectObject): """ Load models, textures, sounds, and code. """ notify = directNotify.newCategory("Loader") loaderIndex = 0 - + class Callback: def __init__(self, numObjects, callback, extraArgs): self.objects = [None] * numObjects @@ -110,12 +111,12 @@ class Loader(DirectObject): # Assume we were given a list of model pathnames. modelList = modelPath gotList = True - + if callback is None: # We got no callback, so it's a synchronous load. result = [] - for modelPath in modelList: + for modelPath in modelList: node = self.loader.loadSync(Filename(modelPath), loaderOptions) if (node != None): nodePath = NodePath(node) @@ -136,23 +137,11 @@ class Loader(DirectObject): # callback (passing it the models on the parameter list). cb = Loader.Callback(len(modelList), callback, extraArgs) - for i in range(len(modelList)): - modelPath = modelList[i] - if loaderOptions.getAllowRamCache() and ModelPool.hasModel(modelPath): - # If it's already in the model pool, we won't - # bother bouncing the load request through the - # thread; and maybe we can just make the callback - # immediately. - node = ModelPool.loadModel(modelPath) - nodePath = NodePath(node.copySubgraph()) - cb.gotObject(i, nodePath) - - else: - # We do need to go to the thread to load this model. - request = ModelLoadRequest(Filename(modelPath), loaderOptions) - request.setDoneEvent(self.hook) - request.setPythonObject((cb, i)) - self.loader.loadAsync(request) + for modelPath in modelList: + request = ModelLoadRequest(Filename(modelPath), loaderOptions) + request.setDoneEvent(self.hook) + request.setPythonObject((cb, i)) + self.loader.loadAsync(request) def loadModelOnce(self, modelPath): """ @@ -231,6 +220,7 @@ class Loader(DirectObject): assert Loader.notify.debug("Unloading model: %s" % (modelNode.getFullpath())) ModelPool.releaseModel(modelNode) + # font loading funcs def loadFont(self, modelPath, spaceAdvance = None, pointSize = None, diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index b7e9326fea..28b9f085aa 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/direct/src/showbase/PythonUtil.py @@ -36,13 +36,33 @@ import sys import random import time import new +import guppy if __debug__: import traceback + + from direct.directutil import Verify ScalarTypes = (types.FloatType, types.IntType, types.LongType) + +class MemoryChecker(object): + def getHeap(self): + if(not self.__dict__.get("hp",0)): + self.hp=guppy.hpy() + return self.hp + def getClassesByType(self,inType): + hp=self.getHeap() + objHeap=hp.heap() & inType + outArr=[] + for i in range(objHeap.byid.count): + outArr.append(objHeap.byid[i].theone) + return outArr + + + + def enumerate(L): """Returns (0, L[0]), (1, L[1]), etc., allowing this syntax: for i, item in enumerate(L):