Change project structure for cross build

This commit is contained in:
Synthasmagoria 2026-09-01 14:12:06 +02:00
commit 80b3e83d4d
17 changed files with 44 additions and 43 deletions

View file

@ -1,4 +1,4 @@
package main
package game
import rl "libraries/raylib"
import "core:math"

19
src/desktop/main.odin Normal file
View file

@ -0,0 +1,19 @@
#+build !wasm32, !wasm64p32
package main
import game ".."
import "core:os"
import "core:path/filepath"
main :: proc() {
exe_path := os.args[0]
exe_dir := filepath.dir(string(exe_path))
os.set_working_directory(exe_dir)
game.init()
for game.should_run() {
game.update()
}
game.shutdown()
}

View file

@ -1,4 +1,4 @@
package main
package game
import "core:math/linalg"
import rl "libraries/raylib"

View file

@ -1,4 +1,4 @@
package main
package game
import rl "libraries/raylib"
import "base:runtime"

View file

@ -1,18 +0,0 @@
package main
import rl "libraries/raylib"
import "core:log"
main :: proc() {
// exe_path := os.args[0]
// exe_dir := filepath.dir(string(exe_path))
// os.set_working_directory(exe_dir)
rl.ChangeDirectory(rl.GetApplicationDirectory())
context.logger = log.create_console_logger()
init()
for should_run() {
update()
}
shutdown()
}

View file

@ -1,4 +1,4 @@
package main
package game
/*
Rules of matrices:
@ -1260,7 +1260,7 @@ ui_labeled_input_float_element :: proc(label: cstring, margin: f32, value: ^f32,
ui_labeled_input_text_element :: proc(label: cstring, margin: f32, str: []byte, allocator := context.temp_allocator) -> ^ui.Element {
label := fmt.ctprintf("%s: ", label)
label_element := ui.element(.Label, {}, {label = label, color = ui.col(rl.WHITE), margin = margin})
dimensions := ui.Dimensions{ui.Size_Pixels(64.0), ui.dimensions_pixels(ui.rect_get_size(ui.get_element_outer_area(label_element^))).height}
dimensions := ui.Dimensions{ui.Size_Pixels(224.0), ui.dimensions_pixels(ui.rect_get_size(ui.get_element_outer_area(label_element^))).height}
ui.same_line()
input_data := new(UiElementData_TextInput, context.temp_allocator)
input_data^ = {str = cstring(&str[0])}

View file

@ -1,4 +1,4 @@
package main
package game
PROJECT_DATA_HEADER :: "WOWOWOW THIS IS HEADER WOWOWOW"
PROJECT_DATA_VERSION :: 1

View file

@ -1,7 +1,7 @@
#+build !wasm32
#+build !wasm64p32
package main
package game
import "core:os"
import "core:io"

View file

@ -1,5 +1,5 @@
#+build wasm32, wasm64p32
package main
package game
ProjectReadErrorType :: enum {
LoadingProjectNotSupportedOnWeb,

View file

@ -1,4 +1,4 @@
package main
package game
import rl "libraries/raylib"
import "base:intrinsics"

View file

@ -1,7 +1,7 @@
#+build !wasm32
#+build !wasm64p32
package main
package game
import "core:os"

View file

@ -4,7 +4,7 @@
#+build wasm32, wasm64p32
package main
package game
import "base:runtime"
import "core:log"

115
src/web/index_template.html Normal file
View file

@ -0,0 +1,115 @@
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Odin + Raylib on the web</title>
<meta name="title" content="Odin + Raylib on the web">
<meta name="description" content="Make games using Odin + Raylib that work in the browser">
<meta name="viewport" content="width=device-width">
<style>
body {
margin: 0px;
overflow: hidden;
background-color: black;
}
canvas.game_canvas {
border: 0px none;
background-color: black;
padding-left: 0;
padding-right: 0;
margin-left: auto;
margin-right: auto;
display: block;
}
</style>
</head>
<body>
<canvas class="game_canvas" id="canvas" oncontextmenu="event.preventDefault()" tabindex="-1" onmousedown="event.target.focus()" onkeydown="event.preventDefault()"></canvas>
<script type="text/javascript" src="odin.js"></script>
<script>
var odinMemoryInterface = new odin.WasmMemoryInterface();
odinMemoryInterface.setIntSize(4);
var odinImports = odin.setupDefaultImports(odinMemoryInterface);
// The Module is used as configuration for emscripten.
var Module = {
// This is called by emscripten when it starts up.
instantiateWasm: (imports, successCallback) => {
const newImports = {
...odinImports,
...imports
}
return WebAssembly.instantiateStreaming(fetch("index.wasm"), newImports).then(function(output) {
var e = output.instance.exports;
console.log(e);
odinMemoryInterface.setExports(e);
odinMemoryInterface.setMemory(e.memory);
return successCallback(output.instance);
});
},
// This happens a bit after `instantiateWasm`, when everything is
// done setting up. At that point we can run code.
onRuntimeInitialized: () => {
var e = wasmExports;
// Calls any procedure marked with @init
e._start();
// See source/main_web/main_web.odin for main_start,
// main_update and main_end.
e.main_start();
function send_resize() {
var canvas = document.getElementById('canvas');
e.web_window_size_changed(canvas.width, canvas.height);
}
window.addEventListener('resize', function(event) {
send_resize();
}, true);
// This can probably be done better: Ideally we'd feed the
// initial size to `main_start`. But there seems to be a
// race condition. `canvas` doesn't have it's correct size yet.
send_resize();
// Runs the "main loop".
function do_main_update() {
if (!e.main_update()) {
e.main_end();
// Calls procedures marked with @fini
e._end();
return;
}
window.requestAnimationFrame(do_main_update);
}
window.requestAnimationFrame(do_main_update);
},
print: (function() {
var element = document.getElementById("output");
if (element) element.value = ''; // clear browser cache
return function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
console.log(text);
if (element) {
element.value += text + "\n";
element.scrollTop = element.scrollHeight; // focus on bottom
}
};
})(),
canvas: (function() {
return document.getElementById("canvas");
})()
};
</script>
<!-- Emscripten injects its javascript here -->
{{{ SCRIPT }}}
</body>
</html>

View file

@ -1,7 +1,6 @@
#+build wasm32, wasm64p32
package main
import game ".."
import "core:log"
import "core:mem"
import "core:c"
@ -28,23 +27,23 @@ import "core:fmt"
web_context = context
init()
game.init()
}
@export main_update :: proc "c" () -> bool {
context = web_context
update()
return should_run()
game.update()
return game.should_run()
}
@export main_end :: proc "c" () {
context = web_context
shutdown()
game.shutdown()
}
@export web_window_size_changed :: proc "c" (w: c.int, h: c.int) {
context = web_context
parent_window_size_changed(int(w), int(h))
game.parent_window_size_changed(int(w), int(h))
}
///////////////////////////////////////////////////////