aboutsummaryrefslogtreecommitdiff
path: root/src/audio/PolRadio.h
blob: c7b0bcc8986b6e5b7d94b6b242d537fde00b7597 (plain) (blame)
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
#pragma once

#include "Crime.h"
#include "AudioSamples.h"

struct cAMCrime {
	int32 type;
	CVector position;
	uint16 timer;

	cAMCrime()
	{
		type = CRIME_NONE;
		position = CVector(0.0f, 0.0f, 0.0f);
		timer = 0;
	}
};

VALIDATE_SIZE(cAMCrime, 20);

#define POLICE_RADIO_QUEUE_MAX_SAMPLES 60

class cPoliceRadioQueue
{
public:
	uint32 m_aSamples[POLICE_RADIO_QUEUE_MAX_SAMPLES];
	uint8 m_nSamplesInQueue;
	uint8 m_nAddOffset;
	uint8 m_nRemoveOffset;

	cPoliceRadioQueue()
	{
		Reset();
	}

	void Reset()
	{
		m_nAddOffset = 0;
		m_nRemoveOffset = 0;
		m_nSamplesInQueue = 0;
	}

	bool8 Add(uint32 sample)
	{
		if (m_nSamplesInQueue != POLICE_RADIO_QUEUE_MAX_SAMPLES) {
			m_aSamples[m_nAddOffset] = sample;
			m_nSamplesInQueue++;
			m_nAddOffset = (m_nAddOffset + 1) % POLICE_RADIO_QUEUE_MAX_SAMPLES;
			return TRUE;
		}
		return FALSE;
	}

	uint32 Remove()
	{
		if (m_nSamplesInQueue != 0) {
			uint32 sample = m_aSamples[m_nRemoveOffset];
			m_nSamplesInQueue--;
			m_nRemoveOffset = (m_nRemoveOffset + 1) % POLICE_RADIO_QUEUE_MAX_SAMPLES;
			return sample;
		}
		return TOTAL_AUDIO_SAMPLES;
	}
};

VALIDATE_SIZE(cPoliceRadioQueue, 244);