aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar gingerBill 2016-05-22 00:41:18 +0100
committerGravatar gingerBill 2016-05-22 00:41:18 +0100
commit0ea0be695ce0cc86a4646b6c778e4ad562e5b94d (patch)
treebe84a31dd93f7714e41d5c18f52fab0a676555e5
parentDropped C90 Support (For numerous reasons) (diff)
Change brace style because why not?
Diffstat (limited to '')
-rw-r--r--README.md10
-rw-r--r--gb.h1240
-rw-r--r--gb_gl.h335
-rw-r--r--gb_math.h319
-rw-r--r--gb_regex.h92
-rw-r--r--gb_string.h76
6 files changed, 544 insertions, 1528 deletions
diff --git a/README.md b/README.md
index 86f3894..10b9a10 100644
--- a/README.md
+++ b/README.md
@@ -4,12 +4,12 @@ gb single-file public domain libraries for C & C++
library | latest version | category | description
----------------|----------------|----------|-------------
-**gb.h** | 0.17 | misc | Helper library (Standard library _improvement_)
-**gb_math.h** | 0.06d | math | Vector math library geared towards game development
-**gb_gl.h** | 0.04d | graphics | OpenGL Helper Library
-**gb_string.h** | 0.95 | strings | A better string library (this is built into gb.h too with custom allocator support!)
+**gb.h** | 0.17b | misc | Helper library (Standard library _improvement_)
+**gb_math.h** | 0.06e | math | Vector math library geared towards game development
+**gb_gl.h** | 0.04e | graphics | OpenGL Helper Library
+**gb_string.h** | 0.95a | strings | A better string library (this is built into gb.h too with custom allocator support!)
**gb_ini.h** | 0.93 | misc | Simple ini file loader library
-**gb_regex.h** | 0.01c | regex | Highly experimental regular expressions library
+**gb_regex.h** | 0.01d | regex | Highly experimental regular expressions library
## FAQ
diff --git a/gb.h b/gb.h
index 7be2452..73991e2 100644
--- a/gb.h
+++ b/gb.h
@@ -1,4 +1,4 @@
-/* gb.h - v0.17a - Ginger Bill's C Helper Library - public domain
+/* gb.h - v0.17b - Ginger Bill's C Helper Library - public domain
- no warranty implied; use at your own risk
This is a single header file with a bunch of useful stuff
@@ -37,7 +37,8 @@ Conventions used:
Version History:
- 0.17a - Dropped C90 Support
+ 0.17b - Change formating style because why not?
+ 0.17a - Dropped C90 Support (For numerous reasons)
0.17 - Instantiated Hash Table
0.16a - Minor code layout changes
0.16 - New file API and improved platform layer
@@ -1292,9 +1293,7 @@ Disadvantages:
#define GB_IMPLEMENTATION
#include "gb.h"
-
-int main(int argc, char **argv)
-{
+ int main(int argc, char **argv) {
gbString str = gb_string_make("Hello");
gbString other_str = gb_string_make_length(", ", 2);
str = gb_string_append(str, other_str);
@@ -1428,8 +1427,7 @@ typedef struct gbBufferHeader {
//
#if 0 // Example
-void foo(void)
-{
+void foo(void) {
isize i;
int test_values[] = {4, 2, 1, 7};
gbAllocator a = gb_heap_allocator();
@@ -1660,21 +1658,15 @@ PREFIX GB_JOIN2(NAME, Entry) const *GB_JOIN2(N,multi_find_next_entry) (NAME cons
#define GB_TABLE_DEFINE_(NAME, N, VALUE) \
-gb_inline void \
-GB_JOIN2(N,init)(NAME *h, gbAllocator a) \
-{ \
+gb_inline void GB_JOIN2(N,init)(NAME *h, gbAllocator a) { \
gb_array_init(h->hashes, a); \
gb_array_init(h->entries, a); \
} \
-gb_inline void \
-GB_JOIN2(N,free)(NAME *h) \
-{ \
+gb_inline void GB_JOIN2(N,free)(NAME *h) { \
gb_array_free(&h->hashes); \
gb_array_free(&h->entries); \
} \
-gbHashTableFindResult \
-GB_JOIN2(N,_find_result_from_key)(NAME const *h, u64 key) \
-{ \
+gbHashTableFindResult GB_JOIN2(N,_find_result_from_key)(NAME const *h, u64 key) { \
gbHashTableFindResult fr = GB__INVALID_FIND_RESULT; \
if (gb_array_count(h->hashes) == 0) \
return fr; \
@@ -1688,22 +1680,16 @@ GB_JOIN2(N,_find_result_from_key)(NAME const *h, u64 key) \
} \
return fr; \
} \
-gb_inline b32 \
-GB_JOIN2(N,has)(NAME const *h, u64 key) \
-{ \
+gb_inline b32 GB_JOIN2(N,has)(NAME const *h, u64 key) { \
return GB_JOIN2(N,_find_result_from_key)(h, key).entry_index >= 0; \
} \
-gb_inline VALUE \
-GB_JOIN2(N,get)(NAME const *h, u64 key, VALUE default_value) \
-{ \
+gb_inline VALUE GB_JOIN2(N,get)(NAME const *h, u64 key, VALUE default_value) { \
isize index = GB_JOIN2(N,_find_result_from_key)(h, key).entry_index; \
if (index < 0) \
return default_value; \
return h->entries[index].value; \
} \
-gb_internal gb_inline isize \
-GB_JOIN2(N,_add_entry)(NAME *h, u64 key) \
-{ \
+gb_internal gb_inline isize GB_JOIN2(N,_add_entry)(NAME *h, u64 key) { \
isize i = gb_array_count(h->entries); \
GB_JOIN2(NAME,Entry) e = {0}; \
e.key = key; \
@@ -1711,16 +1697,12 @@ GB_JOIN2(N,_add_entry)(NAME *h, u64 key) \
gb_array_append(h->entries, e); \
return i; \
} \
-gb_internal gb_inline isize \
-GB_JOIN2(N,_is_full)(NAME *h) \
-{ \
+gb_internal gb_inline isize GB_JOIN2(N,_is_full)(NAME *h) { \
f64 const MAXIMUM_LOAD_COEFFICIENT = 0.85; \
return gb_array_count(h->entries) >= MAXIMUM_LOAD_COEFFICIENT * gb_array_count(h->hashes); \
} \
gb_internal gb_inline void GB_JOIN2(N,_table_grow)(NAME *h); \
-gb_inline void \
-GB_JOIN2(N,multi_insert)(NAME *h, u64 key, VALUE value) \
-{ \
+gb_inline void GB_JOIN2(N,multi_insert)(NAME *h, u64 key, VALUE value) { \
gbHashTableFindResult fr; \
isize next; \
if (gb_array_count(h->hashes) == 0) \
@@ -1736,9 +1718,7 @@ GB_JOIN2(N,multi_insert)(NAME *h, u64 key, VALUE value) \
if (GB_JOIN2(N,_is_full)(h)) \
GB_JOIN2(N,_table_grow)(h); \
} \
-gb_inline void \
-GB_JOIN2(N,multi_get)(NAME const *h, u64 key, VALUE *values, isize count) \
-{ \
+gb_inline void GB_JOIN2(N,multi_get)(NAME const *h, u64 key, VALUE *values, isize count) { \
isize i = 0; \
GB_JOIN2(NAME,Entry) const *e = GB_JOIN2(N,multi_find_first_entry)(h, key); \
while (e && count --> 0) { \
@@ -1746,9 +1726,7 @@ GB_JOIN2(N,multi_get)(NAME const *h, u64 key, VALUE *values, isize count) \
e = GB_JOIN2(N,multi_find_next_entry)(h, e); \
} \
} \
-gb_inline isize \
-GB_JOIN2(N,multi_count)(NAME const *h, u64 key) \
-{ \
+gb_inline isize GB_JOIN2(N,multi_count)(NAME const *h, u64 key) { \
isize count = 0; \
GB_JOIN2(NAME,Entry) const *e = GB_JOIN2(N,multi_find_first_entry)(h, key); \
while (e) { \
@@ -1757,16 +1735,12 @@ GB_JOIN2(N,multi_count)(NAME const *h, u64 key) \
} \
return count; \
} \
-GB_JOIN2(NAME,Entry) const * \
-GB_JOIN2(N,multi_find_first_entry)(NAME const *h, u64 key) \
-{ \
+GB_JOIN2(NAME,Entry) const *GB_JOIN2(N,multi_find_first_entry)(NAME const *h, u64 key) { \
isize index = GB_JOIN2(N,_find_result_from_key)(h, key).entry_index; \
if (index < 0) return NULL; \
return &h->entries[index]; \
} \
-GB_JOIN2(NAME,Entry) const * \
-GB_JOIN2(N,multi_find_next_entry)(NAME const *h, GB_JOIN2(NAME,Entry) const *e) \
-{ \
+GB_JOIN2(NAME,Entry) const *GB_JOIN2(N,multi_find_next_entry)(NAME const *h, GB_JOIN2(NAME,Entry) const *e) { \
if (e) { \
isize index = e->next; \
while (index >= 0) { \
@@ -1777,9 +1751,7 @@ GB_JOIN2(N,multi_find_next_entry)(NAME const *h, GB_JOIN2(NAME,Entry) const *e)
} \
return NULL; \
} \
-void \
-GB_JOIN2(N,_erase_find_result)(NAME *h, gbHashTableFindResult fr) \
-{ \
+void GB_JOIN2(N,_erase_find_result)(NAME *h, gbHashTableFindResult fr) { \
if (fr.data_prev < 0) \
h->hashes[fr.hash_index] = h->entries[fr.entry_index].next; \
else \
@@ -1795,9 +1767,7 @@ GB_JOIN2(N,_erase_find_result)(NAME *h, gbHashTableFindResult fr) \
h->entries[last.entry_index].next = fr.entry_index; \
} \
} \
-gb_inline void \
-GB_JOIN2(N,multi_remove_entry)(NAME *h, GB_JOIN2(NAME,Entry) const *e) \
-{ \
+gb_inline void GB_JOIN2(N,multi_remove_entry)(NAME *h, GB_JOIN2(NAME,Entry) const *e) { \
gbHashTableFindResult fr = GB__INVALID_FIND_RESULT; \
if (gb_array_count(h->hashes) && e) { \
fr.hash_index = e->key % gb_array_count(h->hashes); \
@@ -1812,15 +1782,11 @@ GB_JOIN2(N,multi_remove_entry)(NAME *h, GB_JOIN2(NAME,Entry) const *e) \
if (fr.entry_index >= 0) \
GB_JOIN2(N,_erase_find_result)(h, fr); \
} \
-gb_inline void \
-GB_JOIN2(N,multi_remove_all)(NAME *h, u64 key) \
-{ \
+gb_inline void GB_JOIN2(N,multi_remove_all)(NAME *h, u64 key) { \
while (GB_JOIN2(N,has)(h, key)) \
GB_JOIN2(N,remove)(h, key); \
} \
-void \
-GB_JOIN2(N,_rehash)(NAME *h, isize new_capacity) \
-{ \
+void GB_JOIN2(N,_rehash)(NAME *h, isize new_capacity) { \
NAME nh, empty; \
isize i; \
GB_JOIN2(N,init)(&nh, gb_array_allocator(h->hashes)); \
@@ -1837,15 +1803,11 @@ GB_JOIN2(N,_rehash)(NAME *h, isize new_capacity) \
gb_memcopy(&nh, &h, gb_size_of(NAME)); \
gb_memcopy(&empty, &nh, gb_size_of(NAME)); \
} \
-gb_internal gb_inline void \
-GB_JOIN2(N,_table_grow)(NAME *h) \
-{ \
+gb_internal gb_inline void GB_JOIN2(N,_table_grow)(NAME *h) { \
isize new_capacity = GB_ARRAY_GROW_FORMULA(gb_array_count(h->entries)); \
GB_JOIN2(N,_rehash)(h, new_capacity); \
} \
-isize \
-GB_JOIN2(N,_find_or_make_entry)(NAME *h, u64 key) \
-{ \
+isize GB_JOIN2(N,_find_or_make_entry)(NAME *h, u64 key) { \
isize index; \
gbHashTableFindResult fr = GB_JOIN2(N,_find_result_from_key)(h, key); \
if (fr.entry_index >= 0) \
@@ -1857,9 +1819,7 @@ GB_JOIN2(N,_find_or_make_entry)(NAME *h, u64 key) \
h->entries[fr.data_prev].next = index; \
return index; \
} \
-gb_inline void \
-GB_JOIN2(N,set)(NAME *h, u64 key, isize value) \
-{ \
+gb_inline void GB_JOIN2(N,set)(NAME *h, u64 key, isize value) { \
isize i; \
if (gb_array_count(h->hashes) == 0) \
GB_JOIN2(N,_table_grow)(h); \
@@ -1868,21 +1828,15 @@ GB_JOIN2(N,set)(NAME *h, u64 key, isize value) \
if (GB_JOIN2(N,_is_full)(h)) \
GB_JOIN2(N,_table_grow)(h); \
} \
-gb_inline void \
-GB_JOIN2(N,remove)(NAME *h, u64 key) \
-{ \
+gb_inline void GB_JOIN2(N,remove)(NAME *h, u64 key) { \
gbHashTableFindResult fr = GB_JOIN2(N,_find_result_from_key)(h, key); \
if (fr.entry_index >= 0) \
GB_JOIN2(N,_erase_find_result)(h, fr); \
} \
-gb_inline void \
-GB_JOIN2(N,reserve)(NAME *h, isize capacity) \
-{ \
+gb_inline void GB_JOIN2(N,reserve)(NAME *h, isize capacity) { \
GB_JOIN2(N,_rehash)(h, capacity); \
} \
-gb_inline void \
-GB_JOIN2(N,clear)(NAME *h) \
-{ \
+gb_inline void GB_JOIN2(N,clear)(NAME *h) { \
gb_array_clear(&h->hashes); \
gb_array_clear(&h->entries); \
} \
@@ -2552,9 +2506,7 @@ extern "C" {
#pragma warning(disable:4127) // Conditional expression is constant
#endif
-void
-gb_assert_handler(char const *condition, char const *file, i32 line, char const *msg, ...)
-{
+void gb_assert_handler(char const *condition, char const *file, i32 line, char const *msg, ...) {
gb_printf_err("%s:%d: Assert Failure: ", file, line);
if (condition)
gb_printf_err( "`%s` ", condition);
@@ -2567,17 +2519,13 @@ gb_assert_handler(char const *condition, char const *file, i32 line, char const
gb_printf_err("\n");
}
-b32
-gb_is_power_of_two(isize x)
-{
+b32 gb_is_power_of_two(isize x) {
if (x <= 0)
return false;
return !(x & (x-1));
}
-gb_inline void *
-gb_align_forward(void *ptr, isize alignment)
-{
+gb_inline void *gb_align_forward(void *ptr, isize alignment) {
uintptr p;
isize modulo;
@@ -2603,9 +2551,7 @@ gb_inline void gb_zero_size(void *ptr, isize size) { gb_memset(ptr, 0, size); }
#pragma intrinsic(__movsb)
#endif
-gb_inline void *
-gb_memcopy(void *gb_restrict dest, void const *gb_restrict source, isize size)
-{
+gb_inline void *gb_memcopy(void *gb_restrict dest, void const *gb_restrict source, isize size) {
#if defined(_MSC_VER)
__movsb(cast(u8 *gb_restrict)dest, cast(u8 *gb_restrict)source, size);
#elif (defined(__i386__) || defined(__x86_64___))
@@ -2647,9 +2593,7 @@ gb_memcopy(void *gb_restrict dest, void const *gb_restrict source, isize size)
return dest;
}
-gb_inline void *
-gb_memmove(void *dest, void const *source, isize size)
-{
+gb_inline void *gb_memmove(void *dest, void const *source, isize size) {
// TODO(bill): Heavily optimize
u8 *dp8 = cast(u8 *)dest;
u8 *sp8 = cast(u8 *)source;
@@ -2666,9 +2610,7 @@ gb_memmove(void *dest, void const *source, isize size)
return dest;
}
-gb_inline void *
-gb_memset(void *data, u8 c, isize size)
-{
+gb_inline void *gb_memset(void *data, u8 c, isize size) {
// TODO(bill): Heavily optimize
isize left;
u32 *dp32;
@@ -2701,9 +2643,7 @@ gb_memset(void *data, u8 c, isize size)
return data;
}
-gb_inline i32
-gb_memcompare(void const *s1, void const *s2, isize size)
-{
+gb_inline i32 gb_memcompare(void const *s1, void const *s2, isize size) {
// TODO(bill): Heavily optimize
u8 const *s1p8 = cast(u8 const *)s1;
@@ -2716,9 +2656,7 @@ gb_memcompare(void const *s1, void const *s2, isize size)
return 0;
}
-void
-gb_memswap(void *i, void *j, isize size)
-{
+void gb_memswap(void *i, void *j, isize size) {
if (i == j) return;
if (size == 4) {
@@ -2763,9 +2701,7 @@ gb_inline void *gb_resize_align(gbAllocator a, void *ptr, isize old_size, isize
gb_inline void *gb_alloc_copy (gbAllocator a, void const *src, isize size) { return gb_memcopy(gb_alloc(a, size), src, size); }
gb_inline void *gb_alloc_copy_align(gbAllocator a, void const *src, isize size, isize alignment) { return gb_memcopy(gb_alloc_align(a, size, alignment), src, size); }
-gb_inline char *
-gb_alloc_str(gbAllocator a, char const *str)
-{
+gb_inline char *gb_alloc_str(gbAllocator a, char const *str) {
char *result;
isize len = gb_strlen(str);
result = cast(char *)gb_alloc_copy(a, str, len+1);
@@ -2773,9 +2709,7 @@ gb_alloc_str(gbAllocator a, char const *str)
return result;
}
-gb_inline void *
-gb_default_resize_align(gbAllocator a, void *old_memory, isize old_size, isize new_size, isize alignment)
-{
+gb_inline void *gb_default_resize_align(gbAllocator a, void *old_memory, isize old_size, isize new_size, isize alignment) {
if (!old_memory) return gb_alloc_align(a, new_size, alignment);
if (new_size == 0) {
@@ -2808,36 +2742,24 @@ gb_default_resize_align(gbAllocator a, void *old_memory, isize old_size, isize n
#if defined(_MSC_VER) && !defined(__clang__)
gb_inline i32 gb_atomic32_load (gbAtomic32 const volatile *a) { return a->value; }
gb_inline void gb_atomic32_store(gbAtomic32 volatile *a, i32 value) { a->value = value; }
-gb_inline i32
-gb_atomic32_compare_exchange(gbAtomic32 volatile *a, i32 expected, i32 desired)
-{
+gb_inline i32 gb_atomic32_compare_exchange(gbAtomic32 volatile *a, i32 expected, i32 desired) {
return _InterlockedCompareExchange(cast(long volatile *)a, desired, expected);
}
-gb_inline i32
-gb_atomic32_exchanged(gbAtomic32 volatile *a, i32 desired)
-{
+gb_inline i32 gb_atomic32_exchanged(gbAtomic32 volatile *a, i32 desired) {
return _InterlockedExchange(cast(long volatile *)a, desired);
}
-gb_inline i32
-gb_atomic32_fetch_add(gbAtomic32 volatile *a, i32 operand)
-{
+gb_inline i32 gb_atomic32_fetch_add(gbAtomic32 volatile *a, i32 operand) {
return _InterlockedExchangeAdd(cast(long volatile *)a, operand);
}
-gb_inline i32
-gb_atomic32_fetch_and(gbAtomic32 volatile *a, i32 operand)
-{
+gb_inline i32 gb_atomic32_fetch_and(gbAtomic32 volatile *a, i32 operand) {
return _InterlockedAnd(cast(long volatile *)a, operand);
}
-gb_inline i32
-gb_atomic32_fetch_or(gbAtomic32 volatile *a, i32 operand)
-{
+gb_inline i32 gb_atomic32_fetch_or(gbAtomic32 volatile *a, i32 operand) {
return _InterlockedOr(cast(long volatile *)a, operand);
}
-gb_inline i64
-gb_atomic64_load(gbAtomic64 const volatile *a)
-{
+gb_inline i64 gb_atomic64_load(gbAtomic64 const volatile *a) {
#if defined(GB_ARCH_64_BIT)
return a->value;
#else
@@ -2855,9 +2777,7 @@ gb_atomic64_load(gbAtomic64 const volatile *a)
#endif
}
-gb_inline void
-gb_atomic64_store(gbAtomic64 volatile *a, i64 value)
-{
+gb_inline void gb_atomic64_store(gbAtomic64 volatile *a, i64 value) {
#if defined(GB_ARCH_64_BIT)
a->value = value;
#else
@@ -2873,15 +2793,11 @@ gb_atomic64_store(gbAtomic64 volatile *a, i64 value)
#endif
}
-gb_inline i64
-gb_atomic64_compare_exchange(gbAtomic64 volatile *a, i64 expected, i64 desired)
-{
+gb_inline i64 gb_atomic64_compare_exchange(gbAtomic64 volatile *a, i64 expected, i64 desired) {
return _InterlockedCompareExchange64(cast(i64 volatile *)a, desired, expected);
}
-gb_inline i64
-gb_atomic64_exchanged(gbAtomic64 volatile *a, i64 desired)
-{
+gb_inline i64 gb_atomic64_exchanged(gbAtomic64 volatile *a, i64 desired) {
#if defined(GB_ARCH_64_BIT)
return _InterlockedExchange64(cast(i64 volatile *)a, desired);
#else
@@ -2895,9 +2811,7 @@ gb_atomic64_exchanged(gbAtomic64 volatile *a, i64 desired)
#endif
}
-gb_inline i64
-gb_atomic64_fetch_add(gbAtomic64 volatile *a, i64 operand)
-{
+gb_inline i64 gb_atomic64_fetch_add(gbAtomic64 volatile *a, i64 operand) {
#if defined(GB_ARCH_64_BIT)
return _InterlockedExchangeAdd64(cast(i64 volatile *)a, operand);
#else
@@ -2911,9 +2825,7 @@ gb_atomic64_fetch_add(gbAtomic64 volatile *a, i64 operand)
#endif
}
-gb_inline i64
-gb_atomic64_fetch_and(gbAtomic64 volatile *a, i64 operand)
-{
+gb_inline i64 gb_atomic64_fetch_and(gbAtomic64 volatile *a, i64 operand) {
#if defined(GB_ARCH_64_BIT)
return _InterlockedAnd64(cast(i64 volatile *)a, operand);
#else
@@ -2927,9 +2839,7 @@ gb_atomic64_fetch_and(gbAtomic64 volatile *a, i64 operand)
#endif
}
-gb_inline i64
-gb_atomic64_fetch_or(gbAtomic64 volatile *a, i64 operand)
-{
+gb_inline i64 gb_atomic64_fetch_or(gbAtomic64 volatile *a, i64 operand) {
#if defined(GB_ARCH_64_BIT)
return _InterlockedAnd64(cast(i64 volatile *)a, operand);
#else
@@ -2951,9 +2861,7 @@ gb_atomic64_fetch_or(gbAtomic64 volatile *a, i64 operand)
gb_inline i32 gb_atomic32_load (gbAtomic32 const volatile *a) { return a->value; }
gb_inline void gb_atomic32_store(gbAtomic32 volatile *a, i32 value) { a->value = value; }
-gb_inline i32
-gb_atomic32_compare_exchange(gbAtomic32 volatile *a, i32 expected, i32 desired)
-{
+gb_inline i32 gb_atomic32_compare_exchange(gbAtomic32 volatile *a, i32 expected, i32 desired) {
i32 original;
__asm__ volatile(
"lock; cmpxchgl %2, %1"
@@ -2963,9 +2871,7 @@ gb_atomic32_compare_exchange(gbAtomic32 volatile *a, i32 expected, i32 desired)
return original;
}
-gb_inline i32
-gb_atomic32_exchanged(gbAtomic32 volatile *a, i32 desired)
-{
+gb_inline i32 gb_atomic32_exchanged(gbAtomic32 volatile *a, i32 desired) {
// NOTE(bill): No lock prefix is necessary for xchgl
i32 original;
__asm__ volatile(
@@ -2976,9 +2882,7 @@ gb_atomic32_exchanged(gbAtomic32 volatile *a, i32 desired)
return original;
}
-gb_inline i32
-gb_atomic32_fetch_add(gbAtomic32 volatile *a, i32 operand)
-{
+gb_inline i32 gb_atomic32_fetch_add(gbAtomic32 volatile *a, i32 operand) {
i32 original;
__asm__ volatile(
"lock; xaddl %0, %1"
@@ -2988,9 +2892,7 @@ gb_atomic32_fetch_add(gbAtomic32 volatile *a, i32 operand)
return original;
}
-gb_inline i32
-gb_atomic32_fetch_and(gbAtomic32 volatile *a, i32 operand)
-{
+gb_inline i32 gb_atomic32_fetch_and(gbAtomic32 volatile *a, i32 operand) {
i32 original;
i32 tmp;
__asm__ volatile(
@@ -3005,9 +2907,7 @@ gb_atomic32_fetch_and(gbAtomic32 volatile *a, i32 operand)
return original;
}
-gb_inline i32
-gb_atomic32_fetch_or(gbAtomic32 volatile *a, i32 operand)
-{
+gb_inline i32 gb_atomic32_fetch_or(gbAtomic32 volatile *a, i32 operand) {
i32 original;
i32 temp;
__asm__ volatile(
@@ -3023,9 +2923,7 @@ gb_atomic32_fetch_or(gbAtomic32 volatile *a, i32 operand)
}
-gb_inline i64
-gb_atomic64_load(gbAtomic64 const volatile *a)
-{
+gb_inline i64 gb_atomic64_load(gbAtomic64 const volatile *a) {
#if defined(GB_ARCH_64_BIT)
return a->value;
#else
@@ -3041,9 +2939,7 @@ gb_atomic64_load(gbAtomic64 const volatile *a)
#endif
}
-gb_inline void
-gb_atomic64_store(gbAtomic64 volatile *a, i64 value)
-{
+gb_inline void gb_atomic64_store(gbAtomic64 volatile *a, i64 value) {
#if defined(GB_ARCH_64_BIT)
a->value = value;
#else
@@ -3057,9 +2953,7 @@ gb_atomic64_store(gbAtomic64 volatile *a, i64 value)
#endif
}
-gb_inline i64
-gb_atomic64_compare_exchange(gbAtomic64 volatile *a, i64 expected, i64 desired)
-{
+gb_inline i64 gb_atomic64_compare_exchange(gbAtomic64 volatile *a, i64 expected, i64 desired) {
#if defined(GB_ARCH_64_BIT)
i64 original;
__asm__ volatile(
@@ -3079,9 +2973,7 @@ gb_atomic64_compare_exchange(gbAtomic64 volatile *a, i64 expected, i64 desired)
#endif
}
-gb_inline i64
-gb_atomic64_exchanged(gbAtomic64 volatile *a, i64 desired)
-{
+gb_inline i64 gb_atomic64_exchanged(gbAtomic64 volatile *a, i64 desired) {
#if defined(GB_ARCH_64_BIT)
i64 original;
__asm__ volatile(
@@ -3101,9 +2993,7 @@ gb_atomic64_exchanged(gbAtomic64 volatile *a, i64 desired)
#endif
}
-gb_inline i64
-gb_atomic64_fetch_add(gbAtomic64 volatile *a, i64 operand)
-{
+gb_inline i64 gb_atomic64_fetch_add(gbAtomic64 volatile *a, i64 operand) {
#if defined(GB_ARCH_64_BIT)
i64 original;
__asm__ volatile(
@@ -3121,9 +3011,7 @@ gb_atomic64_fetch_add(gbAtomic64 volatile *a, i64 operand)
#endif
}
-gb_inline i64
-gb_atomic64_fetch_and(gbAtomic64 volatile *a, i64 operand)
-{
+gb_inline i64 gb_atomic64_fetch_and(gbAtomic64 volatile *a, i64 operand) {
#if defined(GB_ARCH_64_BIT)
i64 original;
i64 tmp;
@@ -3146,9 +3034,7 @@ gb_atomic64_fetch_and(gbAtomic64 volatile *a, i64 operand)
#endif
}
-gb_inline i64
-gb_atomic64_fetch_or(gbAtomic64 volatile *a, i64 operand)
-{
+gb_inline i64 gb_atomic64_fetch_or(gbAtomic64 volatile *a, i64 operand) {
#if defined(GB_ARCH_64_BIT)
i64 original;
i64 temp;
@@ -3172,9 +3058,7 @@ gb_atomic64_fetch_or(gbAtomic64 volatile *a, i64 operand)
}
#endif
-gb_inline void
-gb_atomic32_spin_lock(gbAtomic32 volatile *a)
-{
+gb_inline void gb_atomic32_spin_lock(gbAtomic32 volatile *a) {
a->value = 0;
for (;;) {
i32 expected = 0;
@@ -3183,10 +3067,7 @@ gb_atomic32_spin_lock(gbAtomic32 volatile *a)
}
}
gb_inline void gb_atomic32_spin_unlock(gbAtomic32 volatile *a) { gb_atomic32_store(a, 0); }
-
-gb_inline void
-gb_atomic64_spin_lock(gbAtomic64 volatile *a)
-{
+gb_inline void gb_atomic64_spin_lock(gbAtomic64 volatile *a) {
a->value = 0;
for (;;) {
i64 expected = 0;
@@ -3199,114 +3080,61 @@ gb_inline void gb_atomic64_spin_unlock(gbAtomic64 volatile *a) { gb_atomic64_sto
#if defined(GB_ARCH_32_BIT)
-gb_inline void *
-gb_atomic_ptr_load(gbAtomicPtr const volatile *a)
-{
+gb_inline void *gb_atomic_ptr_load(gbAtomicPtr const volatile *a) {
return cast(void *)cast(intptr)gb_atomic32_load(cast(gbAtomic32 const volatile *)a);
}
-
-gb_inline void
-gb_atomic_ptr_store(gbAtomicPtr volatile *a, void *value)
-{
+gb_inline void gb_atomic_ptr_store(gbAtomicPtr volatile *a, void *value) {
gb_atomic32_store(cast(gbAtomic32 volatile *)a, cast(i32)cast(intptr)value);
}
-
-gb_inline void *
-gb_atomic_ptr_compare_exchange(gbAtomicPtr volatile *a, void *expected, void *desired)
-{
+gb_inline void *gb_atomic_ptr_compare_exchange(gbAtomicPtr volatile *a, void *expected, void *desired) {
cast(void *)cast(intptr)gb_atomic32_compare_exchange(cast(gbAtomic32 volatile *)a, cast(i32)cast(intptr)expected, cast(i32)cast(intptr)desired);
}
-
-gb_inline void *
-gb_atomic_ptr_exchanged(gbAtomicPtr volatile *a, void *desired)
-{
+gb_inline void *gb_atomic_ptr_exchanged(gbAtomicPtr volatile *a, void *desired) {
cast(void *)cast(intptr)gb_atomic32_exchanged(cast(gbAtomic32 volatile *)a, cast(i32)cast(intptr)desired);
}
-
-gb_inline void *
-gb_atomic_ptr_fetch_add(gbAtomicPtr volatile *a, void *operand)
-{
+gb_inline void *gb_atomic_ptr_fetch_add(gbAtomicPtr volatile *a, void *operand) {
cast(void *)cast(intptr)gb_atomic32_fetch_add(cast(gbAtomic32 volatile *)a, cast(i32)cast(intptr)operand);
}
-
-gb_inline void *
-gb_atomic_ptr_fetch_and(gbAtomicPtr volatile *a, void *operand)
-{
+gb_inline void *gb_atomic_ptr_fetch_and(gbAtomicPtr volatile *a, void *operand) {
cast(void *)cast(intptr)gb_atomic32_fetch_and(cast(gbAtomic32 volatile *)a, cast(i32)cast(intptr)operand);
}
-
-gb_inline void *
-gb_atomic_ptr_fetch_or(gbAtomicPtr volatile *a, void *operand)
-{
+gb_inline void *gb_atomic_ptr_fetch_or(gbAtomicPtr volatile *a, void *operand) {
cast(void *)cast(intptr)gb_atomic32_fetch_or(cast(gbAtomic32 volatile *)a, cast(i32)cast(intptr)operand);
}
-
-gb_inline void
-gb_atomic_ptr_spin_lock(gbAtomicPtr volatile *a)
-{
+gb_inline void gb_atomic_ptr_spin_lock(gbAtomicPtr volatile *a) {
gb_atomic32_spin_lock(cast(gbAtomic32 volatile *)a);
}
-
-gb_inline void
-gb_atomic_ptr_spin_unlock(gbAtomicPtr volatile *a)
-{
+gb_inline void gb_atomic_ptr_spin_unlock(gbAtomicPtr volatile *a) {
gb_atomic32_spin_unlock(cast(gbAtomic32 volatile *)a);
}
#elif defined(GB_ARCH_64_BIT)
-
-gb_inline void *
-gb_atomic_ptr_load(gbAtomicPtr const volatile *a)
-{
+gb_inline void *gb_atomic_ptr_load(gbAtomicPtr const volatile *a) {
return cast(void *)cast(intptr)gb_atomic64_load(cast(gbAtomic64 const volatile *)a);
}
-
-gb_inline void
-gb_atomic_ptr_store(gbAtomicPtr volatile *a, void *value)
-{
+gb_inline void gb_atomic_ptr_store(gbAtomicPtr volatile *a, void *value) {
gb_atomic64_store(cast(gbAtomic64 volatile *)a, cast(i64)cast(intptr)value);
}
-
-gb_inline void *
-gb_atomic_ptr_compare_exchange(gbAtomicPtr volatile *a, void *expected, void *desired)
-{
+gb_inline void *gb_atomic_ptr_compare_exchange(gbAtomicPtr volatile *a, void *expected, void *desired) {
return cast(void *)cast(intptr)gb_atomic64_compare_exchange(cast(gbAtomic64 volatile *)a, cast(i64)cast(intptr)expected, cast(i64)cast(intptr)desired);
}
-
-gb_inline void *
-gb_atomic_ptr_exchanged(gbAtomicPtr volatile *a, void *desired)
-{
+gb_inline void *gb_atomic_ptr_exchanged(gbAtomicPtr volatile *a, void *desired) {
return cast(void *)cast(intptr)gb_atomic64_exchanged(cast(gbAtomic64 volatile *)a, cast(i64)cast(intptr)desired);
}
-
-gb_inline void *
-gb_atomic_ptr_fetch_add(gbAtomicPtr volatile *a, void *operand)
-{
+gb_inline void *gb_atomic_ptr_fetch_add(gbAtomicPtr volatile *a, void *operand) {
return cast(void *)cast(intptr)gb_atomic64_fetch_add(cast(gbAtomic64 volatile *)a, cast(i64)cast(intptr)operand);
}
-
-gb_inline void *
-gb_atomic_ptr_fetch_and(gbAtomicPtr volatile *a, void *operand)
-{
+gb_inline void *gb_atomic_ptr_fetch_and(gbAtomicPtr volatile *a, void *operand) {
return cast(void *)cast(intptr)gb_atomic64_fetch_and(cast(gbAtomic64 volatile *)a, cast(i64)cast(intptr)operand);
}
-
-gb_inline void *
-gb_atomic_ptr_fetch_or(gbAtomicPtr volatile *a, void *operand)
-{
+gb_inline void *gb_atomic_ptr_fetch_or(gbAtomicPtr volatile *a, void *operand) {
return cast(void *)cast(intptr)gb_atomic64_fetch_or(cast(gbAtomic64 volatile *)a, cast(i64)cast(intptr)operand);
}
-
-gb_inline void
-gb_atomic_ptr_spin_lock(gbAtomicPtr volatile *a)
-{
+gb_inline void gb_atomic_ptr_spin_lock(gbAtomicPtr volatile *a) {
gb_atomic64_spin_lock(cast(gbAtomic64 volatile *)a);
}
-
-gb_inline void
-gb_atomic_ptr_spin_unlock(gbAtomicPtr volatile *a)
-{
+gb_inline void gb_atomic_ptr_spin_unlock(gbAtomicPtr volatile *a) {
gb_atomic64_spin_unlock(cast(gbAtomic64 volatile *)a);
}
#endif
@@ -3339,9 +3167,7 @@ gb_atomic_ptr_spin_unlock(gbAtomicPtr volatile *a)
// NOTE(bill): THIS IS FUCKING AWESOME THAT THIS "MUTEX" IS FAST AND RECURSIVE TOO!
// NOTE(bill): WHO THE FUCK NEEDS A NORMAL MUTEX NOW?!?!?!?!
-gb_inline void
-gb_mutex_init(gbMutex *m)
-{
+gb_inline void gb_mutex_init(gbMutex *m) {
gb_atomic32_store(&m->counter, 0);
gb_atomic32_store(&m->owner, gb_thread_current_id());
gb_semaphore_init(&m->semaphore);
@@ -3350,9 +3176,7 @@ gb_mutex_init(gbMutex *m)
gb_inline void gb_mutex_destroy(gbMutex *m) { gb_semaphore_destroy(&m->semaphore); }
-gb_inline void
-gb_mutex_lock(gbMutex *m)
-{
+gb_inline void gb_mutex_lock(gbMutex *m) {
i32 thread_id = cast(i32)gb_thread_current_id();
if (gb_atomic32_fetch_add(&m->counter, 1) > 0) {
if (thread_id != gb_atomic32_load(&m->owner))
@@ -3363,9 +3187,7 @@ gb_mutex_lock(gbMutex *m)
m->recursion++;
}
-gb_inline b32
-gb_mutex_try_lock(gbMutex *m)
-{
+gb_inline b32 gb_mutex_try_lock(gbMutex *m) {
i32 thread_id = cast(i32)gb_thread_current_id();
if (gb_atomic32_load(&m->owner) == thread_id) {
gb_atomic32_fetch_add(&m->counter, 1);
@@ -3382,9 +3204,7 @@ gb_mutex_try_lock(gbMutex *m)
return true;
}
-gb_inline void
-gb_mutex_unlock(gbMutex *m)
-{
+gb_inline void gb_mutex_unlock(gbMutex *m) {
i32 recursion;
i32 thread_id = cast(i32)gb_thread_current_id();
@@ -3405,9 +3225,7 @@ gb_mutex_unlock(gbMutex *m)
-void
-gb_thread_init(gbThread *t)
-{
+void gb_thread_init(gbThread *t) {
gb_zero_item(t);
#if defined(GB_SYSTEM_WINDOWS)
t->win32_handle = INVALID_HANDLE_VALUE;
@@ -3417,17 +3235,13 @@ gb_thread_init(gbThread *t)
gb_semaphore_init(&t->semaphore);
}
-void
-gb_thread_destory(gbThread *t)
-{
+void gb_thread_destory(gbThread *t) {
if (t->is_running) gb_thread_join(t);
gb_semaphore_destroy(&t->semaphore);
}
-gb_inline void
-gb__thread_run(gbThread *t)
-{
+gb_inline void gb__thread_run(gbThread *t) {
gb_semaphore_post(&t->semaphore, 1);
t->proc(t->data);
}
@@ -3440,9 +3254,7 @@ gb__thread_run(gbThread *t)
gb_inline void gb_thread_start(gbThread *t, gbThreadProc *proc, void *data) { gb_thread_start_with_stack(t, proc, data, 0); }
-gb_inline void
-gb_thread_start_with_stack(gbThread *t, gbThreadProc *proc, void *data, isize stack_size)
-{
+gb_inline void gb_thread_start_with_stack(gbThread *t, gbThreadProc *proc, void *data, isize stack_size) {
GB_ASSERT(!t->is_running);
GB_ASSERT(proc != NULL);
t->proc = proc;
@@ -3468,9 +3280,7 @@ gb_thread_start_with_stack(gbThread *t, gbThreadProc *proc, void *data, isize st
gb_semaphore_wait(&t->semaphore);
}
-gb_inline void
-gb_thread_join(gbThread *t)
-{
+gb_inline void gb_thread_join(gbThread *t) {
if (!t->is_running) return;
#if defined(GB_SYSTEM_WINDOWS)
@@ -3486,9 +3296,7 @@ gb_thread_join(gbThread *t)
gb_inline b32 gb_thread_is_running(gbThread const *t) { return t->is_running != 0; }
-gb_inline u32
-gb_thread_current_id(void)
-{
+gb_inline u32 gb_thread_current_id(void) {
u32 thread_id;
#if defined(GB_SYSTEM_WINDOWS)
thread_id = GetCurrentThreadId();
@@ -3507,9 +3315,7 @@ gb_thread_current_id(void)
-void
-gb_thread_set_name(gbThread *t, char const *name)
-{
+void gb_thread_set_name(gbThread *t, char const *name) {
#if defined(_MSC_VER)
// TODO(bill): Bloody Windows!!!
#pragma pack(push, 8)
@@ -3547,17 +3353,13 @@ gb_thread_set_name(gbThread *t, char const *name)
-gb_inline gbAllocator
-gb_heap_allocator(void)
-{
+gb_inline gbAllocator gb_heap_allocator(void) {
gbAllocator a;
a.proc = gb_heap_allocator_proc;
a.data = NULL;
return a;
}
-
-GB_ALLOCATOR_PROC(gb_heap_allocator_proc)
-{
+ GB_ALLOCATOR_PROC(gb_heap_allocator_proc) {
gb_unused(allocator_data);
gb_unused(options);
gb_unused(old_size);
@@ -3602,9 +3404,7 @@ GB_ALLOCATOR_PROC(gb_heap_allocator_proc)
//
//
-gbVirtualMemory
-gb_virtual_memory(void *data, isize size)
-{
+gbVirtualMemory gb_virtual_memory(void *data, isize size) {
gbVirtualMemory vm;
vm.data = data;
vm.size = size;
@@ -3613,9 +3413,7 @@ gb_virtual_memory(void *data, isize size)
#if defined(GB_SYSTEM_WINDOWS)
-gb_inline gbVirtualMemory
-gb_vm_alloc(void *addr, isize size)
-{
+gb_inline gbVirtualMemory gb_vm_alloc(void *addr, isize size) {
gbVirtualMemory vm;
GB_ASSERT(size > 0);
vm.data = VirtualAlloc(addr, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
@@ -3623,15 +3421,11 @@ gb_vm_alloc(void *addr, isize size)
return vm;
}
-gb_inline void
-gb_vm_free(gbVirtualMemory vm)
-{
+gb_inline void gb_vm_free(gbVirtualMemory vm) {
VirtualFree(vm.data, vm.size > 0 ? vm.size : 0, MEM_RELEASE);
}
-gb_inline gbVirtualMemory
-gb_vm_trim(gbVirtualMemory vm, isize lead_size, isize size)
-{
+gb_inline gbVirtualMemory gb_vm_trim(gbVirtualMemory vm, isize lead_size, isize size) {
gbVirtualMemory new_vm = {0};
void *ptr;
GB_ASSERT(vm.size >= lead_size + size);
@@ -3647,9 +3441,7 @@ gb_vm_trim(gbVirtualMemory vm, isize lead_size, isize size)
return new_vm;
}
-gb_inline b32
-gb_vm_purge(gbVirtualMemory vm)
-{
+gb_inline b32 gb_vm_purge(gbVirtualMemory vm) {
VirtualAlloc(vm.data, vm.size, MEM_RESET, PAGE_READWRITE);
// NOTE(bill): Can this really fail?
return true;
@@ -3660,9 +3452,7 @@ gb_vm_purge(gbVirtualMemory vm)
#define MAP_ANONYMOUS MAP_ANON
#endif
-gb_inline gbVirtualMemory
-gb_vm_alloc(void *addr, isize size)
-{
+gb_inline gbVirtualMemory gb_vm_alloc(void *addr, isize size) {
gbVirtualMemory vm;
GB_ASSERT(size > 0);
vm.data = mmap(addr, size,
@@ -3673,15 +3463,11 @@ gb_vm_alloc(void *addr, isize size)
return vm;
}
-gb_inline void
-gb_vm_free(gbVirtualMemory vm)
-{
+gb_inline void gb_vm_free(gbVirtualMemory vm) {
munmap(vm.data, vm.size);
}
-gb_inline gbVirtualMemory
-gb_vm_trim(gbVirtualMemory vm, isize lead_size, isize size)
-{
+gb_inline gbVirtualMemory gb_vm_trim(gbVirtualMemory vm, isize lead_size, isize size) {
void *ptr;
isize trail_size;
GB_ASSERT(vm.size >= lead_size + size);
@@ -3697,9 +3483,7 @@ gb_vm_trim(gbVirtualMemory vm, isize lead_size, isize size)
}
-gb_inline b32
-gb_vm_purge(gbVirtualMemory vm)
-{
+gb_inline b32 gb_vm_purge(gbVirtualMemory vm) {
int err = madvise(vm.data, vm.size, MADV_DONTNEED);
return err != 0;
}
@@ -3719,9 +3503,7 @@ gb_vm_purge(gbVirtualMemory vm)
// Arena Allocator
//
-gb_inline void
-gb_arena_init_from_memory(gbArena *arena, void *start, isize size)
-{
+gb_inline void gb_arena_init_from_memory(gbArena *arena, void *start, isize size) {
arena->backing.proc = NULL;
arena->backing.data = NULL;
arena->physical_start = start;
@@ -3730,9 +3512,7 @@ gb_arena_init_from_memory(gbArena *arena, void *start, isize size)
arena->temp_count = 0;
}
-gb_inline void
-gb_arena_init_from_allocator(gbArena *arena, gbAllocator backing, isize size)
-{
+gb_inline void gb_arena_init_from_allocator(gbArena *arena, gbAllocator backing, isize size) {
arena->backing = backing;
arena->physical_start = gb_alloc(backing, size); // NOTE(bill): Uses default alignment
arena->total_size = size;
@@ -3743,9 +3523,7 @@ gb_arena_init_from_allocator(gbArena *arena, gbAllocator backing, isize size)
gb_inline void gb_arena_init_sub(gbArena *arena, gbArena *parent_arena, isize size) { gb_arena_init_from_allocator(arena, gb_arena_allocator(parent_arena), size); }
-gb_inline void
-gb_arena_free(gbArena *arena)
-{
+gb_inline void gb_arena_free(gbArena *arena) {
if (arena->backing.proc) {
gb_free(arena->backing, arena->physical_start);
arena->physical_start = NULL;
@@ -3753,9 +3531,7 @@ gb_arena_free(gbArena *arena)
}
-gb_inline isize
-gb_arena_alignment_of(gbArena *arena, isize alignment)
-{
+gb_inline isize gb_arena_alignment_of(gbArena *arena, isize alignment) {
isize alignment_offset, result_pointer, mask;
GB_ASSERT(gb_is_power_of_two(alignment));
@@ -3768,9 +3544,7 @@ gb_arena_alignment_of(gbArena *arena, isize alignment)
return alignment_offset;
}
-gb_inline isize
-gb_arena_size_remaining(gbArena *arena, isize alignment)
-{
+gb_inline isize gb_arena_size_remaining(gbArena *arena, isize alignment) {
isize result = arena->total_size - (arena->total_allocated + gb_arena_alignment_of(arena, alignment));
return result;
}
@@ -3782,18 +3556,14 @@ gb_inline void gb_arena_check(gbArena *arena) { GB_ASSERT(arena->temp_count == 0
-gb_inline gbAllocator
-gb_arena_allocator(gbArena *arena)
-{
+gb_inline gbAllocator gb_arena_allocator(gbArena *arena) {
gbAllocator allocator;
allocator.proc = gb_arena_allocator_proc;
allocator.data = arena;
return allocator;
}
-
-GB_ALLOCATOR_PROC(gb_arena_allocator_proc)
-{
+GB_ALLOCATOR_PROC(gb_arena_allocator_proc) {
gbArena *arena = cast(gbArena *)allocator_data;
gb_unused(options);
@@ -3834,9 +3604,7 @@ GB_ALLOCATOR_PROC(gb_arena_allocator_proc)
}
-gb_inline gbTempArenaMemory
-gb_temp_arena_memory_begin(gbArena *arena)
-{
+gb_inline gbTempArenaMemory gb_temp_arena_memory_begin(gbArena *arena) {
gbTempArenaMemory tmp;
tmp.arena = arena;
tmp.original_count = arena->total_allocated;
@@ -3844,9 +3612,7 @@ gb_temp_arena_memory_begin(gbArena *arena)
return tmp;
}
-gb_inline void
-gb_temp_arena_memory_end(gbTempArenaMemory tmp)
-{
+gb_inline void gb_temp_arena_memory_end(gbTempArenaMemory tmp) {
GB_ASSERT(tmp.arena->total_allocated >= tmp.original_count);
GB_ASSERT(tmp.arena->temp_count > 0);
tmp.arena->total_allocated = tmp.original_count;
@@ -3861,15 +3627,11 @@ gb_temp_arena_memory_end(gbTempArenaMemory tmp)
//
-gb_inline void
-gb_pool_init(gbPool *pool, gbAllocator backing, isize num_blocks, isize block_size)
-{
+gb_inline void gb_pool_init(gbPool *pool, gbAllocator backing, isize num_blocks, isize block_size) {
gb_pool_init_align(pool, backing, num_blocks, block_size, GB_DEFAULT_MEMORY_ALIGNMENT);
}
-void
-gb_pool_init_align(gbPool *pool, gbAllocator backing, isize num_blocks, isize block_size, isize block_align)
-{
+void gb_pool_init_align(gbPool *pool, gbAllocator backing, isize num_blocks, isize block_size, isize block_align) {
isize actual_block_size, pool_size, block_index;
void *data, *curr;
uintptr *end;
@@ -3900,26 +3662,20 @@ gb_pool_init_align(gbPool *pool, gbAllocator backing, isize num_blocks, isize bl
pool->free_list = data;
}
-gb_inline void
-gb_pool_free(gbPool *pool)
-{
+gb_inline void gb_pool_free(gbPool *pool) {
if (pool->backing.proc) {
gb_free(pool->backing, pool->physical_start);
}
}
-gb_inline gbAllocator
-gb_pool_allocator(gbPool *pool)
-{
+gb_inline gbAllocator gb_pool_allocator(gbPool *pool) {
gbAllocator allocator;
allocator.proc = gb_pool_allocator_proc;
allocator.data = pool;
return allocator;
}
-
-GB_ALLOCATOR_PROC(gb_pool_allocator_proc)
-{
+GB_ALLOCATOR_PROC(gb_pool_allocator_proc) {
gbPool *pool = cast(gbPool *)allocator_data;
gb_unused(options);
@@ -3967,17 +3723,14 @@ GB_ALLOCATOR_PROC(gb_pool_allocator_proc)
-gb_inline gbAllocationHeader *
-gb_allocation_header(void *data)
-{
+gb_inline gbAllocationHeader *gb_allocation_header(void *data) {
isize *p = cast(isize *)data;
while (p[-1] == cast(isize)(-1))
p--;
return cast(gbAllocationHeader *)p - 1;
}
-gb_inline void gb_allocation_header_fill(gbAllocationHeader *header, void *data, isize size)
-{
+gb_inline void gb_allocation_header_fill(gbAllocationHeader *header, void *data, isize size) {
isize *ptr;
header->size = size;
ptr = cast(isize *)(header + 1);
@@ -3991,9 +3744,7 @@ gb_inline void gb_allocation_header_fill(gbAllocationHeader *header, void *data,
// Free List Allocator
//
-gb_inline void
-gb_free_list_init(gbFreeList *fl, void *start, isize size)
-{
+gb_inline void gb_free_list_init(gbFreeList *fl, void *start, isize size) {
GB_ASSERT(size > gb_size_of(gbFreeListBlock));
fl->physical_start = start;
@@ -4004,27 +3755,21 @@ gb_free_list_init(gbFreeList *fl, void *start, isize size)
}
-gb_inline void
-gb_free_list_init_from_allocator(gbFreeList *fl, gbAllocator backing, isize size)
-{
+gb_inline void gb_free_list_init_from_allocator(gbFreeList *fl, gbAllocator backing, isize size) {
void *start = gb_alloc(backing, size);
gb_free_list_init(fl, start, size);
}
-gb_inline gbAllocator
-gb_free_list_allocator(gbFreeList *fl)
-{
+gb_inline gbAllocator gb_free_list_allocator(gbFreeList *fl) {
gbAllocator a;
a.proc = gb_free_list_allocator_proc;
a.data = fl;
return a;
}
-
-GB_ALLOCATOR_PROC(gb_free_list_allocator_proc)
-{
+GB_ALLOCATOR_PROC(gb_free_list_allocator_proc) {
gbFreeList *fl = cast(gbFreeList *)allocator_data;
GB_ASSERT_NOT_NULL(fl);
gb_unused(options);
@@ -4143,9 +3888,7 @@ GB_ALLOCATOR_PROC(gb_free_list_allocator_proc)
-void
-gb_scratch_memory_init(gbScratchMemory *s, void *start, isize size)
-{
+void gb_scratch_memory_init(gbScratchMemory *s, void *start, isize size) {
s->physical_start = start;
s->total_size = size;
s->alloc_point = start;
@@ -4153,9 +3896,7 @@ gb_scratch_memory_init(gbScratchMemory *s, void *start, isize size)
}
-b32
-gb_scratch_memory_is_in_use(gbScratchMemory *s, void *ptr)
-{
+b32 gb_scratch_memory_is_in_use(gbScratchMemory *s, void *ptr) {
if (s->free_point == s->alloc_point) return false;
if (s->alloc_point > s->free_point)
return ptr >= s->free_point && ptr < s->alloc_point;
@@ -4163,17 +3904,14 @@ gb_scratch_memory_is_in_use(gbScratchMemory *s, void *ptr)
}
-gbAllocator
-gb_scratch_allocator(gbScratchMemory *s)
-{
+gbAllocator gb_scratch_allocator(gbScratchMemory *s) {
gbAllocator a;
a.proc = gb_scratch_allocator_proc;
a.data = s;
return a;
}
-GB_ALLOCATOR_PROC(gb_scratch_allocator_proc)
-{
+GB_ALLOCATOR_PROC(gb_scratch_allocator_proc) {
gbScratchMemory *s = cast(gbScratchMemory *)allocator_data;
GB_ASSERT_NOT_NULL(s);
gb_unused(options);
@@ -4255,15 +3993,12 @@ GB_ALLOCATOR_PROC(gb_scratch_allocator_proc)
// TODO(bill): Should I make all the macros local?
#define GB__COMPARE_PROC(Type) \
-gb_global isize gb__##Type##_cmp_offset; \
-GB_COMPARE_PROC(gb__##Type##_cmp) \
-{ \
+gb_global isize gb__##Type##_cmp_offset; GB_COMPARE_PROC(gb__##Type##_cmp) { \
Type const p = *cast(Type const *)gb_pointer_add_const(a, gb__##Type##_cmp_offset); \
Type const q = *cast(Type const *)gb_pointer_add_const(b, gb__##Type##_cmp_offset); \
return p < q ? -1 : p > q; \
} \
-GB_COMPARE_PROC_PTR(gb_##Type##_cmp(isize offset)) \
-{ \
+GB_COMPARE_PROC_PTR(gb_##Type##_cmp(isize offset)) { \
gb__##Type##_cmp_offset = offset; \
return &gb__##Type##_cmp; \
}
@@ -4278,15 +4013,12 @@ GB__COMPARE_PROC(f64);
GB__COMPARE_PROC(char);
// NOTE(bill): str_cmp is special as it requires a funny type and funny comparison
-gb_global isize gb__str_cmp_offset;
-GB_COMPARE_PROC(gb__str_cmp)
-{
+gb_global isize gb__str_cmp_offset; GB_COMPARE_PROC(gb__str_cmp) {
char const *p = *cast(char const **)gb_pointer_add_const(a, gb__str_cmp_offset);
char const *q = *cast(char const **)gb_pointer_add_const(b, gb__str_cmp_offset);
return gb_strcmp(p, q);
}
-GB_COMPARE_PROC_PTR(gb_str_cmp(isize offset))
-{
+GB_COMPARE_PROC_PTR(gb_str_cmp(isize offset)) {
gb__str_cmp_offset = offset;
return &gb__str_cmp;
}
@@ -4297,7 +4029,7 @@ GB_COMPARE_PROC_PTR(gb_str_cmp(isize offset))
// TODO(bill): Make user definable?
-#define GB__SORT_STACK_SIZE 64
+#define GB__SORT_STACK_SIZE 64
#define GB__SORT_INSERT_SORT_THRESHOLD 8
#define GB__SORT_PUSH(_base, _limit) do { \
@@ -4315,9 +4047,7 @@ GB_COMPARE_PROC_PTR(gb_str_cmp(isize offset))
-void
-gb_sort(void *base_, isize count, isize size, gbCompareProc cmp)
-{
+void gb_sort(void *base_, isize count, isize size, gbCompareProc cmp) {
u8 *i, *j;
u8 *base = cast(u8 *)base_;
u8 *limit = base + count*size;
@@ -4339,14 +4069,9 @@ gb_sort(void *base_, isize count, isize size, gbCompareProc cmp)
if (cmp(i, base) > 0) gb_memswap(i, base, size);
for (;;) {
- do {
- i += size;
- } while(cmp(i, base) < 0);
- do {
- j -= size;
- } while (cmp(j, base) > 0);
- if (i > j)
- break;
+ do i += size; while (cmp(i, base) < 0);
+ do j -= size; while (cmp(j, base) > 0);
+ if (i > j) break;
gb_memswap(i, j, size);
}
@@ -4366,13 +4091,11 @@ gb_sort(void *base_, isize count, isize size, gbCompareProc cmp)
j = i, i += size) {
for (; cmp(j, j+size) > 0; j -= size) {
gb_memswap(j, j+size, size);
- if (j == base)
- break;
+ if (j == base) break;
}
}
- if (stack_ptr == stack)
- break; // NOTE(bill): Sorting is done!
+ if (stack_ptr == stack) break; // NOTE(bill): Sorting is done!
GB__SORT_POP(base, limit);
}
}
@@ -4382,8 +4105,7 @@ gb_sort(void *base_, isize count, isize size, gbCompareProc cmp)
#undef GB__SORT_POP
-#define GB_RADIX_SORT_PROC_GEN(Type) GB_RADIX_SORT_PROC(Type) \
-{ \
+#define GB_RADIX_SORT_PROC_GEN(Type) GB_RADIX_SORT_PROC(Type) { \
Type *gb_restrict source = items; \
Type *gb_restrict dest = temp; \
isize byte_index, i, byte_max = 8*gb_size_of(Type); \
@@ -4417,9 +4139,7 @@ GB_RADIX_SORT_PROC_GEN(u16);
GB_RADIX_SORT_PROC_GEN(u32);
GB_RADIX_SORT_PROC_GEN(u64);
-gb_inline isize
-gb_binary_search(void const *base, isize count, isize size, void const *key, gbCompareProc compare_proc)
-{
+gb_inline isize gb_binary_search(void const *base, isize count, isize size, void const *key, gbCompareProc compare_proc) {
isize start = 0;
isize end = count;
@@ -4449,25 +4169,19 @@ gb_binary_search(void const *base, isize count, isize size, void const *key, gbC
-gb_inline char
-gb_char_to_lower(char c)
-{
+gb_inline char gb_char_to_lower(char c) {
if (c >= 'A' && c <= 'Z')
return 'a' + (c - 'A');
return c;
}
-gb_inline char
-gb_char_to_upper(char c)
-{
+gb_inline char gb_char_to_upper(char c) {
if (c >= 'a' && c <= 'z')
return 'A' + (c - 'a');
return c;
}
-gb_inline b32
-gb_char_is_space(char c)
-{
+gb_inline b32 gb_char_is_space(char c) {
if (c == ' ' ||
c == '\t' ||
c == '\n' ||
@@ -4478,17 +4192,13 @@ gb_char_is_space(char c)
return false;
}
-gb_inline b32
-gb_char_is_digit(char c)
-{
+gb_inline b32 gb_char_is_digit(char c) {
if (c >= '0' && c <= '9')
return true;
return false;
}
-gb_inline b32
-gb_char_is_hex_digit(char c)
-{
+gb_inline b32 gb_char_is_hex_digit(char c) {
if (gb_char_is_digit(c) ||
(c >= 'a' && c <= 'f') ||
(c >= 'A' && c <= 'F'))
@@ -4496,30 +4206,22 @@ gb_char_is_hex_digit(char c)
return false;
}
-gb_inline b32
-gb_char_is_alpha(char c)
-{
+gb_inline b32 gb_char_is_alpha(char c) {
if ((c >= 'A' && c <= 'Z') ||
(c >= 'a' && c <= 'z'))
return true;
return false;
}
-gb_inline b32
-gb_char_is_alphanumeric(char c)
-{
+gb_inline b32 gb_char_is_alphanumeric(char c) {
return gb_char_is_alpha(c) || gb_char_is_digit(c);
}
-gb_inline i32
-gb_digit_to_int(char c)
-{
+gb_inline i32 gb_digit_to_int(char c) {
return gb_char_is_digit(c) ? c - '0' : c - 'W';
}
-gb_inline i32
-gb_hex_digit_to_int(char c)
-{
+gb_inline i32 gb_hex_digit_to_int(char c) {
if (gb_char_is_digit(c))
return gb_digit_to_int(c);
else if (gb_is_between(c, 'a', 'f'))
@@ -4532,9 +4234,7 @@ gb_hex_digit_to_int(char c)
-gb_inline void
-gb_str_to_lower(char *str)
-{
+gb_inline void gb_str_to_lower(char *str) {
if (!str) return;
while (*str) {
*str = gb_char_to_lower(*str);
@@ -4542,9 +4242,7 @@ gb_str_to_lower(char *str)
}
}
-gb_inline void
-gb_str_to_upper(char *str)
-{
+gb_inline void gb_str_to_upper(char *str) {
if (!str) return;
while (*str) {
*str = gb_char_to_upper(*str);
@@ -4553,9 +4251,7 @@ gb_str_to_upper(char *str)
}
-gb_inline isize
-gb_strlen(char const *str)
-{
+gb_inline isize gb_strlen(char const *str) {
isize result = 0;
if (str) {
char const *end = str;
@@ -4565,9 +4261,7 @@ gb_strlen(char const *str)
return result;
}
-gb_inline isize
-gb_strnlen(char const *str, isize max_len)
-{
+gb_inline isize gb_strnlen(char const *str, isize max_len) {
isize result = 0;
if (str) {
char const *end = str;
@@ -4578,9 +4272,7 @@ gb_strnlen(char const *str, isize max_len)
}
-gb_inline isize
-gb_utf8_strlen(char const *str)
-{
+gb_inline isize gb_utf8_strlen(char const *str) {
isize result = 0;
for (; *str; str++) {
if ((*str & 0xc0) != 0x80)
@@ -4589,9 +4281,7 @@ gb_utf8_strlen(char const *str)
return result;
}
-gb_inline isize
-gb_utf8_strnlen(char const *str, isize max_len)
-{
+gb_inline isize gb_utf8_strnlen(char const *str, isize max_len) {
isize result = 0;
for (; *str && result < max_len; str++) {
if ((*str & 0xc0) != 0x80)
@@ -4601,18 +4291,14 @@ gb_utf8_strnlen(char const *str, isize max_len)
}
-gb_inline i32
-gb_strcmp(char const *s1, char const *s2)
-{
+gb_inline i32 gb_strcmp(char const *s1, char const *s2) {
while (*s1 && (*s1 == *s2)) {
s1++, s2++;
}
return *(u8 *)s1 - *(u8 *)s2;
}
-gb_inline char *
-gb_strcpy(char *dest, char const *source)
-{
+gb_inline char *gb_strcpy(char *dest, char const *source) {
GB_ASSERT_NOT_NULL(dest);
if (source) {
char *str = dest;
@@ -4622,9 +4308,7 @@ gb_strcpy(char *dest, char const *source)
}
-gb_inline char *
-gb_strncpy(char *dest, char const *source, isize len)
-{
+gb_inline char *gb_strncpy(char *dest, char const *source, isize len) {
GB_ASSERT_NOT_NULL(dest);
if (source) {
char *str = dest;
@@ -4640,9 +4324,7 @@ gb_strncpy(char *dest, char const *source, isize len)
return dest;
}
-gb_inline isize
-gb_strlcpy(char *dest, char const *source, isize len)
-{
+gb_inline isize gb_strlcpy(char *dest, char const *source, isize len) {
isize result = 0;
GB_ASSERT_NOT_NULL(dest);
if (source) {
@@ -4662,9 +4344,7 @@ gb_strlcpy(char *dest, char const *source, isize len)
return result;
}
-gb_inline char *
-gb_strrev(char *str)
-{
+gb_inline char *gb_strrev(char *str) {
isize len = gb_strlen(str);
char *a = str + 0;
char *b = str + len-1;
@@ -4679,9 +4359,7 @@ gb_strrev(char *str)
-gb_inline i32
-gb_strncmp(char const *s1, char const *s2, isize len)
-{
+gb_inline i32 gb_strncmp(char const *s1, char const *s2, isize len) {
for (; len > 0;
s1++, s2++, len--) {
if (*s1 != *s2)
@@ -4693,9 +4371,7 @@ gb_strncmp(char const *s1, char const *s2, isize len)
}
-gb_inline char const *
-gb_strtok(char *output, char const *src, char const *delimit)
-{
+gb_inline char const *gb_strtok(char *output, char const *src, char const *delimit) {
while (*src && gb_char_first_occurence(delimit, *src) != NULL)
*output++ = *src++;
@@ -4703,9 +4379,7 @@ gb_strtok(char *output, char const *src, char const *delimit)
return *src ? src+1 : src;
}
-gb_inline b32
-gb_str_has_prefix(char const *str, char const *prefix)
-{
+gb_inline b32 gb_str_has_prefix(char const *str, char const *prefix) {
while (*prefix) {
if (*str++ != *prefix++)
return false;
@@ -4713,9 +4387,7 @@ gb_str_has_prefix(char const *str, char const *prefix)
return true;
}
-gb_inline b32
-gb_str_has_suffix(char const *str, char const *suffix)
-{
+gb_inline b32 gb_str_has_suffix(char const *str, char const *suffix) {
isize i = gb_strlen(str);
isize j = gb_strlen(suffix);
if (j <= i)
@@ -4726,9 +4398,7 @@ gb_str_has_suffix(char const *str, char const *suffix)
-gb_inline char const *
-gb_char_first_occurence(char const *s, char c)
-{
+gb_inline char const *gb_char_first_occurence(char const *s, char c) {
char ch = c;
for (; *s != ch; s++) {
if (*s == '\0')
@@ -4738,9 +4408,7 @@ gb_char_first_occurence(char const *s, char c)
}
-gb_inline char const *
-gb_char_last_occurence(char const *s, char c)
-{
+gb_inline char const *gb_char_last_occurence(char const *s, char c) {
char const *result = NULL;
do {
if (*s == c)
@@ -4752,11 +4420,9 @@ gb_char_last_occurence(char const *s, char c)
-gb_inline void
-gb_str_concat(char *dest, isize dest_len,
- char const *src_a, isize src_a_len,
- char const *src_b, isize src_b_len)
-{
+gb_inline void gb_str_concat(char *dest, isize dest_len,
+ char const *src_a, isize src_a_len,
+ char const *src_b, isize src_b_len) {
GB_ASSERT(dest_len >= src_a_len+src_b_len+1);
if (dest) {
gb_memcopy(dest, src_a, src_a_len);
@@ -4766,9 +4432,7 @@ gb_str_concat(char *dest, isize dest_len,
}
-gb_internal isize
-gb__scan_i64(char const *text, i32 base, i64 *value)
-{
+gb_internal isize gb__scan_i64(char const *text, i32 base, i64 *value) {
char const *text_begin = text;
i64 result = 0;
b32 negative = false;
@@ -4804,9 +4468,7 @@ gb__scan_i64(char const *text, i32 base, i64 *value)
}
-i64
-gb_str_to_i64(char const *str, char **end_ptr, i32 base)
-{
+i64 gb_str_to_i64(char const *str, char **end_ptr, i32 base) {
isize len;
i64 value;
@@ -4830,9 +4492,7 @@ gb_global char const gb__num_to_char_table[] =
"abcdefghijklmnopqrstuvwxyz"
"_/";
-gb_inline void
-gb_i64_to_str(i64 value, char *string, i32 base)
-{
+gb_inline void gb_i64_to_str(i64 value, char *string, i32 base) {
char *buf = string;
b32 negative = false;
if (value < 0) {
@@ -4855,9 +4515,7 @@ gb_i64_to_str(i64 value, char *string, i32 base)
-gb_inline void
-gb_u64_to_str(u64 value, char *string, i32 base)
-{
+gb_inline void gb_u64_to_str(u64 value, char *string, i32 base) {
char *buf = string;
if (value) {
@@ -4882,16 +4540,12 @@ gb_inline void gb__set_string_length (gbString str, isize len) { GB_STRING_HEAD
gb_inline void gb__set_string_capacity(gbString str, isize cap) { GB_STRING_HEADER(str)->capacity = cap; }
-gb_inline gbString
-gb_string_make(gbAllocator a, char const *str)
-{
+gb_inline gbString gb_string_make(gbAllocator a, char const *str) {
isize len = str ? gb_strlen(str) : 0;
return gb_string_make_length(a, str, len);
}
-gbString
-gb_string_make_length(gbAllocator a, void const *init_str, isize num_bytes)
-{
+gbString gb_string_make_length(gbAllocator a, void const *init_str, isize num_bytes) {
isize header_size = gb_size_of(gbStringHeader);
void *ptr = gb_alloc(a, header_size + num_bytes + 1);
@@ -4913,9 +4567,7 @@ gb_string_make_length(gbAllocator a, void const *init_str, isize num_bytes)
return str;
}
-gb_inline void
-gb_string_free(gbString str)
-{
+gb_inline void gb_string_free(gbString str) {
if (str) {
gbStringHeader *header = GB_STRING_HEADER(str);
gb_free(header->allocator, header);
@@ -4928,9 +4580,7 @@ gb_inline gbString gb_string_duplicate(gbAllocator a, gbString const str) { retu
gb_inline isize gb_string_length (gbString const str) { return GB_STRING_HEADER(str)->length; }
gb_inline isize gb_string_capacity(gbString const str) { return GB_STRING_HEADER(str)->capacity; }
-gb_inline isize
-gb_string_available_space(gbString const str)
-{
+gb_inline isize gb_string_available_space(gbString const str) {
gbStringHeader *h = GB_STRING_HEADER(str);
if (h->capacity > h->length)
return h->capacity - h->length;
@@ -4942,9 +4592,7 @@ gb_inline void gb_string_clear(gbString str) { gb__set_string_length(str, 0); st
gb_inline gbString gb_string_append(gbString str, gbString const other) { return gb_string_append_length(str, other, gb_string_length(other)); }
-gbString
-gb_string_append_length(gbString str, void const *other, isize other_len)
-{
+gbString gb_string_append_length(gbString str, void const *other, isize other_len) {
isize curr_len = gb_string_length(str);
str = gb_string_make_space_for(str, other_len);
@@ -4958,16 +4606,12 @@ gb_string_append_length(gbString str, void const *other, isize other_len)
return str;
}
-gb_inline gbString
-gb_string_appendc(gbString str, char const *other)
-{
+gb_inline gbString gb_string_appendc(gbString str, char const *other) {
return gb_string_append_length(str, other, gb_strlen(other));
}
-gbString
-gb_string_set(gbString str, char const *cstr)
-{
+gbString gb_string_set(gbString str, char const *cstr) {
isize len = gb_strlen(cstr);
if (gb_string_capacity(str) < len) {
str = gb_string_make_space_for(str, len - gb_string_length(str));
@@ -4984,9 +4628,7 @@ gb_string_set(gbString str, char const *cstr)
-gbString
-gb_string_make_space_for(gbString str, isize add_len)
-{
+gbString gb_string_make_space_for(gbString str, isize add_len) {
isize available = gb_string_available_space(str);
// NOTE(bill): Return if there is enough space left
@@ -5011,17 +4653,13 @@ gb_string_make_space_for(gbString str, isize add_len)
}
}
-gb_inline isize
-gb_string_allocation_size(gbString const str)
-{
+gb_inline isize gb_string_allocation_size(gbString const str) {
isize cap = gb_string_capacity(str);
return gb_size_of(gbStringHeader) + cap;
}
-gb_inline b32
-gb_string_are_equal(gbString const lhs, gbString const rhs)
-{
+gb_inline b32 gb_string_are_equal(gbString const lhs, gbString const rhs) {
isize lhs_len, rhs_len, i;
lhs_len = gb_string_length(lhs);
rhs_len = gb_string_length(rhs);
@@ -5037,9 +4675,7 @@ gb_string_are_equal(gbString const lhs, gbString const rhs)
}
-gbString
-gb_string_trim(gbString str, char const *cut_set)
-{
+gbString gb_string_trim(gbString str, char const *cut_set) {
char *start, *end, *start_pos, *end_pos;
isize len;
@@ -5074,9 +4710,7 @@ gb_inline gbString gb_string_trim_space(gbString str) { return gb_string_trim(st
//
-char16 *
-gb_utf8_to_ucs2(char16 *buffer, isize len, char const *s)
-{
+char16 *gb_utf8_to_ucs2(char16 *buffer, isize len, char const *s) {
u8 *str = cast(u8 *)s;
char32 c;
isize i = 0;
@@ -5141,9 +4775,7 @@ gb_utf8_to_ucs2(char16 *buffer, isize len, char const *s)
return buffer;
}
-char *
-gb_ucs2_to_utf8(char *buffer, isize len, char16 const *str)
-{
+char *gb_ucs2_to_utf8(char *buffer, isize len, char16 const *str) {
isize i = 0;
len--;
while (*str) {
@@ -5182,16 +4814,12 @@ gb_ucs2_to_utf8(char *buffer, isize len, char16 const *str)
return buffer;
}
-char16 *
-gb_utf8_to_ucs2_buf(char const *str) // NOTE(bill): Uses locally persisting buffer
-{
+char16 *gb_utf8_to_ucs2_buf(char const *str) { // NOTE(bill): Uses locally persisting buffer
gb_local_persist char16 buf[4096];
return gb_utf8_to_ucs2(buf, gb_count_of(buf), str);
}
-char *
-gb_ucs2_to_utf8_buf(char16 const *str) // NOTE(bill): Uses locally persisting buffer
-{
+char *gb_ucs2_to_utf8_buf(char16 const *str) { // NOTE(bill): Uses locally persisting buffer
gb_local_persist char buf[4096];
return gb_ucs2_to_utf8(buf, gb_count_of(buf), str);
}
@@ -5207,9 +4835,7 @@ gb_global u8 const gb__utf_mask[GB__UTF_SIZE+1] = {0xc0, 0x80, 0xe0, 0xf0, 0
gb_global char32 const gb__utf_min [GB__UTF_SIZE+1] = {0, 0, 0x80, 0x800, 0x10000};
gb_global char32 const gb__utf_max [GB__UTF_SIZE+1] = {0x10ffff, 0x7f, 0x7ff, 0xffff, 0x10ffff};
-gb_internal isize
-gb__utf_validate(char32 *c, isize i)
-{
+gb_internal isize gb__utf_validate(char32 *c, isize i) {
GB_ASSERT_NOT_NULL(c);
if (!c) return 0;
if (!gb_is_between(*c, gb__utf_min[i], gb__utf_max[i]) ||
@@ -5222,9 +4848,7 @@ gb__utf_validate(char32 *c, isize i)
return i;
}
-gb_internal char32
-gb__utf_decode_byte(char c, isize *i)
-{
+gb_internal char32 gb__utf_decode_byte(char c, isize *i) {
GB_ASSERT_NOT_NULL(i);
if (!i) return 0;
for (*i = 0; *i < gb_count_of(gb__utf_mask); (*i)++) {
@@ -5236,9 +4860,7 @@ gb__utf_decode_byte(char c, isize *i)
gb_inline isize gb_utf8_decode(char const *str, char32 *codepoint) { return gb_utf8_decode_len(str, gb_strlen(str), codepoint); }
-isize
-gb_utf8_decode_len(char const *s, isize str_len, char32 *c)
-{
+isize gb_utf8_decode_len(char const *s, isize str_len, char32 *c) {
isize i, j, len, type = 0;
char32 cp;
@@ -5275,9 +4897,7 @@ gb_utf8_decode_len(char const *s, isize str_len, char32 *c)
//
-gb_no_inline void *
-gb__array_set_capacity(void *array, isize capacity, isize element_size)
-{
+gb_no_inline void *gb__array_set_capacity(void *array, isize capacity, isize element_size) {
gbArrayHeader *h = GB_ARRAY_HEADER(array);
GB_ASSERT(element_size > 0);
@@ -5314,9 +4934,7 @@ gb__array_set_capacity(void *array, isize capacity, isize element_size)
//
//
-u32
-gb_adler32(void const *data, isize len)
-{
+u32 gb_adler32(void const *data, isize len) {
u32 const MOD_ALDER = 65521;
u32 a = 1, b = 0;
isize i, block_len;
@@ -5483,9 +5101,7 @@ gb_global u64 const GB__CRC64_TABLE[256] = {
0x5dedc41a34bbeeb2ull, 0x1f1d25f19d51d821ull, 0xd80c07cd676f8394ull, 0x9afce626ce85b507ull,
};
-u32
-gb_crc32(void const *data, isize len)
-{
+u32 gb_crc32(void const *data, isize len) {
isize remaining;
u32 result = ~(cast(u32)0);
u8 const *c = cast(u8 const *)data;
@@ -5494,9 +5110,7 @@ gb_crc32(void const *data, isize len)
return ~result;
}
-u64
-gb_crc64(void const *data, isize len)
-{
+u64 gb_crc64(void const *data, isize len) {
isize remaining;
u64 result = ~(cast(u64)0);
u8 const *c = cast(u8 const *)data;
@@ -5505,9 +5119,7 @@ gb_crc64(void const *data, isize len)
return ~result;
}
-u32
-gb_fnv32(void const *data, isize len)
-{
+u32 gb_fnv32(void const *data, isize len) {
isize i;
u32 h = 0x811c9dc5;
u8 const *c = cast(u8 const *)data;
@@ -5518,9 +5130,7 @@ gb_fnv32(void const *data, isize len)
return h;
}
-u64
-gb_fnv64(void const *data, isize len)
-{
+u64 gb_fnv64(void const *data, isize len) {
isize i;
u64 h = 0xcbf29ce484222325ull;
u8 const *c = cast(u8 const *)data;
@@ -5531,9 +5141,7 @@ gb_fnv64(void const *data, isize len)
return h;
}
-u32
-gb_fnv32a(void const *data, isize len)
-{
+u32 gb_fnv32a(void const *data, isize len) {
isize i;
u32 h = 0x811c9dc5;
u8 const *c = cast(u8 const *)data;
@@ -5544,9 +5152,7 @@ gb_fnv32a(void const *data, isize len)
return h;
}
-u64
-gb_fnv64a(void const *data, isize len)
-{
+u64 gb_fnv64a(void const *data, isize len) {
isize i;
u64 h = 0xcbf29ce484222325ull;
u8 const *c = cast(u8 const *)data;
@@ -5560,9 +5166,7 @@ gb_fnv64a(void const *data, isize len)
gb_inline u32 gb_murmur32(void const *data, isize len) { return gb_murmur32_seed(data, len, 0x9747b28c); }
gb_inline u64 gb_murmur64(void const *data, isize len) { return gb_murmur64_seed(data, len, 0x9747b28c); }
-u32
-gb_murmur32_seed(void const *data, isize len, u32 seed)
-{
+u32 gb_murmur32_seed(void const *data, isize len, u32 seed) {
u32 const c1 = 0xcc9e2d51;
u32 const c2 = 0x1b873593;
u32 const r1 = 15;
@@ -5609,9 +5213,7 @@ gb_murmur32_seed(void const *data, isize len, u32 seed)
return hash;
}
-u64
-gb_murmur64_seed(void const *data_, isize len, u64 seed)
-{
+u64 gb_murmur64_seed(void const *data_, isize len, u64 seed) {
#if defined(GB_ARCH_64_BIT)
u64 const m = 0xc6a4a7935bd1e995ULL;
i32 const r = 47;
@@ -5726,9 +5328,7 @@ gb_murmur64_seed(void const *data_, isize len, u64 seed)
#if defined(GB_SYSTEM_WINDOWS)
-gb_internal
-GB_FILE_SEEK_PROC(gb__win32_file_seek)
-{
+gb_internal GB_FILE_SEEK_PROC(gb__win32_file_seek) {
LARGE_INTEGER li_offset;
li_offset.QuadPart = offset;
if (!SetFilePointerEx(fd.p, li_offset, &li_offset, whence)) {
@@ -5739,9 +5339,7 @@ GB_FILE_SEEK_PROC(gb__win32_file_seek)
return true;
}
-gb_internal
-GB_FILE_READ_AT_PROC(gb__win32_file_read)
-{
+gb_internal GB_FILE_READ_AT_PROC(gb__win32_file_read) {
b32 result = false;
DWORD size_ = cast(DWORD)(size > I32_MAX ? I32_MAX : size);
DWORD bytes_read_;
@@ -5754,9 +5352,7 @@ GB_FILE_READ_AT_PROC(gb__win32_file_read)
return result;
}
-gb_internal
-GB_FILE_WRITE_AT_PROC(gb__win32_file_write)
-{
+gb_internal GB_FILE_WRITE_AT_PROC(gb__win32_file_write) {
DWORD size_ = cast(DWORD)(size > I32_MAX ? I32_MAX : size);
DWORD bytes_written_;
gb__win32_file_seek(fd, offset, GB_SEEK_BEGIN, NULL);
@@ -5768,9 +5364,7 @@ GB_FILE_WRITE_AT_PROC(gb__win32_file_write)
}
-gb_internal
-GB_FILE_CLOSE_PROC(gb__win32_file_close)
-{
+gb_internal GB_FILE_CLOSE_PROC(gb__win32_file_close) {
CloseHandle(fd.p);
}
@@ -5784,9 +5378,7 @@ gbFileOperations const GB_DEFAULT_FILE_OPERATIONS = {
-
-GB_FILE_OPEN_PROC(gb__win32_file_open)
-{
+GB_FILE_OPEN_PROC(gb__win32_file_open) {
DWORD desired_access;
DWORD creation_disposition;
HANDLE handle;
@@ -5846,27 +5438,21 @@ GB_FILE_OPEN_PROC(gb__win32_file_open)
#else // POSIX
-gb_internal
-GB_FILE_SEEK_PROC(gb__posix_file_seek)
-{
+gb_internal GB_FILE_SEEK_PROC(gb__posix_file_seek) {
i64 res = lseek64(fd.i, offset, whence);
if (res < 0) return false;
if (new_offset) *new_offset = res;
return true;
}
-gb_internal
-GB_FILE_READ_AT_PROC(gb__posix_file_read)
-{
+gb_internal GB_FILE_READ_AT_PROC(gb__posix_file_read) {
isize res = pread(fd.i, buffer, size, offset);
if (res < 0) return false;
if (bytes_read) *bytes_read = res;
return true;
}
-gb_internal
-GB_FILE_WRITE_AT_PROC(gb__posix_file_write)
-{
+gb_internal GB_FILE_WRITE_AT_PROC(gb__posix_file_write) {
isize res = pwrite(fd.i, buffer, size, offset);
if (res < 0) return false;
if (bytes_written) *bytes_written = res;
@@ -5874,9 +5460,7 @@ GB_FILE_WRITE_AT_PROC(gb__posix_file_write)
}
-gb_internal
-GB_FILE_CLOSE_PROC(gb__posix_file_close)
-{
+gb_internal GB_FILE_CLOSE_PROC(gb__posix_file_close) {
close(fd.i);
}
@@ -5890,9 +5474,7 @@ gbFileOperations const GB_DEFAULT_FILE_OPERATIONS = {
-
-GB_FILE_OPEN_PROC(gb__posix_file_open)
-{
+GB_FILE_OPEN_PROC(gb__posix_file_open) {
i32 os_mode;
switch (mode & (GB_FILE_READ | GB_FILE_WRITE | GB_FILE_APPEND | GB_FILE_RW)) {
case GB_FILE_READ:
@@ -5932,9 +5514,7 @@ GB_FILE_OPEN_PROC(gb__posix_file_open)
-gbFileError
-gb_file_new(gbFile *f, gbFileDescriptor fd, gbFileOperations const *ops, char const *filename)
-{
+gbFileError gb_file_new(gbFile *f, gbFileDescriptor fd, gbFileOperations const *ops, char const *filename) {
gbFileError err = GB_FILE_ERR_NONE;
f->ops = ops;
@@ -5947,9 +5527,7 @@ gb_file_new(gbFile *f, gbFileDescriptor fd, gbFileOperations const *ops, char co
-gbFileError
-gb_file_open_mode_va(gbFile *f, gbFileMode mode, char const *filename, va_list va)
-{
+gbFileError gb_file_open_mode_va(gbFile *f, gbFileMode mode, char const *filename, va_list va) {
gbFileError err;
gb_local_persist char buffer[4096] = {0};
gb_snprintf_va(buffer, gb_size_of(buffer), filename, va);
@@ -5963,9 +5541,7 @@ gb_file_open_mode_va(gbFile *f, gbFileMode mode, char const *filename, va_list v
return err;
}
-gbFileError
-gb_file_close(gbFile *f)
-{
+gbFileError gb_file_close(gbFile *f) {
if (!f)
return GB_FILE_ERR_INVALID;
@@ -5980,36 +5556,26 @@ gb_file_close(gbFile *f)
return GB_FILE_ERR_NONE;
}
-gb_inline b32
-gb_file_read_at_check(gbFile *f, void *buffer, isize size, i64 offset, isize *bytes_read)
-{
+gb_inline b32 gb_file_read_at_check(gbFile *f, void *buffer, isize size, i64 offset, isize *bytes_read) {
if (!f->ops) f->ops = &GB_DEFAULT_FILE_OPERATIONS;
return f->ops->read_at(f->fd, buffer, size, offset, bytes_read);
}
-gb_inline b32
-gb_file_write_at_check(gbFile *f, void const *buffer, isize size, i64 offset, isize *bytes_written)
-{
+gb_inline b32 gb_file_write_at_check(gbFile *f, void const *buffer, isize size, i64 offset, isize *bytes_written) {
if (!f->ops) f->ops = &GB_DEFAULT_FILE_OPERATIONS;
return f->ops->write_at(f->fd, buffer, size, offset, bytes_written);
}
-gb_inline b32
-gb_file_read_at(gbFile *f, void *buffer, isize size, i64 offset)
-{
+gb_inline b32 gb_file_read_at(gbFile *f, void *buffer, isize size, i64 offset) {
return gb_file_read_at_check(f, buffer, size, offset, NULL);
}
-gb_inline b32
-gb_file_write_at(gbFile *f, void const *buffer, isize size, i64 offset)
-{
+gb_inline b32 gb_file_write_at(gbFile *f, void const *buffer, isize size, i64 offset) {
return gb_file_write_at_check(f, buffer, size, offset, NULL);
}
-gb_inline i64
-gb_file_seek(gbFile *f, i64 offset, gbSeekWhence whence)
-{
+gb_inline i64 gb_file_seek(gbFile *f, i64 offset, gbSeekWhence whence) {
i64 new_offset = 0;
if (!f->ops) f->ops = &GB_DEFAULT_FILE_OPERATIONS;
f->ops->seek(f->fd, offset, whence, &new_offset);
@@ -6021,9 +5587,7 @@ gb_inline b32 gb_file_read (gbFile *f, void *buffer, isize size) { return
gb_inline b32 gb_file_write(gbFile *f, void const *buffer, isize size) { return gb_file_write_at(f, buffer, size, gb_file_tell(f)); }
-gbFileError
-gb_file_create(gbFile *f, char const *filename, ...)
-{
+gbFileError gb_file_create(gbFile *f, char const *filename, ...) {
gbFileError err;
va_list va;
va_start(va, filename);
@@ -6033,9 +5597,7 @@ gb_file_create(gbFile *f, char const *filename, ...)
}
-gbFileError
-gb_file_open(gbFile *f, char const *filename, ...)
-{
+gbFileError gb_file_open(gbFile *f, char const *filename, ...) {
gbFileError err;
va_list va;
va_start(va, filename);
@@ -6044,9 +5606,7 @@ gb_file_open(gbFile *f, char const *filename, ...)
return err;
}
-gbFileError
-gb_file_open_mode(gbFile *f, gbFileMode perm, char const *filename, ...)
-{
+gbFileError gb_file_open_mode(gbFile *f, gbFileMode perm, char const *filename, ...) {
gbFileError err;
va_list va;
va_start(va, filename);
@@ -6058,9 +5618,7 @@ gb_file_open_mode(gbFile *f, gbFileMode perm, char const *filename, ...)
char const *gb_file_name(gbFile *f) { return f->filename ? f->filename : ""; }
-gb_inline b32
-gb_file_has_changed(gbFile *f)
-{
+gb_inline b32 gb_file_has_changed(gbFile *f) {
b32 result = false;
gbFileTime last_write_time = gb_file_last_write_time("%s", f->filename);
if (f->last_write_time != last_write_time) {
@@ -6077,9 +5635,7 @@ gb_global gbFile gb__std_files[GB_FILE_STANDARD_COUNT] = {0};
#if defined(GB_SYSTEM_WINDOWS)
-gb_inline gbFile *const
-gb_file_get_standard(gbFileStandardType std)
-{
+gb_inline gbFile *const gb_file_get_standard(gbFileStandardType std) {
if (!gb__std_file_set) {
#define GB__SET_STD_FILE(type, v) gb__std_files[type].fd.p = v; gb__std_files[type].ops = &GB_DEFAULT_FILE_OPERATIONS
GB__SET_STD_FILE(GB_FILE_STANDARD_INPUT, GetStdHandle(STD_INPUT_HANDLE));
@@ -6091,17 +5647,13 @@ gb_file_get_standard(gbFileStandardType std)
return &gb__std_files[std];
}
-gb_inline i64
-gb_file_size(gbFile *f)
-{
+gb_inline i64 gb_file_size(gbFile *f) {
LARGE_INTEGER size;
GetFileSizeEx(f->fd.p, &size);
return size.QuadPart;
}
-gbFileError
-gb_file_truncate(gbFile *f, i64 size)
-{
+gbFileError gb_file_truncate(gbFile *f, i64 size) {
gbFileError err = GB_FILE_ERR_NONE;
i64 prev_offset = gb_file_tell(f);
gb_file_seek(f, size, GB_SEEK_BEGIN);
@@ -6112,9 +5664,7 @@ gb_file_truncate(gbFile *f, i64 size)
}
-b32
-gb_file_exists(char const *name)
-{
+b32 gb_file_exists(char const *name) {
WIN32_FIND_DATAW data;
HANDLE handle = FindFirstFileW(cast(LPCWSTR)gb_utf8_to_ucs2_buf(name), &data);
b32 found = handle != INVALID_HANDLE_VALUE;
@@ -6124,9 +5674,7 @@ gb_file_exists(char const *name)
#else // POSIX
-gb_inline gbFile *const
-gb_file_get_standard(gbFileStandardType std)
-{
+gb_inline gbFile *const gb_file_get_standard(gbFileStandardType std) {
if (!gb__std_file_set) {
#define GB__SET_STD_FILE(type, v) gb__std_files[type].fd.i = v; gb__std_files[type].ops = &GB_DEFAULT_FILE_OPERATIONS
GB__SET_STD_FILE(GB_FILE_STANDARD_INPUT, 0);
@@ -6138,9 +5686,7 @@ gb_file_get_standard(gbFileStandardType std)
return &gb__std_files[std];
}
-gb_inline i64
-gb_file_size(gbFile *f)
-{
+gb_inline i64 gb_file_size(gbFile *f) {
i64 size = 0;
i64 prev_offset = gb_file_tell(f);
gb_file_seek(f, 0, GB_SEEK_END);
@@ -6149,18 +5695,14 @@ gb_file_size(gbFile *f)
return size;
}
-gb_inline gbFileError
-gb_file_truncate(gbFile *f, i64 size)
-{
+gb_inline gbFileError gb_file_truncate(gbFile *f, i64 size) {
gbFileError err = GB_FILE_ERR_NONE;
int i = ftruncate(f->fd.i, size);
if (i != 0) err = GB_FILE_ERR_TRUNCATION_FAILURE;
return err;
}
-b32
-gb_file_exists(char const *name)
-{
+b32 gb_file_exists(char const *name) {
return access(name, F_OK) != -1;
}
#endif
@@ -6168,9 +5710,7 @@ gb_file_exists(char const *name)
#if defined(GB_SYSTEM_WINDOWS)
-gbFileTime
-gb_file_last_write_time(char const *filepath, ...)
-{
+gbFileTime gb_file_last_write_time(char const *filepath, ...) {
gb_local_persist char16 path[2048];
ULARGE_INTEGER li = {0};
FILETIME last_write_time = {0};
@@ -6189,9 +5729,7 @@ gb_file_last_write_time(char const *filepath, ...)
}
-gb_inline b32
-gb_file_copy(char const *existing_filename, char const *new_filename, b32 fail_if_exists)
-{
+gb_inline b32 gb_file_copy(char const *existing_filename, char const *new_filename, b32 fail_if_exists) {
gb_local_persist char16 old_f[2048];
gb_local_persist char16 new_f[2048];
@@ -6200,9 +5738,7 @@ gb_file_copy(char const *existing_filename, char const *new_filename, b32 fail_i
fail_if_exists);
}
-gb_inline b32
-gb_file_move(char const *existing_filename, char const *new_filename)
-{
+gb_inline b32 gb_file_move(char const *existing_filename, char const *new_filename) {
gb_local_persist char16 old_f[2048];
gb_local_persist char16 new_f[2048];
@@ -6214,9 +5750,7 @@ gb_file_move(char const *existing_filename, char const *new_filename)
#else
-gbFileTime
-gb_file_last_write_time(char const *filepath, ...)
-{
+gbFileTime gb_file_last_write_time(char const *filepath, ...) {
time_t result = 0;
struct stat file_stat;
@@ -6232,9 +5766,7 @@ gb_file_last_write_time(char const *filepath, ...)
}
-gb_inline b32
-gb_file_copy(char const *existing_filename, char const *new_filename, b32 fail_if_exists)
-{
+gb_inline b32 gb_file_copy(char const *existing_filename, char const *new_filename, b32 fail_if_exists) {
isize size;
int existing_fd = open(existing_filename, O_RDONLY, 0);
int new_fd = open(new_filename, O_WRONLY|O_CREAT, 0666);
@@ -6250,9 +5782,7 @@ gb_file_copy(char const *existing_filename, char const *new_filename, b32 fail_i
return size == stat_existing.st_size;
}
-gb_inline b32
-gb_file_move(char const *existing_filename, char const *new_filename)
-{
+gb_inline b32 gb_file_move(char const *existing_filename, char const *new_filename) {
if (link(existing_filename, new_filename) == 0) {
if (unlink(existing_filename) != EOF)
return true;
@@ -6266,9 +5796,7 @@ gb_file_move(char const *existing_filename, char const *new_filename)
-gbFileContents
-gb_file_read_contents(gbAllocator a, b32 zero_terminate, char const *filepath, ...)
-{
+gbFileContents gb_file_read_contents(gbAllocator a, b32 zero_terminate, char const *filepath, ...) {
gbFileContents result = {0};
gbFile file = {0};
char *path;
@@ -6296,9 +5824,7 @@ gb_file_read_contents(gbAllocator a, b32 zero_terminate, char const *filepath, .
return result;
}
-void
-gb_file_free_contents(gbFileContents *fc)
-{
+void gb_file_free_contents(gbFileContents *fc) {
GB_ASSERT_NOT_NULL(fc->data);
gb_free(fc->allocator, fc->data);
fc->data = NULL;
@@ -6309,9 +5835,7 @@ gb_file_free_contents(gbFileContents *fc)
-gb_inline b32
-gb_path_is_absolute(char const *path)
-{
+gb_inline b32 gb_path_is_absolute(char const *path) {
b32 result = false;
GB_ASSERT_NOT_NULL(path);
#if defined(GB_SYSTEM_WINDOWS)
@@ -6326,9 +5850,7 @@ gb_path_is_absolute(char const *path)
gb_inline b32 gb_path_is_relative(char const *path) { return !gb_path_is_absolute(path); }
-gb_inline b32
-gb_path_is_root(char const *path)
-{
+gb_inline b32 gb_path_is_root(char const *path) {
b32 result = false;
GB_ASSERT_NOT_NULL(path);
#if defined(GB_SYSTEM_WINDOWS)
@@ -6339,18 +5861,14 @@ gb_path_is_root(char const *path)
return result;
}
-gb_inline char const *
-gb_path_base_name(char const *path)
-{
+gb_inline char const *gb_path_base_name(char const *path) {
char const *ls;
GB_ASSERT_NOT_NULL(path);
ls = gb_char_last_occurence(path, '/');
return (ls == NULL) ? path : ls+1;
}
-gb_inline char const *
-gb_path_extension(char const *path)
-{
+gb_inline char const *gb_path_extension(char const *path) {
char const *ld;
GB_ASSERT_NOT_NULL(path);
ld = gb_char_last_occurence(path, '.');
@@ -6365,9 +5883,7 @@ gb_path_extension(char const *path)
//
-isize
-gb_printf(char const *fmt, ...)
-{
+isize gb_printf(char const *fmt, ...) {
isize res;
va_list va;
va_start(va, fmt);
@@ -6377,9 +5893,7 @@ gb_printf(char const *fmt, ...)
}
-isize
-gb_printf_err(char const *fmt, ...)
-{
+isize gb_printf_err(char const *fmt, ...) {
isize res;
va_list va;
va_start(va, fmt);
@@ -6388,9 +5902,7 @@ gb_printf_err(char const *fmt, ...)
return res;
}
-isize
-gb_fprintf(struct gbFile *f, char const *fmt, ...)
-{
+isize gb_fprintf(struct gbFile *f, char const *fmt, ...) {
isize res;
va_list va;
va_start(va, fmt);
@@ -6399,9 +5911,7 @@ gb_fprintf(struct gbFile *f, char const *fmt, ...)
return res;
}
-char *
-gb_bprintf(char const *fmt, ...)
-{
+char *gb_bprintf(char const *fmt, ...) {
va_list va;
char *str;
va_start(va, fmt);
@@ -6410,9 +5920,7 @@ gb_bprintf(char const *fmt, ...)
return str;
}
-isize
-gb_snprintf(char *str, isize n, char const *fmt, ...)
-{
+isize gb_snprintf(char *str, isize n, char const *fmt, ...) {
isize res;
va_list va;
va_start(va, fmt);
@@ -6423,21 +5931,15 @@ gb_snprintf(char *str, isize n, char const *fmt, ...)
-gb_inline isize
-gb_printf_va(char const *fmt, va_list va)
-{
+gb_inline isize gb_printf_va(char const *fmt, va_list va) {
return gb_fprintf_va(gb_file_get_standard(GB_FILE_STANDARD_OUTPUT), fmt, va);
}
-gb_inline isize
-gb_printf_err_va(char const *fmt, va_list va)
-{
+gb_inline isize gb_printf_err_va(char const *fmt, va_list va) {
return gb_fprintf_va(gb_file_get_standard(GB_FILE_STANDARD_ERROR), fmt, va);
}
-gb_inline isize
-gb_fprintf_va(struct gbFile *f, char const *fmt, va_list va)
-{
+gb_inline isize gb_fprintf_va(struct gbFile *f, char const *fmt, va_list va) {
gb_local_persist char buf[4096];
isize len = gb_snprintf_va(buf, gb_size_of(buf), fmt, va);
gb_file_write(f, buf, len);
@@ -6445,9 +5947,7 @@ gb_fprintf_va(struct gbFile *f, char const *fmt, va_list va)
}
-gb_inline char *
-gb_bprintf_va(char const *fmt, va_list va)
-{
+gb_inline char *gb_bprintf_va(char const *fmt, va_list va) {
gb_local_persist char buffer[4096];
gb_snprintf_va(buffer, gb_size_of(buffer), fmt, va);
return buffer;
@@ -6485,9 +5985,7 @@ typedef struct {
} gbprivFmtInfo;
-gb_internal isize
-gb__print_string(char *text, isize max_len, gbprivFmtInfo *info, char const *str)
-{
+gb_internal isize gb__print_string(char *text, isize max_len, gbprivFmtInfo *info, char const *str) {
// TODO(bill): Get precision and width to work correctly. How does it actually work?!
// TODO(bill): This looks very buggy indeed.
isize res = 0, len;
@@ -6534,35 +6032,27 @@ gb__print_string(char *text, isize max_len, gbprivFmtInfo *info, char const *str
return res;
}
-gb_internal isize
-gb__print_char(char *text, isize max_len, gbprivFmtInfo *info, char arg)
-{
+gb_internal isize gb__print_char(char *text, isize max_len, gbprivFmtInfo *info, char arg) {
char str[2] = "";
str[0] = arg;
return gb__print_string(text, max_len, info, str);
}
-gb_internal isize
-gb__print_i64(char *text, isize max_len, gbprivFmtInfo *info, i64 value)
-{
+gb_internal isize gb__print_i64(char *text, isize max_len, gbprivFmtInfo *info, i64 value) {
char num[130];
gb_i64_to_str(value, num, info ? info->base : 10);
return gb__print_string(text, max_len, info, num);
}
-gb_internal isize
-gb__print_u64(char *text, isize max_len, gbprivFmtInfo *info, u64 value)
-{
+gb_internal isize gb__print_u64(char *text, isize max_len, gbprivFmtInfo *info, u64 value) {
char num[130];
gb_u64_to_str(value, num, info ? info->base : 10);
return gb__print_string(text, max_len, info, num);
}
-gb_internal isize
-gb__print_f64(char *text, isize max_len, gbprivFmtInfo *info, f64 arg)
-{
+gb_internal isize gb__print_f64(char *text, isize max_len, gbprivFmtInfo *info, f64 arg) {
// TODO(bill): Handle exponent notation
isize width, len, remaining = max_len;
char *text_begin = text;
@@ -6650,9 +6140,7 @@ gb__print_f64(char *text, isize max_len, gbprivFmtInfo *info, f64 arg)
-gb_no_inline isize
-gb_snprintf_va(char *text, isize max_len, char const *fmt, va_list va)
-{
+gb_no_inline isize gb_snprintf_va(char *text, isize max_len, char const *fmt, va_list va) {
char const *text_begin = text;
isize remaining = max_len;
@@ -6854,9 +6342,7 @@ gb_snprintf_va(char *text, isize max_len, char const *fmt, va_list va)
#if defined(GB_SYSTEM_WINDOWS)
-gbDllHandle
-gb_dll_load(char const *filepath, ...)
-{
+gbDllHandle gb_dll_load(char const *filepath, ...) {
gb_local_persist char buffer[512];
va_list va;
va_start(va, filepath);
@@ -6869,9 +6355,7 @@ gb_inline gbDllProc gb_dll_proc_address(gbDllHandle dll, char const *proc_name)
#else // POSIX
-gbDllHandle
-gb_dll_load(char const *filepath, ...)
-{
+gbDllHandle gb_dll_load(char const *filepath, ...) {
gb_local_persist char buffer[512];
va_list va;
va_start(va, filepath);
@@ -6896,25 +6380,19 @@ gb_inline gbDllProc gb_dll_proc_address(gbDllHandle dll, char const *proc_name)
#if defined(_MSC_VER) && !defined(__clang__)
gb_inline u64 gb_rdtsc(void) { return __rdtsc(); }
#elif defined(__i386__)
- gb_inline u64
- gb_rdtsc(void)
- {
+ gb_inline u64 gb_rdtsc(void) {
u64 x;
__asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
return x;
}
#elif defined(__x86_64__)
- gb_inline u64
- gb_rdtsc(void)
- {
+ gb_inline u64 gb_rdtsc(void) {
u32 hi, lo;
__asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
return (cast(u64)lo) | ((cast(u64)hi)<<32);
}
#elif defined(__powerpc__)
- gb_inline u64
- gb_rdtsc(void)
- {
+ gb_inline u64 gb_rdtsc(void) {
u64 result = 0;
u32 upper, lower,tmp;
__asm__ volatile(
@@ -6936,9 +6414,7 @@ gb_inline gbDllProc gb_dll_proc_address(gbDllHandle dll, char const *proc_name)
#if defined(GB_SYSTEM_WINDOWS)
- gb_inline f64
- gb_time_now(void)
- {
+ gb_inline f64 gb_time_now(void) {
gb_local_persist LARGE_INTEGER win32_perf_count_freq = {0};
f64 result;
LARGE_INTEGER counter;
@@ -6953,9 +6429,7 @@ gb_inline gbDllProc gb_dll_proc_address(gbDllHandle dll, char const *proc_name)
return result;
}
- gb_inline u64
- gb_utc_time_now(void)
- {
+ gb_inline u64 gb_utc_time_now(void) {
FILETIME ft;
ULARGE_INTEGER li;
@@ -6973,9 +6447,7 @@ gb_inline gbDllProc gb_dll_proc_address(gbDllHandle dll, char const *proc_name)
gb_global f64 gb__timebase = 0.0;
gb_global u64 gb__timestart = 0;
- gb_inline f64
- gb_time_now(void)
- {
+ gb_inline f64 gb_time_now(void) {
#if defined(GB_SYSTEM_OSX)
f64 result;
@@ -6987,7 +6459,7 @@ gb_inline gbDllProc gb_dll_proc_address(gbDllHandle dll, char const *proc_name)
gb__timestart = mach_absolute_time();
}
- result = (mach_absolute_time() - gb__timestart) * gb__timebase;
+ result = (mach_absolute_time() - gb__timestart) *gb__timebase;
return result;
#else
struct timespec t;
@@ -7000,18 +6472,14 @@ gb_inline gbDllProc gb_dll_proc_address(gbDllHandle dll, char const *proc_name)
#endif
}
- gb_inline u64
- gb_utc_time_now(void)
- {
+ gb_inline u64 gb_utc_time_now(void) {
struct timespec t;
// IMPORTANT TODO(bill): THIS IS A HACK
clock_gettime(0 /*CLOCK_REALTIME*/, &t);
return cast(u64)t.tv_sec * 1000000ull + t.tv_nsec/1000 + 11644473600000000ull;
}
- gb_inline void
- gb_sleep_ms(u32 ms)
- {
+ gb_inline void gb_sleep_ms(u32 ms) {
struct timespec req = {cast(time_t)ms/1000, cast(long)((ms%1000)*1000000)};
struct timespec rem = {0, 0};
nanosleep(&req, &rem);
@@ -7027,9 +6495,7 @@ gb_inline gbDllProc gb_dll_proc_address(gbDllHandle dll, char const *proc_name)
//
//
-gb_internal gb_inline u64
-gb__basic_hash(u64 x)
-{
+gb_internal gb_inline u64 gb__basic_hash(u64 x) {
// NOTE(bill): Used in Murmur Hash
x ^= x >> 33;
x *= 0xff51afd7ed558ccdull;
@@ -7040,9 +6506,7 @@ gb__basic_hash(u64 x)
}
-void
-gb_random_init(gbRandom *r)
-{
+void gb_random_init(gbRandom *r) {
u64 t;
isize i;
t = gb_utc_time_now();
@@ -7058,9 +6522,7 @@ gb_random_init(gbRandom *r)
}
}
-u64
-gb_random_next(gbRandom *r)
-{
+u64 gb_random_next(gbRandom *r) {
u64 s1 = r->seed[0];
u64 s0 = r->seed[1];
r->seed[0] = s0;
@@ -7069,9 +6531,7 @@ gb_random_next(gbRandom *r)
return r->seed[1];
}
-i64
-gb_random_range_i64(gbRandom *r, i64 lower_inc, i64 higher_inc)
-{
+i64 gb_random_range_i64(gbRandom *r, i64 lower_inc, i64 higher_inc) {
u64 u = gb_random_next(r);
i64 i = *cast(i64 *)&u;
i64 diff = higher_inc-lower_inc+1;
@@ -7081,9 +6541,7 @@ gb_random_range_i64(gbRandom *r, i64 lower_inc, i64 higher_inc)
}
// NOTE(bill): Semi-cc'ed from gb_math to remove need for fmod and math.h
-f64
-gb__copy_sign64(f64 x, f64 y)
-{
+f64 gb__copy_sign64(f64 x, f64 y) {
i64 ix, iy;
ix = *(i64 *)&x;
iy = *(i64 *)&y;
@@ -7100,9 +6558,7 @@ f64 gb__remainder64(f64 x, f64 y) { return x - (gb__round64(x/y)*y); }
f64 gb__abs64 (f64 x) { return x < 0 ? -x : x; }
f64 gb__sign64 (f64 x) { return x < 0 ? -1.0 : +1.0; }
-f64
-gb__mod64(f64 x, f64 y)
-{
+f64 gb__mod64(f64 x, f64 y) {
f64 result;
y = gb__abs64(y);
result = gb__remainder64(gb__abs64(x), y);
@@ -7111,9 +6567,7 @@ gb__mod64(f64 x, f64 y)
}
-f64
-gb_random_range_f64(gbRandom *r, f64 lower_inc, f64 higher_inc)
-{
+f64 gb_random_range_f64(gbRandom *r, f64 lower_inc, f64 higher_inc) {
u64 u = gb_random_next(r);
f64 f = *cast(f64 *)&u;
f64 diff = higher_inc-lower_inc+1.0;
@@ -7130,9 +6584,7 @@ gb_inline void gb_exit(u32 code) { ExitProcess(code); }
gb_inline void gb_exit(u32 code) { exit(code); }
#endif
-gb_inline void
-gb_yield(void)
-{
+gb_inline void gb_yield(void) {
#if defined(GB_SYSTEM_WINDOWS)
Sleep(0);
#else
@@ -7140,9 +6592,7 @@ gb_yield(void)
#endif
}
-gb_inline void
-gb_set_env(char const *name, char const *value)
-{
+gb_inline void gb_set_env(char const *name, char const *value) {
#if defined(GB_SYSTEM_WINDOWS)
// TODO(bill): Should this be a Wide version?
SetEnvironmentVariableA(name, value);
@@ -7151,9 +6601,7 @@ gb_set_env(char const *name, char const *value)
#endif
}
-gb_inline void
-gb_unset_env(char const *name)
-{
+gb_inline void gb_unset_env(char const *name) {
#if defined(GB_SYSTEM_WINDOWS)
// TODO(bill): Should this be a Wide version?
SetEnvironmentVariableA(name, NULL);
@@ -7163,22 +6611,16 @@ gb_unset_env(char const *name)
}
-gb_inline u16
-gb_endian_swap16(u16 i)
-{
+gb_inline u16 gb_endian_swap16(u16 i) {
return (i>>8) | (i<<8);
}
-gb_inline u32
-gb_endian_swap32(u32 i)
-{
+gb_inline u32 gb_endian_swap32(u32 i) {
return (i>>24) |(i<<24) |
((i&0x00ff0000u)>>8) | ((i&0x0000ff00u)<<8);
}
-gb_inline u64
-gb_endian_swap64(u64 i)
-{
+gb_inline u64 gb_endian_swap64(u64 i) {
// TODO(bill): Do I really need the cast here?
return (i>>56) | (i<<56) |
((i&0x00ff000000000000ull)>>40) | ((i&0x000000000000ff00ull)<<40) |
@@ -7199,9 +6641,7 @@ gb_endian_swap64(u64 i)
//
#if !defined(GB_NO_COLOUR_TYPE)
-gb_inline gbColour
-gb_colour(f32 r, f32 g, f32 b, f32 a)
-{
+gb_inline gbColour gb_colour(f32 r, f32 g, f32 b, f32 a) {
gbColour result;
result.r = cast(u8)(gb_clamp01(r) * 255.0f);
result.g = cast(u8)(gb_clamp01(g) * 255.0f);
@@ -7216,32 +6656,24 @@ gb_colour(f32 r, f32 g, f32 b, f32 a)
#if defined(GB_SYSTEM_WINDOWS)
-
-GB_XINPUT_GET_STATE(gbXInputGetState_Stub)
-{
+GB_XINPUT_GET_STATE(gbXInputGetState_Stub) {
gb_unused(dwUserIndex); gb_unused(pState);
return ERROR_DEVICE_NOT_CONNECTED;
}
-
-GB_XINPUT_SET_STATE(gbXInputSetState_Stub)
-{
+GB_XINPUT_SET_STATE(gbXInputSetState_Stub) {
gb_unused(dwUserIndex); gb_unused(pVibration);
return ERROR_DEVICE_NOT_CONNECTED;
}
-gb_internal gb_inline void
-gb__process_xinput_digital_button(DWORD xinput_button_state, DWORD button_bit,
- gbControllerButton *button)
-{
+gb_internal gb_inline void gb__process_xinput_digital_button(DWORD xinput_button_state, DWORD button_bit,
+ gbControllerButton *button) {
b32 ended_down = ((xinput_button_state & button_bit) == button_bit);
button->half_transition_count = (button->ended_down != ended_down) ? 1 : 0;
button->ended_down = ended_down;
}
-gb_internal gb_inline f32
-gb__process_xinput_stick_value(SHORT value, SHORT dead_zone_threshold)
-{
+gb_internal gb_inline f32 gb__process_xinput_stick_value(SHORT value, SHORT dead_zone_threshold) {
f32 result = 0;
if (value < -dead_zone_threshold)
@@ -7252,17 +6684,13 @@ gb__process_xinput_stick_value(SHORT value, SHORT dead_zone_threshold)
return result;
}
-gb_internal gb_inline f32
-gb__process_xinput_trigger_value(BYTE value)
-{
+gb_internal gb_inline f32 gb__process_xinput_trigger_value(BYTE value) {
f32 result;
result = cast(f32) (value / 255.0f);
return result;
}
-gb_internal void
-gb__window_resize_dib_section(gbWindow *window, i32 width, i32 height)
-{
+gb_internal void gb__window_resize_dib_section(gbWindow *window, i32 width, i32 height) {
if (!(window->width == width && window->height == height)) {
BITMAPINFO bmi = {0};
@@ -7297,9 +6725,7 @@ gb__window_resize_dib_section(gbWindow *window, i32 width, i32 height)
}
}
-void
-gb_platform_init(gbPlatform *p)
-{
+void gb_platform_init(gbPlatform *p) {
gb_zero_item(p);
{ // Load XInput
@@ -7323,9 +6749,7 @@ gb_platform_init(gbPlatform *p)
}
-void
-gb_platform_update(gbPlatform *p)
-{
+void gb_platform_update(gbPlatform *p) {
isize i;
{ // NOTE(bill): Set window state
@@ -7611,9 +7035,7 @@ gb_platform_update(gbPlatform *p)
}
}
-void
-gb_platform_display(gbPlatform *p)
-{
+void gb_platform_display(gbPlatform *p) {
gbWindow *window;
GB_ASSERT_NOT_NULL(p);
@@ -7642,16 +7064,12 @@ gb_platform_display(gbPlatform *p)
-void
-gb_platform_show_cursor(gbPlatform *p, i32 show)
-{
+void gb_platform_show_cursor(gbPlatform *p, i32 show) {
gb_unused(p);
ShowCursor(show);
}
-void
-gb_platform_set_mouse_position(gbPlatform *p, gbWindow *rel_win, i32 x, i32 y)
-{
+void gb_platform_set_mouse_position(gbPlatform *p, gbWindow *rel_win, i32 x, i32 y) {
POINT point;
point.x = cast(LONG)x;
point.y = cast(LONG)y;
@@ -7665,17 +7083,13 @@ gb_platform_set_mouse_position(gbPlatform *p, gbWindow *rel_win, i32 x, i32 y)
}
-gb_inline gbGameController *
-gb_platform_get_controller(gbPlatform *p, isize index)
-{
+gb_inline gbGameController *gb_platform_get_controller(gbPlatform *p, isize index) {
if (index >= 0 && index < gb_count_of(p->game_controllers))
return p->game_controllers + index;
return NULL;
}
-LRESULT CALLBACK
-gb__win32_main_window_callback(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
-{
+LRESULT CALLBACK gb__win32_main_window_callback(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam) {
LRESULT result = 0;
gbWindow *window = cast(gbWindow *)GetWindowLongPtr(wnd, GWLP_USERDATA);
@@ -7697,9 +7111,7 @@ gb__win32_main_window_callback(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
// TODO(bill): Make this return errors rathern than silly message boxes
-gbWindow *
-gb_window_init(gbPlatform *p, char const *title, gbVideoMode mode, u32 flags)
-{
+gbWindow *gb_window_init(gbPlatform *p, char const *title, gbVideoMode mode, u32 flags) {
gbWindow *window = &p->window;
WNDCLASSEXW wc = {gb_size_of(WNDCLASSEXW)};
DWORD ex_style, style;
@@ -7818,9 +7230,7 @@ gb_window_init(gbPlatform *p, char const *title, gbVideoMode mode, u32 flags)
return window;
}
-void
-gb_window_destroy(gbWindow *w)
-{
+void gb_window_destroy(gbWindow *w) {
if (w->flags & GB_WINDOW_OPENGL)
wglDeleteContext(w->opengl.win32_context);
else if (w->flags & GB_WINDOW_SOFTWARE)
@@ -7831,9 +7241,7 @@ gb_window_destroy(gbWindow *w)
gb_zero_item(w);
}
-void
-gb_window_set_position(gbWindow *w, i32 x, i32 y)
-{
+void gb_window_set_position(gbWindow *w, i32 x, i32 y) {
RECT rect;
i32 width, height;
@@ -7843,9 +7251,7 @@ gb_window_set_position(gbWindow *w, i32 x, i32 y)
MoveWindow(cast(HWND)w->handle, x, y, width, height, false);
}
-void
-gb_window_set_title(gbWindow *w, char const *title, ...)
-{
+void gb_window_set_title(gbWindow *w, char const *title, ...) {
char16 buffer[256] = {0};
char *str;
LPCWSTR wstr;
@@ -7859,9 +7265,7 @@ gb_window_set_title(gbWindow *w, char const *title, ...)
SetWindowTextW(cast(HWND)w->handle, wstr);
}
-void
-gb_window_toggle_fullscreen(gbWindow *w, b32 fullscreen_desktop)
-{
+void gb_window_toggle_fullscreen(gbWindow *w, b32 fullscreen_desktop) {
HWND handle = cast(HWND)w->handle;
DWORD style = GetWindowLong(handle, GWL_STYLE);
if (style & WS_OVERLAPPEDWINDOW) {
@@ -7900,32 +7304,24 @@ gb_window_toggle_fullscreen(gbWindow *w, b32 fullscreen_desktop)
}
}
-gb_inline void
-gb_window_make_context_current(gbWindow *w)
-{
+gb_inline void gb_window_make_context_current(gbWindow *w) {
if (w->flags & GB_WINDOW_OPENGL) {
wglMakeCurrent(w->win32_dc, w->opengl.win32_context);
}
}
-gb_inline void
-gb_window_show(gbWindow *w)
-{
+gb_inline void gb_window_show(gbWindow *w) {
ShowWindow(cast(HWND)w->handle, SW_SHOW);
w->flags &= ~GB_WINDOW_HIDDEN;
}
-gb_inline void
-gb_window_hide(gbWindow *w)
-{
+gb_inline void gb_window_hide(gbWindow *w) {
ShowWindow(cast(HWND)w->handle, SW_HIDE);
w->flags |= GB_WINDOW_HIDDEN;
}
-gb_inline gbVideoMode
-gb_video_mode(i32 width, i32 height, i32 bits_per_pixel)
-{
+gb_inline gbVideoMode gb_video_mode(i32 width, i32 height, i32 bits_per_pixel) {
gbVideoMode m;
m.width = width;
m.height = height;
@@ -7933,17 +7329,13 @@ gb_video_mode(i32 width, i32 height, i32 bits_per_pixel)
return m;
}
-gb_inline gbVideoMode
-gb_video_mode_get_desktop(void)
-{
+gb_inline gbVideoMode gb_video_mode_get_desktop(void) {
DEVMODE win32_mode = {gb_size_of(win32_mode)};
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &win32_mode);
return gb_video_mode(win32_mode.dmPelsWidth, win32_mode.dmPelsHeight, win32_mode.dmBitsPerPel);
}
-isize
-gb_video_mode_get_fullscreen_modes(gbVideoMode *modes, isize max_mode_count)
-{
+isize gb_video_mode_get_fullscreen_modes(gbVideoMode *modes, isize max_mode_count) {
DEVMODE win32_mode = {gb_size_of(win32_mode)};
i32 count;
for (count = 0;
@@ -7959,24 +7351,17 @@ gb_video_mode_get_fullscreen_modes(gbVideoMode *modes, isize max_mode_count)
#endif
-b32
-gb_window_is_open(gbWindow const *w)
-{
+gb_inline b32 gb_window_is_open(gbWindow const *w) {
return (w->flags & GB_WINDOW_IS_CLOSED) == 0;
}
-
-gb_inline b32
-gb_video_mode_is_valid(gbVideoMode mode)
-{
+gb_inline b32 gb_video_mode_is_valid(gbVideoMode mode) {
gbVideoMode modes[256];
gb_video_mode_get_fullscreen_modes(modes, gb_count_of(modes));
return gb_binary_search_array(modes, gb_count_of(modes), &mode, gb_video_mode_cmp) == -1;
}
-
-GB_COMPARE_PROC(gb_video_mode_cmp)
-{
+GB_COMPARE_PROC(gb_video_mode_cmp) {
gbVideoMode const *x = cast(gbVideoMode const *)a;
gbVideoMode const *y = cast(gbVideoMode const *)b;
@@ -7988,8 +7373,7 @@ GB_COMPARE_PROC(gb_video_mode_cmp)
return x->bits_per_pixel < y->bits_per_pixel ? -1 : +1;
}
-GB_COMPARE_PROC(gb_video_mode_dsc_cmp)
-{
+GB_COMPARE_PROC(gb_video_mode_dsc_cmp) {
return -gb_video_mode_cmp(a, b);
}
diff --git a/gb_gl.h b/gb_gl.h
index 875ee57..1719c38 100644
--- a/gb_gl.h
+++ b/gb_gl.h
@@ -1,4 +1,4 @@
-/* gb.h - v0.04d - OpenGL Helper Library - public domain
+/* gb.h - v0.04e - OpenGL Helper Library - public domain
- no warranty implied; use at your own risk
This is a single header file with a bunch of useful stuff
@@ -55,6 +55,7 @@ Conventions used:
Version History:
+ 0.04e - Change brace style because why not?
0.04d - Use new gb.h file handling system
0.04c - Use new gb.h file handling system
0.04b - Work with the new gb.h
@@ -281,9 +282,7 @@ i32 const GBGL_INTERNAL_TEXTURE_FORMAT_U32[4] = { GL_R32UI, GL_RG32UI, GL_RGB32U
i32 const GBGL_INTERNAL_TEXTURE_FORMAT_I32[4] = { GL_R32I, GL_RG32I, GL_RGB32I, GL_RGBA32I };
i32 const GBGL_INTERNAL_TEXTURE_FORMAT_F32[4] = { GL_R32F, GL_RG32F, GL_RGB32F, GL_RGBA32F };
-gb_inline i32
-gbgl__get_texture_format(gbglBufferDataType data_type, i32 channel_count)
-{
+gb_inline i32 gbgl__get_texture_format(gbglBufferDataType data_type, i32 channel_count) {
GB_ASSERT(gb_is_between(channel_count, 1, 4));
switch (data_type) {
case GBGL_BDT_U8: return GBGL_INTERNAL_TEXTURE_FORMAT_U8[channel_count-1];
@@ -785,9 +784,7 @@ GBGL_DEF isize gbgl_bs_draw_string_va(gbglBasicState *bs, gbglFont *font, f32 x,
#if defined(GBGL_IMPLEMENTATION)
-u32
-gbgl_make_sampler(u32 min_filter, u32 max_filter, u32 s_wrap, u32 t_wrap)
-{
+u32 gbgl_make_sampler(u32 min_filter, u32 max_filter, u32 s_wrap, u32 t_wrap) {
u32 samp;
glGenSamplers(1, &samp);
glSamplerParameteri(samp, GL_TEXTURE_MIN_FILTER, min_filter);
@@ -804,9 +801,7 @@ gbgl_make_sampler(u32 min_filter, u32 max_filter, u32 s_wrap, u32 t_wrap)
//
//
-gb_inline u32
-gbgl__make_buffer(isize size, void const *data, i32 target, i32 usage_hint)
-{
+gb_inline u32 gbgl__make_buffer(isize size, void const *data, i32 target, i32 usage_hint) {
u32 buffer_handle;
glGenBuffers(1, &buffer_handle);
glBindBuffer(target, buffer_handle);
@@ -814,29 +809,21 @@ gbgl__make_buffer(isize size, void const *data, i32 target, i32 usage_hint)
return buffer_handle;
}
-gb_inline void
-gbgl__buffer_copy(u32 buffer_handle, i32 target, void const *data, isize size, isize offset)
-{
+gb_inline void gbgl__buffer_copy(u32 buffer_handle, i32 target, void const *data, isize size, isize offset) {
glBindBuffer(target, buffer_handle);
glBufferSubData(target, offset, size, data);
}
// NOTE(bill): usage_hint == (GL_STATIC_DRAW, GL_STREAM_DRAW, GL_DYNAMIC_DRAW)
-gb_inline u32
-gbgl_make_vbo(void const *data, isize size, i32 usage_hint)
-{
+gb_inline u32 gbgl_make_vbo(void const *data, isize size, i32 usage_hint) {
return gbgl__make_buffer(size, data, GL_ARRAY_BUFFER, usage_hint);
}
-gb_inline u32
-gbgl_make_ebo(void const *data, isize size, i32 usage_hint)
-{
+gb_inline u32 gbgl_make_ebo(void const *data, isize size, i32 usage_hint) {
return gbgl__make_buffer(size, data, GL_ELEMENT_ARRAY_BUFFER, usage_hint);
}
-gb_inline gbglTBO
-gbgl_make_tbo(gbglBufferDataType data_type, i32 channel_count, void const *data, isize size, i32 usage_hint)
-{
+gb_inline gbglTBO gbgl_make_tbo(gbglBufferDataType data_type, i32 channel_count, void const *data, isize size, i32 usage_hint) {
gbglTBO tbo;
i32 internal_format;
@@ -849,46 +836,34 @@ gbgl_make_tbo(gbglBufferDataType data_type, i32 channel_count, void const *data,
return tbo;
}
-gb_inline void
-gbgl_vbo_copy(u32 vbo_handle, void *const data, isize size, isize offset)
-{
+gb_inline void gbgl_vbo_copy(u32 vbo_handle, void *const data, isize size, isize offset) {
gbgl__buffer_copy(vbo_handle, GL_ARRAY_BUFFER, data, size, offset);
}
-gb_inline void
-gbgl_ebo_copy(u32 ebo_handle, void *const data, isize size, isize offset)
-{
+gb_inline void gbgl_ebo_copy(u32 ebo_handle, void *const data, isize size, isize offset) {
gbgl__buffer_copy(ebo_handle, GL_ELEMENT_ARRAY_BUFFER, data, size, offset);
}
-gb_inline void
-gbgl_tbo_copy(gbglTBO tbo, void *const data, isize size, isize offset)
-{
+gb_inline void gbgl_tbo_copy(gbglTBO tbo, void *const data, isize size, isize offset) {
gbgl__buffer_copy(tbo.buffer_obj_handle, GL_TEXTURE_BUFFER, data, size, offset);
}
gb_inline void gbgl_bind_vbo(u32 vbo_handle) { glBindBuffer(GL_ARRAY_BUFFER, vbo_handle); }
gb_inline void gbgl_bind_ebo(u32 ebo_handle) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo_handle); }
-gb_inline void
-gbgl_bind_tbo(gbglTBO tbo, i32 sampler_handle, i32 tex_unit)
-{
+gb_inline void gbgl_bind_tbo(gbglTBO tbo, i32 sampler_handle, i32 tex_unit) {
glActiveTexture(GL_TEXTURE0 + tex_unit);
glBindTexture(GL_TEXTURE_BUFFER, tbo.buffer_handle);
glBindSampler(0, sampler_handle);
}
// NOTE(bill): access = GL_WRITE_ONLY, etc.
-gb_inline void *
-gbgl_map_vbo(u32 vbo_handle, i32 access)
-{
+gb_inline void * gbgl_map_vbo(u32 vbo_handle, i32 access) {
gbgl_bind_vbo(vbo_handle);
return glMapBuffer(GL_ARRAY_BUFFER, access);
}
-gb_inline void *
-gbgl_map_ebo(u32 ebo_handle, i32 access)
-{
+gb_inline void * gbgl_map_ebo(u32 ebo_handle, i32 access) {
gbgl_bind_ebo(ebo_handle);
return glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, access);
}
@@ -905,9 +880,7 @@ gb_inline void gbgl_unmap_ebo(void) { glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); }
//
-gbglShaderError
-gbgl__load_single_shader_from_file(gbglShader *shader, gbglShaderType type, char const *name)
-{
+gbglShaderError gbgl__load_single_shader_from_file(gbglShader *shader, gbglShaderType type, char const *name) {
gbglShaderError err = GBGL_SHADER_ERROR_NONE;
gbFileError ferr = gb_file_open(&shader->files[type], "%s%s", name, GBGL_SHADER_FILE_EXTENSIONS[type]);
@@ -945,9 +918,7 @@ gbgl__load_single_shader_from_file(gbglShader *shader, gbglShaderType type, char
return err;
}
-gbglShaderError
-gbgl__load_single_shader_from_memory(gbglShader *s, gbglShaderType type, char const *text)
-{
+gbglShaderError gbgl__load_single_shader_from_memory(gbglShader *s, gbglShaderType type, char const *text) {
gbglShaderError err = GBGL_SHADER_ERROR_NONE;
i32 status;
@@ -972,9 +943,7 @@ gbgl__load_single_shader_from_memory(gbglShader *s, gbglShaderType type, char co
return err;
}
-gbglShaderError
-gbgl__link_shader(gbglShader *shader)
-{
+gbglShaderError gbgl__link_shader(gbglShader *shader) {
gbglShaderError err = GBGL_SHADER_ERROR_NONE;
i32 i, status;
shader->program = glCreateProgram();
@@ -1003,9 +972,7 @@ gbgl__link_shader(gbglShader *shader)
-gbglShaderError
-gbgl_load_shader_from_file(gbglShader *shader, u32 type_bits, char const *filename)
-{
+gbglShaderError gbgl_load_shader_from_file(gbglShader *shader, u32 type_bits, char const *filename) {
gbglShaderError err = GBGL_SHADER_ERROR_NONE;
b32 loaded_shader[GBGL_SHADER_TYPE_COUNT] = {0};
i32 i;
@@ -1030,9 +997,7 @@ gbgl_load_shader_from_file(gbglShader *shader, u32 type_bits, char const *filena
-gbglShaderError
-gbgl_load_shader_from_memory_vf(gbglShader *s, char const *vert_source, char const *frag_source)
-{
+gbglShaderError gbgl_load_shader_from_memory_vf(gbglShader *s, char const *vert_source, char const *frag_source) {
gbglShaderError err = GBGL_SHADER_ERROR_NONE;
gb_zero_item(s);
@@ -1048,9 +1013,7 @@ gbgl_load_shader_from_memory_vf(gbglShader *s, char const *vert_source, char con
return err;
}
-gbglShaderError
-gbgl_load_shader_from_memory_vfg(gbglShader *s, char const *vert_source, char const *frag_source, char const *geom_source)
-{
+gbglShaderError gbgl_load_shader_from_memory_vfg(gbglShader *s, char const *vert_source, char const *frag_source, char const *geom_source) {
gbglShaderError err = GBGL_SHADER_ERROR_NONE;
gb_zero_item(s);
@@ -1068,9 +1031,7 @@ gbgl_load_shader_from_memory_vfg(gbglShader *s, char const *vert_source, char co
return err;
}
-gb_inline void
-gbgl_destroy_shader(gbglShader *shader)
-{
+gb_inline void gbgl_destroy_shader(gbglShader *shader) {
i32 i;
for (i = 0; i < GBGL_SHADER_TYPE_COUNT; i++) {
if (shader->type_flags & GB_BIT(i)) {
@@ -1087,9 +1048,7 @@ gbgl_destroy_shader(gbglShader *shader)
}
-gb_inline b32
-gbgl_has_shader_changed(gbglShader *shader)
-{
+gb_inline b32 gbgl_has_shader_changed(gbglShader *shader) {
i32 i;
for (i = 0; i < GBGL_SHADER_TYPE_COUNT; i++) {
if (shader->type_flags & GB_BIT(i)) {
@@ -1102,9 +1061,7 @@ gbgl_has_shader_changed(gbglShader *shader)
}
-b32
-gbgl_reload_shader(gbglShader *shader)
-{
+b32 gbgl_reload_shader(gbglShader *shader) {
i32 i;
for (i = 0; i < GBGL_SHADER_TYPE_COUNT; i++) {
if (shader->type_flags & GB_BIT(i)) {
@@ -1125,9 +1082,7 @@ gbgl_reload_shader(gbglShader *shader)
gb_inline void gbgl_use_shader(gbglShader *s) { glUseProgram(s ? s->program : 0); }
-gb_inline b32
-gbgl_is_shader_in_use(gbglShader *s)
-{
+gb_inline b32 gbgl_is_shader_in_use(gbglShader *s) {
if (s) {
i32 curr = 0;
glGetIntegerv(GL_CURRENT_PROGRAM, &curr);
@@ -1137,9 +1092,7 @@ gbgl_is_shader_in_use(gbglShader *s)
}
-i32
-gbgl_get_uniform(gbglShader *s, char const *name)
-{
+i32 gbgl_get_uniform(gbglShader *s, char const *name) {
i32 i, loc = -1;
for (i = 0; i < s->uniform_count; i++) {
if (gb_strcmp(s->uniform_names[i], name) == 0) {
@@ -1160,52 +1113,36 @@ gbgl_get_uniform(gbglShader *s, char const *name)
-gb_inline void
-gbgl_set_uniform_int(gbglShader *s, char const *name, i32 i)
-{
+gb_inline void gbgl_set_uniform_int(gbglShader *s, char const *name, i32 i) {
glUniform1i(gbgl_get_uniform(s, name), i);
}
-gb_inline void
-gbgl_set_uniform_float(gbglShader *s, char const *name, f32 f)
-{
+gb_inline void gbgl_set_uniform_float(gbglShader *s, char const *name, f32 f) {
glUniform1f(gbgl_get_uniform(s, name), f);
}
-gb_inline void
-gbgl_set_uniform_vec2(gbglShader *s, char const *name, f32 const *v)
-{
+gb_inline void gbgl_set_uniform_vec2(gbglShader *s, char const *name, f32 const *v) {
glUniform2fv(gbgl_get_uniform(s, name), 1, v);
}
-gb_inline void
-gbgl_set_uniform_vec3(gbglShader *s, char const *name, f32 const *v)
-{
+gb_inline void gbgl_set_uniform_vec3(gbglShader *s, char const *name, f32 const *v) {
glUniform3fv(gbgl_get_uniform(s, name), 1, v);
}
-gb_inline void
-gbgl_set_uniform_vec4(gbglShader *s, char const *name, f32 const *v)
-{
+gb_inline void gbgl_set_uniform_vec4(gbglShader *s, char const *name, f32 const *v) {
glUniform4fv(gbgl_get_uniform(s, name), 1, v);
}
-gb_inline void
-gbgl_set_uniform_mat4(gbglShader *s, char const *name, f32 const *m)
-{
+gb_inline void gbgl_set_uniform_mat4(gbglShader *s, char const *name, f32 const *m) {
gbgl_set_uniform_mat4_count(s, name, m, 1);
}
-gb_inline void
-gbgl_set_uniform_mat4_count(gbglShader *s, char const *name, f32 const *m, isize count)
-{
+gb_inline void gbgl_set_uniform_mat4_count(gbglShader *s, char const *name, f32 const *m, isize count) {
glUniformMatrix4fv(gbgl_get_uniform(s, name), count, false, m);
}
-gb_inline void
-gbgl_set_uniform_colour(gbglShader *s, char const *name, gbColour col)
-{
+gb_inline void gbgl_set_uniform_colour(gbglShader *s, char const *name, gbColour col) {
f32 v[4];
v[0] = col.r / 255.0f;
v[1] = col.g / 255.0f;
@@ -1223,9 +1160,7 @@ gbgl_set_uniform_colour(gbglShader *s, char const *name, gbColour col)
//
-b32
-gbgl_init_render_buffer(gbglRenderBuffer *rb, i32 width, i32 height, i32 channel_count)
-{
+b32 gbgl_init_render_buffer(gbglRenderBuffer *rb, i32 width, i32 height, i32 channel_count) {
if ((rb->width == width) && (rb->height == height) && (rb->channel_count == channel_count)) return true;
gbgl_destroy_render_buffer(rb);
gb_zero_item(rb);
@@ -1260,9 +1195,7 @@ gbgl_init_render_buffer(gbglRenderBuffer *rb, i32 width, i32 height, i32 channel
return true;
}
-gb_inline void
-gbgl_destroy_render_buffer(gbglRenderBuffer *rb)
-{
+gb_inline void gbgl_destroy_render_buffer(gbglRenderBuffer *rb) {
if (rb->handle)
glDeleteFramebuffers(1, &rb->handle);
@@ -1270,17 +1203,13 @@ gbgl_destroy_render_buffer(gbglRenderBuffer *rb)
}
-gb_inline void
-gbgl_render_to_buffer(gbglRenderBuffer const *rb)
-{
+gb_inline void gbgl_render_to_buffer(gbglRenderBuffer const *rb) {
GB_ASSERT_NOT_NULL(rb);
glViewport(0, 0, rb->width, rb->height);
glBindFramebuffer(GL_FRAMEBUFFER, rb->handle);
}
-gb_inline void
-gbgl_render_to_screen(i32 width, i32 height)
-{
+gb_inline void gbgl_render_to_screen(i32 width, i32 height) {
glViewport(0, 0, width, height);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
@@ -1293,9 +1222,7 @@ gbgl_render_to_screen(i32 width, i32 height)
//
-b32
-gbgl_load_texture2d_from_memory(gbglTexture *tex, void const *data, i32 width, i32 height, i32 channel_count)
-{
+b32 gbgl_load_texture2d_from_memory(gbglTexture *tex, void const *data, i32 width, i32 height, i32 channel_count) {
b32 result = true;
gb_zero_item(tex);
@@ -1324,9 +1251,7 @@ gbgl_load_texture2d_from_memory(gbglTexture *tex, void const *data, i32 width, i
return result;
}
-b32
-gbgl_load_texture2d_from_file(gbglTexture *texture, b32 flip_vertically, char const *filename, ...)
-{
+b32 gbgl_load_texture2d_from_file(gbglTexture *texture, b32 flip_vertically, char const *filename, ...) {
b32 result;
u8 *data;
int width, height, comp;
@@ -1349,16 +1274,12 @@ gbgl_load_texture2d_from_file(gbglTexture *texture, b32 flip_vertically, char co
return result;
}
-gb_inline b32
-gbgl_make_texture2d_coloured(gbglTexture *t, gbColour colour)
-{
+gb_inline b32 gbgl_make_texture2d_coloured(gbglTexture *t, gbColour colour) {
return gbgl_load_texture2d_from_memory(t, &colour.rgba, 1, 1, 4);
}
-gb_inline void
-gbgl_bind_texture2d(gbglTexture const *t, u32 position, u32 sampler)
-{
+gb_inline void gbgl_bind_texture2d(gbglTexture const *t, u32 position, u32 sampler) {
GB_ASSERT(t->type == GBGL_TEXTURE_TYPE_2D);
if (position > 31) {
@@ -1373,9 +1294,7 @@ gbgl_bind_texture2d(gbglTexture const *t, u32 position, u32 sampler)
glBindSampler(position, sampler);
}
-gb_inline void
-gbgl_destroy_texture(gbglTexture *t)
-{
+gb_inline void gbgl_destroy_texture(gbglTexture *t) {
if (t->handle) {
glDeleteTextures(1, &t->handle);
}
@@ -1389,18 +1308,14 @@ gbgl_destroy_texture(gbglTexture *t)
//
//
#if !defined(GBGL_NO_FONTS)
-gb_inline
-GB_COMPARE_PROC(gbgl__kern_pair_compare)
-{
+gb_inline GB_COMPARE_PROC(gbgl__kern_pair_compare) {
gbglKernPair *kp0 = cast(gbglKernPair *)a;
gbglKernPair *kp1 = cast(gbglKernPair *)b;
return kp0->packed - kp1->packed;
}
-gb_inline
-GB_COMPARE_PROC(gbgl__glyph_map_compare)
-{
+gb_inline GB_COMPARE_PROC(gbgl__glyph_map_compare) {
gbglGlyphMapKVPair g0 = *cast(gbglGlyphMapKVPair *)a;
gbglGlyphMapKVPair g1 = *cast(gbglGlyphMapKVPair *)b;
return g0.codepoint - g1.codepoint;
@@ -1409,9 +1324,7 @@ GB_COMPARE_PROC(gbgl__glyph_map_compare)
-b32
-gbgl_get_packed_font_dim(gbglFontCache *cache, gbglFontCachedTTF *ttf, i32 *width, i32 *height)
-{
+b32 gbgl_get_packed_font_dim(gbglFontCache *cache, gbglFontCachedTTF *ttf, i32 *width, i32 *height) {
b32 result = true;
stbtt_pack_context spc;
b32 ext_w = true;
@@ -1481,9 +1394,7 @@ done:
}
#if 0
-void
-gbgl_destroy_font_cache(gbglFontCache *fc)
-{
+void gbgl_destroy_font_cache(gbglFontCache *fc) {
gbglFontCachedTTF *curr_ttf = fc->ttf_buffer;
gbglFontCachedTTF *next_ttf = NULL;
@@ -1522,18 +1433,14 @@ gbgl_destroy_font_cache(gbglFontCache *fc)
#endif
-gb_inline gbglFont *
-gbgl_load_font_from_file(gbglFontCache *fc, char const *ttf_filename, f32 font_size)
-{
+gb_inline gbglFont * gbgl_load_font_from_file(gbglFontCache *fc, char const *ttf_filename, f32 font_size) {
gbglFont *f = gbgl_get_font_only_from_cache(fc, ttf_filename, font_size);
if (f) return f;
return gbgl_cache_font(fc, ttf_filename, font_size);
}
-gb_inline gbglFont *
-gbgl_get_font_only_from_cache(gbglFontCache *fc, char const *ttf_filename, f32 font_size)
-{
+gb_inline gbglFont * gbgl_get_font_only_from_cache(gbglFontCache *fc, char const *ttf_filename, f32 font_size) {
gbglFont *f = fc->fonts;
while (f) {
if (f->size == font_size && gb_strcmp(ttf_filename, f->ttf_filename) == 0) {
@@ -1544,9 +1451,7 @@ gbgl_get_font_only_from_cache(gbglFontCache *fc, char const *ttf_filename, f32 f
return NULL;
}
-gbglFont *
-gbgl_cache_font(gbglFontCache *fc, char const *ttf_filename, f32 font_size)
-{
+gbglFont * gbgl_cache_font(gbglFontCache *fc, char const *ttf_filename, f32 font_size) {
gbglFont *f = gbgl_get_font_only_from_cache(fc, ttf_filename, font_size);
gbglFontCachedTTF *ttf = NULL;
isize i;
@@ -1757,17 +1662,13 @@ gbgl_cache_font(gbglFontCache *fc, char const *ttf_filename, f32 font_size)
}
-gb_inline
-GB_COMPARE_PROC(gbgl__font_glyph_map_search_proc)
-{
+gb_inline GB_COMPARE_PROC(gbgl__font_glyph_map_search_proc) {
gbglGlyphMapKVPair const *gm = cast(gbglGlyphMapKVPair const *)a;
char32 ucp = *cast(char32 const *)b;
return cast(i32)(cast(i64)gm->codepoint - cast(i64)ucp);
}
-gb_inline gbglGlyphInfo *
-gbgl_get_glyph_info(gbglFont *font, char32 codepoint, isize *out_index)
-{
+gb_inline gbglGlyphInfo * gbgl_get_glyph_info(gbglFont *font, char32 codepoint, isize *out_index) {
isize index = gb_binary_search_array(font->glyph_map, font->glyph_count, &codepoint, gbgl__font_glyph_map_search_proc);
if (index >= 0) {
GB_ASSERT(codepoint == font->glyph_map[index].codepoint);
@@ -1778,9 +1679,7 @@ gbgl_get_glyph_info(gbglFont *font, char32 codepoint, isize *out_index)
return NULL;
}
-gb_inline f32
-gbgl_get_font_kerning_from_glyph_indices(gbglFont *font, isize left_index, isize right_index)
-{
+gb_inline f32 gbgl_get_font_kerning_from_glyph_indices(gbglFont *font, isize left_index, isize right_index) {
isize needle = (right_index << 16) | (left_index & 0xff);
isize f = 0;
@@ -1800,9 +1699,7 @@ gbgl_get_font_kerning_from_glyph_indices(gbglFont *font, isize left_index, isize
return 0.0f;
}
-void
-gbgl_get_string_dimensions(gbglFont *font, char const *str, f32 *out_width, f32 *out_height)
-{
+void gbgl_get_string_dimensions(gbglFont *font, char const *str, f32 *out_width, f32 *out_height) {
isize len, char_count, i;
f32 w = 0.0f;
@@ -1838,9 +1735,7 @@ gbgl_get_string_dimensions(gbglFont *font, char const *str, f32 *out_width, f32
if (out_height) *out_height = h;
}
-f32
-gbgl_get_sub_string_width(gbglFont *font, char const *str, isize char_count)
-{
+f32 gbgl_get_sub_string_width(gbglFont *font, char const *str, isize char_count) {
isize i, len;
f32 w = 0;
char const *ptr = str;
@@ -1874,9 +1769,7 @@ gbgl_get_sub_string_width(gbglFont *font, char const *str, isize char_count)
return w;
}
-i32
-gbgl_get_wrapped_line_count(gbglFont *font, char const *str, isize max_len, isize max_width)
-{
+i32 gbgl_get_wrapped_line_count(gbglFont *font, char const *str, isize max_len, isize max_width) {
isize i, str_len, char_count, line_count = 1;
f32 w = 0;
char const *ptr = str;
@@ -1921,9 +1814,7 @@ gbgl_get_wrapped_line_count(gbglFont *font, char const *str, isize max_len, isiz
return line_count;
}
-gb_inline f32
-gbgl_get_string_width(gbglFont *font, char const *str, isize max_len)
-{
+gb_inline f32 gbgl_get_string_width(gbglFont *font, char const *str, isize max_len) {
isize len = gb_strnlen(str, max_len);
isize char_count = gb_utf8_strnlen(str, len);
return gbgl_get_sub_string_width(font, str, char_count);
@@ -1941,9 +1832,7 @@ gbgl_get_string_width(gbglFont *font, char const *str, isize max_len)
#if !defined(GBGL_NO_BASIC_STATE)
-void
-gbgl_bs_init(gbglBasicState *bs, i32 window_width, i32 window_height)
-{
+void gbgl_bs_init(gbglBasicState *bs, i32 window_width, i32 window_height) {
isize i;
gbgl_bs_set_resolution(bs, window_width, window_height);
@@ -2050,9 +1939,7 @@ gbgl_bs_init(gbglBasicState *bs, i32 window_width, i32 window_height)
#endif
}
-gb_inline void
-gbgl_bs_set_resolution(gbglBasicState *bs, i32 window_width, i32 window_height)
-{
+gb_inline void gbgl_bs_set_resolution(gbglBasicState *bs, i32 window_width, i32 window_height) {
f32 left = 0.0f;
f32 right = cast(f32)window_width;
f32 bottom = 0.0f;
@@ -2084,26 +1971,20 @@ gbgl_bs_set_resolution(gbglBasicState *bs, i32 window_width, i32 window_height)
bs->ortho_mat[15] = 1.0f;
}
-gb_inline void
-gbgl_bs_begin(gbglBasicState *bs, i32 window_width, i32 window_height)
-{
+gb_inline void gbgl_bs_begin(gbglBasicState *bs, i32 window_width, i32 window_height) {
glBindVertexArray(bs->vao);
glDisable(GL_SCISSOR_TEST);
gbgl_bs_set_resolution(bs, window_width, window_height);
}
-gb_inline void
-gbgl_bs_end(gbglBasicState *bs)
-{
+gb_inline void gbgl_bs_end(gbglBasicState *bs) {
glBindVertexArray(0);
}
-void
-gbgl_bs_draw_textured_rect(gbglBasicState *bs, gbglTexture *tex, f32 x, f32 y, f32 w, f32 h, b32 v_up)
-{
+void gbgl_bs_draw_textured_rect(gbglBasicState *bs, gbglTexture *tex, f32 x, f32 y, f32 w, f32 h, b32 v_up) {
bs->vertices[0].x = x;
bs->vertices[0].y = y;
bs->vertices[0].u = 0.0f;
@@ -2141,9 +2022,7 @@ gbgl_bs_draw_textured_rect(gbglBasicState *bs, gbglTexture *tex, f32 x, f32 y, f
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, NULL);
}
-gb_inline void
-gbgl_bs_draw_rect(gbglBasicState *bs, f32 x, f32 y, f32 w, f32 h, gbColour col)
-{
+gb_inline void gbgl_bs_draw_rect(gbglBasicState *bs, f32 x, f32 y, f32 w, f32 h, gbColour col) {
gbgl_bs_draw_quad(bs,
x, y,
x+w, y,
@@ -2152,9 +2031,7 @@ gbgl_bs_draw_rect(gbglBasicState *bs, f32 x, f32 y, f32 w, f32 h, gbColour col)
col);
}
-gb_inline void
-gbgl_bs_draw_rect_outline(gbglBasicState *bs, f32 x, f32 y, f32 w, f32 h, gbColour col, f32 thickness)
-{
+gb_inline void gbgl_bs_draw_rect_outline(gbglBasicState *bs, f32 x, f32 y, f32 w, f32 h, gbColour col, f32 thickness) {
gbgl_bs_draw_quad_outline(bs,
x, y,
x+w, y,
@@ -2165,9 +2042,7 @@ gbgl_bs_draw_rect_outline(gbglBasicState *bs, f32 x, f32 y, f32 w, f32 h, gbColo
}
-gb_internal void
-gbgl__bs_setup_ortho_colour_state(gbglBasicState *bs, isize vertex_count, gbColour col)
-{
+gb_internal void gbgl__bs_setup_ortho_colour_state(gbglBasicState *bs, isize vertex_count, gbColour col) {
gbgl_use_shader(&bs->ortho_col_shader);
gbgl_set_uniform_mat4(&bs->ortho_col_shader, "u_ortho_mat", bs->ortho_mat);
@@ -2182,14 +2057,12 @@ gbgl__bs_setup_ortho_colour_state(gbglBasicState *bs, isize vertex_count, gbColo
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
-gb_inline void
-gbgl_bs_draw_quad(gbglBasicState *bs,
- f32 x0, f32 y0,
- f32 x1, f32 y1,
- f32 x2, f32 y2,
- f32 x3, f32 y3,
- gbColour col)
-{
+gb_inline void gbgl_bs_draw_quad(gbglBasicState *bs,
+ f32 x0, f32 y0,
+ f32 x1, f32 y1,
+ f32 x2, f32 y2,
+ f32 x3, f32 y3,
+ gbColour col) {
bs->vertices[0].x = x0;
bs->vertices[0].y = y0;
@@ -2206,14 +2079,12 @@ gbgl_bs_draw_quad(gbglBasicState *bs,
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, NULL);
}
-gb_inline void
-gbgl_bs_draw_quad_outline(gbglBasicState *bs,
- f32 x0, f32 y0,
- f32 x1, f32 y1,
- f32 x2, f32 y2,
- f32 x3, f32 y3,
- gbColour col, f32 thickness)
-{
+gb_inline void gbgl_bs_draw_quad_outline(gbglBasicState *bs,
+ f32 x0, f32 y0,
+ f32 x1, f32 y1,
+ f32 x2, f32 y2,
+ f32 x3, f32 y3,
+ gbColour col, f32 thickness) {
bs->vertices[0].x = x0;
bs->vertices[0].y = y0;
@@ -2231,9 +2102,7 @@ gbgl_bs_draw_quad_outline(gbglBasicState *bs,
glDrawArrays(GL_LINE_LOOP, 0, 4);
}
-gb_inline void
-gbgl_bs_draw_line(gbglBasicState *bs, f32 x0, f32 y0, f32 x1, f32 y1, gbColour col, f32 thickness)
-{
+gb_inline void gbgl_bs_draw_line(gbglBasicState *bs, f32 x0, f32 y0, f32 x1, f32 y1, gbColour col, f32 thickness) {
bs->vertices[0].x = x0;
bs->vertices[0].y = y0;
@@ -2245,10 +2114,8 @@ gbgl_bs_draw_line(gbglBasicState *bs, f32 x0, f32 y0, f32 x1, f32 y1, gbColour c
glDrawArrays(GL_LINES, 0, 2);
}
-gb_inline void
-gbgl_bs_draw_elliptical_arc(gbglBasicState *bs, f32 x, f32 y, f32 radius_a, f32 radius_b,
- f32 min_angle, f32 max_angle, gbColour col)
-{
+gb_inline void gbgl_bs_draw_elliptical_arc(gbglBasicState *bs, f32 x, f32 y, f32 radius_a, f32 radius_b,
+ f32 min_angle, f32 max_angle, gbColour col) {
isize i;
bs->vertices[0].x = x;
@@ -2267,10 +2134,8 @@ gbgl_bs_draw_elliptical_arc(gbglBasicState *bs, f32 x, f32 y, f32 radius_a, f32
glDrawArrays(GL_TRIANGLE_FAN, 0, 32);
}
-gb_inline void
-gbgl_bs_draw_elliptical_arc_outline(gbglBasicState *bs, f32 x, f32 y, f32 radius_a, f32 radius_b,
- f32 min_angle, f32 max_angle, gbColour col, f32 thickness)
-{
+gb_inline void gbgl_bs_draw_elliptical_arc_outline(gbglBasicState *bs, f32 x, f32 y, f32 radius_a, f32 radius_b,
+ f32 min_angle, f32 max_angle, gbColour col, f32 thickness) {
isize i;
for (i = 0; i < 32; i++) {
@@ -2289,21 +2154,15 @@ gbgl_bs_draw_elliptical_arc_outline(gbglBasicState *bs, f32 x, f32 y, f32 radius
-gb_inline void
-gbgl_bs_draw_circle(gbglBasicState *bs, f32 x, f32 y, f32 radius, gbColour col)
-{
+gb_inline void gbgl_bs_draw_circle(gbglBasicState *bs, f32 x, f32 y, f32 radius, gbColour col) {
gbgl_bs_draw_elliptical_arc(bs, x, y, radius, radius, 0, GBGL_TAU, col);
}
-gb_inline void
-gbgl_bs_draw_circle_outline(gbglBasicState *bs, f32 x, f32 y, f32 radius, gbColour col, f32 thickness)
-{
+gb_inline void gbgl_bs_draw_circle_outline(gbglBasicState *bs, f32 x, f32 y, f32 radius, gbColour col, f32 thickness) {
gbgl_bs_draw_elliptical_arc_outline(bs, x, y, radius, radius, 0, GBGL_TAU, col, thickness);
}
-void
-gbgl_bs_draw_rounded_rect_corners(gbglBasicState *bs, f32 x, f32 y, f32 w, f32 h, f32 roundness, gbColour col, u32 corners)
-{
+void gbgl_bs_draw_rounded_rect_corners(gbglBasicState *bs, f32 x, f32 y, f32 w, f32 h, f32 roundness, gbColour col, u32 corners) {
if ((2.0f*roundness > gbgl_abs(w)) ||
(2.0f*roundness > gbgl_abs(h))) {
roundness = 0.5f*gbgl_min(gbgl_abs(w), gbgl_abs(h));
@@ -2397,16 +2256,12 @@ gbgl_bs_draw_rounded_rect_corners(gbglBasicState *bs, f32 x, f32 y, f32 w, f32 h
}
}
-gb_inline void
-gbgl_bs_draw_rounded_rect(gbglBasicState *bs, f32 x, f32 y, f32 w, f32 h, f32 roundness, gbColour col)
-{
+gb_inline void gbgl_bs_draw_rounded_rect(gbglBasicState *bs, f32 x, f32 y, f32 w, f32 h, f32 roundness, gbColour col) {
gbgl_bs_draw_rounded_rect_corners(bs, x, y, w, h, roundness, col, 1|2|4|8);
}
-void
-gbgl_bs_draw_rounded_rect_corners_outline(gbglBasicState *bs, f32 x, f32 y, f32 w, f32 h, f32 roundness, gbColour col, f32 thickness, u32 corners)
-{
+void gbgl_bs_draw_rounded_rect_corners_outline(gbglBasicState *bs, f32 x, f32 y, f32 w, f32 h, f32 roundness, gbColour col, f32 thickness, u32 corners) {
if ((2.0f*roundness > gbgl_abs(w)) ||
(2.0f*roundness > gbgl_abs(h))) {
roundness = 0.5f*gbgl_min(gbgl_abs(w), gbgl_abs(h));
@@ -2488,9 +2343,7 @@ gbgl_bs_draw_rounded_rect_corners_outline(gbglBasicState *bs, f32 x, f32 y, f32
}
}
-gb_inline void
-gbgl_bs_draw_rounded_rect_outline(gbglBasicState *bs, f32 x, f32 y, f32 w, f32 h, f32 roundness, gbColour col, f32 thickness)
-{
+gb_inline void gbgl_bs_draw_rounded_rect_outline(gbglBasicState *bs, f32 x, f32 y, f32 w, f32 h, f32 roundness, gbColour col, f32 thickness) {
gbgl_bs_draw_rounded_rect_corners_outline(bs, x, y, w, h, roundness, col, thickness, 1|2|4|8);
}
@@ -2500,9 +2353,7 @@ gbgl_bs_draw_rounded_rect_outline(gbglBasicState *bs, f32 x, f32 y, f32 w, f32 h
#if !defined(GBGL_NO_FONTS)
-isize
-gbgl_bs_draw_substring(gbglBasicState *bs, gbglFont *font, f32 x, f32 y, gbColour col, char const *str, isize len)
-{
+isize gbgl_bs_draw_substring(gbglBasicState *bs, gbglFont *font, f32 x, f32 y, gbColour col, char const *str, isize len) {
isize char_count = gb_utf8_strnlen(str, len);
isize line_count = 0;
if (char_count > 0) {
@@ -2656,9 +2507,7 @@ gbgl_bs_draw_substring(gbglBasicState *bs, gbglFont *font, f32 x, f32 y, gbColou
return line_count;
}
-isize
-gbgl_bs_draw_string(gbglBasicState *bs, gbglFont *font, f32 x, f32 y, gbColour col, char const *fmt, ...)
-{
+isize gbgl_bs_draw_string(gbglBasicState *bs, gbglFont *font, f32 x, f32 y, gbColour col, char const *fmt, ...) {
isize len;
va_list va;
va_start(va, fmt);
@@ -2667,9 +2516,7 @@ gbgl_bs_draw_string(gbglBasicState *bs, gbglFont *font, f32 x, f32 y, gbColour c
return len;
}
-gb_inline isize
-gbgl_bs_draw_string_va(gbglBasicState *bs, gbglFont *font, f32 x, f32 y, gbColour col, char const *fmt, va_list va)
-{
+gb_inline isize gbgl_bs_draw_string_va(gbglBasicState *bs, gbglFont *font, f32 x, f32 y, gbColour col, char const *fmt, va_list va) {
isize len = gb_snprintf_va(bs->font_text_buffer, gb_size_of(bs->font_text_buffer),
fmt, va);
isize char_count = gb_utf8_strnlen(bs->font_text_buffer, len);
diff --git a/gb_math.h b/gb_math.h
index b152e68..0a9f5e5 100644
--- a/gb_math.h
+++ b/gb_math.h
@@ -1,8 +1,9 @@
-/* gb_math.h - v0.06d - public domain C math library - no warranty implied; use at your own risk
+/* gb_math.h - v0.06e - public domain C math library - no warranty implied; use at your own risk
A C math library geared towards game development
use '#define GB_MATH_IMPLEMENTATION' before including to create the implementation in _ONE_ file
Version History:
+ 0.06e - Change brace style and fix some warnings
0.06d - Bug fix
0.06c - Remove extra needed define for C++ and inline all operators
0.06b - Just formatting
@@ -551,9 +552,7 @@ inline gbVec4 &operator*=(gbVec4 &a, float scalar) { return (a = a * scalar); }
inline gbVec4 &operator/=(gbVec4 &a, float scalar) { return (a = a / scalar); }
-inline gbMat2
-operator+(gbMat2 const &a, gbMat2 const &b)
-{
+inline gbMat2 operator+(gbMat2 const &a, gbMat2 const &b) {
int i, j;
gbMat2 r = {0};
for (j = 0; j < 2; j++) {
@@ -563,9 +562,7 @@ operator+(gbMat2 const &a, gbMat2 const &b)
return r;
}
-inline gbMat2
-operator-(gbMat2 const &a, gbMat2 const &b)
-{
+inline gbMat2 operator-(gbMat2 const &a, gbMat2 const &b) {
int i, j;
gbMat2 r = {0};
for (j = 0; j < 2; j++) {
@@ -577,9 +574,7 @@ operator-(gbMat2 const &a, gbMat2 const &b)
inline gbMat2 operator*(gbMat2 const &a, gbMat2 const &b) { gbMat2 r; gb_mat2_mul(&r, (gbMat2 *)&a, (gbMat2 *)&b); return r; }
inline gbVec2 operator*(gbMat2 const &a, gbVec2 v) { gbVec2 r; gb_mat2_mul_vec2(&r, (gbMat2 *)&a, v); return r; }
-inline gbMat2
-operator*(gbMat2 const &a, float scalar)
-{
+inline gbMat2 operator*(gbMat2 const &a, float scalar) {
gbMat2 r = {0};
int i;
for (i = 0; i < 2*2; i++) r.e[i] = a.e[i] * scalar;
@@ -594,9 +589,7 @@ inline gbMat2& operator*=(gbMat2& a, gbMat2 const &b) { return (a = a * b); }
-inline gbMat3
-operator+(gbMat3 const &a, gbMat3 const &b)
-{
+inline gbMat3 operator+(gbMat3 const &a, gbMat3 const &b) {
int i, j;
gbMat3 r = {0};
for (j = 0; j < 3; j++) {
@@ -606,9 +599,7 @@ operator+(gbMat3 const &a, gbMat3 const &b)
return r;
}
-inline gbMat3
-operator-(gbMat3 const &a, gbMat3 const &b)
-{
+inline gbMat3 operator-(gbMat3 const &a, gbMat3 const &b) {
int i, j;
gbMat3 r = {0};
for (j = 0; j < 3; j++) {
@@ -619,9 +610,7 @@ operator-(gbMat3 const &a, gbMat3 const &b)
}
inline gbMat3 operator*(gbMat3 const &a, gbMat3 const &b) { gbMat3 r; gb_mat3_mul(&r, (gbMat3 *)&a, (gbMat3 *)&b); return r; }
-inline gbVec3 operator*(gbMat3 const &a, gbVec3 v) { gbVec3 r; gb_mat3_mul_vec3(&r, (gbMat3 *)&a, v); return r; }
-inline gbMat3 operator*(gbMat3 const &a, float scalar)
-{
+inline gbVec3 operator*(gbMat3 const &a, gbVec3 v) { gbVec3 r; gb_mat3_mul_vec3(&r, (gbMat3 *)&a, v); return r; } inline gbMat3 operator*(gbMat3 const &a, float scalar) {
gbMat3 r = {0};
int i;
for (i = 0; i < 3*3; i++) r.e[i] = a.e[i] * scalar;
@@ -636,9 +625,7 @@ inline gbMat3& operator*=(gbMat3& a, gbMat3 const &b) { return (a = a * b); }
-inline gbMat4
-operator+(gbMat4 const &a, gbMat4 const &b)
-{
+inline gbMat4 operator+(gbMat4 const &a, gbMat4 const &b) {
int i, j;
gbMat4 r = {0};
for (j = 0; j < 4; j++) {
@@ -648,9 +635,7 @@ operator+(gbMat4 const &a, gbMat4 const &b)
return r;
}
-inline gbMat4
-operator-(gbMat4 const &a, gbMat4 const &b)
-{
+inline gbMat4 operator-(gbMat4 const &a, gbMat4 const &b) {
int i, j;
gbMat4 r = {0};
for (j = 0; j < 4; j++) {
@@ -662,9 +647,7 @@ operator-(gbMat4 const &a, gbMat4 const &b)
inline gbMat4 operator*(gbMat4 const &a, gbMat4 const &b) { gbMat4 r; gb_mat4_mul(&r, (gbMat4 *)&a, (gbMat4 *)&b); return r; }
inline gbVec4 operator*(gbMat4 const &a, gbVec4 v) { gbVec4 r; gb_mat4_mul_vec4(&r, (gbMat4 *)&a, v); return r; }
-inline gbMat4
-operator*(gbMat4 const &a, float scalar)
-{
+inline gbMat4 operator*(gbMat4 const &a, float scalar) {
gbMat4 r = {0};
int i;
for (i = 0; i < 4*4; i++) r.e[i] = a.e[i] * scalar;
@@ -753,9 +736,7 @@ inline gbVec3 operator*(gbQuat q, gbVec3 v) { gbVec3 r; gb_quat_rotate_vec3(&r,
/* NOTE(bill): To remove the need for memcpy */
-static void
-gb__memcpy_4byte(void *dest, void const *src, size_t size)
-{
+static void gb__memcpy_4byte(void *dest, void const *src, size_t size) {
size_t i;
unsigned int *d, *s;
d = (unsigned int *)dest;
@@ -766,9 +747,7 @@ gb__memcpy_4byte(void *dest, void const *src, size_t size)
}
/* NOTE(bill): To remove the need for memset */
-static void
-gb__memzero_byte4(void *dest, size_t size)
-{
+static void gb__memzero_byte4(void *dest, size_t size) {
unsigned *d = (unsigned *)dest;
unsigned i;
for (i = 0; i < size/4; i++)
@@ -780,18 +759,14 @@ gb__memzero_byte4(void *dest, size_t size)
float gb_to_radians(float degrees) { return degrees * GB_MATH_TAU / 360.0f; }
float gb_to_degrees(float radians) { return radians * 360.0f / GB_MATH_TAU; }
-float
-gb_angle_diff(float radians_a, float radians_b)
-{
+float gb_angle_diff(float radians_a, float radians_b) {
float delta = gb_mod(radians_b-radians_a, GB_MATH_TAU);
delta = gb_mod(delta + 1.5f*GB_MATH_TAU, GB_MATH_TAU);
delta -= 0.5f*GB_MATH_TAU;
return delta;
}
-float
-gb_copy_sign(float x, float y)
-{
+float gb_copy_sign(float x, float y) {
int ix, iy;
ix = *(int *)&x;
iy = *(int *)&y;
@@ -801,15 +776,11 @@ gb_copy_sign(float x, float y)
return *(float *)&ix;
}
-float
-gb_remainder(float x, float y)
-{
+float gb_remainder(float x, float y) {
return x - (gb_round(x/y)*y);
}
-float
-gb_mod(float x, float y)
-{
+float gb_mod(float x, float y) {
float result;
y = gb_abs(y);
result = gb_remainder(gb_abs(x), y);
@@ -818,9 +789,7 @@ gb_mod(float x, float y)
}
-float
-gb_quake_rsqrt(float a)
-{
+float gb_quake_rsqrt(float a) {
union {
int i;
float f;
@@ -1003,11 +972,9 @@ float gb_exp2(float x) { return gb_exp(GB_MATH_LOG_TWO * x); }
float gb_log2(float x) { return gb_log(x) / GB_MATH_LOG_TWO; }
-float
-gb_fast_exp(float x)
-{
+float gb_fast_exp(float x) {
/* NOTE(bill): Only works in the range -1 <= x <= +1 */
- float e = 1.0f + x*(1.0f + x*0.5f*(1.0f + x*0.3333333333f*(1.0f + x*0.25*(1.0f + x*0.2f))));
+ float e = 1.0f + x*(1.0f + x*0.5f*(1.0f + x*0.3333333333f*(1.0f + x*0.25f*(1.0f + x*0.2f))));
return e;
}
@@ -1023,9 +990,7 @@ float gb_ceil(float x) { return (float)((x < 0) ? (int)x : ((int)x)+1); }
-float
-gb_half_to_float(gbHalf value)
-{
+float gb_half_to_float(gbHalf value) {
union { unsigned int i; float f; } result;
int s = (value >> 15) & 0x001;
int e = (value >> 10) & 0x01f;
@@ -1065,9 +1030,7 @@ gb_half_to_float(gbHalf value)
return result.f;
}
-gbHalf
-gb_float_to_half(float value)
-{
+gbHalf gb_float_to_half(float value) {
union { unsigned int i; float f; } v;
int i, s, e, m;
@@ -1154,17 +1117,17 @@ gb_float_to_half(float value)
a->w = b.w op c.w post;
-gbVec2 gb_vec2_zero(void) { gbVec2 v = {0, 0}; return v; }
-gbVec2 gb_vec2(float x, float y) { gbVec2 v = {x, y}; return v; }
-gbVec2 gb_vec2v(float x[2]) { gbVec2 v = {x[0], x[1]}; return v; }
+gbVec2 gb_vec2_zero(void) { gbVec2 v = {0, 0}; return v; }
+gbVec2 gb_vec2(float x, float y) { gbVec2 v; v.x = x; v.y = y; return v; }
+gbVec2 gb_vec2v(float x[2]) { gbVec2 v; v.x = x[0]; v.y = x[1]; return v; }
-gbVec3 gb_vec3_zero(void) { gbVec3 v = {0, 0, 0}; return v; }
-gbVec3 gb_vec3(float x, float y, float z) { gbVec3 v = {x, y, z}; return v; }
-gbVec3 gb_vec3v(float x[3]) { gbVec3 v = {x[0], x[1], x[2]}; return v; }
+gbVec3 gb_vec3_zero(void) { gbVec3 v = {0, 0, 0}; return v; }
+gbVec3 gb_vec3(float x, float y, float z) { gbVec3 v; v.x = x; v.y = y; v.z = z; return v; }
+gbVec3 gb_vec3v(float x[3]) { gbVec3 v; v.x = x[0]; v.y = x[1]; v.z = x[2]; return v; }
-gbVec4 gb_vec4_zero(void) { gbVec4 v = {0, 0, 0, 0}; return v; }
-gbVec4 gb_vec4(float x, float y, float z, float w) { gbVec4 v = {x, y, z, w}; return v; }
-gbVec4 gb_vec4v(float x[4]) { gbVec4 v = {x[0], x[1], x[2], x[3]}; return v; }
+gbVec4 gb_vec4_zero(void) { gbVec4 v = {0, 0, 0, 0}; return v; }
+gbVec4 gb_vec4(float x, float y, float z, float w) { gbVec4 v; v.x = x; v.y = y; v.z = z; v.w = w; return v; }
+gbVec4 gb_vec4v(float x[4]) { gbVec4 v; v.x = x[0]; v.y = x[1]; v.z = x[2]; v.w = x[3]; return v; }
void gb_vec2_add(gbVec2 *d, gbVec2 v0, gbVec2 v1) { GB_VEC2_3OP(d,v0,+,v1,+0); }
@@ -1227,46 +1190,34 @@ float gb_vec2_mag(gbVec2 v) { return gb_sqrt(gb_vec2_dot(v, v)); }
float gb_vec3_mag(gbVec3 v) { return gb_sqrt(gb_vec3_dot(v, v)); }
float gb_vec4_mag(gbVec4 v) { return gb_sqrt(gb_vec4_dot(v, v)); }
-void
-gb_vec2_norm(gbVec2 *d, gbVec2 v)
-{
+void gb_vec2_norm(gbVec2 *d, gbVec2 v) {
float inv_mag = gb_rsqrt(gb_vec2_dot(v, v));
gb_vec2_mul(d, v, inv_mag);
}
-void
-gb_vec3_norm(gbVec3 *d, gbVec3 v)
-{
+void gb_vec3_norm(gbVec3 *d, gbVec3 v) {
float mag = gb_vec3_mag(v);
gb_vec3_div(d, v, mag);
}
-void
-gb_vec4_norm(gbVec4 *d, gbVec4 v)
-{
+void gb_vec4_norm(gbVec4 *d, gbVec4 v) {
float mag = gb_vec4_mag(v);
gb_vec4_div(d, v, mag);
}
-void
-gb_vec2_norm0(gbVec2 *d, gbVec2 v)
-{
+void gb_vec2_norm0(gbVec2 *d, gbVec2 v) {
float mag = gb_vec2_mag(v);
if (mag > 0)
gb_vec2_div(d, v, mag);
else
*d = gb_vec2_zero();
}
-void
-gb_vec3_norm0(gbVec3 *d, gbVec3 v)
-{
+void gb_vec3_norm0(gbVec3 *d, gbVec3 v) {
float mag = gb_vec3_mag(v);
if (mag > 0)
gb_vec3_div(d, v, mag);
else
*d = gb_vec3_zero();
}
-void
-gb_vec4_norm0(gbVec4 *d, gbVec4 v)
-{
+void gb_vec4_norm0(gbVec4 *d, gbVec4 v) {
float mag = gb_vec4_mag(v);
if (mag > 0)
gb_vec4_div(d, v, mag);
@@ -1275,25 +1226,19 @@ gb_vec4_norm0(gbVec4 *d, gbVec4 v)
}
-void
-gb_vec2_reflect(gbVec2 *d, gbVec2 i, gbVec2 n)
-{
+void gb_vec2_reflect(gbVec2 *d, gbVec2 i, gbVec2 n) {
gbVec2 b = n;
gb_vec2_muleq(&b, 2.0f*gb_vec2_dot(n, i));
gb_vec2_sub(d, i, b);
}
-void
-gb_vec3_reflect(gbVec3 *d, gbVec3 i, gbVec3 n)
-{
+void gb_vec3_reflect(gbVec3 *d, gbVec3 i, gbVec3 n) {
gbVec3 b = n;
gb_vec3_muleq(&b, 2.0f*gb_vec3_dot(n, i));
gb_vec3_sub(d, i, b);
}
-void
-gb_vec2_refract(gbVec2 *d, gbVec2 i, gbVec2 n, float eta)
-{
+void gb_vec2_refract(gbVec2 *d, gbVec2 i, gbVec2 n, float eta) {
gbVec2 a, b;
float dv, k;
@@ -1305,9 +1250,7 @@ gb_vec2_refract(gbVec2 *d, gbVec2 i, gbVec2 n, float eta)
gb_vec2_muleq(d, (float)(k >= 0.0f));
}
-void
-gb_vec3_refract(gbVec3 *d, gbVec3 i, gbVec3 n, float eta)
-{
+void gb_vec3_refract(gbVec3 *d, gbVec3 i, gbVec3 n, float eta) {
gbVec3 a, b;
float dv, k;
@@ -1333,9 +1276,7 @@ void gb_mat2_transpose(gbMat2 *m) { gb_float22_transpose(gb_float22_m(m)); }
void gb_mat2_identity(gbMat2 *m) { gb_float22_identity(gb_float22_m(m)); }
void gb_mat2_mul(gbMat2 *out, gbMat2 *m1, gbMat2 *m2) { gb_float22_mul(gb_float22_m(out), gb_float22_m(m1), gb_float22_m(m2)); }
-void
-gb_float22_identity(float m[2][2])
-{
+void gb_float22_identity(float m[2][2]) {
m[0][0] = 1; m[0][1] = 0;
m[1][0] = 0; m[1][1] = 1;
}
@@ -1349,9 +1290,7 @@ gbFloat2 *gb_float22_m(gbMat2 *m) { return (gbFloat2 *)m; }
gbFloat2 *gb_float22_v(gbVec2 m[2]) { return (gbFloat2 *)m; }
gbFloat2 *gb_float22_4(float m[4]) { return (gbFloat2 *)m; }
-void
-gb_float22_transpose(float (*vec)[2])
-{
+void gb_float22_transpose(float (*vec)[2]) {
int i, j;
for (j = 0; j < 2; j++) {
for (i = j + 1; i < 2; i++) {
@@ -1364,9 +1303,7 @@ gb_float22_transpose(float (*vec)[2])
-void
-gb_float22_mul(float (*out)[2], float (*mat1)[2], float (*mat2)[2])
-{
+void gb_float22_mul(float (*out)[2], float (*mat1)[2], float (*mat2)[2]) {
int i, j;
float temp1[2][2], temp2[2][2];
if (mat1 == out) { gb__memcpy_4byte(temp1, mat1, sizeof(temp1)); mat1 = temp1; }
@@ -1379,9 +1316,7 @@ gb_float22_mul(float (*out)[2], float (*mat1)[2], float (*mat2)[2])
}
}
-void
-gb_float22_mul_vec2(gbVec2 *out, float m[2][2], gbVec2 v)
-{
+void gb_float22_mul_vec2(gbVec2 *out, float m[2][2], gbVec2 v) {
out->x = m[0][0]*v.x + m[0][1]*v.y;
out->y = m[1][0]*v.x + m[1][1]*v.y;
}
@@ -1395,9 +1330,7 @@ void gb_mat3_transpose(gbMat3 *m) { gb_float33_transpose(gb_float33_m(m)); }
void gb_mat3_identity(gbMat3 *m) { gb_float33_identity(gb_float33_m(m)); }
void gb_mat3_mul(gbMat3 *out, gbMat3 *m1, gbMat3 *m2) { gb_float33_mul(gb_float33_m(out), gb_float33_m(m1), gb_float33_m(m2)); }
-void
-gb_float33_identity(float m[3][3])
-{
+void gb_float33_identity(float m[3][3]) {
m[0][0] = 1; m[0][1] = 0; m[0][2] = 0;
m[1][0] = 0; m[1][1] = 1; m[1][2] = 0;
m[2][0] = 0; m[2][1] = 0; m[2][2] = 1;
@@ -1412,9 +1345,7 @@ gbFloat3 *gb_float33_m(gbMat3 *m) { return (gbFloat3 *)m; }
gbFloat3 *gb_float33_v(gbVec3 m[3]) { return (gbFloat3 *)m; }
gbFloat3 *gb_float33_16(float m[9]) { return (gbFloat3 *)m; }
-void
-gb_float33_transpose(float (*vec)[3])
-{
+void gb_float33_transpose(float (*vec)[3]) {
int i, j;
for (j = 0; j < 3; j++) {
for (i = j + 1; i < 3; i++) {
@@ -1425,9 +1356,7 @@ gb_float33_transpose(float (*vec)[3])
}
}
-void
-gb_float33_mul(float (*out)[3], float (*mat1)[3], float (*mat2)[3])
-{
+void gb_float33_mul(float (*out)[3], float (*mat1)[3], float (*mat2)[3]) {
int i, j;
float temp1[3][3], temp2[3][3];
if (mat1 == out) { gb__memcpy_4byte(temp1, mat1, sizeof(temp1)); mat1 = temp1; }
@@ -1441,9 +1370,7 @@ gb_float33_mul(float (*out)[3], float (*mat1)[3], float (*mat2)[3])
}
}
-void
-gb_float33_mul_vec3(gbVec3 *out, float m[3][3], gbVec3 v)
-{
+void gb_float33_mul_vec3(gbVec3 *out, float m[3][3], gbVec3 v) {
out->x = m[0][0]*v.x + m[0][1]*v.y + m[0][2]*v.z;
out->y = m[1][0]*v.x + m[1][1]*v.y + m[1][2]*v.z;
out->z = m[2][0]*v.x + m[2][1]*v.y + m[2][2]*v.z;
@@ -1461,18 +1388,14 @@ void gb_mat4_transpose(gbMat4 *m) { gb_float44_transpose(gb_float44_m(m)); }
void gb_mat4_identity(gbMat4 *m) { gb_float44_identity(gb_float44_m(m)); }
void gb_mat4_mul(gbMat4 *out, gbMat4 *m1, gbMat4 *m2) { gb_float44_mul(gb_float44_m(out), gb_float44_m(m1), gb_float44_m(m2)); }
-void
-gb_float44_identity(float m[4][4])
-{
+void gb_float44_identity(float m[4][4]) {
m[0][0] = 1; m[0][1] = 0; m[0][2] = 0; m[0][3] = 0;
m[1][0] = 0; m[1][1] = 1; m[1][2] = 0; m[1][3] = 0;
m[2][0] = 0; m[2][1] = 0; m[2][2] = 1; m[2][3] = 0;
m[3][0] = 0; m[3][1] = 0; m[3][2] = 0; m[3][3] = 1;
}
-void
-gb_mat4_mul_vec4(gbVec4 *out, gbMat4 *m, gbVec4 in)
-{
+void gb_mat4_mul_vec4(gbVec4 *out, gbMat4 *m, gbVec4 in) {
gb_float44_mul_vec4(out, gb_float44_m(m), in);
}
@@ -1483,9 +1406,7 @@ gbFloat4 *gb_float44_m(gbMat4 *m) { return (gbFloat4 *)m; }
gbFloat4 *gb_float44_v(gbVec4 m[4]) { return (gbFloat4 *)m; }
gbFloat4 *gb_float44_16(float m[16]) { return (gbFloat4 *)m; }
-void
-gb_float44_transpose(float (*vec)[4])
-{
+void gb_float44_transpose(float (*vec)[4]) {
int i, j;
for (j = 0; j < 4; j++) {
for (i = j + 1; i < 4; i++) {
@@ -1496,9 +1417,7 @@ gb_float44_transpose(float (*vec)[4])
}
}
-void
-gb_float44_mul(float (*out)[4], float (*mat1)[4], float (*mat2)[4])
-{
+void gb_float44_mul(float (*out)[4], float (*mat1)[4], float (*mat2)[4]) {
int i, j;
float temp1[4][4], temp2[4][4];
if (mat1 == out) { gb__memcpy_4byte(temp1, mat1, sizeof(temp1)); mat1 = temp1; }
@@ -1513,9 +1432,7 @@ gb_float44_mul(float (*out)[4], float (*mat1)[4], float (*mat2)[4])
}
}
-void
-gb_float44_mul_vec4(gbVec4 *out, float m[4][4], gbVec4 v)
-{
+void gb_float44_mul_vec4(gbVec4 *out, float m[4][4], gbVec4 v) {
out->x = m[0][0]*v.x + m[0][1]*v.y + m[0][2]*v.z + m[0][3]*v.w;
out->y = m[1][0]*v.x + m[1][1]*v.y + m[1][2]*v.z + m[1][3]*v.w;
out->z = m[2][0]*v.x + m[2][1]*v.y + m[2][2]*v.z + m[2][3]*v.w;
@@ -1524,17 +1441,13 @@ gb_float44_mul_vec4(gbVec4 *out, float m[4][4], gbVec4 v)
-void
-gb_mat4_translate(gbMat4 *out, gbVec3 v)
-{
+void gb_mat4_translate(gbMat4 *out, gbVec3 v) {
gb_mat4_identity(out);
out->col[3].xyz = v;
out->col[3].w = 1;
}
-void
-gb_mat4_rotate(gbMat4 *out, gbVec3 v, float angle_radians)
-{
+void gb_mat4_rotate(gbMat4 *out, gbVec3 v, float angle_radians) {
float c, s;
gbVec3 axis, t;
gbFloat4 *rot;
@@ -1564,18 +1477,14 @@ gb_mat4_rotate(gbMat4 *out, gbVec3 v, float angle_radians)
rot[2][3] = 0;
}
-void
-gb_mat4_scale(gbMat4 *out, gbVec3 v)
-{
+void gb_mat4_scale(gbMat4 *out, gbVec3 v) {
gb_mat4_identity(out);
out->e[0] = v.x;
out->e[5] = v.y;
out->e[10] = v.z;
}
-void
-gb_mat4_scalef(gbMat4 *out, float s)
-{
+void gb_mat4_scalef(gbMat4 *out, float s) {
gb_mat4_identity(out);
out->e[0] = s;
out->e[5] = s;
@@ -1583,9 +1492,7 @@ gb_mat4_scalef(gbMat4 *out, float s)
}
-void
-gb_mat4_ortho2d(gbMat4 *out, float left, float right, float bottom, float top)
-{
+void gb_mat4_ortho2d(gbMat4 *out, float left, float right, float bottom, float top) {
gbFloat4 *m;
gb_mat4_identity(out);
m = gb_float44_m(out);
@@ -1597,9 +1504,7 @@ gb_mat4_ortho2d(gbMat4 *out, float left, float right, float bottom, float top)
m[3][1] = -(top + bottom) / (top - bottom);
}
-void
-gb_mat4_ortho3d(gbMat4 *out, float left, float right, float bottom, float top, float z_near, float z_far)
-{
+void gb_mat4_ortho3d(gbMat4 *out, float left, float right, float bottom, float top, float z_near, float z_far) {
gbFloat4 *m;
gb_mat4_identity(out);
m = gb_float44_m(out);
@@ -1613,9 +1518,7 @@ gb_mat4_ortho3d(gbMat4 *out, float left, float right, float bottom, float top, f
}
-void
-gb_mat4_perspective(gbMat4 *out, float fovy, float aspect, float z_near, float z_far)
-{
+void gb_mat4_perspective(gbMat4 *out, float fovy, float aspect, float z_near, float z_far) {
float tan_half_fovy = gb_tan(0.5f * fovy);
gbFloat4 *m = gb_float44_m(out);
@@ -1628,9 +1531,7 @@ gb_mat4_perspective(gbMat4 *out, float fovy, float aspect, float z_near, float z
m[3][2] = -2.0f*z_far*z_near / (z_far - z_near);
}
-void
-gb_mat4_infinite_perspective(gbMat4 *out, float fovy, float aspect, float z_near)
-{
+void gb_mat4_infinite_perspective(gbMat4 *out, float fovy, float aspect, float z_near) {
float range = gb_tan(0.5f * fovy) * z_near;
float left = -range * aspect;
float right = range * aspect;
@@ -1647,9 +1548,7 @@ gb_mat4_infinite_perspective(gbMat4 *out, float fovy, float aspect, float z_near
m[3][2] = -2.0f*z_near;
}
-void
-gb_mat4_look_at(gbMat4 *out, gbVec3 eye, gbVec3 centre, gbVec3 up)
-{
+void gb_mat4_look_at(gbMat4 *out, gbVec3 eye, gbVec3 centre, gbVec3 up) {
gbVec3 f, s, u;
gbFloat4 *m;
@@ -1692,12 +1591,10 @@ gb_mat4_look_at(gbMat4 *out, gbVec3 eye, gbVec3 centre, gbVec3 up)
-gbQuat gb_quat(float x, float y, float z, float w) { gbQuat q = {x, y, z, w}; return q; }
-gbQuat gb_quatv(float e[4]) { gbQuat q = {e[0], e[1], e[2], e[3]}; return q; }
+gbQuat gb_quat(float x, float y, float z, float w) { gbQuat q; q.x = x; q.y = y; q.z = z; q.w = w; return q; }
+gbQuat gb_quatv(float e[4]) { gbQuat q; q.x = e[0]; q.y = e[1]; q.z = e[2]; q.w = e[3]; return q; }
-gbQuat
-gb_quat_axis_angle(gbVec3 axis, float angle_radians)
-{
+gbQuat gb_quat_axis_angle(gbVec3 axis, float angle_radians) {
gbQuat q;
gb_vec3_norm(&q.xyz, axis);
gb_vec3_muleq(&q.xyz, gb_sin(0.5f*angle_radians));
@@ -1705,9 +1602,7 @@ gb_quat_axis_angle(gbVec3 axis, float angle_radians)
return q;
}
-gbQuat
-gb_quat_euler_angles(float pitch, float yaw, float roll)
-{
+gbQuat gb_quat_euler_angles(float pitch, float yaw, float roll) {
/* TODO(bill): Do without multiplication, i.e. make it faster */
gbQuat q, p, y, r;
p = gb_quat_axis_angle(gb_vec3(1, 0, 0), pitch);
@@ -1726,9 +1621,7 @@ gbQuat gb_quat_identity(void) { gbQuat q = {0, 0, 0, 1}; return q; }
void gb_quat_add(gbQuat *d, gbQuat q0, gbQuat q1) { gb_vec4_add(&d->xyzw, q0.xyzw, q1.xyzw); }
void gb_quat_sub(gbQuat *d, gbQuat q0, gbQuat q1) { gb_vec4_sub(&d->xyzw, q0.xyzw, q1.xyzw); }
-void
-gb_quat_mul(gbQuat *d, gbQuat q0, gbQuat q1)
-{
+void gb_quat_mul(gbQuat *d, gbQuat q0, gbQuat q1) {
d->x = q0.w * q1.x + q0.x * q1.w + q0.y * q1.z - q0.z * q1.y;
d->y = q0.w * q1.y - q0.x * q1.z + q0.y * q1.w + q0.z * q1.x;
d->z = q0.w * q1.z + q0.x * q1.y - q0.y * q1.x + q0.z * q1.w;
@@ -1758,16 +1651,12 @@ void gb_quat_conj(gbQuat *d, gbQuat q) { d->xyz = gb_vec3(-q.x, -q.y, -q.z);
void gb_quat_inverse(gbQuat *d, gbQuat q) { gb_quat_conj(d, q); gb_quat_diveqf(d, gb_quat_dot(q, q)); }
-void
-gb_quat_axis(gbVec3 *axis, gbQuat q)
-{
+void gb_quat_axis(gbVec3 *axis, gbQuat q) {
gbQuat n; gb_quat_norm(&n, q);
gb_vec3_div(axis, n.xyz, gb_sin(gb_arccos(q.w)));
}
-float
-gb_quat_angle(gbQuat q)
-{
+float gb_quat_angle(gbQuat q) {
float mag = gb_quat_mag(q);
float c = q.w * (1.0f/mag);
float angle = 2.0f*gb_arccos(c);
@@ -1779,9 +1668,7 @@ float gb_quat_roll(gbQuat q) { return gb_arctan2(2.0f*q.x*q.y + q.z*q.w, q.x*q.
float gb_quat_pitch(gbQuat q) { return gb_arctan2(2.0f*q.y*q.z + q.w*q.x, q.w*q.w - q.x*q.x - q.y*q.y + q.z*q.z); }
float gb_quat_yaw(gbQuat q) { return gb_arcsin(-2.0f*(q.x*q.z - q.w*q.y)); }
-void
-gb_quat_rotate_vec3(gbVec3 *d, gbQuat q, gbVec3 v)
-{
+void gb_quat_rotate_vec3(gbVec3 *d, gbQuat q, gbVec3 v) {
/* gbVec3 t = 2.0f * cross(q.xyz, v);
* *d = q.w*t + v + cross(q.xyz, t);
*/
@@ -1797,9 +1684,7 @@ gb_quat_rotate_vec3(gbVec3 *d, gbQuat q, gbVec3 v)
}
-void
-gb_mat4_from_quat(gbMat4 *out, gbQuat q)
-{
+void gb_mat4_from_quat(gbMat4 *out, gbQuat q) {
gbFloat4 *m;
gbQuat a;
float xx, yy, zz,
@@ -1827,9 +1712,7 @@ gb_mat4_from_quat(gbMat4 *out, gbQuat q)
m[2][2] = 1.0f - 2.0f*(xx + yy);
}
-void
-gb_quat_from_mat4(gbQuat *out, gbMat4 *mat)
-{
+void gb_quat_from_mat4(gbQuat *out, gbMat4 *mat) {
gbFloat4 *m;
float four_x_squared_minus_1, four_y_squared_minus_1,
four_z_squared_minus_1, four_w_squared_minus_1,
@@ -1918,9 +1801,7 @@ void gb_vec4_lerp(gbVec4 *d, gbVec4 a, gbVec4 b, float t) { GB_VEC_LERPN(4, d, a
void gb_quat_lerp(gbQuat *d, gbQuat a, gbQuat b, float t) { gb_vec4_lerp(&d->xyzw, a.xyzw, b.xyzw, t); }
void gb_quat_nlerp(gbQuat *d, gbQuat a, gbQuat b, float t) { gb_quat_lerp(d, a, b, t); gb_quat_norm(d, *d); }
-void
-gb_quat_slerp(gbQuat *d, gbQuat a, gbQuat b, float t)
-{
+void gb_quat_slerp(gbQuat *d, gbQuat a, gbQuat b, float t) {
gbQuat x, y, z;
float cos_theta, angle;
float s1, s0, is;
@@ -1949,9 +1830,7 @@ gb_quat_slerp(gbQuat *d, gbQuat a, gbQuat b, float t)
gb_quat_muleqf(d, is);
}
-void
-gb_quat_slerp_approx(gbQuat *d, gbQuat a, gbQuat b, float t)
-{
+void gb_quat_slerp_approx(gbQuat *d, gbQuat a, gbQuat b, float t) {
/* NOTE(bill): Derived by taylor expanding the geometric interpolation equation
* Even works okay for nearly anti-parallel versors!!!
*/
@@ -1960,27 +1839,21 @@ gb_quat_slerp_approx(gbQuat *d, gbQuat a, gbQuat b, float t)
gb_quat_nlerp(d, a, b, tp);
}
-void
-gb_quat_nquad(gbQuat *d, gbQuat p, gbQuat a, gbQuat b, gbQuat q, float t)
-{
+void gb_quat_nquad(gbQuat *d, gbQuat p, gbQuat a, gbQuat b, gbQuat q, float t) {
gbQuat x, y;
gb_quat_nlerp(&x, p, q, t);
gb_quat_nlerp(&y, a, b, t);
gb_quat_nlerp(d, x, y, 2.0f*t*(1.0f-t));
}
-void
-gb_quat_squad(gbQuat *d, gbQuat p, gbQuat a, gbQuat b, gbQuat q, float t)
-{
+void gb_quat_squad(gbQuat *d, gbQuat p, gbQuat a, gbQuat b, gbQuat q, float t) {
gbQuat x, y;
gb_quat_slerp(&x, p, q, t);
gb_quat_slerp(&y, a, b, t);
gb_quat_slerp(d, x, y, 2.0f*t*(1.0f-t));
}
-void
-gb_quat_squad_approx(gbQuat *d, gbQuat p, gbQuat a, gbQuat b, gbQuat q, float t)
-{
+void gb_quat_squad_approx(gbQuat *d, gbQuat p, gbQuat a, gbQuat b, gbQuat q, float t) {
gbQuat x, y;
gb_quat_slerp_approx(&x, p, q, t);
gb_quat_slerp_approx(&y, a, b, t);
@@ -1992,27 +1865,21 @@ gb_quat_squad_approx(gbQuat *d, gbQuat p, gbQuat a, gbQuat b, gbQuat q, float t)
-gbRect2
-gb_rect2(gbVec2 pos, gbVec2 dim)
-{
+gbRect2 gb_rect2(gbVec2 pos, gbVec2 dim) {
gbRect2 r;
r.pos = pos;
r.dim = dim;
return r;
}
-gbRect3
-gb_rect3(gbVec3 pos, gbVec3 dim)
-{
+gbRect3 gb_rect3(gbVec3 pos, gbVec3 dim) {
gbRect3 r;
r.pos = pos;
r.dim = dim;
return r;
}
-int
-gb_rect2_contains(gbRect2 a, float x, float y)
-{
+int gb_rect2_contains(gbRect2 a, float x, float y) {
float min_x = gb_min(a.pos.x, a.pos.x+a.dim.x);
float max_x = gb_max(a.pos.x, a.pos.x+a.dim.x);
float min_y = gb_min(a.pos.y, a.pos.y+a.dim.y);
@@ -2023,16 +1890,12 @@ gb_rect2_contains(gbRect2 a, float x, float y)
int gb_rect2_contains_vec2(gbRect2 a, gbVec2 p) { return gb_rect2_contains(a, p.x, p.y); }
-int
-gb_rect2_intersects(gbRect2 a, gbRect2 b)
-{
+int gb_rect2_intersects(gbRect2 a, gbRect2 b) {
gbRect2 r = {0};
return gb_rect2_intersection_result(a, b, &r);
}
-int
-gb_rect2_intersection_result(gbRect2 a, gbRect2 b, gbRect2 *intersection)
-{
+int gb_rect2_intersection_result(gbRect2 a, gbRect2 b, gbRect2 *intersection) {
float a_min_x = gb_min(a.pos.x, a.pos.x+a.dim.x);
float a_max_x = gb_max(a.pos.x, a.pos.x+a.dim.x);
float a_min_y = gb_min(a.pos.y, a.pos.y+a.dim.y);
@@ -2061,9 +1924,7 @@ gb_rect2_intersection_result(gbRect2 a, gbRect2 b, gbRect2 *intersection)
#if defined(_WIN64) || defined(__x86_64__) || defined(__ppc64__)
- gb_math_u64
- gb_hash_murmur64(void const *key, size_t num_bytes, gb_math_u64 seed)
- {
+ gb_math_u64 gb_hash_murmur64(void const *key, size_t num_bytes, gb_math_u64 seed) {
gb_math_u64 const m = 0xc6a4a7935bd1e995ULL;
gb_math_u64 const r = 47;
@@ -2102,9 +1963,7 @@ gb_rect2_intersection_result(gbRect2 a, gbRect2 b, gbRect2 *intersection)
return h;
}
#else
- gb_math_u64
- gb_hash_murmur64(void const *key, size_t num_bytes, gb_math_u64 seed)
- {
+ gb_math_u64 gb_hash_murmur64(void const *key, size_t num_bytes, gb_math_u64 seed) {
gb_math_u32 const m = 0x5bd1e995;
gb_math_u32 const r = 24;
@@ -2169,9 +2028,7 @@ gb_rect2_intersection_result(gbRect2 a, gbRect2 b, gbRect2 *intersection)
/* TODO(bill): Make better random number generators */
-float
-gb_random_range_float(float min_inc, float max_inc)
-{
+float gb_random_range_float(float min_inc, float max_inc) {
int int_result = gb_random_range_int(0, 2147483646); /* Prevent integer overflow */
float result = int_result/(float)2147483646;
result *= max_inc - min_inc;
@@ -2179,9 +2036,7 @@ gb_random_range_float(float min_inc, float max_inc)
return result;
}
-int
-gb_random_range_int(int min_inc, int max_inc)
-{
+int gb_random_range_int(int min_inc, int max_inc) {
static int random_value = 0xdeadbeef; /* Random Value */
int diff, result;
random_value = random_value * 2147001325 + 715136305; /* BCPL generator */
diff --git a/gb_regex.h b/gb_regex.h
index 5c03116..b355f01 100644
--- a/gb_regex.h
+++ b/gb_regex.h
@@ -1,4 +1,4 @@
-/* gb_regex.h - v0.01c - Regular Expressions Library - public domain
+/* gb_regex.h - v0.01d - Regular Expressions Library - public domain
- no warranty implied; use at your own risk
This is a single header file with a bunch of useful stuff
@@ -20,6 +20,7 @@
Version History:
+ 0.01d - Change brace style because why not?
0.01c - Capture length fix and little more documentation
0.01b - Code readjustment
0.01a - New \ codes and bug fixes
@@ -260,9 +261,7 @@ static gbreContext gbre__exec_single(gbRegex *re, isize op, char const *str, isi
static gbreContext gbre__exec(gbRegex *re, isize op, char const *str, isize str_len, isize offset,
gbreCapture *captures, isize max_capture_count);
-static gbreContext
-gbre__context_no_match(isize op)
-{
+static gbreContext gbre__context_no_match(isize op) {
gbreContext c;
c.op = op;
c.offset = GBRE__NO_MATCH;
@@ -270,18 +269,14 @@ gbre__context_no_match(isize op)
}
-static gbreContext
-gbre__context_internal_failure(isize op)
-{
+static gbreContext gbre__context_internal_failure(isize op) {
gbreContext c;
c.op = op;
c.offset = GBRE__INTERNAL_FAILURE;
return c;
}
-static gbreBool
-gbre__is_hex(char const *s)
-{
+static gbreBool gbre__is_hex(char const *s) {
if ((s[0] < '0' || s[0] > '9') &&
(s[0] < 'a' || s[0] > 'f') &&
(s[0] < 'A' || s[0] > 'F')) {
@@ -295,9 +290,7 @@ gbre__is_hex(char const *s)
return GBRE_TRUE;
}
-static unsigned char
-gbre__hex_digit(char const *s)
-{
+static unsigned char gbre__hex_digit(char const *s) {
if (s[0] >= '0' && s[0] <= '9')
return (unsigned char)(s[0] - '0');
if (s[0] >= 'a' && s[0] <= 'f')
@@ -307,15 +300,11 @@ gbre__hex_digit(char const *s)
return 0;
}
-static unsigned char
-gbre__hex(char const *s)
-{
+static unsigned char gbre__hex(char const *s) {
return ((gbre__hex_digit(s) << 4) & 0xf0) | (gbre__hex_digit(s+1) & 0x0f);
}
-static isize
-gbre__strfind(char const *str, isize len, char c, isize offset)
-{
+static isize gbre__strfind(char const *str, isize len, char c, isize offset) {
if (offset < len) {
char const *found = (char const *)memchr(str+offset, c, len-offset);
if (found)
@@ -324,9 +313,7 @@ gbre__strfind(char const *str, isize len, char c, isize offset)
return -1;
}
-static gbreBool
-gbre__match_escape(char c, int code)
-{
+static gbreBool gbre__match_escape(char c, int code) {
switch (code) {
case GBRE_CODE_NULL: return c == 0;
case GBRE_CODE_WHITESPACE: return gbre__strfind(GBRE__LITERAL(GBRE__WHITESPACE), c, 0) >= 0;
@@ -350,11 +337,9 @@ gbre__match_escape(char c, int code)
}
-static gbreContext
-gbre__consume(gbRegex *re, isize op, char const *str, isize str_len, isize offset,
- gbreCapture *captures, isize max_capture_count,
- gbreBool is_greedy)
-{
+static gbreContext gbre__consume(gbRegex *re, isize op, char const *str, isize str_len, isize offset,
+ gbreCapture *captures, isize max_capture_count,
+ gbreBool is_greedy) {
gbreContext c, best_c, next_c;
c.op = op;
@@ -385,10 +370,8 @@ gbre__consume(gbRegex *re, isize op, char const *str, isize str_len, isize offse
return best_c;
}
-static gbreContext
-gbre__exec_single(gbRegex *re, isize op, char const *str, isize str_len, isize offset,
- gbreCapture *captures, isize max_capture_count)
-{
+static gbreContext gbre__exec_single(gbRegex *re, isize op, char const *str, isize str_len, isize offset,
+ gbreCapture *captures, isize max_capture_count) {
gbreContext context;
isize buffer_len;
isize matchlen;
@@ -578,10 +561,8 @@ gbre__exec_single(gbRegex *re, isize op, char const *str, isize str_len, isize o
return context;
}
-static gbreContext
-gbre__exec(gbRegex *re, isize op, char const *str, isize str_len, isize offset,
- gbreCapture *captures, isize max_capture_count)
-{
+static gbreContext gbre__exec(gbRegex *re, isize op, char const *str, isize str_len, isize offset,
+ gbreCapture *captures, isize max_capture_count) {
gbreContext c;
c.op = op;
c.offset = offset;
@@ -595,9 +576,7 @@ gbre__exec(gbRegex *re, isize op, char const *str, isize str_len, isize offset,
}
-static gbreError
-gbre__emit_ops(gbRegex *re, isize op_count, ...)
-{
+static gbreError gbre__emit_ops(gbRegex *re, isize op_count, ...) {
isize i;
va_list va;
@@ -627,9 +606,7 @@ gbre__emit_ops(gbRegex *re, isize op_count, ...)
return GBRE_ERROR_NONE;
}
-static gbreError
-gbre__emit_ops_buffer(gbRegex *re, isize op_count, unsigned char const *buffer)
-{
+static gbreError gbre__emit_ops_buffer(gbRegex *re, isize op_count, unsigned char const *buffer) {
isize i;
if (re->buf_len + op_count > re->buf_cap) {
@@ -653,9 +630,7 @@ gbre__emit_ops_buffer(gbRegex *re, isize op_count, unsigned char const *buffer)
return GBRE_ERROR_NONE;
}
-static int
-gbre__encode_espace(char code)
-{
+static int gbre__encode_espace(char code) {
switch (code) {
default: break; /* NOTE(bill): It's a normal character */
@@ -687,9 +662,7 @@ gbre__encode_espace(char code)
return code;
}
-static gbreError
-gbre__parse_group(gbRegex *re, char const *pattern, isize len, isize offset, isize *new_offset)
-{
+static gbreError gbre__parse_group(gbRegex *re, char const *pattern, isize len, isize offset, isize *new_offset) {
gbreError err = GBRE_ERROR_NONE;
unsigned char buffer[256] = {0}; /* NOTE(bill): ascii is only 7/8 bits */
isize buffer_len = 0, buffer_cap = gbre_size_of(buffer);
@@ -747,9 +720,7 @@ gbre__parse_group(gbRegex *re, char const *pattern, isize len, isize offset, isi
return GBRE_ERROR_NONE;
}
-static gbreError
-gbre__compile_quantifier(gbRegex *re, isize last_buf_len, unsigned char quantifier)
-{
+static gbreError gbre__compile_quantifier(gbRegex *re, isize last_buf_len, unsigned char quantifier) {
gbreError err;
isize move_size;
if ((re->buf[last_buf_len] == GBRE_OP_EXACT_MATCH) &&
@@ -775,9 +746,7 @@ gbre__compile_quantifier(gbRegex *re, isize last_buf_len, unsigned char quantifi
}
-static gbreError
-gbre__parse(gbRegex *re, char const *pattern, isize len, isize offset, isize level, isize *new_offset)
-{
+static gbreError gbre__parse(gbRegex *re, char const *pattern, isize len, isize offset, isize level, isize *new_offset) {
gbreError err = GBRE_ERROR_NONE;
isize last_buf_len = re->buf_len;
isize branch_begin = re->buf_len;
@@ -928,9 +897,7 @@ gbre__parse(gbRegex *re, char const *pattern, isize len, isize offset, isize lev
return GBRE_ERROR_NONE;
}
-gbreError
-gbre_compile_from_buffer(gbRegex *re, char const *pattern, isize pattern_len, void *buffer, isize buffer_len)
-{
+gbreError gbre_compile_from_buffer(gbRegex *re, char const *pattern, isize pattern_len, void *buffer, isize buffer_len) {
gbreError err;
re->capture_count = 0;
re->buf = (unsigned char *)buffer;
@@ -943,9 +910,7 @@ gbre_compile_from_buffer(gbRegex *re, char const *pattern, isize pattern_len, vo
}
#if !defined(GBRE_NO_MALLOC)
-gbreError
-gbre_compile(gbRegex *re, char const *pattern, isize len)
-{
+gbreError gbre_compile(gbRegex *re, char const *pattern, isize len) {
gbreError err;
isize cap = len+128;
isize offset = 0;
@@ -963,9 +928,7 @@ gbre_compile(gbRegex *re, char const *pattern, isize len)
return err;
}
#endif
-
-void gbre_destroy(gbRegex *re)
-{
+void gbre_destroy(gbRegex *re) {
(void)gbre_size_of(re);
#if !defined(GBRE_NO_MALLOC)
@@ -978,10 +941,7 @@ void gbre_destroy(gbRegex *re)
isize gbre_capture_count(gbRegex *re) { return re->capture_count; }
-
-gbreBool
-gbre_match(gbRegex *re, char const *str, isize len, gbreCapture *captures, isize max_capture_count)
-{
+gbreBool gbre_match(gbRegex *re, char const *str, isize len, gbreCapture *captures, isize max_capture_count) {
if (re && re->buf_len > 0) {
if (re->buf[0] == GBRE_OP_BEGINNING_OF_LINE) {
gbreContext c = gbre__exec(re, 0, str, len, 0, captures, max_capture_count);
diff --git a/gb_string.h b/gb_string.h
index b4e13ab..32ef68a 100644
--- a/gb_string.h
+++ b/gb_string.h
@@ -1,7 +1,8 @@
-/* gb_string.h - v0.95 - public domain string library - no warranty implied; use at your own risk
+/* gb_string.h - v0.95a - public domain string library - no warranty implied; use at your own risk
A Simple Dynamic Strings Library for C and C++
Version History:
+ 0.95a - Change brace style because why not?
0.95 - C90 Support
0.94 - Remove "declare anywhere"
0.93 - Fix typos and errors
@@ -123,8 +124,7 @@
#define GB_STRING_IMPLEMENTATION
#include "gb_string.h"
-int main(int argc, char **argv)
-{
+int main(int argc, char **argv) {
gbString str = gb_make_string("Hello");
gbString other_str = gb_make_string_length(", ", 2);
str = gb_append_string(str, other_str);
@@ -163,8 +163,7 @@ int main(int argc, char **argv)
#define GB_STRING_IMPLEMENTATION
#include "gb_string.h"
-int main(int argc, char **argv)
-{
+int main(int argc, char **argv) {
using namespace gb;
String str = make_string("Hello");
@@ -312,22 +311,16 @@ gb_inline void trim_string(String& str, char const *cut_set) { str = gb_trim_str
#endif /* GB_STRING_CPP */
#endif /* GB_STRING_H */
#ifdef GB_STRING_IMPLEMENTATION
-static void
-gb_set_string_length(gbString str, gbUsize len)
-{
+static void gb_set_string_length(gbString str, gbUsize len) {
GB_STRING_HEADER(str)->len = len;
}
-static void
-gb_set_string_capacity(gbString str, gbUsize cap)
-{
+static void gb_set_string_capacity(gbString str, gbUsize cap) {
GB_STRING_HEADER(str)->cap = cap;
}
-gbString
-gb_make_string_length(void const *init_str, gbUsize len)
-{
+gbString gb_make_string_length(void const *init_str, gbUsize len) {
gbString str;
gbStringHeader *header;
gbUsize header_size = sizeof(gbStringHeader);
@@ -349,58 +342,43 @@ gb_make_string_length(void const *init_str, gbUsize len)
return str;
}
-gbString
-gb_make_string(char const *str)
-{
+gbString gb_make_string(char const *str) {
gbUsize len = str ? strlen(str) : 0;
return gb_make_string_length(str, len);
}
-void
-gb_free_string(gbString str)
-{
+void gb_free_string(gbString str) {
if (str == GB_NULLPTR)
return;
GB_FREE((gbStringHeader *)str - 1);
}
-gbString
-gb_duplicate_string(gbString const str)
-{
+gbString gb_duplicate_string(gbString const str) {
return gb_make_string_length(str, gb_string_length(str));
}
-gbUsize
-gb_string_length(gbString const str)
-{
+gbUsize gb_string_length(gbString const str) {
return GB_STRING_HEADER(str)->len;
}
-gbUsize
-gb_string_capacity(gbString const str)
-{
+gbUsize gb_string_capacity(gbString const str) {
return GB_STRING_HEADER(str)->cap;
}
-gbUsize
-gb_string_available_space(gbString const str)
-{
+gbUsize gb_string_available_space(gbString const str) {
gbStringHeader *h = GB_STRING_HEADER(str);
if (h->cap > h->len)
return h->cap - h->len;
return 0;
}
-void
-gb_clear_string(gbString str)
-{
+void gb_clear_string(gbString str) {
gb_set_string_length(str, 0);
str[0] = '\0';
}
-gbString gb_append_string_length(gbString str, void const *other, gbUsize other_len)
-{
+gbString gb_append_string_length(gbString str, void const *other, gbUsize other_len) {
gbUsize curr_len = gb_string_length(str);
str = gb_string_make_space_for(str, other_len);
@@ -414,18 +392,15 @@ gbString gb_append_string_length(gbString str, void const *other, gbUsize other_
return str;
}
-gbString gb_append_string(gbString str, gbString const other)
-{
+gbString gb_append_string(gbString str, gbString const other) {
return gb_append_string_length(str, other, gb_string_length(other));
}
-gbString gb_append_cstring(gbString str, char const *other)
-{
+gbString gb_append_cstring(gbString str, char const *other) {
return gb_append_string_length(str, other, strlen(other));
}
-gbString gb_set_string(gbString str, char const *cstr)
-{
+gbString gb_set_string(gbString str, char const *cstr) {
gbUsize len = strlen(cstr);
if (gb_string_capacity(str) < len) {
str = gb_string_make_space_for(str, len - gb_string_length(str));
@@ -440,8 +415,7 @@ gbString gb_set_string(gbString str, char const *cstr)
return str;
}
-static gb_inline void *gb__string_realloc(void *ptr, gbUsize old_size, gbUsize new_size)
-{
+static gb_inline void *gb__string_realloc(void *ptr, gbUsize old_size, gbUsize new_size) {
void *new_ptr;
if (!ptr)
return GB_ALLOC(new_size);
@@ -463,8 +437,7 @@ static gb_inline void *gb__string_realloc(void *ptr, gbUsize old_size, gbUsize n
return new_ptr;
}
-gbString gb_string_make_space_for(gbString str, gbUsize add_len)
-{
+gbString gb_string_make_space_for(gbString str, gbUsize add_len) {
gbUsize len = gb_string_length(str);
gbUsize new_len = len + add_len;
void *ptr, *new_ptr;
@@ -489,14 +462,12 @@ gbString gb_string_make_space_for(gbString str, gbUsize add_len)
return str;
}
-gbUsize gb_string_allocation_size(gbString const s)
-{
+gbUsize gb_string_allocation_size(gbString const s) {
gbUsize cap = gb_string_capacity(s);
return sizeof(gbStringHeader) + cap;
}
-gbBool gb_strings_are_equal(gbString const lhs, gbString const rhs)
-{
+gbBool gb_strings_are_equal(gbString const lhs, gbString const rhs) {
gbUsize lhs_len, rhs_len, i;
lhs_len = gb_string_length(lhs);
rhs_len = gb_string_length(rhs);
@@ -511,8 +482,7 @@ gbBool gb_strings_are_equal(gbString const lhs, gbString const rhs)
return GB_TRUE;
}
-gbString gb_trim_string(gbString str, char const *cut_set)
-{
+gbString gb_trim_string(gbString str, char const *cut_set) {
char *start, *end, *start_pos, *end_pos;
gbUsize len;