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
# 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");
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;

@ -10,56 +10,34 @@
#include "HighResTimer.h"
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
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<microseconds>(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<double> s = endTime - mStartTime;
return s.count();
}
}

@ -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 <stdint.h>
#include <chrono>
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<std::chrono::high_resolution_clock> mStartTime;
};
}

@ -11,8 +11,10 @@
#include <iostream>
#include <sstream>
#include <iomanip>
#include <time.h>
#include <ctime>
#include <stdarg.h>
#include <cstring>
#include <stdexcept>
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();

Loading…
Cancel
Save