Lagless preloading

I can’t seem to figure this one out… I’m using the panda threading ability to over come some IO problems for my preloading, but for some reason I still get the huge lag that comes from loading my main big model… Is there any other way to maybe some how lower its pressure on my game? I tried using the threadPriority variable, but I’m a little lost on the whole “TP_low, TP_normal, TP_high, or TP_urgent” passing… it wants a int number so not really sure to pass a high 4 or a low 0, either way it didn’t seem to help when I did it… but then again I didn’t test the time just the human feel.

  ############################PreLoad Data#########################################
  def PreLoad(self):
    taskMgr.setupTaskChain('PreLoadThread', numThreads = 1)
    taskMgr.add(self.PreLoadData, "PreLoading", taskChain = 'PreLoadThread')
  
  def PreLoadData(self, task):
    print "Starting preload"
    if self2.LastLocation:
      LoadEnvironment().PreLoad(self2.LastLocation)
      Thread.considerYield()

    #SP effects
    for Item in ['Misc/Misc/Smoke/Smoke2/Smoke2.bam']:# 'Misc/Misc/Explosion/Explosion1/Explosion1.bam', 'Misc/Misc/Smoke/Smoke1/Smoke1.bam', ]:
      try:
        Smoke = loader.loadModel(''.join(map(str, ("MainMenu/Game/BlockWar/", Item))))
        Smoke.prepareScene(base.win.getGsg())
        Smoke.removeNode()
      except:
        print traceback.format_exception(*sys.exc_info())
      Thread.considerYield()

    #Sounds
    for Item in ['Knife/gunfire/Knife_HitConc1.ogg', 'Pistol/gunfire/pistol_fire.ogg', 'Mrifle/gunfire/rifle_fire_1.ogg', 'hunting_rifle/gunfire/hunting_rifle_fire_1.ogg',
                 'PulseRifle/gunfire/shockrifle_shoot.ogg', 'RocketLauncher/gunfire/rocket_launcher.ogg', 'MiniGun/gunfire/minigun_fire.ogg']:
      try:
        Sound = loader.loadSfx(''.join(map(str, ("MainMenu/Game/BlockWar/Music/Sounds/", Item))))
      except:
        print traceback.format_exception(*sys.exc_info())
      Thread.considerYield()

    #Models
    for Item in ["Scrolls/Scroll.bam"]:
      try:
        Model = loader.loadModel(''.join(map(str, ("MainMenu/Game/BlockWar/Misc/Items/", Item))))
        Model.prepareScene(base.win.getGsg())
        Model.removeNode()
      except:
        print traceback.format_exception(*sys.exc_info())
      Thread.considerYield()
    
    for Item in ["Knife/Knife.bam", "Mrifle/Mrifle.bam", "Pistol/Pistol.bam", "Sniper/Sniper.bam", "bullit.bam"]: # "MiniWeapon/MiniWeapon.bam", "BFG/BFG.bam", "PulseRifle/PulseRifle.bam", "RocketLauncher/RocketLauncher.bam", "ShotWeapon/ShotWeapon.bam"
      try:
        Weapon = loader.loadModel(''.join(map(str, ("MainMenu/Game/BlockWar/Misc/Items/Weapons/", Item))))
        Weapon.prepareScene(base.win.getGsg())
        Weapon.removeNode()
      except:
        print traceback.format_exception(*sys.exc_info())
      Thread.considerYield()


    print "Done preloading"

Take a look at this Manual page:
panda3d.org/manual/index.php/Threading

It explains how to load Models asynchronously (means in background).

Nice… Yea I saw, but I’m a little lost on what it means by the text. Why I made my own task chain I guess. I get this:

loader.loadModel(filename, callback = myFunc)

but what do I pass to the callback? Also, I don’t see any priority flags… where can I check theses flags out? I think I’m missing them in the Python Reference.

I’m guessing it puts it into some sorta background task chain that loads it up in blocks so to keep shuttering down.

The callback will be passed one argument which is a list of the loaded model nodes (may also contain None if okMissing=True)

Yes that Python Reference doesn’t seem to have the full information or I can’t find it. Higher numbers are loaded first. See here: panda3d.org/apiref.php?page=Loader#loadModel

Also note that you can pass a list for the modelPath argument, so you don’t have to do the “for Item in …” loops.