Add game API proc register_memory()
This commit is contained in:
@@ -40,6 +40,8 @@ vendor
|
||||
- microui (temp)
|
||||
- box3d?
|
||||
- build.sh -> bootstrap shim for `compile/build.odin`
|
||||
- stb
|
||||
- kb (https://github.com/JimmyLefevre/kb)
|
||||
|
||||
## Hot Reload
|
||||
|
||||
|
||||
+15
-12
@@ -25,15 +25,16 @@ g: Game_Memory
|
||||
t: Test_Memory
|
||||
|
||||
game_api := core.Game_API {
|
||||
settings = settings,
|
||||
init_once = init_once,
|
||||
init = init,
|
||||
update = update,
|
||||
render = render,
|
||||
destroy = destroy,
|
||||
should_close = should_close,
|
||||
force_reload = force_reload,
|
||||
force_restart = force_restart,
|
||||
settings = settings,
|
||||
register_memory = register_memory,
|
||||
init_once = init_once,
|
||||
init = init,
|
||||
update = update,
|
||||
render = render,
|
||||
destroy = destroy,
|
||||
should_close = should_close,
|
||||
force_reload = force_reload,
|
||||
force_restart = force_restart,
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
@@ -54,13 +55,15 @@ settings :: proc() -> base.Settings {
|
||||
}
|
||||
}
|
||||
|
||||
init_once :: proc() {
|
||||
fmt.println("init once")
|
||||
|
||||
register_memory :: proc() {
|
||||
base.register_region("game_memory", &g, size_of(Game_Memory))
|
||||
base.register_region("test_memory", &t, size_of(Test_Memory))
|
||||
}
|
||||
|
||||
init_once :: proc() {
|
||||
fmt.println("init once")
|
||||
}
|
||||
|
||||
init :: proc() {
|
||||
fmt.println("hello from .dll!")
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/DanielGavin/ols/master/misc/odinfmt.schema.json",
|
||||
"align_comments": true,
|
||||
"align_struct_fields": true,
|
||||
"align_struct_values": true,
|
||||
"character_width": 80,
|
||||
"indent_cases": true,
|
||||
"newline_limit": 1,
|
||||
"newline_style": "LF",
|
||||
"preserve_struct_blank_lines": true,
|
||||
"sort_imports": true,
|
||||
"space_single_line_blocks": true,
|
||||
"tabs": true,
|
||||
|
||||
@@ -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
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user