DXGL r379 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r378‎ | r379 | r380 >
Date:01:28, 24 May 2013
Author:admin
Status:new
Tags:
Comment:
Add CTRL+Break hotkey to Debug and Debug Trace builds.
In Debug build, hotkey triggers a breakpoint.
In Debug Trace build, hotkey stops writing to the dxgl.log trace log.
Modified paths:
  • /ddraw/glRenderWindow.cpp (modified) (history)
  • /ddraw/trace.cpp (modified) (history)
  • /ddraw/trace.h (modified) (history)

Diff [purge]

Index: ddraw/glRenderWindow.cpp
@@ -23,6 +23,9 @@
2424
2525 WNDCLASSEXA wndclass;
2626 bool wndclasscreated = false;
 27+#ifdef _DEBUG
 28+bool hotkeyregistered = false;
 29+#endif
2730
2831 void WaitForObjectAndMessages(HANDLE object)
2932 {
@@ -100,6 +103,10 @@
101104 "DXGLRenderWindow","Renderer",WS_POPUP,0,0,width,height,0,0,NULL,this);
102105 SetWindowPos(hWnd,HWND_TOP,0,0,width,height,SWP_SHOWWINDOW|SWP_NOACTIVATE);
103106 }
 107+ #ifdef _DEBUG
 108+ if(RegisterHotKey(hWnd,1,MOD_CONTROL,VK_CANCEL)) hotkeyregistered = true;
 109+ else Beep(120,1000);
 110+ #endif
104111 SetEvent(ReadyEvent);
105112 while((GetMessage(&Msg, NULL, 0, 0) > 0) && !dead)
106113 {
@@ -111,11 +118,22 @@
112119
113120 glRenderWindow::~glRenderWindow()
114121 {
 122+ #ifdef _DEBUG
 123+ if(hotkeyregistered) UnregisterHotKey(hWnd,1);
 124+ #endif
115125 SendMessage(hWnd,WM_CLOSE,0,0);
116126 WaitForSingleObject(hThread,INFINITE);
117127 CloseHandle(hThread);
118128 }
119129
 130+#ifdef _TRACE
 131+DWORD WINAPI BeepThread(void *unused)
 132+{
 133+ Beep(3600,150);
 134+ return 0;
 135+}
 136+#endif
 137+
120138 LRESULT glRenderWindow::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
121139 {
122140 int oldx,oldy;
@@ -179,6 +197,18 @@
180198 PostQuitMessage(0);
181199 dead = true;
182200 return 0;
 201+ #ifdef _DEBUG
 202+ case WM_HOTKEY:
 203+ #ifdef _TRACE
 204+ trace_end = true;
 205+ CreateThread(NULL,0,BeepThread,NULL,0,NULL);
 206+ UnregisterHotKey(hWnd,1);
 207+ hotkeyregistered = false;
 208+ #else
 209+ Beep(3600,150);
 210+ DebugBreak();
 211+ #endif
 212+ #endif
183213 default:
184214 return DefWindowProc(hwnd,msg,wParam,lParam);
185215 }
Index: ddraw/trace.cpp
@@ -16,6 +16,7 @@
1717 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
1919 #include "common.h"
 20+#include "trace.h"
2021
2122 /* Data types:
2223 -1 - C++ constructor/destructor
@@ -56,6 +57,7 @@
5758 static CRITICAL_SECTION trace_cs;
5859 static bool trace_ready = false;
5960 static bool trace_fail = false;
 61+bool trace_end = false;
6062 static HANDLE outfile = INVALID_HANDLE_VALUE;
6163 unsigned int trace_depth = 0;
6264 static void trace_decode_hresult(HRESULT hr)
@@ -1043,11 +1045,25 @@
10441046 break;
10451047 }
10461048 }
 1049+static void end_trace()
 1050+{
 1051+ DWORD byteswritten;
 1052+ WriteFile(outfile,"Trace cancelled by CTRL+Break\r\n",31,&byteswritten,NULL);
 1053+ CloseHandle(outfile);
 1054+ outfile = INVALID_HANDLE_VALUE;
 1055+ trace_fail = true;
 1056+}
10471057 void trace_enter(const char *function, int paramcount, ...)
10481058 {
10491059 if(trace_fail) return;
10501060 if(!trace_ready) init_trace();
10511061 EnterCriticalSection(&trace_cs);
 1062+ if(trace_end)
 1063+ {
 1064+ end_trace();
 1065+ LeaveCriticalSection(&trace_cs);
 1066+ return;
 1067+ }
10521068 va_list args;
10531069 va_start(args,paramcount);
10541070 DWORD byteswritten;
@@ -1070,6 +1086,12 @@
10711087 if(trace_fail) return;
10721088 if(!trace_ready) init_trace();
10731089 EnterCriticalSection(&trace_cs);
 1090+ if(trace_end)
 1091+ {
 1092+ end_trace();
 1093+ LeaveCriticalSection(&trace_cs);
 1094+ return;
 1095+ }
10741096 if(trace_depth) trace_depth--;
10751097 DWORD byteswritten;
10761098 for(unsigned int i = 0; i < trace_depth; i++)
@@ -1090,6 +1112,12 @@
10911113 if(trace_fail) return;
10921114 if(!trace_ready) init_trace();
10931115 EnterCriticalSection(&trace_cs);
 1116+ if(trace_end)
 1117+ {
 1118+ end_trace();
 1119+ LeaveCriticalSection(&trace_cs);
 1120+ return;
 1121+ }
10941122 DWORD byteswritten;
10951123 for(unsigned int i = 0; i < trace_depth-1; i++)
10961124 WriteFile(outfile," ",4,&byteswritten,NULL);
@@ -1107,6 +1135,12 @@
11081136 if(trace_fail) return;
11091137 if(!trace_ready) init_trace();
11101138 EnterCriticalSection(&trace_cs);
 1139+ if(trace_end)
 1140+ {
 1141+ end_trace();
 1142+ LeaveCriticalSection(&trace_cs);
 1143+ return;
 1144+ }
11111145 DWORD byteswritten;
11121146 OSVERSIONINFOA osver;
11131147 DWORD buildver;
Index: ddraw/trace.h
@@ -21,6 +21,7 @@
2222
2323
2424 #ifdef _TRACE
 25+extern bool trace_end;
2526 #define TRACE_ENTER(paramcount,...) trace_enter(__FUNCTION__,paramcount,__VA_ARGS__)
2627 #define TRACE_EXIT(argtype,arg) trace_exit(__FUNCTION__,argtype,(void*)arg)
2728 #define TRACE_VAR(var,argtype,arg) trace_var(__FUNCTION__,var,argtype,(void*)arg)