Skip to content

Instantly share code, notes, and snippets.

@Bijman
Last active December 17, 2025 17:26
Show Gist options
  • Select an option

  • Save Bijman/e39d5f63b68a7e4251dfe30449b3a7d2 to your computer and use it in GitHub Desktop.

Select an option

Save Bijman/e39d5f63b68a7e4251dfe30449b3a7d2 to your computer and use it in GitHub Desktop.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b7d280190..c5e12d93d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,7 +3,11 @@ cmake_minimum_required(VERSION 3.5)
# Version change is fine.
project(SRB2
VERSION 1.6
- LANGUAGES C)
+ LANGUAGES C CXX)
+
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_EXTENSIONS OFF) # optional but recommended: disables GNU extensions, forces pure ISO C++
if(${PROJECT_SOURCE_DIR} MATCHES ${PROJECT_BINARY_DIR})
message(FATAL_ERROR "In-source builds will bring you a world of pain. Please make a separate directory to invoke CMake from.")
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 361386622..6d2d51835 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,6 +2,8 @@
# Core sources
set(SRB2_CORE_SOURCES
+ core/memory.cpp
+ core/thread_pool.cpp
am_map.c
b_bot.c
command.c
@@ -18,17 +20,21 @@ set(SRB2_CORE_SOURCES
f_wipe.c
filesrch.c
g_game.c
+ g_demo.c
g_input.c
hu_stuff.c
i_tcp.c
info.c
+ k_hud.c
lzf.c
m_aatree.c
m_anigif.c
m_argv.c
m_bbox.c
m_cheat.c
+ m_curl.c
m_cond.c
+ m_emotes.cpp
m_fixed.c
m_menu.c
m_textinput.c
@@ -40,19 +46,25 @@ set(SRB2_CORE_SOURCES
mserv.c
http-mserv.c
qs22j.c
+ r_skins.c
s_sound.c
screen.c
sounds.c
st_stuff.c
- #string.c
+ strcasestr.c
tables.c
v_video.c
w_wad.c
y_inter.c
- z_zone.c
+ z_zone.cpp
)
set(SRB2_CORE_HEADERS
+ core/memory.h
+ core/thread_pool.h
+ m_curl.h
+ m_emotes.h
+ k_hud.h
am_map.h
b_bot.h
byteptr.h
@@ -78,6 +90,7 @@ set(SRB2_CORE_HEADERS
fastcmp.h
filesrch.h
g_game.h
+ g_demo.h
g_input.h
g_state.h
hu_stuff.h
@@ -109,6 +122,7 @@ set(SRB2_CORE_HEADERS
md5.h
mserv.h
qs22j.h
+ r_skins.h
s_sound.h
screen.h
sounds.h
@@ -123,18 +137,18 @@ set(SRB2_CORE_HEADERS
)
set(SRB2_CORE_RENDER_SOURCES
- r_bsp.c
+ r_bsp.cpp
r_data.c
- r_draw.c
- r_fps.c
- r_main.c
- r_patch.c
- r_patchrotation.c
- r_plane.c
- r_segs.c
+ r_draw.cpp
+ r_fps.cpp
+ r_main.cpp
+ r_patch.cpp
+ r_patchrotation.cpp
+ r_plane.cpp
+ r_segs.cpp
r_sky.c
r_splats.c
- r_things.c
+ r_things.cpp
r_portal.c
r_bsp.h
@@ -162,7 +176,7 @@ set(SRB2_CORE_GAME_SOURCES
p_inter.c
p_lights.c
p_map.c
- p_maputl.c
+ p_maputl.cpp
p_mobj.c
p_polyobj.c
p_saveg.c
@@ -475,10 +489,10 @@ if(${SRB2_CONFIG_HWRENDER})
${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_batching.c
${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_shaders.c
${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_bsp.c
- ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_cache.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_cache.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.c
${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_draw.c
- ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_portal.c
${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.c
${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2load.c
@@ -493,7 +507,6 @@ if(${SRB2_CONFIG_HWRENDER})
${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.h
${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_data.h
${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_defs.h
- ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_dll.h
${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_gl.h
${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_glob.h
${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.h
diff --git a/src/command.h b/src/command.h
index 7074158e1..dc7a29e8e 100644
--- a/src/command.h
+++ b/src/command.h
@@ -13,12 +13,13 @@
#ifndef __COMMAND_H__
#define __COMMAND_H__
+#include <stdio.h>
+#include "doomdef.h"
+
#ifdef __cplusplus
extern "C" {
#endif
-#include <stdio.h>
-#include "doomdef.h"
//===================================
// Command buffer & command execution
diff --git a/src/d_netcmd.c b/src/d_netcmd.c
index 8fca12794..b6a57aabc 100644
--- a/src/d_netcmd.c
+++ b/src/d_netcmd.c
@@ -53,6 +53,10 @@
#include "y_inter.h"
#include "fastcmp.h"
#include "m_perfstats.h"
+#include "r_data.h"
+CV_PossibleValue_t Color_cons_t[];
+#include "r_skins.h"
+CV_PossibleValue_t Forceskin_cons_t[];
#ifdef NETGAME_DEVMODE
#define CV_RESTRICT CV_NETVAR
diff --git a/src/doomdef.h b/src/doomdef.h
index 0d40e6e30..571d4a883 100644
--- a/src/doomdef.h
+++ b/src/doomdef.h
@@ -40,22 +40,45 @@
#define ASMCALL
#endif
+#include "doomtype.h"
+
+#ifdef __cplusplus /* Only when compiled as C++ */
+ #include <algorithm> /* std::min, std::max, std::sort, … */
+#endif
+
#ifdef __cplusplus
-extern "C" {
+
+// Force libc++ to expose std::min/std::max even when <cmath> is included first (Apple clang quirk)
+#ifndef _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
+#define _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
+#endif
+#ifndef _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
+#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
#endif
-#include "doomtype.h"
+// Optional: only try <version> if it actually exists (newer Xcode)
+#if __has_include(<version>)
+#include <version>
+#endif
+#define _USE_MATH_DEFINES
+#include <cmath>
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+#include <cstddef>
+#include <cstring>
+#include <climits>
+
+extern "C" {
+#else
+#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stddef.h>
#include <string.h>
-
-#define _USE_MATH_DEFINES // fixes M_PI errors in r_plane.c for Visual Studio
-#ifdef __cplusplus
-#include <cmath>
-#else
-#include <math.h>
+#include <limits.h>
#endif
#include <sys/types.h>
diff --git a/src/p_local.h b/src/p_local.h
index 4d8e8032d..a68614de0 100644
--- a/src/p_local.h
+++ b/src/p_local.h
@@ -14,10 +14,6 @@
#ifndef __P_LOCAL__
#define __P_LOCAL__
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#include "command.h"
#include "d_player.h"
#include "d_think.h"
@@ -28,6 +24,10 @@ extern "C" {
#include "p_maputl.h"
#include "doomstat.h" // MAXSPLITSCREENPLAYERS
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#define FLOATSPEED (FRACUNIT*4)
//#define VIEWHEIGHTS "41"
diff --git a/src/p_tick.h b/src/p_tick.h
index a903be0fd..1a7bea312 100644
--- a/src/p_tick.h
+++ b/src/p_tick.h
@@ -32,12 +32,21 @@ void P_PreTicker(INT32 frames);
void P_DoTeamscrambling(void);
void P_RemoveThinkerDelayed(thinker_t *thinker);
+#ifdef __cplusplus
+extern "C" {
+#endif
+
mobj_t *P_SetTarget2(mobj_t **mo, mobj_t *target
+
#ifdef PARANOIA
, const char *source_file, int source_line
#endif
);
+#ifdef __cplusplus
+}
+#endif
+
#ifdef PARANOIA
#define P_SetTarget(...) P_SetTarget2(__VA_ARGS__, __FILE__, __LINE__)
#else
diff --git a/src/r_fps.h b/src/r_fps.h
index 89efc6cfb..bf3f48362 100644
--- a/src/r_fps.h
+++ b/src/r_fps.h
@@ -15,16 +15,16 @@
#ifndef __R_FPS_H__
#define __R_FPS_H__
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#include "m_fixed.h"
#include "p_local.h"
#include "r_state.h"
#include "r_things.h"
#include "m_perfstats.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
extern consvar_t cv_fpscap, cv_fpscapbg;
extern ps_metric_t ps_interp_frac;
diff --git a/src/r_main.h b/src/r_main.h
index 36c8756f8..4644ad372 100644
--- a/src/r_main.h
+++ b/src/r_main.h
@@ -14,14 +14,15 @@
#ifndef __R_MAIN__
#define __R_MAIN__
-#ifdef __cplusplus
-extern "C" {
-#endif
#include "d_player.h"
#include "r_data.h"
#include "m_perfstats.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
//
// POV related.
//
diff --git a/src/sdl/CMakeLists.txt b/src/sdl/CMakeLists.txt
index e4b0d4f37..5a5d19890 100644
--- a/src/sdl/CMakeLists.txt
+++ b/src/sdl/CMakeLists.txt
@@ -32,7 +32,7 @@ set(SRB2_SDL2_SOURCES
hwsym_sdl.c
i_main.c
i_net.c
- i_system.c
+ i_system.cpp
i_ttf.c
i_video.c
i_threads.c
diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp
index 00250bf4f..90cfa0885 100644
--- a/src/sdl/i_system.cpp
+++ b/src/sdl/i_system.cpp
@@ -30,6 +30,7 @@
#endif
#include <signal.h>
+#include <poll.h>
#ifdef _WIN32
#define RPC_NO_WINDOWS_H
@@ -2418,7 +2419,7 @@ static const char *locateWad(void)
return NULL;
}
-const char *I_LocateWad(void)
+extern "C" const char *I_LocateWad(void)
{
const char *waddir = NULL;
diff --git a/src/sdl/macosx/mac_resources.h b/src/sdl/macosx/mac_resources.h
index 727ac9f6b..24e90a9ba 100644
--- a/src/sdl/macosx/mac_resources.h
+++ b/src/sdl/macosx/mac_resources.h
@@ -1,5 +1,12 @@
#ifndef __MAC_RESOURCES_H__
#define __MAC_RESOURCES_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
void OSX_GetResourcesPath(char * buffer);
+#ifdef __cplusplus
+}
+#endif
+
#endif
\ No newline at end of file
diff --git a/src/strcasestr.c b/src/strcasestr.c
index d24a36e54..0a5c57e7d 100644
--- a/src/strcasestr.c
+++ b/src/strcasestr.c
@@ -23,6 +23,10 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <string.h>
+#include <ctype.h>
+#include <stddef.h>
+
static inline int
trycmp (char **pp, char *cp,
const char *q, size_t qn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment