Skip to content

Commit

Permalink
Cleanup final
Browse files Browse the repository at this point in the history
  • Loading branch information
andraantariksa committed Feb 23, 2022
1 parent 51301ae commit b751a0f
Show file tree
Hide file tree
Showing 30 changed files with 461 additions and 488 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ resolver = "2"
instant = "0.1"
pollster = "0.2.4"
nalgebra = "0.29.0"
rodio = { version = "0.14.0", default-features = false, features = ["vorbis", "flac", "wav"] }
rodio = { version = "0.15.0", default-features = false, features = ["vorbis", "flac", "wav"] }
rapier3d = "0.11.1"
#serde = { version = "1", features = ["derive"] }
log = "0.4.14"
Expand Down
19 changes: 3 additions & 16 deletions src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,11 @@ pub enum InOutAnimationState {
impl PartialEq for InOutAnimationState {
fn eq(&self, other: &Self) -> bool {
match self {
InOutAnimationState::Stopped => match other {
InOutAnimationState::Stopped => true,
_ => false,
},
InOutAnimationState::Foward(_) => match other {
InOutAnimationState::Foward(_) => true,
_ => false,
},
InOutAnimationState::Backward(_) => match other {
InOutAnimationState::Backward(_) => true,
_ => false,
},
InOutAnimationState::Stopped => matches!(other, InOutAnimationState::Stopped),
InOutAnimationState::Foward(_) => matches!(other, InOutAnimationState::Foward(_)),
InOutAnimationState::Backward(_) => matches!(other, InOutAnimationState::Backward(_)),
}
}

fn ne(&self, other: &Self) -> bool {
!self.eq(other)
}
}

pub struct InOutAnimation {
Expand Down
57 changes: 43 additions & 14 deletions src/audio.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

use std::collections::HashMap;

pub const AUDIO_FILE_AWESOMENESS: &[u8] = include_bytes!("../assets/audio/awesomeness.wav");
Expand Down Expand Up @@ -29,53 +30,81 @@ impl Sink {
}
}

#[cfg(not(target_arch = "wasm32"))]
pub struct AudioContext {
pub output_stream_handle: rodio::OutputStreamHandle,
pub output_stream: rodio::OutputStream,
pub global_sinks_map: HashMap<&'static str, Sink>,
pub global_sinks_array: Vec<Sink>,
pub volume: f32,
}
#[cfg(target_arch = "wasm32")]
pub struct AudioContext {
pub global_sinks_map: HashMap<&'static str, Sink>,
pub global_sinks_array: Vec<Sink>,
pub volume: f32,
}

impl AudioContext {
pub fn new() -> Self {
#[cfg(not(target_arch = "wasm32"))]
let (output_stream, output_stream_handle) = rodio::OutputStream::try_default().unwrap();

Self {
#[cfg(not(target_arch = "wasm32"))]
let ret = Self {
global_sinks_map: HashMap::new(),
global_sinks_array: Vec::new(),
volume: 1.0,
output_stream,
output_stream_handle,
}
};
#[cfg(target_arch = "wasm32")]
let ret = Self {
global_sinks_map: HashMap::new(),
global_sinks_array: Vec::new(),
volume: 1.0,
};
ret
}

pub fn get_volume(&self) -> f32 {
self.volume
}

pub fn set_volume(&mut self, volume: f32) {
self.volume = volume;
for (_k, v) in self.global_sinks_map.iter_mut() {
v.set_volume(volume);
}
for sink in self.global_sinks_array.iter_mut() {
sink.set_volume(volume);
#[cfg(not(target_arch = "wasm32"))]
{
self.volume = volume;
for (_k, v) in self.global_sinks_map.iter_mut() {
v.set_volume(volume);
}
for sink in self.global_sinks_array.iter_mut() {
sink.set_volume(volume);
}
}
}

pub fn push(&mut self, mut sink: Sink) {
sink.set_volume(self.volume);
self.global_sinks_array.push(sink);
#[cfg(not(target_arch = "wasm32"))]
{
sink.set_volume(self.volume);
self.global_sinks_array.push(sink);
}
}

pub fn insert(&mut self, key: &'static str, mut sink: Sink) {
sink.set_volume(self.volume);
self.global_sinks_map.insert(key, sink);
#[cfg(not(target_arch = "wasm32"))]
{
sink.set_volume(self.volume);
self.global_sinks_map.insert(key, sink);
}
}

pub fn clear(&mut self) {
self.global_sinks_map.retain(|_k, v| !v.empty());
self.global_sinks_array.retain(|v| !v.empty());
#[cfg(not(target_arch = "wasm32"))]
{
self.global_sinks_map.retain(|_k, v| !v.empty());
self.global_sinks_array.retain(|v| !v.empty());
}
}
}
8 changes: 4 additions & 4 deletions src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ impl Camera {
bottom: FrustumPlane::new(
self.position,
nalgebra::Unit::new_normalize(
(&(&front_times_far + up * half_v_side)).cross(&right),
(&(front_times_far + up * half_v_side)).cross(&right),
),
),
top: FrustumPlane::new(
self.position,
nalgebra::Unit::new_normalize(right.cross(&(&front_times_far - up * half_v_side))),
nalgebra::Unit::new_normalize(right.cross(&(front_times_far - up * half_v_side))),
),
left: FrustumPlane::new(
self.position,
nalgebra::Unit::new_normalize(
(&(&front_times_far - right.into_inner() * half_h_side)).cross(&up),
(&(front_times_far - right.into_inner() * half_h_side)).cross(&up),
),
),
right: FrustumPlane::new(
self.position,
nalgebra::Unit::new_normalize(
(&up).cross(&(&front_times_far + right.into_inner() * half_h_side)),
(&up).cross(&(front_times_far + right.into_inner() * half_h_side)),
),
),
}
Expand Down
Loading

0 comments on commit b751a0f

Please sign in to comment.