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
+4 -3
View File
@@ -145,13 +145,14 @@ register_region :: proc(
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.regions != nil, "[hot-reload] uninitialized")
if !os.exists(hr.snapshot_path) {
hr.write_full_snapshot = true
return nil
return true, nil
}
snapshot := os.open(hr.snapshot_path, {.Read}) or_return
@@ -220,7 +221,7 @@ read_snapshot :: proc() -> os.Error {
copy(dest, data_bytes)
}
return nil
return false, nil
}
// Next write will be a full memory snapshot
+10 -9
View File
@@ -6,13 +6,14 @@ import "sindri:base"
// Types
Game_API :: struct {
settings: proc() -> base.Settings,
init_once: proc(),
init: proc(),
update: proc(dt: f32),
render: proc(),
destroy: proc(),
should_close: proc() -> bool,
force_reload: proc() -> bool,
force_restart: proc() -> bool,
settings: proc() -> base.Settings,
register_memory: proc(),
init_once: proc(),
init: proc(),
update: proc(dt: f32),
render: proc(),
destroy: proc(),
should_close: proc() -> bool,
force_reload: proc() -> bool,
force_restart: proc() -> bool,
}
+1
View File
@@ -43,6 +43,7 @@ Thing :: struct {
Things :: struct {
things: [THINGS_MAX]Thing,
// TODO: Collapse used and gen into 1 array
used: [THINGS_MAX]bool,
gen: [THINGS_MAX]u16,
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))
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()