diff --git a/.gitignore b/.gitignore index d7a825a791c..ac1659e81a4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,15 @@ # macOS .DS_Store +# qt-creator +devilutionx.config +devilutionx.creator +devilutionx.files +devilutionx.includes +.cproject +.settings/ + + # CodeLite .CodeLite *.project @@ -422,3 +431,20 @@ DerivedData/ /libs # End of https://www.gitignore.io/api/xcode +cmake-* +CMakeFiles/* +CMakeCache.txt + + +##mine + +*.mpq +*.a +*.cmake +Makefile +devilutionx +.gitignore +Source/diablo.cpp.debug +Source/interfac.cpp.debug +SourceX/DiabloUI/credits.cpp.debug +SourceX/storm/storm_net.cpp.debug diff --git a/3rdParty/asio/include/asio/detail/impl/handler_tracking.ipp b/3rdParty/asio/include/asio/detail/impl/handler_tracking.ipp index 5a4ff6f0fcb..6647309f7d3 100644 --- a/3rdParty/asio/include/asio/detail/impl/handler_tracking.ipp +++ b/3rdParty/asio/include/asio/detail/impl/handler_tracking.ipp @@ -322,8 +322,8 @@ void handler_tracking::reactor_operation( void handler_tracking::write_line(const char* format, ...) { using namespace std; // For sprintf (or equivalent). - va_list args; + va_start(args, format); char line[256] = ""; diff --git a/CMake/FindLibMad.cmake b/CMake/FindLibMad.cmake new file mode 100644 index 00000000000..e20fb0c042b --- /dev/null +++ b/CMake/FindLibMad.cmake @@ -0,0 +1,45 @@ +#------------------------------------------------------------------------------- +# +# Copyright 2013-2018 BBC Research and Development +# +# This file is part of Audio Waveform Image Generator. +# +# Author: Chris Needham +# +# Audio Waveform Image Generator is free software: you can redistribute it +# and/or modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the License, +# or (at your option) any later version. +# +# Audio Waveform Image Generator is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# Audio Waveform Image Generator. If not, see . +# +#------------------------------------------------------------------------------- +# +# Finds libmad include file and library. This module sets the following +# variables: +# +# LIBMAD_FOUND - Flag if libmad was found +# LIBMAD_INCLUDE_DIRS - libmad include directories +# LIBMAD_LIBRARIES - libmad library paths +# +#------------------------------------------------------------------------------- + +include(FindPackageHandleStandardArgs) + +find_path(LIBMAD_INCLUDE_DIRS mad.h) +find_library(LIBMAD_LIBRARIES mad) + +find_package_handle_standard_args( + LibMad + DEFAULT_MSG + LIBMAD_LIBRARIES + LIBMAD_INCLUDE_DIRS +) + +#------------------------------------------------------------------------------- diff --git a/CMake/FindSDL.cmake b/CMake/FindSDL.cmake new file mode 100644 index 00000000000..582512d305e --- /dev/null +++ b/CMake/FindSDL.cmake @@ -0,0 +1,180 @@ +# Locate SDL library +# This module defines +# SDL_LIBRARY, the name of the library to link against +# SDL_FOUND, if false, do not try to link to SDL +# SDL_INCLUDE_DIR, where to find SDL.h +# +# This module responds to the the flag: +# SDL_BUILDING_LIBRARY +# If this is defined, then no SDL_main will be linked in because +# only applications need main(). +# Otherwise, it is assumed you are building an application and this +# module will attempt to locate and set the the proper link flags +# as part of the returned SDL_LIBRARY variable. +# +# Don't forget to include SDLmain.h and SDLmain.m your project for the +# OS X framework based version. (Other versions link to -lSDLmain which +# this module will try to find on your behalf.) Also for OS X, this +# module will automatically add the -framework Cocoa on your behalf. +# +# +# Additional Note: If you see an empty SDL_LIBRARY_TEMP in your configuration +# and no SDL_LIBRARY, it means CMake did not find your SDL library +# (SDL.dll, libsdl.so, SDL.framework, etc). +# Set SDL_LIBRARY_TEMP to point to your SDL library, and configure again. +# Similarly, if you see an empty SDLMAIN_LIBRARY, you should set this value +# as appropriate. These values are used to generate the final SDL_LIBRARY +# variable, but when these values are unset, SDL_LIBRARY does not get created. +# +# +# $SDLDIR is an environment variable that would +# correspond to the ./configure --prefix=$SDLDIR +# used in building SDL. +# l.e.galup 9-20-02 +# +# Modified by Eric Wing. +# Added code to assist with automated building by using environmental variables +# and providing a more controlled/consistent search behavior. +# Added new modifications to recognize OS X frameworks and +# additional Unix paths (FreeBSD, etc). +# Also corrected the header search path to follow "proper" SDL guidelines. +# Added a search for SDLmain which is needed by some platforms. +# Added a search for threads which is needed by some platforms. +# Added needed compile switches for MinGW. +# +# On OSX, this will prefer the Framework version (if found) over others. +# People will have to manually change the cache values of +# SDL_LIBRARY to override this selection or set the CMake environment +# CMAKE_INCLUDE_PATH to modify the search paths. +# +# Note that the header path has changed from SDL/SDL.h to just SDL.h +# This needed to change because "proper" SDL convention +# is #include "SDL.h", not . This is done for portability +# reasons because not all systems place things in SDL/ (see FreeBSD). + +#============================================================================= +# Copyright 2003-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distributed this file outside of CMake, substitute the full +# License text for the above reference.) + +FIND_PATH(SDL_INCLUDE_DIR SDL.h + HINTS + $ENV{SDLDIR} + PATH_SUFFIXES include/SDL include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local/include/SDL12 + /usr/local/include/SDL11 # FreeBSD ports + /usr/include/SDL12 + /usr/include/SDL11 + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt + ${Package_search_hints} +) +#MESSAGE("SDL_INCLUDE_DIR is ${SDL_INCLUDE_DIR}") + +# SDL-1.1 is the name used by FreeBSD ports... +# don't confuse it for the version number. +FIND_LIBRARY(SDL_LIBRARY_TEMP + NAMES SDL SDL-1.1 + HINTS + $ENV{SDLDIR} + PATH_SUFFIXES lib64 lib + PATHS + /sw + /opt/local + /opt/csw + /opt + ${Package_search_hints} +) + +#MESSAGE("SDL_LIBRARY_TEMP is ${SDL_LIBRARY_TEMP}") + +IF(NOT SDL_BUILDING_LIBRARY) + IF(NOT ${SDL_INCLUDE_DIR} MATCHES ".framework") + # Non-OS X framework versions expect you to also dynamically link to + # SDLmain. This is mainly for Windows and OS X. Other (Unix) platforms + # seem to provide SDLmain for compatibility even though they don't + # necessarily need it. + FIND_LIBRARY(SDLMAIN_LIBRARY + NAMES SDLmain SDLmain-1.1 + HINTS + $ENV{SDLDIR} + PATH_SUFFIXES lib64 lib + PATHS + /sw + /opt/local + /opt/csw + /opt + ${Package_search_hints} + ) + ENDIF(NOT ${SDL_INCLUDE_DIR} MATCHES ".framework") +ENDIF(NOT SDL_BUILDING_LIBRARY) + +# SDL may require threads on your system. +# The Apple build may not need an explicit flag because one of the +# frameworks may already provide it. +# But for non-OSX systems, I will use the CMake Threads package. +IF(NOT APPLE) + FIND_PACKAGE(Threads) +ENDIF(NOT APPLE) + +# MinGW needs an additional library, mwindows +# It's total link flags should look like -lmingw32 -lSDLmain -lSDL -lmwindows +# (Actually on second look, I think it only needs one of the m* libraries.) +IF(MINGW) + SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW") +ENDIF(MINGW) + +SET(SDL_FOUND "NO") +IF(SDL_LIBRARY_TEMP) + # For SDLmain + IF(NOT SDL_BUILDING_LIBRARY) + IF(SDLMAIN_LIBRARY) + SET(SDL_LIBRARY_TEMP ${SDLMAIN_LIBRARY} ${SDL_LIBRARY_TEMP}) + ENDIF(SDLMAIN_LIBRARY) + ENDIF(NOT SDL_BUILDING_LIBRARY) + + # For OS X, SDL uses Cocoa as a backend so it must link to Cocoa. + # CMake doesn't display the -framework Cocoa string in the UI even + # though it actually is there if I modify a pre-used variable. + # I think it has something to do with the CACHE STRING. + # So I use a temporary variable until the end so I can set the + # "real" variable in one-shot. + IF(APPLE) + SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} "-framework Cocoa") + ENDIF(APPLE) + + # For threads, as mentioned Apple doesn't need this. + # In fact, there seems to be a problem if I used the Threads package + # and try using this line, so I'm just skipping it entirely for OS X. + IF(NOT APPLE) + SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT}) + ENDIF(NOT APPLE) + + # For MinGW library + IF(MINGW) + SET(SDL_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL_LIBRARY_TEMP}) + ENDIF(MINGW) + + # Set the final string here so the GUI reflects the final state. + SET(SDL_LIBRARY ${SDL_LIBRARY_TEMP} CACHE STRING "Where the SDL Library can be found") + # Set the temp variable to INTERNAL so it is not seen in the CMake GUI + SET(SDL_LIBRARY_TEMP "${SDL_LIBRARY_TEMP}" CACHE INTERNAL "") + + SET(SDL_FOUND "YES") +ENDIF(SDL_LIBRARY_TEMP) + +#MESSAGE("SDL_LIBRARY is ${SDL_LIBRARY}") + diff --git a/CMake/FindSDL2.cmake b/CMake/FindSDL2.cmake index acde1a993e8..a78643204d3 100644 --- a/CMake/FindSDL2.cmake +++ b/CMake/FindSDL2.cmake @@ -1,255 +1,255 @@ -# - Find SDL2 -# Find the SDL2 headers and libraries -# -# SDL2::SDL2 - Imported target to use for building a library -# SDL2::SDL2main - Imported interface target to use if you want SDL and SDLmain. -# SDL2_FOUND - True if SDL2 was found. -# SDL2_DYNAMIC - If we found a DLL version of SDL (meaning you might want to copy a DLL from SDL2::SDL2) -# -# Original Author: -# 2015 Ryan Pavlik -# -# Copyright Sensics, Inc. 2015. -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) - -# Set up architectures (for windows) and prefixes (for mingw builds) -if(WIN32) - if(MINGW) - include(MinGWSearchPathExtras OPTIONAL) - if(MINGWSEARCH_TARGET_TRIPLE) - set(SDL2_PREFIX ${MINGWSEARCH_TARGET_TRIPLE}) - endif() - endif() - if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(SDL2_LIB_PATH_SUFFIX lib/x64) - if(NOT MSVC AND NOT SDL2_PREFIX) - set(SDL2_PREFIX x86_64-w64-mingw32) - endif() - else() - set(SDL2_LIB_PATH_SUFFIX lib/x86) - if(NOT MSVC AND NOT SDL2_PREFIX) - set(SDL2_PREFIX i686-w64-mingw32) - endif() - endif() -endif() - -if(SDL2_PREFIX) - set(SDL2_ORIGPREFIXPATH ${CMAKE_PREFIX_PATH}) - if(SDL2_ROOT_DIR) - list(APPEND CMAKE_PREFIX_PATH "${SDL2_ROOT_DIR}") - endif() - if(CMAKE_PREFIX_PATH) - foreach(_prefix ${CMAKE_PREFIX_PATH}) - list(APPEND CMAKE_PREFIX_PATH "${_prefix}/${SDL2_PREFIX}") - endforeach() - endif() - if(MINGWSEARCH_PREFIXES) - list(APPEND CMAKE_PREFIX_PATH ${MINGWSEARCH_PREFIXES}) - endif() -endif() - -# Invoke pkgconfig for hints -find_package(PkgConfig QUIET) -set(SDL2_INCLUDE_HINTS) -set(SDL2_LIB_HINTS) -if(PKG_CONFIG_FOUND) - pkg_search_module(SDL2PC QUIET sdl2) - if(SDL2PC_INCLUDE_DIRS) - set(SDL2_INCLUDE_HINTS ${SDL2PC_INCLUDE_DIRS}) - endif() - if(SDL2PC_LIBRARY_DIRS) - set(SDL2_LIB_HINTS ${SDL2PC_LIBRARY_DIRS}) - endif() -endif() - -include(FindPackageHandleStandardArgs) - -find_library(SDL2_LIBRARY - NAMES - SDL2 - HINTS - ${SDL2_LIB_HINTS} - PATHS - ${SDL2_ROOT_DIR} - ENV SDL2DIR - PATH_SUFFIXES lib SDL2 ${SDL2_LIB_PATH_SUFFIX}) - -set(_sdl2_framework FALSE) -# Some special-casing if we've found/been given a framework. -# Handles whether we're given the library inside the framework or the framework itself. -if(APPLE AND "${SDL2_LIBRARY}" MATCHES "(/[^/]+)*.framework(/.*)?$") - set(_sdl2_framework TRUE) - set(SDL2_FRAMEWORK "${SDL2_LIBRARY}") - # Move up in the directory tree as required to get the framework directory. - while("${SDL2_FRAMEWORK}" MATCHES "(/[^/]+)*.framework(/.*)$" AND NOT "${SDL2_FRAMEWORK}" MATCHES "(/[^/]+)*.framework$") - get_filename_component(SDL2_FRAMEWORK "${SDL2_FRAMEWORK}" DIRECTORY) - endwhile() - if("${SDL2_FRAMEWORK}" MATCHES "(/[^/]+)*.framework$") - set(SDL2_FRAMEWORK_NAME ${CMAKE_MATCH_1}) - # If we found a framework, do a search for the header ahead of time that will be more likely to get the framework header. - find_path(SDL2_INCLUDE_DIR - NAMES - SDL_haptic.h # this file was introduced with SDL2 - HINTS - "${SDL2_FRAMEWORK}/Headers/") - else() - # For some reason we couldn't get the framework directory itself. - # Shouldn't happen, but might if something is weird. - unset(SDL2_FRAMEWORK) - endif() -endif() - -find_path(SDL2_INCLUDE_DIR - NAMES - SDL_haptic.h # this file was introduced with SDL2 - HINTS - ${SDL2_INCLUDE_HINTS} - PATHS - ${SDL2_ROOT_DIR} - ENV SDL2DIR - PATH_SUFFIXES include include/sdl2 include/SDL2 SDL2) - -if(WIN32 AND SDL2_LIBRARY) - find_file(SDL2_RUNTIME_LIBRARY - NAMES - SDL2.dll - libSDL2.dll - HINTS - ${SDL2_LIB_HINTS} - PATHS - ${SDL2_ROOT_DIR} - ENV SDL2DIR - PATH_SUFFIXES bin lib ${SDL2_LIB_PATH_SUFFIX}) -endif() - - -if(WIN32 OR ANDROID OR IOS OR (APPLE AND NOT _sdl2_framework)) - set(SDL2_EXTRA_REQUIRED SDL2_SDLMAIN_LIBRARY) - find_library(SDL2_SDLMAIN_LIBRARY - NAMES - SDL2main - PATHS - ${SDL2_ROOT_DIR} - ENV SDL2DIR - PATH_SUFFIXES lib ${SDL2_LIB_PATH_SUFFIX}) -endif() - -if(MINGW AND NOT SDL2PC_FOUND) - find_library(SDL2_MINGW_LIBRARY mingw32) - find_library(SDL2_MWINDOWS_LIBRARY mwindows) -endif() - -if(SDL2_PREFIX) - # Restore things the way they used to be. - set(CMAKE_PREFIX_PATH ${SDL2_ORIGPREFIXPATH}) -endif() - -# handle the QUIETLY and REQUIRED arguments and set QUATLIB_FOUND to TRUE if -# all listed variables are TRUE -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(SDL2 - DEFAULT_MSG - SDL2_LIBRARY - SDL2_INCLUDE_DIR - ${SDL2_EXTRA_REQUIRED}) - -if(SDL2_FOUND) - if(NOT TARGET SDL2::SDL2) - # Create SDL2::SDL2 - if(WIN32 AND SDL2_RUNTIME_LIBRARY) - set(SDL2_DYNAMIC TRUE) - add_library(SDL2::SDL2 SHARED IMPORTED) - set_target_properties(SDL2::SDL2 - PROPERTIES - IMPORTED_IMPLIB "${SDL2_LIBRARY}" - IMPORTED_LOCATION "${SDL2_RUNTIME_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" - ) - else() - add_library(SDL2::SDL2 UNKNOWN IMPORTED) - if(SDL2_FRAMEWORK AND SDL2_FRAMEWORK_NAME) - # Handle the case that SDL2 is a framework and we were able to decompose it above. - set_target_properties(SDL2::SDL2 PROPERTIES - IMPORTED_LOCATION "${SDL2_FRAMEWORK}/${SDL2_FRAMEWORK_NAME}") - elseif(_sdl2_framework AND SDL2_LIBRARY MATCHES "(/[^/]+)*.framework$") - # Handle the case that SDL2 is a framework and SDL_LIBRARY is just the framework itself. - - # This takes the basename of the framework, without the extension, - # and sets it (as a child of the framework) as the imported location for the target. - # This is the library symlink inside of the framework. - set_target_properties(SDL2::SDL2 PROPERTIES - IMPORTED_LOCATION "${SDL2_LIBRARY}/${CMAKE_MATCH_1}") - else() - # Handle non-frameworks (including non-Mac), as well as the case that we're given the library inside of the framework - set_target_properties(SDL2::SDL2 PROPERTIES - IMPORTED_LOCATION "${SDL2_LIBRARY}") - endif() - set_target_properties(SDL2::SDL2 - PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" - ) - endif() - - if(APPLE) - # Need Cocoa here, is always a framework - find_library(SDL2_COCOA_LIBRARY Cocoa) - list(APPEND SDL2_EXTRA_REQUIRED SDL2_COCOA_LIBRARY) - if(SDL2_COCOA_LIBRARY) - set_target_properties(SDL2::SDL2 PROPERTIES - IMPORTED_LINK_INTERFACE_LIBRARIES ${SDL2_COCOA_LIBRARY}) - endif() - endif() - - - # Compute what to do with SDL2main - set(SDL2MAIN_LIBRARIES SDL2::SDL2) - add_library(SDL2::SDL2main INTERFACE IMPORTED) - if(SDL2_SDLMAIN_LIBRARY) - add_library(SDL2::SDL2main_real STATIC IMPORTED) - set_target_properties(SDL2::SDL2main_real - PROPERTIES - IMPORTED_LOCATION "${SDL2_SDLMAIN_LIBRARY}") - set(SDL2MAIN_LIBRARIES SDL2::SDL2main_real ${SDL2MAIN_LIBRARIES}) - endif() - if(MINGW) - # Bugfix - set(SDL2MAIN_LIBRARIES -Wl,--whole-archive ${SDL2MAIN_LIBRARIES} -Wl,--no-whole-archive) - # MinGW requires some additional libraries to appear earlier in the link line. - if(SDL2PC_LIBRARIES) - # Use pkgconfig-suggested extra libraries if available. - list(REMOVE_ITEM SDL2PC_LIBRARIES SDL2main SDL2) - set(SDL2MAIN_LIBRARIES ${SDL2PC_LIBRARIES} ${SDL2MAIN_LIBRARIES}) - else() - # fall back to extra libraries specified in pkg-config in - # an official binary distro of SDL2 for MinGW I downloaded - if(SDL2_MINGW_LIBRARY) - set(SDL2MAIN_LIBRARIES ${SDL2_MINGW_LIBRARY} ${SDL2MAIN_LIBRARIES}) - endif() - if(SDL2_MWINDOWS_LIBRARY) - set(SDL2MAIN_LIBRARIES ${SDL2_MWINDOWS_LIBRARY} ${SDL2MAIN_LIBRARIES}) - endif() - endif() - set_target_properties(SDL2::SDL2main - PROPERTIES - INTERFACE_COMPILE_DEFINITIONS "main=SDL_main") - endif() - set_target_properties(SDL2::SDL2main - PROPERTIES - INTERFACE_LINK_LIBRARIES "${SDL2MAIN_LIBRARIES}") - endif() - mark_as_advanced(SDL2_ROOT_DIR) -endif() - -mark_as_advanced(SDL2_LIBRARY - SDL2_RUNTIME_LIBRARY - SDL2_INCLUDE_DIR - SDL2_SDLMAIN_LIBRARY - SDL2_COCOA_LIBRARY - SDL2_MINGW_LIBRARY - SDL2_MWINDOWS_LIBRARY) - -find_package(Threads REQUIRED) -set_property(TARGET SDL2::SDL2 APPEND PROPERTY - INTERFACE_LINK_LIBRARIES Threads::Threads) +# - Find SDL2 +# Find the SDL2 headers and libraries +# +# SDL2::SDL2 - Imported target to use for building a library +# SDL2::SDL2main - Imported interface target to use if you want SDL and SDLmain. +# SDL2_FOUND - True if SDL2 was found. +# SDL2_DYNAMIC - If we found a DLL version of SDL (meaning you might want to copy a DLL from SDL2::SDL2) +# +# Original Author: +# 2015 Ryan Pavlik +# +# Copyright Sensics, Inc. 2015. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +# Set up architectures (for windows) and prefixes (for mingw builds) +if(WIN32) + if(MINGW) + include(MinGWSearchPathExtras OPTIONAL) + if(MINGWSEARCH_TARGET_TRIPLE) + set(SDL2_PREFIX ${MINGWSEARCH_TARGET_TRIPLE}) + endif() + endif() + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(SDL2_LIB_PATH_SUFFIX lib/x64) + if(NOT MSVC AND NOT SDL2_PREFIX) + set(SDL2_PREFIX x86_64-w64-mingw32) + endif() + else() + set(SDL2_LIB_PATH_SUFFIX lib/x86) + if(NOT MSVC AND NOT SDL2_PREFIX) + set(SDL2_PREFIX i686-w64-mingw32) + endif() + endif() +endif() + +if(SDL2_PREFIX) + set(SDL2_ORIGPREFIXPATH ${CMAKE_PREFIX_PATH}) + if(SDL2_ROOT_DIR) + list(APPEND CMAKE_PREFIX_PATH "${SDL2_ROOT_DIR}") + endif() + if(CMAKE_PREFIX_PATH) + foreach(_prefix ${CMAKE_PREFIX_PATH}) + list(APPEND CMAKE_PREFIX_PATH "${_prefix}/${SDL2_PREFIX}") + endforeach() + endif() + if(MINGWSEARCH_PREFIXES) + list(APPEND CMAKE_PREFIX_PATH ${MINGWSEARCH_PREFIXES}) + endif() +endif() + +# Invoke pkgconfig for hints +find_package(PkgConfig QUIET) +set(SDL2_INCLUDE_HINTS) +set(SDL2_LIB_HINTS) +if(PKG_CONFIG_FOUND) + pkg_search_module(SDL2PC QUIET sdl2) + if(SDL2PC_INCLUDE_DIRS) + set(SDL2_INCLUDE_HINTS ${SDL2PC_INCLUDE_DIRS}) + endif() + if(SDL2PC_LIBRARY_DIRS) + set(SDL2_LIB_HINTS ${SDL2PC_LIBRARY_DIRS}) + endif() +endif() + +include(FindPackageHandleStandardArgs) + +find_library(SDL2_LIBRARY + NAMES + SDL2 + HINTS + ${SDL2_LIB_HINTS} + PATHS + ${SDL2_ROOT_DIR} + ENV SDL2DIR + PATH_SUFFIXES lib SDL2 ${SDL2_LIB_PATH_SUFFIX}) + +set(_sdl2_framework FALSE) +# Some special-casing if we've found/been given a framework. +# Handles whether we're given the library inside the framework or the framework itself. +if(APPLE AND "${SDL2_LIBRARY}" MATCHES "(/[^/]+)*.framework(/.*)?$") + set(_sdl2_framework TRUE) + set(SDL2_FRAMEWORK "${SDL2_LIBRARY}") + # Move up in the directory tree as required to get the framework directory. + while("${SDL2_FRAMEWORK}" MATCHES "(/[^/]+)*.framework(/.*)$" AND NOT "${SDL2_FRAMEWORK}" MATCHES "(/[^/]+)*.framework$") + get_filename_component(SDL2_FRAMEWORK "${SDL2_FRAMEWORK}" DIRECTORY) + endwhile() + if("${SDL2_FRAMEWORK}" MATCHES "(/[^/]+)*.framework$") + set(SDL2_FRAMEWORK_NAME ${CMAKE_MATCH_1}) + # If we found a framework, do a search for the header ahead of time that will be more likely to get the framework header. + find_path(SDL2_INCLUDE_DIR + NAMES + SDL_haptic.h # this file was introduced with SDL2 + HINTS + "${SDL2_FRAMEWORK}/Headers/") + else() + # For some reason we couldn't get the framework directory itself. + # Shouldn't happen, but might if something is weird. + unset(SDL2_FRAMEWORK) + endif() +endif() + +find_path(SDL2_INCLUDE_DIR + NAMES + SDL_haptic.h # this file was introduced with SDL2 + HINTS + ${SDL2_INCLUDE_HINTS} + PATHS + ${SDL2_ROOT_DIR} + ENV SDL2DIR + PATH_SUFFIXES include include/sdl2 include/SDL2 SDL2) + +if(WIN32 AND SDL2_LIBRARY) + find_file(SDL2_RUNTIME_LIBRARY + NAMES + SDL2.dll + libSDL2.dll + HINTS + ${SDL2_LIB_HINTS} + PATHS + ${SDL2_ROOT_DIR} + ENV SDL2DIR + PATH_SUFFIXES bin lib ${SDL2_LIB_PATH_SUFFIX}) +endif() + + +if(WIN32 OR ANDROID OR IOS OR (APPLE AND NOT _sdl2_framework)) + set(SDL2_EXTRA_REQUIRED SDL2_SDLMAIN_LIBRARY) + find_library(SDL2_SDLMAIN_LIBRARY + NAMES + SDL2main + PATHS + ${SDL2_ROOT_DIR} + ENV SDL2DIR + PATH_SUFFIXES lib ${SDL2_LIB_PATH_SUFFIX}) +endif() + +if(MINGW AND NOT SDL2PC_FOUND) + find_library(SDL2_MINGW_LIBRARY mingw32) + find_library(SDL2_MWINDOWS_LIBRARY mwindows) +endif() + +if(SDL2_PREFIX) + # Restore things the way they used to be. + set(CMAKE_PREFIX_PATH ${SDL2_ORIGPREFIXPATH}) +endif() + +# handle the QUIETLY and REQUIRED arguments and set QUATLIB_FOUND to TRUE if +# all listed variables are TRUE +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SDL2 + DEFAULT_MSG + SDL2_LIBRARY + SDL2_INCLUDE_DIR + ${SDL2_EXTRA_REQUIRED}) + +if(SDL2_FOUND) + if(NOT TARGET SDL2::SDL2) + # Create SDL2::SDL2 + if(WIN32 AND SDL2_RUNTIME_LIBRARY) + set(SDL2_DYNAMIC TRUE) + add_library(SDL2::SDL2 SHARED IMPORTED) + set_target_properties(SDL2::SDL2 + PROPERTIES + IMPORTED_IMPLIB "${SDL2_LIBRARY}" + IMPORTED_LOCATION "${SDL2_RUNTIME_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" + ) + else() + add_library(SDL2::SDL2 UNKNOWN IMPORTED) + if(SDL2_FRAMEWORK AND SDL2_FRAMEWORK_NAME) + # Handle the case that SDL2 is a framework and we were able to decompose it above. + set_target_properties(SDL2::SDL2 PROPERTIES + IMPORTED_LOCATION "${SDL2_FRAMEWORK}/${SDL2_FRAMEWORK_NAME}") + elseif(_sdl2_framework AND SDL2_LIBRARY MATCHES "(/[^/]+)*.framework$") + # Handle the case that SDL2 is a framework and SDL_LIBRARY is just the framework itself. + + # This takes the basename of the framework, without the extension, + # and sets it (as a child of the framework) as the imported location for the target. + # This is the library symlink inside of the framework. + set_target_properties(SDL2::SDL2 PROPERTIES + IMPORTED_LOCATION "${SDL2_LIBRARY}/${CMAKE_MATCH_1}") + else() + # Handle non-frameworks (including non-Mac), as well as the case that we're given the library inside of the framework + set_target_properties(SDL2::SDL2 PROPERTIES + IMPORTED_LOCATION "${SDL2_LIBRARY}") + endif() + set_target_properties(SDL2::SDL2 + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" + ) + endif() + + if(APPLE) + # Need Cocoa here, is always a framework + find_library(SDL2_COCOA_LIBRARY Cocoa) + list(APPEND SDL2_EXTRA_REQUIRED SDL2_COCOA_LIBRARY) + if(SDL2_COCOA_LIBRARY) + set_target_properties(SDL2::SDL2 PROPERTIES + IMPORTED_LINK_INTERFACE_LIBRARIES ${SDL2_COCOA_LIBRARY}) + endif() + endif() + + + # Compute what to do with SDL2main + set(SDL2MAIN_LIBRARIES SDL2::SDL2) + add_library(SDL2::SDL2main INTERFACE IMPORTED) + if(SDL2_SDLMAIN_LIBRARY) + add_library(SDL2::SDL2main_real STATIC IMPORTED) + set_target_properties(SDL2::SDL2main_real + PROPERTIES + IMPORTED_LOCATION "${SDL2_SDLMAIN_LIBRARY}") + set(SDL2MAIN_LIBRARIES SDL2::SDL2main_real ${SDL2MAIN_LIBRARIES}) + endif() + if(MINGW) + # Bugfix + set(SDL2MAIN_LIBRARIES -Wl,--whole-archive ${SDL2MAIN_LIBRARIES} -Wl,--no-whole-archive) + # MinGW requires some additional libraries to appear earlier in the link line. + if(SDL2PC_LIBRARIES) + # Use pkgconfig-suggested extra libraries if available. + list(REMOVE_ITEM SDL2PC_LIBRARIES SDL2main SDL2) + set(SDL2MAIN_LIBRARIES ${SDL2PC_LIBRARIES} ${SDL2MAIN_LIBRARIES}) + else() + # fall back to extra libraries specified in pkg-config in + # an official binary distro of SDL2 for MinGW I downloaded + if(SDL2_MINGW_LIBRARY) + set(SDL2MAIN_LIBRARIES ${SDL2_MINGW_LIBRARY} ${SDL2MAIN_LIBRARIES}) + endif() + if(SDL2_MWINDOWS_LIBRARY) + set(SDL2MAIN_LIBRARIES ${SDL2_MWINDOWS_LIBRARY} ${SDL2MAIN_LIBRARIES}) + endif() + endif() + set_target_properties(SDL2::SDL2main + PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "main=SDL_main") + endif() + set_target_properties(SDL2::SDL2main + PROPERTIES + INTERFACE_LINK_LIBRARIES "${SDL2MAIN_LIBRARIES}") + endif() + mark_as_advanced(SDL2_ROOT_DIR) +endif() + +mark_as_advanced(SDL2_LIBRARY + SDL2_RUNTIME_LIBRARY + SDL2_INCLUDE_DIR + SDL2_SDLMAIN_LIBRARY + SDL2_COCOA_LIBRARY + SDL2_MINGW_LIBRARY + SDL2_MWINDOWS_LIBRARY) + +find_package(Threads REQUIRED) +set_property(TARGET SDL2::SDL2 APPEND PROPERTY + INTERFACE_LINK_LIBRARIES Threads::Threads) diff --git a/CMake/Findsodium.cmake b/CMake/Findsodium.cmake index 0667920c255..698e0d0a300 100644 --- a/CMake/Findsodium.cmake +++ b/CMake/Findsodium.cmake @@ -47,7 +47,7 @@ endif() ######################################################################## # UNIX -if (UNIX) +if (UNIX OR AMIGA) # import pkg-config find_package(PkgConfig QUIET) if (PKG_CONFIG_FOUND) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8129e74d5f5..80a44aca7e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Debug") endif() -option(ASAN "Enable address sanitizer" ON) +option(ASAN "Enable address sanitizer" OFF) option(DEBUG "Enable debug mode in engine" ON) option(DIST "Dynamically link only glibc and SDL2" OFF) option(FASTER "Enable FASTER in engine" ON) @@ -64,13 +64,22 @@ if(NOT CMAKE_SIZEOF_VOID_P EQUAL 4) message(WARNING [[Not 32-bit, highly experimental!]]) endif() + find_package(Threads REQUIRED) -find_package(SDL2 CONFIG QUIET) -if (NOT SDL2_FOUND) - find_package(SDL2 REQUIRED) +find_package(Freetype REQUIRED) +find_package(PNG REQUIRED) + +if(SDL1 OR AMIGA) + find_package(SDL 1.2 REQUIRED) + find_package(SDL_ttf REQUIRED) + find_package(SDL_mixer REQUIRED) + find_package(LibMad REQUIRED) +else() + find_package(SDL2 REQUIRED) + find_package(SDL2_ttf REQUIRED) + find_package(SDL2_mixer REQUIRED) endif() -find_package(SDL2_ttf REQUIRED) -find_package(SDL2_mixer REQUIRED) + find_package(sodium REQUIRED) add_library(smacker STATIC @@ -175,8 +184,8 @@ add_library(devilution STATIC Source/track.cpp Source/trigs.cpp Source/wave.cpp) - -add_executable(devilutionx +set( + SOURCES SourceX/dx.cpp SourceX/miniwin/misc.cpp SourceX/miniwin/misc_io.cpp @@ -208,26 +217,106 @@ add_executable(devilutionx SourceX/DiabloUI/selhero.cpp SourceX/DiabloUI/selyesno.cpp SourceX/DiabloUI/title.cpp - SourceX/main.cpp) + SourceX/main.cpp +) + +if(SDL1 OR AMIGA) + list( + APPEND + SOURCES + SourceX/miniwin/sdl1_wrapper.cpp + ) +endif() + +add_executable(devilutionx ${SOURCES}) target_include_directories(devilution PUBLIC Source SourceS) +if(SDL1 OR AMIGA) +target_include_directories(devilutionx PRIVATE + SourceX + 3rdParty/asio/include + 3rdParty/Radon/Radon/include + 3rdParty/libsmacker + ${SDL_INCLUDE_DIR} + ${SDL_INCLUDE_DIRS} + ${SDL_TTF_INCLUDE_DIRS} + ${SDL_MIXER_INCLUDE_DIRS} + ${SDL_INCLUDE_DIRS}/.. + ${SDL_INCLUDE_DIR}/.. + ${SDL_TTF_INCLUDE_DIRS}/.. + ${SDL_MIXER_INCLUDE_DIRS}/.. +) +else() target_include_directories(devilutionx PRIVATE SourceX 3rdParty/asio/include 3rdParty/Radon/Radon/include - 3rdParty/libsmacker) + 3rdParty/libsmacker + ${SDL2_INCLUDE_DIR} + ${SDL2_INCLUDE_DIRS} + ${SDL2_TTF_INCLUDE_DIRS} + ${SDL2_MIXER_INCLUDE_DIRS} + ${SDL2_INCLUDE_DIRS}/.. + ${SDL2_INCLUDE_DIR}/.. + ${SDL2_TTF_INCLUDE_DIRS}/.. + ${SDL2_MIXER_INCLUDE_DIRS}/.. +) + set(SDL_INCLUDE_DIR ${SDL2_INCLUDE_DIR}) +endif() + +message("SDL include dir: " ${SDL_INCLUDE_DIR}) +message("SDL_mixer include dir: " ${SDL_MIXER_INCLUDE_DIRS}) +message("SDL_ttf include dir: " ${SDL_TTF_INCLUDE_DIRS}) target_link_libraries(devilution PUBLIC Threads::Threads) + target_link_libraries(devilutionx PRIVATE devilution PKWare StormLib smacker Radon + sodium + ) + +if(SDL1 OR AMIGA) + target_link_libraries(devilutionx PRIVATE + ${SDL_LIBRARY} + ${SDL_TTF_LIBRARY} + ${SDL_MIXER_LIBRARY} + ${SDL_MIXER_LIBRARIES} + ${FREETYPE_LIBRARIES} + ${PNG_LIBRARIES} + ${LIBMAD_LIBRARIES}) +else() + target_link_libraries(devilutionx PRIVATE SDL2::SDL2main - SDL2::SDL2_ttf - SDL2::SDL2_mixer - sodium) + ${SDL2_ttf_LIBRARY} + ${SDL2_mixer_LIBRARY} + ${FREETYPE_LIBRARIES} + ${PNG_LIBRARIES}) + if(WIN32) + target_link_libraries(devilutionx PRIVATE -lfreetype -lpng -lzlibstatic) + endif() + + message("SDL library: " ${SDL2_LIBRARY} ${SDL2_LIBRARIES}) + message("SDL_mixer library : " ${SDL2_mixer_LIBRARY} ) + message("SDL_ttf library: " ${SDL2_ttf_LIBRARY}) +endif() + +if(AMIGA) + target_link_libraries(devilutionx PRIVATE -ldebug -latomic) +endif() + + # ${PROJECT_SOURCE_DIR}/libSDLmain.a) + # /usr/lib/x86_64-linux-gnu/libSDLmain.a + # ${SDL_LIBRARY} + # `sdl-config --libs` + # ${`sdl-config --libs`} + # SDL2::SDL2main + # SDL2::SDL2_ttf + # SDL2::SDL2_mixer + # sodium) target_compile_definitions(devilution PRIVATE DEVILUTION_ENGINE) target_compile_definitions(devilution PUBLIC @@ -282,6 +371,7 @@ endif() if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") target_compile_options(devilution PRIVATE -fno-aggressive-loop-optimizations) + add_definitions(-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64) endif() if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000000..d80db8de205 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,294 @@ +def notify(status){ + emailext ( + body: '$DEFAULT_CONTENT', + recipientProviders: [ + [$class: 'CulpritsRecipientProvider'], + [$class: 'DevelopersRecipientProvider'], + [$class: 'RequesterRecipientProvider'] + ], + replyTo: '$DEFAULT_REPLYTO', + subject: '$DEFAULT_SUBJECT', + to: '$DEFAULT_RECIPIENTS' + ) +} + +@NonCPS +def killall_jobs() { + def jobname = env.JOB_NAME + def buildnum = env.BUILD_NUMBER.toInteger() + def killnums = "" + def job = Jenkins.instance.getItemByFullName(jobname) + def fixed_job_name = env.JOB_NAME.replace('%2F','/') + + for (build in job.builds) { + if (!build.isBuilding()) { continue; } + if (buildnum == build.getNumber().toInteger()) { continue; println "equals" } + if (buildnum < build.getNumber().toInteger()) { continue; println "newer" } + + echo "Kill task = ${build}" + + killnums += "#" + build.getNumber().toInteger() + ", " + + build.doStop(); + } + + if (killnums != "") { + slackSend color: "danger", channel: "#jenkins", message: "Killing task(s) ${fixed_job_name} ${killnums} in favor of #${buildnum}, ignore following failed builds for ${killnums}" + } + echo "Done killing" +} + + +def get_libs() { + echo "============= Getting Libs =============" + + sh "curl -O https://www.zlib.net/zlib-1.2.11.tar.gz" + sh "curl -O https://www.libsdl.org/release/SDL2-2.0.9.tar.gz" + sh "curl -O https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.4.tar.gz" + sh "curl -O https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.15.tar.gz" + sh "curl -SLO https://download.savannah.gnu.org/releases/freetype/freetype-2.10.1.tar.gz" + sh "curl -SLO https://github.com/glennrp/libpng/archive/v1.6.36.tar.gz" + sh "curl -SLO https://github.com/jedisct1/libsodium/archive/1.0.18.tar.gz" + //sh "wget https://raw.githubusercontent.com/Kitware/CMake/v3.10.0/Modules/FindFreetype.cmake -O CMake/FindFreetype.cmake" + sh "sudo rm -rfv CMake/FindFreetype.cmake" + sh "wget https://raw.githubusercontent.com/Kitware/CMake/v3.10.0/Modules/SelectLibraryConfigurations.cmake -O CMake/SelectLibraryConfigurations.cmake" + sh "wget https://raw.githubusercontent.com/Kitware/CMake/master/Modules/FindZLIB.cmake -O CMake/FindZLIB.cmake" +} + +def decompress_libs() { + echo "============= Unzip Libs =============" + + sh "tar -xvf zlib-1.2.11.tar.gz" + sh "tar -xvf SDL2-2.0.9.tar.gz" + sh "tar -xvf SDL2_mixer-2.0.4.tar.gz" + sh "tar -xvf SDL2_ttf-2.0.15.tar.gz" + sh "tar -xvf v1.6.36.tar.gz" + sh "tar -xvf freetype-2.10.1.tar.gz" + sh "tar -xvf 1.0.18.tar.gz" +} + +def build_zlib(TARGET, SYSROOT) { + echo "============= Build ZLIB =============" + + sh "mkdir -p zlib-1.2.11/build" + sh "sudo rm -rfv zlib-1.2.11/build/*" + + sh "cd zlib-1.2.11/build && cmake .. -DCMAKE_INSTALL_PREFIX=${SYSROOT}" + sh "cd zlib-1.2.11/build && cmake --build . --config Release --target install -- -j8" +} + +def build_sdl2(TARGET, SYSROOT) { + echo "============= Build SDL2 =============" + + sh "cd SDL2-2.0.9/ && ./autogen.sh" + sh "cd SDL2-2.0.9/ && ./configure --host=${TARGET} --enable-sdl2-config --prefix=${SYSROOT}" + sh "cd SDL2-2.0.9/ && make clean" + sh "cd SDL2-2.0.9/ && make -j8" + sh "cd SDL2-2.0.9/ && make install" +} + +def build_sdl2_mixer(TARGET, SYSROOT) { + echo "============= Build SDL2_mixer =============" + + sh "cd SDL2_mixer-2.0.4/ && ./autogen.sh" + sh "cd SDL2_mixer-2.0.4/ && ./configure --host=${TARGET} --prefix=${SYSROOT}" + sh "cd SDL2_mixer-2.0.4/ && make clean" + sh "cd SDL2_mixer-2.0.4/ && make -j8" + sh "cd SDL2_mixer-2.0.4/ && make install" +} + +def build_libpng(TARGET, SYSROOT) { + echo "============= Build libpng =============" + + def ZLIB_FILE = "" + if (SYSROOT.contains('emsdk')) { + ZLIB_FILE = "-DZLIB_LIBRARY:FILEPATH=${SYSROOT}/lib/libz.a -DPNG_SHARED=OFF -DPNG_BUILD_ZLIB=ON -DM_LIBRARY=\"\"" + } + else { + ZLIB_FILE = "" + } + + dir("libpng-1.6.36") { + sh "mkdir -p build" + sh "sudo rm -rfv build/*" + + sh "cd build && cmake .. -DCMAKE_INSTALL_LIBDIR=${SYSROOT}/lib -DCMAKE_INSTALL_INCLUDEDIR=${SYSROOT}/include -DCMAKE_INSTALL_PREFIX=${SYSROOT} ${ZLIB_FILE}" + sh "cd build && cmake --build . --config Release --target install -- -j8" + } +} + +def build_freetype(TARGET, SYSROOT) { + echo "============= Build Freetype =============" + + dir("freetype-2.10.1") { + sh "mkdir -p build" + sh "sudo rm -rfv build/*" + + sh "cd build/ && cmake .. -DCMAKE_INSTALL_PREFIX=${SYSROOT} -DUNIX=1" // -DCMAKE_INSTALL_LIBDIR=${SYSROOT}/lib -DCMAKE_INSTALL_INCLUDEDIR=${SYSROOT}/include + sh "cd build/ && cmake --build . --config Release --target install -- -j8" + } +} + +def build_sdl2_ttf(TARGET, SYSROOT) { + echo "============= Build SDL2_ttf =============" + + def ZLIB_FILE = "" + if (SYSROOT.contains('mingw')) { + ZLIB_FILE = "zlibstatic" + } + else { + ZLIB_FILE = "z" + } + + dir("SDL2_ttf-2.0.15") { + sh "./autogen.sh" + sh "FT2_CFLAGS=\"-I${SYSROOT}/include/freetype2\" FT2_LIBS=\"-lfreetype -lpng -l${ZLIB_FILE}\" ./configure --disable-shared --enable-static --host=${TARGET} --prefix=${SYSROOT}" //FT2_CONFIG=${SYSROOT}/include/freetype2/freetype/config/ftconfig.h + sh "make clean" + sh "make -j8" + sh "make install" + } +} + +def build_libsodium(TARGET, SYSROOT) { + echo "============= Build Libsodium =============" + + def CONF_PARAMS = "" + if (SYSROOT.contains('emsdk')) { + CONF_PARAMS = "--disable-shared --disable-ssp --disable-asm --disable-pie --enable-minimal" + } + else { + CONF_PARAMS = "--host=${TARGET} " + } + + dir("libsodium-1.0.18") { + sh "./autogen.sh" + sh "./configure --prefix=${SYSROOT} ${CONF_PARAMS}" + sh "make clean" + sh "make -j8" + sh "make install" + } +} + + +def buildStep(dockerImage, generator, os, defines) { + def split_job_name = env.JOB_NAME.split(/\/{1}/) + def fixed_job_name = split_job_name[1].replace('%2F',' ') + def fixed_os = os.replace(' ','-') + try{ + stage("Building on \"${dockerImage}\" with \"${generator}\" for \"${os}\"...") { + properties([pipelineTriggers([githubPush()])]) + def commondir = env.WORKSPACE + '/../' + fixed_job_name + '/' + + docker.image("${dockerImage}").inside("-u 0:0 -e BUILDER_UID=1001 -e BUILDER_GID=1001 -e BUILDER_USER=gserver -e BUILDER_GROUP=gserver") { + + sh "sudo apt update" + sh "sudo apt install -y gcc-multilib curl automake autoconf libtool unzip" + + checkout scm + + if (env.CHANGE_ID) { + echo 'Trying to build pull request' + } + + if (!env.CHANGE_ID) { + sh "rm -rfv publishing/deploy/*" + sh "mkdir -p publishing/deploy/devilutionx" + } + + def TARGET = sh ( + script: '$CC -dumpmachine', + returnStdout: true + ).trim() + + def SYSROOT + + if (os.contains('Web')) { + SYSROOT = "/emsdk_portable/sdk/system" + } + else { + SYSROOT = sh ( + script: '$CC -print-sysroot', + returnStdout: true + ).trim() + } + + get_libs() + decompress_libs() + build_zlib(TARGET, SYSROOT) + build_sdl2(TARGET, SYSROOT) + build_sdl2_mixer(TARGET, SYSROOT) + build_libpng(TARGET, SYSROOT) + build_freetype(TARGET, SYSROOT) + build_sdl2_ttf(TARGET, SYSROOT) + build_libsodium(TARGET, SYSROOT) + + sh "mkdir -p build/" + sh "mkdir -p lib/" + sh "sudo rm -rfv build/*" + + slackSend color: "good", channel: "#jenkins", message: "Starting ${os} build target..." + dir("build") { + sh "PKG_CONFIG_PATH=${SYSROOT}/lib/pkgconfig/:${SYSROOT}/share/pkgconfig/ cmake -G\"${generator}\" ${defines} -DVER_EXTRA=\"-${fixed_os}-${fixed_job_name}\" -DCMAKE_PREFIX_PATH=${SYSROOT} .. " + sh "VERBOSE=1 cmake --build . --config Release -- -j 8" + + if (os.contains('Windows')) { + sh "mv devilutionx.exe devilutionx-${fixed_os}-${fixed_job_name}.exe" + archiveArtifacts artifacts: "devilutionx-${fixed_os}-${fixed_job_name}.exe" + } else { + sh "mv devilutionx devilutionx-${fixed_os}-${fixed_job_name}" + archiveArtifacts artifacts: "devilutionx-${fixed_os}-${fixed_job_name}" + } + + //sh "cmake --build . --config Release --target package -- -j 8" + //archiveArtifacts artifacts: '*.zip,*.tar.gz,*.tgz' + } + + slackSend color: "good", channel: "#jenkins", message: "Build ${fixed_job_name} #${env.BUILD_NUMBER} Target: ${os} DockerImage: ${dockerImage} Generator: ${generator} successful!" + } + } + } catch(err) { + slackSend color: "danger", channel: "#jenkins", message: "Build Failed: ${fixed_job_name} #${env.BUILD_NUMBER} Target: ${os} DockerImage: ${dockerImage} Generator: ${generator} (<${env.BUILD_URL}|Open>)" + currentBuild.result = 'FAILURE' + notify('Build failed') + throw err + } +} + +node('master') { + killall_jobs() + def fixed_job_name = env.JOB_NAME.replace('%2F','/') + slackSend color: "good", channel: "#jenkins", message: "Build Started: ${fixed_job_name} #${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)" + parallel ( + /* + 'Win32': { + node { + buildStep('dockcross/windows-static-x86:latest', 'Unix Makefiles', 'Windows x86', '') + } + }, + 'Win64': { + node { + buildStep('dockcross/windows-static-x64:latest', 'Unix Makefiles', 'Windows x86_64', '') + } + }, + 'Linux x86': { + node { + buildStep('desertbit/crossbuild:linux-x86', 'Unix Makefiles', 'Linux x86', '') + } + }, + 'Linux x86_64': { + node { + buildStep('desertbit/crossbuild:linux-x86_64', 'Unix Makefiles', 'Linux x86_64', '') + } + }, + 'Linux ARMv7': { + node { + buildStep('desertbit/crossbuild:linux-armv7', 'Unix Makefiles', 'Linux RasPi', '') + } + },*/ + 'WebASM': { + node { + buildStep('dockcross/web-wasm:latest', 'Unix Makefiles', 'Web assembly', '') + } + } + ) +} \ No newline at end of file diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index 2b82e869c13..ffe3094f57f 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -1,5 +1,6 @@ #include "diablo.h" #include "../3rdParty/Storm/Source/storm.h" +#include "../3rdParty/StormLib/src/StormPort.h" DEVILUTION_BEGIN_NAMESPACE @@ -581,15 +582,15 @@ BOOL WriteMPQHeader() DWORD NumberOfBytesWritten; memset(&fhdr, 0, sizeof(fhdr)); - fhdr.signature = '\x1AQPM'; - fhdr.headersize = 32; - fhdr.filesize = GetFileSize(sghArchive, 0); - fhdr.version = 0; - fhdr.sectorsizeid = 3; - fhdr.hashoffset = 32872; - fhdr.blockoffset = 104; - fhdr.hashcount = 2048; - fhdr.blockcount = 2048; + fhdr.signature = BSWAP_INT32_UNSIGNED('\x1AQPM'); + fhdr.headersize = BSWAP_INT32_UNSIGNED(32); + fhdr.filesize = BSWAP_INT32_UNSIGNED(GetFileSize(sghArchive, 0)); + fhdr.version = BSWAP_INT16_UNSIGNED(0); + fhdr.sectorsizeid = BSWAP_INT16_UNSIGNED(3); + fhdr.hashoffset = BSWAP_INT32_UNSIGNED(32872); + fhdr.blockoffset = BSWAP_INT32_UNSIGNED(104); + fhdr.hashcount = BSWAP_INT32_UNSIGNED(2048); + fhdr.blockcount = BSWAP_INT32_UNSIGNED(2048); if (SetFilePointer(sghArchive, 0, NULL, FILE_BEGIN) == -1) return 0; diff --git a/Source/wave.cpp b/Source/wave.cpp index 7f35a040ad8..eac3f0bfd37 100644 --- a/Source/wave.cpp +++ b/Source/wave.cpp @@ -1,5 +1,6 @@ #include "diablo.h" #include "../3rdParty/Storm/Source/storm.h" +#include "../3rdParty/StormLib/src/StormPort.h" DEVILUTION_BEGIN_NAMESPACE @@ -127,12 +128,12 @@ BOOL ReadWaveFile(MEMFILE *pMemFile, WAVEFORMATEX *pwfx, CKINFO *chunk) return FALSE; pwfx->cbSize = 0; - pwfx->wFormatTag = wf.wf.wFormatTag; - pwfx->nChannels = wf.wf.nChannels; - pwfx->nSamplesPerSec = wf.wf.nSamplesPerSec; - pwfx->nAvgBytesPerSec = wf.wf.nAvgBytesPerSec; - pwfx->nBlockAlign = wf.wf.nBlockAlign; - pwfx->wBitsPerSample = wf.wBitsPerSample; + pwfx->wFormatTag = BSWAP_INT16_UNSIGNED(wf.wf.wFormatTag); + pwfx->nChannels = BSWAP_INT16_UNSIGNED(wf.wf.nChannels); + pwfx->nSamplesPerSec = BSWAP_INT32_UNSIGNED(wf.wf.nSamplesPerSec); + pwfx->nAvgBytesPerSec = BSWAP_INT32_UNSIGNED(wf.wf.nAvgBytesPerSec); + pwfx->nBlockAlign = BSWAP_INT16_UNSIGNED(wf.wf.nBlockAlign); + pwfx->wBitsPerSample = BSWAP_INT16_UNSIGNED(wf.wBitsPerSample); if (chunk == NULL) return TRUE; return ReadWaveSection(pMemFile, MAKEFOURCC('d', 'a', 't', 'a'), chunk); @@ -196,7 +197,7 @@ BOOL ReadWaveSection(MEMFILE *pMemFile, DWORD id, CKINFO *chunk) return FALSE; } - chunk->dwSize = hdr[1]; + chunk->dwSize = BSWAP_INT32_UNSIGNED(hdr[1]); chunk->dwOffset = SeekMemFile(pMemFile, 0, FILE_CURRENT); return chunk->dwOffset != (DWORD)-1; } diff --git a/SourceS/miniwin.h b/SourceS/miniwin.h index a179852b686..415087db3a7 100644 --- a/SourceS/miniwin.h +++ b/SourceS/miniwin.h @@ -5,6 +5,11 @@ // work around https://reviews.llvm.org/D51265 #if defined(__APPLE__) || defined(__FreeBSD__) #include "macos_stdarg.h" +#elseif defined(__EMSCRIPTEN__) +typedef __builtin_va_list va_list; +#define _VA_LIST_T +#define va_start(ap, param) (ap) +#define va_end(ap) (ap) #else #include #endif diff --git a/SourceX/DiabloUI/diabloui.cpp b/SourceX/DiabloUI/diabloui.cpp index 5ea5c364180..6e0cb207049 100644 --- a/SourceX/DiabloUI/diabloui.cpp +++ b/SourceX/DiabloUI/diabloui.cpp @@ -245,7 +245,12 @@ bool UiFocusNavigation(SDL_Event *event) return true; } } - + + if (event->type == SDL_MOUSEBUTTONDOWN) { + UiFocusNavigationSelect(); + return true; + } + if (SDL_IsTextInputActive()) { switch (event->type) { case SDL_KEYDOWN: @@ -267,11 +272,20 @@ bool UiFocusNavigation(SDL_Event *event) } return true; } - break; - case SDL_TEXTINPUT: + break; +#if !SDL_VERSION_ATLEAST(2, 0, 0) + case SDL_KEYUP: + if (event->key.keysym.sym >= SDLK_a && event->key.keysym.sym <= SDLK_z) + selhero_CatToName(SDL_GetKeyName(event->key.keysym.sym), UiTextInput, UiTextInputLen); + return true; +#else +// Todo(Amiga): Fix this + case SDL_TEXTINPUT: selhero_CatToName(event->text.text, UiTextInput, UiTextInputLen); return true; +#endif } + } if (gUiItems && gUiItemCnt && UiItemMouseEvents(event, gUiItems, gUiItemCnt)) @@ -393,8 +407,10 @@ void InitFont() return; } +#ifndef __AMIGA__ TTF_SetFontKerning(font, false); TTF_SetFontHinting(font, TTF_HINTING_MONO); +#endif } void UiInitialize() @@ -786,7 +802,11 @@ bool UiItemMouseEvents(SDL_Event *event, UI_Item *items, int size) if (event->type != SDL_MOUSEBUTTONDOWN || event->button.button != SDL_BUTTON_LEFT) { return false; } - + +/*SDL_PumpEvents(); +if(SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1)) + printf("Mouse Button 1(left) is pressed.\n"); +*/ for (int i = 0; i < size; i++) { if (!IsInsideRect(event, &items[i].rect)) { continue; @@ -800,10 +820,15 @@ bool UiItemMouseEvents(SDL_Event *event, UI_Item *items, int size) if (items[i].caption != NULL && *items[i].caption != '\0') { if (gfnListFocus != NULL && SelectedItem != items[i].value) { UiFocus(items[i].value); - } else if (gfnListFocus == NULL || event->button.clicks >= 2) { + + } + //klaus_BAD + + else if (gfnListFocus == NULL || event->button.button == SDL_BUTTON_LEFT/*event->button.clicks >= 2*/) { SelectedItem = items[i].value; UiFocusNavigationSelect(); } + } return true; diff --git a/SourceX/miniwin/ddraw.h b/SourceX/miniwin/ddraw.h index 1704192d9f1..22155656a01 100644 --- a/SourceX/miniwin/ddraw.h +++ b/SourceX/miniwin/ddraw.h @@ -1,5 +1,10 @@ #include "devilution.h" #include +#include +#include "../SourceS/miniwin/misc.h" +#if !SDL_VERSION_ATLEAST(2, 0, 0) +#include "sdl1_wrapper.h" +#endif namespace dvl { diff --git a/SourceX/miniwin/dsound.cpp b/SourceX/miniwin/dsound.cpp index cff8058eef5..63c8af3094a 100644 --- a/SourceX/miniwin/dsound.cpp +++ b/SourceX/miniwin/dsound.cpp @@ -2,6 +2,10 @@ #include "miniwin/dsound.h" #include "stubs.h" #include +#include "../SourceS/miniwin/misc.h" +#if !SDL_VERSION_ATLEAST(2, 0, 0) +#include "sdl1_wrapper.h" +#endif namespace dvl { @@ -70,6 +74,7 @@ HRESULT DirectSoundBuffer::Play(DWORD dwReserved1, DWORD dwPriority, DWORD dwFla int channel = Mix_PlayChannel(-1, chunk, 0); if (channel == -1) { SDL_Log("Too few channels, skipping sound\n"); + printf("Mix_PlayChannel: %s\n",Mix_GetError()); return DVL_DS_OK; } diff --git a/SourceX/miniwin/misc.cpp b/SourceX/miniwin/misc.cpp index 3d5a8de5ddf..4328fc20675 100644 --- a/SourceX/miniwin/misc.cpp +++ b/SourceX/miniwin/misc.cpp @@ -3,7 +3,11 @@ #include "stubs.h" #include #include - +#include "../SourceS/miniwin/misc.h" +#include "../SourceS/miniwin/com.h" +#if !SDL_VERSION_ATLEAST(2, 0, 0) +#include "sdl1_wrapper.h" +#endif #include "DiabloUI/diabloui.h" #ifdef _MSC_VER @@ -52,6 +56,7 @@ char *_strlwr(char *str) int wsprintfA(LPSTR dest, LPCSTR format, ...) { va_list args; + va_start(args, format); return vsprintf(dest, format, args); } @@ -120,8 +125,10 @@ UINT GetWindowsDirectoryA(LPSTR lpBuffer, UINT uSize) { char *name = SDL_GetPrefPath("diasurgical", "devilution"); strncpy(lpBuffer, name, uSize); - SDL_free(name); - + if(name!=nullptr){ + //eprintf("SDL_free(name) =: %s\n", name); + //SDL_free(name); + } DWORD len = strlen(lpBuffer); lpBuffer[len - 1] = '\0'; @@ -146,7 +153,11 @@ DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize) { char *name = SDL_GetPrefPath("diasurgical", "devilution"); strncpy(lpFilename, name, nSize); - SDL_free(name); + if(name!=nullptr) + { + //eprintf("SDL_free(name) =: %s\n", name); + //SDL_free(name); + } DWORD len = strlen(lpFilename); @@ -201,8 +212,9 @@ DWORD GetCurrentDirectory(DWORD nBufferLength, LPTSTR lpBuffer) char *base_path = SDL_GetBasePath(); if (base_path == NULL) { SDL_Log(SDL_GetError()); - base_path = SDL_strdup("./"); + base_path = SDL_strdup("data/"); } + base_path = SDL_strdup("data/"); eprintf("BasePath: %s\n", base_path); strncpy(lpBuffer, base_path, nBufferLength); @@ -338,7 +350,7 @@ HWND CreateWindowExA( } atexit(SDL_Quit); - int upscale = 1; + int upscale = 0; //disable arczi DvlIntSetting("upscale", &upscale); DvlIntSetting("fullscreen", &fullscreen); @@ -359,6 +371,7 @@ HWND CreateWindowExA( flags |= SDL_WINDOW_INPUT_GRABBED; } + window = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, nWidth, nHeight, flags); if (window == NULL) { SDL_Log(SDL_GetError()); diff --git a/SourceX/miniwin/misc_io.cpp b/SourceX/miniwin/misc_io.cpp index 00b811815c3..83678b5e1f6 100644 --- a/SourceX/miniwin/misc_io.cpp +++ b/SourceX/miniwin/misc_io.cpp @@ -125,29 +125,46 @@ WINBOOL SetFileAttributesA(LPCSTR lpFileName, DWORD dwFileAttributes) WINBOOL CloseHandle(HANDLE hObject) { + //Todo(Amiga): Fix the error handling memfile* file = static_cast(hObject); if (files.find(file) == files.end()) return true; std::unique_ptr ufile(file); // ensure that delete file is // called on returning files.erase(file); +#ifndef __AMIGA__ try { +#endif std::ofstream filestream(file->path + ".tmp", std::ios::binary | std::ios::trunc); if (filestream.fail()) + { + #ifndef __AMIGA__ throw std::runtime_error("ofstream"); + #endif + } filestream.write(file->buf.data(), file->buf.size()); if (filestream.fail()) + { + #ifndef __AMIGA__ throw std::runtime_error("ofstream::write"); + #endif + } filestream.close(); std::remove(file->path.c_str()); if (std::rename((file->path + ".tmp").c_str(), file->path.c_str())) + { + #ifndef __AMIGA__ throw std::runtime_error("rename"); + #endif + } return true; +#ifndef __AMIGA__ } catch (std::runtime_error e) { // log DialogBoxParam(ghInst, DVL_MAKEINTRESOURCE(IDD_DIALOG7), ghMainWnd, (DLGPROC)FuncDlg, (LPARAM)file->path.c_str()); return false; } +#endif } } // namespace dvl diff --git a/SourceX/miniwin/misc_msg.cpp b/SourceX/miniwin/misc_msg.cpp index 31bf16d06a0..b338117ffdc 100644 --- a/SourceX/miniwin/misc_msg.cpp +++ b/SourceX/miniwin/misc_msg.cpp @@ -1,6 +1,8 @@ #include #include - +#if !SDL_VERSION_ATLEAST(2, 0, 0) +#include "sdl1_wrapper.h" +#endif #include "devilution.h" #include "stubs.h" @@ -75,6 +77,7 @@ static int translate_sdl_key(SDL_Keysym key) return DVL_VK_F9; case SDLK_F10: return DVL_VK_F10; +#ifndef __AMIGA__ case SDLK_F11: return DVL_VK_F11; case SDLK_F12: @@ -83,18 +86,23 @@ static int translate_sdl_key(SDL_Keysym key) return DVL_VK_SNAPSHOT; case SDLK_SCROLLLOCK: return DVL_VK_SCROLL; +#endif case SDLK_PAUSE: return DVL_VK_PAUSE; case SDLK_INSERT: return DVL_VK_INSERT; case SDLK_HOME: return DVL_VK_HOME; +#ifndef __AMIGA__ case SDLK_PAGEUP: return DVL_VK_PRIOR; +#endif case SDLK_END: return DVL_VK_END; +#ifndef __AMIGA__ case SDLK_PAGEDOWN: return DVL_VK_NEXT; +#endif case SDLK_RIGHT: return DVL_VK_RIGHT; case SDLK_LEFT: @@ -103,8 +111,10 @@ static int translate_sdl_key(SDL_Keysym key) return DVL_VK_DOWN; case SDLK_UP: return DVL_VK_UP; +#ifndef __AMIGA__ case SDLK_NUMLOCKCLEAR: return DVL_VK_NUMLOCK; +#endif case SDLK_KP_DIVIDE: return DVL_VK_DIVIDE; case SDLK_KP_MULTIPLY: @@ -145,24 +155,30 @@ static int translate_sdl_key(SDL_Keysym key) return DVL_VK_DECIMAL; case SDLK_MENU: return DVL_VK_MENU; +#if SDL_VERSION_ATLEAST(2, 0, 0) case SDLK_KP_COMMA: return DVL_VK_OEM_COMMA; +#endif case SDLK_LCTRL: return DVL_VK_LCONTROL; case SDLK_LSHIFT: return DVL_VK_LSHIFT; case SDLK_LALT: return DVL_VK_LMENU; +#ifndef __AMIGA__ case SDLK_LGUI: return DVL_VK_LWIN; +#endif case SDLK_RCTRL: return DVL_VK_RCONTROL; case SDLK_RSHIFT: return DVL_VK_RSHIFT; case SDLK_RALT: return DVL_VK_RMENU; +#ifndef __AMIGA__ case SDLK_RGUI: return DVL_VK_RWIN; +#endif default: if (sym >= SDLK_a && sym <= SDLK_z) { return 'A' + (sym - SDLK_a); @@ -171,7 +187,7 @@ static int translate_sdl_key(SDL_Keysym key) } else if (sym >= SDLK_F1 && sym <= SDLK_F12) { return DVL_VK_F1 + (sym - SDLK_F1); } - DUMMY_PRINT("unknown key: name=%s sym=0x%X scan=%d mod=0x%X", SDL_GetKeyName(sym), sym, key.scancode, key.mod); + DUMMY_PRINT("unknown key: name=%s sym=0x%X scan=%d mod=0x%X", SDL_GetKeyName(key.sym), sym, key.scancode, key.mod); return -1; } } @@ -271,6 +287,8 @@ WINBOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilter return false_avail(); } } break; +/* +Todo(Amiga): Fix this case SDL_TEXTINPUT: case SDL_WINDOWEVENT: if (e.window.event == SDL_WINDOWEVENT_CLOSE) { @@ -279,6 +297,7 @@ WINBOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilter return false_avail(); } break; +*/ default: DUMMY_PRINT("unknown SDL message 0x%X", e.type); return false_avail(); diff --git a/SourceX/miniwin/sdl1_wrapper.cpp b/SourceX/miniwin/sdl1_wrapper.cpp new file mode 100644 index 00000000000..2db2e7b430f --- /dev/null +++ b/SourceX/miniwin/sdl1_wrapper.cpp @@ -0,0 +1,508 @@ +#include +#include "sdl1_wrapper.h" +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +static SDL_bool isTextInputActive = (SDL_bool)false; + +struct SDL_Window { + const void *magic; + Uint32 id; + char *title; + SDL_Surface *icon; + int x, y; + int w, h; + int min_w, min_h; + int max_w, max_h; + Uint32 flags; + Uint32 last_fullscreen_flags; + + /* Stored position and size for windowed mode */ + SDL_Rect windowed; + + SDL_DisplayMode fullscreen_mode; + + float brightness; + Uint16 *gamma; + Uint16 *saved_gamma; /* (just offset into gamma) */ + + SDL_Surface *surface; + SDL_bool surface_valid; + + SDL_bool is_hiding; + SDL_bool is_destroying; + + SDL_WindowShaper *shaper; + + SDL_HitTest hit_test; + void *hit_test_data; + + SDL_WindowUserData *data; + + void *driverdata; + + SDL_Window *prev; + SDL_Window *next; +}; + +struct SDL_WindowShaper { + /* The window associated with the shaper */ + SDL_Window *window; + + /* The user's specified coordinates for the window, for once we give it a shape. */ + Uint32 userx,usery; + + /* The parameters for shape calculation. */ + SDL_WindowShapeMode mode; + + /* Has this window been assigned a shape? */ + SDL_bool hasshape; + + void *driverdata; +}; + +void SDL_RenderGetScale(SDL_Renderer* renderer, float* scaleX, float* scaleY) +{ +} + +void SDL_GetWindowSize(SDL_Window* window, int* w, int* h) +{ +} + +void SDL_GetWindowPosition(SDL_Window* window, int* x, int* y) +{ +} + +void SDL_EnableScreenSaver(void) +{ +} + +void SDL_DisableScreenSaver(void) +{ +} + +SDL_bool SDL_SetHint(const char* name, const char* value) +{ + return (SDL_bool)1; +} + +int SDL_ShowSimpleMessageBox(Uint32 flags, const char* title, const char* message, SDL_Window* window) +{ + printf("AAAAAA = %s\n", message); + return 1; +} + +void SDL_RenderGetViewport(SDL_Renderer* renderer, SDL_Rect* rect) +{ + +} + +SDL_Surface* SDL_CreateRGBSurfaceWithFormatFrom(void* pixels, + int width, + int height, + int depth, + int pitch, + Uint32 format) +{ + Uint32 rmask, gmask, bmask, amask; + + /* SDL interprets each pixel as a 32-bit number, so our masks must depend + on the endianness (byte order) of the machine */ +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + rmask = 0xff000000; + gmask = 0x00ff0000; + bmask = 0x0000ff00; + amask = 0x000000ff; +#else + rmask = 0x000000ff; + gmask = 0x0000ff00; + bmask = 0x00ff0000; + amask = 0xff000000; +#endif + + return SDL_CreateRGBSurfaceFrom(pixels, width, height, depth, pitch, rmask, gmask, bmask, amask); +} + +int SDL_RenderSetLogicalSize(SDL_Renderer* renderer, int w, int h) +{ + return 1; +} + +void SDL_RaiseWindow(SDL_Window * window) +{ +} + +SDL_Window* SDL_CreateWindow(const char* title, int x, int y, int w, int h, Uint32 flags) +{ + auto* window = new SDL_Window; + + window->surface = SDL_SetVideoMode(w, h, D_BPP, D_SDL_MODES); + + return window; +} + +void SDL_DestroyWindow(SDL_Window* window) +{ + SDL_FreeSurface(window->surface); +} + +SDL_Surface* SDL_GetWindowSurface(SDL_Window* window) +{ + if (window) + return window->surface; + else + return NULL; +} + +int SDL_UpdateWindowSurface(SDL_Window* window) // only used when upscaling is disabled +{ + return SDL_Flip(window->surface); +} + +SDL_Renderer* SDL_CreateRenderer(SDL_Window* window, int index, Uint32 flags) // only used when upscaling is enabled +{ + return window->surface; +} + +int SDL_SetRenderDrawColor(SDL_Renderer* renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a) // only used when upscaling is enabled +{ + SDL_FillRect( renderer, NULL, SDL_MapRGBA( renderer->format, r, g, b, a) ); +} + +SDL_Texture* SDL_CreateTextureFromSurface(SDL_Renderer* renderer, + SDL_Surface* surface) +{ + if( renderer != nullptr ) + { + //Create an optimized image + renderer = SDL_DisplayFormat( surface ); + return renderer; + } +} + +SDL_AudioDeviceID SDL_OpenAudioDevice(const char* device, int iscapture, + const SDL_AudioSpec* desired, + SDL_AudioSpec* obtained, + int allowed_changes) +{ + + return SDL_OpenAudio(const_cast(desired), const_cast(obtained)); + +} + +void SDL_CloseAudioDevice(SDL_AudioDeviceID dev) +{ + SDL_CloseAudio(); +} + +void SDL_SetWindowTitle(SDL_Window* window, const char* title) +{ + SDL_WM_SetCaption(title, ""); +} + +void SDL_SetWindowPosition(SDL_Window* window, int x, int y) +{ + +} + +void SDL_PauseAudioDevice(SDL_AudioDeviceID dev, int pause_on) +{ + SDL_PauseAudio(pause_on); +} + +Uint32 SDL_GetWindowPixelFormat(SDL_Window* window) +{ + return 0;//window->surface->format;//SDL_PIXELFORMAT_RGBA8888; +} + +SDL_bool SDL_IsScreenSaverEnabled(void) +{ + return (SDL_bool)1; +} + +SDL_bool SDL_PointInRect(const SDL_Point* p, const SDL_Rect* r) +{ + SDL_Cursor* cursor = SDL_GetCursor(); + + if (cursor->area.x == p->x && cursor->area.y == p->y) + return SDL_TRUE; + else + return SDL_FALSE; +} + + +int SDL_BlitScaled(SDL_Surface* src, const SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect) +{ + return SDL_BlitSurface(src, const_cast(srcrect), dst, dstrect); +} + +void SDL_ClearQueuedAudio(SDL_AudioDeviceID dev) +{ + +} + +void SDL_ShowWindow(SDL_Window* window) +{ + +} + +const Uint8* SDL_GetKeyboardState(int* numkeys) +{ + return SDL_GetKeyState(numkeys); +} + +void SDL_StopTextInput(void) +{ + isTextInputActive = (SDL_bool)false; +} + +void SDL_StartTextInput(void) +{ + isTextInputActive = (SDL_bool)true; +} + +void SDL_HideWindow(SDL_Window* window) +{ + +} + +int SDL_GetRendererOutputSize(SDL_Renderer* renderer, int* w, int* h) +{ + return 0; +} + +void SDL_WarpMouseInWindow(SDL_Window* window, int x, int y) +{ + SDL_WarpMouse(x, y); +} + +SDL_Surface* SDL_ConvertSurfaceFormat(SDL_Surface* src, Uint32 pixel_format, Uint32 flags) +{ + return SDL_DisplayFormat( src ); +} + +SDL_bool SDL_IsTextInputActive(void) +{ + return isTextInputActive; +} + +int SDL_GetCurrentDisplayMode(int displayIndex, SDL_DisplayMode* mode) +{ + return 0; +} + +int SDL_UpdateTexture(SDL_Texture* texture, const SDL_Rect* rect, const void* pixels, int pitch) +{ + return SDL_Flip(texture); +} + +SDL_Texture* SDL_CreateTexture(SDL_Renderer* renderer, Uint32 format, int access, int w, int h) +{ + Uint32 rmask, gmask, bmask, amask; + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + rmask = 0xff000000; + gmask = 0x00ff0000; + bmask = 0x0000ff00; + amask = 0x000000ff; +#else + rmask = 0x000000ff; + gmask = 0x0000ff00; + bmask = 0x00ff0000; + amask = 0xff000000; +#endif + return SDL_CreateRGBSurface(renderer->flags, w, h, D_BPP, rmask, gmask, bmask, amask); +} + +int SDL_SetWindowInputFocus(SDL_Window* window) +{ + return 0; +} + +void SDL_DestroyTexture(SDL_Texture* texture) +{ + SDL_FreeSurface(texture); +} + +void SDL_DestroyRenderer(SDL_Renderer* Renderer) +{ + SDL_FreeSurface(Renderer); +} + +int SDL_RenderClear(SDL_Renderer* renderer) +{ + return 0; +} + +int SDL_RenderCopy(SDL_Renderer* renderer, + SDL_Texture* texture, + const SDL_Rect* srcrect, + const SDL_Rect* dstrect) +{ + //Blit the surface + return SDL_BlitSurface( texture, NULL, renderer, NULL ); +} + +void SDL_RenderPresent(SDL_Renderer* renderer) +{ + //SDL_Flip(renderer); +} + +void SDL_Log(const char *fmt, ...) { + + printf("%s\n", fmt); +} + +int SDL_SetSurfacePalette(SDL_Surface* surface, SDL_Palette* palette) +{ +// printf("Surface palette set!"); + +// for (int i = 0; i < palette->ncolors;i++) +// printf("%i: r(%i), g(%i), b(%i)", i, palette->colors[i].r, palette->colors[i].g, palette->colors[i].b); + + return SDL_SetPalette(surface, 0/*SDL_LOGPAL|SDL_PHYSPAL*/, palette->colors, 0, palette->ncolors); +} + +SDL_Palette * SDL_AllocPalette(int ncolors) +{ + SDL_Palette *palette; + + /* Input validation */ + if (ncolors < 1) { + printf("ncolors"); + return nullptr; + } + + palette = (SDL_Palette *) SDL_malloc(sizeof(*palette)); + if (!palette) { + SDL_OutOfMemory(); + return nullptr; + } + + palette->colors = (SDL_Color *) SDL_malloc(ncolors * sizeof(*palette->colors)); + + if (!palette->colors) { + SDL_free(palette); + return nullptr; + } + palette->ncolors = ncolors; + //palette->version = 1; + //palette->refcount = 1; + + SDL_memset(palette->colors, 0xFF, ncolors * sizeof(*palette->colors)); + + return palette; +} + +int SDL_SetPaletteColors(SDL_Palette * palette, const SDL_Color * colors, + int firstcolor, int ncolors) +{ + int status = 0; + + /* Verify the parameters */ + if (!palette) { + return -1; + } + if (ncolors > (palette->ncolors - firstcolor)) { + ncolors = (palette->ncolors - firstcolor); + status = -1; + } + + if (colors != (palette->colors + firstcolor)) { + SDL_memcpy(palette->colors + firstcolor, colors, + ncolors * sizeof(*colors)); + } + + /* + ++palette->version; + if (!palette->version) { + palette->version = 1; + } +*/ + return status; +} + +void +SDL_FreePalette(SDL_Palette * palette) +{ + if (!palette) { + SDL_SetError("palette error"); + return; + } + /* + if (--palette->refcount > 0) { + return; + } + */ + SDL_free(palette->colors); + SDL_free(palette); +} + +/* + * Create an empty RGB surface of the appropriate depth using the given + * enum SDL_PIXELFORMAT_* format + */ +SDL_Surface * +SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, + Uint32 format) +{ + SDL_Surface * surface; + Uint32 rmask, gmask, bmask, amask; + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + rmask = 0xff000000; + gmask = 0x00ff0000; + bmask = 0x0000ff00; + amask = 0x000000ff; +#else + rmask = 0x000000ff; + gmask = 0x0000ff00; + bmask = 0x00ff0000; + amask = 0xff000000; +#endif + if (depth == 8) { + surface = SDL_CreateRGBSurface(flags, width, height, depth, 0, 0, 0, 0); + } + else + surface = SDL_CreateRGBSurface(flags, width, height, depth, rmask, gmask, bmask, amask); + return surface; +} + +char* SDL_GetPrefPath(const char* org, const char* app) { return (char*)org; } +// char* SDL_GetPrefPath(const char* org, const char* app) { + +// int len = SDL_strlen(org) + SDL_strlen(app) + 8; +// char* retval = (char *) SDL_malloc(len); + +// if (!retval) { +// SDL_OutOfMemory(); +// return NULL; +// } + +// if (*org) { +// SDL_snprintf(retval, len, "/home/%s/%s/", org, app); +// } else { +// SDL_snprintf(retval, len, "/home/%s/", app); +// } + +// return retval; +// } + +char* SDL_GetBasePath(void) { + + return ""; +} + +char* SDL_GetClipboardText(void) +{ + return ""; +} + + +#ifdef __cplusplus +} +#endif diff --git a/SourceX/miniwin/sdl1_wrapper.h b/SourceX/miniwin/sdl1_wrapper.h new file mode 100644 index 00000000000..fc7a413ee41 --- /dev/null +++ b/SourceX/miniwin/sdl1_wrapper.h @@ -0,0 +1,564 @@ +#ifndef __SDL1_WRAPPER_H +#define __SDL1_WRAPPER_H + +#include + +#define SDL_Keysym SDL_keysym +#define SDLK_KP_1 SDLK_KP1 +#define SDLK_KP_2 SDLK_KP2 +#define SDLK_KP_3 SDLK_KP3 +#define SDLK_KP_4 SDLK_KP4 +#define SDLK_KP_5 SDLK_KP5 +#define SDLK_KP_6 SDLK_KP6 +#define SDLK_KP_7 SDLK_KP7 +#define SDLK_KP_8 SDLK_KP8 +#define SDLK_KP_9 SDLK_KP9 +#define SDLK_KP_0 SDLK_KP0 +#define SDLK_PRINTSCREEN SDLK_PRINT +#define SDLK_SCROLLLOCK SDLK_SCROLLOCK +#define SDLK_NUMLOCKCLEAR SDLK_NUMLOCK +#define SDLK_KP_COMMA SDLK_COMMA +#define SDLK_LGUI SDLK_LSUPER +#define SDLK_RGUI SDLK_RSUPER +#define SDL_SCANCODE_LSHIFT SDLK_LSHIFT +#define SDL_SCANCODE_RSHIFT SDLK_RSHIFT +#define SDL_Keycode SDLKey + +#ifdef __AMIGA__ +#define D_SDL_MODES (SDL_SWSURFACE | SDL_FULLSCREEN) +#define D_BPP 8 +#else +#define D_SDL_MODES (SDL_SWSURFACE) +#define D_BPP 16 +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* + klaus + make sdl1_wrapper.h & .cpp + redefine sdl2 datatypes with sdl1 structs, + redefine sdl2 functions in sdl1 + and link the include to everywhere needed. + + + needed datatypes: + ---------------- + SDL_Window + SDL_Renderer + SDL_Texture + SDL_WindowUserData + SDL_WindowShaper + SDL_DisplayMode + SDL_HitTest + + + needed functions: + ----------------- + SDL_WarpMouseInWindow(window, X, Y); + SDL_RenderGetViewport(*renderer, SDL_Rect ); + SDL_RenderGetScale(*renderer, float, NULL ); + SDL_Log(SDL_GetError()); + SDL_SetWindowTitle(window, const *char); + */ +#define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF) /* 2147483647 */ +#define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */ +#define SDL_INIT_HAPTIC 0x00001000u + +#define SDL_RENDER_SCALE_QUALITY 0 + +#define SDL_HINT_RENDER_SCALE_QUALITY "SDL_RENDER_SCALE_QUALITY" + +#define SDL_WINDOWPOS_UNDEFINED_MASK 0x1FFF0000u + +#define SDL_WINDOWPOS_UNDEFINED_DISPLAY(X) (SDL_WINDOWPOS_UNDEFINED_MASK|(X)) + +#define SDL_WINDOWPOS_UNDEFINED SDL_WINDOWPOS_UNDEFINED_DISPLAY(0) + +/* Define a four character code as a Uint32 */ +#define SDL_FOURCC(A, B, C, D) \ + ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \ + (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \ + (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \ + (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24)) + +#define SDL_DEFINE_PIXELFOURCC(A, B, C, D) SDL_FOURCC(A, B, C, D) + +#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \ + ((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \ + ((bits) << 8) | ((bytes) << 0)) + +#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x))) + +#define SDL_TEXTINPUTEVENT_TEXT_SIZE (32) + + + +#define SDL_Renderer SDL_Surface +#define SDL_Texture SDL_Surface + +//klaus +// #define SDL_QueueAudio SDL_QueueAudio_REAL +#define SDL_QueueAudio 0 + +#define SDL_SCANCODE_RSHIFT 161 /* VirtualKey.RightShift -- */ +#define SDL_SCANCODE_LSHIFT 160 /* VirtualKey.LeftShift -- */ + + +typedef Uint32 SDL_AudioDeviceID; + +typedef enum +{ + SDL_RENDERER_SOFTWARE = 0x00000001, /**< The renderer is a software fallback */ + SDL_RENDERER_ACCELERATED = 0x00000002, /**< The renderer uses hardware acceleration */ + SDL_RENDERER_PRESENTVSYNC = 0x00000004, /**< Present is synchronized with the refresh rate */ + SDL_RENDERER_TARGETTEXTURE = 0x00000008 /**< The renderer supports rendering to texture */ +} SDL_RendererFlags; + +typedef enum +{ + /* !!! FIXME: change this to name = (1< #include +#if !SDL_VERSION_ATLEAST(2, 0, 0) +#include "sdl1_wrapper.h" +#endif +#include "../SourceS/miniwin/misc.h" namespace dvl { @@ -38,7 +42,11 @@ uintptr_t DVL_beginthreadex(void *_Security, unsigned _StackSize, unsigned (*_St func_translate *ft = new func_translate; ft->func = _StartAddress; ft->arg = _ArgList; +#if !SDL_VERSION_ATLEAST(2, 0, 0) + SDL_Thread *ret = SDL_CreateThread(thread_translate, NULL); +#else SDL_Thread *ret = SDL_CreateThread(thread_translate, NULL, ft); +#endif if (ret == NULL) { SDL_Log(SDL_GetError()); } diff --git a/SourceX/sound.cpp b/SourceX/sound.cpp index 951f060092b..cc21928d9f5 100644 --- a/SourceX/sound.cpp +++ b/SourceX/sound.cpp @@ -2,6 +2,9 @@ #include "stubs.h" #include #include +#if !SDL_VERSION_ATLEAST(2, 0, 0) +#include "miniwin/sdl1_wrapper.h" +#endif namespace dvl { @@ -494,7 +497,11 @@ void music_start(int nTrack) if (musicRw == NULL) { SDL_Log(SDL_GetError()); } +#if SDL_VERSION_ATLEAST(2, 0, 0) music = Mix_LoadMUS_RW(musicRw, 1); +#else + music = Mix_LoadMUS_RW(musicRw); +#endif Mix_VolumeMusic(MIX_MAX_VOLUME - MIX_MAX_VOLUME * sglMusicVolume / VOLUME_MIN); Mix_PlayMusic(music, -1); diff --git a/SourceX/storm/storm.cpp b/SourceX/storm/storm.cpp index 2047627b5ea..a1f0591cfd8 100644 --- a/SourceX/storm/storm.cpp +++ b/SourceX/storm/storm.cpp @@ -5,7 +5,11 @@ #include #include #include +#if !SDL_VERSION_ATLEAST(2, 0, 0) +#include "miniwin/sdl1_wrapper.h" +#endif #include +#include "../SourceS/miniwin/misc.h" #include "DiabloUI/diabloui.h" @@ -492,14 +496,14 @@ BOOL SVidPlayBegin(char *filename, int a2, int a3, int a4, int a5, int flags, HA audioFormat.channels = channels[0]; Mix_CloseAudio(); - deviceId = SDL_OpenAudioDevice(NULL, 0, &audioFormat, NULL, 0); - if (deviceId == 0) { - SDL_Log(SDL_GetError()); + //deviceId = SDL_OpenAudioDevice(NULL, 0, &audioFormat, NULL, 0); + //if (deviceId == 0) { + // SDL_Log(SDL_GetError()); SVidRestartMixer(); - return false; - } + // return false; + //} - SDL_PauseAudioDevice(deviceId, 0); /* start audio playing. */ + //SDL_PauseAudioDevice(deviceId, 0); /* start audio playing. */ } unsigned long nFrames; @@ -510,6 +514,7 @@ BOOL SVidPlayBegin(char *filename, int a2, int a3, int a4, int a5, int flags, HA smk_first(SVidSMK); // Decode first frame smk_info_video(SVidSMK, &SVidWidth, &SVidHeight, NULL); + if (renderer) { SDL_DestroyTexture(texture); texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, SVidWidth, SVidHeight); @@ -520,8 +525,13 @@ BOOL SVidPlayBegin(char *filename, int a2, int a3, int a4, int a5, int flags, HA SDL_Log(SDL_GetError()); } } + memcpy(SVidPreviousPalette, orig_palette, 1024); +#ifdef __AMIGA__ + surface = SDL_SetVideoMode(SVidWidth, SVidHeight, D_BPP, D_SDL_MODES); +#endif + // Copy frame to buffer SVidSurface = SDL_CreateRGBSurfaceWithFormatFrom( (unsigned char *)smk_get_video(SVidSMK), @@ -575,7 +585,11 @@ BOOL SVidPlayContinue(void) colors[i].r = palette_data[i * 3 + 0]; colors[i].g = palette_data[i * 3 + 1]; colors[i].b = palette_data[i * 3 + 2]; +#if !SDL_VERSION_ATLEAST(2, 0, 0) + colors[i].unused = SDL_ALPHA_OPAQUE; +#else colors[i].a = SDL_ALPHA_OPAQUE; +#endif orig_palette[i].peFlags = 0; orig_palette[i].peRed = palette_data[i * 3 + 0]; @@ -584,6 +598,11 @@ BOOL SVidPlayContinue(void) } memcpy(logical_palette, orig_palette, 1024); +#if !SDL_VERSION_ATLEAST(2, 0, 0) + //Todo(SDL1.2): Fix SDL_SetPaletteColors wrapper + SDL_SetPalette(SVidSurface, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256); + SDL_SetColors(surface, colors, 0, 256); +#endif if (SDL_SetPaletteColors(SVidPalette, colors, 0, 256) <= -1) { SDL_Log(SDL_GetError()); return false; @@ -594,10 +613,13 @@ BOOL SVidPlayContinue(void) return SVidLoadNextFrame(); // Skip video and audio if the system is to slow } + //klaus + /* if (deviceId && SDL_QueueAudio(deviceId, smk_get_audio(SVidSMK, 0), smk_get_audio_size(SVidSMK, 0)) <= -1) { SDL_Log(SDL_GetError()); return false; } + */ if (SDL_GetTicks() * 1000 >= SVidFrameEnd) { return SVidLoadNextFrame(); // Skip video if the system is to slow @@ -608,7 +630,9 @@ BOOL SVidPlayContinue(void) SDL_Log(SDL_GetError()); return false; } + } else { +#ifndef __AMIGA__ int factor; int wFactor = SCREEN_WIDTH / SVidWidth; int hFactor = SCREEN_HEIGHT / SVidHeight; @@ -623,11 +647,20 @@ BOOL SVidPlayContinue(void) SDL_Rect pal_surface_offset = { (SCREEN_WIDTH - scaledW) / 2, (SCREEN_HEIGHT - scaledH) / 2, scaledW, scaledH }; Uint32 format = SDL_GetWindowPixelFormat(window); SDL_Surface *tmp = SDL_ConvertSurfaceFormat(SVidSurface, format, 0); + if (SDL_BlitScaled(tmp, NULL, surface, &pal_surface_offset) <= -1) { SDL_Log(SDL_GetError()); return false; } +#else + SDL_Surface *tmp = SDL_ConvertSurfaceFormat(SVidSurface, 0, 0); + if (SDL_BlitSurface(tmp, NULL, surface, NULL) <= -1) { + SDL_Log(SDL_GetError()); + return false; + } +#endif SDL_FreeSurface(tmp); + } bufferUpdated = true; @@ -664,6 +697,10 @@ BOOL SVidPlayEnd(HANDLE video) SFileCloseFile(video); video = NULL; +#ifdef __AMIGA__ + surface = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, D_BPP, D_SDL_MODES); +#endif + memcpy(orig_palette, SVidPreviousPalette, 1024); if (renderer) { SDL_DestroyTexture(texture); diff --git a/SourceX/storm/storm_dx.cpp b/SourceX/storm/storm_dx.cpp index ad39141f7a3..e5400cfa654 100644 --- a/SourceX/storm/storm_dx.cpp +++ b/SourceX/storm/storm_dx.cpp @@ -32,11 +32,20 @@ BOOL SDrawUpdatePalette(unsigned int firstentry, unsigned int numentries, PALETT c->r = p->peRed; c->g = p->peGreen; c->b = p->peBlue; +#if !SDL_VERSION_ATLEAST(2, 0, 0) + c->unused = SDL_ALPHA_OPAQUE; +#else c->a = SDL_ALPHA_OPAQUE; +#endif } assert(palette); - if (SDL_SetPaletteColors(palette, colors, firstentry, numentries) <= -1) { +#if !SDL_VERSION_ATLEAST(2, 0, 0) + SDL_SetPalette(pal_surface, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256); + SDL_SetColors(surface, colors, 0, 256); +#endif + + if (SDL_SetPaletteColors(palette, colors, firstentry, numentries) <= -1) { // Todo(Amiga): Fix this! SDL_Log(SDL_GetError()); return false; } diff --git a/devilutionx.info b/devilutionx.info new file mode 100755 index 00000000000..61171e0b2b8 Binary files /dev/null and b/devilutionx.info differ