Ticket #2041: 0001-First-pass-at-SDL2-support.patch

File 0001-First-pass-at-SDL2-support.patch, 8.2 KB (added by julian37, 10 years ago)

Patch against r14495 to build with SDL2 (2.0.1)

  • build/premake/extern_libs4.lua

    From c3aa34bb4703940b88c7045b8cb033feccbd6202 Mon Sep 17 00:00:00 2001
    From: Julian Scheid <julians37@gmail.com>
    Date: Sat, 4 Jan 2014 13:42:40 +0100
    Subject: [PATCH] First pass at SDL2 support
    
    ---
     build/premake/extern_libs4.lua                     |  6 ++--
     build/workspaces/update-workspaces.sh              |  2 +-
     libraries/osx/build-osx-libs.sh                    |  6 ++--
     source/gui/CInput.cpp                              |  4 +++
     source/gui/scripting/GuiScriptConversions.cpp      |  6 +++-
     source/ps/CConsole.cpp                             | 34 +++++++++++++++++++++-
     source/ps/Hotkey.cpp                               |  4 +--
     .../atlas/GameInterface/Handlers/MiscHandlers.cpp  |  4 +--
     8 files changed, 52 insertions(+), 14 deletions(-)
    
    diff --git a/build/premake/extern_libs4.lua b/build/premake/extern_libs4.lua
    index 5b67a06..c0ead69 100644
    a b extern_lib_defs = {  
    535535    sdl = {
    536536        compile_settings = function()
    537537            if os.is("windows") then
    538                 includedirs { libraries_dir .. "sdl/include/SDL" }
     538                includedirs { libraries_dir .. "sdl/include/SDL2" }
    539539            elseif not _OPTIONS["android"] then
    540540                -- Support SDL_CONFIG for overriding for the default PATH-based sdl-config
    541541                sdl_config_path = os.getenv("SDL_CONFIG")
    542542                if not sdl_config_path then
    543                     sdl_config_path = "sdl-config"
     543                    sdl_config_path = "sdl2-config"
    544544                end
    545545
    546546                -- "pkg-config sdl --libs" appears to include both static and dynamic libs
    extern_lib_defs = {  
    554554            elseif not _OPTIONS["android"] then
    555555                sdl_config_path = os.getenv("SDL_CONFIG")
    556556                if not sdl_config_path then
    557                     sdl_config_path = "sdl-config"
     557                    sdl_config_path = "sdl2-config"
    558558                end
    559559                pkgconfig_libs(nil, sdl_config_path.." --libs")
    560560            end
  • build/workspaces/update-workspaces.sh

    diff --git a/build/workspaces/update-workspaces.sh b/build/workspaces/update-workspaces.sh
    index 092755b..94ec490 100755
    a b cd "$(dirname $0)"  
    6767if [ "`uname -s`" = "Darwin" ]; then
    6868  # Set *_CONFIG variables on OS X, to override the path to e.g. sdl-config
    6969  export GLOOX_CONFIG=${GLOOX_CONFIG:="$(pwd)/../../libraries/osx/gloox/bin/gloox-config"}
    70   export SDL_CONFIG=${SDL_CONFIG:="$(pwd)/../../libraries/osx/sdl/bin/sdl-config"}
     70  export SDL_CONFIG=${SDL_CONFIG:="$(pwd)/../../libraries/osx/sdl/bin/sdl2-config"}
    7171  export WX_CONFIG=${WX_CONFIG:="$(pwd)/../../libraries/osx/wxwidgets/bin/wx-config"}
    7272  export XML2_CONFIG=${XML2_CONFIG:="$(pwd)/../../libraries/osx/libxml2/bin/xml2-config"}
    7373fi
  • libraries/osx/build-osx-libs.sh

    diff --git a/libraries/osx/build-osx-libs.sh b/libraries/osx/build-osx-libs.sh
    index 8efcc9d..def77e2 100755
    a b CURL_VERSION="curl-7.32.0"  
    2525ICONV_VERSION="libiconv-1.14"
    2626XML2_VERSION="libxml2-2.9.1"
    2727# * SDL 1.2.15+ required for Lion support
    28 SDL_VERSION="SDL-1.2.15"
     28SDL_VERSION="SDL2-2.0.1"
    2929BOOST_VERSION="boost_1_52_0"
    3030# * wxWidgets 2.9+ is necessary for 64-bit OS X build w/ OpenGL support
    3131WXWIDGETS_VERSION="wxWidgets-3.0.0"
    then  
    277277  pushd $LIB_DIRECTORY
    278278
    279279
    280   # patch SDL to fix Mavericks build (fixed upstream, see https://bugzilla.libsdl.org/show_bug.cgi?id=2085 )
    281   # Don't use X11 - we don't need it and Mountain Lion removed it
    282   (patch -p0 -i ../../patches/sdl-mavericks-quartz-fix.diff && ./configure CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" --prefix="$INSTALL_DIR" --without-x --enable-shared=no && make $JOBS && make install) || die "SDL build failed"
     280  (./configure CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" --prefix="$INSTALL_DIR" --without-x --enable-shared=no && make $JOBS && make install) || die "SDL build failed"
    283281  popd
    284282  touch .already-built
    285283else
  • source/gui/CInput.cpp

    diff --git a/source/gui/CInput.cpp b/source/gui/CInput.cpp
    index af9fed8..850787e 100644
    a b InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)  
    9393        bool shiftKeyPressed = g_keys[SDLK_RSHIFT] || g_keys[SDLK_LSHIFT];
    9494
    9595        int szChar = ev->ev.key.keysym.sym;
     96#if SDL_VERSION_ATLEAST(2, 0, 0)
     97        wchar_t cooked = (wchar_t)ev->ev.key.keysym.sym;
     98#else
    9699        wchar_t cooked = (wchar_t)ev->ev.key.keysym.unicode;
     100#endif
    97101
    98102        switch (szChar)
    99103        {
  • source/gui/scripting/GuiScriptConversions.cpp

    diff --git a/source/gui/scripting/GuiScriptConversions.cpp b/source/gui/scripting/GuiScriptConversions.cpp
    index 93c2600..130e3f8 100644
    a b template<> jsval ScriptInterface::ToJSVal<SDL_Event_>(JSContext* cx, SDL_Event_  
    8484        // SET(keysym, "scancode", (int)val.ev.key.keysym.scancode); // (not in wsdl.h)
    8585        SET(keysym, "sym", (int)val.ev.key.keysym.sym);
    8686        // SET(keysym, "mod", (int)val.ev.key.keysym.mod); // (not in wsdl.h)
    87         if (val.ev.key.keysym.unicode)
     87        if (val.ev.key.keysym.sym)
    8888        {
     89#if SDL_VERSION_ATLEAST(2, 0, 0)
     90            std::wstring unicode(1, (wchar_t)val.ev.key.keysym.sym);
     91#else
    8992            std::wstring unicode(1, (wchar_t)val.ev.key.keysym.unicode);
     93#endif
    9094            SET(keysym, "unicode", unicode);
    9195        }
    9296        else
  • source/ps/CConsole.cpp

    diff --git a/source/ps/CConsole.cpp b/source/ps/CConsole.cpp
    index ccdb61a..f01fcba 100644
    a b static bool isUnprintableChar(SDL_keysym key)  
    669669#endif
    670670{
    671671    // U+0000 to U+001F are control characters
    672     if (key.unicode < 0x20)
     672    if (key.sym < 0x20)
    673673    {
    674674        switch (key.sym)
    675675        {
    InReaction conInputHandler(const SDL_Event_* ev)  
    724724    if (!g_Console->IsActive())
    725725        return IN_PASS;
    726726
     727#if SDL_VERSION_ATLEAST(2, 0, 0)
     728
     729    if (ev->ev.type == SDL_TEXTINPUT) {
     730        if (!HotkeyIsPressed("console.toggle")) {
     731            CStr bytes (ev->ev.text.text, strlen(ev->ev.text.text));
     732            CStrW str (bytes.FromUTF8());
     733            for (CStrW::const_iterator it = str.begin(); it != str.end(); ++it) {
     734                wchar_t chr = *it;
     735                g_Console->InsertChar(0, (wchar_t)chr);
     736            }
     737        }
     738        return IN_HANDLED;
     739    }
     740    else if (ev->ev.type == SDL_KEYDOWN) {
     741        int sym = ev->ev.key.keysym.sym;
     742        // Stop unprintable characters (ctrl+, alt+ and escape),
     743        // also prevent ` and/or ~ appearing in console every time it's toggled.
     744        if (!isUnprintableChar(ev->ev.key.keysym) && !HotkeyIsPressed("console.toggle")) {
     745            g_Console->InsertChar(sym, 0);
     746            return IN_HANDLED;
     747        }
     748        else {
     749            return IN_PASS;
     750        }
     751    }
     752    else {
     753        return IN_PASS;
     754    }
     755
     756#else // SDL 1.2:
     757
    727758    if (ev->ev.type != SDL_KEYDOWN)
    728759        return IN_PASS;
    729760
    InReaction conInputHandler(const SDL_Event_* ev)  
    739770    }
    740771
    741772    return IN_PASS;
     773#endif
    742774}
  • source/ps/Hotkey.cpp

    diff --git a/source/ps/Hotkey.cpp b/source/ps/Hotkey.cpp
    index b89133d..ab18f7e 100644
    a b InReaction HotkeyInputHandler( const SDL_Event_* ev )  
    227227
    228228    // Rather ugly hack to make the '"' key work better on a MacBook Pro on Windows so it doesn't
    229229    // always close the console. (Maybe this would be better handled in wsdl or something?)
    230     if (keycode == SDLK_BACKQUOTE && (ev->ev.key.keysym.unicode == '\'' || ev->ev.key.keysym.unicode == '"'))
    231         keycode = ev->ev.key.keysym.unicode;
     230    if (keycode == SDLK_BACKQUOTE && (ev->ev.key.keysym.sym == '\'' || ev->ev.key.keysym.sym == '"'))
     231        keycode = ev->ev.key.keysym.sym;
    232232
    233233    // Somewhat hackish:
    234234    // Create phantom 'unified-modifier' events when left- or right- modifier keys are pressed
  • source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp

    diff --git a/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp
    index 161ba47..e82fb9e 100644
    a b MESSAGEHANDLER(GuiKeyEvent)  
    189189    ev.ev.key.keysym.sym = (SDL_Keycode)(int)msg->sdlkey;
    190190#else
    191191    ev.ev.key.keysym.sym = (SDLKey)(int)msg->sdlkey;
    192 #endif
    193192    ev.ev.key.keysym.unicode = msg->unichar;
     193#endif
    194194    in_dispatch_event(&ev);
    195195}
    196196
    MESSAGEHANDLER(GuiCharEvent)  
    206206    ev.ev.key.keysym.sym = (SDL_Keycode)(int)msg->sdlkey;
    207207#else
    208208    ev.ev.key.keysym.sym = (SDLKey)(int)msg->sdlkey;
    209 #endif
    210209    ev.ev.key.keysym.unicode = msg->unichar;
     210#endif
    211211    in_dispatch_event(&ev);
    212212
    213213    ev.ev.type = SDL_KEYUP;