Working wasm build!

This commit is contained in:
sergeypdev 2025-07-25 00:38:24 +04:00
parent 456fb19829
commit 5d9d321695
6 changed files with 38 additions and 16 deletions

View File

@ -367,7 +367,7 @@ main :: proc() {
"-sWASM_BIGINT",
"-sWARN_ON_UNDEFINED_SYMBOLS=0",
"-sALLOW_MEMORY_GROWTH",
"-sASSERTIONS=2",
// "-sASSERTIONS=2",
"--shell-file",
"main_web/index_template.html",
"--preload-file",

View File

@ -8,7 +8,8 @@ import "core:sync"
import "libs:tracy"
// When enabled name globals will be initialized automatically
NAME_STATIC_INIT :: #config(NAME_STATIC_INIT, true)
// TODO: this breaks wasm, because it's trying to allocate something before we set up a working allocator...
NAME_STATIC_INIT :: #config(NAME_STATIC_INIT, false)
MAX_STATIC_NAMES :: #config(MAX_STATIC_NAMES, 1024)
Name :: distinct u32

View File

@ -126,6 +126,9 @@ world_init :: proc(world: ^World) {
physics.scene_init(&world.physics_scene, &g_mem.assetman)
}
copy_world :: proc(dst, src: ^World) {
if dst == src {
return
}
copy_track(&dst.track, &src.track)
physics.copy_physics_scene(&dst.physics_scene, &src.physics_scene)
scene_copy(&dst.main_scene, &src.main_scene)
@ -1483,7 +1486,7 @@ game_init :: proc() {
assets.assetman_init(&g_mem.assetman)
editor_state_init(&g_mem.es, 100)
runtime_world_init(&g_mem.runtime_world, DEV_BUILD ? 100 : 2)
runtime_world_init(&g_mem.runtime_world, DEV_BUILD ? 100 : 1)
g_mem.default_font = rl.GetFontDefault()
ui.init(&g_mem.ui_context)
@ -1546,3 +1549,7 @@ game_force_reload :: proc() -> bool {
game_force_restart :: proc() -> bool {
return rl.IsKeyPressed(.F6)
}
game_parent_window_size_changed :: proc(w, h: int) {
rl.SetWindowSize(i32(w), i32(h))
}

View File

@ -5,6 +5,7 @@ import "core:container/bit_array"
import "core:log"
import "core:math"
import lg "core:math/linalg"
import "core:sync"
import "game:halfedge"
import rl "libs:raylib"
import "libs:raylib/rlgl"
@ -37,8 +38,10 @@ box_mesh: Convex
@(private = "file")
triangle_mesh: Convex
@(init)
init_box_mesh :: proc() {
@(private = "file")
init_globals_once: sync.Once
init_globals :: proc() {
box_mesh = Convex(halfedge.mesh_from_vertex_index_list(box_corners_norm[:], box_indices[:], 4))
triangle_mesh = Convex(
@ -50,14 +53,16 @@ init_box_mesh :: proc() {
)
}
@(fini)
deinit_box_mesh :: proc() {
delete(box_mesh.vertices)
delete(box_mesh.faces)
delete(box_mesh.edges)
}
// @(fini)
// deinit_box_mesh :: proc() {
// delete(box_mesh.vertices)
// delete(box_mesh.faces)
// delete(box_mesh.edges)
// }
box_to_convex :: proc(box: Box, allocator := context.allocator) -> (convex: Convex) {
sync.once_do(&init_globals_once, init_globals)
convex = halfedge.copy_mesh(box_mesh, allocator)
for &v in convex.vertices {
@ -73,6 +78,8 @@ double_sided_triangle_to_convex :: proc(
) -> (
convex: Convex,
) {
sync.once_do(&init_globals_once, init_globals)
convex = halfedge.copy_mesh(triangle_mesh, allocator)
convex.vertices[0].pos = tri[0]
convex.vertices[1].pos = tri[1]

View File

@ -121,15 +121,21 @@ Sim_State :: struct {
dynamic_tlas: Dynamic_TLAS,
}
DEV_BUILD :: #config(DEV, false)
NUM_SIM_STATES :: 2 when DEV_BUILD else 1
Scene :: struct {
assetman: ^assets.Asset_Manager,
simulation_states: [2]Sim_State,
simulation_states: [NUM_SIM_STATES]Sim_State,
simulation_state_index: i32,
solver_state: Solver_State,
}
// Copy current state to next
copy_sim_state :: proc(dst: ^Sim_State, src: ^Sim_State) {
if dst == src {
return
}
tracy.Zone()
convex_container_reconcile(&src.convex_container)
@ -176,8 +182,9 @@ copy_physics_scene :: proc(dst, src: ^Scene) {
dst.assetman = src.assetman
dst.simulation_state_index = src.simulation_state_index
copy_sim_state(&dst.simulation_states[0], &src.simulation_states[0])
copy_sim_state(&dst.simulation_states[1], &src.simulation_states[1])
for i in 0 ..< NUM_SIM_STATES {
copy_sim_state(&dst.simulation_states[i], &src.simulation_states[i])
}
copy_solver_state(&dst.solver_state, &src.solver_state)
}

View File

@ -25,7 +25,7 @@ main_start :: proc "c" () {
// Since we now use js_wasm32 we should be able to remove this and use
// context.logger = log.create_console_logger(). However, that one produces
// extra newlines on web. So it's a bug in that core lib.
// context.logger = create_emscripten_logger()
context.logger = create_emscripten_logger()
web_context = context
@ -49,5 +49,5 @@ main_end :: proc "c" () {
@(export)
web_window_size_changed :: proc "c" (w: c.int, h: c.int) {
context = web_context
// game.game_parent_window_size_changed(int(w), int(h))
game.game_parent_window_size_changed(int(w), int(h))
}