Move executable entry point outside of lib
This commit is contained in:
parent
1db03dd4ea
commit
b028d7fa14
14
exe_main.cpp
14
exe_main.cpp
@ -1,15 +1,3 @@
|
|||||||
#include "lib_main.cpp"
|
#include "lib_main.cpp"
|
||||||
|
#include "src/Base_Entry_Point.cpp"
|
||||||
|
|
||||||
#if OS_WINDOWS
|
|
||||||
#if BUILD_CONSOLE_INTERFACE
|
|
||||||
int wmain(int argc, WCHAR **argv) {
|
|
||||||
Win32_Entry_Point(argc, argv);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
int wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd) {
|
|
||||||
Win32_Entry_Point(__argc, __wargv);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|||||||
@ -1,14 +1,7 @@
|
|||||||
// Strongly influenced by Array.jai in Basic module.
|
// Strongly influenced by Array.jai in Basic module.
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// #TODO: Array.h
|
|
||||||
// [x] Set allocations to use context.allocator interface
|
|
||||||
// For now, I'm just disabling alignment:
|
|
||||||
// [ ] Add back alignment, and make sure there's a way to pass alignment to NewArray, which gets passed to allocator.proc.
|
|
||||||
// [ ] Make versions of ArrayView initializer that takes allocator as a param
|
|
||||||
// [ ] Make version of array_free (ArrayView&) that takes allocator as a param
|
|
||||||
// For Arena-Backed arrays use ArenaArray
|
// For Arena-Backed arrays use ArenaArray
|
||||||
// #define DEFAULT_ARRAY_ALIGNMENT 16
|
|
||||||
|
|
||||||
MSVC_RUNTIME_CHECKS_OFF
|
MSVC_RUNTIME_CHECKS_OFF
|
||||||
|
|
||||||
@ -19,7 +12,6 @@ struct Array { // downcasts to an ArrayView.
|
|||||||
T* data;
|
T* data;
|
||||||
s64 allocated;
|
s64 allocated;
|
||||||
Allocator allocator;
|
Allocator allocator;
|
||||||
// s64 alignment = DEFAULT_ARRAY_ALIGNMENT;
|
|
||||||
|
|
||||||
Array() {
|
Array() {
|
||||||
memset(this, 0, sizeof(*this));
|
memset(this, 0, sizeof(*this));
|
||||||
@ -32,15 +24,6 @@ struct Array { // downcasts to an ArrayView.
|
|||||||
allocated = new_count;
|
allocated = new_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// initializer-list type instantiation: `Array<T> new_array = {count, data}`
|
|
||||||
// (Musa) This array cannot then be resized. Why do I even have this? Do I need it?
|
|
||||||
// Array(s64 new_count, void* new_data) {
|
|
||||||
// count = new_count;
|
|
||||||
// data = (T*)new_data;
|
|
||||||
// allocator = { nullptr, nullptr }; // NOT RESIZABLE.
|
|
||||||
// allocated = new_count;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Used by array_zero, array_copy, etc.
|
// Used by array_zero, array_copy, etc.
|
||||||
Array(s64 new_count, void* new_data, s64 _allocated) {
|
Array(s64 new_count, void* new_data, s64 _allocated) {
|
||||||
count = new_count;
|
count = new_count;
|
||||||
|
|||||||
@ -1,6 +1,22 @@
|
|||||||
// See Context_Base in jai, and TCTX in raddebugger:
|
// See Context_Base in jai, and TCTX in raddebugger:
|
||||||
|
|
||||||
Thread_Context* get_thread_context();
|
internal void Bootstrap_Main_Thread_Context () {
|
||||||
|
// 0. Setup general MB(70) allocator
|
||||||
|
GPAllocator_Initialize_Allocation_Tracker();
|
||||||
|
// 1. Setup arena table
|
||||||
|
initialize_arena_table();
|
||||||
|
// 2. Setup thread local context
|
||||||
|
ExpandableArena* arena_ex = expandable_arena_new(Arena_Reserve::Size_64M, 16);
|
||||||
|
|
||||||
|
thread_local_context = New<Thread_Context>(get_allocator(arena_ex));
|
||||||
|
thread_local_context->temp = expandable_arena_new(Arena_Reserve::Size_2M, 16);
|
||||||
|
thread_local_context->arena = arena_ex;
|
||||||
|
thread_local_context->allocator = get_allocator(arena_ex);
|
||||||
|
thread_local_context->thread_idx = 0;
|
||||||
|
thread_local_context->thread_name = "Main Thread";
|
||||||
|
// thread_local_context->logger = init_logger();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
struct Push_Arena {
|
struct Push_Arena {
|
||||||
Thread_Context* context;
|
Thread_Context* context;
|
||||||
@ -47,11 +63,6 @@ struct Push_Allocator {
|
|||||||
PROTOTYPING_API Allocator get_temp_allocator();
|
PROTOTYPING_API Allocator get_temp_allocator();
|
||||||
PROTOTYPING_API Allocator get_context_allocator();
|
PROTOTYPING_API Allocator get_context_allocator();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// C_LINKAGE thread_static TCTX* tctx_thread_local;
|
|
||||||
thread_static Thread_Context* thread_local_context;
|
|
||||||
|
|
||||||
// Start from w32_entry_point_caller ->
|
// Start from w32_entry_point_caller ->
|
||||||
// see main_thread_base_entry_point
|
// see main_thread_base_entry_point
|
||||||
// //- rjf: set up thread context
|
// //- rjf: set up thread context
|
||||||
|
|||||||
@ -17,4 +17,9 @@ struct Thread_Context {
|
|||||||
string thread_name;
|
string thread_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// C_LINKAGE thread_static TCTX* tctx_thread_local;
|
||||||
|
thread_static Thread_Context* thread_local_context;
|
||||||
|
|
||||||
Thread_Context* get_thread_context ();
|
Thread_Context* get_thread_context ();
|
||||||
|
|
||||||
|
internal void Bootstrap_Main_Thread_Context ();
|
||||||
|
|||||||
@ -1,54 +0,0 @@
|
|||||||
internal void Bootstrap_Main_Thread_Context () {
|
|
||||||
// 0. Setup general MB(70) allocator
|
|
||||||
GPAllocator_Initialize_Allocation_Tracker();
|
|
||||||
// 1. Setup arena table
|
|
||||||
initialize_arena_table();
|
|
||||||
// 2. Setup thread local context
|
|
||||||
ExpandableArena* arena_ex = expandable_arena_new(Arena_Reserve::Size_64M, 16);
|
|
||||||
|
|
||||||
thread_local_context = New<Thread_Context>(get_allocator(arena_ex));
|
|
||||||
thread_local_context->temp = expandable_arena_new(Arena_Reserve::Size_2M, 16);
|
|
||||||
thread_local_context->arena = arena_ex;
|
|
||||||
thread_local_context->allocator = get_allocator(arena_ex);
|
|
||||||
thread_local_context->thread_idx = 0;
|
|
||||||
thread_local_context->thread_name = "Main Thread";
|
|
||||||
// thread_local_context->logger = init_logger();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// #include "lib/Base/Arena_Array.h"
|
|
||||||
void run_arena_array_tests () {
|
|
||||||
{ push_arena(thread_local_context->temp);
|
|
||||||
push_alignment(thread_local_context->temp, 1);
|
|
||||||
auto_reset(thread_local_context->temp);
|
|
||||||
auto something = New<Thread_Context>();
|
|
||||||
auto something2 = New<Array<s64>>();
|
|
||||||
auto something3 = internal_alloc(MB(70));
|
|
||||||
}
|
|
||||||
|
|
||||||
{ push_allocator(GPAllocator());
|
|
||||||
auto something = New<Thread_Context>();
|
|
||||||
auto something2 = New<Array<s64>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// { auto na = arena_array_new<s64>(64000, Arena_Reserve::Size_64G);
|
|
||||||
// array_add(...)
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void Main_Entry_Point (int argc, WCHAR **argv) {
|
|
||||||
run_arena_array_tests();
|
|
||||||
|
|
||||||
// Worker_Info* info = (Worker_Info*)GPAllocator_New(sizeof(Worker_Info), 64);
|
|
||||||
temp_reset();
|
|
||||||
debug_break();
|
|
||||||
printf("sizeof(Array): %zd\n", sizeof(Array<f32>));
|
|
||||||
printf("sizeof(Arena): %zd\n", sizeof(Arena));
|
|
||||||
printf("sizeof(Worker_Info): %zd\n", sizeof(Thread));
|
|
||||||
printf("sizeof(Worker_Info): %zd\n", sizeof(Worker_Info));
|
|
||||||
|
|
||||||
// #TODO:
|
|
||||||
// [ ] Launch second thread
|
|
||||||
// [ ] Setup Mouse and Keyboard Inputs
|
|
||||||
// OS_Create_Window();
|
|
||||||
}
|
|
||||||
@ -67,7 +67,6 @@ internal LONG WINAPI Win32_Exception_Filter (EXCEPTION_POINTERS* exception_ptrs)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Bootstrap_Main_Thread_Context ();
|
|
||||||
// internal void Main_Entry_Point (int argc, WCHAR **argv);
|
// internal void Main_Entry_Point (int argc, WCHAR **argv);
|
||||||
internal void Win32_Entry_Point (int argc, WCHAR **argv) {
|
internal void Win32_Entry_Point (int argc, WCHAR **argv) {
|
||||||
// See: w32_entry_point_caller(); (raddebugger)
|
// See: w32_entry_point_caller(); (raddebugger)
|
||||||
@ -173,8 +172,6 @@ internal void Win32_Entry_Point (int argc, WCHAR **argv) {
|
|||||||
// [ ] GetEnvironmentStringsW
|
// [ ] GetEnvironmentStringsW
|
||||||
// temp_reset();
|
// temp_reset();
|
||||||
printf("Hello there!\n\n");
|
printf("Hello there!\n\n");
|
||||||
// See: main_thread_base_entry_point
|
|
||||||
Main_Entry_Point(argc, argv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
C_LINKAGE DWORD OS_Windows_Thread_Entry_Point (void* parameter) {
|
C_LINKAGE DWORD OS_Windows_Thread_Entry_Point (void* parameter) {
|
||||||
|
|||||||
@ -28,8 +28,6 @@
|
|||||||
|
|
||||||
// OS-Abstraction Layer
|
// OS-Abstraction Layer
|
||||||
#include "lib/Base/Threads.cpp"
|
#include "lib/Base/Threads.cpp"
|
||||||
#include "lib/OS/Base_Entry_Point.cpp"
|
|
||||||
|
|
||||||
|
|
||||||
#if OS_WINDOWS
|
#if OS_WINDOWS
|
||||||
# include "lib/OS/OS_Win32.cpp"
|
# include "lib/OS/OS_Win32.cpp"
|
||||||
|
|||||||
44
src/Base_Entry_Point.cpp
Normal file
44
src/Base_Entry_Point.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
void run_arena_array_tests () {
|
||||||
|
{ push_arena(thread_local_context->temp);
|
||||||
|
push_alignment(thread_local_context->temp, 1);
|
||||||
|
auto_reset(thread_local_context->temp);
|
||||||
|
auto something = New<Thread_Context>();
|
||||||
|
auto something2 = New<Array<s64>>();
|
||||||
|
auto something3 = internal_alloc(MB(70));
|
||||||
|
}
|
||||||
|
|
||||||
|
{ push_allocator(GPAllocator());
|
||||||
|
auto something = New<Thread_Context>();
|
||||||
|
auto something2 = New<Array<s64>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// { auto na = arena_array_new<s64>(64000, Arena_Reserve::Size_64G);
|
||||||
|
// array_add(...)
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void Main_Entry_Point (int argc, WCHAR **argv) {
|
||||||
|
temp_reset();
|
||||||
|
// #TODO:
|
||||||
|
// [ ] Launch second thread
|
||||||
|
// [ ] Setup Mouse and Keyboard Inputs
|
||||||
|
// OS_Create_Window();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if OS_WINDOWS
|
||||||
|
#if BUILD_CONSOLE_INTERFACE
|
||||||
|
int wmain(int argc, WCHAR **argv) {
|
||||||
|
Win32_Entry_Point(argc, argv);
|
||||||
|
// See: main_thread_base_entry_point
|
||||||
|
Main_Entry_Point(argc, argv);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
int wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd) {
|
||||||
|
Win32_Entry_Point(__argc, __wargv);
|
||||||
|
// See: main_thread_base_entry_point
|
||||||
|
Main_Entry_Point(__argc, __wargv);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
Loading…
Reference in New Issue
Block a user