wip fixes for hot reload
This commit is contained in:
parent
89f2041b79
commit
1755dac070
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
build/**
|
||||
*.exe
|
||||
thirdparty/**
|
||||
thirdparty/**
|
||||
~thirdparty/odin/core/**
|
7
.vscode/settings.json
vendored
Normal file
7
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
// "ols.server.path": "{workspace"
|
||||
"search.exclude": {
|
||||
"thirdparty/**" : false,
|
||||
"**/thirdparty" : false,
|
||||
}
|
||||
}
|
@ -33,8 +33,6 @@ copy_file_sync :: proc( path_src, path_dst: string ) -> b32
|
||||
}
|
||||
|
||||
is_file_locked :: proc( file_path: string ) -> b32 {
|
||||
// Try to open the file for read access without sharing.
|
||||
// If the file is locked, the call will fail.
|
||||
handle, err := os.open(file_path, os.O_RDONLY)
|
||||
if err != os.ERROR_NONE {
|
||||
// If the error indicates the file is in use, return true.
|
||||
|
@ -20,6 +20,8 @@ import "core:time"
|
||||
import rl "vendor:raylib"
|
||||
import sectr "../."
|
||||
|
||||
path_snapshot :: "VMemChunk_1.snapshot"
|
||||
|
||||
RuntimeState :: struct {
|
||||
running : b32,
|
||||
memory : VMemChunk,
|
||||
@ -27,24 +29,29 @@ RuntimeState :: struct {
|
||||
}
|
||||
|
||||
VMemChunk :: struct {
|
||||
sarena : virtual.Arena,
|
||||
eng_persistent : mem.Arena,
|
||||
eng_transient : mem.Arena,
|
||||
env_persistent : mem.Arena,
|
||||
env_transient : mem.Arena,
|
||||
env_temp : mem.Arena
|
||||
sarena : virtual.Arena,
|
||||
host_persistent : ^ mem.Arena,
|
||||
host_transient : ^ mem.Arena,
|
||||
sectr_persistent : ^ mem.Arena,
|
||||
sectr_transient : ^ mem.Arena,
|
||||
sectr_temp : ^ mem.Arena,
|
||||
|
||||
// snapshot :
|
||||
}
|
||||
|
||||
setup_engine_memory :: proc () -> VMemChunk
|
||||
{
|
||||
memory : VMemChunk; using memory
|
||||
|
||||
Arena :: mem.Arena
|
||||
arena_init :: mem.arena_init
|
||||
ptr_offset :: mem.ptr_offset
|
||||
slice_ptr :: mem.slice_ptr
|
||||
|
||||
chunk_size :: 2 * Gigabyte
|
||||
|
||||
// Setup the static arena for the entire application
|
||||
if result := virtual.arena_init_static( & sarena, Gigabyte * 2, Gigabyte * 2 );
|
||||
if result := virtual.arena_init_static( & sarena, chunk_size, chunk_size );
|
||||
result != runtime.Allocator_Error.None
|
||||
{
|
||||
// TODO(Ed) : Setup a proper logging interface
|
||||
@ -54,30 +61,45 @@ setup_engine_memory :: proc () -> VMemChunk
|
||||
// TODO(Ed) : Figure out the error code enums..
|
||||
}
|
||||
|
||||
// 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 * 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
|
||||
arena_size :: size_of( Arena)
|
||||
|
||||
persistent_size :: Megabyte * 128 * 2
|
||||
transient_size :: (chunk_size - persistent_size * 2) / 2
|
||||
host_persistent_size :: persistent_size / 4 - arena_size
|
||||
host_transient_size :: transient_size / 4 - arena_size
|
||||
sectr_persistent_size :: persistent_size - host_persistent_size - arena_size
|
||||
sectr_trans_temp_size :: (transient_size - host_transient_size) / 2 - arena_size
|
||||
|
||||
block := memory.sarena.curr_block
|
||||
|
||||
// Try to get a slice for each segment
|
||||
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 )
|
||||
// We assign the beginning of the block to be the host's persistent memory's arena.
|
||||
// Then we offset past the arena and determine its slice to be the amount left after for the size of host's persistent.
|
||||
host_persistent = cast( ^ Arena ) block.base
|
||||
host_persistent_slice := slice_ptr( ptr_offset( block.base, arena_size), host_persistent_size)
|
||||
arena_init( host_persistent, host_persistent_slice )
|
||||
|
||||
// Initialize a sub-section of our virtual memory as a sub-arena
|
||||
sub_arena_init :: proc( address : ^ byte, size : int ) -> ( ^ Arena) {
|
||||
sub_arena := cast( ^ Arena ) address
|
||||
mem_slice := slice_ptr( ptr_offset( address, arena_size), size )
|
||||
arena_init( sub_arena, mem_slice )
|
||||
return sub_arena
|
||||
}
|
||||
|
||||
// Helper to get the the beginning of memory after a slice
|
||||
next :: proc( slice : []byte ) -> ( ^ byte) {
|
||||
return ptr_offset( & slice[0], len(slice) )
|
||||
}
|
||||
|
||||
host_transient = sub_arena_init( next( host_persistent.data), host_transient_size)
|
||||
sectr_persistent = sub_arena_init( next( host_transient.data), sectr_persistent_size)
|
||||
sectr_transient = sub_arena_init( next( sectr_persistent.data), sectr_trans_temp_size)
|
||||
sectr_temp = sub_arena_init( next( sectr_transient.data), sectr_trans_temp_size)
|
||||
return memory;
|
||||
}
|
||||
|
||||
setup_snapshot_memory :: proc ()
|
||||
|
||||
load_sectr_api :: proc ( version_id : i32 ) -> sectr.ModuleAPI
|
||||
{
|
||||
loaded_module : sectr.ModuleAPI
|
||||
@ -126,7 +148,7 @@ load_sectr_api :: proc ( version_id : i32 ) -> sectr.ModuleAPI
|
||||
shutdown = shutdown,
|
||||
reload = reload,
|
||||
update = update,
|
||||
render = render
|
||||
render = render,
|
||||
}
|
||||
return loaded_module
|
||||
}
|
||||
@ -153,8 +175,8 @@ main :: proc()
|
||||
// Then shove the context allocator for the engine to it.
|
||||
// The project's context will use its own subsection arena allocator.
|
||||
memory = setup_engine_memory()
|
||||
context.allocator = mem.arena_allocator( & memory.eng_persistent )
|
||||
context.temp_allocator = mem.arena_allocator( & memory.eng_transient )
|
||||
context.allocator = mem.arena_allocator( memory.host_persistent )
|
||||
context.temp_allocator = mem.arena_allocator( memory.host_transient )
|
||||
}
|
||||
|
||||
// Load the Enviornment API for the first-time
|
||||
@ -170,7 +192,7 @@ main :: proc()
|
||||
running = true;
|
||||
memory = memory
|
||||
sectr_api = sectr_api
|
||||
sectr_api.startup( & memory.env_persistent, & memory.env_transient, & memory.env_temp )
|
||||
sectr_api.startup( memory.sectr_persistent, memory.sectr_transient, memory.sectr_temp )
|
||||
|
||||
// TODO(Ed) : This should have an end status so that we know the reason the engine stopped.
|
||||
for ; running ;
|
||||
@ -185,7 +207,7 @@ main :: proc()
|
||||
// Wait for pdb to unlock (linker may still be writting)
|
||||
for ; sectr.is_file_locked( "sectr.pdb" ); {
|
||||
}
|
||||
time.sleep( time.Millisecond )
|
||||
time.sleep( time.Second * 10 )
|
||||
|
||||
sectr_api = load_sectr_api( version_id )
|
||||
if sectr_api.lib_version == 0 {
|
||||
@ -193,13 +215,13 @@ main :: proc()
|
||||
runtime.debug_trap()
|
||||
os.exit(-1)
|
||||
}
|
||||
sectr_api.reload( & memory.env_persistent, & memory.env_transient, & memory.env_temp )
|
||||
sectr_api.reload( memory.sectr_persistent, memory.sectr_transient, memory.sectr_temp )
|
||||
}
|
||||
|
||||
running = sectr_api.update()
|
||||
sectr_api.render()
|
||||
|
||||
free_all( mem.arena_allocator( & memory.env_temp ) )
|
||||
free_all( mem.arena_allocator( memory.sectr_temp ) )
|
||||
// free_all( mem.arena_allocator( & memory.env_transient ) )
|
||||
}
|
||||
|
||||
|
@ -59,8 +59,6 @@ push-location $path_root
|
||||
|
||||
$update_deps = join-path $path_scripts 'update_deps.ps1'
|
||||
$odin = join-path $path_odin 'odin.exe'
|
||||
write-host 'OdinPATH: ' + $odin
|
||||
|
||||
if ( -not( test-path 'build') ) {
|
||||
new-item -ItemType Directory -Path 'build'
|
||||
}
|
||||
@ -69,18 +67,29 @@ push-location $path_root
|
||||
|
||||
function build-prototype
|
||||
{
|
||||
$host_process_active = Get-Process | Where-Object {$_.Name -like 'sectr_host*'}
|
||||
|
||||
push-location $path_code
|
||||
|
||||
$project_name = 'sectr'
|
||||
$executable = join-path $path_build ($project_name + '_host.exe')
|
||||
$pdb = join-path $path_build ($project_name + '_host.pdb')
|
||||
|
||||
$module_host = join-path $path_code 'host'
|
||||
write-host "`nBuilding Sectr Prototype"
|
||||
|
||||
function build-host
|
||||
{
|
||||
$executable = join-path $path_build ($project_name + '_host.exe')
|
||||
$pdb = join-path $path_build ($project_name + '_host.pdb')
|
||||
$module_host = join-path $path_code 'host'
|
||||
|
||||
$host_process_active = Get-Process | Where-Object {$_.Name -like 'sectr_host*'}
|
||||
if ( $host_process_active ) {
|
||||
write-host 'Skipping sectr_host build, process is active'
|
||||
return
|
||||
}
|
||||
|
||||
$should_build = check-ModuleForChanges $module_host
|
||||
if ( -not( $should_build)) {
|
||||
write-host 'Skipping sectr_host build, module up to date'
|
||||
return
|
||||
}
|
||||
|
||||
$should_build = check-ModuleForChanges $module_host
|
||||
if ( -not($host_process_active) -and $should_build ) {
|
||||
$build_args = @()
|
||||
$build_args += $flag_build
|
||||
$build_args += './host'
|
||||
@ -93,13 +102,17 @@ push-location $path_root
|
||||
write-host 'Building Host Module'
|
||||
& $odin $build_args
|
||||
}
|
||||
else {
|
||||
write-host 'Skipping sectr_host build, process is active'
|
||||
}
|
||||
build-host
|
||||
|
||||
function build-sectr
|
||||
{
|
||||
$module_sectr = $path_code
|
||||
$should_build = check-ModuleForChanges $module_sectr
|
||||
if ( -not( $should_build)) {
|
||||
write-host 'Skipping sectr build, module up to date'
|
||||
return
|
||||
}
|
||||
|
||||
$module_sectr = $path_code
|
||||
$should_build = check-ModuleForChanges $module_sectr
|
||||
if ( $should_build ) {
|
||||
$module_dll = join-path $path_build ( $project_name + '.dll' )
|
||||
$pdb = join-path $path_build ( $project_name + '.pdb' )
|
||||
|
||||
@ -115,6 +128,7 @@ push-location $path_root
|
||||
write-host 'Building Sectr Module'
|
||||
& $odin $build_args
|
||||
}
|
||||
build-sectr
|
||||
|
||||
Pop-Location
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ function check-ModuleForChanges
|
||||
}
|
||||
|
||||
$file_hashes = @{}
|
||||
get-childitem -path $path_module -recurse -file -Exclude $excludes | foreach-object {
|
||||
get-childitem -path $path_module -file -Exclude $excludes | foreach-object {
|
||||
$id = $_.fullname
|
||||
$hash_info = get-filehash -path $id -Algorithm MD5
|
||||
$file_hashes[ $id ] = $hash_info.Hash
|
||||
|
@ -50,8 +50,6 @@ else
|
||||
pop-location
|
||||
}
|
||||
|
||||
write-host 'Odin up to date'
|
||||
|
||||
$path_vendor = join-path $path_odin 'vendor'
|
||||
$path_vendor_raylib = join-path $path_vendor 'raylib'
|
||||
$path_raylib_dlls = join-path $path_vendor_raylib 'windows'
|
||||
|
Loading…
Reference in New Issue
Block a user