diff --git a/code/alias_raylib.odin b/code/alias_raylib.odin deleted file mode 100644 index 680a2e1..0000000 --- a/code/alias_raylib.odin +++ /dev/null @@ -1,5 +0,0 @@ -package sectr - -import rl "vendor:raylib" - -Font :: rl.Font diff --git a/code/api.odin b/code/api.odin index d077836..57114f8 100644 --- a/code/api.odin +++ b/code/api.odin @@ -24,31 +24,11 @@ ModuleAPI :: struct { clean_temp : type_of( clean_temp ), } -memory_chunk_size :: 2 * Gigabyte -memory_persistent_size :: 128 * Megabyte -memory_trans_temp_size :: (memory_chunk_size - memory_persistent_size ) / 2 - -Memory :: struct { - live : ^ virtual.Arena, - snapshot : ^ virtual.Arena, - persistent : ^ TrackedAllocator, - transient : ^ TrackedAllocator, - temp : ^ TrackedAllocator -} - -memory : Memory - @export startup :: proc( live_mem, snapshot_mem : ^ virtual.Arena ) { // Setup memory for the first time { - Arena :: mem.Arena - Tracking_Allocator :: mem.Tracking_Allocator - arena_allocator :: mem.arena_allocator - arena_init :: mem.arena_init - slice_ptr :: mem.slice_ptr - arena_size :: size_of( mem.Arena) internals_size :: 4 * Megabyte @@ -110,11 +90,6 @@ sectr_shutdown :: proc() @export reload :: proc( live_mem, snapshot_mem : ^ virtual.Arena ) { - Arena :: mem.Arena - Tracking_Allocator :: mem.Tracking_Allocator - arena_allocator :: mem.arena_allocator - slice_ptr :: mem.slice_ptr - using memory; block := live_mem.curr_block diff --git a/code/env.odin b/code/env.odin index cf34794..a6355c5 100644 --- a/code/env.odin +++ b/code/env.odin @@ -1,5 +1,22 @@ package sectr +import "core:mem/virtual" + +memory : Memory + +memory_chunk_size :: 2 * Gigabyte +memory_persistent_size :: 128 * Megabyte +memory_trans_temp_size :: (memory_chunk_size - memory_persistent_size ) / 2 + +Memory :: struct { + live : ^ virtual.Arena, + snapshot : ^ virtual.Arena, + persistent : ^ TrackedAllocator, + transient : ^ TrackedAllocator, + temp : ^ TrackedAllocator +} + + State :: struct { project : Project, diff --git a/code/grime.odin b/code/grime.odin new file mode 100644 index 0000000..2937f9b --- /dev/null +++ b/code/grime.odin @@ -0,0 +1,44 @@ + +package sectr +// At least its less than C/C++ ... + +import "core:mem" +import "core:mem/virtual" + +Byte :: 1 +Kilobyte :: 1024 * Byte +Megabyte :: 1024 * Kilobyte +Gigabyte :: 1024 * Megabyte +Terabyte :: 1024 * Gigabyte +Petabyte :: 1024 * Terabyte +Exabyte :: 1024 * Petabyte + +kilobytes :: proc ( kb : $ integer_type ) -> integer_type { + return kb * Kilobyte +} +megabytes :: proc ( mb : $ integer_type ) -> integer_type { + return mb * Megabyte +} +gigabyte :: proc ( gb : $ integer_type ) -> integer_type { + return gb * Gigabyte +} +terabyte :: proc ( tb : $ integer_type ) -> integer_type { + return tb * Terabyte +} + +Allocator :: mem.Allocator +alloc :: mem.alloc +Arena :: mem.Arena +arena_allocator :: mem.arena_allocator +arena_init :: mem.arena_init +ptr_offset :: mem.ptr_offset +slice_ptr :: mem.slice_ptr +Tracking_Allocator :: mem.Tracking_Allocator +tracking_allocator :: mem.tracking_allocator +tracking_allocator_init :: mem.tracking_allocator_init + +import rl "vendor:raylib" + +Font :: rl.Font + + diff --git a/code/memory.odin b/code/memory.odin index 01b84b4..8cf8481 100644 --- a/code/memory.odin +++ b/code/memory.odin @@ -6,70 +6,43 @@ import "core:mem/virtual" import "core:runtime" import "core:os" -Byte :: 1 -Kilobyte :: 1024 * Byte -Megabyte :: 1024 * Kilobyte -Gigabyte :: 1024 * Megabyte -Terabyte :: 1024 * Gigabyte -Petabyte :: 1024 * Terabyte -Exabyte :: 1024 * Petabyte - -kilobytes :: proc ( kb : $ integer_type ) -> integer_type { - return kb * Kilobyte -} -megabytes :: proc ( mb : $ integer_type ) -> integer_type { - return mb * Megabyte -} -gigabyte :: proc ( gb : $ integer_type ) -> integer_type { - return gb * Gigabyte -} -terabyte :: proc ( tb : $ integer_type ) -> integer_type { - return tb * Terabyte -} - // Initialize a sub-section of our virtual memory as a sub-arena -sub_arena_init :: proc( address : ^ byte, size : int ) -> ( ^ mem.Arena) { +sub_arena_init :: proc( address : ^ byte, size : int ) -> ( ^ Arena) { Arena :: mem.Arena arena_size :: size_of( Arena) sub_arena := cast( ^ Arena ) address - mem_slice := mem.slice_ptr( mem.ptr_offset( address, arena_size), size ) - mem.arena_init( sub_arena, mem_slice ) + 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 memory_after :: proc( slice : []byte ) -> ( ^ byte) { - return mem.ptr_offset( & slice[0], len(slice) ) + return ptr_offset( & slice[0], len(slice) ) } // Since this is a prototype, all memory is always tracked. No arena is is interfaced directly. TrackedAllocator :: struct { - backing : mem.Arena, - internals : mem.Arena, - tracker : mem.Tracking_Allocator, + backing : Arena, + internals : Arena, + tracker : Tracking_Allocator, } -tracked_allocator :: proc ( self : ^ TrackedAllocator ) -> mem.Allocator { - return mem.tracking_allocator( & self.tracker ) +tracked_allocator :: proc ( self : ^ TrackedAllocator ) -> Allocator { + return tracking_allocator( & self.tracker ) } tracked_allocator_init :: proc( size, internals_size : int, allocator := context.allocator ) -> TrackedAllocator { result : TrackedAllocator - Arena :: mem.Arena - Tracking_Allocator :: mem.Tracking_Allocator - arena_allocator :: mem.arena_allocator - arena_init :: mem.arena_init - slice_ptr :: mem.slice_ptr + arena_size :: size_of( Arena) + backing_size := size + arena_size + internals_size := internals_size + arena_size + raw_size := backing_size + internals_size - arena_size :: size_of( Arena) - backing_size := size + arena_size - internals_size := internals_size + arena_size - raw_size := backing_size + internals_size - - raw_mem, raw_mem_code := mem.alloc( raw_size, mem.DEFAULT_ALIGNMENT, allocator ) + raw_mem, raw_mem_code := alloc( raw_size, mem.DEFAULT_ALIGNMENT, allocator ) if ( raw_mem_code != mem.Allocator_Error.None ) { // TODO(Ed) : Setup a proper logging interface @@ -83,20 +56,12 @@ tracked_allocator_init :: proc( size, internals_size : int, allocator := context backing_allocator := arena_allocator( & result.backing ) internals_allocator := arena_allocator( & result.internals ) - mem.tracking_allocator_init( & result.tracker, backing_allocator, internals_allocator ) + tracking_allocator_init( & result.tracker, backing_allocator, internals_allocator ) return result } tracked_allocator_init_vmem :: proc( vmem : [] byte, internals_size : int ) -> ^ TrackedAllocator { - Arena :: mem.Arena - Tracking_Allocator :: mem.Tracking_Allocator - arena_allocator :: mem.arena_allocator - arena_init :: mem.arena_init - tracking_alloator_init :: mem.tracking_allocator_init - ptr_offset :: mem.ptr_offset - slice_ptr :: mem.slice_ptr - arena_size :: size_of( Arena) tracking_allocator_size :: size_of( Tracking_Allocator ) backing_size := len(vmem) - internals_size @@ -121,6 +86,6 @@ tracked_allocator_init_vmem :: proc( vmem : [] byte, internals_size : int ) -> ^ arena_init( backing, backing_slice ) arena_init( internals, internals_slice ) - tracking_alloator_init( & result.tracker, arena_allocator( backing ), arena_allocator( internals ) ) + tracking_allocator_init( & result.tracker, arena_allocator( backing ), arena_allocator( internals ) ) return result }