#include <context_sound.h>
Inheritance diagram for NLSOUND::CContextSoundContainer< NbJoker, UseRandom, Shift >:
Private Types | |
enum | { JOKER_ARRAY_SIZE = (NbJoker == 0 ? 1 : NbJoker) } |
typedef std::hash_map< CContextMatcher< NbJoker, UseRandom, Shift >, CSound *, CContextMatcher< NbJoker, UseRandom, Shift >::CHash > | THashContextSound |
Private Member Functions | |
virtual void | addSound (CSound *sound, const std::string &baseName) |
virtual float | getMaxDistance () const |
virtual CSound * | getSound (const CSoundContext &context, uint32 randomValue) |
void | getSoundList (std::vector< std::pair< std::string, CSound * > > &subsounds) const |
virtual void | init (uint *contextArgsIndex) |
Private Attributes | |
uint32 | _ContextArgsIndex [JOKER_ARRAY_SIZE] |
THashContextSound | _ContextSounds |
float | _MaxDist |
|
Definition at line 123 of file context_sound.h. |
|
Definition at line 117 of file context_sound.h.
00118 { 00119 // Size of array : special case for 0 joker because we can't declare array of 0 elements 00120 JOKER_ARRAY_SIZE = (NbJoker == 0 ? 1 : NbJoker) 00121 }; |
|
Implements NLSOUND::IContextSoundContainer. Definition at line 136 of file context_sound.h. References NLSOUND::CContextSoundContainer< NbJoker, UseRandom, Shift >::_ContextSounds, NLSOUND::CSound::getMaxDistance(), NLSOUND::CSound::getName(), nlassert, nldebug, nlwarning, uint, and uint32.
00137 { 00138 const std::string &patternName = CStringMapper::unmap(sound->getName()); 00139 nlassert(patternName.size() >= baseName.size()); 00140 00141 std::string arg; 00142 uint32 args[JOKER_ARRAY_SIZE]; 00143 00144 _MaxDist = std::max(sound->getMaxDistance(), _MaxDist); 00145 00146 // extract the context values 00147 std::string::const_iterator first(patternName.begin() + baseName.size()), last(patternName.end()); 00148 // std::string::const_iterator first2(baseName.begin()), last2(baseName.end()); 00149 // 1st, skip the base name 00150 // for (; first == first2; ++first, ++first2); 00151 00152 // 2nd, read all the joker values 00153 uint i; 00154 for ( i=0; i<NbJoker && first != last; ++first) 00155 { 00156 if (isdigit(int(*first))) 00157 { 00158 arg += *first; 00159 } 00160 else if (!arg.empty()) 00161 { 00162 // end of the argument. 00163 args[i++] = atoi(arg.c_str()); 00164 arg = ""; 00165 } 00166 } 00167 // read the potential last arg. 00168 if (!arg.empty()) 00169 { 00170 // end of the argument. 00171 args[i++] = atoi(arg.c_str()); 00172 arg = ""; 00173 } 00174 00175 if (i != NbJoker) 00176 return; 00177 nlassert(i==NbJoker); 00178 00179 int randomValue; 00180 if (UseRandom) 00181 { 00182 bool ok = false; 00183 // 3rd, read the random value (if any) 00184 for (uint i=0; first != last; ++first) 00185 { 00186 if (isdigit(int(*first))) 00187 { 00188 arg += *first; 00189 } 00190 else if (!arg.empty()) 00191 { 00192 nlassert (ok == false); 00193 // end of the argument. 00194 randomValue = atoi(arg.c_str()); 00195 arg = ""; 00196 ok = true; 00197 } 00198 } 00199 // read the potential last arg. 00200 if (!arg.empty()) 00201 { 00202 nlassert (ok == false); 00203 // end of the argument. 00204 randomValue = atoi(arg.c_str()); 00205 arg = ""; 00206 ok = true; 00207 } 00208 nlassert (ok == true); 00209 00210 } 00211 else 00212 { 00213 randomValue = 0; 00214 } 00215 00216 // ok, now create the key and store the sound. 00217 CContextMatcher<NbJoker, UseRandom, Shift> cm(args, randomValue); 00218 00219 #ifdef _DEBUG 00220 char tmp[1024]; 00221 char tmp2[1024]; 00222 00223 smprintf(tmp, 1024, "Adding sound : %s, args = ", patternName.c_str()); 00224 00225 for (uint k=0; k<NbJoker; ++k) 00226 { 00227 sprintf(tmp2, "%u", args[k]); 00228 strcat(tmp, tmp2); 00229 } 00230 00231 nldebug(tmp); 00232 00233 #endif 00234 00235 std::pair<THashContextSound::iterator, bool> ret; 00236 ret = _ContextSounds.insert(std::make_pair(cm, sound)); 00237 if (!ret.second) 00238 { 00239 THashContextSound::iterator it = _ContextSounds.find(cm); 00240 nlassert(it != _ContextSounds.end()); 00241 00242 nlwarning("Sound %s has the same context matcher as the sound %s", CStringMapper::unmap(sound->getName()).c_str(), CStringMapper::unmap(it->second->getName()).c_str()); 00243 } 00244 } |
|
Implements NLSOUND::IContextSoundContainer. Definition at line 131 of file context_sound.h.
00132 { 00133 return _MaxDist; 00134 } |
|
Implements NLSOUND::IContextSoundContainer. Definition at line 246 of file context_sound.h. References NLSOUND::CContextSoundContainer< NbJoker, UseRandom, Shift >::_ContextArgsIndex, NLSOUND::CContextSoundContainer< NbJoker, UseRandom, Shift >::_ContextSounds, NLSOUND::CSoundContext::Args, uint, and uint32.
00247 { 00248 // create a key 00249 uint32 args[JOKER_ARRAY_SIZE]; 00250 for (uint i=0; i<NbJoker; ++i) 00251 args[i] = context.Args[_ContextArgsIndex[i]]; 00252 00253 CContextMatcher<NbJoker, UseRandom, Shift> cm(args, randomValue); 00254 00255 THashContextSound::iterator it = _ContextSounds.find(cm); 00256 00257 if (it != _ContextSounds.end()) 00258 return it->second; 00259 else 00260 return 0; 00261 } |
|
Implements NLSOUND::IContextSoundContainer. Definition at line 263 of file context_sound.h. References NLSOUND::CContextSoundContainer< NbJoker, UseRandom, Shift >::_ContextSounds.
00264 { 00265 THashContextSound::const_iterator first(_ContextSounds.begin()), last(_ContextSounds.end()); 00266 for (; first != last; ++first) 00267 { 00268 subsounds.push_back(std::make_pair(CStringMapper::unmap(first->second->getName()), first->second)); 00269 } 00270 } |
|
Implements NLSOUND::IContextSoundContainer. Definition at line 125 of file context_sound.h. References NLSOUND::CContextSoundContainer< NbJoker, UseRandom, Shift >::_ContextArgsIndex, NLMISC::CFastMem::memcpy, and uint.
00126 { 00127 _MaxDist = 0; 00128 NLMISC::CFastMem::memcpy(_ContextArgsIndex, contextArgsIndex, sizeof(uint) * NbJoker); 00129 } |
|
Definition at line 273 of file context_sound.h. Referenced by NLSOUND::CContextSoundContainer< NbJoker, UseRandom, Shift >::getSound(), and NLSOUND::CContextSoundContainer< NbJoker, UseRandom, Shift >::init(). |
|
|
Definition at line 275 of file context_sound.h. |