fmod/studio/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 bank;
12mod builder;
13mod callback;
14mod command_replay;
15mod general;
16mod lifecycle;
17mod listener;
18mod misc;
19mod parameter;
20mod plugins;
21mod profiling; // things too small to really make their own module
22
23pub use bank::LoadBankUserdata;
24pub use builder::SystemBuilder;
25pub use callback::SystemCallback;
26
27/// The main system object for FMOD Studio.
28///
29/// Initializing the FMOD Studio System object will also initialize the core System object.
30///
31/// Created with [`SystemBuilder`], which handles initialization for you.
32#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
33#[repr(transparent)] // so we can transmute between types
34pub struct System {
35 pub(crate) inner: NonNull<FMOD_STUDIO_SYSTEM>,
36}
37
38impl System {
39 /// # Safety
40 ///
41 /// `value` must be a valid pointer either aquired from [`Self::as_ptr`] or FMOD.
42 ///
43 /// # Panics
44 ///
45 /// Panics if `value` is null.
46 pub unsafe fn from_ffi(value: *mut FMOD_STUDIO_SYSTEM) -> Self {
47 let inner = NonNull::new(value).unwrap();
48 System { inner }
49 }
50
51 /// Converts `self` into its raw representation.
52 pub fn as_ptr(self) -> *mut FMOD_STUDIO_SYSTEM {
53 self.inner.as_ptr()
54 }
55}
56
57/// Convert a System instance to its FFI equivalent.
58///
59/// This is safe, provided you don't use the pointer.
60impl From<System> for *mut FMOD_STUDIO_SYSTEM {
61 fn from(value: System) -> Self {
62 value.inner.as_ptr()
63 }
64}
65
66/// Most of FMOD is thread safe.
67/// There are some select functions that are not thread safe to call, those are marked as unsafe.
68#[cfg(not(feature = "thread-unsafe"))]
69unsafe impl Send for System {}
70#[cfg(not(feature = "thread-unsafe"))]
71unsafe impl Sync for System {}