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.
This commit is contained in:
nethack.allison
2002-09-02 23:28:54 +00:00
parent 0cb3b8543b
commit 6bebdbb135
8 changed files with 53 additions and 7 deletions

View 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

View 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.

View 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;

View 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)
<<

View File

@@ -11,5 +11,18 @@
*/
#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 */

View 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;

View 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;

View 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