fmod/core/system/
mod.rs

1// Copyright (c) 2024 Melody Madeline Lyons
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
7use std::ptr::NonNull;
8
9use fmod_sys::*;
10
11mod builder;
12mod callback;
13mod creation;
14mod device_selection;
15mod filesystem;
16mod general;
17mod geometry;
18mod information;
19mod lifetime;
20mod network;
21mod plugin;
22mod recording;
23mod runtime_control;
24mod setup;
25pub use builder::SystemBuilder;
26pub use callback::{ErrorCallbackInfo, Instance, SystemCallback, SystemCallbackMask};
27pub use setup::RolloffCallback;
28
29/// Management object from which all resources are created and played.
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
31#[repr(transparent)] // so we can transmute between types
32pub struct System {
33    pub(crate) inner: NonNull<FMOD_SYSTEM>,
34}
35
36#[cfg(not(feature = "thread-unsafe"))]
37unsafe impl Send for System {}
38#[cfg(not(feature = "thread-unsafe"))]
39unsafe impl Sync for System {}
40
41impl System {
42    /// # Safety
43    ///
44    /// `value` must be a valid pointer either aquired from [`Self::as_ptr`] or FMOD.
45    ///
46    /// # Panics
47    ///
48    /// Panics if `value` is null.
49    pub unsafe fn from_ffi(value: *mut FMOD_SYSTEM) -> Self {
50        let inner = NonNull::new(value).unwrap();
51        System { inner }
52    }
53
54    /// Converts `self` into its raw representation.
55    pub fn as_ptr(self) -> *mut FMOD_SYSTEM {
56        self.inner.as_ptr()
57    }
58}
59
60impl From<System> for *mut FMOD_SYSTEM {
61    fn from(value: System) -> Self {
62        value.inner.as_ptr()
63    }
64}