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

📄 resource.h

📁 游戏框架
💻 H
字号:
// ***************************************************************
//  Resource   version:  1.0
//  -------------------------------------------------------------
//	File Name:	Resource.h
//	Created:	2007/07/19
//	Modified:	2007/07/19   23:22
//	Author:		William.Liang
//  Msn:		lwq49@msn.com
//  Email:		lwq49@21cn.com, lwq49@msn.com
//	Description:
//
//	Purpose:	
//  -------------------------------------------------------------
//  license:
//
//  The contents of this file are subject to the Mozilla Public
//  License Version 1.1 (the "License"); you may not use this file
//  except in compliance with the License. You may obtain a copy
//  of the License at http://www.mozilla.org/MPL/ Software dis-
//  tributed under the License is distributed on an "AS IS" 
//  basis, WITHOUT WARRANTY OF ANY KIND, either express or im-
//  plied. See the License for the specific language governing
//  rights and limitations under the License.
//
//  The Initial Developer of the Original Code is William.Liang .
//  Copyright (C) 2007 - All Rights Reserved.
// ***************************************************************
#ifndef RESOURCE_HEAD_FILE
#define RESOURCE_HEAD_FILE

#pragma once
#include "stdafx.h"
#include "..\Common\Common.h"

#define RBB_COPY	1
#define RBB_XOR		2
#define RBB_AND		4
#define RBB_OR		8

#define RBB_TILE	16
#define RBB_REVE_W	32
#define RBB_REVE_H	64

//导出定义
#ifndef OBJECT_COM_CLASS
	#ifdef  OBJECT_COM_DLL
		#define OBJECT_COM_CLASS _declspec(dllexport)
	#else
		#define OBJECT_COM_CLASS _declspec(dllimport)
	#endif
#endif

enum enResourceType{
	Resource_Picture,
	Resource_Music,
	Resource_Stream,
	Resource_Effect,
	Resource_Reserve,
};

enum enFileType{
	Resource_BMP,
	Resource_PNG,
	Resource_JPG,
	Resource_DDS,
	Resource_DIB,
	Resource_TGA,
	Resource_UnKnown,
	Resource_MP3,
	Resource_MP1,
	Resource_MP2,
	Resource_WAV,
	Resource_OGG,
};

typedef DWORD LPRESOURCE;

class OBJECT_COM_CLASS CResource
{
private:
	LPGDI			m_lpGDI;				//图形引擎
	_CString			m_szFileName;			//资源文件名

	LPRESOURCE		m_hResource;			//纹理指针
	enResourceType	m_enType;				//资源类型
	enFileType		m_enFileType;			//文件类型

	WORD			m_wStatus;				//当前状态(0 加载失败 1 加载中 2 卸载)

public:
	//构造函数
	CResource(CResource* pResource);
	CResource(LPGDI lpGDI, _SIZE siSize);
	CResource(_CString szFileName, LPGDI lpGDI, enResourceType ResourceType=Resource_Picture);
	//析构函数
	virtual ~CResource();

	//返回资源
	virtual LPRESOURCE __cdecl GetResourcePoint();
	//返回纹理
	virtual HTEXTURE __cdecl GetTexture();
	//返回效果
	virtual HEFFECT __cdecl GetEffect();
	//返回音乐
	virtual HMUSIC __cdecl GetMusic();
	//返回流
	virtual HSTREAM __cdecl GetStream();
	//重新加载
	virtual BOOL __cdecl ReLoad();
	//释放资源的内存占用
	virtual BOOL __cdecl Free();
	//返回资源状态
	virtual WORD __cdecl GetStatus();
	//返回规格
	virtual _SIZE __cdecl GetSize();
	//返回文件名
	virtual _CString __cdecl GetFileName();
	//返回文件类型
	virtual enFileType __cdecl GetFileType();
	//返回长度
	virtual DWORD __cdecl GetFileLength();
	//返回类型
	virtual enResourceType __cdecl GetType();
	//返回GDI指针
	virtual LPGDI __cdecl GetGDI();
	//是否已知格式
	virtual bool __cdecl IsKnownFormat();
	//是否声音资源
	virtual bool __cdecl IsSound();
	//是否图像资源
	virtual bool __cdecl IsPicture();
	//内存写入
	virtual bool __cdecl Bitblt(CResource* pResource, _RECT* pSource=NULL, _RECT* pTarget=NULL, DWORD dwFlag=RBB_COPY|RBB_TILE|RBB_REVE_W|RBB_REVE_H);

private:
	inline void CopyMemoryRect(DWORD* pTarget, DWORD* pSource, DWORD dwRectWidth, DWORD dwRectHeight, DWORD dwTargetWidth, DWORD dwSourceWidth, DWORD dwFlag){
		WORD	wFlag = (WORD)(dwFlag&0xF);
		for(DWORD dwPixalRow=0;dwPixalRow<dwRectHeight;dwPixalRow++){
			// 写像素列
			for(DWORD dwPixalCol=0;dwPixalCol<dwRectWidth;dwPixalCol++){
				switch(wFlag){
					case RBB_XOR:
						*pTarget++ ^= *pSource++;
						break;
					case RBB_AND:
						*pTarget++ &= *pSource++;
						break;
					case RBB_OR:
						*pTarget++ |= *pSource++;
						break;
					default:
						*pTarget++ = *pSource++;
				}
			}
			// 重置下一行头部
			pTarget += (dwTargetWidth-dwRectWidth);
			pSource += (dwSourceWidth-dwRectWidth);
		}
	};
	inline void Exchange(float &a, float &b){
		float c = a; a = b; b = c;
	};
};

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -