SoundFile *SoundData::GetSound (const char *name) { SoundFile *sound; sound = soundfiles.Get(csHashCompute(name), NULL); // sound is null when theres no cached SoundFile if (sound == NULL) { // we go search the library .. maybe it has it if (libsoundfiles.Contains(csHashCompute(name))) { // SoundFile is in our library, copy it sound = new SoundFile(libsoundfiles.Get(csHashCompute(name), NULL)); PutSound(sound); } else { // no such SoundFile ;( return NULL return NULL; } } // update lasttouch to keep that SoundFile in memory sound->lasttouch = csGetTicks(); return sound; }
bool PawsManager::RegisterSound(const char *name,csRef<iSndSysData> sounddata) { PawsSoundHandle *pawssndhandle; int name_hash=csHashCompute(name); // Note that a sound loader, vfs instance and renderer are not required at this point. // A renderer is required during playback. // Name collision check { csHash<PawsSoundHandle *>::Iterator sounditerator = sounds.GetIterator(name_hash); while (sounditerator.HasNext()) { pawssndhandle = sounditerator.Next(); if (pawssndhandle->name.Compare(name)) return false; } } // Create a paws handle to relate the name to the iSndSysHandle and add it to our paws managed list pawssndhandle = new PawsSoundHandle(name,sounddata); if (pawssndhandle) sounds.Put(name_hash,pawssndhandle); return true; }
bool StringStore::StorageBin::ReadStringData (iFile* file) { bool okay = true; uint32 diskMagic; if (file->Read ((char*)&diskMagic, sizeof (diskMagic)) != sizeof (diskMagic)) okay = false; if (okay && csLittleEndian::UInt32 (diskMagic) != binFileMagic) okay = false; if (okay) { csRef<iDataBuffer> fileData (file->GetAllData()); csRef<iDataBuffer> strData; strData.AttachNew (new csParasiticDataBuffer (fileData, 4)); stringDataFile.AttachNew (new csMemFile (strData, true)); stringDataFile->SetPos (stringDataFile->GetSize ()); EntryHash::GlobalIterator entriesIt (entries.GetIterator()); while (entriesIt.HasNext ()) { BinID id; BinEntry& entry = entriesIt.Next (id); const char* entryStr = stringDataFile->GetData() + entry.dataOffset; size_t len = strlen (entryStr); entry.crc = CS::Utility::Checksum::CRC32 ((uint8*)entryStr, len); uint hash = csHashCompute (entryStr, len); hashedIDs.Put (hash, id); } } return okay; }
void SoundData::DeleteSound (SoundFile* &sound) { // do *not* delete all, but only the *specific* one as we don't check // for an existing key upon putting by maybe deleting a duplicate // deleting all here may result in a memory leak soundfiles.Delete(csHashCompute((const char*)sound->name), sound); delete sound; }
csRef<iSndSysData> PawsManager::LoadSound(const char *filename,const char *registeredname) { PawsSoundHandle *pawssndhandle; // If a registered name is not provided, the filename is used as the registered name if (registeredname==NULL) registeredname=filename; // Filename must always be specified if (filename==NULL) return NULL; // Search for the same sound already loaded int name_hash=csHashCompute(registeredname); { csHash<PawsSoundHandle *>::Iterator sounditerator = sounds.GetIterator(name_hash); while (sounditerator.HasNext()) { pawssndhandle = sounditerator.Next(); if (pawssndhandle->name.Compare(registeredname)) return pawssndhandle->snddata; } } // If there is no sound loader or vfs, sound loading cannot not be performed // This is checked after the registered name check since RegisterSound could add sounds created // by some other method. if (!vfs.IsValid() || !soundloader.IsValid()) return NULL; // Load the file data csRef<iDataBuffer> soundbuf = vfs->ReadFile(filename); if (!soundbuf) { Error2("Error while reading file '%s'", filename); return NULL; } // Read it into a sound buffer csRef<iSndSysData> sounddata = soundloader->LoadSound (soundbuf); if (!sounddata) { Error2("Cannot create sound data from file '%s'", filename); return NULL; } // Create a paws handle to relate the name to the iSndData and add it to our paws managed list pawssndhandle = new PawsSoundHandle(registeredname,sounddata); if (pawssndhandle) sounds.Put(name_hash,pawssndhandle); // Return the iSndSysHandle return csPtr<iSndSysData>( sounddata ); }
void SoundData::UnloadSoundFile (const char *name) { // do *not* use GetSound here as it potentially creates // a new sound, why would we want to create a new one // upon deletion? SoundFile* sound = soundfiles.Get(csHashCompute(name), NULL); if(sound) { DeleteSound(sound); } return; }
void EntityManager::LoadFamiliarAffinityAttributes() { csString sql = "SELECT * FROM char_create_affinity"; Result result( db->Select( sql ) ); if (!result.IsValid()) return; for ( unsigned long row = 0; row < result.Count(); row++) { psAffinityAttribute* newAttribute = new psAffinityAttribute(); newAttribute->Attribute = csString( result[row]["attribute"] ).Downcase(); newAttribute->Category = csString( result[row]["category"] ).Downcase(); affinityAttributeList.Put( csHashCompute( newAttribute->Attribute + newAttribute->Category ), newAttribute ); } }
void psOptions::RegisterOptionsClass(const char * className, iOptionsClass * optionsClass) { unsigned int key = csHashCompute(className); optionsClasses.Put(key, optionsClass); }
uint csStringBase::GetHash() const { return csHashCompute (GetDataSafe()); }
bool SoundData::LoadSoundLib (const char* filename, iObjectRegistry* objectReg) { csRef<iDocumentSystem> xml; /* try get existing Document System or create one*/ csRef<iDataBuffer> buff; /* buffer for reading the xml */ csRef<iDocument> doc; /* document created out of the xml */ const char* error; /* to store error msgs */ csRef<iDocumentNode> root; /* document root */ csRef<iDocumentNode> topNode; /* topnode to work with */ csRef<iDocumentNodeIterator> iter; /* node iterator */ csRef<iDocumentNode> node; /* yet another node .... */ SoundFile *snd; ///< soundfile if (!(xml = csQueryRegistry<iDocumentSystem> (objectReg))) xml.AttachNew(new csTinyDocumentSystem); buff = vfs->ReadFile(filename); if ( !buff || !buff->GetSize()) { return false; } doc = xml->CreateDocument(); error = doc->Parse(buff); if (error) { Error3("Parsing file %s gave error %s", filename, error); return false; } if( !(root = doc->GetRoot())) { Error1("No XML root in soundlib.xml"); return false; } if( !(topNode = root->GetNode("Sounds"))) { Error1("No <sounds> tag in soundlib.xml"); return false; } iter = topNode->GetNodes(); while (iter->HasNext()) { node = iter->Next(); if (node->GetType() != CS_NODE_ELEMENT) continue; if (strcmp(node->GetValue(), "Sound") == 0) { snd = new SoundFile(node->GetAttributeValue("name"), node->GetAttributeValue("file")); libsoundfiles.Put(csHashCompute((const char*) snd->name), snd); } } return true; }
void SoundData::PutSound (SoundFile* &sound) { // i know theres PutUnique but i have a bad feeling about overwriting soundfiles.Put(csHashCompute((const char*) sound->name), sound); }