Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

185 lines
6.9 KiB

  1. /*****************************************************************************\
  2. FILE: util.h
  3. DESCRIPTION:
  4. BryanSt 12/22/2000
  5. Copyright (C) Microsoft Corp 2000-2001. All rights reserved.
  6. \*****************************************************************************/
  7. #ifndef UTIL_H
  8. #define UTIL_H
  9. #ifndef ARRAYSIZE
  10. #define ARRAYSIZE(a) (sizeof(a)/sizeof(*a))
  11. #endif
  12. //-----------------------------------------------------------------------------
  13. // Name: enum CULLSTATE
  14. // Desc: Represents the result of the culling calculation on an object.
  15. //-----------------------------------------------------------------------------
  16. enum CULLSTATE
  17. {
  18. CS_UNKNOWN, // cull state not yet computed
  19. CS_INSIDE, // object bounding box is at least partly inside the frustum
  20. CS_OUTSIDE, // object bounding box is outside the frustum
  21. CS_INSIDE_SLOW, // OBB is inside frustum, but it took extensive testing to determine this
  22. CS_OUTSIDE_SLOW, // OBB is outside frustum, but it took extensive testing to determine this
  23. };
  24. //-----------------------------------------------------------------------------
  25. // Name: struct CULLINFO
  26. // Desc: Stores information that will be used when culling objects. It needs
  27. // to be recomputed whenever the view matrix or projection matrix changes.
  28. //-----------------------------------------------------------------------------
  29. struct CULLINFO
  30. {
  31. D3DXVECTOR3 vecFrustum[8]; // corners of the view frustum
  32. D3DXPLANE planeFrustum[6]; // planes of the view frustum
  33. D3DXVECTOR3 vecFrustumCenter; // center of the view frustum
  34. };
  35. #include "main.h"
  36. #define HINST_THISDLL g_hMainInstance
  37. extern BOOL g_fOverheadViewTest;
  38. extern HINSTANCE g_hMainInstance;
  39. void FloatToString(float fValue, int nDecimalDigits, LPTSTR pszString, DWORD cchSize);
  40. void PrintLocation(LPTSTR pszTemplate, D3DXVECTOR3 vLoc, D3DXVECTOR3 vTangent);
  41. HRESULT SetBoxStripVertexes(MYVERTEX * ppvVertexs, D3DXVECTOR3 vLocation, D3DXVECTOR3 vSize, D3DXVECTOR3 vNormal);
  42. float GetSurfaceRatio(IDirect3DTexture8 * pTexture);
  43. float AddVectorComponents(D3DXVECTOR3 vDir);
  44. int CALLBACK DPALocalFree_Callback(LPVOID p, LPVOID pData);
  45. int CALLBACK DPAStrCompare(void * pv1, void * pv2, LPARAM lParam);
  46. BOOL Is3DRectViewable(CULLINFO* pCullInfo, D3DXMATRIX* pMatWorld,
  47. D3DXVECTOR3 vMin, D3DXVECTOR3 vMax);
  48. int GetTextureHeight(IDirect3DTexture8 * pTexture);
  49. int GetTextureWidth(IDirect3DTexture8 * pTexture);
  50. BOOL PathDeleteDirectoryRecursively(LPCTSTR pszDir);
  51. ULONGLONG PathGetFileSize(LPCTSTR pszPath);
  52. int GetRandomInt(int nMin, int nMax);
  53. HRESULT GetCurrentUserCustomName(LPWSTR pszDisplayName, DWORD cchSize);
  54. HRESULT ShellFolderParsePath(LPCWSTR pszPath, LPITEMIDLIST * ppidl);
  55. HRESULT ShellFolderGetPath(LPCITEMIDLIST pidl, LPWSTR pszPath, DWORD cchSize);
  56. // Reg Wrappers
  57. HRESULT HrRegOpenKeyEx(HKEY hKey, LPCTSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult);
  58. HRESULT HrRegCreateKeyEx(HKEY hKey, LPCTSTR lpSubKey, DWORD Reserved, LPTSTR lpClass, DWORD dwOptions,
  59. REGSAM samDesired, LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition);
  60. HRESULT HrRegGetDWORD(IN HKEY hKey, IN LPCTSTR pszSubKey, OPTIONAL IN LPCTSTR pszValue, LPDWORD pdwValue, DWORD dwDefaultValue);
  61. HRESULT HrRegSetDWORD(IN HKEY hKey, IN LPCTSTR pszSubKey, OPTIONAL IN LPCTSTR pszValue, DWORD dwValue);
  62. HRESULT HrRegGetValueString(IN HKEY hKey, IN LPCTSTR pszSubKey, IN LPCTSTR pszValueName, IN LPWSTR pszString, IN DWORD cchSize);
  63. HRESULT HrRegSetValueString(IN HKEY hKey, IN LPCTSTR pszSubKey, IN LPCTSTR pszValueName, OUT LPCWSTR pszString);
  64. // UI Wrappers
  65. void SetCheckBox(HWND hwndDlg, UINT idControl, BOOL fChecked);
  66. BOOL GetCheckBox(HWND hwndDlg, UINT idControl);
  67. // Prototypes for the culling functions
  68. VOID UpdateCullInfo( CULLINFO* pCullInfo, D3DXMATRIX* pMatView, D3DXMATRIX* pMatProj );
  69. CULLSTATE CullObject( CULLINFO* pCullInfo, D3DXVECTOR3* pVecBounds, D3DXPLANE* pPlaneBounds );
  70. BOOL EdgeIntersectsFace( D3DXVECTOR3* pEdges, D3DXVECTOR3* pFaces, D3DXPLANE* pPlane );
  71. // Other
  72. void DebugStartWatch(void);
  73. DWORD DebugStopWatch(void);
  74. D3DXVECTOR3 D3DXVec3Multiply(CONST D3DXVECTOR3 v1, CONST D3DXVECTOR3 v2);
  75. typedef struct
  76. {
  77. float fTimeToRotate;
  78. float fTimeToWalk;
  79. float fTimeToLookAtPaintings;
  80. int nMinTurnFrames;
  81. int nMinWalkFrames;
  82. int nMaxTurnFrames;
  83. int nMaxWalkFrames;
  84. } SPEED_SETTING;
  85. #define MAX_SPEED 11
  86. extern SPEED_SETTING s_SpeedSettings[MAX_SPEED];
  87. #define TaskBar_SetRange(hwndControl, fRedraw, nMin, nMax) SendMessage(hwndControl, TBM_SETRANGE, (WPARAM) (BOOL) fRedraw, (LPARAM) MAKELONG(nMin, nMax))
  88. #define TaskBar_SetPos(hwndControl, fRedraw, nPosition) SendMessage(hwndControl, TBM_SETPOS, (WPARAM) (BOOL) fRedraw, (LPARAM) (LONG) nPosition)
  89. #define TaskBar_GetPos(hwndControl) (int) SendMessage(hwndControl, TBM_GETPOS, 0, 0)
  90. float rnd(void);
  91. #define ABS(i) (((i) < 0) ? -(i) : (i))
  92. //------------------------------------------------------------------------
  93. ////////////////
  94. //
  95. // Critical section stuff
  96. //
  97. // Helper macros that give nice debug support
  98. //
  99. EXTERN_C CRITICAL_SECTION g_csDll;
  100. #ifdef DEBUG
  101. EXTERN_C UINT g_CriticalSectionCount;
  102. EXTERN_C DWORD g_CriticalSectionOwner;
  103. EXTERN_C void Dll_EnterCriticalSection(CRITICAL_SECTION*);
  104. EXTERN_C void Dll_LeaveCriticalSection(CRITICAL_SECTION*);
  105. #if defined(__cplusplus) && defined(AssertMsg)
  106. class DEBUGCRITICAL {
  107. protected:
  108. BOOL fClosed;
  109. public:
  110. DEBUGCRITICAL() {fClosed = FALSE;};
  111. void Leave() {fClosed = TRUE;};
  112. ~DEBUGCRITICAL()
  113. {
  114. AssertMsg(fClosed, TEXT("you left scope while holding the critical section"));
  115. }
  116. };
  117. #define ENTERCRITICAL DEBUGCRITICAL debug_crit; Dll_EnterCriticalSection(&g_csDll)
  118. #define LEAVECRITICAL debug_crit.Leave(); Dll_LeaveCriticalSection(&g_csDll)
  119. #define ENTERCRITICALNOASSERT Dll_EnterCriticalSection(&g_csDll)
  120. #define LEAVECRITICALNOASSERT Dll_LeaveCriticalSection(&g_csDll)
  121. #else // __cplusplus
  122. #define ENTERCRITICAL Dll_EnterCriticalSection(&g_csDll)
  123. #define LEAVECRITICAL Dll_LeaveCriticalSection(&g_csDll)
  124. #define ENTERCRITICALNOASSERT Dll_EnterCriticalSection(&g_csDll)
  125. #define LEAVECRITICALNOASSERT Dll_LeaveCriticalSection(&g_csDll)
  126. #endif // __cplusplus
  127. #define ASSERTCRITICAL ASSERT(g_CriticalSectionCount > 0 && GetCurrentThreadId() == g_CriticalSectionOwner)
  128. #define ASSERTNONCRITICAL ASSERT(GetCurrentThreadId() != g_CriticalSectionOwner)
  129. #else // DEBUG
  130. #define ENTERCRITICAL EnterCriticalSection(&g_csDll)
  131. #define LEAVECRITICAL LeaveCriticalSection(&g_csDll)
  132. #define ENTERCRITICALNOASSERT EnterCriticalSection(&g_csDll)
  133. #define LEAVECRITICALNOASSERT LeaveCriticalSection(&g_csDll)
  134. #define ASSERTCRITICAL
  135. #define ASSERTNONCRITICAL
  136. #endif // DEBUG
  137. #endif // UTIL_H