Skip to content
Draft
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
69 changes: 15 additions & 54 deletions components/bevy_shapefile/src/spatial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,70 +80,31 @@ impl FromSql for RoadSection {
}
}

fn read_f64<'a, I>(iter: &mut I, is_big_endian: bool) -> rusqlite::types::FromSqlResult<f64>
fn read_bytes<'a, I, const N: usize>(iter: &mut I) -> rusqlite::types::FromSqlResult<[u8; N]>
where
I: Iterator<Item = &'a u8>,
{
let bytes: [u8; 8] = [
*iter
.next()
.ok_or(rusqlite::types::FromSqlError::InvalidType)?,
*iter
.next()
.ok_or(rusqlite::types::FromSqlError::InvalidType)?,
*iter
.next()
.ok_or(rusqlite::types::FromSqlError::InvalidType)?,
*iter
.next()
.ok_or(rusqlite::types::FromSqlError::InvalidType)?,
*iter
.next()
.ok_or(rusqlite::types::FromSqlError::InvalidType)?,
*iter
.next()
.ok_or(rusqlite::types::FromSqlError::InvalidType)?,
*iter
.next()
.ok_or(rusqlite::types::FromSqlError::InvalidType)?,
*iter
.next()
.ok_or(rusqlite::types::FromSqlError::InvalidType)?,
];

let value = if is_big_endian {
f64::from_be_bytes(bytes)
} else {
f64::from_le_bytes(bytes)
};
let mut bytes = [0u8; N];
for b in &mut bytes {
*b = *iter.next().ok_or(rusqlite::types::FromSqlError::InvalidType)?;
}
Ok(bytes)
}

Ok(value)
fn read_f64<'a, I>(iter: &mut I, is_big_endian: bool) -> rusqlite::types::FromSqlResult<f64>
where
I: Iterator<Item = &'a u8>,
{
let bytes = read_bytes(iter)?;
Ok(if is_big_endian { f64::from_be_bytes(bytes) } else { f64::from_le_bytes(bytes) })
}

fn read_u32<'a, I>(iter: &mut I, is_big_endian: bool) -> rusqlite::types::FromSqlResult<u32>
where
I: Iterator<Item = &'a u8>,
{
let bytes: [u8; 4] = [
*iter
.next()
.ok_or(rusqlite::types::FromSqlError::InvalidType)?,
*iter
.next()
.ok_or(rusqlite::types::FromSqlError::InvalidType)?,
*iter
.next()
.ok_or(rusqlite::types::FromSqlError::InvalidType)?,
*iter
.next()
.ok_or(rusqlite::types::FromSqlError::InvalidType)?,
];
let value = if is_big_endian {
u32::from_be_bytes(bytes)
} else {
u32::from_le_bytes(bytes)
};
Ok(value)
let bytes = read_bytes(iter)?;
Ok(if is_big_endian { u32::from_be_bytes(bytes) } else { u32::from_le_bytes(bytes) })
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down
23 changes: 0 additions & 23 deletions components/highway/src/generation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,6 @@ macro_rules! stopwatch {

(end - start, value)
}};
($x:block) => {{
let start = std::time::Instant::now();
let value = $x;
let end = std::time::Instant::now();

(end - start, value)
}};

(print $x:block) => {{
let (duration, value) = stopwatch!($x);

println!("Duration: {}µs", duration.as_micros());

value
}};

(print $x:expr) => {{
let (duration, value) = stopwatch!($x);

println!("Duration: {}µs", duration.as_micros());

value
}};
}

pub fn calculate_layer<D: NetworkData>(
Expand Down
2 changes: 1 addition & 1 deletion examples/layer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy_dutch_road_highway_node_network::{nwb::NWBNetworkData, read_file, write_file};
use bevy_dutch_road_highway_node_network::{io::{read_file, write_file}, nwb::NWBNetworkData};
use highway::generation::calculate_layer;
use graph::{DirectedNetworkGraph, NetworkData};

Expand Down
11 changes: 0 additions & 11 deletions src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,6 @@ fn load_camera(mut commands: Commands) {
OrthographicProjection::default_3d(),
))
.insert(MainCamera);
// commands
// .spawn(Camera3d {
// transform: ,
// projection: Projection::Orthographic(Default::default()),
// camera: Camera {
// hdr: true,
// ..default()
// },
// ..default()
// })
// .insert(MainCamera);
}

fn camera_system_zoom(
Expand Down
41 changes: 41 additions & 0 deletions src/io.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use serde::{de::DeserializeOwned, Serialize};
use std::{
io::{Cursor, Write},
path::Path,
};

pub fn write_file<T: Serialize, P: AsRef<Path>>(
value: &T,
path: P,
) -> Result<(), Box<dyn std::error::Error>> {
use std::fs::File;

println!("Started writing file: {:?}", path.as_ref());

let code = bincode::serialize(value)?;
let result = zstd::encode_all(Cursor::new(code), 0)?;
let mut file = File::create(&path)?;

file.write_all(&result)?;

println!("Finished writing file: {:?}", path.as_ref());

Ok(())
}

pub fn read_file<T: DeserializeOwned, P: AsRef<Path>>(
path: P,
) -> Result<T, Box<dyn std::error::Error>> {
use std::fs::File;

println!("Started reading file: {:?}", path.as_ref());

let file = File::open(&path)?;

let result = zstd::decode_all(file)?;
let d = bincode::deserialize(&result)?;

println!("Finished reading file: {:?}", path.as_ref());

Ok(d)
}
42 changes: 1 addition & 41 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,48 +1,8 @@
#![feature(map_try_insert)]
use serde::{de::DeserializeOwned, Serialize};
use std::{
io::{Cursor, Write},
path::Path,
};

pub mod camera;
pub mod geo_coords;
pub mod io;
pub mod nwb;
pub mod ui;
pub mod world;

pub fn write_file<T: Serialize, P: AsRef<Path>>(
value: &T,
path: P,
) -> Result<(), Box<dyn std::error::Error>> {
use std::fs::File;

println!("Started writing file: {:?}", path.as_ref());

let code = bincode::serialize(value)?;
let result = zstd::encode_all(Cursor::new(code), 0)?;
let mut file = File::create(&path)?;

file.write_all(&result)?;

println!("Finished writing file: {:?}", path.as_ref());

Ok(())
}

pub fn read_file<T: DeserializeOwned, P: AsRef<Path>>(
path: P,
) -> Result<T, Box<dyn std::error::Error>> {
use std::fs::File;

println!("Started reading file: {:?}", path.as_ref());

let file = File::open(&path)?;

let result = zstd::decode_all(file)?;
let d = bincode::deserialize(&result)?;

println!("Finished reading file: {:?}", path.as_ref());

Ok(d)
}
10 changes: 0 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#![feature(iter_collect_into)]
#![feature(map_try_insert)]
#![feature(test)]
extern crate test;

use bevy::{prelude::*, DefaultPlugins};
use bevy_dutch_road_highway_node_network::{
camera::{CameraConfig, CameraPlugin},
Expand All @@ -14,16 +9,11 @@ use bevy_polyline::PolylinePlugin;
fn main() {
App::new()
.insert_resource(ClearColor(Color::linear_rgb(0.0, 0.0, 0.2)))
// .insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins)
.add_plugins(HighwayUiPlugin)
.add_plugins(PolylinePlugin)
// .add_plugins(LogDiagnosticsPlugin::default())
// .add_plugins(FrameTimeDiagnosticsPlugin::default())
.add_plugins(WorldPlugin {
config: WorldConfig {
// database_path: "data/database.db".into(),
// shapefile_path: "data/01-05-2024/Wegvakken/Wegvakken.shp".into(),
geopackage_path: "data/01-02-2026/Wegvakken/Wegvakken.gpkg".into(),
road_map_path: "data/road_map.data".into(),
directed_graph_path: "data/directed_graph.graph".into(),
Expand Down
Loading