Planeshift

data.h

Go to the documentation of this file.
00001 /*
00002  * data.h
00003  *
00004  * Copyright (C) 2001-2010 Atomic Blue ([email protected], http://www.planeshift.it)
00005  *
00006  * Credits : Saul Leite <[email protected]>
00007  *           Mathias 'AgY' Voeroes <[email protected]>
00008  *           and all past and present planeshift coders
00009  *
00010  * This program is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU General Public License
00012  * as published by the Free Software Foundation (version 2 of the License.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00021  *
00022  */
00023 
00024 #ifndef _SOUND_DATA_CACHE_H_
00025 #define _SOUND_DATA_CACHE_H_
00026 
00027 
00028 //====================================================================================
00029 // Crystal Space Includes
00030 //====================================================================================
00031 #include <cssysdef.h>
00032 #include <iutil/objreg.h>
00033 #include <csutil/csstring.h>
00034 #include <csutil/hash.h>
00035 #include <iutil/vfs.h>
00036 #include <isndsys/ss_data.h>
00037 #include <isndsys/ss_loader.h>
00038 
00039 #define DEFAULT_SOUNDFILE_CACHETIME 300000
00040 
00041 
00046 struct SoundFile
00047 {
00048 public:
00049     csString            name;           
00050     csString            fileName;       
00051     csRef<iSndSysData>  sndData;        
00052     csTicks             lastTouch;      
00053 
00059     SoundFile(const char* newName, const char* newFileName);
00060 
00065     SoundFile(SoundFile* const &copySoundFile);
00066 
00070     ~SoundFile();
00071 };
00072 
00073 
00074 //--------------------------------------------------
00075 
00076 
00102 class SoundDataCache
00103 {
00104 public:
00105 
00110     SoundDataCache();
00111 
00115     ~SoundDataCache();
00116 
00122     bool Initialize(iObjectRegistry* objectReg);
00123 
00130     bool LoadSoundLib(const char* fileName, iObjectRegistry* objectReg);
00131 
00135     void UnloadSoundLib();
00136 
00150     bool GetSoundData(const char* name, csRef<iSndSysData> &sndData);
00151 
00157     void UnloadSoundFile(const char* name);
00158 
00164     void Update();
00165 
00166 private:
00167     uint                         cacheTime;         
00168     csRef<iVFS>                  vfs;               
00169     csRef<iSndSysLoader>         sndLoader;         
00170     csHash<SoundFile*, csString> libSoundFiles;     
00171     csHash<SoundFile*, csString> loadedSoundFiles;  
00172     
00182     SoundFile* LoadSoundFile(const char* name);
00183 };
00184 
00185 #endif // _SOUND_DATA_CACHE_H_