changed projects structure

This commit is contained in:
2026-07-27 16:46:46 +01:00
parent e94b26690f
commit 0f97ae9293
9 changed files with 69 additions and 48 deletions
+1
View File
@@ -1,3 +1,4 @@
del /s /f /q .\out\*
xcopy /s /e /y .\template\web .\out
xcopy /s /e /y .\lib\js .\out
odin build template -target:js_wasm32 -out:out\game.wasm
+3 -3
View File
@@ -1,4 +1,4 @@
yes | del -r ./out\*
# shellcheck disable=SC2216
yes | cp -r ./template\web ./out
yes | del -r ./out/*
cp -r ./template/web ./out
cp -r ./lib/js/ ./out
odin build template -target:js_wasm32 -out:out/game.wasm
+26
View File
@@ -0,0 +1,26 @@
class ConsoleApi {
constructor(mem) {
this.mem = mem;
}
trace = (str_ptr, str_len) => {
console.trace(this.mem.loadString(str_ptr, str_len));
};
debug = (str_ptr, str_len) => {
console.debug(this.mem.loadString(str_ptr, str_len));
};
info = (str_ptr, str_len) => {
console.info(this.mem.loadString(str_ptr, str_len));
};
warn = function(str_ptr, str_len) {
console.warn(this.mem.loadString(str_ptr, str_len));
};
error = (str_ptr, str_len) => {
console.error(this.mem.loadString(str_ptr, str_len));
};
}
+13
View File
@@ -0,0 +1,13 @@
package js_console
foreign import "console_api"
@(default_calling_convention="contextless")
foreign console_api {
// you can pass values to the JS side too.
trace :: proc(str: string) ---
debug :: proc(str: string) ---
info :: proc(str: string) ---
warn :: proc(str: string) ---
error :: proc(str: string) ---
}
@@ -1,23 +1,12 @@
package js_log
package js_console
import "core:log"
import "core:mem"
foreign import "js_log"
@(default_calling_convention="contextless")
foreign js_log {
// you can pass values to the JS side too.
trace :: proc(str: string) ---
debug :: proc(str: string) ---
info :: proc(str: string) ---
warn :: proc(str: string) ---
error :: proc(str: string) ---
}
// Beware that .FATAL is logged as .Error as it is not supported by this interface
// Unknown log levels will be logged by calling 'console.trace'
js_console_logger_proc :: proc(data: rawptr, level: log.Level, text: string, options: log.Options, location := #caller_location) {
// right now options are ignored, maybe revisit it later
switch level {
case .Debug: debug(text)
case .Info: info(text)
@@ -28,11 +17,11 @@ js_console_logger_proc :: proc(data: rawptr, level: log.Level, text: string, opt
}
}
create_js_console_logger :: proc(options := log.Default_Console_Logger_Opts) -> log.Logger {
create_js_console_logger :: proc() -> log.Logger {
return log.Logger{
lowest_level = .Debug,
procedure = js_console_logger_proc,
options = options,
options = {},
data = nil
}
}
}
+2 -2
View File
@@ -1,11 +1,11 @@
package game
import js_log "../lib/js_log"
import js_console "../lib/odin/js_console"
import log "core:log"
import "base:runtime"
init :: proc(ctx: ^runtime.Context) {
ctx.logger = js_log.create_js_console_logger()
ctx.logger = js_console.create_js_console_logger()
log.info("Initialized")
}
+3 -4
View File
@@ -28,10 +28,9 @@ step :: proc(delta_time: f64) -> bool {
is_init = true
}
if !update_hook() {
keep_running := update_hook()
if !keep_running {
exit_hook()
return false
}
return true
return keep_running
}
+15 -2
View File
@@ -5,10 +5,23 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Example 1</title>
<title>frigg</title>
</head>
<body>
<script type="text/javascript" src="index.js"></script>
<script type="text/javascript" src="consoleApi.js"></script>
<script type="text/javascript" src="odin.js"></script>
<script type="text/javascript">
"use strict";
(async () => {
let mem = new odin.WasmMemoryInterface()
let apis = {
'console_api' : new ConsoleApi(mem),
};
await odin.runWasm("./game.wasm", null, apis, mem);
})();
</script>
</body>
</html>
-20
View File
@@ -1,20 +0,0 @@
"use strict";
(async () => {
await import("./odin.js"); // from the 'sys/wasm/js'
let mem = new odin.WasmMemoryInterface()
let js_log = {
trace: (str_ptr, str_len) => console.trace(mem.loadString(str_ptr, str_len)),
debug: (str_ptr, str_len) => console.debug(mem.loadString(str_ptr, str_len)),
info : (str_ptr, str_len) => console.info(mem.loadString(str_ptr, str_len)),
warn : (str_ptr, str_len) => console.warn(mem.loadString(str_ptr, str_len)),
error: (str_ptr, str_len) => console.error(mem.loadString(str_ptr, str_len)),
};
let extra = {
'js_log' : js_log
};
await odin.runWasm("./game.wasm", null, extra, mem);
})();