summaryrefslogtreecommitdiff
path: root/src/nw4r/snd/snd_SoundStartable.cpp
blob: f098d1d8f0a435bee8d2e6fb3b952fd15cc6c014 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "nw4r/snd/snd_SoundStartable.h"

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

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

#include "common.h" // u32

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

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

namespace nw4r { namespace snd {

SoundStartable::StartResult SoundStartable::detail_StartSound(
	SoundHandle *handle, u32 soundId, const StartInfo *startInfo)
{
	StartResult result = detail_SetupSound(handle, soundId, false, startInfo);
	if (result != START_SUCCESS)
		return result;

	handle->StartPrepared();
	return START_SUCCESS;
}

SoundStartable::StartResult SoundStartable::detail_StartSound(
	SoundHandle *pHandle, const char *label, const StartInfo *pStartInfo)
{
	u32 soundId = detail_ConvertLabelStringToSoundId(label);
	if (soundId == -1)
		return START_ERR_INVALID_LABEL_STRING;

	return detail_StartSound(pHandle, soundId, pStartInfo);
}

SoundStartable::StartResult SoundStartable::detail_HoldSound(
	SoundHandle *handle, u32 soundId, StartInfo const *startInfo)
{
	if (handle->IsAttachedSound() && soundId == handle->GetId())
	{
		handle->detail_GetAttachedSound()->SetAutoStopCounter(1);
		return START_SUCCESS;
	}

	StartResult result = detail_SetupSound(handle, soundId, true, startInfo);
	if (result != START_SUCCESS)
		return result;

	handle->StartPrepared();
	handle->detail_GetAttachedSound()->SetAutoStopCounter(1);
	return START_SUCCESS;
}

SoundStartable::StartResult SoundStartable::detail_HoldSound(
	SoundHandle *pHandle, const char *label, const StartInfo *pStartInfo)
{
	u32 soundId = detail_ConvertLabelStringToSoundId(label);
	if (soundId == -1)
		return START_ERR_INVALID_LABEL_STRING;

	return detail_HoldSound(pHandle, soundId, pStartInfo);
}

SoundStartable::StartResult SoundStartable::detail_PrepareSound(
	SoundHandle *pHandle, u32 id,
	const StartInfo *pStartInfo)
{
	return detail_SetupSound(pHandle, id, false, pStartInfo);
}

SoundStartable::StartResult SoundStartable::detail_PrepareSound(
	SoundHandle *pHandle, const char *label,
	const StartInfo *pStartInfo)
{
	u32 soundId = detail_ConvertLabelStringToSoundId(label);
	if (soundId == -1)
		return START_ERR_INVALID_LABEL_STRING;

	return detail_PrepareSound(pHandle, soundId, pStartInfo);
}

}} // namespace nw4r::snd