Skip to content

Commit

Permalink
generate 2.206.5
Browse files Browse the repository at this point in the history
  • Loading branch information
lebedec committed Mar 19, 2024
1 parent 9789141 commit 631f254
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libfmod"
version = "2.206.4"
version = "2.206.5"
publish = true
edition = "2021"
license = "MIT"
Expand Down
108 changes: 91 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ where
pointer
}

const fn from_ref<T: ?Sized>(value: &T) -> *const T {
value
}

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum LoadingState {
Unloading,
Expand Down Expand Up @@ -4332,7 +4336,7 @@ impl Into<ffi::FMOD_ASYNCREADINFO> for AsyncReadInfo {
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Vector {
pub x: f32,
pub y: f32,
Expand All @@ -4352,6 +4356,44 @@ impl TryFrom<ffi::FMOD_VECTOR> for Vector {
}
}

impl Vector {
pub const fn new(x: f32, y: f32, z: f32) -> Self {
Vector { x, y, z }
}
}

impl From<[f32; 3]> for Vector {
fn from(value: [f32; 3]) -> Vector {
Vector {
x: value[0],
y: value[1],
z: value[2],
}
}
}

impl From<Vector> for [f32; 3] {
fn from(value: Vector) -> [f32; 3] {
[value.x, value.y, value.z]
}
}

impl From<(f32, f32, f32)> for Vector {
fn from(value: (f32, f32, f32)) -> Vector {
Vector {
x: value.0,
y: value.1,
z: value.2,
}
}
}

impl From<Vector> for (f32, f32, f32) {
fn from(value: Vector) -> (f32, f32, f32) {
(value.x, value.y, value.z)
}
}

impl Into<ffi::FMOD_VECTOR> for Vector {
fn into(self) -> ffi::FMOD_VECTOR {
ffi::FMOD_VECTOR {
Expand Down Expand Up @@ -6601,8 +6643,14 @@ impl Channel {
unsafe {
match ffi::FMOD_Channel_Set3DAttributes(
self.pointer,
pos.map(|value| &value.into() as *const _).unwrap_or(null()),
vel.map(|value| &value.into() as *const _).unwrap_or(null()),
pos.map(Vector::into)
.as_ref()
.map(from_ref)
.unwrap_or_else(null),
vel.map(Vector::into)
.as_ref()
.map(from_ref)
.unwrap_or_else(null),
) {
ffi::FMOD_OK => Ok(()),
error => Err(err_fmod!("FMOD_Channel_Set3DAttributes", error)),
Expand Down Expand Up @@ -7443,8 +7491,14 @@ impl ChannelGroup {
unsafe {
match ffi::FMOD_ChannelGroup_Set3DAttributes(
self.pointer,
pos.map(|value| &value.into() as *const _).unwrap_or(null()),
vel.map(|value| &value.into() as *const _).unwrap_or(null()),
pos.map(Vector::into)
.as_ref()
.map(from_ref)
.unwrap_or_else(null),
vel.map(Vector::into)
.as_ref()
.map(from_ref)
.unwrap_or_else(null),
) {
ffi::FMOD_OK => Ok(()),
error => Err(err_fmod!("FMOD_ChannelGroup_Set3DAttributes", error)),
Expand Down Expand Up @@ -8592,9 +8646,14 @@ impl Geometry {
match ffi::FMOD_Geometry_SetRotation(
self.pointer,
forward
.map(|value| &value.into() as *const _)
.unwrap_or(null()),
up.map(|value| &value.into() as *const _).unwrap_or(null()),
.map(Vector::into)
.as_ref()
.map(from_ref)
.unwrap_or_else(null),
up.map(Vector::into)
.as_ref()
.map(from_ref)
.unwrap_or_else(null),
) {
ffi::FMOD_OK => Ok(()),
error => Err(err_fmod!("FMOD_Geometry_SetRotation", error)),
Expand Down Expand Up @@ -8730,8 +8789,10 @@ impl Reverb3d {
match ffi::FMOD_Reverb3D_Set3DAttributes(
self.pointer,
position
.map(|value| &value.into() as *const _)
.unwrap_or(null()),
.map(Vector::into)
.as_ref()
.map(from_ref)
.unwrap_or_else(null),
mindistance,
maxdistance,
) {
Expand Down Expand Up @@ -11638,8 +11699,10 @@ impl Studio {
index,
&attributes.into(),
attenuationposition
.map(|value| &value.into() as *const _)
.unwrap_or(null()),
.map(Vector::into)
.as_ref()
.map(from_ref)
.unwrap_or_else(null),
) {
ffi::FMOD_OK => Ok(()),
error => Err(err_fmod!("FMOD_Studio_System_SetListenerAttributes", error)),
Expand Down Expand Up @@ -12626,12 +12689,23 @@ impl System {
match ffi::FMOD_System_Set3DListenerAttributes(
self.pointer,
listener,
pos.map(|value| &value.into() as *const _).unwrap_or(null()),
vel.map(|value| &value.into() as *const _).unwrap_or(null()),
pos.map(Vector::into)
.as_ref()
.map(from_ref)
.unwrap_or_else(null),
vel.map(Vector::into)
.as_ref()
.map(from_ref)
.unwrap_or_else(null),
forward
.map(|value| &value.into() as *const _)
.unwrap_or(null()),
up.map(|value| &value.into() as *const _).unwrap_or(null()),
.map(Vector::into)
.as_ref()
.map(from_ref)
.unwrap_or_else(null),
up.map(Vector::into)
.as_ref()
.map(from_ref)
.unwrap_or_else(null),
) {
ffi::FMOD_OK => Ok(()),
error => Err(err_fmod!("FMOD_System_Set3DListenerAttributes", error)),
Expand Down
13 changes: 7 additions & 6 deletions tests/manual/getting_started.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use libfmod::ffi::{
FMOD_DEFAULT, FMOD_INIT_NORMAL, FMOD_NONBLOCKING, FMOD_RESULT, FMOD_STUDIO_INIT_NORMAL,
FMOD_SYSTEM_CALLBACK_PREUPDATE,
};
use libfmod::Error::Fmod;
use libfmod::{
ffi, AdvancedSettings, CreateSoundexInfo, DspResampler, Error, Mode, OpenState, Sound, Studio,
StudioAdvancedSettings, System,
ffi, AdvancedSettings, CreateSoundexInfo, DspResampler, Error, Init, Mode, OpenState, Sound,
Studio, StudioAdvancedSettings, System,
};

#[test]
Expand Down Expand Up @@ -87,11 +88,11 @@ fn test_playing_sound() -> Result<(), Error> {
#[test]
fn test_playing_sound_from_data() -> Result<(), Error> {
let system = System::create()?;
system.init(512, FMOD_INIT_NORMAL, None)?;
system.init(512, Init::NORMAL, None)?;
let data = fs::read("./tests/data/Assets/1.ogg").unwrap();
let mut myinfo = CreateSoundexInfo::default();
myinfo.length = data.len() as u32;
let sound = system.create_sound_from(&data, Mode::OPENMEMORY, myinfo)?;
let mut info = CreateSoundexInfo::default();
info.length = data.len() as u32;
let sound = system.create_sound_from(&data, Mode::OPENMEMORY, info)?;
let channel = system.play_sound(sound, None, false)?;
while channel.is_playing()? {
// do something else
Expand Down
18 changes: 18 additions & 0 deletions tests/manual/sound_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ fn test_3d_sound() -> Result<(), Error> {
system.release()
}

#[test]
fn test_3d_optional_parameters() -> Result<(), Error> {
let system = System::create()?;
system.init(512, FMOD_INIT_NORMAL, None)?;
system.set_3d_settings(1.0, 1.0, 1.0)?;

let position = Vector::new(0.1, 0.2, 0.3);
let velocity = Vector::new(0.0, 0.5, 0.0);
let forward = Vector::new(0.0, 0.0, 1.0); // default
let up = Vector::new(0.0, 1.0, 0.0); // default
system.set_3d_listener_attributes(0, Some(position), Some(velocity), None, None)?;

let expected = (position, velocity, forward, up);
let attributes = system.get_3d_listener_attributes(0)?;
assert_eq!(attributes, expected, "position, velocity, forward, up");
system.release()
}

#[test]
fn test_multiple_listeners() -> Result<(), Error> {
let system = System::create()?;
Expand Down

0 comments on commit 631f254

Please sign in to comment.