Debian Codegraph @

common/include/console.h

raw
1 /*
2 * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
3 * It is copyright by its individual contributors, as recorded in the
4 * project's Git history. See COPYING.txt at the top level for license
5 * terms and a link to the Git history.
6 */
7 /* Console */
8
9 #pragma once
10
11 #include <array>
12 #include <cstddef>
13 #include <cstring>
14 #include <span>
15 #include <type_traits>
16 #include "pstypes.h"
17 #include "dxxsconf.h"
18 #include "fmtcheck.h"
19 #include "d_srcloc.h"
20 #ifdef DXX_BUILD_DESCENT
21 #include "kconfig.h"
22 #endif
23
24 namespace dcx {
25
26 /* Priority levels */
27 enum con_priority
28 {
29 CON_CRITICAL = -3,
30 CON_URGENT,
31 CON_HUD,
32 CON_NORMAL,
33 CON_VERBOSE,
34 CON_DEBUG
35 };
36
37 constexpr std::integral_constant<std::size_t, 2048> CON_LINE_LENGTH{};
38
39 struct console_buffer
40 {
41 int priority;
42 std::array<char, CON_LINE_LENGTH> line;
43 };
44
45 /* Define to 1 to capture the __FILE__, __LINE__ of callers to
46 * con_printf, con_puts, and show the captured value in `gamelog.txt`.
47 */
48 #ifndef DXX_CONSOLE_SHOW_FILE_LINE
49 #define DXX_CONSOLE_SHOW_FILE_LINE 0
50 #endif
51
52 using con_priority_wrapper = location_value_wrapper<con_priority, DXX_CONSOLE_SHOW_FILE_LINE>;
53
54 #undef DXX_CONSOLE_SHOW_FILE_LINE
55
56 void con_init(void);
57 void con_puts(con_priority_wrapper level, std::span<char> str);
58 void con_puts(con_priority_wrapper level, std::span<const char> str);
59
60 void con_printf(con_priority_wrapper level, const char *fmt, ...) dxx_compiler_attribute_format_printf(2, 3);
61 #ifdef DXX_CONSTANT_TRUE
62 #define DXX_CON_PRINTF_CHECK_TRAILING_NEWLINE(F) \
63 (DXX_CONSTANT_TRUE(sizeof((F)) > 1 && (F)[sizeof((F)) - 2] == '\n') && \
64 (DXX_ALWAYS_ERROR_FUNCTION("trailing literal newline on con_printf"), 0)),
65 #else
66 #define DXX_CON_PRINTF_CHECK_TRAILING_NEWLINE(C)
67 #endif
68 #define con_printf(A1,F,...) \
69 DXX_CON_PRINTF_CHECK_TRAILING_NEWLINE(F) \
70 dxx_call_printf_checked(con_printf,con_puts,(A1),(F),##__VA_ARGS__)
71
72 }
73
74 #ifdef DXX_BUILD_DESCENT
75 namespace dsx {
76
77 void con_showup(control_info &Controls);
78
79 }
80 #endif