Skip to content
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

Second wave of API changes #116

Merged
merged 40 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5257d16
Renamed init functions to new
Meziu Apr 6, 2023
fe29c25
Derive traits and Screen changes
Meziu Apr 6, 2023
e06114d
Use usize in RawFrameBuffer
Meziu Apr 6, 2023
31ad7cb
Renamed SystemModel enum variants
Meziu Apr 6, 2023
ef074a6
Fmt and clippy
Meziu Apr 6, 2023
f37ccae
Undo double flush in example
Meziu Apr 6, 2023
7aef0de
Update for linker-fix-3ds rename
Meziu Apr 5, 2023
bca9aa7
fmt
Meziu Apr 5, 2023
a2a990b
Compilation error when romfs can't be found
Meziu Apr 8, 2023
93fdaff
fmt
Meziu Apr 8, 2023
ef4ea17
Compilation error only if feature is set
Meziu Apr 8, 2023
a0e36f3
fmt
Meziu Apr 8, 2023
8821ed4
Explicit DPAD nomenclature
Meziu Apr 11, 2023
80efa80
Update flush_buffer docs
Meziu Apr 11, 2023
71ad3e9
Update gfx.rs
Meziu Apr 12, 2023
683fad4
Initial pass of Swap/Flush traits for screens
ian-h-chamberlain Apr 12, 2023
7ac47b8
Merge branch 'improve/api' into feat/flush-swap-screen-traits
ian-h-chamberlain Apr 12, 2023
0ef017c
Do some cleanup and fix swap trait impls
ian-h-chamberlain Apr 12, 2023
a417218
On second thought, it seems better to reuse traits
ian-h-chamberlain Apr 12, 2023
b239fb8
Update doc comments and bitmap example
ian-h-chamberlain Apr 14, 2023
ff08dd9
Renamed init functions to new
Meziu Apr 6, 2023
ae90fc3
Derive traits and Screen changes
Meziu Apr 6, 2023
bc82d20
Use usize in RawFrameBuffer
Meziu Apr 6, 2023
19349db
Renamed SystemModel enum variants
Meziu Apr 6, 2023
9eecd17
Fmt and clippy
Meziu Apr 6, 2023
d3808d0
Undo double flush in example
Meziu Apr 6, 2023
fcdb184
Explicit DPAD nomenclature
Meziu Apr 11, 2023
9a98f32
Update flush_buffer docs
Meziu Apr 11, 2023
d8af910
Update gfx.rs
Meziu Apr 12, 2023
3e349f8
Fix mutability issues after merge of master
ian-h-chamberlain Apr 14, 2023
9b95c88
Renamed init functions to new
Meziu Apr 6, 2023
c7e6437
Rename N3DS to Old3DS
Meziu Apr 17, 2023
97fce22
Rename MiiIndex to Index
Meziu Apr 17, 2023
09d52ea
Fix doctest fmt
Meziu Apr 17, 2023
b47228f
Fix doctest
Meziu Apr 17, 2023
eb8eaa5
HID Touch and Circlepad refactor + new example
Meziu May 2, 2023
a3fc356
Merge branch 'improve/api' into feat/flush-swap-screen-traits
Meziu May 4, 2023
76ef8e6
Fix merge messages
Meziu May 4, 2023
40e5cc9
Readd trait imports
Meziu May 4, 2023
20a8094
Merge pull request #118 from rust3ds/feat/flush-swap-screen-traits
Meziu May 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ctru-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ name = "ctru"
cfg-if = "1.0"
ctru-sys = { path = "../ctru-sys", version = "21.2" }
const-zero = "0.1.0"
linker-fix-3ds = { git = "https://github.com/rust3ds/rust-linker-fix-3ds.git" }
shim-3ds = { git = "https://github.com/rust3ds/shim-3ds.git" }
pthread-3ds = { git = "https://github.com/rust3ds/pthread-3ds.git" }
libc = "0.2.121"
bitflags = "1.0.0"
Expand Down
14 changes: 5 additions & 9 deletions ctru-rs/examples/audio-filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ fn fill_buffer(audio_data: &mut [u8], frequency: f32) {
fn main() {
ctru::use_panic_handler();

let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut());
let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::new(gfx.top_screen.borrow_mut());

let mut note: usize = 4;

Expand Down Expand Up @@ -68,7 +68,7 @@ fn main() {
let mut wave_info1 = Wave::new(audio_data1, AudioFormat::PCM16Stereo, false);
let mut wave_info2 = Wave::new(audio_data2, AudioFormat::PCM16Stereo, false);

let mut ndsp = Ndsp::init().expect("Couldn't obtain NDSP controller");
let mut ndsp = Ndsp::new().expect("Couldn't obtain NDSP controller");

// This line isn't needed since the default NDSP configuration already sets the output mode to `Stereo`
ndsp.set_output_mode(OutputMode::Stereo);
Expand Down Expand Up @@ -154,10 +154,6 @@ fn main() {
altern = !altern;
}

// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();

//Wait for VBlank
gfx.wait_for_vblank();
}
Expand Down
11 changes: 4 additions & 7 deletions ctru-rs/examples/buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use ctru::prelude::*;
fn main() {
ctru::use_panic_handler();

let apt = Apt::init().unwrap();
let mut hid = Hid::init().unwrap();
let gfx = Gfx::init().unwrap();
let console = Console::init(gfx.top_screen.borrow_mut());
let apt = Apt::new().unwrap();
let mut hid = Hid::new().unwrap();
let gfx = Gfx::new().unwrap();
let console = Console::new(gfx.top_screen.borrow_mut());

println!("Hi there! Try pressing a button");
println!("\x1b[29;16HPress Start to exit");
Expand Down Expand Up @@ -63,9 +63,6 @@ fn main() {
// Save our current key presses for the next frame
old_keys = keys;

// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank();
}
}
32 changes: 14 additions & 18 deletions ctru-rs/examples/camera-image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@ const WAIT_TIMEOUT: Duration = Duration::from_millis(300);
fn main() {
ctru::use_panic_handler();

let apt = Apt::init().expect("Failed to initialize Apt service.");
let mut hid = Hid::init().expect("Failed to initialize Hid service.");
let gfx = Gfx::init().expect("Failed to initialize GFX service.");
let apt = Apt::new().expect("Failed to initialize Apt service.");
let mut hid = Hid::new().expect("Failed to initialize Hid service.");
let gfx = Gfx::new().expect("Failed to initialize GFX service.");

gfx.top_screen.borrow_mut().set_double_buffering(true);
gfx.top_screen
.borrow_mut()
.set_framebuffer_format(FramebufferFormat::Rgb565);
gfx.bottom_screen.borrow_mut().set_double_buffering(false);
let _console = Console::init(gfx.bottom_screen.borrow_mut());
let mut top_screen = gfx.top_screen.borrow_mut();
top_screen.set_double_buffering(true);
top_screen.set_framebuffer_format(FramebufferFormat::Rgb565);

let _console = Console::new(gfx.bottom_screen.borrow_mut());

let mut keys_down;

println!("Initializing camera");

let mut cam = Cam::init().expect("Failed to initialize CAM service.");
let mut cam = Cam::new().expect("Failed to initialize CAM service.");

{
let camera = &mut cam.outer_right_cam;
Expand Down Expand Up @@ -86,15 +85,12 @@ fn main() {
cam.play_shutter_sound(ShutterSound::Normal)
.expect("Failed to play shutter sound");

rotate_image_to_screen(
&buf,
gfx.top_screen.borrow_mut().raw_framebuffer().ptr,
WIDTH,
HEIGHT,
);
rotate_image_to_screen(&buf, top_screen.raw_framebuffer().ptr, WIDTH, HEIGHT);

// We will only flush the "camera" screen, since the other screen is handled by `Console`
top_screen.flush_buffer();
top_screen.swap_buffers();

gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank();
}
}
Expand Down
16 changes: 7 additions & 9 deletions ctru-rs/examples/file-explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use std::path::{Path, PathBuf};
fn main() {
ctru::use_panic_handler();

let apt = Apt::init().unwrap();
let mut hid = Hid::init().unwrap();
let gfx = Gfx::init().unwrap();
let apt = Apt::new().unwrap();
let mut hid = Hid::new().unwrap();
let gfx = Gfx::new().unwrap();

#[cfg(all(feature = "romfs", romfs_exists))]
let _romfs = ctru::services::romfs::RomFS::init().unwrap();
let _romfs = ctru::services::romfs::RomFS::new().unwrap();

FileExplorer::init(&apt, &mut hid, &gfx).run();
FileExplorer::new(&apt, &mut hid, &gfx).run();
}

struct FileExplorer<'a> {
Expand All @@ -32,10 +32,10 @@ struct FileExplorer<'a> {
}

impl<'a> FileExplorer<'a> {
fn init(apt: &'a Apt, hid: &'a mut Hid, gfx: &'a Gfx) -> Self {
fn new(apt: &'a Apt, hid: &'a mut Hid, gfx: &'a Gfx) -> Self {
let mut top_screen = gfx.top_screen.borrow_mut();
top_screen.set_wide_mode(true);
let console = Console::init(top_screen);
let console = Console::new(top_screen);

FileExplorer {
apt,
Expand Down Expand Up @@ -68,8 +68,6 @@ impl<'a> FileExplorer<'a> {
self.get_input_and_run(Self::set_exact_path);
}

self.gfx.flush_buffers();
self.gfx.swap_buffers();
self.gfx.wait_for_vblank();
}
}
Expand Down
10 changes: 4 additions & 6 deletions ctru-rs/examples/futures-basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use std::os::horizon::thread::BuilderExt;
fn main() {
ctru::use_panic_handler();

let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut());
let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::new(gfx.top_screen.borrow_mut());

// Give ourselves up to 30% of the system core's time
apt.set_app_cpu_time_limit(30)
Expand Down Expand Up @@ -68,8 +68,6 @@ fn main() {
frame_count = 0;
}

gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank();
}
}
10 changes: 4 additions & 6 deletions ctru-rs/examples/futures-tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use std::time::Duration;
fn main() {
ctru::use_panic_handler();

let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut());
let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::new(gfx.top_screen.borrow_mut());

// Give ourselves up to 30% of the system core's time
apt.set_app_cpu_time_limit(30)
Expand Down Expand Up @@ -63,8 +63,6 @@ fn main() {
break;
}

gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank();
}
}
13 changes: 6 additions & 7 deletions ctru-rs/examples/gfx-3d-mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ static ZERO: &[u8] = &[0; IMAGE.len()];
fn main() {
ctru::use_panic_handler();

let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.bottom_screen.borrow_mut());
let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::new(gfx.bottom_screen.borrow_mut());

println!("Press Start to exit.\nPress A to switch sides (be sure to have 3D mode enabled).");

Expand Down Expand Up @@ -61,9 +61,8 @@ fn main() {
buf.copy_from(IMAGE.as_ptr(), IMAGE.len());
}

// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();
left.flush_buffer();
left.swap_buffers();
Meziu marked this conversation as resolved.
Show resolved Hide resolved

//Wait for VBlank
gfx.wait_for_vblank();
Expand Down
12 changes: 5 additions & 7 deletions ctru-rs/examples/gfx-wide-mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use ctru::prelude::*;
fn main() {
ctru::use_panic_handler();

let apt = Apt::init().unwrap();
let mut hid = Hid::init().unwrap();
let gfx = Gfx::init().unwrap();
let mut console = Console::init(gfx.top_screen.borrow_mut());
let apt = Apt::new().unwrap();
let mut hid = Hid::new().unwrap();
let gfx = Gfx::new().unwrap();
let mut console = Console::new(gfx.top_screen.borrow_mut());

println!("Press A to enable/disable wide screen mode.");

Expand All @@ -23,12 +23,10 @@ fn main() {
let wide_mode = gfx.top_screen.borrow().is_wide();
gfx.top_screen.borrow_mut().set_wide_mode(!wide_mode);

console = Console::init(gfx.top_screen.borrow_mut());
console = Console::new(gfx.top_screen.borrow_mut());
println!("Press A to enable/disable wide screen mode.");
}

gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank();
}
}
12 changes: 6 additions & 6 deletions ctru-rs/examples/graphics-bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ static IMAGE: &[u8] = include_bytes!("assets/ferris.rgb");
fn main() {
ctru::use_panic_handler();

let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut());
let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::new(gfx.top_screen.borrow_mut());

println!("\x1b[21;16HPress Start to exit.");

Expand Down Expand Up @@ -48,8 +48,8 @@ fn main() {
}

// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();
bottom_screen.flush_buffer();
bottom_screen.swap_buffers();

//Wait for VBlank
gfx.wait_for_vblank();
Expand Down
10 changes: 4 additions & 6 deletions ctru-rs/examples/hashmaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ fn main() {
// HashMaps generate hashes thanks to the 3DS' cryptografically secure generator.
// This generator is only active when activating the `PS` service.
// This service is automatically initialized.
let apt = Apt::init().unwrap();
let mut hid = Hid::init().unwrap();
let gfx = Gfx::init().unwrap();
let _console = Console::init(gfx.top_screen.borrow_mut());
let apt = Apt::new().unwrap();
let mut hid = Hid::new().unwrap();
let gfx = Gfx::new().unwrap();
let _console = Console::new(gfx.top_screen.borrow_mut());

let mut map = std::collections::HashMap::new();
map.insert("A Key!", 102);
Expand All @@ -21,8 +21,6 @@ fn main() {
println!("{map:#?}");

while apt.main_loop() {
gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank();

hid.scan_input();
Expand Down
12 changes: 5 additions & 7 deletions ctru-rs/examples/hello-both-screens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ use ctru::prelude::*;
fn main() {
ctru::use_panic_handler();

let apt = Apt::init().unwrap();
let mut hid = Hid::init().unwrap();
let gfx = Gfx::init().unwrap();
let apt = Apt::new().unwrap();
let mut hid = Hid::new().unwrap();
let gfx = Gfx::new().unwrap();

// Start a console on the top screen
let top_screen = Console::init(gfx.top_screen.borrow_mut());
let top_screen = Console::new(gfx.top_screen.borrow_mut());

// Start a console on the bottom screen.
// The most recently initialized console will be active by default
let bottom_screen = Console::init(gfx.bottom_screen.borrow_mut());
let bottom_screen = Console::new(gfx.bottom_screen.borrow_mut());

// Let's print on the top screen first
top_screen.select();
Expand All @@ -27,8 +27,6 @@ fn main() {
println!("\x1b[29;16HPress Start to exit");

while apt.main_loop() {
gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank();

hid.scan_input();
Expand Down
11 changes: 4 additions & 7 deletions ctru-rs/examples/hello-world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use std::io::BufWriter;
fn main() {
ctru::use_panic_handler();

let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut());
let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::new(gfx.top_screen.borrow_mut());

let out = b"Hello fellow Rustaceans, I'm on the Nintendo 3DS!";
let width = 24;
Expand All @@ -29,9 +29,6 @@ fn main() {
if hid.keys_down().contains(KeyPad::START) {
break;
}
// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();
Meziu marked this conversation as resolved.
Show resolved Hide resolved

//Wait for VBlank
gfx.wait_for_vblank();
Expand Down
11 changes: 4 additions & 7 deletions ctru-rs/examples/linear-memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use ctru::prelude::*;
fn main() {
ctru::use_panic_handler();

let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut());
let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::new(gfx.top_screen.borrow_mut());

let linear_space_before = LinearAllocator::free_space();

Expand Down Expand Up @@ -37,9 +37,6 @@ fn main() {
if hid.keys_down().contains(KeyPad::START) {
break;
}
// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();

//Wait for VBlank
gfx.wait_for_vblank();
Expand Down
Loading