?? sound.cpp
字號:
/* sound system * CS Template game * (C)2002 Mat Sutcliffe. See license.txt for license info (GPL). */#include <cssysdef.h>#include <isound/renderer.h>#include <isound/loader.h>#include <isound/source.h>#include <isound/handle.h>#include <isound/data.h>#include <iutil/vfs.h>#include <iutil/cfgmgr.h>#include <csutil/hashmap.h>#include <iutil/objreg.h>#include "sound.h"#include "sys.h"Sound::Sound(iObjectRegistry *obj) { objreg = obj; handles = new csHashMap; render = CS_QUERY_REGISTRY(objreg, iSoundRender); csRef<iVFS> vfs (CS_QUERY_REGISTRY(objreg, iVFS)); csRef<iSoundLoader> loader (CS_QUERY_REGISTRY(objreg, iSoundLoader)); csRef<iConfigManager> conf (CS_QUERY_REGISTRY(objreg, iConfigManager)); if (conf->SubsectionExists(GAME ".Sound.")) { csRef<iConfigIterator> iter (conf->Enumerate(GAME ".Sound.")); System::require(render, "Finding Sound Renderer"); System::require(loader, "Finding Sound Loader"); while (iter->Next()) { csRef<iFile> file (vfs->Open(iter->GetStr(), VFS_FILE_READ)); if (file) { size_t size = file->GetSize(); char data[size]; file->Read(data, size); csRef<iSoundData> sdata (loader->LoadSound(data, size)); System::require(sdata, "Loading Sound"); csRef<iSoundHandle> handle (render->RegisterSound(sdata)); System::require(handle, "Registering Sound"); handles->Put(csHashCompute(iter->GetKey(1)), (csHashObject)handle); } else System::report("Can't load an audio file"); } }}Sound::~Sound() { csHashIterator iter (handles); while (iter.HasNext()) { csRef<iSoundHandle> handle ((iSoundHandle *)iter.Next()); render->UnregisterSound(handle); } delete handles;}csPtr<iSoundSource> Sound::GetSource(char *name, int mode) { csRef<iSoundHandle> hdl ((iSoundHandle *)handles->Get(csHashCompute(name))); if (hdl) return hdl->CreateSource(mode); else return (iSoundSource *)NULL;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -