Add game API proc register_memory()

This commit is contained in:
Riyyi
2026-11-14 15:26:17 +01:00
parent 657d0e21fd
commit ac861fe881
7 changed files with 38 additions and 26 deletions
+2
View File
@@ -40,6 +40,8 @@ vendor
- microui (temp) - microui (temp)
- box3d? - box3d?
- build.sh -> bootstrap shim for `compile/build.odin` - build.sh -> bootstrap shim for `compile/build.odin`
- stb
- kb (https://github.com/JimmyLefevre/kb)
## Hot Reload ## Hot Reload
+6 -3
View File
@@ -26,6 +26,7 @@ t: Test_Memory
game_api := core.Game_API { game_api := core.Game_API {
settings = settings, settings = settings,
register_memory = register_memory,
init_once = init_once, init_once = init_once,
init = init, init = init,
update = update, update = update,
@@ -54,13 +55,15 @@ settings :: proc() -> base.Settings {
} }
} }
init_once :: proc() { register_memory :: proc() {
fmt.println("init once")
base.register_region("game_memory", &g, size_of(Game_Memory)) base.register_region("game_memory", &g, size_of(Game_Memory))
base.register_region("test_memory", &t, size_of(Test_Memory)) base.register_region("test_memory", &t, size_of(Test_Memory))
} }
init_once :: proc() {
fmt.println("init once")
}
init :: proc() { init :: proc() {
fmt.println("hello from .dll!") fmt.println("hello from .dll!")
+2
View File
@@ -1,11 +1,13 @@
{ {
"$schema": "https://raw.githubusercontent.com/DanielGavin/ols/master/misc/odinfmt.schema.json", "$schema": "https://raw.githubusercontent.com/DanielGavin/ols/master/misc/odinfmt.schema.json",
"align_comments": true,
"align_struct_fields": true, "align_struct_fields": true,
"align_struct_values": true, "align_struct_values": true,
"character_width": 80, "character_width": 80,
"indent_cases": true, "indent_cases": true,
"newline_limit": 1, "newline_limit": 1,
"newline_style": "LF", "newline_style": "LF",
"preserve_struct_blank_lines": true,
"sort_imports": true, "sort_imports": true,
"space_single_line_blocks": true, "space_single_line_blocks": true,
"tabs": true, "tabs": true,
+4 -3
View File
@@ -145,13 +145,14 @@ register_region :: proc(
return nil return nil
} }
read_snapshot :: proc() -> os.Error { // returns `fresh` = `true` when booting without a snapshot
read_snapshot :: proc() -> (fresh: bool, err: os.Error) {
assert(hr.region_headers != nil, "[hot-reload] uninitialized") assert(hr.region_headers != nil, "[hot-reload] uninitialized")
assert(hr.regions != nil, "[hot-reload] uninitialized") assert(hr.regions != nil, "[hot-reload] uninitialized")
if !os.exists(hr.snapshot_path) { if !os.exists(hr.snapshot_path) {
hr.write_full_snapshot = true hr.write_full_snapshot = true
return nil return true, nil
} }
snapshot := os.open(hr.snapshot_path, {.Read}) or_return snapshot := os.open(hr.snapshot_path, {.Read}) or_return
@@ -220,7 +221,7 @@ read_snapshot :: proc() -> os.Error {
copy(dest, data_bytes) copy(dest, data_bytes)
} }
return nil return false, nil
} }
// Next write will be a full memory snapshot // Next write will be a full memory snapshot
+1
View File
@@ -7,6 +7,7 @@ import "sindri:base"
Game_API :: struct { Game_API :: struct {
settings: proc() -> base.Settings, settings: proc() -> base.Settings,
register_memory: proc(),
init_once: proc(), init_once: proc(),
init: proc(), init: proc(),
update: proc(dt: f32), update: proc(dt: f32),
+1
View File
@@ -43,6 +43,7 @@ Thing :: struct {
Things :: struct { Things :: struct {
things: [THINGS_MAX]Thing, things: [THINGS_MAX]Thing,
// TODO: Collapse used and gen into 1 array
used: [THINGS_MAX]bool, used: [THINGS_MAX]bool,
gen: [THINGS_MAX]u16, gen: [THINGS_MAX]u16,
free_list: [THINGS_MAX]Thing_Idx, free_list: [THINGS_MAX]Thing_Idx,
+4 -2
View File
@@ -49,9 +49,11 @@ main :: proc() {
base.register_region("things", &things, size_of(core.Things)) base.register_region("things", &things, size_of(core.Things))
api.init_once() api.register_memory()
base.read_snapshot() fresh, err := base.read_snapshot()
fmt.assertf(err == nil, "[main] couldnt read snapshot", err)
if fresh do api.init_once()
api.init() api.init()