Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 11 additions & 25 deletions Engine/source/T3D/assets/SoundAsset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,6 @@ SoundAsset::SoundAsset()

SoundAsset::~SoundAsset()
{

for (U32 i = 0; i < SFXPlayList::NUM_SLOTS; i++)
{
if(mSFXProfile[i].isProperlyAdded() && !mSFXProfile[i].isDeleted())
mSFXProfile[i].unregisterObject();
}

if (mPlaylist.isProperlyAdded() && !mPlaylist.isDeleted())
mPlaylist.unregisterObject();
Expand Down Expand Up @@ -404,22 +398,17 @@ U32 SoundAsset::load()
{
Con::errorf("SoundAsset::initializeAsset: Attempted to load file %s but it was not valid!", mSoundFile[i]);
mLoadedState = BadFileReference;
mSFXProfile[i].setDescription(NULL);
mSFXProfile[i].setSoundFileName(StringTable->insert(StringTable->EmptyString()));
mSFXProfile[i].setPreload(false);
return mLoadedState;
}
else
{
SFXProfile* trackProfile = new SFXProfile();
trackProfile->setDescription(&mProfileDesc);
trackProfile->setSoundFileName(mSoundPath[i]);
trackProfile->setPreload(mPreload);
mSFXProfile[i] = new SFXProfile;
mSFXProfile[i]->setDescription(&mProfileDesc);
mSFXProfile[i]->setSoundFileName(mSoundPath[i]);
mSFXProfile[i]->setPreload(mPreload);
mSFXProfile[i]->registerObject(String::ToString("%s_profile_track%d", getAssetName()).c_str());

mSFXProfile[i] = *trackProfile;
mSFXProfile[i].registerObject(String::ToString("%s_profile_track%d", getAssetName()).c_str());

mPlaylist.mSlots.mTrack[i] = trackProfile;
mPlaylist.mSlots.mTrack[i] = mSFXProfile[i];

}
}
Expand All @@ -436,18 +425,15 @@ U32 SoundAsset::load()
{
Con::errorf("SoundAsset::initializeAsset: Attempted to load file %s but it was not valid!", mSoundFile[0]);
mLoadedState = BadFileReference;
mSFXProfile[0].setDescription(NULL);
mSFXProfile[0].setSoundFileName(StringTable->insert(StringTable->EmptyString()));
mSFXProfile[0].setPreload(false);
return mLoadedState;
}
else
{
mSFXProfile[0].setDescription(&mProfileDesc);
mSFXProfile[0].setSoundFileName(mSoundPath[0]);
mSFXProfile[0].setPreload(mPreload);

mSFXProfile[0].registerObject(String::ToString("%s_profile", getAssetName()).c_str());
mSFXProfile[0] = new SFXProfile;
mSFXProfile[0]->setDescription(&mProfileDesc);
mSFXProfile[0]->setSoundFileName(mSoundPath[0]);
mSFXProfile[0]->setPreload(mPreload);
mSFXProfile[0]->registerObject(String::ToString("%s_profile", getAssetName()).c_str());
}

}
Expand Down
12 changes: 6 additions & 6 deletions Engine/source/T3D/assets/SoundAsset.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ class SoundAsset : public AssetBase
typedef AssetPtr<SoundAsset> ConcreteAssetPtr;

protected:
StringTableEntry mSoundFile[SFXPlayList::SFXPlaylistSettings::NUM_SLOTS];
StringTableEntry mSoundPath[SFXPlayList::SFXPlaylistSettings::NUM_SLOTS];
SFXProfile mSFXProfile[SFXPlayList::SFXPlaylistSettings::NUM_SLOTS];
StringTableEntry mSoundFile[SFXPlayList::SFXPlaylistSettings::NUM_SLOTS];
StringTableEntry mSoundPath[SFXPlayList::SFXPlaylistSettings::NUM_SLOTS];
SimObjectPtr<SFXProfile> mSFXProfile[SFXPlayList::SFXPlaylistSettings::NUM_SLOTS];

SFXDescription mProfileDesc;
SFXPlayList mPlaylist;
Expand Down Expand Up @@ -150,17 +150,17 @@ class SoundAsset : public AssetBase
void copyTo(SimObject* object) override;

//SFXResource* getSound() { return mSoundResource; }
Resource<SFXResource> getSoundResource(const U32 slotId = 0) { load(); return mSFXProfile[slotId].getResource(); }
Resource<SFXResource> getSoundResource(const U32 slotId = 0) { load(); return mSFXProfile[slotId]->getResource(); }

/// Declare Console Object.
DECLARE_CONOBJECT(SoundAsset);

static bool _setSoundFile(void* object, const char* index, const char* data);
U32 load() override;
inline StringTableEntry getSoundPath(const U32 slotId = 0) const { return mSoundPath[slotId]; };
SFXProfile* getSfxProfile(const U32 slotId = 0) { return &mSFXProfile[slotId]; }
SFXProfile* getSfxProfile(const U32 slotId = 0) { return mSFXProfile[slotId]; }
SFXPlayList* getSfxPlaylist() { return &mPlaylist; }
SFXTrack* getSFXTrack() { load(); return mIsPlaylist ? dynamic_cast<SFXTrack*>(&mPlaylist) : dynamic_cast<SFXTrack*>(&mSFXProfile[0]); }
SFXTrack* getSFXTrack() { load(); return mIsPlaylist ? dynamic_cast<SFXTrack*>(&mPlaylist) : dynamic_cast<SFXTrack*>(mSFXProfile[0].getPointer()); }
SFXDescription* getSfxDescription() { return &mProfileDesc; }
bool isPlaylist(){ return mIsPlaylist; }

Expand Down
75 changes: 35 additions & 40 deletions Engine/source/console/simObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
#ifndef _TAML_CALLBACKS_H_
#include "persistence/taml/tamlCallbacks.h"
#endif

#ifndef _OBJECTTYPES_H_
#include "T3D/objectTypes.h"
#endif

class Stream;
class LightManager;
Expand Down Expand Up @@ -606,6 +609,7 @@ class SimObject: public ConsoleObject, public TamlCallbacks

/// @name Events
/// @{
//virtual void onPrepare();

/// Called when the object is added to the sim.
virtual bool onAdd();
Expand Down Expand Up @@ -1045,56 +1049,47 @@ DefineBitfieldType(GameTypeMasksType);
template< typename T >
class SimObjectPtr : public WeakRefPtr< T >
{
public:
public:

typedef WeakRefPtr< T > Parent;
typedef WeakRefPtr< T > Parent;

SimObjectPtr() {}
SimObjectPtr(T *ptr) { this->mReference = NULL; set(ptr); }
SimObjectPtr( const SimObjectPtr& ref ) { this->mReference = NULL; set(ref.mReference); }

T* getObject() const { return Parent::getPointer(); }
SimObjectPtr() = default;
SimObjectPtr(T* ptr) { set(ptr); }
SimObjectPtr(const SimObjectPtr&) = default;
SimObjectPtr& operator=(const SimObjectPtr&) = default;
SimObjectPtr& operator=(T* ptr)
{
set(ptr);
return *this;
}

T* getObject() const { return Parent::getPointer(); }

~SimObjectPtr() { set((WeakRefBase::WeakReference*)NULL); }

SimObjectPtr<T>& operator=(const SimObjectPtr ref)
{
set(ref.mReference);
return *this;
}
SimObjectPtr<T>& operator=(T *ptr)
{
set(ptr);
return *this;
}

protected:
void set(WeakRefBase::WeakReference * ref)
protected:
void set(T* obj)
{
// Nothing to do if same object
if (obj && this->mWeak.lock() == obj->getWeakControl().lock())
return;

// Before overwriting, check old object for auto-delete
if (auto old_ctrl = this->mWeak.lock())
{
if( ref == this->mReference )
return;

if( this->mReference )
{
// Auto-delete
T* obj = this->getPointer();
if ( this->mReference->getRefCount() == 2 && obj && obj->isAutoDeleted() )
obj->deleteObject();

this->mReference->decRefCount();
}
this->mReference = NULL;
if( ref )
T* old_obj = getObject();
if (this->mWeak.use_count() == 1 && old_obj && old_obj->isAutoDeleted())
{
this->mReference = ref;
this->mReference->incRefCount();
old_obj->destroySelf();
}
}

void set(T * obj)
// Assign new weak reference
this->mWeak.reset();
if (obj)
{
set(obj ? obj->getWeakReference() : (WeakRefBase::WeakReference *)NULL);
auto obj_ctrl = obj->getWeakControl().lock();
this->mWeak = obj_ctrl;
}
}
};

#endif // _SIMOBJECT_H_
18 changes: 18 additions & 0 deletions Engine/source/core/util/refBase.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "refBase.h"

WeakRefBase::~WeakRefBase()
{
if (mControl)
mControl->object = NULL;
}

WeakControlBlock::WeakControlBlock(WeakRefBase* obj)
: object(obj)
{
}

WeakControlBlock::~WeakControlBlock()
{

}

Loading
Loading