Set up the basic event loop and threading model.
This commit is contained in:
parent
8edfed0c8c
commit
c83ac39bac
39
src/main.rs
39
src/main.rs
|
|
@ -1,20 +1,14 @@
|
|||
mod gtfs;
|
||||
mod renderer;
|
||||
use std::{collections::HashSet, thread, time::Duration};
|
||||
|
||||
use sdl3::event::{self, Event, EventWatchCallback};
|
||||
|
||||
use std::{collections::HashSet, os, process, thread, time::Duration};
|
||||
use sdl3::{EventPump, event::{self, Event, EventWatchCallback}, sys::init::SDL_Quit};
|
||||
use crate::{gtfs::Gtfs, renderer::Screen};
|
||||
|
||||
|
||||
const SRC_FILE: &str = "/home/nahuel/Downloads/GTFS_Realtime.zip";
|
||||
|
||||
struct Callback{}
|
||||
impl EventWatchCallback for Callback{
|
||||
fn callback(&mut self, event: Event) {
|
||||
println!("Event: {:#?}", event);
|
||||
return;
|
||||
}
|
||||
|
||||
fn refresh_thread() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -40,15 +34,26 @@ fn main() {
|
|||
let mut screen = Screen::init(&screen_prefs);
|
||||
println!("Startup done.");
|
||||
|
||||
screen.print(0, "foo!");
|
||||
// Start an asynchronous refresh thread
|
||||
let _update_thread = thread::Builder::new().name("updater".to_string()).spawn(refresh_thread);
|
||||
|
||||
// Main event loop
|
||||
let mut event_subsystem = screen.get_context().event().unwrap().add_event_watch(Callback{});
|
||||
event_subsystem.activate();
|
||||
let mut event_pump = screen.get_context().event_pump().unwrap();
|
||||
loop {
|
||||
let event = event_pump.wait_event();
|
||||
|
||||
for _ in 0..10 {
|
||||
thread::sleep(Duration::new(1, 0));
|
||||
match event {
|
||||
Event::Quit { timestamp: _ } => {
|
||||
process::exit(0);
|
||||
}
|
||||
event_subsystem.deactivate();
|
||||
|
||||
Event::User { timestamp: _, window_id: _, type_: _, code: _, data1: _, data2: _ } => {
|
||||
// a message from another thread, probably a refresh?
|
||||
}
|
||||
|
||||
// Ignore all other events
|
||||
_ => {}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue