dxx-rebirth/common/include/console.h
Kp 544fc0f893 Add support for increased precision of gamelog timestamps
- Enable display of subsecond (Linux: microseconds; Windows:
  milliseconds) precision on gamelog timestamps.
- Add disabled support for YYYY-MM-DD leaders on gamelog timestamps.
  Activate it by defining DXX_CONSOLE_TIME_FORMAT_YMD to true.
- Add disabled support for capturing caller __FILE__, __LINE__ in calls
  to con_printf, con_puts.  Activate it by defining
  DXX_CONSOLE_SHOW_FILE_LINE to true.  If captured, write those to
  gamelog after the timestamp and before the text.  This feature (and
  only this feature) requires that DXX_HAVE_CXX_BUILTIN_FILE_LINE be
  defined, which is conditional on if the compiler has __builtin_FILE()
  and __builtin_LINE().  If the compiler lacks this support, attempts to
  enable this feature are ignored.
- Switch to using GetLocalTime on Windows.
2017-12-06 05:14:32 +00:00

79 lines
2.1 KiB
C++

/*
* This file is part of the DXX-Rebirth project <http://www.dxx-rebirth.com/>.
* It is copyright by its individual contributors, as recorded in the
* project's Git history. See COPYING.txt at the top level for license
* terms and a link to the Git history.
*/
/* Console */
#pragma once
#include <cstddef>
#include <cstring>
#include <type_traits>
#include "pstypes.h"
#include "dxxsconf.h"
#include "fmtcheck.h"
#include "cli.h"
#include "cmd.h"
#include "d_srcloc.h"
#ifdef __cplusplus
/* Priority levels */
enum con_priority
{
CON_CRITICAL = -3,
CON_URGENT,
CON_HUD,
CON_NORMAL,
CON_VERBOSE,
CON_DEBUG
};
constexpr std::integral_constant<std::size_t, 2048> CON_LINE_LENGTH{};
struct console_buffer
{
char line[CON_LINE_LENGTH];
int priority;
};
/* Define to 1 to capture the __FILE__, __LINE__ of callers to
* con_printf, con_puts, and show the captured value in `gamelog.txt`.
*/
#ifndef DXX_CONSOLE_SHOW_FILE_LINE
#define DXX_CONSOLE_SHOW_FILE_LINE 0
#endif
using con_priority_wrapper = location_value_wrapper<con_priority, DXX_CONSOLE_SHOW_FILE_LINE>;
#undef DXX_CONSOLE_SHOW_FILE_LINE
void con_init(void);
void con_puts(con_priority_wrapper level, char *str, size_t len) __attribute_nonnull();
void con_puts(con_priority_wrapper level, const char *str, size_t len) __attribute_nonnull();
template <typename T>
static inline void con_puts(const con_priority_wrapper level, T &&str)
{
using rr = typename std::remove_reference<T>::type;
constexpr std::size_t len = std::extent<rr>::value;
con_puts(level, str, len && std::is_const<rr>::value ? len - 1 : strlen(str));
}
void con_printf(con_priority_wrapper level, const char *fmt, ...) __attribute_format_printf(2, 3);
#ifdef DXX_CONSTANT_TRUE
#define DXX_CON_PRINTF_CHECK_TRAILING_NEWLINE(F) \
(DXX_CONSTANT_TRUE(sizeof((F)) > 1 && (F)[sizeof((F)) - 2] == '\n') && \
(DXX_ALWAYS_ERROR_FUNCTION(dxx_trap_trailing_newline, "trailing literal newline on con_printf"), 0)),
#else
#define DXX_CON_PRINTF_CHECK_TRAILING_NEWLINE(C)
#endif
#define con_printf(A1,F,...) \
DXX_CON_PRINTF_CHECK_TRAILING_NEWLINE(F) \
dxx_call_printf_checked(con_printf,con_puts,(A1),(F),##__VA_ARGS__)
void con_showup(void);
#endif