diff --git a/src/base.h b/src/base.h index 47a6eca..a64ab1f 100644 --- a/src/base.h +++ b/src/base.h @@ -1,4 +1,6 @@ -#pragma once +#ifndef ORCA_BASE_H +#define ORCA_BASE_H + #include #include #include @@ -60,23 +62,27 @@ #define staticni ORCA_NOINLINE static +#ifdef __cplusplus +extern "C" { +#endif -//---------------------------------------------------------------------------------------- -// Types -//---------------------------------------------------------------------------------------- -typedef uint8_t U8; -typedef int8_t I8; -typedef uint16_t U16; -typedef int16_t I16; -typedef uint32_t U32; -typedef int32_t I32; -typedef uint64_t U64; -typedef int64_t I64; -typedef size_t Usz; -typedef ssize_t Isz; - -typedef char Glyph; -typedef U8 Mark; + + //---------------------------------------------------------------------------------------- + // Types + //---------------------------------------------------------------------------------------- + typedef uint8_t U8; + typedef int8_t I8; + typedef uint16_t U16; + typedef int16_t I16; + typedef uint32_t U32; + typedef int32_t I32; + typedef uint64_t U64; + typedef int64_t I64; + typedef size_t Usz; + typedef ssize_t Isz; + + typedef char Glyph; + typedef U8 Mark; //---------------------------------------------------------------------------------------- // Constants @@ -84,91 +90,95 @@ typedef U8 Mark; #define ORCA_Y_MAX UINT16_MAX #define ORCA_X_MAX UINT16_MAX -enum -{ - Hud_height = 2 -}; - - - - -//---------------------------------------------------------------------------------------- -// Utils -//---------------------------------------------------------------------------------------- - -ORCA_FORCEINLINE static Usz orca_round_up_power2(Usz x) -{ - assert(x <= SIZE_MAX / 2 + 1); - x -= 1; - x |= x >> 1; - x |= x >> 2; - x |= x >> 4; - x |= x >> 8; - x |= x >> 16; + enum + { + Hud_height = 2 + }; + + + //---------------------------------------------------------------------------------------- + // Utils + //---------------------------------------------------------------------------------------- + + ORCA_FORCEINLINE static Usz orca_round_up_power2(Usz x) + { + assert(x <= SIZE_MAX / 2 + 1); + x -= 1; + x |= x >> 1; + x |= x >> 2; + x |= x >> 4; + x |= x >> 8; + x |= x >> 16; #if SIZE_MAX > UINT32_MAX - x |= x >> 32; + x |= x >> 32; #endif - return x + 1; -} + return x + 1; + } -ORCA_OK_IF_UNUSED -static bool orca_is_valid_glyph(Glyph c) -{ - if (c >= '0' && c <= '9') - return true; - if (c >= 'A' && c <= 'Z') - return true; - if (c >= 'a' && c <= 'z') - return true; - switch (c) { - case '!': - case '#': - case '%': - case '*': - case '.': - case ':': - case ';': - case '=': - case '?': + ORCA_OK_IF_UNUSED + static bool orca_is_valid_glyph(Glyph c) + { + if (c >= '0' && c <= '9') + return true; + if (c >= 'A' && c <= 'Z') return true; + if (c >= 'a' && c <= 'z') + return true; + switch (c) { + case '!': + case '#': + case '%': + case '*': + case '.': + case ':': + case ';': + case '=': + case '?': + return true; + } + return false; } - return false; -} -static ORCA_FORCEINLINE double ms_to_sec(double ms) -{ - return ms / 1000.0; -} + static ORCA_FORCEINLINE double ms_to_sec(double ms) + { + return ms / 1000.0; + } -staticni bool str_to_int(char const *str, int *out) -{ - int a; - int res = sscanf(str, "%d", &a); - if (res != 1) - return false; - *out = a; - return true; -} - -// Reads something like '5x3' or '5'. Writes the same value to both outputs if -// only one is specified. Returns false on error. -staticni bool read_nxn_or_n(char const *str, int *out_a, int *out_b) -{ - int a, b; - int res = sscanf(str, "%dx%d", &a, &b); - if (res == EOF) - return false; - if (res == 1) { - *out_a = a; - *out_b = a; + staticni bool str_to_int(char const *str, int *out) + { + int a; + int res = sscanf(str, "%d", &a); + if (res != 1) + return false; + *out = a; return true; } - if (res == 2) { - *out_a = a; - *out_b = b; - return true; + + // Reads something like '5x3' or '5'. Writes the same value to both outputs if + // only one is specified. Returns false on error. + staticni bool read_nxn_or_n(char const *str, int *out_a, int *out_b) + { + int a, b; + int res = sscanf(str, "%dx%d", &a, &b); + if (res == EOF) + return false; + if (res == 1) { + *out_a = a; + *out_b = a; + return true; + } + if (res == 2) { + *out_a = a; + *out_b = b; + return true; + } + return false; } - return false; -} +#ifdef __cplusplus +}; +#endif + + +#endif //ORCA_BASE_H