puling logging functionality from milepost into orca
This commit is contained in:
parent
a1c69fc5f9
commit
7884ddd339
1906
ext/stb_sprintf.h
1906
ext/stb_sprintf.h
File diff suppressed because it is too large
Load Diff
2
milepost
2
milepost
|
@ -1 +1 @@
|
||||||
Subproject commit 86a16d3775727fe2b9dfd51fbd62f3f63b087f2e
|
Subproject commit 794f47b14186e386899cfa184064157f6aca5dbb
|
|
@ -8,7 +8,7 @@ wasmFlags="--target=wasm32 \
|
||||||
-Wl,--allow-undefined \
|
-Wl,--allow-undefined \
|
||||||
-g \
|
-g \
|
||||||
-D__ORCA__ \
|
-D__ORCA__ \
|
||||||
-I ../../sdk -I ../../milepost/src -I ../../milepost/src/util -I ../../milepost/src/platform -I../.."
|
-I ../../sdk -I ../../milepost -I ../../milepost/src -I ../../milepost/src/util -I ../../milepost/src/platform -I../.."
|
||||||
|
|
||||||
/usr/local/opt/llvm/bin/clang $wasmFlags -o ./module.wasm ../../sdk/graphics.c ../../sdk/orca.c src/main.c
|
/usr/local/opt/llvm/bin/clang $wasmFlags -o ./module.wasm ../../sdk/graphics.c ../../sdk/orca.c src/main.c
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,6 @@
|
||||||
|
|
||||||
#include"orca.h"
|
#include"orca.h"
|
||||||
|
|
||||||
#define str8_lit(s) ((str8){.len = sizeof(s)-1, .ptr = (char*)(s)})
|
|
||||||
|
|
||||||
#define M_PI 3.14159265358979323846
|
#define M_PI 3.14159265358979323846
|
||||||
|
|
||||||
extern float cosf(float x);
|
extern float cosf(float x);
|
||||||
|
@ -39,13 +37,13 @@ mem_arena arena;
|
||||||
|
|
||||||
void OnInit(void)
|
void OnInit(void)
|
||||||
{
|
{
|
||||||
// mem_arena_init(&arena);
|
mem_arena_init(&arena);
|
||||||
font = g_font_create_default();
|
font = g_font_create_default();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnFrameResize(u32 width, u32 height)
|
void OnFrameResize(u32 width, u32 height)
|
||||||
{
|
{
|
||||||
// LOG_INFO("frame resize %u, %u\n", width, height);
|
log_info("frame resize %u, %u", width, height);
|
||||||
|
|
||||||
frameSize.x = width;
|
frameSize.x = width;
|
||||||
frameSize.y = height;
|
frameSize.y = height;
|
||||||
|
@ -87,7 +85,7 @@ void OnKeyUp(int key)
|
||||||
|
|
||||||
void OnFrameRefresh(void)
|
void OnFrameRefresh(void)
|
||||||
{
|
{
|
||||||
// char* tmp = mem_arena_alloc(&arena, 512);
|
char* tmp = mem_arena_alloc(&arena, 512);
|
||||||
|
|
||||||
f32 aspect = frameSize.x/frameSize.y;
|
f32 aspect = frameSize.x/frameSize.y;
|
||||||
|
|
||||||
|
@ -161,5 +159,5 @@ void OnFrameRefresh(void)
|
||||||
|
|
||||||
g_matrix_pop();
|
g_matrix_pop();
|
||||||
|
|
||||||
// mem_arena_clear(&arena);
|
mem_arena_clear(&arena);
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ def gen_link(name, sig):
|
||||||
m3_Sig += c
|
m3_Sig += c
|
||||||
|
|
||||||
src = '\tres = m3_LinkRawFunction(module, "*", "' + name + '", "' + m3_Sig + '", ' + name + '_stub);\n'
|
src = '\tres = m3_LinkRawFunction(module, "*", "' + name + '", "' + m3_Sig + '", ' + name + '_stub);\n'
|
||||||
src += '\tif(res != m3Err_none && res != m3Err_functionLookupFailed) { LOG_ERROR("error: %s\\n", res); return(-1); }\n\n'
|
src += '\tif(res != m3Err_none && res != m3Err_functionLookupFailed) { log_error("error: %s\\n", res); return(-1); }\n\n'
|
||||||
links.append(src)
|
links.append(src)
|
||||||
|
|
||||||
for line in inFile:
|
for line in inFile:
|
||||||
|
|
|
@ -193,7 +193,7 @@ for decl in data:
|
||||||
|
|
||||||
|
|
||||||
s += '\tres = m3_LinkRawFunction(module, "*", "' + name + '", "' + m3Sig + '", ' + cname + '_stub);\n'
|
s += '\tres = m3_LinkRawFunction(module, "*", "' + name + '", "' + m3Sig + '", ' + cname + '_stub);\n'
|
||||||
s += '\tif(res != m3Err_none && res != m3Err_functionLookupFailed) { LOG_ERROR("error: %s\\n", res); return(-1); }\n\n'
|
s += '\tif(res != m3Err_none && res != m3Err_functionLookupFailed) { log_error("error: %s\\n", res); return(-1); }\n\n'
|
||||||
|
|
||||||
|
|
||||||
s += '\treturn(0);\n}\n'
|
s += '\treturn(0);\n}\n'
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#define __GRAPHICS_H_
|
#define __GRAPHICS_H_
|
||||||
|
|
||||||
#include"typedefs.h"
|
#include"typedefs.h"
|
||||||
|
#include"strings.h"
|
||||||
|
|
||||||
typedef struct g_mat2x3
|
typedef struct g_mat2x3
|
||||||
{
|
{
|
||||||
|
@ -186,11 +187,6 @@ void g_close_path();
|
||||||
mp_rect g_glyph_outlines(str32 glyphIndices);
|
mp_rect g_glyph_outlines(str32 glyphIndices);
|
||||||
void g_codepoints_outlines(str32 string);
|
void g_codepoints_outlines(str32 string);
|
||||||
*/
|
*/
|
||||||
typedef struct str8
|
|
||||||
{
|
|
||||||
u64 len;
|
|
||||||
char* ptr;
|
|
||||||
} str8;
|
|
||||||
|
|
||||||
void g_text_outlines(str8 string);
|
void g_text_outlines(str8 string);
|
||||||
|
|
||||||
|
|
|
@ -7,5 +7,8 @@
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
|
|
||||||
#include"platform/orca_memory.c"
|
#include"platform/orca_memory.c"
|
||||||
|
#include"platform/orca_strings.c"
|
||||||
|
#include"platform/orca_log.c"
|
||||||
|
|
||||||
#include"util/memory.c"
|
#include"util/memory.c"
|
||||||
#include"util/debug_log.c"
|
#include"util/strings.c"
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
#include"util/typedefs.h"
|
#include"util/typedefs.h"
|
||||||
#include"util/lists.h"
|
#include"util/lists.h"
|
||||||
#include"util/memory.h"
|
#include"util/memory.h"
|
||||||
#include"util/debug_log.h"
|
#include"util/strings.h"
|
||||||
|
#include"platform/platform_log.h"
|
||||||
|
|
||||||
|
|
||||||
#endif //__ORCA_H_
|
#endif //__ORCA_H_
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
orca_log_entry v(iipipi)
|
orca_log_entry v(iipipiip)
|
||||||
orca_log_append v(ip)
|
|
||||||
cosf f(f)
|
cosf f(f)
|
||||||
sinf f(f)
|
sinf f(f)
|
||||||
floorf f(f)
|
floorf f(f)
|
||||||
|
|
39
src/main.c
39
src/main.c
|
@ -22,7 +22,7 @@
|
||||||
/*
|
/*
|
||||||
void orca_log(int len, const char* ptr)
|
void orca_log(int len, const char* ptr)
|
||||||
{
|
{
|
||||||
LOG_INFO("%.*s", len, ptr);
|
log_info("%.*s", len, ptr);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -31,18 +31,19 @@ void orca_log_entry(log_level level,
|
||||||
char* file,
|
char* file,
|
||||||
int functionLen,
|
int functionLen,
|
||||||
char* function,
|
char* function,
|
||||||
int line)
|
int line,
|
||||||
|
int msgLen,
|
||||||
|
char* msg)
|
||||||
{
|
{
|
||||||
log_generic(level, file, function, line, "");
|
log_entry(level,
|
||||||
|
str8_from_buffer(fileLen, file),
|
||||||
|
str8_from_buffer(functionLen, function),
|
||||||
|
line,
|
||||||
|
"%.*s\n",
|
||||||
|
msgLen,
|
||||||
|
msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void orca_log_append(int msgLen, char* msg)
|
|
||||||
{
|
|
||||||
printf("%s", msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void mg_matrix_push_flat(float a11, float a12, float a13,
|
void mg_matrix_push_flat(float a11, float a12, float a13,
|
||||||
float a21, float a22, float a23)
|
float a21, float a22, float a23)
|
||||||
{
|
{
|
||||||
|
@ -62,7 +63,7 @@ int orca_assert(const char* file, const char* function, int line, const char* sr
|
||||||
note);
|
note);
|
||||||
|
|
||||||
const char* msgCStr = str8_to_cstring(scratch, msg);
|
const char* msgCStr = str8_to_cstring(scratch, msg);
|
||||||
LOG_ERROR(msgCStr);
|
log_error(msgCStr);
|
||||||
|
|
||||||
const char* options[] = {"OK"};
|
const char* options[] = {"OK"};
|
||||||
mp_alert_popup("Assertion Failed", msgCStr, 1, options);
|
mp_alert_popup("Assertion Failed", msgCStr, 1, options);
|
||||||
|
@ -80,7 +81,7 @@ mg_font mg_font_create_default()
|
||||||
FILE* fontFile = fopen(fontPathCString, "r");
|
FILE* fontFile = fopen(fontPathCString, "r");
|
||||||
if(!fontFile)
|
if(!fontFile)
|
||||||
{
|
{
|
||||||
LOG_ERROR("Could not load font file '%s': %s\n", fontPathCString, strerror(errno));
|
log_error("Could not load font file '%s': %s\n", fontPathCString, strerror(errno));
|
||||||
return(mg_font_nil());
|
return(mg_font_nil());
|
||||||
}
|
}
|
||||||
unsigned char* fontData = 0;
|
unsigned char* fontData = 0;
|
||||||
|
@ -170,7 +171,7 @@ void* orca_runloop(void* user)
|
||||||
FILE* file = fopen(modulePathCString, "rb");
|
FILE* file = fopen(modulePathCString, "rb");
|
||||||
if(!file)
|
if(!file)
|
||||||
{
|
{
|
||||||
LOG_ERROR("Couldn't load wasm module at %s\n", modulePathCString);
|
log_error("Couldn't load wasm module at %s\n", modulePathCString);
|
||||||
return((void*)-1);
|
return((void*)-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +211,7 @@ void* orca_runloop(void* user)
|
||||||
M3ErrorInfo errInfo = {};
|
M3ErrorInfo errInfo = {};
|
||||||
m3_GetErrorInfo(app->runtime.m3Runtime, &errInfo);
|
m3_GetErrorInfo(app->runtime.m3Runtime, &errInfo);
|
||||||
|
|
||||||
LOG_ERROR("wasm error: %s\n", errInfo.message);
|
log_error("wasm error: %s\n", errInfo.message);
|
||||||
return((void*)-1);
|
return((void*)-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,19 +229,19 @@ void* orca_runloop(void* user)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_ERROR("couldn't get value of __heap_base\n");
|
log_error("couldn't get value of __heap_base\n");
|
||||||
return((void*)-1);
|
return((void*)-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_ERROR("couldn't locate __heap_base\n");
|
log_error("couldn't locate __heap_base\n");
|
||||||
return((void*)-1);
|
return((void*)-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//NOTE: align heap base on 16Bytes
|
//NOTE: align heap base on 16Bytes
|
||||||
heapBase = AlignUpOnPow2(heapBase, 16);
|
heapBase = AlignUpOnPow2(heapBase, 16);
|
||||||
LOG_INFO("mem_size = %u, __heap_base = %u\n", m3_GetMemorySize(app->runtime.m3Runtime), heapBase);
|
log_info("mem_size = %u, __heap_base = %u\n", m3_GetMemorySize(app->runtime.m3Runtime), heapBase);
|
||||||
|
|
||||||
//NOTE: Find and type check event handlers.
|
//NOTE: Find and type check event handlers.
|
||||||
|
|
||||||
|
@ -293,7 +294,7 @@ void* orca_runloop(void* user)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_ERROR("type mismatch for event handler %.*s\n", (int)desc->name.len, desc->name.ptr);
|
log_error("type mismatch for event handler %.*s\n", (int)desc->name.len, desc->name.ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -335,7 +336,7 @@ void* orca_runloop(void* user)
|
||||||
case MP_EVENT_WINDOW_RESIZE:
|
case MP_EVENT_WINDOW_RESIZE:
|
||||||
{
|
{
|
||||||
mp_rect frame = {0, 0, event.frame.rect.w, event.frame.rect.h};
|
mp_rect frame = {0, 0, event.frame.rect.w, event.frame.rect.h};
|
||||||
mg_surface_set_frame(app->surface, frame);
|
mg_surface_set_frame(app->mtlSurface, frame);
|
||||||
|
|
||||||
if(eventHandlers[G_EVENT_FRAME_RESIZE])
|
if(eventHandlers[G_EVENT_FRAME_RESIZE])
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,7 +23,7 @@ int manual_link_gles_api(IM3Module module)
|
||||||
{
|
{
|
||||||
M3Result res;
|
M3Result res;
|
||||||
res = m3_LinkRawFunction(module, "*", "glShaderSource", "v(iiii)", glShaderSource_stub);
|
res = m3_LinkRawFunction(module, "*", "glShaderSource", "v(iiii)", glShaderSource_stub);
|
||||||
if(res) { LOG_ERROR("error: %s\n", res); return(-1); }
|
if(res) { log_error("error: %s\n", res); return(-1); }
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue