diff --git a/.gitignore b/.gitignore index 540743b71..eea2f7835 100644 --- a/.gitignore +++ b/.gitignore @@ -35,7 +35,7 @@ pack_*/ rules.ninja testrunner\[1\]_include.cmake -src/game/generated +generated .cproject .project diff --git a/CMakeLists.txt b/CMakeLists.txt index bff3fa189..0c34517c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,11 @@ else() endif() endif() -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake) +set(ORIGINAL_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}) +set(ORIGINAL_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES}) +set(ORIGINAL_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) +set(OWN_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake) +set(CMAKE_MODULE_PATH ${OWN_CMAKE_MODULE_PATH}) if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(TARGET_BITS "64") @@ -149,8 +153,62 @@ if(NOT MSVC) add_c_compiler_flag_if_supported(OUR_FLAGS_OWN -Wno-unused-parameter) add_c_compiler_flag_if_supported(OUR_FLAGS_OWN -Wno-missing-field-initializers) add_c_compiler_flag_if_supported(OUR_FLAGS_OWN -Wformat=2) # Warn about format strings. + add_c_compiler_flag_if_supported(OUR_FLAGS_DEP -Wno-implicit-function-declaration) endif() +if(NOT MSVC) + check_c_compiler_flag("-O2;-Wp,-Werror;-D_FORTIFY_SOURCE=2" DEFINE_FORTIFY_SOURCE) # Some distributions define _FORTIFY_SOURCE by themselves. +endif() + +######################################################################## +# COMMON FUNCTIONS +######################################################################## + +function(set_glob VAR GLOBBING DIRECTORY) # ... + file(${GLOBBING} GLOB_RESULT "${DIRECTORY}/*.c" "${DIRECTORY}/*.cpp" "${DIRECTORY}/*.h") + list(SORT GLOB_RESULT) + set(FILES) + foreach(file ${ARGN}) + list(APPEND FILES "${PROJECT_SOURCE_DIR}/${DIRECTORY}/${file}") + endforeach() + + if(NOT FILES STREQUAL GLOB_RESULT) + message(AUTHOR_WARNING "${VAR} does not contain every file from directory ${DIRECTORY}") + set(LIST_BUT_NOT_GLOB) + if(POLICY CMP0057) + cmake_policy(SET CMP0057 NEW) + foreach(file ${FILES}) + if(NOT file IN_LIST GLOB_RESULT) + list(APPEND LIST_BUT_NOT_GLOB ${file}) + endif() + endforeach() + if(LIST_BUT_NOT_GLOB) + message(AUTHOR_WARNING "Entries only present in ${VAR}: ${LIST_BUT_NOT_GLOB}") + endif() + set(GLOB_BUT_NOT_LIST) + foreach(file ${GLOB_RESULT}) + if(NOT file IN_LIST FILES) + list(APPEND GLOB_BUT_NOT_LIST ${file}) + endif() + endforeach() + if(GLOB_BUT_NOT_LIST) + message(AUTHOR_WARNING "Entries only present in ${DIRECTORY}: ${GLOB_BUT_NOT_LIST}") + endif() + endif() + endif() + + set(${VAR} ${FILES} PARENT_SCOPE) +endfunction() + +######################################################################## +# INITALIZE TARGET LISTS +######################################################################## + +set(TARGETS_OWN) +set(TARGETS_DEP) + +set(TARGETS_LINK) # Targets with a linking stage. + ######################################################################## # DEPENDENCIES ######################################################################## @@ -203,11 +261,13 @@ if(NOT CMAKE_CROSSCOMPILING) # quietly. find_package(PkgConfig) endif() +find_package(ZLIB) find_package(Curl) find_package(Freetype) if(DOWNLOAD_GTEST) find_package(Git) endif() +find_package(GLEW) find_package(GTest) if(MYSQL) find_package(MySQL) @@ -217,14 +277,11 @@ endif() find_package(Ogg) find_package(Opus) find_package(Opusfile) +find_package(Pnglite) find_package(PythonInterp) find_package(SDL2) find_package(Threads) -if(NOT PREFER_BUNDLED_LIBS) - find_package(ZLIB) -else() - set(ZLIB_FOUND NO) -endif() +find_package(Wavpack) if(TARGET_OS AND TARGET_OS STREQUAL "mac") find_program(DMG dmg) @@ -245,44 +302,42 @@ message(STATUS "Compiler: ${CMAKE_CXX_COMPILER}") message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") message(STATUS "Dependencies:") -function(show_dependency_status NAME FOUND PATH) - if(FOUND) - is_bundled(IS_BUNDLED "${PATH}") - if(IS_BUNDLED) - message(STATUS " * ${NAME} not found (using bundled version)") +function(show_dependency_status OUTPUT_NAME NAME) + if(${NAME}_FOUND) + if(${NAME}_BUNDLED) + message(STATUS " * ${OUTPUT_NAME} not found (using bundled version)") else() - message(STATUS " * ${NAME} found") + message(STATUS " * ${OUTPUT_NAME} found") endif() else() - message(STATUS " * ${NAME} not found") + message(STATUS " * ${OUTPUT_NAME} not found") endif() endfunction() -show_dependency_status("Curl" ${CURL_FOUND} "${CURL_LIBRARY}") +show_dependency_status("Curl" CURL) if(TARGET_OS AND TARGET_OS STREQUAL "mac") - show_dependency_status("Dmg tools" ${DMGTOOLS_FOUND} "") + show_dependency_status("Dmg tools" DMGTOOLS) endif() -show_dependency_status("Freetype" ${FREETYPE_FOUND} "${FREETYPE_LIBRARY}") +show_dependency_status("Freetype" FREETYPE) if(DOWNLOAD_GTEST) - show_dependency_status("Git" ${GIT_FOUND} "${GIT_EXECUTABLE}") + show_dependency_status("Git" GIT) endif() -show_dependency_status("GTest" ${GTEST_FOUND} "${GTEST_LIBRARY}") +show_dependency_status("Glew" GLEW) +show_dependency_status("GTest" GTEST) if(TARGET_OS AND TARGET_OS STREQUAL "mac") - show_dependency_status("Hdiutil" ${HDIUTIL} "") + show_dependency_status("Hdiutil" HDIUTIL) endif() if(MYSQL) - show_dependency_status("MySQL" ${MYSQL_FOUND} "${MYSQL_LIBRARY}") -endif() -show_dependency_status("Ogg" ${OGG_FOUND} "${OGG_INCLUDEDIR}") -show_dependency_status("Opus" ${OPUS_FOUND} "${OPUS_INCLUDEDIR}") -show_dependency_status("Opusfile" ${OPUSFILE_FOUND} "${OPUSFILE_LIBRARY}") -show_dependency_status("PythonInterp" ${PYTHONINTERP_FOUND} "") -show_dependency_status("SDL2" ${SDL2_FOUND} "${SDL2_LIBRARY}") -if(ZLIB_FOUND) - message(STATUS " * Zlib found") -else() - message(STATUS " * Zlib not found (using bundled version)") + show_dependency_status("MySQL" MYSQL) endif() +show_dependency_status("Ogg" OGG) +show_dependency_status("Opus" OPUS) +show_dependency_status("Opusfile" OPUSFILE) +show_dependency_status("Pnglite" PNGLITE) +show_dependency_status("PythonInterp" PYTHONINTERP) +show_dependency_status("SDL2" SDL2) +show_dependency_status("Wavpack" WAVPACK) +show_dependency_status("Zlib" ZLIB) if(NOT(PYTHONINTERP_FOUND)) message(SEND_ERROR "You must install Python to compile DDNet") @@ -350,10 +405,6 @@ else() endif() endif() -if(NOT MSVC) - check_c_compiler_flag("-O2;-Wp,-Werror;-D_FORTIFY_SOURCE=2" DEFINE_FORTIFY_SOURCE) # Some distributions define _FORTIFY_SOURCE by themselves. -endif() - ######################################################################## # DOWNLOAD GTEST ######################################################################## @@ -364,7 +415,7 @@ if(NOT(GTEST_FOUND) AND DOWNLOAD_GTEST) configure_file(cmake/Download_GTest_CMakeLists.txt.in googletest-download/CMakeLists.txt) execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/googletest-download ) if(result) message(WARNING "CMake step for googletest failed: ${result}") @@ -372,7 +423,7 @@ if(NOT(GTEST_FOUND) AND DOWNLOAD_GTEST) else() execute_process(COMMAND ${CMAKE_COMMAND} --build . RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/googletest-download ) if(result) message(WARNING "Build step for googletest failed: ${result}") @@ -383,8 +434,8 @@ if(NOT(GTEST_FOUND) AND DOWNLOAD_GTEST) # Add googletest directly to our build. This defines the gtest target. add_subdirectory( - ${CMAKE_BINARY_DIR}/googletest-src - ${CMAKE_BINARY_DIR}/googletest-build + ${PROJECT_BINARY_DIR}/googletest-src + ${PROJECT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL ) @@ -406,132 +457,17 @@ if(NOT(GTEST_FOUND) AND DOWNLOAD_GTEST) endif() endif() -######################################################################## -# INITALIZE TARGET LISTS -######################################################################## - -set(TARGETS_OWN) -set(TARGETS_DEP) - -set(TARGETS_LINK) # Targets with a linking stage. - -######################################################################## -# COMMON FUNCTIONS -######################################################################## - -function(set_glob VAR GLOBBING DIRECTORY) # ... - file(${GLOBBING} GLOB_RESULT "${DIRECTORY}/*.c" "${DIRECTORY}/*.cpp" "${DIRECTORY}/*.h") - list(SORT GLOB_RESULT) - set(FILES) - foreach(file ${ARGN}) - list(APPEND FILES "${PROJECT_SOURCE_DIR}/${DIRECTORY}/${file}") - endforeach() - - if(NOT FILES STREQUAL GLOB_RESULT) - message(AUTHOR_WARNING "${VAR} does not contain every file from directory ${DIRECTORY}") - set(LIST_BUT_NOT_GLOB) - if(POLICY CMP0057) - cmake_policy(SET CMP0057 NEW) - foreach(file ${FILES}) - if(NOT file IN_LIST GLOB_RESULT) - list(APPEND LIST_BUT_NOT_GLOB ${file}) - endif() - endforeach() - if(LIST_BUT_NOT_GLOB) - message(AUTHOR_WARNING "Entries only present in ${VAR}: ${LIST_BUT_NOT_GLOB}") - endif() - set(GLOB_BUT_NOT_LIST) - foreach(file ${GLOB_RESULT}) - if(NOT file IN_LIST FILES) - list(APPEND GLOB_BUT_NOT_LIST ${file}) - endif() - endforeach() - if(GLOB_BUT_NOT_LIST) - message(AUTHOR_WARNING "Entries only present in ${DIRECTORY}: ${GLOB_BUT_NOT_LIST}") - endif() - endif() - endif() - - set(${VAR} ${FILES} PARENT_SCOPE) -endfunction() - ######################################################################## # DEPENDENCY COMPILATION ######################################################################## -if(NOT(ZLIB_FOUND)) - set(ZLIB_LIBRARIES) - set_glob(ZLIB_SRC GLOB src/engine/external/zlib - adler32.c - compress.c - crc32.c - crc32.h - deflate.c - deflate.h - gzclose.c - gzguts.h - gzlib.c - gzread.c - gzwrite.c - infback.c - inffast.c - inffast.h - inffixed.h - inflate.c - inflate.h - inftrees.c - inftrees.h - trees.c - trees.h - uncompr.c - zconf.h - zlib.h - zutil.c - zutil.h - ) - add_library(zlib EXCLUDE_FROM_ALL OBJECT ${ZLIB_SRC}) - - list(APPEND TARGETS_DEP zlib) - set(ZLIB_INCLUDEDIR src/engine/external/zlib/) - set(DEP_ZLIB $) -else() - set(ZLIB_INCLUDEDIR) - set(DEP_ZLIB) -endif() - -set_glob(DEP_PNG_SRC GLOB src/engine/external/pnglite pnglite.c pnglite.h) -add_library(png OBJECT EXCLUDE_FROM_ALL ${DEP_PNG_SRC}) -target_include_directories(png PRIVATE ${ZLIB_INCLUDEDIR}) - -set(DEP_PNG $) -list(APPEND TARGETS_DEP png) - -set_glob(DEP_GLEW_SRC GLOB src/engine/external/glew glew.c) -set_glob(DEP_GLEW_INCLUDES GLOB src/engine/external/glew/GL eglew.h glew.h glxew.h wglew.h) -add_library(glew OBJECT EXCLUDE_FROM_ALL ${DEP_GLEW_SRC} ${DEP_GLEW_INCLUDES}) -target_include_directories(glew PRIVATE src/engine/external/glew) - -set(DEP_GLEW $) -list(APPEND TARGETS_DEP glew) - if(CLIENT) # Static dependencies - set_glob(DEP_JSON_SRC GLOB src/engine/external/json-parser json.c json.h) - set_glob(DEP_WAV_SRC GLOB src/engine/external/wavpack - bits.c - float.c - metadata.c - unpack.c - wavpack.h - words.c - wputils.c - ) - add_library(json EXCLUDE_FROM_ALL OBJECT ${DEP_JSON_SRC}) - add_library(wav EXCLUDE_FROM_ALL OBJECT ${DEP_WAV_SRC}) + set_glob(JSON_SRC GLOB src/engine/external/json-parser json.c json.h) + add_library(json EXCLUDE_FROM_ALL OBJECT ${JSON_SRC}) - list(APPEND TARGETS_DEP json wav) - set(DEP_JSON $) - set(DEP_WAV $) + list(APPEND TARGETS_DEP json) + set(JSON_DEP $) endif() ######################################################################## @@ -552,16 +488,18 @@ file(COPY ${COPY_FILES} DESTINATION .) ######################################################################## function(chash output_file) - add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/${output_file} - COMMAND ${PYTHON_EXECUTABLE} scripts/cmd5.py ${ARGN} > ${output_file} + add_custom_command(OUTPUT ${output_file} + COMMAND ${PYTHON_EXECUTABLE} scripts/cmd5.py ${ARGN} + > "${PROJECT_BINARY_DIR}/${output_file}" DEPENDS scripts/cmd5.py ${ARGN} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} ) endfunction() function(generate_source output_file script_parameter) - add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/${output_file} - COMMAND ${PYTHON_EXECUTABLE} datasrc/compile.py ${script_parameter} > ${output_file} + add_custom_command(OUTPUT ${output_file} + COMMAND ${PYTHON_EXECUTABLE} datasrc/compile.py ${script_parameter} + > "${PROJECT_BINARY_DIR}/${output_file}" DEPENDS datasrc/compile.py datasrc/content.py @@ -571,10 +509,10 @@ function(generate_source output_file script_parameter) ) endfunction() -file(MAKE_DIRECTORY "${PROJECT_SOURCE_DIR}/src/game/generated/") +file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/src/game/generated/") chash("src/game/generated/nethash.cpp" "src/engine/shared/protocol.h" - "src/game/generated/protocol.h" + "${PROJECT_BINARY_DIR}/src/game/generated/protocol.h" "src/game/tuning.h" "src/game/gamecore.cpp" ) @@ -761,7 +699,7 @@ else() set(DEP_WEBSOCKETS) endif() -set(DEPS ${DEP_MD5} ${DEP_WEBSOCKETS} ${DEP_ZLIB}) +set(DEPS ${DEP_MD5} ${DEP_WEBSOCKETS} ${ZLIB_DEP}) # Libraries set(LIBS ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${PLATFORM_LIBS}) @@ -906,14 +844,17 @@ if(CLIENT) ) set(CLIENT_SRC ${ENGINE_CLIENT} ${PLATFORM_CLIENT} ${GAME_CLIENT} ${GAME_EDITOR} ${GAME_GENERATED_CLIENT}) - set(DEPS_CLIENT ${DEPS} ${DEP_JSON} ${DEP_PNG} ${DEP_WAV} ${DEP_GLEW}) + set(DEPS_CLIENT ${DEPS} ${GLEW_DEP} ${JSON_DEP} ${PNGLITE_DEP} ${WAVPACK_DEP}) # Libraries set(LIBS_CLIENT ${LIBS} ${CURL_LIBRARIES} ${FREETYPE_LIBRARIES} + ${GLEW_LIBRARIES} + ${PNGLITE_LIBRARIES} ${SDL2_LIBRARIES} + ${WAVPACK_LIBRARIES} # Order of these three is important. ${OPUSFILE_LIBRARIES} @@ -950,11 +891,25 @@ if(CLIENT) target_include_directories(${TARGET_CLIENT} PRIVATE ${CURL_INCLUDE_DIRS} ${FREETYPE_INCLUDE_DIRS} + ${GLEW_INCLUDE_DIRS} ${OGG_INCLUDE_DIRS} ${OPUSFILE_INCLUDE_DIRS} ${OPUS_INCLUDE_DIRS} + ${PNGLITE_INCLUDE_DIRS} ${SDL2_INCLUDE_DIRS} + ${WAVPACK_INCLUDE_DIRS} ) + + set(CMAKE_REQUIRED_INCLUDES ${ORIGINAL_CMAKE_REQUIRED_INCLUDES} ${WAVPACK_INCLUDE_DIRS}) + set(CMAKE_REQUIRED_LIBRARIES ${ORIGINAL_CMAKE_REQUIRED_LIBRARIES} ${WAVPACK_LIBRARIES}) + check_symbol_exists(WavpackOpenFileInputEx64 wavpack.h WAVPACK_OPEN_FILE_INPUT_EX64) + set(CMAKE_REQUIRED_INCLUDES ${ORIGINAL_CMAKE_REQUIRED_INCLUDES}) + set(CMAKE_REQUIRED_LIBRARIES ${ORIGINAL_CMAKE_REQUIRED_LIBRARIES}) + + if(WAVPACK_OPEN_FILE_INPUT_EX64) + target_compile_definitions(${TARGET_CLIENT} PRIVATE CONF_WAVPACK_OPEN_FILE_INPUT_EX64) + endif() + list(APPEND TARGETS_OWN ${TARGET_CLIENT}) list(APPEND TARGETS_LINK ${TARGET_CLIENT}) endif() @@ -1113,10 +1068,13 @@ foreach(ABS_T ${TOOLS}) file(RELATIVE_PATH T "${PROJECT_SOURCE_DIR}/src/tools/" ${ABS_T}) if(T MATCHES "\\.cpp$") string(REGEX REPLACE "\\.cpp$" "" TOOL "${T}") - set(EXTRA_TOOL_SRC) + set(TOOL_DEPS ${DEPS}) + set(TOOL_LIBS ${LIBS}) set(EXCLUDE_FROM_ALL EXCLUDE_FROM_ALL) if(TOOL MATCHES "^(tileset_.*|dilate|map_extract|map_replace_image)$") - list(APPEND EXTRA_TOOL_SRC ${DEP_PNG}) + list(APPEND TOOL_DEPS ${PNGLITE_DEP}) + list(APPEND TOOL_LIBS ${PNGLITE_LIBRARIES}) + list(APPEND TOOL_INCLUDE_DIRS ${PNGLITE_INCLUDE_DIRS}) endif() if(TOOL MATCHES "^config_") list(APPEND EXTRA_TOOL_SRC "src/tools/config_common.h") @@ -1125,12 +1083,13 @@ foreach(ABS_T ${TOOLS}) set(EXCLUDE_FROM_ALL) endif() add_executable(${TOOL} ${EXCLUDE_FROM_ALL} - ${DEPS} + ${TOOL_DEPS} src/tools/${TOOL}.cpp ${EXTRA_TOOL_SRC} $ ) - target_link_libraries(${TOOL} ${LIBS}) + target_include_directories(${TOOL} PRIVATE ${TOOL_INCLUDE_DIRS}) + target_link_libraries(${TOOL} ${TOOL_LIBS}) list(APPEND TARGETS_TOOLS ${TOOL}) endif() endforeach() @@ -1348,8 +1307,8 @@ endif() set(PACKAGE_TARGETS) if(DMGTOOLS_FOUND OR HDIUTIL) - file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/bundle/client/") - file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/bundle/server/") + file(MAKE_DIRECTORY bundle/client/) + file(MAKE_DIRECTORY bundle/server/) configure_file(other/bundle/client/Info.plist.in bundle/client/Info.plist) configure_file(other/bundle/server/Info.plist.in bundle/server/Info.plist) @@ -1403,8 +1362,8 @@ if(DMGTOOLS_FOUND OR HDIUTIL) ${TARGET_CLIENT} ${TARGET_SERVER_LAUNCHER} ${TARGET_SERVER} - ${CMAKE_BINARY_DIR}/bundle/client/Info.plist - ${CMAKE_BINARY_DIR}/bundle/server/Info.plist + ${PROJECT_BINARY_DIR}/bundle/client/Info.plist + ${PROJECT_BINARY_DIR}/bundle/server/Info.plist data other/bundle/client/PkgInfo other/bundle/server/PkgInfo @@ -1546,8 +1505,9 @@ foreach(target ${TARGETS_OWN}) target_compile_options(${target} PRIVATE ${OUR_FLAGS_OWN}) endif() target_include_directories(${target} PRIVATE src) + target_include_directories(${target} PRIVATE ${PROJECT_BINARY_DIR}/src) target_compile_definitions(${target} PRIVATE $<$:CONF_DEBUG>) - target_include_directories(${target} PRIVATE ${ZLIB_INCLUDEDIR}) + target_include_directories(${target} PRIVATE ${ZLIB_INCLUDE_DIRS}) target_compile_definitions(${target} PRIVATE GLEW_STATIC) if(WEBSOCKETS) target_compile_definitions(${target} PRIVATE CONF_WEBSOCKETS) @@ -1562,4 +1522,7 @@ foreach(target ${TARGETS_DEP}) if(MSVC) target_compile_options(${target} PRIVATE /W0) endif() + if(OUR_FLAGS_DEP) + target_compile_options(${target} PRIVATE ${OUR_FLAGS_DEP}) + endif() endforeach() diff --git a/cmake/FindCurl.cmake b/cmake/FindCurl.cmake index 355f0b607..ac001c95b 100644 --- a/cmake/FindCurl.cmake +++ b/cmake/FindCurl.cmake @@ -22,33 +22,34 @@ find_package_handle_standard_args(Curl DEFAULT_MSG CURL_LIBRARY CURL_INCLUDEDIR) mark_as_advanced(CURL_LIBRARY CURL_INCLUDEDIR) -is_bundled(IS_BUNDLED "${CURL_LIBRARY}") +if(CURL_FOUND) + is_bundled(CURL_BUNDLED "${CURL_LIBRARY}") + set(CURL_LIBRARIES ${CURL_LIBRARY}) + set(CURL_INCLUDE_DIRS ${CURL_INCLUDEDIR}) + if(CURL_BUNDLED AND TARGET_OS STREQUAL "linux") + find_library(CURL_LIBRARY_SSL + NAMES ssl + HINTS ${EXTRA_CURL_LIBDIR} + ) + find_library(CURL_LIBRARY_CRYPTO + NAMES crypto + HINTS ${EXTRA_CURL_LIBDIR} + ) + # If we don't add `dl`, we get a missing reference to `dlclose`: + # ``` + # /usr/bin/ld: ../ddnet-libs/curl/linux/lib64/libcrypto.a(dso_dlfcn.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5' + # ``` + # + # Order matters, SSL needs to be linked before CRYPTO, otherwise we also get + # undefined symbols. + list(APPEND CURL_LIBRARIES ${CURL_LIBRARY_SSL} ${CURL_LIBRARY_CRYPTO} dl) + endif() -set(CURL_LIBRARIES ${CURL_LIBRARY}) -set(CURL_INCLUDE_DIRS ${CURL_INCLUDEDIR}) -if(IS_BUNDLED AND TARGET_OS STREQUAL "linux") - find_library(CURL_LIBRARY_SSL - NAMES ssl - HINTS ${EXTRA_CURL_LIBDIR} - ) - find_library(CURL_LIBRARY_CRYPTO - NAMES crypto - HINTS ${EXTRA_CURL_LIBDIR} - ) - # If we don't add `dl`, we get a missing reference to `dlclose`: - # ``` - # /usr/bin/ld: ../ddnet-libs/curl/linux/lib64/libcrypto.a(dso_dlfcn.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5' - # ``` - # - # Order matters, SSL needs to be linked before CRYPTO, otherwise we also get - # undefined symbols. - list(APPEND CURL_LIBRARIES ${CURL_LIBRARY_SSL} ${CURL_LIBRARY_CRYPTO} dl) -endif() - -if(IS_BUNDLED AND TARGET_OS STREQUAL "windows") - set(CURL_COPY_FILES - "${EXTRA_CURL_LIBDIR}/libcurl.dll" - ) -else() - set(CURL_COPY_FILES) + if(CURL_BUNDLED AND TARGET_OS STREQUAL "windows") + set(CURL_COPY_FILES + "${EXTRA_CURL_LIBDIR}/libcurl.dll" + ) + else() + set(CURL_COPY_FILES) + endif() endif() diff --git a/cmake/FindFreetype.cmake b/cmake/FindFreetype.cmake index 306ca414a..1e755d66a 100644 --- a/cmake/FindFreetype.cmake +++ b/cmake/FindFreetype.cmake @@ -24,12 +24,14 @@ find_package_handle_standard_args(Freetype DEFAULT_MSG FREETYPE_LIBRARY FREETYPE mark_as_advanced(FREETYPE_LIBRARY FREETYPE_INCLUDEDIR) -set(FREETYPE_LIBRARIES ${FREETYPE_LIBRARY}) -set(FREETYPE_INCLUDE_DIRS ${FREETYPE_INCLUDEDIR}) +if(FREETYPE_FOUND) + set(FREETYPE_LIBRARIES ${FREETYPE_LIBRARY}) + set(FREETYPE_INCLUDE_DIRS ${FREETYPE_INCLUDEDIR}) -is_bundled(IS_BUNDLED "${FREETYPE_LIBRARY}") -if(IS_BUNDLED AND TARGET_OS STREQUAL "windows") - set(FREETYPE_COPY_FILES "${EXTRA_FREETYPE_LIBDIR}/libfreetype.dll") -else() - set(FREETYPE_COPY_FILES) + is_bundled(FREETYPE_BUNDLED "${FREETYPE_LIBRARY}") + if(FREETYPE_BUNDLED AND TARGET_OS STREQUAL "windows") + set(FREETYPE_COPY_FILES "${EXTRA_FREETYPE_LIBDIR}/libfreetype.dll") + else() + set(FREETYPE_COPY_FILES) + endif() endif() diff --git a/cmake/FindGLEW.cmake b/cmake/FindGLEW.cmake index c8a30c316..b451dccc4 100644 --- a/cmake/FindGLEW.cmake +++ b/cmake/FindGLEW.cmake @@ -1,33 +1,29 @@ -if(NOT CMAKE_CROSSCOMPILING) - find_package(PkgConfig QUIET) - pkg_check_modules(PC_GLEW libglew) +if(NOT PREFER_BUNDLED_LIBS) + set(CMAKE_MODULE_PATH ${ORIGINAL_CMAKE_MODULE_PATH}) + find_package(GLEW) + set(CMAKE_MODULE_PATH ${OWN_CMAKE_MODULE_PATH}) + if(GLEW_FOUND) + set(GLEW_BUNDLED OFF) + set(GLEW_DEP) + endif() endif() -set_extra_dirs_lib(GLEW glew) -find_library(GLEW_LIBRARY - NAMES GLEW glew32 - HINTS ${HINTS_GLEW_LIBDIR} ${PC_GLEW_LIBDIR} ${PC_GLEW_LIBRARY_DIRS} - PATHS ${PATHS_GLEW_LIBDIR} - ${CROSSCOMPILING_NO_CMAKE_SYSTEM_PATH} -) -set_extra_dirs_include(GLEW glew "${GLEW_LIBRARY}") -find_path(GLEW_INCLUDEDIR GL - HINTS ${HINTS_GLEW_INCLUDEDIR} ${PC_GLEW_INCLUDEDIR} ${PC_GLEW_INCLUDE_DIRS} - PATHS ${PATHS_GLEW_INCLUDEDIR} - ${CROSSCOMPILING_NO_CMAKE_SYSTEM_PATH} -) +if(NOT GLEW_FOUND) + set(GLEW_FOUND ON) + set(GLEW_BUNDLED ON) + set(GLEW_SRC_DIR src/engine/external/glew) + set_glob(GLEW_SRC GLOB ${GLEW_SRC_DIR} glew.c) + set_glob(GLEW_INCLUDES GLOB ${GLEW_SRC_DIR}/GL eglew.h glew.h glxew.h wglew.h) + add_library(glew EXCLUDE_FROM_ALL OBJECT ${GLEW_SRC} ${GLEW_INCLUDES}) + set(GLEW_INCLUDEDIR ${GLEW_SRC_DIR}) + target_include_directories(glew PRIVATE ${GLEW_INCLUDEDIR}) -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(GLEW DEFAULT_MSG GLEW_LIBRARY GLEW_INCLUDEDIR) + set(GLEW_DEP $) + set(GLEW_INCLUDE_DIRS ${GLEW_INCLUDEDIR}) + set(GLEW_LIBRARIES) -mark_as_advanced(GLEW_LIBRARY GLEW_INCLUDEDIR) + list(APPEND TARGETS_DEP glew) -set(GLEW_LIBRARIES ${GLEW_LIBRARY}) -set(GLEW_INCLUDE_DIRS ${GLEW_INCLUDEDIR}) - -is_bundled(IS_BUNDLED "${GLEW_LIBRARY}") -if(IS_BUNDLED AND TARGET_OS STREQUAL "windows") - set(GLEW_COPY_FILES "${EXTRA_GLEW_LIBDIR}/glew32.dll") -else() - set(GLEW_COPY_FILES) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(GLEW DEFAULT_MSG GLEW_INCLUDEDIR) endif() diff --git a/cmake/FindMySQL.cmake b/cmake/FindMySQL.cmake index f4e451dcf..9fce30338 100644 --- a/cmake/FindMySQL.cmake +++ b/cmake/FindMySQL.cmake @@ -69,7 +69,11 @@ find_path(MYSQL_CPPCONN_INCLUDEDIR include(FindPackageHandleStandardArgs) find_package_handle_standard_args(MySQL DEFAULT_MSG MYSQL_LIBRARY MYSQL_INCLUDEDIR) -set(MYSQL_LIBRARIES ${MYSQL_LIBRARY} ${MYSQL_CPPCONN_LIBRARY}) -set(MYSQL_INCLUDE_DIRS ${MYSQL_INCLUDEDIR} ${MYSQL_CPPCONN_INCLUDEDIR}) +if(MYSQL_FOUND) + is_bundled(MYSQL_BUNDLED "${MYSQL_LIBRARY}") -mark_as_advanced(MYSQL_INCLUDEDIR MYSQL_LIBRARY) + set(MYSQL_LIBRARIES ${MYSQL_LIBRARY} ${MYSQL_CPPCONN_LIBRARY}) + set(MYSQL_INCLUDE_DIRS ${MYSQL_INCLUDEDIR} ${MYSQL_CPPCONN_INCLUDEDIR}) + + mark_as_advanced(MYSQL_INCLUDEDIR MYSQL_LIBRARY) +endif() diff --git a/cmake/FindOgg.cmake b/cmake/FindOgg.cmake index 7a6705428..44496b491 100644 --- a/cmake/FindOgg.cmake +++ b/cmake/FindOgg.cmake @@ -23,9 +23,11 @@ find_package_handle_standard_args(Ogg DEFAULT_MSG OGG_INCLUDEDIR) mark_as_advanced(OGG_INCLUDEDIR OGG_LIBRARY) -set(OGG_INCLUDE_DIRS ${OGG_INCLUDEDIR}) -if(OGG_LIBRARY) - set(OGG_LIBRARIES ${OGG_LIBRARY}) -else() - set(OGG_LIBRARIES) +if(OGG_FOUND) + set(OGG_INCLUDE_DIRS ${OGG_INCLUDEDIR}) + if(OGG_LIBRARY) + set(OGG_LIBRARIES ${OGG_LIBRARY}) + else() + set(OGG_LIBRARIES) + endif() endif() diff --git a/cmake/FindOpus.cmake b/cmake/FindOpus.cmake index fe117e98c..37c07a2a4 100644 --- a/cmake/FindOpus.cmake +++ b/cmake/FindOpus.cmake @@ -23,9 +23,11 @@ find_package_handle_standard_args(Opus DEFAULT_MSG OPUS_INCLUDEDIR) mark_as_advanced(OPUS_INCLUDEDIR OPUS_LIBRARY) -set(OPUS_INCLUDE_DIRS ${OPUS_INCLUDEDIR}) -if(OPUS_LIBRARY) - set(OPUS_LIBRARIES ${OPUS_LIBRARY}) -else() - set(OPUS_LIBRARIES) +if(OPUS_FOUND) + set(OPUS_INCLUDE_DIRS ${OPUS_INCLUDEDIR}) + if(OPUS_LIBRARY) + set(OPUS_LIBRARIES ${OPUS_LIBRARY}) + else() + set(OPUS_LIBRARIES) + endif() endif() diff --git a/cmake/FindOpusfile.cmake b/cmake/FindOpusfile.cmake index e3d9b01a0..39a3f0878 100644 --- a/cmake/FindOpusfile.cmake +++ b/cmake/FindOpusfile.cmake @@ -26,19 +26,21 @@ mark_as_advanced(OPUSFILE_LIBRARY OPUSFILE_INCLUDEDIR) set(OPUSFILE_LIBRARIES ${OPUSFILE_LIBRARY}) set(OPUSFILE_INCLUDE_DIRS ${OPUSFILE_INCLUDEDIR}) -is_bundled(IS_BUNDLED "${OPUSFILE_LIBRARY}") -if(IS_BUNDLED AND TARGET_OS STREQUAL "windows") - set(OPUSFILE_COPY_FILES - "${EXTRA_OPUSFILE_LIBDIR}/libogg.dll" - "${EXTRA_OPUSFILE_LIBDIR}/libopus.dll" - "${EXTRA_OPUSFILE_LIBDIR}/libopusfile.dll" - "${EXTRA_OPUSFILE_LIBDIR}/libwinpthread-1.dll" - ) - if(TARGET_BITS EQUAL 32) - list(APPEND OPUSFILE_COPY_FILES - "${EXTRA_OPUSFILE_LIBDIR}/libgcc_s_sjlj-1.dll" +if(OPUSFILE_FOUND) + is_bundled(OPUSFILE_BUNDLED "${OPUSFILE_LIBRARY}") + if(OPUSFILE_BUNDLED AND TARGET_OS STREQUAL "windows") + set(OPUSFILE_COPY_FILES + "${EXTRA_OPUSFILE_LIBDIR}/libogg.dll" + "${EXTRA_OPUSFILE_LIBDIR}/libopus.dll" + "${EXTRA_OPUSFILE_LIBDIR}/libopusfile.dll" + "${EXTRA_OPUSFILE_LIBDIR}/libwinpthread-1.dll" ) + if(TARGET_BITS EQUAL 32) + list(APPEND OPUSFILE_COPY_FILES + "${EXTRA_OPUSFILE_LIBDIR}/libgcc_s_sjlj-1.dll" + ) + endif() + else() + set(OPUSFILE_COPY_FILES) endif() -else() - set(OPUSFILE_COPY_FILES) endif() diff --git a/cmake/FindPnglite.cmake b/cmake/FindPnglite.cmake new file mode 100644 index 000000000..b011a5011 --- /dev/null +++ b/cmake/FindPnglite.cmake @@ -0,0 +1,46 @@ +if(NOT PREFER_BUNDLED_LIBS) + if(NOT CMAKE_CROSSCOMPILING) + find_package(PkgConfig QUIET) + pkg_check_modules(PC_PNGLITE pnglite) + endif() + + find_library(PNGLITE_LIBRARY + NAMES pnglite + HINTS ${PC_PNGLITE_LIBDIR} ${PC_PNGLITE_LIBRARY_DIRS} + ${CROSSCOMPILING_NO_CMAKE_SYSTEM_PATH} + ) + find_path(PNGLITE_INCLUDEDIR + NAMES pnglite.h + HINTS ${PC_PNGLITE_INCLUDEDIR} ${PC_PNGLITE_INCLUDE_DIRS} + ${CROSSCOMPILING_NO_CMAKE_SYSTEM_PATH} + ) + + mark_as_advanced(PNGLITE_LIBRARY PNGLITE_INCLUDEDIR) + + if(PNGLITE_LIBRARY AND PNGLITE_INCLUDEDIR) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Pnglite DEFAULT_MSG PNGLITE_LIBRARY PNGLITE_INCLUDEDIR) + + set(PNGLITE_LIBRARIES ${PNGLITE_LIBRARY}) + set(PNGLITE_INCLUDE_DIRS ${PNGLITE_INCLUDEDIR}) + set(PNGLITE_BUNDLED OFF) + endif() +endif() + +if(NOT PNGLITE_FOUND) + set(PNGLITE_SRC_DIR src/engine/external/pnglite) + set_glob(PNGLITE_SRC GLOB ${PNGLITE_SRC_DIR} pnglite.c pnglite.h) + add_library(pnglite EXCLUDE_FROM_ALL OBJECT ${PNGLITE_SRC}) + list(APPEND TARGETS_DEP pnglite) + + set(PNGLITE_INCLUDEDIR ${PNGLITE_SRC_DIR}) + target_include_directories(pnglite PRIVATE ${ZLIB_INCLUDE_DIRS}) + + set(PNGLITE_DEP $) + set(PNGLITE_INCLUDE_DIRS ${PNGLITE_INCLUDEDIR}) + set(PNGLITE_LIBRARIES) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Pnglite DEFAULT_MSG PNGLITE_INCLUDEDIR) + set(PNGLITE_BUNDLED ON) +endif() diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake index 6c5bf0880..dbd3edaa5 100644 --- a/cmake/FindSDL2.cmake +++ b/cmake/FindSDL2.cmake @@ -25,12 +25,14 @@ find_package_handle_standard_args(SDL2 DEFAULT_MSG SDL2_LIBRARY SDL2_INCLUDEDIR) mark_as_advanced(SDL2_LIBRARY SDL2_INCLUDEDIR) -set(SDL2_LIBRARIES ${SDL2_LIBRARY}) -set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDEDIR}) +if(SDL2_FOUND) + set(SDL2_LIBRARIES ${SDL2_LIBRARY}) + set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDEDIR}) -is_bundled(IS_BUNDLED "${SDL2_LIBRARY}") -if(IS_BUNDLED AND TARGET_OS STREQUAL "windows") - set(SDL2_COPY_FILES "${EXTRA_SDL2_LIBDIR}/SDL2.dll") -else() - set(SDL2_COPY_FILES) + is_bundled(SDL2_BUNDLED "${SDL2_LIBRARY}") + if(SDL2_BUNDLED AND TARGET_OS STREQUAL "windows") + set(SDL2_COPY_FILES "${EXTRA_SDL2_LIBDIR}/SDL2.dll") + else() + set(SDL2_COPY_FILES) + endif() endif() diff --git a/cmake/FindWavpack.cmake b/cmake/FindWavpack.cmake new file mode 100644 index 000000000..086902ca7 --- /dev/null +++ b/cmake/FindWavpack.cmake @@ -0,0 +1,52 @@ +if(NOT PREFER_BUNDLED_LIBS) + if(NOT CMAKE_CROSSCOMPILING) + find_package(PkgConfig QUIET) + pkg_check_modules(PC_WAVPACK wavpack) + endif() + + find_library(WAVPACK_LIBRARY + NAMES wavpack + HINTS ${PC_WAVPACK_LIBDIR} ${PC_WAVPACK_LIBRARY_DIRS} + ${CROSSCOMPILING_NO_CMAKE_SYSTEM_PATH} + ) + find_path(WAVPACK_INCLUDEDIR + NAMES wavpack.h + PATH_SUFFIXES wavpack + HINTS ${PC_WAVPACK_INCLUDEDIR} ${PC_WAVPACK_INCLUDE_DIRS} + ${CROSSCOMPILING_NO_CMAKE_SYSTEM_PATH} + ) + + mark_as_advanced(WAVPACK_LIBRARY WAVPACK_INCLUDEDIR) + + if(WAVPACK_LIBRARY AND WAVPACK_INCLUDEDIR) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Wavpack DEFAULT_MSG WAVPACK_LIBRARY WAVPACK_INCLUDEDIR) + + set(WAVPACK_LIBRARIES ${WAVPACK_LIBRARY}) + set(WAVPACK_INCLUDE_DIRS ${WAVPACK_INCLUDEDIR}) + set(WAVPACK_BUNDLED OFF) + endif() +endif() + +if(NOT WAVPACK_FOUND) + set(WAVPACK_SRC_DIR src/engine/external/wavpack) + set_glob(WAVPACK_SRC GLOB ${WAVPACK_SRC_DIR} + bits.c + float.c + metadata.c + unpack.c + wavpack.h + words.c + wputils.c + ) + add_library(wavpack EXCLUDE_FROM_ALL OBJECT ${WAVPACK_SRC}) + set(WAVPACK_DEP $) + set(WAVPACK_INCLUDEDIR ${WAVPACK_SRC_DIR}) + set(WAVPACK_INCLUDE_DIRS ${WAVPACK_INCLUDEDIR}) + + list(APPEND TARGETS_DEP wavpack) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Wavpack DEFAULT_MSG WAVPACK_INCLUDEDIR) + set(WAVPACK_BUNDLED ON) +endif() diff --git a/cmake/FindZLIB.cmake b/cmake/FindZLIB.cmake new file mode 100644 index 000000000..cd49eabf1 --- /dev/null +++ b/cmake/FindZLIB.cmake @@ -0,0 +1,55 @@ +if(NOT PREFER_BUNDLED_LIBS) + set(CMAKE_MODULE_PATH ${ORIGINAL_CMAKE_MODULE_PATH}) + find_package(ZLIB) + set(CMAKE_MODULE_PATH ${OWN_CMAKE_MODULE_PATH}) + if(ZLIB_FOUND) + set(ZLIB_BUNDLED OFF) + set(ZLIB_DEP) + endif() +endif() + +if(NOT ZLIB_FOUND) + set(ZLIB_FOUND ON) + set(ZLIB_BUNDLED ON) + set(ZLIB_SRC_DIR src/engine/external/zlib) + set_glob(ZLIB_SRC GLOB ${ZLIB_SRC_DIR} + adler32.c + compress.c + crc32.c + crc32.h + deflate.c + deflate.h + gzclose.c + gzguts.h + gzlib.c + gzread.c + gzwrite.c + infback.c + inffast.c + inffast.h + inffixed.h + inflate.c + inflate.h + inftrees.c + inftrees.h + trees.c + trees.h + uncompr.c + zconf.h + zlib.h + zutil.c + zutil.h + ) + add_library(zlib EXCLUDE_FROM_ALL OBJECT ${ZLIB_SRC}) + set(ZLIB_INCLUDEDIR ${ZLIB_SRC_DIR}) + target_include_directories(zlib PRIVATE ${ZLIB_INCLUDEDIR}) + + set(ZLIB_DEP $) + set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDEDIR}) + set(ZLIB_LIBRARIES) + + list(APPEND TARGETS_DEP zlib) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(ZLIB DEFAULT_MSG ZLIB_INCLUDEDIR) +endif() diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 4d734e921..40f35e1b0 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -6,7 +6,7 @@ #define WINVER 0x0501 #endif -#include "engine/external/glew/GL/glew.h" +#include #include #include diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 4ffd5cfde..1550fe1a1 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -10,7 +10,8 @@ #endif #include -#include + +#include #include #include diff --git a/src/engine/client/opengl_sl.h b/src/engine/client/opengl_sl.h index 6de06ce1e..4e83073f3 100644 --- a/src/engine/client/opengl_sl.h +++ b/src/engine/client/opengl_sl.h @@ -1,6 +1,7 @@ -#pragma once +#ifndef ENGINE_CLIENT_OPENGL_SL_H +#define ENGINE_CLIENT_OPENGL_SL_H -#include "engine/external/glew/GL/glew.h" +#include class CGLSL { public: @@ -17,3 +18,5 @@ private: int m_Type; bool m_IsLoaded; }; + +#endif // ENGINE_CLIENT_OPENGL_SL_H diff --git a/src/engine/client/opengl_sl_program.h b/src/engine/client/opengl_sl_program.h index 3cc04b593..4f4bbda5b 100644 --- a/src/engine/client/opengl_sl_program.h +++ b/src/engine/client/opengl_sl_program.h @@ -1,6 +1,7 @@ -#pragma once +#ifndef ENGINE_CLIENT_OPENGL_SL_PROGRAM_H +#define ENGINE_CLIENT_OPENGL_SL_PROGRAM_H -#include "engine/external/glew/GL/glew.h" +#include class CGLSL; @@ -74,3 +75,5 @@ public: int m_LocDir; int m_LocNum; }; + +#endif // ENGINE_CLIENT_OPENGL_SL_PROGRAM_H diff --git a/src/engine/client/sound.cpp b/src/engine/client/sound.cpp index 307d1c46e..d9079806a 100644 --- a/src/engine/client/sound.cpp +++ b/src/engine/client/sound.cpp @@ -12,9 +12,10 @@ #include "sound.h" -extern "C" { // wavpack - #include +extern "C" +{ #include + #include } #include @@ -77,9 +78,9 @@ static int m_NextVoice = 0; static int *m_pMixBuffer = 0; // buffer only used by the thread callback function static unsigned m_MaxFrames = 0; -static const void *ms_pWVBuffer = 0x0; -static int ms_WVBufferPosition = 0; -static int ms_WVBufferSize = 0; +static const void *s_pWVBuffer = 0x0; +static int s_WVBufferPosition = 0; +static int s_WVBufferSize = 0; const int DefaultDistance = 1500; @@ -414,14 +415,6 @@ void CSound::RateConvert(int SampleID) pSample->m_Rate = m_MixingRate; } -int CSound::ReadData(void *pBuffer, int Size) -{ - int ChunkSize = min(Size, ms_WVBufferSize - ms_WVBufferPosition); - mem_copy(pBuffer, (const char *)ms_pWVBuffer + ms_WVBufferPosition, ChunkSize); - ms_WVBufferPosition += ChunkSize; - return ChunkSize; -} - int CSound::DecodeOpus(int SampleID, const void *pData, unsigned DataSize) { if(SampleID == -1 || SampleID >= NUM_SAMPLES) @@ -468,6 +461,46 @@ int CSound::DecodeOpus(int SampleID, const void *pData, unsigned DataSize) return SampleID; } +static int ReadDataOld(void *pBuffer, int Size) +{ + int ChunkSize = min(Size, s_WVBufferSize - s_WVBufferPosition); + mem_copy(pBuffer, (const char *)s_pWVBuffer + s_WVBufferPosition, ChunkSize); + s_WVBufferPosition += ChunkSize; + return ChunkSize; +} + +#if defined(CONF_WAVPACK_OPEN_FILE_INPUT_EX64) +static int ReadData(void *pId, void *pBuffer, int Size) +{ + (void)pId; + return ReadDataOld(pBuffer, Size); +} + +static int ReturnFalse(void *pId) +{ + (void)pId; + return 0; +} + +static int64_t GetPos(void *pId) +{ + (void)pId; + return s_WVBufferPosition; +} + +static int64_t GetLength(void *pId) +{ + (void)pId; + return s_WVBufferSize; +} + +static int PushBackByte(void *pId, int Char) +{ + s_WVBufferPosition -= 1; + return 0; +} +#endif + int CSound::DecodeWV(int SampleID, const void *pData, unsigned DataSize) { if(SampleID == -1 || SampleID >= NUM_SAMPLES) @@ -477,12 +510,22 @@ int CSound::DecodeWV(int SampleID, const void *pData, unsigned DataSize) char aError[100]; WavpackContext *pContext; - ms_pWVBuffer = pData; - ms_WVBufferSize = DataSize; - ms_WVBufferPosition = 0; + s_pWVBuffer = pData; + s_WVBufferSize = DataSize; + s_WVBufferPosition = 0; - pContext = WavpackOpenFileInput(ReadData, aError); - if (pContext) +#if defined(CONF_WAVPACK_OPEN_FILE_INPUT_EX64) + WavpackStreamReader64 Callback = {0}; + Callback.can_seek = ReturnFalse; + Callback.get_length = GetLength; + Callback.get_pos = GetPos; + Callback.push_back_byte = PushBackByte; + Callback.read_bytes = ::ReadData; + pContext = WavpackOpenFileInputEx64(&Callback,0, 0, aError, 0, 0); +#else + pContext = WavpackOpenFileInput(ReadDataOld, aError); +#endif + if(pContext) { int NumSamples = WavpackGetNumSamples(pContext); int BitsPerSample = WavpackGetBitsPerSample(pContext); @@ -548,32 +591,32 @@ int CSound::LoadOpus(const char *pFilename) if(!m_pStorage) return -1; - ms_File = m_pStorage->OpenFile(pFilename, IOFLAG_READ, IStorage::TYPE_ALL); - if(!ms_File) + IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_READ, IStorage::TYPE_ALL); + if(!File) { dbg_msg("sound/opus", "failed to open file. filename='%s'", pFilename); return -1; } int SampleID = AllocID(); - int DataSize = io_length(ms_File); + int DataSize = io_length(File); if(SampleID < 0 || DataSize <= 0) { - io_close(ms_File); - ms_File = NULL; + io_close(File); + File = NULL; dbg_msg("sound/opus", "failed to open file. filename='%s'", pFilename); return -1; } // read the whole file into memory char *pData = new char[DataSize]; - io_read(ms_File, pData, DataSize); + io_read(File, pData, DataSize); SampleID = DecodeOpus(SampleID, pData, DataSize); delete[] pData; - io_close(ms_File); - ms_File = NULL; + io_close(File); + File = NULL; if(g_Config.m_Debug) dbg_msg("sound/opus", "loaded %s", pFilename); @@ -598,32 +641,32 @@ int CSound::LoadWV(const char *pFilename) if(!m_pStorage) return -1; - ms_File = m_pStorage->OpenFile(pFilename, IOFLAG_READ, IStorage::TYPE_ALL); - if(!ms_File) + IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_READ, IStorage::TYPE_ALL); + if(!File) { dbg_msg("sound/wv", "failed to open file. filename='%s'", pFilename); return -1; } int SampleID = AllocID(); - int DataSize = io_length(ms_File); + int DataSize = io_length(File); if(SampleID < 0 || DataSize <= 0) { - io_close(ms_File); - ms_File = NULL; + io_close(File); + File = NULL; dbg_msg("sound/wv", "failed to open file. filename='%s'", pFilename); return -1; } // read the whole file into memory char *pData = new char[DataSize]; - io_read(ms_File, pData, DataSize); + io_read(File, pData, DataSize); SampleID = DecodeWV(SampleID, pData, DataSize); delete[] pData; - io_close(ms_File); - ms_File = NULL; + io_close(File); + File = NULL; if(g_Config.m_Debug) dbg_msg("sound/wv", "loaded %s", pFilename); @@ -930,6 +973,4 @@ void CSound::StopVoice(CVoiceHandle Voice) } -IOHANDLE CSound::ms_File = 0; - IEngineSound *CreateEngineSound() { return new CSound; } diff --git a/src/engine/client/sound.h b/src/engine/client/sound.h index 8621b9c87..dfc59d5c9 100644 --- a/src/engine/client/sound.h +++ b/src/engine/client/sound.h @@ -25,8 +25,6 @@ public: static void RateConvert(int SampleID); // TODO: Refactor: clean this mess up - static IOHANDLE ms_File; - static int ReadData(void *pBuffer, int Size); static int DecodeWV(int SampleID, const void *pData, unsigned DataSize); static int DecodeOpus(int SampleID, const void *pData, unsigned DataSize); diff --git a/src/game/gamecore.cpp b/src/game/gamecore.cpp index 12ef3c73e..81745be1e 100644 --- a/src/game/gamecore.cpp +++ b/src/game/gamecore.cpp @@ -3,7 +3,7 @@ #include "gamecore.h" #include -#include + const char *CTuningParams::ms_apNames[] = { #define MACRO_TUNING_PARAM(Name,ScriptName,Value,Description) #ScriptName, diff --git a/src/game/version.h b/src/game/version.h index c870e6739..e2e134cdc 100644 --- a/src/game/version.h +++ b/src/game/version.h @@ -2,7 +2,7 @@ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #ifndef GAME_VERSION_H #define GAME_VERSION_H -#include "generated/nethash.cpp" +#include #define GAME_VERSION "0.6.4, 11.0.3" #define GAME_NETVERSION "0.6 626fce9a778df4d4" #define GAME_RELEASE_VERSION "11.0.3" diff --git a/src/tools/dilate.cpp b/src/tools/dilate.cpp index 17de1e37e..e5e848e5d 100644 --- a/src/tools/dilate.cpp +++ b/src/tools/dilate.cpp @@ -2,7 +2,7 @@ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include #include -#include +#include typedef struct { diff --git a/src/tools/map_diff.cpp b/src/tools/map_diff.cpp index 89f073edb..79abfe514 100644 --- a/src/tools/map_diff.cpp +++ b/src/tools/map_diff.cpp @@ -1,10 +1,11 @@ #include #include #include -#include #include #include +#include + bool Process(IStorage *pStorage, char **pMapNames) { CDataFileReader Maps[2]; diff --git a/src/tools/map_extract.cpp b/src/tools/map_extract.cpp index e9fe815ef..1ef11d228 100644 --- a/src/tools/map_extract.cpp +++ b/src/tools/map_extract.cpp @@ -1,10 +1,11 @@ // Adapted from TWMapImagesRecovery by Tardo: https://github.com/Tardo/TWMapImagesRecovery #include #include -#include #include #include +#include + bool Process(IStorage *pStorage, const char *pMapName, const char *pPathSave) { CDataFileReader Map; diff --git a/src/tools/map_replace_image.cpp b/src/tools/map_replace_image.cpp index fe627f072..2b5f4a170 100644 --- a/src/tools/map_replace_image.cpp +++ b/src/tools/map_replace_image.cpp @@ -5,10 +5,10 @@ #include #include #include -#include #include #include +#include /* Usage: map_replace_image Notes: map filepath must be relative to user default teeworlds folder diff --git a/src/tools/tileset_borderadd.cpp b/src/tools/tileset_borderadd.cpp index 8c0bccc0d..8f786ed51 100644 --- a/src/tools/tileset_borderadd.cpp +++ b/src/tools/tileset_borderadd.cpp @@ -2,7 +2,8 @@ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include #include -#include + +#include typedef struct { diff --git a/src/tools/tileset_borderfix.cpp b/src/tools/tileset_borderfix.cpp index 3b1fc4e85..59f069878 100644 --- a/src/tools/tileset_borderfix.cpp +++ b/src/tools/tileset_borderfix.cpp @@ -1,7 +1,8 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include -#include + +#include typedef struct { diff --git a/src/tools/tileset_borderrem.cpp b/src/tools/tileset_borderrem.cpp index 59cd17a66..d87a8d1f3 100644 --- a/src/tools/tileset_borderrem.cpp +++ b/src/tools/tileset_borderrem.cpp @@ -2,7 +2,8 @@ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include #include -#include + +#include typedef struct { diff --git a/src/tools/tileset_borderset.cpp b/src/tools/tileset_borderset.cpp index 97d837601..dcd750790 100644 --- a/src/tools/tileset_borderset.cpp +++ b/src/tools/tileset_borderset.cpp @@ -2,7 +2,8 @@ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include #include -#include + +#include typedef struct {