Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change #6173: Update SDL driver to use SDL 2.0 #7086

Merged
merged 1 commit into from Sep 19, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -751,7 +751,7 @@ check_params() {
log 1 "checking GDI video driver... not Windows, skipping"
fi

if [ -z "$allegro_config" ] && [ -z "$sdl_config" ] && [ "$with_cocoa" = 0 ] && [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ]; then
if [ -z "$allegro_config" ] && [ -z "$sdl2_config" ] && [ -z "$sdl_config" ] && [ "$with_cocoa" = 0 ] && [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ]; then
log 1 "configure: error: no video driver development files found"
log 1 " If you want a dedicated server use --enable-dedicated as parameter"
exit 1
@@ -1629,7 +1629,16 @@ make_cflags_and_ldflags() {
fi
fi

if [ -n "$sdl_config" ]; then
if [ -n "$sdl2_config" ]; then
CFLAGS="$CFLAGS -DWITH_SDL2"
# SDL must not add _GNU_SOURCE as it breaks many platforms
CFLAGS="$CFLAGS `$sdl2_config --cflags | sed 's@-D_GNU_SOURCE[^ ]*@@'`"
if [ "$enable_static" != "0" ]; then
LIBS="$LIBS `$sdl2_config --static --libs`"
else
LIBS="$LIBS `$sdl2_config --libs`"
fi
elif [ -n "$sdl_config" ]; then
CFLAGS="$CFLAGS -DWITH_SDL"
# SDL must not add _GNU_SOURCE as it breaks many platforms
CFLAGS="$CFLAGS `$sdl_config --cflags | sed 's@-D_GNU_SOURCE[^ ]*@@'`"
@@ -2426,7 +2435,13 @@ detect_sdl() {
sleep 5
fi

detect_pkg_config "$with_sdl" "sdl" "sdl_config" "1.2"
if [ $with_sdl = "sdl1" ]; then
detect_pkg_config "2" "sdl" "sdl_config" "1.2"
elif [ $with_sdl = "sdl2" ] || [ -x `which sdl2-config` ]; then
detect_pkg_config "2" "sdl2" "sdl2_config" "2.0"
else
detect_pkg_config "$with_sdl" "sdl" "sdl_config" "1.2"
fi
}

detect_osx_sdk() {
@@ -3496,7 +3511,7 @@ showhelp() {
echo " --with-allegro[=\"pkg-config allegro\"]"
echo " enables Allegro video driver support"
echo " --with-cocoa enables COCOA video driver (OSX ONLY)"
echo " --with-sdl[=\"pkg-config sdl\"] enables SDL video driver support"
echo " --with-sdl[=\"sdl1|sdl2\"] enables SDL video driver support"
echo " --with-zlib[=\"pkg-config zlib\"]"
echo " enables zlib support"
echo " --with-liblzma[=\"pkg-config liblzma\"]"
@@ -110,6 +110,7 @@ AWKCOMMAND='
if ($0 == "ALLEGRO" && "'$allegro_config'" == "") { next; }
if ($0 == "SDL" && "'$sdl_config'" == "") { next; }
if ($0 == "SDL2" && "'$sdl2_config'" == "") { next; }
if ($0 == "PNG" && "'$png_config'" == "") { next; }
if ($0 == "OSX" && "'$os'" != "OSX") { next; }
if ($0 == "OS2" && "'$os'" != "OS2") { next; }
@@ -3,7 +3,7 @@ Section: games
Priority: optional
Maintainer: Matthijs Kooijman <matthijs@stdin.nl>
Uploaders: Jordi Mallach <jordi@debian.org>
Build-Depends: debhelper (>= 7.0.50), libsdl-dev, zlib1g-dev, libpng-dev, libfreetype6-dev, libfontconfig-dev, libicu-dev, liblzma-dev, liblzo2-dev
Build-Depends: debhelper (>= 7.0.50), libsdl2-dev, zlib1g-dev, libpng-dev, libfreetype6-dev, libfontconfig-dev, libicu-dev, liblzma-dev, liblzo2-dev
Standards-Version: 3.8.4
Vcs-Browser: http://anonscm.debian.org/gitweb/?p=collab-maint/openttd.git
Vcs-Git: git://anonscm.debian.org/collab-maint/openttd.git
@@ -91,7 +91,7 @@ Group: Amusements/Games/Strategy/Other
Requires: %{name}
Conflicts: %{name}-dedicated

BuildRequires: SDL-devel
BuildRequires: SDL2-devel
BuildRequires: fontconfig-devel

%if 0%{?rhel_version} != 600
@@ -314,6 +314,7 @@ safeguards.h
screenshot.h
sound/sdl_s.h
video/sdl_v.h
video/sdl2_v.h
settings_func.h
settings_gui.h
settings_internal.h
@@ -1097,6 +1098,9 @@ video/null_v.cpp
#if SDL
video/sdl_v.cpp
#end
#if SDL2
video/sdl2_v.cpp
#end
#if WIN32
video/win32_v.cpp
#end
@@ -1139,6 +1143,9 @@ sound/null_s.cpp
#if SDL
sound/sdl_s.cpp
#end
#if SDL2
sound/sdl2_s.cpp
#end
#if WIN32
sound/win32_s.cpp
#if USE_XAUDIO2
@@ -61,9 +61,9 @@
#ifdef WITH_LZO
#include <lzo/lzo1x.h>
#endif
#ifdef WITH_SDL
#if defined(WITH_SDL) || defined(WITH_SDL2)
# include <SDL.h>
#endif /* WITH_SDL */
#endif /* WITH_SDL || WITH_SDL2 */
#ifdef WITH_ZLIB
# include <zlib.h>
#endif
@@ -267,9 +267,13 @@ char *CrashLog::LogLibraries(char *buffer, const char *last) const
#endif /* WITH_PNG */

#ifdef WITH_SDL
const SDL_version *v = SDL_Linked_Version();
buffer += seprintf(buffer, last, " SDL: %d.%d.%d\n", v->major, v->minor, v->patch);
#endif /* WITH_SDL */
const SDL_version *sdl_v = SDL_Linked_Version();
buffer += seprintf(buffer, last, " SDL1: %d.%d.%d\n", sdl_v->major, sdl_v->minor, sdl_v->patch);
#elif defined(WITH_SDL2)
SDL_version sdl2_v;
SDL_GetVersion(&sdl2_v);
buffer += seprintf(buffer, last, " SDL2: %d.%d.%d\n", sdl2_v.major, sdl2_v.minor, sdl2_v.patch);
#endif

#ifdef WITH_ZLIB
buffer += seprintf(buffer, last, " Zlib: %s\n", zlibVersion());
@@ -0,0 +1,70 @@
/* $Id$ */

/*
* This file is part of OpenTTD.
* OpenTTD 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, version 2.
* OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/

/** @file sdl2_s.cpp Playing sound via SDL2. */

#ifdef WITH_SDL2

#include "../stdafx.h"

#include "../mixer.h"
#include "sdl_s.h"
#include <SDL.h>

#include "../safeguards.h"

/** Factory for the SDL sound driver. */
static FSoundDriver_SDL iFSoundDriver_SDL;

/**
* Callback that fills the sound buffer.
* @param userdata Ignored.
* @param stream The stream to put data into.
* @param len The length of the stream in bytes.
*/
static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len)
{
MxMixSamples(stream, len / 4);
}

const char *SoundDriver_SDL::Start(const char * const *parm)
{
SDL_AudioSpec spec;
SDL_AudioSpec spec_actual;

/* Only initialise SDL if the video driver hasn't done it already */
int ret_code = 0;
if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
ret_code = SDL_Init(SDL_INIT_AUDIO);
} else if (SDL_WasInit(SDL_INIT_AUDIO) == 0) {
ret_code = SDL_InitSubSystem(SDL_INIT_AUDIO);
}
if (ret_code == -1) return SDL_GetError();

spec.freq = GetDriverParamInt(parm, "hz", 44100);
spec.format = AUDIO_S16SYS;
spec.channels = 2;
spec.samples = GetDriverParamInt(parm, "samples", 1024);
spec.callback = fill_sound_buffer;
SDL_AudioDeviceID dev = SDL_OpenAudioDevice(nullptr, 0, &spec, &spec_actual, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE);
MxInitialize(spec_actual.freq);
SDL_PauseAudioDevice(dev, 0);
return nullptr;
}

void SoundDriver_SDL::Stop()
{
SDL_CloseAudio();
SDL_QuitSubSystem(SDL_INIT_AUDIO);
if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
SDL_Quit(); // If there's nothing left, quit SDL
}
}

#endif /* WITH_SDL2 */
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.