Skip to content

Commit 7dd6ae5

Browse files
Merge branch 'stable' into modern-iteration
2 parents 8f743f8 + 6a6e272 commit 7dd6ae5

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);
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);
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-
M_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>
@@ -78,3 +83,59 @@ size_t PrintFmt(const int printlevel, const fmt::string_view format, const ARGS&
7883
{
7984
return C_BasePrint(printlevel, TEXTCOLOR_NORMAL, fmt::format(format, args...));
8085
}
86+
87+
/**
88+
* @brief Print to all clients in a server, or to the local player offline.
89+
*
90+
* @note This could really use a new name, like "ServerPrintf".
91+
*
92+
* @param printlevel PRINT_* constant designating what kind of print this is.
93+
* @param format printf-style format string.
94+
* @param args printf-style arguments.
95+
*/
96+
template <typename... ARGS>
97+
void SV_BroadcastPrintf(int printlevel, const fmt::string_view format, const ARGS&... args)
98+
{
99+
if (!serverside)
100+
return;
101+
102+
std::string string = fmt::sprintf(format, args...);
103+
C_BasePrint(printlevel, TEXTCOLOR_NORMAL, string);
104+
105+
#ifdef SERVER_APP
106+
// Hacky code to display messages as normal ones to clients
107+
if (printlevel == PRINT_NORCON)
108+
printlevel = PRINT_HIGH;
109+
110+
SV_BasePrintAllPlayers(printlevel, string);
111+
#endif
112+
}
113+
114+
/**
115+
* @brief Print to all clients in a server, or to the local player offline.
116+
*
117+
* @note This could really use a new name, like "ServerPrintf".
118+
*
119+
* @param format printf-style format string.
120+
* @param args printf-style arguments.
121+
*/
122+
template <typename... ARGS>
123+
void SV_BroadcastPrintf(const fmt::string_view format, const ARGS&... args)
124+
{
125+
SV_BroadcastPrintf(PRINT_NORCON, format, args...);
126+
}
127+
128+
#ifdef SERVER_APP
129+
template <typename... ARGS>
130+
void SV_BroadcastPrintfButPlayer(int printlevel, int player_id, const fmt::string_view format, const ARGS&... args)
131+
{
132+
std::string string = fmt::sprintf(format, args...);
133+
C_BasePrint(printlevel, TEXTCOLOR_NORMAL, string); // print to the console
134+
135+
// Hacky code to display messages as normal ones to clients
136+
if (printlevel == PRINT_NORCON)
137+
printlevel = PRINT_HIGH;
138+
139+
SV_BasePrintButPlayer(printlevel, player_id, string);
140+
}
141+
#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
// [RH] Some windows includes already define this
5549
#if !defined(_WINDEF_) && !defined(__wtypes_h__) && !defined(GEKKO)
5650
typedef int BOOL;
@@ -188,32 +182,6 @@ static inline uint32_t BIT_MASK(uint32_t a, uint32_t b)
188182
return (static_cast<uint32_t>(-1) >> (31 - b)) & ~(BIT(a) - 1);
189183
}
190184

191-
/**
192-
* @brief Print to all clients in a server, or to the local player offline.
193-
*
194-
* @note This could really use a new name, like "ServerPrintf".
195-
*
196-
* @param format printf-style format string.
197-
* @param ... printf-style arguments.
198-
*/
199-
void STACK_ARGS SV_BroadcastPrintf(const char* format, ...) FORMAT_PRINTF(1, 2);
200-
201-
/**
202-
* @brief Print to all clients in a server, or to the local player offline.
203-
*
204-
* @note This could really use a new name, like "ServerPrintf".
205-
*
206-
* @param printlevel PRINT_* constant designating what kind of print this is.
207-
* @param format printf-style format string.
208-
* @param ... printf-style arguments.
209-
*/
210-
void STACK_ARGS SV_BroadcastPrintf(int printlevel, const char* format, ...)
211-
FORMAT_PRINTF(2, 3);
212-
213-
#ifdef SERVER_APP
214-
void STACK_ARGS SV_BroadcastPrintfButPlayer(int printlevel, int player_id, const char* format, ...);
215-
#endif
216-
217185
// game print flags
218186
typedef enum {
219187
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)