2017-02-05 10:36:37 +01:00
|
|
|
#pragma once
|
|
|
|
|
2018-02-12 13:05:19 +01:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cassert>
|
2017-02-05 10:36:37 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2017-02-05 14:37:58 +01:00
|
|
|
struct GuiInputState {
|
|
|
|
int32_t mousedX;
|
|
|
|
int32_t mousedY;
|
|
|
|
int32_t mouseX;
|
|
|
|
int32_t mouseY;
|
|
|
|
uint8_t mouseButton;
|
|
|
|
int32_t mouseScroll;
|
|
|
|
char key;
|
|
|
|
|
|
|
|
GuiInputState() :
|
|
|
|
mouseX(0),
|
|
|
|
mouseY(0),
|
|
|
|
mouseButton(0),
|
|
|
|
mouseScroll(0),
|
|
|
|
key(0) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-05 10:36:37 +01:00
|
|
|
inline void gGetFileModTime (const char* filename, int *sec, int *nsec) {
|
|
|
|
struct stat attr;
|
|
|
|
|
|
|
|
bool stat_result = stat(filename, &attr);
|
|
|
|
if (!stat_result) {
|
|
|
|
*sec = -1;
|
|
|
|
*nsec = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*sec = attr.st_mtime;
|
|
|
|
*nsec = attr.st_mtim.tv_nsec;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline double gGetCurrentTime () {
|
|
|
|
struct timespec spec;
|
|
|
|
clock_gettime(CLOCK_REALTIME, &spec);
|
|
|
|
|
|
|
|
return static_cast<double>(spec.tv_sec) + spec.tv_nsec * 1.0e-9;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern double gTimeAtStart;
|
|
|
|
|
|
|
|
inline double gGetTimeSinceStart () {
|
|
|
|
return gGetCurrentTime() - gTimeAtStart;
|
|
|
|
}
|
|
|
|
|
2018-02-12 13:05:19 +01:00
|
|
|
extern FILE *gLogFile;
|
|
|
|
|
|
|
|
void LoggingInit();
|
|
|
|
|
|
|
|
const int cLogBufferSize = 1024;
|
|
|
|
|
2017-02-05 10:36:37 +01:00
|
|
|
inline void gLog (const char* format, ...) {
|
2018-02-12 13:05:19 +01:00
|
|
|
assert(gLogFile != NULL);
|
|
|
|
|
|
|
|
|
2017-02-05 10:36:37 +01:00
|
|
|
fprintf (stdout, "%11.6f: ", gGetTimeSinceStart());
|
2018-02-12 13:05:19 +01:00
|
|
|
fprintf (gLogFile,"%11.6f: ", gGetTimeSinceStart());
|
|
|
|
|
2017-02-05 10:36:37 +01:00
|
|
|
va_list argptr;
|
2018-02-12 13:05:19 +01:00
|
|
|
|
|
|
|
char buffer[cLogBufferSize];
|
2017-02-05 10:36:37 +01:00
|
|
|
va_start(argptr, format);
|
2018-02-12 13:05:19 +01:00
|
|
|
vsnprintf(buffer, cLogBufferSize, format, argptr);
|
2017-02-05 10:36:37 +01:00
|
|
|
va_end(argptr);
|
2018-02-12 13:05:19 +01:00
|
|
|
|
|
|
|
fprintf(stdout, "%s\n", buffer);
|
|
|
|
fprintf(gLogFile, "%s\n", buffer);
|
|
|
|
|
|
|
|
fflush(gLogFile);
|
|
|
|
|
2017-02-05 10:36:37 +01:00
|
|
|
}
|