Skip to content

Commit c511838

Browse files
Merge branch 'stable' into remove-BOOL
2 parents 75816f6 + 6a6e272 commit c511838

File tree

9 files changed

+159
-299
lines changed

9 files changed

+159
-299
lines changed

client/src/cl_stubs.cpp

-32
Original file line numberDiff line numberDiff line change
@@ -35,38 +35,6 @@
3535
// to switch to a specific map out of order, otherwise false.
3636
bool unnatural_level_progression;
3737

38-
FORMAT_PRINTF(2, 3)
39-
void STACK_ARGS SV_BroadcastPrintf(int printlevel, const char* format, ...)
40-
{
41-
if (!serverside)
42-
return;
43-
44-
// Local game, print the message normally.
45-
std::string str;
46-
va_list va;
47-
va_start(va, format);
48-
VStrFormat(str, format, va);
49-
va_end(va);
50-
51-
Printf(printlevel, "%s", str.c_str());
52-
}
53-
54-
FORMAT_PRINTF(1, 2)
55-
void STACK_ARGS SV_BroadcastPrintf(const char* format, ...)
56-
{
57-
if (!serverside)
58-
return;
59-
60-
// Local game, print the message normally.
61-
std::string str;
62-
va_list va;
63-
va_start(va, format);
64-
VStrFormat(str, format, va);
65-
va_end(va);
66-
67-
Printf(PRINT_HIGH, "%s", str.c_str());
68-
}
69-
7038
void D_SendServerInfoChange(const cvar_t *cvar, const char *value) {}
7139
void D_DoServerInfoChange(byte **stream) {}
7240
void D_WriteUserInfoStrings(int i, byte **stream, bool compact) {}

common/cmdlib.cpp

-34
Original file line numberDiff line numberDiff line change
@@ -351,40 +351,6 @@ StringTokens TokenizeString(const std::string& str, const std::string& delim) {
351351
return tokens;
352352
}
353353

354-
//
355-
// A quick and dirty std::string formatting that uses snprintf under the covers.
356-
//
357-
void STACK_ARGS VStrFormat(std::string& out, const char* fmt, va_list va)
358-
{
359-
va_list va2;
360-
va_copy(va2, va);
361-
362-
// Get desired length of buffer.
363-
int chars = vsnprintf(NULL, 0, fmt, va);
364-
if (chars < 0)
365-
{
366-
I_Error("Encoding error detected in StrFormat\n");
367-
}
368-
size_t len = (size_t)chars + sizeof('\0');
369-
370-
// Allocate the buffer.
371-
char* buf = (char*)malloc(len);
372-
if (buf == NULL)
373-
{
374-
I_Error("Could not allocate StrFormat buffer\n");
375-
}
376-
377-
// Actually write to the buffer.
378-
int ok = vsnprintf(buf, len, fmt, va2);
379-
if (ok != chars)
380-
{
381-
I_Error("Truncation detected in StrFormat\n");
382-
}
383-
384-
out = buf;
385-
free(buf);
386-
}
387-
388354
/**
389355
* @brief Format passed number of bytes with a byte multiple suffix.
390356
*

common/cmdlib.h

-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ std::string JoinStrings(const std::vector<std::string> &pieces, const std::strin
9191
typedef std::vector<std::string> StringTokens;
9292
StringTokens TokenizeString(const std::string& str, const std::string& delim);
9393

94-
void STACK_ARGS VStrFormat(std::string& out, const char* fmt, va_list va);
95-
9694
void StrFormatBytes(std::string& out, size_t bytes);
9795
bool StrFormatISOTime(std::string& s, const tm* utc_tm);
9896
bool StrParseISOTime(const std::string& s, tm* utc_tm);

common/doomfunc.h

+61
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525

2626
#include "v_textcolors.h"
2727

28+
#ifdef SERVER_APP
29+
void SV_BasePrintAllPlayers(const int printlevel, const std::string& str);
30+
void SV_BasePrintButPlayer(const int printlevel, const int player_id, const std::string& str);
31+
#endif
32+
2833
size_t C_BasePrint(const int printlevel, const char* color_code, const std::string& str);
2934

3035
template <typename... ARGS>
@@ -67,3 +72,59 @@ size_t PrintFmt(const int printlevel, const fmt::string_view format, const ARGS&
6772
{
6873
return C_BasePrint(printlevel, TEXTCOLOR_NORMAL, fmt::format(format, args...));
6974
}
75+
76+
/**
77+
* @brief Print to all clients in a server, or to the local player offline.
78+
*
79+
* @note This could really use a new name, like "ServerPrintf".
80+
*
81+
* @param printlevel PRINT_* constant designating what kind of print this is.
82+
* @param format printf-style format string.
83+
* @param args printf-style arguments.
84+
*/
85+
template <typename... ARGS>
86+
void SV_BroadcastPrintf(int printlevel, const fmt::string_view format, const ARGS&... args)
87+
{
88+
if (!serverside)
89+
return;
90+
91+
std::string string = fmt::sprintf(format, args...);
92+
C_BasePrint(printlevel, TEXTCOLOR_NORMAL, string);
93+
94+
#ifdef SERVER_APP
95+
// Hacky code to display messages as normal ones to clients
96+
if (printlevel == PRINT_NORCON)
97+
printlevel = PRINT_HIGH;
98+
99+
SV_BasePrintAllPlayers(printlevel, string);
100+
#endif
101+
}
102+
103+
/**
104+
* @brief Print to all clients in a server, or to the local player offline.
105+
*
106+
* @note This could really use a new name, like "ServerPrintf".
107+
*
108+
* @param format printf-style format string.
109+
* @param args printf-style arguments.
110+
*/
111+
template <typename... ARGS>
112+
void SV_BroadcastPrintf(const fmt::string_view format, const ARGS&... args)
113+
{
114+
SV_BroadcastPrintf(PRINT_NORCON, format, args...);
115+
}
116+
117+
#ifdef SERVER_APP
118+
template <typename... ARGS>
119+
void SV_BroadcastPrintfButPlayer(int printlevel, int player_id, const fmt::string_view format, const ARGS&... args)
120+
{
121+
std::string string = fmt::sprintf(format, args...);
122+
C_BasePrint(printlevel, TEXTCOLOR_NORMAL, string); // print to the console
123+
124+
// Hacky code to display messages as normal ones to clients
125+
if (printlevel == PRINT_NORCON)
126+
printlevel = PRINT_HIGH;
127+
128+
SV_BasePrintButPlayer(printlevel, player_id, string);
129+
}
130+
#endif

common/doomtype.h

-32
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@
4545
#include <gctypes.h>
4646
#endif
4747

48-
#ifdef _MSC_VER
49-
#define FORMAT_PRINTF(index, first_arg)
50-
#else
51-
#define FORMAT_PRINTF(index, first_arg) __attribute__ ((format(printf, index, first_arg)))
52-
#endif
53-
5448
typedef unsigned char byte;
5549
typedef unsigned int uint;
5650

@@ -183,32 +177,6 @@ static inline uint32_t BIT_MASK(uint32_t a, uint32_t b)
183177
return (static_cast<uint32_t>(-1) >> (31 - b)) & ~(BIT(a) - 1);
184178
}
185179

186-
/**
187-
* @brief Print to all clients in a server, or to the local player offline.
188-
*
189-
* @note This could really use a new name, like "ServerPrintf".
190-
*
191-
* @param format printf-style format string.
192-
* @param ... printf-style arguments.
193-
*/
194-
void STACK_ARGS SV_BroadcastPrintf(const char* format, ...) FORMAT_PRINTF(1, 2);
195-
196-
/**
197-
* @brief Print to all clients in a server, or to the local player offline.
198-
*
199-
* @note This could really use a new name, like "ServerPrintf".
200-
*
201-
* @param printlevel PRINT_* constant designating what kind of print this is.
202-
* @param format printf-style format string.
203-
* @param ... printf-style arguments.
204-
*/
205-
void STACK_ARGS SV_BroadcastPrintf(int printlevel, const char* format, ...)
206-
FORMAT_PRINTF(2, 3);
207-
208-
#ifdef SERVER_APP
209-
void STACK_ARGS SV_BroadcastPrintfButPlayer(int printlevel, int player_id, const char* format, ...);
210-
#endif
211-
212180
// game print flags
213181
typedef enum {
214182
PRINT_PICKUP, // Pickup messages

common/g_skill.cpp

-36
This file was deleted.

common/g_skill.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,11 @@ struct SkillInfo
107107
{}
108108
};
109109

110-
extern SkillInfo SkillInfos[MAX_SKILLS];
111-
extern byte skillnum;
112-
extern byte defaultskillmenu;
110+
inline SkillInfo SkillInfos[MAX_SKILLS];
111+
inline byte skillnum;
112+
inline byte defaultskillmenu;
113113

114-
const SkillInfo& G_GetCurrentSkill();
114+
inline const SkillInfo& G_GetCurrentSkill()
115+
{
116+
return SkillInfos[sv_skill.asInt() - 1];
117+
}

0 commit comments

Comments
 (0)