From: Matthias Braun Date: Sun, 14 May 2006 19:35:43 +0000 (+0000) Subject: somre sound preloading X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=8e724da15bbc4945cf02620b125e1b20622c5e09;p=supertux.git somre sound preloading SVN-Revision: 3520 --- diff --git a/src/audio/sound_manager.cpp b/src/audio/sound_manager.cpp index 0576fe6ba..fd1be4f6f 100644 --- a/src/audio/sound_manager.cpp +++ b/src/audio/sound_manager.cpp @@ -16,6 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include #include "sound_manager.hpp" @@ -138,6 +139,26 @@ SoundManager::create_sound_source(const std::string& filename) } void +SoundManager::preload(const std::string& filename) +{ + if(!sound_enabled) + return; + + SoundBuffers::iterator i = buffers.find(filename); + // already loaded? + if(i != buffers.end()) + return; + + std::auto_ptr file (load_sound_file(filename)); + // only keep small files + if(file->size >= 100000) + return; + + ALuint buffer = load_file_into_buffer(file.get()); + buffers.insert(std::make_pair(filename, buffer)); +} + +void SoundManager::play(const std::string& filename, const Vector& pos) { try { diff --git a/src/audio/sound_manager.hpp b/src/audio/sound_manager.hpp index c87f89013..88f2437f2 100644 --- a/src/audio/sound_manager.hpp +++ b/src/audio/sound_manager.hpp @@ -51,6 +51,8 @@ public: */ void play(const std::string& name, const Vector& pos = Vector(-1, -1)); void play_and_delete(SoundSource* source); + /// preloads a sound, so that you don't get a lag later when playing it + void preload(const std::string& name); void set_listener_position(const Vector& position); void set_listener_velocity(const Vector& velocity); diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index 51d5fd936..8718b1918 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -16,7 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - #include #include "badguy.hpp" @@ -37,12 +36,18 @@ BadGuy::BadGuy(const Vector& pos, const std::string& sprite_name, int layer) : MovingSprite(pos, sprite_name, layer, COLGROUP_DISABLED), countMe(true), dir(LEFT), state(STATE_INIT) { start_position = bbox.p1; + + sound_manager->preload("sounds/squish.wav"); + sound_manager->preload("sounds/fall.wav"); } BadGuy::BadGuy(const lisp::Lisp& reader, const std::string& sprite_name, int layer) : MovingSprite(reader, sprite_name, layer, COLGROUP_DISABLED), countMe(true), dir(LEFT), state(STATE_INIT) { start_position = bbox.p1; + + sound_manager->preload("sounds/squish.wav"); + sound_manager->preload("sounds/fall.wav"); } void diff --git a/src/object/player.cpp b/src/object/player.cpp index eefc7bb3f..f9efddf07 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -109,6 +109,11 @@ Player::Player(PlayerStatus* _player_status) smalltux_star = sprite_manager->create("images/creatures/tux_small/smalltux-star.sprite"); bigtux_star = sprite_manager->create("images/creatures/tux_big/bigtux-star.sprite"); + sound_manager->preload("sounds/bigjump.wav"); + sound_manager->preload("sounds/jump.wav"); + sound_manager->preload("sounds/hurt.wav"); + sound_manager->preload("sounds/skid.wav"); + init(); }