Memory setup for hot-reload & save states

This commit is contained in:
Edward R. Gonzalez 2024-01-22 00:22:06 -05:00
parent 3b259f2893
commit 77a48d7104
6 changed files with 36 additions and 24 deletions

Binary file not shown.

View File

@ -23,18 +23,20 @@ ModuleAPI :: struct {
Memory :: struct {
persistent : ^ mem.Arena,
transient : ^ mem.Arena
transient : ^ mem.Arena,
temp : ^ mem.Arena
}
memory : Memory
@export
startup :: proc( persistent, transient : ^ mem.Arena )
startup :: proc( persistent, transient, temp : ^ mem.Arena )
{
memory.persistent = persistent
memory.transient = transient
memory.persistent = persistent
// Anything allocated by default is considered transient.
context.allocator = mem.arena_allocator( transient )
context.temp_allocator = mem.arena_allocator( transient )
context.temp_allocator = mem.arena_allocator( temp )
state := cast(^State) memory.persistent
@ -53,7 +55,7 @@ startup :: proc( persistent, transient : ^ mem.Arena )
// Basic Font Setup
{
path_rec_mono_semicasual_reg := strings.concatenate( { Path_Assets, "RecMonoSemicasual-Regular-1.084.ttf" })
cstr := strings.clone_to_cstring(path_rec_mono_semicasual_reg)
cstr := strings.clone_to_cstring( path_rec_mono_semicasual_reg )
font_rec_mono_semicasual_reg = rl.LoadFontEx( cstr, 24, nil, 0 )
delete( cstr)
@ -71,7 +73,7 @@ sectr_shutdown :: proc()
}
@export
reload :: proc( persistent, transient : ^ mem.Arena )
reload :: proc( persistent, transient, temp : ^ mem.Arena )
{
memory.persistent = persistent
memory.transient = transient

View File

@ -33,7 +33,8 @@ VMemChunk :: struct {
eng_persistent : mem.Arena,
eng_transient : mem.Arena,
env_persistent : mem.Arena,
env_transient : mem.Arena
env_transient : mem.Arena,
env_temp : mem.Arena
}
setup_engine_memory :: proc () -> VMemChunk
@ -57,22 +58,29 @@ setup_engine_memory :: proc () -> VMemChunk
}
// For now I'm making persistent sections each 128 meg and transient sections w/e is left over / 2 (one for engine the other for the env)
persistent_size := Megabyte * 128
transient_size := (Gigabyte * 2 - persistent_size * 2) / 2
persistent_size :: Megabyte * 128 * 2
transient_size :: (Gigabyte * 2 - persistent_size * 2) / 2
eng_persistent_size :: persistent_size / 4
eng_transient_size :: transient_size / 4
env_persistent_size :: persistent_size - eng_persistent_size
env_trans_temp_size :: (transient_size - eng_transient_size) / 2
block := memory.sarena.curr_block
// Try to get a slice for each segment
eng_persistent_slice := slice_ptr( block.base, persistent_size)
eng_transient_slice := slice_ptr( & eng_persistent_slice[persistent_size - 1], transient_size)
env_persistent_slice := slice_ptr( & eng_transient_slice [transient_size - 1], persistent_size)
env_transient_slice := slice_ptr( & env_persistent_slice[persistent_size -1], transient_size)
eng_persistent_slice := slice_ptr( block.base, eng_persistent_size)
eng_transient_slice := slice_ptr( & eng_persistent_slice[ eng_persistent_size - 1], eng_transient_size)
env_persistent_slice := slice_ptr( & eng_transient_slice [ eng_transient_size - 1], env_persistent_size)
env_transient_slice := slice_ptr( & env_persistent_slice[ env_persistent_size - 1], env_trans_temp_size)
env_temp_slice := slice_ptr( & env_transient_slice [ env_trans_temp_size - 1], env_trans_temp_size)
arena_init( & eng_persistent, eng_persistent_slice )
arena_init( & eng_transient, eng_transient_slice )
arena_init( & env_persistent, env_persistent_slice )
arena_init( & env_transient, env_transient_slice )
arena_init( & env_temp, env_temp_slice )
return memory;
}
@ -141,15 +149,10 @@ main :: proc()
state : RuntimeState
state.running = true;
// state.monitor_id = monitor_id
// state.screen_width = screen_width
// state.screen_height = screen_height
// state.monitor_id = monitor_id
// state.monitor_refresh_hz = monitor_refresh_hz
state.memory = memory
state.sectr_api = sectr_api
state.sectr_api.startup( & memory.env_persistent, & memory.env_persistent )
state.sectr_api.startup( & memory.env_persistent, & memory.env_transient, & memory.env_temp )
// TODO(Ed) : This should return a end status so that we know the reason the engine stopped.
for ; state.running ;

View File

@ -1,8 +1,9 @@
cls
$path_root = git rev-parse --show-toplevel
$path_code = join-path $path_root 'code'
$path_build = join-path $path_root 'build'
$path_root = git rev-parse --show-toplevel
$path_code = join-path $path_root 'code'
$path_build = join-path $path_root 'build'
$path_thirdparty = join-path $path_root 'thirdparty'
# Odin Compiler Flags
@ -87,6 +88,12 @@ push-location $path_root
& odin $build_args
$third_party_dlls = Get-ChildItem -Path $path_thirdparty -Filter '*.dll'
foreach ($dll in $third_party_dlls) {
$destination = join-path $path_build $dll.Name
Copy-Item $dll.FullName -Destination $destination -Force
}
Pop-Location
}
build-prototype

BIN
thirdparty/raygui.dll vendored Normal file

Binary file not shown.

BIN
thirdparty/raylib.dll vendored Normal file

Binary file not shown.