mirror of
https://github.com/Ed94/metadesk.git
synced 2026-07-30 11:20:06 +00:00
base progress
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#ifdef MD_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "base_types.h"
|
||||
#include "macros.h"
|
||||
#include "base_types.h"
|
||||
#endif
|
||||
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
@@ -18,48 +18,49 @@
|
||||
typedef U32 ArenaFlags;
|
||||
enum
|
||||
{
|
||||
ArenaFlag_NoChain = (1<<0),
|
||||
ArenaFlag_LargePages = (1<<1),
|
||||
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;
|
||||
ArenaFlags flags;
|
||||
U64 reserve_size;
|
||||
U64 commit_size;
|
||||
void* optional_backing_buffer;
|
||||
};
|
||||
|
||||
typedef struct Arena Arena;
|
||||
struct Arena
|
||||
{
|
||||
Arena *prev; // previous arena in chain
|
||||
Arena *current; // current arena in chain
|
||||
ArenaFlags flags;
|
||||
U32 cmt_size;
|
||||
U64 res_size;
|
||||
U64 base_pos;
|
||||
U64 pos;
|
||||
U64 cmt;
|
||||
U64 res;
|
||||
Arena* prev; // previous arena in chain
|
||||
Arena* current; // current arena in chain
|
||||
ArenaFlags flags;
|
||||
U32 cmt_size;
|
||||
U64 res_size;
|
||||
U64 base_pos;
|
||||
U64 pos;
|
||||
U64 cmt;
|
||||
U64 res;
|
||||
};
|
||||
static_assert(sizeof(Arena) <= MD_ARENA_HEADER_SIZE, "sizeof(Arena) <= MD_ARENA_HEADER_SIZE");
|
||||
|
||||
typedef struct TempArena TempArena;
|
||||
struct TempArena
|
||||
{
|
||||
Arena *arena;
|
||||
U64 pos;
|
||||
Arena* arena;
|
||||
U64 pos;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Arena Functions
|
||||
|
||||
//- 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 rarena_release(Arena *arena);
|
||||
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);
|
||||
|
||||
//- rjf: arena push/pop/pos core functions
|
||||
internal void *arena_push(Arena *arena, U64 size, U64 align);
|
||||
@@ -76,6 +77,6 @@ internal void temp_arena_end(TempArena temp);
|
||||
|
||||
//- rjf: push helper macros
|
||||
#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))
|
||||
#define push_array_no_zero(a, T, c) push_array_no_zero_aligned(a, T, c, Max(8, AlignOf(T)))
|
||||
#define push_array(a, T, c) push_array_aligned(a, T, c, Max(8, AlignOf(T)))
|
||||
#define push_array_aligned(a, T, c, align) (T *)memory_zero(push_array_no_zero_aligned(a, T, c, align), sizeof(T)*(c))
|
||||
#define push_array_no_zero(a, T, c) push_array_no_zero_aligned(a, T, c, max(8, align_of(T)))
|
||||
#define push_array(a, T, c) push_array_aligned(a, T, c, max(8, align_of(T)))
|
||||
@@ -0,0 +1,259 @@
|
||||
#if MD_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#pragma region Compiler Vendor
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
# pragma message("Detected MSVC")
|
||||
// # define MD_COMPILER_CLANG 0
|
||||
# define MD_COMPILER_MSVC 1
|
||||
// # define MD_COMPILER_GCC 0
|
||||
# if _MSC_VER >= 1920
|
||||
# define MD_COMPILER_MSVC_YEAR 2019
|
||||
# elif _MSC_VER >= 1910
|
||||
# define MD_COMPILER_MSVC_YEAR 2017
|
||||
# elif _MSC_VER >= 1900
|
||||
# define MD_COMPILER_MSVC_YEAR 2015
|
||||
# elif _MSC_VER >= 1800
|
||||
# define MD_COMPILER_MSVC_YEAR 2013
|
||||
# elif _MSC_VER >= 1700
|
||||
# define MD_COMPILER_MSVC_YEAR 2012
|
||||
# elif _MSC_VER >= 1600
|
||||
# define MD_COMPILER_MSVC_YEAR 2010
|
||||
# elif _MSC_VER >= 1500
|
||||
# define M_DCOMPILER_MSVC_YEAR 2008
|
||||
# elif _MSC_VER >= 1400
|
||||
# define MD_COMPILER_MSVC_YEAR 2005
|
||||
# else
|
||||
# define MD_COMPILER_MSVC_YEAR 0
|
||||
# endif
|
||||
|
||||
#elif defined( __GNUC__ )
|
||||
# pragma message("Detected GCC")
|
||||
// # define MD_COMPILER_CLANG 0
|
||||
// # define MD_COMPILER_MSVC 0
|
||||
# define MD_COMPILER_GCC 1
|
||||
#elif defined( __clang__ )
|
||||
# pragma message("Detected CLANG")
|
||||
# define MD_COMPILER_CLANG 1
|
||||
// # define MD_COMPILER_MSVC 0
|
||||
// # define MD_COMPILER_GCC 0
|
||||
#else
|
||||
# error Unknown compiler
|
||||
#endif
|
||||
|
||||
#if defined( __has_attribute )
|
||||
# define MD_HAS_ATTRIBUTE( attribute ) __has_attribute( attribute )
|
||||
#else
|
||||
# define MD_HAS_ATTRIBUTE( attribute ) ( 0 )
|
||||
#endif
|
||||
|
||||
#if defined(MD_GCC_VERSION_CHECK)
|
||||
# undef MD_GCC_VERSION_CHECK
|
||||
#endif
|
||||
#if defined(GEN_GCC_VERSION)
|
||||
# define MD_GCC_VERSION_CHECK(major,minor,patch) (GEN_GCC_VERSION >= GEN_VERSION_ENCODE(major, minor, patch))
|
||||
#else
|
||||
# define MD_GCC_VERSION_CHECK(major,minor,patch) (0)
|
||||
#endif
|
||||
|
||||
#pragma endregion Compiler Vendor
|
||||
|
||||
#pragma endregion Language
|
||||
|
||||
#if ! defined(MD_LANG_C)
|
||||
# ifdef __cplusplus
|
||||
# define MD_LANG_C 0
|
||||
# define MD_LANG_CPP 1
|
||||
# else
|
||||
# if defined(__STDC__)
|
||||
# define MD_LANG_C 1
|
||||
# define MD_LANG_CPP 0
|
||||
# else
|
||||
// Fallback for very old C compilers
|
||||
# define MD_LANG_C 1
|
||||
# define MD_LANG_CPP 0
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if MD_LANG_C
|
||||
# pragma message("MD: Detected C")
|
||||
#endif
|
||||
|
||||
#if MD_LANG_CPP
|
||||
# pragma message("MD: Detected CPP")
|
||||
#endif
|
||||
|
||||
#pragma endregion Langauge
|
||||
|
||||
#pragma region Hardware Architecture
|
||||
|
||||
#if MD_COMPILER_CLANG
|
||||
# if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64)
|
||||
# define MD_ARCH_X64 1
|
||||
# elif defined(i386) || defined(__i386) || defined(__i386__)
|
||||
# define MD_ARCH_X86 1
|
||||
# elif defined(__aarch64__)
|
||||
# define MD_ARCH_ARM64 1
|
||||
# elif defined(__arm__)
|
||||
# define MD_ARCH_ARM32 1
|
||||
# else
|
||||
# error Architecture not supported.
|
||||
# endif
|
||||
#endif // MD_COMPILER_CLANG
|
||||
|
||||
#if MD_COMPILER_MSVC
|
||||
# if defined(_M_AMD64)
|
||||
# define MD_ARCH_X64 1
|
||||
# elif defined(_M_IX86)
|
||||
# define MD_ARCH_X86 1
|
||||
# elif defined(_M_ARM64)
|
||||
# define MD_ARCH_ARM64 1
|
||||
# elif defined(_M_ARM)
|
||||
# define MD_ARCH_ARM32 1
|
||||
# else
|
||||
# error Architecture not supported.
|
||||
# endif
|
||||
#endif // MD_COMPILER_MSVC
|
||||
|
||||
#if MD_COMPILER_GCC
|
||||
# if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64)
|
||||
# define MD_ARCH_X64 1
|
||||
# elif defined(i386) || defined(__i386) || defined(__i386__)
|
||||
# define MD_ARCH_X86 1
|
||||
# elif defined(__aarch64__)
|
||||
# define MD_ARCH_ARM64 1
|
||||
# elif defined(__arm__)
|
||||
# define MD_ARCH_ARM32 1
|
||||
# else
|
||||
# error Architecture not supported.
|
||||
# endif
|
||||
#endif // MD_COMPILER_GCC
|
||||
|
||||
#if defined(MD_ARCH_X64)
|
||||
# define MD_ARCH_64BIT 1
|
||||
#elif defined(MD_ARCH_X86)
|
||||
# define MD_ARCH_32BIT 1
|
||||
#endif
|
||||
|
||||
#if MD_ARCH_ARM32 || MD_ARCH_ARM64 || MD_ARCH_X64 || MD_ARCH_X86
|
||||
# define MD_ARCH_LITTLE_ENDIAN 1
|
||||
#else
|
||||
# error Endianness of this architecture not understood by context cracker.
|
||||
#endif
|
||||
|
||||
#pragma endregion Hardware Architecture
|
||||
|
||||
#pragma region Operating System
|
||||
|
||||
#if defined( _WIN32 ) || defined( _WIN64 )
|
||||
# ifndef MD_OS_WINDOWS
|
||||
# define MD_OS_WINDOWS 1
|
||||
# endif
|
||||
#elif defined( __APPLE__ ) && defined( __MACH__ )
|
||||
# ifndef MD_OS_OSX
|
||||
# define MD_OS_OSX 1
|
||||
# endif
|
||||
# ifndef MD_OS_MACOS
|
||||
# define MD_OS_MACOS 1
|
||||
# endif
|
||||
#elif defined( __unix__ )
|
||||
# ifndef MD_OS_UNIX
|
||||
# define MD_OS_UNIX 1
|
||||
# endif
|
||||
# if defined( ANDROID ) || defined( __ANDROID__ )
|
||||
# ifndef MD_OS_ANDROID
|
||||
# define MD_OS_ANDROID 1
|
||||
# endif
|
||||
# ifndef MD_OS_LINUX
|
||||
# define MD_OS_LINUX 1
|
||||
# endif
|
||||
# elif defined( __linux__ )
|
||||
# ifndef MD_OS_LINUX
|
||||
# define MD_OS_LINUX 1
|
||||
# endif
|
||||
# elif defined( __FreeBSD__ ) || defined( __FreeBSD_kernel__ )
|
||||
# ifndef MD_OS_FREEBSD
|
||||
# define MD_OS_FREEBSD 1
|
||||
# endif
|
||||
# elif defined( __OpenBSD__ )
|
||||
# ifndef MD_OS_OPENBSD
|
||||
# define MD_OS_OPENBSD 1
|
||||
# endif
|
||||
# elif defined( __EMSCRIPTEN__ )
|
||||
# ifndef MD_OS_EMSCRIPTEN
|
||||
# define MD_OS_EMSCRIPTEN 1
|
||||
# endif
|
||||
# elif defined( __CYGWIN__ )
|
||||
# ifndef MD_OS_CYGWIN
|
||||
# define MD_OS_CYGWIN 1
|
||||
# endif
|
||||
# else
|
||||
# error This UNIX operating system is not supported
|
||||
# endif
|
||||
#else
|
||||
# error This operating system is not supported
|
||||
#endif
|
||||
|
||||
#pragma endregion Operating System
|
||||
|
||||
#pragma region Language
|
||||
#pragma endregion Langage
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Zero All Undefined Options
|
||||
|
||||
#if !defined(MD_ARCH_32BIT)
|
||||
# define MD_ARCH_32BIT 0
|
||||
#endif
|
||||
#if !defined(MD_ARCH_64BIT)
|
||||
# define MD_ARCH_64BIT 0
|
||||
#endif
|
||||
#if !defined(MD_ARCH_X64)
|
||||
# define MD_ARCH_X64 0
|
||||
#endif
|
||||
#if !defined(MD_ARCH_X86)
|
||||
# define MD_ARCH_X86 0
|
||||
#endif
|
||||
#if !defined(MD_ARCH_ARM64)
|
||||
# define MD_ARCH_ARM64 0
|
||||
#endif
|
||||
#if !defined(MD_ARCH_ARM32)
|
||||
# define MD_ARCH_ARM32 0
|
||||
#endif
|
||||
#if !defined(MD_COMPILER_MSVC)
|
||||
# define MD_COMPILER_MSVC 0
|
||||
#endif
|
||||
#if !defined(MD-COMPILER_GCC)
|
||||
# define MD_COMPILER_GCC 0
|
||||
#endif
|
||||
#if !defined(MD_COMPILER_CLANG)
|
||||
# define MD_COMPILER_CLANG 0
|
||||
#endif
|
||||
#if !defined(MD_OS_WINDOWS)
|
||||
# define MD_OS_WINDOWS 0
|
||||
#endif
|
||||
#if !defined(MD_OS_LINUX)
|
||||
# define MD_OS_LINUX 0
|
||||
#endif
|
||||
#if !defined(MD_OS_MAC)
|
||||
# define MD_OS_MAC 0
|
||||
#endif
|
||||
#if !defined(MD_LANG_CPP)
|
||||
# define MD_LANG_CPP 0
|
||||
#endif
|
||||
#if !defined(MD_LANG_C)
|
||||
# define MD_LANG_C 0
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Unsupported Errors
|
||||
|
||||
#if MD_ARCH_X86
|
||||
# error You tried to build in x86 (32 bit) mode, but currently, only building in x64 (64 bit) mode is supported.
|
||||
#endif
|
||||
#if ! MD_ARCH_X64
|
||||
# error You tried to build with an unsupported architecture. Currently, only building in x64 mode is supported.
|
||||
#endif
|
||||
@@ -1,13 +0,0 @@
|
||||
#if MD_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#if defined( _WIN64 ) || defined( __x86_64__ ) || defined( _M_X64 ) || defined( __64BIT__ ) || defined( __powerpc64__ ) || defined( __ppc64__ ) || defined( __aarch64__ )
|
||||
# ifndef MD_ARCH_64_BIT
|
||||
# define MD_ARCH_64_BIT 1
|
||||
# endif
|
||||
#else
|
||||
# ifndef MD_ARCH_32_BIT
|
||||
# define MD_ARCH_32_BIT 1
|
||||
# endif
|
||||
#endif
|
||||
@@ -1,61 +0,0 @@
|
||||
#if MD_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
# pragma message("Detected MSVC")
|
||||
// # define MD_COMPILER_CLANG 0
|
||||
# define MD_COMPILER_MSVC 1
|
||||
// # define MD_COMPILER_GCC 0
|
||||
#elif defined( __GNUC__ )
|
||||
# pragma message("Detected GCC")
|
||||
// # define MD_COMPILER_CLANG 0
|
||||
// # define MD_COMPILER_MSVC 0
|
||||
# define MD_COMPILER_GCC 1
|
||||
#elif defined( __clang__ )
|
||||
# pragma message("Detected CLANG")
|
||||
# define MD_COMPILER_CLANG 1
|
||||
// # define MD_COMPILER_MSVC 0
|
||||
// # define MD_COMPILER_GCC 0
|
||||
#else
|
||||
# error Unknown compiler
|
||||
#endif
|
||||
|
||||
#if defined( __has_attribute )
|
||||
# define MD_HAS_ATTRIBUTE( attribute ) __has_attribute( attribute )
|
||||
#else
|
||||
# define MD_HAS_ATTRIBUTE( attribute ) ( 0 )
|
||||
#endif
|
||||
|
||||
#if defined(MD_GCC_VERSION_CHECK)
|
||||
# undef MD_GCC_VERSION_CHECK
|
||||
#endif
|
||||
#if defined(GEN_GCC_VERSION)
|
||||
# define MD_GCC_VERSION_CHECK(major,minor,patch) (GEN_GCC_VERSION >= GEN_VERSION_ENCODE(major, minor, patch))
|
||||
#else
|
||||
# define MD_GCC_VERSION_CHECK(major,minor,patch) (0)
|
||||
#endif
|
||||
|
||||
#if ! defined(MD_COMPILER_C)
|
||||
# ifdef __cplusplus
|
||||
# define MD_COMPILER_C 0
|
||||
# define MD_COMPILER_CPP 1
|
||||
# else
|
||||
# if defined(__STDC__)
|
||||
# define MD_COMPILER_C 1
|
||||
# define MD_COMPILER_CPP 0
|
||||
# else
|
||||
// Fallback for very old C compilers
|
||||
# define MD_COMPILER_C 1
|
||||
# define MD_COMPILER_CPP 0
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if MD_COMPILER_C
|
||||
#pragma message("MD: Detected C")
|
||||
#endif
|
||||
|
||||
#if MD_COMPILER_CPP
|
||||
#pragma message("MD: Detected CPP")
|
||||
#endif
|
||||
@@ -1,52 +1,3 @@
|
||||
#if MD_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#if defined( _WIN32 ) || defined( _WIN64 )
|
||||
# ifndef MD_OS_WINDOWS
|
||||
# define MD_OS_WINDOWS 1
|
||||
# endif
|
||||
#elif defined( __APPLE__ ) && defined( __MACH__ )
|
||||
# ifndef MD_OS_OSX
|
||||
# define MD_OS_OSX 1
|
||||
# endif
|
||||
# ifndef MD_OS_MACOS
|
||||
# define MD_OS_MACOS 1
|
||||
# endif
|
||||
#elif defined( __unix__ )
|
||||
# ifndef MD_OS_UNIX
|
||||
# define MD_OS_UNIX 1
|
||||
# endif
|
||||
# if defined( ANDROID ) || defined( __ANDROID__ )
|
||||
# ifndef MD_OS_ANDROID
|
||||
# define MD_OS_ANDROID 1
|
||||
# endif
|
||||
# ifndef MD_OS_LINUX
|
||||
# define MD_OS_LINUX 1
|
||||
# endif
|
||||
# elif defined( __linux__ )
|
||||
# ifndef MD_OS_LINUX
|
||||
# define MD_OS_LINUX 1
|
||||
# endif
|
||||
# elif defined( __FreeBSD__ ) || defined( __FreeBSD_kernel__ )
|
||||
# ifndef MD_OS_FREEBSD
|
||||
# define MD_OS_FREEBSD 1
|
||||
# endif
|
||||
# elif defined( __OpenBSD__ )
|
||||
# ifndef MD_OS_OPENBSD
|
||||
# define MD_OS_OPENBSD 1
|
||||
# endif
|
||||
# elif defined( __EMSCRIPTEN__ )
|
||||
# ifndef MD_OS_EMSCRIPTEN
|
||||
# define MD_OS_EMSCRIPTEN 1
|
||||
# endif
|
||||
# elif defined( __CYGWIN__ )
|
||||
# ifndef MD_OS_CYGWIN
|
||||
# define MD_OS_CYGWIN 1
|
||||
# endif
|
||||
# else
|
||||
# error This UNIX operating system is not supported
|
||||
# endif
|
||||
#else
|
||||
# error This operating system is not supported
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
internal void
|
||||
main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **arguments, U64 arguments_count)
|
||||
{
|
||||
#if PROFILE_TELEMETRY
|
||||
local_persist U8 tm_data[MB(64)];
|
||||
tmLoadLibrary(TM_RELEASE);
|
||||
tmSetMaxThreadCount(256);
|
||||
tmInitialize(sizeof(tm_data), (char *)tm_data);
|
||||
#endif
|
||||
ThreadNameF("[main thread]");
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
String8List command_line_argument_strings = os_string_list_from_argcv(scratch.arena, (int)arguments_count, arguments);
|
||||
CmdLine cmdline = cmd_line_from_string_list(scratch.arena, command_line_argument_strings);
|
||||
B32 capture = cmd_line_has_flag(&cmdline, str8_lit("capture"));
|
||||
if(capture)
|
||||
{
|
||||
ProfBeginCapture(arguments[0]);
|
||||
}
|
||||
#if defined(TASK_SYSTEM_H) && !defined(TS_INIT_MANUAL)
|
||||
ts_init();
|
||||
#endif
|
||||
#if defined(HASH_STORE_H) && !defined(HS_INIT_MANUAL)
|
||||
hs_init();
|
||||
#endif
|
||||
#if defined(FILE_STREAM_H) && !defined(FS_INIT_MANUAL)
|
||||
fs_init();
|
||||
#endif
|
||||
#if defined(TEXT_CACHE_H) && !defined(TXT_INIT_MANUAL)
|
||||
txt_init();
|
||||
#endif
|
||||
#if defined(MUTABLE_TEXT_H) && !defined(MTX_INIT_MANUAL)
|
||||
mtx_init();
|
||||
#endif
|
||||
#if defined(DASM_CACHE_H) && !defined(DASM_INIT_MANUAL)
|
||||
dasm_init();
|
||||
#endif
|
||||
#if defined(DI_H) && !defined(DI_INIT_MANUAL)
|
||||
di_init();
|
||||
#endif
|
||||
#if defined(FUZZY_SEARCH_H) && !defined(FZY_INIT_MANUAL)
|
||||
fzy_init();
|
||||
#endif
|
||||
#if defined(DEMON_CORE_H) && !defined(DMN_INIT_MANUAL)
|
||||
dmn_init();
|
||||
#endif
|
||||
#if defined(CTRL_CORE_H) && !defined(CTRL_INIT_MANUAL)
|
||||
ctrl_init();
|
||||
#endif
|
||||
#if defined(OS_GRAPHICAL_H) && !defined(OS_GFX_INIT_MANUAL)
|
||||
os_gfx_init();
|
||||
#endif
|
||||
#if defined(FONT_PROVIDER_H) && !defined(FP_INIT_MANUAL)
|
||||
fp_init();
|
||||
#endif
|
||||
#if defined(RENDER_CORE_H) && !defined(R_INIT_MANUAL)
|
||||
r_init(&cmdline);
|
||||
#endif
|
||||
#if defined(TEXTURE_CACHE_H) && !defined(TEX_INIT_MANUAL)
|
||||
tex_init();
|
||||
#endif
|
||||
#if defined(GEO_CACHE_H) && !defined(GEO_INIT_MANUAL)
|
||||
geo_init();
|
||||
#endif
|
||||
#if defined(FONT_CACHE_H) && !defined(F_INIT_MANUAL)
|
||||
f_init();
|
||||
#endif
|
||||
#if defined(DF_CORE_H) && !defined(DF_INIT_MANUAL)
|
||||
DF_StateDeltaHistory *hist = df_state_delta_history_alloc();
|
||||
df_core_init(&cmdline, hist);
|
||||
#endif
|
||||
#if defined(DF_GFX_H) && !defined(DF_GFX_INIT_MANUAL)
|
||||
df_gfx_init(update_and_render, df_state_delta_history());
|
||||
#endif
|
||||
entry_point(&cmdline);
|
||||
if(capture)
|
||||
{
|
||||
ProfEndCapture();
|
||||
}
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
internal void
|
||||
supplement_thread_base_entry_point(void (*entry_point)(void *params), void *params)
|
||||
{
|
||||
TCTX tctx;
|
||||
tctx_init_and_equip(&tctx);
|
||||
entry_point(params);
|
||||
tctx_release();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef BASE_ENTRY_POINT_H
|
||||
#define BASE_ENTRY_POINT_H
|
||||
|
||||
internal void main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **arguments, U64 arguments_count);
|
||||
internal void supplement_thread_base_entry_point(void (*entry_point)(void *params), void *params);
|
||||
|
||||
#endif // BASE_ENTRY_POINT_H
|
||||
@@ -0,0 +1,103 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Globals/Thread-Locals
|
||||
|
||||
C_LINKAGE thread_static Log *log_active;
|
||||
#if !BUILD_SUPPLEMENTARY_UNIT
|
||||
C_LINKAGE thread_static Log *log_active = 0;
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Log Creation/Selection
|
||||
|
||||
internal Log *
|
||||
log_alloc(void)
|
||||
{
|
||||
Arena *arena = arena_alloc();
|
||||
Log *log = push_array(arena, Log, 1);
|
||||
log->arena = arena;
|
||||
return log;
|
||||
}
|
||||
|
||||
internal void
|
||||
log_release(Log *log)
|
||||
{
|
||||
arena_release(log->arena);
|
||||
}
|
||||
|
||||
internal void
|
||||
log_select(Log *log)
|
||||
{
|
||||
log_active = log;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Log Building/Clearing
|
||||
|
||||
internal void
|
||||
log_msg(LogMsgKind kind, String8 string)
|
||||
{
|
||||
if(log_active != 0 && log_active->top_scope != 0)
|
||||
{
|
||||
String8 string_copy = push_str8_copy(log_active->arena, string);
|
||||
str8_list_push(log_active->arena, &log_active->top_scope->strings[kind], string_copy);
|
||||
}
|
||||
}
|
||||
|
||||
internal void
|
||||
log_msgf(LogMsgKind kind, char *fmt, ...)
|
||||
{
|
||||
if(log_active != 0)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
String8 string = push_str8fv(scratch.arena, fmt, args);
|
||||
log_msg(kind, string);
|
||||
va_end(args);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Log Scopes
|
||||
|
||||
internal void
|
||||
log_scope_begin(void)
|
||||
{
|
||||
if(log_active != 0)
|
||||
{
|
||||
U64 pos = arena_pos(log_active->arena);
|
||||
LogScope *scope = push_array(log_active->arena, LogScope, 1);
|
||||
scope->pos = pos;
|
||||
SLLStackPush(log_active->top_scope, scope);
|
||||
}
|
||||
}
|
||||
|
||||
internal LogScopeResult
|
||||
log_scope_end(Arena *arena)
|
||||
{
|
||||
LogScopeResult result = {0};
|
||||
if(log_active != 0)
|
||||
{
|
||||
LogScope *scope = log_active->top_scope;
|
||||
if(scope != 0)
|
||||
{
|
||||
SLLStackPop(log_active->top_scope);
|
||||
if(arena != 0)
|
||||
{
|
||||
for(EachEnumVal(LogMsgKind, kind))
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
String8 result_unindented = str8_list_join(scratch.arena, &scope->strings[kind], 0);
|
||||
result.strings[kind] = indented_from_string(arena, result_unindented);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
}
|
||||
arena_pop_to(log_active->arena, scope->pos);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef BASE_LOG_H
|
||||
#define BASE_LOG_H
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Log Types
|
||||
|
||||
typedef enum LogMsgKind
|
||||
{
|
||||
LogMsgKind_Info,
|
||||
LogMsgKind_UserError,
|
||||
LogMsgKind_COUNT
|
||||
}
|
||||
LogMsgKind;
|
||||
|
||||
typedef struct LogScope LogScope;
|
||||
struct LogScope
|
||||
{
|
||||
LogScope *next;
|
||||
U64 pos;
|
||||
String8List strings[LogMsgKind_COUNT];
|
||||
};
|
||||
|
||||
typedef struct LogScopeResult LogScopeResult;
|
||||
struct LogScopeResult
|
||||
{
|
||||
String8 strings[LogMsgKind_COUNT];
|
||||
};
|
||||
|
||||
typedef struct Log Log;
|
||||
struct Log
|
||||
{
|
||||
Arena *arena;
|
||||
LogScope *top_scope;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Log Creation/Selection
|
||||
|
||||
internal Log *log_alloc(void);
|
||||
internal void log_release(Log *log);
|
||||
internal void log_select(Log *log);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Log Building
|
||||
|
||||
internal void log_msg(LogMsgKind kind, String8 string);
|
||||
internal void log_msgf(LogMsgKind kind, char *fmt, ...);
|
||||
#define log_info(s) log_msg(LogMsgKind_Info, (s))
|
||||
#define log_infof(fmt, ...) log_msgf(LogMsgKind_Info, (fmt), __VA_ARGS__)
|
||||
#define log_user_error(s) log_msg(LogMsgKind_UserError, (s))
|
||||
#define log_user_errorf(fmt, ...) log_msgf(LogMsgKind_UserError, (fmt), __VA_ARGS__)
|
||||
|
||||
#define LogInfoNamedBlock(s) DeferLoop(log_infof("%S:\n{\n", (s)), log_infof("}\n"))
|
||||
#define LogInfoNamedBlockF(fmt, ...) DeferLoop((log_infof(fmt, __VA_ARGS__), log_infof(":\n{\n")), log_infof("}\n"))
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Log Scopes
|
||||
|
||||
internal void log_scope_begin(void);
|
||||
internal LogScopeResult log_scope_end(Arena *arena);
|
||||
|
||||
#endif // BASE_LOG_H
|
||||
+8
-8
@@ -1,6 +1,6 @@
|
||||
#if MD_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "platform.h"
|
||||
# pragma once
|
||||
# include "platform.h"
|
||||
#endif
|
||||
|
||||
#ifndef local_persist
|
||||
@@ -8,22 +8,22 @@
|
||||
#endif
|
||||
|
||||
#if MD_COMPILER_MSVC
|
||||
# define thread_static __declspec(thread)
|
||||
# define thread_static __declspec(thread)
|
||||
#elif MD_COMPILER_CLANG || MD_COMPILER_GCC
|
||||
# define thread_static __thread
|
||||
# define thread_static __thread
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Branch Predictor Hints
|
||||
|
||||
#if defined(__clang__)
|
||||
#if MD_COMPILER_CLANG
|
||||
# define expect(expr, val) __builtin_expect((expr), (val))
|
||||
#else
|
||||
# define expect(expr, val) (expr)
|
||||
#endif
|
||||
|
||||
#define likely(expr) expect(expr,1)
|
||||
#define unlikely(expr) expect(expr,0)
|
||||
#define likely(expr) expect(expr,1)
|
||||
#define unlikely(expr) expect(expr,0)
|
||||
|
||||
////////////////////////////////
|
||||
//~ erg: type casting
|
||||
@@ -56,7 +56,7 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if ! defined(typeof) && (!MD_COMPILER_C || __STDC_VERSION__ < 202311L)
|
||||
#if ! defined(typeof) && ( ! MD_COMPILER_C || __STDC_VERSION__ < 202311L)
|
||||
# if ! MD_COMPILER_C
|
||||
# define typeof decltype
|
||||
# elif defined(_MSC_VER)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
internal void
|
||||
set_thread_name(String8 string)
|
||||
{
|
||||
ProfThreadName("%.*s", str8_varg(string));
|
||||
os_set_thread_name(string);
|
||||
}
|
||||
|
||||
internal void
|
||||
set_thread_namef(char *fmt, ...)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
String8 string = push_str8fv(scratch.arena, fmt, args);
|
||||
set_thread_name(string);
|
||||
va_end(args);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef BASE_MARKUP_H
|
||||
#define BASE_MARKUP_H
|
||||
|
||||
internal void set_thread_name(String8 string);
|
||||
internal void set_thread_namef(char *fmt, ...);
|
||||
#define ThreadNameF(...) (set_thread_namef(__VA_ARGS__))
|
||||
#define ThreadName(str) (set_thread_name(str))
|
||||
|
||||
#endif // BASE_MARKUP_H
|
||||
+64
-36
@@ -31,13 +31,13 @@
|
||||
//~ rjf: Type -> Alignment
|
||||
|
||||
#if MD_COMPILER_MSVC
|
||||
# define align_of(T) __alignof(T)
|
||||
# define align_of(T) __alignof(T)
|
||||
#elif MD_COMPILER_CLANG
|
||||
# define align_of(T) __alignof(T)
|
||||
# define align_of(T) __alignof(T)
|
||||
#elif MD_COMPILER_GCC
|
||||
# define align_of(T) __alignof__(T)
|
||||
# define align_of(T) __alignof__(T)
|
||||
#else
|
||||
# error AlignOf not defined for this compiler.
|
||||
# error AlignOf not defined for this compiler.
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
@@ -51,8 +51,8 @@
|
||||
////////////////////////////////
|
||||
//~ rjf: For-Loop Construct Macros
|
||||
|
||||
#define defer_loop(begin, end) for(int _i_ = ((begin), 0); ! _i_; _i_ += 1, (end))
|
||||
#define defer_loop_checked(begin, end) for(int _i_ = 2 * ! (begin); (_i_ == 2 ? ((end), 0) : !_i_); _i_ += 1, (end))
|
||||
#define defer_loop(begin, end) for (int _i_ = ((begin), 0); ! _i_; _i_ += 1, (end))
|
||||
#define defer_loop_checked(begin, end) for (int _i_ = 2 * ! (begin); (_i_ == 2 ? ((end), 0) : !_i_); _i_ += 1, (end))
|
||||
|
||||
#define each_enum_val(type, it) type it = (type) 0; it < type ## _COUNT; it = (type)( it + 1 )
|
||||
#define each_non_zero_enum_val(type, it) type it = (type) 1; it < type ## _COUNT; it = (type)( it + 1 )
|
||||
@@ -65,21 +65,21 @@
|
||||
#define memory_compare(a, b, size) memcmp((a), (b), (size))
|
||||
#define memory_str_len(ptr) cstr_len(ptr)
|
||||
|
||||
#define memory_copy_struct(d,s) memory_copy((d), (s), sizeof( *(d)))
|
||||
#define memory_copy_array(d,s) memory_copy((d), (s), sizeof( d))
|
||||
#define memory_copy_type(d,s,c) memory_copy((d), (s), sizeof( *(d)) * (c))
|
||||
#define memory_copy_struct(d,s) memory_copy((d), (s), sizeof( *(d)))
|
||||
#define memory_copy_array(d,s) memory_copy((d), (s), sizeof( d))
|
||||
#define memory_copy_type(d,s,c) memory_copy((d), (s), sizeof( *(d)) * (c))
|
||||
|
||||
#define memory_zero(s,z) mem_set((s), 0, (z))
|
||||
#define memory_zero_struct(s) memory_zero((s), sizeof( *(s)))
|
||||
#define memory_zero_array(a) memroy_zero((a), sizeof(a))
|
||||
#define memory_zero_type(m,c) memroy_zero((m), sizeof( *(m)) * (c))
|
||||
#define memory_zero(s,z) mem_set((s), 0, (z))
|
||||
#define memory_zero_struct(s) memory_zero((s), sizeof( *(s)))
|
||||
#define memory_zero_array(a) memroy_zero((a), sizeof(a))
|
||||
#define memory_zero_type(m,c) memroy_zero((m), sizeof( *(m)) * (c))
|
||||
|
||||
#define memory_match(a,b,z) (memory_compare((a), (b), (z)) == 0)
|
||||
#define memory_match_struct(a,b) memory_match((a), (b), sizeof(*(a)))
|
||||
#define memory_match_array(a,b) memory_match((a), (b), sizeof(a))
|
||||
#define memory_match(a,b,z) (memory_compare((a), (b), (z)) == 0)
|
||||
#define memory_match_struct(a,b) memory_match((a), (b), sizeof(*(a)))
|
||||
#define memory_match_array(a,b) memory_match((a), (b), sizeof(a))
|
||||
|
||||
#define memory_read(T,p,e) ( ((p) + sizeof(T) <= (e)) ? ( *(T*)(p)) : (0) )
|
||||
#define memory_consume(T,p,e) ( ((p) + sizeof(T) <= (e)) ? ((p) += sizeof(T), *(T*)((p) - sizeof(T))) : ((p) = (e),0) )
|
||||
#define memory_read(T,p,e) ( ((p) + sizeof(T) <= (e)) ? ( *(T*)(p)) : (0) )
|
||||
#define memory_consume(T,p,e) ( ((p) + sizeof(T) <= (e)) ? ((p) += sizeof(T), *(T*)((p) - sizeof(T))) : ((p) = (e),0) )
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Asserts
|
||||
@@ -147,17 +147,37 @@
|
||||
#define set_nil(nil,p) ((p) = nil)
|
||||
|
||||
//- rjf: doubly-linked-lists
|
||||
#define dll_insert_npz(nil, f, l, p, n, next, prev) \
|
||||
(check_nil(nil, f) ? \
|
||||
((f) = (l) = (n), set_nil(nil, (n)->next), set_nil(nil, (n)->prev)) \
|
||||
: CheckNil(nil,p) ? \
|
||||
((n)->next = (f), (f)->prev = (n), (f) = (n), SetNil(nil,(n)->prev)) \
|
||||
: ((p) == (l)) ? \
|
||||
((l)->next = (n), (n)->prev = (l), (l) = (n), SetNil(nil, (n)->next)) \
|
||||
: ( ((!CheckNil(nil, p) && CheckNil(nil, (p)->next) ) ? \
|
||||
(0) \
|
||||
: ((p)->next->prev = (n))), ((n)->next = (p)->next), ((p)->next = (n)), ((n)->prev = (p))) \
|
||||
) \
|
||||
#define dll_insert_npz(nil, f, l, p, n, next, prev) ( \
|
||||
check_nil(nil, f) ? ( \
|
||||
(f) = (l) = (n), \
|
||||
set_nil(nil, (n)->next), \
|
||||
set_nil(nil, (n)->prev) \
|
||||
) \
|
||||
: ( \
|
||||
check_nil(nil,p) ? ( \
|
||||
(n)->next = (f), \
|
||||
(f)->prev = (n), \
|
||||
(f) = (n), \
|
||||
set_nil(nil,(n)->prev) \
|
||||
) \
|
||||
: ((p) == (l)) ? ( \
|
||||
(l)->next = (n), \
|
||||
(n)->prev = (l), \
|
||||
(l) = (n), \
|
||||
set_nil(nil, (n)->next) \
|
||||
) \
|
||||
: ( \
|
||||
( \
|
||||
( ! check_nil(nil, p) && check_nil(nil, (p)->next) ) ? \
|
||||
(0) \
|
||||
: ( (p)->next->prev = (n) ) \
|
||||
), \
|
||||
((n)->next = (p)->next), \
|
||||
((p)->next = (n)), \
|
||||
((n)->prev = (p)) \
|
||||
) \
|
||||
) \
|
||||
) \
|
||||
|
||||
#define dll_push_back_npz(nil, f, l, n, next, prev) dll_insert_npz(nil, f, l, l, n, next, prev)
|
||||
#define dll_push_front_npz(nil, f, l, n, next, prev) dll_insert_npz(nil, l, f, f, n, prev, next)
|
||||
@@ -173,13 +193,21 @@
|
||||
(l) = (l)->prev \
|
||||
: (0) \
|
||||
), \
|
||||
(CheckNil(nil,(n)->prev) ? (0) :\
|
||||
((n)->prev->next = (n)->next)),\
|
||||
(CheckNil(nil,(n)->next) ? (0) :\
|
||||
((n)->next->prev = (n)->prev)))
|
||||
( \
|
||||
CheckNil(nil,(n)->prev) ? \
|
||||
(0) \
|
||||
: ((n)->prev->next = (n)->next) \
|
||||
), \
|
||||
( \
|
||||
CheckNil(nil,(n)->next) ? \
|
||||
(0) \
|
||||
: ((n)->next->prev = (n)->prev) \
|
||||
) \
|
||||
)
|
||||
|
||||
//- rjf: singly-linked, doubly-headed lists (queues)
|
||||
#define SLLQueuePush_NZ(nil,f,l,n,next) (CheckNil(nil,f)?\
|
||||
#define SLLQueuePush_NZ(nil,f,l,n,next) ( \
|
||||
CheckNil(nil,f)?\
|
||||
((f)=(l)=(n),SetNil(nil,(n)->next)):\
|
||||
((l)->next=(n),(l)=(n),SetNil(nil,(n)->next)))
|
||||
#define SLLQueuePushFront_NZ(nil,f,l,n,next) (CheckNil(nil,f)?\
|
||||
@@ -238,8 +266,8 @@
|
||||
|
||||
#if ASAN_ENABLED
|
||||
#pragma comment(lib, "clang_rt.asan-x86_64.lib")
|
||||
C_LINKAGE void __asan_poison_memory_region(void const volatile *addr, size_t size);
|
||||
C_LINKAGE void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
|
||||
MD_C_API void __asan_poison_memory_region(void const volatile *addr, size_t size);
|
||||
MD_C_API void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
|
||||
# define AsanPoisonMemoryRegion(addr, size) __asan_poison_memory_region((addr), (size))
|
||||
# define AsanUnpoisonMemoryRegion(addr, size) __asan_unpoison_memory_region((addr), (size))
|
||||
#else
|
||||
|
||||
@@ -119,4 +119,3 @@ constexpr AllocatorInfo heap( void ) { AllocatorInfo allocator = { heap_allocato
|
||||
|
||||
//! Helper to free memory allocated by heap allocator.
|
||||
#define mfree( ptr ) free( heap(), ptr )
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifdef MD_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "cracking_arch.h"
|
||||
# pragma once
|
||||
# include "cracking_compiler.h"
|
||||
#endif
|
||||
|
||||
// C++ namespace support
|
||||
@@ -10,14 +10,15 @@
|
||||
# define MD_NS_BEGIN
|
||||
# define MD_NS_END
|
||||
# else
|
||||
# define MD_NS ::
|
||||
# define MD_NS ::
|
||||
# define MD_NS_BEGIN
|
||||
# define MD_NS_END
|
||||
# endif
|
||||
#else
|
||||
namespace MD {}
|
||||
namespace md = MD;
|
||||
# define MD_NS MD::
|
||||
# define MD_NS_BEGIN namespace MD {
|
||||
# define MD_NS_END }
|
||||
|
||||
# define MD_NS MD::
|
||||
# define MD_NS_BEGIN namespace MD {
|
||||
# define MD_NS_END }
|
||||
#endif
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
#if MD_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "cracking_arch.h"
|
||||
#include "cracking_os.h"
|
||||
#include "cracking_compiler.h"
|
||||
# pragma once
|
||||
# include "context_cracking.h"
|
||||
#endif
|
||||
|
||||
#pragma region Mandatory Includes
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -18,5 +14,3 @@
|
||||
# include <assert.h>
|
||||
# include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#pragma endregion Mandatory Includes
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
@@ -0,0 +1,74 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef BASE_PROFILE_H
|
||||
#define BASE_PROFILE_H
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Zero Settings
|
||||
|
||||
#if !defined(PROFILE_TELEMETRY)
|
||||
# define PROFILE_TELEMETRY 0
|
||||
#endif
|
||||
|
||||
#if !defined(MARKUP_LAYER_COLOR)
|
||||
# define MARKUP_LAYER_COLOR 1.00f, 0.00f, 1.00f
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Third Party Includes
|
||||
|
||||
#if PROFILE_TELEMETRY
|
||||
# include "rad_tm.h"
|
||||
# if OS_WINDOWS
|
||||
# pragma comment(lib, "rad_tm_win64.lib")
|
||||
# endif
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Telemetry Profile Defines
|
||||
|
||||
#if PROFILE_TELEMETRY
|
||||
# define ProfBegin(...) tmEnter(0, 0, __VA_ARGS__)
|
||||
# define ProfBeginDynamic(...) (TM_API_PTR ? TM_API_PTR->_tmEnterZoneV_Core(0, 0, __FILE__, &g_telemetry_filename_id, __LINE__, __VA_ARGS__) : (void)0)
|
||||
# define ProfEnd(...) (TM_API_PTR ? TM_API_PTR->_tmLeaveZone(0) : (void)0)
|
||||
# define ProfTick(...) tmTick(0)
|
||||
# define ProfIsCapturing(...) tmRunning()
|
||||
# define ProfBeginCapture(...) tmOpen(0, __VA_ARGS__, __DATE__, "localhost", TMCT_TCP, TELEMETRY_DEFAULT_PORT, TMOF_INIT_NETWORKING|TMOF_CAPTURE_CONTEXT_SWITCHES, 100)
|
||||
# define ProfEndCapture(...) tmClose(0)
|
||||
# define ProfThreadName(...) (TM_API_PTR ? TM_API_PTR->_tmThreadName(0, 0, __VA_ARGS__) : (void)0)
|
||||
# define ProfMsg(...) (TM_API_PTR ? TM_API_PTR->_tmMessageV_Core(0, TMMF_ICON_NOTE, __FILE__, &g_telemetry_filename_id, __LINE__, __VA_ARGS__) : (void)0)
|
||||
# define ProfBeginLockWait(...) tmStartWaitForLock(0, 0, __VA_ARGS__)
|
||||
# define ProfEndLockWait(...) tmEndWaitForLock(0)
|
||||
# define ProfLockTake(...) tmAcquiredLock(0, 0, __VA_ARGS__)
|
||||
# define ProfLockDrop(...) tmReleasedLock(0, __VA_ARGS__)
|
||||
# define ProfColor(color) tmZoneColorSticky(color)
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Zeroify Undefined Defines
|
||||
|
||||
#if !defined(ProfBegin)
|
||||
# define ProfBegin(...) (0)
|
||||
# define ProfBeginDynamic(...) (0)
|
||||
# define ProfEnd(...) (0)
|
||||
# define ProfTick(...) (0)
|
||||
# define ProfIsCapturing(...) (0)
|
||||
# define ProfBeginCapture(...) (0)
|
||||
# define ProfEndCapture(...) (0)
|
||||
# define ProfThreadName(...) (0)
|
||||
# define ProfMsg(...) (0)
|
||||
# define ProfBeginLockWait(...) (0)
|
||||
# define ProfEndLockWait(...) (0)
|
||||
# define ProfLockTake(...) (0)
|
||||
# define ProfLockDrop(...) (0)
|
||||
# define ProfColor(...) (0)
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Helper Wrappers
|
||||
|
||||
#define ProfBeginFunction(...) ProfBegin(this_function_name)
|
||||
#define ProfScope(...) DeferLoop(ProfBeginDynamic(__VA_ARGS__), ProfEnd())
|
||||
|
||||
#endif // BASE_PROFILE_H
|
||||
@@ -0,0 +1,4 @@
|
||||
#ifdef MD_INTELLISENSE_DIRECTIVES
|
||||
#include "text.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
#ifdef MD_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
////////////////////////////////
|
||||
// NOTE(allen): Thread Context Functions
|
||||
|
||||
C_LINKAGE thread_static TCTX* tctx_thread_local;
|
||||
#if !BUILD_SUPPLEMENTARY_UNIT
|
||||
C_LINKAGE thread_static TCTX* tctx_thread_local = 0;
|
||||
#endif
|
||||
|
||||
internal void
|
||||
tctx_init_and_equip(TCTX *tctx){
|
||||
MemoryZeroStruct(tctx);
|
||||
Arena **arena_ptr = tctx->arenas;
|
||||
for (U64 i = 0; i < ArrayCount(tctx->arenas); i += 1, arena_ptr += 1){
|
||||
*arena_ptr = arena_alloc();
|
||||
}
|
||||
tctx_thread_local = tctx;
|
||||
}
|
||||
|
||||
internal void
|
||||
tctx_release(void)
|
||||
{
|
||||
for(U64 i = 0; i < ArrayCount(tctx_thread_local->arenas); i += 1)
|
||||
{
|
||||
arena_release(tctx_thread_local->arenas[i]);
|
||||
}
|
||||
}
|
||||
|
||||
internal TCTX*
|
||||
tctx_get_equipped(void){
|
||||
return(tctx_thread_local);
|
||||
}
|
||||
|
||||
internal Arena*
|
||||
tctx_get_scratch(Arena **conflicts, U64 count){
|
||||
TCTX *tctx = tctx_get_equipped();
|
||||
|
||||
Arena *result = 0;
|
||||
Arena **arena_ptr = tctx->arenas;
|
||||
for (U64 i = 0; i < ArrayCount(tctx->arenas); i += 1, arena_ptr += 1){
|
||||
Arena **conflict_ptr = conflicts;
|
||||
B32 has_conflict = 0;
|
||||
for (U64 j = 0; j < count; j += 1, conflict_ptr += 1){
|
||||
if (*arena_ptr == *conflict_ptr){
|
||||
has_conflict = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!has_conflict){
|
||||
result = *arena_ptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal void
|
||||
tctx_set_thread_name(String8 string){
|
||||
TCTX *tctx = tctx_get_equipped();
|
||||
U64 size = ClampTop(string.size, sizeof(tctx->thread_name));
|
||||
MemoryCopy(tctx->thread_name, string.str, size);
|
||||
tctx->thread_name_size = size;
|
||||
}
|
||||
|
||||
internal String8
|
||||
tctx_get_thread_name(void){
|
||||
TCTX *tctx = tctx_get_equipped();
|
||||
String8 result = str8(tctx->thread_name, tctx->thread_name_size);
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal void
|
||||
tctx_write_srcloc(char *file_name, U64 line_number){
|
||||
TCTX *tctx = tctx_get_equipped();
|
||||
tctx->file_name = file_name;
|
||||
tctx->line_number = line_number;
|
||||
}
|
||||
|
||||
internal void
|
||||
tctx_read_srcloc(char **file_name, U64 *line_number){
|
||||
TCTX *tctx = tctx_get_equipped();
|
||||
*file_name = tctx->file_name;
|
||||
*line_number = tctx->line_number;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef BASE_THREAD_CONTEXT_H
|
||||
#define BASE_THREAD_CONTEXT_H
|
||||
|
||||
////////////////////////////////
|
||||
// NOTE(allen): Thread Context
|
||||
|
||||
typedef struct TCTX TCTX;
|
||||
struct TCTX
|
||||
{
|
||||
Arena *arenas[2];
|
||||
|
||||
U8 thread_name[32];
|
||||
U64 thread_name_size;
|
||||
|
||||
char *file_name;
|
||||
U64 line_number;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
// NOTE(allen): Thread Context Functions
|
||||
|
||||
internal void tctx_init_and_equip(TCTX *tctx);
|
||||
internal void tctx_release(void);
|
||||
internal TCTX* tctx_get_equipped(void);
|
||||
|
||||
internal Arena* tctx_get_scratch(Arena **conflicts, U64 count);
|
||||
|
||||
internal void tctx_set_thread_name(String8 name);
|
||||
internal String8 tctx_get_thread_name(void);
|
||||
|
||||
internal void tctx_write_srcloc(char *file_name, U64 line_number);
|
||||
internal void tctx_read_srcloc(char **file_name, U64 *line_number);
|
||||
#define tctx_write_this_srcloc() tctx_write_srcloc(__FILE__, __LINE__)
|
||||
|
||||
#define scratch_begin(conflicts, count) temp_begin(tctx_get_scratch((conflicts), (count)))
|
||||
#define scratch_end(scratch) temp_end(scratch)
|
||||
|
||||
#endif // BASE_THREAD_CONTEXT_H
|
||||
@@ -0,0 +1,5 @@
|
||||
#ifdef MD_INTELLISENSE_DIRECTIVES
|
||||
#include "toolchain.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user