-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e358a7
commit d630ce9
Showing
3 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* xoreos - A reimplementation of BioWare's Aurora engine | ||
* | ||
* xoreos is the legal property of its developers, whose names | ||
* can be found in the AUTHORS file distributed with this source | ||
* distribution. | ||
* | ||
* xoreos is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 3 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* xoreos 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with xoreos. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** @file | ||
* An ingame sound in kotor. | ||
*/ | ||
|
||
#include "src/aurora/resman.h" | ||
#include "src/aurora/gff3file.h" | ||
|
||
#include "src/sound/sound.h" | ||
|
||
#include "src/engines/aurora/util.h" | ||
|
||
#include "src/engines/kotor/sound.h" | ||
|
||
namespace Engines { | ||
|
||
namespace KotOR { | ||
|
||
SoundObject::SoundObject(const Aurora::GFF3Struct &sound) { | ||
Common::UString temp = sound.getString("TemplateResRef"); | ||
|
||
Common::ScopedPtr<Aurora::GFF3File> uts; | ||
if (!temp.empty()) | ||
uts.reset(loadOptionalGFF3(temp, Aurora::kFileTypeUTS, MKTAG('U', 'T', 'S', ' '))); | ||
|
||
if (!uts) | ||
throw Common::Exception("Sound \"%s\" has no blueprint", _tag.c_str()); | ||
|
||
const Aurora::GFF3Struct &gff = uts->getTopLevel(); | ||
|
||
Aurora::GFF3List soundFileList = gff.getList("Sounds"); | ||
for (Aurora::GFF3List::const_iterator c = soundFileList.begin(); c != soundFileList.end(); ++c) { | ||
_soundFiles.push_back((*c)->getString("Sound")); | ||
} | ||
|
||
_looping = gff.getBool("Looping"); | ||
_positional = gff.getBool("Positional"); | ||
_random = gff.getBool("Random"); | ||
|
||
_interval = gff.getUint("Interval"); | ||
|
||
// TODO: Investigate how kotor handles randomness of sounds. | ||
Common::UString soundFile = _soundFiles[0]; | ||
if (_random) | ||
soundFile = _soundFiles[std::rand() % _soundFiles.size()]; | ||
|
||
Common::SeekableReadStream *soundStream = ResMan.getResource(Aurora::kResourceSound, soundFile); | ||
|
||
_sound = SoundMan.playSoundFile(soundStream, Sound::kSoundTypeSFX, _looping); | ||
|
||
_name = gff.getString("Tag"); | ||
|
||
if (gff.getBool("Active")) { | ||
play(); | ||
} | ||
|
||
setPosition( | ||
static_cast<float>(sound.getDouble("XPosition")), | ||
static_cast<float>(sound.getDouble("YPosition")), | ||
static_cast<float>(sound.getDouble("ZPosition")) | ||
); | ||
|
||
SoundMan.setChannelGain(_sound, static_cast<float>(gff.getUint("Volume"))/100.0f); | ||
} | ||
|
||
void SoundObject::setPosition(float x, float y, float z) { | ||
Object::setPosition(x, y, z); | ||
|
||
if (_positional) | ||
SoundMan.setChannelPosition(_sound, x, y, z); | ||
} | ||
|
||
void SoundObject::play() { | ||
SoundMan.startChannel(_sound); | ||
} | ||
|
||
void SoundObject::stop() { | ||
SoundMan.stopChannel(_sound); | ||
} | ||
|
||
} // End of namespace KotOR | ||
|
||
} // End of namespace Engines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* xoreos - A reimplementation of BioWare's Aurora engine | ||
* | ||
* xoreos is the legal property of its developers, whose names | ||
* can be found in the AUTHORS file distributed with this source | ||
* distribution. | ||
* | ||
* xoreos is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 3 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* xoreos 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with xoreos. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** @file | ||
* An ingame sound in kotor. | ||
*/ | ||
|
||
#ifndef ENGINES_KOTOR_SOUND_H | ||
#define ENGINES_KOTOR_SOUND_H | ||
|
||
#include "src/events/timerman.h" | ||
|
||
#include "src/engines/kotor/object.h" | ||
|
||
namespace Engines { | ||
|
||
namespace KotOR { | ||
|
||
class SoundObject : public Object { | ||
public: | ||
SoundObject(const Aurora::GFF3Struct &sound); | ||
|
||
void setPosition(float x, float y, float z); | ||
|
||
void play(); | ||
void stop(); | ||
|
||
private: | ||
bool _positional; | ||
bool _looping; | ||
bool _random; | ||
|
||
unsigned int _interval; | ||
|
||
std::vector<Common::UString> _soundFiles; | ||
|
||
Sound::ChannelHandle _sound; | ||
}; | ||
|
||
} // End of namespace KotOR | ||
|
||
} // End of namespace Engines | ||
|
||
#endif // ENGINES_KOTOR_SOUND_H |