|
|
@@ -28,7 +28,7 @@ class Loader(DirectObject):
|
|
|
self.extraArgs = extraArgs
|
|
|
self.numRemaining = numObjects
|
|
|
self.cancelled = False
|
|
|
- self.requests = {}
|
|
|
+ self.requests = set()
|
|
|
|
|
|
def gotObject(self, index, object):
|
|
|
self.objects[index] = object
|
|
|
@@ -45,6 +45,8 @@ class Loader(DirectObject):
|
|
|
self.base = base
|
|
|
self.loader = PandaLoader.getGlobalPtr()
|
|
|
|
|
|
+ self.__requests = {}
|
|
|
+
|
|
|
self.hook = "async_loader_%s" % (Loader.loaderIndex)
|
|
|
Loader.loaderIndex += 1
|
|
|
self.accept(self.hook, self.__gotAsyncObject)
|
|
|
@@ -116,7 +118,7 @@ class Loader(DirectObject):
|
|
|
"""
|
|
|
|
|
|
assert Loader.notify.debug("Loading model: %s" % (modelPath))
|
|
|
- if loaderOptions == None:
|
|
|
+ if loaderOptions is None:
|
|
|
loaderOptions = LoaderOptions()
|
|
|
else:
|
|
|
loaderOptions = LoaderOptions(loaderOptions)
|
|
|
@@ -156,7 +158,7 @@ class Loader(DirectObject):
|
|
|
result = []
|
|
|
for modelPath in modelList:
|
|
|
node = self.loader.loadSync(Filename(modelPath), loaderOptions)
|
|
|
- if (node != None):
|
|
|
+ if node is not None:
|
|
|
nodePath = NodePath(node)
|
|
|
else:
|
|
|
nodePath = None
|
|
|
@@ -179,16 +181,16 @@ class Loader(DirectObject):
|
|
|
# callback (passing it the models on the parameter list).
|
|
|
|
|
|
cb = Loader.Callback(len(modelList), gotList, callback, extraArgs)
|
|
|
- i=0
|
|
|
+ i = 0
|
|
|
for modelPath in modelList:
|
|
|
request = self.loader.makeAsyncRequest(Filename(modelPath), loaderOptions)
|
|
|
if priority is not None:
|
|
|
request.setPriority(priority)
|
|
|
request.setDoneEvent(self.hook)
|
|
|
- request.setPythonObject((cb, i))
|
|
|
- i+=1
|
|
|
self.loader.loadAsync(request)
|
|
|
- cb.requests[request] = True
|
|
|
+ cb.requests.add(request)
|
|
|
+ self.__requests[request] = (cb, i)
|
|
|
+ i += 1
|
|
|
return cb
|
|
|
|
|
|
def cancelRequest(self, cb):
|
|
|
@@ -200,6 +202,7 @@ class Loader(DirectObject):
|
|
|
cb.cancelled = True
|
|
|
for request in cb.requests:
|
|
|
self.loader.remove(request)
|
|
|
+ del self.__requests[request]
|
|
|
cb.requests = None
|
|
|
|
|
|
def isRequestPending(self, cb):
|
|
|
@@ -273,7 +276,7 @@ class Loader(DirectObject):
|
|
|
# to resolve it for us.
|
|
|
options = LoaderOptions(LoaderOptions.LFSearch | LoaderOptions.LFNoDiskCache | LoaderOptions.LFCacheOnly)
|
|
|
modelNode = self.loader.loadSync(Filename(model), options)
|
|
|
- if modelNode == None:
|
|
|
+ if modelNode is None:
|
|
|
# Model not found.
|
|
|
assert Loader.notify.debug("Unloading model not loaded: %s" % (model))
|
|
|
return
|
|
|
@@ -293,7 +296,7 @@ class Loader(DirectObject):
|
|
|
a callback is used, the model is saved asynchronously, and the
|
|
|
true/false status is passed to the callback function. """
|
|
|
|
|
|
- if loaderOptions == None:
|
|
|
+ if loaderOptions is None:
|
|
|
loaderOptions = LoaderOptions()
|
|
|
else:
|
|
|
loaderOptions = LoaderOptions(loaderOptions)
|
|
|
@@ -342,16 +345,16 @@ class Loader(DirectObject):
|
|
|
# callback (passing it the models on the parameter list).
|
|
|
|
|
|
cb = Loader.Callback(len(modelList), gotList, callback, extraArgs)
|
|
|
- i=0
|
|
|
+ i = 0
|
|
|
for modelPath, node in modelList:
|
|
|
request = self.loader.makeAsyncSaveRequest(Filename(modelPath), loaderOptions, node)
|
|
|
if priority is not None:
|
|
|
request.setPriority(priority)
|
|
|
request.setDoneEvent(self.hook)
|
|
|
- request.setPythonObject((cb, i))
|
|
|
- i+=1
|
|
|
self.loader.saveAsync(request)
|
|
|
- cb.requests[request] = True
|
|
|
+ cb.requests.add(request)
|
|
|
+ self.__requests[request] = (cb, i)
|
|
|
+ i += 1
|
|
|
return cb
|
|
|
|
|
|
|
|
|
@@ -496,7 +499,7 @@ class Loader(DirectObject):
|
|
|
phaseChecker(modelPath, loaderOptions)
|
|
|
|
|
|
font = FontPool.loadFont(modelPath)
|
|
|
- if font == None:
|
|
|
+ if font is None:
|
|
|
if not okMissing:
|
|
|
message = 'Could not load font file: %s' % (modelPath)
|
|
|
raise IOError(message)
|
|
|
@@ -506,21 +509,21 @@ class Loader(DirectObject):
|
|
|
|
|
|
# The following properties may only be set for dynamic fonts.
|
|
|
if hasattr(font, "setPointSize"):
|
|
|
- if pointSize != None:
|
|
|
+ if pointSize is not None:
|
|
|
font.setPointSize(pointSize)
|
|
|
- if pixelsPerUnit != None:
|
|
|
+ if pixelsPerUnit is not None:
|
|
|
font.setPixelsPerUnit(pixelsPerUnit)
|
|
|
- if scaleFactor != None:
|
|
|
+ if scaleFactor is not None:
|
|
|
font.setScaleFactor(scaleFactor)
|
|
|
- if textureMargin != None:
|
|
|
+ if textureMargin is not None:
|
|
|
font.setTextureMargin(textureMargin)
|
|
|
- if polyMargin != None:
|
|
|
+ if polyMargin is not None:
|
|
|
font.setPolyMargin(polyMargin)
|
|
|
- if minFilter != None:
|
|
|
+ if minFilter is not None:
|
|
|
font.setMinfilter(minFilter)
|
|
|
- if magFilter != None:
|
|
|
+ if magFilter is not None:
|
|
|
font.setMagfilter(magFilter)
|
|
|
- if anisotropicDegree != None:
|
|
|
+ if anisotropicDegree is not None:
|
|
|
font.setAnisotropicDegree(anisotropicDegree)
|
|
|
if color:
|
|
|
font.setFg(color)
|
|
|
@@ -577,10 +580,10 @@ class Loader(DirectObject):
|
|
|
the texture and the number of expected mipmap images.
|
|
|
|
|
|
If minfilter or magfilter is not None, they should be a symbol
|
|
|
- like Texture.FTLinear or Texture.FTNearest. (minfilter may be
|
|
|
- further one of the Mipmap filter type symbols.) These specify
|
|
|
- the filter mode that will automatically be applied to the
|
|
|
- texture when it is loaded. Note that this setting may
|
|
|
+ like SamplerState.FTLinear or SamplerState.FTNearest. (minfilter
|
|
|
+ may be further one of the Mipmap filter type symbols.) These
|
|
|
+ specify the filter mode that will automatically be applied to
|
|
|
+ the texture when it is loaded. Note that this setting may
|
|
|
override the texture's existing settings, even if it has
|
|
|
already been loaded. See egg-texture-cards for a more robust
|
|
|
way to apply per-texture filter types and settings.
|
|
|
@@ -596,7 +599,7 @@ class Loader(DirectObject):
|
|
|
left image and '1' for the right image. Larger numbers are
|
|
|
also allowed if you need more than two views.
|
|
|
"""
|
|
|
- if loaderOptions == None:
|
|
|
+ if loaderOptions is None:
|
|
|
loaderOptions = LoaderOptions()
|
|
|
else:
|
|
|
loaderOptions = LoaderOptions(loaderOptions)
|
|
|
@@ -657,7 +660,7 @@ class Loader(DirectObject):
|
|
|
numbered 8 - 15 will be part of the right eye view.
|
|
|
"""
|
|
|
assert Loader.notify.debug("Loading 3-D texture: %s" % (texturePattern))
|
|
|
- if loaderOptions == None:
|
|
|
+ if loaderOptions is None:
|
|
|
loaderOptions = LoaderOptions()
|
|
|
else:
|
|
|
loaderOptions = LoaderOptions(loaderOptions)
|
|
|
@@ -711,7 +714,7 @@ class Loader(DirectObject):
|
|
|
and each six images will define a new view.
|
|
|
"""
|
|
|
assert Loader.notify.debug("Loading cube map: %s" % (texturePattern))
|
|
|
- if loaderOptions == None:
|
|
|
+ if loaderOptions is None:
|
|
|
loaderOptions = LoaderOptions()
|
|
|
else:
|
|
|
loaderOptions = LoaderOptions(loaderOptions)
|
|
|
@@ -821,13 +824,12 @@ class Loader(DirectObject):
|
|
|
# callback (passing it the sounds on the parameter list).
|
|
|
|
|
|
cb = Loader.Callback(len(soundList), gotList, callback, extraArgs)
|
|
|
- for i in range(len(soundList)):
|
|
|
- soundPath = soundList[i]
|
|
|
+ for i, soundPath in enumerate(soundList):
|
|
|
request = AudioLoadRequest(manager, soundPath, positional)
|
|
|
request.setDoneEvent(self.hook)
|
|
|
- request.setPythonObject((cb, i))
|
|
|
self.loader.loadAsync(request)
|
|
|
- cb.requests[request] = True
|
|
|
+ cb.requests.add(request)
|
|
|
+ self.__requests[request] = (cb, i)
|
|
|
return cb
|
|
|
|
|
|
def unloadSfx(self, sfx):
|
|
|
@@ -852,7 +854,7 @@ class Loader(DirectObject):
|
|
|
return shader
|
|
|
|
|
|
def unloadShader(self, shaderPath):
|
|
|
- if (shaderPath != None):
|
|
|
+ if shaderPath is not None:
|
|
|
ShaderPool.releaseShader(shaderPath)
|
|
|
|
|
|
def asyncFlattenStrong(self, model, inPlace = True,
|
|
|
@@ -886,14 +888,15 @@ class Loader(DirectObject):
|
|
|
gotList = True
|
|
|
|
|
|
cb = Loader.Callback(len(modelList), gotList, callback, extraArgs)
|
|
|
- i=0
|
|
|
+ i = 0
|
|
|
for model in modelList:
|
|
|
request = ModelFlattenRequest(model.node())
|
|
|
request.setDoneEvent(self.hook)
|
|
|
request.setPythonObject((cb, i))
|
|
|
- i+=1
|
|
|
self.loader.loadAsync(request)
|
|
|
cb.requests[request] = True
|
|
|
+ self.__requests[request] = (cb, i)
|
|
|
+ i += 1
|
|
|
return cb
|
|
|
|
|
|
def __asyncFlattenDone(self, models,
|
|
|
@@ -921,16 +924,23 @@ class Loader(DirectObject):
|
|
|
of loaded objects, and call the appropriate callback when it's
|
|
|
time."""
|
|
|
|
|
|
- cb, i = request.getPythonObject()
|
|
|
+ if request not in self.__requests:
|
|
|
+ return
|
|
|
+
|
|
|
+ cb, i = self.__requests[request]
|
|
|
if cb.cancelled:
|
|
|
+ # Shouldn't be here.
|
|
|
+ del self.__requests[request]
|
|
|
return
|
|
|
|
|
|
- del cb.requests[request]
|
|
|
+ cb.requests.discard(request)
|
|
|
+ if not cb.requests:
|
|
|
+ del self.__requests[request]
|
|
|
|
|
|
object = None
|
|
|
if hasattr(request, "getModel"):
|
|
|
node = request.getModel()
|
|
|
- if (node != None):
|
|
|
+ if node is not None:
|
|
|
object = NodePath(node)
|
|
|
|
|
|
elif hasattr(request, "getSound"):
|