mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-06 05:48:40 +00:00
simplification pass over os core layer; simplification pass over base arena; set up build.sh; stub out new spot for linux os core
This commit is contained in:
@@ -4,11 +4,11 @@ cd /D "%~dp0"
|
|||||||
|
|
||||||
:: --- Usage Notes (2024/1/10) ------------------------------------------------
|
:: --- Usage Notes (2024/1/10) ------------------------------------------------
|
||||||
::
|
::
|
||||||
:: This is a central build script for the RAD Debugger project. It takes a list
|
:: This is a central build script for the RAD Debugger project, for use in
|
||||||
:: of simple alphanumeric-only arguments which control (a) what is built, (b)
|
:: Windows development environments. It takes a list of simple alphanumeric-
|
||||||
:: which compiler & linker are used, and (c) extra high-level build options. By
|
:: only arguments which control (a) what is built, (b) which compiler & linker
|
||||||
:: default, if no options are passed, then the main "raddbg" graphical debugger
|
:: are used, and (c) extra high-level build options. By default, if no options
|
||||||
:: is built.
|
:: are passed, then the main "raddbg" graphical debugger is built.
|
||||||
::
|
::
|
||||||
:: Below is a non-exhaustive list of possible ways to use the script:
|
:: Below is a non-exhaustive list of possible ways to use the script:
|
||||||
:: `build raddbg`
|
:: `build raddbg`
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# --- Unpack Arguments --------------------------------------------------------
|
||||||
|
for arg in "$@"; do declare $arg='1'; done
|
||||||
|
if [ ! "$gcc" = "1" ]; then clang=1; fi
|
||||||
|
if [ ! "$release" = "1" ]; then debug=1; fi
|
||||||
|
if [ "$debug" = "1" ]; then release=0 && echo "[debug mode]"; fi
|
||||||
|
if [ "$release" = "1" ]; then debug=0 && echo "[release mode]"; fi
|
||||||
|
if [ "$clang" = "1" ]; then gcc=0 && echo "[clang compile]"; fi
|
||||||
|
if [ "$gcc" = "1" ]; then clang=0 && echo "[gcc compile]"; fi
|
||||||
|
|
||||||
|
# --- Unpack Command Line Build Arguments -------------------------------------
|
||||||
|
auto_compile_flags=''
|
||||||
|
|
||||||
|
# --- Compile/Link Line Definitions -------------------------------------------
|
||||||
|
clang_common='-I../src/ -I../local/ -gcodeview -fdiagnostics-absolute-paths -Wall -Wno-unknown-warning-option -Wno-missing-braces -Wno-unused-function -Wno-writable-strings -Wno-unused-value -Wno-unused-variable -Wno-unused-local-typedef -Wno-deprecated-register -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-single-bit-bitfield-constant-conversion -Wno-compare-distinct-pointer-types -Wno-initializer-overrides -Wno-incompatible-pointer-types-discards-qualifiers -Xclang -flto-visibility-public-std -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf'
|
||||||
|
clang_debug="clang -g -O0 -DBUILD_DEBUG=1 ${clang_common} ${auto_compile_flags}"
|
||||||
|
clang_release="clang -g -O2 -DBUILD_DEBUG=0 ${clang_common} ${auto_compile_flags}"
|
||||||
|
clang_link=""
|
||||||
|
clang_out="-o"
|
||||||
|
|
||||||
|
# --- Per-Build Settings ------------------------------------------------------
|
||||||
|
link_dll="-fPIC"
|
||||||
|
|
||||||
|
# --- Choose Compile/Link Lines -----------------------------------------------
|
||||||
|
if [ "$clang" = "1" ]; then compile_debug="$clang_debug"; fi
|
||||||
|
if [ "$clang" = "1" ]; then compile_release="$clang_release"; fi
|
||||||
|
if [ "$clang" = "1" ]; then compile_link="$clang_link"; fi
|
||||||
|
if [ "$clang" = "1" ]; then out="$clang_out"; fi
|
||||||
|
if [ "$debug" = "1" ]; then compile="$compile_debug"; fi
|
||||||
|
if [ "$release" = "1" ]; then compile="$compile_release"; fi
|
||||||
|
|
||||||
|
# --- Prep Directories --------------------------------------------------------
|
||||||
|
if [ ! -d build ]; then mkdir build; fi
|
||||||
|
if [ ! -d local ]; then mkdir local; fi
|
||||||
|
|
||||||
|
# --- Build & Run Metaprogram -------------------------------------------------
|
||||||
|
if [ "$no_meta" = "1" ]; then echo "[skipping metagen]"; fi
|
||||||
|
if [ "$no_meta" = "" ]
|
||||||
|
then
|
||||||
|
cd build
|
||||||
|
$compile_debug ../src/metagen/metagen_main.c $compile_link $out metagen || exit 1
|
||||||
|
metagen || exit 1
|
||||||
|
cd ..
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Build Everything (@build_targets) ---------------------------------------
|
||||||
|
cd build
|
||||||
|
if [ "$raddbg" = "1" ]; then didbuild=1 && $compile ../src/raddbg/raddbg_main.c $compile_link $out raddbg || exit 1; fi
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
# --- Warn On No Builds -------------------------------------------------------
|
||||||
|
#if [ "$didbuild" = "" ]
|
||||||
|
#then
|
||||||
|
# echo "[WARNING] no valid build target specified; must use build target names as arguments to this script, like `./build.sh raddbg` or `./build.sh rdi_from_pdb`."
|
||||||
|
# exit 1
|
||||||
|
#fi
|
||||||
+107
-214
@@ -2,172 +2,135 @@
|
|||||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
// Implementation
|
//~ rjf: Arena Functions
|
||||||
|
|
||||||
|
//- rjf: arena creation/destruction
|
||||||
|
|
||||||
internal Arena *
|
internal Arena *
|
||||||
arena_alloc__sized(U64 init_res, U64 init_cmt)
|
arena_alloc_(ArenaParams *params)
|
||||||
{
|
{
|
||||||
ProfBeginFunction();
|
// rjf: round up reserve/commit sizes
|
||||||
Assert(ARENA_HEADER_SIZE < init_cmt && init_cmt <= init_res);
|
U64 reserve_size = params->reserve_size;
|
||||||
|
U64 commit_size = params->commit_size;
|
||||||
void *memory = 0;
|
if(params->flags & ArenaFlag_LargePages)
|
||||||
U64 res = 0;
|
|
||||||
U64 cmt = 0;
|
|
||||||
B32 large_pages = os_large_pages_enabled();
|
|
||||||
if(large_pages)
|
|
||||||
{
|
{
|
||||||
U64 page_size = os_large_page_size();
|
reserve_size = AlignPow2(reserve_size, os_get_system_info()->large_page_size);
|
||||||
res = AlignPow2(init_res, page_size);
|
commit_size = AlignPow2(commit_size, os_get_system_info()->large_page_size);
|
||||||
#if OS_WINDOWS
|
|
||||||
cmt = res;
|
|
||||||
#else
|
|
||||||
cmt = AlignPow2(init_cmt, page_size);
|
|
||||||
#endif
|
|
||||||
memory = os_reserve_large(res);
|
|
||||||
if(!os_commit_large(memory, cmt))
|
|
||||||
{
|
|
||||||
memory = 0;
|
|
||||||
os_release(memory, res);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
U64 page_size = os_page_size();
|
reserve_size = AlignPow2(reserve_size, os_get_system_info()->page_size);
|
||||||
res = AlignPow2(init_res, page_size);
|
commit_size = AlignPow2(commit_size, os_get_system_info()->page_size);
|
||||||
cmt = AlignPow2(init_cmt, page_size);
|
}
|
||||||
memory = os_reserve(res);
|
|
||||||
if(!os_commit(memory, cmt))
|
// rjf: reserve/commit initial block
|
||||||
|
void *base = params->optional_backing_buffer;
|
||||||
|
if(base == 0)
|
||||||
|
{
|
||||||
|
if(params->flags & ArenaFlag_LargePages)
|
||||||
{
|
{
|
||||||
memory = 0;
|
base = os_reserve_large(reserve_size);
|
||||||
os_release(memory, res);
|
os_commit_large(base, commit_size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
base = os_reserve(reserve_size);
|
||||||
|
os_commit(base, commit_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Arena *arena = (Arena*)memory;
|
// rjf: panic on arena creation failure
|
||||||
if(arena)
|
#if OS_FEATURE_GRAPHICAL
|
||||||
|
if(Unlikely(base == 0))
|
||||||
{
|
{
|
||||||
AsanPoisonMemoryRegion(memory, cmt);
|
os_graphical_message(1, str8_lit("Fatal Allocation Failure"), str8_lit("Unexpected memory allocation failure."));
|
||||||
AsanUnpoisonMemoryRegion(memory, ARENA_HEADER_SIZE);
|
os_abort(1);
|
||||||
arena->prev = 0;
|
|
||||||
arena->current = arena;
|
|
||||||
arena->base_pos = 0;
|
|
||||||
arena->pos = ARENA_HEADER_SIZE;
|
|
||||||
arena->cmt = cmt;
|
|
||||||
arena->res = res;
|
|
||||||
arena->align = 8;
|
|
||||||
arena->grow = 1;
|
|
||||||
arena->large_pages = large_pages;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
ProfEnd();
|
// rjf: extract arena header & fill
|
||||||
return arena;
|
Arena *arena = (Arena *)base;
|
||||||
}
|
arena->current = arena;
|
||||||
|
arena->flags = params->flags;
|
||||||
internal Arena *
|
arena->cmt_size = (U32)params->commit_size;
|
||||||
arena_alloc(void)
|
arena->res_size = params->reserve_size;
|
||||||
{
|
arena->base_pos = 0;
|
||||||
ProfBeginFunction();
|
arena->pos = ARENA_HEADER_SIZE;
|
||||||
|
arena->cmt = commit_size;
|
||||||
U64 init_res, init_cmt;
|
arena->res = reserve_size;
|
||||||
if (os_large_pages_enabled()) {
|
AsanPoisonMemoryRegion(base, commit_size);
|
||||||
init_res = ARENA_RESERVE_SIZE_LARGE_PAGES;
|
AsanUnpoisonMemoryRegion(base, ARENA_HEADER_SIZE);
|
||||||
init_cmt = ARENA_COMMIT_SIZE_LARGE_PAGES;
|
|
||||||
} else {
|
|
||||||
init_res = ARENA_RESERVE_SIZE;
|
|
||||||
init_cmt = ARENA_COMMIT_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
Arena *arena = arena_alloc__sized(init_res, init_cmt);
|
|
||||||
|
|
||||||
ProfEnd();
|
|
||||||
return arena;
|
return arena;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
arena_release(Arena *arena)
|
arena_release(Arena *arena)
|
||||||
{
|
{
|
||||||
for (Arena *node = arena->current, *prev = 0; node != 0; node = prev) {
|
for(Arena *n = arena->current, *prev = 0; n != 0; n = prev)
|
||||||
prev = node->prev;
|
{
|
||||||
os_release(node, node->res);
|
prev = n->prev;
|
||||||
|
os_release(n, n->res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal U64
|
//- rjf: arena push/pop core functions
|
||||||
arena_huge_push_threshold(void)
|
|
||||||
{
|
|
||||||
U64 reserve_size = os_large_pages_enabled() ? ARENA_RESERVE_SIZE_LARGE_PAGES : ARENA_RESERVE_SIZE;
|
|
||||||
U64 threshold = (reserve_size - ARENA_HEADER_SIZE) / 2 + 1;
|
|
||||||
return threshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void *
|
internal void *
|
||||||
arena_push__impl(Arena *arena, U64 size)
|
arena_push(Arena *arena, U64 size, U64 align)
|
||||||
{
|
{
|
||||||
Arena *current = arena->current;
|
Arena *current = arena->current;
|
||||||
U64 pos_mem = AlignPow2(current->pos, arena->align);
|
U64 pos_pre = AlignPow2(current->pos, align);
|
||||||
U64 pos_new = pos_mem + size;
|
U64 pos_pst = pos_pre + size;
|
||||||
|
|
||||||
if (current->res < pos_new && arena->grow) {
|
// rjf: chain, if needed
|
||||||
Arena *new_block;
|
if(current->res < pos_pst && !(arena->flags & ArenaFlag_NoChain))
|
||||||
|
{
|
||||||
// normal growth path
|
U64 res_size = current->res_size;
|
||||||
if (size < arena_huge_push_threshold()) {
|
U64 cmt_size = current->cmt_size;
|
||||||
new_block = arena_alloc();
|
if(size > cmt_size)
|
||||||
}
|
{
|
||||||
// huge growth path
|
res_size = size + ARENA_HEADER_SIZE;
|
||||||
else {
|
cmt_size = size + ARENA_HEADER_SIZE;
|
||||||
U64 new_block_size = size + ARENA_HEADER_SIZE;
|
|
||||||
new_block = arena_alloc__sized(new_block_size, new_block_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (new_block) {
|
|
||||||
new_block->base_pos = current->base_pos + current->res;
|
|
||||||
SLLStackPush_N(arena->current, new_block, prev);
|
|
||||||
|
|
||||||
current = new_block;
|
|
||||||
pos_mem = AlignPow2(current->pos, current->align);
|
|
||||||
pos_new = pos_mem + size;
|
|
||||||
}
|
}
|
||||||
|
Arena *new_block = arena_alloc(.reserve_size = res_size,
|
||||||
|
.commit_size = cmt_size,
|
||||||
|
.flags = current->flags);
|
||||||
|
new_block->base_pos = current->base_pos + current->res;
|
||||||
|
SLLStackPush_N(arena->current, new_block, prev);
|
||||||
|
current = new_block;
|
||||||
|
pos_pre = AlignPow2(current->pos, align);
|
||||||
|
pos_pst = pos_pst + size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current->cmt < pos_new) {
|
// rjf: commit new pages, if needed
|
||||||
U64 cmt_new_aligned, cmt_new_clamped, cmt_new_size;
|
if(current->cmt < pos_pst && !(current->flags & ArenaFlag_LargePages))
|
||||||
B32 is_cmt_ok;
|
{
|
||||||
|
U64 cmt_pst_aligned = AlignPow2(pos_pst, current->cmt_size);
|
||||||
if (current->large_pages) {
|
U64 cmt_pst_clamped = ClampTop(cmt_pst_aligned, current->res);
|
||||||
cmt_new_aligned = AlignPow2(pos_new, ARENA_COMMIT_SIZE_LARGE_PAGES);
|
U64 cmt_size = cmt_pst_clamped - current->cmt;
|
||||||
cmt_new_clamped = ClampTop(cmt_new_aligned, current->res);
|
os_commit((U8 *)current + current->cmt, cmt_size);
|
||||||
cmt_new_size = cmt_new_clamped - current->cmt;
|
current->cmt = cmt_pst_clamped;
|
||||||
is_cmt_ok = os_commit_large((U8*)current + current->cmt, cmt_new_size);
|
|
||||||
} else {
|
|
||||||
cmt_new_aligned = AlignPow2(pos_new, ARENA_COMMIT_SIZE);
|
|
||||||
cmt_new_clamped = ClampTop(cmt_new_aligned, current->res);
|
|
||||||
cmt_new_size = cmt_new_clamped - current->cmt;
|
|
||||||
is_cmt_ok = os_commit((U8*)current + current->cmt, cmt_new_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_cmt_ok) {
|
|
||||||
current->cmt = cmt_new_clamped;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void *memory = 0;
|
// rjf: push onto current block
|
||||||
|
void *result = 0;
|
||||||
if (current->cmt >= pos_new) {
|
if(current->cmt >= pos_pst)
|
||||||
memory = (U8*)current + pos_mem;
|
{
|
||||||
current->pos = pos_new;
|
result = (U8 *)current+pos_pre;
|
||||||
AsanUnpoisonMemoryRegion(memory, size);
|
current->pos = pos_pst;
|
||||||
|
AsanUnpoisonMemoryRegion(result, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// rjf: panic on failure
|
||||||
#if OS_FEATURE_GRAPHICAL
|
#if OS_FEATURE_GRAPHICAL
|
||||||
if(Unlikely(memory == 0))
|
if(Unlikely(result == 0))
|
||||||
{
|
{
|
||||||
os_graphical_message(1, str8_lit("Fatal Allocation Failure"), str8_lit("Unexpected memory allocation failure."));
|
os_graphical_message(1, str8_lit("Fatal Allocation Failure"), str8_lit("Unexpected memory allocation failure."));
|
||||||
os_exit_process(1);
|
os_abort(1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return memory;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal U64
|
internal U64
|
||||||
@@ -179,85 +142,23 @@ arena_pos(Arena *arena)
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
arena_pop_to(Arena *arena, U64 big_pos_unclamped)
|
arena_pop_to(Arena *arena, U64 pos)
|
||||||
{
|
{
|
||||||
U64 big_pos = ClampBot(ARENA_HEADER_SIZE, big_pos_unclamped);
|
U64 big_pos = ClampBot(ARENA_HEADER_SIZE, pos);
|
||||||
|
|
||||||
// unroll the chain
|
|
||||||
Arena *current = arena->current;
|
Arena *current = arena->current;
|
||||||
for (Arena *prev = 0; current->base_pos >= big_pos; current = prev) {
|
for(Arena *prev = 0; current->base_pos >= big_pos; current = prev)
|
||||||
|
{
|
||||||
prev = current->prev;
|
prev = current->prev;
|
||||||
os_release(current, current->res);
|
os_release(current, current->res);
|
||||||
}
|
}
|
||||||
AssertAlways(current);
|
|
||||||
arena->current = current;
|
arena->current = current;
|
||||||
|
|
||||||
// compute arena-relative position
|
|
||||||
U64 new_pos = big_pos - current->base_pos;
|
U64 new_pos = big_pos - current->base_pos;
|
||||||
AssertAlways(new_pos <= current->pos);
|
AssertAlways(new_pos <= current->pos);
|
||||||
|
|
||||||
// poison popped memory block
|
|
||||||
AsanPoisonMemoryRegion((U8*)current + new_pos, (current->pos - new_pos));
|
AsanPoisonMemoryRegion((U8*)current + new_pos, (current->pos - new_pos));
|
||||||
|
|
||||||
// update position
|
|
||||||
current->pos = new_pos;
|
current->pos = new_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
//- rjf: arena push/pop helpers
|
||||||
arena_absorb(Arena *arena, Arena *sub)
|
|
||||||
{
|
|
||||||
// base adjustment
|
|
||||||
Arena *current = arena->current;
|
|
||||||
U64 base_adjust = current->base_pos + current->res;
|
|
||||||
for (Arena *node = sub->current; node != 0; node = node->prev) {
|
|
||||||
node->base_pos += base_adjust;
|
|
||||||
}
|
|
||||||
|
|
||||||
// attach sub to arena
|
|
||||||
sub->prev = arena->current;
|
|
||||||
arena->current = sub->current;
|
|
||||||
sub->current = sub;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
// Wrappers
|
|
||||||
|
|
||||||
internal void *
|
|
||||||
arena_push(Arena *arena, U64 size)
|
|
||||||
{
|
|
||||||
void *memory = arena_push__impl(arena, size);
|
|
||||||
return memory;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void *
|
|
||||||
arena_push_contiguous(Arena *arena, U64 size)
|
|
||||||
{
|
|
||||||
B32 restore = arena->grow;
|
|
||||||
arena->grow = 0;
|
|
||||||
void *memory = arena_push(arena, size);
|
|
||||||
arena->grow = restore;
|
|
||||||
return memory;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
|
||||||
arena_push_align(Arena *arena, U64 align)
|
|
||||||
{
|
|
||||||
Assert(IsPow2(align));
|
|
||||||
U64 amt = AlignPadPow2(arena->pos, align);
|
|
||||||
void *ptr = arena_push(arena, amt);
|
|
||||||
MemoryZero(ptr, amt);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
|
||||||
arena_put_back(Arena *arena, U64 amt)
|
|
||||||
{
|
|
||||||
U64 pos_old = arena_pos(arena);
|
|
||||||
U64 pos_new = pos_old;
|
|
||||||
if (amt < pos_old) {
|
|
||||||
pos_new = pos_old - amt;
|
|
||||||
}
|
|
||||||
arena_pop_to(arena, pos_new);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
arena_clear(Arena *arena)
|
arena_clear(Arena *arena)
|
||||||
@@ -265,6 +166,20 @@ arena_clear(Arena *arena)
|
|||||||
arena_pop_to(arena, 0);
|
arena_pop_to(arena, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void
|
||||||
|
arena_pop(Arena *arena, U64 amt)
|
||||||
|
{
|
||||||
|
U64 pos_old = arena_pos(arena);
|
||||||
|
U64 pos_new = pos_old;
|
||||||
|
if(amt < pos_old)
|
||||||
|
{
|
||||||
|
pos_new = pos_old - amt;
|
||||||
|
}
|
||||||
|
arena_pop_to(arena, pos_new);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- rjf: temporary arena scopes
|
||||||
|
|
||||||
internal Temp
|
internal Temp
|
||||||
temp_begin(Arena *arena)
|
temp_begin(Arena *arena)
|
||||||
{
|
{
|
||||||
@@ -278,25 +193,3 @@ temp_end(Temp temp)
|
|||||||
{
|
{
|
||||||
arena_pop_to(temp.arena, temp.pos);
|
arena_pop_to(temp.arena, temp.pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ NOTE(allen): "Mini-Arena" Helper
|
|
||||||
|
|
||||||
internal B32
|
|
||||||
ensure_commit(void **cmtptr, void *pos, U64 cmt_block_size){
|
|
||||||
B32 result = 0;
|
|
||||||
U8 *cmt = (U8*)*cmtptr;
|
|
||||||
if (cmt < (U8*)pos){
|
|
||||||
U64 cmt_size_raw = (U8*)pos - cmt;
|
|
||||||
U64 cmt_size = AlignPow2(cmt_size_raw, cmt_block_size);
|
|
||||||
if (os_commit(cmt, cmt_size)){
|
|
||||||
*cmtptr = cmt + cmt_size;
|
|
||||||
result = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
result = 1;
|
|
||||||
}
|
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
+44
-51
@@ -7,38 +7,41 @@
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Constants
|
//~ rjf: Constants
|
||||||
|
|
||||||
#define ARENA_HEADER_SIZE 128
|
#define ARENA_HEADER_SIZE 64
|
||||||
|
|
||||||
#ifndef ARENA_RESERVE_SIZE
|
|
||||||
# define ARENA_RESERVE_SIZE MB(64)
|
|
||||||
#endif
|
|
||||||
#ifndef ARENA_COMMIT_SIZE
|
|
||||||
# define ARENA_COMMIT_SIZE KB(64)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef ARENA_RESERVE_SIZE_LARGE_PAGES
|
|
||||||
# define ARENA_RESERVE_SIZE_LARGE_PAGES MB(8)
|
|
||||||
#endif
|
|
||||||
#ifndef ARENA_COMMIT_SIZE_LARGE_PAGES
|
|
||||||
# define ARENA_COMMIT_SIZE_LARGE_PAGES MB(2)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Arena Types
|
//~ rjf: Types
|
||||||
|
|
||||||
|
typedef U32 ArenaFlags;
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
ArenaFlag_NoChain = (1<<0),
|
||||||
|
ArenaFlag_LargePages = (1<<1),
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct ArenaParams ArenaParams;
|
||||||
|
struct ArenaParams
|
||||||
|
{
|
||||||
|
ArenaFlags flags;
|
||||||
|
U64 reserve_size;
|
||||||
|
U64 commit_size;
|
||||||
|
void *optional_backing_buffer;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct Arena Arena;
|
typedef struct Arena Arena;
|
||||||
struct Arena
|
struct Arena
|
||||||
{
|
{
|
||||||
struct Arena *prev;
|
Arena *prev; // previous arena in chain
|
||||||
struct Arena *current;
|
Arena *current; // current arena in chain
|
||||||
|
ArenaFlags flags;
|
||||||
|
U32 cmt_size;
|
||||||
|
U64 res_size;
|
||||||
U64 base_pos;
|
U64 base_pos;
|
||||||
U64 pos;
|
U64 pos;
|
||||||
U64 cmt;
|
U64 cmt;
|
||||||
U64 res;
|
U64 res;
|
||||||
U64 align;
|
|
||||||
B8 grow;
|
|
||||||
B8 large_pages;
|
|
||||||
};
|
};
|
||||||
|
StaticAssert(sizeof(Arena) <= ARENA_HEADER_SIZE, arena_header_size_check);
|
||||||
|
|
||||||
typedef struct Temp Temp;
|
typedef struct Temp Temp;
|
||||||
struct Temp
|
struct Temp
|
||||||
@@ -48,40 +51,30 @@ struct Temp
|
|||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
// Implementation
|
//~ rjf: Arena Functions
|
||||||
|
|
||||||
internal Arena* arena_alloc__sized(U64 init_res, U64 init_cmt);
|
//- rjf: arena creation/destruction
|
||||||
|
internal Arena *arena_alloc_(ArenaParams *params);
|
||||||
|
#define arena_alloc(...) arena_alloc_(&(ArenaParams){.reserve_size = MB(64), .commit_size = KB(64), __VA_ARGS__})
|
||||||
|
internal void arena_release(Arena *arena);
|
||||||
|
|
||||||
internal Arena* arena_alloc(void);
|
//- rjf: arena push/pop/pos core functions
|
||||||
internal void arena_release(Arena *arena);
|
internal void *arena_push(Arena *arena, U64 size, U64 align);
|
||||||
|
internal U64 arena_pos(Arena *arena);
|
||||||
|
internal void arena_pop_to(Arena *arena, U64 pos);
|
||||||
|
|
||||||
internal void* arena_push__impl(Arena *arena, U64 size);
|
//- rjf: arena push/pop helpers
|
||||||
internal U64 arena_pos(Arena *arena);
|
internal void arena_clear(Arena *arena);
|
||||||
internal void arena_pop_to(Arena *arena, U64 pos);
|
internal void arena_pop(Arena *arena, U64 amt);
|
||||||
|
|
||||||
internal void arena_absorb(Arena *arena, Arena *sub);
|
//- rjf: temporary arena scopes
|
||||||
|
internal Temp temp_begin(Arena *arena);
|
||||||
|
internal void temp_end(Temp temp);
|
||||||
|
|
||||||
////////////////////////////////
|
//- rjf: push helper macros
|
||||||
// Wrappers
|
#define push_array_no_zero_aligned(a, T, c, align) (T *)arena_push((a), sizeof(T)*(c), (align))
|
||||||
|
#define push_array_aligned(a, T, c, align) (T *)MemoryZero(push_array_no_zero_aligned(a, T, c, align), sizeof(T)*(c))
|
||||||
internal void* arena_push(Arena *arena, U64 size);
|
#define push_array_no_zero(a, T, c) push_array_no_zero_aligned(a, T, c, Max(8, AlignOf(T)))
|
||||||
internal void* arena_push_contiguous(Arena *arena, U64 size);
|
#define push_array(a, T, c) push_array_aligned(a, T, c, Max(8, AlignOf(T)))
|
||||||
internal void arena_clear(Arena *arena);
|
|
||||||
internal void arena_push_align(Arena *arena, U64 align);
|
|
||||||
internal void arena_put_back(Arena *arena, U64 amt);
|
|
||||||
|
|
||||||
internal Temp temp_begin(Arena *arena);
|
|
||||||
internal void temp_end(Temp temp);
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ NOTE(allen): "Mini-Arena" Helper
|
|
||||||
|
|
||||||
internal B32 ensure_commit(void **cmt, void *pos, U64 cmt_block_size);
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ NOTE(allen): Main API Macros
|
|
||||||
|
|
||||||
#define push_array_no_zero(a,T,c) (T*)arena_push((a), sizeof(T)*(c))
|
|
||||||
#define push_array(a,T,c) (T*)MemoryZero(push_array_no_zero(a,T,c), sizeof(T)*(c))
|
|
||||||
|
|
||||||
#endif // BASE_ARENA_H
|
#endif // BASE_ARENA_H
|
||||||
|
|||||||
+16
-2
@@ -1,8 +1,8 @@
|
|||||||
// Copyright (c) 2024 Epic Games Tools
|
// Copyright (c) 2024 Epic Games Tools
|
||||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||||
|
|
||||||
#ifndef BASE_TYPES_H
|
#ifndef BASE_CORE_H
|
||||||
#define BASE_TYPES_H
|
#define BASE_CORE_H
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Foreign Includes
|
//~ rjf: Foreign Includes
|
||||||
@@ -91,6 +91,20 @@
|
|||||||
#define ClampBot(X,B) Max(X,B)
|
#define ClampBot(X,B) Max(X,B)
|
||||||
#define Clamp(A,X,B) (((X)<(A))?(A):((X)>(B))?(B):(X))
|
#define Clamp(A,X,B) (((X)<(A))?(A):((X)>(B))?(B):(X))
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ rjf: Type -> Alignment
|
||||||
|
|
||||||
|
#if COMPILER_MSVC
|
||||||
|
# define AlignOf(T) __alignof(T)
|
||||||
|
#elif COMPILER_CLANG
|
||||||
|
# define AlignOf(T) __alignof(T)
|
||||||
|
#elif COMPILER_GCC
|
||||||
|
# define AlignOf(T) __alignof__(T)
|
||||||
|
#else
|
||||||
|
#else
|
||||||
|
# error AlignOf not defined for this compiler.
|
||||||
|
#endif
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Member Offsets
|
//~ rjf: Member Offsets
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// Copyright (c) 2024 Epic Games Tools
|
||||||
|
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **arguments, U64 arguments_count)
|
main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **arguments, U64 arguments_count)
|
||||||
{
|
{
|
||||||
@@ -7,8 +10,6 @@ main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **argum
|
|||||||
tmSetMaxThreadCount(256);
|
tmSetMaxThreadCount(256);
|
||||||
tmInitialize(sizeof(tm_data), (char *)tm_data);
|
tmInitialize(sizeof(tm_data), (char *)tm_data);
|
||||||
#endif
|
#endif
|
||||||
TCTX tctx;
|
|
||||||
tctx_init_and_equip(&tctx);
|
|
||||||
ThreadNameF("[main thread]");
|
ThreadNameF("[main thread]");
|
||||||
Temp scratch = scratch_begin(0, 0);
|
Temp scratch = scratch_begin(0, 0);
|
||||||
String8List command_line_argument_strings = os_string_list_from_argcv(scratch.arena, (int)arguments_count, arguments);
|
String8List command_line_argument_strings = os_string_list_from_argcv(scratch.arena, (int)arguments_count, arguments);
|
||||||
@@ -18,9 +19,6 @@ main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **argum
|
|||||||
{
|
{
|
||||||
ProfBeginCapture(arguments[0]);
|
ProfBeginCapture(arguments[0]);
|
||||||
}
|
}
|
||||||
#if defined(OS_CORE_H) && !defined(OS_INIT_MANUAL)
|
|
||||||
os_init();
|
|
||||||
#endif
|
|
||||||
#if defined(TASK_SYSTEM_H) && !defined(TS_INIT_MANUAL)
|
#if defined(TASK_SYSTEM_H) && !defined(TS_INIT_MANUAL)
|
||||||
ts_init();
|
ts_init();
|
||||||
#endif
|
#endif
|
||||||
@@ -52,7 +50,7 @@ main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **argum
|
|||||||
ctrl_init();
|
ctrl_init();
|
||||||
#endif
|
#endif
|
||||||
#if defined(OS_GRAPHICAL_H) && !defined(OS_GFX_INIT_MANUAL)
|
#if defined(OS_GRAPHICAL_H) && !defined(OS_GFX_INIT_MANUAL)
|
||||||
os_graphical_init();
|
os_gfx_init();
|
||||||
#endif
|
#endif
|
||||||
#if defined(FONT_PROVIDER_H) && !defined(FP_INIT_MANUAL)
|
#if defined(FONT_PROVIDER_H) && !defined(FP_INIT_MANUAL)
|
||||||
fp_init();
|
fp_init();
|
||||||
@@ -82,7 +80,6 @@ main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **argum
|
|||||||
ProfEndCapture();
|
ProfEndCapture();
|
||||||
}
|
}
|
||||||
scratch_end(scratch);
|
scratch_end(scratch);
|
||||||
tctx_release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
|
|||||||
@@ -1358,7 +1358,7 @@ str8_from_16(Arena *arena, String16 in){
|
|||||||
size += utf8_encode(str + size, consume.codepoint);
|
size += utf8_encode(str + size, consume.codepoint);
|
||||||
}
|
}
|
||||||
str[size] = 0;
|
str[size] = 0;
|
||||||
arena_put_back(arena, (cap - size));
|
arena_pop(arena, (cap - size));
|
||||||
return(str8(str, size));
|
return(str8(str, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1375,7 +1375,7 @@ str16_from_8(Arena *arena, String8 in){
|
|||||||
size += utf16_encode(str + size, consume.codepoint);
|
size += utf16_encode(str + size, consume.codepoint);
|
||||||
}
|
}
|
||||||
str[size] = 0;
|
str[size] = 0;
|
||||||
arena_put_back(arena, (cap - size)*2);
|
arena_pop(arena, (cap - size)*2);
|
||||||
return(str16(str, size));
|
return(str16(str, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1390,7 +1390,7 @@ str8_from_32(Arena *arena, String32 in){
|
|||||||
size += utf8_encode(str + size, *ptr);
|
size += utf8_encode(str + size, *ptr);
|
||||||
}
|
}
|
||||||
str[size] = 0;
|
str[size] = 0;
|
||||||
arena_put_back(arena, (cap - size));
|
arena_pop(arena, (cap - size));
|
||||||
return(str8(str, size));
|
return(str8(str, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1408,7 +1408,7 @@ str32_from_8(Arena *arena, String8 in){
|
|||||||
size += 1;
|
size += 1;
|
||||||
}
|
}
|
||||||
str[size] = 0;
|
str[size] = 0;
|
||||||
arena_put_back(arena, (cap - size)*4);
|
arena_pop(arena, (cap - size)*4);
|
||||||
return(str32(str, size));
|
return(str32(str, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,4 +38,4 @@ internal void tctx_read_srcloc(char **file_name, U64 *line_number);
|
|||||||
#define scratch_begin(conflicts, count) temp_begin(tctx_get_scratch((conflicts), (count)))
|
#define scratch_begin(conflicts, count) temp_begin(tctx_get_scratch((conflicts), (count)))
|
||||||
#define scratch_end(scratch) temp_end(scratch)
|
#define scratch_end(scratch) temp_end(scratch)
|
||||||
|
|
||||||
#endif //BASE_THREAD_CONTEXT_H
|
#endif // BASE_THREAD_CONTEXT_H
|
||||||
|
|||||||
@@ -268,8 +268,7 @@ cv_rec_range_stream_from_data(Arena *arena, String8 sym_data, U64 sym_align)
|
|||||||
for(;cursor + sizeof(CV_RecHeader) <= cap;)
|
for(;cursor + sizeof(CV_RecHeader) <= cap;)
|
||||||
{
|
{
|
||||||
// setup a new chunk
|
// setup a new chunk
|
||||||
arena_push_align(arena, 64);
|
CV_RecRangeChunk *cur_chunk = push_array_aligned(arena, CV_RecRangeChunk, 1, 64);
|
||||||
CV_RecRangeChunk *cur_chunk = push_array_no_zero(arena, CV_RecRangeChunk, 1);
|
|
||||||
SLLQueuePush(result->first_chunk, result->last_chunk, cur_chunk);
|
SLLQueuePush(result->first_chunk, result->last_chunk, cur_chunk);
|
||||||
U64 partial_count = 0;
|
U64 partial_count = 0;
|
||||||
for(;partial_count < CV_REC_RANGE_CHUNK_SIZE && cursor + sizeof(CV_RecHeader) <= cap; partial_count += 1)
|
for(;partial_count < CV_REC_RANGE_CHUNK_SIZE && cursor + sizeof(CV_RecHeader) <= cap; partial_count += 1)
|
||||||
@@ -296,7 +295,7 @@ internal CV_RecRangeArray
|
|||||||
cv_rec_range_array_from_stream(Arena *arena, CV_RecRangeStream *stream)
|
cv_rec_range_array_from_stream(Arena *arena, CV_RecRangeStream *stream)
|
||||||
{
|
{
|
||||||
U64 total_count = stream->total_count;
|
U64 total_count = stream->total_count;
|
||||||
CV_RecRange *ranges = push_array_no_zero(arena, CV_RecRange, total_count);
|
CV_RecRange *ranges = push_array_no_zero_aligned(arena, CV_RecRange, total_count, 8);
|
||||||
U64 idx = 0;
|
U64 idx = 0;
|
||||||
for(CV_RecRangeChunk *chunk = stream->first_chunk; chunk != 0; chunk = chunk->next)
|
for(CV_RecRangeChunk *chunk = stream->first_chunk; chunk != 0; chunk = chunk->next)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,8 +4,6 @@
|
|||||||
#ifndef CODEVIEW_H
|
#ifndef CODEVIEW_H
|
||||||
#define CODEVIEW_H
|
#define CODEVIEW_H
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
|
|
||||||
// https://github.com/microsoft/microsoft-pdb/blob/master/include/cvinfo.h
|
// https://github.com/microsoft/microsoft-pdb/blob/master/include/cvinfo.h
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
@@ -957,6 +955,8 @@ typedef enum CV_LanguageEnum
|
|||||||
}
|
}
|
||||||
CV_LanguageEnum;
|
CV_LanguageEnum;
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: CodeView Format "Sym" and "Leaf" Header Type
|
//~ rjf: CodeView Format "Sym" and "Leaf" Header Type
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -304,7 +304,7 @@ coff_symbol_array_from_data_16(Arena *arena, String8 data, U64 symbol_array_off,
|
|||||||
{
|
{
|
||||||
COFF_Symbol32Array result;
|
COFF_Symbol32Array result;
|
||||||
result.count = symbol_count;
|
result.count = symbol_count;
|
||||||
result.v = push_array_no_zero(arena, COFF_Symbol32, result.count);
|
result.v = push_array_no_zero_aligned(arena, COFF_Symbol32, result.count, 8);
|
||||||
|
|
||||||
COFF_Symbol16 *sym16_arr = (COFF_Symbol16 *)(data.str + symbol_array_off);
|
COFF_Symbol16 *sym16_arr = (COFF_Symbol16 *)(data.str + symbol_array_off);
|
||||||
for (U64 isymbol = 0; isymbol < symbol_count; isymbol += 1) {
|
for (U64 isymbol = 0; isymbol < symbol_count; isymbol += 1) {
|
||||||
|
|||||||
+15
-15
@@ -913,7 +913,7 @@ ctrl_init(void)
|
|||||||
}
|
}
|
||||||
ctrl_state->process_memory_cache.slots_count = 256;
|
ctrl_state->process_memory_cache.slots_count = 256;
|
||||||
ctrl_state->process_memory_cache.slots = push_array(arena, CTRL_ProcessMemoryCacheSlot, ctrl_state->process_memory_cache.slots_count);
|
ctrl_state->process_memory_cache.slots = push_array(arena, CTRL_ProcessMemoryCacheSlot, ctrl_state->process_memory_cache.slots_count);
|
||||||
ctrl_state->process_memory_cache.stripes_count = os_logical_core_count();
|
ctrl_state->process_memory_cache.stripes_count = os_get_system_info()->logical_processor_count;
|
||||||
ctrl_state->process_memory_cache.stripes = push_array(arena, CTRL_ProcessMemoryCacheStripe, ctrl_state->process_memory_cache.stripes_count);
|
ctrl_state->process_memory_cache.stripes = push_array(arena, CTRL_ProcessMemoryCacheStripe, ctrl_state->process_memory_cache.stripes_count);
|
||||||
for(U64 idx = 0; idx < ctrl_state->process_memory_cache.stripes_count; idx += 1)
|
for(U64 idx = 0; idx < ctrl_state->process_memory_cache.stripes_count; idx += 1)
|
||||||
{
|
{
|
||||||
@@ -922,7 +922,7 @@ ctrl_init(void)
|
|||||||
}
|
}
|
||||||
ctrl_state->thread_reg_cache.slots_count = 1024;
|
ctrl_state->thread_reg_cache.slots_count = 1024;
|
||||||
ctrl_state->thread_reg_cache.slots = push_array(arena, CTRL_ThreadRegCacheSlot, ctrl_state->thread_reg_cache.slots_count);
|
ctrl_state->thread_reg_cache.slots = push_array(arena, CTRL_ThreadRegCacheSlot, ctrl_state->thread_reg_cache.slots_count);
|
||||||
ctrl_state->thread_reg_cache.stripes_count = os_logical_core_count();
|
ctrl_state->thread_reg_cache.stripes_count = os_get_system_info()->logical_processor_count;
|
||||||
ctrl_state->thread_reg_cache.stripes = push_array(arena, CTRL_ThreadRegCacheStripe, ctrl_state->thread_reg_cache.stripes_count);
|
ctrl_state->thread_reg_cache.stripes = push_array(arena, CTRL_ThreadRegCacheStripe, ctrl_state->thread_reg_cache.stripes_count);
|
||||||
for(U64 idx = 0; idx < ctrl_state->thread_reg_cache.stripes_count; idx += 1)
|
for(U64 idx = 0; idx < ctrl_state->thread_reg_cache.stripes_count; idx += 1)
|
||||||
{
|
{
|
||||||
@@ -931,7 +931,7 @@ ctrl_init(void)
|
|||||||
}
|
}
|
||||||
ctrl_state->module_image_info_cache.slots_count = 1024;
|
ctrl_state->module_image_info_cache.slots_count = 1024;
|
||||||
ctrl_state->module_image_info_cache.slots = push_array(arena, CTRL_ModuleImageInfoCacheSlot, ctrl_state->module_image_info_cache.slots_count);
|
ctrl_state->module_image_info_cache.slots = push_array(arena, CTRL_ModuleImageInfoCacheSlot, ctrl_state->module_image_info_cache.slots_count);
|
||||||
ctrl_state->module_image_info_cache.stripes_count = os_logical_core_count();
|
ctrl_state->module_image_info_cache.stripes_count = os_get_system_info()->logical_processor_count;
|
||||||
ctrl_state->module_image_info_cache.stripes = push_array(arena, CTRL_ModuleImageInfoCacheStripe, ctrl_state->module_image_info_cache.stripes_count);
|
ctrl_state->module_image_info_cache.stripes = push_array(arena, CTRL_ModuleImageInfoCacheStripe, ctrl_state->module_image_info_cache.stripes_count);
|
||||||
for(U64 idx = 0; idx < ctrl_state->module_image_info_cache.stripes_count; idx += 1)
|
for(U64 idx = 0; idx < ctrl_state->module_image_info_cache.stripes_count; idx += 1)
|
||||||
{
|
{
|
||||||
@@ -949,7 +949,7 @@ ctrl_init(void)
|
|||||||
ctrl_state->c2u_ring_cv = os_condition_variable_alloc();
|
ctrl_state->c2u_ring_cv = os_condition_variable_alloc();
|
||||||
{
|
{
|
||||||
Temp scratch = scratch_begin(0, 0);
|
Temp scratch = scratch_begin(0, 0);
|
||||||
String8 user_program_data_path = os_string_from_system_path(scratch.arena, OS_SystemPath_UserProgramData);
|
String8 user_program_data_path = os_get_process_info()->user_program_data_path;
|
||||||
String8 user_data_folder = push_str8f(scratch.arena, "%S/raddbg/logs", user_program_data_path);
|
String8 user_data_folder = push_str8f(scratch.arena, "%S/raddbg/logs", user_program_data_path);
|
||||||
os_make_directory(user_data_folder);
|
os_make_directory(user_data_folder);
|
||||||
ctrl_state->ctrl_thread_log_path = push_str8f(ctrl_state->arena, "%S/ctrl_thread.raddbg_log", user_data_folder);
|
ctrl_state->ctrl_thread_log_path = push_str8f(ctrl_state->arena, "%S/ctrl_thread.raddbg_log", user_data_folder);
|
||||||
@@ -971,12 +971,12 @@ ctrl_init(void)
|
|||||||
ctrl_state->u2ms_ring_mutex = os_mutex_alloc();
|
ctrl_state->u2ms_ring_mutex = os_mutex_alloc();
|
||||||
ctrl_state->u2ms_ring_cv = os_condition_variable_alloc();
|
ctrl_state->u2ms_ring_cv = os_condition_variable_alloc();
|
||||||
ctrl_state->ctrl_thread_log = log_alloc();
|
ctrl_state->ctrl_thread_log = log_alloc();
|
||||||
ctrl_state->ctrl_thread = os_launch_thread(ctrl_thread__entry_point, 0, 0);
|
ctrl_state->ctrl_thread = os_thread_launch(ctrl_thread__entry_point, 0, 0);
|
||||||
ctrl_state->ms_thread_count = Clamp(1, os_logical_core_count()-1, 4);
|
ctrl_state->ms_thread_count = Clamp(1, os_get_system_info()->logical_processor_count-1, 4);
|
||||||
ctrl_state->ms_threads = push_array(arena, OS_Handle, ctrl_state->ms_thread_count);
|
ctrl_state->ms_threads = push_array(arena, OS_Handle, ctrl_state->ms_thread_count);
|
||||||
for(U64 idx = 0; idx < ctrl_state->ms_thread_count; idx += 1)
|
for(U64 idx = 0; idx < ctrl_state->ms_thread_count; idx += 1)
|
||||||
{
|
{
|
||||||
ctrl_state->ms_threads[idx] = os_launch_thread(ctrl_mem_stream_thread__entry_point, (void *)idx, 0);
|
ctrl_state->ms_threads[idx] = os_thread_launch(ctrl_mem_stream_thread__entry_point, (void *)idx, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3820,14 +3820,14 @@ internal void
|
|||||||
ctrl_thread__launch(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg)
|
ctrl_thread__launch(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg)
|
||||||
{
|
{
|
||||||
//- rjf: launch
|
//- rjf: launch
|
||||||
OS_LaunchOptions opts = {0};
|
OS_ProcessLaunchParams params = {0};
|
||||||
{
|
{
|
||||||
opts.cmd_line = msg->cmd_line_string_list;
|
params.cmd_line = msg->cmd_line_string_list;
|
||||||
opts.path = msg->path;
|
params.path = msg->path;
|
||||||
opts.env = msg->env_string_list;
|
params.env = msg->env_string_list;
|
||||||
opts.inherit_env = msg->env_inherit;
|
params.inherit_env = msg->env_inherit;
|
||||||
}
|
}
|
||||||
U32 id = dmn_ctrl_launch(ctrl_ctx, &opts);
|
U32 id = dmn_ctrl_launch(ctrl_ctx, ¶ms);
|
||||||
|
|
||||||
//- rjf: record (id -> entry points), so that we know custom entry points for this PID
|
//- rjf: record (id -> entry points), so that we know custom entry points for this PID
|
||||||
for(String8Node *n = msg->entry_points.first; n != 0; n = n->next)
|
for(String8Node *n = msg->entry_points.first; n != 0; n = n->next)
|
||||||
@@ -5198,8 +5198,8 @@ ctrl_mem_stream_thread__entry_point(void *p)
|
|||||||
if(got_task && pre_read_mem_gen != preexisting_mem_gen)
|
if(got_task && pre_read_mem_gen != preexisting_mem_gen)
|
||||||
{
|
{
|
||||||
range_size = dim_1u64(vaddr_range_clamped);
|
range_size = dim_1u64(vaddr_range_clamped);
|
||||||
U64 arena_size = AlignPow2(range_size + ARENA_HEADER_SIZE, os_page_size());
|
U64 arena_size = AlignPow2(range_size + ARENA_HEADER_SIZE, os_get_system_info()->page_size);
|
||||||
range_arena = arena_alloc__sized(range_size+ARENA_HEADER_SIZE, range_size+ARENA_HEADER_SIZE);
|
range_arena = arena_alloc(.reserve_size = range_size+ARENA_HEADER_SIZE, .commit_size = range_size+ARENA_HEADER_SIZE);
|
||||||
if(range_arena == 0)
|
if(range_arena == 0)
|
||||||
{
|
{
|
||||||
range_size = 0;
|
range_size = 0;
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ dasm_init(void)
|
|||||||
dasm_shared = push_array(arena, DASM_Shared, 1);
|
dasm_shared = push_array(arena, DASM_Shared, 1);
|
||||||
dasm_shared->arena = arena;
|
dasm_shared->arena = arena;
|
||||||
dasm_shared->slots_count = 1024;
|
dasm_shared->slots_count = 1024;
|
||||||
dasm_shared->stripes_count = Min(dasm_shared->slots_count, os_logical_core_count());
|
dasm_shared->stripes_count = Min(dasm_shared->slots_count, os_get_system_info()->logical_processor_count);
|
||||||
dasm_shared->slots = push_array(arena, DASM_Slot, dasm_shared->slots_count);
|
dasm_shared->slots = push_array(arena, DASM_Slot, dasm_shared->slots_count);
|
||||||
dasm_shared->stripes = push_array(arena, DASM_Stripe, dasm_shared->stripes_count);
|
dasm_shared->stripes = push_array(arena, DASM_Stripe, dasm_shared->stripes_count);
|
||||||
for(U64 idx = 0; idx < dasm_shared->stripes_count; idx += 1)
|
for(U64 idx = 0; idx < dasm_shared->stripes_count; idx += 1)
|
||||||
@@ -120,9 +120,9 @@ dasm_init(void)
|
|||||||
dasm_shared->parse_threads = push_array(arena, OS_Handle, dasm_shared->parse_thread_count);
|
dasm_shared->parse_threads = push_array(arena, OS_Handle, dasm_shared->parse_thread_count);
|
||||||
for(U64 idx = 0; idx < dasm_shared->parse_thread_count; idx += 1)
|
for(U64 idx = 0; idx < dasm_shared->parse_thread_count; idx += 1)
|
||||||
{
|
{
|
||||||
dasm_shared->parse_threads[idx] = os_launch_thread(dasm_parse_thread__entry_point, (void *)idx, 0);
|
dasm_shared->parse_threads[idx] = os_thread_launch(dasm_parse_thread__entry_point, (void *)idx, 0);
|
||||||
}
|
}
|
||||||
dasm_shared->evictor_detector_thread = os_launch_thread(dasm_evictor_detector_thread__entry_point, 0, 0);
|
dasm_shared->evictor_detector_thread = os_thread_launch(dasm_evictor_detector_thread__entry_point, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|||||||
+16
-16
@@ -85,7 +85,7 @@ di_init(void)
|
|||||||
di_shared->arena = arena;
|
di_shared->arena = arena;
|
||||||
di_shared->slots_count = 1024;
|
di_shared->slots_count = 1024;
|
||||||
di_shared->slots = push_array(arena, DI_Slot, di_shared->slots_count);
|
di_shared->slots = push_array(arena, DI_Slot, di_shared->slots_count);
|
||||||
di_shared->stripes_count = Min(di_shared->slots_count, os_logical_core_count());
|
di_shared->stripes_count = Min(di_shared->slots_count, os_get_system_info()->logical_processor_count);
|
||||||
di_shared->stripes = push_array(arena, DI_Stripe, di_shared->stripes_count);
|
di_shared->stripes = push_array(arena, DI_Stripe, di_shared->stripes_count);
|
||||||
for(U64 idx = 0; idx < di_shared->stripes_count; idx += 1)
|
for(U64 idx = 0; idx < di_shared->stripes_count; idx += 1)
|
||||||
{
|
{
|
||||||
@@ -101,11 +101,11 @@ di_init(void)
|
|||||||
di_shared->p2u_ring_cv = os_condition_variable_alloc();
|
di_shared->p2u_ring_cv = os_condition_variable_alloc();
|
||||||
di_shared->p2u_ring_size = KB(64);
|
di_shared->p2u_ring_size = KB(64);
|
||||||
di_shared->p2u_ring_base = push_array_no_zero(arena, U8, di_shared->p2u_ring_size);
|
di_shared->p2u_ring_base = push_array_no_zero(arena, U8, di_shared->p2u_ring_size);
|
||||||
di_shared->parse_thread_count = Max(2, os_logical_core_count()/2);
|
di_shared->parse_thread_count = Max(2, os_get_system_info()->logical_processor_count/2);
|
||||||
di_shared->parse_threads = push_array(arena, OS_Handle, di_shared->parse_thread_count);
|
di_shared->parse_threads = push_array(arena, OS_Handle, di_shared->parse_thread_count);
|
||||||
for(U64 idx = 0; idx < di_shared->parse_thread_count; idx += 1)
|
for(U64 idx = 0; idx < di_shared->parse_thread_count; idx += 1)
|
||||||
{
|
{
|
||||||
di_shared->parse_threads[idx] = os_launch_thread(di_parse_thread__entry_point, (void *)idx, 0);
|
di_shared->parse_threads[idx] = os_thread_launch(di_parse_thread__entry_point, (void *)idx, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -765,21 +765,21 @@ di_parse_thread__entry_point(void *p)
|
|||||||
//- rjf: kick off process
|
//- rjf: kick off process
|
||||||
OS_Handle process = {0};
|
OS_Handle process = {0};
|
||||||
{
|
{
|
||||||
OS_LaunchOptions opts = {0};
|
OS_ProcessLaunchParams params = {0};
|
||||||
opts.path = os_string_from_system_path(scratch.arena, OS_SystemPath_Binary);
|
params.path = os_get_process_info()->binary_path;
|
||||||
opts.inherit_env = 1;
|
params.inherit_env = 1;
|
||||||
opts.consoleless = 1;
|
params.consoleless = 1;
|
||||||
str8_list_pushf(scratch.arena, &opts.cmd_line, "raddbg");
|
str8_list_pushf(scratch.arena, ¶ms.cmd_line, "raddbg");
|
||||||
str8_list_pushf(scratch.arena, &opts.cmd_line, "--convert");
|
str8_list_pushf(scratch.arena, ¶ms.cmd_line, "--convert");
|
||||||
str8_list_pushf(scratch.arena, &opts.cmd_line, "--quiet");
|
str8_list_pushf(scratch.arena, ¶ms.cmd_line, "--quiet");
|
||||||
if(should_compress)
|
if(should_compress)
|
||||||
{
|
{
|
||||||
str8_list_pushf(scratch.arena, &opts.cmd_line, "--compress");
|
str8_list_pushf(scratch.arena, ¶ms.cmd_line, "--compress");
|
||||||
}
|
}
|
||||||
//str8_list_pushf(scratch.arena, &opts.cmd_line, "--capture");
|
// str8_list_pushf(scratch.arena, ¶ms.cmd_line, "--capture");
|
||||||
str8_list_pushf(scratch.arena, &opts.cmd_line, "--pdb:%S", og_path);
|
str8_list_pushf(scratch.arena, ¶ms.cmd_line, "--pdb:%S", og_path);
|
||||||
str8_list_pushf(scratch.arena, &opts.cmd_line, "--out:%S", rdi_path);
|
str8_list_pushf(scratch.arena, ¶ms.cmd_line, "--out:%S", rdi_path);
|
||||||
os_launch_process(&opts, &process);
|
process = os_process_launch(¶ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- rjf: wait for process to complete
|
//- rjf: wait for process to complete
|
||||||
@@ -787,7 +787,7 @@ di_parse_thread__entry_point(void *p)
|
|||||||
U64 start_wait_t = os_now_microseconds();
|
U64 start_wait_t = os_now_microseconds();
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
B32 wait_done = os_process_wait(process, os_now_microseconds()+1000);
|
B32 wait_done = os_process_join(process, os_now_microseconds()+1000);
|
||||||
if(wait_done)
|
if(wait_done)
|
||||||
{
|
{
|
||||||
rdi_file_is_up_to_date = 1;
|
rdi_file_is_up_to_date = 1;
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ internal DMN_CtrlCtx *dmn_ctrl_begin(void);
|
|||||||
internal void dmn_ctrl_exclusive_access_begin(void);
|
internal void dmn_ctrl_exclusive_access_begin(void);
|
||||||
internal void dmn_ctrl_exclusive_access_end(void);
|
internal void dmn_ctrl_exclusive_access_end(void);
|
||||||
#define DMN_CtrlExclusiveAccessScope DeferLoop(dmn_ctrl_exclusive_access_begin(), dmn_ctrl_exclusive_access_end())
|
#define DMN_CtrlExclusiveAccessScope DeferLoop(dmn_ctrl_exclusive_access_begin(), dmn_ctrl_exclusive_access_end())
|
||||||
internal U32 dmn_ctrl_launch(DMN_CtrlCtx *ctx, OS_LaunchOptions *options);
|
internal U32 dmn_ctrl_launch(DMN_CtrlCtx *ctx, OS_ProcessLaunchParams *params);
|
||||||
internal B32 dmn_ctrl_attach(DMN_CtrlCtx *ctx, U32 pid);
|
internal B32 dmn_ctrl_attach(DMN_CtrlCtx *ctx, U32 pid);
|
||||||
internal B32 dmn_ctrl_kill(DMN_CtrlCtx *ctx, DMN_Handle process, U32 exit_code);
|
internal B32 dmn_ctrl_kill(DMN_CtrlCtx *ctx, DMN_Handle process, U32 exit_code);
|
||||||
internal B32 dmn_ctrl_detach(DMN_CtrlCtx *ctx, DMN_Handle process);
|
internal B32 dmn_ctrl_detach(DMN_CtrlCtx *ctx, DMN_Handle process);
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ demon_lnx_executable_path_from_pid(Arena *arena, pid_t pid){
|
|||||||
temp_end(restore_point);
|
temp_end(restore_point);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
arena_put_back(arena, (cap - size - 1));
|
arena_pop(arena, (cap - size - 1));
|
||||||
result = str8(buffer, size + 1);
|
result = str8(buffer, size + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1083,7 +1083,7 @@ dmn_init(void)
|
|||||||
dmn_w32_shared->arena = arena;
|
dmn_w32_shared->arena = arena;
|
||||||
dmn_w32_shared->access_mutex = os_mutex_alloc();
|
dmn_w32_shared->access_mutex = os_mutex_alloc();
|
||||||
dmn_w32_shared->detach_arena = arena_alloc();
|
dmn_w32_shared->detach_arena = arena_alloc();
|
||||||
dmn_w32_shared->entities_arena = arena_alloc__sized(GB(8), KB(64));
|
dmn_w32_shared->entities_arena = arena_alloc(.reserve_size = GB(8), .commit_size = KB(64));
|
||||||
dmn_w32_shared->entities_base = dmn_w32_entity_alloc(&dmn_w32_entity_nil, DMN_W32_EntityKind_Root, 0);
|
dmn_w32_shared->entities_base = dmn_w32_entity_alloc(&dmn_w32_entity_nil, DMN_W32_EntityKind_Root, 0);
|
||||||
dmn_w32_shared->entities_id_hash_slots_count = 4096;
|
dmn_w32_shared->entities_id_hash_slots_count = 4096;
|
||||||
dmn_w32_shared->entities_id_hash_slots = push_array(arena, DMN_W32_EntityIDHashSlot, dmn_w32_shared->entities_id_hash_slots_count);
|
dmn_w32_shared->entities_id_hash_slots = push_array(arena, DMN_W32_EntityIDHashSlot, dmn_w32_shared->entities_id_hash_slots_count);
|
||||||
@@ -1147,7 +1147,7 @@ dmn_ctrl_exclusive_access_end(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal U32
|
internal U32
|
||||||
dmn_ctrl_launch(DMN_CtrlCtx *ctx, OS_LaunchOptions *options)
|
dmn_ctrl_launch(DMN_CtrlCtx *ctx, OS_ProcessLaunchParams *params)
|
||||||
{
|
{
|
||||||
Temp scratch = scratch_begin(0, 0);
|
Temp scratch = scratch_begin(0, 0);
|
||||||
U32 result = 0;
|
U32 result = 0;
|
||||||
@@ -1155,12 +1155,12 @@ dmn_ctrl_launch(DMN_CtrlCtx *ctx, OS_LaunchOptions *options)
|
|||||||
{
|
{
|
||||||
//- rjf: produce exe / arguments string
|
//- rjf: produce exe / arguments string
|
||||||
String8 cmd = {0};
|
String8 cmd = {0};
|
||||||
if(options->cmd_line.first != 0)
|
if(params->cmd_line.first != 0)
|
||||||
{
|
{
|
||||||
String8List args = {0};
|
String8List args = {0};
|
||||||
String8 exe_path = options->cmd_line.first->string;
|
String8 exe_path = params->cmd_line.first->string;
|
||||||
str8_list_pushf(scratch.arena, &args, "\"%S\"", exe_path);
|
str8_list_pushf(scratch.arena, &args, "\"%S\"", exe_path);
|
||||||
for(String8Node *n = options->cmd_line.first->next; n != 0; n = n->next)
|
for(String8Node *n = params->cmd_line.first->next; n != 0; n = n->next)
|
||||||
{
|
{
|
||||||
str8_list_push(scratch.arena, &args, n->string);
|
str8_list_push(scratch.arena, &args, n->string);
|
||||||
}
|
}
|
||||||
@@ -1172,12 +1172,12 @@ dmn_ctrl_launch(DMN_CtrlCtx *ctx, OS_LaunchOptions *options)
|
|||||||
//- rjf: produce environment strings
|
//- rjf: produce environment strings
|
||||||
String8 env = {0};
|
String8 env = {0};
|
||||||
{
|
{
|
||||||
String8List all_opts = options->env;
|
String8List all_opts = params->env;
|
||||||
if(options->inherit_env != 0)
|
if(params->inherit_env != 0)
|
||||||
{
|
{
|
||||||
MemoryZeroStruct(&all_opts);
|
MemoryZeroStruct(&all_opts);
|
||||||
str8_list_push(scratch.arena, &all_opts, str8_lit("_NO_DEBUG_HEAP=1"));
|
str8_list_push(scratch.arena, &all_opts, str8_lit("_NO_DEBUG_HEAP=1"));
|
||||||
for(String8Node *n = options->env.first; n != 0; n = n->next)
|
for(String8Node *n = params->env.first; n != 0; n = n->next)
|
||||||
{
|
{
|
||||||
str8_list_push(scratch.arena, &all_opts, n->string);
|
str8_list_push(scratch.arena, &all_opts, n->string);
|
||||||
}
|
}
|
||||||
@@ -1194,7 +1194,7 @@ dmn_ctrl_launch(DMN_CtrlCtx *ctx, OS_LaunchOptions *options)
|
|||||||
|
|
||||||
//- rjf: produce utf-16 strings
|
//- rjf: produce utf-16 strings
|
||||||
String16 cmd16 = str16_from_8(scratch.arena, cmd);
|
String16 cmd16 = str16_from_8(scratch.arena, cmd);
|
||||||
String16 dir16 = str16_from_8(scratch.arena, options->path);
|
String16 dir16 = str16_from_8(scratch.arena, params->path);
|
||||||
String16 env16 = str16_from_8(scratch.arena, env);
|
String16 env16 = str16_from_8(scratch.arena, env);
|
||||||
|
|
||||||
//- rjf: launch
|
//- rjf: launch
|
||||||
|
|||||||
+5
-50
@@ -3935,47 +3935,6 @@ df_frame_from_unwind_idxs(DF_Unwind *unwind, U64 base_unwind_idx, U64 inline_unw
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ rjf: Entity -> Log Entities
|
|
||||||
|
|
||||||
internal DF_Entity *
|
|
||||||
df_log_from_entity(DF_Entity *entity)
|
|
||||||
{
|
|
||||||
Temp scratch = scratch_begin(0, 0);
|
|
||||||
String8 log_name = {0};
|
|
||||||
switch(entity->kind)
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
log_name = push_str8f(scratch.arena, "id_%I64u", entity->id);
|
|
||||||
}break;
|
|
||||||
case DF_EntityKind_Root:
|
|
||||||
{
|
|
||||||
U32 session_pid = os_get_pid();
|
|
||||||
log_name = push_str8f(scratch.arena, "session_%i", session_pid);
|
|
||||||
}break;
|
|
||||||
case DF_EntityKind_Machine:
|
|
||||||
{
|
|
||||||
log_name = push_str8f(scratch.arena, "machine_%I64u", entity->id);
|
|
||||||
}break;
|
|
||||||
case DF_EntityKind_Process:
|
|
||||||
{
|
|
||||||
log_name = push_str8f(scratch.arena, "pid_%i", entity->ctrl_id);
|
|
||||||
}break;
|
|
||||||
case DF_EntityKind_Thread:
|
|
||||||
{
|
|
||||||
log_name = push_str8f(scratch.arena, "tid_%i", entity->ctrl_id);
|
|
||||||
}break;
|
|
||||||
}
|
|
||||||
String8 user_program_data_path = os_string_from_system_path(scratch.arena, OS_SystemPath_UserProgramData);
|
|
||||||
String8 user_data_folder = push_str8f(scratch.arena, "%S/%S", user_program_data_path, str8_lit("raddbg/logs"));
|
|
||||||
String8 log_path = push_str8f(scratch.arena, "%S/log%s%S.txt", user_data_folder, log_name.size != 0 ? "_" : "", log_name);
|
|
||||||
DF_Entity *log = df_entity_from_path(log_path, DF_EntityFromPathFlag_OpenAsNeeded|DF_EntityFromPathFlag_OpenMissing);
|
|
||||||
log->flags |= DF_EntityFlag_Output;
|
|
||||||
scratch_end(scratch);
|
|
||||||
return log;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Target Controls
|
//~ rjf: Target Controls
|
||||||
|
|
||||||
@@ -6805,7 +6764,7 @@ df_core_init(CmdLine *cmdln, DF_StateDeltaHistory *hist)
|
|||||||
}
|
}
|
||||||
df_state->root_cmd_arena = arena_alloc();
|
df_state->root_cmd_arena = arena_alloc();
|
||||||
df_state->output_log_key = hs_hash_from_data(str8_lit("df_output_log_key"));
|
df_state->output_log_key = hs_hash_from_data(str8_lit("df_output_log_key"));
|
||||||
df_state->entities_arena = arena_alloc__sized(GB(64), KB(64));
|
df_state->entities_arena = arena_alloc(.reserve_size = GB(64), .commit_size = KB(64));
|
||||||
df_state->entities_root = &df_g_nil_entity;
|
df_state->entities_root = &df_g_nil_entity;
|
||||||
df_state->entities_base = push_array(df_state->entities_arena, DF_Entity, 0);
|
df_state->entities_base = push_array(df_state->entities_arena, DF_Entity, 0);
|
||||||
df_state->entities_count = 0;
|
df_state->entities_count = 0;
|
||||||
@@ -6883,7 +6842,7 @@ df_core_init(CmdLine *cmdln, DF_StateDeltaHistory *hist)
|
|||||||
project_cfg_path = cmd_line_string(cmdln, str8_lit("profile"));
|
project_cfg_path = cmd_line_string(cmdln, str8_lit("profile"));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
String8 user_program_data_path = os_string_from_system_path(scratch.arena, OS_SystemPath_UserProgramData);
|
String8 user_program_data_path = os_get_process_info()->user_program_data_path;
|
||||||
String8 user_data_folder = push_str8f(scratch.arena, "%S/%S", user_program_data_path, str8_lit("raddbg"));
|
String8 user_data_folder = push_str8f(scratch.arena, "%S/%S", user_program_data_path, str8_lit("raddbg"));
|
||||||
os_make_directory(user_data_folder);
|
os_make_directory(user_data_folder);
|
||||||
if(user_cfg_path.size == 0)
|
if(user_cfg_path.size == 0)
|
||||||
@@ -6921,11 +6880,9 @@ df_core_init(CmdLine *cmdln, DF_StateDeltaHistory *hist)
|
|||||||
// rjf: set up initial browse path
|
// rjf: set up initial browse path
|
||||||
{
|
{
|
||||||
Temp scratch = scratch_begin(0, 0);
|
Temp scratch = scratch_begin(0, 0);
|
||||||
String8List current_path_strs = {0};
|
String8 current_path = os_get_current_path(scratch.arena);
|
||||||
os_string_list_from_system_path(scratch.arena, OS_SystemPath_Current, ¤t_path_strs);
|
|
||||||
df_state->current_path_arena = arena_alloc();
|
|
||||||
String8 current_path = str8_list_first(¤t_path_strs);
|
|
||||||
String8 current_path_with_slash = push_str8f(scratch.arena, "%S/", current_path);
|
String8 current_path_with_slash = push_str8f(scratch.arena, "%S/", current_path);
|
||||||
|
df_state->current_path_arena = arena_alloc();
|
||||||
df_state->current_path = push_str8_copy(df_state->current_path_arena, current_path_with_slash);
|
df_state->current_path = push_str8_copy(df_state->current_path_arena, current_path_with_slash);
|
||||||
scratch_end(scratch);
|
scratch_end(scratch);
|
||||||
}
|
}
|
||||||
@@ -7519,9 +7476,7 @@ df_core_begin_frame(Arena *arena, DF_CmdList *cmds, F32 dt)
|
|||||||
entry = str8_skip_chop_whitespace(entry);
|
entry = str8_skip_chop_whitespace(entry);
|
||||||
if(path.size == 0)
|
if(path.size == 0)
|
||||||
{
|
{
|
||||||
String8List current_path_strs = {0};
|
path = os_get_current_path(scratch.arena);
|
||||||
os_string_list_from_system_path(scratch.arena, OS_SystemPath_Current, ¤t_path_strs);
|
|
||||||
path = str8_list_first(¤t_path_strs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// rjf: build launch options
|
// rjf: build launch options
|
||||||
|
|||||||
@@ -1683,11 +1683,6 @@ internal DF_Entity *df_module_from_thread_candidates(DF_Entity *thread, DF_Entit
|
|||||||
internal DF_Unwind df_unwind_from_ctrl_unwind(Arena *arena, DI_Scope *di_scope, DF_Entity *process, CTRL_Unwind *base_unwind);
|
internal DF_Unwind df_unwind_from_ctrl_unwind(Arena *arena, DI_Scope *di_scope, DF_Entity *process, CTRL_Unwind *base_unwind);
|
||||||
internal DF_UnwindFrame *df_frame_from_unwind_idxs(DF_Unwind *unwind, U64 base_unwind_idx, U64 inline_unwind_idx);
|
internal DF_UnwindFrame *df_frame_from_unwind_idxs(DF_Unwind *unwind, U64 base_unwind_idx, U64 inline_unwind_idx);
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ rjf: Entity -> Log Entities
|
|
||||||
|
|
||||||
internal DF_Entity *df_log_from_entity(DF_Entity *entity);
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Target Controls
|
//~ rjf: Target Controls
|
||||||
|
|
||||||
|
|||||||
@@ -3706,7 +3706,7 @@ DF_VIEW_UI_FUNCTION_DEF(FileSystem)
|
|||||||
UI_FlagsAdd(UI_BoxFlag_DrawTextWeak)
|
UI_FlagsAdd(UI_BoxFlag_DrawTextWeak)
|
||||||
{
|
{
|
||||||
DateTime time = date_time_from_dense_time(file->props.modified);
|
DateTime time = date_time_from_dense_time(file->props.modified);
|
||||||
DateTime time_local = os_local_time_from_universal_time(&time);
|
DateTime time_local = os_local_time_from_universal(&time);
|
||||||
String8 string = push_date_time_string(scratch.arena, &time_local);
|
String8 string = push_date_time_string(scratch.arena, &time_local);
|
||||||
ui_label(string);
|
ui_label(string);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -135,7 +135,7 @@ d_begin_frame(void)
|
|||||||
{
|
{
|
||||||
if(d_thread_ctx == 0)
|
if(d_thread_ctx == 0)
|
||||||
{
|
{
|
||||||
Arena *arena = arena_alloc__sized(GB(64), MB(8));
|
Arena *arena = arena_alloc(.reserve_size = GB(64), .commit_size = MB(8));
|
||||||
d_thread_ctx = push_array(arena, D_ThreadCtx, 1);
|
d_thread_ctx = push_array(arena, D_ThreadCtx, 1);
|
||||||
d_thread_ctx->arena = arena;
|
d_thread_ctx->arena = arena;
|
||||||
d_thread_ctx->arena_frame_start_pos = arena_pos(arena);
|
d_thread_ctx->arena_frame_start_pos = arena_pos(arena);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ fs_init(void)
|
|||||||
fs_shared->arena = arena;
|
fs_shared->arena = arena;
|
||||||
fs_shared->change_gen = 1;
|
fs_shared->change_gen = 1;
|
||||||
fs_shared->slots_count = 1024;
|
fs_shared->slots_count = 1024;
|
||||||
fs_shared->stripes_count = os_logical_core_count();
|
fs_shared->stripes_count = os_get_system_info()->logical_processor_count;
|
||||||
fs_shared->slots = push_array(arena, FS_Slot, fs_shared->slots_count);
|
fs_shared->slots = push_array(arena, FS_Slot, fs_shared->slots_count);
|
||||||
fs_shared->stripes = push_array(arena, FS_Stripe, fs_shared->stripes_count);
|
fs_shared->stripes = push_array(arena, FS_Stripe, fs_shared->stripes_count);
|
||||||
for(U64 idx = 0; idx < fs_shared->stripes_count; idx += 1)
|
for(U64 idx = 0; idx < fs_shared->stripes_count; idx += 1)
|
||||||
@@ -25,13 +25,13 @@ fs_init(void)
|
|||||||
fs_shared->u2s_ring_base = push_array_no_zero(arena, U8, fs_shared->u2s_ring_size);
|
fs_shared->u2s_ring_base = push_array_no_zero(arena, U8, fs_shared->u2s_ring_size);
|
||||||
fs_shared->u2s_ring_cv = os_condition_variable_alloc();
|
fs_shared->u2s_ring_cv = os_condition_variable_alloc();
|
||||||
fs_shared->u2s_ring_mutex = os_mutex_alloc();
|
fs_shared->u2s_ring_mutex = os_mutex_alloc();
|
||||||
fs_shared->streamer_count = Clamp(1, os_logical_core_count()-1, 4);
|
fs_shared->streamer_count = Clamp(1, os_get_system_info()->logical_processor_count-1, 4);
|
||||||
fs_shared->streamers = push_array(arena, OS_Handle, 1);
|
fs_shared->streamers = push_array(arena, OS_Handle, 1);
|
||||||
for(U64 idx = 0; idx < fs_shared->streamer_count; idx += 1)
|
for(U64 idx = 0; idx < fs_shared->streamer_count; idx += 1)
|
||||||
{
|
{
|
||||||
fs_shared->streamers[idx] = os_launch_thread(fs_streamer_thread__entry_point, (void *)idx, 0);
|
fs_shared->streamers[idx] = os_thread_launch(fs_streamer_thread__entry_point, (void *)idx, 0);
|
||||||
}
|
}
|
||||||
fs_shared->detector_thread = os_launch_thread(fs_detector_thread__entry_point, 0, 0);
|
fs_shared->detector_thread = os_thread_launch(fs_detector_thread__entry_point, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
@@ -214,7 +214,7 @@ fs_streamer_thread__entry_point(void *p)
|
|||||||
data_arena_size += KB(4)-1;
|
data_arena_size += KB(4)-1;
|
||||||
data_arena_size -= data_arena_size%KB(4);
|
data_arena_size -= data_arena_size%KB(4);
|
||||||
ProfBegin("allocate");
|
ProfBegin("allocate");
|
||||||
Arena *data_arena = arena_alloc__sized(data_arena_size, data_arena_size);
|
Arena *data_arena = arena_alloc(.reserve_size = data_arena_size, .commit_size = data_arena_size);
|
||||||
ProfEnd();
|
ProfEnd();
|
||||||
ProfBegin("read");
|
ProfBegin("read");
|
||||||
String8 data = os_string_from_file_range(data_arena, file, r1u64(0, pre_props.size));
|
String8 data = os_string_from_file_range(data_arena, file, r1u64(0, pre_props.size));
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ fzy_init(void)
|
|||||||
fzy_shared = push_array(arena, FZY_Shared, 1);
|
fzy_shared = push_array(arena, FZY_Shared, 1);
|
||||||
fzy_shared->arena = arena;
|
fzy_shared->arena = arena;
|
||||||
fzy_shared->slots_count = 256;
|
fzy_shared->slots_count = 256;
|
||||||
fzy_shared->stripes_count = os_logical_core_count();
|
fzy_shared->stripes_count = os_get_system_info()->logical_processor_count;
|
||||||
fzy_shared->slots = push_array(arena, FZY_Slot, fzy_shared->slots_count);
|
fzy_shared->slots = push_array(arena, FZY_Slot, fzy_shared->slots_count);
|
||||||
fzy_shared->stripes = push_array(arena, FZY_Stripe, fzy_shared->stripes_count);
|
fzy_shared->stripes = push_array(arena, FZY_Stripe, fzy_shared->stripes_count);
|
||||||
for(U64 idx = 0; idx < fzy_shared->stripes_count; idx += 1)
|
for(U64 idx = 0; idx < fzy_shared->stripes_count; idx += 1)
|
||||||
@@ -117,7 +117,7 @@ fzy_init(void)
|
|||||||
fzy_shared->stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
fzy_shared->stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||||
fzy_shared->stripes[idx].cv = os_condition_variable_alloc();
|
fzy_shared->stripes[idx].cv = os_condition_variable_alloc();
|
||||||
}
|
}
|
||||||
fzy_shared->thread_count = Min(os_logical_core_count(), 2);
|
fzy_shared->thread_count = Min(os_get_system_info()->logical_processor_count, 2);
|
||||||
fzy_shared->threads = push_array(arena, FZY_Thread, fzy_shared->thread_count);
|
fzy_shared->threads = push_array(arena, FZY_Thread, fzy_shared->thread_count);
|
||||||
for(U64 idx = 0; idx < fzy_shared->thread_count; idx += 1)
|
for(U64 idx = 0; idx < fzy_shared->thread_count; idx += 1)
|
||||||
{
|
{
|
||||||
@@ -125,7 +125,7 @@ fzy_init(void)
|
|||||||
fzy_shared->threads[idx].u2f_ring_cv = os_condition_variable_alloc();
|
fzy_shared->threads[idx].u2f_ring_cv = os_condition_variable_alloc();
|
||||||
fzy_shared->threads[idx].u2f_ring_size = KB(64);
|
fzy_shared->threads[idx].u2f_ring_size = KB(64);
|
||||||
fzy_shared->threads[idx].u2f_ring_base = push_array_no_zero(arena, U8, fzy_shared->threads[idx].u2f_ring_size);
|
fzy_shared->threads[idx].u2f_ring_base = push_array_no_zero(arena, U8, fzy_shared->threads[idx].u2f_ring_size);
|
||||||
fzy_shared->threads[idx].thread = os_launch_thread(fzy_search_thread__entry_point, (void *)idx, 0);
|
fzy_shared->threads[idx].thread = os_thread_launch(fzy_search_thread__entry_point, (void *)idx, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ geo_init(void)
|
|||||||
geo_shared = push_array(arena, GEO_Shared, 1);
|
geo_shared = push_array(arena, GEO_Shared, 1);
|
||||||
geo_shared->arena = arena;
|
geo_shared->arena = arena;
|
||||||
geo_shared->slots_count = 1024;
|
geo_shared->slots_count = 1024;
|
||||||
geo_shared->stripes_count = Min(geo_shared->slots_count, os_logical_core_count());
|
geo_shared->stripes_count = Min(geo_shared->slots_count, os_get_system_info()->logical_processor_count);
|
||||||
geo_shared->slots = push_array(arena, GEO_Slot, geo_shared->slots_count);
|
geo_shared->slots = push_array(arena, GEO_Slot, geo_shared->slots_count);
|
||||||
geo_shared->stripes = push_array(arena, GEO_Stripe, geo_shared->stripes_count);
|
geo_shared->stripes = push_array(arena, GEO_Stripe, geo_shared->stripes_count);
|
||||||
geo_shared->stripes_free_nodes = push_array(arena, GEO_Node *, geo_shared->stripes_count);
|
geo_shared->stripes_free_nodes = push_array(arena, GEO_Node *, geo_shared->stripes_count);
|
||||||
@@ -25,13 +25,13 @@ geo_init(void)
|
|||||||
geo_shared->u2x_ring_base = push_array_no_zero(arena, U8, geo_shared->u2x_ring_size);
|
geo_shared->u2x_ring_base = push_array_no_zero(arena, U8, geo_shared->u2x_ring_size);
|
||||||
geo_shared->u2x_ring_cv = os_condition_variable_alloc();
|
geo_shared->u2x_ring_cv = os_condition_variable_alloc();
|
||||||
geo_shared->u2x_ring_mutex = os_mutex_alloc();
|
geo_shared->u2x_ring_mutex = os_mutex_alloc();
|
||||||
geo_shared->xfer_thread_count = Clamp(1, os_logical_core_count()-1, 4);
|
geo_shared->xfer_thread_count = Clamp(1, os_get_system_info()->logical_processor_count-1, 4);
|
||||||
geo_shared->xfer_threads = push_array(arena, OS_Handle, geo_shared->xfer_thread_count);
|
geo_shared->xfer_threads = push_array(arena, OS_Handle, geo_shared->xfer_thread_count);
|
||||||
for(U64 idx = 0; idx < geo_shared->xfer_thread_count; idx += 1)
|
for(U64 idx = 0; idx < geo_shared->xfer_thread_count; idx += 1)
|
||||||
{
|
{
|
||||||
geo_shared->xfer_threads[idx] = os_launch_thread(geo_xfer_thread__entry_point, (void *)idx, 0);
|
geo_shared->xfer_threads[idx] = os_thread_launch(geo_xfer_thread__entry_point, (void *)idx, 0);
|
||||||
}
|
}
|
||||||
geo_shared->evictor_thread = os_launch_thread(geo_evictor_thread__entry_point, 0, 0);
|
geo_shared->evictor_thread = os_thread_launch(geo_evictor_thread__entry_point, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ hs_init(void)
|
|||||||
hs_shared = push_array(arena, HS_Shared, 1);
|
hs_shared = push_array(arena, HS_Shared, 1);
|
||||||
hs_shared->arena = arena;
|
hs_shared->arena = arena;
|
||||||
hs_shared->slots_count = 4096;
|
hs_shared->slots_count = 4096;
|
||||||
hs_shared->stripes_count = Min(hs_shared->slots_count, os_logical_core_count());
|
hs_shared->stripes_count = Min(hs_shared->slots_count, os_get_system_info()->logical_processor_count);
|
||||||
hs_shared->slots = push_array(arena, HS_Slot, hs_shared->slots_count);
|
hs_shared->slots = push_array(arena, HS_Slot, hs_shared->slots_count);
|
||||||
hs_shared->stripes = push_array(arena, HS_Stripe, hs_shared->stripes_count);
|
hs_shared->stripes = push_array(arena, HS_Stripe, hs_shared->stripes_count);
|
||||||
hs_shared->stripes_free_nodes = push_array(arena, HS_Node *, hs_shared->stripes_count);
|
hs_shared->stripes_free_nodes = push_array(arena, HS_Node *, hs_shared->stripes_count);
|
||||||
@@ -43,7 +43,7 @@ hs_init(void)
|
|||||||
stripe->cv = os_condition_variable_alloc();
|
stripe->cv = os_condition_variable_alloc();
|
||||||
}
|
}
|
||||||
hs_shared->key_slots_count = 4096;
|
hs_shared->key_slots_count = 4096;
|
||||||
hs_shared->key_stripes_count = Min(hs_shared->key_slots_count, os_logical_core_count());
|
hs_shared->key_stripes_count = Min(hs_shared->key_slots_count, os_get_system_info()->logical_processor_count);
|
||||||
hs_shared->key_slots = push_array(arena, HS_KeySlot, hs_shared->key_slots_count);
|
hs_shared->key_slots = push_array(arena, HS_KeySlot, hs_shared->key_slots_count);
|
||||||
hs_shared->key_stripes = push_array(arena, HS_Stripe, hs_shared->key_stripes_count);
|
hs_shared->key_stripes = push_array(arena, HS_Stripe, hs_shared->key_stripes_count);
|
||||||
for(U64 idx = 0; idx < hs_shared->key_stripes_count; idx += 1)
|
for(U64 idx = 0; idx < hs_shared->key_stripes_count; idx += 1)
|
||||||
@@ -53,7 +53,7 @@ hs_init(void)
|
|||||||
stripe->rw_mutex = os_rw_mutex_alloc();
|
stripe->rw_mutex = os_rw_mutex_alloc();
|
||||||
stripe->cv = os_condition_variable_alloc();
|
stripe->cv = os_condition_variable_alloc();
|
||||||
}
|
}
|
||||||
hs_shared->evictor_thread = os_launch_thread(hs_evictor_thread__entry_point, 0, 0);
|
hs_shared->evictor_thread = os_thread_launch(hs_evictor_thread__entry_point, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|||||||
@@ -206,6 +206,19 @@ struct RDIM_Temp
|
|||||||
|
|
||||||
#define RDIM_ProfScope(...) for(int _i_ = ((RDIM_ProfBegin(__VA_ARGS__)), 0); !_i_; _i_ += 1, (RDIM_ProfEnd()))
|
#define RDIM_ProfScope(...) for(int _i_ = ((RDIM_ProfBegin(__VA_ARGS__)), 0); !_i_; _i_ += 1, (RDIM_ProfEnd()))
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ rjf: Alignment Macros
|
||||||
|
|
||||||
|
#if _MSC_VER
|
||||||
|
# define RDIM_AlignOf(T) __alignof(T)
|
||||||
|
#elif __clang__
|
||||||
|
# define RDIM_AlignOf(T) __alignof(T)
|
||||||
|
#elif __GNUC__
|
||||||
|
# define RDIM_AlignOf(T) __alignof__(T)
|
||||||
|
#else
|
||||||
|
# error [RDIM Build Error] RDIM_AlignOf(T) is not defined for this compiler.
|
||||||
|
#endif
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Linked List Helper Macros
|
//~ rjf: Linked List Helper Macros
|
||||||
|
|
||||||
@@ -1287,10 +1300,10 @@ RDI_PROC void *rdim_memcpy_fallback(void *dst, void *src, RDI_U64 size);
|
|||||||
RDI_PROC RDIM_Arena *rdim_arena_alloc_fallback(void);
|
RDI_PROC RDIM_Arena *rdim_arena_alloc_fallback(void);
|
||||||
RDI_PROC void rdim_arena_release_fallback(RDIM_Arena *arena);
|
RDI_PROC void rdim_arena_release_fallback(RDIM_Arena *arena);
|
||||||
RDI_PROC RDI_U64 rdim_arena_pos_fallback(RDIM_Arena *arena);
|
RDI_PROC RDI_U64 rdim_arena_pos_fallback(RDIM_Arena *arena);
|
||||||
RDI_PROC void *rdim_arena_push_fallback(RDIM_Arena *arena, RDI_U64 size);
|
RDI_PROC void *rdim_arena_push_fallback(RDIM_Arena *arena, RDI_U64 align, RDI_U64 size);
|
||||||
RDI_PROC void rdim_arena_pop_to_fallback(RDIM_Arena *arena, RDI_U64 pos);
|
RDI_PROC void rdim_arena_pop_to_fallback(RDIM_Arena *arena, RDI_U64 pos);
|
||||||
#endif
|
#endif
|
||||||
#define rdim_push_array_no_zero(a,T,c) (T*)rdim_arena_push((a), sizeof(T)*(c))
|
#define rdim_push_array_no_zero(a,T,c) (T*)rdim_arena_push((a), sizeof(T)*(c), RDIM_AlignOf(T))
|
||||||
#define rdim_push_array(a,T,c) (T*)rdim_memzero(rdim_push_array_no_zero(a,T,c), sizeof(T)*(c))
|
#define rdim_push_array(a,T,c) (T*)rdim_memzero(rdim_push_array_no_zero(a,T,c), sizeof(T)*(c))
|
||||||
|
|
||||||
//- rjf: thread-local scratch arenas
|
//- rjf: thread-local scratch arenas
|
||||||
|
|||||||
@@ -36,4 +36,4 @@
|
|||||||
# error no OS layer setup
|
# error no OS layer setup
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif //OS_SWITCH_H
|
#endif // OS_INC_H
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ mtx_init(void)
|
|||||||
mtx_shared = push_array(arena, MTX_Shared, 1);
|
mtx_shared = push_array(arena, MTX_Shared, 1);
|
||||||
mtx_shared->arena = arena;
|
mtx_shared->arena = arena;
|
||||||
mtx_shared->slots_count = 256;
|
mtx_shared->slots_count = 256;
|
||||||
mtx_shared->stripes_count = Min(mtx_shared->slots_count, os_logical_core_count());
|
mtx_shared->stripes_count = Min(mtx_shared->slots_count, os_get_system_info()->logical_processor_count);
|
||||||
mtx_shared->slots = push_array(arena, MTX_Slot, mtx_shared->slots_count);
|
mtx_shared->slots = push_array(arena, MTX_Slot, mtx_shared->slots_count);
|
||||||
mtx_shared->stripes = push_array(arena, MTX_Stripe, mtx_shared->stripes_count);
|
mtx_shared->stripes = push_array(arena, MTX_Stripe, mtx_shared->stripes_count);
|
||||||
for(U64 idx = 0; idx < mtx_shared->stripes_count; idx += 1)
|
for(U64 idx = 0; idx < mtx_shared->stripes_count; idx += 1)
|
||||||
@@ -19,7 +19,7 @@ mtx_init(void)
|
|||||||
mtx_shared->stripes[idx].arena = arena_alloc();
|
mtx_shared->stripes[idx].arena = arena_alloc();
|
||||||
mtx_shared->stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
mtx_shared->stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||||
}
|
}
|
||||||
mtx_shared->mut_threads_count = Min(os_logical_core_count(), 4);
|
mtx_shared->mut_threads_count = Min(os_get_system_info()->logical_processor_count, 4);
|
||||||
mtx_shared->mut_threads = push_array(arena, MTX_MutThread, mtx_shared->mut_threads_count);
|
mtx_shared->mut_threads = push_array(arena, MTX_MutThread, mtx_shared->mut_threads_count);
|
||||||
for(U64 idx = 0; idx < mtx_shared->mut_threads_count; idx += 1)
|
for(U64 idx = 0; idx < mtx_shared->mut_threads_count; idx += 1)
|
||||||
{
|
{
|
||||||
@@ -27,7 +27,7 @@ mtx_init(void)
|
|||||||
mtx_shared->mut_threads[idx].ring_base = push_array_no_zero(arena, U8, mtx_shared->mut_threads[idx].ring_size);
|
mtx_shared->mut_threads[idx].ring_base = push_array_no_zero(arena, U8, mtx_shared->mut_threads[idx].ring_size);
|
||||||
mtx_shared->mut_threads[idx].cv = os_condition_variable_alloc();
|
mtx_shared->mut_threads[idx].cv = os_condition_variable_alloc();
|
||||||
mtx_shared->mut_threads[idx].mutex = os_mutex_alloc();
|
mtx_shared->mut_threads[idx].mutex = os_mutex_alloc();
|
||||||
mtx_shared->mut_threads[idx].thread = os_launch_thread(mtx_mut_thread__entry_point, &mtx_shared->mut_threads[idx], 0);
|
mtx_shared->mut_threads[idx].thread = os_thread_launch(mtx_mut_thread__entry_point, &mtx_shared->mut_threads[idx], 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ mtx_mut_thread__entry_point(void *p)
|
|||||||
if(op.range.max != op.range.min || op.replace.size != 0)
|
if(op.range.max != op.range.min || op.replace.size != 0)
|
||||||
{
|
{
|
||||||
U64 new_data_size = data.size + op.replace.size - dim_1u64(op.range);
|
U64 new_data_size = data.size + op.replace.size - dim_1u64(op.range);
|
||||||
Arena *arena = arena_alloc__sized(new_data_size + ARENA_HEADER_SIZE, new_data_size + ARENA_HEADER_SIZE);
|
Arena *arena = arena_alloc(.commit_size = new_data_size + ARENA_HEADER_SIZE, .reserve_size = new_data_size + ARENA_HEADER_SIZE);
|
||||||
U8 *new_data_base = push_array_no_zero(arena, U8, new_data_size);
|
U8 *new_data_base = push_array_no_zero(arena, U8, new_data_size);
|
||||||
String8 pre_replace_data = str8_substr(data, r1u64(0, op.range.min));
|
String8 pre_replace_data = str8_substr(data, r1u64(0, op.range.min));
|
||||||
String8 post_replace_data = str8_substr(data, r1u64(op.range.max, data.size));
|
String8 post_replace_data = str8_substr(data, r1u64(op.range.max, data.size));
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,88 +1,7 @@
|
|||||||
// Copyright (c) 2024 Epic Games Tools
|
// Copyright (c) 2024 Epic Games Tools
|
||||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||||
|
|
||||||
#ifndef LINUX_H
|
#ifndef OS_CORE_LINUX_H
|
||||||
#define LINUX_H
|
#define OS_CORE_LINUX_H
|
||||||
|
|
||||||
////////////////////////////////
|
#endif // OS_CORE_LINUX_H
|
||||||
//~ NOTE(allen): Get all these linux includes
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <linux/limits.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <sys/syscall.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
#include <sys/sysinfo.h>
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ NOTE(allen): File Iterator
|
|
||||||
|
|
||||||
struct LNX_FileIter{
|
|
||||||
int fd;
|
|
||||||
DIR *dir;
|
|
||||||
};
|
|
||||||
StaticAssert(sizeof(Member(OS_FileIter, memory)) >= sizeof(LNX_FileIter), file_iter_memory_size);
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ NOTE(allen): Threading Entities
|
|
||||||
|
|
||||||
enum LNX_EntityKind{
|
|
||||||
LNX_EntityKind_Null,
|
|
||||||
LNX_EntityKind_Thread,
|
|
||||||
LNX_EntityKind_Mutex,
|
|
||||||
LNX_EntityKind_ConditionVariable,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct LNX_Entity{
|
|
||||||
LNX_Entity *next;
|
|
||||||
LNX_EntityKind kind;
|
|
||||||
volatile U32 reference_mask;
|
|
||||||
union{
|
|
||||||
struct{
|
|
||||||
OS_ThreadFunctionType *func;
|
|
||||||
void *ptr;
|
|
||||||
pthread_t handle;
|
|
||||||
} thread;
|
|
||||||
pthread_mutex_t mutex;
|
|
||||||
pthread_cond_t cond;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ NOTE(allen): Safe Call Chain
|
|
||||||
|
|
||||||
struct LNX_SafeCallChain{
|
|
||||||
LNX_SafeCallChain *next;
|
|
||||||
OS_ThreadFunctionType *fail_handler;
|
|
||||||
void *ptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ NOTE(allen): Helpers
|
|
||||||
|
|
||||||
internal B32 lnx_write_list_to_file_descriptor(int fd, String8List list);
|
|
||||||
|
|
||||||
internal void lnx_date_time_from_tm(DateTime *out, struct tm *in, U32 msec);
|
|
||||||
internal void lnx_tm_from_date_time(struct tm *out, DateTime *in);
|
|
||||||
internal void lnx_dense_time_from_timespec(DenseTime *out, struct timespec *in);
|
|
||||||
internal void lnx_file_properties_from_stat(FileProperties *out, struct stat *in);
|
|
||||||
|
|
||||||
internal String8 lnx_string_from_signal(int signum);
|
|
||||||
internal String8 lnx_string_from_errno(int error_number);
|
|
||||||
|
|
||||||
internal LNX_Entity* lnx_alloc_entity(LNX_EntityKind kind);
|
|
||||||
internal void lnx_free_entity(LNX_Entity *entity);
|
|
||||||
internal void* lnx_thread_base(void *ptr);
|
|
||||||
|
|
||||||
internal void lnx_safe_call_sig_handler(int);
|
|
||||||
|
|
||||||
#endif //LINUX_H
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,88 @@
|
|||||||
|
// Copyright (c) 2024 Epic Games Tools
|
||||||
|
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||||
|
|
||||||
|
#ifndef LINUX_H
|
||||||
|
#define LINUX_H
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ NOTE(allen): Get all these linux includes
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <linux/limits.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <sys/syscall.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <sys/sysinfo.h>
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ NOTE(allen): File Iterator
|
||||||
|
|
||||||
|
struct LNX_FileIter{
|
||||||
|
int fd;
|
||||||
|
DIR *dir;
|
||||||
|
};
|
||||||
|
StaticAssert(sizeof(Member(OS_FileIter, memory)) >= sizeof(LNX_FileIter), file_iter_memory_size);
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ NOTE(allen): Threading Entities
|
||||||
|
|
||||||
|
enum LNX_EntityKind{
|
||||||
|
LNX_EntityKind_Null,
|
||||||
|
LNX_EntityKind_Thread,
|
||||||
|
LNX_EntityKind_Mutex,
|
||||||
|
LNX_EntityKind_ConditionVariable,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LNX_Entity{
|
||||||
|
LNX_Entity *next;
|
||||||
|
LNX_EntityKind kind;
|
||||||
|
volatile U32 reference_mask;
|
||||||
|
union{
|
||||||
|
struct{
|
||||||
|
OS_ThreadFunctionType *func;
|
||||||
|
void *ptr;
|
||||||
|
pthread_t handle;
|
||||||
|
} thread;
|
||||||
|
pthread_mutex_t mutex;
|
||||||
|
pthread_cond_t cond;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ NOTE(allen): Safe Call Chain
|
||||||
|
|
||||||
|
struct LNX_SafeCallChain{
|
||||||
|
LNX_SafeCallChain *next;
|
||||||
|
OS_ThreadFunctionType *fail_handler;
|
||||||
|
void *ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ NOTE(allen): Helpers
|
||||||
|
|
||||||
|
internal B32 lnx_write_list_to_file_descriptor(int fd, String8List list);
|
||||||
|
|
||||||
|
internal void lnx_date_time_from_tm(DateTime *out, struct tm *in, U32 msec);
|
||||||
|
internal void lnx_tm_from_date_time(struct tm *out, DateTime *in);
|
||||||
|
internal void lnx_dense_time_from_timespec(DenseTime *out, struct timespec *in);
|
||||||
|
internal void lnx_file_properties_from_stat(FileProperties *out, struct stat *in);
|
||||||
|
|
||||||
|
internal String8 lnx_string_from_signal(int signum);
|
||||||
|
internal String8 lnx_string_from_errno(int error_number);
|
||||||
|
|
||||||
|
internal LNX_Entity* lnx_alloc_entity(LNX_EntityKind kind);
|
||||||
|
internal void lnx_free_entity(LNX_Entity *entity);
|
||||||
|
internal void* lnx_thread_base(void *ptr);
|
||||||
|
|
||||||
|
internal void lnx_safe_call_sig_handler(int);
|
||||||
|
|
||||||
|
#endif //LINUX_H
|
||||||
+1
-71
@@ -40,18 +40,6 @@ os_handle_array_from_list(Arena *arena, OS_HandleList *list)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ rjf: System Path Helper (Helper, Implemented Once)
|
|
||||||
|
|
||||||
internal String8
|
|
||||||
os_string_from_system_path(Arena *arena, OS_SystemPath path)
|
|
||||||
{
|
|
||||||
String8List strs = {0};
|
|
||||||
os_string_list_from_system_path(arena, path, &strs);
|
|
||||||
String8 result = str8_list_first(&strs);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Command Line Argc/Argv Helper (Helper, Implemented Once)
|
//~ rjf: Command Line Argc/Argv Helper (Helper, Implemented Once)
|
||||||
|
|
||||||
@@ -164,65 +152,7 @@ os_string_from_file_range(Arena *arena, OS_Handle file, Rng1U64 range)
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Synchronization Primitive Helpers (Helpers, Implemented Once)
|
//~ rjf: GUID Helpers (Helpers, Implemented Once)
|
||||||
|
|
||||||
internal void
|
|
||||||
os_mutex_take(OS_Handle mutex){
|
|
||||||
os_mutex_take_(mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
|
||||||
os_mutex_drop(OS_Handle mutex){
|
|
||||||
os_mutex_drop_(mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
|
||||||
os_rw_mutex_take_r(OS_Handle rw_mutex){
|
|
||||||
os_rw_mutex_take_r_(rw_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
|
||||||
os_rw_mutex_drop_r(OS_Handle rw_mutex){
|
|
||||||
os_rw_mutex_drop_r_(rw_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
|
||||||
os_rw_mutex_take_w(OS_Handle rw_mutex){
|
|
||||||
os_rw_mutex_take_w_(rw_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
|
||||||
os_rw_mutex_drop_w(OS_Handle rw_mutex){
|
|
||||||
os_rw_mutex_drop_w_(rw_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal B32
|
|
||||||
os_condition_variable_wait(OS_Handle cv, OS_Handle mutex, U64 endt_us){
|
|
||||||
B32 result = os_condition_variable_wait_(cv, mutex, endt_us);
|
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal B32
|
|
||||||
os_condition_variable_wait_rw_r(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us){
|
|
||||||
B32 result = os_condition_variable_wait_rw_r_(cv, mutex_rw, endt_us);
|
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal B32
|
|
||||||
os_condition_variable_wait_rw_w(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us){
|
|
||||||
B32 result = os_condition_variable_wait_rw_w_(cv, mutex_rw, endt_us);
|
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
|
||||||
os_condition_variable_signal(OS_Handle cv){
|
|
||||||
os_condition_variable_signal_(cv);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
|
||||||
os_condition_variable_broadcast(OS_Handle cv){
|
|
||||||
os_condition_variable_broadcast_(cv);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal String8
|
internal String8
|
||||||
os_string_from_guid(Arena *arena, OS_Guid guid)
|
os_string_from_guid(Arena *arena, OS_Guid guid)
|
||||||
|
|||||||
+80
-121
@@ -4,6 +4,34 @@
|
|||||||
#ifndef OS_CORE_H
|
#ifndef OS_CORE_H
|
||||||
#define OS_CORE_H
|
#define OS_CORE_H
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ rjf: System Info
|
||||||
|
|
||||||
|
typedef struct OS_SystemInfo OS_SystemInfo;
|
||||||
|
struct OS_SystemInfo
|
||||||
|
{
|
||||||
|
U32 logical_processor_count;
|
||||||
|
U64 page_size;
|
||||||
|
U64 large_page_size;
|
||||||
|
U64 allocation_granularity;
|
||||||
|
U64 microsecond_resolution;
|
||||||
|
String8 machine_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ rjf: Process Info
|
||||||
|
|
||||||
|
typedef struct OS_ProcessInfo OS_ProcessInfo;
|
||||||
|
struct OS_ProcessInfo
|
||||||
|
{
|
||||||
|
U32 pid;
|
||||||
|
String8 binary_path;
|
||||||
|
String8 initial_path;
|
||||||
|
String8 user_program_data_path;
|
||||||
|
String8List module_load_paths;
|
||||||
|
String8List environment;
|
||||||
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Access Flags
|
//~ rjf: Access Flags
|
||||||
|
|
||||||
@@ -19,7 +47,7 @@ enum
|
|||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ allen: Files
|
//~ rjf: Files
|
||||||
|
|
||||||
typedef U32 OS_FileIterFlags;
|
typedef U32 OS_FileIterFlags;
|
||||||
enum
|
enum
|
||||||
@@ -52,40 +80,10 @@ struct OS_FileID
|
|||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: System Paths
|
//~ rjf: Process Launch Parameters
|
||||||
|
|
||||||
typedef enum OS_SystemPath
|
typedef struct OS_ProcessLaunchParams OS_ProcessLaunchParams;
|
||||||
{
|
struct OS_ProcessLaunchParams
|
||||||
OS_SystemPath_Binary,
|
|
||||||
OS_SystemPath_Initial,
|
|
||||||
OS_SystemPath_Current,
|
|
||||||
OS_SystemPath_UserProgramData,
|
|
||||||
OS_SystemPath_ModuleLoad,
|
|
||||||
}
|
|
||||||
OS_SystemPath;
|
|
||||||
|
|
||||||
typedef enum OS_PathFromUserKind
|
|
||||||
{
|
|
||||||
OS_PathFromUserKind_Save,
|
|
||||||
OS_PathFromUserKind_Load,
|
|
||||||
}
|
|
||||||
OS_PathFromUserKind;
|
|
||||||
|
|
||||||
typedef struct OS_PathFromUser OS_PathFromUser;
|
|
||||||
struct OS_PathFromUser
|
|
||||||
{
|
|
||||||
OS_PathFromUserKind kind;
|
|
||||||
String8 path;
|
|
||||||
U64 filter_count;
|
|
||||||
String8 *filter_extensions;
|
|
||||||
String8 *filter_names;
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ allen: Launch Input
|
|
||||||
|
|
||||||
typedef struct OS_LaunchOptions OS_LaunchOptions;
|
|
||||||
struct OS_LaunchOptions
|
|
||||||
{
|
{
|
||||||
String8List cmd_line;
|
String8List cmd_line;
|
||||||
String8 path;
|
String8 path;
|
||||||
@@ -126,21 +124,16 @@ struct OS_HandleArray
|
|||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
// Time
|
//~ rjf: Globally Unique IDs
|
||||||
|
|
||||||
#define OS_UNIX_TIME_MAX max_U32
|
typedef struct OS_Guid OS_Guid;
|
||||||
typedef U32 OS_UnixTime;
|
struct OS_Guid
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
// Global Unique ID
|
|
||||||
|
|
||||||
typedef struct OS_Guid
|
|
||||||
{
|
{
|
||||||
U32 data1;
|
U32 data1;
|
||||||
U16 data2;
|
U16 data2;
|
||||||
U16 data3;
|
U16 data3;
|
||||||
U8 data4[8];
|
U8 data4[8];
|
||||||
} OS_Guid;
|
};
|
||||||
StaticAssert(sizeof(OS_Guid) == 16, os_guid_check);
|
StaticAssert(sizeof(OS_Guid) == 16, os_guid_check);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
@@ -156,11 +149,6 @@ internal B32 os_handle_match(OS_Handle a, OS_Handle b);
|
|||||||
internal void os_handle_list_push(Arena *arena, OS_HandleList *handles, OS_Handle handle);
|
internal void os_handle_list_push(Arena *arena, OS_HandleList *handles, OS_Handle handle);
|
||||||
internal OS_HandleArray os_handle_array_from_list(Arena *arena, OS_HandleList *list);
|
internal OS_HandleArray os_handle_array_from_list(Arena *arena, OS_HandleList *list);
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ rjf: System Path Helper (Helper, Implemented Once)
|
|
||||||
|
|
||||||
internal String8 os_string_from_system_path(Arena *arena, OS_SystemPath path);
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Command Line Argc/Argv Helper (Helper, Implemented Once)
|
//~ rjf: Command Line Argc/Argv Helper (Helper, Implemented Once)
|
||||||
|
|
||||||
@@ -178,73 +166,42 @@ internal S64 os_file_id_compare(OS_FileID a, OS_FileID b);
|
|||||||
internal String8 os_string_from_file_range(Arena *arena, OS_Handle file, Rng1U64 range);
|
internal String8 os_string_from_file_range(Arena *arena, OS_Handle file, Rng1U64 range);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Synchronization Primitive Helpers (Helpers, Implemented Once)
|
//~ rjf: GUID Helpers (Helpers, Implemented Once)
|
||||||
|
|
||||||
internal void os_mutex_take(OS_Handle mutex);
|
internal String8 os_string_from_guid(Arena *arena, OS_Guid guid);
|
||||||
internal void os_mutex_drop(OS_Handle mutex);
|
|
||||||
internal void os_rw_mutex_take_r(OS_Handle rw_mutex);
|
|
||||||
internal void os_rw_mutex_drop_r(OS_Handle rw_mutex);
|
|
||||||
internal void os_rw_mutex_take_w(OS_Handle rw_mutex);
|
|
||||||
internal void os_rw_mutex_drop_w(OS_Handle rw_mutex);
|
|
||||||
// returns false on timeout, true on signal, (max_wait_ms = max_U64) -> no timeout
|
|
||||||
internal B32 os_condition_variable_wait(OS_Handle cv, OS_Handle mutex, U64 endt_us);
|
|
||||||
internal B32 os_condition_variable_wait_rw_r(OS_Handle cv, OS_Handle rw_mutex, U64 endt_us);
|
|
||||||
internal B32 os_condition_variable_wait_rw_w(OS_Handle cv, OS_Handle rw_mutex, U64 endt_us);
|
|
||||||
internal void os_condition_variable_signal(OS_Handle cv);
|
|
||||||
internal void os_condition_variable_broadcast(OS_Handle cv);
|
|
||||||
|
|
||||||
#define OS_MutexScope(mutex) DeferLoop(os_mutex_take(mutex), os_mutex_drop(mutex))
|
|
||||||
#define OS_MutexScopeR(mutex) DeferLoop(os_rw_mutex_take_r(mutex), os_rw_mutex_drop_r(mutex))
|
|
||||||
#define OS_MutexScopeW(mutex) DeferLoop(os_rw_mutex_take_w(mutex), os_rw_mutex_drop_w(mutex))
|
|
||||||
#define OS_MutexScopeRWPromote(mutex) DeferLoop((os_rw_mutex_drop_r(mutex), os_rw_mutex_take_w(mutex)), (os_rw_mutex_drop_w(mutex), os_rw_mutex_take_r(mutex)))
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: @os_hooks Main Initialization API (Implemented Per-OS)
|
//~ rjf: @os_hooks System/Process Info (Implemented Per-OS)
|
||||||
|
|
||||||
internal void os_init(void);
|
internal OS_SystemInfo *os_get_system_info(void);
|
||||||
|
internal OS_ProcessInfo *os_get_process_info(void);
|
||||||
|
internal String8 os_get_current_path(Arena *arena);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: @os_hooks Memory Allocation (Implemented Per-OS)
|
//~ rjf: @os_hooks Memory Allocation (Implemented Per-OS)
|
||||||
|
|
||||||
internal void* os_reserve(U64 size);
|
//- rjf: basic
|
||||||
|
internal void *os_reserve(U64 size);
|
||||||
internal B32 os_commit(void *ptr, U64 size);
|
internal B32 os_commit(void *ptr, U64 size);
|
||||||
internal void* os_reserve_large(U64 size);
|
|
||||||
internal B32 os_commit_large(void *ptr, U64 size);
|
|
||||||
internal void os_decommit(void *ptr, U64 size);
|
internal void os_decommit(void *ptr, U64 size);
|
||||||
internal void os_release(void *ptr, U64 size);
|
internal void os_release(void *ptr, U64 size);
|
||||||
|
|
||||||
internal B32 os_set_large_pages(B32 flag);
|
//- rjf: large pages
|
||||||
|
internal B32 os_set_large_pages_enabled(B32 flag);
|
||||||
internal B32 os_large_pages_enabled(void);
|
internal B32 os_large_pages_enabled(void);
|
||||||
internal U64 os_large_page_size(void);
|
internal void *os_reserve_large(U64 size);
|
||||||
|
internal B32 os_commit_large(void *ptr, U64 size);
|
||||||
internal void* os_alloc_ring_buffer(U64 size, U64 *actual_size_out);
|
|
||||||
internal void os_free_ring_buffer(void *ring_buffer, U64 actual_size);
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: @os_hooks System Info (Implemented Per-OS)
|
//~ rjf: @os_hooks Thread Info (Implemented Per-OS)
|
||||||
|
|
||||||
internal String8 os_machine_name(void);
|
|
||||||
internal U64 os_page_size(void);
|
|
||||||
internal U64 os_allocation_granularity(void);
|
|
||||||
internal U64 os_logical_core_count(void);
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ rjf: @os_hooks Process & Thread Info (Implemented Per-OS)
|
|
||||||
|
|
||||||
internal S32 os_get_pid(void);
|
|
||||||
internal S32 os_get_tid(void);
|
|
||||||
internal String8List os_get_environment(void);
|
|
||||||
internal U64 os_string_list_from_system_path(Arena *arena, OS_SystemPath path, String8List *out);
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ rjf: @os_hooks Thread Names
|
|
||||||
|
|
||||||
|
internal U32 os_tid(void);
|
||||||
internal void os_set_thread_name(String8 string);
|
internal void os_set_thread_name(String8 string);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: @os_hooks Process Control (Implemented Per-OS)
|
//~ rjf: @os_hooks Aborting (Implemented Per-OS)
|
||||||
|
|
||||||
internal void os_exit_process(S32 exit_code);
|
internal void os_abort(S32 exit_code);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: @os_hooks File System (Implemented Per-OS)
|
//~ rjf: @os_hooks File System (Implemented Per-OS)
|
||||||
@@ -289,56 +246,53 @@ internal void os_shared_memory_view_close(OS_Handle handle, void *ptr);
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: @os_hooks Time (Implemented Per-OS)
|
//~ rjf: @os_hooks Time (Implemented Per-OS)
|
||||||
|
|
||||||
internal OS_UnixTime os_now_unix(void);
|
|
||||||
internal DateTime os_now_universal_time(void);
|
|
||||||
internal DateTime os_universal_time_from_local_time(DateTime *local_time);
|
|
||||||
internal DateTime os_local_time_from_universal_time(DateTime *universal_time);
|
|
||||||
internal U64 os_now_microseconds(void);
|
internal U64 os_now_microseconds(void);
|
||||||
|
internal U32 os_now_unix(void);
|
||||||
|
internal DateTime os_now_universal_time(void);
|
||||||
|
internal DateTime os_universal_time_from_local(DateTime *local_time);
|
||||||
|
internal DateTime os_local_time_from_universal(DateTime *universal_time);
|
||||||
internal void os_sleep_milliseconds(U32 msec);
|
internal void os_sleep_milliseconds(U32 msec);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: @os_hooks Child Processes (Implemented Per-OS)
|
//~ rjf: @os_hooks Child Processes (Implemented Per-OS)
|
||||||
|
|
||||||
internal B32 os_launch_process(OS_LaunchOptions *options, OS_Handle *handle_out);
|
internal OS_Handle os_process_launch(OS_ProcessLaunchParams *params);
|
||||||
internal B32 os_process_wait(OS_Handle handle, U64 endt_us);
|
internal B32 os_process_join(OS_Handle handle, U64 endt_us);
|
||||||
internal void os_process_release_handle(OS_Handle handle);
|
internal void os_process_detach(OS_Handle handle);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: @os_hooks Threads (Implemented Per-OS)
|
//~ rjf: @os_hooks Threads (Implemented Per-OS)
|
||||||
|
|
||||||
internal OS_Handle os_launch_thread(OS_ThreadFunctionType *func, void *ptr, void *params);
|
internal OS_Handle os_thread_launch(OS_ThreadFunctionType *func, void *ptr, void *params);
|
||||||
internal B32 os_thread_wait(OS_Handle handle, U64 endt_us);
|
internal B32 os_thread_join(OS_Handle handle, U64 endt_us);
|
||||||
internal void os_release_thread_handle(OS_Handle thread);
|
internal void os_thread_detach(OS_Handle handle);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: @os_hooks Synchronization Primitives (Implemented Per-OS)
|
//~ rjf: @os_hooks Synchronization Primitives (Implemented Per-OS)
|
||||||
|
|
||||||
// NOTE(allen): Mutexes are recursive - support counted acquire/release nesting
|
|
||||||
// on a single thread
|
|
||||||
|
|
||||||
//- rjf: recursive mutexes
|
//- rjf: recursive mutexes
|
||||||
internal OS_Handle os_mutex_alloc(void);
|
internal OS_Handle os_mutex_alloc(void);
|
||||||
internal void os_mutex_release(OS_Handle mutex);
|
internal void os_mutex_release(OS_Handle mutex);
|
||||||
internal void os_mutex_take_(OS_Handle mutex);
|
internal void os_mutex_take(OS_Handle mutex);
|
||||||
internal void os_mutex_drop_(OS_Handle mutex);
|
internal void os_mutex_drop(OS_Handle mutex);
|
||||||
|
|
||||||
//- rjf: reader/writer mutexes
|
//- rjf: reader/writer mutexes
|
||||||
internal OS_Handle os_rw_mutex_alloc(void);
|
internal OS_Handle os_rw_mutex_alloc(void);
|
||||||
internal void os_rw_mutex_release(OS_Handle rw_mutex);
|
internal void os_rw_mutex_release(OS_Handle rw_mutex);
|
||||||
internal void os_rw_mutex_take_r_(OS_Handle mutex);
|
internal void os_rw_mutex_take_r(OS_Handle mutex);
|
||||||
internal void os_rw_mutex_drop_r_(OS_Handle mutex);
|
internal void os_rw_mutex_drop_r(OS_Handle mutex);
|
||||||
internal void os_rw_mutex_take_w_(OS_Handle mutex);
|
internal void os_rw_mutex_take_w(OS_Handle mutex);
|
||||||
internal void os_rw_mutex_drop_w_(OS_Handle mutex);
|
internal void os_rw_mutex_drop_w(OS_Handle mutex);
|
||||||
|
|
||||||
//- rjf: condition variables
|
//- rjf: condition variables
|
||||||
internal OS_Handle os_condition_variable_alloc(void);
|
internal OS_Handle os_condition_variable_alloc(void);
|
||||||
internal void os_condition_variable_release(OS_Handle cv);
|
internal void os_condition_variable_release(OS_Handle cv);
|
||||||
// returns false on timeout, true on signal, (max_wait_ms = max_U64) -> no timeout
|
// returns false on timeout, true on signal, (max_wait_ms = max_U64) -> no timeout
|
||||||
internal B32 os_condition_variable_wait_(OS_Handle cv, OS_Handle mutex, U64 endt_us);
|
internal B32 os_condition_variable_wait(OS_Handle cv, OS_Handle mutex, U64 endt_us);
|
||||||
internal B32 os_condition_variable_wait_rw_r_(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us);
|
internal B32 os_condition_variable_wait_rw_r(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us);
|
||||||
internal B32 os_condition_variable_wait_rw_w_(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us);
|
internal B32 os_condition_variable_wait_rw_w(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us);
|
||||||
internal void os_condition_variable_signal_(OS_Handle cv);
|
internal void os_condition_variable_signal(OS_Handle cv);
|
||||||
internal void os_condition_variable_broadcast_(OS_Handle cv);
|
internal void os_condition_variable_broadcast(OS_Handle cv);
|
||||||
|
|
||||||
//- rjf: cross-process semaphores
|
//- rjf: cross-process semaphores
|
||||||
internal OS_Handle os_semaphore_alloc(U32 initial_count, U32 max_count, String8 name);
|
internal OS_Handle os_semaphore_alloc(U32 initial_count, U32 max_count, String8 name);
|
||||||
@@ -348,12 +302,18 @@ internal void os_semaphore_close(OS_Handle semaphore);
|
|||||||
internal B32 os_semaphore_take(OS_Handle semaphore, U64 endt_us);
|
internal B32 os_semaphore_take(OS_Handle semaphore, U64 endt_us);
|
||||||
internal void os_semaphore_drop(OS_Handle semaphore);
|
internal void os_semaphore_drop(OS_Handle semaphore);
|
||||||
|
|
||||||
|
//- rjf: scope macros
|
||||||
|
#define OS_MutexScope(mutex) DeferLoop(os_mutex_take(mutex), os_mutex_drop(mutex))
|
||||||
|
#define OS_MutexScopeR(mutex) DeferLoop(os_rw_mutex_take_r(mutex), os_rw_mutex_drop_r(mutex))
|
||||||
|
#define OS_MutexScopeW(mutex) DeferLoop(os_rw_mutex_take_w(mutex), os_rw_mutex_drop_w(mutex))
|
||||||
|
#define OS_MutexScopeRWPromote(mutex) DeferLoop((os_rw_mutex_drop_r(mutex), os_rw_mutex_take_w(mutex)), (os_rw_mutex_drop_w(mutex), os_rw_mutex_take_r(mutex)))
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: @os_hooks Dynamically-Loaded Libraries (Implemented Per-OS)
|
//~ rjf: @os_hooks Dynamically-Loaded Libraries (Implemented Per-OS)
|
||||||
|
|
||||||
internal OS_Handle os_library_open(String8 path);
|
internal OS_Handle os_library_open(String8 path);
|
||||||
internal VoidProc *os_library_load_proc(OS_Handle lib, String8 name);
|
|
||||||
internal void os_library_close(OS_Handle lib);
|
internal void os_library_close(OS_Handle lib);
|
||||||
|
internal VoidProc *os_library_load_proc(OS_Handle lib, String8 name);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: @os_hooks Safe Calls (Implemented Per-OS)
|
//~ rjf: @os_hooks Safe Calls (Implemented Per-OS)
|
||||||
@@ -364,7 +324,6 @@ internal void os_safe_call(OS_ThreadFunctionType *func, OS_ThreadFunctionType *f
|
|||||||
//~ rjf: @os_hooks GUIDs (Implemented Per-OS)
|
//~ rjf: @os_hooks GUIDs (Implemented Per-OS)
|
||||||
|
|
||||||
internal OS_Guid os_make_guid(void);
|
internal OS_Guid os_make_guid(void);
|
||||||
internal String8 os_string_from_guid(Arena *arena, OS_Guid guid);
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: @os_hooks Entry Points (Implemented Per-OS)
|
//~ rjf: @os_hooks Entry Points (Implemented Per-OS)
|
||||||
|
|||||||
+445
-632
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,11 @@
|
|||||||
// Copyright (c) 2024 Epic Games Tools
|
// Copyright (c) 2024 Epic Games Tools
|
||||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||||
|
|
||||||
#ifndef WIN32_H
|
#ifndef OS_CORE_WIN32_H
|
||||||
#define WIN32_H
|
#define OS_CORE_WIN32_H
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ NOTE(allen): Negotiate the windows header include order
|
//~ rjf: Includes / Libraries
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
@@ -14,12 +14,20 @@
|
|||||||
#include <tlhelp32.h>
|
#include <tlhelp32.h>
|
||||||
#include <Shlobj.h>
|
#include <Shlobj.h>
|
||||||
#include <processthreadsapi.h>
|
#include <processthreadsapi.h>
|
||||||
|
#pragma comment(lib, "user32")
|
||||||
|
#pragma comment(lib, "winmm")
|
||||||
|
#pragma comment(lib, "shell32")
|
||||||
|
#pragma comment(lib, "advapi32")
|
||||||
|
#pragma comment(lib, "rpcrt4")
|
||||||
|
#pragma comment(lib, "shlwapi")
|
||||||
|
#pragma comment(lib, "comctl32")
|
||||||
|
#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") // this is required for loading correct comctl32 dll file
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ NOTE(allen): File Iterator
|
//~ rjf: File Iterator Types
|
||||||
|
|
||||||
typedef struct W32_FileIter W32_FileIter;
|
typedef struct OS_W32_FileIter OS_W32_FileIter;
|
||||||
struct W32_FileIter
|
struct OS_W32_FileIter
|
||||||
{
|
{
|
||||||
HANDLE handle;
|
HANDLE handle;
|
||||||
WIN32_FIND_DATAW find_data;
|
WIN32_FIND_DATAW find_data;
|
||||||
@@ -27,29 +35,30 @@ struct W32_FileIter
|
|||||||
String8Array drive_strings;
|
String8Array drive_strings;
|
||||||
U64 drive_strings_iter_idx;
|
U64 drive_strings_iter_idx;
|
||||||
};
|
};
|
||||||
StaticAssert(sizeof(Member(OS_FileIter, memory)) >= sizeof(W32_FileIter), file_iter_memory_size);
|
StaticAssert(sizeof(Member(OS_FileIter, memory)) >= sizeof(OS_W32_FileIter), file_iter_memory_size);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ NOTE(allen): Threading Entities
|
//~ rjf: Entity Types
|
||||||
|
|
||||||
typedef enum W32_EntityKind
|
typedef enum OS_W32_EntityKind
|
||||||
{
|
{
|
||||||
W32_EntityKind_Null,
|
OS_W32_EntityKind_Null,
|
||||||
W32_EntityKind_Thread,
|
OS_W32_EntityKind_Thread,
|
||||||
W32_EntityKind_Mutex,
|
OS_W32_EntityKind_Mutex,
|
||||||
W32_EntityKind_RWMutex,
|
OS_W32_EntityKind_RWMutex,
|
||||||
W32_EntityKind_ConditionVariable,
|
OS_W32_EntityKind_ConditionVariable,
|
||||||
}
|
}
|
||||||
W32_EntityKind;
|
OS_W32_EntityKind;
|
||||||
|
|
||||||
typedef struct W32_Entity W32_Entity;
|
typedef struct OS_W32_Entity OS_W32_Entity;
|
||||||
struct W32_Entity
|
struct OS_W32_Entity
|
||||||
{
|
{
|
||||||
W32_Entity *next;
|
OS_W32_Entity *next;
|
||||||
W32_EntityKind kind;
|
OS_W32_EntityKind kind;
|
||||||
volatile U32 reference_mask;
|
union
|
||||||
union{
|
{
|
||||||
struct{
|
struct
|
||||||
|
{
|
||||||
OS_ThreadFunctionType *func;
|
OS_ThreadFunctionType *func;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
HANDLE handle;
|
HANDLE handle;
|
||||||
@@ -62,23 +71,54 @@ struct W32_Entity
|
|||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Helpers
|
//~ rjf: State
|
||||||
|
|
||||||
//- rjf: files
|
typedef struct OS_W32_State OS_W32_State;
|
||||||
internal FilePropertyFlags w32_file_property_flags_from_dwFileAttributes(DWORD dwFileAttributes);
|
struct OS_W32_State
|
||||||
internal void w32_file_properties_from_attributes(FileProperties *properties, WIN32_FILE_ATTRIBUTE_DATA *attributes);
|
{
|
||||||
|
Arena *arena;
|
||||||
|
|
||||||
//- rjf: time
|
// rjf: info
|
||||||
internal void w32_date_time_from_system_time(DateTime *out, SYSTEMTIME *in);
|
OS_SystemInfo system_info;
|
||||||
internal void w32_system_time_from_date_time(SYSTEMTIME *out, DateTime *in);
|
OS_ProcessInfo process_info;
|
||||||
internal void w32_dense_time_from_file_time(DenseTime *out, FILETIME *in);
|
|
||||||
internal U32 w32_sleep_ms_from_endt_us(U64 endt_us);
|
|
||||||
|
|
||||||
//- rjf: entities
|
// rjf: large pages
|
||||||
internal W32_Entity* w32_alloc_entity(W32_EntityKind kind);
|
B32 large_pages_enabled;
|
||||||
internal void w32_free_entity(W32_Entity *entity);
|
|
||||||
|
|
||||||
//- rjf: threads
|
// rjf: entity storage
|
||||||
internal DWORD w32_thread_base(void *ptr);
|
CRITICAL_SECTION entity_mutex;
|
||||||
|
Arena *entity_arena;
|
||||||
|
OS_W32_Entity *entity_free;
|
||||||
|
};
|
||||||
|
|
||||||
#endif //WIN32_H
|
////////////////////////////////
|
||||||
|
//~ rjf: Globals
|
||||||
|
|
||||||
|
global OS_W32_State os_w32_state = {0};
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ rjf: File Info Conversion Helpers
|
||||||
|
|
||||||
|
internal FilePropertyFlags os_w32_file_property_flags_from_dwFileAttributes(DWORD dwFileAttributes);
|
||||||
|
internal void os_w32_file_properties_from_attribute_data(FileProperties *properties, WIN32_FILE_ATTRIBUTE_DATA *attributes);
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ rjf: Time Conversion Helpers
|
||||||
|
|
||||||
|
internal void os_w32_date_time_from_system_time(DateTime *out, SYSTEMTIME *in);
|
||||||
|
internal void os_w32_system_time_from_date_time(SYSTEMTIME *out, DateTime *in);
|
||||||
|
internal void os_w32_dense_time_from_file_time(DenseTime *out, FILETIME *in);
|
||||||
|
internal U32 os_w32_sleep_ms_from_endt_us(U64 endt_us);
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ rjf: Entity Functions
|
||||||
|
|
||||||
|
internal OS_W32_Entity *os_w32_entity_alloc(OS_W32_EntityKind kind);
|
||||||
|
internal void os_w32_entity_release(OS_W32_Entity *entity);
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ rjf: Thread Entry Point
|
||||||
|
|
||||||
|
internal DWORD os_w32_thread_entry_point(void *ptr);
|
||||||
|
|
||||||
|
#endif // OS_CORE_WIN32_H
|
||||||
|
|||||||
+19
-10
@@ -4,6 +4,17 @@
|
|||||||
#ifndef OS_GRAPHICAL_H
|
#ifndef OS_GRAPHICAL_H
|
||||||
#define OS_GRAPHICAL_H
|
#define OS_GRAPHICAL_H
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ rjf: Graphics System Info
|
||||||
|
|
||||||
|
typedef struct OS_GfxInfo OS_GfxInfo;
|
||||||
|
struct OS_GfxInfo
|
||||||
|
{
|
||||||
|
F32 double_click_time;
|
||||||
|
F32 caret_blink_time;
|
||||||
|
F32 default_refresh_rate;
|
||||||
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Window Types
|
//~ rjf: Window Types
|
||||||
|
|
||||||
@@ -107,13 +118,18 @@ internal void os_event_list_concat_in_place(OS_EventList *dst, OS_EventList *to_
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: @os_hooks Main Initialization API (Implemented Per-OS)
|
//~ rjf: @os_hooks Main Initialization API (Implemented Per-OS)
|
||||||
|
|
||||||
internal void os_graphical_init(void);
|
internal void os_gfx_init(void);
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ rjf: @os_hooks Graphics System Info (Implemented Per-OS)
|
||||||
|
|
||||||
|
internal OS_GfxInfo *os_get_gfx_info(void);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: @os_hooks Clipboards (Implemented Per-OS)
|
//~ rjf: @os_hooks Clipboards (Implemented Per-OS)
|
||||||
|
|
||||||
internal void os_set_clipboard_text(String8 string);
|
internal void os_set_clipboard_text(String8 string);
|
||||||
internal String8 os_get_clipboard_text(Arena *arena);
|
internal String8 os_get_clipboard_text(Arena *arena);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: @os_hooks Windows (Implemented Per-OS)
|
//~ rjf: @os_hooks Windows (Implemented Per-OS)
|
||||||
@@ -162,13 +178,6 @@ internal Vec2F32 os_mouse_from_window(OS_Handle window);
|
|||||||
|
|
||||||
internal void os_set_cursor(OS_Cursor cursor);
|
internal void os_set_cursor(OS_Cursor cursor);
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ rjf: @os_hooks System Properties (Implemented Per-OS)
|
|
||||||
|
|
||||||
internal F32 os_double_click_time(void);
|
|
||||||
internal F32 os_caret_blink_time(void);
|
|
||||||
internal F32 os_default_refresh_rate(void);
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: @os_hooks Native User-Facing Graphical Messages (Implemented Per-OS)
|
//~ rjf: @os_hooks Native User-Facing Graphical Messages (Implemented Per-OS)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
//~ rjf: @os_hooks Main Initialization API (Implemented Per-OS)
|
//~ rjf: @os_hooks Main Initialization API (Implemented Per-OS)
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
os_graphical_init(void)
|
os_gfx_init(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,33 +212,6 @@ os_set_cursor(OS_Cursor cursor)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ rjf: @os_hooks System Properties (Implemented Per-OS)
|
|
||||||
|
|
||||||
internal F32
|
|
||||||
os_double_click_time(void)
|
|
||||||
{
|
|
||||||
return 1.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal F32
|
|
||||||
os_caret_blink_time(void)
|
|
||||||
{
|
|
||||||
return 1.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal F32
|
|
||||||
os_default_refresh_rate(void)
|
|
||||||
{
|
|
||||||
return 60.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal B32
|
|
||||||
os_granular_sleep_enabled(void)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: @os_hooks Native User-Facing Graphical Messages (Implemented Per-OS)
|
//~ rjf: @os_hooks Native User-Facing Graphical Messages (Implemented Per-OS)
|
||||||
|
|
||||||
|
|||||||
+224
-160
@@ -2,44 +2,20 @@
|
|||||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Includes
|
//~ rjf: Modern Windows SDK Functions
|
||||||
|
//
|
||||||
#include <uxtheme.h>
|
// (We must dynamically link to them, since they can be missing in older SDKs)
|
||||||
#include <dwmapi.h>
|
|
||||||
#include <shellscalingapi.h>
|
|
||||||
#pragma comment(lib, "gdi32")
|
|
||||||
#pragma comment(lib, "dwmapi")
|
|
||||||
#pragma comment(lib, "UxTheme")
|
|
||||||
#pragma comment(lib, "ole32")
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ rjf: Globals
|
|
||||||
|
|
||||||
global U32 w32_gfx_thread_tid = 0;
|
|
||||||
global HINSTANCE w32_h_instance = 0;
|
|
||||||
global W32_Window * w32_first_window = 0;
|
|
||||||
global W32_Window * w32_last_window = 0;
|
|
||||||
global W32_Window * w32_first_free_window = 0;
|
|
||||||
global OS_EventList w32_event_list = {0};
|
|
||||||
global Arena * w32_event_arena = 0;
|
|
||||||
global HCURSOR w32_hcursor = 0;
|
|
||||||
global B32 w32_resizing = 0;
|
|
||||||
global F32 w32_default_refresh_rate = 60.f;
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ allen: Windows SDK Inconsistency Fixer
|
|
||||||
|
|
||||||
typedef BOOL w32_SetProcessDpiAwarenessContext_Type(void* value);
|
typedef BOOL w32_SetProcessDpiAwarenessContext_Type(void* value);
|
||||||
typedef UINT w32_GetDpiForWindow_Type(HWND hwnd);
|
typedef UINT w32_GetDpiForWindow_Type(HWND hwnd);
|
||||||
#define w32_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((void*)-4)
|
#define w32_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((void*)-4)
|
||||||
|
|
||||||
global w32_GetDpiForWindow_Type *w32_GetDpiForWindow_func = 0;
|
global w32_GetDpiForWindow_Type *w32_GetDpiForWindow_func = 0;
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Basic Helpers
|
//~ rjf: Basic Helpers
|
||||||
|
|
||||||
internal Rng2F32
|
internal Rng2F32
|
||||||
w32_base_rect_from_win32_rect(RECT rect)
|
os_w32_rng2f32_from_rect(RECT rect)
|
||||||
{
|
{
|
||||||
Rng2F32 r = {0};
|
Rng2F32 r = {0};
|
||||||
r.x0 = (F32)rect.left;
|
r.x0 = (F32)rect.left;
|
||||||
@@ -53,24 +29,24 @@ w32_base_rect_from_win32_rect(RECT rect)
|
|||||||
//~ rjf: Windows
|
//~ rjf: Windows
|
||||||
|
|
||||||
internal OS_Handle
|
internal OS_Handle
|
||||||
os_window_from_w32_window(W32_Window *window)
|
os_w32_handle_from_window(OS_W32_Window *window)
|
||||||
{
|
{
|
||||||
OS_Handle handle = {(U64)window};
|
OS_Handle handle = {(U64)window};
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal W32_Window *
|
internal OS_W32_Window *
|
||||||
w32_window_from_os_window(OS_Handle handle)
|
os_w32_window_from_handle(OS_Handle handle)
|
||||||
{
|
{
|
||||||
W32_Window *window = (W32_Window *)handle.u64[0];
|
OS_W32_Window *window = (OS_W32_Window *)handle.u64[0];
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal W32_Window *
|
internal OS_W32_Window *
|
||||||
w32_window_from_hwnd(HWND hwnd)
|
os_w32_window_from_hwnd(HWND hwnd)
|
||||||
{
|
{
|
||||||
W32_Window *result = 0;
|
OS_W32_Window *result = 0;
|
||||||
for(W32_Window *w = w32_first_window; w; w = w->next)
|
for(OS_W32_Window *w = os_w32_gfx_state->first_window; w; w = w->next)
|
||||||
{
|
{
|
||||||
if(w->hwnd == hwnd)
|
if(w->hwnd == hwnd)
|
||||||
{
|
{
|
||||||
@@ -82,60 +58,59 @@ w32_window_from_hwnd(HWND hwnd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal HWND
|
internal HWND
|
||||||
w32_hwnd_from_window(W32_Window *window)
|
os_w32_hwnd_from_window(OS_W32_Window *window)
|
||||||
{
|
{
|
||||||
return window->hwnd;
|
return window->hwnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal W32_Window *
|
internal OS_W32_Window *
|
||||||
w32_allocate_window(void)
|
os_w32_window_alloc(void)
|
||||||
{
|
{
|
||||||
W32_Window *result = w32_first_free_window;
|
OS_W32_Window *result = os_w32_gfx_state->free_window;
|
||||||
if(result == 0)
|
if(result)
|
||||||
{
|
{
|
||||||
result = push_array(w32_perm_arena, W32_Window, 1);
|
SLLStackPop(os_w32_gfx_state->free_window);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
w32_first_free_window = w32_first_free_window->next;
|
result = push_array_no_zero(os_w32_gfx_state->arena, OS_W32_Window, 1);
|
||||||
MemoryZeroStruct(result);
|
|
||||||
}
|
}
|
||||||
|
MemoryZeroStruct(result);
|
||||||
if(result)
|
if(result)
|
||||||
{
|
{
|
||||||
DLLPushBack(w32_first_window, w32_last_window, result);
|
DLLPushBack(os_w32_gfx_state->first_window, os_w32_gfx_state->last_window, result);
|
||||||
}
|
}
|
||||||
result->last_window_placement.length = sizeof(WINDOWPLACEMENT);
|
result->last_window_placement.length = sizeof(WINDOWPLACEMENT);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
w32_free_window(W32_Window *window)
|
os_w32_window_release(OS_W32_Window *window)
|
||||||
{
|
{
|
||||||
if(window->paint_arena != 0)
|
if(window->paint_arena != 0)
|
||||||
{
|
{
|
||||||
arena_release(window->paint_arena);
|
arena_release(window->paint_arena);
|
||||||
}
|
}
|
||||||
DestroyWindow(window->hwnd);
|
DestroyWindow(window->hwnd);
|
||||||
DLLRemove(w32_first_window, w32_last_window, window);
|
DLLRemove(os_w32_gfx_state->first_window, os_w32_gfx_state->last_window, window);
|
||||||
window->next = w32_first_free_window;
|
SLLStackPush(os_w32_gfx_state->free_window, window);
|
||||||
w32_first_free_window = window;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal OS_Event *
|
internal OS_Event *
|
||||||
w32_push_event(OS_EventKind kind, W32_Window *window)
|
os_w32_push_event(OS_EventKind kind, OS_W32_Window *window)
|
||||||
{
|
{
|
||||||
OS_Event *result = push_array(w32_event_arena, OS_Event, 1);
|
OS_Event *result = push_array(os_w32_event_arena, OS_Event, 1);
|
||||||
DLLPushBack(w32_event_list.first, w32_event_list.last, result);
|
DLLPushBack(os_w32_event_list.first, os_w32_event_list.last, result);
|
||||||
result->timestamp_us = os_now_microseconds();
|
result->timestamp_us = os_now_microseconds();
|
||||||
result->kind = kind;
|
result->kind = kind;
|
||||||
result->window = os_window_from_w32_window(window);
|
result->window = os_w32_handle_from_window(window);
|
||||||
result->flags = os_get_event_flags();
|
result->flags = os_get_event_flags();
|
||||||
w32_event_list.count += 1;
|
os_w32_event_list.count += 1;
|
||||||
return(result);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal OS_Key
|
internal OS_Key
|
||||||
w32_os_key_from_vkey(WPARAM vkey)
|
os_w32_os_key_from_vkey(WPARAM vkey)
|
||||||
{
|
{
|
||||||
local_persist B32 first = 1;
|
local_persist B32 first = 1;
|
||||||
local_persist OS_Key key_table[256];
|
local_persist OS_Key key_table[256];
|
||||||
@@ -243,11 +218,11 @@ w32_os_key_from_vkey(WPARAM vkey)
|
|||||||
}
|
}
|
||||||
|
|
||||||
OS_Key key = key_table[vkey&bitmask8];
|
OS_Key key = key_table[vkey&bitmask8];
|
||||||
return(key);
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal WPARAM
|
internal WPARAM
|
||||||
w32_vkey_from_os_key(OS_Key key)
|
os_w32_vkey_from_os_key(OS_Key key)
|
||||||
{
|
{
|
||||||
WPARAM result = 0;
|
WPARAM result = 0;
|
||||||
{
|
{
|
||||||
@@ -350,22 +325,20 @@ w32_vkey_from_os_key(OS_Key key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal LRESULT
|
internal LRESULT
|
||||||
w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
ProfBeginFunction();
|
ProfBeginFunction();
|
||||||
LRESULT result = 0;
|
LRESULT result = 0;
|
||||||
|
|
||||||
B32 good = 1;
|
B32 good = 1;
|
||||||
if(w32_event_arena == 0)
|
if(os_w32_event_arena == 0)
|
||||||
{
|
{
|
||||||
result = DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
result = DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||||
good = 0;
|
good = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(good)
|
if(good)
|
||||||
{
|
{
|
||||||
W32_Window *window = w32_window_from_hwnd(hwnd);
|
OS_W32_Window *window = os_w32_window_from_hwnd(hwnd);
|
||||||
OS_Handle window_handle = os_window_from_w32_window(window);
|
OS_Handle window_handle = os_w32_handle_from_window(window);
|
||||||
B32 release = 0;
|
B32 release = 0;
|
||||||
|
|
||||||
switch(uMsg)
|
switch(uMsg)
|
||||||
@@ -377,12 +350,12 @@ w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
|
|
||||||
case WM_ENTERSIZEMOVE:
|
case WM_ENTERSIZEMOVE:
|
||||||
{
|
{
|
||||||
w32_resizing = 1;
|
os_w32_resizing = 1;
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case WM_EXITSIZEMOVE:
|
case WM_EXITSIZEMOVE:
|
||||||
{
|
{
|
||||||
w32_resizing = 0;
|
os_w32_resizing = 0;
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case WM_SIZE:
|
case WM_SIZE:
|
||||||
@@ -392,7 +365,7 @@ w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
{
|
{
|
||||||
PAINTSTRUCT ps = {0};
|
PAINTSTRUCT ps = {0};
|
||||||
BeginPaint(hwnd, &ps);
|
BeginPaint(hwnd, &ps);
|
||||||
window->repaint(os_window_from_w32_window(window), window->repaint_user_data);
|
window->repaint(os_w32_handle_from_window(window), window->repaint_user_data);
|
||||||
EndPaint(hwnd, &ps);
|
EndPaint(hwnd, &ps);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -403,7 +376,7 @@ w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
|
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
{
|
{
|
||||||
w32_push_event(OS_EventKind_WindowClose, window);
|
os_w32_push_event(OS_EventKind_WindowClose, window);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case WM_LBUTTONUP:
|
case WM_LBUTTONUP:
|
||||||
@@ -416,7 +389,7 @@ w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
case WM_MBUTTONDOWN:
|
case WM_MBUTTONDOWN:
|
||||||
case WM_RBUTTONDOWN:
|
case WM_RBUTTONDOWN:
|
||||||
{
|
{
|
||||||
OS_Event *event = w32_push_event(release ? OS_EventKind_Release : OS_EventKind_Press, window);
|
OS_Event *event = os_w32_push_event(release ? OS_EventKind_Release : OS_EventKind_Press, window);
|
||||||
switch (uMsg)
|
switch (uMsg)
|
||||||
{
|
{
|
||||||
case WM_LBUTTONUP: case WM_LBUTTONDOWN:
|
case WM_LBUTTONUP: case WM_LBUTTONDOWN:
|
||||||
@@ -446,7 +419,7 @@ w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
|
|
||||||
case WM_MOUSEMOVE:
|
case WM_MOUSEMOVE:
|
||||||
{
|
{
|
||||||
OS_Event *event = w32_push_event(OS_EventKind_MouseMove, window);
|
OS_Event *event = os_w32_push_event(OS_EventKind_MouseMove, window);
|
||||||
event->pos.x = (F32)(S16)LOWORD(lParam);
|
event->pos.x = (F32)(S16)LOWORD(lParam);
|
||||||
event->pos.y = (F32)(S16)HIWORD(lParam);
|
event->pos.y = (F32)(S16)HIWORD(lParam);
|
||||||
}break;
|
}break;
|
||||||
@@ -454,7 +427,7 @@ w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
case WM_MOUSEWHEEL:
|
case WM_MOUSEWHEEL:
|
||||||
{
|
{
|
||||||
S16 wheel_delta = HIWORD(wParam);
|
S16 wheel_delta = HIWORD(wParam);
|
||||||
OS_Event *event = w32_push_event(OS_EventKind_Scroll, window);
|
OS_Event *event = os_w32_push_event(OS_EventKind_Scroll, window);
|
||||||
POINT p;
|
POINT p;
|
||||||
p.x = (S32)(S16)LOWORD(lParam);
|
p.x = (S32)(S16)LOWORD(lParam);
|
||||||
p.y = (S32)(S16)HIWORD(lParam);
|
p.y = (S32)(S16)HIWORD(lParam);
|
||||||
@@ -467,7 +440,7 @@ w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
case WM_MOUSEHWHEEL:
|
case WM_MOUSEHWHEEL:
|
||||||
{
|
{
|
||||||
S16 wheel_delta = HIWORD(wParam);
|
S16 wheel_delta = HIWORD(wParam);
|
||||||
OS_Event *event = w32_push_event(OS_EventKind_Scroll, window);
|
OS_Event *event = os_w32_push_event(OS_EventKind_Scroll, window);
|
||||||
POINT p;
|
POINT p;
|
||||||
p.x = (S32)(S16)LOWORD(lParam);
|
p.x = (S32)(S16)LOWORD(lParam);
|
||||||
p.y = (S32)(S16)HIWORD(lParam);
|
p.y = (S32)(S16)HIWORD(lParam);
|
||||||
@@ -508,8 +481,8 @@ w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
right_sided = 1;
|
right_sided = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
OS_Event *event = w32_push_event(release ? OS_EventKind_Release : OS_EventKind_Press, window);
|
OS_Event *event = os_w32_push_event(release ? OS_EventKind_Release : OS_EventKind_Press, window);
|
||||||
event->key = w32_os_key_from_vkey(wParam);
|
event->key = os_w32_os_key_from_vkey(wParam);
|
||||||
event->repeat_count = lParam & bitmask16;
|
event->repeat_count = lParam & bitmask16;
|
||||||
event->is_repeat = is_repeat;
|
event->is_repeat = is_repeat;
|
||||||
event->right_sided = right_sided;
|
event->right_sided = right_sided;
|
||||||
@@ -528,7 +501,7 @@ w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
U32 character = wParam;
|
U32 character = wParam;
|
||||||
if(character >= 32 && character != 127)
|
if(character >= 32 && character != 127)
|
||||||
{
|
{
|
||||||
OS_Event *event = w32_push_event(OS_EventKind_Text, window);
|
OS_Event *event = os_w32_push_event(OS_EventKind_Text, window);
|
||||||
if(lParam & bit29)
|
if(lParam & bit29)
|
||||||
{
|
{
|
||||||
event->flags |= OS_EventFlag_Alt;
|
event->flags |= OS_EventFlag_Alt;
|
||||||
@@ -539,7 +512,7 @@ w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
|
|
||||||
case WM_KILLFOCUS:
|
case WM_KILLFOCUS:
|
||||||
{
|
{
|
||||||
w32_push_event(OS_EventKind_WindowLoseFocus, window);
|
os_w32_push_event(OS_EventKind_WindowLoseFocus, window);
|
||||||
ReleaseCapture();
|
ReleaseCapture();
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
@@ -556,10 +529,9 @@ w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
B32 on_border_y = (mouse.y <= window->custom_border_edge_thickness || window_rect.y1-window->custom_border_edge_thickness <= mouse.y);
|
B32 on_border_y = (mouse.y <= window->custom_border_edge_thickness || window_rect.y1-window->custom_border_edge_thickness <= mouse.y);
|
||||||
on_border = on_border_x || on_border_y;
|
on_border = on_border_x || on_border_y;
|
||||||
}
|
}
|
||||||
if(!w32_resizing && !on_border &&
|
if(!os_w32_resizing && !on_border && contains_2f32(window_rect, mouse))
|
||||||
contains_2f32(window_rect, mouse))
|
|
||||||
{
|
{
|
||||||
SetCursor(w32_hcursor);
|
SetCursor(os_w32_gfx_state->hCursor);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -745,7 +717,7 @@ w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
|
|
||||||
//- rjf: check against title bar client areas
|
//- rjf: check against title bar client areas
|
||||||
B32 is_over_title_bar_client_area = 0;
|
B32 is_over_title_bar_client_area = 0;
|
||||||
for(W32_TitleBarClientArea *area = window->first_title_bar_client_area;
|
for(OS_W32_TitleBarClientArea *area = window->first_title_bar_client_area;
|
||||||
area != 0;
|
area != 0;
|
||||||
area = area->next)
|
area = area->next)
|
||||||
{
|
{
|
||||||
@@ -793,7 +765,6 @@ w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
}break;
|
}break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfEnd();
|
ProfEnd();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -802,9 +773,9 @@ w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
//~ rjf: Monitors
|
//~ rjf: Monitors
|
||||||
|
|
||||||
internal BOOL
|
internal BOOL
|
||||||
w32_monitor_gather_enum_proc(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM bundle_ptr)
|
os_w32_monitor_gather_enum_proc(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM bundle_ptr)
|
||||||
{
|
{
|
||||||
W32_MonitorGatherBundle *bundle = (W32_MonitorGatherBundle *)bundle_ptr;
|
OS_W32_MonitorGatherBundle *bundle = (OS_W32_MonitorGatherBundle *)bundle_ptr;
|
||||||
OS_Handle handle = {(U64)monitor};
|
OS_Handle handle = {(U64)monitor};
|
||||||
os_handle_list_push(bundle->arena, bundle->list, handle);
|
os_handle_list_push(bundle->arena, bundle->list, handle);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -814,13 +785,14 @@ w32_monitor_gather_enum_proc(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM bund
|
|||||||
//~ rjf: @os_hooks Main Initialization API (Implemented Per-OS)
|
//~ rjf: @os_hooks Main Initialization API (Implemented Per-OS)
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
os_graphical_init(void)
|
os_gfx_init(void)
|
||||||
{
|
{
|
||||||
//- rjf: grab TID of thread which is doing graphics
|
//- rjf: set up base shared state
|
||||||
w32_gfx_thread_tid = (U32)GetCurrentThreadId();
|
Arena *arena = arena_alloc();
|
||||||
|
os_w32_gfx_state = push_array(arena, OS_W32_GfxState, 1);
|
||||||
//- rjf: grab hinstance
|
os_w32_gfx_state->arena = arena;
|
||||||
w32_h_instance = GetModuleHandle(0);
|
os_w32_gfx_state->gfx_thread_tid = (U32)GetCurrentThreadId();
|
||||||
|
os_w32_gfx_state->hInstance = GetModuleHandle(0);
|
||||||
|
|
||||||
//- rjf: set dpi awareness
|
//- rjf: set dpi awareness
|
||||||
w32_SetProcessDpiAwarenessContext_Type *SetProcessDpiAwarenessContext_func = 0;
|
w32_SetProcessDpiAwarenessContext_Type *SetProcessDpiAwarenessContext_func = 0;
|
||||||
@@ -841,27 +813,144 @@ os_graphical_init(void)
|
|||||||
//- rjf: register graphical-window class
|
//- rjf: register graphical-window class
|
||||||
{
|
{
|
||||||
WNDCLASSEXW wndclass = {sizeof(wndclass)};
|
WNDCLASSEXW wndclass = {sizeof(wndclass)};
|
||||||
wndclass.lpfnWndProc = w32_wnd_proc;
|
wndclass.lpfnWndProc = os_w32_wnd_proc;
|
||||||
wndclass.hInstance = w32_h_instance;
|
wndclass.hInstance = os_w32_gfx_state->hInstance;
|
||||||
wndclass.lpszClassName = L"graphical-window";
|
wndclass.lpszClassName = L"graphical-window";
|
||||||
wndclass.hCursor = LoadCursorA(0, IDC_ARROW);
|
wndclass.hCursor = LoadCursorA(0, IDC_ARROW);
|
||||||
wndclass.hIcon = LoadIcon(w32_h_instance, MAKEINTRESOURCE(1));
|
wndclass.hIcon = LoadIcon(os_w32_gfx_state->hInstance, MAKEINTRESOURCE(1));
|
||||||
wndclass.style = CS_VREDRAW|CS_HREDRAW;
|
wndclass.style = CS_VREDRAW|CS_HREDRAW;
|
||||||
ATOM wndatom = RegisterClassExW(&wndclass);
|
ATOM wndatom = RegisterClassExW(&wndclass);
|
||||||
(void)wndatom;
|
(void)wndatom;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- rjf: grab refresh rate
|
//- rjf: grab graphics system info
|
||||||
{
|
{
|
||||||
|
os_w32_gfx_state->gfx_info.double_click_time = GetDoubleClickTime()/1000.f;
|
||||||
|
os_w32_gfx_state->gfx_info.caret_blink_time = GetCaretBlinkTime()/1000.f;
|
||||||
DEVMODEW devmodew = {0};
|
DEVMODEW devmodew = {0};
|
||||||
if(EnumDisplaySettingsW(0, ENUM_CURRENT_SETTINGS, &devmodew))
|
if(EnumDisplaySettingsW(0, ENUM_CURRENT_SETTINGS, &devmodew))
|
||||||
{
|
{
|
||||||
w32_default_refresh_rate = (F32)devmodew.dmDisplayFrequency;
|
os_w32_gfx_state->gfx_info.default_refresh_rate = (F32)devmodew.dmDisplayFrequency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//- rjf: set initial cursor
|
//- rjf: set initial cursor
|
||||||
os_set_cursor(OS_Cursor_Pointer);
|
os_set_cursor(OS_Cursor_Pointer);
|
||||||
|
|
||||||
|
//- rjf: fill vkey -> OS_Key table
|
||||||
|
{
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'A'] = OS_Key_A;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'B'] = OS_Key_B;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'C'] = OS_Key_C;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'D'] = OS_Key_D;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'E'] = OS_Key_E;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'F'] = OS_Key_F;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'G'] = OS_Key_G;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'H'] = OS_Key_H;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'I'] = OS_Key_I;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'J'] = OS_Key_J;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'K'] = OS_Key_K;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'L'] = OS_Key_L;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'M'] = OS_Key_M;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'N'] = OS_Key_N;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'O'] = OS_Key_O;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'P'] = OS_Key_P;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'Q'] = OS_Key_Q;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'R'] = OS_Key_R;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'S'] = OS_Key_S;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'T'] = OS_Key_T;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'U'] = OS_Key_U;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'V'] = OS_Key_V;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'W'] = OS_Key_W;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'X'] = OS_Key_X;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'Y'] = OS_Key_Y;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[(unsigned int)'Z'] = OS_Key_Z;
|
||||||
|
|
||||||
|
for(U64 i = '0', j = OS_Key_0; i <= '9'; i += 1, j += 1)
|
||||||
|
{
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[i] = (OS_Key)j;
|
||||||
|
}
|
||||||
|
for(U64 i = VK_NUMPAD0, j = OS_Key_0; i <= VK_NUMPAD9; i += 1, j += 1)
|
||||||
|
{
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[i] = (OS_Key)j;
|
||||||
|
}
|
||||||
|
for(U64 i = VK_F1, j = OS_Key_F1; i <= VK_F24; i += 1, j += 1)
|
||||||
|
{
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[i] = (OS_Key)j;
|
||||||
|
}
|
||||||
|
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_SPACE] = OS_Key_Space;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_OEM_3] = OS_Key_Tick;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_OEM_MINUS] = OS_Key_Minus;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_OEM_PLUS] = OS_Key_Equal;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_OEM_4] = OS_Key_LeftBracket;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_OEM_6] = OS_Key_RightBracket;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_OEM_1] = OS_Key_Semicolon;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_OEM_7] = OS_Key_Quote;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_OEM_COMMA] = OS_Key_Comma;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_OEM_PERIOD]= OS_Key_Period;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_OEM_2] = OS_Key_Slash;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_OEM_5] = OS_Key_BackSlash;
|
||||||
|
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_TAB] = OS_Key_Tab;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_PAUSE] = OS_Key_Pause;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_ESCAPE] = OS_Key_Esc;
|
||||||
|
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_UP] = OS_Key_Up;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_LEFT] = OS_Key_Left;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_DOWN] = OS_Key_Down;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_RIGHT] = OS_Key_Right;
|
||||||
|
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_BACK] = OS_Key_Backspace;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_RETURN] = OS_Key_Return;
|
||||||
|
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_DELETE] = OS_Key_Delete;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_INSERT] = OS_Key_Insert;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_PRIOR] = OS_Key_PageUp;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_NEXT] = OS_Key_PageDown;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_HOME] = OS_Key_Home;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_END] = OS_Key_End;
|
||||||
|
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_CAPITAL] = OS_Key_CapsLock;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_NUMLOCK] = OS_Key_NumLock;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_SCROLL] = OS_Key_ScrollLock;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_APPS] = OS_Key_Menu;
|
||||||
|
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_CONTROL] = OS_Key_Ctrl;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_LCONTROL] = OS_Key_Ctrl;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_RCONTROL] = OS_Key_Ctrl;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_SHIFT] = OS_Key_Shift;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_LSHIFT] = OS_Key_Shift;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_RSHIFT] = OS_Key_Shift;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_MENU] = OS_Key_Alt;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_LMENU] = OS_Key_Alt;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_RMENU] = OS_Key_Alt;
|
||||||
|
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_DIVIDE] = OS_Key_NumSlash;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_MULTIPLY] = OS_Key_NumStar;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_SUBTRACT] = OS_Key_NumMinus;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_ADD] = OS_Key_NumPlus;
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_DECIMAL] = OS_Key_NumPeriod;
|
||||||
|
|
||||||
|
for(U32 i = 0; i < 10; i += 1)
|
||||||
|
{
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[VK_NUMPAD0 + i] = (OS_Key)((U64)OS_Key_Num0 + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(U64 i = 0xDF, j = 0; i < 0xFF; i += 1, j += 1)
|
||||||
|
{
|
||||||
|
os_w32_gfx_state->key_from_vkey_table[i] = (OS_Key)((U64)OS_Key_Ex0 + j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ rjf: @os_hooks Graphics System Info (Implemented Per-OS)
|
||||||
|
|
||||||
|
internal OS_GfxInfo *
|
||||||
|
os_get_gfx_info(void)
|
||||||
|
{
|
||||||
|
return &os_w32_gfx_state->gfx_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
@@ -928,13 +1017,13 @@ os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title)
|
|||||||
(int)resolution.x,
|
(int)resolution.x,
|
||||||
(int)resolution.y,
|
(int)resolution.y,
|
||||||
0, 0,
|
0, 0,
|
||||||
w32_h_instance,
|
os_w32_gfx_state->hInstance,
|
||||||
0);
|
0);
|
||||||
scratch_end(scratch);
|
scratch_end(scratch);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- rjf- make/fill window
|
//- rjf- make/fill window
|
||||||
W32_Window *window = w32_allocate_window();
|
OS_W32_Window *window = os_w32_window_alloc();
|
||||||
{
|
{
|
||||||
window->hwnd = hwnd;
|
window->hwnd = hwnd;
|
||||||
if (w32_GetDpiForWindow_func != 0){
|
if (w32_GetDpiForWindow_func != 0){
|
||||||
@@ -960,21 +1049,21 @@ os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//- rjf: convert to handle + return
|
//- rjf: convert to handle + return
|
||||||
OS_Handle result = os_window_from_w32_window(window);
|
OS_Handle result = os_w32_handle_from_window(window);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
os_window_close(OS_Handle handle)
|
os_window_close(OS_Handle handle)
|
||||||
{
|
{
|
||||||
W32_Window *window = w32_window_from_os_window(handle);
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
w32_free_window(window);
|
os_w32_window_release(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
os_window_first_paint(OS_Handle window_handle)
|
os_window_first_paint(OS_Handle window_handle)
|
||||||
{
|
{
|
||||||
W32_Window *window = w32_window_from_os_window(window_handle);
|
OS_W32_Window *window = os_w32_window_from_handle(window_handle);
|
||||||
window->first_paint_done = 1;
|
window->first_paint_done = 1;
|
||||||
ShowWindow(window->hwnd, SW_SHOW);
|
ShowWindow(window->hwnd, SW_SHOW);
|
||||||
if(window->maximized)
|
if(window->maximized)
|
||||||
@@ -986,7 +1075,7 @@ os_window_first_paint(OS_Handle window_handle)
|
|||||||
internal void
|
internal void
|
||||||
os_window_equip_repaint(OS_Handle handle, OS_WindowRepaintFunctionType *repaint, void *user_data)
|
os_window_equip_repaint(OS_Handle handle, OS_WindowRepaintFunctionType *repaint, void *user_data)
|
||||||
{
|
{
|
||||||
W32_Window *window = w32_window_from_os_window(handle);
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
window->repaint = repaint;
|
window->repaint = repaint;
|
||||||
window->repaint_user_data = user_data;
|
window->repaint_user_data = user_data;
|
||||||
}
|
}
|
||||||
@@ -994,7 +1083,7 @@ os_window_equip_repaint(OS_Handle handle, OS_WindowRepaintFunctionType *repaint,
|
|||||||
internal void
|
internal void
|
||||||
os_window_focus(OS_Handle handle)
|
os_window_focus(OS_Handle handle)
|
||||||
{
|
{
|
||||||
W32_Window *window = w32_window_from_os_window(handle);
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
SetForegroundWindow(window->hwnd);
|
SetForegroundWindow(window->hwnd);
|
||||||
SetFocus(window->hwnd);
|
SetFocus(window->hwnd);
|
||||||
}
|
}
|
||||||
@@ -1002,7 +1091,7 @@ os_window_focus(OS_Handle handle)
|
|||||||
internal B32
|
internal B32
|
||||||
os_window_is_focused(OS_Handle handle)
|
os_window_is_focused(OS_Handle handle)
|
||||||
{
|
{
|
||||||
W32_Window *window = w32_window_from_os_window(handle);
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
HWND active_hwnd = GetActiveWindow();
|
HWND active_hwnd = GetActiveWindow();
|
||||||
return active_hwnd == window->hwnd;
|
return active_hwnd == window->hwnd;
|
||||||
}
|
}
|
||||||
@@ -1010,7 +1099,7 @@ os_window_is_focused(OS_Handle handle)
|
|||||||
internal B32
|
internal B32
|
||||||
os_window_is_fullscreen(OS_Handle handle)
|
os_window_is_fullscreen(OS_Handle handle)
|
||||||
{
|
{
|
||||||
W32_Window *window = w32_window_from_os_window(handle);
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
DWORD window_style = GetWindowLong(window->hwnd, GWL_STYLE);
|
DWORD window_style = GetWindowLong(window->hwnd, GWL_STYLE);
|
||||||
return !(window_style & WS_OVERLAPPEDWINDOW);
|
return !(window_style & WS_OVERLAPPEDWINDOW);
|
||||||
}
|
}
|
||||||
@@ -1018,7 +1107,7 @@ os_window_is_fullscreen(OS_Handle handle)
|
|||||||
internal void
|
internal void
|
||||||
os_window_set_fullscreen(OS_Handle handle, B32 fullscreen)
|
os_window_set_fullscreen(OS_Handle handle, B32 fullscreen)
|
||||||
{
|
{
|
||||||
W32_Window *window = w32_window_from_os_window(handle);
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
OS_WindowRepaintFunctionType *repaint = window->repaint;
|
OS_WindowRepaintFunctionType *repaint = window->repaint;
|
||||||
window->repaint = 0;
|
window->repaint = 0;
|
||||||
DWORD window_style = GetWindowLong(window->hwnd, GWL_STYLE);
|
DWORD window_style = GetWindowLong(window->hwnd, GWL_STYLE);
|
||||||
@@ -1056,7 +1145,7 @@ internal B32
|
|||||||
os_window_is_maximized(OS_Handle handle)
|
os_window_is_maximized(OS_Handle handle)
|
||||||
{
|
{
|
||||||
B32 result = 0;
|
B32 result = 0;
|
||||||
W32_Window *window = w32_window_from_os_window(handle);
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
if(window)
|
if(window)
|
||||||
{
|
{
|
||||||
result = !!(IsZoomed(window->hwnd));
|
result = !!(IsZoomed(window->hwnd));
|
||||||
@@ -1067,7 +1156,7 @@ os_window_is_maximized(OS_Handle handle)
|
|||||||
internal void
|
internal void
|
||||||
os_window_set_maximized(OS_Handle handle, B32 maximized)
|
os_window_set_maximized(OS_Handle handle, B32 maximized)
|
||||||
{
|
{
|
||||||
W32_Window *window = w32_window_from_os_window(handle);
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
if(window != 0)
|
if(window != 0)
|
||||||
{
|
{
|
||||||
if(window->first_paint_done)
|
if(window->first_paint_done)
|
||||||
@@ -1089,7 +1178,7 @@ os_window_set_maximized(OS_Handle handle, B32 maximized)
|
|||||||
internal void
|
internal void
|
||||||
os_window_minimize(OS_Handle handle)
|
os_window_minimize(OS_Handle handle)
|
||||||
{
|
{
|
||||||
W32_Window *window = w32_window_from_os_window(handle);
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
if(window != 0)
|
if(window != 0)
|
||||||
{
|
{
|
||||||
ShowWindow(window->hwnd, SW_MINIMIZE);
|
ShowWindow(window->hwnd, SW_MINIMIZE);
|
||||||
@@ -1099,7 +1188,7 @@ os_window_minimize(OS_Handle handle)
|
|||||||
internal void
|
internal void
|
||||||
os_window_bring_to_front(OS_Handle handle)
|
os_window_bring_to_front(OS_Handle handle)
|
||||||
{
|
{
|
||||||
W32_Window *window = w32_window_from_os_window(handle);
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
if(window != 0)
|
if(window != 0)
|
||||||
{
|
{
|
||||||
BringWindowToTop(window->hwnd);
|
BringWindowToTop(window->hwnd);
|
||||||
@@ -1109,7 +1198,7 @@ os_window_bring_to_front(OS_Handle handle)
|
|||||||
internal void
|
internal void
|
||||||
os_window_set_monitor(OS_Handle window_handle, OS_Handle monitor)
|
os_window_set_monitor(OS_Handle window_handle, OS_Handle monitor)
|
||||||
{
|
{
|
||||||
W32_Window *window = w32_window_from_os_window(window_handle);
|
OS_W32_Window *window = os_w32_window_from_handle(window_handle);
|
||||||
HMONITOR hmonitor = (HMONITOR)monitor.u64[0];
|
HMONITOR hmonitor = (HMONITOR)monitor.u64[0];
|
||||||
{
|
{
|
||||||
MONITORINFOEXW info;
|
MONITORINFOEXW info;
|
||||||
@@ -1130,7 +1219,7 @@ os_window_set_monitor(OS_Handle window_handle, OS_Handle monitor)
|
|||||||
internal void
|
internal void
|
||||||
os_window_clear_custom_border_data(OS_Handle handle)
|
os_window_clear_custom_border_data(OS_Handle handle)
|
||||||
{
|
{
|
||||||
W32_Window *window = w32_window_from_os_window(handle);
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
if(window->custom_border)
|
if(window->custom_border)
|
||||||
{
|
{
|
||||||
arena_clear(window->paint_arena);
|
arena_clear(window->paint_arena);
|
||||||
@@ -1143,24 +1232,24 @@ os_window_clear_custom_border_data(OS_Handle handle)
|
|||||||
internal void
|
internal void
|
||||||
os_window_push_custom_title_bar(OS_Handle handle, F32 thickness)
|
os_window_push_custom_title_bar(OS_Handle handle, F32 thickness)
|
||||||
{
|
{
|
||||||
W32_Window *window = w32_window_from_os_window(handle);
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
window->custom_border_title_thickness = thickness;
|
window->custom_border_title_thickness = thickness;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
os_window_push_custom_edges(OS_Handle handle, F32 thickness)
|
os_window_push_custom_edges(OS_Handle handle, F32 thickness)
|
||||||
{
|
{
|
||||||
W32_Window *window = w32_window_from_os_window(handle);
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
window->custom_border_edge_thickness = thickness;
|
window->custom_border_edge_thickness = thickness;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
os_window_push_custom_title_bar_client_area(OS_Handle handle, Rng2F32 rect)
|
os_window_push_custom_title_bar_client_area(OS_Handle handle, Rng2F32 rect)
|
||||||
{
|
{
|
||||||
W32_Window *window = w32_window_from_os_window(handle);
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
if(window->custom_border)
|
if(window->custom_border)
|
||||||
{
|
{
|
||||||
W32_TitleBarClientArea *area = push_array(window->paint_arena, W32_TitleBarClientArea, 1);
|
OS_W32_TitleBarClientArea *area = push_array(window->paint_arena, OS_W32_TitleBarClientArea, 1);
|
||||||
if(area != 0)
|
if(area != 0)
|
||||||
{
|
{
|
||||||
area->rect = rect;
|
area->rect = rect;
|
||||||
@@ -1173,12 +1262,12 @@ internal Rng2F32
|
|||||||
os_rect_from_window(OS_Handle handle)
|
os_rect_from_window(OS_Handle handle)
|
||||||
{
|
{
|
||||||
Rng2F32 r = {0};
|
Rng2F32 r = {0};
|
||||||
W32_Window *window = w32_window_from_os_window(handle);
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
if(window)
|
if(window)
|
||||||
{
|
{
|
||||||
RECT rect = {0};
|
RECT rect = {0};
|
||||||
GetWindowRect(w32_hwnd_from_window(window), &rect);
|
GetWindowRect(os_w32_hwnd_from_window(window), &rect);
|
||||||
r = w32_base_rect_from_win32_rect(rect);
|
r = os_w32_rng2f32_from_rect(rect);
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@@ -1187,12 +1276,12 @@ internal Rng2F32
|
|||||||
os_client_rect_from_window(OS_Handle handle)
|
os_client_rect_from_window(OS_Handle handle)
|
||||||
{
|
{
|
||||||
Rng2F32 r = {0};
|
Rng2F32 r = {0};
|
||||||
W32_Window *window = w32_window_from_os_window(handle);
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
if(window)
|
if(window)
|
||||||
{
|
{
|
||||||
RECT rect = {0};
|
RECT rect = {0};
|
||||||
GetClientRect(w32_hwnd_from_window(window), &rect);
|
GetClientRect(os_w32_hwnd_from_window(window), &rect);
|
||||||
r = w32_base_rect_from_win32_rect(rect);
|
r = os_w32_rng2f32_from_rect(rect);
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@@ -1201,7 +1290,7 @@ internal F32
|
|||||||
os_dpi_from_window(OS_Handle handle)
|
os_dpi_from_window(OS_Handle handle)
|
||||||
{
|
{
|
||||||
F32 result = 96.f;
|
F32 result = 96.f;
|
||||||
W32_Window *window = w32_window_from_os_window(handle);
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
if(window != 0)
|
if(window != 0)
|
||||||
{
|
{
|
||||||
result = window->dpi;
|
result = window->dpi;
|
||||||
@@ -1218,8 +1307,8 @@ os_push_monitors_array(Arena *arena)
|
|||||||
Temp scratch = scratch_begin(&arena, 1);
|
Temp scratch = scratch_begin(&arena, 1);
|
||||||
OS_HandleList list = {0};
|
OS_HandleList list = {0};
|
||||||
{
|
{
|
||||||
W32_MonitorGatherBundle bundle = {arena, &list};
|
OS_W32_MonitorGatherBundle bundle = {arena, &list};
|
||||||
EnumDisplayMonitors(0, 0, w32_monitor_gather_enum_proc, (LPARAM)&bundle);
|
EnumDisplayMonitors(0, 0, os_w32_monitor_gather_enum_proc, (LPARAM)&bundle);
|
||||||
}
|
}
|
||||||
OS_HandleArray array = os_handle_array_from_list(arena, &list);
|
OS_HandleArray array = os_handle_array_from_list(arena, &list);
|
||||||
scratch_end(scratch);
|
scratch_end(scratch);
|
||||||
@@ -1238,7 +1327,7 @@ os_primary_monitor(void)
|
|||||||
internal OS_Handle
|
internal OS_Handle
|
||||||
os_monitor_from_window(OS_Handle window)
|
os_monitor_from_window(OS_Handle window)
|
||||||
{
|
{
|
||||||
W32_Window *w = w32_window_from_os_window(window);
|
OS_W32_Window *w = os_w32_window_from_handle(window);
|
||||||
HMONITOR handle = MonitorFromWindow(w->hwnd, MONITOR_DEFAULTTOPRIMARY);
|
HMONITOR handle = MonitorFromWindow(w->hwnd, MONITOR_DEFAULTTOPRIMARY);
|
||||||
OS_Handle result = {(U64)handle};
|
OS_Handle result = {(U64)handle};
|
||||||
return result;
|
return result;
|
||||||
@@ -1280,14 +1369,14 @@ os_dim_from_monitor(OS_Handle monitor)
|
|||||||
internal void
|
internal void
|
||||||
os_send_wakeup_event(void)
|
os_send_wakeup_event(void)
|
||||||
{
|
{
|
||||||
PostThreadMessageA(w32_gfx_thread_tid, 0x401, 0, 0);
|
PostThreadMessageA(os_w32_gfx_state->gfx_thread_tid, 0x401, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal OS_EventList
|
internal OS_EventList
|
||||||
os_get_events(Arena *arena, B32 wait)
|
os_get_events(Arena *arena, B32 wait)
|
||||||
{
|
{
|
||||||
w32_event_arena = arena;
|
os_w32_event_arena = arena;
|
||||||
MemoryZeroStruct(&w32_event_list);
|
MemoryZeroStruct(&os_w32_event_list);
|
||||||
MSG msg = {0};
|
MSG msg = {0};
|
||||||
if(!wait || GetMessage(&msg, 0, 0, 0))
|
if(!wait || GetMessage(&msg, 0, 0, 0))
|
||||||
{
|
{
|
||||||
@@ -1298,11 +1387,11 @@ os_get_events(Arena *arena, B32 wait)
|
|||||||
TranslateMessage(&msg);
|
TranslateMessage(&msg);
|
||||||
if(msg.message == WM_QUIT)
|
if(msg.message == WM_QUIT)
|
||||||
{
|
{
|
||||||
w32_push_event(OS_EventKind_WindowClose, 0);
|
os_w32_push_event(OS_EventKind_WindowClose, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return w32_event_list;
|
return os_w32_event_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal OS_EventFlags
|
internal OS_EventFlags
|
||||||
@@ -1329,7 +1418,7 @@ os_key_is_down(OS_Key key)
|
|||||||
{
|
{
|
||||||
B32 result = 0;
|
B32 result = 0;
|
||||||
{
|
{
|
||||||
WPARAM vkey_code = w32_vkey_from_os_key(key);
|
WPARAM vkey_code = os_w32_vkey_from_os_key(key);
|
||||||
SHORT state = GetAsyncKeyState(vkey_code);
|
SHORT state = GetAsyncKeyState(vkey_code);
|
||||||
result = !!(state & (0x8000));
|
result = !!(state & (0x8000));
|
||||||
}
|
}
|
||||||
@@ -1344,7 +1433,7 @@ os_mouse_from_window(OS_Handle handle)
|
|||||||
POINT p;
|
POINT p;
|
||||||
if(GetCursorPos(&p))
|
if(GetCursorPos(&p))
|
||||||
{
|
{
|
||||||
W32_Window *window = w32_window_from_os_window(handle);
|
OS_W32_Window *window = os_w32_window_from_handle(handle);
|
||||||
ScreenToClient(window->hwnd, &p);
|
ScreenToClient(window->hwnd, &p);
|
||||||
v.x = (F32)p.x;
|
v.x = (F32)p.x;
|
||||||
v.y = (F32)p.y;
|
v.y = (F32)p.y;
|
||||||
@@ -1360,7 +1449,6 @@ internal void
|
|||||||
os_set_cursor(OS_Cursor cursor)
|
os_set_cursor(OS_Cursor cursor)
|
||||||
{
|
{
|
||||||
B32 valid_cursor = 1;
|
B32 valid_cursor = 1;
|
||||||
|
|
||||||
HCURSOR hcursor = 0;
|
HCURSOR hcursor = 0;
|
||||||
switch(cursor)
|
switch(cursor)
|
||||||
{
|
{
|
||||||
@@ -1383,43 +1471,19 @@ hcursor = curs; }break;
|
|||||||
#undef CursorCase
|
#undef CursorCase
|
||||||
#undef Win32CursorXList
|
#undef Win32CursorXList
|
||||||
}
|
}
|
||||||
|
if(valid_cursor && !os_w32_resizing)
|
||||||
if(valid_cursor && !w32_resizing)
|
|
||||||
{
|
{
|
||||||
if(hcursor != w32_hcursor)
|
if(hcursor != os_w32_gfx_state->hCursor)
|
||||||
{
|
{
|
||||||
PostMessage(0, WM_SETCURSOR, 0, 0);
|
PostMessage(0, WM_SETCURSOR, 0, 0);
|
||||||
POINT p = {0};
|
POINT p = {0};
|
||||||
GetCursorPos(&p);
|
GetCursorPos(&p);
|
||||||
SetCursorPos(p.x, p.y);
|
SetCursorPos(p.x, p.y);
|
||||||
}
|
}
|
||||||
w32_hcursor = hcursor;
|
os_w32_gfx_state->hCursor = hcursor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ rjf: @os_hooks System Properties (Implemented Per-OS)
|
|
||||||
|
|
||||||
internal F32
|
|
||||||
os_double_click_time(void)
|
|
||||||
{
|
|
||||||
UINT time_milliseconds = GetDoubleClickTime();
|
|
||||||
return time_milliseconds / 1000.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal F32
|
|
||||||
os_caret_blink_time(void)
|
|
||||||
{
|
|
||||||
UINT time_milliseconds = GetCaretBlinkTime();
|
|
||||||
return time_milliseconds / 1000.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal F32
|
|
||||||
os_default_refresh_rate(void)
|
|
||||||
{
|
|
||||||
return w32_default_refresh_rate;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: @os_hooks Native User-Facing Graphical Messages (Implemented Per-OS)
|
//~ rjf: @os_hooks Native User-Facing Graphical Messages (Implemented Per-OS)
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
// Copyright (c) 2024 Epic Games Tools
|
// Copyright (c) 2024 Epic Games Tools
|
||||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||||
|
|
||||||
#ifndef WIN32_GRAPHICAL_H
|
#ifndef OS_GFX_WIN32_H
|
||||||
#define WIN32_GRAPHICAL_H
|
#define OS_GFX_WIN32_H
|
||||||
|
|
||||||
#pragma comment(lib, "user32")
|
////////////////////////////////
|
||||||
|
//~ rjf: Includes / Libraries
|
||||||
|
|
||||||
|
#include <uxtheme.h>
|
||||||
|
#include <dwmapi.h>
|
||||||
|
#include <shellscalingapi.h>
|
||||||
#pragma comment(lib, "gdi32")
|
#pragma comment(lib, "gdi32")
|
||||||
|
#pragma comment(lib, "dwmapi")
|
||||||
|
#pragma comment(lib, "UxTheme")
|
||||||
|
#pragma comment(lib, "ole32")
|
||||||
|
#pragma comment(lib, "user32")
|
||||||
#ifndef WM_NCUAHDRAWCAPTION
|
#ifndef WM_NCUAHDRAWCAPTION
|
||||||
#define WM_NCUAHDRAWCAPTION (0x00AE)
|
#define WM_NCUAHDRAWCAPTION (0x00AE)
|
||||||
#endif
|
#endif
|
||||||
@@ -17,18 +25,18 @@
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Windows
|
//~ rjf: Windows
|
||||||
|
|
||||||
typedef struct W32_TitleBarClientArea W32_TitleBarClientArea;
|
typedef struct OS_W32_TitleBarClientArea OS_W32_TitleBarClientArea;
|
||||||
struct W32_TitleBarClientArea
|
struct OS_W32_TitleBarClientArea
|
||||||
{
|
{
|
||||||
W32_TitleBarClientArea *next;
|
OS_W32_TitleBarClientArea *next;
|
||||||
Rng2F32 rect;
|
Rng2F32 rect;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct W32_Window W32_Window;
|
typedef struct OS_W32_Window OS_W32_Window;
|
||||||
struct W32_Window
|
struct OS_W32_Window
|
||||||
{
|
{
|
||||||
W32_Window *next;
|
OS_W32_Window *next;
|
||||||
W32_Window *prev;
|
OS_W32_Window *prev;
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
WINDOWPLACEMENT last_window_placement;
|
WINDOWPLACEMENT last_window_placement;
|
||||||
OS_WindowRepaintFunctionType *repaint;
|
OS_WindowRepaintFunctionType *repaint;
|
||||||
@@ -41,42 +49,67 @@ struct W32_Window
|
|||||||
F32 custom_border_edge_thickness;
|
F32 custom_border_edge_thickness;
|
||||||
B32 custom_border_composition_enabled;
|
B32 custom_border_composition_enabled;
|
||||||
Arena *paint_arena;
|
Arena *paint_arena;
|
||||||
W32_TitleBarClientArea *first_title_bar_client_area;
|
OS_W32_TitleBarClientArea *first_title_bar_client_area;
|
||||||
W32_TitleBarClientArea *last_title_bar_client_area;
|
OS_W32_TitleBarClientArea *last_title_bar_client_area;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Monitor Gathering Bundle
|
//~ rjf: Monitor Gathering Bundle
|
||||||
|
|
||||||
typedef struct W32_MonitorGatherBundle W32_MonitorGatherBundle;
|
typedef struct OS_W32_MonitorGatherBundle OS_W32_MonitorGatherBundle;
|
||||||
struct W32_MonitorGatherBundle
|
struct OS_W32_MonitorGatherBundle
|
||||||
{
|
{
|
||||||
Arena *arena;
|
Arena *arena;
|
||||||
OS_HandleList *list;
|
OS_HandleList *list;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ rjf: Global State
|
||||||
|
|
||||||
|
typedef struct OS_W32_GfxState OS_W32_GfxState;
|
||||||
|
struct OS_W32_GfxState
|
||||||
|
{
|
||||||
|
Arena *arena;
|
||||||
|
U32 gfx_thread_tid;
|
||||||
|
HINSTANCE hInstance;
|
||||||
|
HCURSOR hCursor;
|
||||||
|
OS_GfxInfo gfx_info;
|
||||||
|
OS_W32_Window *first_window;
|
||||||
|
OS_W32_Window *last_window;
|
||||||
|
OS_W32_Window *free_window;
|
||||||
|
OS_Key key_from_vkey_table[256];
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ rjf: Globals
|
||||||
|
|
||||||
|
global OS_W32_GfxState *os_w32_gfx_state = 0;
|
||||||
|
global OS_EventList os_w32_event_list = {0};
|
||||||
|
global Arena *os_w32_event_arena = 0;
|
||||||
|
B32 os_w32_resizing = 0;
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Basic Helpers
|
//~ rjf: Basic Helpers
|
||||||
|
|
||||||
internal Rng2F32 w32_base_rect_from_win32_rect(RECT rect);
|
internal Rng2F32 os_w32_rng2f32_from_rect(RECT rect);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Windows
|
//~ rjf: Windows
|
||||||
|
|
||||||
internal OS_Handle os_window_from_w32_window(W32_Window *window);
|
internal OS_Handle os_w32_handle_from_window(OS_W32_Window *window);
|
||||||
internal W32_Window * w32_window_from_os_window(OS_Handle window);
|
internal OS_W32_Window * os_w32_window_from_handle(OS_Handle window);
|
||||||
internal W32_Window * w32_window_from_hwnd(HWND hwnd);
|
internal OS_W32_Window * os_w32_window_from_hwnd(HWND hwnd);
|
||||||
internal HWND w32_hwnd_from_window(W32_Window *window);
|
internal HWND os_w32_hwnd_from_window(OS_W32_Window *window);
|
||||||
internal W32_Window * w32_allocate_window(void);
|
internal OS_W32_Window * os_w32_window_alloc(void);
|
||||||
internal void w32_free_window(W32_Window *window);
|
internal void os_w32_window_release(OS_W32_Window *window);
|
||||||
internal OS_Event * w32_push_event(OS_EventKind kind, W32_Window *window);
|
internal OS_Event * os_w32_push_event(OS_EventKind kind, OS_W32_Window *window);
|
||||||
internal OS_Key w32_os_key_from_vkey(WPARAM vkey);
|
internal OS_Key os_w32_os_key_from_vkey(WPARAM vkey);
|
||||||
internal WPARAM w32_vkey_from_os_key(OS_Key key);
|
internal WPARAM os_w32_vkey_from_os_key(OS_Key key);
|
||||||
internal LRESULT w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
internal LRESULT os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Monitors
|
//~ rjf: Monitors
|
||||||
|
|
||||||
internal BOOL w32_monitor_gather_enum_proc(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM bundle_ptr);
|
internal BOOL os_w32_monitor_gather_enum_proc(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM bundle_ptr);
|
||||||
|
|
||||||
#endif // WIN32_GRAPHICAL_H
|
#endif // OS_GFX_WIN32_H
|
||||||
|
|||||||
+15
-21
@@ -1,33 +1,27 @@
|
|||||||
// Copyright (c) 2024 Epic Games Tools
|
// Copyright (c) 2024 Epic Games Tools
|
||||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||||
|
|
||||||
////////////////////////////////
|
#include "os/core/os_core.c"
|
||||||
// NOTE(allen): Include OS features for extra features and target OS
|
|
||||||
|
|
||||||
#include "core/os_core.c"
|
|
||||||
|
|
||||||
#if OS_FEATURE_SOCKET
|
|
||||||
#include "socket/os_socket.c"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if OS_FEATURE_GRAPHICAL
|
#if OS_FEATURE_GRAPHICAL
|
||||||
#include "gfx/os_gfx.c"
|
# include "os/gfx/os_gfx.c"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if OS_WINDOWS
|
#if OS_WINDOWS
|
||||||
# include "core/win32/os_core_win32.c"
|
# include "os/core/win32/os_core_win32.c"
|
||||||
# if OS_FEATURE_SOCKET
|
|
||||||
# include "socket/win32/os_socket_win32.c"
|
|
||||||
# endif
|
|
||||||
# if OS_FEATURE_GRAPHICAL && !OS_GFX_STUB
|
|
||||||
# include "gfx/win32/os_gfx_win32.c"
|
|
||||||
# endif
|
|
||||||
#elif OS_LINUX
|
#elif OS_LINUX
|
||||||
# include "core/linux/os_core_linux.c"
|
# include "os/core/linux/os_core_linux.c"
|
||||||
#else
|
#else
|
||||||
# error no OS layer setup
|
# error OS core layer not implemented for this operating system.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if OS_GFX_STUB
|
#if OS_FEATURE_GRAPHICAL
|
||||||
#include "gfx/stub/os_gfx_stub.c"
|
# if OS_GFX_STUB
|
||||||
|
# include "os/gfx/stub/os_gfx_stub.c"
|
||||||
|
# elif OS_WINDOWS
|
||||||
|
# include "os/gfx/win32/os_gfx_win32.c"
|
||||||
|
# elif OS_LINUX
|
||||||
|
# include "os/gfx/linux/os_gfx_linux.c"
|
||||||
|
# else
|
||||||
|
# error OS graphical layer not implemented for this operating system.
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+16
-23
@@ -4,10 +4,6 @@
|
|||||||
#ifndef OS_INC_H
|
#ifndef OS_INC_H
|
||||||
#define OS_INC_H
|
#define OS_INC_H
|
||||||
|
|
||||||
#if !defined(OS_FEATURE_SOCKET)
|
|
||||||
# define OS_FEATURE_SOCKET 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(OS_FEATURE_GRAPHICAL)
|
#if !defined(OS_FEATURE_GRAPHICAL)
|
||||||
# define OS_FEATURE_GRAPHICAL 0
|
# define OS_FEATURE_GRAPHICAL 0
|
||||||
#endif
|
#endif
|
||||||
@@ -16,32 +12,29 @@
|
|||||||
# define OS_GFX_STUB 0
|
# define OS_GFX_STUB 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "core/os_core.h"
|
#include "os/core/os_core.h"
|
||||||
|
|
||||||
#if OS_FEATURE_SOCKET
|
|
||||||
#include "socket/os_socket.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if OS_FEATURE_GRAPHICAL
|
#if OS_FEATURE_GRAPHICAL
|
||||||
#include "gfx/os_gfx.h"
|
# include "os/gfx/os_gfx.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if OS_WINDOWS
|
#if OS_WINDOWS
|
||||||
# include "core/win32/os_core_win32.h"
|
# include "os/core/win32/os_core_win32.h"
|
||||||
# if OS_FEATURE_SOCKET
|
|
||||||
# include "socket/win32/os_socket_win32.h"
|
|
||||||
# endif
|
|
||||||
# if OS_FEATURE_GRAPHICAL && !OS_GFX_STUB
|
|
||||||
# include "gfx/win32/os_gfx_win32.h"
|
|
||||||
# endif
|
|
||||||
#elif OS_LINUX
|
#elif OS_LINUX
|
||||||
# include "core/linux/os_core_linux.h"
|
# include "os/core/linux/os_core_linux.h"
|
||||||
#else
|
#else
|
||||||
# error no OS layer setup
|
# error OS core layer not implemented for this operating system.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if OS_GFX_STUB
|
#if OS_FEATURE_GRAPHICAL
|
||||||
#include "gfx/stub/os_gfx_stub.h"
|
# if OS_GFX_STUB
|
||||||
|
# include "os/gfx/stub/os_gfx_stub.h"
|
||||||
|
# elif OS_WINDOWS
|
||||||
|
# include "os/gfx/win32/os_gfx_win32.h"
|
||||||
|
# elif OS_LINUX
|
||||||
|
# include "os/gfx/linux/os_gfx_linux.h"
|
||||||
|
# else
|
||||||
|
# error OS graphical layer not implemented for this operating system.
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif //OS_SWITCH_H
|
#endif // OS_INC_H
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
// Copyright (c) 2024 Epic Games Tools
|
|
||||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
// NOTE(allen): Helper
|
|
||||||
|
|
||||||
internal B32
|
|
||||||
os_socket_write(OS_Socket *socket, String8 data){
|
|
||||||
String8Node node = {0};
|
|
||||||
String8List list = {0};
|
|
||||||
str8_list_push(&list, &node, data);
|
|
||||||
B32 result = os_socket_write(socket, list);
|
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
// Copyright (c) 2024 Epic Games Tools
|
|
||||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
|
||||||
|
|
||||||
#ifndef OS_SOCKET_H
|
|
||||||
#define OS_SOCKET_H
|
|
||||||
|
|
||||||
enum OS_SocketStatus{
|
|
||||||
OS_SocketStatus_Uninitialized,
|
|
||||||
OS_SocketStatus_Connected,
|
|
||||||
OS_SocketStatus_GracefullyClosed,
|
|
||||||
OS_SocketStatus_Error,
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef U16 OS_SocketError;
|
|
||||||
enum{
|
|
||||||
OS_SocketError_None,
|
|
||||||
OS_SocketError_SocketSystemNotInitialized,
|
|
||||||
OS_SocketError_BadPortArgument,
|
|
||||||
OS_SocketError_BadIPArgument,
|
|
||||||
OS_SocketError_WSAError,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct OS_Socket{
|
|
||||||
U8 memory[32];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ NOTE(allen): Implemented Per Operating System
|
|
||||||
|
|
||||||
internal void os_socket_init(void);
|
|
||||||
|
|
||||||
internal void os_socket_listen(OS_Socket *socket, String8 port);
|
|
||||||
internal void os_socket_connect(OS_Socket *socket, String8 ip, String8 port);
|
|
||||||
internal void os_socket_close(OS_Socket *socket);
|
|
||||||
|
|
||||||
internal String8 os_socket_read(Arena *arena, OS_Socket *socket);
|
|
||||||
internal B32 os_socket_write(OS_Socket *socket, String8List list);
|
|
||||||
|
|
||||||
internal B32 os_socket_status(OS_Socket *socket, OS_SocketStatus status);
|
|
||||||
internal String8 os_socket_error_string(Arena *arena, OS_Socket *socket);
|
|
||||||
internal void os_socket_assert_on_error(OS_Socket *socket, B32 assert_on_error);
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ NOTE(allen): Helpers - Portable Implementation
|
|
||||||
|
|
||||||
internal B32 os_socket_write(OS_Socket *socket, String8 data);
|
|
||||||
|
|
||||||
#endif //OS_SOCKET_H
|
|
||||||
@@ -1,353 +0,0 @@
|
|||||||
// Copyright (c) 2024 Epic Games Tools
|
|
||||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ rjf: Helpers
|
|
||||||
|
|
||||||
internal void
|
|
||||||
w32_socket_set_error(W32_Socket *socket, OS_SocketError error){
|
|
||||||
socket->error = error;
|
|
||||||
// NOTE(allen): This flag was set earlier so that the socket would assert
|
|
||||||
// when an error occurs. The "bug" or issue is whatever caused this error
|
|
||||||
// not the fact the flag is set. Unless the flag wasn't supposed to be set!
|
|
||||||
Assert(!(socket->flags & W32_SocketFlag_AssertOnError));
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
|
||||||
w32_socket_set_error_wsa(W32_Socket *socket, int wsa_error){
|
|
||||||
switch (wsa_error){
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
socket->wsa_error = wsa_error;
|
|
||||||
w32_socket_set_error(socket, OS_SocketError_WSAError);
|
|
||||||
}break;
|
|
||||||
case WSANOTINITIALISED:
|
|
||||||
{
|
|
||||||
w32_socket_set_error(socket, OS_SocketError_SocketSystemNotInitialized);
|
|
||||||
}break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal B32
|
|
||||||
w32_socket_read_looped(W32_Socket *w32_socket, void *buffer, U32 size){
|
|
||||||
U32 p = 0;
|
|
||||||
CHAR *ptr = (CHAR*)buffer;
|
|
||||||
for (;p < size;){
|
|
||||||
DWORD amt = (DWORD)(size - p);
|
|
||||||
WSABUF wsabuf = {amt, ptr};
|
|
||||||
// NOTE(allen): The flags pointer is _NOT_ optional but we can ignore it.
|
|
||||||
// We have to zero it because it's an in/out pointer.
|
|
||||||
DWORD ignore = 0;
|
|
||||||
if (WSARecv(w32_socket->socket, &wsabuf, 1, &amt, &ignore, 0, 0) != 0){
|
|
||||||
w32_socket_set_error_wsa(w32_socket, WSAGetLastError());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (amt == 0){
|
|
||||||
w32_socket->flags |= W32_SocketFlag_Closed;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
p += amt;
|
|
||||||
ptr += amt;
|
|
||||||
}
|
|
||||||
B32 result = (p == size);
|
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ rjf: Per-OS Hook Implementations
|
|
||||||
|
|
||||||
internal void
|
|
||||||
os_socket_init(void){
|
|
||||||
WSADATA wsaData;
|
|
||||||
WORD vreq = MAKEWORD(2,2);
|
|
||||||
WSAStartup(vreq, &wsaData);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
|
||||||
os_socket_listen(OS_Socket *s, String8 port){
|
|
||||||
W32_Socket *w32_socket = (W32_Socket*)s->memory;
|
|
||||||
|
|
||||||
// NOTE(allen): check port string
|
|
||||||
char port_buffer[6];
|
|
||||||
if (port.size == 0 || port.size >= sizeof(port_buffer)){
|
|
||||||
w32_socket_set_error(w32_socket, OS_SocketError_BadPortArgument);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MemoryCopy(port_buffer, port.str, port.size);
|
|
||||||
port_buffer[port.size] = 0;
|
|
||||||
|
|
||||||
// NOTE(allen): listen socket addrinfo
|
|
||||||
addrinfo listen_hint = {0};
|
|
||||||
listen_hint.ai_flags = AI_PASSIVE|AI_NUMERICSERV;
|
|
||||||
listen_hint.ai_family = AF_UNSPEC;
|
|
||||||
listen_hint.ai_socktype = SOCK_STREAM;
|
|
||||||
listen_hint.ai_protocol = AF_UNSPEC;
|
|
||||||
|
|
||||||
addrinfo *addr = {0};
|
|
||||||
INT error = getaddrinfo(0, port_buffer, &listen_hint, &addr);
|
|
||||||
if (error != 0){
|
|
||||||
w32_socket_set_error_wsa(w32_socket, WSAGetLastError());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE(allen): init listen socket
|
|
||||||
SOCKET socket_listener = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
|
|
||||||
W32_SocketCloser listener_closer(&socket_listener);
|
|
||||||
|
|
||||||
// NOTE(allen): reuseraddr
|
|
||||||
{
|
|
||||||
union { B32 b; char c[1]; } enable;
|
|
||||||
enable.b = true;
|
|
||||||
if (setsockopt(socket_listener, SOL_SOCKET, SO_REUSEADDR, enable.c, sizeof(enable)) < 0){
|
|
||||||
w32_socket_set_error_wsa(w32_socket, WSAGetLastError());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE(allen): bind
|
|
||||||
if (bind(socket_listener, addr->ai_addr, (int)addr->ai_addrlen) < 0){
|
|
||||||
w32_socket_set_error_wsa(w32_socket, WSAGetLastError());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE(allen): listen
|
|
||||||
if (listen(socket_listener, 1) < 0){
|
|
||||||
w32_socket_set_error_wsa(w32_socket, WSAGetLastError());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE(allen): accept
|
|
||||||
SOCKET client_socket = accept(socket_listener, 0, 0);
|
|
||||||
W32_SocketCloser client_closer(&client_socket);
|
|
||||||
|
|
||||||
// NOTE(allen): TCP_NODELAY
|
|
||||||
{
|
|
||||||
union { B32 b; char c[1]; } enable;
|
|
||||||
enable.b = true;
|
|
||||||
if (setsockopt(client_socket, IPPROTO_TCP, TCP_NODELAY, enable.c, sizeof(enable)) < 0){
|
|
||||||
w32_socket_set_error_wsa(w32_socket, WSAGetLastError());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE(allen): success
|
|
||||||
w32_socket->flags |= W32_SocketFlag_Connected;
|
|
||||||
w32_socket->socket = client_socket;
|
|
||||||
w32_socket->error = OS_SocketError_None;
|
|
||||||
client_closer.do_not_close();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
|
||||||
os_socket_connect(OS_Socket *s, String8 ip, String8 port){
|
|
||||||
W32_Socket *w32_socket = (W32_Socket*)s->memory;
|
|
||||||
|
|
||||||
// NOTE(allen): check port string
|
|
||||||
char port_buffer[6];
|
|
||||||
if (port.size == 0 || port.size >= sizeof(port_buffer)){
|
|
||||||
w32_socket_set_error(w32_socket, OS_SocketError_BadPortArgument);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MemoryCopy(port_buffer, port.str, port.size);
|
|
||||||
port_buffer[port.size] = 0;
|
|
||||||
|
|
||||||
// NOTE(allen): check ip string
|
|
||||||
if (ip.size == 0){
|
|
||||||
ip = str8_lit("localhost");
|
|
||||||
}
|
|
||||||
char ip_buffer[KB(1)];
|
|
||||||
if (ip.size >= sizeof(ip_buffer)){
|
|
||||||
w32_socket_set_error(w32_socket, OS_SocketError_BadIPArgument);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MemoryCopy(ip_buffer, ip.str, ip.size);
|
|
||||||
ip_buffer[ip.size] = 0;
|
|
||||||
|
|
||||||
// NOTE(allen): socket addrinfo
|
|
||||||
addrinfo hint = {0};
|
|
||||||
hint.ai_flags = AI_PASSIVE|AI_NUMERICSERV;
|
|
||||||
hint.ai_family = AF_UNSPEC;
|
|
||||||
hint.ai_socktype = SOCK_STREAM;
|
|
||||||
hint.ai_protocol = AF_UNSPEC;
|
|
||||||
|
|
||||||
addrinfo *addr = {0};
|
|
||||||
INT error = getaddrinfo(ip_buffer, port_buffer, &hint, &addr);
|
|
||||||
if (error != 0){
|
|
||||||
w32_socket_set_error_wsa(w32_socket, WSAGetLastError());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE(allen): init socket
|
|
||||||
SOCKET socket_server = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
|
|
||||||
W32_SocketCloser closer(&socket_server);
|
|
||||||
|
|
||||||
// NOTE(allen): TCP_NODELAY
|
|
||||||
{
|
|
||||||
union { B32 b; char c[1]; } enable;
|
|
||||||
enable.b = true;
|
|
||||||
if (setsockopt(socket_server, IPPROTO_TCP, TCP_NODELAY, enable.c, sizeof(enable)) < 0){
|
|
||||||
w32_socket_set_error_wsa(w32_socket, WSAGetLastError());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE(allen): connect
|
|
||||||
if (connect(socket_server, addr->ai_addr, (int)addr->ai_addrlen) < 0){
|
|
||||||
w32_socket_set_error_wsa(w32_socket, WSAGetLastError());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE(allen): success
|
|
||||||
w32_socket->flags |= W32_SocketFlag_Connected;
|
|
||||||
w32_socket->socket = socket_server;
|
|
||||||
w32_socket->error = OS_SocketError_None;
|
|
||||||
closer.do_not_close();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
|
||||||
os_socket_close(OS_Socket *socket){
|
|
||||||
W32_Socket *w32_socket = (W32_Socket*)socket->memory;
|
|
||||||
closesocket(w32_socket->socket);
|
|
||||||
MemoryZeroStruct(w32_socket);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal String8
|
|
||||||
os_socket_read(Arena *arena, OS_Socket *socket){
|
|
||||||
W32_Socket *w32_socket = (W32_Socket*)socket->memory;
|
|
||||||
String8 result = {0};
|
|
||||||
U32 size = 0;
|
|
||||||
if (w32_socket_read_looped(w32_socket, &size, sizeof(size))){
|
|
||||||
Temp restore = temp_begin(arena);
|
|
||||||
result.str = push_array_no_zero(arena, U8, size);
|
|
||||||
if (w32_socket_read_looped(w32_socket, result.str, size)){
|
|
||||||
result.size = size;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
temp_end(restore);
|
|
||||||
result.str = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal B32
|
|
||||||
os_socket_write(OS_Socket *socket, String8List list){
|
|
||||||
U32 size = (U32)list.total_size;
|
|
||||||
String8Node node = {0};
|
|
||||||
str8_list_push_front(&list, &node, str8_struct(&size));
|
|
||||||
|
|
||||||
W32_Socket *w32_socket = (W32_Socket*)socket->memory;
|
|
||||||
|
|
||||||
WSABUF wsabuf[64];
|
|
||||||
Assert(list.node_count <= ArrayCount(wsabuf));
|
|
||||||
|
|
||||||
U64 wsabuf_count = 0;
|
|
||||||
for (String8Node *node = list.first;
|
|
||||||
node != 0;
|
|
||||||
node = node->next){
|
|
||||||
wsabuf[wsabuf_count].len = (U32)node->string.size;
|
|
||||||
wsabuf[wsabuf_count].buf = (CHAR*)node->string.str;
|
|
||||||
wsabuf_count += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
B32 result = false;
|
|
||||||
DWORD amt = 0;
|
|
||||||
if (WSASend(w32_socket->socket, wsabuf, wsabuf_count, &amt, 0, 0, 0) != 0){
|
|
||||||
w32_socket_set_error_wsa(w32_socket, WSAGetLastError());
|
|
||||||
}
|
|
||||||
else if (amt == 0){
|
|
||||||
w32_socket->flags |= W32_SocketFlag_Connected;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal B32
|
|
||||||
os_socket_status(OS_Socket *socket, OS_SocketStatus status){
|
|
||||||
W32_Socket *w32_socket = (W32_Socket*)socket;
|
|
||||||
B32 result = false;
|
|
||||||
switch (status){
|
|
||||||
case OS_SocketStatus_Uninitialized:
|
|
||||||
{
|
|
||||||
result = (((w32_socket->flags & (W32_SocketFlag_Connected|W32_SocketFlag_Closed)) == 0) &&
|
|
||||||
(w32_socket->error == 0));
|
|
||||||
}break;
|
|
||||||
|
|
||||||
case OS_SocketStatus_Connected:
|
|
||||||
{
|
|
||||||
result = (((w32_socket->flags & (W32_SocketFlag_Connected|W32_SocketFlag_Closed)) == W32_SocketFlag_Connected) &&
|
|
||||||
(w32_socket->error == 0));
|
|
||||||
}break;
|
|
||||||
|
|
||||||
case OS_SocketStatus_GracefullyClosed:
|
|
||||||
{
|
|
||||||
result = (((w32_socket->flags & W32_SocketFlag_Closed) == W32_SocketFlag_Closed) && (w32_socket->error == 0));
|
|
||||||
}break;
|
|
||||||
|
|
||||||
case OS_SocketStatus_Error:
|
|
||||||
{
|
|
||||||
result = (w32_socket->error != 0);
|
|
||||||
}break;
|
|
||||||
}
|
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal String8
|
|
||||||
os_socket_error_string(Arena *arena, OS_Socket *socket){
|
|
||||||
String8 result = str8_lit("no error");
|
|
||||||
|
|
||||||
W32_Socket *w32_socket = (W32_Socket*)socket;
|
|
||||||
switch (w32_socket->error){
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
result = str8_lit("Bad error code");
|
|
||||||
}break;
|
|
||||||
|
|
||||||
case OS_SocketError_None:break;
|
|
||||||
|
|
||||||
case OS_SocketError_SocketSystemNotInitialized:
|
|
||||||
{
|
|
||||||
result = str8_lit("Missing call to os_socket_init");
|
|
||||||
}break;
|
|
||||||
|
|
||||||
case OS_SocketError_BadPortArgument:
|
|
||||||
{
|
|
||||||
result = str8_lit("Invalid port argument to socket API");
|
|
||||||
}break;
|
|
||||||
|
|
||||||
case OS_SocketError_BadIPArgument:
|
|
||||||
{
|
|
||||||
result = str8_lit("Invalid ip argument to socket API");
|
|
||||||
}break;
|
|
||||||
|
|
||||||
case OS_SocketError_WSAError:
|
|
||||||
{
|
|
||||||
DWORD flags = FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM;
|
|
||||||
CHAR *message = 0;
|
|
||||||
DWORD size = FormatMessageA(flags, 0, w32_socket->wsa_error, 0, (CHAR*)&message, 0, 0);
|
|
||||||
if (size == 0){
|
|
||||||
result = str8_lit("Unknown WSA error");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
String8 string = str8_skip_chop_whitespace(str8((U8*)message, size));
|
|
||||||
result = push_str8_copy(arena, string);
|
|
||||||
LocalFree(message);
|
|
||||||
}
|
|
||||||
}break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
|
||||||
os_socket_assert_on_error(OS_Socket *socket, B32 assert_on_error){
|
|
||||||
W32_Socket *w32_socket = (W32_Socket*)socket;
|
|
||||||
if (assert_on_error){
|
|
||||||
w32_socket->flags |= W32_SocketFlag_AssertOnError;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
w32_socket->flags &= ~W32_SocketFlag_AssertOnError;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
// Copyright (c) 2024 Epic Games Tools
|
|
||||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
|
||||||
|
|
||||||
#ifndef WIN32_SOCKET_H
|
|
||||||
#define WIN32_SOCKET_H
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ rjf: Types
|
|
||||||
|
|
||||||
typedef U16 W32_SocketFlags;
|
|
||||||
enum{
|
|
||||||
W32_SocketFlag_Connected = (1 << 0),
|
|
||||||
W32_SocketFlag_Closed = (1 << 1),
|
|
||||||
W32_SocketFlag_AssertOnError = (1 << 2),
|
|
||||||
};
|
|
||||||
|
|
||||||
struct W32_Socket{
|
|
||||||
W32_SocketFlags flags;
|
|
||||||
OS_SocketError error;
|
|
||||||
int wsa_error;
|
|
||||||
SOCKET socket;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct W32_SocketCloser{
|
|
||||||
B32 need_to_close;
|
|
||||||
SOCKET *socket;
|
|
||||||
W32_SocketCloser(SOCKET *s){
|
|
||||||
this->need_to_close = true;
|
|
||||||
this->socket = s;
|
|
||||||
}
|
|
||||||
~W32_SocketCloser(){
|
|
||||||
this->close_now();
|
|
||||||
}
|
|
||||||
void close_now(){
|
|
||||||
if (this->need_to_close){
|
|
||||||
closesocket(*this->socket);
|
|
||||||
this->need_to_close = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void do_not_close(){
|
|
||||||
this->need_to_close = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
StaticAssert(sizeof(Member(OS_Socket, memory)) >= sizeof(W32_Socket), socket_memory_size);
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ rjf: Helpers
|
|
||||||
|
|
||||||
internal void w32_socket_set_error(W32_Socket *socket, OS_SocketError error);
|
|
||||||
internal void w32_socket_set_error_wsa(W32_Socket *socket, int wsa_error);
|
|
||||||
internal B32 w32_socket_read_looped(W32_Socket *w32_socket, void *buffer, U32 size);
|
|
||||||
|
|
||||||
#endif // WIN32_SOCKET_H
|
|
||||||
+1
-3
@@ -130,9 +130,7 @@ path_normalized_list_from_string(Arena *arena, String8 path_string, PathStyle *s
|
|||||||
// prepend current path to convert relative -> absolute
|
// prepend current path to convert relative -> absolute
|
||||||
PathStyle path_style_full = path_style;
|
PathStyle path_style_full = path_style;
|
||||||
if (path.node_count != 0 && path_style == PathStyle_Relative){
|
if (path.node_count != 0 && path_style == PathStyle_Relative){
|
||||||
String8List current_path_strs = {0};
|
String8 current_path_string = os_get_current_path(arena);
|
||||||
os_string_list_from_system_path(arena, OS_SystemPath_Current, ¤t_path_strs);
|
|
||||||
String8 current_path_string = str8_list_first(¤t_path_strs);
|
|
||||||
|
|
||||||
PathStyle current_path_style = path_style_from_str8(current_path_string);
|
PathStyle current_path_style = path_style_from_str8(current_path_string);
|
||||||
Assert(current_path_style != PathStyle_Relative);
|
Assert(current_path_style != PathStyle_Relative);
|
||||||
|
|||||||
+2
-3
@@ -537,8 +537,7 @@ pdb_gsi_from_data(Arena *arena, String8 data){
|
|||||||
U32 num_steps = prev_n - n;
|
U32 num_steps = prev_n - n;
|
||||||
|
|
||||||
// fill this bucket
|
// fill this bucket
|
||||||
arena_push_align(arena, 4);
|
U32 *bucket_offs = push_array_aligned(arena, U32, num_steps, 4);
|
||||||
U32 *bucket_offs = push_array_no_zero(arena, U32, num_steps);
|
|
||||||
for (U32 j = num_steps; j > 0;){
|
for (U32 j = num_steps; j > 0;){
|
||||||
j -= 1;
|
j -= 1;
|
||||||
// * The "- 1" is more sloppy PDB magic.
|
// * The "- 1" is more sloppy PDB magic.
|
||||||
@@ -947,7 +946,7 @@ pdb_tpi_itypes_from_name(Arena *arena, PDB_TpiHashParsed *tpi_hash, CV_LeafParse
|
|||||||
|
|
||||||
|
|
||||||
// assemble result
|
// assemble result
|
||||||
CV_TypeId *itypes = push_array(arena, CV_TypeId, count);
|
CV_TypeId *itypes = push_array_aligned(arena, CV_TypeId, count, 8);
|
||||||
{
|
{
|
||||||
CV_TypeId *itype_ptr = itypes;
|
CV_TypeId *itype_ptr = itypes;
|
||||||
for (struct Chain *node = first;
|
for (struct Chain *node = first;
|
||||||
|
|||||||
+2
-2
@@ -17,7 +17,7 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data)
|
|||||||
if(main_thread_log == 0)
|
if(main_thread_log == 0)
|
||||||
{
|
{
|
||||||
main_thread_log = log_alloc();
|
main_thread_log = log_alloc();
|
||||||
String8 user_program_data_path = os_string_from_system_path(scratch.arena, OS_SystemPath_UserProgramData);
|
String8 user_program_data_path = os_get_process_info()->user_program_data_path;
|
||||||
String8 user_data_folder = push_str8f(scratch.arena, "%S/raddbg/logs", user_program_data_path);
|
String8 user_data_folder = push_str8f(scratch.arena, "%S/raddbg/logs", user_program_data_path);
|
||||||
main_thread_log_path = push_str8f(df_state->arena, "%S/ui_thread.raddbg_log", user_data_folder);
|
main_thread_log_path = push_str8f(df_state->arena, "%S/ui_thread.raddbg_log", user_data_folder);
|
||||||
os_make_directory(user_data_folder);
|
os_make_directory(user_data_folder);
|
||||||
@@ -38,7 +38,7 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data)
|
|||||||
//- rjf: pick target hz
|
//- rjf: pick target hz
|
||||||
//
|
//
|
||||||
// TODO(rjf): maximize target, given all windows and their monitors
|
// TODO(rjf): maximize target, given all windows and their monitors
|
||||||
F32 target_hz = os_default_refresh_rate();
|
F32 target_hz = os_get_gfx_info()->default_refresh_rate;
|
||||||
if(frame_time_us_history_idx > 32)
|
if(frame_time_us_history_idx > 32)
|
||||||
{
|
{
|
||||||
// rjf: calculate average frame time out of the last N
|
// rjf: calculate average frame time out of the last N
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ entry_point(CmdLine *cmd_line)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// rjf: get current path
|
// rjf: get current path
|
||||||
String8 current_path = os_string_from_system_path(scratch.arena, OS_SystemPath_Current);
|
String8 current_path = os_get_current_path(scratch.arena);
|
||||||
|
|
||||||
// rjf: equip exe
|
// rjf: equip exe
|
||||||
if(args.first->string.size != 0)
|
if(args.first->string.size != 0)
|
||||||
@@ -295,7 +295,7 @@ entry_point(CmdLine *cmd_line)
|
|||||||
//- rjf: set up shared resources for ipc to this instance; launch IPC signaler thread
|
//- rjf: set up shared resources for ipc to this instance; launch IPC signaler thread
|
||||||
{
|
{
|
||||||
Temp scratch = scratch_begin(0, 0);
|
Temp scratch = scratch_begin(0, 0);
|
||||||
U32 instance_pid = os_get_pid();
|
U32 instance_pid = os_get_process_info()->pid;
|
||||||
String8 ipc_shared_memory_name = push_str8f(scratch.arena, "_raddbg_ipc_shared_memory_%i_", instance_pid);
|
String8 ipc_shared_memory_name = push_str8f(scratch.arena, "_raddbg_ipc_shared_memory_%i_", instance_pid);
|
||||||
String8 ipc_signal_semaphore_name = push_str8f(scratch.arena, "_raddbg_ipc_signal_semaphore_%i_", instance_pid);
|
String8 ipc_signal_semaphore_name = push_str8f(scratch.arena, "_raddbg_ipc_signal_semaphore_%i_", instance_pid);
|
||||||
String8 ipc_lock_semaphore_name = push_str8f(scratch.arena, "_raddbg_ipc_lock_semaphore_%i_", instance_pid);
|
String8 ipc_lock_semaphore_name = push_str8f(scratch.arena, "_raddbg_ipc_lock_semaphore_%i_", instance_pid);
|
||||||
@@ -307,7 +307,7 @@ entry_point(CmdLine *cmd_line)
|
|||||||
ipc_s2m_ring_cv = os_condition_variable_alloc();
|
ipc_s2m_ring_cv = os_condition_variable_alloc();
|
||||||
IPCInfo *ipc_info = (IPCInfo *)ipc_shared_memory_base;
|
IPCInfo *ipc_info = (IPCInfo *)ipc_shared_memory_base;
|
||||||
MemoryZeroStruct(ipc_info);
|
MemoryZeroStruct(ipc_info);
|
||||||
os_launch_thread(ipc_signaler_thread__entry_point, 0, 0);
|
os_thread_launch(ipc_signaler_thread__entry_point, 0, 0);
|
||||||
scratch_end(scratch);
|
scratch_end(scratch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,7 +446,7 @@ entry_point(CmdLine *cmd_line)
|
|||||||
//- rjf: no explicit PID? -> find PID to send message to, by looking for other raddbg instances
|
//- rjf: no explicit PID? -> find PID to send message to, by looking for other raddbg instances
|
||||||
if(dst_pid == 0)
|
if(dst_pid == 0)
|
||||||
{
|
{
|
||||||
U32 this_pid = os_get_pid();
|
U32 this_pid = os_get_process_info()->pid;
|
||||||
DMN_ProcessIter it = {0};
|
DMN_ProcessIter it = {0};
|
||||||
dmn_process_iter_begin(&it);
|
dmn_process_iter_begin(&it);
|
||||||
for(DMN_ProcessInfo info = {0}; dmn_process_iter_next(scratch.arena, &it, &info);)
|
for(DMN_ProcessInfo info = {0}; dmn_process_iter_next(scratch.arena, &it, &info);)
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ entry_point(CmdLine *cmdline)
|
|||||||
fprintf(stderr, "error(input): %.*s\n", str8_varg(n->string));
|
fprintf(stderr, "error(input): %.*s\n", str8_varg(n->string));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
os_exit_process(0);
|
os_abort(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- rjf: convert
|
//- rjf: convert
|
||||||
|
|||||||
@@ -2230,7 +2230,7 @@ internal TS_TASK_FUNCTION_DEF(p2r_symbol_stream_convert_task__entry_point)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
U64 scratch_overkill = sizeof(procedure_frameprocs[0])*(procedure_frameprocs_cap-procedure_frameprocs_count);
|
U64 scratch_overkill = sizeof(procedure_frameprocs[0])*(procedure_frameprocs_cap-procedure_frameprocs_count);
|
||||||
arena_put_back(scratch.arena, scratch_overkill);
|
arena_pop(scratch.arena, scratch_overkill);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////
|
//////////////////////////
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ entry_point(CmdLine *cmdline)
|
|||||||
fprintf(stderr, "error(input): %.*s\n", str8_varg(n->string));
|
fprintf(stderr, "error(input): %.*s\n", str8_varg(n->string));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
os_exit_process(0);
|
os_abort(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- rjf: convert
|
//- rjf: convert
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ r_init(CmdLine *cmdln)
|
|||||||
char buffer[256] = {0};
|
char buffer[256] = {0};
|
||||||
raddbg_snprintf(buffer, sizeof(buffer), "D3D11 device creation failure (%lx). The process is terminating.", error);
|
raddbg_snprintf(buffer, sizeof(buffer), "D3D11 device creation failure (%lx). The process is terminating.", error);
|
||||||
os_graphical_message(1, str8_lit("Fatal Error"), str8_cstring(buffer));
|
os_graphical_message(1, str8_lit("Fatal Error"), str8_cstring(buffer));
|
||||||
os_exit_process(1);
|
os_abort(1);
|
||||||
}
|
}
|
||||||
ProfEnd();
|
ProfEnd();
|
||||||
|
|
||||||
@@ -514,8 +514,8 @@ r_window_equip(OS_Handle handle)
|
|||||||
//- rjf: map os window handle -> hwnd
|
//- rjf: map os window handle -> hwnd
|
||||||
HWND hwnd = {0};
|
HWND hwnd = {0};
|
||||||
{
|
{
|
||||||
W32_Window *w32_layer_window = w32_window_from_os_window(handle);
|
OS_W32_Window *w32_layer_window = os_w32_window_from_handle(handle);
|
||||||
hwnd = w32_hwnd_from_window(w32_layer_window);
|
hwnd = os_w32_hwnd_from_window(w32_layer_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- rjf: create swapchain
|
//- rjf: create swapchain
|
||||||
@@ -540,7 +540,7 @@ r_window_equip(OS_Handle handle)
|
|||||||
char buffer[256] = {0};
|
char buffer[256] = {0};
|
||||||
raddbg_snprintf(buffer, sizeof(buffer), "DXGI swap chain creation failure (%lx). The process is terminating.", error);
|
raddbg_snprintf(buffer, sizeof(buffer), "DXGI swap chain creation failure (%lx). The process is terminating.", error);
|
||||||
os_graphical_message(1, str8_lit("Fatal Error"), str8_cstring(buffer));
|
os_graphical_message(1, str8_lit("Fatal Error"), str8_cstring(buffer));
|
||||||
os_exit_process(1);
|
os_abort(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
r_d3d11_state->dxgi_factory->lpVtbl->MakeWindowAssociation(r_d3d11_state->dxgi_factory, hwnd, DXGI_MWA_NO_ALT_ENTER);
|
r_d3d11_state->dxgi_factory->lpVtbl->MakeWindowAssociation(r_d3d11_state->dxgi_factory, hwnd, DXGI_MWA_NO_ALT_ENTER);
|
||||||
@@ -1034,7 +1034,7 @@ r_window_end_frame(OS_Handle window, R_Handle window_equip)
|
|||||||
char buffer[256] = {0};
|
char buffer[256] = {0};
|
||||||
raddbg_snprintf(buffer, sizeof(buffer), "D3D11 present failure (%lx). The process is terminating.", error);
|
raddbg_snprintf(buffer, sizeof(buffer), "D3D11 present failure (%lx). The process is terminating.", error);
|
||||||
os_graphical_message(1, str8_lit("Fatal Error"), str8_cstring(buffer));
|
os_graphical_message(1, str8_lit("Fatal Error"), str8_cstring(buffer));
|
||||||
os_exit_process(1);
|
os_abort(1);
|
||||||
}
|
}
|
||||||
d_ctx->lpVtbl->ClearState(d_ctx);
|
d_ctx->lpVtbl->ClearState(d_ctx);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ ts_init(void)
|
|||||||
ts_shared = push_array(arena, TS_Shared, 1);
|
ts_shared = push_array(arena, TS_Shared, 1);
|
||||||
ts_shared->arena = arena;
|
ts_shared->arena = arena;
|
||||||
ts_shared->artifact_slots_count = 1024;
|
ts_shared->artifact_slots_count = 1024;
|
||||||
ts_shared->artifact_stripes_count = Min(ts_shared->artifact_slots_count, os_logical_core_count());
|
ts_shared->artifact_stripes_count = Min(ts_shared->artifact_slots_count, os_get_system_info()->logical_processor_count);
|
||||||
ts_shared->artifact_slots = push_array(arena, TS_TaskArtifactSlot, ts_shared->artifact_slots_count);
|
ts_shared->artifact_slots = push_array(arena, TS_TaskArtifactSlot, ts_shared->artifact_slots_count);
|
||||||
ts_shared->artifact_stripes = push_array(arena, TS_TaskArtifactStripe, ts_shared->artifact_stripes_count);
|
ts_shared->artifact_stripes = push_array(arena, TS_TaskArtifactStripe, ts_shared->artifact_stripes_count);
|
||||||
for(U64 idx = 0; idx < ts_shared->artifact_stripes_count; idx += 1)
|
for(U64 idx = 0; idx < ts_shared->artifact_stripes_count; idx += 1)
|
||||||
@@ -40,12 +40,12 @@ ts_init(void)
|
|||||||
ts_shared->u2t_ring_base = push_array_no_zero(arena, U8, ts_shared->u2t_ring_size);
|
ts_shared->u2t_ring_base = push_array_no_zero(arena, U8, ts_shared->u2t_ring_size);
|
||||||
ts_shared->u2t_ring_mutex = os_mutex_alloc();
|
ts_shared->u2t_ring_mutex = os_mutex_alloc();
|
||||||
ts_shared->u2t_ring_cv = os_condition_variable_alloc();
|
ts_shared->u2t_ring_cv = os_condition_variable_alloc();
|
||||||
ts_shared->task_threads_count = os_logical_core_count()-1;
|
ts_shared->task_threads_count = os_get_system_info()->logical_processor_count-1;
|
||||||
ts_shared->task_threads = push_array(arena, TS_TaskThread, ts_shared->task_threads_count);
|
ts_shared->task_threads = push_array(arena, TS_TaskThread, ts_shared->task_threads_count);
|
||||||
for(U64 idx = 0; idx < ts_shared->task_threads_count; idx += 1)
|
for(U64 idx = 0; idx < ts_shared->task_threads_count; idx += 1)
|
||||||
{
|
{
|
||||||
ts_shared->task_threads[idx].arena = arena_alloc();
|
ts_shared->task_threads[idx].arena = arena_alloc();
|
||||||
ts_shared->task_threads[idx].thread = os_launch_thread(ts_task_thread__entry_point, (void *)idx, 0);
|
ts_shared->task_threads[idx].thread = os_thread_launch(ts_task_thread__entry_point, (void *)idx, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1574,7 +1574,7 @@ txt_init(void)
|
|||||||
txt_shared->arena = arena;
|
txt_shared->arena = arena;
|
||||||
txt_shared->slots_count = 1024;
|
txt_shared->slots_count = 1024;
|
||||||
txt_shared->slots = push_array(arena, TXT_Slot, txt_shared->slots_count);
|
txt_shared->slots = push_array(arena, TXT_Slot, txt_shared->slots_count);
|
||||||
txt_shared->stripes_count = Min(txt_shared->slots_count, os_logical_core_count());
|
txt_shared->stripes_count = Min(txt_shared->slots_count, os_get_system_info()->logical_processor_count);
|
||||||
txt_shared->stripes = push_array(arena, TXT_Stripe, txt_shared->stripes_count);
|
txt_shared->stripes = push_array(arena, TXT_Stripe, txt_shared->stripes_count);
|
||||||
txt_shared->stripes_free_nodes = push_array(arena, TXT_Node *, txt_shared->stripes_count);
|
txt_shared->stripes_free_nodes = push_array(arena, TXT_Node *, txt_shared->stripes_count);
|
||||||
for(U64 idx = 0; idx < txt_shared->stripes_count; idx += 1)
|
for(U64 idx = 0; idx < txt_shared->stripes_count; idx += 1)
|
||||||
@@ -1587,13 +1587,13 @@ txt_init(void)
|
|||||||
txt_shared->u2p_ring_base = push_array_no_zero(arena, U8, txt_shared->u2p_ring_size);
|
txt_shared->u2p_ring_base = push_array_no_zero(arena, U8, txt_shared->u2p_ring_size);
|
||||||
txt_shared->u2p_ring_cv = os_condition_variable_alloc();
|
txt_shared->u2p_ring_cv = os_condition_variable_alloc();
|
||||||
txt_shared->u2p_ring_mutex = os_mutex_alloc();
|
txt_shared->u2p_ring_mutex = os_mutex_alloc();
|
||||||
txt_shared->parse_thread_count = Clamp(1, os_logical_core_count()-1, 4);
|
txt_shared->parse_thread_count = Clamp(1, os_get_system_info()->logical_processor_count-1, 4);
|
||||||
txt_shared->parse_threads = push_array(arena, OS_Handle, txt_shared->parse_thread_count);
|
txt_shared->parse_threads = push_array(arena, OS_Handle, txt_shared->parse_thread_count);
|
||||||
for(U64 idx = 0; idx < txt_shared->parse_thread_count; idx += 1)
|
for(U64 idx = 0; idx < txt_shared->parse_thread_count; idx += 1)
|
||||||
{
|
{
|
||||||
txt_shared->parse_threads[idx] = os_launch_thread(txt_parse_thread__entry_point, (void *)idx, 0);
|
txt_shared->parse_threads[idx] = os_thread_launch(txt_parse_thread__entry_point, (void *)idx, 0);
|
||||||
}
|
}
|
||||||
txt_shared->evictor_thread = os_launch_thread(txt_evictor_thread__entry_point, 0, 0);
|
txt_shared->evictor_thread = os_thread_launch(txt_evictor_thread__entry_point, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ tex_init(void)
|
|||||||
tex_shared = push_array(arena, TEX_Shared, 1);
|
tex_shared = push_array(arena, TEX_Shared, 1);
|
||||||
tex_shared->arena = arena;
|
tex_shared->arena = arena;
|
||||||
tex_shared->slots_count = 1024;
|
tex_shared->slots_count = 1024;
|
||||||
tex_shared->stripes_count = Min(tex_shared->slots_count, os_logical_core_count());
|
tex_shared->stripes_count = Min(tex_shared->slots_count, os_get_system_info()->logical_processor_count);
|
||||||
tex_shared->slots = push_array(arena, TEX_Slot, tex_shared->slots_count);
|
tex_shared->slots = push_array(arena, TEX_Slot, tex_shared->slots_count);
|
||||||
tex_shared->stripes = push_array(arena, TEX_Stripe, tex_shared->stripes_count);
|
tex_shared->stripes = push_array(arena, TEX_Stripe, tex_shared->stripes_count);
|
||||||
tex_shared->stripes_free_nodes = push_array(arena, TEX_Node *, tex_shared->stripes_count);
|
tex_shared->stripes_free_nodes = push_array(arena, TEX_Node *, tex_shared->stripes_count);
|
||||||
@@ -38,13 +38,13 @@ tex_init(void)
|
|||||||
tex_shared->u2x_ring_base = push_array_no_zero(arena, U8, tex_shared->u2x_ring_size);
|
tex_shared->u2x_ring_base = push_array_no_zero(arena, U8, tex_shared->u2x_ring_size);
|
||||||
tex_shared->u2x_ring_cv = os_condition_variable_alloc();
|
tex_shared->u2x_ring_cv = os_condition_variable_alloc();
|
||||||
tex_shared->u2x_ring_mutex = os_mutex_alloc();
|
tex_shared->u2x_ring_mutex = os_mutex_alloc();
|
||||||
tex_shared->xfer_thread_count = Clamp(1, os_logical_core_count()-1, 4);
|
tex_shared->xfer_thread_count = Clamp(1, os_get_system_info()->logical_processor_count-1, 4);
|
||||||
tex_shared->xfer_threads = push_array(arena, OS_Handle, tex_shared->xfer_thread_count);
|
tex_shared->xfer_threads = push_array(arena, OS_Handle, tex_shared->xfer_thread_count);
|
||||||
for(U64 idx = 0; idx < tex_shared->xfer_thread_count; idx += 1)
|
for(U64 idx = 0; idx < tex_shared->xfer_thread_count; idx += 1)
|
||||||
{
|
{
|
||||||
tex_shared->xfer_threads[idx] = os_launch_thread(tex_xfer_thread__entry_point, (void *)idx, 0);
|
tex_shared->xfer_threads[idx] = os_thread_launch(tex_xfer_thread__entry_point, (void *)idx, 0);
|
||||||
}
|
}
|
||||||
tex_shared->evictor_thread = os_launch_thread(tex_evictor_thread__entry_point, 0, 0);
|
tex_shared->evictor_thread = os_thread_launch(tex_evictor_thread__entry_point, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|||||||
+6
-6
@@ -2522,14 +2522,14 @@ ui_signal_from_box(UI_Box *box)
|
|||||||
sig.f |= (UI_SignalFlag_LeftPressed<<evt_mouse_button_kind);
|
sig.f |= (UI_SignalFlag_LeftPressed<<evt_mouse_button_kind);
|
||||||
ui_state->drag_start_mouse = evt->pos;
|
ui_state->drag_start_mouse = evt->pos;
|
||||||
if(ui_key_match(box->key, ui_state->press_key_history[evt_mouse_button_kind][0]) &&
|
if(ui_key_match(box->key, ui_state->press_key_history[evt_mouse_button_kind][0]) &&
|
||||||
evt->timestamp_us-ui_state->press_timestamp_history_us[evt_mouse_button_kind][0] <= 1000000*os_double_click_time())
|
evt->timestamp_us-ui_state->press_timestamp_history_us[evt_mouse_button_kind][0] <= 1000000*os_get_gfx_info()->double_click_time)
|
||||||
{
|
{
|
||||||
sig.f |= (UI_SignalFlag_LeftDoubleClicked<<evt_mouse_button_kind);
|
sig.f |= (UI_SignalFlag_LeftDoubleClicked<<evt_mouse_button_kind);
|
||||||
}
|
}
|
||||||
if(ui_key_match(box->key, ui_state->press_key_history[evt_mouse_button_kind][0]) &&
|
if(ui_key_match(box->key, ui_state->press_key_history[evt_mouse_button_kind][0]) &&
|
||||||
ui_key_match(box->key, ui_state->press_key_history[evt_mouse_button_kind][1]) &&
|
ui_key_match(box->key, ui_state->press_key_history[evt_mouse_button_kind][1]) &&
|
||||||
evt->timestamp_us-ui_state->press_timestamp_history_us[evt_mouse_button_kind][0] <= 1000000*os_double_click_time() &&
|
evt->timestamp_us-ui_state->press_timestamp_history_us[evt_mouse_button_kind][0] <= 1000000*os_get_gfx_info()->double_click_time &&
|
||||||
ui_state->press_timestamp_history_us[evt_mouse_button_kind][0] - ui_state->press_timestamp_history_us[evt_mouse_button_kind][1] <= 1000000*os_double_click_time())
|
ui_state->press_timestamp_history_us[evt_mouse_button_kind][0] - ui_state->press_timestamp_history_us[evt_mouse_button_kind][1] <= 1000000*os_get_gfx_info()->double_click_time)
|
||||||
{
|
{
|
||||||
sig.f |= (UI_SignalFlag_LeftTripleClicked<<evt_mouse_button_kind);
|
sig.f |= (UI_SignalFlag_LeftTripleClicked<<evt_mouse_button_kind);
|
||||||
}
|
}
|
||||||
@@ -2720,7 +2720,7 @@ ui_signal_from_box(UI_Box *box)
|
|||||||
if(sig.f & (UI_SignalFlag_LeftDragging<<k) &&
|
if(sig.f & (UI_SignalFlag_LeftDragging<<k) &&
|
||||||
ui_key_match(ui_state->press_key_history[k][0], box->key) &&
|
ui_key_match(ui_state->press_key_history[k][0], box->key) &&
|
||||||
ui_key_match(ui_state->press_key_history[k][1], box->key) &&
|
ui_key_match(ui_state->press_key_history[k][1], box->key) &&
|
||||||
ui_state->press_timestamp_history_us[k][0] - ui_state->press_timestamp_history_us[k][1] <= 1000000*os_double_click_time() &&
|
ui_state->press_timestamp_history_us[k][0] - ui_state->press_timestamp_history_us[k][1] <= 1000000*os_get_gfx_info()->double_click_time &&
|
||||||
length_2f32(sub_2f32(ui_state->press_pos_history[k][0], ui_state->press_pos_history[k][1])) < 10.f)
|
length_2f32(sub_2f32(ui_state->press_pos_history[k][0], ui_state->press_pos_history[k][1])) < 10.f)
|
||||||
{
|
{
|
||||||
sig.f |= (UI_SignalFlag_LeftDoubleDragging<<k);
|
sig.f |= (UI_SignalFlag_LeftDoubleDragging<<k);
|
||||||
@@ -2739,8 +2739,8 @@ ui_signal_from_box(UI_Box *box)
|
|||||||
ui_key_match(ui_state->press_key_history[k][0], box->key) &&
|
ui_key_match(ui_state->press_key_history[k][0], box->key) &&
|
||||||
ui_key_match(ui_state->press_key_history[k][1], box->key) &&
|
ui_key_match(ui_state->press_key_history[k][1], box->key) &&
|
||||||
ui_key_match(ui_state->press_key_history[k][2], box->key) &&
|
ui_key_match(ui_state->press_key_history[k][2], box->key) &&
|
||||||
ui_state->press_timestamp_history_us[k][0] - ui_state->press_timestamp_history_us[k][1] <= 1000000*os_double_click_time() &&
|
ui_state->press_timestamp_history_us[k][0] - ui_state->press_timestamp_history_us[k][1] <= 1000000*os_get_gfx_info()->double_click_time &&
|
||||||
ui_state->press_timestamp_history_us[k][1] - ui_state->press_timestamp_history_us[k][2] <= 1000000*os_double_click_time() &&
|
ui_state->press_timestamp_history_us[k][1] - ui_state->press_timestamp_history_us[k][2] <= 1000000*os_get_gfx_info()->double_click_time &&
|
||||||
length_2f32(sub_2f32(ui_state->press_pos_history[k][0], ui_state->press_pos_history[k][1])) < 10.f &&
|
length_2f32(sub_2f32(ui_state->press_pos_history[k][0], ui_state->press_pos_history[k][1])) < 10.f &&
|
||||||
length_2f32(sub_2f32(ui_state->press_pos_history[k][1], ui_state->press_pos_history[k][2])) < 10.f)
|
length_2f32(sub_2f32(ui_state->press_pos_history[k][1], ui_state->press_pos_history[k][2])) < 10.f)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user