summaryrefslogtreecommitdiff
path: root/include/d/snd/d_snd_checkers.h
blob: 22a560978b4d8120c8b185c5c466ba5ea70a2174 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#ifndef D_SND_CHECKERS_H
#define D_SND_CHECKERS_H

#include "common.h"
#include "d/snd/d_snd_bgm_mgr.h"
#include "d/snd/d_snd_player_mgr.h"
#include "nw4r/snd/snd_SoundHandle.h"

class SoundPropertiesChecker {
public:
    // @bug forgot to initialize mCounter4. see `dSndSourceEquipment_c::cbPcHit` for one consequence
    SoundPropertiesChecker(u32 soundId)
        : mSoundId(soundId),
          mPlayCounter(0),
          mPauseCounter(0),
          mCounter3(0),
          mpPlayCounter(nullptr),
          mpPauseCounter(nullptr),
          mpCounter3(nullptr),
          mpCounter4(nullptr) {}
    virtual void operator()(nw4r::snd::SoundHandle &pHandle) {
        if (mSoundId != -1 && mSoundId != pHandle.GetId()) {
            return;
        }

        if (mpPlayCounter != nullptr) {
            (*mpPlayCounter)++;
        } else {
            mPlayCounter++;
        }

        if (pHandle.IsPause()) {
            if (mpPauseCounter != nullptr) {
                (*mpPauseCounter)++;
            } else {
                mPauseCounter++;
            }
            return;
        }

        if (dSndBgmMgr_c::GetInstance()->isPreparedBgmSoundId(pHandle.GetId())) {
            if (mpCounter3 != nullptr) {
                (*mpCounter3)++;
            } else {
                mCounter3++;
            }
            return;
        }

        if (dSndBgmMgr_c::GetInstance()->isPreparingBgmSoundId(pHandle.GetId())) {
            if (mpCounter3 != nullptr) {
                (*mpCounter3)++;
            } else {
                mCounter3++;
            }
            return;
        }

        if (dSndBgmMgr_c::GetInstance()->isFadingOutBgmSoundId(pHandle.GetId())) {
            if (mpCounter4 != nullptr) {
                (*mpCounter4)++;
            } else {
                mCounter4++;
            }
            return;
        }

        if (dSndBgmMgr_c::GetInstance()->getFanSoundHandleForFan2(pHandle.GetId()) != nullptr &&
            !dSndBgmMgr_c::GetInstance()->isCurrentlyPlayingFanSound(pHandle.GetId())) {
            // Why not mpCounter3???
            mCounter3++;
        }
    }

public:
    /* 0x04 */ u32 mSoundId;
    /* 0x08 */ s32 mPlayCounter;
    /* 0x0C */ s32 mPauseCounter;
    /* 0x10 */ s32 mCounter3;
    /* 0x14 */ s32 mCounter4;
    /* 0x18 */ s32 *mpPlayCounter;
    /* 0x1C */ s32 *mpPauseCounter;
    /* 0x20 */ s32 *mpCounter3;
    /* 0x24 */ s32 *mpCounter4;
};

// used at the very least when trying to finish Demise
class IsCurrentSoundIdChecker {
public:
    IsCurrentSoundIdChecker(u32 id, bool *pResult) : mSoundId(id), mpResult(pResult) {}
    ~IsCurrentSoundIdChecker() {}

    virtual void operator()(nw4r::snd::SoundHandle &pHandle) {
        if (mSoundId == pHandle.GetId()) {
            *mpResult = true;
        }
    }

private:
    /* 0x04 */ u32 mSoundId;
    /* 0x08 */ bool *mpResult;
};

class SoundStopper {
public:
    SoundStopper(u32 id, s32 fadeFrames) : mSoundId(id), mFadeFrames(fadeFrames) {}
    // ~SoundStopper() {}

    virtual void operator()(nw4r::snd::SoundHandle &pHandle) {
        if (mSoundId == pHandle.GetId()) {
            pHandle.Stop(mFadeFrames);
        }
    }

private:
    /* 0x04 */ u32 mSoundId;
    /* 0x08 */ s32 mFadeFrames;
};

class SoundStopperIfParamFlag20 {
public:
    SoundStopperIfParamFlag20() {}

    virtual void operator()(nw4r::snd::SoundHandle &pHandle) {
        u32 id = pHandle.GetId();
        u32 param = dSndPlayerMgr_c::GetInstance()->getDemoArchive()->GetSoundUserParam(id);
        if ((param & 0x100000) != 0) {
            u32 fadeFrames = param & 0xFF;
            pHandle.Stop(fadeFrames);
        }
    }

private:
};

class SoundVolumeSetter {
public:
    SoundVolumeSetter() {}
    ~SoundVolumeSetter() {}

    virtual void operator()(nw4r::snd::SoundHandle &pHandle) {
        pHandle.SetVolume(mVolume, mFadeFrames);
    }

public:
    /* 0x04 */ f32 mVolume;
    /* 0x08 */ s32 mFadeFrames;
};

#endif