first commit

This commit is contained in:
2026-07-27 14:36:37 +01:00
commit e94b26690f
10 changed files with 2434 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
out/
.idea
+11
View File
@@ -0,0 +1,11 @@
zlib License
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
+3
View File
@@ -0,0 +1,3 @@
del /s /f /q .\out\*
xcopy /s /e /y .\template\web .\out
odin build template -target:js_wasm32 -out:out\game.wasm
+4
View File
@@ -0,0 +1,4 @@
yes | del -r ./out\*
# shellcheck disable=SC2216
yes | cp -r ./template\web ./out
odin build template -target:js_wasm32 -out:out/game.wasm
+38
View File
@@ -0,0 +1,38 @@
package js_log
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) {
switch level {
case .Debug: debug(text)
case .Info: info(text)
case .Warning: warn(text)
case .Error: error(text)
case .Fatal: error(text)
case: trace(text)
}
}
create_js_console_logger :: proc(options := log.Default_Console_Logger_Opts) -> log.Logger {
return log.Logger{
lowest_level = .Debug,
procedure = js_console_logger_proc,
options = options,
data = nil
}
}
+20
View File
@@ -0,0 +1,20 @@
package game
import js_log "../lib/js_log"
import log "core:log"
import "base:runtime"
init :: proc(ctx: ^runtime.Context) {
ctx.logger = js_log.create_js_console_logger()
log.info("Initialized")
}
// return false to exit
update :: proc() -> bool {
log.info("Running frame")
return true
}
exit :: proc() {
}
+37
View File
@@ -0,0 +1,37 @@
package main
import game "../src"
import "base:runtime"
// ignored
main :: proc() {}
is_init: bool
init_hook :: proc() {
global_ctx := runtime.default_context_ptr()
game.init(global_ctx)
}
exit_hook :: proc() {
game.exit()
}
update_hook :: proc() -> bool {
return game.update()
}
@(export)
step :: proc(delta_time: f64) -> bool {
if !is_init {
init_hook()
is_init = true
}
if !update_hook() {
exit_hook()
return false
}
return true
}
+14
View File
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<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>
</head>
<body>
<script type="text/javascript" src="index.js"></script>
</body>
</html>
+20
View File
@@ -0,0 +1,20 @@
"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);
})();
+2284
View File
File diff suppressed because it is too large Load Diff