Skip to content

Add floppy example, port older examples to newer api #39

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

Merged
merged 14 commits into from
May 7, 2024
Merged
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
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
override: true
- name: Setup git submodules
run: git submodule init; git submodule update
- name: Install alsa, udev, glfw3, and wayland
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libglfw3-dev libwayland-dev
- name: Install alsa, udev, glfw3, sdl, and wayland
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libglfw3-dev libwayland-dev libsdl2-dev
if: runner.os == 'linux'
- name: Build & run tests under Windows
run: cargo test
Expand All @@ -52,8 +52,8 @@ jobs:
override: true
- name: Setup git submodules
run: git submodule init; git submodule update
- name: Install alsa, udev, glfw3, and wayland
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libglfw3-dev libwayland-dev
- name: Install alsa, udev, glfw3, sdl, and wayland
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libglfw3-dev libwayland-dev libsdl2-dev
- name: Run doc tests with all features (this also compiles README examples)
run: cargo test --doc --all-features
lint:
Expand All @@ -76,8 +76,8 @@ jobs:
override: true
- name: Setup git submodules
run: git submodule init; git submodule update
- name: Install alsa, udev, glfw3, and wayland
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libglfw3-dev libwayland-dev
- name: Install alsa, udev, glfw3, sdl, and wayland
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libglfw3-dev libwayland-dev libsdl2-dev
- name: Run clippy
run: cargo clippy --workspace --all-targets --all-features
- name: Check format
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ on: [push]
jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Setup git submodules
run: git submodule init; git submodule update
- name: Install alsa, udev, glfw3, sdl, and wayland
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libglfw3-dev libwayland-dev libsdl2-dev
- name: Build
run: cd raylib && cargo build --verbose
# - name: Run tests [Requires window system]
Expand Down
47 changes: 29 additions & 18 deletions raylib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ repository = "https://github.com/deltaphc/raylib-rs"
keywords = ["bindings", "raylib", "gamedev"]
categories = ["api-bindings", "game-engines", "graphics"]
edition = "2018"
autoexamples = false

[dependencies]
raylib-sys = { version = "5.0.0", path = "../raylib-sys" }
Expand All @@ -20,12 +21,18 @@ serde = { version = "1.0.125", features = ["derive"], optional = true }
serde_json = { version = "1.0.64", optional = true }
nalgebra = { version = "0.26", optional = true }
parking_lot = "0.12.1"
tcod = "0.15"
specs-derive = "0.4.1"

[dev-dependencies]
structopt = "0.3"
rand = "0.8.5"
arr_macro = "0.1.3"

[dependencies.specs]
version = "0.16.1"
default-features = false

[features]
nightly = []
with_serde = ["serde", "serde_json"]
Expand All @@ -36,88 +43,92 @@ opengl_33 = ["raylib-sys/opengl_33"]
opengl_21 = ["raylib-sys/opengl_21"]
opengl_es_20 = ["raylib-sys/opengl_es_20"]


[[target.'cfg(not(target_os = "windows"))'.example]]
[[example]]
name = "specs"
path = "examples/samples/specs.rs"
doc-scrape-examples = true

[[target.'cfg(not(target_os = "windows"))'.example]]
[[example]]
name = "rgui"
path = "examples/samples/rgui.rs"
doc-scrape-examples = true

[[target.'cfg(not(target_os = "windows"))'.example]]
[[example]]
name = "arkanoid"
path = "examples/samples/arkanoid.rs"
doc-scrape-examples = true

[[target.'cfg(not(target_os = "windows"))'.example]]
[[example]]
name = "logo"
path = "examples/samples/logo.rs"
doc-scrape-examples = true


[[target.'cfg(not(target_os = "windows"))'.example]]
[[example]]
name = "camera2D"
path = "examples/samples/camera2D.rs"
doc-scrape-examples = true

[[target.'cfg(not(target_os = "windows"))'.example]]
[[example]]
name = "raymarch"
path = "examples/samples/raymarch.rs"
doc-scrape-examples = true

[[target.'cfg(not(target_os = "windows"))'.example]]
[[example]]
name = "font"
path = "examples/samples/font.rs"
doc-scrape-examples = true

[[target.'cfg(not(target_os = "windows"))'.example]]
[[example]]
name = "drop"
path = "examples/samples/drop.rs"
doc-scrape-examples = true

[[target.'cfg(not(target_os = "windows"))'.example]]
[[example]]
name = "texture"
path = "examples/samples/texture.rs"
doc-scrape-examples = true


[[target.'cfg(not(target_os = "windows"))'.example]]
[[example]]
name = "yaw_pitch_roll"
path = "examples/samples/yaw_pitch_roll.rs"
doc-scrape-examples = true

[[target.'cfg(not(target_os = "windows"))'.example]]
[[example]]
name = "roguelike"
path = "examples/samples/roguelike.rs"
required-features = ["with_serde"]
doc-scrape-examples = true

[[target.'cfg(not(target_os = "windows"))'.example]]
[[example]]
name = "input"
path = "examples/samples/input.rs"
doc-scrape-examples = true

[[target.'cfg(not(target_os = "windows"))'.example]]
[[example]]
name = "3d_camera_first_person"
path = "examples/samples/3d_camera_first_person.rs"
doc-scrape-examples = true

[[target.'cfg(not(target_os = "windows"))'.example]]
[[example]]
name = "model_shader"
path = "examples/samples/model_shader.rs"
doc-scrape-examples = true

[[target.'cfg(not(target_os = "windows"))'.example]]
[[example]]
name = "extensions"
path = "examples/samples/extensions.rs"
doc-scrape-examples = true

[[target.'cfg(not(target_os = "windows"))'.example]]
[[example]]
name = "asteroids"
path = "examples/samples/asteroids.rs"
doc-scrape-examples = true

[[example]]
name = "floppy"
path = "examples/samples/floppy.rs"
doc-scrape-examples = true

[package.metadata.docs.rs]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
4 changes: 2 additions & 2 deletions raylib/examples/samples/arkanoid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ fn draw_game(game: &Game, rl: &mut RaylibHandle, thread: &RaylibThread) {
if game.pause {
d.draw_text(
"Game Pause",
(w / 2.0) as i32 - measure_text("Game Paused", 40) / 2,
(w / 2.0) as i32 - d.measure_text("Game Paused", 40) / 2,
(h / 2.0 - 40.0) as i32,
40,
Color::GRAY,
Expand All @@ -332,7 +332,7 @@ fn draw_game(game: &Game, rl: &mut RaylibHandle, thread: &RaylibThread) {
} else {
d.draw_text(
"PRESS [ENTER] TO PLAY AGAIN",
(w / 2.0) as i32 - measure_text("PRESS [ENTER] TO PLAY AGAIN", 20) / 2,
(w / 2.0) as i32 - d.measure_text("PRESS [ENTER] TO PLAY AGAIN", 20) / 2,
(h / 2.0) as i32 - 50,
20,
Color::GRAY,
Expand Down
6 changes: 3 additions & 3 deletions raylib/examples/samples/asteroids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ fn draw_game(game: &Game, rl: &mut RaylibHandle, thread: &RaylibThread) {
if game.victory {
d.draw_text(
"VICTORY",
half_width - measure_text("VICTORY", 20),
half_width - d.measure_text("VICTORY", 20),
half_height,
20,
Color::LIGHTGRAY,
Expand All @@ -619,7 +619,7 @@ fn draw_game(game: &Game, rl: &mut RaylibHandle, thread: &RaylibThread) {
if game.pause {
d.draw_text(
"GAME PAUSED",
half_width - measure_text("GAME PAUSED", 40),
half_width - d.measure_text("GAME PAUSED", 40),
half_height - 40,
40,
Color::GRAY,
Expand All @@ -628,7 +628,7 @@ fn draw_game(game: &Game, rl: &mut RaylibHandle, thread: &RaylibThread) {
} else {
d.draw_text(
"PRESS [ENTER] TO PLAY AGAIN",
half_width - measure_text("PRESS [ENTER] TO PLAY AGAIN", 20),
half_width - d.measure_text("PRESS [ENTER] TO PLAY AGAIN", 20),
half_height - 50,
20,
Color::GRAY,
Expand Down
18 changes: 4 additions & 14 deletions raylib/examples/samples/drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ mod options;
fn main() {
let opt = options::Opt::from_args();
test_rslice(&opt);
test_shader_dropping(&opt);
test_model_dropping(&opt);
test_audio_dropping(&opt);
test_font_dropping(&opt);
Expand All @@ -20,16 +19,6 @@ fn test_rslice(opt: &options::Opt) {
let pallet = img.extract_palette(16);
}

/// Checks that shader files are droppable after window is closed
fn test_shader_dropping(opt: &options::Opt) {
let _ten_millis = time::Duration::from_millis(10);
let _v = {
let (mut rl, thread) = opt.open_window("Drop Shader");
rl.load_shader(&thread, None, Some("static/shader/pbr.fs"))
.expect("shader didn't load")
};
}

/// Checks that model files are droppable after window is closed
fn test_model_dropping(opt: &options::Opt) {
let ten_millis = time::Duration::from_millis(10);
Expand All @@ -56,21 +45,22 @@ fn test_model_dropping(opt: &options::Opt) {
/// Checks that audio files are droppable after window is closed
fn test_audio_dropping(opt: &options::Opt) {
let ten_millis = time::Duration::from_millis(10);
let ra = RaylibAudio::init_audio_device().expect("Failed to initialize audio");
let w = {
let (_, _thread) = raylib::init()
.size(opt.width, opt.height)
.title("Drop")
.build();
Wave::load_wave("static/wave.ogg").expect("couldn't load wave")
ra.new_wave("static/wave.ogg").expect("couldn't load wave")
};
thread::sleep(ten_millis);
let _s = {
let (_rl, _thread) = opt.open_window("Drop Sound");
Sound::load_sound("static/wave.ogg").expect("couldn't load wave")
ra.new_sound("static/wave.ogg").expect("couldn't load wave")
};
thread::sleep(ten_millis);

let _samples = w.load_wave_samples();
let _samples = w.load_samples();
thread::sleep(ten_millis);

// Broken on mac
Expand Down
Loading