mirror of
https://github.com/Ed94/metadesk.git
synced 2026-08-06 15:48:47 +00:00
draft of base.c
This commit is contained in:
@@ -2,4 +2,22 @@
|
|||||||
# include "base.h"
|
# include "base.h"
|
||||||
#endif
|
#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
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ MD_NS_BEGIN
|
|||||||
#include "sort.h"
|
#include "sort.h"
|
||||||
#include "toolchain.h"
|
#include "toolchain.h"
|
||||||
#include "strings.h"
|
#include "strings.h"
|
||||||
|
#include "text.h"
|
||||||
#include "thread_context.h"
|
#include "thread_context.h"
|
||||||
#include "command_line.h"
|
#include "command_line.h"
|
||||||
#include "markup.h"
|
#include "markup.h"
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
#ifdef INTELLISENSE_DIRECTIVES
|
|
||||||
# pragma once
|
|
||||||
# include "base_types.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
+8
-7
@@ -1,25 +1,26 @@
|
|||||||
#ifdef INTELLISENSE_DIRECTIVES
|
#ifdef INTELLISENSE_DIRECTIVES
|
||||||
# include "strings.h"
|
# include "strings.h"
|
||||||
# include "debug.h"
|
# include "debug.h"
|
||||||
|
# include "platform.c"
|
||||||
#endif
|
#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, ... )
|
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
|
md__printf_err( "%s - %s:(%d): Assert Failure: ", file, function, line );
|
||||||
_printf_err( "%s - %s:(%d): Assert Failure: ", file, function, line );
|
|
||||||
|
|
||||||
if ( condition )
|
if ( condition )
|
||||||
// TODO(Ed): Change this to metadesks's procs
|
md__printf_err( "`%s` \n", condition );
|
||||||
_printf_err( "`%s` \n", condition );
|
|
||||||
|
|
||||||
if ( msg )
|
if ( msg )
|
||||||
{
|
{
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start( va, msg );
|
va_start( va, msg );
|
||||||
_printf_err_va( msg, va );
|
md__printf_err_va( msg, va );
|
||||||
va_end( va );
|
va_end( va );
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(Ed): Change this to metadesks's procs
|
md__printf_err( "%s", "\n" );
|
||||||
_printf_err( "%s", "\n" );
|
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-10
@@ -6,15 +6,17 @@
|
|||||||
# include "base_types.h"
|
# include "base_types.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// TODO(Ed): Review this
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Asserts
|
//~ rjf: Asserts
|
||||||
|
|
||||||
#ifndef trap
|
#ifndef trap
|
||||||
# if COMPILER_MSVC
|
# if COMPILER_MSVC
|
||||||
# if _MSC_VER < 1300
|
# 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
|
# else
|
||||||
# define GEN_DEBUG_TRAP() __debugbreak()
|
# define MD_DEBUG_TRAP() __debugbreak()
|
||||||
# endif
|
# endif
|
||||||
# elif COMPILER_CLANG || COMPILER_GCC
|
# elif COMPILER_CLANG || COMPILER_GCC
|
||||||
# define trap() __builtin_trap()
|
# define trap() __builtin_trap()
|
||||||
@@ -23,14 +25,14 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define assert_msg( cond, msg, ... ) \
|
#define assert_msg( cond, msg, ... ) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
if ( ! ( cond ) ) \
|
if ( ! ( cond ) ) \
|
||||||
{ \
|
{ \
|
||||||
assert_handler( #cond, __FILE__, __func__, scast( S64, __LINE__ ), msg, ##__VA_ARGS__ ); \
|
assert_handler( #cond, __FILE__, __func__, scast( S64, __LINE__ ), msg, ##__VA_ARGS__ ); \
|
||||||
GEN_DEBUG_TRAP(); \
|
MD_DEBUG_TRAP(); \
|
||||||
} \
|
} \
|
||||||
} while ( 0 )
|
} while ( 0 )
|
||||||
|
|
||||||
#ifndef assert_always
|
#ifndef assert_always
|
||||||
|
|||||||
@@ -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);
|
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);
|
CmdLine cmdline = cmd_line_from_string_list(scratch.arena, command_line_argument_strings);
|
||||||
B32 capture = cmd_line_has_flag(&cmdline, str8_lit("capture"));
|
B32 capture = cmd_line_has_flag(&cmdline, str8_lit("capture"));
|
||||||
if(capture)
|
if (capture) {
|
||||||
{
|
|
||||||
prof_begin_capture(arguments[0]);
|
prof_begin_capture(arguments[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
entry_point(&cmdline);
|
entry_point(&cmdline);
|
||||||
|
|
||||||
if(capture)
|
if (capture) {
|
||||||
{
|
|
||||||
prof_end_capture();
|
prof_end_capture();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
@@ -7,7 +7,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/)
|
||||||
|
|
||||||
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
|
inline void
|
||||||
set_thread_namef(char *fmt, ...)
|
set_thread_namef(char *fmt, ...)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#ifdef INTELLISENSE_DIRECTIVES
|
#ifdef INTELLISENSE_DIRECTIVES
|
||||||
# pragma once
|
|
||||||
# include "platform.h"
|
# include "platform.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
// Copyright (c) 2024 Epic Games Tools
|
|
||||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
|
||||||
+1
-103
@@ -2,112 +2,10 @@
|
|||||||
# include "text.h"
|
# include "text.h"
|
||||||
#endif
|
#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
|
//~ rjf: Text Path Helpers
|
||||||
|
|
||||||
internal String8TxtPtPair
|
String8TxtPtPair
|
||||||
str8_txt_pt_pair_from_string(String8 string)
|
str8_txt_pt_pair_from_string(String8 string)
|
||||||
{
|
{
|
||||||
String8TxtPtPair pair = {0};
|
String8TxtPtPair pair = {0};
|
||||||
|
|||||||
+71
-15
@@ -9,15 +9,15 @@
|
|||||||
typedef struct TxtPt TxtPt;
|
typedef struct TxtPt TxtPt;
|
||||||
struct TxtPt
|
struct TxtPt
|
||||||
{
|
{
|
||||||
S64 line;
|
S64 line;
|
||||||
S64 column;
|
S64 column;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct TxtRng TxtRng;
|
typedef struct TxtRng TxtRng;
|
||||||
struct TxtRng
|
struct TxtRng
|
||||||
{
|
{
|
||||||
TxtPt min;
|
TxtPt min;
|
||||||
TxtPt max;
|
TxtPt max;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
@@ -26,8 +26,8 @@ struct TxtRng
|
|||||||
typedef struct String8TxtPtPair String8TxtPtPair;
|
typedef struct String8TxtPtPair String8TxtPtPair;
|
||||||
struct String8TxtPtPair
|
struct String8TxtPtPair
|
||||||
{
|
{
|
||||||
String8 string;
|
String8 string;
|
||||||
TxtPt pt;
|
TxtPt pt;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
@@ -38,13 +38,69 @@ MD_API String8TxtPtPair str8_txt_pt_pair_from_string(String8 string);
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Text 2D Coordinate/Range Functions
|
//~ rjf: Text 2D Coordinate/Range Functions
|
||||||
|
|
||||||
TxtPt txt_pt(S64 line, S64 column);
|
inline TxtPt txt_pt(S64 line, S64 column) { TxtPt p = { line, column }; return p; }
|
||||||
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 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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
#ifdef INTELLISENSE_DIRECTIVES
|
|
||||||
#include "toolchain.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user