Пример #1
0
//------------------------------------------------------------------------//
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;
}
Пример #2
0
//------------------------------------------------------------------------//
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;
}
Пример #3
0
//------------------------------------------------------------------------//
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;
}
Пример #4
0
//------------------------------------------------------------------------//
bool SoundManager::LoadSoundScape(ScriptNode* pNode)
{
	FN("SoundManager::LoadSoundScape()");
	// We use string ids in this scripting system
	if(pNode->GetDataType() != Script::STRING)
		return Error::Handle("No id found for soundscape identifier");

	// Just return true if the soundscape is already registered
	if(IsSoundScapeRegistered(pNode->GetString()))
		return true;

	SoundScapeInternalInit init;
	BackgroundElement bge;
	PeriodicElement pe;

	ScriptNode* pChildNode = pNode->GetChild();
	while(pChildNode)
	{
		if(SNDMGR_STRCMP(pChildNode->GetName(), "Periodic") == 0)
		{
			if(!LoadPeriodic(pChildNode, pe))
				return false;
			init.m_aPeriodic.push_back(pe);
		}
		else if(SNDMGR_STRCMP(pChildNode->GetName(), "Background") == 0)
		{
			if(!LoadBackground(pChildNode, bge))
				return false;
			init.m_aBackground.push_back(bge);
		}
		else
			return false;

		pChildNode = pChildNode->GetSibling();
	}

	// Insert the sound definition into the map
	m_SSMap.insert(make_pair(pNode->GetString(), init));
	DebugOut(4, "Registering Soundscape \"%s\" in sound manager", pNode->GetString());
	return true;
}
Пример #5
0
//------------------------------------------------------------------------//
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;
}
Пример #6
0
//------------------------------------------------------------------------//
bool MusicManager::LoadScript(string sFileName)
{
	if(!IsInitialized())
		return Error::Handle("Music manager is not initialized");

	Script script;
	if(!m_Loader.Load(sFileName, script))
		return Error::Handle("Could not load script %s", sFileName.c_str());

	ScriptNode* pNode = script.GetRoot();
	while(pNode)
	{
		// Look for named "DLS" nodes in the script
		if(MUSMGR_STRCMP(pNode->GetName(), "DLS") == 0)
		{
			if(!LoadDLS(pNode))
				return false;
		}
		// Look for named "Segment" nodes in the script
		else if(MUSMGR_STRCMP(pNode->GetName(), "Segment") == 0)
		{
			if(!LoadSegment(pNode))
				return false;
		}
		// Look for named "Theme" nodes in the script
		else if(MUSMGR_STRCMP(pNode->GetName(), "Theme") == 0)
		{
			if(!LoadTheme(pNode))
				return false;
		}
		else
		{
			return Error::Handle("Unrecognized keyword in music script");
		}

		// advance to the next sibling node if one exists
		pNode = pNode->GetSibling();
	};

	return true;
}
Пример #7
0
//------------------------------------------------------------------------//
bool MusicManager::LoadTheme(ScriptNode* pNode)
{
	FN("MusicManager::LoadTheme()");
	// We use string ids in this scripting system
	if(pNode->GetDataType() != Script::STRING)
		return Error::Handle("No id found for theme identifier");

	Theme* pTheme = 0;

	// Make sure the theme ID doesn't already exist
	ThemeMap::iterator itr = m_ThemeMap.find(pNode->GetString());
	if(itr != m_ThemeMap.end())
		pTheme = itr->second;
	else
		pTheme = new Theme;

	if(!pTheme)
		return false;

	ScriptNode* pChildNode = pNode->GetChild();
	while(pChildNode)
	{
		if(MUSMGR_STRCMP(pChildNode->GetName(), "Src") == 0)
		{
			if(!LoadThemeNode(pChildNode, pTheme))
				return false;
		}
		else if(MUSMGR_STRCMP(pChildNode->GetName(), "Interlude") == 0)
		{
			pTheme->SetInterlude(pChildNode->GetBool());
		}
		else
			return false;
		pChildNode = pChildNode->GetSibling();
	}
	
	// Insert the theme into the map
	m_ThemeMap.insert(make_pair(pNode->GetString(), pTheme));

	return true;
}
Пример #8
0
//------------------------------------------------------------------------//
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;
}
Пример #9
0
//------------------------------------------------------------------------//
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;
}
Пример #10
0
//------------------------------------------------------------------------//
bool SoundManager::LoadScript(string sFileName)
{
	FN("SoundManager::LoadScript()");
	CHECK_INIT();
	Script script;
	if(!m_Loader.Load(sFileName, script))
		return Error::Handle("Could not load script %s", sFileName.c_str());

	ScriptNode* pNode = script.GetRoot();
	while(pNode)
	{
		// Look for named "Sound" nodes in the script
		if(SNDMGR_STRCMP(pNode->GetName(), "Sound") == 0)
		{
			if(!LoadSound(pNode))
				return false;
		}
		// Look for named "Sound3D" nodes in the script
		else if(SNDMGR_STRCMP(pNode->GetName(), "Sound3D") == 0)
		{
			if(!LoadSound3D(pNode))
				return false;
		}
		// Look for named "soundscape" nodes in the script
		else if(SNDMGR_STRCMP(pNode->GetName(), "SoundScape") == 0)
		{
			if(!LoadSoundScape(pNode))
				return false;
		}
		
		// advance to the next sibling node if one exists
		pNode = pNode->GetSibling();
	};

	return true;
}
Пример #11
0
//------------------------------------------------------------------------//
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;
}