55 lines
1.6 KiB
C++
55 lines
1.6 KiB
C++
//TODO: Debug logger
|
|
//TODO: File IO functions
|
|
#include "Utility.h"
|
|
#include "Config.h"
|
|
#include <Windows.h>
|
|
|
|
namespace nf {
|
|
#ifdef _DEBUG
|
|
void Debug::LogImp(const char* in) {
|
|
std::chrono::duration<float> time = getCurrentTime();
|
|
std::printf("[%.4f] Debug: %s\n", time.count(), in);
|
|
}
|
|
|
|
void Debug::LogImp(const std::string& in) {
|
|
std::chrono::duration<float> time = getCurrentTime();
|
|
std::printf("[%.4f] Debug: %s\n", time.count(), in.c_str());
|
|
}
|
|
|
|
void Debug::LogImp(int in) {
|
|
std::chrono::duration<float> time = getCurrentTime();
|
|
std::printf("[%.4f] Debug: %i\n", time.count(), in);
|
|
}
|
|
|
|
void Debug::LogImp(double in) {
|
|
std::chrono::duration<float> time = getCurrentTime();
|
|
std::printf("[%.4f] Debug: %.4f\n", time.count(), in);
|
|
}
|
|
|
|
void Debug::ErrorImp(const char* in, const char* filename, int line) {
|
|
std::chrono::duration<float> time = getCurrentTime();
|
|
HANDLE cmd = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
SetConsoleTextAttribute(cmd, FOREGROUND_RED);
|
|
std::printf("[%.4f] Error (%s, %i): %s\n", time.count(), filename, line, in);
|
|
SetConsoleTextAttribute(cmd, 7);
|
|
CloseHandle(cmd);
|
|
}
|
|
|
|
std::chrono::duration<float> Debug::getCurrentTime() {
|
|
std::chrono::steady_clock::time_point now = std::chrono::high_resolution_clock::now();
|
|
return now - m_initTime;
|
|
}
|
|
#endif
|
|
|
|
const wchar_t* toWide(const char* in) {
|
|
int length = std::strlen(in) + 1;
|
|
wchar_t* out = new wchar_t[length];
|
|
MultiByteToWideChar(CP_ACP, NULL, in, -1, out, length);
|
|
return out;
|
|
}
|
|
}
|
|
|
|
//Nvidia Optimius support
|
|
extern "C" {
|
|
_declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
|
|
} |