Skip to content

Commit

Permalink
doom: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalmiel committed Oct 20, 2024
1 parent 0574556 commit 2c98cf5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 105 deletions.
2 changes: 1 addition & 1 deletion userspace/doom/src/cykusz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl CykuszDoom {
syscall_user::sleep(ms as usize).unwrap();
}

pub fn draw_frame(&mut self, out: &mut DoomScreen) {
pub fn draw_frame(&mut self, out: &DoomScreen) {
self.input.poll();
self.fb.flip(out);
}
Expand Down
84 changes: 4 additions & 80 deletions userspace/doom/src/cykusz/audio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ mod music;
mod sounds;

use crate::cykusz::audio::music::Music;
use crate::doomgeneric::sfxinfo_t;
use fon::chan::{Ch16, Ch32};
use kittyaudio::Frame;
use sounds::Sounds;
use std::os::raw::c_int;
use std::os::unix::net::UnixStream;
use std::process::ExitCode;
use std::sync::Arc;
Expand Down Expand Up @@ -57,85 +55,11 @@ impl Audio {
}
}

pub fn sound_init(&mut self, use_prefix: bool) {
self.sounds.init(use_prefix);
pub fn sound(&mut self) -> &mut Sounds {
&mut self.sounds
}

pub fn sound_shutdown(&mut self) {
self.sounds.shutdown();
}

pub fn sound_sfx_lumpnum(&self, sfx: &mut sfxinfo_t) -> c_int {
self.sounds.sfx_lumpnum(sfx)
}

pub fn sound_update(&mut self) {
self.sounds.update()
}

pub fn sound_update_params(&mut self, channel: c_int, vol: c_int, sep: c_int) {
self.sounds.update_params(channel, vol, sep)
}

pub fn sound_start(
&mut self,
sfx: &mut sfxinfo_t,
channel: c_int,
vol: c_int,
sep: c_int,
) -> c_int {
self.sounds.start(sfx, channel, vol, sep)
}

pub fn sound_stop(&mut self, channel: c_int) {
self.sounds.stop(channel)
}

pub fn sound_is_playing(&self, channel: c_int) -> bool {
self.sounds.is_playing(channel)
}

pub fn sound_cache(&mut self, sounds: &mut [sfxinfo_t]) {
self.sounds.cache_sounds(sounds)
}

pub fn music_shutdown(&mut self) {
self.music.shutdown()
}

pub fn music_set_volume(&mut self, volume: c_int) {
self.music.set_volume(volume)
}

pub fn music_pause(&mut self) {
self.music.pause()
}

pub fn music_resume(&mut self) {
self.music.resume()
}

pub fn music_register_song(&mut self, data: &[u8]) -> *mut () {
self.music.register_song(data)
}

pub fn music_unregister_song(&mut self, handle: *mut ()) {
self.music.unregister_song(handle)
}

pub fn music_play_song(&mut self, handle: *mut (), looping: bool) {
self.music.play_song(handle, looping)
}

pub fn music_stop_song(&mut self) {
self.music.stop_song()
}

pub fn music_is_playing(&self) -> bool {
self.music.is_playing()
}

pub fn music_poll(&mut self) {
self.music.poll()
pub fn music(&mut self) -> &mut Music {
&mut self.music
}
}
8 changes: 4 additions & 4 deletions userspace/doom/src/cykusz/fb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ impl Fb {
fb
}

pub fn flip(&mut self, out: &mut DoomScreen) {
pub fn flip(&mut self, from: &DoomScreen) {
if let Some(mem) = self.mem.as_mut() {
for i in 0..out.height {
mem[i * self.pitch..i * self.pitch + out.width]
.copy_from_slice(&out.map[i * out.width..i * out.width + out.width])
for i in 0..from.height {
mem[i * self.pitch..i * self.pitch + from.width]
.copy_from_slice(&from.map[i * from.width..i * from.width + from.width])
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion userspace/doom/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn doom<'a>() -> &'a mut cykusz::CykuszDoom {
unsafe { DOOM.as_mut().unwrap_unchecked() }
}

fn doom_screen() -> &'static mut DoomScreen {
fn doom_screen() -> &'static DoomScreen {
unsafe { DOOM_SCREEN.as_mut().unwrap_unchecked() }
}

Expand Down
38 changes: 19 additions & 19 deletions userspace/doom/src/sound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,52 +18,52 @@ extern "C" fn music_init() -> boolean {
}

extern "C" fn music_shutdown() {
crate::doom().audio().music_shutdown()
crate::doom().audio().music().shutdown()
}

extern "C" fn music_set_volume(volume: c_int) {
crate::doom().audio().music_set_volume(volume)
crate::doom().audio().music().set_volume(volume)
}

extern "C" fn music_pause() {
crate::doom().audio().music_pause()
crate::doom().audio().music().pause()
}

extern "C" fn music_resume() {
crate::doom().audio().music_resume()
crate::doom().audio().music().resume()
}

extern "C" fn music_register_song(data: *mut c_void, len: c_int) -> *mut c_void {
let data = unsafe { std::slice::from_raw_parts_mut(data as *mut u8, len as usize) };
crate::doom().audio().music_register_song(data) as *mut c_void
crate::doom().audio().music().register_song(data) as *mut c_void
}

extern "C" fn music_unregister_song(handle: *mut c_void) {
crate::doom()
.audio()
.music_unregister_song(handle as *mut ())
.music().unregister_song(handle as *mut ())
}

extern "C" fn music_play_song(handle: *mut c_void, looping: boolean) {
crate::doom()
.audio()
.music_play_song(handle as *mut (), looping == 1)
.music().play_song(handle as *mut (), looping == 1)
}

extern "C" fn music_stop_song() {
crate::doom().audio().music_stop_song()
crate::doom().audio().music().stop_song()
}

extern "C" fn music_is_playing() -> boolean {
if crate::doom().audio().music_is_playing() {
if crate::doom().audio().music().is_playing() {
1
} else {
0
}
}

extern "C" fn music_poll() {
crate::doom().audio().music_poll()
crate::doom().audio().music().poll()
}

#[no_mangle]
Expand All @@ -84,25 +84,25 @@ static DG_music_module: music_module_t = music_module_t {
};

extern "C" fn sound_init(use_sfx_prefix: boolean) -> boolean {
crate::doom().audio().sound_init(use_sfx_prefix == 1);
crate::doom().audio().sound().init(use_sfx_prefix == 1);
1
}

extern "C" fn sound_shutdown() {
crate::doom().audio().sound_shutdown()
crate::doom().audio().sound().shutdown()
}

extern "C" fn sound_get_sfx_lumpnum(sfxinfo: *mut sfxinfo_t) -> c_int {
crate::doom()
.audio()
.sound_sfx_lumpnum(unsafe { sfxinfo.as_mut_unchecked() })
.sound().sfx_lumpnum(unsafe { sfxinfo.as_mut_unchecked() })
}

extern "C" fn sound_update() {
crate::doom().audio().sound_update()
crate::doom().audio().sound().update()
}
extern "C" fn sound_update_params(channel: c_int, vol: c_int, sep: c_int) {
crate::doom().audio().sound_update_params(channel, vol, sep);
crate::doom().audio().sound().update_params(channel, vol, sep);
}

extern "C" fn sound_start(
Expand All @@ -113,15 +113,15 @@ extern "C" fn sound_start(
) -> c_int {
crate::doom()
.audio()
.sound_start(unsafe { sfxinfo.as_mut_unchecked() }, channel, vol, sep)
.sound().start(unsafe { sfxinfo.as_mut_unchecked() }, channel, vol, sep)
}

extern "C" fn sound_stop(channel: c_int) {
crate::doom().audio().sound_stop(channel);
crate::doom().audio().sound().stop(channel);
}

extern "C" fn sound_is_playing(channel: c_int) -> boolean {
if crate::doom().audio().sound_is_playing(channel) {
if crate::doom().audio().sound().is_playing(channel) {
1
} else {
0
Expand All @@ -131,7 +131,7 @@ extern "C" fn sound_is_playing(channel: c_int) -> boolean {
extern "C" fn sound_cache(sounds: *mut sfxinfo_t, num: c_int) {
let sounds = unsafe { std::slice::from_raw_parts_mut(sounds, num as usize) };

crate::doom().audio().sound_cache(sounds);
crate::doom().audio().sound().cache_sounds(sounds);
}

#[no_mangle]
Expand Down

0 comments on commit 2c98cf5

Please sign in to comment.