summaryrefslogtreecommitdiff
path: root/src/nw4r/snd/snd_WaveSoundHandle.cpp
blob: 4d1774f1701a64174fb62a04f8bfc1b9ce8b7ed4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "nw4r/snd/snd_WaveSoundHandle.h"

/* Original source:
 * kiwi515/ogws
 * src/nw4r/snd/snd_WaveSoundHandle.cpp
 */

/*******************************************************************************
 * headers
 */

#include "common.h" // nullptr

#include "nw4r/snd/snd_BasicSound.h"
#include "nw4r/snd/snd_SoundHandle.h"
#include "nw4r/snd/snd_WaveSound.h"

#include "nw4r/ut/ut_RuntimeTypeInfo.h" // ut::DynamicCast

#include "nw4r/NW4RAssert.hpp"

/*******************************************************************************
 * functions
 */

namespace nw4r { namespace snd {

WaveSoundHandle::WaveSoundHandle(SoundHandle *handle) :
	mSound	(nullptr)
{
	if (!handle)
		return;

	detail::BasicSound *basicSound = handle->detail_GetAttachedSound();
	if (!basicSound)
		return;

	if (detail::WaveSound *sound =
	        ut::DynamicCast<detail::WaveSound *>(basicSound))
	{
		NW4RAssertPointerNonnull_Line(50, sound); // ?

		mSound = sound;

		if (mSound->IsAttachedTempSpecialHandle())
			mSound->DetachTempSpecialHandle();

		mSound->mTempSpecialHandle = this;
	}
}

void WaveSoundHandle::DetachSound()
{
	if (IsAttachedSound())
	{
		if (mSound->mTempSpecialHandle == this)
			mSound->mTempSpecialHandle = nullptr;
	}

	if (mSound)
		mSound = nullptr;
}

}} // namespace nw4r::snd