-
Notifications
You must be signed in to change notification settings - Fork 473
Adds from_static_bytes function to Chunk struct #922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,6 +250,27 @@ impl Chunk { | |
} | ||
} | ||
|
||
/// Load chunk from a static byte buffer. | ||
pub fn from_static_bytes(buf: &'static [u8]) -> Result<Chunk, String> { | ||
let rw = unsafe { | ||
sys::SDL_RWFromConstMem(buf.as_ptr() as *const c_void, buf.len() as c_int) | ||
}; | ||
|
||
if rw.is_null() { | ||
return Err(get_error()); | ||
} | ||
|
||
let raw = unsafe { mixer::Mix_LoadWAV_RW(rw, 0) }; | ||
if raw.is_null() { | ||
Err(get_error()) | ||
} else { | ||
Ok(Chunk { | ||
raw: raw, | ||
owned: true, | ||
}) | ||
} | ||
Comment on lines
+264
to
+271
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
EDIT: I guess the code base is out-of-date just by looking at the extended diff… or at least different from the latest stable release. I guess this is also one of the things that should be checked after rebasing the fork and before merging it. |
||
} | ||
|
||
/// Set chunk->volume to volume. | ||
pub fn set_volume(&mut self, volume: i32) -> i32 { | ||
unsafe { mixer::Mix_VolumeChunk(self.raw, volume as c_int) as i32 } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you could use
RWops
there (exactlyRWops::from_bytes(buf)
), I've seen other methods to do this and even make it a one-liner inraw
declaration (avoiding declaring another var and doing another check I guess). I'm not sure about the benefits with that other than avoiding the use of anotherunsafe
block (I'm not the Rust expert, so I might still be unfamiliar with that language design and quirks, same goes with SDL2).