diff --git a/cpp_lib.todo b/cpp_lib.todo index 207e44e..b3fe687 100644 --- a/cpp_lib.todo +++ b/cpp_lib.todo @@ -1,14 +1,18 @@ [#TODO] + [ ] Context should include links to other living thread data (+ save dead threads in debug mode) + [ ] GetUnixTimestamp for timing and rdtsc for timing. [ ] Thread primitives (Mutex, Semaphore, etc.) [ ] Thread Creation / Deletion + [ ] Base layer and OS abstraction for Windows. (Ryan's Win32 platform layer is ~2k lines of code.) + - just implement the stuff we need + [ ] push_scratch() macro. (basically an auto_release_temp) [ ] CreateWindow [ ] ... Mouse / Keyboard inputs [*] This is the order I want to follow, because I need them in thread context. - - Entry point(s) `Entry_Point_Main.cpp` - -> We can have a lib_init() instead of a clear entry point for now. - -> Switch from library to application once I add an entry point - -> See how rjf abstracts his entry points for each platform with TCTX. + -> We can have a lib_init() instead of a clear entry point for now. + -> Switch from library to application once I add an entry point + -> See how rjf abstracts his entry points for each platform with TCTX. [ ] 1. setup thread-local storage via thread_static (see raddbg, base_core.h, C_LINKAGE thread_static TCTX *tctx_thread_local; >> Must be assigned at entry point (arena_alloc()) @@ -24,8 +28,9 @@ [ ] Maybe we just shouldn't do this? [ ] *our* program memory usage can be calculated by Stack Size + allocations from GPAllocator + allocations from arena. [TODO - Low priority] + [ ] Fix implementation so all source is just in .cpp files (including templates), and auto-generate forward declares like Vjekoslav does. [ ] Implement Secure Arenas (with VirtualLock, wiping memory with RtlSecureZeroMemory) - [ ] + [ ] Way to serialize and deserialize settings in Text (I think using binary is a mistake here?). [Project Ideas] [ ](Graphics): How do I create a basic overlay that shows the time, date, cpu/gpu temps, frequency, memory usage all the time and responds to global hotkey to show more info [Documentation Notes] diff --git a/lib/Base/Allocator.cpp b/lib/Base/Allocator.cpp index 2a67819..bc1f1b3 100644 --- a/lib/Base/Allocator.cpp +++ b/lib/Base/Allocator.cpp @@ -9,7 +9,7 @@ void* internal_alloc (s64 size) { void* internal_realloc (void* memory, s64 size, s64 old_size) { Allocator allocator = get_context_allocator(); - void* result = allocator.proc(Allocator_Mode::RESIZE, size, old_size, nullptr, allocator.data); + void* result = allocator.proc(Allocator_Mode::RESIZE, size, old_size, memory, allocator.data); return result; } diff --git a/lib/Base/Allocator.h b/lib/Base/Allocator.h index fa7abec..b85fed0 100644 --- a/lib/Base/Allocator.h +++ b/lib/Base/Allocator.h @@ -76,10 +76,26 @@ template T* NewArray (s64 count, bool initialize=true) { return memory; } +// #TODO: allocator versions of resize and delete +template T* Resize (Allocator allocator, void* memory, s64 size, s64 old_size, bool initialize=true) { + void* result = allocator.proc(Allocator_Mode::RESIZE, size, old_size, memory, allocator.data); + return result; +} +// template void Delete (Allocator allocator, void* memory) { + +// We use internal functions when we assume the user just wants to use the +// current allocator on the context. // For Resizes and Deletes, use internal_realloc and internal_free. -// template typename void reset_struct(T* src) { (*src) = T(); } -// template typename void zero_struct(T* src) { memset(src, 0, sizeof(T)); } -// template typename T* copy_struct(T* src) { -// T* dst = New(false); -// memcpy(dst, src, sizeof(T)); -// } + +template void reset_struct (T* src) { + (*src) = T(); +} + +template void zero_struct(T* src) { + memset(src, 0, sizeof(T)); +} + +template T* copy_struct(T* src) { + T* dst = New(false); + memcpy(dst, src, sizeof(T)); +} diff --git a/lib/Base/Arena.h b/lib/Base/Arena.h index cfd2bba..f68a888 100644 --- a/lib/Base/Arena.h +++ b/lib/Base/Arena.h @@ -19,6 +19,7 @@ enum class Arena_Reserve: u8 { Size_64G = 4, Size_2T = 5 }; + enum class Arena_Flags: u8 { None = 0, Chained = 0x01, diff --git a/lib/Base/Array.h b/lib/Base/Array.h index c06cf0e..3262191 100644 --- a/lib/Base/Array.h +++ b/lib/Base/Array.h @@ -144,7 +144,7 @@ void array_reserve(Array& src, s64 desired_items) { Assert(src.allocator.proc != nullptr); - src.data = (T*)src.allocator.proc(Allocator_Mode::RESIZE, desired_items * sizeof(T), src.allocated * sizeof(T), nullptr, src.allocator.data); + src.data = (T*)src.allocator.proc(Allocator_Mode::RESIZE, desired_items * sizeof(T), src.allocated * sizeof(T), src.data, src.allocator.data); Assert(src.data != nullptr); diff --git a/lib/Base/Base_Thread_Context.h b/lib/Base/Base_Thread_Context.h index 6305eb7..fd7fa6e 100644 --- a/lib/Base/Base_Thread_Context.h +++ b/lib/Base/Base_Thread_Context.h @@ -8,16 +8,19 @@ struct Arena; // #TEMP - Base_Thread_Context and Arena rely on each other, so I // See Context_Base in jai, and TCTX in raddebugger: struct Thread_Context { - Arena* temp; // Used for temporary allocations. + Arena* temp; // Used for temporary allocations, scratch space. Arena* arena; // general purpose local arena Allocator allocator; + s32 thread_idx; + u16 _padding0; u16 GPAllocator_alignment = 16; // Logger logger; // Stack_Trace* stack_trace; // #TODO: other debug information - - s64 thread_idx; + // #TODO: + // Array threads_created; // maybe should be linked-list? + // Thread* thread_that_created_me = nullptr; // so we can remove from above array string thread_name; }; diff --git a/src/OS_Win32.cpp b/src/OS_Win32.cpp index c3ed3e8..5fa2d4f 100644 --- a/src/OS_Win32.cpp +++ b/src/OS_Win32.cpp @@ -1,5 +1,3 @@ -// Move into src/Win32.cpp - struct OS_System_Info { s32 logical_processor_count; s32 physical_core_count; diff --git a/unity_build_exe.cpp b/unity_build_exe.cpp index e3c3126..4735e9e 100644 --- a/unity_build_exe.cpp +++ b/unity_build_exe.cpp @@ -1,9 +1,9 @@ #include "unity_build_lib.cpp" #include "Base_Entry_Point.cpp" // #include "imgui-docking.cpp" -#include "src/OS_Win32.cpp" -// #include "src/OS_Linux.cpp" -// #include "src/OS_MacOS.cpp" +#include "src/OS_Win32.cpp" // should be in lib/ +// #include "src/OS_Linux.cpp" // #TODO: Future. +// #include "src/OS_MacOS.cpp" // #TODO: Future. #if OS_WINDOWS