⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sound.cpp

📁 3D游戏模板
💻 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 + -