//------------------------------------------------------------------------// bool MusicManager::LoadThemeNode(ScriptNode* pNode, Theme* pTheme) { FN("MusicManager::LoadThemeNode()"); if(pNode->GetDataType() != Script::STRING) return Error::Handle("No id found for theme node"); ISegment* pSegmentSource = 0; Theme* pThemeSource = 0; // First look for matching segments based on the id value ISegmentMap::iterator itr = m_SegmentMap.find(pNode->GetString()); if(itr == m_SegmentMap.end()) { // Next, look for matching themes ThemeMap::iterator itor = m_ThemeMap.find(pNode->GetString()); if(itor == m_ThemeMap.end()) return Error::Handle("Unknown id %s in theme node", pNode->GetString()); pThemeSource = itor->second; if(!pTheme->CreateNode(pThemeSource)) return Error::Handle("Could not create theme node"); } else { pSegmentSource = itr->second; if(!pTheme->CreateNode(pSegmentSource)) return Error::Handle("Could not create theme node"); } ScriptNode* pChildNode = pNode->GetChild(); while(pChildNode) { if(MUSMGR_STRCMP(pChildNode->GetName(), "Dest") == 0) { itr = m_SegmentMap.find(pChildNode->GetString()); if(itr == m_SegmentMap.end()) return Error::Handle("Unknown id %s in theme node", pChildNode->GetString()); ISegment* pDest = itr->second; if(pThemeSource) { if(!pTheme->CreateTransition(pThemeSource, pDest)) return Error::Handle("Error creating theme node transition"); } else { if(!pTheme->CreateTransition(pSegmentSource, pDest)) return Error::Handle("Error creating theme node transition"); } } else { return Error::Handle("Unknown syntax or keyword in theme node"); } pChildNode = pChildNode->GetSibling(); } return true; }
//------------------------------------------------------------------------// bool MusicManager::LoadDLS(ScriptNode* pNode) { FN("MusicManager::LoadDLS()"); // We use string ids in this scripting system if(pNode->GetDataType() != Script::STRING) return Error::Handle("No id found for DLS identifier"); // Make sure the segment ID doesn't already exist IDLSMap::iterator itr = m_DLSMap.find(pNode->GetString()); if(itr != m_DLSMap.end()) return true; DLSInit init; ScriptNode* pChildNode = pNode->GetChild(); while(pChildNode) { if(MUSMGR_STRCMP(pChildNode->GetName(), "FileName") == 0) init.m_sFileName = pChildNode->GetString(); pChildNode = pChildNode->GetSibling(); } IDLS* pDLS; if(!AudioMgr()->CreateDLS(pDLS)) return false; if(!pDLS->Init(init)) return false; m_pCurrentDLS = pDLS; // Insert the segment into the map m_DLSMap.insert(make_pair(pNode->GetString(), pDLS)); return true; }
//------------------------------------------------------------------------// bool MusicManager::LoadSegment(ScriptNode* pNode) { FN("MusicManager::LoadSegment()"); // We use string ids in this scripting system if(pNode->GetDataType() != Script::STRING) return Error::Handle("No id found for sound identifier"); // Make sure the segment ID doesn't already exist ISegmentMap::iterator itr = m_SegmentMap.find(pNode->GetString()); if(itr != m_SegmentMap.end()) return true; SegmentInit init; ScriptNode* pChildNode = pNode->GetChild(); init.m_pDLS = m_pCurrentDLS; while(pChildNode) { if(MUSMGR_STRCMP(pChildNode->GetName(), "FileName") == 0) init.m_sFileName = pChildNode->GetString(); else if(MUSMGR_STRCMP(pChildNode->GetName(), "Looping") == 0) init.m_bLooping = pChildNode->GetBool(); else if(MUSMGR_STRCMP(pChildNode->GetName(), "Music") == 0) init.m_bMusic = pChildNode->GetBool(); else if(MUSMGR_STRCMP(pChildNode->GetName(), "DLS") == 0) { IDLSMap::iterator itr = m_DLSMap.find(pChildNode->GetString()); if(itr != m_DLSMap.end()) init.m_pDLS = itr->second; } pChildNode = pChildNode->GetSibling(); } ISegment* pSegment; if(!AudioMgr()->CreateSegment(pSegment)) return false; if(!pSegment->Init(init)) return false; // Insert the segment into the map m_SegmentMap.insert(make_pair(pNode->GetString(), pSegment)); return true; }
//------------------------------------------------------------------------// bool SoundManager::LoadSound(ScriptNode* pNode) { FN("SoundManager::LoadSound()"); // We use string ids in this scripting system if(pNode->GetDataType() != Script::STRING) return Error::Handle("No id found for sound identifier"); // Just return true if the sound is already registered if(IsSoundRegistered(pNode->GetString())) return true; SoundPool pool; ScriptNode* pChildNode = pNode->GetChild(); while(pChildNode) { if(SNDMGR_STRCMP(pChildNode->GetName(), "FileName") == 0) pool.m_Init.m_sFileName = pChildNode->GetString(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Looping") == 0) pool.m_Init.m_bLooping = pChildNode->GetBool(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Streaming") == 0) pool.m_Init.m_bStreaming = pChildNode->GetBool(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Music") == 0) pool.m_Init.m_bMusic = pChildNode->GetBool(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Volume") == 0) pool.m_Init.m_Prop.m_fVolume = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Pan") == 0) pool.m_Init.m_Prop.m_fPan = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Pitch") == 0) pool.m_Init.m_Prop.m_fPitch = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "ReadCursor") == 0) pool.m_Init.m_Prop.m_nReadCursor = pChildNode->GetInteger(); else return Error::Handle("Syntax error in Sound definition"); pChildNode = pChildNode->GetSibling(); } // Insert the sound definition into the map m_SndMap.insert(make_pair(pNode->GetString(), pool)); DebugOut(4, "Registering Sound \"%s\" in sound manager", pNode->GetString()); return true; }
//------------------------------------------------------------------------// bool SoundManager::LoadPeriodic(ScriptNode* pNode, PeriodicElement& pe) { FN("SoundManager::LoadPeriodic()"); // Check to see if the node has the "default" keyword, meaning it should // clear all values to their original defaults. if((pNode->GetDataType() == Script::VARIABLE) && (strcmp(pNode->GetVariable(), "Default") == 0)) pe.Clear(); ScriptNode* pChildNode = pNode->GetChild(); while(pChildNode) { if(SNDMGR_STRCMP(pChildNode->GetName(), "Sound3D") == 0) pe.m_sSound3DID = pChildNode->GetString(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MinPitch") == 0) pe.m_Init.m_fMinPitch = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MaxPitch") == 0) pe.m_Init.m_fMaxPitch = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MinDelay") == 0) pe.m_Init.m_fMinDelay = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MaxDelay") == 0) pe.m_Init.m_fMaxDelay = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "XRange") == 0) pe.m_Init.m_fXRange = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "YRange") == 0) pe.m_Init.m_fYRange = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "ZRange") == 0) pe.m_Init.m_fZRange = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MinDistance") == 0) pe.m_Init.m_fMinDistance = pChildNode->GetReal(); else return false; pChildNode = pChildNode->GetSibling(); } return true; }
//------------------------------------------------------------------------// bool SoundManager::LoadBackground(ScriptNode* pNode, BackgroundElement& bge) { FN("SoundManager::LoadBackground()"); // Check to see if the node has the "Default" keyword, meaning it should // clear all values to their original defaults. if((pNode->GetDataType() == Script::VARIABLE) && (strcmp(pNode->GetVariable(), "Default") == 0)) bge.Clear(); ScriptNode* pChildNode = pNode->GetChild(); while(pChildNode) { if(SNDMGR_STRCMP(pChildNode->GetName(), "Sound") == 0) bge.m_sSoundID = pChildNode->GetString(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MinVolume") == 0) bge.m_Init.m_fMinVolume = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MaxVolume") == 0) bge.m_Init.m_fMaxVolume = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MinVolumeTime") == 0) bge.m_Init.m_fMinVolumeTime = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MaxVolumeTime") == 0) bge.m_Init.m_fMaxVolumeTime = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MinPitch") == 0) bge.m_Init.m_fMinPitch = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MaxPitch") == 0) bge.m_Init.m_fMaxPitch = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MinPitchTime") == 0) bge.m_Init.m_fMinPitchTime = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MaxPitchTime") == 0) bge.m_Init.m_fMaxPitchTime = pChildNode->GetReal(); else return false; pChildNode = pChildNode->GetSibling(); } return true; }
//------------------------------------------------------------------------// bool SoundManager::LoadSound3D(ScriptNode* pNode) { FN("SoundManager::LoadSound3D()"); // We use string ids in this scripting system if(pNode->GetDataType() != Script::STRING) return Error::Handle("No id found for sound3d identifier"); // Just return true if the sound3d is already registered if(IsSound3DRegistered(pNode->GetString())) return true; Sound3DPool pool; ScriptNode* pChildNode = pNode->GetChild(); while(pChildNode) { if(SNDMGR_STRCMP(pChildNode->GetName(), "FileName") == 0) pool.m_Init.m_sFileName = pChildNode->GetString(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Looping") == 0) pool.m_Init.m_bLooping = pChildNode->GetBool(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Streaming") == 0) pool.m_Init.m_bStreaming = pChildNode->GetBool(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Music") == 0) pool.m_Init.m_bMusic = pChildNode->GetBool(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Position") == 0) pool.m_Init.m_Prop.m_vPosition = pChildNode->GetVector(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Velocity") == 0) pool.m_Init.m_Prop.m_vVelocity = pChildNode->GetVector(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "ConeOrientation") == 0) pool.m_Init.m_Prop.m_vConeOrientation = pChildNode->GetVector(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "InsideConeAngle") == 0) pool.m_Init.m_Prop.m_nInsideConeAngle = pChildNode->GetInteger(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "OutsideConeAngle") == 0) pool.m_Init.m_Prop.m_nOutsideConeAngle = pChildNode->GetInteger(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "ConeOutsideVolume") == 0) pool.m_Init.m_Prop.m_fConeOutsideVolume = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MinDistance") == 0) pool.m_Init.m_Prop.m_fMinDistance = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MaxDistance") == 0) pool.m_Init.m_Prop.m_fMaxDistance = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Mode") == 0) { if(pChildNode->GetDataType() == Script::INTEGER) { pool.m_Init.m_Prop.m_nMode = pChildNode->GetInteger(); } else { if(SNDMGR_STRCMP(pChildNode->GetString(), "Normal") == 0) pool.m_Init.m_Prop.m_nMode = MODE_NORMAL; else if(SNDMGR_STRCMP(pChildNode->GetString(), "HeadRelative") == 0) pool.m_Init.m_Prop.m_nMode = MODE_HEADRELATIVE; else if(SNDMGR_STRCMP(pChildNode->GetString(), "Disable") == 0) pool.m_Init.m_Prop.m_nMode = MODE_DISABLE; } } else if(SNDMGR_STRCMP(pChildNode->GetName(), "Volume") == 0) pool.m_Init.m_Prop.m_fVolume = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Pitch") == 0) pool.m_Init.m_Prop.m_fPitch = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "ReadCursor") == 0) pool.m_Init.m_Prop.m_nReadCursor = pChildNode->GetInteger(); else { return Error::Handle("Syntax error in Sound3D definition"); } pChildNode = pChildNode->GetSibling(); } // Insert the sound3d definition into the map m_Snd3DMap.insert(make_pair(pNode->GetString(), pool)); DebugOut(4, "Registering Sound3D \"%s\" in sound manager", pNode->GetString()); return true; }