datablock-temp-clone -- Implements creation of temporary datablock clones to allow late substitution of datablock fields.

This commit is contained in:
Marc Chapman 2017-07-26 21:10:43 +01:00
parent 0b84fccdd2
commit f9f05f154f
24 changed files with 865 additions and 11 deletions

View file

@ -20,6 +20,10 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
// Copyright (C) 2015 Faust Logic, Inc.
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
#include "platform/platform.h"
#include "sfx/sfxDescription.h"
@ -176,6 +180,37 @@ SFXDescription::SFXDescription( const SFXDescription& desc )
//-----------------------------------------------------------------------------
SFXDescription::SFXDescription(const SFXDescription& other, bool temp_clone)
: SimDataBlock(other, temp_clone),
mVolume( other.mVolume ),
mPitch( other.mPitch ),
mIsLooping( other.mIsLooping ),
mIsStreaming( other.mIsStreaming ),
mIs3D( other.mIs3D ),
mUseHardware( other.mUseHardware ),
mMinDistance( other.mMinDistance ),
mMaxDistance( other.mMaxDistance ),
mConeInsideAngle( other.mConeInsideAngle ),
mConeOutsideAngle( other.mConeOutsideAngle ),
mConeOutsideVolume( other.mConeOutsideVolume ),
mRolloffFactor( other.mRolloffFactor ),
mSourceGroup( other.mSourceGroup ),
mFadeInTime( other.mFadeInTime ),
mFadeOutTime( other.mFadeOutTime ),
mFadeInEase( other.mFadeInEase ),
mFadeOutEase( other.mFadeOutEase ),
mFadeLoops( other.mFadeLoops ),
mStreamPacketSize( other.mStreamPacketSize ),
mStreamReadAhead( other.mStreamReadAhead ),
mUseReverb( other.mUseReverb ),
mReverb( other.mReverb ),
mPriority( other.mPriority ),
mScatterDistance( other.mScatterDistance )
{
for( U32 i = 0; i < MaxNumParameters; ++ i )
mParameters[ i ] = other.mParameters[ i ];
}
void SFXDescription::initPersistFields()
{
addGroup( "Playback" );

View file

@ -20,6 +20,10 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
// Copyright (C) 2015 Faust Logic, Inc.
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
#ifndef _SFXDESCRIPTION_H_
#define _SFXDESCRIPTION_H_
@ -192,6 +196,9 @@ class SFXDescription : public SimDataBlock
/// Validates the description fixing any
/// parameters that are out of range.
void validate();
public:
SFXDescription(const SFXDescription&, bool);
virtual bool allowSubstitutions() const { return true; }
};

View file

@ -24,6 +24,7 @@
// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
// Copyright (C) 2015 Faust Logic, Inc.
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
#include "platform/platform.h"
#include "sfx/sfxProfile.h"
@ -96,9 +97,6 @@ SFXProfile::SFXProfile( SFXDescription* desc, const String& filename, bool prelo
//-----------------------------------------------------------------------------
SFXProfile::~SFXProfile()
{
}
//-----------------------------------------------------------------------------
@ -380,3 +378,95 @@ DefineEngineMethod( SFXProfile, getSoundDuration, F32, (),,
{
return ( F32 ) object->getSoundDuration() * 0.001f;
}
// enable this to help verify that temp-clones of AudioProfile are being deleted
//#define TRACK_AUDIO_PROFILE_CLONES
#ifdef TRACK_AUDIO_PROFILE_CLONES
static int audio_prof_clones = 0;
#endif
SFXProfile::SFXProfile(const SFXProfile& other, bool temp_clone) : SFXTrack(other, temp_clone)
{
#ifdef TRACK_AUDIO_PROFILE_CLONES
audio_prof_clones++;
if (audio_prof_clones == 1)
Con::errorf("SFXProfile -- Clones are on the loose!");
#endif
mResource = other.mResource;
mFilename = other.mFilename;
mPreload = other.mPreload;
mBuffer = other.mBuffer; // -- AudioBuffer loaded using mFilename
mChangedSignal = other.mChangedSignal;
}
SFXProfile::~SFXProfile()
{
if (!isTempClone())
return;
// cleanup after a temp-clone
if (mDescription && mDescription->isTempClone())
{
delete mDescription;
mDescription = 0;
}
#ifdef TRACK_AUDIO_PROFILE_CLONES
if (audio_prof_clones > 0)
{
audio_prof_clones--;
if (audio_prof_clones == 0)
Con::errorf("SFXProfile -- Clones eliminated!");
}
else
Con::errorf("SFXProfile -- Too many clones deleted!");
#endif
}
// Clone and perform substitutions on the SFXProfile and on any SFXDescription
// it references.
SFXProfile* SFXProfile::cloneAndPerformSubstitutions(const SimObject* owner, S32 index)
{
if (!owner)
return this;
SFXProfile* sub_profile_db = this;
// look for mDescriptionObject subs
SFXDescription* desc_db;
if (mDescription && mDescription->getSubstitutionCount() > 0)
{
SFXDescription* orig_db = mDescription;
desc_db = new SFXDescription(*orig_db, true);
orig_db->performSubstitutions(desc_db, owner, index);
}
else
desc_db = 0;
if (this->getSubstitutionCount() > 0 || desc_db)
{
sub_profile_db = new SFXProfile(*this, true);
performSubstitutions(sub_profile_db, owner, index);
if (desc_db)
sub_profile_db->mDescription = desc_db;
}
return sub_profile_db;
}
void SFXProfile::onPerformSubstitutions()
{
if ( SFX )
{
// If preload is enabled we load the resource
// and device buffer now to avoid a delay on
// first playback.
if ( mPreload && !_preloadBuffer() )
Con::errorf( "SFXProfile(%s)::onPerformSubstitutions: The preload failed!", getName() );
// We need to get device change notifications.
SFX->getEventSignal().notify( this, &SFXProfile::_onDeviceEvent );
}
}

View file

@ -20,6 +20,11 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
// Copyright (C) 2015 Faust Logic, Inc.
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
#ifndef _SFXPROFILE_H_
#define _SFXPROFILE_H_
@ -175,6 +180,11 @@ class SFXProfile : public SFXTrack
///
ChangedSignal& getChangedSignal() { return mChangedSignal; }
public:
/*C*/ SFXProfile(const SFXProfile&, bool = false);
SFXProfile* cloneAndPerformSubstitutions(const SimObject*, S32 index=0);
virtual void onPerformSubstitutions();
virtual bool allowSubstitutions() const { return true; }
};

View file

@ -20,6 +20,10 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
// Copyright (C) 2015 Faust Logic, Inc.
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
#include "sfx/sfxTrack.h"
#include "sfx/sfxTypes.h"
#include "sfx/sfxDescription.h"
@ -65,6 +69,11 @@ SFXTrack::SFXTrack( SFXDescription* description )
dMemset( mParameters, 0, sizeof( mParameters ) );
}
SFXTrack::SFXTrack(const SFXTrack& other, bool temp_clone) : SimDataBlock(other, temp_clone)
{
mDescription = other.mDescription;
dMemcpy(mParameters, other.mParameters, sizeof(mParameters));
}
//-----------------------------------------------------------------------------
void SFXTrack::initPersistFields()

View file

@ -20,6 +20,10 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
// Copyright (C) 2015 Faust Logic, Inc.
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
#ifndef _SFXTRACK_H_
#define _SFXTRACK_H_
@ -92,6 +96,8 @@ class SFXTrack : public SimDataBlock
DECLARE_CONOBJECT( SFXTrack );
DECLARE_CATEGORY( "SFX" );
DECLARE_DESCRIPTION( "Abstract base class for any kind of data that can be turned into SFXSources." );
public:
/*C*/ SFXTrack(const SFXTrack&, bool = false);
};
#endif // !_SFXTRACK_H_