From: nethack.allison Date: Mon, 2 Sep 2002 23:28:54 +0000 (+0000) Subject: win32 USER_SOUNDS X-Git-Tag: MOVE2GIT~2443 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6bebdbb135b5ed9e95514917395f42cee0889e06;p=nethack win32 USER_SOUNDS 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. --- diff --git a/include/config.h b/include/config.h index 72d608858..aff74d910 100644 --- a/include/config.h +++ b/include/config.h @@ -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 diff --git a/include/ntconf.h b/include/ntconf.h index a002a6b53..5995f69a2 100644 --- a/include/ntconf.h +++ b/include/ntconf.h @@ -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. diff --git a/src/sounds.c b/src/sounds.c index fad33099b..d4e64f8ea 100644 --- a/src/sounds.c +++ b/src/sounds.c @@ -5,7 +5,9 @@ #include "hack.h" #include "edog.h" #ifdef USER_SOUNDS +# ifdef USER_SOUNDS_REGEX #include +# 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; diff --git a/sys/winnt/Makefile.msc b/sys/winnt/Makefile.msc index 9487894f2..debfac99f 100644 --- a/sys/winnt/Makefile.msc +++ b/sys/winnt/Makefile.msc @@ -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) << diff --git a/sys/winnt/ntsound.c b/sys/winnt/ntsound.c index 1b4803bc6..fae368aa1 100644 --- a/sys/winnt/ntsound.c +++ b/sys/winnt/ntsound.c @@ -11,5 +11,18 @@ */ #include "hack.h" +#include "win32api.h" +#include +#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 */ diff --git a/win/tty/wintty.c b/win/tty/wintty.c index a0a064a09..8990483e1 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -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; diff --git a/win/win32/mhmsgwnd.c b/win/win32/mhmsgwnd.c index eaab27777..ed6447bc4 100644 --- a/win/win32/mhmsgwnd.c +++ b/win/win32/mhmsgwnd.c @@ -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; diff --git a/win/win32/nethackw.dsp b/win/win32/nethackw.dsp index ed0d73da3..b6fc6ae16 100644 --- a/win/win32/nethackw.dsp +++ b/win/win32/nethackw.dsp @@ -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