remove most common types from base core
This commit is contained in:
parent
4821bd1e85
commit
06e69945c9
1
build.c
1
build.c
@ -871,7 +871,6 @@ void OnBuild(StringList cli_args)
|
||||
D_TagListAppend(&perm, &src_files, D_TagFromPath(&perm, Lit("src/asset_cache/asset_cache.c"), D_TagKind_File));
|
||||
D_TagListAppend(&perm, &src_files, D_TagFromPath(&perm, Lit("src/mixer/mixer.c"), D_TagKind_File));
|
||||
D_TagListAppend(&perm, &src_files, D_TagFromPath(&perm, Lit("src/settings/settings.c"), D_TagKind_File));
|
||||
D_TagListAppend(&perm, &src_files, D_TagFromPath(&perm, Lit("src/space/space.c"), D_TagKind_File));
|
||||
D_TagListAppend(&perm, &src_files, D_TagFromPath(&perm, Lit("src/collider/collider.c"), D_TagKind_File));
|
||||
D_TagListAppend(&perm, &src_files, D_TagFromPath(&perm, Lit("src/app/app.c"), D_TagKind_File));
|
||||
D_TagListAppend(&perm, &src_files, D_TagFromPath(&perm, Lit("src/playback/playback.c"), D_TagKind_File));
|
||||
|
||||
@ -27,16 +27,16 @@
|
||||
#include "base_intrinsics.h"
|
||||
#include "base_atomic.h"
|
||||
#include "base_fiber.h"
|
||||
#include "base_gstat.h"
|
||||
#include "base_memory.h"
|
||||
#include "base_arena.h"
|
||||
#include "base_uid.h"
|
||||
#include "base_string.h"
|
||||
#include "base_uni.h"
|
||||
#include "base_gstat.h"
|
||||
#include "base_buddy.h"
|
||||
#include "base_math.h"
|
||||
#include "base_rand.h"
|
||||
#include "base_string.h"
|
||||
#include "base_bitbuff.h"
|
||||
#include "base_uid.h"
|
||||
#include "base_uni.h"
|
||||
#include "base_util.h"
|
||||
#include "base_incbin.h"
|
||||
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
/* ========================== *
|
||||
* Arena
|
||||
* ========================== */
|
||||
|
||||
#define ARENA_HEADER_SIZE 256
|
||||
#define ARENA_BLOCK_SIZE 16384
|
||||
|
||||
@ -14,6 +18,15 @@
|
||||
* Equivalent to arena_push but without actually allocating anything or modifying the arena. */
|
||||
#define arena_push_dry(a, type) (type *)(_arena_push_dry((a), alignof(type)))
|
||||
|
||||
struct arena {
|
||||
u64 pos;
|
||||
u64 committed;
|
||||
u64 reserved;
|
||||
#if RTC
|
||||
b32 readonly;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct arena_temp {
|
||||
struct arena *arena;
|
||||
u64 start_pos;
|
||||
@ -102,14 +115,6 @@ INLINE void arena_reset(struct arena *arena)
|
||||
arena_pop_to(arena, 0);
|
||||
}
|
||||
|
||||
INLINE struct string arena_to_string(struct arena *arena)
|
||||
{
|
||||
struct string b;
|
||||
b.text = arena_base(arena);
|
||||
b.len = arena->pos;
|
||||
return b;
|
||||
}
|
||||
|
||||
INLINE void *_arena_push_dry(struct arena *arena, u64 align)
|
||||
{
|
||||
u64 aligned_start_pos = (arena->pos + (align - 1));
|
||||
|
||||
@ -1,3 +1,57 @@
|
||||
/* ========================== *
|
||||
* Atomic types
|
||||
* ========================== */
|
||||
|
||||
/* NOTE: Must be aligned to 32 bit boundary by user */
|
||||
struct atomic8 {
|
||||
volatile i8 _v;
|
||||
};
|
||||
|
||||
/* NOTE: Must be aligned to 32 bit boundary by user */
|
||||
struct atomic16 {
|
||||
volatile i16 _v;
|
||||
};
|
||||
|
||||
struct atomic32 {
|
||||
volatile i32 _v;
|
||||
};
|
||||
|
||||
struct atomic64 {
|
||||
volatile i64 _v;
|
||||
};
|
||||
|
||||
/* ========================== *
|
||||
* Cache-line isolated atomic types
|
||||
* ========================== */
|
||||
|
||||
struct alignas(64) atomic8_padded {
|
||||
struct atomic8 v;
|
||||
u8 _pad[60];
|
||||
};
|
||||
STATIC_ASSERT(sizeof(struct atomic8_padded) == 64 && alignof(struct atomic8_padded) == 64);
|
||||
|
||||
struct alignas(64) atomic16_padded {
|
||||
struct atomic16 v;
|
||||
u8 _pad[60];
|
||||
};
|
||||
STATIC_ASSERT(sizeof(struct atomic16_padded) == 64 && alignof(struct atomic16_padded) == 64);
|
||||
|
||||
struct alignas(64) atomic32_padded {
|
||||
struct atomic32 v;
|
||||
u8 _pad[60];
|
||||
};
|
||||
STATIC_ASSERT(sizeof(struct atomic32_padded) == 64 && alignof(struct atomic32_padded) == 64);
|
||||
|
||||
struct alignas(64) atomic64_padded {
|
||||
struct atomic64 v;
|
||||
u8 _pad[56];
|
||||
};
|
||||
STATIC_ASSERT(sizeof(struct atomic64_padded) == 64 && alignof(struct atomic64_padded) == 64);
|
||||
|
||||
/* ========================== *
|
||||
* Atomics impl
|
||||
* ========================== */
|
||||
|
||||
#if PLATFORM_WINDOWS
|
||||
|
||||
FORCE_INLINE i8 atomic8_fetch(struct atomic8 *x) { return (i8)_InterlockedCompareExchange8((char *)&x->_v, 0, 0); }
|
||||
|
||||
@ -365,95 +365,10 @@ GLOBAL const f64 *_f64_nan = (f64 *)&_f64_nan_u64;
|
||||
#define F32_IS_NAN(x) (x != x)
|
||||
#define F64_IS_NAN(x) (x != x)
|
||||
|
||||
#define PI ((f32)3.14159265358979323846)
|
||||
#define TAU ((f32)6.28318530717958647693)
|
||||
|
||||
/* ========================== *
|
||||
* Atomics
|
||||
* ========================== */
|
||||
|
||||
/* NOTE: Must be aligned to 32 bit boundary by user */
|
||||
struct atomic8 {
|
||||
volatile i8 _v;
|
||||
};
|
||||
|
||||
/* NOTE: Must be aligned to 32 bit boundary by user */
|
||||
struct atomic16 {
|
||||
volatile i16 _v;
|
||||
};
|
||||
|
||||
struct atomic32 {
|
||||
volatile i32 _v;
|
||||
};
|
||||
|
||||
struct atomic64 {
|
||||
volatile i64 _v;
|
||||
};
|
||||
|
||||
/* ========================== *
|
||||
* Cache-line isolated atomics
|
||||
* ========================== */
|
||||
|
||||
struct alignas(64) atomic8_padded {
|
||||
struct atomic8 v;
|
||||
u8 _pad[60];
|
||||
};
|
||||
STATIC_ASSERT(sizeof(struct atomic8_padded) == 64 && alignof(struct atomic8_padded) == 64);
|
||||
|
||||
struct alignas(64) atomic16_padded {
|
||||
struct atomic16 v;
|
||||
u8 _pad[60];
|
||||
};
|
||||
STATIC_ASSERT(sizeof(struct atomic16_padded) == 64 && alignof(struct atomic16_padded) == 64);
|
||||
|
||||
struct alignas(64) atomic32_padded {
|
||||
struct atomic32 v;
|
||||
u8 _pad[60];
|
||||
};
|
||||
STATIC_ASSERT(sizeof(struct atomic32_padded) == 64 && alignof(struct atomic32_padded) == 64);
|
||||
|
||||
struct alignas(64) atomic64_padded {
|
||||
struct atomic64 v;
|
||||
u8 _pad[56];
|
||||
};
|
||||
STATIC_ASSERT(sizeof(struct atomic64_padded) == 64 && alignof(struct atomic64_padded) == 64);
|
||||
|
||||
/* ========================== *
|
||||
* Common structs
|
||||
* ========================== */
|
||||
|
||||
struct arena {
|
||||
u64 pos;
|
||||
u64 committed;
|
||||
u64 reserved;
|
||||
#if RTC
|
||||
b32 readonly;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct string {
|
||||
u64 len;
|
||||
u8 *text;
|
||||
};
|
||||
|
||||
struct string16 {
|
||||
u64 len;
|
||||
u16 *text;
|
||||
};
|
||||
|
||||
struct string32 {
|
||||
u64 len;
|
||||
u32 *text;
|
||||
};
|
||||
|
||||
#define UID(hi64, lo64) ((struct uid) { .hi = (hi64), .lo = (lo64) })
|
||||
struct uid {
|
||||
u64 hi;
|
||||
u64 lo;
|
||||
};
|
||||
INLINE b32 uid_eq(struct uid a, struct uid b) { return a.hi == b.hi && a.lo == b.lo; }
|
||||
INLINE b32 uid_is_zero(struct uid v) { return v.hi == 0 && v.lo == 0; }
|
||||
|
||||
struct image_rgba {
|
||||
u32 width;
|
||||
u32 height;
|
||||
@ -465,192 +380,6 @@ struct pcm {
|
||||
i16 *samples;
|
||||
};
|
||||
|
||||
struct sim_client_handle {
|
||||
u32 idx;
|
||||
u32 gen;
|
||||
};
|
||||
|
||||
struct sim_ent_id {
|
||||
struct uid uid;
|
||||
};
|
||||
|
||||
struct space_entry_handle {
|
||||
u64 idx;
|
||||
u64 gen;
|
||||
};
|
||||
|
||||
struct host_channel_id {
|
||||
u32 gen;
|
||||
u32 idx;
|
||||
};
|
||||
|
||||
/* ========================== *
|
||||
* Tag structs
|
||||
* ========================== */
|
||||
|
||||
struct sprite_tag {
|
||||
u64 hash;
|
||||
struct string path;
|
||||
};
|
||||
|
||||
/* ========================== *
|
||||
* String utils
|
||||
* ========================== */
|
||||
|
||||
/* Expand C string literal with size for string initialization */
|
||||
#define LIT(cstr_lit) CPPCOMPAT_INITLIST_TYPE(struct string) { (sizeof((cstr_lit)) - 1), (u8 *)(cstr_lit) }
|
||||
|
||||
/* Same as `STR`, but works with static variable initialization */
|
||||
#define LIT_NOCAST(cstr_lit) { .len = (sizeof((cstr_lit)) - 1), .text = (u8 *)(cstr_lit) }
|
||||
|
||||
#define STRING(size, data) (CPPCOMPAT_INITLIST_TYPE(struct string) { (size), (data) })
|
||||
|
||||
#define STRING_FROM_POINTERS(p0, p1) (CPPCOMPAT_INITLIST_TYPE(struct string) { (u8 *)(p1) - (u8 *)(p0), (u8 *)p0 })
|
||||
|
||||
#define STRING_FROM_STRUCT(ptr) (CPPCOMPAT_INITLIST_TYPE(struct string) { sizeof(*(ptr)), (u8 *)(ptr) })
|
||||
|
||||
#define STRING_FROM_ARENA(arena) (STRING((arena)->pos, arena_base(arena)))
|
||||
|
||||
/* String from static array */
|
||||
#define STRING_FROM_ARRAY(a) \
|
||||
( \
|
||||
/* Must be array */ \
|
||||
ASSERT(IS_ARRAY(a)), \
|
||||
((struct string) { .len = sizeof(a), .text = (u8 *)(a) }) \
|
||||
)
|
||||
|
||||
/* ========================== *
|
||||
* Math types
|
||||
* ========================== */
|
||||
|
||||
#define V2(x, y) CPPCOMPAT_INITLIST_TYPE(struct v2) { (x), (y) }
|
||||
#define V2_FROM_V2I32(v) V2((v).x, (v).y)
|
||||
struct v2 {
|
||||
f32 x, y;
|
||||
};
|
||||
|
||||
struct v2_array {
|
||||
struct v2 *points;
|
||||
u64 count;
|
||||
};
|
||||
|
||||
#define V3(x, y, z) ((struct v3) { (x), (y), (z) })
|
||||
struct v3 {
|
||||
f32 x, y, z;
|
||||
};
|
||||
|
||||
struct v3_array {
|
||||
struct v3 *points;
|
||||
u64 count;
|
||||
};
|
||||
|
||||
#define V4(x, y, z, w) ((struct v4) { (x), (y), (z), (w) })
|
||||
struct v4 {
|
||||
f32 x, y, z, w;
|
||||
};
|
||||
|
||||
struct v4_array {
|
||||
struct v4 *points;
|
||||
u64 count;
|
||||
};
|
||||
|
||||
#define V2I32(x, y) CPPCOMPAT_INITLIST_TYPE(struct v2i32) { (x), (y) }
|
||||
struct v2i32 {
|
||||
i32 x, y;
|
||||
};
|
||||
|
||||
#define V3I32(x, y, z) CPPCOMPAT_INITLIST_TYPE(struct v3i32) { (x), (y), (z) }
|
||||
struct v3i32 {
|
||||
i32 x, y, z;
|
||||
};
|
||||
|
||||
struct xform {
|
||||
struct v2 bx; /* X basis vector (x axis) */
|
||||
struct v2 by; /* Y basis vector (y axis)*/
|
||||
struct v2 og; /* Translation vector (origin) */
|
||||
};
|
||||
|
||||
struct mat4x4 {
|
||||
union {
|
||||
struct { struct v4 bx, by, bz, bw; };
|
||||
f32 e[4][4];
|
||||
};
|
||||
};
|
||||
|
||||
#define RECT(_x, _y, _width, _height) (struct rect) { .x = (_x), .y = (_y), .width = (_width), .height = (_height) }
|
||||
#define RECT_FROM_V2(_pos, _size) (struct rect) { .pos = (_pos), .size = (_size) }
|
||||
struct rect {
|
||||
union {
|
||||
struct { f32 x, y, width, height; };
|
||||
struct { struct v2 pos, size; };
|
||||
};
|
||||
};
|
||||
|
||||
INLINE b32 rect_eq(struct rect r1, struct rect r2) { return r1.x == r2.x && r1.y == r2.y && r1.width == r2.width && r1.height == r2.height; }
|
||||
|
||||
struct aabb {
|
||||
struct v2 p0, p1;
|
||||
};
|
||||
|
||||
/* Values expected to be normalized 0.0 -> 1.0 */
|
||||
#define CLIP_ALL ((struct clip_rect) { { 0.0f, 0.0f }, { 1.0f, 1.0f } })
|
||||
struct clip_rect {
|
||||
struct v2 p0, p1;
|
||||
};
|
||||
|
||||
#define QUAD_UNIT_SQUARE (struct quad) { .p0 = V2(0, 0), .p1 = V2(0, 1), .p2 = V2(1, 1), .p3 = V2(1, 0) }
|
||||
#define QUAD_UNIT_SQUARE_CENTERED (struct quad) { .p0 = V2(-0.5f, -0.5f), .p1 = V2(0.5f, -0.5f), .p2 = V2(0.5f, 0.5f), .p3 = V2(-0.5f, 0.5f) }
|
||||
struct quad {
|
||||
union {
|
||||
struct { struct v2 p0, p1, p2, p3; };
|
||||
struct { struct v2 e[4]; };
|
||||
};
|
||||
};
|
||||
|
||||
/* (T)ranslation, (R)otation, (S)cale */
|
||||
#define TRS(...) ((struct trs) { .t = V2(0,0), .s = V2(1, 1), .r = 0, __VA_ARGS__ })
|
||||
struct trs {
|
||||
struct v2 t;
|
||||
struct v2 s;
|
||||
f32 r;
|
||||
};
|
||||
|
||||
/* ========================== *
|
||||
* Collider types
|
||||
* ========================== */
|
||||
|
||||
struct collider_shape {
|
||||
struct v2 points[8];
|
||||
u32 count;
|
||||
f32 radius;
|
||||
};
|
||||
|
||||
/* ========================== *
|
||||
* Common utilities
|
||||
* ========================== */
|
||||
|
||||
INLINE u8 min_u8(u8 a, u8 b) { return a <= b ? a : b; }
|
||||
INLINE u8 max_u8(u8 a, u8 b) { return a >= b ? a : b; }
|
||||
INLINE u32 min_u32(u32 a, u32 b) { return a <= b ? a : b; }
|
||||
INLINE u32 max_u32(u32 a, u32 b) { return a >= b ? a : b; }
|
||||
INLINE u64 min_u64(u64 a, u64 b) { return a <= b ? a : b; }
|
||||
INLINE u64 max_u64(u64 a, u64 b) { return a >= b ? a : b; }
|
||||
INLINE i32 min_i32(i32 a, i32 b) { return a <= b ? a : b; }
|
||||
INLINE i32 max_i32(i32 a, i32 b) { return a >= b ? a : b; }
|
||||
INLINE i64 min_i64(i64 a, i64 b) { return a <= b ? a : b; }
|
||||
INLINE i64 max_i64(i64 a, i64 b) { return a >= b ? a : b; }
|
||||
INLINE f32 min_f32(f32 a, f32 b) { return a <= b ? a : b; }
|
||||
INLINE f32 max_f32(f32 a, f32 b) { return a >= b ? a : b; }
|
||||
INLINE f64 min_f64(f64 a, f64 b) { return a <= b ? a : b; }
|
||||
INLINE f64 max_f64(f64 a, f64 b) { return a >= b ? a : b; }
|
||||
|
||||
INLINE u32 clamp_u32(u32 v, u32 min, u32 max) { return v < min ? min : v > max ? max : v; }
|
||||
INLINE u64 clamp_u64(u64 v, u64 min, u64 max) { return v < min ? min : v > max ? max : v; }
|
||||
INLINE i32 clamp_i32(i32 v, i32 min, i32 max) { return v < min ? min : v > max ? max : v; }
|
||||
INLINE i64 clamp_i64(i64 v, i64 min, i64 max) { return v < min ? min : v > max ? max : v; }
|
||||
INLINE f32 clamp_f32(f32 v, f32 min, f32 max) { return v < min ? min : v > max ? max : v; }
|
||||
INLINE f64 clamp_f64(f64 v, f64 min, f64 max) { return v < min ? min : v > max ? max : v; }
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1,6 +1,129 @@
|
||||
/* Math functions are default 32 bit (f32, i32, etc) unless specified */
|
||||
|
||||
INLINE f32 math_sqrt(f32 x);
|
||||
#define PI ((f32)3.14159265358979323846)
|
||||
#define TAU ((f32)6.28318530717958647693)
|
||||
|
||||
/* ========================== *
|
||||
* Math types
|
||||
* ========================== */
|
||||
|
||||
#define V2(x, y) CPPCOMPAT_INITLIST_TYPE(struct v2) { (x), (y) }
|
||||
#define V2_FROM_V2I32(v) V2((v).x, (v).y)
|
||||
struct v2 {
|
||||
f32 x, y;
|
||||
};
|
||||
|
||||
struct v2_array {
|
||||
struct v2 *points;
|
||||
u64 count;
|
||||
};
|
||||
|
||||
#define V3(x, y, z) ((struct v3) { (x), (y), (z) })
|
||||
struct v3 {
|
||||
f32 x, y, z;
|
||||
};
|
||||
|
||||
struct v3_array {
|
||||
struct v3 *points;
|
||||
u64 count;
|
||||
};
|
||||
|
||||
#define V4(x, y, z, w) ((struct v4) { (x), (y), (z), (w) })
|
||||
struct v4 {
|
||||
f32 x, y, z, w;
|
||||
};
|
||||
|
||||
struct v4_array {
|
||||
struct v4 *points;
|
||||
u64 count;
|
||||
};
|
||||
|
||||
#define V2I32(x, y) CPPCOMPAT_INITLIST_TYPE(struct v2i32) { (x), (y) }
|
||||
struct v2i32 {
|
||||
i32 x, y;
|
||||
};
|
||||
|
||||
#define V3I32(x, y, z) CPPCOMPAT_INITLIST_TYPE(struct v3i32) { (x), (y), (z) }
|
||||
struct v3i32 {
|
||||
i32 x, y, z;
|
||||
};
|
||||
|
||||
struct xform {
|
||||
struct v2 bx; /* X basis vector (x axis) */
|
||||
struct v2 by; /* Y basis vector (y axis)*/
|
||||
struct v2 og; /* Translation vector (origin) */
|
||||
};
|
||||
|
||||
struct mat4x4 {
|
||||
union {
|
||||
struct { struct v4 bx, by, bz, bw; };
|
||||
f32 e[4][4];
|
||||
};
|
||||
};
|
||||
|
||||
#define RECT(_x, _y, _width, _height) (struct rect) { .x = (_x), .y = (_y), .width = (_width), .height = (_height) }
|
||||
#define RECT_FROM_V2(_pos, _size) (struct rect) { .pos = (_pos), .size = (_size) }
|
||||
struct rect {
|
||||
union {
|
||||
struct { f32 x, y, width, height; };
|
||||
struct { struct v2 pos, size; };
|
||||
};
|
||||
};
|
||||
|
||||
INLINE b32 rect_eq(struct rect r1, struct rect r2) { return r1.x == r2.x && r1.y == r2.y && r1.width == r2.width && r1.height == r2.height; }
|
||||
|
||||
struct aabb {
|
||||
struct v2 p0, p1;
|
||||
};
|
||||
|
||||
/* Values expected to be normalized 0.0 -> 1.0 */
|
||||
#define CLIP_ALL ((struct clip_rect) { { 0.0f, 0.0f }, { 1.0f, 1.0f } })
|
||||
struct clip_rect {
|
||||
struct v2 p0, p1;
|
||||
};
|
||||
|
||||
#define QUAD_UNIT_SQUARE (struct quad) { .p0 = V2(0, 0), .p1 = V2(0, 1), .p2 = V2(1, 1), .p3 = V2(1, 0) }
|
||||
#define QUAD_UNIT_SQUARE_CENTERED (struct quad) { .p0 = V2(-0.5f, -0.5f), .p1 = V2(0.5f, -0.5f), .p2 = V2(0.5f, 0.5f), .p3 = V2(-0.5f, 0.5f) }
|
||||
struct quad {
|
||||
union {
|
||||
struct { struct v2 p0, p1, p2, p3; };
|
||||
struct { struct v2 e[4]; };
|
||||
};
|
||||
};
|
||||
|
||||
/* (T)ranslation, (R)otation, (S)cale */
|
||||
#define TRS(...) ((struct trs) { .t = V2(0,0), .s = V2(1, 1), .r = 0, __VA_ARGS__ })
|
||||
struct trs {
|
||||
struct v2 t;
|
||||
struct v2 s;
|
||||
f32 r;
|
||||
};
|
||||
|
||||
/* ========================== *
|
||||
* Clamping
|
||||
* ========================== */
|
||||
|
||||
INLINE u8 min_u8(u8 a, u8 b) { return a <= b ? a : b; }
|
||||
INLINE u8 max_u8(u8 a, u8 b) { return a >= b ? a : b; }
|
||||
INLINE u32 min_u32(u32 a, u32 b) { return a <= b ? a : b; }
|
||||
INLINE u32 max_u32(u32 a, u32 b) { return a >= b ? a : b; }
|
||||
INLINE u64 min_u64(u64 a, u64 b) { return a <= b ? a : b; }
|
||||
INLINE u64 max_u64(u64 a, u64 b) { return a >= b ? a : b; }
|
||||
INLINE i32 min_i32(i32 a, i32 b) { return a <= b ? a : b; }
|
||||
INLINE i32 max_i32(i32 a, i32 b) { return a >= b ? a : b; }
|
||||
INLINE i64 min_i64(i64 a, i64 b) { return a <= b ? a : b; }
|
||||
INLINE i64 max_i64(i64 a, i64 b) { return a >= b ? a : b; }
|
||||
INLINE f32 min_f32(f32 a, f32 b) { return a <= b ? a : b; }
|
||||
INLINE f32 max_f32(f32 a, f32 b) { return a >= b ? a : b; }
|
||||
INLINE f64 min_f64(f64 a, f64 b) { return a <= b ? a : b; }
|
||||
INLINE f64 max_f64(f64 a, f64 b) { return a >= b ? a : b; }
|
||||
|
||||
INLINE u32 clamp_u32(u32 v, u32 min, u32 max) { return v < min ? min : v > max ? max : v; }
|
||||
INLINE u64 clamp_u64(u64 v, u64 min, u64 max) { return v < min ? min : v > max ? max : v; }
|
||||
INLINE i32 clamp_i32(i32 v, i32 min, i32 max) { return v < min ? min : v > max ? max : v; }
|
||||
INLINE i64 clamp_i64(i64 v, i64 min, i64 max) { return v < min ? min : v > max ? max : v; }
|
||||
INLINE f32 clamp_f32(f32 v, f32 min, f32 max) { return v < min ? min : v > max ? max : v; }
|
||||
INLINE f64 clamp_f64(f64 v, f64 min, f64 max) { return v < min ? min : v > max ? max : v; }
|
||||
|
||||
/* ========================== *
|
||||
* Float rounding
|
||||
@ -1241,22 +1364,6 @@ INLINE struct quad quad_floor(struct quad quad)
|
||||
return res;
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Collider
|
||||
* ========================== */
|
||||
|
||||
INLINE struct collider_shape collider_from_quad(struct quad quad)
|
||||
{
|
||||
struct collider_shape res;
|
||||
res.points[0] = quad.p0;
|
||||
res.points[1] = quad.p1;
|
||||
res.points[2] = quad.p2;
|
||||
res.points[3] = quad.p3;
|
||||
res.count = 4;
|
||||
res.radius = 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Convex polygon
|
||||
* ========================== */
|
||||
|
||||
@ -1,8 +1,50 @@
|
||||
struct string {
|
||||
u64 len;
|
||||
u8 *text;
|
||||
};
|
||||
|
||||
struct string16 {
|
||||
u64 len;
|
||||
u16 *text;
|
||||
};
|
||||
|
||||
struct string32 {
|
||||
u64 len;
|
||||
u32 *text;
|
||||
};
|
||||
|
||||
struct string_array {
|
||||
u64 count;
|
||||
struct string *strings;
|
||||
};
|
||||
|
||||
/* ========================== *
|
||||
* String utils
|
||||
* ========================== */
|
||||
|
||||
/* Expand C string literal with size for string initialization */
|
||||
#define LIT(cstr_lit) CPPCOMPAT_INITLIST_TYPE(struct string) { (sizeof((cstr_lit)) - 1), (u8 *)(cstr_lit) }
|
||||
|
||||
/* Same as `STR`, but works with static variable initialization */
|
||||
#define LIT_NOCAST(cstr_lit) { .len = (sizeof((cstr_lit)) - 1), .text = (u8 *)(cstr_lit) }
|
||||
|
||||
#define STRING(size, data) (CPPCOMPAT_INITLIST_TYPE(struct string) { (size), (data) })
|
||||
|
||||
#define STRING_FROM_POINTERS(p0, p1) (CPPCOMPAT_INITLIST_TYPE(struct string) { (u8 *)(p1) - (u8 *)(p0), (u8 *)p0 })
|
||||
|
||||
#define STRING_FROM_STRUCT(ptr) (CPPCOMPAT_INITLIST_TYPE(struct string) { sizeof(*(ptr)), (u8 *)(ptr) })
|
||||
|
||||
#define STRING_FROM_ARENA(arena) (STRING((arena)->pos, arena_base(arena)))
|
||||
|
||||
/* String from static array */
|
||||
#define STRING_FROM_ARRAY(a) \
|
||||
( \
|
||||
/* Must be array */ \
|
||||
ASSERT(IS_ARRAY(a)), \
|
||||
((struct string) { .len = sizeof(a), .text = (u8 *)(a) }) \
|
||||
)
|
||||
|
||||
|
||||
/* ========================== *
|
||||
* Conversion
|
||||
* ========================== */
|
||||
|
||||
@ -1,3 +1,13 @@
|
||||
#define UID(hi64, lo64) ((struct uid) { .hi = (hi64), .lo = (lo64) })
|
||||
struct uid {
|
||||
u64 hi;
|
||||
u64 lo;
|
||||
};
|
||||
|
||||
INLINE b32 uid_eq(struct uid a, struct uid b) { return a.hi == b.hi && a.lo == b.lo; }
|
||||
|
||||
INLINE b32 uid_is_zero(struct uid v) { return v.hi == 0 && v.lo == 0; }
|
||||
|
||||
struct uid uid_true_rand(void);
|
||||
|
||||
struct uid uid_combine(struct uid a, struct uid b);
|
||||
|
||||
@ -69,6 +69,18 @@ INTERNAL struct collider_support_point collider_get_support_point_internal(struc
|
||||
return res;
|
||||
}
|
||||
|
||||
struct collider_shape collider_from_quad(struct quad quad)
|
||||
{
|
||||
struct collider_shape res;
|
||||
res.points[0] = quad.p0;
|
||||
res.points[1] = quad.p1;
|
||||
res.points[2] = quad.p2;
|
||||
res.points[3] = quad.p3;
|
||||
res.count = 4;
|
||||
res.radius = 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
struct collider_support_point collider_get_support_point(struct collider_shape *shape, struct xform xf, struct v2 dir)
|
||||
{
|
||||
return collider_get_support_point_internal(shape, xf, dir, -1);
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
struct collider_shape {
|
||||
struct v2 points[8];
|
||||
u32 count;
|
||||
f32 radius;
|
||||
};
|
||||
|
||||
struct collider_support_point {
|
||||
struct v2 p;
|
||||
u32 i; /* Index of original point in shape */
|
||||
@ -51,6 +57,8 @@ struct collider_closest_points_result {
|
||||
struct collider_prototype prototype;
|
||||
};
|
||||
|
||||
struct collider_shape collider_from_quad(struct quad quad);
|
||||
|
||||
struct collider_support_point collider_get_support_point(struct collider_shape *shape, struct xform xf, struct v2 dir);
|
||||
|
||||
struct aabb collider_aabb_from_collider(struct collider_shape *shape, struct xform xf);
|
||||
|
||||
@ -30,6 +30,11 @@ enum host_write_flag {
|
||||
HOST_WRITE_FLAG_RELIABLE = (1 << 0)
|
||||
};
|
||||
|
||||
struct host_channel_id {
|
||||
u32 gen;
|
||||
u32 idx;
|
||||
};
|
||||
|
||||
struct host_cmd {
|
||||
enum host_cmd_kind kind;
|
||||
struct host_channel_id channel_id;
|
||||
|
||||
@ -4,3 +4,4 @@
|
||||
#include "sim_ent.c"
|
||||
#include "sim_phys.c"
|
||||
#include "sim_step.c"
|
||||
#include "sim_space.c"
|
||||
|
||||
@ -4,12 +4,12 @@
|
||||
#include "../base/base.h"
|
||||
#include "../sprite/sprite.h"
|
||||
#include "../collider/collider.h"
|
||||
#include "../space/space.h"
|
||||
#include "../host/host.h"
|
||||
#include "../mixer/mixer.h"
|
||||
|
||||
#include "sim_core.h"
|
||||
#include "sim_phys.h"
|
||||
#include "sim_space.h"
|
||||
#include "sim_ent.h"
|
||||
#include "sim_step.h"
|
||||
|
||||
|
||||
@ -11,6 +11,15 @@
|
||||
#define SIM_LAYER_RELATIVE_DEFAULT (0)
|
||||
#define SIM_LAYER_RELATIVE_WEAPON (1)
|
||||
|
||||
struct sim_ent_id {
|
||||
struct uid uid;
|
||||
};
|
||||
|
||||
struct sim_client_handle {
|
||||
u32 idx;
|
||||
u32 gen;
|
||||
};
|
||||
|
||||
/* ========================== *
|
||||
* Startup
|
||||
* ========================== */
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
struct space_cell_bin;
|
||||
|
||||
struct space_entry_handle {
|
||||
u64 idx;
|
||||
u64 gen;
|
||||
};
|
||||
|
||||
struct space_entry {
|
||||
b32 valid;
|
||||
struct space_entry_handle handle;
|
||||
@ -1,3 +0,0 @@
|
||||
#include "space.h"
|
||||
|
||||
#include "space_core.c"
|
||||
@ -1,9 +0,0 @@
|
||||
#ifndef SPACE_H
|
||||
#define SPACE_H
|
||||
|
||||
#include "../base/base.h"
|
||||
#include "../collider/collider.h"
|
||||
|
||||
#include "space_core.h"
|
||||
|
||||
#endif
|
||||
@ -12,6 +12,11 @@ struct sprite_startup_receipt sprite_startup(void);
|
||||
* Tag
|
||||
* ========================== */
|
||||
|
||||
struct sprite_tag {
|
||||
u64 hash;
|
||||
struct string path;
|
||||
};
|
||||
|
||||
INLINE struct sprite_tag sprite_tag_nil(void) { return (struct sprite_tag) { 0 }; }
|
||||
|
||||
struct sprite_tag sprite_tag_from_path(struct string path);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user