From 1afa3712fb6e1b50668a1d673a5957fe03ad90ef Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Mon, 22 Aug 2005 18:29:47 +0000 Subject: [PATCH] Cope with failing to initialize the sound system. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3683 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/openal/BlankSound.java | 38 +++++++++++++++++++ .../com/threerings/openal/SoundGroup.java | 12 +++++- .../com/threerings/openal/SoundManager.java | 8 ++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/java/com/threerings/openal/BlankSound.java diff --git a/src/java/com/threerings/openal/BlankSound.java b/src/java/com/threerings/openal/BlankSound.java new file mode 100644 index 000000000..977744281 --- /dev/null +++ b/src/java/com/threerings/openal/BlankSound.java @@ -0,0 +1,38 @@ +// +// $Id$ +// +// Narya library - tools for developing networked games +// Copyright (C) 2002-2005 Three Rings Design, Inc., All Rights Reserved +// http://www.threerings.net/code/narya/ +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.threerings.openal; + +/** + * A blank sound used when we cannot initialize the sound system. + */ +public class BlankSound extends Sound +{ + protected BlankSound () + { + super(null, null); + } + + protected boolean play (boolean allowDefer, boolean loop) + { + return false; // nothing doing + } +} diff --git a/src/java/com/threerings/openal/SoundGroup.java b/src/java/com/threerings/openal/SoundGroup.java index 2ffed3f08..feae3c89b 100644 --- a/src/java/com/threerings/openal/SoundGroup.java +++ b/src/java/com/threerings/openal/SoundGroup.java @@ -48,7 +48,11 @@ public class SoundGroup */ public Sound getSound (String path) { - return new Sound(this, _manager.getClip(_provider, path)); + if (_manager.isInitialized()) { + return new Sound(this, _manager.getClip(_provider, path)); + } else { + return new BlankSound(); + } } /** @@ -67,6 +71,12 @@ public class SoundGroup _manager = manager; _provider = provider; + // if we were unable to initialize the sound system at all, just + // stop here and we'll behave as if we have no available sources + if (!_manager.isInitialized()) { + return; + } + // create our sources _sourceIds = BufferUtils.createIntBuffer(sources); AL10.alGenSources(_sourceIds); diff --git a/src/java/com/threerings/openal/SoundManager.java b/src/java/com/threerings/openal/SoundManager.java index f561bf269..059d0a97b 100644 --- a/src/java/com/threerings/openal/SoundManager.java +++ b/src/java/com/threerings/openal/SoundManager.java @@ -69,6 +69,14 @@ public class SoundManager return _soundmgr; } + /** + * Returns true if we were able to initialize the sound system. + */ + public boolean isInitialized () + { + return (_toLoad != null); + } + /** * Configures the size of our sound cache. If this value is larger * than memory available to the underlying sound system, it will be