mirror of
https://github.com/XProger/OpenLara.git
synced 2025-01-17 21:09:00 +01:00
#9 underwater ambient sound
This commit is contained in:
parent
3d1fab932c
commit
e669f6c395
BIN
bin/OpenLara.exe
BIN
bin/OpenLara.exe
Binary file not shown.
@ -83,6 +83,10 @@ struct Camera : Controller {
|
||||
Sound::reverb.setRoomSize(vec3(float(r.xSectors), float(h), float(r.zSectors)) * 2.419f); // convert cells size into meters
|
||||
}
|
||||
|
||||
bool isUnderwater() {
|
||||
return level->rooms[getRoomIndex()].flags.water;
|
||||
}
|
||||
|
||||
virtual void update() {
|
||||
#ifndef LEVEL_EDITOR
|
||||
if (cutscene) { // cutscene
|
||||
|
@ -206,12 +206,12 @@ struct Controller {
|
||||
return b.floor - floor;
|
||||
}
|
||||
|
||||
void playSound(int id, const vec3 &pos, int flags) const {
|
||||
Sound::Sample* playSound(int id, const vec3 &pos, int flags) const {
|
||||
if (level->version == TR::Level::VER_TR1_PSX && id == TR::SND_SECRET)
|
||||
return;
|
||||
return NULL;
|
||||
|
||||
int16 a = level->soundsMap[id];
|
||||
if (a == -1) return;
|
||||
if (a == -1) return NULL;
|
||||
|
||||
TR::SoundInfo &b = level->soundsInfo[a];
|
||||
if (b.chance == 0 || (rand() & 0x7fff) <= b.chance) {
|
||||
@ -223,8 +223,9 @@ struct Controller {
|
||||
if (b.flags.mode == 3) flags |= Sound::SYNC;
|
||||
if (b.flags.gain) volume = max(0.0f, volume - randf() * 0.25f);
|
||||
if (b.flags.fixed) flags |= Sound::LOOP;
|
||||
Sound::play(level->getSampleStream(index), pos, volume, pitch, flags, entity * 1000 + index);
|
||||
return Sound::play(level->getSampleStream(index), pos, volume, pitch, flags, entity * 1000 + index);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vec3 getDir() const {
|
||||
|
@ -10,12 +10,8 @@ namespace Game {
|
||||
|
||||
void startLevel(Stream *lvl, Stream *snd, bool demo, bool home) {
|
||||
delete level;
|
||||
level = new Level(*lvl, demo, home);
|
||||
level = new Level(*lvl, snd, demo, home);
|
||||
delete lvl;
|
||||
|
||||
|
||||
//Sound::play(Sound::openWAD("05_Lara's_Themes.wav"), 1, 1, 0);
|
||||
Sound::play(snd, vec3(0.0f), 1, 1, Sound::Flags::LOOP);
|
||||
}
|
||||
|
||||
void init(Stream *lvl, Stream *snd) {
|
||||
|
18
src/level.h
18
src/level.h
@ -35,6 +35,9 @@ struct Level : IGame {
|
||||
AmbientCache *ambientCache;
|
||||
WaterCache *waterCache;
|
||||
|
||||
Sound::Sample *sndAmbient;
|
||||
Sound::Sample *sndUnderwater;
|
||||
|
||||
// IGame implementation ========
|
||||
virtual TR::Level* getLevel() {
|
||||
return &level;
|
||||
@ -95,7 +98,7 @@ struct Level : IGame {
|
||||
}
|
||||
//==============================
|
||||
|
||||
Level(Stream &stream, bool demo, bool home) : level(stream, demo), lara(NULL) {
|
||||
Level(Stream &stream, Stream *snd, bool demo, bool home) : level(stream, demo), lara(NULL) {
|
||||
params->time = 0.0f;
|
||||
|
||||
#ifdef _DEBUG
|
||||
@ -211,6 +214,15 @@ struct Level : IGame {
|
||||
shadow = Core::settings.shadows ? new Texture(1024, 1024, Texture::SHADOW, false) : NULL;
|
||||
|
||||
initReflections();
|
||||
|
||||
// init sounds
|
||||
//Sound::play(Sound::openWAD("05_Lara's_Themes.wav"), 1, 1, 0);
|
||||
sndAmbient = Sound::play(snd, vec3(0.0f), 1, 1, Sound::Flags::LOOP);
|
||||
|
||||
sndUnderwater = lara->playSound(TR::SND_UNDERWATER, vec3(0.0f), Sound::LOOP);
|
||||
if (sndUnderwater)
|
||||
sndUnderwater->volume = 0.0f;
|
||||
|
||||
for (int i = 0; i < level.soundSourcesCount; i++) {
|
||||
TR::SoundSource &src = level.soundSources[i];
|
||||
lara->playSound(src.id, vec3(float(src.x), float(src.y), float(src.z)), Sound::PAN | Sound::LOOP | Sound::STATIC);
|
||||
@ -549,6 +561,10 @@ struct Level : IGame {
|
||||
}
|
||||
|
||||
camera->update();
|
||||
float ambientVolume = camera->isUnderwater() ? 0.0f : 1.0f;
|
||||
if (sndAmbient) sndAmbient->volume = ambientVolume;
|
||||
if (sndUnderwater) sndUnderwater->volume = 1.0f - ambientVolume;
|
||||
|
||||
if (waterCache)
|
||||
waterCache->update();
|
||||
}
|
||||
|
@ -564,6 +564,9 @@ namespace Sound {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((channels[i]->flags & LOOP) && channels[i]->volume < EPS)
|
||||
continue;
|
||||
|
||||
memset(buffer, 0, sizeof(Frame) * bufSize);
|
||||
channels[i]->render(buffer, int(count * channels[i]->pitch));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user