mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
More improvements related to use of model-cache
This commit is contained in:
parent
fe79990cdf
commit
2f1bf73bc7
@ -12,11 +12,9 @@ import os,sys
|
|||||||
from pandac.PandaModules import *
|
from pandac.PandaModules import *
|
||||||
|
|
||||||
class EggCacher:
|
class EggCacher:
|
||||||
def __init__(self):
|
def __init__(self, args):
|
||||||
if (len(sys.argv) != 2):
|
maindir = Filename.fromOsSpecific(os.getcwd()).getFullpath()
|
||||||
print "Usage: eggcacher <file-or-directory>"
|
ExecutionEnvironment.setEnvironmentVariable("MAIN_DIR", maindir)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
self.bamcache = BamCache.getGlobalPtr()
|
self.bamcache = BamCache.getGlobalPtr()
|
||||||
self.pandaloader = PandaLoader()
|
self.pandaloader = PandaLoader()
|
||||||
self.loaderopts = LoaderOptions()
|
self.loaderopts = LoaderOptions()
|
||||||
@ -24,29 +22,60 @@ class EggCacher:
|
|||||||
print "The model cache is not currently active."
|
print "The model cache is not currently active."
|
||||||
print "You must set a model-cache-dir in your config file."
|
print "You must set a model-cache-dir in your config file."
|
||||||
sys.exit(1)
|
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):
|
if (os.path.exists(path)==0):
|
||||||
print "No such file or directory: "+path
|
print "No such file or directory: "+path
|
||||||
return
|
return
|
||||||
if (os.path.isdir(path)):
|
if (os.path.isdir(path)):
|
||||||
for f in os.listdir(path):
|
for f in os.listdir(path):
|
||||||
self.traversePath(os.path.join(path,f))
|
self.scanPath(eggs, os.path.join(path,f))
|
||||||
return
|
return
|
||||||
if (path.endswith(".egg")) or (path.endswith(".egg.pz")):
|
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)
|
fn = Filename.fromOsSpecific(path)
|
||||||
cached = self.bamcache.lookup(fn,"bam")
|
cached = self.bamcache.lookup(fn,"bam")
|
||||||
if (cached == None):
|
percent = (progress * 100) / total
|
||||||
print "Not cacheable: "+path
|
report = path
|
||||||
elif (cached.hasData()):
|
if (self.concise): report = os.path.basename(report)
|
||||||
print "Already Cached: "+path
|
print "Preprocessing Models %2d%% %s" % (percent, report)
|
||||||
else:
|
sys.stdout.flush()
|
||||||
print "Caching "+path
|
if (cached) and (cached.hasData()==0):
|
||||||
self.pandaloader.loadSync(fn, self.loaderopts)
|
self.pandaloader.loadSync(fn, self.loaderopts)
|
||||||
ModelPool.releaseAllModels()
|
ModelPool.releaseAllModels()
|
||||||
|
progress += size
|
||||||
cacher = EggCacher()
|
|
||||||
for x in sys.argv[1:]:
|
|
||||||
cacher.traversePath(os.path.abspath(x))
|
|
||||||
|
|
||||||
|
|
||||||
|
cacher = EggCacher(sys.argv[1:])
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ Section "${SMDIRECTORY}" SecCore
|
|||||||
File /r "${PANDA}\pandac\*.py"
|
File /r "${PANDA}\pandac\*.py"
|
||||||
SetOutPath $INSTDIR\python
|
SetOutPath $INSTDIR\python
|
||||||
File /r "${PANDA}\python\*"
|
File /r "${PANDA}\python\*"
|
||||||
CreateDirectory $INSTDIR/modelcache
|
CreateDirectory "$INSTDIR\modelcache"
|
||||||
|
|
||||||
RMDir /r "$SMPROGRAMS\${SMDIRECTORY}"
|
RMDir /r "$SMPROGRAMS\${SMDIRECTORY}"
|
||||||
CreateDirectory "$SMPROGRAMS\${SMDIRECTORY}"
|
CreateDirectory "$SMPROGRAMS\${SMDIRECTORY}"
|
||||||
@ -114,6 +114,13 @@ Section "${SMDIRECTORY}" SecCore
|
|||||||
SetOutpath $INSTDIR\game
|
SetOutpath $INSTDIR\game
|
||||||
File /r "${PPGAME}\*"
|
File /r "${PPGAME}\*"
|
||||||
CreateShortCut "$SMPROGRAMS\${SMDIRECTORY}\Play ${NAME}.lnk" "$INSTDIR\python\ppython.exe" "${PPMAIN}" "$INSTDIR\${PPICON}" 0 SW_SHOWMINIMIZED "" "Play ${NAME}"
|
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
|
!else
|
||||||
|
|
||||||
@ -146,6 +153,13 @@ Section "${SMDIRECTORY}" SecCore
|
|||||||
File /r /x CVS "${PANDA}\models\*"
|
File /r /x CVS "${PANDA}\models\*"
|
||||||
SetOutPath $INSTDIR\samples
|
SetOutPath $INSTDIR\samples
|
||||||
File /r /x CVS "${PSOURCE}\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
|
SetOutPath $INSTDIR
|
||||||
WriteINIStr $INSTDIR\Website.url "InternetShortcut" "URL" "http://panda3d.etc.cmu.edu/"
|
WriteINIStr $INSTDIR\Website.url "InternetShortcut" "URL" "http://panda3d.etc.cmu.edu/"
|
||||||
@ -201,9 +215,6 @@ Section -post
|
|||||||
|
|
||||||
!ifndef PPGAME
|
!ifndef PPGAME
|
||||||
|
|
||||||
# Preload all EGG files into the model-cache
|
|
||||||
ExecWait '"$INSTDIR\bin\eggcacher.exe" samples models"
|
|
||||||
|
|
||||||
# Add the "bin" directory to the PATH.
|
# Add the "bin" directory to the PATH.
|
||||||
Push "$INSTDIR\python"
|
Push "$INSTDIR\python"
|
||||||
Call RemoveFromPath
|
Call RemoveFromPath
|
||||||
|
@ -1010,7 +1010,7 @@ def CopyAllFiles(dstdir, srcdir, suffix=""):
|
|||||||
def CompileAllModels(dstdir, srcdir):
|
def CompileAllModels(dstdir, srcdir):
|
||||||
for x in GetDirectoryContents(srcdir, ["*.egg", "*.flt"]):
|
for x in GetDirectoryContents(srcdir, ["*.egg", "*.flt"]):
|
||||||
eggpz = os.path.basename(x[:-4] + ".egg.pz")
|
eggpz = os.path.basename(x[:-4] + ".egg.pz")
|
||||||
EnqueueEggPZ("", dstdir + eggpz, srcdir + x)
|
EnqueueEggPZ(dstdir + eggpz, srcdir + x)
|
||||||
|
|
||||||
def CopyAllHeaders(dir, skip=[]):
|
def CopyAllHeaders(dir, skip=[]):
|
||||||
for filename in GetDirectoryContents(dir, ["*.h", "*.I", "*.T"], 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")):
|
if (src.endswith(".egg")):
|
||||||
CopyFile(eggpz[:-3], src)
|
CopyFile(eggpz[:-3], src)
|
||||||
elif (src.endswith(".flt")):
|
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])
|
oscmd("built/bin/pzip " + eggpz[:-3])
|
||||||
|
|
||||||
def EnqueueEggPZ(preconv, eggpz, src):
|
def EnqueueEggPZ(eggpz, src):
|
||||||
dep = [src, "flt2egg.exe"]
|
dep = [src, "flt2egg.exe"]
|
||||||
SDependencyQueue([], [CompileEggPZ, preconv, eggpz, src], [eggpz], dep)
|
SDependencyQueue([], [CompileEggPZ, eggpz, src], [eggpz], dep)
|
||||||
|
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
#
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user