diff --git a/direct/src/directscripts/eggcacher.py b/direct/src/directscripts/eggcacher.py index 5cf5dba352..0da0cea9bb 100644 --- a/direct/src/directscripts/eggcacher.py +++ b/direct/src/directscripts/eggcacher.py @@ -12,11 +12,9 @@ import os,sys from pandac.PandaModules import * class EggCacher: - def __init__(self): - if (len(sys.argv) != 2): - print "Usage: eggcacher " - sys.exit(1) - + def __init__(self, args): + maindir = Filename.fromOsSpecific(os.getcwd()).getFullpath() + ExecutionEnvironment.setEnvironmentVariable("MAIN_DIR", maindir) self.bamcache = BamCache.getGlobalPtr() self.pandaloader = PandaLoader() self.loaderopts = LoaderOptions() @@ -24,29 +22,60 @@ class EggCacher: print "The model cache is not currently active." print "You must set a model-cache-dir in your config file." sys.exit(1) + self.parseArgs(args) + files = self.scanPaths(self.paths) + self.processFiles(files) - def traversePath(self, path): + def parseArgs(self, args): + self.concise =0 + while len(args): + if (args[0]=="--concise"): + self.concise = 1 + args = args[1:] + else: + break + if (len(args) < 1): + print "Usage: eggcacher options file-or-directory" + sys.exit(1) + self.paths = args + + def scanPath(self, eggs, path): if (os.path.exists(path)==0): print "No such file or directory: "+path return if (os.path.isdir(path)): for f in os.listdir(path): - self.traversePath(os.path.join(path,f)) + self.scanPath(eggs, os.path.join(path,f)) return if (path.endswith(".egg")) or (path.endswith(".egg.pz")): + size = os.path.getsize(path) + eggs.append((path,size)) + + def scanPaths(self, paths): + eggs = [] + for path in paths: + abs = os.path.abspath(path) + self.scanPath(eggs,path) + return eggs + + def processFiles(self, files): + total = 0 + for (path,size) in files: + total += size + progress = 0 + for (path,size) in files: fn = Filename.fromOsSpecific(path) cached = self.bamcache.lookup(fn,"bam") - if (cached == None): - print "Not cacheable: "+path - elif (cached.hasData()): - print "Already Cached: "+path - else: - print "Caching "+path + percent = (progress * 100) / total + report = path + if (self.concise): report = os.path.basename(report) + print "Preprocessing Models %2d%% %s" % (percent, report) + sys.stdout.flush() + if (cached) and (cached.hasData()==0): self.pandaloader.loadSync(fn, self.loaderopts) ModelPool.releaseAllModels() - -cacher = EggCacher() -for x in sys.argv[1:]: - cacher.traversePath(os.path.abspath(x)) + progress += size +cacher = EggCacher(sys.argv[1:]) + diff --git a/direct/src/directscripts/packpanda.nsi b/direct/src/directscripts/packpanda.nsi index 8fc0c3b39d..7a9aa5bb29 100755 --- a/direct/src/directscripts/packpanda.nsi +++ b/direct/src/directscripts/packpanda.nsi @@ -100,7 +100,7 @@ Section "${SMDIRECTORY}" SecCore File /r "${PANDA}\pandac\*.py" SetOutPath $INSTDIR\python File /r "${PANDA}\python\*" - CreateDirectory $INSTDIR/modelcache + CreateDirectory "$INSTDIR\modelcache" RMDir /r "$SMPROGRAMS\${SMDIRECTORY}" CreateDirectory "$SMPROGRAMS\${SMDIRECTORY}" @@ -114,6 +114,13 @@ Section "${SMDIRECTORY}" SecCore SetOutpath $INSTDIR\game File /r "${PPGAME}\*" CreateShortCut "$SMPROGRAMS\${SMDIRECTORY}\Play ${NAME}.lnk" "$INSTDIR\python\ppython.exe" "${PPMAIN}" "$INSTDIR\${PPICON}" 0 SW_SHOWMINIMIZED "" "Play ${NAME}" + # Preload all EGG files into the model-cache + SetOutPath $INSTDIR + SetDetailsPrint textonly + SetDetailsView show + nsExec::ExecToLog '"$INSTDIR\bin\eggcacher.exe" --concise game' + SetDetailsPrint none + SetDetailsView hide !else @@ -146,6 +153,13 @@ Section "${SMDIRECTORY}" SecCore File /r /x CVS "${PANDA}\models\*" SetOutPath $INSTDIR\samples File /r /x CVS "${PSOURCE}\samples\*" + # Preload all EGG files into the model-cache + SetOutPath $INSTDIR + SetDetailsPrint both + SetDetailsView show + nsExec::ExecToLog '"$INSTDIR\bin\eggcacher.exe" --concise models samples' + SetDetailsPrint none + SetDetailsView hide SetOutPath $INSTDIR WriteINIStr $INSTDIR\Website.url "InternetShortcut" "URL" "http://panda3d.etc.cmu.edu/" @@ -201,9 +215,6 @@ Section -post !ifndef PPGAME - # Preload all EGG files into the model-cache - ExecWait '"$INSTDIR\bin\eggcacher.exe" samples models" - # Add the "bin" directory to the PATH. Push "$INSTDIR\python" Call RemoveFromPath diff --git a/doc/makepanda/makepanda.py b/doc/makepanda/makepanda.py index b216b414f7..3b312edf0e 100755 --- a/doc/makepanda/makepanda.py +++ b/doc/makepanda/makepanda.py @@ -1010,7 +1010,7 @@ def CopyAllFiles(dstdir, srcdir, suffix=""): def CompileAllModels(dstdir, srcdir): for x in GetDirectoryContents(srcdir, ["*.egg", "*.flt"]): eggpz = os.path.basename(x[:-4] + ".egg.pz") - EnqueueEggPZ("", dstdir + eggpz, srcdir + x) + EnqueueEggPZ(dstdir + eggpz, srcdir + x) def CopyAllHeaders(dir, skip=[]): for filename in GetDirectoryContents(dir, ["*.h", "*.I", "*.T"], skip): @@ -1427,16 +1427,16 @@ def EnqueueLink(dll=0, obj=[], opts=[], xdep=[], ldef=0): # ########################################################################################## -def CompileEggPZ(preconv, eggpz, src): +def CompileEggPZ(eggpz, src): if (src.endswith(".egg")): CopyFile(eggpz[:-3], src) elif (src.endswith(".flt")): - oscmd("built/bin/flt2egg " + preconv + " -o " + eggpz[:-3] + " " + src) + oscmd("built/bin/flt2egg -ps keep -o " + eggpz[:-3] + " " + src) oscmd("built/bin/pzip " + eggpz[:-3]) -def EnqueueEggPZ(preconv, eggpz, src): +def EnqueueEggPZ(eggpz, src): dep = [src, "flt2egg.exe"] - SDependencyQueue([], [CompileEggPZ, preconv, eggpz, src], [eggpz], dep) + SDependencyQueue([], [CompileEggPZ, eggpz, src], [eggpz], dep) ########################################################################################## #