]> granicus.if.org Git - nethack/commitdiff
win32 USER_SOUNDS
authornethack.allison <nethack.allison>
Mon, 2 Sep 2002 23:28:54 +0000 (23:28 +0000)
committernethack.allison <nethack.allison>
Mon, 2 Sep 2002 23:28:54 +0000 (23:28 +0000)
This uses pmatch() as a default pattern matcher,
and #defines USER_SOUNDS_REGEX for Qt
to enable the code for regular expressions.

This is enabled for win32tty and win32gui.

include/config.h
include/ntconf.h
src/sounds.c
sys/winnt/Makefile.msc
sys/winnt/ntsound.c
win/tty/wintty.c
win/win32/mhmsgwnd.c
win/win32/nethackw.dsp

index 72d6088587beca92ce3961e4ead10f7bc078bd69..aff74d9103eec89d1d8738d967c8655efa3572ab 100644 (file)
@@ -85,6 +85,7 @@
 #ifdef QT_GRAPHICS
 # define DEFAULT_WC_TILED_MAP   /* Default to tiles if users doesn't say wc_ascii_map */
 # define USER_SOUNDS           /* Use sounds */
+# define USER_SOUNDS_REGEX
 # define USE_XPM               /* Use XPM format for images (required) */
 # define GRAPHIC_TOMBSTONE     /* Use graphical tombstone (rip.ppm) */
 # ifndef DEFAULT_WINDOW_SYS
index a002a6b539223059096af996eed1a8bdaa83de51..5995f69a249485d47b0391981ae3122f65cf6fe4 100644 (file)
@@ -23,6 +23,7 @@
 
 #define SELF_RECOVER           /* Allow the game itself to recover from an aborted game */
 
+#define USER_SOUNDS
 /*
  * -----------------------------------------------------------------
  *  The remaining code shouldn't need modification.
index fad33099bf31556822505067ec260e1b50a2a53c..d4e64f8eab5a27247c3d12ff4256c871f971719b 100644 (file)
@@ -5,7 +5,9 @@
 #include "hack.h"
 #include "edog.h"
 #ifdef USER_SOUNDS
+# ifdef USER_SOUNDS_REGEX
 #include <regex.h>
+# endif
 #endif
 
 #ifdef OVLB
@@ -923,7 +925,11 @@ dochat()
 extern void FDECL(play_usersound, (const char*, int));
 
 typedef struct audio_mapping_rec {
+#ifdef USER_SOUNDS_REGEX
        struct re_pattern_buffer regex;
+#else
+       char *pattern;
+#endif
        char *filename;
        int volume;
        struct audio_mapping_rec *next;
@@ -956,17 +962,25 @@ const char *mapping;
 
            if (can_read_file(filespec)) {
                new_map = (audio_mapping *)alloc(sizeof(audio_mapping));
+#ifdef USER_SOUNDS_REGEX
                new_map->regex.translate = 0;
                new_map->regex.fastmap = 0;
                new_map->regex.buffer = 0;
                new_map->regex.allocated = 0;
                new_map->regex.regs_allocated = REGS_FIXED;
+#else
+               new_map->pattern = (char *)alloc(strlen(text) + 1);
+               Strcpy(new_map->pattern, text);
+#endif
                new_map->filename = strdup(filespec);
                new_map->volume = volume;
                new_map->next = soundmap;
 
+#ifdef USER_SOUNDS_REGEX
                err = re_compile_pattern(text, strlen(text), &new_map->regex);
-
+#else
+               err = 0;
+#endif
                if (err) {
                    raw_print(err);
                    free(new_map->filename);
@@ -995,7 +1009,11 @@ const char* msg;
        audio_mapping* cursor = soundmap;
 
        while (cursor) {
+#ifdef USER_SOUNDS_REGEX
            if (re_search(&cursor->regex, msg, strlen(msg), 0, 9999, 0) >= 0) {
+#else
+           if (pmatch(cursor->pattern, msg)) {
+#endif
                play_usersound(cursor->filename, cursor->volume);
            }
            cursor = cursor->next;
index 9487894f24cadf4de59ac6fc585a6a48d0cb2cc6..debfac99f0b27c3212b05e090fda6e69ed129bd1 100644 (file)
@@ -162,7 +162,7 @@ TILEBMP16   = $(SRC)\tiles.bmp
 TILEUTIL32  = $(UTIL)\til2bm32.exe
 TILEBMP32   = $(SRC)\tiles32.bmp
 
-#SOUND = $(OBJ)\ntsound.o
+SOUND = $(OBJ)\ntsound.o
 
 #SOUND =
 
@@ -573,7 +573,7 @@ $(NHRES): $(NTSYS)\console.rc $(NTSYS)\NetHack.ico
 $(GAMEFILE) : $(ALLOBJ) $(NHRES)
        @if not exist $(GAMEDIR)\*.* mkdir $(GAMEDIR)
        @echo Linking....
-       $(link) $(LFLAGS) user32.lib -out:$@ @<<$(GAME).lnk
+       $(link) $(LFLAGS) user32.lib winmm.lib -out:$@ @<<$(GAME).lnk
                $(ALLOBJ:^      =^
                ) $(NHRES)
 <<
index 1b4803bc61f688b3096a0d59a1690faf63408cce..fae368aa147ab7ec6c6aa83205c72f0a88baa6e6 100644 (file)
  */
 
 #include "hack.h"
+#include "win32api.h"
+#include <mmsystem.h>
 
+#ifdef USER_SOUNDS
+
+void play_usersound(filename, volume)
+const char* filename;
+int volume;
+{
+/*    pline("play_usersound: %s (%d).", filename, volume); */
+       (void)sndPlaySound(filename, SND_ASYNC | SND_NODEFAULT);
+}
+
+#endif /*USER_SOUNDS*/
 /* ntsound.c */
index a0a064a09a43aae64e27e166cd5611d837269114..8990483e1bdf21d0722ffd2f8d7c2d3efe5896ba 100644 (file)
@@ -1761,6 +1761,9 @@ tty_putstr(window, attr, str)
     switch(cw->type) {
     case NHW_MESSAGE:
        /* really do this later */
+#if defined(USER_SOUNDS) && defined(WIN32CON)
+       play_sound_for_message(str);
+#endif
        update_topl(str);
        break;
 
index eaab2777710779a17f8ccccf4ec4c00257d64e09..ed6447bc4723e2af3e18d35524da17a0e8e52616 100644 (file)
@@ -18,8 +18,6 @@
 
 #define MORE "--More--"
 
-
-
 struct window_line {
        int  attr;
        char text[MAXWINDOWTEXT];
@@ -61,6 +59,10 @@ static COLORREF setMsgTextColor(HDC hdc, int gray);
 static void onPaint(HWND hWnd);
 static void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam);
 
+#ifdef USER_SOUNDS
+extern void play_sound_for_message(const char* str);
+#endif
+
 HWND mswin_init_message_window () {
        static int run_once = 0;
        HWND ret;
@@ -242,6 +244,10 @@ void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
 
                /* update window content */
                InvalidateRect(hWnd, NULL, TRUE);
+
+#ifdef USER_SOUNDS
+               play_sound_for_message(msg_data->text);
+#endif
        }
        break;
 
index ed0d73da34ab69ee7dd7cb6ee5e9ad1877679f1e..b6fc6ae1623fd537806019a4ca61179d6b42d614 100644 (file)
@@ -54,7 +54,7 @@ BSC32=bscmake.exe
 # ADD BSC32 /nologo
 LINK32=link.exe
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib comctl32.lib advapi32.lib /nologo /subsystem:windows /map /debug /machine:I386 /MAPINFO:EXPORTS /MAPINFO:LINES
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib comctl32.lib advapi32.lib winmm.lib /nologo /subsystem:windows /map /debug /machine:I386 /MAPINFO:EXPORTS /MAPINFO:LINES
 # SUBTRACT LINK32 /pdb:none
 # Begin Special Build Tool
 OutDir=.\Release
@@ -95,7 +95,7 @@ BSC32=bscmake.exe
 # ADD BSC32 /nologo
 LINK32=link.exe
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib comctl32.lib advapi32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib comctl32.lib advapi32.lib winmm.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
 # Begin Special Build Tool
 OutDir=.\Debug
 SOURCE="$(InputPath)"
@@ -358,6 +358,10 @@ SOURCE=..\src\music.c
 # End Source File
 # Begin Source File
 
+SOURCE=..\sys\winnt\ntsound.c
+# End Source File
+# Begin Source File
 SOURCE=..\src\o_init.c
 # End Source File
 # Begin Source File