Adding more stuff in
This commit is contained in:
parent
34dad5e000
commit
e28d4fdb22
11
Cargo.toml
11
Cargo.toml
|
|
@ -5,12 +5,11 @@ edition = "2024"
|
||||||
host = "x86_64-unknown-linux-gnu"
|
host = "x86_64-unknown-linux-gnu"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
sdl3 = "0.17.*"
|
sdl3 = {version = "0.17", features = ["ttf"]}
|
||||||
sdl3-ttf-sys = "0.6.*"
|
serde = "1.0"
|
||||||
serde = "*"
|
gtfs-structures = "0.47"
|
||||||
gtfs-structures = "0.47.*"
|
zip = "8.3"
|
||||||
zip = "8.3.*"
|
csv = "1.4"
|
||||||
csv = "1.4.*"
|
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
opt-level = 0
|
opt-level = 0
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,16 @@
|
||||||
use std::{collections::{HashMap, HashSet}, fs::File, hash::Hash};
|
|
||||||
use gtfs_structures::{Calendar, CalendarDate, RawStopTime, RawTrip, Route, Stop};
|
use gtfs_structures::{Calendar, CalendarDate, RawStopTime, RawTrip, Route, Stop};
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
|
use std::{
|
||||||
|
collections::{HashMap, HashSet},
|
||||||
|
fs::File,
|
||||||
|
hash::Hash,
|
||||||
|
};
|
||||||
use zip::ZipArchive;
|
use zip::ZipArchive;
|
||||||
|
|
||||||
use crate::gtfs::{structs::Gtfs, utils::{route_ids_from_numbers, stop_ids_from_codes}};
|
use crate::gtfs::{
|
||||||
|
structs::Gtfs,
|
||||||
|
utils::{route_ids_from_numbers, stop_ids_from_codes},
|
||||||
|
};
|
||||||
|
|
||||||
trait Filter<T> {
|
trait Filter<T> {
|
||||||
fn accept(&self, v: &T) -> bool;
|
fn accept(&self, v: &T) -> bool;
|
||||||
|
|
@ -128,9 +135,12 @@ fn load_vector_map<'a, K, V, IndexFn, FilterT>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn load_gtfs(
|
||||||
pub fn load_gtfs(gtfs: &mut Gtfs, zip_reader: &mut ZipArchive<File>, route_numbers: &HashSet<String>, stop_codes: &HashSet<String>) {
|
gtfs: &mut Gtfs,
|
||||||
|
zip_reader: &mut ZipArchive<File>,
|
||||||
|
route_numbers: &HashSet<String>,
|
||||||
|
stop_codes: &HashSet<String>,
|
||||||
|
) {
|
||||||
// Agencies
|
// Agencies
|
||||||
load_vector(&mut gtfs.agencies, zip_reader, "agency.txt");
|
load_vector(&mut gtfs.agencies, zip_reader, "agency.txt");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,17 @@ mod loader;
|
||||||
mod utils;
|
mod utils;
|
||||||
pub mod structs;
|
pub mod structs;
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap},
|
||||||
fs::File,
|
fs::File,
|
||||||
};
|
};
|
||||||
use crate::gtfs::{loader::load_gtfs, structs::{Arrival, Gtfs, Preferences}};
|
use crate::gtfs::{loader::load_gtfs, structs::{Arrival, Gtfs, Preferences}};
|
||||||
|
|
||||||
|
pub fn _get_next_stops(_gtfs: &Gtfs) -> Vec<Arrival> {
|
||||||
pub fn get_next_stops(gtfs: &Gtfs) -> Vec<Arrival> {
|
|
||||||
let arrivals = Vec::<Arrival>::new();
|
let arrivals = Vec::<Arrival>::new();
|
||||||
|
|
||||||
return arrivals;
|
return arrivals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Load a GTFS structure from a zip file
|
/// Load a GTFS structure from a zip file
|
||||||
pub fn load(src_file: &str, prefs: &Preferences) -> Gtfs {
|
pub fn load(src_file: &str, prefs: &Preferences) -> Gtfs {
|
||||||
// Open zip file
|
// Open zip file
|
||||||
|
|
|
||||||
21
src/main.rs
21
src/main.rs
|
|
@ -1,23 +1,28 @@
|
||||||
mod gtfs;
|
mod gtfs;
|
||||||
use std::{collections::HashSet, time::Instant};
|
mod renderer;
|
||||||
|
use std::{collections::HashSet};
|
||||||
|
|
||||||
use crate::gtfs::structs;
|
|
||||||
|
|
||||||
const SRC_FILE: &str = "/home/nahuel/Downloads/GTFS_Realtime.zip";
|
const SRC_FILE: &str = "/home/nahuel/Downloads/GTFS_Realtime.zip";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
let gtfs_prefs = structs::Preferences {
|
let gtfs_prefs = gtfs::structs::Preferences {
|
||||||
route_numbers: HashSet::from([String::from("15A"), String::from("F1"), String::from("F2"), String::from("F3")]),
|
route_numbers: HashSet::from([String::from("15A"), String::from("F1"), String::from("F2"), String::from("F3")]),
|
||||||
stop_codes: HashSet::from([String::from("1117")])
|
stop_codes: HashSet::from([String::from("1117")])
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let screen_prefs = renderer::structs::Prefs {
|
||||||
|
font_path: String::from("todo!()"),
|
||||||
|
screen_width: 1920,
|
||||||
|
screen_height: 720,
|
||||||
|
};
|
||||||
|
|
||||||
// Init GTFS static info
|
// Init GTFS static info
|
||||||
for _ in 0..1000 {
|
|
||||||
let start_gtfs = Instant::now();
|
|
||||||
println!("Loading GTFS data...");
|
println!("Loading GTFS data...");
|
||||||
let gtfs = gtfs::load(SRC_FILE, >fs_prefs);
|
let _gtfs = gtfs::load(SRC_FILE, >fs_prefs);
|
||||||
println!("Loaded records in {:#?}. Data size: {:#?}", start_gtfs.elapsed(), ::std::mem::size_of_val(>fs))
|
|
||||||
}
|
// Init screen
|
||||||
|
let _screen = renderer::init(&screen_prefs);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
|
||||||
|
pub mod structs;
|
||||||
|
use sdl3::{pixels::Color};
|
||||||
|
use structs::{Prefs, Screen};
|
||||||
|
|
||||||
|
/// Initialize video, allocate buffers and load fonts
|
||||||
|
/// Based on https://github.com/vhspace/sdl3-rs/blob/master/examples/ttf-demo.rs
|
||||||
|
|
||||||
|
pub fn init(prefs: &Prefs) -> &mut structs::Screen {
|
||||||
|
// Initialize the screen
|
||||||
|
let sdl_context = sdl3::init().unwrap();
|
||||||
|
let video_subsys = sdl_context.video().unwrap();
|
||||||
|
|
||||||
|
let window = video_subsys
|
||||||
|
.window("Dublin Bus", prefs.screen_width, prefs.screen_height)
|
||||||
|
.position_centered()
|
||||||
|
.borderless()
|
||||||
|
//.fullscreen()
|
||||||
|
.build().unwrap();
|
||||||
|
|
||||||
|
// Load font
|
||||||
|
let ttf_context = sdl3::ttf::init().unwrap();
|
||||||
|
let mut font = ttf_context.load_font(&prefs.font_path, 128.0).unwrap();
|
||||||
|
|
||||||
|
// Clear screen
|
||||||
|
let mut canvas = window.into_canvas();
|
||||||
|
canvas.set_draw_color(Color::BLACK);
|
||||||
|
canvas.clear();
|
||||||
|
canvas.present();
|
||||||
|
|
||||||
|
let screen = Screen {
|
||||||
|
canvas: &canvas,
|
||||||
|
font: &font,
|
||||||
|
};
|
||||||
|
return &mut &screen;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
use sdl3::{render::Canvas, ttf::Font, video::Window};
|
||||||
|
|
||||||
|
|
||||||
|
pub struct Prefs {
|
||||||
|
pub font_path: String,
|
||||||
|
pub screen_width: u32,
|
||||||
|
pub screen_height: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Screen<'a> {
|
||||||
|
pub canvas: &'a Canvas<Window>,
|
||||||
|
pub font: &'a Font<'a>,
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue