Skip to content

Commit e7ff7ef

Browse files
committed
enum for speech priority and flags for blocking speech
1 parent a413c69 commit e7ff7ef

10 files changed

+69
-25
lines changed

Makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ ifeq ($(GRAPHICS),YES)
2424
sources += $(addprefix src/platform/,sdl2-platform.c tiles.c)
2525
cflags += $(shell $(SDL_CONFIG) --cflags)
2626
cppflags += -DBROGUE_SDL
27-
libs += $(shell $(SDL_CONFIG) --libs) -lSDL2_image
27+
libs += $(shell $(SDL_CONFIG) --libs) -lSDL2_image -lespeak-ng
2828
endif
2929

3030
ifeq ($(SPEECH),YES)
3131
cppflags += -DBROGUE_SPEECH
32-
libs += -lespeak-ng
3332
endif
3433

3534
ifeq ($(WEBBROGUE),YES)

config.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ SDL_CONFIG := sdl2-config
1313
WEBBROGUE := NO
1414

1515
# Add TTS. Requires GRAPHICS for now, just to add SDL.
16-
SPEECH := YES
16+
SPEECH := NO
1717

1818
# Enable debugging mode. See top of Rogue.h for features
19-
DEBUG := NO
19+
DEBUG := YES
2020

2121
# Declare this is a release build
2222
RELEASE := NO

src/brogue/IO.c

+10-7
Original file line numberDiff line numberDiff line change
@@ -2690,6 +2690,9 @@ void executeKeystroke(signed long keystroke, boolean controlKey, boolean shiftKe
26902690
gameOver("Quit", true);
26912691
}
26922692
break;
2693+
case TTS_TOGGLE_KEY:
2694+
toggleTTS();
2695+
break;
26932696
case GRAPHICS_KEY:
26942697
if (hasGraphics) {
26952698
graphicsMode = setGraphicsMode((graphicsMode + 1) % 3);
@@ -2974,8 +2977,8 @@ boolean confirm(char *prompt, boolean alsoDuringPlayback) {
29742977
return true; // oh yes he did
29752978
}
29762979

2977-
playSpeech(prompt, 3);
2978-
playSpeech("Yes... No", 3);
2980+
playSpeech(prompt, THREE_SPEECH, SPEECH_BLOCKS);
2981+
playSpeech("Yes... No", THREE_SPEECH, 0);
29792982

29802983
encodeMessageColor(whiteColorEscape, 0, &white);
29812984
encodeMessageColor(yellowColorEscape, 0, KEYBOARD_LABELS ? &yellow : &white);
@@ -3441,17 +3444,17 @@ void temporaryMessage(const char *msg, enum messageFlags flags) {
34413444
}
34423445
restoreRNG;
34433446

3444-
playSpeech(msg, 1);
3447+
playSpeech(msg, ONE_SPEECH, 0);
34453448
}
34463449

3447-
void messageWithColor(char *msg, color *theColor, enum messageFlags flags, short speechPriority) {
3450+
void messageWithColor(char *msg, color *theColor, enum messageFlags flags, enum speechPriority priority) {
34483451
char buf[COLS*2] = "";
34493452
short i;
34503453

34513454
i=0;
34523455
i = encodeMessageColor(buf, i, theColor);
34533456
strcpy(&(buf[i]), msg);
3454-
message(buf, flags, speechPriority);
3457+
message(buf, flags, priority);
34553458
}
34563459

34573460
void flavorMessage(char *msg) {
@@ -3479,7 +3482,7 @@ void flavorMessage(char *msg) {
34793482
// arrived on the same turn, they may collapse. Alternately, they may collapse
34803483
// if the older message is the latest one in the archive and the new one is not
34813484
// semi-colon foldable (such as a combat message.)
3482-
void message(const char *msg, enum messageFlags flags, short speechPriority) {
3485+
void message(const char *msg, enum messageFlags flags, enum speechPriority priority) {
34833486
short i;
34843487
archivedMessage *archiveEntry;
34853488
boolean newMessage;
@@ -3549,7 +3552,7 @@ void message(const char *msg, enum messageFlags flags, short speechPriority) {
35493552

35503553
restoreRNG;
35513554

3552-
playSpeech(msg, speechPriority);
3555+
playSpeech(msg, priority, 0);
35533556
}
35543557

35553558
// Only used for the "you die..." message, to enable posthumous inventory viewing.

src/brogue/Items.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2958,7 +2958,7 @@ char displayInventory(unsigned short categoryMask,
29582958

29592959
overlayDisplayBuffer(dbuf, NULL);
29602960

2961-
playSpeech(buttons[highlightItemLine].text, 3);
2961+
playSpeech(buttons[highlightItemLine].text, THREE_SPEECH, 0);
29622962

29632963
//buttons[highlightItemLine].buttonColor = interfaceBoxColor;
29642964
drawButton(&(buttons[highlightItemLine]), BUTTON_PRESSED, NULL);

src/brogue/MainMenu.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ void titleMenu() {
344344
initializeMenuFlames(true, colors, colorStorage, colorSources, flames, mask);
345345
rogue.creaturesWillFlashThisTurn = false; // total unconscionable hack
346346

347-
playSpeech("Welcome to Brogue!", 1);
347+
playSpeech("Welcome to Brogue!", ONE_SPEECH, 0);
348348

349349
do {
350350
if (isApplicationActive()) {

src/brogue/Movement.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ void speakLocation(char *locationDescription, short x, short y) {
405405
strcat(locationMessage, posY);
406406
strcat(locationMessage, posX);
407407

408-
playSpeech(locationMessage, 0);
408+
playSpeech(locationMessage, ZERO_SPEECH, 0);
409409
}
410410

411411
void printLocationDescription(short x, short y) {

src/brogue/Rogue.h

+18-3
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,18 @@ enum graphicsModes {
325325
HYBRID_GRAPHICS, // text for items and creatures, tiles for environment
326326
};
327327

328+
enum speechPriority {
329+
NO_SPEECH,
330+
ZERO_SPEECH,
331+
ONE_SPEECH,
332+
TWO_SPEECH,
333+
THREE_SPEECH
334+
};
335+
336+
enum TTSFlags {
337+
SPEECH_BLOCKS = Fl(0),
338+
};
339+
328340
enum eventTypes {
329341
KEYSTROKE,
330342
MOUSE_UP,
@@ -357,6 +369,7 @@ typedef struct rogueEvent {
357369

358370
typedef struct speechData {
359371
short priority;
372+
unsigned long flags;
360373
char message[DCOLS];
361374
} speechData;
362375

@@ -1160,6 +1173,7 @@ enum tileFlags {
11601173
#define AUTOPLAY_KEY 'A'
11611174
#define SEED_KEY '~'
11621175
#define EASY_MODE_KEY '&'
1176+
#define TTS_TOGGLE_KEY '!'
11631177
#define ESCAPE_KEY '\033'
11641178
#define RETURN_KEY '\012'
11651179
#define DELETE_KEY '\177'
@@ -2750,8 +2764,9 @@ extern "C" {
27502764
void nextKeyOrMouseEvent(rogueEvent *returnEvent, boolean textInput, boolean colorsDance);
27512765
void notifyEvent(short eventId, int data1, int data2, const char *str1, const char *str2);
27522766
boolean takeScreenshot();
2767+
void toggleTTS();
27532768
enum graphicsModes setGraphicsMode(enum graphicsModes mode);
2754-
void playSpeech(char *text, short priority);
2769+
void playSpeech(char *text, enum speechPriority priority, unsigned long flags);
27552770
boolean controlKeyIsDown();
27562771
boolean shiftKeyIsDown();
27572772
short getHighScoresList(rogueHighScoresEntry returnList[HIGH_SCORES_COUNT]);
@@ -2924,9 +2939,9 @@ extern "C" {
29242939
void displayRecentMessages();
29252940
void displayMessageArchive();
29262941
void temporaryMessage(const char *msg1, enum messageFlags flags);
2927-
void messageWithColor(char *msg, color *theColor, enum messageFlags flags, short speechPriority);
2942+
void messageWithColor(char *msg, color *theColor, enum messageFlags flags, enum speechPriority priority);
29282943
void flavorMessage(char *msg);
2929-
void message(const char *msg, enum messageFlags flags, short speechPriority);
2944+
void message(const char *msg, enum messageFlags flags, enum speechPriority priority);
29302945
void displayMoreSignWithoutWaitingForAcknowledgment();
29312946
void displayMoreSign();
29322947
short encodeMessageColor(char *msg, short i, const color *theColor);

src/platform/platform.h

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ struct brogueConsole {
8484
*/
8585
enum graphicsModes (*setGraphicsMode)(enum graphicsModes mode);
8686
void (*playSpeech)();
87+
boolean (*toggleTTS)();
8788
};
8889

8990
// defined in platform

src/platform/platformdependent.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,15 @@ enum graphicsModes setGraphicsMode(enum graphicsModes mode) {
267267
}
268268
}
269269

270-
void playSpeech(char *text, short priority) {
270+
void toggleTTS() {
271+
if (currentConsole.toggleTTS) {
272+
currentConsole.toggleTTS();
273+
}
274+
}
275+
276+
void playSpeech(char *text, enum speechPriority priority, unsigned long flags) {
271277
if (currentConsole.playSpeech) {
272-
currentConsole.playSpeech(text, priority);
278+
currentConsole.playSpeech(text, priority, flags);
273279
}
274280
}
275281

src/platform/sdl2-platform.c

+26-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ static struct keypair remapping[MAX_REMAPS];
2121
static size_t nremaps = 0;
2222
static enum graphicsModes showGraphics = TEXT_GRAPHICS;
2323

24+
#ifdef BROGUE_SPEECH
25+
static boolean useTTS = true;
26+
#else
27+
static boolean useTTS = false;
28+
#endif
29+
2430
static rogueEvent lastEvent;
2531
static speechData lastSpeech;
2632

@@ -152,20 +158,25 @@ static boolean audioInit() {
152158

153159
static void _playSpeech(
154160
char *text,
155-
short priority
161+
enum speechPriority priority,
162+
unsigned long flags
156163
) {
157-
if (priority >= lastSpeech.priority) {
158-
espeak_Cancel();
159-
} else {
164+
if (!useTTS) {
165+
return;
166+
}
167+
if (lastSpeech.flags & SPEECH_BLOCKS) {
160168
espeak_Synchronize();
169+
} else if (priority >= lastSpeech.priority) {
170+
espeak_Cancel();
161171
}
162172
// remove any escape codes from the text
163173
int i, j;
164174
char sanitizedMessage[90] = "";
175+
color white;
165176
for(i = 0, j = 0; i < strlen(text); i++)
166177
{
167-
while (text[i] == COLOR_ESCAPE) {
168-
i += 4;
178+
if (text[i] == COLOR_ESCAPE) {
179+
i = decodeMessageColor(text, i, &white);
169180
}
170181

171182
if(i >= strlen(text)) {
@@ -187,6 +198,7 @@ static void _playSpeech(
187198
);
188199
// TODO: mark interruptable messages with unique_identifier
189200
lastSpeech.priority = priority;
201+
lastSpeech.flags = flags;
190202
}
191203

192204

@@ -474,6 +486,13 @@ static enum graphicsModes _setGraphicsMode(enum graphicsModes mode) {
474486
return mode;
475487
}
476488

489+
static boolean _toggleTTS() {
490+
useTTS = !useTTS;
491+
if (useTTS) {
492+
playSpeech("Speech enabled", ZERO_SPEECH, 0);
493+
}
494+
}
495+
477496

478497
struct brogueConsole sdlConsole = {
479498
_gameLoop,
@@ -485,5 +504,6 @@ struct brogueConsole sdlConsole = {
485504
NULL,
486505
_takeScreenshot,
487506
_setGraphicsMode,
507+
.toggleTTS = _toggleTTS,
488508
.playSpeech = _playSpeech
489509
};

0 commit comments

Comments
 (0)