-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebug.cpp
90 lines (66 loc) · 2.11 KB
/
Debug.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//------------------------------------------------------------------------------------------------
//
// Written by Lucky K.
//
//------------------------------------------------------------------------------------------------
#include "Debug.h"
namespace Debug
{
//////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Internal Globals
//
//////////////////////////////////////////////////////////////////////////////////////////////////////
HANDLE hFile = INVALID_HANDLE_VALUE;
HANDLE hTmsgFile = INVALID_HANDLE_VALUE;
TCHAR temp[1024];
LARGE_INTEGER start;
LARGE_INTEGER freq;
LARGE_INTEGER finish;
//////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Methods
//
//////////////////////////////////////////////////////////////////////////////////////////////////////
bool Initialize()
{
if ( (hFile = CreateFile( _T("log6572.log"), GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, NULL, NULL )) == INVALID_HANDLE_VALUE )
goto Fail;
if ( (hTmsgFile = CreateFile( _T("Hellfish.xml"), GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, NULL, NULL )) == INVALID_HANDLE_VALUE )
goto Fail;
QueryPerformanceFrequency( &freq );
freq.QuadPart /= 1000;
return true;
Fail:
return false;
}
void _cdecl Error( const TCHAR *str, ... )
{
DWORD dwBytesWritten = 0;
va_list arglist;
va_start( arglist, str );
dwBytesWritten = _vstprintf( temp, str, arglist );
WriteFile( hFile, temp, _tcslen(temp), &dwBytesWritten, NULL );
//_tprintf( temp );
//FlushFileBuffers( hFile );
va_end( arglist );
}
void _cdecl TMSG( const TCHAR *str, ... )
{
DWORD dwBytesWritten = 0;
va_list arglist;
va_start( arglist, str );
dwBytesWritten = _vstprintf( temp, str, arglist );
WriteFile( hTmsgFile, temp, _tcslen(temp), &dwBytesWritten, NULL );
va_end( arglist );
}
void StartTime()
{
QueryPerformanceCounter( &start );
}
void StopTime()
{
QueryPerformanceCounter( &finish );
Error( _T("Time: %f\n"), ((float)(finish.QuadPart - start.QuadPart) / (float)freq.QuadPart) );
}
}