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

Steamdeck Support #77

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ See [the contributing guide](./CONTRIBUTING.md) for instructions on how to get s
- [Confetti mouse demo](./examples/confetti/main.rs)
- [Moving box](./examples/moving-box/main.rs)

## Running
## Running in native window

Run examples (`celeste`, `moving_box`, `confetti`) with:

Expand All @@ -49,3 +49,34 @@ Or run `cargo run --bin` to get a list of the available examples.

Press the `Escape` key to switch between the game and the editor.

## Running on the Steamdeck

Run examples (`celeste`, `moving_box`, `confetti`) with:

```bash
cargo run --bin celeste -- --game --feature steamdeck
cargo run --bin confetti -- --game --feature steamdeck
cargo run --bin moving-box -- --game --feature steamdeck
```

This will ensure to have a better scale/window size which fits the small screen.
Please note for now it only works in desktop mode on the deck

## Running in browser using WASM

Run examples (`celeste`, `moving_box`, `confetti`) with:

```bash
rustup target add wasm32-unknown-emscripten
rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cli

./build_script.sh celeste
```

If you see an error with serve ensure to install the tool as well via cargo.
Alternative you can use any static web server to host the files located in the folder generated

```bash
cd ./generated
```
4 changes: 4 additions & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ runty8 = { path = "../src/runty8" }
runty8-core = { path = "../src/runty8-core" }
log = "0.4"

[features]
default = []
steamdeck = ["runty8/steamdeck"]

[[bin]]
name = "celeste"
path = "./celeste/main.rs"
Expand Down
4 changes: 2 additions & 2 deletions src/runty8-core/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ impl Input {

fn key_to_button(key: Key) -> Option<Button> {
match key {
Key::X => Some(Button::Cross),
Key::C => Some(Button::Circle),
Key::X | Key::Escape => Some(Button::Cross),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm Escape is currently used for switching between the editor and the game 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per default steamdeck button is mapped to escape - It does not cause any big issue.
As I have tested it before

Key::C | Key::Enter => Some(Button::Circle),
Key::LeftArrow => Some(Button::Left),
Key::RightArrow => Some(Button::Right),
Key::UpArrow => Some(Button::Up),
Expand Down
2 changes: 2 additions & 0 deletions src/runty8-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ pub enum Key {
Alt,
///
Space,
///
Enter,
}

/// Keyboard event (key up/down).
Expand Down
5 changes: 4 additions & 1 deletion src/runty8-editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ edition = "2021"
[dependencies]
runty8-core = { path = "../runty8-core" }
runty8-winit = { path = "../runty8-winit" }
runty8-event-loop = { path = "../runty8-event-loop" }
itertools = "0.10"
instant = "0.1"
once_cell = "1.16"
log = "0.4"
runty8-event-loop = { path = "../runty8-event-loop"}

[target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = { version = "0.3", features = ["Window", "Storage"] }
js-sys = { version = "0.3" }
wasm-bindgen = "0.2"

[features]
steamdeck = ["runty8-event-loop/steamdeck"]
4 changes: 4 additions & 0 deletions src/runty8-event-loop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name = "runty8-event-loop"
version = "0.1.0"
edition = "2021"

[features]
default = []
steamdeck = []

[dependencies]
runty8-core = { path = "../runty8-core" }
runty8-winit = { path = "../runty8-winit" }
Expand Down
11 changes: 10 additions & 1 deletion src/runty8-event-loop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ pub fn event_loop(
mut on_event: impl FnMut(Event, &mut ControlFlow, &dyn Fn(&[u8], &mut ControlFlow), &dyn Fn(&str))
+ 'static,
) {
let mut screen_info = ScreenInfo::new(640.0, 640.0);
let (width, height) = get_window_size();

let mut screen_info = ScreenInfo::new(width, height);

let event_loop = EventLoop::new();

Expand Down Expand Up @@ -72,6 +74,13 @@ pub fn event_loop(
})
}

fn get_window_size() -> (f64, f64) {
#[cfg(not(feature = "steamdeck"))]
return (640.0, 640.0);
#[cfg(feature = "steamdeck")]
return (320.0, 320.0);
}

fn draw(gl: &glow::Context, texture: glow::Texture, pixels: &[u8]) {
unsafe {
gl::upload_pixels(gl, texture, pixels);
Expand Down
5 changes: 4 additions & 1 deletion src/runty8-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ edition = "2021"
[dependencies]
runty8-core = { path = "../runty8-core" }
runty8-winit = { path = "../runty8-winit" }
runty8-event-loop = { path = "../runty8-event-loop" }
winit = "0.27"
runty8-event-loop = { path = "../runty8-event-loop"}

[features]
steamdeck = ["runty8-event-loop/steamdeck"]
2 changes: 1 addition & 1 deletion src/runty8-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl Runty8KeyExt for Key {
VirtualKeyCode::Down => Some(Self::DownArrow),
VirtualKeyCode::Escape => Some(Self::Escape),
VirtualKeyCode::LAlt => Some(Self::Alt),
VirtualKeyCode::Space => Some(Self::Space),
VirtualKeyCode::Space => Some(Self::Enter),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise it wont work on the steamdeck

_ => None,
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/runty8/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ edition = "2021"
runty8-core = { path = "../runty8-core" }
runty8-runtime = { path = "../runty8-runtime" }
runty8-editor = { path = "../runty8-editor" }

[features]
steamdeck = ["runty8-runtime/steamdeck"]
Loading