www.pudn.com > Gimcrack-v0.0051-Source.zip > debug.cpp


#include "debug.h" 
#include  
#include  
#include  
#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  
#include  
#include  
#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