diff --git a/code2/host/host.odin b/code2/host/host.odin index 565c1be..6b73072 100644 --- a/code2/host/host.odin +++ b/code2/host/host.odin @@ -1,8 +1,5 @@ package host -// TODO(Ed): Remove this -import "core:mem" - Path_Logs :: "../logs" when ODIN_OS == .Windows { @@ -21,8 +18,8 @@ master_prepper_proc :: proc(thread: ^SysThread) {} main :: proc() { // TODO(Ed): Change this - host_scratch: mem.Arena; mem.arena_init(& host_scratch, host_memory.host_scratch[:]) - context.allocator = mem.arena_allocator(& host_scratch) + host_scratch: Arena; arena_init(& host_scratch, host_memory.host_scratch[:]) + context.allocator = arena_allocator(& host_scratch) context.temp_allocator = context.allocator thread_memory.index = .Master_Prepper @@ -63,6 +60,7 @@ main :: proc() host_memory.client_api.hot_reload = hot_reload } host_memory.host_api.sync_client_module = sync_client_api + host_memory.host_api.launch_live_thread = launch_live_thread host_memory.client_api.startup(& host_memory, & thread_memory) } @@ -70,4 +68,13 @@ main :: proc() sync_client_api :: proc() { // Fill out detection and reloading of client api. + + // Needs to flag and atomic to spin-lock live helepr threads when reloading +} + +@export +launch_live_thread :: proc() +{ + // TODO(Ed): Prep the thread + host_memory.client_api.live_thread_startup(& thread_memory) } diff --git a/code2/host/pkg_mappings.odin b/code2/host/pkg_mappings.odin index 7f2ecf6..7e51812 100644 --- a/code2/host/pkg_mappings.odin +++ b/code2/host/pkg_mappings.odin @@ -19,6 +19,11 @@ import "core:dynlib" os_lib_unload :: dynlib.unload_library os_lib_get_proc :: dynlib.symbol_address +import "core:mem" + Arena :: mem.Arena + arena_allocator :: mem.arena_allocator + arena_init :: mem.arena_init + import core_os "core:os" file_last_write_time_by_name :: core_os.last_write_time_by_name OS_ERROR_NONE :: core_os.ERROR_NONE diff --git a/code2/sectr/engine/client_api.odin b/code2/sectr/engine/client_api.odin index a583112..c0f5622 100644 --- a/code2/sectr/engine/client_api.odin +++ b/code2/sectr/engine/client_api.odin @@ -1,8 +1,9 @@ package sectr -import "base:runtime" -import c "core:c/libc" +// import "base:runtime" +// import c "core:c/libc" import "core:dynlib" +import "core:sync" Path_Assets :: "../assets/" Path_Shaders :: "../shaders/" @@ -12,8 +13,9 @@ ModuleAPI :: struct { lib: dynlib.Library, // write-time: FileTime, - startup: type_of( startup ), - hot_reload: type_of( hot_reload ), + startup: type_of( startup ), + hot_reload: type_of( hot_reload ), + tick_lane_startup: type_of( tick_lane_startup), } StartupContext :: struct {} @@ -24,12 +26,46 @@ startup :: proc(host_mem: ^HostMemory, thread_mem: ^ThreadMemory) dummy : int = 0 dummy += 1 + memory = host_mem + thread_wide_startup() } thread_wide_startup :: proc() { + if thread_memory.id == .Master_Prepper + { + thread_memory.live_lanes = + tick_lane_startup() // + } + + // TODO(Ed): Spawn helper thraed, then prepp both live threads + memory.state.live_threads += 1; // Atomic_Accountant + memory.host_api.launch_live_thread() +} + +@export +tick_lane_startup :: proc(thread_mem: ^ThreadMemory) +{ + memory.state.live_threads += 1 + + + tick_lane() +} + +tick_lane :: proc() +{ + dummy : int = 0 + for ;; + { + dummy += 1 + if thread_memory.index == .Master_Prepper + { + memory.host_api.sync_client_api() + } + + } } @export diff --git a/code2/sectr/engine/host_api.odin b/code2/sectr/engine/host_api.odin index a169913..5bdb952 100644 --- a/code2/sectr/engine/host_api.odin +++ b/code2/sectr/engine/host_api.odin @@ -1,15 +1,19 @@ package sectr +import "core:sync" + HostMemory :: struct { host_scratch: [256 * Kilo]byte, + client_api_sync_lock: sync.Benaphore, + client_api: ModuleAPI, client_memory: ^State, host_api: Host_API, } Host_API :: struct { - launch_thread: #type proc(), + launch_live_thread: #type proc(), request_virtual_memory: #type proc(), request_virtual_mapped_io: #type proc(), @@ -19,4 +23,5 @@ Host_API :: struct { ThreadMemory :: struct { using _: ThreadWorkerContext, + live_lanes: int, } diff --git a/code2/sectr/engine/job_system.odin b/code2/sectr/engine/job_system.odin index cdec8b9..4fdc28c 100644 --- a/code2/sectr/engine/job_system.odin +++ b/code2/sectr/engine/job_system.odin @@ -42,8 +42,8 @@ JobSystemContext :: struct { ThreadWorkerContext :: struct { system_ctx: Thread, - index: WorkerID, -} + id: WorkerID, +} WorkerID :: enum int { Master_Prepper = 0, diff --git a/code2/sectr/state.odin b/code2/sectr/state.odin index cc46ac6..e3ab347 100644 --- a/code2/sectr/state.odin +++ b/code2/sectr/state.odin @@ -1,8 +1,14 @@ package sectr // This should be the only global on client module side. -host_memory: ^HostMemory +memory: ^HostMemory + +@(thread_local) +thread_memory: ^ThreadMemory + +THREAD_TICK_LANES :: 2 State :: struct { + live_threads: int, job_system: JobSystemContext, }