2012-11-26 18:58:24 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
|
|
|
|
Doom 3 BFG Edition GPL Source Code
|
2012-11-28 15:47:07 +00:00
|
|
|
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code 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.
|
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
|
|
|
|
|
|
|
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
|
|
|
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
#pragma hdrstop
|
2012-12-22 15:18:19 +00:00
|
|
|
#include "precompiled.h"
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
#include "snd_local.h"
|
|
|
|
|
|
|
|
idCVar s_lockListener( "s_lockListener", "0", CVAR_BOOL, "lock listener updates" );
|
|
|
|
idCVar s_constantAmplitude( "s_constantAmplitude", "-1", CVAR_FLOAT, "" );
|
|
|
|
idCVar s_maxEmitterChannels( "s_maxEmitterChannels", "48", CVAR_INTEGER, "Can be set lower than the absolute max of MAX_HARDWARE_VOICES" );
|
|
|
|
idCVar s_cushionFadeChannels( "s_cushionFadeChannels", "2", CVAR_INTEGER, "Ramp currentCushionDB so this many emitter channels should be silent" );
|
|
|
|
idCVar s_cushionFadeRate( "s_cushionFadeRate", "60", CVAR_FLOAT, "DB / second change to currentCushionDB" );
|
|
|
|
idCVar s_cushionFadeLimit( "s_cushionFadeLimit", "-30", CVAR_FLOAT, "Never cushion fade beyond this level" );
|
|
|
|
idCVar s_cushionFadeOver( "s_cushionFadeOver", "10", CVAR_FLOAT, "DB above s_cushionFadeLimit to start ramp to silence" );
|
|
|
|
idCVar s_unpauseFadeInTime( "s_unpauseFadeInTime", "250", CVAR_INTEGER, "When unpausing a sound world, milliseconds to fade sounds in over" );
|
|
|
|
idCVar s_doorDistanceAdd( "s_doorDistanceAdd", "150", CVAR_FLOAT, "reduce sound volume with this distance when going through a door" );
|
2012-11-28 15:47:07 +00:00
|
|
|
idCVar s_drawSounds( "s_drawSounds", "0", CVAR_INTEGER, "", 0, 2, idCmdSystem::ArgCompletion_Integer<0, 2> );
|
2012-11-26 18:58:24 +00:00
|
|
|
idCVar s_showVoices( "s_showVoices", "0", CVAR_BOOL, "show active voices" );
|
|
|
|
idCVar s_volume_dB( "s_volume_dB", "0", CVAR_ARCHIVE | CVAR_FLOAT, "volume in dB" );
|
|
|
|
extern idCVar s_noSound;
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::idSoundWorldLocal
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idSoundWorldLocal::idSoundWorldLocal()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
volumeFade.Clear();
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < SOUND_MAX_CLASSES; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
soundClassFade[i].Clear();
|
|
|
|
}
|
|
|
|
renderWorld = NULL;
|
|
|
|
writeDemo = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
listener.axis.Identity();
|
|
|
|
listener.pos.Zero();
|
|
|
|
listener.id = -1;
|
|
|
|
listener.area = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
shakeAmp = 0.0f;
|
|
|
|
currentCushionDB = DB_SILENCE;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
localSound = AllocSoundEmitter();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
pauseFade.Clear();
|
|
|
|
pausedTime = 0;
|
|
|
|
accumulatedPauseTime = 0;
|
|
|
|
isPaused = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
slowmoSpeed = 1.0f;
|
|
|
|
enviroSuitActive = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::~idSoundWorldLocal
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idSoundWorldLocal::~idSoundWorldLocal()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( soundSystemLocal.currentSoundWorld == this )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
soundSystemLocal.currentSoundWorld = NULL;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < emitters.Num(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
emitters[i]->Reset();
|
|
|
|
emitterAllocator.Free( emitters[i] );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Make sure we aren't leaking emitters or channels
|
|
|
|
assert( emitterAllocator.GetAllocCount() == 0 );
|
|
|
|
assert( channelAllocator.GetAllocCount() == 0 );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
emitterAllocator.Shutdown();
|
|
|
|
channelAllocator.Shutdown();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
renderWorld = NULL;
|
|
|
|
localSound = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::AllocSoundEmitter
|
|
|
|
|
|
|
|
This is called from the main thread.
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idSoundEmitter* idSoundWorldLocal::AllocSoundEmitter()
|
|
|
|
{
|
|
|
|
idSoundEmitterLocal* emitter = emitterAllocator.Alloc();
|
2012-11-26 18:58:24 +00:00
|
|
|
emitter->Init( emitters.Append( emitter ), this );
|
|
|
|
return emitter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::AllocSoundChannel
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idSoundChannel* idSoundWorldLocal::AllocSoundChannel()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return channelAllocator.Alloc();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::FreeSoundChannel
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::FreeSoundChannel( idSoundChannel* channel )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
channel->Mute();
|
|
|
|
channelAllocator.Free( channel );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::CurrentShakeAmplitude
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
float idSoundWorldLocal::CurrentShakeAmplitude()
|
|
|
|
{
|
|
|
|
if( s_constantAmplitude.GetFloat() >= 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return s_constantAmplitude.GetFloat();
|
|
|
|
}
|
|
|
|
return shakeAmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::PlaceListener
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::PlaceListener( const idVec3& origin, const idMat3& axis, const int id )
|
|
|
|
{
|
|
|
|
if( writeDemo )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
writeDemo->WriteInt( DS_SOUND );
|
|
|
|
writeDemo->WriteInt( SCMD_PLACE_LISTENER );
|
|
|
|
writeDemo->WriteVec3( origin );
|
|
|
|
writeDemo->WriteMat3( axis );
|
|
|
|
writeDemo->WriteInt( id );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( s_lockListener.GetBool() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
listener.axis = axis;
|
|
|
|
listener.pos = origin;
|
|
|
|
listener.id = id;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( renderWorld )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
listener.area = renderWorld->PointInArea( origin ); // where are we?
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
listener.area = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idActiveChannel
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
class idActiveChannel
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
public:
|
2012-11-28 15:47:07 +00:00
|
|
|
idActiveChannel() :
|
|
|
|
channel( NULL ),
|
|
|
|
sortKey( 0 ) {}
|
|
|
|
idActiveChannel( idSoundChannel* channel_, int sortKey_ ) :
|
|
|
|
channel( channel_ ),
|
|
|
|
sortKey( sortKey_ ) {}
|
|
|
|
|
|
|
|
idSoundChannel* channel;
|
2012-11-26 18:58:24 +00:00
|
|
|
int sortKey;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
MapVolumeFromFadeDB
|
|
|
|
|
|
|
|
Ramp down volumes that are close to fadeDB so that fadeDB is DB_SILENCE
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
float MapVolumeFromFadeDB( const float volumeDB, const float fadeDB )
|
|
|
|
{
|
|
|
|
if( volumeDB <= fadeDB )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return DB_SILENCE;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
const float fadeOver = s_cushionFadeOver.GetFloat();
|
|
|
|
const float fadeFrom = fadeDB + fadeOver;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( volumeDB >= fadeFrom )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// unchanged
|
|
|
|
return volumeDB;
|
|
|
|
}
|
|
|
|
const float fadeFraction = ( volumeDB - fadeDB ) / fadeOver;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
const float mappedDB = DB_SILENCE + ( fadeFrom - DB_SILENCE ) * fadeFraction;
|
|
|
|
return mappedDB;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
AdjustForCushionChannels
|
|
|
|
|
|
|
|
In the very common case of having more sounds that would contribute to the
|
|
|
|
mix than there are available hardware voices, it can be an audible discontinuity
|
|
|
|
when a channel initially gets a voice or loses a voice.
|
|
|
|
To avoid this, make sure that the last few hardware voices are mixed with a volume
|
|
|
|
of zero, so they won't make a difference as they come and go.
|
|
|
|
It isn't obvious what the exact best volume ramping method should be, just that
|
|
|
|
it smoothly change frame to frame.
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
static float AdjustForCushionChannels( const idStaticList< idActiveChannel, MAX_HARDWARE_VOICES >& activeEmitterChannels,
|
|
|
|
const int uncushionedChannels, const float currentCushionDB, const float driftRate )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
float targetCushionDB;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( activeEmitterChannels.Num() <= uncushionedChannels )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// we should be able to hear all of them
|
|
|
|
targetCushionDB = DB_SILENCE;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// we should be able to hear all of them
|
|
|
|
targetCushionDB = activeEmitterChannels[uncushionedChannels].channel->volumeDB;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( targetCushionDB < DB_SILENCE )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
targetCushionDB = DB_SILENCE;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( targetCushionDB > s_cushionFadeLimit.GetFloat() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
targetCushionDB = s_cushionFadeLimit.GetFloat();
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// linearly drift the currentTargetCushionDB towards targetCushionDB
|
|
|
|
float driftedDB = currentCushionDB;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( driftedDB < targetCushionDB )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
driftedDB += driftRate;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( driftedDB > targetCushionDB )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
driftedDB = targetCushionDB;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
driftedDB -= driftRate;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( driftedDB < targetCushionDB )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
driftedDB = targetCushionDB;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// ramp the lower sound volumes down
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < activeEmitterChannels.Num(); i++ )
|
|
|
|
{
|
|
|
|
idSoundChannel* chan = activeEmitterChannels[i].channel;
|
2012-11-26 18:58:24 +00:00
|
|
|
chan->volumeDB = MapVolumeFromFadeDB( chan->volumeDB, driftedDB );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return driftedDB;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::Update
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::Update()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( s_noSound.GetBool() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// ------------------
|
|
|
|
// Update emitters
|
|
|
|
//
|
|
|
|
// Only loop through the list once to avoid extra cache misses
|
|
|
|
// ------------------
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// The naming convention is weird here because we reuse the name "channel"
|
|
|
|
// An idSoundChannel is a channel on an emitter, which may have an explicit channel assignment or SND_CHANNEL_ANY
|
|
|
|
// A hardware channel is a channel from the sound file itself (IE: left, right, LFE)
|
|
|
|
// We only allow MAX_HARDWARE_CHANNELS channels, which may wind up being a smaller number of idSoundChannels
|
|
|
|
idStaticList< idActiveChannel, MAX_HARDWARE_VOICES > activeEmitterChannels;
|
|
|
|
int maxEmitterChannels = s_maxEmitterChannels.GetInteger() + 1; // +1 to leave room for insert-before-sort
|
2012-11-28 15:47:07 +00:00
|
|
|
if( maxEmitterChannels > MAX_HARDWARE_VOICES )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
maxEmitterChannels = MAX_HARDWARE_VOICES;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int activeHardwareChannels = 0;
|
|
|
|
int totalHardwareChannels = 0;
|
|
|
|
int totalEmitterChannels = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int currentTime = GetSoundTime();
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int e = emitters.Num() - 1; e >= 0; e-- )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// check for freeing a one-shot emitter that is finished playing
|
2012-11-28 15:47:07 +00:00
|
|
|
if( emitters[e]->CheckForCompletion( currentTime ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// do a fast list collapse by swapping the last element into
|
|
|
|
// the slot we are deleting
|
|
|
|
emitters[e]->Reset();
|
|
|
|
emitterAllocator.Free( emitters[e] );
|
|
|
|
int lastEmitter = emitters.Num() - 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( e != lastEmitter )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
emitters[e] = emitters[lastEmitter];
|
|
|
|
emitters[e]->index = e;
|
|
|
|
}
|
|
|
|
emitters.SetNum( lastEmitter );
|
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
emitters[e]->Update( currentTime );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
totalEmitterChannels += emitters[e]->channels.Num();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// sort the active channels into the hardware list
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < emitters[e]->channels.Num(); i++ )
|
|
|
|
{
|
|
|
|
idSoundChannel* channel = emitters[e]->channels[i];
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// check if this channel contributes at all
|
|
|
|
const bool canMute = channel->CanMute();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( canMute && channel->volumeDB <= DB_SILENCE )
|
|
|
|
{
|
2013-01-03 19:17:54 +00:00
|
|
|
#if !defined(USE_OPENAL)
|
2012-11-26 18:58:24 +00:00
|
|
|
channel->Mute();
|
|
|
|
continue;
|
2013-01-03 19:17:54 +00:00
|
|
|
#endif
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Calculate the sort key.
|
|
|
|
// VO can't be stopped and restarted accurately, so always keep VO channels by adding a large value to the sort key.
|
|
|
|
const int sortKey = idMath::Ftoi( channel->volumeDB * 100.0f + ( canMute ? 0.0f : 100000.0f ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Keep track of the total number of hardware channels.
|
|
|
|
// This is done after calculating the sort key to avoid a load-hit-store that
|
|
|
|
// would occur when using the sort key in the loop below after the Ftoi above.
|
|
|
|
const int sampleChannels = channel->leadinSample->NumChannels();
|
|
|
|
totalHardwareChannels += sampleChannels;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Find the location to insert this channel based on the sort key.
|
|
|
|
int insertIndex = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( insertIndex = 0; insertIndex < activeEmitterChannels.Num(); insertIndex++ )
|
|
|
|
{
|
|
|
|
if( sortKey > activeEmitterChannels[insertIndex].sortKey )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Only insert at the end if there is room.
|
2012-11-28 15:47:07 +00:00
|
|
|
if( insertIndex == activeEmitterChannels.Num() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// Always leave one spot free in the 'activeEmitterChannels' so there is room to insert sort a potentially louder sound later.
|
2012-11-28 15:47:07 +00:00
|
|
|
if( activeEmitterChannels.Num() + 1 >= activeEmitterChannels.Max() || activeHardwareChannels + sampleChannels > MAX_HARDWARE_CHANNELS )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// We don't have enough voices to play this, so mute it if it was playing.
|
|
|
|
channel->Mute();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// We want to insert the sound at this point.
|
|
|
|
activeEmitterChannels.Insert( idActiveChannel( channel, sortKey ), insertIndex );
|
|
|
|
activeHardwareChannels += sampleChannels;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// If we are over our voice limit or at our channel limit, mute sounds until it fits.
|
|
|
|
// If activeEmitterChannels is full, always remove the last one so there is room to insert sort a potentially louder sound later.
|
2012-11-28 15:47:07 +00:00
|
|
|
while( activeEmitterChannels.Num() == maxEmitterChannels || activeHardwareChannels > MAX_HARDWARE_CHANNELS )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
const int indexToRemove = activeEmitterChannels.Num() - 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
idSoundChannel* const channelToMute = activeEmitterChannels[ indexToRemove ].channel;
|
2012-11-26 18:58:24 +00:00
|
|
|
channelToMute->Mute();
|
|
|
|
activeHardwareChannels -= channelToMute->leadinSample->NumChannels();
|
|
|
|
activeEmitterChannels.RemoveIndex( indexToRemove );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
const float secondsPerFrame = 1.0f / com_engineHz_latched;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// ------------------
|
|
|
|
// In the very common case of having more sounds that would contribute to the
|
|
|
|
// mix than there are available hardware voices, it can be an audible discontinuity
|
|
|
|
// when a channel initially gets a voice or loses a voice.
|
|
|
|
// To avoid this, make sure that the last few hardware voices are mixed with a volume
|
|
|
|
// of zero, so they won't make a difference as they come and go.
|
|
|
|
// It isn't obvious what the exact best volume ramping method should be, just that
|
|
|
|
// it smoothly change frame to frame.
|
|
|
|
// ------------------
|
|
|
|
const int uncushionedChannels = maxEmitterChannels - s_cushionFadeChannels.GetInteger();
|
2012-11-28 15:47:07 +00:00
|
|
|
currentCushionDB = AdjustForCushionChannels( activeEmitterChannels, uncushionedChannels,
|
|
|
|
currentCushionDB, s_cushionFadeRate.GetFloat() * secondsPerFrame );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// ------------------
|
|
|
|
// Update Hardware
|
|
|
|
// ------------------
|
|
|
|
shakeAmp = 0.0f;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr showVoiceTable;
|
|
|
|
bool showVoices = s_showVoices.GetBool();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( showVoices )
|
|
|
|
{
|
|
|
|
showVoiceTable.Format( "currentCushionDB: %5.1f freeVoices: %i zombieVoices: %i buffers:%i/%i\n", currentCushionDB,
|
|
|
|
soundSystemLocal.hardware.GetNumFreeVoices(), soundSystemLocal.hardware.GetNumZombieVoices(),
|
|
|
|
soundSystemLocal.activeStreamBufferContexts.Num(), soundSystemLocal.freeStreamBufferContexts.Num() );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < activeEmitterChannels.Num(); i++ )
|
|
|
|
{
|
|
|
|
idSoundChannel* chan = activeEmitterChannels[i].channel;
|
2012-11-26 18:58:24 +00:00
|
|
|
chan->UpdateHardware( 0.0f, currentTime );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( showVoices )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr voiceLine;
|
|
|
|
voiceLine.Format( "%5.1f db [%3i:%2i] %s", chan->volumeDB, chan->emitter->index, chan->logicalChannel, chan->CanMute() ? "" : " <CANT MUTE>\n" );
|
2012-11-28 15:47:07 +00:00
|
|
|
idSoundSample* leadinSample = chan->leadinSample;
|
|
|
|
idSoundSample* loopingSample = chan->loopingSample;
|
|
|
|
if( loopingSample == NULL )
|
|
|
|
{
|
|
|
|
voiceLine.Append( va( "%ikhz*%i %s\n", leadinSample->SampleRate() / 1000, leadinSample->NumChannels(), leadinSample->GetName() ) );
|
|
|
|
}
|
|
|
|
else if( loopingSample == leadinSample )
|
|
|
|
{
|
|
|
|
voiceLine.Append( va( "%ikhz*%i <LOOPING> %s\n", leadinSample->SampleRate() / 1000, leadinSample->NumChannels(), leadinSample->GetName() ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
voiceLine.Append( va( "%ikhz*%i %s | %ikhz*%i %s\n", leadinSample->SampleRate() / 1000, leadinSample->NumChannels(), leadinSample->GetName(), loopingSample->SampleRate() / 1000, loopingSample->NumChannels(), loopingSample->GetName() ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
showVoiceTable += voiceLine;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Calculate shakes
|
2012-11-28 15:47:07 +00:00
|
|
|
if( chan->hardwareVoice == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
shakeAmp += chan->parms.shakes * chan->hardwareVoice->GetGain() * chan->currentAmplitude;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( showVoices )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
static idOverlayHandle handle;
|
|
|
|
console->PrintOverlay( handle, JUSTIFY_LEFT, showVoiceTable.c_str() );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( s_drawSounds.GetBool() && renderWorld != NULL )
|
|
|
|
{
|
|
|
|
for( int e = 0; e < emitters.Num(); e++ )
|
|
|
|
{
|
|
|
|
idSoundEmitterLocal* emitter = emitters[e];
|
2012-11-26 18:58:24 +00:00
|
|
|
bool audible = false;
|
|
|
|
float maxGain = 0.0f;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int c = 0; c < emitter->channels.Num(); c++ )
|
|
|
|
{
|
|
|
|
if( emitter->channels[c]->hardwareVoice != NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
audible = true;
|
|
|
|
maxGain = Max( maxGain, emitter->channels[c]->hardwareVoice->GetGain() );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !audible )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
static const int lifetime = 20;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idBounds ref;
|
|
|
|
ref.Clear();
|
|
|
|
ref.AddPoint( idVec3( -10.0f ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
ref.AddPoint( idVec3( 10.0f ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// draw a box
|
|
|
|
renderWorld->DebugBounds( idVec4( maxGain, maxGain, 1.0f, 1.0f ), ref, emitter->origin, lifetime );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( emitter->origin != emitter->spatializedOrigin )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
renderWorld->DebugLine( idVec4( 1.0f, 0.0f, 0.0f, 1.0f ), emitter->origin, emitter->spatializedOrigin, lifetime );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// draw the index
|
|
|
|
idVec3 textPos = emitter->origin;
|
|
|
|
textPos.z -= 8;
|
2012-11-28 15:47:07 +00:00
|
|
|
renderWorld->DrawText( va( "%i", e ), textPos, 0.1f, idVec4( 1, 0, 0, 1 ), listener.axis, 1, lifetime );
|
2012-11-26 18:58:24 +00:00
|
|
|
textPos.z += 8;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// run through all the channels
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int k = 0; k < emitter->channels.Num(); k++ )
|
|
|
|
{
|
|
|
|
idSoundChannel* chan = emitter->channels[k];
|
2012-11-26 18:58:24 +00:00
|
|
|
float min = chan->parms.minDistance;
|
|
|
|
float max = chan->parms.maxDistance;
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* defaulted = chan->leadinSample->IsDefault() ? " *DEFAULTED*" : "";
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr text;
|
|
|
|
text.Format( "%s (%i %i/%i)%s", chan->soundShader->GetName(), idMath::Ftoi( emitter->spatializedDistance ), idMath::Ftoi( min ), idMath::Ftoi( max ), defaulted );
|
2012-11-28 15:47:07 +00:00
|
|
|
renderWorld->DrawText( text, textPos, 0.1f, idVec4( 1, 0, 0, 1 ), listener.axis, 1, lifetime );
|
2012-11-26 18:58:24 +00:00
|
|
|
textPos.z += 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::OnReloadSound
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::OnReloadSound( const idDecl* shader )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < emitters.Num(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
emitters[i]->OnReloadSound( shader );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::EmitterForIndex
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idSoundEmitter* idSoundWorldLocal::EmitterForIndex( int index )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// This is only used by save/load code which assumes index = 0 is invalid
|
|
|
|
// Which is fine since we use index 0 for the local sound emitter anyway
|
2012-11-28 15:47:07 +00:00
|
|
|
if( index <= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( index >= emitters.Num() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idLib::Error( "idSoundWorldLocal::EmitterForIndex: %i >= %i", index, emitters.Num() );
|
|
|
|
}
|
|
|
|
return emitters[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::ClearAllSoundEmitters
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::ClearAllSoundEmitters()
|
|
|
|
{
|
|
|
|
for( int i = 0; i < emitters.Num(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
emitters[i]->Reset();
|
|
|
|
emitterAllocator.Free( emitters[i] );
|
|
|
|
}
|
|
|
|
emitters.Clear();
|
|
|
|
localSound = AllocSoundEmitter();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::StopAllSounds
|
|
|
|
|
|
|
|
This is called from the main thread.
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::StopAllSounds()
|
|
|
|
{
|
|
|
|
for( int i = 0; i < emitters.Num(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
emitters[i]->Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::PlayShaderDirectly
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idSoundWorldLocal::PlayShaderDirectly( const char* name, int channel )
|
|
|
|
{
|
|
|
|
if( name == NULL || name[0] == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
localSound->StopSound( channel );
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
const idSoundShader* shader = declManager->FindSound( name );
|
|
|
|
if( shader == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
localSound->StopSound( channel );
|
|
|
|
return 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return localSound->StartSound( shader, channel, soundSystemLocal.random.RandomFloat(), SSF_GLOBAL, true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::Skip
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::Skip( int time )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
accumulatedPauseTime -= time;
|
|
|
|
pauseFade.SetVolume( DB_SILENCE );
|
|
|
|
pauseFade.Fade( 0.0f, s_unpauseFadeInTime.GetInteger(), GetSoundTime() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::Pause
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::Pause()
|
|
|
|
{
|
|
|
|
if( !isPaused )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
pausedTime = soundSystemLocal.SoundTime();
|
|
|
|
isPaused = true;
|
|
|
|
// just pause all unmutable voices (normally just voice overs)
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int e = emitters.Num() - 1; e > 0; e-- )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < emitters[e]->channels.Num(); i++ )
|
|
|
|
{
|
|
|
|
idSoundChannel* channel = emitters[e]->channels[i];
|
|
|
|
if( !channel->CanMute() && channel->hardwareVoice != NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
channel->hardwareVoice->Pause();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::UnPause
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::UnPause()
|
|
|
|
{
|
|
|
|
if( isPaused )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
isPaused = false;
|
|
|
|
accumulatedPauseTime += soundSystemLocal.SoundTime() - pausedTime;
|
|
|
|
pauseFade.SetVolume( DB_SILENCE );
|
|
|
|
pauseFade.Fade( 0.0f, s_unpauseFadeInTime.GetInteger(), GetSoundTime() );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// just unpause all unmutable voices (normally just voice overs)
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int e = emitters.Num() - 1; e > 0; e-- )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < emitters[e]->channels.Num(); i++ )
|
|
|
|
{
|
|
|
|
idSoundChannel* channel = emitters[e]->channels[i];
|
|
|
|
if( !channel->CanMute() && channel->hardwareVoice != NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
channel->hardwareVoice->UnPause();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::GetSoundTime
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idSoundWorldLocal::GetSoundTime()
|
|
|
|
{
|
|
|
|
if( isPaused )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return pausedTime - accumulatedPauseTime;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return soundSystemLocal.SoundTime() - accumulatedPauseTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
idSoundWorldLocal::ResolveOrigin
|
|
|
|
|
|
|
|
Find out of the sound is completely occluded by a closed door portal, or
|
|
|
|
the virtual sound origin position at the portal closest to the listener.
|
|
|
|
this is called by the main thread
|
|
|
|
|
|
|
|
dist is the distance from the orignial sound origin to the current portal that enters soundArea
|
|
|
|
def->distance is the distance we are trying to reduce.
|
|
|
|
|
|
|
|
If there is no path through open portals from the sound to the listener, def->spatializedDistance will remain
|
|
|
|
set at maxDistance
|
|
|
|
===================
|
|
|
|
*/
|
|
|
|
static const int MAX_PORTAL_TRACE_DEPTH = 10;
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::ResolveOrigin( const int stackDepth, const soundPortalTrace_t* prevStack, const int soundArea, const float dist, const idVec3& soundOrigin, idSoundEmitterLocal* def )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( dist >= def->spatializedDistance )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// we can't possibly hear the sound through this chain of portals
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( soundArea == listener.area )
|
|
|
|
{
|
|
|
|
float fullDist = dist + ( soundOrigin - listener.pos ).LengthFast();
|
|
|
|
if( fullDist < def->spatializedDistance )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
def->spatializedDistance = fullDist;
|
|
|
|
def->spatializedOrigin = soundOrigin;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( stackDepth == MAX_PORTAL_TRACE_DEPTH )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// don't spend too much time doing these calculations in big maps
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
soundPortalTrace_t newStack;
|
|
|
|
newStack.portalArea = soundArea;
|
|
|
|
newStack.prevStack = prevStack;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int numPortals = renderWorld->NumPortalsInArea( soundArea );
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int p = 0; p < numPortals; p++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
exitPortal_t re = renderWorld->GetPortal( soundArea, p );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
float occlusionDistance = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// air blocking windows will block sound like closed doors
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ( re.blockingBits & ( PS_BLOCK_VIEW | PS_BLOCK_AIR ) ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// we could just completely cut sound off, but reducing the volume works better
|
|
|
|
// continue;
|
|
|
|
occlusionDistance = s_doorDistanceAdd.GetFloat();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// what area are we about to go look at
|
|
|
|
int otherArea = re.areas[0];
|
2012-11-28 15:47:07 +00:00
|
|
|
if( re.areas[0] == soundArea )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
otherArea = re.areas[1];
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// if this area is already in our portal chain, don't bother looking into it
|
2012-11-28 15:47:07 +00:00
|
|
|
const soundPortalTrace_t* prev;
|
|
|
|
for( prev = prevStack ; prev ; prev = prev->prevStack )
|
|
|
|
{
|
|
|
|
if( prev->portalArea == otherArea )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( prev )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// pick a point on the portal to serve as our virtual sound origin
|
|
|
|
idVec3 source;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idPlane pl;
|
|
|
|
re.w->GetPlane( pl );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
float scale;
|
|
|
|
idVec3 dir = listener.pos - soundOrigin;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !pl.RayIntersection( soundOrigin, dir, scale ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
source = re.w->GetCenter();
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
source = soundOrigin + scale * dir;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// if this point isn't inside the portal edges, slide it in
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0 ; i < re.w->GetNumPoints() ; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int j = ( i + 1 ) % re.w->GetNumPoints();
|
2012-11-28 15:47:07 +00:00
|
|
|
idVec3 edgeDir = ( *( re.w ) )[j].ToVec3() - ( *( re.w ) )[i].ToVec3();
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 edgeNormal;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
edgeNormal.Cross( pl.Normal(), edgeDir );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idVec3 fromVert = source - ( *( re.w ) )[j].ToVec3();
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
float d = edgeNormal * fromVert;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( d > 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// move it in
|
|
|
|
float div = edgeNormal.Normalize();
|
|
|
|
d /= div;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
source -= d * edgeNormal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 tlen = source - soundOrigin;
|
|
|
|
float tlenLength = tlen.LengthFast();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
ResolveOrigin( stackDepth + 1, &newStack, otherArea, dist + tlenLength + occlusionDistance, source, def );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::StartWritingDemo
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::StartWritingDemo( idDemoFile* demo )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
writeDemo = demo;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
writeDemo->WriteInt( DS_SOUND );
|
|
|
|
writeDemo->WriteInt( SCMD_STATE );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// use the normal save game code to archive all the emitters
|
|
|
|
WriteToSaveGame( writeDemo );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::StopWritingDemo
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::StopWritingDemo()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
writeDemo = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSoundWorldLocal::ProcessDemoCommand
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::ProcessDemoCommand( idDemoFile* readDemo )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !readDemo )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int index;
|
|
|
|
soundDemoCommand_t dc;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !readDemo->ReadInt( ( int& )dc ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
switch( dc )
|
|
|
|
{
|
|
|
|
case SCMD_STATE:
|
|
|
|
ReadFromSaveGame( readDemo );
|
|
|
|
UnPause();
|
|
|
|
break;
|
|
|
|
case SCMD_PLACE_LISTENER:
|
2012-11-26 18:58:24 +00:00
|
|
|
{
|
|
|
|
idVec3 origin;
|
|
|
|
idMat3 axis;
|
|
|
|
int listenerId;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
readDemo->ReadVec3( origin );
|
|
|
|
readDemo->ReadMat3( axis );
|
|
|
|
readDemo->ReadInt( listenerId );
|
|
|
|
|
|
|
|
PlaceListener( origin, axis, listenerId );
|
|
|
|
};
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
case SCMD_ALLOC_EMITTER:
|
2012-11-26 18:58:24 +00:00
|
|
|
{
|
|
|
|
readDemo->ReadInt( index );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( index < 1 || index > emitters.Num() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Error( "idSoundWorldLocal::ProcessDemoCommand: bad emitter number" );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( index == emitters.Num() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// append a brand new one
|
|
|
|
AllocSoundEmitter();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
case SCMD_FREE:
|
2012-11-26 18:58:24 +00:00
|
|
|
{
|
|
|
|
int immediate;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
readDemo->ReadInt( index );
|
|
|
|
readDemo->ReadInt( immediate );
|
|
|
|
EmitterForIndex( index )->Free( immediate != 0 );
|
|
|
|
}
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
case SCMD_UPDATE:
|
2012-11-26 18:58:24 +00:00
|
|
|
{
|
|
|
|
idVec3 origin;
|
|
|
|
int listenerId;
|
|
|
|
soundShaderParms_t parms;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
readDemo->ReadInt( index );
|
|
|
|
readDemo->ReadVec3( origin );
|
|
|
|
readDemo->ReadInt( listenerId );
|
|
|
|
readDemo->ReadFloat( parms.minDistance );
|
|
|
|
readDemo->ReadFloat( parms.maxDistance );
|
|
|
|
readDemo->ReadFloat( parms.volume );
|
|
|
|
readDemo->ReadFloat( parms.shakes );
|
|
|
|
readDemo->ReadInt( parms.soundShaderFlags );
|
|
|
|
readDemo->ReadInt( parms.soundClass );
|
|
|
|
EmitterForIndex( index )->UpdateEmitter( origin, listenerId, &parms );
|
|
|
|
}
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
case SCMD_START:
|
2012-11-26 18:58:24 +00:00
|
|
|
{
|
2012-11-28 15:47:07 +00:00
|
|
|
const idSoundShader* shader;
|
2012-11-26 18:58:24 +00:00
|
|
|
int channel;
|
|
|
|
float diversity;
|
|
|
|
int shaderFlags;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
readDemo->ReadInt( index );
|
|
|
|
shader = declManager->FindSound( readDemo->ReadHashString() );
|
|
|
|
readDemo->ReadInt( channel );
|
|
|
|
readDemo->ReadFloat( diversity );
|
|
|
|
readDemo->ReadInt( shaderFlags );
|
2012-11-28 15:47:07 +00:00
|
|
|
EmitterForIndex( index )->StartSound( shader, ( s_channelType )channel, diversity, shaderFlags );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
case SCMD_MODIFY:
|
2012-11-26 18:58:24 +00:00
|
|
|
{
|
|
|
|
int channel;
|
|
|
|
soundShaderParms_t parms;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
readDemo->ReadInt( index );
|
|
|
|
readDemo->ReadInt( channel );
|
|
|
|
readDemo->ReadFloat( parms.minDistance );
|
|
|
|
readDemo->ReadFloat( parms.maxDistance );
|
|
|
|
readDemo->ReadFloat( parms.volume );
|
|
|
|
readDemo->ReadFloat( parms.shakes );
|
|
|
|
readDemo->ReadInt( parms.soundShaderFlags );
|
|
|
|
readDemo->ReadInt( parms.soundClass );
|
2012-11-28 15:47:07 +00:00
|
|
|
EmitterForIndex( index )->ModifySound( ( s_channelType )channel, &parms );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
case SCMD_STOP:
|
2012-11-26 18:58:24 +00:00
|
|
|
{
|
|
|
|
int channel;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
readDemo->ReadInt( index );
|
|
|
|
readDemo->ReadInt( channel );
|
2012-11-28 15:47:07 +00:00
|
|
|
EmitterForIndex( index )->StopSound( ( s_channelType )channel );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
case SCMD_FADE:
|
2012-11-26 18:58:24 +00:00
|
|
|
{
|
|
|
|
int channel;
|
|
|
|
float to, over;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
readDemo->ReadInt( index );
|
|
|
|
readDemo->ReadInt( channel );
|
|
|
|
readDemo->ReadFloat( to );
|
|
|
|
readDemo->ReadFloat( over );
|
2012-11-28 15:47:07 +00:00
|
|
|
EmitterForIndex( index )->FadeSound( ( s_channelType )channel, to, over );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
idSoundWorldLocal::AVIOpen
|
|
|
|
=================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::AVIOpen( const char*, const char* )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
idSoundWorldLocal::AVIClose
|
|
|
|
=================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::AVIClose()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
idSoundWorldLocal::WriteToSaveGame
|
|
|
|
=================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::WriteToSaveGame( idFile* savefile )
|
|
|
|
{
|
|
|
|
struct helper
|
|
|
|
{
|
|
|
|
static void WriteSoundFade( idFile* savefile, idSoundFade& sf )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->WriteInt( sf.fadeStartTime );
|
|
|
|
savefile->WriteInt( sf.fadeEndTime );
|
|
|
|
savefile->WriteFloat( sf.fadeStartVolume );
|
|
|
|
savefile->WriteFloat( sf.fadeEndVolume );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
static void WriteShaderParms( idFile* savefile, soundShaderParms_t& parms )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->WriteFloat( parms.minDistance );
|
|
|
|
savefile->WriteFloat( parms.maxDistance );
|
|
|
|
savefile->WriteFloat( parms.volume );
|
|
|
|
savefile->WriteFloat( parms.shakes );
|
|
|
|
savefile->WriteInt( parms.soundShaderFlags );
|
|
|
|
savefile->WriteInt( parms.soundClass );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
savefile->WriteInt( GetSoundTime() );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
helper::WriteSoundFade( savefile, volumeFade );
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int c = 0; c < SOUND_MAX_CLASSES; c++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
helper::WriteSoundFade( savefile, soundClassFade[c] );
|
|
|
|
}
|
|
|
|
savefile->WriteFloat( slowmoSpeed );
|
|
|
|
savefile->WriteBool( enviroSuitActive );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->WriteMat3( listener.axis );
|
|
|
|
savefile->WriteVec3( listener.pos );
|
|
|
|
savefile->WriteInt( listener.id );
|
|
|
|
savefile->WriteInt( listener.area );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->WriteFloat( shakeAmp );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int num = emitters.Num();
|
|
|
|
savefile->WriteInt( num );
|
|
|
|
// Start at 1 because the local sound emitter is not saved
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int e = 1; e < emitters.Num(); e++ )
|
|
|
|
{
|
|
|
|
idSoundEmitterLocal* emitter = emitters[e];
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->WriteBool( emitter->canFree );
|
|
|
|
savefile->WriteVec3( emitter->origin );
|
|
|
|
savefile->WriteInt( emitter->emitterId );
|
|
|
|
helper::WriteShaderParms( savefile, emitter->parms );
|
|
|
|
savefile->WriteInt( emitter->channels.Num() );
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int c = 0; c < emitter->channels.Num(); c++ )
|
|
|
|
{
|
|
|
|
idSoundChannel* channel = emitter->channels[c];
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->WriteInt( channel->startTime );
|
|
|
|
savefile->WriteInt( channel->endTime );
|
|
|
|
savefile->WriteInt( channel->logicalChannel );
|
|
|
|
savefile->WriteBool( channel->allowSlow );
|
|
|
|
helper::WriteShaderParms( savefile, channel->parms );
|
|
|
|
helper::WriteSoundFade( savefile, channel->volumeFade );
|
|
|
|
savefile->WriteString( channel->soundShader->GetName() );
|
|
|
|
int leadin = -1;
|
|
|
|
int looping = -1;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < channel->soundShader->entries.Num(); i++ )
|
|
|
|
{
|
|
|
|
if( channel->soundShader->entries[i] == channel->leadinSample )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
leadin = i;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( channel->soundShader->entries[i] == channel->loopingSample )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
looping = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
savefile->WriteInt( leadin );
|
|
|
|
savefile->WriteInt( looping );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
idSoundWorldLocal::ReadFromSaveGame
|
|
|
|
=================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::ReadFromSaveGame( idFile* savefile )
|
|
|
|
{
|
|
|
|
struct helper
|
|
|
|
{
|
|
|
|
static void ReadSoundFade( idFile* savefile, idSoundFade& sf, int timeDelta )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->ReadInt( sf.fadeStartTime );
|
|
|
|
savefile->ReadInt( sf.fadeEndTime );
|
|
|
|
savefile->ReadFloat( sf.fadeStartVolume );
|
|
|
|
savefile->ReadFloat( sf.fadeEndVolume );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( sf.fadeEndTime > 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
sf.fadeStartTime += timeDelta;
|
|
|
|
sf.fadeEndTime += timeDelta;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
static void ReadShaderParms( idFile* savefile, soundShaderParms_t& parms )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->ReadFloat( parms.minDistance );
|
|
|
|
savefile->ReadFloat( parms.maxDistance );
|
|
|
|
savefile->ReadFloat( parms.volume );
|
|
|
|
savefile->ReadFloat( parms.shakes );
|
|
|
|
savefile->ReadInt( parms.soundShaderFlags );
|
|
|
|
savefile->ReadInt( parms.soundClass );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
int oldSoundTime = 0;
|
|
|
|
savefile->ReadInt( oldSoundTime );
|
|
|
|
int timeDelta = GetSoundTime() - oldSoundTime;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
helper::ReadSoundFade( savefile, volumeFade, timeDelta );
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int c = 0; c < SOUND_MAX_CLASSES; c++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
helper::ReadSoundFade( savefile, soundClassFade[c], timeDelta );
|
|
|
|
}
|
|
|
|
savefile->ReadFloat( slowmoSpeed );
|
|
|
|
savefile->ReadBool( enviroSuitActive );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->ReadMat3( listener.axis );
|
|
|
|
savefile->ReadVec3( listener.pos );
|
|
|
|
savefile->ReadInt( listener.id );
|
|
|
|
savefile->ReadInt( listener.area );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->ReadFloat( shakeAmp );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int numEmitters = 0;
|
|
|
|
savefile->ReadInt( numEmitters );
|
|
|
|
ClearAllSoundEmitters();
|
|
|
|
idStr shaderName;
|
|
|
|
// Start at 1 because the local sound emitter is not saved
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int e = 1; e < numEmitters; e++ )
|
|
|
|
{
|
|
|
|
idSoundEmitterLocal* emitter = ( idSoundEmitterLocal* )AllocSoundEmitter();
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( emitter == emitters[e] );
|
|
|
|
assert( emitter->index == e );
|
|
|
|
assert( emitter->soundWorld == this );
|
|
|
|
assert( emitter->channels.Num() == 0 );
|
|
|
|
savefile->ReadBool( emitter->canFree );
|
|
|
|
savefile->ReadVec3( emitter->origin );
|
|
|
|
savefile->ReadInt( emitter->emitterId );
|
|
|
|
helper::ReadShaderParms( savefile, emitter->parms );
|
|
|
|
int numChannels = 0;
|
|
|
|
savefile->ReadInt( numChannels );
|
|
|
|
emitter->channels.SetNum( numChannels );
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int c = 0; c < numChannels; c++ )
|
|
|
|
{
|
|
|
|
idSoundChannel* channel = AllocSoundChannel();
|
2012-11-26 18:58:24 +00:00
|
|
|
emitter->channels[c] = channel;
|
|
|
|
channel->emitter = emitter;
|
|
|
|
savefile->ReadInt( channel->startTime );
|
|
|
|
savefile->ReadInt( channel->endTime );
|
|
|
|
savefile->ReadInt( channel->logicalChannel );
|
|
|
|
savefile->ReadBool( channel->allowSlow );
|
|
|
|
helper::ReadShaderParms( savefile, channel->parms );
|
|
|
|
helper::ReadSoundFade( savefile, channel->volumeFade, timeDelta );
|
|
|
|
savefile->ReadString( shaderName );
|
|
|
|
channel->soundShader = declManager->FindSound( shaderName );
|
|
|
|
int leadin = 0;
|
|
|
|
int looping = 0;
|
|
|
|
savefile->ReadInt( leadin );
|
|
|
|
savefile->ReadInt( looping );
|
|
|
|
// If the leadin entry is not valid (possible if the shader changed after saving) then the looping entry can't be valid either
|
2012-11-28 15:47:07 +00:00
|
|
|
if( leadin >= 0 && leadin < channel->soundShader->entries.Num() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
channel->leadinSample = channel->soundShader->entries[ leadin ];
|
2012-11-28 15:47:07 +00:00
|
|
|
if( looping >= 0 && looping < channel->soundShader->entries.Num() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
channel->loopingSample = channel->soundShader->entries[ looping ];
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
channel->leadinSample = NULL;
|
|
|
|
channel->loopingSample = NULL;
|
|
|
|
}
|
|
|
|
channel->startTime += timeDelta;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( channel->endTime == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// Do nothing, endTime == 0 means loop forever
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( channel->endTime <= oldSoundTime )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// Channel already stopped
|
|
|
|
channel->endTime = 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
channel->endTime += timeDelta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
idSoundWorldLocal::FadeSoundClasses
|
|
|
|
|
|
|
|
fade all sounds in the world with a given shader soundClass
|
|
|
|
to is in Db, over is in seconds
|
|
|
|
=================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::FadeSoundClasses( const int soundClass, const float to, const float over )
|
|
|
|
{
|
|
|
|
if( soundClass < 0 || soundClass >= SOUND_MAX_CLASSES )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Error( "idSoundWorldLocal::FadeSoundClasses: bad soundClass %i", soundClass );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
soundClassFade[ soundClass ].Fade( to, SEC2MS( over ), GetSoundTime() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
idSoundWorldLocal::SetSlowmoSpeed
|
|
|
|
=================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::SetSlowmoSpeed( float speed )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
slowmoSpeed = speed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
idSoundWorldLocal::SetEnviroSuit
|
|
|
|
=================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSoundWorldLocal::SetEnviroSuit( bool active )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
enviroSuitActive = active;
|
|
|
|
}
|