D3D盗墓笔记

来源:互联网 发布:ntfs for mac 破解版 编辑:程序博客网 时间:2024/04/25 23:41

D3D盗墓笔记

呵呵,既然最近在看鬼吹灯,又在学D3D,同时有做最近这个游戏项目中一些比较简单的工作,闲暇时间,便找写代码和知识过来

前文我是已经模糊不清,只能从中间开始

#if defined(DEBUG) | defined(_DEBUG) 

#ifndef HR                                           

#define HR(x)                                        /

{                                                   /

HRESULT hr = x;                                     /

if(FAILED(hr))                                       /

{                                                   /

DXTrace(__FILE__, __LINE__, hr, #x, TRUE);             /

}                                                   /

}                                                  /

#endif 

#else 

#ifndef HR 

#define HR(x) x;

#endif #endif 

用这种方法就可以用少量的代码来控制错误异常这些内容了。

例如HR(D3DXCreateFontIndirect(gd3dDevice, &fontDesc, &mFont));

这样看上去貌似节省了很多的代码,同时也使得代码的复杂度大大的降低了,更容易让人理解其中的内容了。宏定义的使用还是有很重要的作用的。

Observe that we pass #x into the fourth parameter; this turns the HR macro's argument token into a string. In this way, we can output the function call that caused the error; see Figure 4.14 (in particular, the "Calling: D3DXCreateFontIndirect…," which corresponds to this fourth parameter of DXTrace).

By construction, the HR macro only does anything in debug mode. This is fine, because by the time we are shipping an application, all the Direct3D bugs should be worked out.

HR needs to be a macro and not a function, because if it were a function, __FlLE__ and __LINE__ would refer to the file and line of the function implementation, and not the file and line where the function HR was called. So we need a macro so that the code is actually substituted into the place where we write HR. 

这些是写什么意思,自己理解便是。

原创粉丝点击