bank.cc
Go to the documentation of this file.00001
00002
00003
00004
00005 #include "vfx/bank.h"
00006 #include "foundation/factory.h"
00007
00008 namespace VFX
00009 {
00010 ImplementRtti(VFX::Bank, Foundation::RefCounted);
00011 ImplementFactory(VFX::Bank);
00012
00013
00016 Bank::Bank()
00017 {
00018
00019 }
00020
00021
00024 Bank::~Bank()
00025 {
00026
00027 }
00028
00029
00030
00036 bool
00037 Bank::Open()
00038 {
00039 if (!this->xmlSpreadSheet.Open())
00040 {
00041 n_error("VFX::Bank::Open(): failed to load '%s'", this->xmlSpreadSheet.GetFilename().Get());
00042 return false;
00043 }
00044
00045 nXmlTable& xmlTable = this->xmlSpreadSheet.TableAt(0);
00046 int numRows = xmlTable.NumRows();
00047 n_assert(numRows >= 1);
00048 int numSounds = numRows - 1;
00049
00050 int effectIndex;
00051 for (effectIndex = 0; effectIndex < numSounds; effectIndex++)
00052 {
00053 int rowIndex = effectIndex + 1;
00054
00055
00056 const nString& name = xmlTable.Cell(rowIndex, "Name").AsString();
00057 const nString& gfxResource = xmlTable.Cell(rowIndex, "File").AsString();
00058 float timeout = xmlTable.Cell(rowIndex, "Timeout").AsFloat();
00059 this->AddEffect(name, gfxResource, timeout);
00060 }
00061 return true;
00062 }
00063
00064
00065
00069 void
00070 Bank::Close()
00071 {
00072 this->xmlSpreadSheet.Close();
00073 }
00074
00075
00076
00082 Effect*
00083 Bank::FindEffect(const nString& name)
00084 {
00085 n_assert(name.IsValid());
00086 int i;
00087 int num = this->effectArray.Size();
00088 for (i = 0; i < num; i++)
00089 {
00090 if (name == this->effectArray[i]->GetName())
00091 {
00092 return this->effectArray[i];
00093 }
00094 }
00095
00096 return 0;
00097 }
00098
00099
00107 void
00108 Bank::AddEffect(const nString& effectName, const nString& resourceName, nTime duration)
00109 {
00110 n_assert(effectName.IsValid());
00111 n_assert(resourceName.IsValid());
00112 n_assert(duration > 0.0);
00113
00114
00115 n_assert(!this->FindEffect(effectName));
00116
00117
00118 Effect* newEffect = Effect::Create();
00119 newEffect->SetName(effectName);
00120 newEffect->SetResourceName(resourceName);
00121 newEffect->SetDuration(duration);
00122 this->effectArray.Append(newEffect);
00123 }
00124
00125
00133 Effect*
00134 Bank::CreateEffect(const nString& templateEffectName, const matrix44& transform)
00135 {
00136 n_assert(templateEffectName.IsValid());
00137 Effect* templateEffect = this->FindEffect(templateEffectName);
00138 if (templateEffect)
00139 {
00140 Effect* newEffect = n_new(Effect(*templateEffect));
00141 newEffect->SetTransform(transform);
00142 return newEffect;
00143 }
00144 else
00145 {
00146 return 0;
00147 }
00148 }
00149
00150 }