Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add audio and text narration #211

Draft
wants to merge 1 commit into
base: release
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ifeq ($(GRAPHICS),YES)
sources += $(addprefix src/platform/,sdl2-platform.c)
cflags += $(shell $(SDL_CONFIG) --cflags)
cppflags += -DBROGUE_SDL
libs += $(shell $(SDL_CONFIG) --libs) -lSDL2_image
libs += $(shell $(SDL_CONFIG) --libs) -lSDL2_image -lespeak-ng
endif

ifeq ($(WEBBROGUE),YES)
Expand Down
2 changes: 2 additions & 0 deletions src/brogue/MainMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ void titleMenu() {
initializeMenuFlames(true, colors, colorStorage, colorSources, flames, mask);
rogue.creaturesWillFlashThisTurn = false; // total unconscionable hack

playSpeech("Welcome to Brogue!");

do {
if (isApplicationActive()) {
// Revert the display.
Expand Down
1 change: 1 addition & 0 deletions src/brogue/Rogue.h
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,7 @@ extern "C" {
void notifyEvent(short eventId, int data1, int data2, const char *str1, const char *str2);
boolean takeScreenshot();
boolean setGraphicsEnabled(boolean);
void playSpeech(char *text);
boolean controlKeyIsDown();
boolean shiftKeyIsDown();
short getHighScoresList(rogueHighScoresEntry returnList[HIGH_SCORES_COUNT]);
Expand Down
2 changes: 2 additions & 0 deletions src/platform/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ struct brogueConsole {
very start of the program, even before .gameLoop, to set the initial value.
*/
boolean (*setGraphicsEnabled)(boolean);

void (*playSpeech)();
};

// defined in platform
Expand Down
6 changes: 6 additions & 0 deletions src/platform/platformdependent.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ boolean setGraphicsEnabled(boolean state) {
}
}

void playSpeech(char *text) {
if (currentConsole.playSpeech) {
currentConsole.playSpeech(text);
}
}

// creates an empty high scores file
void initScores() {
short i;
Expand Down
16 changes: 15 additions & 1 deletion src/platform/sdl2-platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <SDL.h>
#include <SDL_image.h>
#include <espeak-ng/speak_lib.h>

#include "platform.h"

Expand Down Expand Up @@ -230,6 +231,16 @@ static char applyRemaps(char c) {
}


static boolean audioInit() {
return espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, NULL, 0) != -1;
}


static void _playSpeech(char *text) {
espeak_Synth(text, strlen(text), 0, 0, 0, espeakCHARS_UTF8, NULL, NULL);
}


/*
If an event is available, returns true and updates returnEvent. Otherwise
it returns false and an error event. This function also processes
Expand Down Expand Up @@ -366,6 +377,8 @@ static void _gameLoop() {

if (!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG)) imgfatal();

audioInit();

lastEvent.eventType = EVENT_ERROR;

if (brogueFontSize == 0) {
Expand Down Expand Up @@ -559,5 +572,6 @@ struct brogueConsole sdlConsole = {
_modifierHeld,
NULL,
_takeScreenshot,
_setGraphicsEnabled
_setGraphicsEnabled,
.playSpeech = _playSpeech
};