mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 06:38:47 +00:00
Update time procedures for js targets
This commit is contained in:
+17
-8
@@ -2,22 +2,31 @@
|
|||||||
//+build js
|
//+build js
|
||||||
package time
|
package time
|
||||||
|
|
||||||
_IS_SUPPORTED :: false
|
foreign import "odin_env"
|
||||||
|
|
||||||
|
_IS_SUPPORTED :: true
|
||||||
|
|
||||||
_now :: proc "contextless" () -> Time {
|
_now :: proc "contextless" () -> Time {
|
||||||
return {}
|
foreign odin_env {
|
||||||
|
time_now :: proc "contextless" () -> i64 ---
|
||||||
|
}
|
||||||
|
return Time{time_now()}
|
||||||
}
|
}
|
||||||
|
|
||||||
_sleep :: proc "contextless" (d: Duration) {
|
_sleep :: proc "contextless" (d: Duration) {
|
||||||
|
foreign odin_env {
|
||||||
|
time_sleep :: proc "contextless" (ms: u32) ---
|
||||||
|
}
|
||||||
|
if d > 0 {
|
||||||
|
time_sleep(u32(d/1e6))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_tick_now :: proc "contextless" () -> Tick {
|
_tick_now :: proc "contextless" () -> Tick {
|
||||||
// mul_div_u64 :: proc "contextless" (val, num, den: i64) -> i64 {
|
foreign odin_env {
|
||||||
// q := val / den
|
tick_now :: proc "contextless" () -> i64 ---
|
||||||
// r := val % den
|
}
|
||||||
// return q * num + r * num / den
|
return Tick{tick_now()}
|
||||||
// }
|
|
||||||
return {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_yield :: proc "contextless" () {
|
_yield :: proc "contextless" () {
|
||||||
|
|||||||
Vendored
+10
@@ -1280,8 +1280,18 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement) {
|
|||||||
evaluate: (str_ptr, str_len) => { eval.call(null, wasmMemoryInterface.loadString(str_ptr, str_len)); },
|
evaluate: (str_ptr, str_len) => { eval.call(null, wasmMemoryInterface.loadString(str_ptr, str_len)); },
|
||||||
|
|
||||||
time_now: () => {
|
time_now: () => {
|
||||||
|
// convert ms to ns
|
||||||
|
return Date.now() * 1e6;
|
||||||
|
},
|
||||||
|
time_tick_now: () => {
|
||||||
|
// convert ms to ns
|
||||||
return performance.now() * 1e6;
|
return performance.now() * 1e6;
|
||||||
},
|
},
|
||||||
|
time_sleep: (duration_ms) => {
|
||||||
|
if (duration_ms > 0) {
|
||||||
|
// TODO(bill): Does this even make any sense?
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
sqrt: (x) => Math.sqrt(x),
|
sqrt: (x) => Math.sqrt(x),
|
||||||
sin: (x) => Math.sin(x),
|
sin: (x) => Math.sin(x),
|
||||||
|
|||||||
Reference in New Issue
Block a user