Utility files adjusted to work on linux

Gui_Panel_Refactor
Joey Pollack 4 years ago
parent fd424abd16
commit 6c18832de4

@ -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]

@ -2,4 +2,4 @@
# This script expects to be run from the parent directory # This script expects to be run from the parent directory
# ex. scripts/run.sh # ex. scripts/run.sh
build/GLFWTesting ( cd "build" && ./Lunarium )

@ -60,13 +60,13 @@ int main(int argc, char** argv)
pugi::xml_parse_result result = doc.load_file("../test_data/test.xml"); pugi::xml_parse_result result = doc.load_file("../test_data/test.xml");
if (!result) if (!result)
{ {
std::cout << "\nCould not open the file!"; std::cout << "\nCould not open the file!\n";
return -1; return -1;
} }
else else
{ {
int x = doc.child("test").attribute("x").as_int(); 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 // UTILS TEST
@ -76,6 +76,8 @@ int main(int argc, char** argv)
// int meaning = file.ReadInt("section", "var"); // int meaning = file.ReadInt("section", "var");
// std::cout << "\nvar from test.ini is: " << meaning; // std::cout << "\nvar from test.ini is: " << meaning;
std::cout << "\nTesting GLFW and ImGui\n";
// GLFW DEAR IMGUI TEST // GLFW DEAR IMGUI TEST
GLFWwindow* window; GLFWwindow* window;
int width, height; int width, height;

@ -10,56 +10,34 @@
#include "HighResTimer.h" #include "HighResTimer.h"
#define WIN32_LEAN_AND_MEAN using std::chrono::high_resolution_clock;
#include <Windows.h> using std::chrono::duration;
using std::chrono::duration_cast;
using std::chrono::microseconds;
namespace Lunarium namespace Lunarium
{ {
HighResTimer::HighResTimer()
{
Initialize();
}
void HighResTimer::Initialize()
{
mStartTime = 0;
LARGE_INTEGER tickFreq;
QueryPerformanceFrequency(&tickFreq);
mTickFrequency = tickFreq.QuadPart;
}
// Starts or re-starts the timer. // Starts or re-starts the timer.
void HighResTimer::Reset() void HighResTimer::Reset()
{ {
LARGE_INTEGER tickStart; mStartTime = high_resolution_clock::now();
QueryPerformanceCounter(&tickStart);
mStartTime = tickStart.QuadPart;
} }
// Returns the amount of time in microseconds since the last Reset() call. // Returns the amount of time in microseconds since the last Reset() call.
int64_t HighResTimer::GetElapsedTime() int64_t HighResTimer::GetElapsedMicros()
{ {
LARGE_INTEGER ticks; auto endTime = high_resolution_clock::now();
QueryPerformanceCounter(&ticks); auto micros = duration_cast<microseconds>(endTime - mStartTime);
int64_t elapsedMicro = ticks.QuadPart - mStartTime; return micros.count();
elapsedMicro *= mcMils;
elapsedMicro /= mTickFrequency;
return elapsedMicro;
} }
double HighResTimer::GetElapsedSeconds() double HighResTimer::GetElapsedSeconds()
{ {
int64_t emicro = GetElapsedTime(); auto endTime = high_resolution_clock::now();
double dmicro = ((double)emicro); duration<double> s = endTime - mStartTime;
double dmcMils = ((double)mcMils); return s.count();
double seconds = dmicro / dmcMils;
return seconds;
} }
} }

@ -8,10 +8,13 @@
* does not include windows.h in the header. * 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_ #ifndef HIGH_RES_TIMER_H_
#define HIGH_RES_TIMER_H_ #define HIGH_RES_TIMER_H_
#include <stdint.h> #include <stdint.h>
#include <chrono>
namespace Lunarium namespace Lunarium
@ -20,20 +23,12 @@ namespace Lunarium
class HighResTimer class HighResTimer
{ {
public: public:
// NOTE: Currently unused
enum eUnits { SECONDS, MILLISECONDS, MICROSECONDS, NANOSECONDS, PICOSECONDS };
public:
HighResTimer();
void Initialize();
// Starts or re starts the timer. // Starts or re starts the timer.
void Reset(); void Reset();
// Returns the amount of time in microseconds since the last Reset() call. // 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 // Returns the elapsed time in terms of seconds
double GetElapsedSeconds(); double GetElapsedSeconds();
@ -41,19 +36,7 @@ namespace Lunarium
private: private:
int64_t mStartTime; std::chrono::time_point<std::chrono::high_resolution_clock> 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;
*/
}; };
} }

@ -11,8 +11,10 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <time.h> #include <ctime>
#include <stdarg.h> #include <stdarg.h>
#include <cstring>
#include <stdexcept>
namespace Lunarium namespace Lunarium
{ {
@ -191,17 +193,17 @@ namespace Lunarium
{ {
time_t t = time(0); time_t t = time(0);
struct tm now; struct tm* now;
localtime_s(&now, &t); now = localtime(&t);
std::ostringstream oss(""); std::ostringstream oss("");
oss << "[" << (now.tm_year + 1900) << "/"; oss << "[" << (now->tm_year + 1900) << "/";
oss << std::setfill('0') << std::setw(2); oss << std::setfill('0') << std::setw(2);
oss << (now.tm_mon + 1) << "/" oss << (now->tm_mon + 1) << "/"
<< std::setw(2) << now.tm_mday << " -- " << std::setw(2) << now->tm_mday << " -- "
<< std::setw(2) << now.tm_hour << ":" << std::setw(2) << now->tm_hour << ":"
<< std::setw(2) << now.tm_min << ":" << std::setw(2) << now->tm_min << ":"
<< std::setw(2) << now.tm_sec << "] "; << std::setw(2) << now->tm_sec << "] ";
return oss.str(); return oss.str();
} }
@ -331,12 +333,15 @@ namespace Lunarium
void Logger::Log(uint32_t logCategory, uint32_t logLevel, const char * message, ...) void Logger::Log(uint32_t logCategory, uint32_t logLevel, const char * message, ...)
{ {
// clear the buffer // 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 // Fill the buffer with the formatted message
va_list args; va_list args;
va_start(args, message); va_start(args, message);
vsprintf_s(mBuffer, BUFFER_SIZE, message, args); vsprintf(mBuffer, message, args);
va_end(args); va_end(args);
double timeStamp = mTimer.GetElapsedSeconds(); double timeStamp = mTimer.GetElapsedSeconds();

Loading…
Cancel
Save