diff --git a/scripts/build.sh b/scripts/build.sh old mode 100644 new mode 100755 diff --git a/scripts/cmconfig.sh b/scripts/cmconfig.sh old mode 100644 new mode 100755 diff --git a/scripts/imgui.ini b/scripts/imgui.ini new file mode 100644 index 0000000..a2f8136 --- /dev/null +++ b/scripts/imgui.ini @@ -0,0 +1,12 @@ +[Window][Debug##Default] +Pos=60,60 +Size=400,400 +Collapsed=0 + +[Window][Dear ImGui Demo] +Pos=650,20 +Size=550,680 +Collapsed=0 + +[Docking][Data] + diff --git a/scripts/run.sh b/scripts/run.sh old mode 100644 new mode 100755 index 34bfc1e..b7e02b6 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -2,4 +2,4 @@ # This script expects to be run from the parent directory # ex. scripts/run.sh -build/GLFWTesting \ No newline at end of file +( cd "build" && ./Lunarium ) \ No newline at end of file diff --git a/src/test_main.cpp b/src/test_main.cpp index 2018e52..7aad191 100644 --- a/src/test_main.cpp +++ b/src/test_main.cpp @@ -60,13 +60,13 @@ int main(int argc, char** argv) pugi::xml_parse_result result = doc.load_file("../test_data/test.xml"); if (!result) { - std::cout << "\nCould not open the file!"; + std::cout << "\nCould not open the file!\n"; return -1; } else { int x = doc.child("test").attribute("x").as_int(); - std::cout << "\nPugiXML worked! -- x is: " << x; + std::cout << "\nPugiXML worked! -- x is: " << x << std::endl; } // UTILS TEST @@ -76,6 +76,8 @@ int main(int argc, char** argv) // int meaning = file.ReadInt("section", "var"); // std::cout << "\nvar from test.ini is: " << meaning; + std::cout << "\nTesting GLFW and ImGui\n"; + // GLFW DEAR IMGUI TEST GLFWwindow* window; int width, height; diff --git a/src/utils/HighResTimer.cpp b/src/utils/HighResTimer.cpp index 99542af..5ad9860 100644 --- a/src/utils/HighResTimer.cpp +++ b/src/utils/HighResTimer.cpp @@ -10,56 +10,34 @@ #include "HighResTimer.h" -#define WIN32_LEAN_AND_MEAN -#include +using std::chrono::high_resolution_clock; +using std::chrono::duration; +using std::chrono::duration_cast; +using std::chrono::microseconds; namespace Lunarium { - HighResTimer::HighResTimer() - { - Initialize(); - } - - - - void HighResTimer::Initialize() - { - mStartTime = 0; - LARGE_INTEGER tickFreq; - QueryPerformanceFrequency(&tickFreq); - mTickFrequency = tickFreq.QuadPart; - } - // Starts or re-starts the timer. void HighResTimer::Reset() { - LARGE_INTEGER tickStart; - QueryPerformanceCounter(&tickStart); - mStartTime = tickStart.QuadPart; + mStartTime = high_resolution_clock::now(); } // Returns the amount of time in microseconds since the last Reset() call. - int64_t HighResTimer::GetElapsedTime() + int64_t HighResTimer::GetElapsedMicros() { - LARGE_INTEGER ticks; - QueryPerformanceCounter(&ticks); - int64_t elapsedMicro = ticks.QuadPart - mStartTime; - - elapsedMicro *= mcMils; - elapsedMicro /= mTickFrequency; - - return elapsedMicro; + auto endTime = high_resolution_clock::now(); + auto micros = duration_cast(endTime - mStartTime); + return micros.count(); } double HighResTimer::GetElapsedSeconds() { - int64_t emicro = GetElapsedTime(); - double dmicro = ((double)emicro); - double dmcMils = ((double)mcMils); - double seconds = dmicro / dmcMils; - return seconds; + auto endTime = high_resolution_clock::now(); + duration s = endTime - mStartTime; + return s.count(); } } \ No newline at end of file diff --git a/src/utils/HighResTimer.h b/src/utils/HighResTimer.h index 0d49d13..568279f 100644 --- a/src/utils/HighResTimer.h +++ b/src/utils/HighResTimer.h @@ -8,10 +8,13 @@ * does not include windows.h in the header. ******************************************************************************/ +// TODO: Rewrite class with c++11 standard code: https://stackoverflow.com/questions/22387586/measuring-execution-time-of-a-function-in-c + #ifndef HIGH_RES_TIMER_H_ #define HIGH_RES_TIMER_H_ #include +#include namespace Lunarium @@ -20,20 +23,12 @@ namespace Lunarium class HighResTimer { public: - // NOTE: Currently unused - enum eUnits { SECONDS, MILLISECONDS, MICROSECONDS, NANOSECONDS, PICOSECONDS }; - - public: - - HighResTimer(); - - void Initialize(); // Starts or re starts the timer. void Reset(); // Returns the amount of time in microseconds since the last Reset() call. - int64_t GetElapsedTime(); + int64_t GetElapsedMicros(); // Returns the elapsed time in terms of seconds double GetElapsedSeconds(); @@ -41,19 +36,7 @@ namespace Lunarium private: - int64_t mStartTime; - int64_t mTickFrequency; - - - - const int mcMils = 1000000; - const int mcBils = 1000000000; - const long long mcTrils = 1000000000000; - - /* // OLD MEMBERS - long long m_TickFreqQuadPart; - double m_StartTime; - */ + std::chrono::time_point mStartTime; }; } diff --git a/src/utils/Logger.cpp b/src/utils/Logger.cpp index 452f520..f757ad8 100644 --- a/src/utils/Logger.cpp +++ b/src/utils/Logger.cpp @@ -11,8 +11,10 @@ #include #include #include -#include +#include #include +#include +#include namespace Lunarium { @@ -191,17 +193,17 @@ namespace Lunarium { time_t t = time(0); - struct tm now; - localtime_s(&now, &t); + struct tm* now; + now = localtime(&t); std::ostringstream oss(""); - oss << "[" << (now.tm_year + 1900) << "/"; + oss << "[" << (now->tm_year + 1900) << "/"; oss << std::setfill('0') << std::setw(2); - oss << (now.tm_mon + 1) << "/" - << std::setw(2) << now.tm_mday << " -- " - << std::setw(2) << now.tm_hour << ":" - << std::setw(2) << now.tm_min << ":" - << std::setw(2) << now.tm_sec << "] "; + oss << (now->tm_mon + 1) << "/" + << std::setw(2) << now->tm_mday << " -- " + << std::setw(2) << now->tm_hour << ":" + << std::setw(2) << now->tm_min << ":" + << std::setw(2) << now->tm_sec << "] "; return oss.str(); } @@ -331,12 +333,15 @@ namespace Lunarium void Logger::Log(uint32_t logCategory, uint32_t logLevel, const char * message, ...) { // clear the buffer - memset(mBuffer, 0, 1024); + memset(mBuffer, 0, BUFFER_SIZE); + + if (strlen(message) >= BUFFER_SIZE) + throw std::runtime_error("Log message size exceeds buffer size"); // Fill the buffer with the formatted message va_list args; va_start(args, message); - vsprintf_s(mBuffer, BUFFER_SIZE, message, args); + vsprintf(mBuffer, message, args); va_end(args); double timeStamp = mTimer.GetElapsedSeconds();