D3D盜墓筆記

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. 

這些是寫什麼意思,自己理解便是。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章