Skip to content

Commit

Permalink
Log command line options
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Sep 16, 2024
1 parent 61a44a5 commit f6cdf94
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
25 changes: 25 additions & 0 deletions source/base/lib/inc/tactile/base/log/log_level.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include <cstdint> // uint8_t
#include <format> // formatter, format_to

#include "tactile/base/prelude.hpp"

Expand All @@ -25,3 +26,27 @@ enum class LogLevel : std::uint8_t
};

} // namespace tactile

template <>
struct std::formatter<tactile::LogLevel> final
{
template <typename FormatParseContext>
constexpr static auto parse(FormatParseContext& ctx)
{
return ctx.begin();
}

template <typename FormatContext>
auto format(const tactile::LogLevel& level, FormatContext& ctx) const
{
switch (level) {
case tactile::LogLevel::kTrace: return std::format_to(ctx.out(), "trace");
case tactile::LogLevel::kDebug: return std::format_to(ctx.out(), "debug");
case tactile::LogLevel::kInfo: return std::format_to(ctx.out(), "info");
case tactile::LogLevel::kWarn: return std::format_to(ctx.out(), "warn");
case tactile::LogLevel::kError: return std::format_to(ctx.out(), "error");
case tactile::LogLevel::kFatal: return std::format_to(ctx.out(), "fatal");
default: return std::format_to(ctx.out(), "?");
}
}
};
21 changes: 21 additions & 0 deletions source/base/lib/inc/tactile/base/render/renderer_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include <cstdint> // uint8_t
#include <format> // formatter, format_to

#include "tactile/base/prelude.hpp"

Expand Down Expand Up @@ -30,3 +31,23 @@ struct RendererOptions final
};

} // namespace tactile

template <>
struct std::formatter<tactile::TextureFilterMode> final
{
template <typename FormatParseContext>
constexpr static auto parse(FormatParseContext& ctx)
{
return ctx.begin();
}

template <typename FormatContext>
auto format(const tactile::TextureFilterMode& mode, FormatContext& ctx) const
{
switch (mode) {
case tactile::TextureFilterMode::kNearest: return std::format_to(ctx.out(), "nearest");
case tactile::TextureFilterMode::kLinear: return std::format_to(ctx.out(), "linear");
default: return std::format_to(ctx.out(), "?");
}
}
};
21 changes: 21 additions & 0 deletions source/runtime/lib/inc/tactile/runtime/command_line_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include <cstdint> // uint8_t
#include <format> // formatter, format_to
#include <optional> // optional

#include "tactile/base/log/log_level.hpp"
Expand Down Expand Up @@ -39,3 +40,23 @@ TACTILE_RUNTIME_API auto parse_command_line_options(int argc, char* argv[])
-> std::optional<CommandLineOptions>;

} // namespace tactile

template <>
struct std::formatter<tactile::RendererBackendId> final
{
template <typename FormatParseContext>
constexpr static auto parse(FormatParseContext& ctx)
{
return ctx.begin();
}

template <typename FormatContext>
auto format(const tactile::RendererBackendId& id, FormatContext& ctx) const
{
switch (id) {
case tactile::RendererBackendId::kOpenGL: return std::format_to(ctx.out(), "opengl");
case tactile::RendererBackendId::kVulkan: return std::format_to(ctx.out(), "vulkan");
default: return std::format_to(ctx.out(), "?");
}
}
};
16 changes: 16 additions & 0 deletions source/runtime/lib/src/tactile/runtime/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ auto _make_logger(const LogLevel log_level) -> Logger
return logger;
}

void _log_command_line_options(const CommandLineOptions& options)
{
TACTILE_LOG_TRACE("renderer: {}", options.renderer_backend);
TACTILE_LOG_TRACE("load_zlib: {}", options.load_zlib);
TACTILE_LOG_TRACE("load_zstd: {}", options.load_zstd);
TACTILE_LOG_TRACE("load_yaml_format: {}", options.load_yaml_format);
TACTILE_LOG_TRACE("load_tiled_tmj_format: {}", options.load_tiled_tmj_format);
TACTILE_LOG_TRACE("load_tiled_tmx_format: {}", options.load_tiled_tmx_format);
TACTILE_LOG_TRACE("load_godot_tscn_format: {}", options.load_godot_tscn_format);
TACTILE_LOG_TRACE("texture_filter_mode: {}", options.renderer_options.texture_filter_mode);
TACTILE_LOG_TRACE("use_mipmaps: {}", options.renderer_options.use_mipmaps);
TACTILE_LOG_TRACE("use_vsync: {}", options.renderer_options.use_vsync);
TACTILE_LOG_TRACE("limit_fps: {}", options.renderer_options.limit_fps);
}

} // namespace

struct Runtime::Data final
Expand All @@ -72,6 +87,7 @@ struct Runtime::Data final
logger {_make_logger(options.log_level)}
{
set_default_logger(&logger);
_log_command_line_options(options);
TACTILE_LOG_DEBUG("Tactile " TACTILE_VERSION_STRING);
}

Expand Down

0 comments on commit f6cdf94

Please sign in to comment.