tAdd sound support on Mac - vaccinewars - be a doctor and try to vaccinate the … | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 81bdbf0ebfdca35cfde80dcc3a70911446234feb | |
parent c6c0df719bf603a7547cc1f85c1179957d96344b | |
Author: Ben Webb <[email protected]> | |
Date: Tue, 3 Nov 2020 23:24:33 -0800 | |
Add sound support on Mac | |
Add a new sound driver which uses the native | |
Cocoa libraries on Mac OS to play sounds. | |
This requires an Objective C compiler. | |
Diffstat: | |
M ChangeLog | 1 + | |
M configure.ac | 25 +++++++++++++++++++++++++ | |
M src/plugins/Makefile.am | 12 ++++++++++-- | |
A src/plugins/sound_cocoa.m | 70 +++++++++++++++++++++++++++++… | |
M src/sound.c | 6 ++++++ | |
5 files changed, 112 insertions(+), 2 deletions(-) | |
--- | |
diff --git a/ChangeLog b/ChangeLog | |
t@@ -14,6 +14,7 @@ SVN | |
and MetaServer.UseSocks are removed (set the https_proxy environment | |
variable instead, as per | |
https://curl.haxx.se/libcurl/c/libcurl-tutorial.html#Environment) | |
+ - Add sound support on Mac. | |
- Fix for a DOS against the server using the REQUESTJET message type | |
(thanks to Doug Prostko for reporting the problem). | |
diff --git a/configure.ac b/configure.ac | |
t@@ -58,8 +58,13 @@ AC_ARG_WITH(sdl, | |
[ --without-sdl do not support SDL sound output], | |
[ USE_SDL="$withval" ], [ USE_SDL="probe" ]) | |
+AC_ARG_WITH(cocoa, | |
+[ --without-cocoa do not support Cocoa (Mac) sound output], | |
+[ USE_COCOA="$withval" ], [ USE_COCOA="probe" ]) | |
+ | |
ESD=no | |
SDL=no | |
+COCOA=no | |
dnl Test for Cygwin environment | |
AC_CYGWIN | |
t@@ -194,6 +199,25 @@ else | |
fi | |
fi | |
+ dnl Add Cocoa (Mac) sound support if available | |
+ if test "$USE_COCOA" != "no"; then | |
+ AC_PROG_OBJC | |
+ if test "x$OBJC" != "x"; then | |
+ AC_LANG_PUSH([Objective C]) | |
+ AC_CHECK_HEADERS(AppKit/AppKit.h, [HAVE_APPKIT="1"], [HAVE_APPKIT="0"]) | |
+ AC_LANG_POP() | |
+ if test "x$HAVE_APPKIT" = "x1"; then | |
+ COCOA="yes" | |
+ PLUGOBJS="$PLUGOBJS plugins/sound_cocoa.o" | |
+ AC_DEFINE(HAVE_COCOA, 1, [Do we have the Cocoa sound library?]) | |
+ else | |
+ AC_MSG_ERROR([Cannot find AppKit.h, needed for Cocoa (Mac) sound]) | |
+ fi | |
+ else | |
+ AC_MSG_ERROR([Cannot find Cocoa (Mac) sound library]) | |
+ fi | |
+ fi | |
+ | |
dnl Use console server by default | |
if test "$GUI_SERVER" = "probe"; then | |
GUI_SERVER="no" | |
t@@ -211,6 +235,7 @@ fi | |
AM_CONDITIONAL(ESD, test "$ESD" = "yes") | |
AM_CONDITIONAL(SDL, test "$SDL" = "yes") | |
+AM_CONDITIONAL(COCOA, test "$COCOA" = "yes") | |
dnl If probing was unsuccessful, these will be set to "no"; therefore, | |
dnl if still set to "probe" then everything worked, so set to "yes" | |
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am | |
t@@ -1,9 +1,11 @@ | |
-noinst_LTLIBRARIES = libsound_esd.la libsound_sdl.la libsound_winmm.la | |
+noinst_LTLIBRARIES = libsound_esd.la libsound_sdl.la libsound_winmm.la libsoun… | |
libsound_esd_la_SOURCES = sound_esd.c sound_esd.h | |
libsound_esd_la_LDFLAGS = @ESD_LIBS@ | |
libsound_sdl_la_SOURCES = sound_sdl.c sound_sdl.h | |
libsound_sdl_la_LDFLAGS = @SDL_LIBS@ | |
libsound_winmm_la_SOURCES = sound_winmm.c sound_winmm.h | |
+libsound_cocoa_la_LDFLAGS = -module -avoid-version -no-undefined -Wl,-framewor… | |
+libsound_cocoa_la_SOURCES = sound_cocoa.m | |
LIBS = @GLIB_LIBS@ | |
AM_CPPFLAGS = @SOUND_CFLAGS@ @GLIB_CFLAGS@ | |
LINKNOO = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) | |
t@@ -16,7 +18,10 @@ endif | |
if SDL | |
SDL_SO = .libs/libsound_sdl.so | |
endif | |
-PLUGINS = $(ESD_SO) $(SDL_SO) | |
+if COCOA | |
+COCOA_SO = .libs/libsound_cocoa.so | |
+endif | |
+PLUGINS = $(ESD_SO) $(SDL_SO) $(COCOA_SO) | |
all-local: ${PLUGINS} | |
t@@ -29,6 +34,9 @@ all-local: ${PLUGINS} | |
.libs/libsound_winmm.so: $(libsound_winmm_la_OBJECTS) | |
$(LINKNOO) -o libsound_winmm.la -rpath $(libdir) $(libsound_winmm_la_L… | |
+.libs/libsound_cocoa.so: $(libsound_cocoa_la_OBJECTS) | |
+ $(LINKNOO) -o libsound_cocoa.la -rpath $(libdir) $(libsound_cocoa_la_L… | |
+ | |
install-exec-am: | |
${mkinstalldirs} ${PLUGINDIR} | |
for plug in ${PLUGINS}; do \ | |
diff --git a/src/plugins/sound_cocoa.m b/src/plugins/sound_cocoa.m | |
t@@ -0,0 +1,70 @@ | |
+/************************************************************************ | |
+ * sound_cocoa.m Implementation of dopewars sound system (Cocoa driver)* | |
+ * Copyright (C) 1998-2020 Ben Webb * | |
+ * Email: [email protected] * | |
+ * WWW: https://dopewars.sourceforge.io/ * | |
+ * * | |
+ * This program 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 2 * | |
+ * of the License, or (at your option) any later version. * | |
+ * * | |
+ * This program 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 this program; if not, write to the Free Software * | |
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * | |
+ * MA 02111-1307, USA. * | |
+ ************************************************************************/ | |
+ | |
+#ifdef HAVE_CONFIG_H | |
+#include <config.h> | |
+#endif | |
+ | |
+#ifdef HAVE_COCOA | |
+#include <glib.h> | |
+#include "../sound.h" | |
+ | |
+#import <Foundation/Foundation.h> | |
+#import <AppKit/AppKit.h> | |
+ | |
+/* Cache player by name of sound file */ | |
+NSMutableDictionary *play_by_name; | |
+ | |
+static gboolean SoundOpen_Cocoa(void) | |
+{ | |
+ play_by_name = [[NSMutableDictionary alloc] init]; | |
+ return TRUE; | |
+} | |
+ | |
+static void SoundClose_Cocoa(void) | |
+{ | |
+ [play_by_name release]; | |
+} | |
+ | |
+static void SoundPlay_Cocoa(const gchar *snd) | |
+{ | |
+ NSString *sound = [[NSString alloc] initWithUTF8String:snd]; | |
+ NSSound *p; | |
+ p = [play_by_name objectForKey:sound]; | |
+ if (!p) { | |
+ p = [[NSSound alloc] initWithContentsOfFile:sound byReference:YES]; | |
+ [play_by_name setObject:p forKey:sound]; | |
+ } | |
+ [p play]; | |
+} | |
+ | |
+SoundDriver *sound_cocoa_init(void) | |
+{ | |
+ static SoundDriver driver; | |
+ | |
+ driver.name = "cocoa"; | |
+ driver.open = SoundOpen_Cocoa; | |
+ driver.close = SoundClose_Cocoa; | |
+ driver.play = SoundPlay_Cocoa; | |
+ return &driver; | |
+} | |
+#endif | |
diff --git a/src/sound.c b/src/sound.c | |
t@@ -35,6 +35,9 @@ | |
#include "plugins/sound_sdl.h" | |
#include "plugins/sound_esd.h" | |
#include "plugins/sound_winmm.h" | |
+#ifdef HAVE_COCOA | |
+SoundDriver *sound_cocoa_init(void); | |
+#endif | |
#endif | |
#include "dopewars.h" | |
t@@ -155,6 +158,9 @@ void SoundInit(void) | |
#ifdef HAVE_WINMM | |
AddPlugin(sound_winmm_init, NULL); | |
#endif | |
+#ifdef HAVE_COCOA | |
+ AddPlugin(sound_cocoa_init, NULL); | |
+#endif | |
#endif | |
driver = NULL; | |
} |