This repository has been archived on 2025-03-10. You can view files and clone it, but cannot push or open issues or pull requests.
NFRev1/NothinFancy/src/Utility.cpp
Grayson Riffe (Laptop) 94c503f098 Added Gamestate class
2021-08-16 14:24:36 -05:00

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;
}