logging
This commit is contained in:
19
src/COMMON.h
19
src/COMMON.h
@@ -44,6 +44,8 @@ typedef double f64;
|
||||
|
||||
using namespace glm;
|
||||
|
||||
#define PREFERENCES_DIRECTORY "anm2ed"
|
||||
|
||||
#define ROUND_NEAREST_MULTIPLE(value, multiple) (roundf((value) / (multiple)) * (multiple))
|
||||
#define FLOAT_TO_U8(x) (static_cast<u8>((x) * 255.0f))
|
||||
#define U8_TO_FLOAT(x) ((x) / 255.0f)
|
||||
@@ -98,19 +100,12 @@ static const vec4 COLOR_OPAQUE = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
static const vec4 COLOR_TRANSPARENT = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
static const vec3 COLOR_OFFSET_NONE = {0.0f, 0.0f, 0.0f};
|
||||
|
||||
static inline void log_error(const std::string& string)
|
||||
static inline std::string preferences_path_get(void)
|
||||
{
|
||||
std::println("[ERROR] {}", string);
|
||||
}
|
||||
|
||||
static inline void log_info(const std::string& string)
|
||||
{
|
||||
std::println("[INFO] {}", string);
|
||||
}
|
||||
|
||||
static inline void log_warning(const std::string& string)
|
||||
{
|
||||
std::println("[WARNING] {}", string);
|
||||
char* preferencesPath = SDL_GetPrefPath("", PREFERENCES_DIRECTORY);
|
||||
std::string preferencesPathString = preferencesPath;
|
||||
SDL_free(preferencesPath);
|
||||
return preferencesPathString;
|
||||
}
|
||||
|
||||
static inline bool string_to_bool(const std::string& string)
|
||||
|
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "COMMON.h"
|
||||
#include "resources.h"
|
||||
|
||||
#define ANM2_SCALE_CONVERT(x) ((f32)x / 100.0f)
|
||||
|
@@ -73,11 +73,11 @@ void dialog_ffmpeg_path_set(Dialog* self)
|
||||
void dialog_explorer_open(const std::string& path)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
ShellExecuteA(NULL, "open", path.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||
ShellExecuteA(NULL, DIALOG_FILE_EXPLORER_COMMAND, path.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||
#else
|
||||
char cmd[512];
|
||||
snprintf(cmd, sizeof(cmd), "xdg-open \"%s\" &", path.c_str());
|
||||
system(cmd);
|
||||
char command[DIALOG_FILE_EXPLORER_COMMAND_SIZE];
|
||||
snprintf(command, sizeof(command), DIALOG_FILE_EXPLORER_COMMAND, path.c_str());
|
||||
system(command);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@@ -3,6 +3,14 @@
|
||||
#include "render.h"
|
||||
#include "window.h"
|
||||
|
||||
#define DIALOG_FILE_EXPLORER_COMMAND_SIZE 512
|
||||
|
||||
#ifdef _WIN32
|
||||
#define DIALOG_FILE_EXPLORER_COMMAND "open"
|
||||
#else
|
||||
#define DIALOG_FILE_EXPLORER_COMMAND "xdg-open \"%s\" &"
|
||||
#endif
|
||||
|
||||
const SDL_DialogFileFilter DIALOG_FILE_FILTER_ANM2[] =
|
||||
{
|
||||
{"Anm2 file", "anm2;xml"}
|
||||
|
@@ -207,7 +207,7 @@ struct ImguiHotkey
|
||||
static void imgui_log_push(Imgui* self, const std::string& text)
|
||||
{
|
||||
self->log.push_back({text, IMGUI_LOG_DURATION});
|
||||
std::println("[IMGUI] {}", text);
|
||||
log_imgui(text);
|
||||
}
|
||||
|
||||
static std::vector<ImguiHotkey>& imgui_hotkey_registry()
|
||||
|
45
src/log.cpp
Normal file
45
src/log.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "log.h"
|
||||
|
||||
inline std::ofstream logFile;
|
||||
|
||||
static void _log_write(const std::string& string)
|
||||
{
|
||||
std::println("{}", string);
|
||||
|
||||
if (logFile.is_open())
|
||||
{
|
||||
logFile << string << '\n';
|
||||
logFile.flush();
|
||||
}
|
||||
}
|
||||
|
||||
void log_init(const std::string& file)
|
||||
{
|
||||
logFile.open(file, std::ios::out | std::ios::trunc);
|
||||
if (!logFile) std::println("{}", std::format(LOG_INIT_ERROR, file));
|
||||
}
|
||||
|
||||
void log_error(const std::string& error)
|
||||
{
|
||||
_log_write(LOG_ERROR_FORMAT + error);
|
||||
}
|
||||
|
||||
void log_info(const std::string& info)
|
||||
{
|
||||
_log_write(LOG_INFO_FORMAT + info);
|
||||
}
|
||||
|
||||
void log_warning(const std::string& warning)
|
||||
{
|
||||
_log_write(LOG_WARNING_FORMAT + warning);
|
||||
}
|
||||
|
||||
void log_imgui(const std::string& imgui)
|
||||
{
|
||||
_log_write(LOG_IMGUI_FORMAT + imgui);
|
||||
}
|
||||
|
||||
void log_free(void)
|
||||
{
|
||||
logFile.close();
|
||||
}
|
17
src/log.h
Normal file
17
src/log.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "COMMON.h"
|
||||
|
||||
#define LOG_WARNING_FORMAT "[WARNING] "
|
||||
#define LOG_ERROR_FORMAT "[ERROR] "
|
||||
#define LOG_INFO_FORMAT "[INFO] "
|
||||
#define LOG_IMGUI_FORMAT "[IMGUI] "
|
||||
#define LOG_INIT_ERROR "[ERROR] Failed to open log file: {}"
|
||||
#define LOG_PATH "log.txt"
|
||||
|
||||
void log_init(const std::string& file);
|
||||
void log_error(const std::string& error);
|
||||
void log_info(const std::string& info);
|
||||
void log_warning(const std::string& warning);
|
||||
void log_imgui(const std::string& imgui);
|
||||
void log_free(void);
|
@@ -14,6 +14,8 @@ main(s32 argc, char* argv[])
|
||||
{
|
||||
State state;
|
||||
|
||||
log_init(preferences_path_get() + LOG_PATH);
|
||||
|
||||
if (argc > 0 && argv[1])
|
||||
{
|
||||
if (std::string(argv[1]) == ARGUMENT_RESCALE)
|
||||
|
@@ -74,9 +74,7 @@ static void _settings_setting_load(Settings* self, const std::string& line)
|
||||
|
||||
std::string settings_path_get(void)
|
||||
{
|
||||
char* path = SDL_GetPrefPath("", SETTINGS_FOLDER);
|
||||
std::string filePath = std::string(path) + SETTINGS_PATH;
|
||||
SDL_free(path);
|
||||
std::string filePath = preferences_path_get() + SETTINGS_PATH;
|
||||
return filePath;
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "COMMON.h"
|
||||
#include "log.h"
|
||||
|
||||
#define SHADER_INFO_LOG_MAX 0xFF
|
||||
#define SHADER_INIT_ERROR "Failed to initialize shader {}:\n{}"
|
||||
|
@@ -24,9 +24,6 @@ static void _draw(State* self)
|
||||
|
||||
void init(State* self)
|
||||
{
|
||||
|
||||
log_info(STATE_INIT_INFO);
|
||||
|
||||
settings_init(&self->settings);
|
||||
|
||||
if (!SDL_Init(SDL_INIT_VIDEO))
|
||||
@@ -78,8 +75,6 @@ void init(State* self)
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||
|
||||
self->glContext = SDL_GL_CreateContext(self->window);
|
||||
|
||||
window_vsync_set(self->settings.isVsync);
|
||||
|
||||
if (!self->glContext)
|
||||
{
|
||||
@@ -87,10 +82,18 @@ void init(State* self)
|
||||
quit(self);
|
||||
}
|
||||
|
||||
glewInit();
|
||||
GLenum glewError = glewInit();
|
||||
|
||||
if (glewError != GLEW_OK)
|
||||
{
|
||||
log_error(std::format(STATE_GL_CONTEXT_INIT_ERROR, (const char*)glewGetErrorString(glewError)));
|
||||
quit(self);
|
||||
}
|
||||
|
||||
log_info(std::format(STATE_GL_CONTEXT_INIT_INFO, (const char*)glGetString(GL_VERSION)));
|
||||
|
||||
window_vsync_set(self->settings.isVsync);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glLineWidth(STATE_GL_LINE_WIDTH);
|
||||
@@ -191,4 +194,5 @@ void quit(State* self)
|
||||
|
||||
settings_save(&self->settings);
|
||||
log_info(STATE_QUIT_INFO);
|
||||
log_free();
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "COMMON.h"
|
||||
#include "log.h"
|
||||
|
||||
#define TEXTURE_CHANNELS 4
|
||||
#define TEXTURE_INIT_INFO "Initialized texture from file: {}"
|
||||
|
Reference in New Issue
Block a user