Skip to content

Commit

Permalink
better ctrl-flow, fix examples and templates
Browse files Browse the repository at this point in the history
  • Loading branch information
boozook committed Sep 28, 2023
1 parent e4c7b94 commit 0f2a7fe
Show file tree
Hide file tree
Showing 24 changed files with 280 additions and 186 deletions.
12 changes: 7 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ menu = { version = "0.1", path = "api/menu", package = "playdate-menu", default-
sound = { version = "0.2", path = "api/sound", package = "playdate-sound", default-features = false }
sprite = { version = "0.1", path = "api/sprite", package = "playdate-sprite", default-features = false }
system = { version = "0.3", path = "api/system", package = "playdate-system", default-features = false }
sys = { version = "0.1", path = "api/sys", package = "playdate-sys", default-features = false }
sys = { version = "0.2", path = "api/sys", package = "playdate-sys", default-features = false }

build = { version = "0.2", path = "support/build", package = "playdate-build", default-features = false }
utils = { version = "0.1", path = "support/utils", package = "playdate-build-utils", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion api/playdate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "playdate"
version = "0.1.4"
version = "0.1.5"
readme = "README.md"
description = "High-level Playdate API"
keywords = ["playdate", "sdk", "api", "gamedev"]
Expand Down
11 changes: 6 additions & 5 deletions api/playdate/examples/hello-world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use gfx::bitmap::Bitmap;
use gfx::bitmap::Color;
use fs::Path;

use sys::EventLoopCtrl;
use system::prelude::*;
use sound::prelude::*;
use player::*;
Expand Down Expand Up @@ -123,7 +124,7 @@ impl State {


/// System event handler
fn event(&'static mut self, event: SystemEvent) -> bool {
fn event(&'static mut self, event: SystemEvent) -> EventLoopCtrl {
match event {
// Initial setup
SystemEvent::Init => {
Expand All @@ -135,14 +136,14 @@ impl State {
},
_ => {},
}
true
EventLoopCtrl::Continue
}
}


impl Update for State {
/// Updates the state
fn update(&mut self) -> bool {
fn update(&mut self) -> UpdateCtrl {
gfx::clear(Color::WHITE);


Expand Down Expand Up @@ -190,14 +191,14 @@ impl Update for State {

System::Default().draw_fps(0, 0);

true
UpdateCtrl::Continue
}
}


/// Entry point
#[no_mangle]
fn event_handler(_api: NonNull<PlaydateAPI>, event: SystemEvent, _sim_key_code: u32) -> bool {
fn event_handler(_api: NonNull<PlaydateAPI>, event: SystemEvent, _sim_key_code: u32) -> EventLoopCtrl {
// Unsafe static storage for our state.
// Usually it's safe because there's only one thread.
pub static mut STATE: Option<State> = None;
Expand Down
15 changes: 7 additions & 8 deletions api/playdate/examples/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ extern crate playdate as pd;
use core::ffi::*;
use core::ptr::NonNull;
use pd::ext::PlaydateAPIExt;
use pd::sys::EventLoopCtrl;
use pd::sys::ffi::PlaydateAPI;
use pd::graphics::video::VideoPlayer;

use fs::Path;
use pd::graphics::*;
use pd::system::prelude::*;
use pd::graphics::*;
use pd::fs::Path;


const VIDEO_PATH: &Path = "examples/video.pdv";
Expand All @@ -31,10 +31,10 @@ struct State {

/// Entry point
#[no_mangle]
fn event_handler(api: NonNull<PlaydateAPI>, event: SystemEvent, _sim_key_code: u32) -> bool {
fn event_handler(api: NonNull<PlaydateAPI>, event: SystemEvent, _sim_key_code: u32) -> EventLoopCtrl {
// Ignore any other events, just for this minimalistic example
if !matches!(event, SystemEvent::Init) {
return true;
return EventLoopCtrl::Continue;
}

// Set FPS
Expand All @@ -61,15 +61,14 @@ fn event_handler(api: NonNull<PlaydateAPI>, event: SystemEvent, _sim_key_code: u
// Draw FPS on-top of the player's render
system.draw_fps(0, 0);

// Continue
true
UpdateCtrl::Continue
},
State { length: player.info().frame_count,
current: 0,
player, },
);

true
EventLoopCtrl::Continue
}


Expand Down
41 changes: 32 additions & 9 deletions api/sound/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "playdate-sound"
version = "0.2.0"
version = "0.2.1"
readme = "README.md"
description = "High-level sound API built on-top of Playdate API"
keywords = ["playdate", "sdk", "api", "gamedev"]
Expand All @@ -19,33 +19,56 @@ lang-items = ["sys/lang-items", "fs/lang-items"]
allocator = ["sys/allocator", "fs/allocator"]
panic-handler = ["sys/panic-handler", "fs/panic-handler"]
eh-personality = ["sys/eh-personality", "fs/eh-personality"]
entry-point = ["sys/entry-point"]
error-ctx = ["sys/error-ctx", "fs/error-ctx"]
bindgen-runtime = ["sys/bindgen-runtime", "fs/bindgen-runtime"]
bindgen-static = ["sys/bindgen-static", "fs/bindgen-static"]
bindings-derive-default = ["sys/bindings-derive-default", "fs/bindings-derive-default"]
bindings-derive-default = [
"sys/bindings-derive-default",
"fs/bindings-derive-default",
]
bindings-derive-eq = ["sys/bindings-derive-eq", "fs/bindings-derive-eq"]
bindings-derive-copy = ["sys/bindings-derive-copy", "fs/bindings-derive-copy"]
bindings-derive-debug = ["sys/bindings-derive-debug", "fs/bindings-derive-debug"]
bindings-derive-debug = [
"sys/bindings-derive-debug",
"fs/bindings-derive-debug",
]
bindings-derive-hash = ["sys/bindings-derive-hash", "fs/bindings-derive-hash"]
bindings-derive-ord = ["sys/bindings-derive-ord", "fs/bindings-derive-ord"]
bindings-derive-partialeq = ["sys/bindings-derive-partialeq", "fs/bindings-derive-partialeq"]
bindings-derive-partialord = ["sys/bindings-derive-partialord", "fs/bindings-derive-partialord"]
bindings-derive-constparamty = ["sys/bindings-derive-constparamty", "fs/bindings-derive-constparamty"]
bindings-documentation = ["sys/bindings-documentation", "fs/bindings-documentation"]
bindings-derive-partialeq = [
"sys/bindings-derive-partialeq",
"fs/bindings-derive-partialeq",
]
bindings-derive-partialord = [
"sys/bindings-derive-partialord",
"fs/bindings-derive-partialord",
]
bindings-derive-constparamty = [
"sys/bindings-derive-constparamty",
"fs/bindings-derive-constparamty",
]
bindings-documentation = [
"sys/bindings-documentation",
"fs/bindings-documentation",
]


[dependencies]
sys = { workspace = true, default-features = false }
fs = { workspace = true, default-features = false }

[dev-dependencies]
gfx = { workspace = true }
system = { workspace = true, features = ["try-trait-v2"] }

[[example]]
name = "sp-simple"
name = "sp"
crate-type = ["dylib", "staticlib"]
path = "examples/sp-simple.rs"
required-features = ["entry-point"]

[[example]]
name = "fp-simple"
name = "fp"
crate-type = ["dylib", "staticlib"]
path = "examples/fp-simple.rs"

Expand Down
30 changes: 22 additions & 8 deletions api/sound/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

High-level sound API built on-top of [playdate-sys][].

Covered components:
Covered parts the sound API:
- File Player
- Sample Player
- Sample
Expand All @@ -11,6 +11,15 @@ Covered components:

⚠️ __Incomplete__, WiP.

Not covered things:
- channel
- synth
- sequence
- effect
- lfo
- envelope
- callbacks

Before the version `0.3` API is unstable and can be changed.


Expand All @@ -24,20 +33,25 @@ Before the version `0.3` API is unstable and can be changed.
[sdk]: https://play.date/dev/#cardSDK
[doc-prerequisites]: https://sdk.play.date/Inside%20Playdate%20with%20C.html#_prerequisites

<!-- ## Usage -->
## Usage

<!-- ... -->
```rust
use playdate_sound::sample::*;
use playdate_sound::player::sp::*;
use playdate_sound::player::Repeat;

<!-- See more in [examples][playdate-sound-examples]. -->
let player = Player::<api::Cache>::new()?;
let sample = Sample::new_from_file("game_main_theme.pda")?;

player.set_sample(&sample);
player.play(Repeat::LoopsEndlessly, 1.0);
```

See more in [examples][playdate-sound-examples].


[playdate-sys]: https://crates.io/crates/playdate-sys
[playdate-sound-examples]: https://github.com/boozook/playdate#//TODO:PATH-TO-EXAMPLES



[playdate-sound-examples]: https://github.com/boozook/playdate/tree/main/api/sound/examples



Expand Down
8 changes: 5 additions & 3 deletions api/sound/examples/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# Examples

⚠️ All of the examples here are very low-level, except for the parts that directly demonstrate the functionality of this package.
Here is two examples:
- `sp` is for `SamplePlayer`, additionally uses other crates with parts of Playdate API to minimize the amount of code
- `fp` is for `FilePlayer`, very low-level, except for the parts that directly demonstrate the functionality of this package


# How to run

```bash
# Simulator:
cargo playdate run -p=playdate-sound --example=fp-simple --features=bindgen-runtime,bindings-derive-debug
cargo playdate run -p=playdate-sound --example=fp
# Device:
cargo playdate run -p=playdate-sound --example=sp-simple --features=bindgen-runtime,bindings-derive-debug --device
cargo playdate run -p=playdate-sound --example=sp --features=entry-point --device
```

More information how to use [cargo-playdate][] in help: `cargo playdate --help`.
Expand Down
Loading

0 comments on commit 0f2a7fe

Please sign in to comment.