1use std::collections::HashMap;
5use std::time::Instant;
6
7use crate::assets::Assets;
8use crate::audio::AudioOut;
9use crate::gfx::Gfx;
10use crate::host::{Game, Host, LoadOptions, Stop};
11use crate::net::Net;
12use crate::storage::Storage;
13
14pub struct Session {
15 pub name: String,
17 pub wasm: Vec<u8>,
19 pub assets: Assets,
20 pub params: HashMap<String, String>,
21 pub allow_net: bool,
22 pub storage: Storage,
23 pub load: LoadOptions,
24}
25
26impl Session {
27 pub fn start(self, audio: Option<Box<dyn AudioOut>>, gfx: Gfx, reproducible: bool, hashing: bool) -> Result<Game, Stop> {
30 let mut host = Host::new(self.assets, self.params, audio, gfx, Net::new(self.allow_net), self.storage);
31 if reproducible {
32 host.set_reproducible();
33 }
34 host.hashing = hashing;
35 let t0 = Instant::now();
36 let game = Game::load(&self.wasm, host, self.load)?;
37 eprintln!("[gasm] loaded {} in {:.0} ms", self.name, t0.elapsed().as_secs_f64() * 1000.0);
38 Ok(game)
39 }
40}