diff --git a/src/enemy.h b/src/enemy.h index 98cd949..17c3625 100644 --- a/src/enemy.h +++ b/src/enemy.h @@ -1847,7 +1847,7 @@ struct Mutant : Enemy { bool exploded = explodeMask != 0; if (health <= 0.0f && !exploded) { - game->playSound(TR::SND_MUTANT_DEATH, pos, 0); + game->playSound(TR::SND_MUTANT_DEATH, pos, Sound::PAN); explode(0xffffffff); } @@ -1976,6 +1976,7 @@ struct Mutant : Enemy { }; #define GIANT_MUTANT_TURN_SLOW (DEG2RAD * 90) +#define GIANT_MUTANT_MIN_ANGLE (DEG2RAD * 10) #define GIANT_MUTANT_MAX_ANGLE (DEG2RAD * 45) #define GIANT_MUTANT_DAMAGE 500 #define GIANT_MUTANT_DAMAGE_WALK 5 @@ -2009,11 +2010,11 @@ struct GiantMutant : Enemy { STATE_FATAL, }; - GiantMutant(IGame *game, int entity) : Enemy(game, entity, 1/*500*/, 341, 375.0f, 1.0f) { + GiantMutant(IGame *game, int entity) : Enemy(game, entity, 500, 341, 375.0f, 1.0f) { hitSound = TR::SND_HIT_MUTANT; stand = STAND_AIR; jointChest = -1; - jointHead = 3; + jointHead = -1; // 3; TODO: fix head orientation rangeHead = vec4(-0.5f, 0.5f, -0.5f, 0.5f) * PI; invertAim = true; } @@ -2025,7 +2026,7 @@ struct GiantMutant : Enemy { if (health <= 0.0f && !exploded && animation.index == ANIM_DEATH && flags.state == TR::Entity::asInactive) { flags.state = TR::Entity::asActive; - game->playSound(TR::SND_MUTANT_DEATH, pos, 0); + game->playSound(TR::SND_MUTANT_DEATH, pos, Sound::PAN); explode(0xffffffff); game->checkTrigger(this, true); } @@ -2115,7 +2116,7 @@ struct GiantMutant : Enemy { } virtual void updatePosition() { - if (target && target->health > 0.0f) + if (target && target->health > 0.0f && fabsf(targetAngle) > GIANT_MUTANT_MIN_ANGLE) if (state == STATE_TURN_LEFT || state == STATE_TURN_RIGHT || state == STATE_WALK || state == STATE_STOP) turn(targetAngle, GIANT_MUTANT_TURN_SLOW); diff --git a/src/lara.h b/src/lara.h index 270ec56..0e2371d 100644 --- a/src/lara.h +++ b/src/lara.h @@ -1490,7 +1490,6 @@ struct Lara : Character { break; } case TR::HIT_BOULDER : { - camera->setAngle(-25, 170); animation.setAnim(ANIM_DEATH_BOULDER); vec3 v(0.0f); @@ -1518,7 +1517,6 @@ struct Lara : Character { break; } case TR::HIT_REX : { - camera->setAngle(-25, 170); pos = enemy->pos; angle = enemy->angle; @@ -1538,7 +1536,6 @@ struct Lara : Character { break; } case TR::HIT_GIANT_MUTANT : { -// camera->setAngle(-25, 170); pos = enemy->pos; angle = enemy->angle; diff --git a/src/level.h b/src/level.h index c41bbce..5dea63f 100644 --- a/src/level.h +++ b/src/level.h @@ -464,16 +464,16 @@ struct Level : IGame { players[i]->camera->shake = 0.5f * max(0.0f, 1.0f - (controller->pos - players[i]->camera->eye.pos).length2() / (15 * 1024 * 15 * 1024)); return; case TR::Effect::FLOOD : { - Sound::Sample *sample = playSound(TR::SND_FLOOD, vec3(), 0); + Sound::Sample *sample = playSound(TR::SND_FLOOD); if (sample) sample->setVolume(0.0f, 4.0f); break; } case TR::Effect::STAIRS2SLOPE : - playSound(TR::SND_STAIRS2SLOPE, vec3(), 0); + playSound(TR::SND_STAIRS2SLOPE); break; case TR::Effect::EXPLOSION : - playSound(TR::SND_TNT, vec3(0), 0); + playSound(TR::SND_TNT); shakeCamera(1.0f); break; default : ; @@ -572,7 +572,6 @@ struct Level : IGame { } virtual Sound::Sample* playSound(int id, const vec3 &pos = vec3(0.0f), int flags = 0) const { - //return NULL; if (level.version == TR::VER_TR1_PSX && id == TR::SND_SECRET) return NULL; @@ -590,7 +589,7 @@ struct Level : IGame { if (!(flags & Sound::MUSIC)) { switch (b.flags.mode) { - case 0 : if (level.version & TR::VER_TR1) flags |= Sound::UNIQUE; break; // TODO check this + case 0 : flags |= Sound::UNIQUE; break; case 1 : flags |= Sound::REPLAY; break; case 2 : if (level.version & TR::VER_TR1) flags |= Sound::LOOP; break; case 3 : if (!(level.version & TR::VER_TR1)) flags |= Sound::LOOP | Sound::UNIQUE; break; @@ -598,7 +597,7 @@ struct Level : IGame { } if (b.flags.gain) volume = max(0.0f, volume - randf() * 0.25f); //if (b.flags.camera) flags &= ~Sound::PAN; - return Sound::play(level.getSampleStream(index), pos, volume, pitch, flags, id); + return Sound::play(level.getSampleStream(index), &pos, volume, pitch, flags, id); } return NULL; } @@ -623,7 +622,7 @@ struct Level : IGame { Level *level = req->level; level->waitTrack = false; if (stream) { - level->sndTrack = Sound::play(stream, vec3(0.0f), 0.01f, 1.0f, req->flags); + level->sndTrack = Sound::play(stream, NULL, 0.01f, 1.0f, req->flags); if (level->sndTrack) { if (level->level.isCutsceneLevel()) { Core::resetTime(); diff --git a/src/sound.h b/src/sound.h index e0cb88e..29d5bbf 100644 --- a/src/sound.h +++ b/src/sound.h @@ -469,6 +469,7 @@ namespace Sound { bool flipped; struct Sample { + const vec3 *uniquePtr; Decoder *decoder; vec3 pos; float volume; @@ -480,8 +481,10 @@ namespace Sound { bool isPlaying; bool stopAfterFade; - Sample(Stream *stream, const vec3 &pos, float volume, float pitch, int flags, int id) : decoder(NULL), pos(pos), volume(volume), volumeTarget(volume), volumeDelta(0.0f), pitch(pitch), flags(flags), id(id) { - uint32 fourcc; + Sample(Stream *stream, const vec3 *pos, float volume, float pitch, int flags, int id) : uniquePtr(pos), decoder(NULL), volume(volume), volumeTarget(volume), volumeDelta(0.0f), pitch(pitch), flags(flags), id(id) { + this->pos = pos ? *pos : vec3(0.0f); + + uint32 fourcc; stream->read(fourcc); if (fourcc == FOURCC("RIFF")) { // wav @@ -760,16 +763,23 @@ namespace Sound { return stream; } - Sample* play(Stream *stream, const vec3 &pos, float volume = 1.0f, float pitch = 0.0f, int flags = 0, int id = - 1) { + Sample* getChannel(int id, const vec3 *pos) { + for (int i = 0; i < channelsCount; i++) + if (channels[i]->id == id && channels[i]->uniquePtr == pos) + return channels[i]; + return NULL; + } + + Sample* play(Stream *stream, const vec3 *pos = NULL, float volume = 1.0f, float pitch = 0.0f, int flags = 0, int id = - 1) { OS_LOCK(lock); ASSERT(pitch >= 0.0f); if (!stream) return NULL; if (volume > 0.001f) { - vec3 listenerPos = getListener(pos).matrix.getPos(); + if (pos && !(flags & (FLIPPED | UNFLIPPED | MUSIC)) && (flags & PAN)) { + vec3 listenerPos = getListener(*pos).matrix.getPos(); + vec3 d = *pos - listenerPos; - if (!(flags & (FLIPPED | UNFLIPPED | MUSIC)) && (flags & PAN)) { - vec3 d = pos - listenerPos; if (fabsf(d.x) > SND_FADEOFF_DIST || fabsf(d.y) > SND_FADEOFF_DIST || fabsf(d.z) > SND_FADEOFF_DIST) { delete stream; return NULL; @@ -777,21 +787,19 @@ namespace Sound { } if (flags & (UNIQUE | REPLAY)) { - for (int i = 0; i < channelsCount; i++) - if (channels[i]->id == id) { - vec3 p = listenerPos; + Sample *ch = getChannel(id, pos); - if ((p - channels[i]->pos).length2() > (p - pos).length2()) { - channels[i]->pos = pos; - channels[i]->pitch = pitch; - } + if (ch) { + if (pos) + ch->pos = *pos; + ch->pitch = pitch; - if (flags & REPLAY) - channels[i]->replay(); + if (flags & REPLAY) + ch->replay(); - delete stream; - return channels[i]; - } + delete stream; + return ch; + } } if (channelsCount < SND_CHANNELS_MAX) diff --git a/src/trigger.h b/src/trigger.h index 2937fc6..5a066f2 100644 --- a/src/trigger.h +++ b/src/trigger.h @@ -1513,7 +1513,7 @@ struct Bubble : Sprite { struct Explosion : Sprite { Explosion(IGame *game, int entity) : Sprite(game, entity, true, Sprite::FRAME_ANIMATED) { - game->playSound(TR::SND_EXPLOSION, pos, 0); + game->playSound(TR::SND_EXPLOSION, pos, Sound::PAN); game->getMesh()->sequences[-(getEntity().modelIndex + 1)].transp = 2; // fix blending mode to additive } };