aboutsummaryrefslogtreecommitdiffstats
path: root/al/listener.h
blob: 318ab024a4e0baff9165c82f065903a53007bb31 (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
#ifndef AL_LISTENER_H
#define AL_LISTENER_H

#include <array>
#include <atomic>

#include "AL/al.h"
#include "AL/alc.h"
#include "AL/efx.h"

#include "almalloc.h"
#include "vecmat.h"

enum class DistanceModel;


struct ALlistenerProps {
    std::array<ALfloat,3> Position;
    std::array<ALfloat,3> Velocity;
    std::array<ALfloat,3> OrientAt;
    std::array<ALfloat,3> OrientUp;
    ALfloat Gain;
    ALfloat MetersPerUnit;

    std::atomic<ALlistenerProps*> next;

    DEF_NEWDEL(ALlistenerProps)
};

struct ALlistener {
    std::array<ALfloat,3> Position{{0.0f, 0.0f, 0.0f}};
    std::array<ALfloat,3> Velocity{{0.0f, 0.0f, 0.0f}};
    std::array<ALfloat,3> OrientAt{{0.0f, 0.0f, -1.0f}};
    std::array<ALfloat,3> OrientUp{{0.0f, 1.0f, 0.0f}};
    ALfloat Gain{1.0f};
    ALfloat mMetersPerUnit{AL_DEFAULT_METERS_PER_UNIT};

    std::atomic_flag PropsClean;

    struct {
        /* Pointer to the most recent property values that are awaiting an
         * update.
         */
        std::atomic<ALlistenerProps*> Update{nullptr};

        alu::Matrix Matrix;
        alu::Vector Velocity;

        ALfloat Gain;
        ALfloat MetersPerUnit;

        ALfloat DopplerFactor;
        ALfloat SpeedOfSound; /* in units per sec! */

        ALboolean SourceDistanceModel;
        DistanceModel mDistanceModel;
    } Params;

    ALlistener() { PropsClean.test_and_set(std::memory_order_relaxed); }
};

void UpdateListenerProps(ALCcontext *context);

#endif