diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..ff27be35d --- /dev/null +++ b/.clang-format @@ -0,0 +1,54 @@ +--- +Language: Cpp +Standard: c++17 +IndentWidth: 4 +UseTab: Always +TabWidth: 4 +ColumnLimit: 120 +AccessModifierOffset: -4 +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortIfStatementsOnASingleLine: false +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: false +BinPackParameters: false +BreakBeforeBraces: Attach # K&R/OTBS, braces on same line, Java style +BreakConstructorInitializers: BeforeComma +CompactNamespaces: true +ConstructorInitializerAllOnOneLineOrOnePerLine: true +Cpp11BracedListStyle: true +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: Always +FixNamespaceComments: true +IndentCaseBlocks: true +IndentCaseLabels: false +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: false +PointerAlignment: Left # Pointer and reference marker is an integral part of type ID +ReferenceAlignment: Left +ReflowComments: true +SortIncludes: CaseInsensitive +SortUsingDeclarations: true +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..44d6325c2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,43 @@ +root = true + +[*] +charset = utf-8 +insert_final_newline = true +trim_trailing_whitespace = true + +[.editorconfig] +indent_size = 4 +indent_style = tab +tab_width = 4 + +[src/**.{c,h,cpp,hpp}] +indent_style = tab +indent_size = 4 +tab_width = 4 + +[{CMakeLists.txt,*.cmake}] +indent_size = 4 +indent_style = tab +tab_width = 4 + +[{Makefile,*.mk}] +indent_size = 8 +indent_style = tab +tab_width = 8 + +[*{.yml,.yaml}] +indent_size = 2 +indent_style = space +tab_width = 8 + +[*.sh] +indent_size = 4 +indent_style = tab +tab_width = 4 +end_of_line = lf + +[*.bat] +indent_size = 4 +indent_style = tab +tab_width = 4 +end_of_line = crlf diff --git a/CMakeLists.txt b/CMakeLists.txt index f7014dbeb..4e46b3af8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,22 +173,25 @@ add_subdirectory(src) add_subdirectory(assets) -## config.h generation set(GIT_EXECUTABLE "git" CACHE FILEPATH "Path to git binary") include(GitUtilities) -git_latest_commit(SRB2_COMP_COMMIT "${CMAKE_SOURCE_DIR}") -git_current_branch(SRB2_GIT_BRANCH "${CMAKE_SOURCE_DIR}") -git_working_tree_dirty(SRB2_COMP_UNCOMMITTED "${CMAKE_SOURCE_DIR}") -set(SRB2_COMP_BRANCH "${SRB2_GIT_BRANCH}") -set(SRB2_COMP_REVISION "${SRB2_COMP_COMMIT}") -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/src/config.h) - if("${SRB2_SDL2_EXE_NAME}" STREQUAL "") + # cause a reconfigure if the branch changes + get_git_dir(SRB2_GIT_DIR) + configure_file("${SRB2_GIT_DIR}/HEAD" HEAD COPYONLY) + + git_current_branch(SRB2_GIT_REVISION) + + if("${SRB2_GIT_REVISION}" STREQUAL "") + # use abbreviated commit hash if on detached HEAD + git_latest_commit(SRB2_GIT_REVISION) + endif() + list(APPEND EXE_NAME_PARTS "ringracers") - if(NOT "${SRB2_GIT_BRANCH}" STREQUAL "master") - list(APPEND EXE_NAME_PARTS ${SRB2_GIT_BRANCH}) + if(NOT "${SRB2_GIT_REVISION}" STREQUAL "master") + list(APPEND EXE_NAME_PARTS ${SRB2_GIT_REVISION}) endif() else() list(APPEND EXE_NAME_PARTS ${SRB2_SDL2_EXE_NAME}) diff --git a/cmake/Comptime.cmake b/cmake/Comptime.cmake new file mode 100644 index 000000000..3859c2aad --- /dev/null +++ b/cmake/Comptime.cmake @@ -0,0 +1,13 @@ +set(CMAKE_BINARY_DIR "${BINARY_DIR}") +set(CMAKE_CURRENT_BINARY_DIR "${BINARY_DIR}") + +# Set up CMAKE path +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") + +include(GitUtilities) + +git_current_branch(SRB2_COMP_BRANCH) +git_summary(SRB2_COMP_REVISION) +git_working_tree_dirty(SRB2_COMP_UNCOMMITTED) + +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/src/config.h") diff --git a/cmake/Modules/GitUtilities.cmake b/cmake/Modules/GitUtilities.cmake index 4a94b5b5c..bddc552a6 100644 --- a/cmake/Modules/GitUtilities.cmake +++ b/cmake/Modules/GitUtilities.cmake @@ -6,54 +6,54 @@ endif() set(__GitUtilities ON) -function(git_describe variable path) - execute_process(COMMAND "${GIT_EXECUTABLE}" "describe" - WORKING_DIRECTORY "${path}" - RESULT_VARIABLE result +macro(_git_command) + execute_process( + COMMAND "${GIT_EXECUTABLE}" ${ARGN} + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE output ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) +endmacro() + +macro(_git_easy_command) + _git_command(${ARGN}) + set(${variable} "${output}" PARENT_SCOPE) +endmacro() + +function(git_current_branch variable) + _git_command(symbolic-ref -q --short HEAD) + + # If a detached head, a ref could still be resolved. + if("${output}" STREQUAL "") + _git_command(describe --all --exact-match) + + # Get the ref, in the form heads/master or + # remotes/origin/master so isolate the final part. + string(REGEX REPLACE ".*/" "" output "${output}") + endif() set(${variable} "${output}" PARENT_SCOPE) endfunction() -function(git_current_branch variable path) - execute_process(COMMAND ${GIT_EXECUTABLE} "symbolic-ref" "--short" "HEAD" - WORKING_DIRECTORY "${path}" - RESULT_VARIABLE result - OUTPUT_VARIABLE output - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - - set(${variable} "${output}" PARENT_SCOPE) +function(git_latest_commit variable) + _git_easy_command(rev-parse --short HEAD) endfunction() -function(git_latest_commit variable path) - execute_process(COMMAND ${GIT_EXECUTABLE} "rev-parse" "--short" "HEAD" - WORKING_DIRECTORY "${path}" - RESULT_VARIABLE result - OUTPUT_VARIABLE output - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - - set(${variable} "${output}" PARENT_SCOPE) -endfunction() - -function(git_working_tree_dirty variable path) - execute_process(COMMAND ${GIT_EXECUTABLE} "status" "--porcelain" "-uno" - WORKING_DIRECTORY "${path}" - RESULT_VARIABLE result - OUTPUT_VARIABLE output - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE - ) +function(git_working_tree_dirty variable) + _git_command(status --porcelain -uno) if(output STREQUAL "") set(${variable} FALSE PARENT_SCOPE) else() set(${variable} TRUE PARENT_SCOPE) endif() -endfunction() \ No newline at end of file +endfunction() + +function(git_summary variable) + _git_easy_command(log -1 "--format=%h %s") +endfunction() + +function(get_git_dir variable) + _git_easy_command(rev-parse --git-dir) +endfunction() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 888fe5d27..283749c1b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,6 @@ add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32 comptime.c + cxxutil.hpp md5.c config.h.in string.c @@ -132,6 +133,32 @@ add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32 k_roulette.c ) +# This updates the modification time for comptime.c at the +# end of building so when the build system is ran next time, +# that file gets flagged. comptime.c will always be rebuilt. +# +# This begs the question, why always rebuild comptime.c? +# Some things like the git commit must be checked each time +# the program is built. But the build system determines which +# files should be rebuilt before anything else. So +# comptime.c, which only needs to be rebuilt based on +# information known at build time, must be told to rebuild +# before that information can be ascertained. +add_custom_command( + TARGET SRB2SDL2 + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${CMAKE_CURRENT_SOURCE_DIR}/comptime.c +) + +# config.h is generated by this command. It should be done at +# build time for accurate git information and before anything +# that needs it, obviously. +add_custom_target(_SRB2_reconf ALL + COMMAND ${CMAKE_COMMAND} -DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DBINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}/.. -P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Comptime.cmake + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.." +) +add_dependencies(SRB2SDL2 _SRB2_reconf) + if("${CMAKE_COMPILER_IS_GNUCC}" AND "${CMAKE_SYSTEM_NAME}" MATCHES "Windows") target_link_options(SRB2SDL2 PRIVATE "-Wl,--disable-dynamicbase") if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}" AND NOT "${SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES}") @@ -198,6 +225,7 @@ target_link_libraries(SRB2SDL2 PRIVATE DiscordRPC::DiscordRPC) target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_DISCORDRPC -DUSE_STUN) target_sources(SRB2SDL2 PRIVATE discord.c stun.c) +target_link_libraries(SRB2SDL2 PRIVATE tcbrindle::span) target_link_libraries(SRB2SDL2 PRIVATE acsvm::acsvm) set(SRB2_HAVE_THREADS ON) @@ -511,6 +539,7 @@ if(SRB2_CONFIG_PROFILEMODE AND "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") target_link_options(SRB2SDL2 PRIVATE -pg) endif() +add_subdirectory(io) add_subdirectory(sdl) add_subdirectory(objects) add_subdirectory(acs) diff --git a/src/am_map.h b/src/am_map.h index 596a17d46..56a5f9616 100644 --- a/src/am_map.h +++ b/src/am_map.h @@ -16,6 +16,10 @@ #include "d_event.h" +#ifdef __cplusplus +extern "C" { +#endif + struct fpoint_t { INT32 x, y; @@ -44,4 +48,8 @@ void AM_Start(void); // Called to force the automap to quit if the level is completed while it is up. void AM_Stop(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/android/i_video.h b/src/android/i_video.h index 62fec6654..aa0e78f3d 100644 --- a/src/android/i_video.h +++ b/src/android/i_video.h @@ -3,10 +3,18 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + UINT8 *android_surface; JNIEnv* jni_env; jobject androidVideo; jmethodID videoFrameCB; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/apng.h b/src/apng.h index a8b5c8f24..f96d4555d 100644 --- a/src/apng.h +++ b/src/apng.h @@ -39,6 +39,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#ifdef __cplusplus +extern "C" { +#endif + typedef struct apng_info_def apng_info; typedef apng_info * apng_infop; typedef const apng_info * apng_const_infop; @@ -77,4 +81,8 @@ void apng_set_write_fn (png_structp png_ptr, apng_infop ainfo_ptr, void apng_set_set_acTL_fn (png_structp png_ptr, apng_infop ainfo_ptr, apng_set_acTL_ptr set_acTL_fn); +#ifdef __cplusplus +} // extern "C" +#endif + #endif/* APNG_H */ diff --git a/src/byteptr.h b/src/byteptr.h index 5d1b50630..3d89f6e94 100644 --- a/src/byteptr.h +++ b/src/byteptr.h @@ -11,12 +11,19 @@ /// \brief Macros to read/write from/to a UINT8 *, /// used for packet creation and such +#ifndef __BYTEPTR_H__ +#define __BYTEPTR_H__ + #if defined (__alpha__) || defined (__arm__) || defined (__mips__) || defined (__ia64__) || defined (__clang__) #define DEALIGNED #endif #include "endian.h" +#ifdef __cplusplus +extern "C" { +#endif + #ifndef SRB2_BIG_ENDIAN // // Little-endian machines @@ -214,3 +221,9 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) memcpy(s, p, n); \ p += n; \ } while (0) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // __BYTEPTR_H__ diff --git a/src/command.h b/src/command.h index 6715d66a0..d1ddfa337 100644 --- a/src/command.h +++ b/src/command.h @@ -16,6 +16,10 @@ #include #include "doomdef.h" +#ifdef __cplusplus +extern "C" { +#endif + //=================================== // Command buffer & command execution //=================================== @@ -238,4 +242,8 @@ void CV_CheaterWarning(UINT8 playerID, const char *command); // Returns cvar by name. Exposed here for Lua. consvar_t *CV_FindVar(const char *name); +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __COMMAND_H__ diff --git a/src/console.h b/src/console.h index 203698d5e..b5b806369 100644 --- a/src/console.h +++ b/src/console.h @@ -10,10 +10,17 @@ /// \file console.h /// \brief Console drawing and input +#ifndef __CONSOLE_H__ +#define __CONSOLE_H__ + #include "d_event.h" #include "command.h" #include "i_threads.h" +#ifdef __cplusplus +extern "C" { +#endif + void CON_Init(void); boolean CON_Responder(event_t *ev); @@ -90,3 +97,9 @@ void CON_LogMessage(const char *msg); // Startup loading bar void CON_SetLoadingProgress(con_loadprogress_t newStep); void CON_DrawLoadBar(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // __CONSOLE_H__ diff --git a/src/d_clisrv.h b/src/d_clisrv.h index bc534266d..a648b07ae 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -24,6 +24,10 @@ #include "k_pwrlv.h" // PWRLV_NUMTYPES #include "p_saveg.h" // NETSAVEGAMESIZE +#ifdef __cplusplus +extern "C" { +#endif + /* The 'packet version' is used to distinguish packet formats. This version is independent of VERSION and SUBVERSION. Different @@ -545,4 +549,8 @@ void CL_ClearRewinds(void); rewind_t *CL_SaveRewindPoint(size_t demopos); rewind_t *CL_RewindToTime(tic_t time); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/d_event.h b/src/d_event.h index 3ae1010c4..0c621e942 100644 --- a/src/d_event.h +++ b/src/d_event.h @@ -17,6 +17,10 @@ #include "doomtype.h" #include "g_state.h" +#ifdef __cplusplus +extern "C" { +#endif + // Input event types. typedef enum { @@ -45,4 +49,8 @@ struct event_t extern event_t events[MAXEVENTS]; extern INT32 eventhead, eventtail; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/d_main.c b/src/d_main.c index b95d213c3..b9020eb04 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -78,12 +78,6 @@ #include "k_specialstage.h" #include "acs/interface.h" -#ifdef CMAKECONFIG -#include "config.h" -#else -#include "config.h.in" -#endif - #ifdef HWRENDER #include "hardware/hw_main.h" // 3D View Rendering #endif @@ -1126,6 +1120,7 @@ static void IdentifyVersion(void) #define TEXTURESNAME "MISC_TEXTURES.pk3" #define MAPSNAME "MISC_MAPS.pk3" #define PATCHNAME "MISC_SCRIPTS.pk3" +#define UNLOCKNAME "MISC_UNLOCKS.pk3" #define MUSICNAME "MISC_MUSIC.PK3" //// #else @@ -1133,6 +1128,7 @@ static void IdentifyVersion(void) #define TEXTURESNAME "textures.pk3" #define MAPSNAME "maps.pk3" #define PATCHNAME "scripts.pk3" +#define UNLOCKNAME "unlocks.pk3" #define MUSICNAME "music.pk3" //// #endif @@ -1149,7 +1145,7 @@ static void IdentifyVersion(void) #endif #define UNLOCKTESTING #if defined(DEVELOP) && defined(UNLOCKTESTING) - D_AddFile(startupiwads, va(pandf,srb2waddir,"unlocks.pk3")); + D_AddFile(startupiwads, va(pandf,srb2waddir,UNLOCKNAME)); #endif //// #undef TEXTURESNAME @@ -1216,6 +1212,12 @@ void D_SRB2Main(void) /* break the version string into version numbers, for netplay */ D_ConvertVersionNumbers(); + if (!strcmp(compbranch, "")) + { + // \x8b = aqua highlight + compbranch = "\x8b" "detached HEAD" "\x80"; + } + #ifdef DEVELOP D_AbbrevCommit(); #endif @@ -1445,6 +1447,7 @@ void D_SRB2Main(void) mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_MAPS_PK3); // maps.pk3 -- 4 - If you touch this, make sure to touch up the majormods stuff below. mainwads++; W_VerifyFileMd5(mainwads, ASSET_HASH_FOLLOWERS_PK3); // followers.pk3 #ifdef USE_PATCH_FILE + mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_PATCH_PK3); // patch.pk3 #endif #else diff --git a/src/d_main.h b/src/d_main.h index c8e803521..75a8e4b25 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -18,6 +18,10 @@ #include "d_event.h" #include "w_wad.h" // for MAX_WADFILES +#ifdef __cplusplus +extern "C" { +#endif + // make sure not to write back the config until it's been correctly loaded extern tic_t rendergametic; @@ -52,4 +56,8 @@ const char *D_Home(void); // void D_StartTitle(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif //__D_MAIN__ diff --git a/src/d_net.h b/src/d_net.h index 48595532a..12ab72693 100644 --- a/src/d_net.h +++ b/src/d_net.h @@ -18,6 +18,10 @@ #ifndef __D_NET__ #define __D_NET__ +#ifdef __cplusplus +extern "C" { +#endif + // Max computers in a game // 127 is probably as high as this can go, because // SINT8 is used for nodes sometimes >:( @@ -64,4 +68,8 @@ void Net_AbortPacketType(UINT8 packettype); void Net_SendAcks(INT32 node); void Net_WaitAllAckReceived(UINT32 timeout); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 2151bb70f..975c165ad 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -4742,7 +4742,7 @@ static void Command_ListDoomednums_f(void) static void Command_Version_f(void) { #ifdef DEVELOP - CONS_Printf("Ring Racers %s-%s (%s %s)\n", compbranch, comprevision, compdate, comptime); + CONS_Printf("Ring Racers %s %s (%s %s)\n", compbranch, comprevision, compdate, comptime); #else CONS_Printf("Ring Racers %s (%s %s %s %s) ", VERSIONSTRING, compdate, comptime, comprevision, compbranch); #endif diff --git a/src/d_netcmd.h b/src/d_netcmd.h index ee1fb6ec7..8cf262df0 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -18,6 +18,10 @@ #include "command.h" #include "d_player.h" +#ifdef __cplusplus +extern "C" { +#endif + // console vars extern consvar_t cv_playername[MAXSPLITSCREENPLAYERS]; extern consvar_t cv_playercolor[MAXSPLITSCREENPLAYERS]; @@ -279,4 +283,8 @@ void D_Cheat(INT32 playernum, INT32 cheat, ...); UINT8 CanChangeSkin(INT32 playernum); boolean CanChangeSkinWhilePlaying(INT32 playernum); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/d_netfil.h b/src/d_netfil.h index 1191e1bfa..904c1862a 100644 --- a/src/d_netfil.h +++ b/src/d_netfil.h @@ -17,6 +17,10 @@ #include "d_clisrv.h" #include "w_wad.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef enum { SF_FILE, @@ -162,4 +166,8 @@ void CURLGetFile(void); HTTP_login * CURLGetLogin (const char *url, HTTP_login ***return_prev_next); #endif +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __D_NETFIL__ diff --git a/src/d_player.h b/src/d_player.h index 265bd13cb..45f4c6074 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -32,6 +32,10 @@ // the player struct stores a waypoint for racing #include "k_waypoint.h" +#ifdef __cplusplus +extern "C" { +#endif + // Extra abilities/settings for skins (combinable stuff) typedef enum { @@ -657,4 +661,8 @@ struct player_t #endif }; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/d_think.h b/src/d_think.h index 719efa564..75b7137f1 100644 --- a/src/d_think.h +++ b/src/d_think.h @@ -17,6 +17,10 @@ #ifndef __D_THINK__ #define __D_THINK__ +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __GNUG__ #pragma interface #endif @@ -51,4 +55,8 @@ struct thinker_t INT32 references; }; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/d_ticcmd.h b/src/d_ticcmd.h index 7cf95cb0a..c7a37614c 100644 --- a/src/d_ticcmd.h +++ b/src/d_ticcmd.h @@ -17,6 +17,10 @@ #include "m_fixed.h" #include "doomtype.h" +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __GNUG__ #pragma interface #endif @@ -78,4 +82,8 @@ struct ticcmd_t #pragma pack() #endif +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/deh_lua.h b/src/deh_lua.h index 0912907f2..2eff6c9cf 100644 --- a/src/deh_lua.h +++ b/src/deh_lua.h @@ -13,9 +13,17 @@ #ifndef __DEH_LUA_H__ #define __DEH_LUA_H__ +#ifdef __cplusplus +extern "C" { +#endif + boolean LUA_SetLuaAction(void *state, const char *actiontocompare); const char *LUA_GetActionName(void *action); void LUA_SetActionByName(void *state, const char *actiontocompare); size_t LUA_GetActionNumByName(const char *actiontocompare); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/deh_soc.h b/src/deh_soc.h index 6aed7e7f2..cd20b7714 100644 --- a/src/deh_soc.h +++ b/src/deh_soc.h @@ -45,6 +45,10 @@ #include "dehacked.h" #include "doomdef.h" // HWRENDER +#ifdef __cplusplus +extern "C" { +#endif + // Crazy word-reading stuff /// \todo Put these in a seperate file or something. mobjtype_t get_mobjtype(const char *word); @@ -87,4 +91,8 @@ void readfollowercategory(MYFILE *f); preciptype_t get_precip(const char *word); void readweather(MYFILE *f, INT32 num); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/deh_tables.h b/src/deh_tables.h index 8103634a3..816f09c8f 100644 --- a/src/deh_tables.h +++ b/src/deh_tables.h @@ -18,6 +18,10 @@ #include "info.h" // Mobj, state, sprite, etc constants #include "lua_script.h" +#ifdef __cplusplus +extern "C" { +#endif + // Free slot names // The crazy word-reading stuff uses these. extern char *FREE_STATES[NUMSTATEFREESLOTS]; @@ -78,4 +82,8 @@ extern struct int_const_s const INT_CONST[]; // Moved to this file because it can't work compile-time otherwise void DEH_TableCheck(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/dehacked.h b/src/dehacked.h index 63cf9cedd..f32cfd579 100644 --- a/src/dehacked.h +++ b/src/dehacked.h @@ -15,6 +15,10 @@ #include "m_fixed.h" // for get_number +#ifdef __cplusplus +extern "C" { +#endif + typedef enum { UNDO_NONE = 0x00, @@ -69,5 +73,8 @@ char *myfgets(char *buf, size_t bufsize, MYFILE *f); char *myhashfgets(char *buf, size_t bufsize, MYFILE *f); +#ifdef __cplusplus +} // extern "C" +#endif #endif diff --git a/src/discord.h b/src/discord.h index 82d955d01..587be6a42 100644 --- a/src/discord.h +++ b/src/discord.h @@ -17,6 +17,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + extern consvar_t cv_discordrp; extern consvar_t cv_discordstreamer; extern consvar_t cv_discordasks; @@ -77,4 +81,8 @@ void DRPC_UpdatePresence(void); #endif // HAVE_DISCORDRPC +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __DISCORD__ diff --git a/src/doomdata.h b/src/doomdata.h index eab695ca7..73c9e45d9 100644 --- a/src/doomdata.h +++ b/src/doomdata.h @@ -26,6 +26,10 @@ #include "taglist.h" #include "m_fixed.h" // See the mapthing_t scale. +#ifdef __cplusplus +extern "C" { +#endif + // // Map level types. // The following data structures define the persistent format @@ -258,4 +262,8 @@ enum CEILING_SLOPE_THING = 778, }; +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __DOOMDATA__ diff --git a/src/doomdef.h b/src/doomdef.h index 11ba96305..31892fb28 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -97,6 +97,10 @@ #include #endif +#ifdef __cplusplus +extern "C" { +#endif + //#define NOMD5 // Uncheck this to compile debugging code @@ -746,4 +750,8 @@ extern int compuncommitted; /// Other karma comeback modes //#define OTHERKARMAMODES +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __DOOMDEF__ diff --git a/src/doomstat.h b/src/doomstat.h index 045924213..3457dcd2c 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -28,6 +28,10 @@ // For lumpnum_t. #include "w_wad.h" +#ifdef __cplusplus +extern "C" { +#endif + // ============================= // Selected map etc. // ============================= @@ -750,4 +754,8 @@ extern INT32 adminplayers[MAXPLAYERS]; /// \note put these in d_clisrv outright? +#ifdef __cplusplus +} // extern "C" +#endif + #endif //__DOOMSTAT__ diff --git a/src/f_finale.h b/src/f_finale.h index d3ed08d78..a42228625 100644 --- a/src/f_finale.h +++ b/src/f_finale.h @@ -19,6 +19,10 @@ #include "d_event.h" #include "p_mobj.h" +#ifdef __cplusplus +extern "C" { +#endif + // // FINALE // @@ -196,4 +200,8 @@ enum extern UINT8 wipedefs[NUMWIPEDEFS]; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/fastcmp.h b/src/fastcmp.h index 0f7c24aaa..833b75330 100644 --- a/src/fastcmp.h +++ b/src/fastcmp.h @@ -1,6 +1,10 @@ #ifndef __FASTCMP_H__ #define __FASTCMP_H__ +#ifdef __cplusplus +extern "C" { +#endif + // returns false if s != c // returns true if s == c FUNCINLINE static ATTRINLINE boolean fasticmp(const char *s, const char *c) @@ -24,4 +28,8 @@ FUNCINLINE static ATTRINLINE boolean fastncmp(const char *s, const char *c, UINT return !l; // make sure you reached the end } +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/filesrch.h b/src/filesrch.h index ae824a5ae..778e758ac 100644 --- a/src/filesrch.h +++ b/src/filesrch.h @@ -8,6 +8,10 @@ #include "d_netfil.h" #include "k_menu.h" // MAXSTRINGLENGTH +#ifdef __cplusplus +extern "C" { +#endif + extern consvar_t cv_addons_option, cv_addons_folder, cv_addons_md5, cv_addons_showall, cv_addons_search_case, cv_addons_search_type; /** \brief The filesearch function @@ -93,4 +97,8 @@ void closefilemenu(boolean validsize); void searchfilemenu(char *tempname); boolean preparefilemenu(boolean samedepth, boolean replayhut); +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __FILESRCH_H__ diff --git a/src/font.h b/src/font.h index 0cc6610d0..30a4a5002 100644 --- a/src/font.h +++ b/src/font.h @@ -13,6 +13,10 @@ #ifndef __FONT_H__ #define __FONT_H__ +#ifdef __cplusplus +extern "C" { +#endif + #define MAX_FONTS 32 struct font_t @@ -44,4 +48,8 @@ Register a new font, but do not load it yet. */ int Font_DumbRegister (const font_t *); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/g_demo.h b/src/g_demo.h index 4b7de3b30..d24ed3bbb 100644 --- a/src/g_demo.h +++ b/src/g_demo.h @@ -18,6 +18,10 @@ #include "doomstat.h" #include "d_event.h" +#ifdef __cplusplus +extern "C" { +#endif + // ====================================== // DEMO playback/recording related stuff. // ====================================== @@ -201,4 +205,8 @@ boolean G_DemoTitleResponder(event_t *ev); boolean G_CheckDemoTitleEntry(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __G_DEMO__ diff --git a/src/g_game.c b/src/g_game.c index 472c3f898..c13094bf5 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -75,7 +75,9 @@ JoyType_t Joystick[MAXSPLITSCREENPLAYERS]; // SRB2kart char gamedatafilename[64] = -#ifdef DEVELOP +#if defined (TESTERS) || defined (HOSTTESTERS) + "test" +#elif defined(DEVELOP) "develop" #endif "ringdata.dat"; diff --git a/src/g_game.h b/src/g_game.h index 0108cc06d..cc4787ea9 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -20,6 +20,10 @@ #include "g_demo.h" #include "m_cheat.h" // objectplacing +#ifdef __cplusplus +extern "C" { +#endif + extern char gamedatafilename[64]; extern char timeattackfolder[64]; extern char customversionstring[32]; @@ -262,4 +266,8 @@ INT16 G_GetFirstMapOfGametype(UINT8 pgametype); INT16 G_RandMap(UINT32 tolflags, INT16 pprevmap, UINT8 ignorebuffer, UINT8 maphell, boolean callagainsoon, INT16 *extbuffer); void G_AddMapToBuffer(INT16 map); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/g_input.h b/src/g_input.h index 17ecb9281..c99260ceb 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -18,6 +18,10 @@ #include "keys.h" #include "command.h" +#ifdef __cplusplus +extern "C" { +#endif + // number of total 'button' inputs, include keyboard keys, plus virtual // keys (mousebuttons and joybuttons becomes keys) #define NUMKEYS 256 @@ -156,4 +160,8 @@ void G_CopyControls(INT32 (*setupcontrols)[MAXINPUTMAPPING], INT32 (*fromcontrol void G_SaveKeySetting(FILE *f, INT32 (*fromcontrolsa)[MAXINPUTMAPPING], INT32 (*fromcontrolsb)[MAXINPUTMAPPING], INT32 (*fromcontrolsc)[MAXINPUTMAPPING], INT32 (*fromcontrolsd)[MAXINPUTMAPPING]); INT32 G_CheckDoubleUsage(INT32 keynum, INT32 playernum, boolean modify); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/g_state.h b/src/g_state.h index 80d816732..ed526f056 100644 --- a/src/g_state.h +++ b/src/g_state.h @@ -15,6 +15,10 @@ #include "doomtype.h" +#ifdef __cplusplus +extern "C" { +#endif + // the current state of the game typedef enum { @@ -58,4 +62,8 @@ extern UINT8 titlemapinaction; extern UINT8 ultimatemode; // was sk_insane extern gameaction_t gameaction; +#ifdef __cplusplus +} // extern "C" +#endif + #endif //__G_STATE__ diff --git a/src/hardware/hw3dsdrv.h b/src/hardware/hw3dsdrv.h index 9b8670705..adbe7c146 100644 --- a/src/hardware/hw3dsdrv.h +++ b/src/hardware/hw3dsdrv.h @@ -16,6 +16,10 @@ #include "hw_dll.h" #include "hws_data.h" +#ifdef __cplusplus +extern "C" { +#endif + #if defined (HAVE_SDL) || !defined (HWD) EXPORT void HWRAPI(Shutdown) (void); #endif @@ -74,4 +78,8 @@ extern struct hardware3ds_s hw3ds_driver; #endif // _CREATE_DLL_ +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __HW_3DS_DRV_H__ diff --git a/src/hardware/hw3sound.h b/src/hardware/hw3sound.h index 1796dd696..333b3acee 100644 --- a/src/hardware/hw3sound.h +++ b/src/hardware/hw3sound.h @@ -17,6 +17,10 @@ //#include "../s_sound.h" //#include "../p_mobj.h" +#ifdef __cplusplus +extern "C" { +#endif + // Default sound mode (original stereo mode) enum { @@ -95,4 +99,8 @@ void HW3S_FreeSfx(sfxinfo_t *sfx); INT32 S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, INT32 *vol, INT32 *sep, INT32 *pitch, sfxinfo_t *sfxinfo); +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __HW3_SOUND_H__ diff --git a/src/hardware/hw_batching.h b/src/hardware/hw_batching.h index 42291a0df..b7a80d9ce 100644 --- a/src/hardware/hw_batching.h +++ b/src/hardware/hw_batching.h @@ -16,6 +16,10 @@ #include "hw_data.h" #include "hw_drv.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef struct { FSurfaceInfo surf;// surf also has its own polyflags for some reason, but it seems unused @@ -33,4 +37,8 @@ void HWR_SetCurrentTexture(GLMipmap_t *texture); void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, int shader, boolean horizonSpecial); void HWR_RenderBatches(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/hardware/hw_clip.h b/src/hardware/hw_clip.h index 27a2ed1ef..58d788c90 100644 --- a/src/hardware/hw_clip.h +++ b/src/hardware/hw_clip.h @@ -7,11 +7,18 @@ * */ +#ifndef __HARDWARE_HW_CLIP_H__ +#define __HARDWARE_HW_CLIP_H__ + // OpenGL BSP clipping #include "../doomdef.h" #include "../tables.h" #include "../doomtype.h" +#ifdef __cplusplus +extern "C" { +#endif + //#define HAVE_SPHEREFRUSTRUM // enable if you want gld_SphereInFrustum and related code boolean gld_clipper_SafeCheckRange(angle_t startAngle, angle_t endAngle); @@ -22,3 +29,9 @@ angle_t gld_FrustumAngle(angle_t tiltangle); void gld_FrustrumSetup(void); boolean gld_SphereInFrustum(float x, float y, float z, float radius); #endif + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // __HARDWARE_HW_CLIP_H__ diff --git a/src/hardware/hw_data.h b/src/hardware/hw_data.h index 6007c29c5..3d3ed07c2 100644 --- a/src/hardware/hw_data.h +++ b/src/hardware/hw_data.h @@ -22,6 +22,10 @@ #include "../doomdef.h" #include "../screen.h" +#ifdef __cplusplus +extern "C" { +#endif + // ========================================================================== // TEXTURE INFO // ========================================================================== @@ -86,4 +90,8 @@ struct GLPatch_s }; typedef struct GLPatch_s GLPatch_t; +#ifdef __cplusplus +} // extern "C" +#endif + #endif //_HWR_DATA_ diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 74b79c1b5..2738cc28f 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -15,6 +15,10 @@ #include "../doomtype.h" #include "../r_defs.h" +#ifdef __cplusplus +extern "C" { +#endif + #define ZCLIP_PLANE 4.0f // Used for the actual game drawing #define NZCLIP_PLANE 0.9f // Seems to be only used for the HUD and screen textures @@ -330,4 +334,8 @@ enum hwdfiltermode HWD_SET_TEXTUREFILTER_MIXED3, }; +#ifdef __cplusplus +} // extern "C" +#endif + #endif //_HWR_DEFS_ diff --git a/src/hardware/hw_dll.h b/src/hardware/hw_dll.h index 80ff590b5..989b1b8ec 100644 --- a/src/hardware/hw_dll.h +++ b/src/hardware/hw_dll.h @@ -12,6 +12,10 @@ #ifndef __HWR_DLL_H__ #define __HWR_DLL_H__ +#ifdef __cplusplus +extern "C" { +#endif + // Function declaration for exports from the DLL : // EXPORT HWRAPI() (); // If _CREATE_DLL_ is defined the above declaration translates to : @@ -56,4 +60,8 @@ void _init(); void _fini(); #endif +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index 7e808ef58..0ba9e3426 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -21,6 +21,10 @@ #include "hw_dll.h" +#ifdef __cplusplus +extern "C" { +#endif + // ========================================================================== // STANDARD DLL EXPORTS // ========================================================================== @@ -129,4 +133,8 @@ extern struct hwdriver_s hwdriver; #endif //not defined _CREATE_DLL_ +#ifdef __cplusplus +} // extern "C" +#endif + #endif //__HWR_DRV_H__ diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index bc05ea4d4..12d998084 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -19,6 +19,10 @@ #include "../r_defs.h" #include "../p_setup.h" +#ifdef __cplusplus +extern "C" { +#endif + // the original aspect ratio of Doom graphics isn't square #define ORIGINAL_ASPECT (320.0f/200.0f) @@ -143,4 +147,8 @@ void HWR_SetPalette(RGBA_t *palette); extern INT32 patchformat; extern INT32 textureformat; +#ifdef __cplusplus +} // extern "C" +#endif + #endif //_HW_GLOB_ diff --git a/src/hardware/hw_light.h b/src/hardware/hw_light.h index fed7db47f..4cac62ab0 100644 --- a/src/hardware/hw_light.h +++ b/src/hardware/hw_light.h @@ -16,6 +16,10 @@ #include "hw_glob.h" #include "hw_defs.h" +#ifdef __cplusplus +extern "C" { +#endif + #define NUMLIGHTFREESLOTS 32 // Free light slots (for SOCs) #ifdef ALAM_LIGHTING @@ -91,4 +95,9 @@ typedef enum extern light_t lspr[NUMLIGHTS]; extern light_t *t_lspr[NUMSPRITES]; + +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 7f0777841..010d83327 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -20,6 +20,10 @@ #include "../d_player.h" #include "../r_defs.h" +#ifdef __cplusplus +extern "C" { +#endif + // Startup & Shutdown the hardware mode renderer void HWR_Startup(void); void HWR_Switch(void); @@ -150,4 +154,8 @@ extern boolean gl_maptexturesloaded; extern boolean gl_sessioncommandsadded; extern boolean gl_shadersavailable; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/hardware/hw_md2.h b/src/hardware/hw_md2.h index 0f4d2c7bc..f76715306 100644 --- a/src/hardware/hw_md2.h +++ b/src/hardware/hw_md2.h @@ -17,6 +17,10 @@ #include "hw_glob.h" #include "hw_model.h" +#ifdef __cplusplus +extern "C" { +#endif + #if defined(_MSC_VER) #pragma pack() #endif @@ -46,4 +50,8 @@ boolean HWR_DrawModel(gl_vissprite_t *spr); #define PLAYERMODELPREFIX "PLAYER" +#ifdef __cplusplus +} // extern "C" +#endif + #endif // _HW_MD2_H_ diff --git a/src/hardware/hw_md2load.h b/src/hardware/hw_md2load.h index 1662d6471..f1112200c 100644 --- a/src/hardware/hw_md2load.h +++ b/src/hardware/hw_md2load.h @@ -13,7 +13,15 @@ #include "hw_model.h" #include "../doomtype.h" +#ifdef __cplusplus +extern "C" { +#endif + // Load the Model model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/hardware/hw_md3load.h b/src/hardware/hw_md3load.h index c0e0522ff..69461fb93 100644 --- a/src/hardware/hw_md3load.h +++ b/src/hardware/hw_md3load.h @@ -13,7 +13,15 @@ #include "hw_model.h" #include "../doomtype.h" +#ifdef __cplusplus +extern "C" { +#endif + // Load the Model model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/hardware/hw_model.h b/src/hardware/hw_model.h index 6b39eb24d..b42792925 100644 --- a/src/hardware/hw_model.h +++ b/src/hardware/hw_model.h @@ -12,6 +12,10 @@ #include "../doomtype.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef struct { float x, y, z; @@ -132,4 +136,8 @@ void CreateVBOTiny(mesh_t *mesh, tinyframe_t *frame); void CreateVBO(mesh_t *mesh, mdlframe_t *frame); void DeleteVBOs(model_t *model); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/hardware/hws_data.h b/src/hardware/hws_data.h index a8607ac67..2980b8029 100644 --- a/src/hardware/hws_data.h +++ b/src/hardware/hws_data.h @@ -12,6 +12,10 @@ #ifndef __HWS_DATA_H__ #define __HWS_DATA_H__ +#ifdef __cplusplus +extern "C" { +#endif + #define NORMAL_SEP 128 // abuse? @@ -113,4 +117,8 @@ typedef struct snddev_s #endif } snddev_t; +#ifdef __cplusplus +} // extern "C" +#endif + #endif //__HWS_DATA_H__ diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index f44e0818b..c6dd9312a 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -47,6 +47,10 @@ #include "../../doomdef.h" #include "../hw_drv.h" +#ifdef __cplusplus +extern "C" { +#endif + // ========================================================================== // DEFINITIONS // ========================================================================== @@ -138,4 +142,8 @@ typedef enum GLF_NOTEXENV = 0x02, } oglflags_t; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/hardware/r_opengl/r_vbo.h b/src/hardware/r_opengl/r_vbo.h index ca1a974da..f7c519efa 100644 --- a/src/hardware/r_opengl/r_vbo.h +++ b/src/hardware/r_opengl/r_vbo.h @@ -9,6 +9,10 @@ #ifndef _R_VBO_H_ #define _R_VBO_H_ +#ifdef __cplusplus +extern "C" { +#endif + typedef struct { float x, y, z; // Vertex @@ -49,4 +53,8 @@ typedef struct unsigned char r, g, b, a; // Color } vbo64_t; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/hardware/u_list.h b/src/hardware/u_list.h index 7e9a3cabd..e47a61740 100644 --- a/src/hardware/u_list.h +++ b/src/hardware/u_list.h @@ -10,6 +10,10 @@ #ifndef _U_LIST_H_ #define _U_LIST_H_ +#ifdef __cplusplus +extern "C" { +#endif + typedef struct listitem_s { struct listitem_s *next; @@ -26,4 +30,8 @@ void ListRemoveNoFree(void *pItem, listitem_t **itemHead); unsigned int ListGetCount(void *itemHead); listitem_t *ListGetByIndex(void *itemHead, unsigned int index); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 078cd0751..3e8233020 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -19,6 +19,10 @@ #include "r_defs.h" #include "font.h" +#ifdef __cplusplus +extern "C" { +#endif + //------------------------------------ // heads up font //------------------------------------ @@ -152,4 +156,9 @@ void HU_DoCEcho(const char *msg); // Demo playback info extern UINT32 hu_demotime; extern UINT32 hu_demolap; + +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/i_addrinfo.h b/src/i_addrinfo.h index 7ae006719..8a1ba8f4b 100644 --- a/src/i_addrinfo.h +++ b/src/i_addrinfo.h @@ -12,6 +12,10 @@ #ifndef __I_ADDRINFO__ #define __I_ADDRINFO__ +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __GNUG__ #pragma interface #endif @@ -68,4 +72,8 @@ int I_getaddrinfo(const char *node, const char *service, #endif +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/i_joy.h b/src/i_joy.h index eb83a6649..d75e7bed7 100644 --- a/src/i_joy.h +++ b/src/i_joy.h @@ -15,6 +15,10 @@ #include "g_input.h" +#ifdef __cplusplus +extern "C" { +#endif + /*! \brief -JOYAXISRANGE to +JOYAXISRANGE for each axis @@ -54,4 +58,8 @@ struct JoyType_t extern JoyType_t Joystick[MAXSPLITSCREENPLAYERS]; +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __I_JOY_H__ diff --git a/src/i_net.h b/src/i_net.h index bc98dca8e..bcd07eb17 100644 --- a/src/i_net.h +++ b/src/i_net.h @@ -33,6 +33,10 @@ #define NO_BAN_TIME (time_t)(-1) +#ifdef __cplusplus +extern "C" { +#endif + extern INT16 hardware_MAXPACKETLENGTH; extern INT32 net_bandwidth; // in byte/s @@ -182,4 +186,8 @@ extern bannednode_t *bannednode; /// \brief Called by D_SRB2Main to be defined by extern network driver boolean I_InitNetwork(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/i_sound.h b/src/i_sound.h index f1cb5bfa4..a26aa5a8a 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -18,6 +18,10 @@ #include "sounds.h" #include "command.h" +#ifdef __cplusplus +extern "C" { +#endif + // copied from SDL mixer, plus GME typedef enum { MU_NONE, @@ -241,4 +245,8 @@ boolean I_FadeSong(UINT8 target_volume, UINT32 ms, void (*callback)(void)); boolean I_FadeOutStopSong(UINT32 ms); boolean I_FadeInPlaySong(UINT32 ms, boolean looping); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/i_system.h b/src/i_system.h index e7b9f2bf5..1289b384f 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -17,6 +17,10 @@ #include "d_ticcmd.h" #include "d_event.h" +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __GNUG__ #pragma interface #endif @@ -361,4 +365,8 @@ void I_RegisterSysCommands(void); void I_CursedWindowMovement(int xd, int yd); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/i_tcp.h b/src/i_tcp.h index 738b8b4d1..2bbe96fbd 100644 --- a/src/i_tcp.h +++ b/src/i_tcp.h @@ -13,6 +13,10 @@ #ifndef __I_TCP__ #define __I_TCP__ +#ifdef __cplusplus +extern "C" { +#endif + extern UINT16 current_port; /** \brief The I_InitTcpNetwork function @@ -28,4 +32,8 @@ boolean I_InitTcpNetwork(void); boolean I_InitTcpDriver(void); void I_ShutdownTcpDriver(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/i_threads.h b/src/i_threads.h index ecb9fce67..b27595450 100644 --- a/src/i_threads.h +++ b/src/i_threads.h @@ -14,6 +14,10 @@ #ifndef I_THREADS_H #define I_THREADS_H +#ifdef __cplusplus +extern "C" { +#endif + typedef void (*I_thread_fn)(void *userdata); typedef void * I_mutex; @@ -35,5 +39,9 @@ void I_hold_cond (I_cond *, I_mutex); void I_wake_one_cond (I_cond *); void I_wake_all_cond (I_cond *); +#ifdef __cplusplus +} // extern "C" +#endif + #endif/*I_THREADS_H*/ #endif/*HAVE_THREADS*/ diff --git a/src/i_video.h b/src/i_video.h index 760440209..1c9a9a64c 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -16,6 +16,10 @@ #include "doomtype.h" +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __GNUG__ #pragma interface #endif @@ -153,4 +157,8 @@ void I_EndRead(void); UINT32 I_GetRefreshRate(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/info.h b/src/info.h index 5056d4f69..d0d5228e3 100644 --- a/src/info.h +++ b/src/info.h @@ -19,6 +19,10 @@ #include "sounds.h" #include "m_fixed.h" +#ifdef __cplusplus +extern "C" { +#endif + // deh_tables.c now has lists for the more named enums! PLEASE keep them up to date! // For great modding!! @@ -6739,4 +6743,8 @@ void P_BackupTables(void); void P_ResetData(INT32 flags); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/io/CMakeLists.txt b/src/io/CMakeLists.txt new file mode 100644 index 000000000..cfe318b2b --- /dev/null +++ b/src/io/CMakeLists.txt @@ -0,0 +1,4 @@ +target_sources(SRB2SDL2 PRIVATE + streams.cpp + streams.hpp +) diff --git a/src/io/streams.cpp b/src/io/streams.cpp new file mode 100644 index 000000000..af134548b --- /dev/null +++ b/src/io/streams.cpp @@ -0,0 +1,4 @@ +#include "streams.hpp" + +template class srb2::io::ZlibInputStream; +template class srb2::io::ZlibInputStream; diff --git a/src/io/streams.hpp b/src/io/streams.hpp new file mode 100644 index 000000000..60ad130b1 --- /dev/null +++ b/src/io/streams.hpp @@ -0,0 +1,733 @@ +#ifndef __SRB2_IO_STREAMS_HPP__ +#define __SRB2_IO_STREAMS_HPP__ + +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace srb2::io { + +using StreamSize = uint64_t; +using StreamOffset = int64_t; + +enum class SeekFrom { + kStart, + kCurrent, + kEnd +}; + +template +struct IsInputStream + : public std::is_same().read(std::declval>())), StreamSize> {}; + +template +struct IsOutputStream + : public std::is_same().write(std::declval>())), StreamSize> { +}; + +template +struct IsSeekableStream + : public std::is_same().seek(std::declval(), std::declval())), + StreamSize> {}; + +template +struct IsStream : public std::disjunction, IsOutputStream> {}; + +template +struct IsInputOutputStream : public std::conjunction, IsOutputStream> {}; + +template +inline constexpr const bool IsInputStreamV = IsInputStream::value; +template +inline constexpr const bool IsOutputStreamV = IsOutputStream::value; +template +inline constexpr const bool IsSeekableStreamV = IsSeekableStream::value; +template +inline constexpr const bool IsStreamV = IsStream::value; +template +inline constexpr const bool IsInputOutputStreamV = IsInputOutputStream::value; + +template >* = nullptr> +void read_exact(I& stream, tcb::span buffer) { + std::size_t total = 0; + const std::size_t buf_size = buffer.size(); + while (total < buf_size) { + total += stream.read(buffer.subspan(total, buf_size - total)); + } +} + +template >* = nullptr> +void write_exact(O& stream, tcb::span buffer) { + std::size_t total = 0; + const std::size_t buf_size = buffer.size(); + while (total < buf_size) { + total += stream.write(buffer.subspan(total, buf_size - total)); + } +} + +enum class Endian { + kLE, + kBE, +}; + +template >* = nullptr> +void read(std::byte& value, I& stream) { + read_exact(stream, tcb::span {&value, 1}); +} + +template >* = nullptr> +void write(std::byte value, O& stream) { + write_exact(stream, tcb::span {&value, 1}); +} + +template >* = nullptr> +void read(uint8_t& value, I& stream) { + std::byte in; + read_exact(stream, tcb::span {&in, 1}); + value = std::to_integer(in); +} + +template >* = nullptr> +uint8_t read_uint8(I& stream) { + uint8_t ret; + read(ret, stream); + return ret; +} + +template >* = nullptr> +void write(uint8_t value, O& stream) { + std::byte out {value}; + + write_exact(stream, tcb::span {&out, 1}); +} + +template >* = nullptr> +void read(bool& value, I& stream) { + uint8_t v; + read(v, stream); + value = !(v == 0); +} + +template >* = nullptr> +bool read_bool(I& stream) { + bool ret; + read(ret, stream); + return ret; +} + +template >* = nullptr> +void write(bool value, O& stream) { + uint8_t out; + if (value) + out = 1; + else + out = 0; + + write(out, stream); +} + +template >* = nullptr> +void read(int8_t& value, I& stream) { + uint8_t in; + read(in, stream); + value = *reinterpret_cast(&in); +} + +template >* = nullptr> +int8_t read_int8(I& stream) { + int8_t ret; + read(ret, stream); + return ret; +} + +template >* = nullptr> +void write(int8_t value, O& stream) { + write(*reinterpret_cast(&value), stream); +} + +template >* = nullptr> +void read(uint16_t& value, I& stream, Endian endian = Endian::kLE) { + std::array out; + read_exact(stream, tcb::make_span(out)); + if (endian == Endian::kBE) + value = std::to_integer(out[1]) + (std::to_integer(out[0]) << 8); + else + value = std::to_integer(out[0]) + (std::to_integer(out[1]) << 8); +} + +template >* = nullptr> +uint16_t read_uint16(I& stream) { + uint16_t ret; + read(ret, stream); + return ret; +} + +template >* = nullptr> +void write(uint16_t value, O& stream, Endian endian = Endian::kLE) { + std::array out; + + if (endian == Endian::kBE) + out = {std::byte {static_cast((value & 0xFF00) >> 8)}, + std::byte {static_cast((value & 0x00FF) >> 0)}}; + else + out = {std::byte {static_cast((value & 0x00FF) >> 0)}, + std::byte {static_cast((value & 0xFF00) >> 8)}}; + + write_exact(stream, tcb::make_span(out)); +} + +template >* = nullptr> +void read(int16_t& value, I& stream, Endian endian = Endian::kLE) { + uint16_t r; + read(r, stream, endian); + value = *reinterpret_cast(&r); +} + +template >* = nullptr> +int16_t read_int16(I& stream) { + int16_t ret; + read(ret, stream); + return ret; +} + +template >* = nullptr> +void write(int16_t value, O& stream, Endian endian = Endian::kLE) { + write(*reinterpret_cast(&value), stream, endian); +} + +template >* = nullptr> +void read(uint32_t& value, I& stream, Endian endian = Endian::kLE) { + std::array out; + read_exact(stream, tcb::make_span(out)); + if (endian == Endian::kBE) + value = std::to_integer(out[3]) + (std::to_integer(out[2]) << 8) + + (std::to_integer(out[1]) << 16) + (std::to_integer(out[0]) << 24); + else + value = std::to_integer(out[0]) + (std::to_integer(out[1]) << 8) + + (std::to_integer(out[2]) << 16) + (std::to_integer(out[3]) << 24); +} + +template >* = nullptr> +uint32_t read_uint32(I& stream) { + uint32_t ret; + read(ret, stream); + return ret; +} + +template >* = nullptr> +void write(uint32_t value, O& stream, Endian endian = Endian::kLE) { + std::array out; + + if (endian == Endian::kBE) + out = {std::byte {static_cast((value & 0xFF000000) >> 24)}, + std::byte {static_cast((value & 0x00FF0000) >> 16)}, + std::byte {static_cast((value & 0x0000FF00) >> 8)}, + std::byte {static_cast((value & 0x000000FF) >> 0)}}; + else + out = {std::byte {static_cast((value & 0x000000FF) >> 0)}, + std::byte {static_cast((value & 0x0000FF00) >> 8)}, + std::byte {static_cast((value & 0x00FF0000) >> 16)}, + std::byte {static_cast((value & 0xFF000000) >> 24)}}; + + write_exact(stream, tcb::make_span(out)); +} + +template >* = nullptr> +void read(int32_t& value, I& stream, Endian endian = Endian::kLE) { + uint32_t r; + read(r, stream, endian); + value = *reinterpret_cast(&r); +} + +template >* = nullptr> +int32_t read_int32(I& stream) { + int32_t ret; + read(ret, stream); + return ret; +} + +template >* = nullptr> +void write(int32_t value, O& stream, Endian endian = Endian::kLE) { + write(*reinterpret_cast(&value), stream, endian); +} + +template >* = nullptr> +void read(uint64_t& value, I& stream, Endian endian = Endian::kLE) { + std::array out; + read_exact(stream, tcb::make_span(out)); + if (endian == Endian::kBE) + value = std::to_integer(out[7]) + (std::to_integer(out[6]) << 8) + + (std::to_integer(out[5]) << 16) + (std::to_integer(out[4]) << 24) + + (std::to_integer(out[3]) << 32) + (std::to_integer(out[2]) << 40) + + (std::to_integer(out[1]) << 48) + (std::to_integer(out[0]) << 56); + else + value = std::to_integer(out[0]) + (std::to_integer(out[1]) << 8) + + (std::to_integer(out[2]) << 16) + (std::to_integer(out[3]) << 24) + + (std::to_integer(out[4]) << 32) + (std::to_integer(out[5]) << 40) + + (std::to_integer(out[6]) << 48) + (std::to_integer(out[7]) << 56); +} + +template >* = nullptr> +uint64_t read_uint64(I& stream) { + uint64_t ret; + read(ret, stream); + return ret; +} + +template >* = nullptr> +void write(uint64_t value, O& stream, Endian endian = Endian::kLE) { + std::array out; + + if (endian == Endian::kBE) + out = {std::byte {static_cast((value & 0xFF00000000000000) >> 56)}, + std::byte {static_cast((value & 0x00FF000000000000) >> 48)}, + std::byte {static_cast((value & 0x0000FF0000000000) >> 40)}, + std::byte {static_cast((value & 0x000000FF00000000) >> 32)}, + std::byte {static_cast((value & 0x00000000FF000000) >> 24)}, + std::byte {static_cast((value & 0x0000000000FF0000) >> 16)}, + std::byte {static_cast((value & 0x000000000000FF00) >> 8)}, + std::byte {static_cast((value & 0x00000000000000FF) >> 0)}}; + else + out = {std::byte {static_cast((value & 0x00000000000000FF) >> 0)}, + std::byte {static_cast((value & 0x000000000000FF00) >> 8)}, + std::byte {static_cast((value & 0x0000000000FF0000) >> 16)}, + std::byte {static_cast((value & 0x00000000FF000000) >> 24)}, + std::byte {static_cast((value & 0x000000FF00000000) >> 32)}, + std::byte {static_cast((value & 0x0000FF0000000000) >> 40)}, + std::byte {static_cast((value & 0x00FF000000000000) >> 48)}, + std::byte {static_cast((value & 0xFF00000000000000) >> 56)}}; + + write_exact(stream, tcb::make_span(out)); +} + +template >* = nullptr> +void read(int64_t& value, I& stream, Endian endian = Endian::kLE) { + uint64_t r; + read(r, stream, endian); + value = *reinterpret_cast(&r); +} + +template >* = nullptr> +int64_t read_int64(I& stream) { + int64_t ret; + read(ret, stream); + return ret; +} + +template >* = nullptr> +void write(int64_t value, O& stream, Endian endian = Endian::kLE) { + write(*reinterpret_cast(&value), stream, endian); +} + +template >* = nullptr> +void read(float& value, I& stream, Endian endian = Endian::kLE) { + uint32_t r; + read(r, stream, endian); + value = *reinterpret_cast(&r); +} + +template >* = nullptr> +float read_float(I& stream) { + float ret; + read(ret, stream); + return ret; +} + +template >* = nullptr> +void write(float value, O& stream, Endian endian = Endian::kLE) { + write(*reinterpret_cast(&value), stream, endian); +} + +template >* = nullptr> +void read(double& value, I& stream, Endian endian = Endian::kLE) { + uint64_t r; + read(r, stream, endian); + value = *reinterpret_cast(&r); +} + +template >* = nullptr> +double read_double(I& stream) { + double ret; + read(ret, stream); + return ret; +} + +template >* = nullptr> +void write(double value, O& stream, Endian endian = Endian::kLE) { + write(*reinterpret_cast(&value), stream, endian); +} + +template >* = nullptr> +StreamSize remaining(S& stream) { + const StreamSize current = stream.seek(SeekFrom::kCurrent, 0); + const StreamSize end = stream.seek(SeekFrom::kEnd, 0); + stream.seek(SeekFrom::kStart, current); + return end - current; +} + +// Kinds of streams + +class SpanStream { +public: + SpanStream() noexcept = default; + SpanStream(tcb::span span) : span_(span), head_(0) { + if (span_.size() > static_cast(static_cast(-1))) { + throw std::logic_error("Span must not be greater than 2 billion bytes"); + } + }; + + StreamSize read(tcb::span buffer) { + if (head_ >= span_.size()) + return 0; + + const auto begin = buffer.begin(); + const auto end = std::copy( + span_.begin() + head_, span_.begin() + head_ + std::min(buffer.size(), span_.size() - head_), begin); + head_ += std::distance(begin, end); + return std::distance(begin, end); + } + + StreamSize write(tcb::span buffer) { + if (head_ >= span_.size()) + return 0; + + const auto begin = span_.begin() + head_; + const auto end = + std::copy(buffer.begin(), buffer.begin() + std::min(span_.size() - head_, buffer.size()), begin); + head_ += std::distance(begin, end); + return std::distance(begin, end); + } + + StreamSize seek(SeekFrom seek_from, StreamOffset offset) { + std::size_t head = 0; + + switch (seek_from) { + case SeekFrom::kStart: + if (offset < 0 || offset >= static_cast(span_.size())) { + throw std::logic_error("start offset is out of bounds"); + } + head = offset; + break; + case SeekFrom::kEnd: + if (-offset >= static_cast(span_.size())) { + throw std::logic_error("end offset is out of bounds"); + } + head = span_.size() - offset; + break; + case SeekFrom::kCurrent: + if (head_ + offset < 0 || head_ + offset >= span_.size()) { + throw std::logic_error("offset is out of bounds"); + } + head = head_ + offset; + break; + } + + std::swap(head, head_); + return head_; + } + +private: + tcb::span span_; + std::size_t head_ {0}; +}; + +class VecStream { + std::vector vec_; + std::size_t head_ {0}; + +public: + VecStream() = default; + VecStream(const std::vector& vec) : vec_(vec) {} + VecStream(std::vector&& vec) : vec_(std::move(vec)) {} + VecStream(const VecStream& rhs) = default; + VecStream(VecStream&& rhs) = default; + + VecStream& operator=(const VecStream& rhs) = default; + VecStream& operator=(VecStream&& rhs) = default; + + StreamSize read(tcb::span buffer) { + if (head_ >= vec_.size()) + return 0; + + const auto begin = buffer.begin(); + const auto end = + std::copy(vec_.begin() + head_, vec_.begin() + head_ + std::min(buffer.size(), vec_.size() - head_), begin); + head_ += std::distance(begin, end); + return std::distance(begin, end); + } + + StreamSize write(tcb::span buffer) { + const std::size_t buffer_size = buffer.size(); + if (head_ + buffer_size >= vec_.size()) { + vec_.resize(head_ + buffer_size); + } + + const auto begin = vec_.begin() + head_; + const auto end = + std::copy(buffer.begin(), buffer.begin() + std::min(vec_.size() - head_, buffer.size()), begin); + head_ += std::distance(begin, end); + return std::distance(begin, end); + } + + StreamSize seek(SeekFrom seek_from, StreamOffset offset) { + std::size_t head = 0; + + switch (seek_from) { + case SeekFrom::kStart: + if (offset < 0 || offset >= static_cast(vec_.size())) { + throw std::logic_error("start offset is out of bounds"); + } + head = offset; + break; + case SeekFrom::kEnd: + if (-offset >= static_cast(vec_.size())) { + throw std::logic_error("end offset is out of bounds"); + } + head = vec_.size() - offset; + break; + case SeekFrom::kCurrent: + if (head_ + offset < 0 || head_ + offset >= vec_.size()) { + throw std::logic_error("offset is out of bounds"); + } + head = head_ + offset; + break; + } + + std::swap(head, head_); + return head_; + } + + std::vector& vector() { return vec_; } +}; + +class ZlibException : public std::exception { + int err_ {0}; + std::string msg_; + +public: + ZlibException(int err, const char* msg = nullptr) : err_(err), msg_("srb2::io::ZlibException: zlib error: ") { + const char* err_msg = "(UNKNOWN) "; + switch (err_) { + case Z_OK: + err_msg = "(Z_OK) "; + break; + case Z_STREAM_END: + err_msg = "(Z_STREAM_END) "; + break; + case Z_NEED_DICT: + err_msg = "(Z_NEED_DICT) "; + break; + case Z_ERRNO: + err_msg = "(Z_ERRNO) "; + break; + case Z_STREAM_ERROR: + err_msg = "(Z_STREAM_ERROR) "; + break; + case Z_DATA_ERROR: + err_msg = "(Z_DATA_ERROR) "; + break; + case Z_MEM_ERROR: + err_msg = "(Z_MEM_ERROR) "; + break; + case Z_BUF_ERROR: + err_msg = "(Z_BUF_ERROR) "; + break; + case Z_VERSION_ERROR: + err_msg = "(Z_VERSION_ERROR) "; + break; + } + msg_.append(err_msg); + if (msg != nullptr) + msg_.append(msg); + else + msg_.append("nullptr"); + } + + virtual const char* what() const noexcept override final { return msg_.c_str(); } +}; + +template && std::is_move_constructible_v && + std::is_move_assignable_v>* = nullptr> +class ZlibInputStream { + I inner_; + z_stream stream_; + std::vector buf_; + std::size_t buf_head_; + bool zstream_initialized_; + bool zstream_ended_; + +public: + ZlibInputStream(I&& inner) + : inner_(std::move(inner)) + , stream_ {} + , buf_() + , buf_head_(0) + , zstream_initialized_ {false} + , zstream_ended_ {false} {} + + ZlibInputStream(const ZlibInputStream& rhs) = delete; + ZlibInputStream(ZlibInputStream&& rhs) = delete; + + ZlibInputStream& operator=(const ZlibInputStream& rhs) = delete; + ZlibInputStream& operator=(ZlibInputStream&& rhs) = delete; + + StreamSize read(tcb::span buffer) { + if (zstream_ended_) + return 0; + + std::size_t written = 0; + const std::size_t buffer_size = buffer.size(); + while (written < buffer_size && !zstream_ended_) { + _fill_read_buffer(); + + if (buf_.size() == 0) { + break; + } + + const std::size_t written_this_time = _inflate(buffer.subspan(written)); + written += written_this_time; + } + return written; + } + + I& stream() { return inner_; } + + void close() { + if (!zstream_initialized_) + return; + + int ret = inflateEnd(&stream_); + if (ret != Z_OK) + throw ZlibException {ret, stream_.msg}; + zstream_initialized_ = false; + zstream_ended_ = true; + } + + ~ZlibInputStream() { + if (zstream_initialized_) { + int ret = inflateEnd(&stream_); + if (ret != Z_OK) + // can't throw exceptions in destructors + std::terminate(); + zstream_initialized_ = false; + zstream_ended_ = true; + } + }; + +private: + constexpr static const std::size_t kReadHighWater = 2048; + + void _init() { + stream_.avail_in = buf_.size() - buf_head_; + const std::size_t start_avail_in = stream_.avail_in; + stream_.next_in = reinterpret_cast(buf_.data() + buf_head_); + int ret = inflateInit2(&stream_, 32); + if (ret != Z_OK) { + throw ZlibException {ret, stream_.msg}; + } + buf_head_ += start_avail_in - stream_.avail_in; + _move_buf_backwards(); + zstream_initialized_ = true; + zstream_ended_ = false; + } + + void _fill_read_buffer() { + const std::size_t old_size = buf_.size(); + if (old_size < kReadHighWater) { + buf_.resize(kReadHighWater); + const std::size_t read = inner_.read(tcb::span(buf_.data() + old_size, buf_.size() - old_size)); + buf_.resize(old_size + read); + } + } + + StreamSize _inflate(tcb::span out) { + if (!zstream_initialized_) { + _init(); + } + if (zstream_ended_) + return 0; + + const std::size_t out_size = out.size(); + + stream_.avail_in = buf_.size() - buf_head_; + const std::size_t start_avail_in = stream_.avail_in; + stream_.next_in = reinterpret_cast(buf_.data() + buf_head_); + stream_.avail_out = out_size; + const std::size_t start_avail_out = stream_.avail_out; + stream_.next_out = reinterpret_cast(out.data()); + + int ret = inflate(&stream_, Z_NO_FLUSH); + if (ret == Z_STREAM_END) { + zstream_ended_ = true; + } else if (ret != Z_OK && ret != Z_BUF_ERROR) { + throw ZlibException {ret, stream_.msg}; + } + + buf_head_ += start_avail_in - stream_.avail_in; + const std::size_t written = start_avail_out - stream_.avail_out; + + _move_buf_backwards(); + + return written; + } + + void _move_buf_backwards() { + if (buf_head_ == 0) { + return; + } + + if (buf_head_ >= buf_.size()) { + buf_.clear(); + buf_head_ = 0; + return; + } + + auto end = std::move(buf_.begin() + buf_head_, buf_.end(), buf_.begin()); + buf_.resize(end - buf_.begin()); + buf_head_ = 0; + } +}; + +// Utility functions + +template +StreamSize pipe_all(I& input, O& output) { + std::vector buf; + + StreamSize total_written = 0; + StreamSize read_this_time = 0; + do { + buf.clear(); + buf.resize(2048); + read_this_time = input.read(tcb::make_span(buf)); + buf.resize(read_this_time); + + write_exact(output, tcb::make_span(buf)); + total_written += read_this_time; + } while (read_this_time != 0); + + return total_written; +} + +template +std::vector read_to_vec(I& input) { + VecStream out; + pipe_all(input, out); + return std::move(out.vector()); +} + +// Instantiated templates + +extern template class ZlibInputStream; +extern template class ZlibInputStream; + +} // namespace srb2::io + +#endif // __SRB2_IO_STREAMS_HPP__ diff --git a/src/k_battle.h b/src/k_battle.h index 3370e041b..42d92cf33 100644 --- a/src/k_battle.h +++ b/src/k_battle.h @@ -4,6 +4,10 @@ #include "doomtype.h" #include "d_player.h" +#ifdef __cplusplus +extern "C" { +#endif + extern struct battleovertime { UINT16 enabled; ///< Has this been initalized yet? @@ -31,4 +35,8 @@ void K_SetupMovingCapsule(mapthing_t *mt, mobj_t *mobj); void K_SpawnPlayerBattleBumpers(player_t *p); void K_BattleInit(boolean singleplayercontext); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/k_bheap.h b/src/k_bheap.h index be07b40df..b47ad7a74 100644 --- a/src/k_bheap.h +++ b/src/k_bheap.h @@ -15,6 +15,10 @@ #include "doomdef.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef void(*updateindexfunc)(void *const, const size_t); struct bheapitem_t @@ -150,4 +154,8 @@ size_t K_BHeapContains(bheap_t *const heap, void *const data, size_t index); boolean K_BHeapFree(bheap_t *const heap); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/k_boss.h b/src/k_boss.h index f24365b29..9986d3e36 100644 --- a/src/k_boss.h +++ b/src/k_boss.h @@ -16,6 +16,10 @@ #include "doomdef.h" #include "doomstat.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef enum { SPOT_NONE = 0, @@ -112,4 +116,8 @@ void K_UpdateBossHealthBar(fixed_t magnitude, tic_t jitterlen); void K_DeclareWeakspot(mobj_t *spot, spottype_t spottype, UINT16 color, boolean minimap); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/k_bot.h b/src/k_bot.h index 60d22700d..bce0a1655 100644 --- a/src/k_bot.h +++ b/src/k_bot.h @@ -17,6 +17,10 @@ #include "d_player.h" #include "r_defs.h" +#ifdef __cplusplus +extern "C" { +#endif + // Maximum value of botvars.difficulty #define MAXBOTDIFFICULTY 13 @@ -270,4 +274,8 @@ void K_UpdateBotGameplayVars(player_t *player); void K_BotItemUsage(player_t *player, ticcmd_t *cmd, INT16 turnamt); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/k_brightmap.h b/src/k_brightmap.h index 2c22a171f..7986b48e2 100644 --- a/src/k_brightmap.h +++ b/src/k_brightmap.h @@ -17,6 +17,10 @@ #include "doomdef.h" #include "doomtype.h" +#ifdef __cplusplus +extern "C" { +#endif + struct brightmapStorage_t { // Brightmap storage struct. @@ -46,4 +50,8 @@ void K_InitBrightmapsPwad(INT32 wadNum); void K_InitBrightmaps(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __K_BRIGHTMAP_H__ diff --git a/src/k_collide.h b/src/k_collide.h index e8700a097..c93c72ed2 100644 --- a/src/k_collide.h +++ b/src/k_collide.h @@ -4,6 +4,10 @@ #include "doomtype.h" #include "p_mobj.h" +#ifdef __cplusplus +extern "C" { +#endif + angle_t K_GetCollideAngle(mobj_t *t1, mobj_t *t2); boolean K_BananaBallhogCollide(mobj_t *t1, mobj_t *t2); @@ -27,4 +31,8 @@ boolean K_SMKIceBlockCollide(mobj_t *t1, mobj_t *t2); boolean K_PvPTouchDamage(mobj_t *t1, mobj_t *t2); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/k_color.h b/src/k_color.h index 6e6778d75..bd2fea5dc 100644 --- a/src/k_color.h +++ b/src/k_color.h @@ -15,6 +15,10 @@ #include "doomdef.h" #include "doomtype.h" +#ifdef __cplusplus +extern "C" { +#endif + #define SKIN_RAMP_LENGTH 16 #define DEFAULT_STARTTRANSCOLOR 96 #define NUM_PALETTE_ENTRIES 256 @@ -110,4 +114,8 @@ void K_HitlagColormap(UINT8 *dest_colormap); --------------------------------------------------*/ void K_GenerateKartColormap(UINT8 *dest_colormap, INT32 skinnum, UINT8 color); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/k_director.h b/src/k_director.h index db19fbe8b..29bb01721 100644 --- a/src/k_director.h +++ b/src/k_director.h @@ -3,6 +3,13 @@ /// \file k_director.h /// \brief SRB2kart automatic spectator camera. +#ifndef __K_DIRECTOR_H__ +#define __K_DIRECTOR_H__ + +#ifdef __cplusplus +extern "C" { +#endif + extern struct directorinfo { tic_t cooldown; // how long has it been since we last switched? @@ -18,4 +25,10 @@ extern struct directorinfo void K_InitDirector(void); void K_UpdateDirector(void); void K_DrawDirectorDebugger(void); -void K_DirectorFollowAttack(player_t *player, mobj_t *inflictor, mobj_t *source); \ No newline at end of file +void K_DirectorFollowAttack(player_t *player, mobj_t *inflictor, mobj_t *source); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // __K_DIRECTOR_H__ diff --git a/src/k_follower.h b/src/k_follower.h index a5f5d54a8..288bb34b8 100644 --- a/src/k_follower.h +++ b/src/k_follower.h @@ -16,6 +16,10 @@ #include "doomdef.h" #include "doomstat.h" +#ifdef __cplusplus +extern "C" { +#endif + #define FOLLOWERCOLOR_MATCH UINT16_MAX #define FOLLOWERCOLOR_OPPOSITE (UINT16_MAX-1) @@ -211,5 +215,8 @@ void K_HandleFollower(player_t *player); void K_RemoveFollower(player_t *player); +#ifdef __cplusplus +} // extern "C" +#endif #endif // __K_FOLLOWER__ diff --git a/src/k_grandprix.h b/src/k_grandprix.h index 3d966d4d3..a862245c7 100644 --- a/src/k_grandprix.h +++ b/src/k_grandprix.h @@ -16,6 +16,10 @@ #include "doomdef.h" #include "doomstat.h" +#ifdef __cplusplus +extern "C" { +#endif + #define GPEVENT_NONE 0 #define GPEVENT_BONUS 1 #define GPEVENT_SPECIAL 2 @@ -166,4 +170,8 @@ void K_PlayerLoseLife(player_t *player); boolean K_CanChangeRules(boolean allowdemos); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/k_hud.h b/src/k_hud.h index 09420503f..7960c0aba 100644 --- a/src/k_hud.h +++ b/src/k_hud.h @@ -9,12 +9,16 @@ /// \file k_hud.h /// \brief HUD drawing functions exclusive to Kart +#ifndef __K_HUD__ +#define __K_HUD__ + #include "doomtype.h" #include "doomstat.h" #include "hu_stuff.h" -#ifndef __K_HUD__ -#define __K_HUD__ +#ifdef __cplusplus +extern "C" { +#endif #define RINGANIM_NUMFRAMES 10 #define RINGANIM_DELAYMAX 5 @@ -43,4 +47,8 @@ void K_DrawLikeMapThumbnail(INT32 x, INT32 y, INT32 width, UINT32 flags, patch_t extern patch_t *kp_facehighlight[8]; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/k_kart.h b/src/k_kart.h index 4db338643..f74f14e12 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -10,6 +10,10 @@ #include "d_player.h" // Need for player_t #include "command.h" // Need for player_t +#ifdef __cplusplus +extern "C" { +#endif + #define KART_FULLTURN 800 /* @@ -193,5 +197,9 @@ fixed_t K_ItemScaleForPlayer(player_t *player); void K_SetItemOut(player_t *player); void K_UnsetItemOut(player_t *player); +#ifdef __cplusplus +} // extern "C" +#endif + // ========================================================================= #endif // __K_KART__ diff --git a/src/k_menu.h b/src/k_menu.h index eb57069b7..cfb325fd6 100644 --- a/src/k_menu.h +++ b/src/k_menu.h @@ -24,6 +24,10 @@ #include "i_threads.h" #include "mserv.h" +#ifdef __cplusplus +extern "C" { +#endif + #define SERVERLISTDEBUG // flags for items in the menu @@ -1195,5 +1199,8 @@ boolean M_StatisticsInputs(INT32 ch); NULL\ } +#ifdef __cplusplus +} // extern "C" +#endif #endif //__K_MENU__ diff --git a/src/k_objects.h b/src/k_objects.h index 284ec1c61..dbe3b6ffc 100644 --- a/src/k_objects.h +++ b/src/k_objects.h @@ -2,6 +2,10 @@ #ifndef k_objects_H #define k_objects_H +#ifdef __cplusplus +extern "C" { +#endif + /* Hyudoro */ void Obj_InitHyudoroCenter(mobj_t *center, mobj_t *master); void Obj_HyudoroDeploy(mobj_t *master); @@ -69,4 +73,8 @@ void Obj_UFOPieceRemoved(mobj_t *piece); mobj_t *Obj_CreateSpecialUFO(void); UINT32 K_GetSpecialUFODistance(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif/*k_objects_H*/ diff --git a/src/k_pathfind.h b/src/k_pathfind.h index 38b0b207f..0e6671b0e 100644 --- a/src/k_pathfind.h +++ b/src/k_pathfind.h @@ -15,6 +15,10 @@ #include "doomtype.h" +#ifdef __cplusplus +extern "C" { +#endif + // function pointer for returning a node's connected node data // should return a pointer to an array of pointers to the data, as arguments takes a node's data and a pointer that the // number of connected nodes should be placed into @@ -84,4 +88,8 @@ struct pathfindsetup_t { --------------------------------------------------*/ boolean K_PathfindAStar(path_t *const path, pathfindsetup_t *const pathfindsetup); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/k_profiles.h b/src/k_profiles.h index 2e65a49fe..f0ae7e287 100644 --- a/src/k_profiles.h +++ b/src/k_profiles.h @@ -22,6 +22,10 @@ #include "g_game.h" // game CVs #include "k_follower.h" // followers +#ifdef __cplusplus +extern "C" { +#endif + // We have to redefine this because somehow including r_skins.h causes a redefinition of node_t since that's used for both net nodes and BSP nodes too...... // And honestly I don't wanna refactor that. #define SKINNAMESIZE 16 @@ -152,4 +156,8 @@ SINT8 PR_ProfileUsedBy(profile_t *p); profile_t *PR_GetPlayerProfile(player_t *player); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/k_pwrlv.h b/src/k_pwrlv.h index 0dff84774..17822a661 100644 --- a/src/k_pwrlv.h +++ b/src/k_pwrlv.h @@ -15,6 +15,10 @@ #include "doomdef.h" #include "d_player.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef enum { PWRLV_DISABLED = -1, @@ -47,4 +51,8 @@ void K_CashInPowerLevels(void); void K_SetPowerLevelScrambles(SINT8 powertype); void K_PlayerForfeit(UINT8 playernum, boolean nopointloss); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/k_race.h b/src/k_race.h index b9021893e..390029e96 100644 --- a/src/k_race.h +++ b/src/k_race.h @@ -14,6 +14,10 @@ #include "r_defs.h" +#ifdef __cplusplus +extern "C" { +#endif + extern line_t *finishBeamLine; #define FINISHLINEBEAM_SPACING (48*mapobjectscale) @@ -66,4 +70,8 @@ boolean K_GenerateFinishBeamLine(void); void K_RunFinishLineBeam(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/k_respawn.h b/src/k_respawn.h index 81ee16b77..4d02f9931 100644 --- a/src/k_respawn.h +++ b/src/k_respawn.h @@ -15,6 +15,10 @@ #include "k_waypoint.h" #include "d_player.h" +#ifdef __cplusplus +extern "C" { +#endif + #define RESPAWN_DIST 1024 #define RESPAWN_TIME 48 #define RESPAWNST_NONE 0x00 @@ -98,4 +102,8 @@ size_t K_NextRespawnWaypointIndex(waypoint_t *waypoint); void K_RespawnChecker(player_t *player); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/k_roulette.h b/src/k_roulette.h index 0cef89f7a..f4afb4988 100644 --- a/src/k_roulette.h +++ b/src/k_roulette.h @@ -16,6 +16,10 @@ #include "doomtype.h" #include "d_player.h" +#ifdef __cplusplus +extern "C" { +#endif + #define ROULETTE_SPACING (36 << FRACBITS) #define ROULETTE_SPACING_SPLITSCREEN (16 << FRACBITS) @@ -165,5 +169,8 @@ fixed_t K_GetRouletteOffset(itemroulette_t *const roulette, fixed_t renderDelta) void K_KartItemRoulette(player_t *const player, ticcmd_t *cmd); +#ifdef __cplusplus +} // extern "C" +#endif #endif // __K_ROULETTE_H__ diff --git a/src/k_specialstage.h b/src/k_specialstage.h index c93136b99..34df449fa 100644 --- a/src/k_specialstage.h +++ b/src/k_specialstage.h @@ -16,6 +16,10 @@ #include "doomdef.h" #include "doomstat.h" +#ifdef __cplusplus +extern "C" { +#endif + extern struct specialStage { boolean active; ///< If true, then we are in a special stage @@ -51,5 +55,8 @@ void K_InitSpecialStage(void); void K_TickSpecialStage(void); +#ifdef __cplusplus +} // extern "C" +#endif #endif diff --git a/src/k_terrain.h b/src/k_terrain.h index 166900036..4b452567d 100644 --- a/src/k_terrain.h +++ b/src/k_terrain.h @@ -20,6 +20,10 @@ #include "m_fixed.h" #include "p_mobj.h" +#ifdef __cplusplus +extern "C" { +#endif + #define TERRAIN_NAME_LEN 32 struct t_splash_t @@ -565,4 +569,8 @@ void K_UpdateTerrainOverlay(mobj_t *mo); void K_InitTerrain(UINT16 wadNum); +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __K_TERRAIN_H__ diff --git a/src/k_waypoint.h b/src/k_waypoint.h index 9239cd41c..c5f9a3a79 100644 --- a/src/k_waypoint.h +++ b/src/k_waypoint.h @@ -18,6 +18,10 @@ #include "p_mobj.h" #include "k_pathfind.h" +#ifdef __cplusplus +extern "C" { +#endif + #define DEFAULT_WAYPOINT_RADIUS (384) struct waypoint_t @@ -419,4 +423,8 @@ void K_ClearWaypoints(void); void K_AdjustWaypointsParameters (void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/keys.h b/src/keys.h index 6cdd7956c..6ba295572 100644 --- a/src/keys.h +++ b/src/keys.h @@ -13,6 +13,10 @@ #ifndef __KEYS_H__ #define __KEYS_H__ +#ifdef __cplusplus +extern "C" { +#endif + // These are the key codes as posted by the keyboard handler, // ascii codes are 0->127, // scancodes are 0x80 + 0->127 @@ -94,4 +98,8 @@ #define KEY_OPENBRACKETS #define KEY_CLOSEBRACKETS +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/lua_hook.h b/src/lua_hook.h index 600a7e672..7088e53c8 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -10,6 +10,9 @@ /// \file lua_hook.h /// \brief hooks for Lua scripting +#ifndef __LUA_HOOK_H__ +#define __LUA_HOOK_H__ + #include "r_defs.h" #include "d_player.h" #include "s_sound.h" @@ -17,6 +20,10 @@ #include "lua_hudlib_drawlist.h" +#ifdef __cplusplus +extern "C" { +#endif + /* Do you know what an 'X Macro' is? Such a macro is called over each element of a list and expands the input. I use it for the hook lists because both an enum @@ -143,3 +150,9 @@ int LUA_HookViewpointSwitch(player_t *player, player_t *newdisplayplayer, boole int LUA_HookSeenPlayer(player_t *player, player_t *seenfriend); int LUA_HookShouldJingleContinue(player_t *, const char *musname); int LUA_HookMusicChange(const char *oldname, struct MusicChange *); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // __LUA_HOOK_H__ diff --git a/src/lua_hud.h b/src/lua_hud.h index fc91811f0..20a6e6549 100644 --- a/src/lua_hud.h +++ b/src/lua_hud.h @@ -15,6 +15,10 @@ #include "lua_hudlib_drawlist.h" +#ifdef __cplusplus +extern "C" { +#endif + enum hud { hud_stagetitle = 0, hud_textspectator, @@ -49,4 +53,8 @@ boolean LUA_HudEnabled(enum hud option); void LUA_SetHudHook(int hook, huddrawlist_h list); +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __LUA_HUD_H__ diff --git a/src/lua_libs.h b/src/lua_libs.h index 9150cd98b..265cf8bc8 100644 --- a/src/lua_libs.h +++ b/src/lua_libs.h @@ -9,6 +9,12 @@ //----------------------------------------------------------------------------- /// \file lua_libs.h /// \brief libraries for Lua scripting +#ifndef __LUA_LIBS_H__ +#define __LUA_LIBS_H__ + +#ifdef __cplusplus +extern "C" { +#endif extern lua_State *gL; @@ -110,3 +116,9 @@ int LUA_TagLib(lua_State *L); int LUA_PolyObjLib(lua_State *L); int LUA_BlockmapLib(lua_State *L); int LUA_HudLib(lua_State *L); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // __LUA_LIBS_H__ diff --git a/src/lua_script.h b/src/lua_script.h index 2d19a5a04..9bfddc875 100644 --- a/src/lua_script.h +++ b/src/lua_script.h @@ -23,6 +23,10 @@ #include "blua/lualib.h" #include "blua/lauxlib.h" +#ifdef __cplusplus +extern "C" { +#endif + #define lua_optboolean(L, i) (!lua_isnoneornil(L, i) && lua_toboolean(L, i)) #define lua_opttrueboolean(L, i) (lua_isnoneornil(L, i) || lua_toboolean(L, i)) @@ -140,4 +144,8 @@ void COM_Lua_f(void); #define INLEVEL if (! ISINLEVEL)\ return luaL_error(L, "This can only be used in a level!"); +#ifdef __cplusplus +} // extern "C" +#endif + #endif/*LUA_SCRIPT_H*/ diff --git a/src/lzf.h b/src/lzf.h index 85daf255e..995e4ebd6 100644 --- a/src/lzf.h +++ b/src/lzf.h @@ -13,6 +13,10 @@ #define LZF_H #include +#ifdef __cplusplus +extern "C" { +#endif + /*********************************************************************** ** ** lzf -- an extremely fast/free compression/decompression-method @@ -71,5 +75,9 @@ size_t lzf_decompress (const void *const in_data, size_t in_len, void *out_data, size_t out_len); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/m_aatree.h b/src/m_aatree.h index 77bfd05fb..ce45f44dc 100644 --- a/src/m_aatree.h +++ b/src/m_aatree.h @@ -16,6 +16,10 @@ #include "doomtype.h" +#ifdef __cplusplus +extern "C" { +#endif + // Flags for AA trees. #define AATREE_ZUSER 1 // Treat values as z_zone-allocated blocks and set their user fields @@ -27,4 +31,8 @@ void M_AATreeSet(aatree_t *aatree, INT32 key, void* value); void *M_AATreeGet(aatree_t *aatree, INT32 key); void M_AATreeIterate(aatree_t *aatree, aatree_iter_t callback); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/m_anigif.h b/src/m_anigif.h index abe05dd96..9ee209aea 100644 --- a/src/m_anigif.h +++ b/src/m_anigif.h @@ -17,6 +17,10 @@ #include "command.h" #include "screen.h" +#ifdef __cplusplus +extern "C" { +#endif + #if NUMSCREENS > 2 #define HAVE_ANIGIF #endif @@ -29,4 +33,8 @@ INT32 GIF_close(void); extern consvar_t cv_gif_optimize, cv_gif_downscale, cv_gif_dynamicdelay, cv_gif_localcolortable; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/m_argv.h b/src/m_argv.h index 92770f4e9..05ffb797d 100644 --- a/src/m_argv.h +++ b/src/m_argv.h @@ -14,6 +14,10 @@ #ifndef __M_ARGV__ #define __M_ARGV__ +#ifdef __cplusplus +extern "C" { +#endif + // // MISC // @@ -39,4 +43,8 @@ const char *M_GetNextParm(void); // Finds and loads a response file (@moreargs.txt) void M_FindResponseFile(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif //__M_ARGV__ diff --git a/src/m_bbox.h b/src/m_bbox.h index 9b63c61b6..3841854d3 100644 --- a/src/m_bbox.h +++ b/src/m_bbox.h @@ -16,6 +16,10 @@ #include "m_fixed.h" +#ifdef __cplusplus +extern "C" { +#endif + /** \brief Bounding box coordinate storage */ @@ -34,4 +38,8 @@ void M_AddToBox(fixed_t *box, fixed_t x, fixed_t y); boolean M_PointInBox(fixed_t *box, fixed_t x, fixed_t y); boolean M_CircleTouchBox(fixed_t *box, fixed_t circlex, fixed_t circley, fixed_t circleradius); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/m_cheat.h b/src/m_cheat.h index c952721c3..b8b85db00 100644 --- a/src/m_cheat.h +++ b/src/m_cheat.h @@ -19,6 +19,10 @@ #include "p_mobj.h" #include "command.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef enum { CHEAT_NOCLIP, CHEAT_GOD, @@ -83,4 +87,8 @@ void Command_CauseCfail_f(void); void Command_Dumplua_f(void); #endif +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/m_cond.h b/src/m_cond.h index 5c50146f0..5ab291c35 100644 --- a/src/m_cond.h +++ b/src/m_cond.h @@ -10,8 +10,15 @@ /// \file m_cond.h /// \brief Unlockable condition system for SRB2 version 2.1 +#ifndef __M_COND_H__ +#define __M_COND_H__ + #include "doomdef.h" +#ifdef __cplusplus +extern "C" { +#endif + // -------- // Typedefs // -------- @@ -234,3 +241,9 @@ INT32 M_EmblemSkinNum(emblem_t *emblem); UINT16 M_EmblemMapNum(emblem_t *emblem); #define M_Achieved(a) ((a) >= MAXCONDITIONSETS || gamedata->achieved[a]) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // __M_COND_H__ diff --git a/src/m_dllist.h b/src/m_dllist.h index 1a1f0a6ea..a80022a2e 100644 --- a/src/m_dllist.h +++ b/src/m_dllist.h @@ -25,6 +25,10 @@ #ifndef M_DLLIST_H__ #define M_DLLIST_H__ +#ifdef __cplusplus +extern "C" { +#endif + #ifdef _MSC_VER #pragma warning(disable : 4706) #endif @@ -54,6 +58,10 @@ FUNCINLINE static ATTRINLINE void M_DLListRemove(mdllistitem_t *item) next->prev = prev; } +#ifdef __cplusplus +} // extern "C" +#endif + #endif // EOF diff --git a/src/m_easing.h b/src/m_easing.h index 435ad35e7..4dc84320c 100644 --- a/src/m_easing.h +++ b/src/m_easing.h @@ -15,6 +15,10 @@ #include "doomtype.h" #include "m_fixed.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef enum { EASE_LINEAR = 0, @@ -98,4 +102,9 @@ EASINGFUNC(OutBackParameterized) /* Easing_OutBackParameterized */ EASINGFUNC(InOutBackParameterized) /* Easing_InOutBackParameterized */ #undef EASINGFUNC + +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/m_fixed.h b/src/m_fixed.h index b605434fb..57dde19bd 100644 --- a/src/m_fixed.h +++ b/src/m_fixed.h @@ -20,6 +20,10 @@ #include #endif +#ifdef __cplusplus +extern "C" { +#endif + /*! \brief bits of the fraction */ @@ -413,4 +417,8 @@ void FM_MultMatrix(matrix_t *dest, const matrix_t *multme); void FM_Translate(matrix_t *dest, fixed_t x, fixed_t y, fixed_t z); void FM_Scale(matrix_t *dest, fixed_t x, fixed_t y, fixed_t z); +#ifdef __cplusplus +} // extern "C" +#endif + #endif //m_fixed.h diff --git a/src/m_misc.h b/src/m_misc.h index f4beb8501..97cc3e2c8 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -21,6 +21,10 @@ #include "d_event.h" // Screenshot responder #include "command.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef enum { MM_OFF = 0, MM_APNG, @@ -140,4 +144,8 @@ FUNCMATH UINT8 M_CountBits(UINT32 num, UINT8 size); #include "w_wad.h" extern char configfile[MAX_WADPATH]; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/m_perfstats.h b/src/m_perfstats.h index 186447827..f95776e1a 100644 --- a/src/m_perfstats.h +++ b/src/m_perfstats.h @@ -16,6 +16,10 @@ #include "lua_script.h" #include "p_local.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef enum { PS_OFF = 0, @@ -62,4 +66,8 @@ void PS_ResetBotInfo(void); void M_DrawPerfStats(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/m_queue.h b/src/m_queue.h index 8e0c02797..4b8c15c1b 100644 --- a/src/m_queue.h +++ b/src/m_queue.h @@ -13,6 +13,10 @@ #ifndef M_QUEUE_H #define M_QUEUE_H +#ifdef __cplusplus +extern "C" { +#endif + struct mqueueitem_t { mqueueitem_t *next; @@ -31,6 +35,10 @@ mqueueitem_t *M_QueueIterator(mqueue_t *queue); void M_QueueResetIterator(mqueue_t *queue); void M_QueueFree(mqueue_t *queue); +#ifdef __cplusplus +} // extern "C" +#endif + #endif // EOF diff --git a/src/m_random.h b/src/m_random.h index 9172648a7..e9591970d 100644 --- a/src/m_random.h +++ b/src/m_random.h @@ -18,6 +18,10 @@ #include "doomtype.h" #include "m_fixed.h" +#ifdef __cplusplus +extern "C" { +#endif + //#define DEBUGRANDOM typedef enum @@ -127,4 +131,8 @@ void P_SetRandSeedNet(pr_class_t pr_class, UINT32 init, UINT32 seed); void P_ClearRandom(UINT32 seed); UINT32 M_RandomizedSeed(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/m_swap.h b/src/m_swap.h index faa54e0b2..5b3c7ee56 100644 --- a/src/m_swap.h +++ b/src/m_swap.h @@ -16,6 +16,10 @@ #include "endian.h" +#ifdef __cplusplus +extern "C" { +#endif + #define SWAP_SHORT(x) ((INT16)(\ (((UINT16)(x) & (UINT16)0x00ffU) << 8) \ | \ @@ -53,4 +57,8 @@ #define BIGENDIAN_SHORT(x) ((INT16)(x)) #endif +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/md5.h b/src/md5.h index eaa85dc19..8e7c1fc1a 100644 --- a/src/md5.h +++ b/src/md5.h @@ -74,6 +74,10 @@ typedef u_int32_t md5_uint32; #define __P(x) () #endif +#ifdef __cplusplus +extern "C" { +#endif + /* * The following three functions are build up the low level used in * the functions `md5_stream' and `md5_buffer'. @@ -128,4 +132,8 @@ int md5_stream __P ((FILE *stream, void *resblock)); digest. */ extern void *md5_buffer __P ((const char *buffer, size_t len, void *resblock)); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/mserv.h b/src/mserv.h index b47bf2c25..7417585d6 100644 --- a/src/mserv.h +++ b/src/mserv.h @@ -16,6 +16,10 @@ #include "i_threads.h" +#ifdef __cplusplus +extern "C" { +#endif + #if defined(_MSC_VER) #pragma pack(1) #endif @@ -91,4 +95,8 @@ void HMS_list_servers (void); msg_server_t * HMS_fetch_servers (msg_server_t *list, int id); int HMS_compare_mod_version (char *buffer, size_t size_of_buffer); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/p_local.h b/src/p_local.h index 95677b447..06adebf6b 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -24,6 +24,10 @@ #include "p_maputl.h" #include "doomstat.h" // MAXSPLITSCREENPLAYERS +#ifdef __cplusplus +extern "C" { +#endif + #define FLOATSPEED (FRACUNIT*4) //#define VIEWHEIGHTS "41" @@ -578,4 +582,8 @@ fixed_t P_GetMobjFeet(const mobj_t *); fixed_t P_GetMobjGround(const mobj_t *); fixed_t P_GetMobjZMovement(mobj_t *mo); +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __P_LOCAL__ diff --git a/src/p_maputl.h b/src/p_maputl.h index 15e2abbf4..5718afd04 100644 --- a/src/p_maputl.h +++ b/src/p_maputl.h @@ -17,6 +17,10 @@ #include "r_defs.h" #include "m_fixed.h" +#ifdef __cplusplus +extern "C" { +#endif + // // P_MAPUTL // @@ -88,4 +92,9 @@ extern divline_t trace; // bbox defined by the radius //boolean P_RadiusLinesCheck(fixed_t radius, fixed_t x, fixed_t y, // boolean (*func)(line_t *)); + +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __P_MAPUTL__ diff --git a/src/p_mobj.h b/src/p_mobj.h index 8b569f069..e73e834da 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -28,6 +28,10 @@ // Needs precompiled tables/data structures. #include "info.h" +#ifdef __cplusplus +extern "C" { +#endif + // // NOTES: mobj_t // @@ -556,4 +560,9 @@ extern UINT16 emeraldspawndelay; extern INT32 numstarposts; extern UINT16 bossdisabled; extern boolean stoppedclock; + +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/p_polyobj.h b/src/p_polyobj.h index 91f8079d3..11aefb4cd 100644 --- a/src/p_polyobj.h +++ b/src/p_polyobj.h @@ -18,6 +18,10 @@ #include "p_mobj.h" #include "r_defs.h" +#ifdef __cplusplus +extern "C" { +#endif + // // Defines // @@ -397,6 +401,10 @@ extern polyobj_t *PolyObjects; extern INT32 numPolyObjects; extern polymaplink_t **polyblocklinks; // polyobject blockmap +#ifdef __cplusplus +} // extern "C" +#endif + #endif // EOF diff --git a/src/p_pspr.h b/src/p_pspr.h index ff2ead048..82fe1af74 100644 --- a/src/p_pspr.h +++ b/src/p_pspr.h @@ -31,6 +31,10 @@ // and the Frame Sequence table. #include "info.h" +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __GNUG__ #pragma interface #endif @@ -120,4 +124,8 @@ typedef enum NUMTRANSMAPS, } transnum_t; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/p_saveg.h b/src/p_saveg.h index a658d63c9..a0b0f8587 100644 --- a/src/p_saveg.h +++ b/src/p_saveg.h @@ -14,6 +14,10 @@ #ifndef __P_SAVEG__ #define __P_SAVEG__ +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __GNUG__ #pragma interface #endif @@ -53,4 +57,8 @@ struct savebuffer_t size_t size; }; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/p_setup.h b/src/p_setup.h index 9284a2b0d..f203c00de 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -19,6 +19,10 @@ #include "r_defs.h" #include "k_terrain.h" +#ifdef __cplusplus +extern "C" { +#endif + // map md5, sent to players via PT_SERVERINFO extern unsigned char mapmd5[16]; @@ -145,4 +149,8 @@ void P_DeleteFlickies(INT16 i); // Needed for NiGHTS void P_ReloadRings(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/p_slopes.h b/src/p_slopes.h index 454dd344f..0a2205fce 100644 --- a/src/p_slopes.h +++ b/src/p_slopes.h @@ -15,6 +15,10 @@ #include "m_fixed.h" // Vectors +#ifdef __cplusplus +extern "C" { +#endif + extern pslope_t *slopelist; extern UINT16 slopecount; @@ -139,4 +143,9 @@ struct dynvertexplanethink_t void T_DynamicSlopeLine (dynlineplanethink_t* th); void T_DynamicSlopeVert (dynvertexplanethink_t* th); + +#ifdef __cplusplus +} // extern "C" +#endif + #endif // #ifndef P_SLOPES_H__ diff --git a/src/p_spec.h b/src/p_spec.h index 7aa0f5185..fcd5348a8 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -17,6 +17,10 @@ #ifndef __P_SPEC__ #define __P_SPEC__ +#ifdef __cplusplus +extern "C" { +#endif + extern mobj_t *skyboxviewpnts[16]; // array of MT_SKYBOX viewpoint mobjs extern mobj_t *skyboxcenterpnts[16]; // array of MT_SKYBOX centerpoint mobjs @@ -1189,4 +1193,8 @@ enum LT_SLOPE_ANCHORS_OLD = 779, }; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/p_tick.h b/src/p_tick.h index f892942ea..a1018d721 100644 --- a/src/p_tick.h +++ b/src/p_tick.h @@ -14,6 +14,10 @@ #ifndef __P_TICK__ #define __P_TICK__ +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __GNUG__ #pragma interface #endif @@ -43,4 +47,8 @@ INT32 P_AltFlip(INT32 value, tic_t tics); // A full cycle takes 4 * tics. INT32 P_LerpFlip(INT32 value, tic_t tics); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/r_bsp.h b/src/r_bsp.h index 0c232d67b..5a24ffe47 100644 --- a/src/r_bsp.h +++ b/src/r_bsp.h @@ -14,6 +14,10 @@ #ifndef __R_BSP__ #define __R_BSP__ +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __GNUG__ #pragma interface #endif @@ -58,4 +62,9 @@ boolean R_IsEmptyLine(seg_t *line, sector_t *front, sector_t *back); INT32 R_GetPlaneLight(sector_t *sector, fixed_t planeheight, boolean underside); void R_Prep3DFloors(sector_t *sector); + +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/r_data.h b/src/r_data.h index 5ba30010c..17368bb3c 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -18,6 +18,10 @@ #include "r_state.h" #include "p_setup.h" // levelflats +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __GNUG__ #pragma interface #endif @@ -121,4 +125,8 @@ const char *R_NameForColormap(extracolormap_t *extra_colormap); UINT8 NearestPaletteColor(UINT8 r, UINT8 g, UINT8 b, RGBA_t *palette); #define NearestColor(r, g, b) NearestPaletteColor(r, g, b, NULL) +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/r_defs.h b/src/r_defs.h index 9853f8593..e5c6ea834 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -30,6 +30,10 @@ #include "taglist.h" +#ifdef __cplusplus +extern "C" { +#endif + // // ClipWallSegment // Clips the given range of columns @@ -977,4 +981,8 @@ struct spritedef_t spriteframe_t *spriteframes; }; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/r_draw.h b/src/r_draw.h index aee8ecc5f..beb19b739 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -16,6 +16,10 @@ #include "r_defs.h" +#ifdef __cplusplus +extern "C" { +#endif + // ------------------------------- // COMMON STUFF FOR 8bpp AND 16bpp // ------------------------------- @@ -252,5 +256,9 @@ void R_DrawTranslatedColumn_16(void); void R_DrawSpan_16(void); #endif +#ifdef __cplusplus +} // extern "C" +#endif + // ========================================================================= #endif // __R_DRAW__ diff --git a/src/r_fps.h b/src/r_fps.h index 8a12e1d10..969c427fa 100644 --- a/src/r_fps.h +++ b/src/r_fps.h @@ -19,6 +19,10 @@ #include "p_local.h" #include "r_state.h" +#ifdef __cplusplus +extern "C" { +#endif + extern consvar_t cv_fpscap; UINT32 R_GetFramerateCap(void); @@ -168,4 +172,8 @@ void R_UpdateMobjInterpolators(void); void R_ResetMobjInterpolationState(mobj_t *mobj); void R_ResetPrecipitationMobjInterpolationState(precipmobj_t *mobj); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/r_local.h b/src/r_local.h index 4ccb766cf..72ee66fe9 100644 --- a/src/r_local.h +++ b/src/r_local.h @@ -35,8 +35,16 @@ #include "r_things.h" #include "r_draw.h" +#ifdef __cplusplus +extern "C" { +#endif + extern drawseg_t *firstseg; void SplitScreen_OnChange(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __R_LOCAL__ diff --git a/src/r_main.h b/src/r_main.h index c3e60a0ca..01a0d9b31 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -18,6 +18,10 @@ #include "r_data.h" #include "r_textures.h" +#ifdef __cplusplus +extern "C" { +#endif + // // POV related. // @@ -144,4 +148,9 @@ void R_RenderPlayerView(void); // add commands related to engine, at game startup void R_RegisterEngineStuff(void); + +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/r_patch.h b/src/r_patch.h index b86908281..dd3a6a29c 100644 --- a/src/r_patch.h +++ b/src/r_patch.h @@ -17,6 +17,10 @@ #include "doomdef.h" #include "d_player.h" +#ifdef __cplusplus +extern "C" { +#endif + // Patch functions patch_t *Patch_Create(softwarepatch_t *source, size_t srcsize, void *dest); void Patch_Free(patch_t *patch); @@ -46,4 +50,8 @@ angle_t R_ModelRotationAngle(mobj_t *mobj, player_t *viewPlayer); angle_t R_SpriteRotationAngle(mobj_t *mobj, player_t *viewPlayer); #endif +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __R_PATCH__ diff --git a/src/r_patchrotation.h b/src/r_patchrotation.h index 2744f71d2..4c463a8ce 100644 --- a/src/r_patchrotation.h +++ b/src/r_patchrotation.h @@ -12,10 +12,19 @@ #include "r_patch.h" #include "r_picformats.h" +#ifdef __cplusplus +extern "C" { +#endif + #ifdef ROTSPRITE rotsprite_t *RotatedPatch_Create(INT32 numangles); void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip); extern fixed_t rollcosang[ROTANGLES]; extern fixed_t rollsinang[ROTANGLES]; + +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/r_picformats.h b/src/r_picformats.h index 57af58100..3ce99a924 100644 --- a/src/r_picformats.h +++ b/src/r_picformats.h @@ -17,6 +17,10 @@ #include "r_defs.h" #include "doomdef.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef enum { PICFMT_NONE = 0, @@ -127,4 +131,8 @@ extern spriteinfo_t spriteinfo[NUMSPRITES]; void R_LoadSpriteInfoLumps(UINT16 wadnum, UINT16 numlumps); void R_ParseSPRTINFOLump(UINT16 wadNum, UINT16 lumpNum); +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __R_PICFORMATS__ diff --git a/src/r_plane.h b/src/r_plane.h index 782691af6..e238878f5 100644 --- a/src/r_plane.h +++ b/src/r_plane.h @@ -14,6 +14,10 @@ #ifndef __R_PLANE__ #define __R_PLANE__ +#ifdef __cplusplus +extern "C" { +#endif + #include "screen.h" // needs MAXVIDWIDTH/MAXVIDHEIGHT #include "r_data.h" #include "r_textures.h" @@ -127,4 +131,9 @@ struct visffloor_t extern visffloor_t ffloor[MAXFFLOORS]; extern INT32 numffloors; + +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/r_portal.h b/src/r_portal.h index 4f665f90b..933ff31d9 100644 --- a/src/r_portal.h +++ b/src/r_portal.h @@ -18,6 +18,10 @@ #include "r_textures.h" #include "r_plane.h" // visplanes +#ifdef __cplusplus +extern "C" { +#endif + /** Portal structure for the software renderer. */ struct portal_t @@ -58,4 +62,9 @@ void Portal_ClipRange (portal_t* portal); void Portal_ClipApply (const portal_t* portal); void Portal_AddSkyboxPortals (const player_t* player); + +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/r_segs.h b/src/r_segs.h index ace5711d4..b9052cfa4 100644 --- a/src/r_segs.h +++ b/src/r_segs.h @@ -14,6 +14,10 @@ #ifndef __R_SEGS__ #define __R_SEGS__ +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __GNUG__ #pragma interface #endif @@ -23,4 +27,8 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2); void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pffloor); void R_StoreWallRange(INT32 start, INT32 stop); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/r_skins.h b/src/r_skins.h index 551cf56b9..fe29282e7 100644 --- a/src/r_skins.h +++ b/src/r_skins.h @@ -21,6 +21,10 @@ #include "r_picformats.h" // spriteinfo_t #include "r_defs.h" // spritedef_t +#ifdef __cplusplus +extern "C" { +#endif + /// Defaults #define SKINRIVALS 3 // should be all lowercase!! S_SKIN processing does a strlwr @@ -95,4 +99,8 @@ void R_AddSkins(UINT16 wadnum, boolean mainfile); UINT8 P_GetSkinSprite2(skin_t *skin, UINT8 spr2, player_t *player); +#ifdef __cplusplus +} // extern "C" +#endif + #endif //__R_SKINS__ diff --git a/src/r_sky.h b/src/r_sky.h index 123d66274..abf29b508 100644 --- a/src/r_sky.h +++ b/src/r_sky.h @@ -16,6 +16,10 @@ #include "m_fixed.h" +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __GNUG__ #pragma interface #endif @@ -38,4 +42,8 @@ void R_SetupSkyDraw(void); void R_SetSkyScale(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/r_splats.h b/src/r_splats.h index 23e475c06..f5a92cb08 100644 --- a/src/r_splats.h +++ b/src/r_splats.h @@ -16,6 +16,10 @@ #include "r_defs.h" #include "r_things.h" +#ifdef __cplusplus +extern "C" { +#endif + // ========================================================================== // DEFINITIONS // ========================================================================== @@ -43,4 +47,8 @@ struct floorsplat_t void R_DrawFloorSplat(vissprite_t *spr); +#ifdef __cplusplus +} // extern "C" +#endif + #endif /*__R_SPLATS_H__*/ diff --git a/src/r_state.h b/src/r_state.h index 4807a0f92..1a9652122 100644 --- a/src/r_state.h +++ b/src/r_state.h @@ -19,6 +19,10 @@ #include "r_data.h" #include "doomstat.h" // MAXSPLITSCREENPLAYERS +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __GNUG__ #pragma interface #endif @@ -119,4 +123,8 @@ extern angle_t rw_normalangle; // angle to line origin extern angle_t rw_angle1; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/r_textures.h b/src/r_textures.h index 8f39f5bd4..f413e9d0f 100644 --- a/src/r_textures.h +++ b/src/r_textures.h @@ -19,6 +19,10 @@ #include "p_setup.h" // levelflats #include "r_data.h" +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __GNUG__ #pragma interface #endif @@ -107,4 +111,8 @@ lumpnum_t R_GetFlatNumForName(const char *name); extern INT32 numtextures; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/r_things.h b/src/r_things.h index f27f3a7c9..da35d9475 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -21,6 +21,10 @@ #include "r_defs.h" #include "r_skins.h" +#ifdef __cplusplus +extern "C" { +#endif + // -------------- // SPRITE LOADING // -------------- @@ -312,4 +316,8 @@ FUNCMATH FUNCINLINE static ATTRINLINE UINT8 R_Char2Rotation(char cn) return 255; } +#ifdef __cplusplus +} // extern "C" +#endif + #endif //__R_THINGS__ diff --git a/src/s_sound.h b/src/s_sound.h index c9a86a2f5..bc55cc0e7 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -22,6 +22,13 @@ #ifdef HAVE_OPENMPT #include "libopenmpt/libopenmpt.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef HAVE_OPENMPT extern openmpt_module *openmpt_mhandle; #endif @@ -334,4 +341,8 @@ void S_StopSoundByNum(sfxenum_t sfxnum); #define S_StartScreamSound S_StartSound #endif +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/screen.h b/src/screen.h index d49f4aee2..23498de59 100644 --- a/src/screen.h +++ b/src/screen.h @@ -23,6 +23,10 @@ #define DNWH void * // unused in DOS version #endif +#ifdef __cplusplus +extern "C" { +#endif + // quickhack for V_Init()... to be cleaned up #ifdef NOPOSTPROCESSING #define NUMSCREENS 2 @@ -243,4 +247,9 @@ void SCR_ClosedCaptions(void); void SCR_DisplayLocalPing(void); void SCR_DisplayMarathonInfo(void); #undef DNWH + +#ifdef __cplusplus +} // extern "C" +#endif + #endif //__SCREEN_H__ diff --git a/src/sdl/endtxt.h b/src/sdl/endtxt.h index 41f8e51ad..5691312b4 100644 --- a/src/sdl/endtxt.h +++ b/src/sdl/endtxt.h @@ -19,6 +19,14 @@ #ifndef __ENDTXT__ #define __ENDTXT__ +#ifdef __cplusplus +extern "C" { +#endif + void ShowEndTxt (void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/sdl/hwsym_sdl.h b/src/sdl/hwsym_sdl.h index 7297587bf..7670935b1 100644 --- a/src/sdl/hwsym_sdl.h +++ b/src/sdl/hwsym_sdl.h @@ -16,8 +16,21 @@ /// \file /// \brief Tool for dynamic referencing of hardware rendering/3D sound functions +#ifndef __SDL_HWSYM_SDL_H__ +#define __SDL_HWSYM_SDL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + void *hwSym(const char *funcName,void *handle); void *hwOpen(const char *hwfile); void hwClose(void *handle); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // __SDL_HWSYM_SDL_H__ diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 707d20427..b390b6d1e 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -23,12 +23,6 @@ /// \file /// \brief SRB2 system stuff for SDL -#ifdef CMAKECONFIG -#include "config.h" -#else -#include "../config.h.in" -#endif - #include #ifdef _WIN32 diff --git a/src/sdl/i_ttf.h b/src/sdl/i_ttf.h index 5fae9ed16..3b0d16288 100644 --- a/src/sdl/i_ttf.h +++ b/src/sdl/i_ttf.h @@ -20,7 +20,11 @@ #define __I_TTF__ #include "../doomdef.h" -#include "SDL_ttf.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif // Default name for standard TTF file. #define FONTFILE "srb2.ttf" @@ -84,4 +88,9 @@ void I_TTFDrawText(TTF_Font *font, TextQuality quality, INT32 fgR, INT32 fgG, IN void I_StartupTTF(UINT32 fontpointsize, Uint32 initflags, Uint32 vidmodeflags); void I_ShutdownTTF(void); + +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/sdl/ogl_sdl.h b/src/sdl/ogl_sdl.h index 748e30bae..00697074a 100644 --- a/src/sdl/ogl_sdl.h +++ b/src/sdl/ogl_sdl.h @@ -17,8 +17,15 @@ /// \file /// \brief SDL specific part of the OpenGL API for SRB2 +#ifndef __SDL_OGL_SDL_H__ +#define __SDL_OGL_SDL_H__ + #include "../v_video.h" +#ifdef __cplusplus +extern "C" { +#endif + extern void *GLUhandle; boolean OglSdlSurface(INT32 w, INT32 h); @@ -33,3 +40,9 @@ extern Uint16 realheight; #ifdef _CREATE_DLL_ EXPORT void HWRAPI( OglSdlSetPalette ) (RGBA_t *palette); #endif + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // __SDL_OGL_SDL_H__ diff --git a/src/sdl/sdlmain.h b/src/sdl/sdlmain.h index 86d584632..8fd360248 100644 --- a/src/sdl/sdlmain.h +++ b/src/sdl/sdlmain.h @@ -25,6 +25,10 @@ extern SDL_bool framebuffer; #include "../m_fixed.h" #include "../doomdef.h" +#ifdef __cplusplus +extern "C" { +#endif + // SDL2 stub macro #ifdef _MSC_VER #define SDL2STUB() CONS_Printf("SDL2: stubbed: %s:%d\n", __FUNCTION__, __LINE__) @@ -89,4 +93,8 @@ void SDLforceUngrabMouse(void); // Needed for some WIN32 functions extern SDL_Window *window; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/sounds.h b/src/sounds.h index 51aecb94a..0c98c8ac2 100644 --- a/src/sounds.h +++ b/src/sounds.h @@ -16,6 +16,10 @@ #include "doomdef.h" +#ifdef __cplusplus +extern "C" { +#endif + // Customisable sounds for Skins typedef enum { @@ -1376,4 +1380,8 @@ sfxenum_t S_AddSoundFx(const char *name, boolean singular, INT32 flags, boolean extern sfxenum_t sfxfree; // sound test and slotting void S_RemoveSoundFx(sfxenum_t id); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/st_stuff.h b/src/st_stuff.h index e24343551..1224f227c 100644 --- a/src/st_stuff.h +++ b/src/st_stuff.h @@ -22,6 +22,10 @@ // SRB2Kart #include "r_skins.h" // NUMFACES +#ifdef __cplusplus +extern "C" { +#endif + // // STATUS BAR // @@ -85,4 +89,8 @@ extern patch_t *faceprefix[MAXSKINS][NUMFACES]; extern UINT16 objectsdrawn; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/stun.h b/src/stun.h index de23aeb42..7fe6bf42a 100644 --- a/src/stun.h +++ b/src/stun.h @@ -12,9 +12,17 @@ #ifndef KART_STUN_H #define KART_STUN_H +#ifdef __cplusplus +extern "C" { +#endif + typedef void (*stun_callback_t)(UINT32 address); void STUN_bind (stun_callback_t); boolean STUN_got_response (const char * const buffer, const size_t size); +#ifdef __cplusplus +} // extern "C" +#endif + #endif/*KART_STUN_H*/ diff --git a/src/tables.h b/src/tables.h index e122975e1..ac3bfe8a5 100644 --- a/src/tables.h +++ b/src/tables.h @@ -20,6 +20,10 @@ #include "m_fixed.h" +#ifdef __cplusplus +extern "C" { +#endif + #define FINEANGLES 8192 #define FINEMASK (FINEANGLES - 1) #define ANGLETOFINESHIFT 19 // 0x100000000 to 0x2000 @@ -132,4 +136,8 @@ void FM_Rotate(matrix_t *dest, angle_t angle, fixed_t x, fixed_t y, fixed_t z); #define FINECOSINE(n) (finecosine[n]>>(FINE_FRACBITS-FRACBITS)) #define FINETANGENT(n) (finetangent[n]>>(FINE_FRACBITS-FRACBITS)) +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/taglist.h b/src/taglist.h index 8db78b880..938e98fa4 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -16,6 +16,10 @@ #include "doomtype.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef INT16 mtag_t; #define MAXTAGS UINT16_MAX #define MTAG_GLOBAL -1 @@ -127,4 +131,8 @@ Notes: If no elements are found for a given tag, the loop inside won't be executed. */ +#ifdef __cplusplus +} // extern "C" +#endif + #endif //__R_TAGLIST__ diff --git a/src/typedef.h b/src/typedef.h index a2dd66997..23336dbf5 100644 --- a/src/typedef.h +++ b/src/typedef.h @@ -11,6 +11,13 @@ /// file exists so these types can be used anywhere /// without needing to include specific headers. +#ifndef __TYPEDEF_H__ +#define __TYPEDEF_H__ + +#ifdef __cplusplus +extern "C" { +#endif + #define TYPEDEF2(struct_id, new_type) \ typedef struct struct_id new_type @@ -399,3 +406,9 @@ TYPEDEF (wadfile_t); #undef TYPEDEF #undef TYPEDEF2 + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // __TYPEDEF_H__ diff --git a/src/v_video.h b/src/v_video.h index ddf5bb89e..8a47d87d0 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -21,6 +21,10 @@ // SRB2Kart #include "hu_stuff.h" // fonts +#ifdef __cplusplus +extern "C" { +#endif + // // VIDEO // @@ -402,4 +406,8 @@ void V_DrawPatchFill(patch_t *pat); void VID_BlitLinearScreen(const UINT8 *srcptr, UINT8 *destptr, INT32 width, INT32 height, size_t srcrowbytes, size_t destrowbytes); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/w_wad.h b/src/w_wad.h index 54bc9f4da..24c0ac74b 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -18,6 +18,10 @@ #include "hardware/hw_data.h" #endif +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __GNUG__ #pragma interface #endif @@ -217,4 +221,8 @@ void W_VerifyFileMD5(UINT16 wadfilenum, const char *matchmd5); int W_VerifyNMUSlumps(const char *filename, boolean exit_on_error); +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __W_WAD__ diff --git a/src/win32/win_dbg.h b/src/win32/win_dbg.h index 8f1692ea6..6daf991b4 100644 --- a/src/win32/win_dbg.h +++ b/src/win32/win_dbg.h @@ -16,10 +16,17 @@ /// \file /// \brief exception handler +#ifndef __WIN32_WIN_DBG_H__ +#define __WIN32_WIN_DBG_H__ + //#define WIN32_LEAN_AND_MEAN #define RPC_NO_WINDOWS_H #include +#ifdef __cplusplus +extern "C" { +#endif + #ifdef BUGTRAP BOOL InitBugTrap(void); @@ -62,3 +69,9 @@ void *__cdecl _exception_info(void); #endif // !__TRYLEVEL_NONE #endif // __MINGW32__ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // __WIN32_WIN_DBG_H__ diff --git a/src/y_inter.h b/src/y_inter.h index 6a887dea8..f7a0960e8 100644 --- a/src/y_inter.h +++ b/src/y_inter.h @@ -9,6 +9,13 @@ /// \file y_inter.h /// \brief Tally screens, or "Intermissions" as they were formally called in Doom +#ifndef __Y_INTER_H__ +#define __Y_INTER_H__ + +#ifdef __cplusplus +extern "C" { +#endif + void Y_IntermissionDrawer(void); void Y_Ticker(void); @@ -33,3 +40,9 @@ typedef enum extern intertype_t intertype; extern intertype_t intermissiontypes[NUMGAMETYPES]; + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // __Y_INTER_H__ diff --git a/src/z_zone.h b/src/z_zone.h index 94cf244cf..d45fde9b3 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -17,6 +17,10 @@ #include #include "doomtype.h" +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __GNUC__ // __attribute__ ((X)) #if (__GNUC__ > 4) || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 3 || (__GNUC_MINOR__ == 2 && __GNUC_PATCHLEVEL__ >= 5))) #define FUNCALLOC(X) __attribute__((alloc_size(X))) @@ -142,4 +146,8 @@ size_t Z_TagsUsage(INT32 lowtag, INT32 hightag); char *Z_StrDup(const char *in); #define Z_Unlock(p) (void)p // TODO: remove this now that NDS code has been removed +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index 4dd5304e5..8a1edf778 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -620,3 +620,5 @@ if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}") add_library(acsvm::acsvm ALIAS acsvm) endif() endif() + +add_subdirectory(tcbrindle_span) diff --git a/thirdparty/tcbrindle_span/CMakeLists.txt b/thirdparty/tcbrindle_span/CMakeLists.txt new file mode 100644 index 000000000..a9a5bf643 --- /dev/null +++ b/thirdparty/tcbrindle_span/CMakeLists.txt @@ -0,0 +1,8 @@ +# https://github.com/tcbrindle/span/ +# Portable implementation of C++20 std::span +# Boost License 1.0 + +add_library(tcbrindle_span INTERFACE include/tcb/span.hpp) +target_include_directories(tcbrindle_span INTERFACE include) + +add_library(tcbrindle::span ALIAS tcbrindle_span) diff --git a/thirdparty/tcbrindle_span/include/tcb/span.hpp b/thirdparty/tcbrindle_span/include/tcb/span.hpp new file mode 100644 index 000000000..fdc3a988a --- /dev/null +++ b/thirdparty/tcbrindle_span/include/tcb/span.hpp @@ -0,0 +1,618 @@ + +/* +This is an implementation of C++20's std::span +http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/n4820.pdf +*/ + +// Copyright Tristan Brindle 2018. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file ../../LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +#ifndef TCB_SPAN_HPP_INCLUDED +#define TCB_SPAN_HPP_INCLUDED + +#include +#include +#include +#include + +#ifndef TCB_SPAN_NO_EXCEPTIONS +// Attempt to discover whether we're being compiled with exception support +#if !(defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) +#define TCB_SPAN_NO_EXCEPTIONS +#endif +#endif + +#ifndef TCB_SPAN_NO_EXCEPTIONS +#include +#include +#endif + +// Various feature test macros + +#ifndef TCB_SPAN_NAMESPACE_NAME +#define TCB_SPAN_NAMESPACE_NAME tcb +#endif + +#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) +#define TCB_SPAN_HAVE_CPP17 +#endif + +#if __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) +#define TCB_SPAN_HAVE_CPP14 +#endif + +namespace TCB_SPAN_NAMESPACE_NAME { + +// Establish default contract checking behavior +#if !defined(TCB_SPAN_THROW_ON_CONTRACT_VIOLATION) && \ + !defined(TCB_SPAN_TERMINATE_ON_CONTRACT_VIOLATION) && \ + !defined(TCB_SPAN_NO_CONTRACT_CHECKING) +#if defined(NDEBUG) || !defined(TCB_SPAN_HAVE_CPP14) +#define TCB_SPAN_NO_CONTRACT_CHECKING +#else +#define TCB_SPAN_TERMINATE_ON_CONTRACT_VIOLATION +#endif +#endif + +#if defined(TCB_SPAN_THROW_ON_CONTRACT_VIOLATION) +struct contract_violation_error : std::logic_error { + explicit contract_violation_error(const char* msg) : std::logic_error(msg) + {} +}; + +inline void contract_violation(const char* msg) +{ + throw contract_violation_error(msg); +} + +#elif defined(TCB_SPAN_TERMINATE_ON_CONTRACT_VIOLATION) +[[noreturn]] inline void contract_violation(const char* /*unused*/) +{ + std::terminate(); +} +#endif + +#if !defined(TCB_SPAN_NO_CONTRACT_CHECKING) +#define TCB_SPAN_STRINGIFY(cond) #cond +#define TCB_SPAN_EXPECT(cond) \ + cond ? (void) 0 : contract_violation("Expected " TCB_SPAN_STRINGIFY(cond)) +#else +#define TCB_SPAN_EXPECT(cond) +#endif + +#if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_inline_variables) +#define TCB_SPAN_INLINE_VAR inline +#else +#define TCB_SPAN_INLINE_VAR +#endif + +#if defined(TCB_SPAN_HAVE_CPP14) || \ + (defined(__cpp_constexpr) && __cpp_constexpr >= 201304) +#define TCB_SPAN_HAVE_CPP14_CONSTEXPR +#endif + +#if defined(TCB_SPAN_HAVE_CPP14_CONSTEXPR) +#define TCB_SPAN_CONSTEXPR14 constexpr +#else +#define TCB_SPAN_CONSTEXPR14 +#endif + +#if defined(TCB_SPAN_HAVE_CPP14_CONSTEXPR) && \ + (!defined(_MSC_VER) || _MSC_VER > 1900) +#define TCB_SPAN_CONSTEXPR_ASSIGN constexpr +#else +#define TCB_SPAN_CONSTEXPR_ASSIGN +#endif + +#if defined(TCB_SPAN_NO_CONTRACT_CHECKING) +#define TCB_SPAN_CONSTEXPR11 constexpr +#else +#define TCB_SPAN_CONSTEXPR11 TCB_SPAN_CONSTEXPR14 +#endif + +#if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_deduction_guides) +#define TCB_SPAN_HAVE_DEDUCTION_GUIDES +#endif + +#if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_lib_byte) +#define TCB_SPAN_HAVE_STD_BYTE +#endif + +#if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_lib_array_constexpr) +#define TCB_SPAN_HAVE_CONSTEXPR_STD_ARRAY_ETC +#endif + +#if defined(TCB_SPAN_HAVE_CONSTEXPR_STD_ARRAY_ETC) +#define TCB_SPAN_ARRAY_CONSTEXPR constexpr +#else +#define TCB_SPAN_ARRAY_CONSTEXPR +#endif + +#ifdef TCB_SPAN_HAVE_STD_BYTE +using byte = std::byte; +#else +using byte = unsigned char; +#endif + +#if defined(TCB_SPAN_HAVE_CPP17) +#define TCB_SPAN_NODISCARD [[nodiscard]] +#else +#define TCB_SPAN_NODISCARD +#endif + +TCB_SPAN_INLINE_VAR constexpr std::size_t dynamic_extent = SIZE_MAX; + +template +class span; + +namespace detail { + +template +struct span_storage { + constexpr span_storage() noexcept = default; + + constexpr span_storage(E* p_ptr, std::size_t /*unused*/) noexcept + : ptr(p_ptr) + {} + + E* ptr = nullptr; + static constexpr std::size_t size = S; +}; + +template +struct span_storage { + constexpr span_storage() noexcept = default; + + constexpr span_storage(E* p_ptr, std::size_t p_size) noexcept + : ptr(p_ptr), size(p_size) + {} + + E* ptr = nullptr; + std::size_t size = 0; +}; + +// Reimplementation of C++17 std::size() and std::data() +#if defined(TCB_SPAN_HAVE_CPP17) || \ + defined(__cpp_lib_nonmember_container_access) +using std::data; +using std::size; +#else +template +constexpr auto size(const C& c) -> decltype(c.size()) +{ + return c.size(); +} + +template +constexpr std::size_t size(const T (&)[N]) noexcept +{ + return N; +} + +template +constexpr auto data(C& c) -> decltype(c.data()) +{ + return c.data(); +} + +template +constexpr auto data(const C& c) -> decltype(c.data()) +{ + return c.data(); +} + +template +constexpr T* data(T (&array)[N]) noexcept +{ + return array; +} + +template +constexpr const E* data(std::initializer_list il) noexcept +{ + return il.begin(); +} +#endif // TCB_SPAN_HAVE_CPP17 + +#if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_lib_void_t) +using std::void_t; +#else +template +using void_t = void; +#endif + +template +using uncvref_t = + typename std::remove_cv::type>::type; + +template +struct is_span : std::false_type {}; + +template +struct is_span> : std::true_type {}; + +template +struct is_std_array : std::false_type {}; + +template +struct is_std_array> : std::true_type {}; + +template +struct has_size_and_data : std::false_type {}; + +template +struct has_size_and_data())), + decltype(detail::data(std::declval()))>> + : std::true_type {}; + +template > +struct is_container { + static constexpr bool value = + !is_span::value && !is_std_array::value && + !std::is_array::value && has_size_and_data::value; +}; + +template +using remove_pointer_t = typename std::remove_pointer::type; + +template +struct is_container_element_type_compatible : std::false_type {}; + +template +struct is_container_element_type_compatible< + T, E, + typename std::enable_if< + !std::is_same< + typename std::remove_cv()))>::type, + void>::value && + std::is_convertible< + remove_pointer_t()))> (*)[], + E (*)[]>::value + >::type> + : std::true_type {}; + +template +struct is_complete : std::false_type {}; + +template +struct is_complete : std::true_type {}; + +} // namespace detail + +template +class span { + static_assert(std::is_object::value, + "A span's ElementType must be an object type (not a " + "reference type or void)"); + static_assert(detail::is_complete::value, + "A span's ElementType must be a complete type (not a forward " + "declaration)"); + static_assert(!std::is_abstract::value, + "A span's ElementType cannot be an abstract class type"); + + using storage_type = detail::span_storage; + +public: + // constants and types + using element_type = ElementType; + using value_type = typename std::remove_cv::type; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + using pointer = element_type*; + using const_pointer = const element_type*; + using reference = element_type&; + using const_reference = const element_type&; + using iterator = pointer; + using reverse_iterator = std::reverse_iterator; + + static constexpr size_type extent = Extent; + + // [span.cons], span constructors, copy, assignment, and destructor + template < + std::size_t E = Extent, + typename std::enable_if<(E == dynamic_extent || E <= 0), int>::type = 0> + constexpr span() noexcept + {} + + TCB_SPAN_CONSTEXPR11 span(pointer ptr, size_type count) + : storage_(ptr, count) + { + TCB_SPAN_EXPECT(extent == dynamic_extent || count == extent); + } + + TCB_SPAN_CONSTEXPR11 span(pointer first_elem, pointer last_elem) + : storage_(first_elem, last_elem - first_elem) + { + TCB_SPAN_EXPECT(extent == dynamic_extent || + last_elem - first_elem == + static_cast(extent)); + } + + template ::value, + int>::type = 0> + constexpr span(element_type (&arr)[N]) noexcept : storage_(arr, N) + {} + + template &, ElementType>::value, + int>::type = 0> + TCB_SPAN_ARRAY_CONSTEXPR span(std::array& arr) noexcept + : storage_(arr.data(), N) + {} + + template &, ElementType>::value, + int>::type = 0> + TCB_SPAN_ARRAY_CONSTEXPR span(const std::array& arr) noexcept + : storage_(arr.data(), N) + {} + + template < + typename Container, std::size_t E = Extent, + typename std::enable_if< + E == dynamic_extent && detail::is_container::value && + detail::is_container_element_type_compatible< + Container&, ElementType>::value, + int>::type = 0> + constexpr span(Container& cont) + : storage_(detail::data(cont), detail::size(cont)) + {} + + template < + typename Container, std::size_t E = Extent, + typename std::enable_if< + E == dynamic_extent && detail::is_container::value && + detail::is_container_element_type_compatible< + const Container&, ElementType>::value, + int>::type = 0> + constexpr span(const Container& cont) + : storage_(detail::data(cont), detail::size(cont)) + {} + + constexpr span(const span& other) noexcept = default; + + template ::value, + int>::type = 0> + constexpr span(const span& other) noexcept + : storage_(other.data(), other.size()) + {} + + ~span() noexcept = default; + + TCB_SPAN_CONSTEXPR_ASSIGN span& + operator=(const span& other) noexcept = default; + + // [span.sub], span subviews + template + TCB_SPAN_CONSTEXPR11 span first() const + { + TCB_SPAN_EXPECT(Count <= size()); + return {data(), Count}; + } + + template + TCB_SPAN_CONSTEXPR11 span last() const + { + TCB_SPAN_EXPECT(Count <= size()); + return {data() + (size() - Count), Count}; + } + + template + using subspan_return_t = + span; + + template + TCB_SPAN_CONSTEXPR11 subspan_return_t subspan() const + { + TCB_SPAN_EXPECT(Offset <= size() && + (Count == dynamic_extent || Offset + Count <= size())); + return {data() + Offset, + Count != dynamic_extent ? Count : size() - Offset}; + } + + TCB_SPAN_CONSTEXPR11 span + first(size_type count) const + { + TCB_SPAN_EXPECT(count <= size()); + return {data(), count}; + } + + TCB_SPAN_CONSTEXPR11 span + last(size_type count) const + { + TCB_SPAN_EXPECT(count <= size()); + return {data() + (size() - count), count}; + } + + TCB_SPAN_CONSTEXPR11 span + subspan(size_type offset, size_type count = dynamic_extent) const + { + TCB_SPAN_EXPECT(offset <= size() && + (count == dynamic_extent || offset + count <= size())); + return {data() + offset, + count == dynamic_extent ? size() - offset : count}; + } + + // [span.obs], span observers + constexpr size_type size() const noexcept { return storage_.size; } + + constexpr size_type size_bytes() const noexcept + { + return size() * sizeof(element_type); + } + + TCB_SPAN_NODISCARD constexpr bool empty() const noexcept + { + return size() == 0; + } + + // [span.elem], span element access + TCB_SPAN_CONSTEXPR11 reference operator[](size_type idx) const + { + TCB_SPAN_EXPECT(idx < size()); + return *(data() + idx); + } + + TCB_SPAN_CONSTEXPR11 reference front() const + { + TCB_SPAN_EXPECT(!empty()); + return *data(); + } + + TCB_SPAN_CONSTEXPR11 reference back() const + { + TCB_SPAN_EXPECT(!empty()); + return *(data() + (size() - 1)); + } + + constexpr pointer data() const noexcept { return storage_.ptr; } + + // [span.iterators], span iterator support + constexpr iterator begin() const noexcept { return data(); } + + constexpr iterator end() const noexcept { return data() + size(); } + + TCB_SPAN_ARRAY_CONSTEXPR reverse_iterator rbegin() const noexcept + { + return reverse_iterator(end()); + } + + TCB_SPAN_ARRAY_CONSTEXPR reverse_iterator rend() const noexcept + { + return reverse_iterator(begin()); + } + +private: + storage_type storage_{}; +}; + +#ifdef TCB_SPAN_HAVE_DEDUCTION_GUIDES + +/* Deduction Guides */ +template +span(T (&)[N])->span; + +template +span(std::array&)->span; + +template +span(const std::array&)->span; + +template +span(Container&)->span()))>::type>; + +template +span(const Container&)->span; + +#endif // TCB_HAVE_DEDUCTION_GUIDES + +template +constexpr span +make_span(span s) noexcept +{ + return s; +} + +template +constexpr span make_span(T (&arr)[N]) noexcept +{ + return {arr}; +} + +template +TCB_SPAN_ARRAY_CONSTEXPR span make_span(std::array& arr) noexcept +{ + return {arr}; +} + +template +TCB_SPAN_ARRAY_CONSTEXPR span +make_span(const std::array& arr) noexcept +{ + return {arr}; +} + +template +constexpr span()))>::type> +make_span(Container& cont) +{ + return {cont}; +} + +template +constexpr span +make_span(const Container& cont) +{ + return {cont}; +} + +template +span +as_bytes(span s) noexcept +{ + return {reinterpret_cast(s.data()), s.size_bytes()}; +} + +template < + class ElementType, size_t Extent, + typename std::enable_if::value, int>::type = 0> +span +as_writable_bytes(span s) noexcept +{ + return {reinterpret_cast(s.data()), s.size_bytes()}; +} + +template +constexpr auto get(span s) -> decltype(s[N]) +{ + return s[N]; +} + +} // namespace TCB_SPAN_NAMESPACE_NAME + +namespace std { + +template +class tuple_size> + : public integral_constant {}; + +template +class tuple_size>; // not defined + +template +class tuple_element> { +public: + static_assert(Extent != TCB_SPAN_NAMESPACE_NAME::dynamic_extent && + I < Extent, + ""); + using type = ElementType; +}; + +} // end namespace std + +#endif // TCB_SPAN_HPP_INCLUDED