Migrate to Bevy 0.18 (#13)
* update: enable message loop work for Windows and Linux * update: upgrade Bevy to version 0.18 and adjust asset loader for path handling * update: rename bevy_picking to picking in Cargo.toml * update: remove pull_request trigger from CI and change AmbientLight to GlobalAmbientLight * update: remove demo example from workspace and exclude it from tests * update: remove demo package from Cargo.lock --------- Co-authored-by: not-elm <elmgameinfo@gmail.com>
This commit is contained in:
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@@ -1,7 +1,6 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
|
||||
jobs:
|
||||
@@ -29,7 +28,7 @@ jobs:
|
||||
if: runner.os == 'linux'
|
||||
- name: Build & run tests
|
||||
run: |
|
||||
cargo test --workspace --no-default-features
|
||||
cargo test --workspace --no-default-features --tests --exclude demo
|
||||
all-doc-tests:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
37
AGENTS.md
Normal file
37
AGENTS.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# Repository Guidelines
|
||||
|
||||
## Project Structure & Module Organization
|
||||
- `src/`: Public `bevy_cef` crate API surface.
|
||||
- `crates/bevy_cef_core`: Core CEF integration and IPC.
|
||||
- `crates/bevy_cef_debug_render_process`: Debug render-process tool.
|
||||
- `examples/`: Runnable samples (e.g., `simple.rs`, `js_emit.rs`, `brp.rs`).
|
||||
- `assets/`: Local HTML/CSS/JS served via `cef://localhost/`.
|
||||
- `docs/`: Supporting documentation.
|
||||
|
||||
## Build, Test, and Development Commands
|
||||
- `cargo build --features debug`: Build with macOS debug tooling enabled.
|
||||
- `cargo run --example simple --features debug`: Run a basic webview example.
|
||||
- `cargo test --workspace --all-features`: Run tests (currently no automated tests; validates compilation).
|
||||
- `make fix`: Run `cargo clippy --fix` and `cargo fmt --all`.
|
||||
- `make install`: Install and copy the debug render process into the CEF framework (macOS).
|
||||
|
||||
## Coding Style & Naming Conventions
|
||||
- Rust 2024 edition; format with `cargo fmt` before committing.
|
||||
- Lint with `cargo clippy` (see `make fix`).
|
||||
- Naming: `snake_case` for modules/functions/files, `CamelCase` for types/traits, `SCREAMING_SNAKE_CASE` for constants.
|
||||
- Prefer small, focused modules; keep public API in `src/` and implementation in `crates/`.
|
||||
|
||||
## Testing Guidelines
|
||||
- No dedicated test suite yet; rely on examples for manual verification.
|
||||
- Use `examples/` to validate features (IPC, navigation, zoom, devtools).
|
||||
- If adding tests, keep names descriptive (e.g., `test_ipc_roundtrip`) and run with `cargo test --workspace --all-features`.
|
||||
|
||||
## Commit & Pull Request Guidelines
|
||||
- Commit subjects are short, imperative; common prefixes include `add:`, `fix:`, `update:`, `remove:`.
|
||||
- Include PR or issue references when relevant (e.g., `Support Bevy 0.17 (#11)`).
|
||||
- PRs should describe changes, testing performed, and target platform (macOS/Windows/Linux).
|
||||
- For webview or UI changes, include screenshots or short clips when possible.
|
||||
|
||||
## Platform & Configuration Notes
|
||||
- Primary development target is macOS; CEF framework should exist at `$HOME/.local/share/cef`.
|
||||
- Local assets are served as `cef://localhost/<file>`; prefer `CefWebviewUri::local("file.html")`.
|
||||
612
Cargo.lock
generated
612
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -15,7 +15,6 @@ exclude = ["assets/"]
|
||||
resolver = "2"
|
||||
members = [
|
||||
"crates/*",
|
||||
"examples/demo",
|
||||
]
|
||||
|
||||
[workspace.package]
|
||||
@@ -29,18 +28,16 @@ keywords = ["bevy", "cef", "web", "rendering"]
|
||||
categories = ["game-development", "web-programming", "graphics"]
|
||||
|
||||
[workspace.dependencies]
|
||||
bevy = { version = "0.17", default-features = false, features = [
|
||||
bevy = { version = "0.18", default-features = false, features = [
|
||||
"bevy_log",
|
||||
"bevy_window",
|
||||
"bevy_asset",
|
||||
"bevy_sprite",
|
||||
"bevy_pbr",
|
||||
"bevy_winit",
|
||||
"bevy_picking",
|
||||
"bevy_mesh_picking_backend",
|
||||
"bevy_sprite_picking_backend",
|
||||
"picking",
|
||||
] }
|
||||
bevy_remote = "0.17"
|
||||
bevy_remote = "0.18"
|
||||
cef = { version = "139" }
|
||||
cef-dll-sys = { version = "139.0", features = ["sandbox"] }
|
||||
bevy_cef = { path = "." , version = "0.2.0-dev" }
|
||||
|
||||
5937
examples/demo/Cargo.lock
generated
5937
examples/demo/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,13 +0,0 @@
|
||||
[package]
|
||||
name = "demo"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
repository.workspace = true
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
bevy = { workspace = true, default-features = true, features = ["file_watcher"]}
|
||||
bevy_cef = { workspace = true, features = ["debug"] }
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
use bevy::input::common_conditions::input_pressed;
|
||||
use bevy::prelude::*;
|
||||
use bevy::window::PrimaryWindow;
|
||||
use bevy_cef::prelude::*;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins((DefaultPlugins, CefPlugin))
|
||||
.add_systems(
|
||||
Startup,
|
||||
(
|
||||
spawn_camera,
|
||||
spawn_directional_light,
|
||||
spawn_github_webview,
|
||||
spawn_github_io_webview,
|
||||
spawn_ground,
|
||||
enable_ime,
|
||||
),
|
||||
)
|
||||
.insert_resource(AmbientLight::default())
|
||||
.add_systems(
|
||||
Update,
|
||||
(
|
||||
walk::<1, 0>.run_if(input_pressed(KeyCode::ArrowRight)),
|
||||
walk::<-1, 0>.run_if(input_pressed(KeyCode::ArrowLeft)),
|
||||
walk::<0, 1>.run_if(input_pressed(KeyCode::ArrowUp)),
|
||||
walk::<0, -1>.run_if(input_pressed(KeyCode::ArrowDown)),
|
||||
rotate_camera::<1>.run_if(input_pressed(KeyCode::Digit1)),
|
||||
rotate_camera::<-1>.run_if(input_pressed(KeyCode::Digit2)),
|
||||
),
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
fn spawn_camera(mut commands: Commands) {
|
||||
commands.spawn(Camera3d::default());
|
||||
}
|
||||
|
||||
fn spawn_directional_light(mut commands: Commands) {
|
||||
commands.spawn((
|
||||
DirectionalLight {
|
||||
shadows_enabled: true,
|
||||
..default()
|
||||
},
|
||||
Transform::from_translation(Vec3::new(1., 1., 1.)).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
));
|
||||
}
|
||||
|
||||
fn enable_ime(mut primary_window: Query<&mut Window, With<PrimaryWindow>>) {
|
||||
primary_window.single_mut().unwrap().ime_enabled = true;
|
||||
}
|
||||
|
||||
fn spawn_github_webview(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<WebviewExtendStandardMaterial>>,
|
||||
) {
|
||||
commands.spawn((
|
||||
CefWebviewUri::new("https://github.com/not-elm/bevy_cef"),
|
||||
Mesh3d(meshes.add(Plane3d::new(Vec3::Z, Vec2::ONE))),
|
||||
WebviewSize(Vec2::splat(800.0)),
|
||||
MeshMaterial3d(materials.add(WebviewExtendStandardMaterial::default())),
|
||||
Transform::from_translation(Vec3::new(1.5, 0., -4.0)),
|
||||
));
|
||||
}
|
||||
|
||||
fn spawn_github_io_webview(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<WebviewExtendStandardMaterial>>,
|
||||
) {
|
||||
commands.spawn((
|
||||
CefWebviewUri::new("https://not-elm.github.io/bevy_cef"),
|
||||
WebviewSize(Vec2::splat(800.0)),
|
||||
Mesh3d(meshes.add(Plane3d::new(Vec3::Z, Vec2::ONE))),
|
||||
MeshMaterial3d(materials.add(WebviewExtendStandardMaterial::default())),
|
||||
Transform::from_translation(Vec3::new(-1.5, 0., -4.0)), // .with_rotation(Quat::from_rotation_y(-90f32.to_radians())),
|
||||
));
|
||||
}
|
||||
|
||||
fn spawn_ground(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::new(10., 10.)))),
|
||||
MeshMaterial3d(materials.add(StandardMaterial {
|
||||
base_color: Color::srgba(0.8, 0.8, 0.8, 1.0),
|
||||
..default()
|
||||
})),
|
||||
Transform::from_translation(Vec3::new(0., -2., 0.)),
|
||||
));
|
||||
}
|
||||
|
||||
fn walk<const X: isize, const Z: isize>(
|
||||
mut q: Query<&mut Transform, With<Camera3d>>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
for mut t in &mut q {
|
||||
const SPEED: f32 = 1.5; // 調整可
|
||||
let dt = time.delta_secs();
|
||||
|
||||
let up = Vec3::Y;
|
||||
let mut f = t.forward().as_vec3();
|
||||
f = (f - up * f.dot(up)).normalize_or_zero();
|
||||
let r = f.cross(up).normalize_or_zero();
|
||||
|
||||
let input = Vec2::new(X as f32, Z as f32);
|
||||
if input.length_squared() > 0.0 {
|
||||
let dir = (r * input.x + f * input.y).normalize_or_zero();
|
||||
t.translation += dir * SPEED * dt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn rotate_camera<const X: isize>(
|
||||
mut transforms: Query<&mut Transform, With<Camera3d>>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
for mut transform in transforms.iter_mut() {
|
||||
const SPEED: f32 = 1.0;
|
||||
let rotation = Quat::from_rotation_y(SPEED * time.delta_secs() * X as f32);
|
||||
transform.rotation *= rotation;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ impl Plugin for LocalSchemeAssetLoaderPlugin {
|
||||
#[reflect(Component, Debug)]
|
||||
pub struct CefResponseHandle(pub Handle<CefResponse>);
|
||||
|
||||
#[derive(Default)]
|
||||
#[derive(Default, TypePath)]
|
||||
pub struct CefResponseAssetLoader;
|
||||
|
||||
impl AssetLoader for CefResponseAssetLoader {
|
||||
@@ -35,7 +35,7 @@ impl AssetLoader for CefResponseAssetLoader {
|
||||
load_context: &mut LoadContext<'_>,
|
||||
) -> std::result::Result<Self::Asset, Self::Error> {
|
||||
let mut body = Vec::new();
|
||||
let mime_type = get_mime_type(load_context.path())
|
||||
let mime_type = get_mime_type(load_context.path().path())
|
||||
.unwrap_or("text/html")
|
||||
.to_string();
|
||||
reader.read_to_end(&mut body).await?;
|
||||
|
||||
@@ -19,10 +19,8 @@ pub struct MessageLoopPlugin {
|
||||
impl Plugin for MessageLoopPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.insert_non_send_resource(RunOnMainThread)
|
||||
.add_systems(Main, cef_do_message_loop_work)
|
||||
.add_systems(Update, cef_shutdown.run_if(on_message::<AppExit>));
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
app.add_systems(Main, cef_do_message_loop_work);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,8 +60,8 @@ impl Default for MessageLoopPlugin {
|
||||
#[cfg(all(target_os = "macos", feature = "debug"))]
|
||||
no_sandbox: true as _,
|
||||
windowless_rendering_enabled: true as _,
|
||||
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
||||
multi_threaded_message_loop: true as _,
|
||||
// #[cfg(any(target_os = "windows", target_os = "linux"))]
|
||||
// multi_threaded_message_loop: true as _,
|
||||
#[cfg(target_os = "macos")]
|
||||
external_message_pump: true as _,
|
||||
..Default::default()
|
||||
@@ -85,7 +83,6 @@ impl Default for MessageLoopPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn cef_do_message_loop_work(_: NonSend<RunOnMainThread>) {
|
||||
cef::do_message_loop_work();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user