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