modifications to log system to support orca env where stdio is not defined
This commit is contained in:
parent
0d6fb197fb
commit
86a16d3775
|
@ -11,8 +11,6 @@
|
|||
#include"glsl_shaders.h"
|
||||
#include"gl_api.h"
|
||||
|
||||
#define LOG_SUBSYSTEM "Graphics"
|
||||
|
||||
typedef struct mg_gl_canvas_backend
|
||||
{
|
||||
mg_canvas_backend interface;
|
||||
|
@ -498,6 +496,3 @@ mg_canvas_backend* mg_gl_canvas_create(mg_surface surface)
|
|||
|
||||
return((mg_canvas_backend*)backend);
|
||||
}
|
||||
|
||||
|
||||
#undef LOG_SUBSYSTEM
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
#include"debug_log.h"
|
||||
#include"graphics_internal.h"
|
||||
|
||||
#define LOG_SUBSYSTEM "Graphics"
|
||||
|
||||
typedef struct mg_glyph_map_entry
|
||||
{
|
||||
unicode_range range;
|
||||
|
@ -912,8 +910,6 @@ int mg_cubic_outside_test(vec4 c)
|
|||
|
||||
void mg_render_fill_cubic(mg_canvas_data* canvas, vec2 p[4])
|
||||
{
|
||||
LOG_DEBUG("graphics render fill cubic\n");
|
||||
|
||||
vec4 testCoords[4];
|
||||
|
||||
/*NOTE(martin): first convert the control points to power basis, multiplying by M3
|
||||
|
@ -975,8 +971,6 @@ void mg_render_fill_cubic(mg_canvas_data* canvas, vec2 p[4])
|
|||
if(fabs(d1) < 0.1 && fabs(d2) < 0.1 && d3 != 0)
|
||||
{
|
||||
//NOTE(martin): quadratic degenerate case
|
||||
LOG_DEBUG("quadratic curve\n");
|
||||
|
||||
//NOTE(martin): compute quadratic curve control point, which is at p0 + 1.5*(p1-p0) = 1.5*p1 - 0.5*p0
|
||||
vec2 quadControlPoints[3] = { p[0],
|
||||
{1.5*p[1].x - 0.5*p[0].x, 1.5*p[1].y - 0.5*p[0].y},
|
||||
|
@ -990,8 +984,6 @@ void mg_render_fill_cubic(mg_canvas_data* canvas, vec2 p[4])
|
|||
{
|
||||
//NOTE(martin): serpentine curve or cusp with inflection at infinity
|
||||
// (these two cases are handled the same way).
|
||||
LOG_DEBUG("%s\n", (discrFactor2 > 0 && d1 != 0) ? "serpentine curve" : "cusp with inflection at infinity");
|
||||
|
||||
//NOTE(martin): compute the solutions (tl, sl), (tm, sm), and (tn, sn) of the inflection point equation
|
||||
f32 tl = d2 + sqrt(discrFactor2/3);
|
||||
f32 sl = 2*d1;
|
||||
|
@ -1034,8 +1026,6 @@ void mg_render_fill_cubic(mg_canvas_data* canvas, vec2 p[4])
|
|||
else if(discrFactor2 < 0 && d1 != 0)
|
||||
{
|
||||
//NOTE(martin): loop curve
|
||||
LOG_DEBUG("loop curve\n");
|
||||
|
||||
f32 td = d2 + sqrt(-discrFactor2);
|
||||
f32 sd = 2*d1;
|
||||
f32 te = d2 - sqrt(-discrFactor2);
|
||||
|
@ -1050,13 +1040,11 @@ void mg_render_fill_cubic(mg_canvas_data* canvas, vec2 p[4])
|
|||
|
||||
if(sd != 0 && td/sd < 0.99 && td/sd > 0.01)
|
||||
{
|
||||
LOG_DEBUG("split curve at first double point\n");
|
||||
mg_split_and_fill_cubic(canvas, p, td/sd);
|
||||
return;
|
||||
}
|
||||
if(se != 0 && te/se < 0.99 && te/se > 0.01)
|
||||
{
|
||||
LOG_DEBUG("split curve at second double point\n");
|
||||
mg_split_and_fill_cubic(canvas, p, te/se);
|
||||
return;
|
||||
}
|
||||
|
@ -1097,7 +1085,6 @@ void mg_render_fill_cubic(mg_canvas_data* canvas, vec2 p[4])
|
|||
else if(d1 == 0 && d2 != 0)
|
||||
{
|
||||
//NOTE(martin): cusp with cusp at infinity
|
||||
LOG_DEBUG("cusp at infinity curve\n");
|
||||
|
||||
f32 tl = d3;
|
||||
f32 sl = 3*d2;
|
||||
|
@ -1139,13 +1126,11 @@ void mg_render_fill_cubic(mg_canvas_data* canvas, vec2 p[4])
|
|||
else if(d1 == 0 && d2 == 0 && d3 == 0)
|
||||
{
|
||||
//NOTE(martin): line or point degenerate case, ignored
|
||||
LOG_DEBUG("line or point curve (ignored)\n");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO(martin): handle error ? put some epsilon slack on the conditions ?
|
||||
LOG_DEBUG("none of the above...\n");
|
||||
ASSERT(0, "not implemented yet !");
|
||||
return;
|
||||
}
|
||||
|
@ -3754,5 +3739,3 @@ void mg_image_atlas_recycle(mg_rect_atlas* atlas, mg_image_region imageRgn)
|
|||
{
|
||||
mg_rect_atlas_recycle(atlas, imageRgn.rect);
|
||||
}
|
||||
|
||||
#undef LOG_SUBSYSTEM
|
||||
|
|
119
src/main.c
119
src/main.c
|
@ -1,119 +0,0 @@
|
|||
/************************************************************//**
|
||||
*
|
||||
* @file: main.cpp
|
||||
* @author: Martin Fouilleul
|
||||
* @date: 30/07/2022
|
||||
* @revision:
|
||||
*
|
||||
*****************************************************************/
|
||||
#include<stdlib.h>
|
||||
#include<string.h>
|
||||
#include<errno.h>
|
||||
|
||||
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC
|
||||
#include<math.h>
|
||||
|
||||
#include"milepost.h"
|
||||
|
||||
#define LOG_SUBSYSTEM "Main"
|
||||
|
||||
int main()
|
||||
{
|
||||
LogLevel(LOG_LEVEL_WARNING);
|
||||
|
||||
mp_init();
|
||||
mp_clock_init(); //TODO put that in mp_init()?
|
||||
|
||||
mp_rect windowRect = {.x = 100, .y = 100, .w = 810, .h = 610};
|
||||
mp_window window = mp_window_create(windowRect, "test", 0);
|
||||
|
||||
mp_rect contentRect = mp_window_get_content_rect(window);
|
||||
|
||||
//NOTE: create surface
|
||||
mg_surface surface = mg_surface_create_for_window(window, MG_BACKEND_DEFAULT);
|
||||
mg_surface_swap_interval(surface, 0);
|
||||
|
||||
//NOTE: create canvas
|
||||
mg_canvas canvas = mg_canvas_create(surface);
|
||||
if(mg_canvas_is_nil(canvas))
|
||||
{
|
||||
printf("Error: couldn't create canvas\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
//NOTE: create image
|
||||
str8 imagePath = mp_app_get_resource_path(mem_scratch(), "../resources/triceratops.png");
|
||||
mg_image image = mg_image_create_from_file(imagePath, true);
|
||||
vec2 imageSize = mg_image_size(image);
|
||||
|
||||
str8 imagePath2 = mp_app_get_resource_path(mem_scratch(), "../resources/Top512.png");
|
||||
mg_image image2 = mg_image_create_from_file(imagePath2, true);
|
||||
vec2 imageSize2 = mg_image_size(image2);
|
||||
|
||||
// start app
|
||||
mp_window_bring_to_front(window);
|
||||
mp_window_focus(window);
|
||||
|
||||
while(!mp_should_quit())
|
||||
{
|
||||
mp_pump_events(0);
|
||||
mp_event event = {0};
|
||||
while(mp_next_event(&event))
|
||||
{
|
||||
switch(event.type)
|
||||
{
|
||||
case MP_EVENT_WINDOW_CLOSE:
|
||||
{
|
||||
mp_request_quit();
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mg_surface_prepare(surface);
|
||||
|
||||
// background
|
||||
mg_set_color_rgba(0, 1, 1, 1);
|
||||
mg_clear();
|
||||
|
||||
mg_set_color_rgba(1, 1, 1, 1);
|
||||
|
||||
mg_matrix_push((mg_mat2x3){0.707, -0.707, 200,
|
||||
0.707, 0.707, 100});
|
||||
|
||||
mg_set_image(image);
|
||||
mg_set_image_source_region((mp_rect){500, 500, 2000, 1400});
|
||||
|
||||
//mg_rectangle_fill(100, 100, imageSize.x/8, imageSize.y/8);
|
||||
|
||||
mg_move_to(0, 0);
|
||||
mg_line_to(200, 0);
|
||||
mg_line_to(300, 100);
|
||||
mg_line_to(200, 200);
|
||||
mg_line_to(0, 200);
|
||||
mg_line_to(100, 100);
|
||||
mg_fill();
|
||||
|
||||
//mg_image_draw_rounded(image, (mp_rect){0, 0, imageSize.x/8, imageSize.y/8}, 40.);
|
||||
|
||||
mg_matrix_pop();
|
||||
|
||||
mg_image_draw(image2, (mp_rect){200, 200, 300, 300});
|
||||
|
||||
mg_flush();
|
||||
mg_surface_present(surface);
|
||||
|
||||
mem_arena_clear(mem_scratch());
|
||||
}
|
||||
|
||||
mg_image_destroy(image);
|
||||
mg_canvas_destroy(canvas);
|
||||
mg_surface_destroy(surface);
|
||||
mp_window_destroy(window);
|
||||
|
||||
mp_terminate();
|
||||
|
||||
return(0);
|
||||
}
|
|
@ -9,8 +9,6 @@
|
|||
|
||||
#include"mp_app_internal.h"
|
||||
|
||||
#define LOG_SUBSYSTEM "Application"
|
||||
|
||||
mp_app __mpApp = {0};
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
@ -407,6 +405,3 @@ str8 mp_input_text_utf8(mem_arena* arena)
|
|||
}
|
||||
return(res);
|
||||
}
|
||||
|
||||
|
||||
#undef LOG_SUBSYSTEM
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
#include"mtl_renderer.h"
|
||||
|
||||
#define LOG_SUBSYSTEM "Graphics"
|
||||
|
||||
const int MG_MTL_INPUT_BUFFERS_COUNT = 3,
|
||||
MG_MTL_TILE_SIZE = 16,
|
||||
MG_MTL_MSAA_COUNT = 8;
|
||||
|
@ -82,7 +80,7 @@ void mg_mtl_print_log(int bufferIndex, id<MTLBuffer> logBuffer, id<MTLBuffer> lo
|
|||
|
||||
if(size)
|
||||
{
|
||||
LOG_MESSAGE("Log from buffer %i:\n", bufferIndex);
|
||||
LOG_INFO("Log from buffer %i:\n", bufferIndex);
|
||||
|
||||
int index = 0;
|
||||
while(index < size)
|
||||
|
@ -1281,5 +1279,3 @@ mg_canvas_backend* mg_mtl_canvas_create(mg_surface surface)
|
|||
}
|
||||
return((mg_canvas_backend*)backend);
|
||||
}
|
||||
|
||||
#undef LOG_SUBSYSTEM
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
#include"macro_helpers.h"
|
||||
#include"osx_app.h"
|
||||
|
||||
#define LOG_SUBSYSTEM "Graphics"
|
||||
|
||||
typedef struct mg_mtl_surface
|
||||
{
|
||||
mg_surface_data interface;
|
||||
|
@ -255,6 +253,3 @@ void* mg_mtl_surface_command_buffer(mg_surface surface)
|
|||
return(nil);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#undef LOG_SUBSYSTEM
|
||||
|
|
|
@ -22,8 +22,6 @@
|
|||
|
||||
#include"mp_app.c"
|
||||
|
||||
#define LOG_SUBSYSTEM "Application"
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// mp window struct and utility functions
|
||||
//--------------------------------------------------------------------
|
||||
|
@ -1170,15 +1168,12 @@ void mp_init()
|
|||
|
||||
mp_clock_init();
|
||||
|
||||
LOG_MESSAGE("init keys\n");
|
||||
mp_init_osx_keys();
|
||||
mp_update_keyboard_layout();
|
||||
mp_install_keyboard_layout_listener();
|
||||
|
||||
LOG_MESSAGE("init handles\n");
|
||||
mp_init_window_handles();
|
||||
|
||||
LOG_MESSAGE("init event queue\n");
|
||||
ringbuffer_init(&__mpApp.eventQueue, 16);
|
||||
|
||||
[MPApplication sharedApplication];
|
||||
|
@ -1191,15 +1186,7 @@ void mp_init()
|
|||
|
||||
__mpApp.init = true;
|
||||
|
||||
LOG_MESSAGE("run application\n");
|
||||
[NSApp run];
|
||||
|
||||
/*
|
||||
CGDirectDisplayID displayID = CGMainDisplayID();
|
||||
CVDisplayLinkCreateWithCGDisplay(displayID, &__mpApp.displayLink);
|
||||
CVDisplayLinkSetOutputCallback(__mpApp.displayLink, DisplayLinkCallback, 0);
|
||||
*/
|
||||
|
||||
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
|
||||
|
@ -2309,5 +2296,3 @@ int mp_directory_create(str8 path)
|
|||
return(-1);
|
||||
}
|
||||
}}
|
||||
|
||||
#undef LOG_SUBSYSTEM
|
||||
|
|
|
@ -26,8 +26,6 @@
|
|||
typedef struct timeval timeval;
|
||||
typedef struct timespec timespec;
|
||||
|
||||
#define LOG_SUBSYSTEM "Platform"
|
||||
|
||||
//TODO(martin): measure the actual values of these constants
|
||||
const f64 SYSTEM_FUZZ = 25e-9, // minimum time to read the clock (s)
|
||||
SYSTEM_TICK = 25e-9; // minimum step between two clock readings (s)
|
||||
|
@ -172,5 +170,3 @@ void mp_sleep_nanoseconds(u64 nanoseconds)
|
|||
rqtp.tv_nsec = nanoseconds - rqtp.tv_sec * 1000000000;
|
||||
nanosleep(&rqtp, 0);
|
||||
}
|
||||
|
||||
#undef LOG_SUBSYSTEM
|
||||
|
|
|
@ -27,8 +27,6 @@ typedef struct cmsghdr cmsghdr;
|
|||
typedef struct ip_mreq ip_mreq;
|
||||
typedef struct iovec iovec;
|
||||
|
||||
#define LOG_SUBSYSTEM "Platform"
|
||||
|
||||
net_ip StringToNetIP(const char* addr)
|
||||
{
|
||||
return(inet_addr(addr));
|
||||
|
@ -511,5 +509,3 @@ int SocketReceiveMessage(platform_socket* socket, socket_msg* msg, socket_addres
|
|||
|
||||
return(size);
|
||||
}
|
||||
|
||||
#undef LOG_SUBSYSTEM
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
#include"debug_log.h"
|
||||
#include"typedefs.h"
|
||||
|
||||
#define LOG_SUBSYSTEM "Platform"
|
||||
|
||||
int RandomSeedFromDevice()
|
||||
{
|
||||
FILE* urandom = fopen("/dev/urandom", "r");
|
||||
|
@ -56,5 +54,3 @@ u64 RandomU64()
|
|||
u64 u3 = (u64)random();
|
||||
return((u1<<33) | (u2<<2) | (u3 & 0x03));
|
||||
}
|
||||
|
||||
#undef LOG_SUBSYSTEM
|
||||
|
|
6
src/ui.c
6
src/ui.c
|
@ -12,9 +12,6 @@
|
|||
#include"platform_clock.h"
|
||||
#include"ui.h"
|
||||
|
||||
#define LOG_SUBSYSTEM "UI"
|
||||
|
||||
|
||||
static ui_style UI_STYLE_DEFAULTS =
|
||||
{
|
||||
.size.width = {.kind = UI_SIZE_CHILDREN,
|
||||
|
@ -2860,6 +2857,3 @@ ui_text_box_result ui_text_box(const char* name, mem_arena* arena, str8 text)
|
|||
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
#undef LOG_SUBSYSTEM
|
||||
|
|
|
@ -6,120 +6,151 @@
|
|||
* @revision:
|
||||
*
|
||||
*****************************************************************/
|
||||
#include<string.h>
|
||||
#include"debug_log.h"
|
||||
|
||||
#include"platform_varg.h"
|
||||
|
||||
static const char* LOG_HEADINGS[LOG_LEVEL_COUNT] = {
|
||||
"Error",
|
||||
"Warning",
|
||||
"Message",
|
||||
"Debug"};
|
||||
"Info"};
|
||||
|
||||
static const char* LOG_FORMATS[LOG_LEVEL_COUNT] = {
|
||||
"\033[38;5;9m\033[1m",
|
||||
"\033[38;5;13m\033[1m",
|
||||
"\033[38;5;10m\033[1m",
|
||||
"\033[38;5;14m\033[1m" };
|
||||
"\033[38;5;10m\033[1m"};
|
||||
|
||||
static const char* LOG_FORMAT_STOP = "\033[m";
|
||||
|
||||
enum {
|
||||
LOG_SUBSYSTEM_MAX_COUNT = 16 };
|
||||
|
||||
typedef struct log_config
|
||||
{
|
||||
FILE* out;
|
||||
log_output output;
|
||||
log_level level;
|
||||
const char* subsystemNames[LOG_SUBSYSTEM_MAX_COUNT];
|
||||
log_level subsystemLevels[LOG_SUBSYSTEM_MAX_COUNT];
|
||||
bool enableVTColor;
|
||||
|
||||
} log_config;
|
||||
|
||||
static log_config __log_config = {.out = 0,
|
||||
.level = LOG_DEFAULT_LEVEL,
|
||||
.subsystemNames = {0},
|
||||
.subsystemLevels = {0}};
|
||||
#if PLATFORM_ORCA
|
||||
#define LOG_DEFAULT_OUTPUT (log_output){.kind = ORCA_LOG_OUTPUT_CONSOLE}
|
||||
#define LOG_DEFAULT_ENABLE_VT_COLOR true
|
||||
#else
|
||||
#define LOG_DEFAULT_OUTPUT 0
|
||||
#define LOG_DEFAULT_ENABLE_VT_COLOR true
|
||||
#endif
|
||||
|
||||
int LogFindSubsystem(const char* subsystem)
|
||||
static log_config __logConfig = {.output = LOG_DEFAULT_OUTPUT,
|
||||
.level = LOG_DEFAULT_LEVEL,
|
||||
.enableVTColor = LOG_DEFAULT_ENABLE_VT_COLOR};
|
||||
|
||||
void log_set_output(log_output output)
|
||||
{
|
||||
for(int i=0; i<LOG_SUBSYSTEM_MAX_COUNT; i++)
|
||||
{
|
||||
if(__log_config.subsystemNames[i])
|
||||
{
|
||||
if(!strcmp(__log_config.subsystemNames[i], subsystem))
|
||||
{
|
||||
return(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return(-1);
|
||||
__logConfig.output = output;
|
||||
}
|
||||
|
||||
void LogGeneric(log_level level,
|
||||
const char* subsystem,
|
||||
void log_set_level(log_level level)
|
||||
{
|
||||
__logConfig.level = level;
|
||||
}
|
||||
|
||||
void log_enable_vt_color(bool enable)
|
||||
{
|
||||
__logConfig.enableVTColor = enable;
|
||||
}
|
||||
|
||||
#if PLATFORM_ORCA
|
||||
|
||||
#define STB_SPRINTF_IMPLEMENTATION
|
||||
#include"ext/stb_sprintf.h"
|
||||
|
||||
typedef int orca_log_mode;
|
||||
enum {ORCA_LOG_BEGIN, ORCA_LOG_APPEND};
|
||||
|
||||
extern void orca_log_entry(log_level level,
|
||||
int fileLen,
|
||||
const char* file,
|
||||
int functionLen,
|
||||
const char* function,
|
||||
int line);
|
||||
|
||||
extern void orca_log_append(int msgLen, const char* msg);
|
||||
|
||||
char* log_stbsp_callback(char const* buf, void* user, int len)
|
||||
{
|
||||
orca_log_append(len, buf);
|
||||
return((char*)buf);
|
||||
}
|
||||
|
||||
|
||||
//TODO: later, move this to orca_strings in milepost
|
||||
size_t strlen(const char *s)
|
||||
{
|
||||
size_t len = 0;
|
||||
while(s[len] != '\0')
|
||||
{
|
||||
len++;
|
||||
}
|
||||
return(len);
|
||||
}
|
||||
|
||||
void log_generic(log_level level,
|
||||
const char* functionName,
|
||||
const char* fileName,
|
||||
u32 line,
|
||||
const char* msg,
|
||||
...)
|
||||
{
|
||||
int subsystemIndex = LogFindSubsystem(subsystem);
|
||||
int filterLevel = (subsystemIndex >= 0)? __log_config.subsystemLevels[subsystemIndex] : __log_config.level;
|
||||
if(level <= __logConfig.level)
|
||||
{
|
||||
orca_log_entry(level, strlen(functionName), functionName, strlen(fileName), fileName, line);
|
||||
|
||||
if(level <= filterLevel)
|
||||
{
|
||||
if(!__log_config.out)
|
||||
{
|
||||
__log_config.out = LOG_DEFAULT_OUTPUT;
|
||||
}
|
||||
fprintf(__log_config.out,
|
||||
"%s%s:%s [%s] %s() in %s:%i: ",
|
||||
LOG_FORMATS[level],
|
||||
LOG_HEADINGS[level],
|
||||
LOG_FORMAT_STOP,
|
||||
subsystem,
|
||||
functionName,
|
||||
fileName,
|
||||
line);
|
||||
char buf[STB_SPRINTF_MIN];
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, msg);
|
||||
vfprintf(__log_config.out, msg, ap);
|
||||
stbsp_vsprintfcb(log_stbsp_callback, 0, buf, msg, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
|
||||
void LogOutput(FILE* output)
|
||||
{
|
||||
__log_config.out = output;
|
||||
}
|
||||
#else
|
||||
|
||||
void LogLevel(log_level level)
|
||||
void log_generic(log_level level,
|
||||
const char* functionName,
|
||||
const char* fileName,
|
||||
u32 line,
|
||||
const char* msg,
|
||||
...)
|
||||
{
|
||||
__log_config.level = level;
|
||||
}
|
||||
|
||||
void LogFilter(const char* subsystem, log_level level)
|
||||
{
|
||||
int firstNull = -1;
|
||||
for(int i=0; i<LOG_SUBSYSTEM_MAX_COUNT; i++)
|
||||
if(__logConfig.output == 0)
|
||||
{
|
||||
if(__log_config.subsystemNames[i])
|
||||
{
|
||||
if(!strcmp(__log_config.subsystemNames[i], subsystem))
|
||||
{
|
||||
__log_config.subsystemLevels[i] = level;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if(firstNull < 0)
|
||||
{
|
||||
firstNull = i;
|
||||
}
|
||||
__logConfig.output = stdout;
|
||||
}
|
||||
|
||||
__log_config.subsystemNames[firstNull] = subsystem;
|
||||
__log_config.subsystemLevels[firstNull] = level;
|
||||
if(level <= __logConfig.level)
|
||||
{
|
||||
if(__logConfig.enableVTColor)
|
||||
{
|
||||
fprintf(__logConfig.output,
|
||||
"%s%s:%s %s() in %s:%i: ",
|
||||
LOG_FORMATS[level],
|
||||
LOG_HEADINGS[level],
|
||||
LOG_FORMAT_STOP,
|
||||
functionName,
|
||||
fileName,
|
||||
line);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(__logConfig.output,
|
||||
"%s: %s() in %s:%i: ",
|
||||
LOG_HEADINGS[level],
|
||||
functionName,
|
||||
fileName,
|
||||
line);
|
||||
}
|
||||
va_list ap;
|
||||
va_start(ap, msg);
|
||||
vfprintf(__logConfig.output, msg, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#ifndef __DEBUG_LOG_H_
|
||||
#define __DEBUG_LOG_H_
|
||||
|
||||
#include<stdio.h>
|
||||
#include"platform.h"
|
||||
#include"typedefs.h"
|
||||
#include"macro_helpers.h"
|
||||
|
@ -17,63 +16,61 @@
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
//NOTE(martin): the default logging level can be adjusted by defining LOG_DEFAULT_LEVEL. As the name suggest, it is the default, but it
|
||||
// can be adjusted at runtime with LogLevel()
|
||||
//NOTE(martin): the default logging level can be adjusted by defining LOG_DEFAULT_LEVEL.
|
||||
// It can be adjusted at runtime with log_set_level()
|
||||
#ifndef LOG_DEFAULT_LEVEL
|
||||
#define LOG_DEFAULT_LEVEL LOG_LEVEL_WARNING
|
||||
#endif
|
||||
|
||||
//NOTE(martin): the default output can be adjusted by defining LOG_DEFAULT_OUTPUT. It can be adjusted at runtime with LogOutput()
|
||||
#ifndef LOG_DEFAULT_OUTPUT
|
||||
#define LOG_DEFAULT_OUTPUT stdout
|
||||
#endif
|
||||
|
||||
//NOTE(martin): LOG_SUBSYSTEM can be defined in each compilation unit to associate it with a subsystem, like this:
|
||||
// #define LOG_SUBSYSTEM "name"
|
||||
|
||||
typedef enum { LOG_LEVEL_ERROR,
|
||||
LOG_LEVEL_WARNING,
|
||||
LOG_LEVEL_MESSAGE,
|
||||
LOG_LEVEL_DEBUG,
|
||||
LOG_LEVEL_INFO,
|
||||
LOG_LEVEL_COUNT } log_level;
|
||||
|
||||
MP_API void LogGeneric(log_level level,
|
||||
const char* subsystem,
|
||||
#ifdef PLATFORM_ORCA
|
||||
typedef enum
|
||||
{
|
||||
ORCA_LOG_OUTPUT_CONSOLE,
|
||||
ORCA_LOG_OUTPUT_FILE
|
||||
} orca_log_output_kind;
|
||||
|
||||
typedef struct log_output
|
||||
{
|
||||
orca_log_output_kind kind;
|
||||
//TODO: file
|
||||
} log_output;
|
||||
|
||||
#else
|
||||
#include<stdio.h>
|
||||
typedef FILE* log_output;
|
||||
#endif
|
||||
|
||||
MP_API void log_set_level(log_level level);
|
||||
MP_API void log_set_output(log_output output);
|
||||
MP_API void log_enable_vt_color(bool enable);
|
||||
|
||||
MP_API void log_generic(log_level level,
|
||||
const char* functionName,
|
||||
const char* fileName,
|
||||
u32 line,
|
||||
const char* msg,
|
||||
...);
|
||||
|
||||
MP_API void LogOutput(FILE* output);
|
||||
MP_API void LogLevel(log_level level);
|
||||
MP_API void LogFilter(const char* subsystem, log_level level);
|
||||
|
||||
#define LOG_GENERIC(level, func, file, line, msg, ...) LogGeneric(level, LOG_SUBSYSTEM, func, file, line, msg, ##__VA_ARGS__ )
|
||||
|
||||
#define LOG_ERROR(msg, ...) LOG_GENERIC(LOG_LEVEL_ERROR, __FUNCTION__, __FILE__, __LINE__, msg, ##__VA_ARGS__ )
|
||||
|
||||
//NOTE(martin): warnings, messages, and debug info can be enabled in debug mode by defining LOG_COMPILE_XXX, XXX being the max desired log level
|
||||
// error logging is always compiled
|
||||
#if defined(LOG_COMPILE_WARNING) || defined(LOG_COMPILE_MESSAGE) || defined(LOG_COMPILE_DEBUG)
|
||||
#define LOG_WARNING(msg, ...) LOG_GENERIC(LOG_LEVEL_WARNING, __FUNCTION__, __FILE__, __LINE__, msg, ##__VA_ARGS__ )
|
||||
#define LOG_ERROR(msg, ...) log_generic(LOG_LEVEL_ERROR, __FUNCTION__, __FILE__, __LINE__, msg, ##__VA_ARGS__ )
|
||||
|
||||
#if defined(LOG_COMPILE_MESSAGE) || defined(LOG_COMPILE_DEBUG)
|
||||
#define LOG_MESSAGE(msg, ...) LOG_GENERIC(LOG_LEVEL_MESSAGE, __FUNCTION__, __FILE__, __LINE__, msg, ##__VA_ARGS__ )
|
||||
#if defined(LOG_COMPILE_WARNING) || defined(LOG_COMPILE_INFO)
|
||||
#define LOG_WARNING(msg, ...) log_generic(LOG_LEVEL_WARNING, __FUNCTION__, __FILE__, __LINE__, msg, ##__VA_ARGS__ )
|
||||
|
||||
#if defined(LOG_COMPILE_DEBUG)
|
||||
#define LOG_DEBUG(msg, ...) LOG_GENERIC(LOG_LEVEL_DEBUG, __FUNCTION__, __FILE__, __LINE__, msg, ##__VA_ARGS__ )
|
||||
#if defined(LOG_COMPILE_INFO)
|
||||
#define LOG_INFO(msg, ...) log_generic(LOG_LEVEL_INFO, __FUNCTION__, __FILE__, __LINE__, msg, ##__VA_ARGS__ )
|
||||
#else
|
||||
#define LOG_DEBUG(msg, ...)
|
||||
#endif
|
||||
#else
|
||||
#define LOG_MESSAGE(msg, ...)
|
||||
#define LOG_DEBUG(msg, ...)
|
||||
#define LOG_INFO(msg, ...)
|
||||
#endif
|
||||
#else
|
||||
#define LOG_WARNING(msg, ...)
|
||||
#define LOG_MESSAGE(msg, ...)
|
||||
#define LOG_DEBUG(msg, ...)
|
||||
#define LOG_INFO(msg, ...)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
|
||||
#include"mp_app.c"
|
||||
|
||||
#define LOG_SUBSYSTEM "Application"
|
||||
|
||||
void mp_init_keys()
|
||||
{
|
||||
memset(__mpApp.keyCodes, MP_KEY_UNKNOWN, 256*sizeof(int));
|
||||
|
@ -1104,5 +1102,3 @@ str8 mp_app_get_resource_path(mem_arena* arena, const char* name)
|
|||
return(result);
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#undef LOG_SUBSYSTEM
|
||||
|
|
Loading…
Reference in New Issue