Add game API proc register_memory()
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|||||||
+15
-12
@@ -25,15 +25,16 @@ g: Game_Memory
|
|||||||
t: Test_Memory
|
t: Test_Memory
|
||||||
|
|
||||||
game_api := core.Game_API {
|
game_api := core.Game_API {
|
||||||
settings = settings,
|
settings = settings,
|
||||||
init_once = init_once,
|
register_memory = register_memory,
|
||||||
init = init,
|
init_once = init_once,
|
||||||
update = update,
|
init = init,
|
||||||
render = render,
|
update = update,
|
||||||
destroy = destroy,
|
render = render,
|
||||||
should_close = should_close,
|
destroy = destroy,
|
||||||
force_reload = force_reload,
|
should_close = should_close,
|
||||||
force_restart = force_restart,
|
force_reload = force_reload,
|
||||||
|
force_restart = force_restart,
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
@@ -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!")
|
||||||
|
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
+10
-9
@@ -6,13 +6,14 @@ import "sindri:base"
|
|||||||
// Types
|
// Types
|
||||||
|
|
||||||
Game_API :: struct {
|
Game_API :: struct {
|
||||||
settings: proc() -> base.Settings,
|
settings: proc() -> base.Settings,
|
||||||
init_once: proc(),
|
register_memory: proc(),
|
||||||
init: proc(),
|
init_once: proc(),
|
||||||
update: proc(dt: f32),
|
init: proc(),
|
||||||
render: proc(),
|
update: proc(dt: f32),
|
||||||
destroy: proc(),
|
render: proc(),
|
||||||
should_close: proc() -> bool,
|
destroy: proc(),
|
||||||
force_reload: proc() -> bool,
|
should_close: proc() -> bool,
|
||||||
force_restart: proc() -> bool,
|
force_reload: proc() -> bool,
|
||||||
|
force_restart: proc() -> bool,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
@@ -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()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user