Adding printing functions and asserts
This commit is contained in:
parent
d43afa2ac0
commit
caa454f1ca
|
@ -18,3 +18,4 @@ Debug/*
|
|||
|
||||
src/bindgen_core_api.c
|
||||
src/bindgen_gles_api.c
|
||||
*bind_gen.c
|
File diff suppressed because it is too large
Load Diff
2
milepost
2
milepost
|
@ -1 +1 @@
|
|||
Subproject commit e9e9ab68c250c597fd6b7552d97977b99b103d33
|
||||
Subproject commit 0d6fb197fb5a4ec52dd65d4bd8fd52b7acf0e95e
|
|
@ -8,7 +8,7 @@ wasmFlags="--target=wasm32 \
|
|||
-Wl,--allow-undefined \
|
||||
-g \
|
||||
-D__ORCA__ \
|
||||
-I ../../sdk -I ../../milepost/src -I ../../milepost/src/util -I ../../milepost/src/platform"
|
||||
-I ../../sdk -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
|
||||
|
||||
|
|
|
@ -16,16 +16,9 @@
|
|||
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
extern void log_string_flat(unsigned long long len, char* ptr);
|
||||
extern void log_int(int i);
|
||||
extern float cosf(float x);
|
||||
extern float sinf(float x);
|
||||
|
||||
void log_string(str8 string)
|
||||
{
|
||||
log_string_flat(string.len, string.ptr);
|
||||
}
|
||||
|
||||
const g_color paddleColor = {1, 0, 0, 1};
|
||||
mp_rect paddle = {200, 40, 200, 40};
|
||||
|
||||
|
@ -48,15 +41,12 @@ void OnInit(void)
|
|||
{
|
||||
mem_arena_init(&arena);
|
||||
font = g_font_create_default();
|
||||
//log_string(str8_lit("init procedure\n"));
|
||||
}
|
||||
|
||||
void OnFrameResize(u32 width, u32 height)
|
||||
{
|
||||
log_string(str8_lit("frame resize "));
|
||||
log_int(width);
|
||||
log_int(height);
|
||||
log_string(str8_lit("\n"));
|
||||
ASSERT(width == 0, "assert if width different from 0");
|
||||
log_print("frame resize %u, %u\n", width, height);
|
||||
|
||||
frameSize.x = width;
|
||||
frameSize.y = height;
|
||||
|
@ -99,7 +89,6 @@ void OnKeyUp(int key)
|
|||
void OnFrameRefresh(void)
|
||||
{
|
||||
char* tmp = mem_arena_alloc(&arena, 512);
|
||||
//log_string(str8_lit("frame procedure\n"));
|
||||
|
||||
f32 aspect = frameSize.x/frameSize.y;
|
||||
|
||||
|
|
|
@ -8,3 +8,5 @@
|
|||
|
||||
#include"platform/orca_memory.c"
|
||||
#include"util/memory.c"
|
||||
|
||||
#include"orca_log.c"
|
||||
|
|
|
@ -12,4 +12,6 @@
|
|||
#include"util/lists.h"
|
||||
#include"util/memory.h"
|
||||
|
||||
#include"orca_log.h"
|
||||
|
||||
#endif //__ORCA_H_
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/************************************************************//**
|
||||
*
|
||||
* @file: orca_log.c
|
||||
* @author: Martin Fouilleul
|
||||
* @date: 17/04/2023
|
||||
*
|
||||
*****************************************************************/
|
||||
#include"orca_log.h"
|
||||
#include"platform_varg.h"
|
||||
|
||||
#define STB_SPRINTF_IMPLEMENTATION
|
||||
#include"ext/stb_sprintf.h"
|
||||
|
||||
extern void orca_log(size_t len, const char* ptr);
|
||||
|
||||
//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_print(const char* fmt, ...)
|
||||
{
|
||||
char buf[4096];
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
stbsp_vsnprintf(buf, 4096, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
orca_log(strlen(buf), buf);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
/************************************************************//**
|
||||
*
|
||||
* @file: orca_log.h
|
||||
* @author: Martin Fouilleul
|
||||
* @date: 17/04/2023
|
||||
*
|
||||
*****************************************************************/
|
||||
#ifndef __ORCA_LOG_H_
|
||||
#define __ORCA_LOG_H_
|
||||
|
||||
#include"typedefs.h"
|
||||
|
||||
void log_print(const char* s, ...);
|
||||
|
||||
#endif //__ORCA_LOG_H_
|
|
@ -1,8 +1,7 @@
|
|||
log_string_flat v(Ip)
|
||||
log_int v(i)
|
||||
orca_log v(ip)
|
||||
cosf f(f)
|
||||
sinf f(f)
|
||||
floorf f(f)
|
||||
sqrtf f(f)
|
||||
orca_mem_grow i(I)
|
||||
orca_assert v(i)
|
||||
orca_assert i(ppipp)
|
29
src/main.c
29
src/main.c
|
@ -20,14 +20,9 @@
|
|||
#define LOG_SUBSYSTEM "Orca"
|
||||
|
||||
|
||||
void log_string_flat(u64 len, char* ptr)
|
||||
void orca_log(int len, const char* ptr)
|
||||
{
|
||||
LOG_MESSAGE("%.*s", (int)len, ptr);
|
||||
}
|
||||
|
||||
void log_int(int i)
|
||||
{
|
||||
printf("%i ", i);
|
||||
LOG_MESSAGE("%.*s", len, ptr);
|
||||
}
|
||||
|
||||
void mg_matrix_push_flat(float a11, float a12, float a13,
|
||||
|
@ -37,9 +32,25 @@ void mg_matrix_push_flat(float a11, float a12, float a13,
|
|||
mg_matrix_push(m);
|
||||
}
|
||||
|
||||
void orca_assert(bool x)
|
||||
int orca_assert(const char* file, const char* function, int line, const char* src, const char* note)
|
||||
{
|
||||
ASSERT(x);
|
||||
mem_arena* scratch = mem_scratch();
|
||||
str8 msg = str8_pushf(scratch,
|
||||
"Assertion failed in function %s() in file \"%s\", line %i:\n%s\nNote: %s\n",
|
||||
function,
|
||||
file,
|
||||
line,
|
||||
src,
|
||||
note);
|
||||
|
||||
const char* msgCStr = str8_to_cstring(scratch, msg);
|
||||
LOG_ERROR(msgCStr);
|
||||
|
||||
const char* options[] = {"OK"};
|
||||
mp_alert_popup("Assertion Failed", msgCStr, 1, options);
|
||||
|
||||
//TODO: should terminate more gracefully...
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
mg_font mg_font_create_default()
|
||||
|
|
Loading…
Reference in New Issue