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
use super::super::RAW_STATE;
use std::sync::atomic::Ordering::Relaxed;
pub fn add_position(effect: usize, pos: [f32;3]) {
let mut state = unsafe { (*RAW_STATE).write().unwrap() };
state.effect.persistent_positions[effect].push(pos);
}
pub fn add_positions(effect: usize, mut pos: Vec<[f32;3]>) {
let mut state = unsafe { (*RAW_STATE).write().unwrap() };
state.effect.persistent_positions[effect].append(&mut pos);
}
pub fn add_positions_for_all(all: Vec<(usize,Vec<[f32;3]>)>) {
let mut state = unsafe { (*RAW_STATE).write().unwrap() };
for (effect,mut pos) in all {
state.effect.persistent_positions[effect].append(&mut pos);
}
}
pub fn clear_positions(effect: usize) {
let mut state = unsafe { (*RAW_STATE).write().unwrap() };
state.effect.persistent_positions[effect].clear()
}
pub fn clear_positions_for_all() {
let mut state = unsafe { (*RAW_STATE).write().unwrap() };
for p in &mut state.effect.persistent_positions {
p.clear()
}
}
pub fn update_volume(effect: usize) {
let state = unsafe { (*RAW_STATE).read().unwrap() };
let volume = state.effect.persistent_positions[effect].iter()
.fold(0f32, |acc, &pos| acc + state.effect.distance_model.distance(pos,state.effect.listener));
state.effect.persistent_final_volumes[effect].store((volume * 10_000f32) as usize, Relaxed);
}
pub fn update_volume_for_all() {
let state = unsafe { (*RAW_STATE).read().unwrap() };
for (positions,final_volume) in state.effect.persistent_positions.iter().zip(state.effect.persistent_final_volumes.iter()) {
let volume = positions.iter()
.fold(0f32, |acc, &pos| acc + state.effect.distance_model.distance(pos,state.effect.listener));
final_volume.store((volume * 10_000f32) as usize, Relaxed);
}
}