diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b3be999 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,79 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +env: + CARGO_TERM_COLOR: always + +jobs: + # Run cargo test + test: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + name: Test `cargo test` on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + timeout-minutes: 30 + steps: + - name: Checkout sources + uses: actions/checkout@v4 + - name: Cache + uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ matrix.os }}-cargo-test-${{ hashFiles('**/Cargo.toml') }} + - name: Install stable toolchain + uses: dtolnay/rust-toolchain@stable + - name: Install Dependencies + if: matrix.os == 'ubuntu-latest' + run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libopenxr-loader1 libopenxr-dev + - name: Run cargo test + run: cargo test + + # Run cargo clippy -- -D warnings + clippy: + name: Clippy + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: Checkout sources + uses: actions/checkout@v4 + - name: Cache + uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.toml') }} + - name: Add clippy to rustup + run: rustup component add clippy + - name: Install Dependencies + run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev + - name: Run clippy + run: cargo clippy -- -D warnings + + # Run cargo fmt --all -- --check + format: + name: Format + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: Checkout sources + uses: actions/checkout@v4 + - name: Add rustfmt to rustup + run: rustup component add rustfmt + - name: Run cargo fmt + run: cargo fmt --all -- --check diff --git a/.gitignore b/.gitignore index 9dc9aae..7d80a30 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ - **/.DS_Store -assets/** +/assets Cargo.lock -target/** +/target diff --git a/Cargo.toml b/Cargo.toml index 3e5893b..393c226 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,26 +1,30 @@ [package] -name = "osmeta" # OSMeta ??? `#[warn(non_snake_case)]` on by default +name = "osmeta" # OSMeta ??? `#[warn(non_snake_case)]` on by default version = "0.1.0" edition = "2021" # Enable a small amount of optimization in debug mode -#[profile.dev] -#opt-level = 1 +[profile.dev] +opt-level = 1 # Enable high optimizations for dependencies (incl. Bevy), but not for our code: -#[profile.dev.package."*"] -#opt-level = 3 +[profile.dev.package."*"] +opt-level = 3 [dependencies] -bevy = { version = "0.12", features = ["jpeg"] } ## NOT the local file bevy, the one from the net -bevy_flycam = { git = "https://github.com/sburris0/bevy_flycam" } ## control +bevy = { version = "0.12", features = [ + "jpeg", +] } ## NOT the local file bevy, the one from the net +bevy_flycam = { git = "https://github.com/sburris0/bevy_flycam" } ## control +bevy_oxr = { git = "https://github.com/awtterpip/bevy_openxr" } ## bevy_config_cam = { git = "https://github.com/BlackPhlox/bevy_config_cam" } ## { version = "0.3.0"} glam = "0" -#[features] +[features] +#xr = ["bevy_oxr"] #jpeg = ["bevy_internal/jpeg"] diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 0000000..dc87e8a --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +1.74.0 diff --git a/src/main.rs b/src/main.rs index 4c42965..14c0377 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,36 +1,44 @@ +//! Loads and renders a glTF file as a scene. + use bevy::{ pbr::{CascadeShadowConfigBuilder, DirectionalLightShadowMap}, prelude::*, }; use std::f32::consts::*; +use tilemap::TileMap; +use xr::XRPlugin; use bevy_flycam::prelude::*; +use bevy_oxr::DefaultXrPlugins; -//mod geopos; -//use geopos::*; - - +mod tilemap; +mod xr; fn main() { - - App::new() - .insert_resource(DirectionalLightShadowMap { size: 4096 }) + let mut app = App::new(); + if std::env::args().any(|arg| arg == "xr") { + app.add_plugins(DefaultXrPlugins).add_plugins(XRPlugin); + } else { + app.add_plugins(DefaultPlugins); + } + app.insert_resource(DirectionalLightShadowMap { size: 4096 }) .insert_resource(Msaa::Sample4) // Msaa::Sample4 Msaa::default() -- Todo: tut nichts? - .add_plugins(DefaultPlugins) - .add_plugins(bevy::diagnostic::LogDiagnosticsPlugin::default()) - .add_plugins(bevy::diagnostic::FrameTimeDiagnosticsPlugin::default()) + .add_plugins(bevy::diagnostic::FrameTimeDiagnosticsPlugin) .add_systems(Startup, setup) - .add_systems(Update, animate_light_direction) - //.add_systems(Update, _animate_camera_position) - + .add_systems( + Update, + ( + animate_light_direction, + update_active_tile_zone, + tilemap::update, + ), + ) .add_plugins(NoCameraPlayerPlugin) // https://github.com/sburris0/bevy_flycam (bevy_config_cam dies not work wiht Bevy 12) - .run(); } -fn setup(mut commands: Commands, asset_server: Res) { - +fn setup(mut commands: Commands, asset_server: Res, mut meshes: ResMut>) { commands.spawn(( Camera3dBundle { transform: Transform::from_xyz(3., 100., 400.) @@ -56,48 +64,31 @@ fn setup(mut commands: Commands, asset_server: Res) { // only using a single cascade. cascade_shadow_config: CascadeShadowConfigBuilder { num_cascades: 1, - //maximum_distance: 1.6, + //maximum_distance: 1.6, ..default() } .into(), ..default() }); - add_tile(&mut commands, &asset_server,17429, 11369); - add_tile(&mut commands, &asset_server,17429, 11370); - add_tile(&mut commands, &asset_server,17429, 11371); - - add_tile(&mut commands, &asset_server,17430, 11369); - add_tile(&mut commands, &asset_server,17430, 11370); - add_tile(&mut commands, &asset_server,17430, 11371); - - add_tile(&mut commands, &asset_server,17431, 11369); - add_tile(&mut commands, &asset_server,17431, 11370); - add_tile(&mut commands, &asset_server,17431, 11371); - + commands.spawn(TileMap::new(&mut meshes)); } +fn update_active_tile_zone(mut commands: Commands, mut tilemap: Query<&mut TileMap>) { + let mut tilemap = tilemap.single_mut(); + tilemap.load(&mut commands, 17429, 11369); + tilemap.load(&mut commands, 17429, 11370); + tilemap.load(&mut commands, 17429, 11371); -fn add_tile(commands: &mut Commands, asset_server: &Res,x: u32, y: u32) { - // https://gltiles.osm2world.org/glb/lod1/15/17388/11332.glb#Scene0" - - // Just for testing: - const TILE_SIZE: f32 = 814.5; - const X0: u32 = 17430; - const Y0: u32 = 11370; - - let name: String = format!( "models/{}_{}.glb#Scene0",x,y); //format!("hello {}", "world!"); - commands.spawn(SceneBundle { - scene: asset_server.load(name), // "models/17430_11371.glb#Scene0" - transform: Transform::from_xyz( - (x-X0) as f32 * TILE_SIZE, 0., - (y-Y0) as f32 * TILE_SIZE), // OSM y => GPU z - ..default() - }); + tilemap.load(&mut commands, 17430, 11369); + tilemap.load(&mut commands, 17430, 11370); + tilemap.load(&mut commands, 17430, 11371); + tilemap.load(&mut commands, 17431, 11369); + tilemap.load(&mut commands, 17431, 11370); + tilemap.load(&mut commands, 17431, 11371); } - fn animate_light_direction( time: Res