From 8eb661461c3a176897b4a7572ae96d48d29c1f13 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sat, 24 May 2014 16:52:43 +0300 Subject: [PATCH] - vcmi compiles with SDL2 on Linux, video player is disabled for now --- CMakeLists.txt | 25 +++++++++++++++++++++---- Global.h | 2 ++ client/CMT.cpp | 2 +- client/CVideoHandler.cpp | 2 ++ client/CVideoHandler.h | 2 +- client/gui/CGuiHandler.cpp | 2 +- lib/VCMIDirs.cpp | 1 + 7 files changed, 29 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 420bf163c..e848deff7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ option(ENABLE_EDITOR "Enable compilation of map editor" OFF) option(ENABLE_LAUNCHER "Enable compilation of launcher" ON) option(ENABLE_TEST "Enable compilation of unit tests" OFF) option(ENABLE_PCH "Enable compilation using precompiled headers" ON) +option(ENABLE_SDL2 "Use SDL2 for compilation instead of SDL 1.2" ON) ############################################ # Building section # @@ -54,11 +55,27 @@ if (APPLE) endif() find_package(Boost 1.48.0 COMPONENTS program_options filesystem system thread locale REQUIRED) -find_package(SDL REQUIRED) -find_package(SDL_image REQUIRED) -find_package(SDL_mixer REQUIRED) -find_package(SDL_ttf REQUIRED) find_package(ZLIB REQUIRED) + +if (ENABLE_SDL2) + include (FindPkgConfig) + pkg_search_module(SDL REQUIRED sdl2) + pkg_search_module(SDL_TTF REQUIRED SDL2_ttf) + pkg_search_module(SDL_IMAGE REQUIRED SDL2_image) + pkg_search_module(SDL_MIXER REQUIRED SDL2_mixer) + + #This is weird - SDL defines singular variables while pkg_search defines plural + set(SDL_INCLUDE_DIR "${SDL_INCLUDE_DIRS}") + set(SDL_LIBRARY "${SDL_LIBRARIES}") + set(SDLTTF_LIBRARY "${SDL_TTF_LIBRARIES}") + set(SDLIMAGE_LIBRARY "${SDL_IMAGE_LIBRARIES}") + set(SDLMIXER_LIBRARY "${SDL_MIXER_LIBRARIES}") +else() + find_package(SDL REQUIRED) + find_package(SDL_image REQUIRED) + find_package(SDL_mixer REQUIRED) + find_package(SDL_ttf REQUIRED) +endif() include(cotire) if (ENABLE_EDITOR OR ENABLE_LAUNCHER) diff --git a/Global.h b/Global.h index 3802796ef..a9702ae63 100644 --- a/Global.h +++ b/Global.h @@ -16,6 +16,8 @@ // Fixed width bool data type is important for serialization static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size."); +# define DISABLE_VIDEO + #if defined _M_X64 && defined _WIN32 //Win64 -> cannot load 32-bit DLLs for video handling # define DISABLE_VIDEO #endif diff --git a/client/CMT.cpp b/client/CMT.cpp index 311100cc9..e8dddaac7 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -390,7 +390,7 @@ int main(int argc, char** argv) CCS = new CClientState; CGI = new CGameInfo; //contains all global informations about game (texts, lodHandlers, map handler etc.) // Initialize video -#if DISABLE_VIDEO +#ifdef DISABLE_VIDEO CCS->videoh = new CEmptyVideoPlayer; #else if (!gNoGUI && !vm.count("disable-video")) diff --git a/client/CVideoHandler.cpp b/client/CVideoHandler.cpp index ceae0d58b..dae7389e2 100644 --- a/client/CVideoHandler.cpp +++ b/client/CVideoHandler.cpp @@ -9,6 +9,7 @@ extern CGuiHandler GH; //global gui handler +#ifndef DISABLE_VIDEO //reads events and returns true on key down static bool keyDown() { @@ -20,6 +21,7 @@ static bool keyDown() } return false; } +#endif #if defined(_WIN32) && (_MSC_VER < 1800 || !defined(USE_FFMPEG)) diff --git a/client/CVideoHandler.h b/client/CVideoHandler.h index 216faa027..48b6c6201 100644 --- a/client/CVideoHandler.h +++ b/client/CVideoHandler.h @@ -221,7 +221,7 @@ public: #include #include -#if SDL_VERSION_ATLEAST(1,3,0) +#if SDL_VERSION_ATLEAST(1,3,0) && !SDL_VERSION_ATLEAST(2,0,0) #include #endif diff --git a/client/gui/CGuiHandler.cpp b/client/gui/CGuiHandler.cpp index bd4bae284..07873bd9c 100644 --- a/client/gui/CGuiHandler.cpp +++ b/client/gui/CGuiHandler.cpp @@ -285,7 +285,7 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent) #endif } #ifndef VCMI_SDL1 //SDL2x only events - else if ((sEvent->type == SDL_MOUSEWHEEL)) + else if (sEvent->type == SDL_MOUSEWHEEL) { std::list hlp = wheelInterested; for(auto i=hlp.begin(); i != hlp.end() && current; i++) diff --git a/lib/VCMIDirs.cpp b/lib/VCMIDirs.cpp index 35c6ad47c..07abe5c92 100644 --- a/lib/VCMIDirs.cpp +++ b/lib/VCMIDirs.cpp @@ -222,6 +222,7 @@ std::vector VCMIDirs::dataPaths() const { std::string dataDirsEnv = getenv("XDG_DATA_DIRS"); std::vector dataDirs; + std::cout << dataDirsEnv; boost::split(dataDirs, dataDirsEnv, boost::is_any_of(":")); for (auto & entry : boost::adaptors::reverse(dataDirs)) ret.push_back(entry + "/vcmi");