Jump to content

Muting Game Sounds System


Recommended Posts

  • Honorable Member

M2 Download Center

This is the hidden content, please
( Internal )

This is the hidden content, please
( GitHub )

I saw this feature when playing PUBG^_^

  • Metin2 Dev 23
  • Not Good 1
  • Think 1
  • Scream 1
  • Good 4
  • Love 1
  • Love 14

 

Link to comment
Share on other sites

  • Forum Moderator
On 11/22/2019 at 10:22 PM, Mali61 said:

void CSoundManager::MuteSound(bool b)
{
	m_isMuted = !m_isMuted;
	if (m_isMuted) {
		StopAllSound3D();
		for (int i = 0; i < CSoundManager2D::INSTANCE_MAX_COUNT; ++i) {
			ISoundInstance* pInstance = ms_SoundManager2D.GetInstance(i);
			if (pInstance) pInstance->Stop();
		}
	}
	if (b) {
		for (int i = 0; i < CSoundManagerStream::MUSIC_INSTANCE_MAX_NUM; ++i) {
			TMusicInstance& rMusicInstance = m_MusicInstances[i];
			for (const auto& dmiss : { MUSIC_STATE_OFF , MUSIC_STATE_FADE_OUT })
				if (dmiss == rMusicInstance.MusicState)
					continue;
			auto pInstance = ms_SoundManagerStream.GetInstance(i);
			if (pInstance) m_isMuted ? pInstance->Pause() : pInstance->Resume();
		}
	}
	char buf[15];
	snprintf(buf, sizeof(buf), "Mute %s", m_isMuted ? "Enabled." : "Disabled.");
	IAbstractChat::GetSingleton().AppendChat(1, buf);
}

 

Good idea, thanks for release.

But here's one thing, C++ doesn't work like this, you did two loops and in the second loop you're trying to continue with the next iteration in the loop of iterator i, but this will not work, you continue the dmiss iterator, not i.

Basically what you did is:

for (int i = 0; i < 5; ++i)
{
	for (int j = 0; j < 3; ++j)
		if (j == 2)
			continue;

	std::cout << i << std::endl;
}
// 0 1 2 3 4

You need something like:

This is the hidden content, please

But in your case just for check two values, you don't need nested loops, using a simple condition for state OFF and FADE_OUT it's enough, also you should create StopAllSound2D function and use auto for all references/pointers.

void CSoundManager::StopAllSound2D()
{
	for (uint8_t i = 0; i < CSoundManager2D::INSTANCE_MAX_COUNT; ++i)
	{
		const auto pSoundInstance = ms_SoundManager2D.GetInstance(i);
		if (pSoundInstance)
			pSoundInstance->Stop();
	}
}

void CSoundManager::MuteSound(const bool bFadeIn)
{
	m_isMuted = !m_isMuted;
	if (m_isMuted)
	{
		StopAllSound2D();
		StopAllSound3D();
	}

	if (bFadeIn)
	{
		for (uint8_t i = 0; i < CSoundManagerStream::MUSIC_INSTANCE_MAX_NUM; ++i)
		{
			const auto rMusicInstance = m_MusicInstances[i];
			if (rMusicInstance.MusicState == MUSIC_STATE_OFF || rMusicInstance.MusicState == MUSIC_STATE_FADE_OUT)
				continue;

			const auto pSoundInstance = ms_SoundManagerStream.GetInstance(i);
			if (pSoundInstance)
				m_isMuted ? pSoundInstance->Pause() : pSoundInstance->Resume();
		}
	}

	char buf[15];
	_snprintf(buf, sizeof(buf), "Mute %s.", m_isMuted ? "Enabled" : "Disabled");
	IAbstractChat::GetSingleton().AppendChat(1, buf);
}
  • Metin2 Dev 1
  • Love 9
Link to comment
Share on other sites

  • Honorable Member
9 minutes ago, VegaS™ said:

Good idea, thanks for release.

But here's one thing, C++ doesn't work like this, you did two loops and in the second loop you're trying to continue with the next iteration in the loop of iterator i, but this will not work, you continue the dmiss iterator, not i.

Basically what you did is:


for (int i = 0; i < 5; ++i)
{
	for (int j = 0; j < 3; ++j)
		if (j == 2)
			continue;

	std::cout << i << std::endl;
}
// 0 1 2 3 4

You need something like: (just an example)

  Reveal hidden contents


for (int i = 0; i < 5; ++i)
{
	bool bStop = false;
	for (int j = 0; j < 3; ++j)
	{
		if (j == something)
		{
			bStop = True;
			break;
		}
	}
	
	if (bStop)
		continue;

	std::cout << i << std::endl;
}

But in your case just for check two values, you don't need nested loops, using a simple condition for state OFF and FADE_OUT it's enough, also you should create StopAllSound2D function and use auto for all references/pointers.


void CSoundManager::StopAllSound2D()
{
	for (uint8_t i = 0; i < CSoundManager3D::INSTANCE_MAX_COUNT; ++i)
	{
		const auto pSoundInstance = ms_SoundManager2D.GetInstance(i);
		if (pSoundInstance)
			pSoundInstance->Stop();
	}
}

void CSoundManager::MuteSound(const bool bFadeIn)
{
	m_isMuted = !m_isMuted;
	if (m_isMuted)
	{
		StopAllSound2D();
		StopAllSound3D();
	}

	if (bFadeIn)
	{
		for (uint8_t i = 0; i < CSoundManagerStream::MUSIC_INSTANCE_MAX_NUM; ++i)
		{
			const auto rMusicInstance = m_MusicInstances[i];
			if (rMusicInstance.MusicState == MUSIC_STATE_OFF || rMusicInstance.MusicState == MUSIC_STATE_FADE_OUT)
				continue;

			const auto pSoundInstance = ms_SoundManagerStream.GetInstance(i);
			if (pSoundInstance)
				m_isMuted ? pSoundInstance->Pause() : pSoundInstance->Resume();
		}
	}

	char buf[15];
	_snprintf(buf, sizeof(buf), "Mute %s.", m_isMuted ? "Enabled" : "Disabled");
	IAbstractChat::GetSingleton().AppendChat(1, buf);
}

 

my bad, I guess I need some sleep?

updated

 

Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.