/******************************************************************************* * * W�ms of Prey - game data loader class header * * $Id: loader.hpp,v 1.10 2005/06/28 13:55:20 chfreund Exp $ * *******************************************************************************/ #ifndef _LOADER_HPP #include #include #include #include #include #include "string.hpp" #include "physfsrwops.hpp" class Video; //! map type for shared references typedef std::map LoaderFileMap; //! class for loading images,sounds,fonts etc. from the data directories /* * call "Loader::getInstance()" to get a reference to the unique loader object * PhysFs init needs the path to the program executable (argv[0] from main) * this is stored in Loader::m_wopPath , which is set in main , and is * needed before getInstance is called for the first time * * warning: all standard "getXXX" load methods return shared instances, * call "getUniqueXXX" to get a unique copy that can be modified * */ class Loader { public: //! init loader, pass argv[0] from commandline to init PhysFs Loader(String argv0); //! destruct loader, deinit PhysFs ~Loader(); //! make abort on error flag clearer to use in the sources typedef enum { noErrorAbort = false, errorAbort = true }; // the loading routines... // these return shared references //! load a font TTF file TTF_Font *getFont(String filename, int fontSize, bool abortOnError=false); //! load a font an image file into a SDL surface SDL_Surface* getImage(String filename, bool alpha, bool abortOnError=false); //! load a sound file Mix_Chunk* getSound(String filename, bool abortOnError=false); //! load a music file Mix_Music* getMusic(String filename, bool abortOnError=false); // unique loading routines... // these return a unique copy unpon each call //! convert unix path to absolute, if necessary String getAbsolutePath(String filename); //! load a unique font TTF file TTF_Font *getUniqueFont(String filename, int fontSize, bool abortOnError=false); //! load a unique font an image file into a SDL surface SDL_Surface* getUniqueImage(String filename, bool alpha, bool abortOnError=false); //! load a unique sound file Mix_Chunk* getUniqueSound(String filename, bool abortOnError=false); //! load a unique sound file Mix_Music* getUniqueMusic(String filename, bool abortOnError=false); protected: #ifdef USE_PHYSFS //! open file as RWops SDL_RWops* getRWops(String filename, bool abortOnError); #endif //! map instance LoaderFileMap m_map; //! singleton instance static Loader* m_singleton; // program path for PhysFs init static String m_wopPath; //! graphics display obj pointer static Video *m_video; public: //! singleton interface, returns loader object, creates if it doenst yet exist static Loader *getInstance(); //! singleton interface to delete a possibly present instance static void deleteInstance(); //! set wop path char pointer for PhysFs init static void setWopPath( const char* const set ) { m_wopPath = set; } //! set video obj pointer static void setVideo(Video *set) { m_video = set; } }; #define _LOADER_HPP #endif // _LOADER_HPP