Revision: 6939 http://playerstage.svn.sourceforge.net/playerstage/?rev=6939&view=rev Author: jeremy_asher Date: 2008-08-01 18:49:44 +0000 (Fri, 01 Aug 2008)
Log Message: ----------- stage: major FileManager updates, rgb.txt is now searched for in STAGEPATH as well Modified Paths: -------------- code/stage/trunk/RELEASE.txt code/stage/trunk/assets/CMakeLists.txt code/stage/trunk/config.h.in code/stage/trunk/docsrc/Makefile code/stage/trunk/libstage/canvas.cc code/stage/trunk/libstage/file_manager.cc code/stage/trunk/libstage/file_manager.hh code/stage/trunk/libstage/model_load.cc code/stage/trunk/libstage/stage.cc code/stage/trunk/libstage/stage.hh code/stage/trunk/libstage/world.cc code/stage/trunk/libstage/worldgui.cc Removed Paths: ------------- code/stage/trunk/.cvsignore code/stage/trunk/docsrc/.cvsignore code/stage/trunk/examples/.cvsignore code/stage/trunk/examples/libplayerc/.cvsignore code/stage/trunk/examples/libstage/.cvsignore code/stage/trunk/libstage/.cvsignore code/stage/trunk/libstageplugin/.cvsignore code/stage/trunk/replace/.cvsignore code/stage/trunk/worlds/.cvsignore code/stage/trunk/worlds/bitmaps/.cvsignore code/stage/trunk/worlds/wifi/.cvsignore Deleted: code/stage/trunk/.cvsignore =================================================================== --- code/stage/trunk/.cvsignore 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/.cvsignore 2008-08-01 18:49:44 UTC (rev 6939) @@ -1,24 +0,0 @@ -.DS_Store -.gdb_history -Makefile -Makefile.in -aclocal.m4 -autom4te.cache -config.cache -config.guess -config.h -config.h.in -config.log -config.status -config.sub -configure -depcomp -install-sh -libtool -ltmain.sh -missing -mkinstalldirs -stage.pc -stamp-h -stamp-h.in -stamp-h1 \ No newline at end of file Modified: code/stage/trunk/RELEASE.txt =================================================================== --- code/stage/trunk/RELEASE.txt 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/RELEASE.txt 2008-08-01 18:49:44 UTC (rev 6939) @@ -1,6 +1,7 @@ Version 3.0.1 ------------- -This version incorporates a number of fixes made since the previous major release: +This version incorporates a number of fixes made since the previous +major release: * Player plugin * added unit test suite to verify functionality (build instructions Modified: code/stage/trunk/assets/CMakeLists.txt =================================================================== --- code/stage/trunk/assets/CMakeLists.txt 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/assets/CMakeLists.txt 2008-08-01 18:49:44 UTC (rev 6939) @@ -6,6 +6,6 @@ ) INSTALL(FILES rgb.txt - DESTINATION share/stage/ + DESTINATION share/stage ) Modified: code/stage/trunk/config.h.in =================================================================== --- code/stage/trunk/config.h.in 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/config.h.in 2008-08-01 18:49:44 UTC (rev 6939) @@ -4,7 +4,6 @@ #define PROJECT "@PROJECT_NAME@" #define VERSION "@VERSION@" #define APIVERSION "@APIVERSION@" -#define RGBFILE "@RGBFILE@" #define INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@" #endif Deleted: code/stage/trunk/docsrc/.cvsignore =================================================================== --- code/stage/trunk/docsrc/.cvsignore 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/docsrc/.cvsignore 2008-08-01 18:49:44 UTC (rev 6939) @@ -1,7 +0,0 @@ -Makefile -Makefile.in -stage_user -stage_reference -player.tag -header.html -stage Modified: code/stage/trunk/docsrc/Makefile =================================================================== --- code/stage/trunk/docsrc/Makefile 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/docsrc/Makefile 2008-08-01 18:49:44 UTC (rev 6939) @@ -16,6 +16,7 @@ ./sourcedocs.sh > sourced.txt doxygen stage.dox cp stage_button.png stage + rm -f sourced.txt # install the latest docs doc-install: doc Deleted: code/stage/trunk/examples/.cvsignore =================================================================== --- code/stage/trunk/examples/.cvsignore 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/examples/.cvsignore 2008-08-01 18:49:44 UTC (rev 6939) @@ -1,2 +0,0 @@ -Makefile.in -Makefile \ No newline at end of file Deleted: code/stage/trunk/examples/libplayerc/.cvsignore =================================================================== --- code/stage/trunk/examples/libplayerc/.cvsignore 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/examples/libplayerc/.cvsignore 2008-08-01 18:49:44 UTC (rev 6939) @@ -1,4 +0,0 @@ -Makefile.in -Makefile -ptest -audio Deleted: code/stage/trunk/examples/libstage/.cvsignore =================================================================== --- code/stage/trunk/examples/libstage/.cvsignore 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/examples/libstage/.cvsignore 2008-08-01 18:49:44 UTC (rev 6939) @@ -1,3 +0,0 @@ -Makefile.in -Makefile -stest Deleted: code/stage/trunk/libstage/.cvsignore =================================================================== --- code/stage/trunk/libstage/.cvsignore 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/libstage/.cvsignore 2008-08-01 18:49:44 UTC (rev 6939) @@ -1,4 +0,0 @@ -Makefile -Makefile.in -stage -.DS_Store Modified: code/stage/trunk/libstage/canvas.cc =================================================================== --- code/stage/trunk/libstage/canvas.cc 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/libstage/canvas.cc 2008-08-01 18:49:44 UTC (rev 6939) @@ -950,7 +950,7 @@ //TODO find a better home for loading textures if( loaded_texture == false ) { - std::string fullpath = world->fileMan->fullPath( "stall.png" ); + std::string fullpath = FileManager::findFile( "assets/stall.png" ); if ( fullpath == "" ) { PRINT_DEBUG( "Unable to load texture.\n" ); } Modified: code/stage/trunk/libstage/file_manager.cc =================================================================== --- code/stage/trunk/libstage/file_manager.cc 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/libstage/file_manager.cc 2008-08-01 18:49:44 UTC (rev 6939) @@ -1,3 +1,5 @@ +//#define DEBUG + #include "file_manager.hh" #include "stage.hh" // to get PRINT_DEBUG #include "config.h" // to get INSTALL_PREFIX @@ -2,43 +4,62 @@ +#include <sstream> +#include <fstream> + +std::string searchDirs( const std::vector<std::string> dirs, const std::string filename ) { + for ( unsigned int i=0; i<dirs.size(); i++ ) { + std::string path = dirs[i] + '/' + filename; + PRINT_DEBUG1("FileManager: trying %s\n", path.c_str()); + if ( Stg::FileManager::readable( path ) ) { + return path; + } + } + + PRINT_DEBUG1("FileManager: %s not found.\n", filename.c_str() ); + return ""; +} + namespace Stg { - FileManager::FileManager() { - char *tmp; - - SharePath = INSTALL_PREFIX "/share/stage"; - AssetPath = SharePath + '/' + "assets"; - WorldsRoot = "."; - - paths.push_back( "." ); - paths.push_back( SharePath ); - paths.push_back( AssetPath ); - if( tmp = getenv("STAGEPATH") ) - paths.push_back( tmp ); + FileManager::FileManager() : WorldsRoot( "." ) + { } + + std::string FileManager::stagePath() { + static char* stgPath = getenv("STAGEPATH"); + if ( stgPath == NULL ) + return ""; + else + return std::string( stgPath ); } - std::string FileManager::fullPath( std::string filename ) { + std::string FileManager::findFile( const std::string filename ) { PRINT_DEBUG1("FileManager: trying %s\n", filename.c_str()); if ( readable( filename ) ) return filename; - - for ( unsigned int i=0; i<paths.size(); i++ ) { - std::string path = paths[i] + '/' + filename; - PRINT_DEBUG1("FileManager: trying %s\n", path.c_str()); - if ( readable( path ) ) { - return path; + + static std::vector<std::string> paths; + static bool ranOnce = false; + + // initialize the path list, if necessary + if ( !ranOnce ) { + std::string SharePath = INSTALL_PREFIX "/share/stage"; + paths.push_back( SharePath ); + + std::string stgPath = stagePath(); + + std::istringstream is( stgPath ); + std::string path; + while ( getline( is, path, ':' ) ) { + paths.push_back( path ); + PRINT_DEBUG1("FileManager - INIT: added path %s\n", path.c_str() ); } + + ranOnce = true; + + PRINT_DEBUG1("FileManager - INIT: %d paths in search paths\n", paths.size() ); } - - PRINT_DEBUG("FileManager: Not found.\n"); - return ""; + + // search the path list + return searchDirs( paths, filename ); } - - /*std::string FileManager::fullPathImage( std::string filename ) { - std::string path = ImgPath + '/' + filename; - if ( readable ( path ) ) - return path; - else - return ""; - }*/ - + bool FileManager::readable( std::string path ) { @@ -54,7 +75,7 @@ return false; } } - + std::string FileManager::stripFilename( std::string path ) { std::string pathChars( "\\/" ); size_t loc = path.find_last_of( pathChars ); @@ -63,6 +84,6 @@ else return path.substr( 0, loc ); } - -}; // namespace Stg +}; // namespace Stg + Modified: code/stage/trunk/libstage/file_manager.hh =================================================================== --- code/stage/trunk/libstage/file_manager.hh 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/libstage/file_manager.hh 2008-08-01 18:49:44 UTC (rev 6939) @@ -1,7 +1,6 @@ #ifndef _FILE_MANAGER_HH_ #define _FILE_MANAGER_HH_ -#include <fstream> #include <string> #include <vector> @@ -9,24 +8,30 @@ class FileManager { private: - std::vector<std::string> paths; - std::string SharePath; - std::string AssetPath; - std::string CtrlPath; std::string WorldsRoot; - - std::string stripFilename( std::string path ); + + std::string stripFilename( const std::string path ); public: FileManager(); - - std::string fullPath( std::string filename ); - //std::string fullPathImage( std::string filename ); - + + /// Return the path where the current worldfile was loaded from inline const std::string worldsRoot() const { return WorldsRoot; } - inline void newWorld( std::string worldfile ) { + /// Update the worldfile path + inline void newWorld( const std::string worldfile ) { WorldsRoot = stripFilename( worldfile ); } - - bool readable( std::string path ); + + /// Determine whether a file can be opened for reading + static bool readable( const std::string path ); + + /** Search for a file in the current directory, in the + * prefix/share/stage location, and in the locations specified by + * the STAGEPATH environment variable. Returns the first match or + * the original filename if not found. + **/ + static std::string findFile( const std::string filename ); + + /// Return the STAGEPATH environment variable + static std::string stagePath(); }; }; Modified: code/stage/trunk/libstage/model_load.cc =================================================================== --- code/stage/trunk/libstage/model_load.cc 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/libstage/model_load.cc 2008-08-01 18:49:44 UTC (rev 6939) @@ -8,8 +8,9 @@ #include <ltdl.h> #include "stage_internal.hh" +#include "file_manager.hh" -#define DEBUG 1 +//#define DEBUG void StgModel::Load() { @@ -379,12 +380,8 @@ int errors = lt_dlinit(); assert(errors==0); - char* stagepath = getenv("STAGEPATH"); - if( stagepath == NULL ) - stagepath = (char*)"."; + lt_dlsetsearchpath( FileManager::stagePath().c_str() ); - lt_dlsetsearchpath( stagepath ); - lt_dlhandle handle = NULL; if(( handle = lt_dlopenext( lib ) )) Modified: code/stage/trunk/libstage/stage.cc =================================================================== --- code/stage/trunk/libstage/stage.cc 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/libstage/stage.cc 2008-08-01 18:49:44 UTC (rev 6939) @@ -18,6 +18,7 @@ #include "stage_internal.hh" #include "config.h" // results of cmake's system configuration tests +#include "file_manager.hh" static bool init_called = false; @@ -193,24 +194,9 @@ if( file == NULL ) { - const char* searchfiles[] = { - "./rgb.txt", -#ifdef RGBFILE - RGBFILE, -#endif - "../rgb.txt", - NULL }; - - for( int i=0; - searchfiles[i]; - i++ ) - { - const char* filename = searchfiles[i]; - PRINT_DEBUG1( "Attempting to open \"%s\"", filename ); - if( (file = fopen( filename, "r")) ) - break; // opened a file ok - jump out of for loop - } - + std::string rgbFile = FileManager::findFile( "rgb.txt" ); + file = fopen( rgbFile.c_str(), "r" ); + if( file == NULL ) { Modified: code/stage/trunk/libstage/stage.hh =================================================================== --- code/stage/trunk/libstage/stage.hh 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/libstage/stage.hh 2008-08-01 18:49:44 UTC (rev 6939) @@ -67,6 +67,7 @@ #endif #include "option.hh" +#include "file_manager.hh" /** The Stage library uses its own namespace */ namespace Stg @@ -77,7 +78,6 @@ class StgWorld; class StgWorldGui; class StgModel; - class FileManager; class OptionsDlg; class StgCamera; @@ -1065,7 +1065,7 @@ long unsigned int updates; ///< the number of simulated time steps executed so far - FileManager* fileMan; + FileManager fileMan; public: static const int DEFAULT_PPM = 50; // default resolution in pixels per meter Modified: code/stage/trunk/libstage/world.cc =================================================================== --- code/stage/trunk/libstage/world.cc 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/libstage/world.cc 2008-08-01 18:49:44 UTC (rev 6939) @@ -153,8 +153,6 @@ bzero( &this->extent, sizeof(this->extent)); this->real_time_now = 0; - - fileMan = new FileManager(); } StgWorld::~StgWorld( void ) @@ -170,8 +168,6 @@ g_free( token ); world_list = g_list_remove( world_list, this ); - - delete fileMan; } Modified: code/stage/trunk/libstage/worldgui.cc =================================================================== --- code/stage/trunk/libstage/worldgui.cc 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/libstage/worldgui.cc 2008-08-01 18:49:44 UTC (rev 6939) @@ -216,7 +216,7 @@ { PRINT_DEBUG1( "%s.Load()", token ); - fileMan->newWorld( filename ); + fileMan.newWorld( filename ); StgWorld::Load( filename ); @@ -403,7 +403,7 @@ //bool success; const char* pattern = "World Files (*.world)"; - std::string worldsPath( worldGui->fileMan->worldsRoot() ); + std::string worldsPath = worldGui->fileMan.worldsRoot(); worldsPath.append( "/" ); Fl_File_Chooser fc( worldsPath.c_str(), pattern, Fl_File_Chooser::CREATE, "Load World File..." ); fc.ok_label( "Load" ); @@ -415,7 +415,7 @@ filename = fc.value(); if (filename != NULL) { // chose something - if ( worldGui->fileMan->readable( filename ) ) { + if ( FileManager::readable( filename ) ) { // file is readable, clear and load // if (initialized) { @@ -562,7 +562,7 @@ std::string fullpath; - fullpath = worldGui->fileMan->fullPath( "stagelogo.png" ); + fullpath = FileManager::findFile( "assets/stagelogo.png" ); Fl_PNG_Image* png = new Fl_PNG_Image( fullpath.c_str() ); // load image into ram box->image( png ); // attach image to box Deleted: code/stage/trunk/libstageplugin/.cvsignore =================================================================== --- code/stage/trunk/libstageplugin/.cvsignore 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/libstageplugin/.cvsignore 2008-08-01 18:49:44 UTC (rev 6939) @@ -1,3 +0,0 @@ -Makefile -Makefile.in -.DS_Store Deleted: code/stage/trunk/replace/.cvsignore =================================================================== --- code/stage/trunk/replace/.cvsignore 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/replace/.cvsignore 2008-08-01 18:49:44 UTC (rev 6939) @@ -1,2 +0,0 @@ -Makefile.in -Makefile Deleted: code/stage/trunk/worlds/.cvsignore =================================================================== --- code/stage/trunk/worlds/.cvsignore 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/worlds/.cvsignore 2008-08-01 18:49:44 UTC (rev 6939) @@ -1,2 +0,0 @@ -Makefile -Makefile.in Deleted: code/stage/trunk/worlds/bitmaps/.cvsignore =================================================================== --- code/stage/trunk/worlds/bitmaps/.cvsignore 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/worlds/bitmaps/.cvsignore 2008-08-01 18:49:44 UTC (rev 6939) @@ -1,2 +0,0 @@ -Makefile -Makefile.in \ No newline at end of file Deleted: code/stage/trunk/worlds/wifi/.cvsignore =================================================================== --- code/stage/trunk/worlds/wifi/.cvsignore 2008-07-30 18:08:13 UTC (rev 6938) +++ code/stage/trunk/worlds/wifi/.cvsignore 2008-08-01 18:49:44 UTC (rev 6939) @@ -1,2 +0,0 @@ -Makefile -Makefile.in This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Playerstage-commit mailing list Playerstage-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/playerstage-commit