8 changed files with 195 additions and 6 deletions
@ -0,0 +1,18 @@
|
||||
if(NOT DEVILUTIONX_SYSTEM_LIBFMT) |
||||
include(FetchContent_MakeAvailableExcludeFromAll) |
||||
|
||||
add_definitions(-D_POSIX_C_SOURCE=200809L) |
||||
|
||||
if(DEVILUTIONX_STATIC_LIBFMT) |
||||
set(BUILD_SHARED_LIBS OFF) |
||||
else() |
||||
set(BUILD_SHARED_LIBS ON) |
||||
endif() |
||||
include(FetchContent) |
||||
FetchContent_Declare(fmt |
||||
GIT_REPOSITORY https://github.com/fmtlib/fmt.git |
||||
GIT_TAG 7bdf0628b1276379886c7f6dda2cef2b3b374f0b |
||||
) |
||||
FetchContent_MakeAvailableExcludeFromAll(fmt) |
||||
set(fmt_SOURCE_DIR ${fmt_SOURCE_DIR} PARENT_SCOPE) |
||||
endif() |
||||
@ -0,0 +1,57 @@
|
||||
#pragma once |
||||
|
||||
#include "../player.h" |
||||
|
||||
#include <fmt/format.h> |
||||
|
||||
namespace fmt { |
||||
|
||||
template <> |
||||
struct formatter<devilution::PLR_MODE> : formatter<string_view> { |
||||
template <typename FormatContext> |
||||
auto format(devilution::PLR_MODE mode, FormatContext &ctx) |
||||
{ |
||||
string_view name = "unknown"; |
||||
switch (mode) { |
||||
case devilution::PM_STAND: |
||||
name = "stand"; |
||||
break; |
||||
case devilution::PM_WALK: |
||||
name = "walk (N, NW, or NE)"; |
||||
break; |
||||
case devilution::PM_WALK2: |
||||
name = "walk (S, SW, or SE)"; |
||||
break; |
||||
case devilution::PM_WALK3: |
||||
name = "walk (W or E)"; |
||||
break; |
||||
case devilution::PM_ATTACK: |
||||
name = "attack"; |
||||
break; |
||||
case devilution::PM_RATTACK: |
||||
name = "ranged attack"; |
||||
break; |
||||
case devilution::PM_BLOCK: |
||||
name = "block"; |
||||
break; |
||||
case devilution::PM_GOTHIT: |
||||
name = "got hit"; |
||||
break; |
||||
case devilution::PM_DEATH: |
||||
name = "death"; |
||||
break; |
||||
case devilution::PM_SPELL: |
||||
name = "spell"; |
||||
break; |
||||
case devilution::PM_NEWLVL: |
||||
name = "new level"; |
||||
break; |
||||
case devilution::PM_QUIT: |
||||
name = "quit"; |
||||
break; |
||||
} |
||||
return formatter<string_view>::format(name, ctx); |
||||
} |
||||
}; |
||||
|
||||
} |
||||
@ -0,0 +1,91 @@
|
||||
#pragma once |
||||
|
||||
#include "fmt/core.h" |
||||
#include "fmt/ranges.h" |
||||
|
||||
#include <SDL.h> |
||||
|
||||
#ifdef USE_SDL1 |
||||
#include "sdl2_to_1_2_backports.h" |
||||
#endif |
||||
|
||||
namespace devilution { |
||||
|
||||
enum class LogCategory { |
||||
Application = SDL_LOG_CATEGORY_APPLICATION, |
||||
Error = SDL_LOG_CATEGORY_ERROR, |
||||
Assert = SDL_LOG_CATEGORY_ASSERT, |
||||
System = SDL_LOG_CATEGORY_SYSTEM, |
||||
Audio = SDL_LOG_CATEGORY_AUDIO, |
||||
Video = SDL_LOG_CATEGORY_VIDEO, |
||||
Render = SDL_LOG_CATEGORY_RENDER, |
||||
Input = SDL_LOG_CATEGORY_INPUT, |
||||
Test = SDL_LOG_CATEGORY_TEST, |
||||
}; |
||||
|
||||
enum class LogPriority { |
||||
Verbose = SDL_LOG_PRIORITY_VERBOSE, |
||||
Debug = SDL_LOG_PRIORITY_DEBUG, |
||||
Info = SDL_LOG_PRIORITY_INFO, |
||||
Warn = SDL_LOG_PRIORITY_WARN, |
||||
Error = SDL_LOG_PRIORITY_ERROR, |
||||
Critical = SDL_LOG_PRIORITY_CRITICAL, |
||||
}; |
||||
|
||||
template <typename... Args> |
||||
void Log(const char *fmt, Args &&... args) |
||||
{ |
||||
auto str = fmt::format(fmt, std::forward<Args>(args)...); |
||||
SDL_Log("%s", str.c_str()); |
||||
} |
||||
|
||||
template <typename... Args> |
||||
void LogVerbose(LogCategory category, const char *fmt, Args &&... args) |
||||
{ |
||||
auto str = fmt::format(fmt, std::forward<Args>(args)...); |
||||
SDL_LogVerbose(static_cast<int>(category), "%s", str.c_str()); |
||||
} |
||||
|
||||
template <typename... Args> |
||||
void LogDebug(LogCategory category, const char *fmt, Args &&... args) |
||||
{ |
||||
auto str = fmt::format(fmt, std::forward<Args>(args)...); |
||||
SDL_LogDebug(static_cast<int>(category), "%s", str.c_str()); |
||||
} |
||||
|
||||
template <typename... Args> |
||||
void LogInfo(LogCategory category, const char *fmt, Args &&... args) |
||||
{ |
||||
auto str = fmt::format(fmt, std::forward<Args>(args)...); |
||||
SDL_LogInfo(static_cast<int>(category), "%s", str.c_str()); |
||||
} |
||||
|
||||
template <typename... Args> |
||||
void LogWarn(LogCategory category, const char *fmt, Args &&... args) |
||||
{ |
||||
auto str = fmt::format(fmt, std::forward<Args>(args)...); |
||||
SDL_LogWarn(static_cast<int>(category), "%s", str.c_str()); |
||||
} |
||||
|
||||
template <typename... Args> |
||||
void LogError(LogCategory category, const char *fmt, Args &&... args) |
||||
{ |
||||
auto str = fmt::format(fmt, std::forward<Args>(args)...); |
||||
SDL_LogError(static_cast<int>(category), "%s", str.c_str()); |
||||
} |
||||
|
||||
template <typename... Args> |
||||
void LogCritical(LogCategory category, const char *fmt, Args &&... args) |
||||
{ |
||||
auto str = fmt::format(fmt, std::forward<Args>(args)...); |
||||
SDL_LogCritical(static_cast<int>(category), "%s", str.c_str()); |
||||
} |
||||
|
||||
template <typename... Args> |
||||
void LogMessageV(LogCategory category, LogPriority priority, const char *fmt, Args &&... args) |
||||
{ |
||||
auto str = fmt::format(fmt, std::forward<Args>(args)...); |
||||
SDL_LogMessageV(static_cast<int>(category), static_cast<SDL_LogPriority>(priority), "%s", str.c_str()); |
||||
} |
||||
|
||||
} // namespace devilution
|
||||
Loading…
Reference in new issue