Fixing issues with some repeating patterns not playing correctly

This commit is contained in:
Simon 2021-04-01 23:59:23 +01:00
parent 73db4ae7e7
commit 400bb237c7
4 changed files with 41 additions and 30 deletions

View file

@ -1621,36 +1621,6 @@ bool idEntity::StartSoundShader( const idSoundShader *shader, const s_channelTyp
*length = len;
}
idPlayer *player = gameLocal.GetLocalPlayer();
if (vr_useHapticsService.GetBool() &&
player != NULL) {
idVec3 playerOrigin = gameLocal.GetLocalPlayer()->GetPlayerPhysics()->GetOrigin(0);
idVec3 entityOrigin = GetPhysics()->GetOrigin(0);
idVec3 direction = playerOrigin - entityOrigin;
float distance = direction.Length();
if (distance <= 150.0F) {
bool looping = (shader->GetParms()->soundShaderFlags & SSF_LOOPING) != 0;
direction.Normalize();
idVec3 bodyOrigin = vec3_zero;
idMat3 bodyAxis;
player->GetViewPos( bodyOrigin, bodyAxis );
idAngles bodyAng = bodyAxis.ToAngles();
idAngles directionYaw(0, 180 + (direction.ToYaw() - bodyAng.yaw), 0);
directionYaw.Normalize360();
//Pass sound on in case it can trigger a haptic event (like doors)
float intensity = looping ? ((distance * 100)/ 150.0f) :
40 + Min<float>((int)(150.0f - distance), 80);
common->HapticEvent(shader->GetName(), 4, looping ? 1 : 0, intensity,
directionYaw.yaw, 0);
}
}
// set reference to the sound for shader synced effects
renderEntity.referenceSound = refSound.referenceSound;

View file

@ -842,6 +842,46 @@ int idSoundEmitterLocal::StartSound( const idSoundShader *shader, const s_channe
chan->stopped = false;
chan->Start();
if (cvarSystem->GetCVarBool("vr_useHapticsService"))
{
idVec3 direction = (soundWorld->listenerPos / DOOM_TO_METERS) - origin;
float distance = direction.Length();
bool looping = (shader->GetParms()->soundShaderFlags & SSF_LOOPING) != 0;
if (distance <= 150.0F || looping)
{
direction.Normalize();
idAngles bodyAng = soundWorld->listenerAxis.ToAngles();
idAngles directionYaw(0, 180 + (direction.ToYaw() - bodyAng.yaw), 0);
directionYaw.Normalize360();
//Pass sound on in case it can trigger a haptic event (like doors)
float intensity = looping ? (100 - ((distance * 100)/ 150.0f)) :
40 + Min<float>((int)(150.0f - distance), 80);
if (distance == 0)
{
intensity = 100;
}
//Even if the sound is too far away to make a haptic play, we still need to report it if
//it is a looping event, looping event intensity are handled in snd_world
if (distance > 150.0F || intensity < 0 || looping)
{
intensity = 0;
}
if (looping)
{
common->Printf("Start Looping: %s", shader->GetName());
}
common->HapticEvent(shader->GetName(), 4, looping ? 1 : 0, intensity,
directionYaw.yaw, 0);
}
}
// we need to start updating the def and mixing it in
playing = true;

View file

@ -61,6 +61,7 @@ import static android.system.Os.setenv;
public void shutdown() {
finish();
System.exit(0);
}