Torque3D Documentation / _generateds / afxAudioBank.cpp

afxAudioBank.cpp

Engine/source/afx/ce/afxAudioBank.cpp

More...

Public Functions

ConsoleDocClass(afxAudioBank , "@brief A datablock that specifies an Audio Bank <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">effect.\n\n</a>" "<a href="/coding/class/classafxaudiobank/">afxAudioBank</a> is very similar <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the stock Torque <a href="/coding/class/classsfxprofile/">SFXProfile</a> datablock but it allows specification of up <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> 32 different sound " "files. The sound that actually plays is determined by the playIndex field." "\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "<a href="/coding/class/classafxaudiobank/">afxAudioBank</a> is most useful when used in combination with field substitutions, whereby <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> substitution statement " "assigned <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> playIndex selects <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> different sound(perhaps randomly) each time the effect is used." "\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxEffects\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )

Detailed Description

Public Functions

ConsoleDocClass(afxAudioBank , "@brief A datablock that specifies an Audio Bank <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">effect.\n\n</a>" "<a href="/coding/class/classafxaudiobank/">afxAudioBank</a> is very similar <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the stock Torque <a href="/coding/class/classsfxprofile/">SFXProfile</a> datablock but it allows specification of up <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> 32 different sound " "files. The sound that actually plays is determined by the playIndex field." "\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "<a href="/coding/class/classafxaudiobank/">afxAudioBank</a> is most useful when used in combination with field substitutions, whereby <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> substitution statement " "assigned <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> playIndex selects <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> different sound(perhaps randomly) each time the effect is used." "\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxEffects\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )

IMPLEMENT_CO_DATABLOCK_V1(afxAudioBank )

  1
  2
  3//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  4// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  5// Copyright (C) 2015 Faust Logic, Inc.
  6//
  7// Permission is hereby granted, free of charge, to any person obtaining a copy
  8// of this software and associated documentation files (the "Software"), to
  9// deal in the Software without restriction, including without limitation the
 10// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 11// sell copies of the Software, and to permit persons to whom the Software is
 12// furnished to do so, subject to the following conditions:
 13//
 14// The above copyright notice and this permission notice shall be included in
 15// all copies or substantial portions of the Software.
 16//
 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 23// IN THE SOFTWARE.
 24//
 25//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 26
 27#include "afx/arcaneFX.h"
 28
 29#include "console/consoleTypes.h"
 30#include "sim/netConnection.h"
 31#include "sfx/sfxDescription.h"
 32
 33#include "afx/ce/afxAudioBank.h"
 34
 35//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 36
 37IMPLEMENT_CO_DATABLOCK_V1(afxAudioBank);
 38
 39ConsoleDocClass( afxAudioBank,
 40   "@brief A datablock that specifies an Audio Bank effect.\n\n"
 41
 42   "afxAudioBank is very similar to the stock Torque SFXProfile datablock but it allows specification of up to 32 different sound "
 43   "files. The sound that actually plays is determined by the playIndex field."
 44   "\n\n"
 45
 46   "afxAudioBank is most useful when used in combination with field substitutions, whereby a substitution statement "
 47   "assigned to playIndex selects a different sound (perhaps randomly) each time the effect is used."
 48   "\n\n"
 49
 50   "@ingroup afxEffects\n"
 51   "@ingroup AFX\n"
 52   "@ingroup Datablocks\n"
 53);
 54
 55afxAudioBank::afxAudioBank()
 56{
 57  mPath = ST_NULLSTRING;
 58  mDescriptionObjectID = 0;
 59  mDescriptionObject = NULL;
 60  mPreload = false;
 61  play_index = -1;
 62
 63  for (S32 i = 0; i < 32; i++)
 64    mFilenames[i] = ST_NULLSTRING;
 65}
 66
 67afxAudioBank::afxAudioBank(const afxAudioBank& other, bool temp_clone) : SimDataBlock(other, temp_clone)
 68{
 69  mPath = other.mPath;
 70  mDescriptionObject = other.mDescriptionObject;
 71  mDescriptionObjectID = other.mDescriptionObjectID; // -- for pack/unpack of mDescriptionObject ptr
 72  mPreload = other.mPreload;
 73  play_index = other.play_index;
 74
 75  for (S32 i = 0; i < 32; i++)
 76    mFilenames[i] = other.mFilenames[i];
 77}
 78
 79afxAudioBank::~afxAudioBank()
 80{
 81  if (!isTempClone())
 82    return;
 83
 84  if (mDescriptionObject && mDescriptionObject->isTempClone())
 85  {
 86    delete mDescriptionObject;
 87    mDescriptionObject = 0;
 88  }
 89}
 90
 91afxAudioBank* afxAudioBank::cloneAndPerformSubstitutions(const SimObject* owner, S32 index)
 92{
 93  if (!owner)
 94    return this;
 95
 96  afxAudioBank* sub_profile_db = this;
 97
 98  SFXDescription* desc_db;
 99  if (mDescriptionObject && mDescriptionObject->getSubstitutionCount() > 0)
100  {
101    SFXDescription* orig_db = mDescriptionObject;
102    desc_db = new SFXDescription(*orig_db, true);
103    orig_db->performSubstitutions(desc_db, owner, index);
104  }
105  else
106    desc_db = 0;
107
108  if (this->getSubstitutionCount() > 0 || desc_db)
109  {
110    sub_profile_db = new afxAudioBank(*this, true);
111    performSubstitutions(sub_profile_db, owner, index);
112    if (desc_db)
113      sub_profile_db->mDescriptionObject = desc_db;
114  }
115
116  return sub_profile_db;
117}
118
119void afxAudioBank::onPerformSubstitutions() 
120{ 
121}
122
123void afxAudioBank::initPersistFields()
124{
125  addField("path",        TypeFilename,             Offset(mPath, afxAudioBank),
126    "A filesystem path to the folder containing the sound files specified by the "
127    "filenames[] field. All sound files used in a single AudioBank must be located in "
128    "the same folder.");
129  addField("filenames",   TypeString,               Offset(mFilenames, afxAudioBank), 32,
130    "Up to 32 names of sound files found in the path folder. The sound that is actually "
131    "played by an Audio Bank effect is determined by the playIndex field.");
132  addField("description", TYPEID<SFXDescription>(), Offset(mDescriptionObject, afxAudioBank),
133    "SFXDescription datablock to use with this set of sounds.");
134  addField("preload",     TypeBool,                 Offset(mPreload, afxAudioBank),
135    "If set to true, file is pre-loaded, otherwise it is loaded on-demand.");
136  addField("playIndex",   TypeS32,                  Offset(play_index, afxAudioBank),
137    "An array index that selects a sound to play from the filenames[] field. Values "
138    "outside of the range of assigned filename[] entries will not play any sound.");
139
140  Parent::initPersistFields();
141}
142
143bool afxAudioBank::preload(bool server, String &errorStr)
144{
145  if(!Parent::preload(server, errorStr))
146    return false;
147
148  return true;
149}
150
151bool afxAudioBank::onAdd()
152{
153  if (!Parent::onAdd())
154    return false;
155
156  if (!mDescriptionObject && mDescriptionObjectID)
157    Sim::findObject(mDescriptionObjectID , mDescriptionObject);
158
159  // if this is client side, make sure that description is as well
160  if(mDescriptionObject)
161  {  // client side dataBlock id's are not in the dataBlock id range
162    if (getId() >= DataBlockObjectIdFirst && getId() <= DataBlockObjectIdLast)
163    {
164      SimObjectId pid = mDescriptionObject->getId();
165      if (pid < DataBlockObjectIdFirst || pid > DataBlockObjectIdLast)
166      {
167        Con::errorf(ConsoleLogEntry::General,"afxAudioBank: data dataBlock not networkable (use datablock to create).");
168        return false;
169      }
170    }
171  }
172
173  return(true);
174}
175
176void afxAudioBank::packData(BitStream* stream)
177{
178  Parent::packData(stream);
179
180  if (stream->writeFlag(mDescriptionObject))
181    stream->writeRangedU32(mDescriptionObject->getId(), DataBlockObjectIdFirst, DataBlockObjectIdLast);
182
183  /*
184  char buffer[256];
185  if(!mFilename)
186    buffer[0] = 0;
187  else
188    dStrcpy(buffer, mFilename, 256);
189  stream->writeString(buffer);
190  */
191
192  stream->writeString(mPath);
193
194  for (S32 i = 0; i < 32; i++)
195  {
196    stream->writeString(mFilenames[i]);
197    if (mFilenames[i] == ST_NULLSTRING)
198      break;
199  }
200
201  stream->writeFlag(mPreload);
202
203  if (stream->writeFlag(play_index >= 0 && play_index < 32))
204    stream->writeInt(play_index, 5);
205}
206
207void afxAudioBank::unpackData(BitStream* stream)
208{
209  Parent::unpackData(stream);
210
211  if (stream->readFlag()) // AudioDescription
212  {
213    SimObjectId id = stream->readRangedU32(DataBlockObjectIdFirst, DataBlockObjectIdLast);
214    mDescriptionObjectID = id;
215    Sim::findObject(id, mDescriptionObject);
216  }
217
218  // Filename
219  /*
220  char buffer[256];
221  stream->readString(buffer);
222  mFilename = StringTable->insert(buffer);
223  */
224
225  char buffer[256]; 
226
227  stream->readString(buffer);
228  mPath = StringTable->insert(buffer);
229
230  for (S32 i = 0; i < 32; i++)
231  {
232    stream->readString(buffer);
233    mFilenames[i] = StringTable->insert(buffer);
234    if (mFilenames[i] == ST_NULLSTRING)
235      break;
236  }
237
238  mPreload = stream->readFlag(); // Preload
239
240  if (stream->readFlag())
241    play_index = stream->readInt(5);
242  else
243    play_index = -1;
244}
245
246//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
247
248