minor tweaks

This commit is contained in:
jacob 2024-05-16 23:50:17 -05:00
parent 9eabdcd222
commit 27d6acadc7
8 changed files with 16 additions and 12 deletions

View File

@ -85,7 +85,7 @@ INLINE void *_arena_align(struct arena *arena, u64 align)
INLINE struct temp_arena arena_temp_begin(struct arena *arena) INLINE struct temp_arena arena_temp_begin(struct arena *arena)
{ {
struct temp_arena t; struct temp_arena t = { 0 };
t.arena = arena; t.arena = arena;
t.start_pos = arena->pos; t.start_pos = arena->pos;
return t; return t;

View File

@ -102,7 +102,9 @@ extern "C" {
#if defined(__cplusplus) #if defined(__cplusplus)
# define LANGUAGE_CPP 1 # define LANGUAGE_CPP 1
# define LANGUAGE_C 0
#else #else
# define LANGUAGE_CPP 0
# define LANGUAGE_C 1 # define LANGUAGE_C 1
#endif #endif
@ -238,7 +240,7 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
#endif #endif
/* Bool */ /* Bool */
#ifndef __cplusplus #if !LANGUAGE_CPP
# define true 1 # define true 1
# define false 0 # define false 0
#endif #endif
@ -353,7 +355,7 @@ INLINE u128 u128_mul(u128 a, u128 b) { return a * b; }
#elif COMPILER_MSVC #elif COMPILER_MSVC
#ifdef __cplusplus #if LANGUAGE_CPP
# define U128(hi64, lo64) { (hi64), (lo64) } # define U128(hi64, lo64) { (hi64), (lo64) }
#else #else
# define U128(hi64, lo64) ((u128) { .hi = (hi64), .lo = (lo64) }) # define U128(hi64, lo64) ((u128) { .hi = (hi64), .lo = (lo64) })

View File

@ -7,14 +7,14 @@
* an embedded file. */ * an embedded file. */
#if RESOURCES_EMBEDDED #if RESOURCES_EMBEDDED
INCBIN_INCLUDE(res_tar, "../build/res.tar"); INCBIN_INCLUDE(res_tar, "build/res.tar");
struct buffer inc_res_tar(void) struct buffer inc_res_tar(void)
{ {
return INCBIN_GET(res_tar); return INCBIN_GET(res_tar);
} }
#endif #endif
INCBIN_INCLUDE(shaders_tar, "../build/shaders.tar"); INCBIN_INCLUDE(shaders_tar, "build/shaders.tar");
struct buffer inc_shaders_tar(void) struct buffer inc_shaders_tar(void)
{ {
return INCBIN_GET(shaders_tar); return INCBIN_GET(shaders_tar);

View File

@ -135,7 +135,8 @@ INLINE i64 math_fsign64(f64 f)
* ========================== */ * ========================== */
/* Taken from https://gist.github.com/orlp/3551590 */ /* Taken from https://gist.github.com/orlp/3551590 */
INLINE u64 math_pow_u64(u64 base, u8 exp) { INLINE u64 math_pow_u64(u64 base, u8 exp)
{
LOCAL_PERSIST const u8 highest_bit_set[] = { LOCAL_PERSIST const u8 highest_bit_set[] = {
0, 1, 2, 2, 3, 3, 3, 3, 0, 1, 2, 2, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,

View File

@ -115,7 +115,7 @@ struct string string_from_float(struct arena *arena, f64 f, u32 precision)
/* Add one half of next precision level to round up */ /* Add one half of next precision level to round up */
f += 0.5 / (f64)math_pow_u64(10, (u8)precision); f += 0.5 / (f64)math_pow_u64(10, (u8)precision);
f64 part_whole = math_floor64(f); f64 part_whole = math_trunc64(f);
f64 part_decimal = f - part_whole; f64 part_decimal = f - part_whole;
/* Print whole part */ /* Print whole part */
@ -129,7 +129,7 @@ struct string string_from_float(struct arena *arena, f64 f, u32 precision)
u64 digit = (u64)math_round_to_int64(math_fmod64(part_whole, 10.0)); u64 digit = (u64)math_round_to_int64(math_fmod64(part_whole, 10.0));
string_from_char(scratch.arena, INT_CHARS[digit % 10]); string_from_char(scratch.arena, INT_CHARS[digit % 10]);
++backwards_text_len; ++backwards_text_len;
part_whole = math_floor64(part_whole / 10.0); part_whole = math_trunc64(part_whole / 10.0);
} while (part_whole > 0); } while (part_whole > 0);
/* Reverse text into final string */ /* Reverse text into final string */
@ -146,7 +146,7 @@ struct string string_from_float(struct arena *arena, f64 f, u32 precision)
string_from_char(arena, '.'); string_from_char(arena, '.');
for (u64 i = 0; i < precision; ++i) { for (u64 i = 0; i < precision; ++i) {
part_decimal *= 10.0; part_decimal *= 10.0;
u64 digit = (u64)math_floor_to_int64(part_decimal); u64 digit = (u64)part_decimal;
part_decimal -= digit; part_decimal -= digit;
string_from_char(arena, INT_CHARS[digit % 10]); string_from_char(arena, INT_CHARS[digit % 10]);
} }
@ -439,7 +439,7 @@ struct string string_formatv(struct arena *arena, struct string fmt, va_list arg
no_more_args = true; no_more_args = true;
} break; } break;
case FMT_TYPE_NONE: { default: {
/* Unknown format type */ /* Unknown format type */
ASSERT(false); ASSERT(false);
parsed_str = string_copy(arena, STR("<?>")); parsed_str = string_copy(arena, STR("<?>"));

View File

@ -78,7 +78,7 @@ struct fmt_arg {
#define FMT_FLOAT(v) FMT_FLOAT_P(v, DEFAULT_FMT_PRECISION) #define FMT_FLOAT(v) FMT_FLOAT_P(v, DEFAULT_FMT_PRECISION)
#define FMT_FLOAT_P(v, p) (struct fmt_arg) {.type = FMT_TYPE_FLOAT, .value.f.val = (v), .value.f.precision = p} #define FMT_FLOAT_P(v, p) (struct fmt_arg) {.type = FMT_TYPE_FLOAT, .value.f.val = (v), .value.f.precision = p}
#define string_format(arena, fmt, ...) _string_format(arena, fmt, __VA_ARGS__, FMT_END) #define string_format(arena, fmt, ...) _string_format((arena), (fmt), __VA_ARGS__, FMT_END)
struct string _string_format(struct arena *arena, struct string fmt, ...); struct string _string_format(struct arena *arena, struct string fmt, ...);
struct string string_formatv(struct arena *arena, struct string fmt, va_list args); struct string string_formatv(struct arena *arena, struct string fmt, va_list args);

View File

@ -376,7 +376,7 @@ struct sys_file sys_file_open_read(struct string path)
); );
scratch_end(scratch); scratch_end(scratch);
struct sys_file file = (struct sys_file) { (u64)handle }; struct sys_file file = { (u64)handle };
return file; return file;
} }

View File

@ -31,6 +31,7 @@ INLINE u64 hash_fnv64(u64 seed, struct buffer buff)
#define HASH_FNV128_BASIS U128(0x6C62272E07BB0142, 0x62B821756295C58D) #define HASH_FNV128_BASIS U128(0x6C62272E07BB0142, 0x62B821756295C58D)
INLINE u128 hash_fnv128(u128 seed, struct buffer buff) INLINE u128 hash_fnv128(u128 seed, struct buffer buff)
{ {
/* FIXME: Verify MSVC version of 128 is same */
u128 hash = seed; u128 hash = seed;
for (u64 i = 0; i < buff.size; ++i) { for (u64 i = 0; i < buff.size; ++i) {
u8 c = (u8)buff.data[i]; u8 c = (u8)buff.data[i];