From 1a28393dabf4f4696bf433ddde52e7a25253c955 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 16 Oct 2008 16:34:15 +0000 Subject: various user interface related updates --- src/audio/audio.cc | 19 +++++++++++++++---- src/audio/audio.h | 3 +++ src/audio/buffers.cc | 8 +++++++- src/audio/buffers.h | 1 + src/audio/sources.cc | 15 ++++++++++++++- src/audio/sources.h | 1 + 6 files changed, 41 insertions(+), 6 deletions(-) (limited to 'src/audio') diff --git a/src/audio/audio.cc b/src/audio/audio.cc index 81a260c..ca30590 100644 --- a/src/audio/audio.cc +++ b/src/audio/audio.cc @@ -18,13 +18,13 @@ ALCcontext *audio_context = 0; void init() { - con_print << "^BInitializing audio..."; + con_print << "^BInitializing audio..." << std::endl; // open the default audio device audio_device = alcOpenDevice(0); if (!audio_device) { - con_warn << "Could not initialize audio!"; + con_warn << "Could not initialize audio!" << std::endl; return; } @@ -34,7 +34,7 @@ void init() if (!audio_context) { alcCloseDevice(audio_device); audio_device = 0; - con_warn << "Could not create audio context!"; + con_warn << "Could not create audio context!" << std::endl; return; } @@ -56,6 +56,17 @@ void init() load("ui/console"); } +void reset() +{ + con_print << "^BReloading audio..." << std::endl; + + Sources::reset(); + Buffers::reset(); + + load("ui/nosnd"); + load("ui/console"); +} + void load (const char *name) { Buffers::load(std::string(name)); @@ -63,7 +74,7 @@ void load (const char *name) void shutdown() { - con_print << "^BShutting down audio..."; + con_print << "^BShutting down audio..." << std::endl; Sources::shutdown(); diff --git a/src/audio/audio.h b/src/audio/audio.h index c0479d3..930edaf 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -29,6 +29,9 @@ void init(); /// shut down the audio subsystem void shutdown(); +/// reload audio +void reset(); + /// load an audio sample void load(const char *name); diff --git a/src/audio/buffers.cc b/src/audio/buffers.cc index af14cb1..33c4dbf 100644 --- a/src/audio/buffers.cc +++ b/src/audio/buffers.cc @@ -25,7 +25,7 @@ void Buffers::init() alGenBuffers(MAXBUFFERS, buffers); if ((error = alGetError()) != AL_NO_ERROR) { - con_warn << "Error " << std::hex << error << " initializing OpenAL buffers!" << std::endl; + con_warn << "Error " << error << " initializing OpenAL buffers!" << std::endl; return; } } @@ -44,6 +44,12 @@ void Buffers::clear() index = 0; } +void Buffers::reset() +{ + shutdown(); + init(); +} + size_t Buffers::load(std::string name) { // check if it is already loaded diff --git a/src/audio/buffers.h b/src/audio/buffers.h index cc7a6c8..462afff 100644 --- a/src/audio/buffers.h +++ b/src/audio/buffers.h @@ -23,6 +23,7 @@ class Buffers { public: static void init(); static void shutdown(); + static void reset(); /// find previously loaded PCM data static size_t find(std::string name); diff --git a/src/audio/sources.cc b/src/audio/sources.cc index 584f366..01fbafb 100644 --- a/src/audio/sources.cc +++ b/src/audio/sources.cc @@ -23,7 +23,7 @@ void Sources::init() alGenSources(MAXSOURCES, sources); if ((error = alGetError()) != AL_NO_ERROR) { - con_warn << "Error " << std::hex << error << " initializing OpenAL sources!" << std::endl; + con_warn << "Error " << error << " initializing OpenAL sources!" << std::endl; return; } @@ -55,6 +55,19 @@ void Sources::clear() } +void Sources::reset() +{ + for (size_t index= 0; index < MAXSOURCES; index++) { + source_available[index] = true; + alSourceRewind(sources[index]); + } + + // reserve ui sound sources + for (size_t i=0; i < MAXUISOURCES; i++) { + source_available[i] = false; + } +} + size_t Sources::get() { for (size_t i= MAXUISOURCES; i < MAXSOURCES; i++) { diff --git a/src/audio/sources.h b/src/audio/sources.h index 078c424..f01e7a4 100644 --- a/src/audio/sources.h +++ b/src/audio/sources.h @@ -23,6 +23,7 @@ class Sources { public: static void init(); static void shutdown(); + static void reset(); static inline bool available(size_t index) { return source_available[index]; } -- cgit v1.2.3