SoundAsset.cpp

Engine/source/T3D/assets/SoundAsset.cpp

More...

Public Functions

ConsoleSetType(TypeSoundAssetPtr )
ConsoleType(SoundAssetPtr , TypeSoundAssetPtr , SoundAsset , ASSET_ID_FIELD_PREFIX )
DefineEngineMethod(SoundAsset , getSoundPath , const char * , () , "" )

Detailed Description

Public Functions

ConsoleSetType(TypeSoundAssetPtr )

ConsoleType(SoundAssetPtr , TypeSoundAssetPtr , SoundAsset , ASSET_ID_FIELD_PREFIX )

DefineEngineMethod(SoundAsset , getSoundPath , const char * , () , "" )

IMPLEMENT_CONOBJECT(SoundAsset )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2013 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef SOUND_ASSET_H
 25#include "SoundAsset.h"
 26#endif
 27
 28#ifndef _ASSET_MANAGER_H_
 29#include "assets/assetManager.h"
 30#endif
 31
 32#ifndef _CONSOLETYPES_H_
 33#include "console/consoleTypes.h"
 34#endif
 35
 36#ifndef _TAML_
 37#include "persistence/taml/taml.h"
 38#endif
 39
 40#ifndef _ASSET_PTR_H_
 41#include "assets/assetPtr.h"
 42#endif
 43
 44// Debug Profiling.
 45#include "platform/profiler.h"
 46
 47//-----------------------------------------------------------------------------
 48
 49IMPLEMENT_CONOBJECT(SoundAsset);
 50
 51ConsoleType(SoundAssetPtr, TypeSoundAssetPtr, SoundAsset, ASSET_ID_FIELD_PREFIX)
 52
 53//-----------------------------------------------------------------------------
 54
 55ConsoleGetType(TypeSoundAssetPtr)
 56{
 57   // Fetch asset Id.
 58   return (*((AssetPtr<SoundAsset>*)dptr)).getAssetId();
 59}
 60
 61//-----------------------------------------------------------------------------
 62
 63ConsoleSetType(TypeSoundAssetPtr)
 64{
 65   // Was a single argument specified?
 66   if (argc == 1)
 67   {
 68      // Yes, so fetch field value.
 69      const char* pFieldValue = argv[0];
 70
 71      // Fetch asset pointer.
 72      AssetPtr<SoundAsset>* pAssetPtr = dynamic_cast<AssetPtr<SoundAsset>*>((AssetPtrBase*)(dptr));
 73
 74      // Is the asset pointer the correct type?
 75      if (pAssetPtr == NULL)
 76      {
 77         // No, so fail.
 78         //Con::warnf("(TypeSoundAssetPtr) - Failed to set asset Id '%d'.", pFieldValue);
 79         return;
 80      }
 81
 82      // Set asset.
 83      pAssetPtr->setAssetId(pFieldValue);
 84
 85      return;
 86   }
 87
 88   // Warn.
 89   Con::warnf("(TypeSoundAssetPtr) - Cannot set multiple args to a single asset.");
 90}
 91
 92//-----------------------------------------------------------------------------
 93
 94SoundAsset::SoundAsset()
 95{
 96   mSoundFile = StringTable->EmptyString();
 97   mSoundPath = StringTable->EmptyString();
 98
 99   mPitchAdjust = 1;
100   mVolumeAdjust = 1;
101
102   //mSound = nullptr;
103}
104
105//-----------------------------------------------------------------------------
106
107SoundAsset::~SoundAsset()
108{
109}
110
111//-----------------------------------------------------------------------------
112
113void SoundAsset::initPersistFields()
114{
115   // Call parent.
116   Parent::initPersistFields();
117
118   addProtectedField("soundFile", TypeAssetLooseFilePath, Offset(mSoundFile, SoundAsset),
119      &setSoundFile, &getSoundFile, "Path to the sound file.");
120
121   addField("pitchAdjust", TypeF32, Offset(mPitchAdjust, SoundAsset), "Adjustment of the pitch value");
122   addField("volumeAdjust", TypeF32, Offset(mVolumeAdjust, SoundAsset), "Adjustment to the volume.");
123}
124
125//------------------------------------------------------------------------------
126
127void SoundAsset::copyTo(SimObject* object)
128{
129   // Call to parent.
130   Parent::copyTo(object);
131}
132
133void SoundAsset::initializeAsset(void)
134{
135   mSoundPath = expandAssetFilePath(mSoundFile);
136}
137
138void SoundAsset::onAssetRefresh(void)
139{
140   mSoundPath = expandAssetFilePath(mSoundFile);
141}
142
143void SoundAsset::setSoundFile(const char* pSoundFile)
144{
145   // Sanity!
146   AssertFatal(pSoundFile != NULL, "Cannot use a NULL shape file.");
147
148   // Fetch image file.
149   pSoundFile = StringTable->insert(pSoundFile);
150
151   // Ignore no change,
152   if (pSoundFile == mSoundFile)
153      return;
154
155   // Update.
156   mSoundFile = StringTable->insert(pSoundFile);
157
158   // Refresh the asset.
159   refreshAsset();
160}
161
162DefineEngineMethod(SoundAsset, getSoundPath, const char*, (), , "")
163{
164   return object->getSoundPath();
165}
166