-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from oli-obk/main
Some initial work
- Loading branch information
Showing
7 changed files
with
393 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
|
||
**/.DS_Store | ||
assets/** | ||
/assets | ||
Cargo.lock | ||
target/** | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.74.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
use std::collections::{BTreeMap, VecDeque}; | ||
|
||
use bevy::prelude::*; | ||
|
||
#[derive(Component, Default)] | ||
pub struct TileMap { | ||
tiles: BTreeMap<i32, BTreeMap<i32, Entity>>, | ||
to_load: VecDeque<(i32, i32)>, | ||
loading: Option<(i32, i32, Handle<Scene>)>, | ||
dummy: Handle<Mesh>, | ||
} | ||
|
||
#[derive(Component)] | ||
pub struct Tile; | ||
|
||
impl TileMap { | ||
pub fn load(&mut self, commands: &mut Commands, x: i32, y: i32) { | ||
self.tiles | ||
.entry(x) | ||
.or_default() | ||
.entry(y) | ||
.or_insert_with(|| { | ||
self.to_load.push_front((x, y)); | ||
let transform = test_transform(x, y); | ||
|
||
commands | ||
.spawn(PbrBundle { | ||
mesh: self.dummy.clone(), | ||
transform, | ||
..default() | ||
}) | ||
.id() | ||
}); | ||
} | ||
} | ||
|
||
pub fn update(mut commands: Commands, server: Res<AssetServer>, mut tilemap: Query<&mut TileMap>) { | ||
for mut tilemap in &mut tilemap { | ||
if let Some((x, y, scene)) = tilemap.loading.take() { | ||
use bevy::asset::LoadState::*; | ||
match server.get_load_state(&scene).unwrap() { | ||
NotLoaded | Loading => { | ||
tilemap.loading = Some((x, y, scene)); | ||
return; | ||
} | ||
Loaded => { | ||
let entity = tilemap.tiles.entry(x).or_default().get_mut(&y).unwrap(); | ||
|
||
let transform = test_transform(x, y); | ||
let tile = commands | ||
.spawn(( | ||
SceneBundle { | ||
scene, // "models/17430_11371.glb#Scene0" | ||
transform, | ||
..default() | ||
}, | ||
Tile, | ||
)) | ||
.id(); | ||
let dummy = std::mem::replace(entity, tile); | ||
commands.entity(dummy).despawn(); | ||
} | ||
Failed => todo!(), | ||
} | ||
} | ||
|
||
assert!(tilemap.loading.is_none()); | ||
let Some((x, y)) = tilemap.to_load.pop_back() else { | ||
return; | ||
}; | ||
|
||
// https://gltiles.osm2world.org/glb/lod1/15/17388/11332.glb#Scene0" | ||
let name: String = format!("models/{}_{}.glb#Scene0", x, y); | ||
tilemap.loading = Some((x, y, server.load(name))); // "models/17430_11371.glb#Scene0" | ||
} | ||
} | ||
|
||
impl TileMap { | ||
pub fn new(meshes: &mut Assets<Mesh>) -> Self { | ||
Self { | ||
dummy: meshes.add( | ||
shape::Box { | ||
min_x: 0.0, | ||
max_x: 814.5, | ||
min_y: 0.0, | ||
max_y: 1.0, | ||
min_z: 0.0, | ||
max_z: 814.5, | ||
} | ||
.into(), | ||
), | ||
..default() | ||
} | ||
} | ||
} | ||
|
||
fn test_transform(x: i32, y: i32) -> Transform { | ||
// Just for testing: | ||
const TILE_SIZE: f32 = 814.5; | ||
const X0: i32 = 17430; | ||
const Y0: i32 = 11370; | ||
|
||
// OSM y => GPU z | ||
Transform::from_xyz((x - X0) as f32 * TILE_SIZE, 0., (y - Y0) as f32 * TILE_SIZE) | ||
} |
Oops, something went wrong.