update: Code style & Resource Class & File Class
This commit is contained in:
		
							parent
							
								
									9472aebff2
								
							
						
					
					
						commit
						f26aff5e78
					
				|  | @ -71,7 +71,7 @@ namespace e2d | ||||||
| 
 | 
 | ||||||
| 		// 譜崔完悶夕炎
 | 		// 譜崔完悶夕炎
 | ||||||
| 		void SetIcon( | 		void SetIcon( | ||||||
| 			int icon_id | 			int icon_id			/* ͼ±ê×ÊÔ´ ID */ | ||||||
| 		); | 		); | ||||||
| 
 | 
 | ||||||
| 		// 譜崔報炎峺寞劔塀
 | 		// 譜崔報炎峺寞劔塀
 | ||||||
|  | @ -131,9 +131,9 @@ namespace e2d | ||||||
| 		MSG		msg_; | 		MSG		msg_; | ||||||
| 		int		width_; | 		int		width_; | ||||||
| 		int		height_; | 		int		height_; | ||||||
| 		String	title_; |  | ||||||
| 		int		icon_id_; | 		int		icon_id_; | ||||||
| 		float	dpi_; | 		float	dpi_; | ||||||
|  | 		String	title_; | ||||||
| 
 | 
 | ||||||
| 		static Window * instance_; | 		static Window * instance_; | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
|  | @ -591,12 +591,12 @@ namespace e2d | ||||||
| 	{ | 	{ | ||||||
| 	public: | 	public: | ||||||
| 		Resource( | 		Resource( | ||||||
| 			size_t resource_name,			/* ×ĘÔ´ĂűłĆ */ | 			int resource_id,				/* ×ÊÔ´Ãû³Æ */ | ||||||
| 			const String& resource_type		/* ×ÊÔ´ÀàÐÍ */ | 			const String& resource_type		/* ×ÊÔ´ÀàÐÍ */ | ||||||
| 		); | 		); | ||||||
| 
 | 
 | ||||||
| 	public: | 	public: | ||||||
| 		size_t	name; | 		int		id; | ||||||
| 		String	type; | 		String	type; | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -53,7 +53,7 @@ bool e2d::Image::Open(const Resource& res) | ||||||
| 		return false; | 		return false; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	this->SetBitmap(bitmap_cache_.at(res.name)); | 	this->SetBitmap(bitmap_cache_.at(res.id)); | ||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -153,98 +153,98 @@ e2d::Point e2d::Image::GetCropPos() const | ||||||
| 
 | 
 | ||||||
| bool e2d::Image::Preload(const Resource& res) | bool e2d::Image::Preload(const Resource& res) | ||||||
| { | { | ||||||
| 	if (bitmap_cache_.find(res.name) != bitmap_cache_.end()) | 	if (bitmap_cache_.find(res.id) != bitmap_cache_.end()) | ||||||
| 	{ | 	{ | ||||||
| 		return true; | 		return true; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	IWICImagingFactory *pImagingFactory = Renderer::GetImagingFactory(); | 	IWICImagingFactory *imaging_factory = Renderer::GetImagingFactory(); | ||||||
| 	ID2D1HwndRenderTarget* pRenderTarget = Renderer::GetInstance()->GetRenderTarget(); | 	ID2D1HwndRenderTarget* render_target = Renderer::GetInstance()->GetRenderTarget(); | ||||||
| 	IWICBitmapDecoder *pDecoder = nullptr; | 	IWICBitmadecoder *decoder = nullptr; | ||||||
| 	IWICBitmapFrameDecode *pSource = nullptr; | 	IWICBitmapFrameDecode *source = nullptr; | ||||||
| 	IWICStream *pStream = nullptr; | 	IWICStream *stream = nullptr; | ||||||
| 	IWICFormatConverter *pConverter = nullptr; | 	IWICFormatConverter *converter = nullptr; | ||||||
| 	ID2D1Bitmap *pBitmap = nullptr; | 	ID2D1Bitmap *bitmap = nullptr; | ||||||
| 	HRSRC imageResHandle = nullptr; | 	HRSRC res_handle = nullptr; | ||||||
| 	HGLOBAL imageResDataHandle = nullptr; | 	HGLOBAL res_data_handle = nullptr; | ||||||
| 	void *pImageFile = nullptr; | 	void *image_file = nullptr; | ||||||
| 	DWORD imageFileSize = 0; | 	DWORD image_file_size = 0; | ||||||
| 
 | 
 | ||||||
| 	// 定位资源
 | 	// 定位资源
 | ||||||
| 	imageResHandle = ::FindResourceW( | 	res_handle = ::FindResourceW( | ||||||
| 		HINST_THISCOMPONENT,  | 		HINST_THISCOMPONENT,  | ||||||
| 		MAKEINTRESOURCE(res.name),  | 		MAKEINTRESOURCE(res.id),  | ||||||
| 		(LPCWSTR)res.type | 		(LPCWSTR)res.type | ||||||
| 	); | 	); | ||||||
| 
 | 
 | ||||||
| 	HRESULT hr = imageResHandle ? S_OK : E_FAIL; | 	HRESULT hr = res_handle ? S_OK : E_FAIL; | ||||||
| 	if (SUCCEEDED(hr)) | 	if (SUCCEEDED(hr)) | ||||||
| 	{ | 	{ | ||||||
| 		// 加载资源
 | 		// 加载资源
 | ||||||
| 		imageResDataHandle = ::LoadResource(HINST_THISCOMPONENT, imageResHandle); | 		res_data_handle = ::LoadResource(HINST_THISCOMPONENT, res_handle); | ||||||
| 
 | 
 | ||||||
| 		hr = imageResDataHandle ? S_OK : E_FAIL; | 		hr = res_data_handle ? S_OK : E_FAIL; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (SUCCEEDED(hr)) | 	if (SUCCEEDED(hr)) | ||||||
| 	{ | 	{ | ||||||
| 		// 获取文件指针,并锁定资源
 | 		// 获取文件指针,并锁定资源
 | ||||||
| 		pImageFile = ::LockResource(imageResDataHandle); | 		image_file = ::LockResource(res_data_handle); | ||||||
| 
 | 
 | ||||||
| 		hr = pImageFile ? S_OK : E_FAIL; | 		hr = image_file ? S_OK : E_FAIL; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (SUCCEEDED(hr)) | 	if (SUCCEEDED(hr)) | ||||||
| 	{ | 	{ | ||||||
| 		// 计算大小
 | 		// 计算大小
 | ||||||
| 		imageFileSize = ::SizeofResource(HINST_THISCOMPONENT, imageResHandle); | 		image_file_size = ::SizeofResource(HINST_THISCOMPONENT, res_handle); | ||||||
| 
 | 
 | ||||||
| 		hr = imageFileSize ? S_OK : E_FAIL; | 		hr = image_file_size ? S_OK : E_FAIL; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (SUCCEEDED(hr)) | 	if (SUCCEEDED(hr)) | ||||||
| 	{ | 	{ | ||||||
| 		// 创建 WIC 流
 | 		// 创建 WIC 流
 | ||||||
| 		hr = pImagingFactory->CreateStream(&pStream); | 		hr = imaging_factory->CreateStream(&stream); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (SUCCEEDED(hr)) | 	if (SUCCEEDED(hr)) | ||||||
| 	{ | 	{ | ||||||
| 		// 初始化流
 | 		// 初始化流
 | ||||||
| 		hr = pStream->InitializeFromMemory( | 		hr = stream->InitializeFromMemory( | ||||||
| 			reinterpret_cast<BYTE*>(pImageFile), | 			reinterpret_cast<BYTE*>(image_file), | ||||||
| 			imageFileSize | 			image_file_size | ||||||
| 		); | 		); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (SUCCEEDED(hr)) | 	if (SUCCEEDED(hr)) | ||||||
| 	{ | 	{ | ||||||
| 		// 创建流的解码器
 | 		// 创建流的解码器
 | ||||||
| 		hr = pImagingFactory->CreateDecoderFromStream( | 		hr = imaging_factory->CreateDecoderFromStream( | ||||||
| 			pStream, | 			stream, | ||||||
| 			nullptr, | 			nullptr, | ||||||
| 			WICDecodeMetadataCacheOnLoad, | 			WICDecodeMetadataCacheOnLoad, | ||||||
| 			&pDecoder | 			&decoder | ||||||
| 		); | 		); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (SUCCEEDED(hr)) | 	if (SUCCEEDED(hr)) | ||||||
| 	{ | 	{ | ||||||
| 		// 创建初始化框架
 | 		// 创建初始化框架
 | ||||||
| 		hr = pDecoder->GetFrame(0, &pSource); | 		hr = decoder->GetFrame(0, &source); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (SUCCEEDED(hr)) | 	if (SUCCEEDED(hr)) | ||||||
| 	{ | 	{ | ||||||
| 		// 创建图片格式转换器
 | 		// 创建图片格式转换器
 | ||||||
| 		hr = pImagingFactory->CreateFormatConverter(&pConverter); | 		hr = imaging_factory->CreateFormatConverter(&converter); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (SUCCEEDED(hr)) | 	if (SUCCEEDED(hr)) | ||||||
| 	{ | 	{ | ||||||
| 		// 图片格式转换成 32bppPBGRA
 | 		// 图片格式转换成 32bppPBGRA
 | ||||||
| 		hr = pConverter->Initialize( | 		hr = converter->Initialize( | ||||||
| 			pSource, | 			source, | ||||||
| 			GUID_WICPixelFormat32bppPBGRA, | 			GUID_WICPixelFormat32bppPBGRA, | ||||||
| 			WICBitmapDitherTypeNone, | 			WICBitmapDitherTypeNone, | ||||||
| 			nullptr, | 			nullptr, | ||||||
|  | @ -256,71 +256,74 @@ bool e2d::Image::Preload(const Resource& res) | ||||||
| 	if (SUCCEEDED(hr)) | 	if (SUCCEEDED(hr)) | ||||||
| 	{ | 	{ | ||||||
| 		// 从 WIC 位图创建一个 Direct2D 位图
 | 		// 从 WIC 位图创建一个 Direct2D 位图
 | ||||||
| 		hr = pRenderTarget->CreateBitmapFromWicBitmap( | 		hr = render_target->CreateBitmapFromWicBitmap( | ||||||
| 			pConverter, | 			converter, | ||||||
| 			nullptr, | 			nullptr, | ||||||
| 			&pBitmap | 			&bitmap | ||||||
| 		); | 		); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (SUCCEEDED(hr)) | 	if (SUCCEEDED(hr)) | ||||||
| 	{ | 	{ | ||||||
| 		bitmap_cache_.insert(std::make_pair(res.name, pBitmap)); | 		bitmap_cache_.insert(std::make_pair(res.id, bitmap)); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// 释放相关资源
 | 	// 释放相关资源
 | ||||||
| 	SafeRelease(pDecoder); | 	SafeRelease(decoder); | ||||||
| 	SafeRelease(pSource); | 	SafeRelease(source); | ||||||
| 	SafeRelease(pStream); | 	SafeRelease(stream); | ||||||
| 	SafeRelease(pConverter); | 	SafeRelease(converter); | ||||||
| 
 | 
 | ||||||
| 	return SUCCEEDED(hr); | 	return SUCCEEDED(hr); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool e2d::Image::Preload(const String & file_name) | bool e2d::Image::Preload(const String & file_name) | ||||||
| { | { | ||||||
| 	String actualFilePath = File(file_name).GetPath(); | 	File image_file; | ||||||
| 	if (actualFilePath.IsEmpty()) | 	if (!image_file.Open(file_name)) | ||||||
| 		return false; | 		return false; | ||||||
| 
 | 
 | ||||||
| 	size_t hash = actualFilePath.GetHash(); | 	// 用户输入的路径不一定是完整路径,因为用户可能通过 File::AddSearchPath 添加
 | ||||||
|  | 	// 默认搜索路径,所以需要通过 File::GetPath 获取完整路径
 | ||||||
|  | 	String image_file_path = image_file.GetPath(); | ||||||
|  | 	size_t hash = image_file_path.GetHash(); | ||||||
| 	if (bitmap_cache_.find(hash) != bitmap_cache_.end()) | 	if (bitmap_cache_.find(hash) != bitmap_cache_.end()) | ||||||
| 		return true; | 		return true; | ||||||
| 
 | 
 | ||||||
| 	IWICImagingFactory *pImagingFactory = Renderer::GetImagingFactory(); | 	IWICImagingFactory *imaging_factory = Renderer::GetImagingFactory(); | ||||||
| 	ID2D1HwndRenderTarget* pRenderTarget = Renderer::GetInstance()->GetRenderTarget(); | 	ID2D1HwndRenderTarget* render_target = Renderer::GetInstance()->GetRenderTarget(); | ||||||
| 	IWICBitmapDecoder *pDecoder = nullptr; | 	IWICBitmadecoder *decoder = nullptr; | ||||||
| 	IWICBitmapFrameDecode *pSource = nullptr; | 	IWICBitmapFrameDecode *source = nullptr; | ||||||
| 	IWICStream *pStream = nullptr; | 	IWICStream *stream = nullptr; | ||||||
| 	IWICFormatConverter *pConverter = nullptr; | 	IWICFormatConverter *converter = nullptr; | ||||||
| 	ID2D1Bitmap *pBitmap = nullptr; | 	ID2D1Bitmap *bitmap = nullptr; | ||||||
| 
 | 
 | ||||||
| 	// 创建解码器
 | 	// 创建解码器
 | ||||||
| 	HRESULT hr = pImagingFactory->CreateDecoderFromFilename( | 	HRESULT hr = imaging_factory->CreateDecoderFromFilename( | ||||||
| 		(LPCWSTR)actualFilePath, | 		(LPCWSTR)image_file_path, | ||||||
| 		nullptr, | 		nullptr, | ||||||
| 		GENERIC_READ, | 		GENERIC_READ, | ||||||
| 		WICDecodeMetadataCacheOnLoad, | 		WICDecodeMetadataCacheOnLoad, | ||||||
| 		&pDecoder | 		&decoder | ||||||
| 	); | 	); | ||||||
| 
 | 
 | ||||||
| 	if (SUCCEEDED(hr)) | 	if (SUCCEEDED(hr)) | ||||||
| 	{ | 	{ | ||||||
| 		// 创建初始化框架
 | 		// 创建初始化框架
 | ||||||
| 		hr = pDecoder->GetFrame(0, &pSource); | 		hr = decoder->GetFrame(0, &source); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (SUCCEEDED(hr)) | 	if (SUCCEEDED(hr)) | ||||||
| 	{ | 	{ | ||||||
| 		// 创建图片格式转换器
 | 		// 创建图片格式转换器
 | ||||||
| 		hr = pImagingFactory->CreateFormatConverter(&pConverter); | 		hr = imaging_factory->CreateFormatConverter(&converter); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (SUCCEEDED(hr)) | 	if (SUCCEEDED(hr)) | ||||||
| 	{ | 	{ | ||||||
| 		// 图片格式转换成 32bppPBGRA
 | 		// 图片格式转换成 32bppPBGRA
 | ||||||
| 		hr = pConverter->Initialize( | 		hr = converter->Initialize( | ||||||
| 			pSource, | 			source, | ||||||
| 			GUID_WICPixelFormat32bppPBGRA, | 			GUID_WICPixelFormat32bppPBGRA, | ||||||
| 			WICBitmapDitherTypeNone, | 			WICBitmapDitherTypeNone, | ||||||
| 			nullptr, | 			nullptr, | ||||||
|  | @ -332,23 +335,23 @@ bool e2d::Image::Preload(const String & file_name) | ||||||
| 	if (SUCCEEDED(hr)) | 	if (SUCCEEDED(hr)) | ||||||
| 	{ | 	{ | ||||||
| 		// 从 WIC 位图创建一个 Direct2D 位图
 | 		// 从 WIC 位图创建一个 Direct2D 位图
 | ||||||
| 		hr = pRenderTarget->CreateBitmapFromWicBitmap( | 		hr = render_target->CreateBitmapFromWicBitmap( | ||||||
| 			pConverter, | 			converter, | ||||||
| 			nullptr, | 			nullptr, | ||||||
| 			&pBitmap | 			&bitmap | ||||||
| 		); | 		); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (SUCCEEDED(hr)) | 	if (SUCCEEDED(hr)) | ||||||
| 	{ | 	{ | ||||||
| 		bitmap_cache_.insert(std::make_pair(hash, pBitmap)); | 		bitmap_cache_.insert(std::make_pair(hash, bitmap)); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// 释放相关资源
 | 	// 释放相关资源
 | ||||||
| 	SafeRelease(pDecoder); | 	SafeRelease(decoder); | ||||||
| 	SafeRelease(pSource); | 	SafeRelease(source); | ||||||
| 	SafeRelease(pStream); | 	SafeRelease(stream); | ||||||
| 	SafeRelease(pConverter); | 	SafeRelease(converter); | ||||||
| 
 | 
 | ||||||
| 	return SUCCEEDED(hr); | 	return SUCCEEDED(hr); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -40,11 +40,11 @@ bool e2d::File::Open(const String & file_name) | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| 		for (const auto& resPath : search_paths_) | 		for (const auto& path : search_paths_) | ||||||
| 		{ | 		{ | ||||||
| 			if (FindFile(resPath + file_name)) | 			if (FindFile(path + file_name)) | ||||||
| 			{ | 			{ | ||||||
| 				file_path_ = resPath + file_name; | 				file_path_ = path + file_name; | ||||||
| 				return true; | 				return true; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -10,15 +10,15 @@ | ||||||
| #define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p); (p)=nullptr; } } | #define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p); (p)=nullptr; } } | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| inline bool TraceError(wchar_t* sPrompt) | inline bool TraceError(wchar_t* prompt) | ||||||
| { | { | ||||||
| 	WARN("MusicInfo error: %s failed!", sPrompt); | 	WARN("Music error: %s failed!", prompt); | ||||||
| 	return false; | 	return false; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| inline bool TraceError(wchar_t* sPrompt, HRESULT hr) | inline bool TraceError(wchar_t* prompt, HRESULT hr) | ||||||
| { | { | ||||||
| 	WARN("MusicInfo error: %s (%#X)", sPrompt, hr); | 	WARN("Music error: %s (%#X)", prompt, hr); | ||||||
| 	return false; | 	return false; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -75,20 +75,24 @@ bool e2d::Music::Open(const e2d::String & file_path) | ||||||
| 
 | 
 | ||||||
| 	if (file_path.IsEmpty()) | 	if (file_path.IsEmpty()) | ||||||
| 	{ | 	{ | ||||||
| 		WARN("MusicInfo::Open Invalid file name."); | 		WARN("Music::Open error: Invalid file name."); | ||||||
| 		return false; | 		return false; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	String actualFilePath = File(file_path).GetPath(); | 	File music_file; | ||||||
| 	if (actualFilePath.IsEmpty()) | 	if (!music_file.Open(file_name)) | ||||||
| 	{ | 	{ | ||||||
| 		WARN("MusicInfo::Open File not found."); | 		WARN("Music::Open error: File not found."); | ||||||
| 		return false; | 		return false; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	// 用户输入的路径不一定是完整路径,因为用户可能通过 File::AddSearchPath 添加
 | ||||||
|  | 	// 默认搜索路径,所以需要通过 File::GetPath 获取完整路径
 | ||||||
|  | 	String music_file_path = music_file.GetPath(); | ||||||
|  | 
 | ||||||
| 	// ¶¨Î» wave Îļþ
 | 	// ¶¨Î» wave Îļþ
 | ||||||
| 	wchar_t pFilePath[MAX_PATH]; | 	wchar_t pFilePath[MAX_PATH]; | ||||||
| 	if (!FindMediaFileCch(pFilePath, MAX_PATH, (const wchar_t *)actualFilePath)) | 	if (!FindMediaFileCch(pFilePath, MAX_PATH, (const wchar_t *)music_file_path)) | ||||||
| 	{ | 	{ | ||||||
| 		WARN("Failed to Find media file: %s", pFilePath); | 		WARN("Failed to Find media file: %s", pFilePath); | ||||||
| 		return false; | 		return false; | ||||||
|  | @ -151,7 +155,7 @@ bool e2d::Music::Open(const Resource& res) | ||||||
| 	DWORD dwSize; | 	DWORD dwSize; | ||||||
| 	void* pvRes; | 	void* pvRes; | ||||||
| 
 | 
 | ||||||
| 	if (nullptr == (hResInfo = FindResourceW(HINST_THISCOMPONENT, MAKEINTRESOURCE(res.name), (LPCWSTR)res.type))) | 	if (nullptr == (hResInfo = FindResourceW(HINST_THISCOMPONENT, MAKEINTRESOURCE(res.id), (LPCWSTR)res.type))) | ||||||
| 		return TraceError(L"FindResource"); | 		return TraceError(L"FindResource"); | ||||||
| 
 | 
 | ||||||
| 	if (nullptr == (hResData = LoadResource(HINST_THISCOMPONENT, hResInfo))) | 	if (nullptr == (hResData = LoadResource(HINST_THISCOMPONENT, hResInfo))) | ||||||
|  |  | ||||||
|  | @ -121,7 +121,7 @@ bool e2d::Player::IsPlaying(const String & file_path) | ||||||
| 
 | 
 | ||||||
| bool e2d::Player::Preload(const Resource& res) | bool e2d::Player::Preload(const Resource& res) | ||||||
| { | { | ||||||
| 	if (musics_.end() != musics_.find(res.name)) | 	if (musics_.end() != musics_.find(res.id)) | ||||||
| 		return true; | 		return true; | ||||||
| 
 | 
 | ||||||
| 	Music * music = new (std::nothrow) Music(); | 	Music * music = new (std::nothrow) Music(); | ||||||
|  | @ -133,7 +133,7 @@ bool e2d::Player::Preload(const Resource& res) | ||||||
| 		if (music->Open(res)) | 		if (music->Open(res)) | ||||||
| 		{ | 		{ | ||||||
| 			music->SetVolume(volume_); | 			music->SetVolume(volume_); | ||||||
| 			musics_.insert(std::make_pair(res.name, music)); | 			musics_.insert(std::make_pair(res.id, music)); | ||||||
| 			return true; | 			return true; | ||||||
| 		} | 		} | ||||||
| 		else | 		else | ||||||
|  | @ -148,7 +148,7 @@ bool e2d::Player::Play(const Resource& res, int loop_count) | ||||||
| { | { | ||||||
| 	if (Player::Preload(res)) | 	if (Player::Preload(res)) | ||||||
| 	{ | 	{ | ||||||
| 		auto music = musics_[res.name]; | 		auto music = musics_[res.id]; | ||||||
| 		if (music->Play(loop_count)) | 		if (music->Play(loop_count)) | ||||||
| 		{ | 		{ | ||||||
| 			return true; | 			return true; | ||||||
|  | @ -159,26 +159,26 @@ bool e2d::Player::Play(const Resource& res, int loop_count) | ||||||
| 
 | 
 | ||||||
| void e2d::Player::Pause(const Resource& res) | void e2d::Player::Pause(const Resource& res) | ||||||
| { | { | ||||||
| 	if (musics_.end() != musics_.find(res.name)) | 	if (musics_.end() != musics_.find(res.id)) | ||||||
| 		musics_[res.name]->Pause(); | 		musics_[res.id]->Pause(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::Player::Resume(const Resource& res) | void e2d::Player::Resume(const Resource& res) | ||||||
| { | { | ||||||
| 	if (musics_.end() != musics_.find(res.name)) | 	if (musics_.end() != musics_.find(res.id)) | ||||||
| 		musics_[res.name]->Resume(); | 		musics_[res.id]->Resume(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::Player::Stop(const Resource& res) | void e2d::Player::Stop(const Resource& res) | ||||||
| { | { | ||||||
| 	if (musics_.end() != musics_.find(res.name)) | 	if (musics_.end() != musics_.find(res.id)) | ||||||
| 		musics_[res.name]->Stop(); | 		musics_[res.id]->Stop(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool e2d::Player::IsPlaying(const Resource& res) | bool e2d::Player::IsPlaying(const Resource& res) | ||||||
| { | { | ||||||
| 	if (musics_.end() != musics_.find(res.name)) | 	if (musics_.end() != musics_.find(res.id)) | ||||||
| 		return musics_[res.name]->IsPlaying(); | 		return musics_[res.id]->IsPlaying(); | ||||||
| 	return false; | 	return false; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,8 +1,8 @@ | ||||||
| #include "..\e2dtool.h" | #include "..\e2dtool.h" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| e2d::Resource::Resource(size_t resource_name, const String & resource_type) | e2d::Resource::Resource(int resource_id, const String & resource_type) | ||||||
| 	: name(resource_name) | 	: id(resource_id) | ||||||
| 	, type(resource_type) | 	, type(resource_type) | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue