forked from Themaister/Dinothawr
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbg_manager.cpp
61 lines (50 loc) · 1.16 KB
/
bg_manager.cpp
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
#include "game.hpp"
#ifndef USE_CXX03
#include <stdlib.h>
using namespace std;
namespace Icy
{
void BGManager::init(const vector<Track>& tracks)
{
this->tracks = tracks;
srand(time(NULL));
first = true;
last = 0;
}
void BGManager::step(Audio::Mixer& mixer)
{
lock_guard<Audio::Mixer> guard(mixer);
if (current && current->valid())
return;
if (!tracks.size())
return;
if (!loader.size())
{
if (first)
{
loader.request_vorbis(tracks[0].path);
last = 0;
}
else
{
unsigned index = rand() % tracks.size();
if (index == last)
index = (index + 1) % tracks.size();
loader.request_vorbis(tracks[index].path);
last = index;
}
first = false;
}
std::shared_ptr<std::vector<float> > ret = loader.flush();
if (ret)
{
current = make_shared<Audio::PCMStream>(ret);
current->volume(tracks[last].gain);
}
else
current.reset();
if (current)
mixer.add_stream(current);
}
}
#endif