draft of base.c

This commit is contained in:
2025-02-08 20:02:31 -05:00
parent 843cc7fa90
commit ad47dc037f
13 changed files with 119 additions and 168 deletions
+18
View File
@@ -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
+1
View File
@@ -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"
-6
View File
@@ -1,6 +0,0 @@
#ifdef INTELLISENSE_DIRECTIVES
# pragma once
# include "base_types.h"
#endif
+8 -7
View File
@@ -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" );
}
+12 -10
View File
@@ -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
+2 -4
View File
@@ -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();
}
-13
View File
@@ -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);
}
+5 -1
View File
@@ -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, ...)
+1 -2
View File
@@ -1,6 +1,5 @@
#ifdef INTELLISENSE_DIRECTIVES
# pragma once
# include "platform.h"
#endif
#include <stdio.h>
-2
View File
@@ -1,2 +0,0 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
+1 -103
View File
@@ -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};
+71 -15
View File
@@ -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;
}
-5
View File
@@ -1,5 +0,0 @@
#ifdef INTELLISENSE_DIRECTIVES
#include "toolchain.h"
#endif