[oden] Time, path searching, game directory
This commit is contained in:
parent
96e95e22ce
commit
26bfcc7a94
8 changed files with 185 additions and 13 deletions
|
|
@ -3,8 +3,8 @@ use oden_js::{
|
|||
Context, ContextRef, Result, Runtime, Value,
|
||||
};
|
||||
use std::ffi::OsStr;
|
||||
use std::path::Path;
|
||||
use std::sync::mpsc::{channel, Receiver};
|
||||
use std::time::Instant;
|
||||
|
||||
pub mod graphics;
|
||||
use graphics::GraphicsCommand;
|
||||
|
|
@ -13,6 +13,7 @@ mod typescript;
|
|||
use typescript::transpile_to_javascript;
|
||||
|
||||
mod io;
|
||||
mod time;
|
||||
|
||||
struct Loader {}
|
||||
|
||||
|
|
@ -25,8 +26,8 @@ impl Loader {
|
|||
impl ModuleLoader for Loader {
|
||||
fn load(&self, _context: &ContextRef, name: &str) -> Result<ModuleSource> {
|
||||
eprintln!("Loading {name}...");
|
||||
let path = Path::new(name);
|
||||
let contents = std::fs::read_to_string(path)?;
|
||||
let path = io::resolve_path(name, &["ts"])?;
|
||||
let contents = std::fs::read_to_string(&path)?;
|
||||
let contents = if path.extension().and_then(OsStr::to_str) == Some("ts") {
|
||||
transpile_to_javascript(name, contents)?
|
||||
} else {
|
||||
|
|
@ -45,6 +46,8 @@ pub struct ScriptContext {
|
|||
|
||||
gfx: graphics::GraphicsAPI,
|
||||
gfx_receive: Receiver<graphics::GraphicsCommand>,
|
||||
|
||||
time: time::TimeAPI,
|
||||
}
|
||||
|
||||
impl ScriptContext {
|
||||
|
|
@ -61,9 +64,10 @@ impl ScriptContext {
|
|||
let gfx = graphics::GraphicsAPI::define(&context, gfx_send.clone())
|
||||
.expect("Graphics module should load without error");
|
||||
let _io = io::IoAPI::define(&context).expect("IO module should load without error");
|
||||
let time = time::TimeAPI::define(&context).expect("Time module should load without error");
|
||||
|
||||
let module = context
|
||||
.import_module("./src/main.ts", "")
|
||||
.import_module("./main.ts", "")
|
||||
.expect("Unable to load main");
|
||||
|
||||
let init = module
|
||||
|
|
@ -85,6 +89,8 @@ impl ScriptContext {
|
|||
|
||||
gfx,
|
||||
gfx_receive,
|
||||
|
||||
time,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -99,6 +105,10 @@ impl ScriptContext {
|
|||
}
|
||||
|
||||
pub fn update(&mut self) {
|
||||
// Do we update the frame time before of after async completion?
|
||||
// Hmmmmm.
|
||||
self.time.set_frame_time(Instant::now());
|
||||
|
||||
// Tell the runtime to process all pending "jobs". This includes
|
||||
// promise completions.
|
||||
self.context
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue