📄 debug.cpp
字号:
#include "debug.h"
#include <fstream>
#include <cstdio>
#include <windows.h>
#include "../opengl/opengl.h"
#include "../global.h"
using namespace std;
////////////////////////////////////////////////////////////////////////////////
// Initialized here because a CERTAIN compiler refuses to do it in-class
__int64 GcDebug::memoryUsed = 0;
unsigned int GcDebug::numAllocated = 0;
unsigned int GcDebug::numDeallocated = 0;
////////////////////////////////////////////////////////////////////////////////
GcDebug::GcDebug()
{
fileName[0] = '\0';
m_debugConsole = NULL;
m_debugConsole = new GcDebugConsole("Debug console");
}
//////////////////////////////////////////////////////////////////////////
GcDebug::~GcDebug()
{
Log("Allocated: %i times \nDeallocated: %i times", numAllocated, numDeallocated);
_DELETEP(m_debugConsole)
}
//////////////////////////////////////////////////////////////////////////
void GcDebug::GetInfo()
{
// Log the computer information (cpu speed, win version etc)
comp.LogCompCharac();
}
//////////////////////////////////////////////////////////////////////////
void GcDebug::Report(char * string, ...)
{
char buffer[128];
va_list arglist;
HWND hwnd = NULL;
if(g_OpenGL) {
hwnd = g_OpenGL->GetWindowHandle();
}
va_start(arglist, string);
vsprintf(buffer, string, arglist);
va_end(arglist);
MessageBox(hwnd, buffer, "Information", MB_OK | MB_ICONINFORMATION );
}
////////////////////////////////////////////////////////////////////////////////
/*
void GcDebug::Report( MsgType type, char * string, ... )
{
char buffer[128];
va_list arglist;
HWND hwnd = GcOpenGL::GetSingletonPtr()->GetWindowHandle();
va_start(arglist, string);
vsprintf(buffer, string, arglist);
va_end(arglist);
switch( type )
{
case INFO: MessageBox(hwnd, buffer, "Information", MB_OK | MB_ICONINFORMATION ); break;
case ERROR: MessageBox(hwnd, buffer, "Error!", MB_OK | MB_ICONSTOP ); break;
}
}
*/
//////////////////////////////////////////////////////////////////////////
bool GcDebug::Log(char * string, ...)
{
char buffer[80]; // Working buffer
va_list arglist; // Variable argument list
FILE * file;
if( fileName[0] == '\0' )
{
file = fopen("logfil.log", "w");
strcpy(fileName, "logfil.log");
}
else {
file = fopen(fileName, "a");
}
if(!file) {
return false;
}
// Make sure the string is valid
if(!string)
{
fclose(file);
return false;
}
// Print out the string using the variable number of arguments on stack
va_start(arglist,string);
vsprintf(buffer,string,arglist);
va_end(arglist);
//strcat(buffer, "\n");
// Write string to file
fprintf(file, buffer);
fclose(file);
return true;
}
////////////////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#include <stdio.h>
#include <stdarg.h>
#include <windows.h>
#include "debug.h"
void _assert( int expression )
{
//if( expression )
// return;
char out[1024];
sprintf(out, "File: %s\nLine: %s\n", __FILE__, __LINE__);
MessageBox(NULL, out, "ERROR!", MB_OK | MB_ICONERROR);
}
void _trace( char *fmt, ... )
{
char out[1024];
va_list body;
va_start(body, fmt);
vsprintf(out, fmt, body);
va_end(body);
OutputDebugString(out);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -