Improved the egg-cacher

This commit is contained in:
Josh Yelon 2007-06-17 09:10:47 +00:00
parent e20cf31373
commit ccef375974
6 changed files with 57 additions and 19 deletions

View File

@ -24,7 +24,7 @@
#endif
#ifdef BUILDING_EGGCACHER
#define LINK_SOURCE "\\bin\\loadalleggs.exe"
#define LINK_SOURCE "\\bin\\eggcacher.exe"
#define LINK_TARGET "\\python\\python.exe"
#endif

View File

@ -2,18 +2,51 @@
#
# eggcacher
#
# this tool searches a directory for egg files, and loads
# them all into the model-cache.
# EggCacher searches a directory for egg files, and loads
# them all into the model-cache. This is used as part of the
# panda installation process.
#
##############################################################################
import os,sys
from pandac.PandaModules import *
MODELCACHE = ConfigVariableFilename("model-cache-dir", Filename()).getValue()
class EggCacher:
def __init__(self):
if (len(sys.argv) != 2):
print "Usage: eggcacher <file-or-directory>"
sys.exit(1)
self.bamcache = BamCache.getGlobalPtr()
self.pandaloader = PandaLoader()
self.loaderopts = LoaderOptions()
if (self.bamcache.getActive() == 0):
print "The model cache is not currently active."
print "You must set a model-cache-dir in your config file."
sys.exit(1)
def traversePath(self, 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))
return
if (path.endswith(".egg")) or (path.endswith(".egg.pz")):
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
self.pandaloader.loadSync(fn, self.loaderopts)
ModelPool.releaseAllModels()
cacher = EggCacher()
for x in sys.argv[1:]:
cacher.traversePath(os.path.abspath(x))
if (MODELCACHE.getValue().isEmpty()==0):
print "The config variable 'model-cache-dir' is not set."
print "You cannot cache egg files until you configure a cache dir."
sys.exit(1)

View File

@ -110,7 +110,7 @@ Section "${SMDIRECTORY}" SecCore
SetOutPath $INSTDIR\models\audio
File /r /x CVS "${PANDA}\models\audio\*"
SetOutPath $INSTDIR\bin
File /r "${PANDA}\bin\pzip.exe"
File /r "${PANDA}\bin\eggcacher.exe"
SetOutpath $INSTDIR\game
File /r "${PPGAME}\*"
CreateShortCut "$SMPROGRAMS\${SMDIRECTORY}\Play ${NAME}.lnk" "$INSTDIR\python\ppython.exe" "${PPMAIN}" "$INSTDIR\${PPICON}" 0 SW_SHOWMINIMIZED "" "Play ${NAME}"
@ -151,10 +151,10 @@ Section "${SMDIRECTORY}" SecCore
WriteINIStr $INSTDIR\Website.url "InternetShortcut" "URL" "http://panda3d.etc.cmu.edu/"
WriteINIStr $INSTDIR\Manual.url "InternetShortcut" "URL" "http://panda3d.etc.cmu.edu/wiki/index.php"
SetOutPath $INSTDIR\samples\GreetingCard
CreateShortCut "$SMPROGRAMS\${SMDIRECTORY}\Panda Greeting Card.lnk" "$INSTDIR\python\ppython.exe" 'GreetingCard.py "$SMPROGRAMS\${SMDIRECTORY}"' "$INSTDIR\bin\pzip.exe" 0 SW_SHOWMINIMIZED "" "Panda Greeting Card"
CreateShortCut "$SMPROGRAMS\${SMDIRECTORY}\Panda Greeting Card.lnk" "$INSTDIR\python\ppython.exe" 'GreetingCard.py "$SMPROGRAMS\${SMDIRECTORY}"' "$INSTDIR\bin\eggcacher.exe" 0 SW_SHOWMINIMIZED "" "Panda Greeting Card"
SetOutPath $INSTDIR
CreateShortCut "$SMPROGRAMS\${SMDIRECTORY}\Panda Manual.lnk" "$INSTDIR\Manual.url" "" "$INSTDIR\bin\pzip.exe" 0 "" "" "Panda Manual"
CreateShortCut "$SMPROGRAMS\${SMDIRECTORY}\Panda Website.lnk" "$INSTDIR\Website.url" "" "$INSTDIR\bin\pzip.exe" 0 "" "" "Panda Website"
CreateShortCut "$SMPROGRAMS\${SMDIRECTORY}\Panda Manual.lnk" "$INSTDIR\Manual.url" "" "$INSTDIR\bin\eggcacher.exe" 0 "" "" "Panda Manual"
CreateShortCut "$SMPROGRAMS\${SMDIRECTORY}\Panda Website.lnk" "$INSTDIR\Website.url" "" "$INSTDIR\bin\eggcacher.exe" 0 "" "" "Panda Website"
FindFirst $0 $1 $INSTDIR\samples\*--*
loop:
@ -182,8 +182,8 @@ Section "${SMDIRECTORY}" SecCore
Call StrRep
Pop $R0
StrCpy $TUTNAME $R0
CreateShortCut "$SMPROGRAMS\${SMDIRECTORY}\$READABLE\Run $TUTNAME.lnk" "$INSTDIR\python\ppython.exe" "$3" "$INSTDIR\bin\pzip.exe" 0 SW_SHOWMINIMIZED "" "Run $TUTNAME"
CreateShortCut "$INSTDIR\samples\$1\Run $TUTNAME.lnk" "$INSTDIR\python\ppython.exe" "$3" "$INSTDIR\bin\pzip.exe" 0 SW_SHOWMINIMIZED "" "Run $TUTNAME"
CreateShortCut "$SMPROGRAMS\${SMDIRECTORY}\$READABLE\Run $TUTNAME.lnk" "$INSTDIR\python\ppython.exe" "$3" "$INSTDIR\bin\eggcacher.exe" 0 SW_SHOWMINIMIZED "" "Run $TUTNAME"
CreateShortCut "$INSTDIR\samples\$1\Run $TUTNAME.lnk" "$INSTDIR\python\ppython.exe" "$3" "$INSTDIR\bin\eggcacher.exe" 0 SW_SHOWMINIMIZED "" "Run $TUTNAME"
FindNext $2 $3
goto iloop
idone:
@ -201,8 +201,9 @@ Section -post
!ifndef PPGAME
# Install the visual studio runtime system.
# ExecWait '"$INSTDIR\bin\vcredist_x86.exe" /Q:a /C:"msiexec.exe /qn /i vcredist.msi"'
# 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

View File

@ -68,6 +68,8 @@ audio-library-name p3fmod_audio
hardware-animated-vertices 0
# Enable the bam-cache
# Enable the model-cache, but only for models, not textures.
model-cache-dir $THIS_PRC_DIR/../modelcache
model-cache-textures #f

View File

@ -3150,6 +3150,8 @@ if (OMIT.count("PYTHON")==0):
EnqueueLink(opts=['WINUSER'], dll='genpycode.exe', obj=['genpycode.obj'])
EnqueueCxx(ipath=IPATH, opts=['BUILDING_PACKPANDA'], src='ppython.cxx', obj='packpanda.obj')
EnqueueLink(opts=['WINUSER'], dll='packpanda.exe', obj=['packpanda.obj'])
EnqueueCxx(ipath=IPATH, opts=['BUILDING_EGGCACHER'], src='ppython.cxx', obj='eggcacher.obj')
EnqueueLink(opts=['WINUSER'], dll='eggcacher.exe', obj=['eggcacher.obj'])
#

View File

@ -70,6 +70,8 @@ PUBLISHED:
INLINE static void list_contents();
static void write(ostream &out);
static ModelPool *get_ptr();
private:
INLINE ModelPool();
@ -86,8 +88,6 @@ private:
int ns_garbage_collect();
void ns_list_contents(ostream &out) const;
static ModelPool *get_ptr();
static ModelPool *_global_ptr;
Mutex _lock;