diff --git a/code/base/base.c b/code/base/base.c index ce7a429..d75c124 100644 --- a/code/base/base.c +++ b/code/base/base.c @@ -2,4 +2,22 @@ # include "base.h" #endif +#undef MARKUP_LAYER_COLOR +#define MARKUP_LAYER_COLOR 0.20f, 0.60f, 0.80f +#include "platform.c" + +MD_NS_BEGIN + +#include "debug.c" +#include "memory_substrate.c" +#include "arena.c" +#include "strings.c" +#include "text.c" +#include "thread_context.c" +#include "command_line.c" +#include "logger.c" +#include "entry_point.c" +#include "time.c" + +MD_NS_END diff --git a/code/base/base.h b/code/base/base.h index ebf45df..c881c59 100644 --- a/code/base/base.h +++ b/code/base/base.h @@ -23,6 +23,7 @@ MD_NS_BEGIN #include "sort.h" #include "toolchain.h" #include "strings.h" +#include "text.h" #include "thread_context.h" #include "command_line.h" #include "markup.h" diff --git a/code/base/base_types.c b/code/base/base_types.c deleted file mode 100644 index 21e2ecf..0000000 --- a/code/base/base_types.c +++ /dev/null @@ -1,6 +0,0 @@ -#ifdef INTELLISENSE_DIRECTIVES -# pragma once -# include "base_types.h" -#endif - - diff --git a/code/base/debug.c b/code/base/debug.c index 5de2530..a313553 100644 --- a/code/base/debug.c +++ b/code/base/debug.c @@ -1,25 +1,26 @@ #ifdef INTELLISENSE_DIRECTIVES # include "strings.h" # include "debug.h" +# include "platform.c" #endif +#define md__printf_err( fmt, ... ) fprintf( stderr, fmt, __VA_ARGS__ ) +#define md__printf_err_va( fmt, va ) vfprintf( stderr, fmt, va ) + void assert_handler( char const* condition, char const* file, char const* function, S32 line, char const* msg, ... ) { - // TODO(Ed): Change this to metadesks's procs - _printf_err( "%s - %s:(%d): Assert Failure: ", file, function, line ); + md__printf_err( "%s - %s:(%d): Assert Failure: ", file, function, line ); if ( condition ) - // TODO(Ed): Change this to metadesks's procs - _printf_err( "`%s` \n", condition ); + md__printf_err( "`%s` \n", condition ); if ( msg ) { va_list va; va_start( va, msg ); - _printf_err_va( msg, va ); + md__printf_err_va( msg, va ); va_end( va ); } - // TODO(Ed): Change this to metadesks's procs - _printf_err( "%s", "\n" ); + md__printf_err( "%s", "\n" ); } diff --git a/code/base/debug.h b/code/base/debug.h index e31281c..e078dee 100644 --- a/code/base/debug.h +++ b/code/base/debug.h @@ -6,15 +6,17 @@ # include "base_types.h" #endif +// TODO(Ed): Review this + //////////////////////////////// //~ rjf: Asserts #ifndef trap # if COMPILER_MSVC # if _MSC_VER < 1300 -# define GEN_DEBUG_TRAP() __asm int 3 /* Trap to debugger! */ +# define MD_DEBUG_TRAP() __asm int 3 /* Trap to debugger! */ # else -# define GEN_DEBUG_TRAP() __debugbreak() +# define MD_DEBUG_TRAP() __debugbreak() # endif # elif COMPILER_CLANG || COMPILER_GCC # define trap() __builtin_trap() @@ -23,14 +25,14 @@ # endif #endif -#define assert_msg( cond, msg, ... ) \ - do \ - { \ - if ( ! ( cond ) ) \ - { \ - assert_handler( #cond, __FILE__, __func__, scast( S64, __LINE__ ), msg, ##__VA_ARGS__ ); \ - GEN_DEBUG_TRAP(); \ - } \ +#define assert_msg( cond, msg, ... ) \ + do \ + { \ + if ( ! ( cond ) ) \ + { \ + assert_handler( #cond, __FILE__, __func__, scast( S64, __LINE__ ), msg, ##__VA_ARGS__ ); \ + MD_DEBUG_TRAP(); \ + } \ } while ( 0 ) #ifndef assert_always diff --git a/code/base/entry_point.c b/code/base/entry_point.c index 7c3308c..56aec48 100644 --- a/code/base/entry_point.c +++ b/code/base/entry_point.c @@ -25,15 +25,13 @@ void main_thread_base_entry_point(MainThread_EntryPointProc* entry_point, char** 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) - { + if (capture) { prof_begin_capture(arguments[0]); } entry_point(&cmdline); - if(capture) - { + if (capture) { prof_end_capture(); } diff --git a/code/base/markup.c b/code/base/markup.c deleted file mode 100644 index 3ae280f..0000000 --- a/code/base/markup.c +++ /dev/null @@ -1,13 +0,0 @@ -#ifdef INTELLISENSE_DIRECTIVES -# include "markup.h" -# include "os/os.h" -#endif - -// Copyright (c) 2024 Epic Games Tools -// Licensed under the MIT license (https://opensource.org/license/mit/) - -void -set_thread_name(String8 string) { - prof_thread_name("%.*s", str8_varg(string)); - os_set_thread_name(string); -} diff --git a/code/base/markup.h b/code/base/markup.h index 5de7e69..f0636ae 100644 --- a/code/base/markup.h +++ b/code/base/markup.h @@ -7,7 +7,11 @@ // Copyright (c) 2024 Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) -MD_API void set_thread_name(String8 string); +inline void +set_thread_name(String8 string) { + prof_thread_name("%.*s", str8_varg(string)); + os_set_thread_name(string); +} inline void set_thread_namef(char *fmt, ...) diff --git a/code/base/platform.c b/code/base/platform.c index 679637d..1d8c149 100644 --- a/code/base/platform.c +++ b/code/base/platform.c @@ -1,6 +1,5 @@ #ifdef INTELLISENSE_DIRECTIVES -# pragma once # include "platform.h" #endif - +#include diff --git a/code/base/profiling.c b/code/base/profiling.c deleted file mode 100644 index 7ea8904..0000000 --- a/code/base/profiling.c +++ /dev/null @@ -1,2 +0,0 @@ -// Copyright (c) 2024 Epic Games Tools -// Licensed under the MIT license (https://opensource.org/license/mit/) diff --git a/code/base/text.c b/code/base/text.c index 0086f4e..a2ba48d 100644 --- a/code/base/text.c +++ b/code/base/text.c @@ -2,112 +2,10 @@ # include "text.h" #endif -//////////////////////////////// -//~ rjf: Text 2D Coordinate/Range Functions - -internal TxtPt -txt_pt(S64 line, S64 column) -{ - TxtPt p = {0}; - p.line = line; - p.column = column; - return p; -} - -internal B32 -txt_pt_match(TxtPt a, TxtPt b) -{ - return a.line == b.line && a.column == b.column; -} - -internal B32 -txt_pt_less_than(TxtPt a, TxtPt b) -{ - B32 result = 0; - if(a.line < b.line) - { - result = 1; - } - else if(a.line == b.line) - { - result = a.column < b.column; - } - return result; -} - -internal TxtPt -txt_pt_min(TxtPt a, TxtPt b) -{ - TxtPt result = b; - if(txt_pt_less_than(a, b)) - { - result = a; - } - return result; -} - -internal TxtPt -txt_pt_max(TxtPt a, TxtPt b) -{ - TxtPt result = a; - if(txt_pt_less_than(a, b)) - { - result = b; - } - return result; -} - -internal TxtRng -txt_rng(TxtPt min, TxtPt max) -{ - TxtRng range = {0}; - if(txt_pt_less_than(min, max)) - { - range.min = min; - range.max = max; - } - else - { - range.min = max; - range.max = min; - } - return range; -} - -internal TxtRng -txt_rng_intersect(TxtRng a, TxtRng b) -{ - TxtRng result = {0}; - result.min = txt_pt_max(a.min, b.min); - result.max = txt_pt_min(a.max, b.max); - if(txt_pt_less_than(result.max, result.min)) - { - MemoryZeroStruct(&result); - } - return result; -} - -internal TxtRng -txt_rng_union(TxtRng a, TxtRng b) -{ - TxtRng result = {0}; - result.min = txt_pt_min(a.min, b.min); - result.max = txt_pt_max(a.max, b.max); - return result; -} - -internal B32 -txt_rng_contains(TxtRng r, TxtPt pt) -{ - B32 result = ((txt_pt_less_than(r.min, pt) || txt_pt_match(r.min, pt)) && - txt_pt_less_than(pt, r.max)); - return result; -} - //////////////////////////////// //~ rjf: Text Path Helpers -internal String8TxtPtPair +String8TxtPtPair str8_txt_pt_pair_from_string(String8 string) { String8TxtPtPair pair = {0}; diff --git a/code/base/text.h b/code/base/text.h index 7c0a6bc..2ddf599 100644 --- a/code/base/text.h +++ b/code/base/text.h @@ -9,15 +9,15 @@ typedef struct TxtPt TxtPt; struct TxtPt { - S64 line; - S64 column; + S64 line; + S64 column; }; typedef struct TxtRng TxtRng; struct TxtRng { - TxtPt min; - TxtPt max; + TxtPt min; + TxtPt max; }; //////////////////////////////// @@ -26,8 +26,8 @@ struct TxtRng typedef struct String8TxtPtPair String8TxtPtPair; struct String8TxtPtPair { - String8 string; - TxtPt pt; + String8 string; + TxtPt pt; }; //////////////////////////////// @@ -38,13 +38,69 @@ MD_API String8TxtPtPair str8_txt_pt_pair_from_string(String8 string); //////////////////////////////// //~ rjf: Text 2D Coordinate/Range Functions -TxtPt txt_pt(S64 line, S64 column); -B32 txt_pt_match(TxtPt a, TxtPt b); -B32 txt_pt_less_than(TxtPt a, TxtPt b); -TxtPt txt_pt_min(TxtPt a, TxtPt b); -TxtPt txt_pt_max(TxtPt a, TxtPt b); -TxtRng txt_rng(TxtPt min, TxtPt max); -TxtRng txt_rng_intersect(TxtRng a, TxtRng b); -TxtRng txt_rng_union(TxtRng a, TxtRng b); -B32 txt_rng_contains(TxtRng r, TxtPt pt); +inline TxtPt txt_pt(S64 line, S64 column) { TxtPt p = { line, column }; return p; } +inline B32 txt_pt_match(TxtPt a, TxtPt b) { return a.line == b.line && a.column == b.column; } +inline TxtPt txt_pt_min (TxtPt a, TxtPt b) { TxtPt result = b; if (txt_pt_less_than(a, b)) { result = a; } return result; } +inline TxtPt txt_pt_max (TxtPt a, TxtPt b) { TxtPt result = a; if (txt_pt_less_than(a, b)) { result = b; } return result; } + +B32 txt_pt_less_than (TxtPt a, TxtPt b); +TxtRng txt_rng (TxtPt min, TxtPt max); +TxtRng txt_rng_intersect(TxtRng a, TxtRng b); +TxtRng txt_rng_union (TxtRng a, TxtRng b); +B32 txt_rng_contains (TxtRng r, TxtPt pt); + +inline B32 +txt_pt_less_than(TxtPt a, TxtPt b) +{ + B32 result = 0; + if (a.line < b.line) { + result = 1; + } + else if (a.line == b.line) { + result = a.column < b.column; + } + return result; +} + +inline TxtRng +txt_rng(TxtPt min, TxtPt max) +{ + TxtRng range = {0}; + if(txt_pt_less_than(min, max)) { + range.min = min; + range.max = max; + } + else { + range.min = max; + range.max = min; + } + return range; +} + +inline TxtRng +txt_rng_intersect(TxtRng a, TxtRng b) +{ + TxtRng result = {0}; + result.min = txt_pt_max(a.min, b.min); + result.max = txt_pt_min(a.max, b.max); + if (txt_pt_less_than(result.max, result.min)) { + MemoryZeroStruct(&result); + } + return result; +} + +inline TxtRng +txt_rng_union(TxtRng a, TxtRng b) +{ + TxtRng result = {0}; + result.min = txt_pt_min(a.min, b.min); + result.max = txt_pt_max(a.max, b.max); + return result; +} + +inline B32 +txt_rng_contains(TxtRng r, TxtPt pt) { + B32 result = ((txt_pt_less_than(r.min, pt) || txt_pt_match(r.min, pt)) && txt_pt_less_than(pt, r.max)); + return result; +} diff --git a/code/base/toolchain.c b/code/base/toolchain.c deleted file mode 100644 index 9feb887..0000000 --- a/code/base/toolchain.c +++ /dev/null @@ -1,5 +0,0 @@ -#ifdef INTELLISENSE_DIRECTIVES -#include "toolchain.h" -#endif - -