res -> result

This commit is contained in:
jacob 2025-07-30 15:58:38 -05:00
parent 1215f9ff58
commit dd3427db83
28 changed files with 794 additions and 795 deletions

View File

@ -80,7 +80,7 @@ struct app_arg_list {
/* TODO: Remove this and do real argument parsing */ /* TODO: Remove this and do real argument parsing */
internal struct app_arg_list parse_args(Arena *arena, String args_str) internal struct app_arg_list parse_args(Arena *arena, String args_str)
{ {
struct app_arg_list res = ZI; struct app_arg_list result = ZI;
i64 mode = 0; i64 mode = 0;
i64 i = 0; i64 i = 0;
i64 key_start = -1; i64 key_start = -1;
@ -123,13 +123,13 @@ internal struct app_arg_list parse_args(Arena *arena, String args_str)
struct app_arg *arg = PushStruct(arena, struct app_arg); struct app_arg *arg = PushStruct(arena, struct app_arg);
arg->key = key; arg->key = key;
arg->value = value; arg->value = value;
if (res.last) { if (result.last) {
res.last->next = arg; result.last->next = arg;
} else { } else {
res.first = arg; result.first = arg;
} }
res.last = arg; result.last = arg;
++res.count; ++result.count;
} }
key_start = i + 1; key_start = i + 1;
mode = 1; mode = 1;
@ -139,7 +139,7 @@ internal struct app_arg_list parse_args(Arena *arena, String args_str)
default: break; default: break;
} }
} }
return res; return result;
} }
/* ========================== * /* ========================== *
@ -224,7 +224,7 @@ void P_AppStartup(String args_str)
P_CloseFIle(settings_file); P_CloseFIle(settings_file);
P_LogInfoF("Deserializing settings file data: %F", FmtString(file_data)); P_LogInfoF("Deserializing settings file data: %F", FmtString(file_data));
String error = ZI; String error = ZI;
P_WindowSettings *res = settings_deserialize(temp.arena, file_data, &error); P_WindowSettings *deser = settings_deserialize(temp.arena, file_data, &error);
if (error.len > 0) { if (error.len > 0) {
P_LogInfoF("Failed to load settings file with error - %F", FmtString(error)); P_LogInfoF("Failed to load settings file with error - %F", FmtString(error));
String msg = StringFormat(temp.arena, String msg = StringFormat(temp.arena,
@ -240,7 +240,7 @@ void P_AppStartup(String args_str)
P_Panic(msg); P_Panic(msg);
} }
P_LogInfoF("Settings file loaded successfully"); P_LogInfoF("Settings file loaded successfully");
window_settings = *res; window_settings = *deser;
} else { } else {
P_LogInfoF("Settings file not found, loading default"); P_LogInfoF("Settings file not found, loading default");
window_settings = default_window_settings(window); window_settings = default_window_settings(window);

View File

@ -162,13 +162,13 @@ internal u32 reverse_bits(u32 v, u32 bit_count)
return v >> 1; return v >> 1;
} else { } else {
u32 res = 0; u32 result = 0;
for (u32 i = 0; i <= (bit_count / 2); ++i) { for (u32 i = 0; i <= (bit_count / 2); ++i) {
u32 inv = (bit_count - (i + 1)); u32 inv = (bit_count - (i + 1));
res |= ((v >> i) & 0x1) << inv; result |= ((v >> i) & 0x1) << inv;
res |= ((v >> inv) & 0x1) << i; result |= ((v >> inv) & 0x1) << i;
} }
return res; return result;
} }
} }
@ -176,10 +176,10 @@ internal struct huffman huffman_init(Arena *arena, u32 max_code_bits, u32 *bl_co
{ {
__prof; __prof;
struct huffman res = ZI; struct huffman result = ZI;
res.max_code_bits = max_code_bits; result.max_code_bits = max_code_bits;
res.entries_count = (1 << max_code_bits); result.entries_count = (1 << max_code_bits);
res.entries = PushStructsNoZero(arena, struct huffman_entry, res.entries_count); result.entries = PushStructsNoZero(arena, struct huffman_entry, result.entries_count);
u32 code_length_hist[HUFFMAN_BIT_COUNT] = ZI; u32 code_length_hist[HUFFMAN_BIT_COUNT] = ZI;
for (u32 i = 0; i < bl_counts_count; ++i) { for (u32 i = 0; i < bl_counts_count; ++i) {
@ -200,20 +200,20 @@ internal struct huffman huffman_init(Arena *arena, u32 max_code_bits, u32 *bl_co
if (code_bits) { if (code_bits) {
Assert(code_bits < countof(next_code)); Assert(code_bits < countof(next_code));
u32 code = next_code[code_bits]++; u32 code = next_code[code_bits]++;
u32 arbitrary_bits = res.max_code_bits - code_bits; u32 arbitrary_bits = result.max_code_bits - code_bits;
u32 entry_count = (1 << arbitrary_bits); u32 entry_count = (1 << arbitrary_bits);
for (u32 entry_index = 0; entry_index < entry_count; ++entry_index) { for (u32 entry_index = 0; entry_index < entry_count; ++entry_index) {
/* TODO: Optimize this. It's bloating up the loading times. */ /* TODO: Optimize this. It's bloating up the loading times. */
u32 base_index = (code << arbitrary_bits) | entry_index; u32 base_index = (code << arbitrary_bits) | entry_index;
u32 index = reverse_bits(base_index, res.max_code_bits); u32 index = reverse_bits(base_index, result.max_code_bits);
struct huffman_entry *entry = &res.entries[index]; struct huffman_entry *entry = &result.entries[index];
entry->symbol = (u16)i; entry->symbol = (u16)i;
entry->bits_used = (u16)code_bits; entry->bits_used = (u16)code_bits;
} }
} }
} }
return res; return result;
} }
internal u16 huffman_decode(struct huffman *huffman, struct huff_bb *bb) internal u16 huffman_decode(struct huffman *huffman, struct huff_bb *bb)
@ -222,11 +222,10 @@ internal u16 huffman_decode(struct huffman *huffman, struct huff_bb *bb)
Assert(index < huffman->entries_count); Assert(index < huffman->entries_count);
struct huffman_entry *entry = &huffman->entries[index]; struct huffman_entry *entry = &huffman->entries[index];
u16 res = entry->symbol; u16 result = entry->symbol;
skip_bits(bb, entry->bits_used); skip_bits(bb, entry->bits_used);
Assert(entry->bits_used > 0); Assert(entry->bits_used > 0);
return result;
return res;
} }
internal void inflate(u8 *dst, u8 *encoded) internal void inflate(u8 *dst, u8 *encoded)
@ -549,7 +548,7 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded)
__prof; __prof;
TempArena scratch = BeginScratch(arena); TempArena scratch = BeginScratch(arena);
Ase_DecodedImage res = ZI; Ase_DecodedImage result = ZI;
BB_Buff bb = BitbuffFromString(encoded); BB_Buff bb = BitbuffFromString(encoded);
BB_Reader br = BB_ReaderFromBuffNoDebug(&bb); BB_Reader br = BB_ReaderFromBuffNoDebug(&bb);
@ -557,7 +556,7 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded)
BB_ReadBytes(&br, StringFromStruct(&ase_header)); BB_ReadBytes(&br, StringFromStruct(&ase_header));
if (ase_header.magic != 0xA5E0) { if (ase_header.magic != 0xA5E0) {
push_error_copy_msg(arena, &res.errors, Lit("Not a valid aseprite file")); push_error_copy_msg(arena, &result.errors, Lit("Not a valid aseprite file"));
goto abort; goto abort;
} }
@ -565,7 +564,7 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded)
String msg = StringFormat(scratch.arena, String msg = StringFormat(scratch.arena,
Lit("Only 32 bit rgba color mode is supported (got %F)"), Lit("Only 32 bit rgba color mode is supported (got %F)"),
FmtUint(ase_header.color_depth)); FmtUint(ase_header.color_depth));
push_error_copy_msg(arena, &res.errors, msg); push_error_copy_msg(arena, &result.errors, msg);
goto abort; goto abort;
} }
@ -578,10 +577,10 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded)
u64 image_height = frame_height * frames_y; u64 image_height = frame_height * frames_y;
make_image_dimensions_squareish(&ase_header, &frames_x, &frames_y, &image_width, &image_height); make_image_dimensions_squareish(&ase_header, &frames_x, &frames_y, &image_width, &image_height);
res.width = image_width; result.width = image_width;
res.height = image_height; result.height = image_height;
/* TODO: Optimize this. Naive memset(0) is bloating the decode time for large images. */ /* TODO: Optimize this. Naive memset(0) is bloating the decode time for large images. */
res.pixels = PushStructs(arena, u32, image_width * image_height); result.pixels = PushStructs(arena, u32, image_width * image_height);
u32 num_layers = 0; u32 num_layers = 0;
struct layer *layer_head = 0; struct layer *layer_head = 0;
@ -628,7 +627,7 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded)
layer->blend_mode = BB_ReadUBits(&br, 16); layer->blend_mode = BB_ReadUBits(&br, 16);
if (layer->blend_mode != 0) { if (layer->blend_mode != 0) {
push_error_copy_msg(arena, push_error_copy_msg(arena,
&res.errors, &result.errors,
Lit("Layer has unsupported blend mode (only 'Normal' mode is supported). Tip: Try using 'merge down' to create a normal layer as a workaround")); Lit("Layer has unsupported blend mode (only 'Normal' mode is supported). Tip: Try using 'merge down' to create a normal layer as a workaround"));
goto abort; goto abort;
} }
@ -694,7 +693,7 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded)
case CEL_TYPE_COMPRESSED_TILEMAP: { case CEL_TYPE_COMPRESSED_TILEMAP: {
/* Unsupported */ /* Unsupported */
push_error_copy_msg(arena, &res.errors, Lit("Tilemaps are not supported")); push_error_copy_msg(arena, &result.errors, Lit("Tilemaps are not supported"));
goto abort; goto abort;
} break; } break;
} }
@ -781,7 +780,7 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded)
for (i32 cel_x = cel_left; cel_x < cel_right; ++cel_x) { for (i32 cel_x = cel_left; cel_x < cel_right; ++cel_x) {
i32 image_x = image_left + cel_x; i32 image_x = image_left + cel_x;
u32 cel_pixel = cel->pixels[cel_x + cel_stride]; u32 cel_pixel = cel->pixels[cel_x + cel_stride];
u32 *image_pixel = &res.pixels[image_x + image_stride]; u32 *image_pixel = &result.pixels[image_x + image_stride];
*image_pixel = blend(cel_pixel, *image_pixel, opacity); *image_pixel = blend(cel_pixel, *image_pixel, opacity);
} }
} }
@ -794,12 +793,12 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded)
abort: abort:
if (res.errors.count <= 0) { if (result.errors.count <= 0) {
res.success = 1; result.success = 1;
} }
EndScratch(scratch); EndScratch(scratch);
return res; return result;
} }
/* ========================== * /* ========================== *
@ -810,7 +809,7 @@ Ase_DecodedSheet ase_decode_sheet(Arena *arena, String encoded)
{ {
__prof; __prof;
Ase_DecodedSheet res = ZI; Ase_DecodedSheet result = ZI;
BB_Buff bb = BitbuffFromString(encoded); BB_Buff bb = BitbuffFromString(encoded);
BB_Reader br = BB_ReaderFromBuffNoDebug(&bb); BB_Reader br = BB_ReaderFromBuffNoDebug(&bb);
@ -960,18 +959,18 @@ Ase_DecodedSheet ase_decode_sheet(Arena *arena, String encoded)
/* Assert all data was read */ /* Assert all data was read */
Assert(BB_NumBytesRemaining(&br) == 0); Assert(BB_NumBytesRemaining(&br) == 0);
res.image_size = VEC2(image_width, image_height); result.image_size = VEC2(image_width, image_height);
res.frame_size = VEC2(frame_width, frame_height); result.frame_size = VEC2(frame_width, frame_height);
res.num_frames = num_frames; result.num_frames = num_frames;
res.num_spans = num_spans; result.num_spans = num_spans;
res.num_slice_keys = num_slice_keys; result.num_slice_keys = num_slice_keys;
res.frame_head = frame_head; result.frame_head = frame_head;
res.span_head = span_head; result.span_head = span_head;
res.slice_key_head = slice_key_head; result.slice_key_head = slice_key_head;
if (res.errors.count <= 0) { if (result.errors.count <= 0) {
res.success = 1; result.success = 1;
} }
return res; return result;
} }

View File

@ -663,31 +663,31 @@ f32 ArcTanF32(f32 x)
//- ArcTan2 //- ArcTan2
f32 ArcTan2F32(f32 y, f32 x) f32 ArcTan2F32(f32 y, f32 x)
{ {
f32 res; f32 result;
if (x == 0) if (x == 0)
{ {
if (y < 0) if (y < 0)
{ {
res = 3 * Pi / 2; result = 3 * Pi / 2;
} }
else if (y == 0) else if (y == 0)
{ {
res = 0; result = 0;
} }
else else
{ {
res = Pi / 2; result = Pi / 2;
} }
} }
else if (y == 0) else if (y == 0)
{ {
if (x < 0) if (x < 0)
{ {
res = Pi; result = Pi;
} }
else else
{ {
res = 0; result = 0;
} }
} }
else else
@ -705,9 +705,9 @@ f32 ArcTan2F32(f32 y, f32 x)
{ {
offset = 0; offset = 0;
} }
res = ArcTanF32(y / x) + offset; result = ArcTanF32(y / x) + offset;
} }
return res; return result;
} }
//- ArcSin //- ArcSin
@ -1032,22 +1032,22 @@ Xform XformFromPos(Vec2 v)
Xform XformFromRot(f32 r) Xform XformFromRot(f32 r)
{ {
Xform res; Xform result;
f32 c = CosF32(r); f32 c = CosF32(r);
f32 s = SinF32(r); f32 s = SinF32(r);
res.bx = VEC2(c, s); result.bx = VEC2(c, s);
res.by = VEC2(-s, c); result.by = VEC2(-s, c);
res.og = VEC2(0, 0); result.og = VEC2(0, 0);
return res; return result;
} }
Xform XformFromScale(Vec2 scale) Xform XformFromScale(Vec2 scale)
{ {
Xform res; Xform result;
res.bx = VEC2(scale.x, 0); result.bx = VEC2(scale.x, 0);
res.by = VEC2(0, scale.y); result.by = VEC2(0, scale.y);
res.og = VEC2(0, 0); result.og = VEC2(0, 0);
return res; return result;
} }
Xform XformFromTrs(Trs trs) Xform XformFromTrs(Trs trs)
@ -1117,21 +1117,21 @@ Xform ScaleXform(Xform xf, Vec2 scale)
Xform WorldScaleXform(Xform xf, Vec2 scale) Xform WorldScaleXform(Xform xf, Vec2 scale)
{ {
Xform res; Xform result;
res.bx = MulVec2Vec2(xf.bx, scale); result.bx = MulVec2Vec2(xf.bx, scale);
res.by = MulVec2Vec2(xf.by, scale); result.by = MulVec2Vec2(xf.by, scale);
res.og = MulVec2Vec2(xf.og, scale); result.og = MulVec2Vec2(xf.og, scale);
return res; return result;
} }
//- Lerp //- Lerp
Xform LerpXform(Xform a, Xform b, f32 t) Xform LerpXform(Xform a, Xform b, f32 t)
{ {
Xform res; Xform result;
res.bx = SlerpVec2(a.bx, b.bx, t); result.bx = SlerpVec2(a.bx, b.bx, t);
res.by = SlerpVec2(a.by, b.by, t); result.by = SlerpVec2(a.by, b.by, t);
res.og = LerpVec2(a.og, b.og, t); result.og = LerpVec2(a.og, b.og, t);
return res; return result;
} }
//- Invert //- Invert
@ -1155,13 +1155,13 @@ Xform InvertXform(Xform xf)
//- Mul //- Mul
Xform MulXform(Xform a, Xform b) Xform MulXform(Xform a, Xform b)
{ {
Xform res; Xform result;
res.bx.x = a.bx.x * b.bx.x + a.by.x * b.bx.y; result.bx.x = a.bx.x * b.bx.x + a.by.x * b.bx.y;
res.bx.y = a.bx.y * b.bx.x + a.by.y * b.bx.y; result.bx.y = a.bx.y * b.bx.x + a.by.y * b.bx.y;
res.by.x = a.bx.x * b.by.x + a.by.x * b.by.y; result.by.x = a.bx.x * b.by.x + a.by.x * b.by.y;
res.by.y = a.bx.y * b.by.x + a.by.y * b.by.y; result.by.y = a.bx.y * b.by.x + a.by.y * b.by.y;
res.og = MulXformV2(a, b.og); result.og = MulXformV2(a, b.og);
return res; return result;
} }
Vec2 MulXformBasisV2(Xform xf, Vec2 v) Vec2 MulXformBasisV2(Xform xf, Vec2 v)
@ -1174,27 +1174,27 @@ Vec2 MulXformBasisV2(Xform xf, Vec2 v)
Vec2 MulXformV2(Xform xf, Vec2 v) Vec2 MulXformV2(Xform xf, Vec2 v)
{ {
Vec2 res = MulXformBasisV2(xf, v); Vec2 result = MulXformBasisV2(xf, v);
res = AddVec2(res, xf.og); result = AddVec2(result, xf.og);
return res; return result;
} }
Quad MulXformQuad(Xform xf, Quad quad) Quad MulXformQuad(Xform xf, Quad quad)
{ {
Quad res; Quad result;
res.p0 = MulXformV2(xf, quad.p0); result.p0 = MulXformV2(xf, quad.p0);
res.p1 = MulXformV2(xf, quad.p1); result.p1 = MulXformV2(xf, quad.p1);
res.p2 = MulXformV2(xf, quad.p2); result.p2 = MulXformV2(xf, quad.p2);
res.p3 = MulXformV2(xf, quad.p3); result.p3 = MulXformV2(xf, quad.p3);
return res; return result;
} }
Vec2 InvertXformBasisMulV2(Xform xf, Vec2 v) Vec2 InvertXformBasisMulV2(Xform xf, Vec2 v)
{ {
Xform inv = InvertXform(xf); Xform inv = InvertXform(xf);
Vec2 res = MulXformBasisV2(inv, v); Vec2 result = MulXformBasisV2(inv, v);
return res; return result;
} }
/* TODO: Get rid of this? Just force caller to use invert manually since it's expensive. */ /* TODO: Get rid of this? Just force caller to use invert manually since it's expensive. */
@ -1207,10 +1207,10 @@ Vec2 InvertXformMulV2(Xform xf, Vec2 v)
//- Helpers //- Helpers
Xform BasisFromXform(Xform xf) Xform BasisFromXform(Xform xf)
{ {
Xform res = ZI; Xform result = ZI;
res.bx = xf.bx; result.bx = xf.bx;
res.by = xf.by; result.by = xf.by;
return res; return result;
} }
f32 DeterminantFromXform(Xform xf) f32 DeterminantFromXform(Xform xf)
@ -1254,22 +1254,22 @@ Vec2 ScaleFromXform(Xform xf)
Quad QuadFromRect(Rect rect) Quad QuadFromRect(Rect rect)
{ {
Quad res; Quad result;
res.p0 = VEC2(rect.x, rect.y); /* Top left */ result.p0 = VEC2(rect.x, rect.y); /* Top left */
res.p1 = VEC2(rect.x + rect.width, rect.y); /* Top right */ result.p1 = VEC2(rect.x + rect.width, rect.y); /* Top right */
res.p2 = VEC2(rect.x + rect.width, rect.y + rect.height); /* Bottom right */ result.p2 = VEC2(rect.x + rect.width, rect.y + rect.height); /* Bottom right */
res.p3 = VEC2(rect.x, rect.y + rect.height); /* Bottom left */ result.p3 = VEC2(rect.x, rect.y + rect.height); /* Bottom left */
return res; return result;
} }
Quad QuadFromAabb(Aabb aabb) Quad QuadFromAabb(Aabb aabb)
{ {
Quad res; Quad result;
res.p0 = VEC2(aabb.p0.x, aabb.p0.y); /* Top left */ result.p0 = VEC2(aabb.p0.x, aabb.p0.y); /* Top left */
res.p1 = VEC2(aabb.p1.x, aabb.p0.y); /* Top right */ result.p1 = VEC2(aabb.p1.x, aabb.p0.y); /* Top right */
res.p2 = VEC2(aabb.p1.x, aabb.p1.y); /* Bottom right */ result.p2 = VEC2(aabb.p1.x, aabb.p1.y); /* Bottom right */
res.p3 = VEC2(aabb.p0.x, aabb.p1.y); /* Bottom left */ result.p3 = VEC2(aabb.p0.x, aabb.p1.y); /* Bottom left */
return res; return result;
} }
Quad QuadFromLine(Vec2 start, Vec2 end, f32 thickness) Quad QuadFromLine(Vec2 start, Vec2 end, f32 thickness)
@ -1282,12 +1282,12 @@ Quad QuadFromLine(Vec2 start, Vec2 end, f32 thickness)
Vec2 left = MulVec2(dir_perp, -width); Vec2 left = MulVec2(dir_perp, -width);
Vec2 right = MulVec2(dir_perp, width); Vec2 right = MulVec2(dir_perp, width);
Quad res; Quad result;
res.p0 = AddVec2(start, left); result.p0 = AddVec2(start, left);
res.p1 = AddVec2(start, right); result.p1 = AddVec2(start, right);
res.p2 = AddVec2(end, right); result.p2 = AddVec2(end, right);
res.p3 = AddVec2(end, left); result.p3 = AddVec2(end, left);
return res; return result;
} }
Quad QuadFromRay(Vec2 pos, Vec2 rel, f32 thickness) Quad QuadFromRay(Vec2 pos, Vec2 rel, f32 thickness)
@ -1307,22 +1307,22 @@ Quad ScaleQuad(Quad q, f32 s)
Quad RoundQuad(Quad quad) Quad RoundQuad(Quad quad)
{ {
Quad res; Quad result;
res.p0 = RoundVec2(quad.p0); result.p0 = RoundVec2(quad.p0);
res.p1 = RoundVec2(quad.p1); result.p1 = RoundVec2(quad.p1);
res.p2 = RoundVec2(quad.p2); result.p2 = RoundVec2(quad.p2);
res.p3 = RoundVec2(quad.p3); result.p3 = RoundVec2(quad.p3);
return res; return result;
} }
Quad FloorQuad(Quad quad) Quad FloorQuad(Quad quad)
{ {
Quad res; Quad result;
res.p0 = FloorVec2(quad.p0); result.p0 = FloorVec2(quad.p0);
res.p1 = FloorVec2(quad.p1); result.p1 = FloorVec2(quad.p1);
res.p2 = FloorVec2(quad.p2); result.p2 = FloorVec2(quad.p2);
res.p3 = FloorVec2(quad.p3); result.p3 = FloorVec2(quad.p3);
return res; return result;
} }
//////////////////////////////// ////////////////////////////////
@ -1331,12 +1331,12 @@ Quad FloorQuad(Quad quad)
/* https://box2d.org/files/ErinCatto_SoftConstraints_GDC2011.pdf */ /* https://box2d.org/files/ErinCatto_SoftConstraints_GDC2011.pdf */
SoftSpring MakeSpring(f32 hertz, f32 damping_ratio, f32 dt) SoftSpring MakeSpring(f32 hertz, f32 damping_ratio, f32 dt)
{ {
SoftSpring res; SoftSpring result;
if (hertz == 0.0f) if (hertz == 0.0f)
{ {
res.bias_rate = 0; result.bias_rate = 0;
res.mass_scale = 1; result.mass_scale = 1;
res.impulse_scale = 0; result.impulse_scale = 0;
} }
else else
{ {
@ -1344,11 +1344,11 @@ SoftSpring MakeSpring(f32 hertz, f32 damping_ratio, f32 dt)
f32 a = 2 * damping_ratio + angular_frequency * dt; f32 a = 2 * damping_ratio + angular_frequency * dt;
f32 b = angular_frequency * a * dt; f32 b = angular_frequency * a * dt;
f32 c = 1 / (b + 1); f32 c = 1 / (b + 1);
res.bias_rate = angular_frequency / a; result.bias_rate = angular_frequency / a;
res.mass_scale = b * c; result.mass_scale = b * c;
res.impulse_scale = c; result.impulse_scale = c;
} }
return res; return result;
} }
//////////////////////////////// ////////////////////////////////
@ -1398,23 +1398,23 @@ Mat4x4 MulMat4x4(Mat4x4 m1, Mat4x4 m2)
b20 = m2.e[2][0], b21 = m2.e[2][1], b22 = m2.e[2][2], b23 = m2.e[2][3], b20 = m2.e[2][0], b21 = m2.e[2][1], b22 = m2.e[2][2], b23 = m2.e[2][3],
b30 = m2.e[3][0], b31 = m2.e[3][1], b32 = m2.e[3][2], b33 = m2.e[3][3]; b30 = m2.e[3][0], b31 = m2.e[3][1], b32 = m2.e[3][2], b33 = m2.e[3][3];
Mat4x4 res; Mat4x4 result;
res.e[0][0] = a00 * b00 + a10 * b01 + a20 * b02 + a30 * b03; result.e[0][0] = a00 * b00 + a10 * b01 + a20 * b02 + a30 * b03;
res.e[0][1] = a01 * b00 + a11 * b01 + a21 * b02 + a31 * b03; result.e[0][1] = a01 * b00 + a11 * b01 + a21 * b02 + a31 * b03;
res.e[0][2] = a02 * b00 + a12 * b01 + a22 * b02 + a32 * b03; result.e[0][2] = a02 * b00 + a12 * b01 + a22 * b02 + a32 * b03;
res.e[0][3] = a03 * b00 + a13 * b01 + a23 * b02 + a33 * b03; result.e[0][3] = a03 * b00 + a13 * b01 + a23 * b02 + a33 * b03;
res.e[1][0] = a00 * b10 + a10 * b11 + a20 * b12 + a30 * b13; result.e[1][0] = a00 * b10 + a10 * b11 + a20 * b12 + a30 * b13;
res.e[1][1] = a01 * b10 + a11 * b11 + a21 * b12 + a31 * b13; result.e[1][1] = a01 * b10 + a11 * b11 + a21 * b12 + a31 * b13;
res.e[1][2] = a02 * b10 + a12 * b11 + a22 * b12 + a32 * b13; result.e[1][2] = a02 * b10 + a12 * b11 + a22 * b12 + a32 * b13;
res.e[1][3] = a03 * b10 + a13 * b11 + a23 * b12 + a33 * b13; result.e[1][3] = a03 * b10 + a13 * b11 + a23 * b12 + a33 * b13;
res.e[2][0] = a00 * b20 + a10 * b21 + a20 * b22 + a30 * b23; result.e[2][0] = a00 * b20 + a10 * b21 + a20 * b22 + a30 * b23;
res.e[2][1] = a01 * b20 + a11 * b21 + a21 * b22 + a31 * b23; result.e[2][1] = a01 * b20 + a11 * b21 + a21 * b22 + a31 * b23;
res.e[2][2] = a02 * b20 + a12 * b21 + a22 * b22 + a32 * b23; result.e[2][2] = a02 * b20 + a12 * b21 + a22 * b22 + a32 * b23;
res.e[2][3] = a03 * b20 + a13 * b21 + a23 * b22 + a33 * b23; result.e[2][3] = a03 * b20 + a13 * b21 + a23 * b22 + a33 * b23;
res.e[3][0] = a00 * b30 + a10 * b31 + a20 * b32 + a30 * b33; result.e[3][0] = a00 * b30 + a10 * b31 + a20 * b32 + a30 * b33;
res.e[3][1] = a01 * b30 + a11 * b31 + a21 * b32 + a31 * b33; result.e[3][1] = a01 * b30 + a11 * b31 + a21 * b32 + a31 * b33;
res.e[3][2] = a02 * b30 + a12 * b31 + a22 * b32 + a32 * b33; result.e[3][2] = a02 * b30 + a12 * b31 + a22 * b32 + a32 * b33;
res.e[3][3] = a03 * b30 + a13 * b31 + a23 * b32 + a33 * b33; result.e[3][3] = a03 * b30 + a13 * b31 + a23 * b32 + a33 * b33;
return res; return result;
} }

View File

@ -80,16 +80,16 @@ void *memset(void *dst, i32 c, u64 n)
__attribute((section(".text.memcmp"))) __attribute((section(".text.memcmp")))
i32 memcmp(const void *p1, const void *p2, u64 n) i32 memcmp(const void *p1, const void *p2, u64 n)
{ {
i32 res = 0; i32 result = 0;
for (u64 i = 0; i < n; ++i) for (u64 i = 0; i < n; ++i)
{ {
res = ((u8 *)p1)[i] - ((u8 *)p2)[i]; result = ((u8 *)p1)[i] - ((u8 *)p2)[i];
if (res != 0) if (result != 0)
{ {
break; break;
} }
} }
return res; return result;
} }
#endif /* !CrtlibIsEnabled */ #endif /* !CrtlibIsEnabled */

View File

@ -174,23 +174,23 @@ String StringFromF64(Arena *arena, f64 f, u32 precision)
String StringFromhandle(Arena *arena, u64 v0, u64 v1) String StringFromhandle(Arena *arena, u64 v0, u64 v1)
{ {
String res = ZI; String result = ZI;
res.text = PushDry(arena, u8); result.text = PushDry(arena, u8);
res.len += CopyString(arena, Lit("h")).len; result.len += CopyString(arena, Lit("h")).len;
res.len += StringFromU64(arena, v0, 16, 0).len; result.len += StringFromU64(arena, v0, 16, 0).len;
res.len += CopyString(arena, Lit("x")).len; result.len += CopyString(arena, Lit("x")).len;
res.len += StringFromU64(arena, v1, 16, 0).len; result.len += StringFromU64(arena, v1, 16, 0).len;
return res; return result;
} }
//- Uid conversion //- Uid conversion
String StringFromUid(Arena *arena, Uid uid) String StringFromUid(Arena *arena, Uid uid)
{ {
String res = ZI; String result = ZI;
res.text = PushDry(arena, u8); result.text = PushDry(arena, u8);
res.len += StringFromU64(arena, (uid.hi >> 32), 16, 8).len; result.len += StringFromU64(arena, (uid.hi >> 32), 16, 8).len;
return res; return result;
} }
//////////////////////////////// ////////////////////////////////
@ -210,11 +210,11 @@ String CopyString(Arena *arena, String src)
String CopyStringToBuffer(String dst, String src) String CopyStringToBuffer(String dst, String src)
{ {
String res = ZI; String result = ZI;
res.len = MinU64(dst.len, src.len); result.len = MinU64(dst.len, src.len);
res.text = dst.text; result.text = dst.text;
CopyBytes(res.text, src.text, res.len); CopyBytes(result.text, src.text, result.len);
return res; return result;
} }
//- Repeat //- Repeat
@ -328,9 +328,9 @@ String IndentString(Arena *arena, String str, u32 indent)
String LowerString(Arena *arena, String str) String LowerString(Arena *arena, String str)
{ {
String res = ZI; String result = ZI;
res.text = PushStructsNoZero(arena, u8, str.len); result.text = PushStructsNoZero(arena, u8, str.len);
res.len = str.len; result.len = str.len;
for (u64 i = 0; i < str.len; ++i) for (u64 i = 0; i < str.len; ++i)
{ {
@ -339,10 +339,10 @@ String LowerString(Arena *arena, String str)
{ {
c += 32; c += 32;
} }
res.text[i] = c; result.text[i] = c;
} }
return res; return result;
} }
//- Compare //- Compare
@ -370,27 +370,27 @@ b32 EqString(String str1, String str2)
i32 CmpString(String str1, String str2) i32 CmpString(String str1, String str2)
{ {
i32 res = 0; i32 result = 0;
for (u64 i = 0; i < MinU64(str1.len, str2.len); ++i) for (u64 i = 0; i < MinU64(str1.len, str2.len); ++i)
{ {
res = str1.text[i] - str2.text[i]; result = str1.text[i] - str2.text[i];
if (res != 0) if (result != 0)
{ {
break; break;
} }
} }
if (res == 0) if (result == 0)
{ {
if (str1.len > str2.len) if (str1.len > str2.len)
{ {
res = str1.text[str2.len]; result = str1.text[str2.len];
} }
else if (str2.len > str1.len) else if (str2.len > str1.len)
{ {
res = str2.text[str1.len]; result = str2.text[str1.len];
} }
} }
return res; return result;
} }
//- Match //- Match
@ -657,7 +657,7 @@ void EndCodepointIter(CodepointIter *iter)
/* utf8 <- utf16 */ /* utf8 <- utf16 */
String StringFromString16(Arena *arena, String16 str16) String StringFromString16(Arena *arena, String16 str16)
{ {
String res = { String result = {
.len = 0, .len = 0,
.text = PushDry(arena, u8) .text = PushDry(arena, u8)
}; };
@ -673,16 +673,16 @@ String StringFromString16(Arena *arena, String16 str16)
CopyBytes(dst, encoded.chars8, encoded.count8); CopyBytes(dst, encoded.chars8, encoded.count8);
pos16 += decoded.advance16; pos16 += decoded.advance16;
res.len += encoded.count8; result.len += encoded.count8;
} }
return res; return result;
} }
/* utf8 <- utf32 */ /* utf8 <- utf32 */
String StringFromString32(Arena *arena, String32 str32) String StringFromString32(Arena *arena, String32 str32)
{ {
String res = { String result = {
.len = 0, .len = 0,
.text = PushDry(arena, u8) .text = PushDry(arena, u8)
}; };
@ -698,10 +698,10 @@ String StringFromString32(Arena *arena, String32 str32)
CopyBytes(dst, &encoded.chars8, encoded.count8); CopyBytes(dst, &encoded.chars8, encoded.count8);
pos32 += 1; pos32 += 1;
res.len += encoded.count8; result.len += encoded.count8;
} }
return res; return result;
} }
//- String encode //- String encode
@ -709,7 +709,7 @@ String StringFromString32(Arena *arena, String32 str32)
/* utf16 <- utf8 */ /* utf16 <- utf8 */
String16 String16FromString(Arena *arena, String str8) String16 String16FromString(Arena *arena, String str8)
{ {
String16 res = { String16 result = {
.len = 0, .len = 0,
.text = PushDry(arena, u16) .text = PushDry(arena, u16)
}; };
@ -725,16 +725,16 @@ String16 String16FromString(Arena *arena, String str8)
CopyBytes(dst, encoded.chars16, (encoded.count16 << 1)); CopyBytes(dst, encoded.chars16, (encoded.count16 << 1));
pos8 += decoded.advance8; pos8 += decoded.advance8;
res.len += encoded.count16; result.len += encoded.count16;
} }
return res; return result;
} }
/* utf32 <- utf8 */ /* utf32 <- utf8 */
String32 String32FromString(Arena *arena, String str8) String32 String32FromString(Arena *arena, String str8)
{ {
String32 res = { String32 result = {
.len = 0, .len = 0,
.text = PushDry(arena, u32) .text = PushDry(arena, u32)
}; };
@ -750,10 +750,10 @@ String32 String32FromString(Arena *arena, String str8)
*dst = encoded.chars32; *dst = encoded.chars32;
pos8 += decoded.advance8; pos8 += decoded.advance8;
res.len += 1; result.len += 1;
} }
return res; return result;
} }
//////////////////////////////// ////////////////////////////////

View File

@ -1,22 +1,22 @@
/* Returns a uid generated from the system's random number generator */ /* Returns a uid generated from the system's random number generator */
Uid UidFromTrueRand(void) Uid UidFromTrueRand(void)
{ {
Uid res = ZI; Uid result = ZI;
TrueRand(StringFromStruct(&res)); TrueRand(StringFromStruct(&result));
return res; return result;
} }
/* Combines 2 uids into a new uid */ /* Combines 2 uids into a new uid */
Uid CombineUid(Uid a, Uid b) Uid CombineUid(Uid a, Uid b)
{ {
Uid res; Uid result;
res.hi = (a.hi * 3) + b.hi; result.hi = (a.hi * 3) + b.hi;
res.lo = (a.lo * 3) + b.lo; result.lo = (a.lo * 3) + b.lo;
res.hi += res.lo; result.hi += result.lo;
res.lo += res.hi; result.lo += result.hi;
res.hi = RandU64FromSeed(res.hi); result.hi = RandU64FromSeed(result.hi);
res.lo = RandU64FromSeed(res.lo); result.lo = RandU64FromSeed(result.lo);
res.hi += res.lo; result.hi += result.lo;
res.lo += res.hi; result.lo += result.hi;
return res; return result;
} }

View File

@ -5,10 +5,10 @@
BB_Buff AllocBitbuff(u64 arena_reserve) BB_Buff AllocBitbuff(u64 arena_reserve)
{ {
BB_Buff res = ZI; BB_Buff result = ZI;
res.arena = AllocArena(arena_reserve); result.arena = AllocArena(arena_reserve);
res.is_backed_by_arena = 1; result.is_backed_by_arena = 1;
return res; return result;
} }
void ReleaseBitbuff(BB_Buff *bb) void ReleaseBitbuff(BB_Buff *bb)
@ -22,9 +22,9 @@ void ReleaseBitbuff(BB_Buff *bb)
BB_Buff BitbuffFromString(String s) BB_Buff BitbuffFromString(String s)
{ {
BB_Buff res = ZI; BB_Buff result = ZI;
res.fixed_buffer = s; result.fixed_buffer = s;
return res; return result;
} }
//////////////////////////////// ////////////////////////////////
@ -32,31 +32,31 @@ BB_Buff BitbuffFromString(String s)
BB_Writer BB_WriterFromBuff(BB_Buff *bb) BB_Writer BB_WriterFromBuff(BB_Buff *bb)
{ {
BB_Writer res = ZI; BB_Writer result = ZI;
res.bb = bb; result.bb = bb;
if (bb->is_backed_by_arena) if (bb->is_backed_by_arena)
{ {
res.base = ArenaBase(bb->arena); result.base = ArenaBase(bb->arena);
} }
else else
{ {
res.base = bb->fixed_buffer.text; result.base = bb->fixed_buffer.text;
} }
res.cur_bit = 0; result.cur_bit = 0;
#if BB_DebugIsEnabled #if BB_DebugIsEnabled
res.debug_enabled = 1; result.debug_enabled = 1;
#endif #endif
return res; return result;
} }
/* Use this when writing external formats that will not verify bitbuff debug symbols / magic numbers */ /* Use this when writing external formats that will not verify bitbuff debug symbols / magic numbers */
BB_Writer BB_WriterFromBuffNoDebug(BB_Buff *bb) BB_Writer BB_WriterFromBuffNoDebug(BB_Buff *bb)
{ {
BB_Writer res = BB_WriterFromBuff(bb); BB_Writer result = BB_WriterFromBuff(bb);
#if BB_DebugIsEnabled #if BB_DebugIsEnabled
res.debug_enabled = 0; result.debug_enabled = 0;
#endif #endif
return res; return result;
} }
/* FIXME: Handle overflowed bw */ /* FIXME: Handle overflowed bw */
@ -74,11 +74,11 @@ u64 BB_GetNumBytesWritten(BB_Writer *bw)
/* FIXME: Handle overflowed bw */ /* FIXME: Handle overflowed bw */
String BB_GetWritten(Arena *arena, BB_Writer *bw) String BB_GetWritten(Arena *arena, BB_Writer *bw)
{ {
String res = ZI; String result = ZI;
res.len = (bw->cur_bit + 7) >> 3; result.len = (bw->cur_bit + 7) >> 3;
res.text = PushStructsNoZero(arena, u8, res.len); result.text = PushStructsNoZero(arena, u8, result.len);
CopyBytes(res.text, bw->base, res.len); CopyBytes(result.text, bw->base, result.len);
return res; return result;
} }
/* FIXME: Handle overflowed bw */ /* FIXME: Handle overflowed bw */
@ -90,11 +90,11 @@ u8 *BB_GetWrittenRaw(BB_Writer *bw)
/* Returns 1 if num_bits would cause the writer to overflow its fixed buffer size (if writer is not backed by a dynamic arena bitbuff) */ /* Returns 1 if num_bits would cause the writer to overflow its fixed buffer size (if writer is not backed by a dynamic arena bitbuff) */
b32 BB_CheckWriterOverflowBits(BB_Writer *bw, u64 num_bits) b32 BB_CheckWriterOverflowBits(BB_Writer *bw, u64 num_bits)
{ {
b32 res = 0; b32 result = 0;
BB_Buff *bb = bw->bb; BB_Buff *bb = bw->bb;
if (bw->overflowed) if (bw->overflowed)
{ {
res = 1; result = 1;
} }
else else
{ {
@ -116,13 +116,13 @@ b32 BB_CheckWriterOverflowBits(BB_Writer *bw, u64 num_bits)
{ {
/* Writer overflowed fixed buffer */ /* Writer overflowed fixed buffer */
Assert(0); Assert(0);
res = 1; result = 1;
bw->cur_bit = max_len << 3; bw->cur_bit = max_len << 3;
bw->overflowed = 1; bw->overflowed = 1;
} }
} }
} }
return res; return result;
} }
//////////////////////////////// ////////////////////////////////
@ -346,33 +346,33 @@ void BB_WriteDebugMagic(BB_Writer *bw, BB_DebugMagicKind magic, u8 num_bits)
BB_Reader BB_ReaderFromBuff(BB_Buff *bb) BB_Reader BB_ReaderFromBuff(BB_Buff *bb)
{ {
BB_Reader res = ZI; BB_Reader result = ZI;
if (!bb->is_backed_by_arena) if (!bb->is_backed_by_arena)
{ {
res.base = bb->fixed_buffer.text; result.base = bb->fixed_buffer.text;
res.base_len = bb->fixed_buffer.len; result.base_len = bb->fixed_buffer.len;
} }
else else
{ {
Arena *arena = bb->arena; Arena *arena = bb->arena;
res.base = ArenaBase(arena); result.base = ArenaBase(arena);
res.base_len = arena->pos; result.base_len = arena->pos;
} }
res.cur_bit = 0; result.cur_bit = 0;
#if BB_DebugIsEnabled #if BB_DebugIsEnabled
res.debug_enabled = 1; result.debug_enabled = 1;
#endif #endif
return res; return result;
} }
/* Use this when reading from external formats that will not contain bitbuff debug symbols / magic numbers */ /* Use this when reading from external formats that will not contain bitbuff debug symbols / magic numbers */
BB_Reader BB_ReaderFromBuffNoDebug(BB_Buff *bb) BB_Reader BB_ReaderFromBuffNoDebug(BB_Buff *bb)
{ {
BB_Reader res = BB_ReaderFromBuff(bb); BB_Reader result = BB_ReaderFromBuff(bb);
#if BB_DebugIsEnabled #if BB_DebugIsEnabled
res.debug_enabled = 0; result.debug_enabled = 0;
#endif #endif
return res; return result;
} }
/* Returns the number of bits read from the bitbuff */ /* Returns the number of bits read from the bitbuff */
@ -405,10 +405,10 @@ u64 BB_NumBytesRemaining(BB_Reader *br)
b32 BB_CheckReaderOverflowBits(BB_Reader *br, u64 num_bits) b32 BB_CheckReaderOverflowBits(BB_Reader *br, u64 num_bits)
{ {
b32 res = 0; b32 result = 0;
if (br->overflowed) if (br->overflowed)
{ {
res = 1; result = 1;
} }
else else
{ {
@ -418,12 +418,12 @@ b32 BB_CheckReaderOverflowBits(BB_Reader *br, u64 num_bits)
{ {
/* Tried to read past bitbuff memory */ /* Tried to read past bitbuff memory */
Assert(0); Assert(0);
res = 1; result = 1;
br->cur_bit = base_len_bits; br->cur_bit = base_len_bits;
br->overflowed = 1; br->overflowed = 1;
} }
} }
return res; return result;
} }
//////////////////////////////// ////////////////////////////////
@ -451,7 +451,7 @@ u64 BB_ReadUBitsNoMagic(BB_Reader *br, u8 num_bits)
return 0; return 0;
} }
u64 res = 0; u64 result = 0;
u8 offset = br->cur_bit & 7; u8 offset = br->cur_bit & 7;
u8 num_trailing_bits = 0; u8 num_trailing_bits = 0;
@ -462,7 +462,7 @@ u64 BB_ReadUBitsNoMagic(BB_Reader *br, u8 num_bits)
u8 mix_byte = *at; u8 mix_byte = *at;
mix_byte >>= offset; mix_byte >>= offset;
mix_byte &= (1 << num_trailing_bits) - 1; mix_byte &= (1 << num_trailing_bits) - 1;
res = mix_byte; result = mix_byte;
num_bits -= num_trailing_bits; num_bits -= num_trailing_bits;
br->cur_bit += num_trailing_bits; br->cur_bit += num_trailing_bits;
} }
@ -478,9 +478,9 @@ u64 BB_ReadUBitsNoMagic(BB_Reader *br, u8 num_bits)
mask = ~(U64Max << num_bits); mask = ~(U64Max << num_bits);
} }
tmp &= mask; tmp &= mask;
res |= tmp << num_trailing_bits; result |= tmp << num_trailing_bits;
br->cur_bit += num_bits; br->cur_bit += num_bits;
return res; return result;
} }
u64 BB_ReadUBits(BB_Reader *br, u8 num_bits) u64 BB_ReadUBits(BB_Reader *br, u8 num_bits)
@ -511,18 +511,18 @@ u64 BB_ReadUV(BB_Reader *br)
{ {
BB_ReadDebugMagic(br, BB_DebugMagicKind_UV, 0); BB_ReadDebugMagic(br, BB_DebugMagicKind_UV, 0);
u64 res = 0; u64 result = 0;
for (u64 i = 0; i <= 9; ++i) for (u64 i = 0; i <= 9; ++i)
{ {
u64 part = BB_ReadUBits(br, 8); u64 part = BB_ReadUBits(br, 8);
u8 is_last_part = part <= 0x7F; u8 is_last_part = part <= 0x7F;
res |= (part & 0x7F) << (i * 7); result |= (part & 0x7F) << (i * 7);
if (is_last_part) if (is_last_part)
{ {
break; break;
} }
} }
return res; return result;
} }
/* Read a variable length signed integer. /* Read a variable length signed integer.
@ -552,18 +552,18 @@ i64 BB_ReadIV(BB_Reader *br)
} }
num_bits = MinU8(num_bits, 64); num_bits = MinU8(num_bits, 64);
i64 res; i64 result;
if (sign_bit) if (sign_bit)
{ {
/* Sign bit is 1, indicating result is stored in twos compliment */ /* Sign bit is 1, indicating result is stored in twos compliment */
res = BB_IntFromTwosCompliment(tc, num_bits); result = BB_IntFromTwosCompliment(tc, num_bits);
} }
else else
{ {
res = (i64)tc; result = (i64)tc;
} }
return res; return result;
} }
//////////////////////////////// ////////////////////////////////
@ -600,16 +600,16 @@ Uid BB_ReadUid(BB_Reader *br)
String BB_ReadString(Arena *arena, BB_Reader *br) String BB_ReadString(Arena *arena, BB_Reader *br)
{ {
BB_ReadDebugMagic(br, BB_DebugMagicKind_String, 0); BB_ReadDebugMagic(br, BB_DebugMagicKind_String, 0);
String res = ZI; String result = ZI;
u64 len = BB_ReadUV(br); u64 len = BB_ReadUV(br);
u8 *src = BB_ReadBytesRaw(br, len); u8 *src = BB_ReadBytesRaw(br, len);
if (src != 0) if (src != 0)
{ {
res.len = len; result.len = len;
res.text = PushStructsNoZero(arena, u8, len); result.text = PushStructsNoZero(arena, u8, len);
CopyBytes(res.text, src, len); CopyBytes(result.text, src, len);
} }
return res; return result;
} }
/* Will fill dst with zeroes if bitbuff overflows */ /* Will fill dst with zeroes if bitbuff overflows */

View File

@ -63,22 +63,22 @@ internal CLD_SupportPoint collider_get_support_point_internal(CLD_Shape *shape,
furthest = MulXformV2(xf, furthest); furthest = MulXformV2(xf, furthest);
CLD_SupportPoint res; CLD_SupportPoint result;
res.p = furthest; result.p = furthest;
res.i = furthest_index; result.i = furthest_index;
return res; return result;
} }
CLD_Shape collider_from_quad(Quad quad) CLD_Shape collider_from_quad(Quad quad)
{ {
CLD_Shape res; CLD_Shape result;
res.points[0] = quad.p0; result.points[0] = quad.p0;
res.points[1] = quad.p1; result.points[1] = quad.p1;
res.points[2] = quad.p2; result.points[2] = quad.p2;
res.points[3] = quad.p3; result.points[3] = quad.p3;
res.count = 4; result.count = 4;
res.radius = 0; result.radius = 0;
return res; return result;
} }
CLD_SupportPoint collider_get_support_point(CLD_Shape *shape, Xform xf, Vec2 dir) CLD_SupportPoint collider_get_support_point(CLD_Shape *shape, Xform xf, Vec2 dir)
@ -88,11 +88,11 @@ CLD_SupportPoint collider_get_support_point(CLD_Shape *shape, Xform xf, Vec2 dir
internal CLD_MenkowskiPoint get_menkowski_point(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, Vec2 dir) internal CLD_MenkowskiPoint get_menkowski_point(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, Vec2 dir)
{ {
CLD_MenkowskiPoint res; CLD_MenkowskiPoint result;
res.s0 = collider_get_support_point(shape0, xf0, dir); result.s0 = collider_get_support_point(shape0, xf0, dir);
res.s1 = collider_get_support_point(shape1, xf1, NegVec2(dir)); result.s1 = collider_get_support_point(shape1, xf1, NegVec2(dir));
res.p = SubVec2(res.s0.p, res.s1.p); result.p = SubVec2(result.s0.p, result.s1.p);
return res; return result;
} }
/* ========================== * /* ========================== *
@ -101,22 +101,22 @@ internal CLD_MenkowskiPoint get_menkowski_point(CLD_Shape *shape0, CLD_Shape *sh
Aabb collider_aabb_from_collider(CLD_Shape *shape, Xform xf) Aabb collider_aabb_from_collider(CLD_Shape *shape, Xform xf)
{ {
Aabb res; Aabb result;
res.p0.x = collider_get_support_point(shape, xf, VEC2(-1, 0)).p.x - COLLISION_TOLERANCE; result.p0.x = collider_get_support_point(shape, xf, VEC2(-1, 0)).p.x - COLLISION_TOLERANCE;
res.p0.y = collider_get_support_point(shape, xf, VEC2(0, -1)).p.y - COLLISION_TOLERANCE; result.p0.y = collider_get_support_point(shape, xf, VEC2(0, -1)).p.y - COLLISION_TOLERANCE;
res.p1.x = collider_get_support_point(shape, xf, VEC2(1, 0)).p.x + COLLISION_TOLERANCE; result.p1.x = collider_get_support_point(shape, xf, VEC2(1, 0)).p.x + COLLISION_TOLERANCE;
res.p1.y = collider_get_support_point(shape, xf, VEC2(0, 1)).p.y + COLLISION_TOLERANCE; result.p1.y = collider_get_support_point(shape, xf, VEC2(0, 1)).p.y + COLLISION_TOLERANCE;
return res; return result;
} }
Aabb collider_aabb_from_combined_aabb(Aabb b0, Aabb b1) Aabb collider_aabb_from_combined_aabb(Aabb b0, Aabb b1)
{ {
Aabb res; Aabb result;
res.p0.x = MinF32(MinF32(b0.p0.x, b0.p1.x), MinF32(b1.p0.x, b1.p1.x)); result.p0.x = MinF32(MinF32(b0.p0.x, b0.p1.x), MinF32(b1.p0.x, b1.p1.x));
res.p0.y = MinF32(MinF32(b0.p0.y, b0.p1.y), MinF32(b1.p0.y, b1.p1.y)); result.p0.y = MinF32(MinF32(b0.p0.y, b0.p1.y), MinF32(b1.p0.y, b1.p1.y));
res.p1.x = MaxF32(MaxF32(b0.p0.x, b0.p1.x), MaxF32(b1.p0.x, b1.p1.x)); result.p1.x = MaxF32(MaxF32(b0.p0.x, b0.p1.x), MaxF32(b1.p0.x, b1.p1.x));
res.p1.y = MaxF32(MaxF32(b0.p0.y, b0.p1.y), MaxF32(b1.p0.y, b1.p1.y)); result.p1.y = MaxF32(MaxF32(b0.p0.y, b0.p1.y), MaxF32(b1.p0.y, b1.p1.y));
return res; return result;
} }
b32 collider_test_aabb(Aabb box0, Aabb box1) b32 collider_test_aabb(Aabb box0, Aabb box1)
@ -294,7 +294,7 @@ internal struct gjk_result gjk_get_simplex(CLD_Shape *shape0, CLD_Shape *shape1,
abort: abort:
#endif #endif
struct gjk_result res = { struct gjk_result result = {
.simplex = s, .simplex = s,
.overlapping = overlapping, .overlapping = overlapping,
.final_dir = dir, .final_dir = dir,
@ -303,7 +303,7 @@ internal struct gjk_result gjk_get_simplex(CLD_Shape *shape0, CLD_Shape *shape1,
#endif #endif
}; };
return res; return result;
} }
/* ========================== * /* ========================== *
@ -323,9 +323,9 @@ struct epa_result {
}; };
#if COLLIDER_DEBUG #if COLLIDER_DEBUG
internal struct epa_result epa_get_normal_from_gjk(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, struct gjk_result gjk_res, f32 min_unique_pt_dist_sq, u32 max_iterations, u32 dbg_step) internal struct epa_result epa_get_normal_from_gjk(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, struct gjk_result gjk_result, f32 min_unique_pt_dist_sq, u32 max_iterations, u32 dbg_step)
#else #else
internal struct epa_result epa_get_normal_from_gjk(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, struct gjk_result gjk_res, f32 min_unique_pt_dist_sq, u32 max_iterations) internal struct epa_result epa_get_normal_from_gjk(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, struct gjk_result gjk_result, f32 min_unique_pt_dist_sq, u32 max_iterations)
#endif #endif
{ {
TempArena scratch = BeginScratchNoConflict(); TempArena scratch = BeginScratchNoConflict();
@ -335,8 +335,8 @@ internal struct epa_result epa_get_normal_from_gjk(CLD_Shape *shape0, CLD_Shape
CLD_MenkowskiPoint *proto = 0; CLD_MenkowskiPoint *proto = 0;
u32 proto_count = 0; u32 proto_count = 0;
if (gjk_res.overlapping) { if (gjk_result.overlapping) {
CLD_MenkowskiSimplex s = gjk_res.simplex; CLD_MenkowskiSimplex s = gjk_result.simplex;
proto = PushDry(scratch.arena, CLD_MenkowskiPoint); proto = PushDry(scratch.arena, CLD_MenkowskiPoint);
{ {
Assert(s.len == 3); Assert(s.len == 3);
@ -444,32 +444,32 @@ internal struct epa_result epa_get_normal_from_gjk(CLD_Shape *shape0, CLD_Shape
proto[closest_b_index] = m; proto[closest_b_index] = m;
} }
} else { } else {
normal = NormVec2(gjk_res.final_dir); normal = NormVec2(gjk_result.final_dir);
closest_feature.len = gjk_res.simplex.len; closest_feature.len = gjk_result.simplex.len;
closest_feature.a = gjk_res.simplex.a; closest_feature.a = gjk_result.simplex.a;
closest_feature.b = gjk_res.simplex.b; closest_feature.b = gjk_result.simplex.b;
} }
#if COLLIDER_DEBUG #if COLLIDER_DEBUG
abort: abort:
#endif #endif
struct epa_result res = { struct epa_result result = {
.normal = normal, .normal = normal,
.closest_feature = closest_feature .closest_feature = closest_feature
}; };
#if COLLIDER_DEBUG #if COLLIDER_DEBUG
res.dbg_step = dbg_step; result.dbg_step = dbg_step;
u32 len = MinU32(proto_count, countof(res.prototype.points)); u32 len = MinU32(proto_count, countof(result.prototype.points));
for (u32 i = 0; i < len; ++i) { for (u32 i = 0; i < len; ++i) {
res.prototype.points[i] = proto[i].p; result.prototype.points[i] = proto[i].p;
} }
res.prototype.len = len; result.prototype.len = len;
#endif #endif
EndScratch(scratch); EndScratch(scratch);
return res; return result;
} }
/* ========================== * /* ========================== *
@ -508,12 +508,12 @@ internal struct clip_line_to_line_result clip_line_to_line(Vec2 a0, Vec2 b0, Vec
b1t = ClampF32(-vb0b1_w * -w, 0, 1); b1t = ClampF32(-vb0b1_w * -w, 0, 1);
} }
struct clip_line_to_line_result res; struct clip_line_to_line_result result;
res.a0_clipped = AddVec2(a0, MulVec2(vab0, a0t)); result.a0_clipped = AddVec2(a0, MulVec2(vab0, a0t));
res.a1_clipped = AddVec2(a1, MulVec2(vab1, a1t)); result.a1_clipped = AddVec2(a1, MulVec2(vab1, a1t));
res.b0_clipped = AddVec2(b0, MulVec2(vab0, -b0t)); result.b0_clipped = AddVec2(b0, MulVec2(vab0, -b0t));
res.b1_clipped = AddVec2(b1, MulVec2(vab1, -b1t)); result.b1_clipped = AddVec2(b1, MulVec2(vab1, -b1t));
return res; return result;
} }
internal Vec2 clip_point_to_line(Vec2 a, Vec2 b, Vec2 p, Vec2 normal) internal Vec2 clip_point_to_line(Vec2 a, Vec2 b, Vec2 p, Vec2 normal)
@ -530,8 +530,8 @@ internal Vec2 clip_point_to_line(Vec2 a, Vec2 b, Vec2 p, Vec2 normal)
t = ClampF32(vap_w * w, 0, 1); t = ClampF32(vap_w * w, 0, 1);
} }
Vec2 res = AddVec2(a, MulVec2(vab, t)); Vec2 result = AddVec2(a, MulVec2(vab, t));
return res; return result;
} }
/* ========================== * /* ========================== *
@ -540,7 +540,7 @@ internal Vec2 clip_point_to_line(Vec2 a, Vec2 b, Vec2 p, Vec2 normal)
CLD_CollisionResult collider_collision_points(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1) CLD_CollisionResult collider_collision_points(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1)
{ {
CLD_CollisionResult res = ZI; CLD_CollisionResult result = ZI;
const f32 tolerance = COLLISION_TOLERANCE; const f32 tolerance = COLLISION_TOLERANCE;
const f32 min_unique_pt_dist_sq = MIN_UNIQUE_PT_DIST_SQ; const f32 min_unique_pt_dist_sq = MIN_UNIQUE_PT_DIST_SQ;
@ -555,33 +555,33 @@ CLD_CollisionResult collider_collision_points(CLD_Shape *shape0, CLD_Shape *shap
u32 dbg_step = 0; u32 dbg_step = 0;
#endif #endif
struct gjk_result gjk_res = ZI; struct gjk_result gjk_result = ZI;
struct epa_result epa_res = ZI; struct epa_result epa_result = ZI;
/* Run GJK */ /* Run GJK */
#if COLLIDER_DEBUG #if COLLIDER_DEBUG
gjk_res = gjk_get_simplex(shape0, shape1, xf0, xf1, min_unique_pt_dist_sq, dbg_step); gjk_result = gjk_get_simplex(shape0, shape1, xf0, xf1, min_unique_pt_dist_sq, dbg_step);
dbg_step = gjk_res.dbg_step; dbg_step = gjk_result.dbg_step;
#else #else
gjk_res = gjk_get_simplex(shape0, shape1, xf0, xf1, min_unique_pt_dist_sq); gjk_result = gjk_get_simplex(shape0, shape1, xf0, xf1, min_unique_pt_dist_sq);
#endif #endif
DBGSTEP; DBGSTEP;
/* Run EPA */ /* Run EPA */
#if COLLIDER_DEBUG #if COLLIDER_DEBUG
epa_res = epa_get_normal_from_gjk(shape0, shape1, xf0, xf1, gjk_res, min_unique_pt_dist_sq, max_epa_iterations, dbg_step); epa_result = epa_get_normal_from_gjk(shape0, shape1, xf0, xf1, gjk_result, min_unique_pt_dist_sq, max_epa_iterations, dbg_step);
dbg_step = epa_res.dbg_step; dbg_step = epa_result.dbg_step;
#else #else
epa_res = epa_get_normal_from_gjk(shape0, shape1, xf0, xf1, gjk_res, min_unique_pt_dist_sq, max_epa_iterations); epa_result = epa_get_normal_from_gjk(shape0, shape1, xf0, xf1, gjk_result, min_unique_pt_dist_sq, max_epa_iterations);
#endif #endif
normal = epa_res.normal; normal = epa_result.normal;
DBGSTEP; DBGSTEP;
/* Determine collision */ /* Determine collision */
if (gjk_res.overlapping) { if (gjk_result.overlapping) {
colliding = 1; colliding = 1;
} else { } else {
CLD_MenkowskiFeature f = epa_res.closest_feature; CLD_MenkowskiFeature f = epa_result.closest_feature;
/* Shapes not overlapping, determine if distance between shapes within tolerance */ /* Shapes not overlapping, determine if distance between shapes within tolerance */
if (f.len == 1) { if (f.len == 1) {
Vec2 p = NegVec2(f.a.p); Vec2 p = NegVec2(f.a.p);
@ -606,7 +606,7 @@ CLD_CollisionResult collider_collision_points(CLD_Shape *shape0, CLD_Shape *shap
/* Max vertices must be < 16 to fit in 4 bit ids */ /* Max vertices must be < 16 to fit in 4 bit ids */
StaticAssert(countof(shape0->points) <= 16); StaticAssert(countof(shape0->points) <= 16);
CLD_MenkowskiFeature f = epa_res.closest_feature; CLD_MenkowskiFeature f = epa_result.closest_feature;
{ {
b32 collapse0 = 0; b32 collapse0 = 0;
@ -691,11 +691,11 @@ CLD_CollisionResult collider_collision_points(CLD_Shape *shape0, CLD_Shape *shap
b32 ignore_b = 1; b32 ignore_b = 1;
if (!collapse0 && !collapse1) { if (!collapse0 && !collapse1) {
/* Clip line to line */ /* Clip line to line */
struct clip_line_to_line_result clip_res = clip_line_to_line(a0.p, b0.p, a1.p, b1.p, normal); struct clip_line_to_line_result clip_result = clip_line_to_line(a0.p, b0.p, a1.p, b1.p, normal);
Vec2 a0_clipped = clip_res.a0_clipped; Vec2 a0_clipped = clip_result.a0_clipped;
Vec2 a1_clipped = clip_res.a1_clipped; Vec2 a1_clipped = clip_result.a1_clipped;
Vec2 b0_clipped = clip_res.b0_clipped; Vec2 b0_clipped = clip_result.b0_clipped;
Vec2 b1_clipped = clip_res.b1_clipped; Vec2 b1_clipped = clip_result.b1_clipped;
/* Calc midpoint between clipped a & b */ /* Calc midpoint between clipped a & b */
Vec2 va0a1_clipped = SubVec2(a1_clipped, a0_clipped); Vec2 va0a1_clipped = SubVec2(a1_clipped, a0_clipped);
Vec2 vb0b1_clipped = SubVec2(b1_clipped, b0_clipped); Vec2 vb0b1_clipped = SubVec2(b1_clipped, b0_clipped);
@ -713,10 +713,10 @@ CLD_CollisionResult collider_collision_points(CLD_Shape *shape0, CLD_Shape *shap
ignore_b = 1; ignore_b = 1;
} }
} }
res.a0_clipped = a0_clipped; result.a0_clipped = a0_clipped;
res.a1_clipped = a1_clipped; result.a1_clipped = a1_clipped;
res.b0_clipped = b0_clipped; result.b0_clipped = b0_clipped;
res.b1_clipped = b1_clipped; result.b1_clipped = b1_clipped;
} else { } else {
Vec2 p0 = a0.p; Vec2 p0 = a0.p;
Vec2 p1 = a1.p; Vec2 p1 = a1.p;
@ -734,10 +734,10 @@ CLD_CollisionResult collider_collision_points(CLD_Shape *shape0, CLD_Shape *shap
a_midpoint = AddVec2(p0, MulVec2(vsep, 0.5f)); a_midpoint = AddVec2(p0, MulVec2(vsep, 0.5f));
a_sep = DotVec2(normal, p1) - DotVec2(normal, p0); a_sep = DotVec2(normal, p1) - DotVec2(normal, p0);
ignore_a = 0; ignore_a = 0;
res.a0_clipped = p0; result.a0_clipped = p0;
res.a1_clipped = p1; result.a1_clipped = p1;
res.b0_clipped = p0; result.b0_clipped = p0;
res.b1_clipped = p1; result.b1_clipped = p1;
} }
/* Insert points */ /* Insert points */
@ -754,25 +754,25 @@ CLD_CollisionResult collider_collision_points(CLD_Shape *shape0, CLD_Shape *shap
point->point = b_midpoint; point->point = b_midpoint;
} }
res.a0 = a0.p; result.a0 = a0.p;
res.a1 = a1.p; result.a1 = a1.p;
res.b0 = b0.p; result.b0 = b0.p;
res.b1 = b1.p; result.b1 = b1.p;
} }
} }
#if COLLIDER_DEBUG #if COLLIDER_DEBUG
res.solved = 1; result.solved = 1;
abort: abort:
res.simplex = gjk_res.simplex; result.simplex = gjk_result.simplex;
res.prototype.len = epa_res.prototype.len; result.prototype.len = epa_result.prototype.len;
CopyBytes(res.prototype.points, epa_res.prototype.points, sizeof(res.prototype.points[0]) * res.prototype.len); CopyBytes(result.prototype.points, epa_result.prototype.points, sizeof(result.prototype.points[0]) * result.prototype.len);
#endif #endif
res.normal = normal; result.normal = normal;
res.points[0] = points[0]; result.points[0] = points[0];
res.points[1] = points[1]; result.points[1] = points[1];
res.num_points = num_points; result.num_points = num_points;
return res; return result;
} }
/* ========================== * /* ========================== *
@ -783,7 +783,7 @@ CLD_CollisionResult collider_collision_points(CLD_Shape *shape0, CLD_Shape *shap
CLD_ClosestResult collider_closest_points(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1) CLD_ClosestResult collider_closest_points(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1)
{ {
CLD_ClosestResult res = ZI; CLD_ClosestResult result = ZI;
const f32 tolerance = COLLISION_TOLERANCE; const f32 tolerance = COLLISION_TOLERANCE;
const f32 min_unique_pt_dist_sq = MIN_UNIQUE_PT_DIST_SQ; const f32 min_unique_pt_dist_sq = MIN_UNIQUE_PT_DIST_SQ;
@ -797,24 +797,24 @@ CLD_ClosestResult collider_closest_points(CLD_Shape *shape0, CLD_Shape *shape1,
u32 dbg_step = 0; u32 dbg_step = 0;
#endif #endif
struct gjk_result gjk_res = ZI; struct gjk_result gjk_result = ZI;
struct epa_result epa_res = ZI; struct epa_result epa_result = ZI;
/* Run GJK */ /* Run GJK */
#if COLLIDER_DEBUG #if COLLIDER_DEBUG
gjk_res = gjk_get_simplex(shape0, shape1, xf0, xf1, min_unique_pt_dist_sq, dbg_step); gjk_result = gjk_get_simplex(shape0, shape1, xf0, xf1, min_unique_pt_dist_sq, dbg_step);
dbg_step = gjk_res.dbg_step; dbg_step = gjk_result.dbg_step;
#else #else
gjk_res = gjk_get_simplex(shape0, shape1, xf0, xf1, min_unique_pt_dist_sq); gjk_result = gjk_get_simplex(shape0, shape1, xf0, xf1, min_unique_pt_dist_sq);
#endif #endif
DBGSTEP; DBGSTEP;
/* Run EPA */ /* Run EPA */
#if COLLIDER_DEBUG #if COLLIDER_DEBUG
epa_res = epa_get_normal_from_gjk(shape0, shape1, xf0, xf1, gjk_res, min_unique_pt_dist_sq, max_epa_iterations, dbg_step); epa_result = epa_get_normal_from_gjk(shape0, shape1, xf0, xf1, gjk_result, min_unique_pt_dist_sq, max_epa_iterations, dbg_step);
dbg_step = epa_res.dbg_step; dbg_step = epa_result.dbg_step;
#else #else
epa_res = epa_get_normal_from_gjk(shape0, shape1, xf0, xf1, gjk_res, min_unique_pt_dist_sq, max_epa_iterations); epa_result = epa_get_normal_from_gjk(shape0, shape1, xf0, xf1, gjk_result, min_unique_pt_dist_sq, max_epa_iterations);
#endif #endif
DBGSTEP; DBGSTEP;
@ -822,12 +822,12 @@ CLD_ClosestResult collider_closest_points(CLD_Shape *shape0, CLD_Shape *shape1,
* Resolve points * Resolve points
* ========================== */ * ========================== */
colliding = gjk_res.overlapping; colliding = gjk_result.overlapping;
CLD_MenkowskiFeature f = epa_res.closest_feature; CLD_MenkowskiFeature f = epa_result.closest_feature;
if (f.len == 1) { if (f.len == 1) {
p0 = f.a.s0.p; p0 = f.a.s0.p;
p1 = f.a.s1.p; p1 = f.a.s1.p;
colliding = gjk_res.overlapping || Vec2LenSq(NegVec2(f.a.p)) <= (tolerance * tolerance); colliding = gjk_result.overlapping || Vec2LenSq(NegVec2(f.a.p)) <= (tolerance * tolerance);
} else { } else {
Assert(f.len == 2); Assert(f.len == 2);
/* FIXME: Winding order dependent? */ /* FIXME: Winding order dependent? */
@ -846,21 +846,21 @@ CLD_ClosestResult collider_closest_points(CLD_Shape *shape0, CLD_Shape *shape1,
p1 = SubVec2(f.b.s1.p, f.a.s1.p); p1 = SubVec2(f.b.s1.p, f.a.s1.p);
p1 = MulVec2(p1, ratio); p1 = MulVec2(p1, ratio);
p1 = AddVec2(p1, f.a.s1.p); p1 = AddVec2(p1, f.a.s1.p);
colliding = gjk_res.overlapping || Vec2LenSq(SubVec2(p1, p0)) <= (tolerance * tolerance); colliding = gjk_result.overlapping || Vec2LenSq(SubVec2(p1, p0)) <= (tolerance * tolerance);
} }
#if COLLIDER_DEBUG #if COLLIDER_DEBUG
res.solved = 1; result.solved = 1;
abort: abort:
res.simplex = gjk_res.simplex; result.simplex = gjk_result.simplex;
res.prototype.len = epa_res.prototype.len; result.prototype.len = epa_result.prototype.len;
CopyBytes(res.prototype.points, epa_res.prototype.points, sizeof(res.prototype.points[0]) *res.prototype.len); CopyBytes(result.prototype.points, epa_result.prototype.points, sizeof(result.prototype.points[0]) *result.prototype.len);
res.simplex = gjk_res.simplex; result.simplex = gjk_result.simplex;
#endif #endif
res.p0 = p0; result.p0 = p0;
res.p1 = p1; result.p1 = p1;
res.colliding = colliding; result.colliding = colliding;
return res; return result;
} }
/* ========================== * /* ========================== *
@ -885,12 +885,12 @@ f32 collider_time_of_impact(CLD_Shape *c0, CLD_Shape *c1,
Vec2 dir; Vec2 dir;
Vec2 dir_neg; Vec2 dir_neg;
{ {
CLD_ClosestResult closest_points_res = collider_closest_points(c0, c1, xf0_t0, xf1_t0); CLD_ClosestResult closest_points = collider_closest_points(c0, c1, xf0_t0, xf1_t0);
if (closest_points_res.colliding) { if (closest_points.colliding) {
/* Shapes are penetrating at t=0 */ /* Shapes are penetrating at t=0 */
return 0; return 0;
} }
dir = SubVec2(closest_points_res.p1, closest_points_res.p0); dir = SubVec2(closest_points.p1, closest_points.p0);
t0_sep = Vec2Len(dir); t0_sep = Vec2Len(dir);
dir = DivVec2(dir, t0_sep); /* Normalize */ dir = DivVec2(dir, t0_sep); /* Normalize */
dir_neg = NegVec2(dir); dir_neg = NegVec2(dir);
@ -949,24 +949,24 @@ f32 collider_time_of_impact(CLD_Shape *c0, CLD_Shape *c1,
/* TODO: Remove this (debugging) */ /* TODO: Remove this (debugging) */
V2Array menkowski(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, u32 detail) V2Array menkowski(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, u32 detail)
{ {
V2Array res = { .points = PushDry(arena, Vec2) }; V2Array result = { .points = PushDry(arena, Vec2) };
for (u64 i = 0; i < detail; ++i) { for (u64 i = 0; i < detail; ++i) {
f32 angle = ((f32)i / detail) * (2 * Pi); f32 angle = ((f32)i / detail) * (2 * Pi);
Vec2 dir = Vec2FromAngle(angle); Vec2 dir = Vec2FromAngle(angle);
CLD_MenkowskiPoint m = get_menkowski_point(shape0, shape1, xf0, xf1, dir); CLD_MenkowskiPoint m = get_menkowski_point(shape0, shape1, xf0, xf1, dir);
if (res.count == 0 || !EqVec2(m.p, res.points[res.count - 1])) { if (result.count == 0 || !EqVec2(m.p, result.points[result.count - 1])) {
*PushStructNoZero(arena, Vec2) = m.p; *PushStructNoZero(arena, Vec2) = m.p;
++res.count; ++result.count;
} }
} }
return res; return result;
} }
/* TODO: Remove this (debugging) */ /* TODO: Remove this (debugging) */
V2Array cloud(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1) V2Array cloud(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1)
{ {
/* FIXME: Account for radius */ /* FIXME: Account for radius */
V2Array res = { .points = PushDry(arena, Vec2) }; V2Array result = { .points = PushDry(arena, Vec2) };
Vec2 *points0 = shape0->points; Vec2 *points0 = shape0->points;
Vec2 *points1 = shape1->points; Vec2 *points1 = shape1->points;
u32 count0 = shape0->count; u32 count0 = shape0->count;
@ -976,10 +976,10 @@ V2Array cloud(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xfo
for (u64 j = 0; j < count1; ++j) { for (u64 j = 0; j < count1; ++j) {
Vec2 p1 = MulXformV2(xf1, points1[j]); Vec2 p1 = MulXformV2(xf1, points1[j]);
*PushStructNoZero(arena, Vec2) = SubVec2(p0, p1); *PushStructNoZero(arena, Vec2) = SubVec2(p0, p1);
++res.count; ++result.count;
} }
} }
return res; return result;
} }
/* ========================== * /* ========================== *

View File

@ -69,7 +69,7 @@
# define SIM_MAX_ANGULAR_VELOCITY F32Infinity # define SIM_MAX_ANGULAR_VELOCITY F32Infinity
#endif #endif
#define COLLIDER_DEBUG 0 #define COLLIDER_DEBUG 1
#define COLLIDER_DEBUG_DETAILED 1 #define COLLIDER_DEBUG_DETAILED 1
#define COLLIDER_DEBUG_DETAILED_DRAW_MENKOWSKI 1 #define COLLIDER_DEBUG_DETAILED_DRAW_MENKOWSKI 1

View File

@ -6,8 +6,8 @@ DXC_Result dxc_compile(Arena *arena, String shader_source, i32 num_args, String
(UNUSED)shader_source; (UNUSED)shader_source;
(UNUSED)num_args; (UNUSED)num_args;
(UNUSED)args; (UNUSED)args;
DXC_Result res = ZI; DXC_Result result = ZI;
return res; return result;
} }
#else #else
@ -33,7 +33,7 @@ DXC_Result dxc_compile(Arena *arena, String shader_source, i32 num_args, String
{ {
__prof; __prof;
TempArena scratch = BeginScratch(arena); TempArena scratch = BeginScratch(arena);
DXC_Result res = ZI; DXC_Result result = ZI;
wchar_t **wstr_args = PushStructs(scratch.arena, wchar_t *, num_args); wchar_t **wstr_args = PushStructs(scratch.arena, wchar_t *, num_args);
for (i32 i = 0; i < num_args; ++i) { for (i32 i = 0; i < num_args; ++i) {
@ -64,28 +64,28 @@ DXC_Result dxc_compile(Arena *arena, String shader_source, i32 num_args, String
String blob_str = ZI; String blob_str = ZI;
blob_str.len = dxc_errors->GetBufferSize(); blob_str.len = dxc_errors->GetBufferSize();
blob_str.text = (u8 *)dxc_errors->GetBufferPointer(); blob_str.text = (u8 *)dxc_errors->GetBufferPointer();
res.errors = CopyString(arena, blob_str); result.errors = CopyString(arena, blob_str);
} }
/* Get status */ /* Get status */
HRESULT dxc_hr = 0; HRESULT dxc_hr = 0;
compile_results->GetStatus(&dxc_hr); compile_results->GetStatus(&dxc_hr);
res.success = SUCCEEDED(dxc_hr); result.success = SUCCEEDED(dxc_hr);
/* CopyStruct shader output */ /* CopyStruct shader output */
if (res.success) { if (result.success) {
CComPtr<IDxcBlob> dxc_shader = 0; CComPtr<IDxcBlob> dxc_shader = 0;
compile_results->GetOutput(DXC_OUT_OBJECT, IID_PPV_ARGS(&dxc_shader), 0); compile_results->GetOutput(DXC_OUT_OBJECT, IID_PPV_ARGS(&dxc_shader), 0);
if (dxc_shader != 0) { if (dxc_shader != 0) {
String blob_str = ZI; String blob_str = ZI;
blob_str.len = dxc_shader->GetBufferSize(); blob_str.len = dxc_shader->GetBufferSize();
blob_str.text = (u8 *)dxc_shader->GetBufferPointer(); blob_str.text = (u8 *)dxc_shader->GetBufferPointer();
res.dxc = CopyString(arena, blob_str); result.dxc = CopyString(arena, blob_str);
} }
} }
EndScratch(scratch); EndScratch(scratch);
return res; return result;
} }
#endif #endif

View File

@ -1250,12 +1250,12 @@ internal Readonly struct pipeline g_nil_pipeline = ZI;
internal struct pipeline *pipeline_from_name(struct pipeline_scope *scope, String name) internal struct pipeline *pipeline_from_name(struct pipeline_scope *scope, String name)
{ {
__prof; __prof;
struct pipeline *res = &g_nil_pipeline; struct pipeline *result = &g_nil_pipeline;
u64 hash = HashFnv64(Fnv64Basis, name); u64 hash = HashFnv64(Fnv64Basis, name);
struct pipeline *tmp = (struct pipeline *)DictValueFromHash(scope->refs, hash); struct pipeline *tmp = (struct pipeline *)DictValueFromHash(scope->refs, hash);
if (tmp) { if (tmp) {
res = tmp; result = tmp;
} else { } else {
{ {
P_Lock lock = P_LockE(&G.pipelines_mutex); P_Lock lock = P_LockE(&G.pipelines_mutex);
@ -1267,11 +1267,11 @@ internal struct pipeline *pipeline_from_name(struct pipeline_scope *scope, Strin
} }
if (tmp) { if (tmp) {
SetDictValue(scope->arena, scope->refs, hash, (u64)tmp); SetDictValue(scope->arena, scope->refs, hash, (u64)tmp);
res = tmp; result = tmp;
} }
} }
return res; return result;
} }
internal void pipeline_register(u64 num_pipelines, struct pipeline **pipelines) internal void pipeline_register(u64 num_pipelines, struct pipeline **pipelines)
@ -2041,18 +2041,18 @@ internal u64 command_buffer_hash_from_size(u64 size)
internal u64 align_up_pow2(u64 v) internal u64 align_up_pow2(u64 v)
{ {
u64 res = 0; u64 result = 0;
if (v > 0) { if (v > 0) {
res = v - 1; result = v - 1;
res |= res >> 1; result |= result >> 1;
res |= res >> 2; result |= result >> 2;
res |= res >> 4; result |= result >> 4;
res |= res >> 8; result |= result >> 8;
res |= res >> 16; result |= result >> 16;
res |= res >> 32; result |= result >> 32;
++res; ++result;
} }
return res; return result;
} }
#define command_list_push_buffer(cl, count, elems) _command_list_push_buffer((cl), count * ((elems) ? sizeof(*(elems)) : 0), (elems), (elems) ? sizeof(*(elems)) : 1) #define command_list_push_buffer(cl, count, elems) _command_list_push_buffer((cl), count * ((elems) ? sizeof(*(elems)) : 0), (elems), (elems) ? sizeof(*(elems)) : 1)
@ -2502,9 +2502,9 @@ Inline Mat4x4 calculate_vp(Xform view, f32 viewport_width, f32 viewport_height)
internal D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle_from_descriptor(struct descriptor *descriptor, struct command_descriptor_heap *cdh) internal D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle_from_descriptor(struct descriptor *descriptor, struct command_descriptor_heap *cdh)
{ {
struct D3D12_GPU_DESCRIPTOR_HANDLE res = ZI; struct D3D12_GPU_DESCRIPTOR_HANDLE result = ZI;
res.ptr = cdh->start_gpu_handle.ptr + descriptor->index * G.desc_sizes[descriptor->heap->type]; result.ptr = cdh->start_gpu_handle.ptr + descriptor->index * G.desc_sizes[descriptor->heap->type];
return res; return result;
} }
/* ========================== * /* ========================== *
@ -3153,7 +3153,7 @@ G_Resource *gp_run_render(G_RenderSig *gp_render_sig, G_RenderParams params)
G_MemoryInfo gp_query_memory_info(void) G_MemoryInfo gp_query_memory_info(void)
{ {
G_MemoryInfo res = ZI; G_MemoryInfo result = ZI;
HRESULT hr = 0; HRESULT hr = 0;
IDXGIAdapter3 *dxgiAdapter3 = 0; IDXGIAdapter3 *dxgiAdapter3 = 0;
@ -3163,19 +3163,19 @@ G_MemoryInfo gp_query_memory_info(void)
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
struct DXGI_QUERY_VIDEO_MEMORY_INFO info = ZI; struct DXGI_QUERY_VIDEO_MEMORY_INFO info = ZI;
IDXGIAdapter3_QueryVideoMemoryInfo(dxgiAdapter3, 0, DXGI_MEMORY_SEGMENT_GROUP_LOCAL, &info); IDXGIAdapter3_QueryVideoMemoryInfo(dxgiAdapter3, 0, DXGI_MEMORY_SEGMENT_GROUP_LOCAL, &info);
res.local_used = info.CurrentUsage; result.local_used = info.CurrentUsage;
res.local_budget = info.Budget; result.local_budget = info.Budget;
} }
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
struct DXGI_QUERY_VIDEO_MEMORY_INFO info = ZI; struct DXGI_QUERY_VIDEO_MEMORY_INFO info = ZI;
IDXGIAdapter3_QueryVideoMemoryInfo(dxgiAdapter3, 0, DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, &info); IDXGIAdapter3_QueryVideoMemoryInfo(dxgiAdapter3, 0, DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, &info);
res.non_local_used = info.CurrentUsage; result.non_local_used = info.CurrentUsage;
res.non_local_budget = info.Budget; result.non_local_budget = info.Budget;
} }
if (dxgiAdapter3) { if (dxgiAdapter3) {
IDXGIAdapter_Release(dxgiAdapter3); IDXGIAdapter_Release(dxgiAdapter3);
} }
return res; return result;
} }
/* ========================== * /* ========================== *

View File

@ -89,9 +89,9 @@ internal struct token *push_token(Arena *arena, struct token_list *list)
internal struct token_list lex(Arena *arena, String src) internal struct token_list lex(Arena *arena, String src)
{ {
struct token_list res = ZI; struct token_list result = ZI;
struct token *bof = push_token(arena, &res); struct token *bof = push_token(arena, &result);
bof->type = TOKEN_TYPE_BOF; bof->type = TOKEN_TYPE_BOF;
u64 pos = 0; u64 pos = 0;
@ -113,7 +113,7 @@ internal struct token_list lex(Arena *arena, String src)
} }
/* Create token */ /* Create token */
struct token *t = push_token(arena, &res); struct token *t = push_token(arena, &result);
t->start = pos; t->start = pos;
if (pos >= src.len) { if (pos >= src.len) {
@ -341,13 +341,13 @@ internal struct token_list lex(Arena *arena, String src)
t->end = pos; t->end = pos;
/* Exit early if unknown token encountered */ /* Exit early if unknown token encountered */
return res; return result;
} else { } else {
t->end = pos; t->end = pos;
} }
} }
return res; return result;
} }
/* ========================== * /* ========================== *
@ -473,7 +473,7 @@ internal f64 interpret_number(String src)
} }
} }
f64 res = 0; f64 result = 0;
/* Process whole part */ /* Process whole part */
if (whole_present) { if (whole_present) {
@ -481,10 +481,10 @@ internal f64 interpret_number(String src)
while (pos <= whole_right) { while (pos <= whole_right) {
u8 digit = MinU8(src.text[pos] - 48, 9); u8 digit = MinU8(src.text[pos] - 48, 9);
u64 exp = whole_right - pos; u64 exp = whole_right - pos;
res += digit * PowU64(10, exp); result += digit * PowU64(10, exp);
++pos; ++pos;
} }
res *= whole_sign; result *= whole_sign;
} }
/* Process fraction part */ /* Process fraction part */
@ -498,7 +498,7 @@ internal f64 interpret_number(String src)
++pos; ++pos;
} }
res += (f64)frac_whole / PowU64(10, (fraction_right - fraction_left + 1)); result += (f64)frac_whole / PowU64(10, (fraction_right - fraction_left + 1));
} }
/* Process exponent part */ /* Process exponent part */
@ -513,18 +513,18 @@ internal f64 interpret_number(String src)
} }
if (exponent_sign >= 0) { if (exponent_sign >= 0) {
res *= PowU64(10, exponent_whole); result *= PowU64(10, exponent_whole);
} else { } else {
res /= PowU64(10, exponent_whole); result /= PowU64(10, exponent_whole);
} }
} }
return res; return result;
} }
internal String interpret_string(Arena *arena, String src, String *error) internal String interpret_string(Arena *arena, String src, String *error)
{ {
String res = { String result = {
.len = 0, .len = 0,
.text = PushDry(arena, u8) .text = PushDry(arena, u8)
}; };
@ -533,7 +533,7 @@ internal String interpret_string(Arena *arena, String src, String *error)
if (error) { if (error) {
*error = Lit("Malformed string."); *error = Lit("Malformed string.");
} }
return res; return result;
} }
/* Ignore beginning quote */ /* Ignore beginning quote */
u64 pos = 1; u64 pos = 1;
@ -550,37 +550,37 @@ internal String interpret_string(Arena *arena, String src, String *error)
case '"': case '"':
case '\\': case '\\':
case '/': { case '/': {
append_char(arena, &res, src.text[pos]); append_char(arena, &result, src.text[pos]);
++pos; ++pos;
} break; } break;
/* Backspace */ /* Backspace */
case 'b': { case 'b': {
append_char(arena, &res, '\b'); append_char(arena, &result, '\b');
++pos; ++pos;
} break; } break;
/* Formfeed */ /* Formfeed */
case 'f': { case 'f': {
append_char(arena, &res, '\f'); append_char(arena, &result, '\f');
++pos; ++pos;
} break; } break;
/* Linefeed */ /* Linefeed */
case 'n': { case 'n': {
append_char(arena, &res, '\n'); append_char(arena, &result, '\n');
++pos; ++pos;
} break; } break;
/* Carriage return */ /* Carriage return */
case 'r': { case 'r': {
append_char(arena, &res, '\r'); append_char(arena, &result, '\r');
++pos; ++pos;
} break; } break;
/* Horizontal tab */ /* Horizontal tab */
case 't': { case 't': {
append_char(arena, &res, '\t'); append_char(arena, &result, '\t');
++pos; ++pos;
} break; } break;
@ -594,7 +594,7 @@ internal String interpret_string(Arena *arena, String src, String *error)
default: { default: {
if (error) { if (error) {
*error = Lit("Invalid escape character in string."); *error = Lit("Invalid escape character in string.");
return res; return result;
} }
} break; } break;
} }
@ -612,7 +612,7 @@ internal String interpret_string(Arena *arena, String src, String *error)
} break; } break;
default: { default: {
append_char(arena, &res, src.text[pos]); append_char(arena, &result, src.text[pos]);
++pos; ++pos;
} break; } break;
} }
@ -625,7 +625,7 @@ internal String interpret_string(Arena *arena, String src, String *error)
} }
} }
return res; return result;
} }
/* ========================== * /* ========================== *

View File

@ -72,19 +72,19 @@ typedef struct K_float4x4 K_float4x4;
struct K_float4x4 { f32 v[4][4]; }; struct K_float4x4 { f32 v[4][4]; };
Inline struct K_float4x4 K_Float4x4FromMat4x4(Mat4x4 v) Inline struct K_float4x4 K_Float4x4FromMat4x4(Mat4x4 v)
{ {
struct K_float4x4 res; struct K_float4x4 result;
StaticAssert(sizeof(res) == sizeof(v)); StaticAssert(sizeof(result) == sizeof(v));
CopyBytes(&res, v.e, sizeof(res)); CopyBytes(&result, v.e, sizeof(result));
return res; return result;
} }
struct K_float2x3 { f32 v[2][3]; }; struct K_float2x3 { f32 v[2][3]; };
Inline struct K_float2x3 K_Float2x3FromXform(Xform v) Inline struct K_float2x3 K_Float2x3FromXform(Xform v)
{ {
struct K_float2x3 res; struct K_float2x3 result;
StaticAssert(sizeof(res) == sizeof(v)); StaticAssert(sizeof(result) == sizeof(v));
CopyBytes(&res, &v, sizeof(res)); CopyBytes(&result, &v, sizeof(result));
return res; return result;
} }
#else #else
@ -106,12 +106,12 @@ Inline struct K_float2x3 K_Float2x3FromXform(Xform v)
float4 float4_from_uint_norm(uint v) float4 float4_from_uint_norm(uint v)
{ {
float4 res; float4 result;
res.r = ((v >> 0) & 0xFF) / 255.0; result.r = ((v >> 0) & 0xFF) / 255.0;
res.g = ((v >> 8) & 0xFF) / 255.0; result.g = ((v >> 8) & 0xFF) / 255.0;
res.b = ((v >> 16) & 0xFF) / 255.0; result.b = ((v >> 16) & 0xFF) / 255.0;
res.a = ((v >> 24) & 0xFF) / 255.0; result.a = ((v >> 24) & 0xFF) / 255.0;
return res; return result;
} }
/* Linear color from normalized sRGB */ /* Linear color from normalized sRGB */

View File

@ -194,7 +194,7 @@ M_Handle mixer_play_ex(SND_Sound *sound, M_TrackDesc desc)
/* NOTE: This is quite inefficient. */ /* NOTE: This is quite inefficient. */
M_TrackDesc mixer_track_get(M_Handle handle) M_TrackDesc mixer_track_get(M_Handle handle)
{ {
M_TrackDesc res = ZI; M_TrackDesc result = ZI;
struct track *track = track_from_handle(handle); struct track *track = track_from_handle(handle);
if (track) { if (track) {
@ -204,13 +204,13 @@ M_TrackDesc mixer_track_get(M_Handle handle)
/* Confirm handle is still valid now that we're locked */ /* Confirm handle is still valid now that we're locked */
track = track_from_handle(handle); track = track_from_handle(handle);
if (track) { if (track) {
res = track->desc; result = track->desc;
} }
} }
P_Unlock(&lock); P_Unlock(&lock);
} }
return res; return result;
} }
/* NOTE: This is quite inefficient. */ /* NOTE: This is quite inefficient. */
@ -263,9 +263,9 @@ M_PcmF32 mixer_update(Arena *arena, u64 frame_count)
TempArena scratch = BeginScratch(arena); TempArena scratch = BeginScratch(arena);
M_PcmF32 res = ZI; M_PcmF32 result = ZI;
res.count = frame_count * 2; result.count = frame_count * 2;
res.samples = PushStructs(arena, f32, res.count); result.samples = PushStructs(arena, f32, result.count);
Vec2 listener_pos = VEC2(0, 0); Vec2 listener_pos = VEC2(0, 0);
Vec2 listener_dir = VEC2(0, 0); Vec2 listener_dir = VEC2(0, 0);
@ -336,8 +336,8 @@ M_PcmF32 mixer_update(Arena *arena, u64 frame_count)
mix->source_pos = source_sample_pos_end; mix->source_pos = source_sample_pos_end;
M_PcmF32 mix_pcm = { M_PcmF32 mix_pcm = {
.count = res.count, .count = result.count,
.samples = PushStructs(scratch.arena, f32, res.count) .samples = PushStructs(scratch.arena, f32, result.count)
}; };
/* ========================== * /* ========================== *
@ -456,7 +456,7 @@ M_PcmF32 mixer_update(Arena *arena, u64 frame_count)
* ========================== */ * ========================== */
for (u64 i = 0; i < mix_pcm.count; ++i) { for (u64 i = 0; i < mix_pcm.count; ++i) {
res.samples[i] += mix_pcm.samples[i] * desc.volume; result.samples[i] += mix_pcm.samples[i] * desc.volume;
} }
} }
@ -477,5 +477,5 @@ M_PcmF32 mixer_update(Arena *arena, u64 frame_count)
} }
EndScratch(scratch); EndScratch(scratch);
return res; return result;
} }

View File

@ -20,7 +20,7 @@
MP3_Result mp3_decode(Arena *arena, String encoded, u32 sample_rate, u32 flags) MP3_Result mp3_decode(Arena *arena, String encoded, u32 sample_rate, u32 flags)
{ {
MP3_Result res = ZI; MP3_Result result = ZI;
u64 bytes_per_sample = 2; u64 bytes_per_sample = 2;
u64 channel_count; u64 channel_count;
@ -84,7 +84,7 @@ MP3_Result mp3_decode(Arena *arena, String encoded, u32 sample_rate, u32 flags)
* Read * Read
* ========================== */ * ========================== */
res.samples = PushDry(arena, i16); result.samples = PushDry(arena, i16);
u64 sample_bytes_read = 0; u64 sample_bytes_read = 0;
for (;;) { for (;;) {
IMFSample *sample; IMFSample *sample;
@ -96,7 +96,7 @@ MP3_Result mp3_decode(Arena *arena, String encoded, u32 sample_rate, u32 flags)
/* Check if done */ /* Check if done */
if (sample_flags & MF_SOURCE_READERF_ENDOFSTREAM) { if (sample_flags & MF_SOURCE_READERF_ENDOFSTREAM) {
res.success = 1; result.success = 1;
break; break;
} }
Assert(sample_flags == 0); Assert(sample_flags == 0);
@ -119,7 +119,7 @@ MP3_Result mp3_decode(Arena *arena, String encoded, u32 sample_rate, u32 flags)
IMFSample_Release(sample); IMFSample_Release(sample);
} }
res.samples_count = sample_bytes_read / bytes_per_sample; result.samples_count = sample_bytes_read / bytes_per_sample;
/* ========================== * /* ========================== *
* Cleanup * Cleanup
@ -130,5 +130,5 @@ MP3_Result mp3_decode(Arena *arena, String encoded, u32 sample_rate, u32 flags)
IStream_Release(i_stream); IStream_Release(i_stream);
MFShutdown(); MFShutdown();
return res; return result;
} }

View File

@ -211,19 +211,19 @@ internal struct host_channel *host_single_channel_from_id(N_Host *host, N_Channe
internal struct host_channel_list host_channels_from_id(Arena *arena, N_Host *host, N_ChannelId channel_id) internal struct host_channel_list host_channels_from_id(Arena *arena, N_Host *host, N_ChannelId channel_id)
{ {
struct host_channel_list res = ZI; struct host_channel_list result = ZI;
if (host_channel_id_eq(channel_id, HOST_CHANNEL_ID_ALL)) { if (host_channel_id_eq(channel_id, HOST_CHANNEL_ID_ALL)) {
for (u64 i = 0; i < host->num_channels_reserved; ++i) { for (u64 i = 0; i < host->num_channels_reserved; ++i) {
struct host_channel *channel = &host->channels[i]; struct host_channel *channel = &host->channels[i];
if (channel->valid) { if (channel->valid) {
struct host_channel_node *n = PushStruct(arena, struct host_channel_node); struct host_channel_node *n = PushStruct(arena, struct host_channel_node);
n->channel = channel; n->channel = channel;
if (res.last) { if (result.last) {
res.last->next = n; result.last->next = n;
} else { } else {
res.first = n; result.first = n;
} }
res.last = n; result.last = n;
} }
} }
} else { } else {
@ -231,11 +231,11 @@ internal struct host_channel_list host_channels_from_id(Arena *arena, N_Host *ho
if (channel->valid) { if (channel->valid) {
struct host_channel_node *n = PushStruct(arena, struct host_channel_node); struct host_channel_node *n = PushStruct(arena, struct host_channel_node);
n->channel = channel; n->channel = channel;
res.first = n; result.first = n;
res.last = n; result.last = n;
} }
} }
return res; return result;
} }
internal struct host_channel *host_channel_alloc(N_Host *host, P_Address address) internal struct host_channel *host_channel_alloc(N_Host *host, P_Address address)
@ -324,10 +324,10 @@ internal void host_channel_release(struct host_channel *channel)
internal u64 hash_from_channel_msg(N_ChannelId channel_id, u64 msg_id) internal u64 hash_from_channel_msg(N_ChannelId channel_id, u64 msg_id)
{ {
u64 res = Fnv64Basis; u64 result = Fnv64Basis;
res = HashFnv64(res, StringFromStruct(&channel_id)); result = HashFnv64(result, StringFromStruct(&channel_id));
res = HashFnv64(res, StringFromStruct(&msg_id)); result = HashFnv64(result, StringFromStruct(&msg_id));
return res; return result;
} }
internal struct host_msg_assembler *host_get_msg_assembler(N_Host *host, N_ChannelId channel_id, u64 msg_id) internal struct host_msg_assembler *host_get_msg_assembler(N_Host *host, N_ChannelId channel_id, u64 msg_id)
@ -612,10 +612,10 @@ N_EventList host_update_begin(Arena *arena, N_Host *host)
{ {
__profn("Read socket"); __profn("Read socket");
P_Sock *sock = host->sock; P_Sock *sock = host->sock;
P_SockReadResult res = ZI; P_SockReadResult result = ZI;
while ((res = P_ReadSock(scratch.arena, sock)).valid) { while ((result = P_ReadSock(scratch.arena, sock)).valid) {
P_Address address = res.address; P_Address address = result.address;
String data = res.data; String data = result.data;
if (data.len > 0) { if (data.len > 0) {
struct host_rcv_packet *packet = PushStruct(scratch.arena, struct host_rcv_packet); struct host_rcv_packet *packet = PushStruct(scratch.arena, struct host_rcv_packet);
packet->address = address; packet->address = address;

View File

@ -145,8 +145,8 @@ b32 P_W32_TryReleaseThread(P_W32_Thread *thread, f32 timeout_seconds)
{ {
/* Wait for thread to stop */ /* Wait for thread to stop */
DWORD timeout_ms = (timeout_seconds > 10000000) ? INFINITE : RoundF32ToI32(timeout_seconds * 1000); DWORD timeout_ms = (timeout_seconds > 10000000) ? INFINITE : RoundF32ToI32(timeout_seconds * 1000);
DWORD wait_res = WaitForSingleObject(handle, timeout_ms); DWORD wait_result = WaitForSingleObject(handle, timeout_ms);
if (wait_res == WAIT_OBJECT_0) if (wait_result == WAIT_OBJECT_0)
{ {
/* Release thread */ /* Release thread */
success = 1; success = 1;
@ -1195,7 +1195,7 @@ P_DateTime P_W32_DateTimeFromWin32SystemTime(SYSTEMTIME st)
String P_W32_StringFromWin32Path(Arena *arena, wchar_t *src) String P_W32_StringFromWin32Path(Arena *arena, wchar_t *src)
{ {
String res = { String result = {
.len = 0, .len = 0,
.text = PushDry(arena, u8) .text = PushDry(arena, u8)
}; };
@ -1215,11 +1215,11 @@ String P_W32_StringFromWin32Path(Arena *arena, wchar_t *src)
} }
dest[i] = byte; dest[i] = byte;
} }
res.len += encoded.count8; result.len += encoded.count8;
src += decoded.advance16; src += decoded.advance16;
} }
return res; return result;
} }
//////////////////////////////// ////////////////////////////////
@ -1852,24 +1852,24 @@ LRESULT CALLBACK P_W32_Win32WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARA
P_W32_Address P_W32_Win32AddressFromPlatformAddress(P_Address addr) P_W32_Address P_W32_Win32AddressFromPlatformAddress(P_Address addr)
{ {
P_W32_Address res = ZI; P_W32_Address result = ZI;
if (addr.family == P_AddressFamily_Ipv4) if (addr.family == P_AddressFamily_Ipv4)
{ {
res.family = AF_INET; result.family = AF_INET;
res.size = sizeof(struct sockaddr_in); result.size = sizeof(struct sockaddr_in);
res.sin.sin_port = addr.portnb; result.sin.sin_port = addr.portnb;
res.sin.sin_family = res.family; result.sin.sin_family = result.family;
CopyBytes(&res.sin.sin_addr, addr.ipnb, 4); CopyBytes(&result.sin.sin_addr, addr.ipnb, 4);
} }
else else
{ {
res.family = AF_INET6; result.family = AF_INET6;
res.sin6.sin6_port = addr.portnb; result.sin6.sin6_port = addr.portnb;
res.sin6.sin6_family = res.family; result.sin6.sin6_family = result.family;
res.size = sizeof(struct sockaddr_in6); result.size = sizeof(struct sockaddr_in6);
CopyBytes(&res.sin6.sin6_addr.s6_addr, addr.ipnb, 16); CopyBytes(&result.sin6.sin6_addr.s6_addr, addr.ipnb, 16);
} }
return res; return result;
} }
/* If supplied address has ip INADDR_ANY (0), convert ip to localhost */ /* If supplied address has ip INADDR_ANY (0), convert ip to localhost */
@ -1915,22 +1915,22 @@ P_W32_Address P_W32_ConvertAnyaddrToLocalhost(P_W32_Address addr)
P_Address P_W32_PlatformAddressFromWin32Address(P_W32_Address ws_addr) P_Address P_W32_PlatformAddressFromWin32Address(P_W32_Address ws_addr)
{ {
P_Address res = ZI; P_Address result = ZI;
if (ws_addr.family == AF_INET) if (ws_addr.family == AF_INET)
{ {
res.family = P_AddressFamily_Ipv4; result.family = P_AddressFamily_Ipv4;
res.portnb = ws_addr.sin.sin_port; result.portnb = ws_addr.sin.sin_port;
CopyBytes(res.ipnb, &ws_addr.sin.sin_addr, 4); CopyBytes(result.ipnb, &ws_addr.sin.sin_addr, 4);
res.valid = 1; result.valid = 1;
} }
else if (ws_addr.family == AF_INET6) else if (ws_addr.family == AF_INET6)
{ {
res.family = P_AddressFamily_Ipv6; result.family = P_AddressFamily_Ipv6;
res.portnb = ws_addr.sin6.sin6_port; result.portnb = ws_addr.sin6.sin6_port;
CopyBytes(res.ipnb, &ws_addr.sin6.sin6_addr.s6_addr, 16); CopyBytes(result.ipnb, &ws_addr.sin6.sin6_addr.s6_addr, 16);
res.valid = 1; result.valid = 1;
} }
return res; return result;
} }
//////////////////////////////// ////////////////////////////////
@ -2068,8 +2068,8 @@ i64 P_TimeNs(void)
struct P_W32_SharedCtx *g = &P_W32_shared_ctx; struct P_W32_SharedCtx *g = &P_W32_shared_ctx;
LARGE_INTEGER qpc; LARGE_INTEGER qpc;
QueryPerformanceCounter(&qpc); QueryPerformanceCounter(&qpc);
i64 res = (qpc.QuadPart - g->timer_start_qpc) * g->ns_per_qpc; i64 result = (qpc.QuadPart - g->timer_start_qpc) * g->ns_per_qpc;
return res; return result;
} }
//////////////////////////////// ////////////////////////////////
@ -2079,14 +2079,14 @@ String P_GetWritePath(Arena *arena)
{ {
u16 *p = 0; u16 *p = 0;
/* TODO: cache this? */ /* TODO: cache this? */
HRESULT res = SHGetKnownFolderPath( HRESULT result = SHGetKnownFolderPath(
&FOLDERID_LocalAppData, &FOLDERID_LocalAppData,
0, 0,
0, 0,
&p &p
); );
String path = ZI; String path = ZI;
if (res == S_OK) if (result == S_OK)
{ {
path = P_W32_StringFromWin32Path(arena, p); path = P_W32_StringFromWin32Path(arena, p);
} }
@ -2521,14 +2521,14 @@ P_WatchInfoList P_ReadWatchWait(Arena *arena, P_Watch *dw)
ov.hEvent, ov.hEvent,
w32_watch->wake_handle w32_watch->wake_handle
}; };
DWORD wait_res = WaitForMultipleObjects(2, handles, 0, INFINITE); DWORD wait_result = WaitForMultipleObjects(2, handles, 0, INFINITE);
if (wait_res == WAIT_OBJECT_0) if (wait_result == WAIT_OBJECT_0)
{ {
i64 offset = 0; i64 offset = 0;
while (!done) while (!done)
{ {
FILE_NOTIFY_INFORMATION *res = (FILE_NOTIFY_INFORMATION *)(w32_watch->results_buff + offset); FILE_NOTIFY_INFORMATION *result = (FILE_NOTIFY_INFORMATION *)(w32_watch->results_buff + offset);
P_WatchInfo *info = PushStruct(arena, P_WatchInfo); P_WatchInfo *info = PushStruct(arena, P_WatchInfo);
if (list.last) if (list.last)
@ -2544,8 +2544,8 @@ P_WatchInfoList P_ReadWatchWait(Arena *arena, P_Watch *dw)
++list.count; ++list.count;
String16 name16 = ZI; String16 name16 = ZI;
name16.text = res->FileName; name16.text = result->FileName;
name16.len = res->FileNameLength / sizeof(wchar_t); name16.len = result->FileNameLength / sizeof(wchar_t);
info->name = StringFromString16(arena, name16); info->name = StringFromString16(arena, name16);
for (u64 i = 0; i < info->name.len; ++i) for (u64 i = 0; i < info->name.len; ++i)
@ -2556,7 +2556,7 @@ P_WatchInfoList P_ReadWatchWait(Arena *arena, P_Watch *dw)
} }
} }
switch (res->Action) switch (result->Action)
{ {
case FILE_ACTION_ADDED: case FILE_ACTION_ADDED:
{ {
@ -2589,17 +2589,17 @@ P_WatchInfoList P_ReadWatchWait(Arena *arena, P_Watch *dw)
} break; } break;
} }
if (res->NextEntryOffset == 0) if (result->NextEntryOffset == 0)
{ {
done = 1; done = 1;
} }
else else
{ {
offset += res->NextEntryOffset; offset += result->NextEntryOffset;
} }
} }
} }
else if (wait_res == WAIT_OBJECT_0 + 1) else if (wait_result == WAIT_OBJECT_0 + 1)
{ {
ResetEvent(w32_watch->wake_handle); ResetEvent(w32_watch->wake_handle);
done = 1; done = 1;
@ -2768,48 +2768,48 @@ u64 P_GetInternalWindowHandle(P_Window *p_window)
P_Address P_AddressFromIpPortCstr(char *ip_cstr, char *port_cstr) P_Address P_AddressFromIpPortCstr(char *ip_cstr, char *port_cstr)
{ {
P_Address res = ZI; P_Address result = ZI;
struct addrinfo hints = ZI; struct addrinfo hints = ZI;
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM; hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = AI_PASSIVE; hints.ai_flags = AI_PASSIVE;
struct addrinfo *ai_res = 0; struct addrinfo *ai_result = 0;
i32 status = getaddrinfo(ip_cstr, port_cstr, &hints, &ai_res); i32 status = getaddrinfo(ip_cstr, port_cstr, &hints, &ai_result);
if (status == 0) if (status == 0)
{ {
while (ai_res) while (ai_result)
{ {
if (ai_res->ai_family == AF_INET) if (ai_result->ai_family == AF_INET)
{ {
struct sockaddr_in *sockaddr = (struct sockaddr_in *)ai_res->ai_addr; struct sockaddr_in *sockaddr = (struct sockaddr_in *)ai_result->ai_addr;
res.valid = 1; result.valid = 1;
res.family = P_AddressFamily_Ipv4; result.family = P_AddressFamily_Ipv4;
res.portnb = sockaddr->sin_port; result.portnb = sockaddr->sin_port;
StaticAssert(sizeof(sockaddr->sin_addr) == 4); StaticAssert(sizeof(sockaddr->sin_addr) == 4);
CopyBytes(res.ipnb, (void *)&sockaddr->sin_addr, 4); CopyBytes(result.ipnb, (void *)&sockaddr->sin_addr, 4);
break; break;
} }
else if (ai_res->ai_family == AF_INET6) else if (ai_result->ai_family == AF_INET6)
{ {
/* TODO: Enable ipv6 */ /* TODO: Enable ipv6 */
#if 0 #if 0
struct sockaddr_in6 *sockaddr = (struct sockaddr_in6 *)ai_res->ai_addr; struct sockaddr_in6 *sockaddr = (struct sockaddr_in6 *)ai_result->ai_addr;
res.valid = 1; result.valid = 1;
res.family = P_AddressFamily_Ipv6; result.family = P_AddressFamily_Ipv6;
res.portnb = sockaddr->sin6_port; result.portnb = sockaddr->sin6_port;
StaticAssert(sizeof(sockaddr->sin6_addr) == 16); StaticAssert(sizeof(sockaddr->sin6_addr) == 16);
CopyBytes(res.ipnb, (void *)&sockaddr->sin6_addr, 16); CopyBytes(result.ipnb, (void *)&sockaddr->sin6_addr, 16);
break; break;
#endif #endif
} }
ai_res = ai_res->ai_next; ai_result = ai_result->ai_next;
} }
freeaddrinfo(ai_res); freeaddrinfo(ai_result);
} }
return res; return result;
} }
P_Address P_AddressFromString(String str) P_Address P_AddressFromString(String str)
@ -2903,8 +2903,8 @@ P_Address P_AddressFromString(String str)
} }
} }
P_Address res = P_AddressFromIpPortCstr(ip_cstr, port_cstr); P_Address result = P_AddressFromIpPortCstr(ip_cstr, port_cstr);
return res; return result;
} }
P_Address P_AddressFromPort(u16 port) P_Address P_AddressFromPort(u16 port)
@ -2933,14 +2933,14 @@ P_Address P_AddressFromPort(u16 port)
} }
} }
P_Address res = P_AddressFromIpPortCstr(0, port_cstr); P_Address result = P_AddressFromIpPortCstr(0, port_cstr);
return res; return result;
} }
String P_StringFromAddress(Arena *arena, P_Address address) String P_StringFromAddress(Arena *arena, P_Address address)
{ {
String res = ZI; String result = ZI;
if (address.family == P_AddressFamily_Ipv6) if (address.family == P_AddressFamily_Ipv6)
{ {
@ -2954,10 +2954,10 @@ String P_StringFromAddress(Arena *arena, P_Address address)
ip[i] = ntohs(address.ipnb[i]); ip[i] = ntohs(address.ipnb[i]);
} }
u16 port = ntohs(address.portnb); u16 port = ntohs(address.portnb);
res = StringFormat(arena, Lit("%F.%F.%F.%F:%F"), FmtUint(ip[0]), FmtUint(ip[1]), FmtUint(ip[2]), FmtUint(ip[3]), FmtUint(port)); result = StringFormat(arena, Lit("%F.%F.%F.%F:%F"), FmtUint(ip[0]), FmtUint(ip[1]), FmtUint(ip[2]), FmtUint(ip[3]), FmtUint(port));
} }
return res; return result;
} }
b32 P_AddressIsEqual(P_Address a, P_Address b) b32 P_AddressIsEqual(P_Address a, P_Address b)
@ -3025,7 +3025,7 @@ P_SockReadResult P_ReadSock(Arena *arena, P_Sock *sock)
read_buff.len = read_buff_size; read_buff.len = read_buff_size;
read_buff.text = PushStructsNoZero(arena, u8, read_buff_size); read_buff.text = PushStructsNoZero(arena, u8, read_buff_size);
P_SockReadResult res = ZI; P_SockReadResult result = ZI;
P_W32_Address ws_addr = ZI; P_W32_Address ws_addr = ZI;
ws_addr.size = sizeof(ws_addr.sas); ws_addr.size = sizeof(ws_addr.sas);
@ -3033,13 +3033,13 @@ P_SockReadResult P_ReadSock(Arena *arena, P_Sock *sock)
i32 size = recvfrom(ws->sock, (char *)read_buff.text, read_buff.len, 0, &ws_addr.sa, &ws_addr.size); i32 size = recvfrom(ws->sock, (char *)read_buff.text, read_buff.len, 0, &ws_addr.sa, &ws_addr.size);
ws_addr.family = ws_addr.sin.sin_family; ws_addr.family = ws_addr.sin.sin_family;
res.address = P_W32_PlatformAddressFromWin32Address(ws_addr); result.address = P_W32_PlatformAddressFromWin32Address(ws_addr);
if (size >= 0) if (size >= 0)
{ {
AddGstat(GSTAT_SOCK_BYTES_RECEIVED, size); AddGstat(GSTAT_SOCK_BYTES_RECEIVED, size);
res.data.text = read_buff.text; result.data.text = read_buff.text;
res.data.len = size; result.data.len = size;
res.valid = 1; result.valid = 1;
/* PopStruct arena back to end of msg */ /* PopStruct arena back to end of msg */
PopTo(arena, arena->pos - read_buff_size + size); PopTo(arena, arena->pos - read_buff_size + size);
@ -3055,7 +3055,7 @@ P_SockReadResult P_ReadSock(Arena *arena, P_Sock *sock)
#endif #endif
} }
return res; return result;
} }
void P_WriteSock(P_Sock *sock, P_Address address, String data) void P_WriteSock(P_Sock *sock, P_Address address, String data)
@ -3144,19 +3144,19 @@ void P_SetClipboardText(String str)
String P_GetClipboardText(Arena *arena) String P_GetClipboardText(Arena *arena)
{ {
String res = ZI; String result = ZI;
if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(0)) if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(0))
{ {
HANDLE handle = GetClipboardData(CF_UNICODETEXT); HANDLE handle = GetClipboardData(CF_UNICODETEXT);
if (handle) if (handle)
{ {
u16 *src_wstr = (u16 *)GlobalLock(handle); u16 *src_wstr = (u16 *)GlobalLock(handle);
res = StringFromString16(arena, String16FromWstrNoLimit(src_wstr)); result = StringFromString16(arena, String16FromWstrNoLimit(src_wstr));
GlobalUnlock(handle); GlobalUnlock(handle);
} }
CloseClipboard(); CloseClipboard();
} }
return res; return result;
} }
u32 P_GetLogicalProcessorCount(void) u32 P_GetLogicalProcessorCount(void)

View File

@ -45,16 +45,16 @@ R_Resource resource_open(String name)
{ {
__prof; __prof;
#if RESOURCES_EMBEDDED #if RESOURCES_EMBEDDED
R_Resource res = ZI; R_Resource result = ZI;
struct tar_entry *entry = tar_get(&G.archive, name); struct tar_entry *entry = tar_get(&G.archive, name);
res._data = entry->data; result._data = entry->data;
res._name = entry->file_name; result._name = entry->file_name;
res._exists = entry->valid; result._exists = entry->valid;
return res; return result;
#else #else
R_Resource res = ZI; R_Resource result = ZI;
if (name.len < countof(res._name_text)) { if (name.len < countof(result._name_text)) {
u8 path_text[RESOURCE_NAME_LEN_MAX + (sizeof("res/") - 1)]; u8 path_text[RESOURCE_NAME_LEN_MAX + (sizeof("result/") - 1)];
String path = ZI; String path = ZI;
{ {
path_text[0] = 'r'; path_text[0] = 'r';
@ -81,16 +81,16 @@ R_Resource resource_open(String name)
P_CloseFIle(file); P_CloseFIle(file);
} }
res._exists = file.valid && file_map.valid; result._exists = file.valid && file_map.valid;
res._data = data; result._data = data;
res._file = file; result._file = file;
res._file_map = file_map; result._file_map = file_map;
res._name_len = name.len; result._name_len = name.len;
CopyBytes(res._name_text, name.text, name.len); CopyBytes(result._name_text, name.text, name.len);
} else { } else {
Assert(0); Assert(0);
} }
return res; return result;
#endif #endif
} }

View File

@ -46,14 +46,14 @@ P_WindowSettings *settings_deserialize(Arena *arena, String src, String *error_o
JSON_Error json_error = ZI; JSON_Error json_error = ZI;
P_WindowSettings *settings = PushStruct(arena, P_WindowSettings); P_WindowSettings *settings = PushStruct(arena, P_WindowSettings);
JSON_Result parse_res = json_from_string(scratch.arena, src); JSON_Result parse_result = json_from_string(scratch.arena, src);
if (parse_res.errors.count > 0) { if (parse_result.errors.count > 0) {
json_error = *parse_res.errors.first; json_error = *parse_result.errors.first;
goto abort; goto abort;
} }
JSON_Blob *root = parse_res.root; JSON_Blob *root = parse_result.root;
if (!root) { if (!root) {
error = Lit("Root object not found."); error = Lit("Root object not found.");
goto abort; goto abort;

View File

@ -238,17 +238,17 @@ void sim_client_set_channel_id(Client *client, N_ChannelId channel_id)
Client *sim_client_from_channel_id(ClientStore *store, N_ChannelId channel_id) Client *sim_client_from_channel_id(ClientStore *store, N_ChannelId channel_id)
{ {
Client *res = sim_client_nil(); Client *result = sim_client_nil();
u64 channel_hash = hash_from_channel_id(channel_id); u64 channel_hash = hash_from_channel_id(channel_id);
u64 bin_index = channel_hash % store->num_client_lookup_bins; u64 bin_index = channel_hash % store->num_client_lookup_bins;
ClientLookupBin *bin = &store->client_lookup_bins[bin_index]; ClientLookupBin *bin = &store->client_lookup_bins[bin_index];
for (Client *client = sim_client_from_handle(store, bin->first); client->valid; client = sim_client_from_handle(store, client->next_in_bin)) { for (Client *client = sim_client_from_handle(store, bin->first); client->valid; client = sim_client_from_handle(store, client->next_in_bin)) {
if (client->channel_hash == channel_hash) { if (client->channel_hash == channel_hash) {
res = client; result = client;
break; break;
} }
} }
return res; return result;
} }
Client *sim_client_from_handle(ClientStore *store, ClientHandle handle) Client *sim_client_from_handle(ClientStore *store, ClientHandle handle)
@ -542,51 +542,51 @@ Snapshot *sim_snapshot_from_closest_tick_gte(Client *client, u64 tick)
Vec2I32 sim_world_tile_index_from_pos(Vec2 pos) Vec2I32 sim_world_tile_index_from_pos(Vec2 pos)
{ {
Vec2I32 res = VEC2I32(pos.x * SIM_TILES_PER_UNIT_SQRT, pos.y * SIM_TILES_PER_UNIT_SQRT); Vec2I32 result = VEC2I32(pos.x * SIM_TILES_PER_UNIT_SQRT, pos.y * SIM_TILES_PER_UNIT_SQRT);
res.x -= pos.x < 0; result.x -= pos.x < 0;
res.y -= pos.y < 0; result.y -= pos.y < 0;
return res; return result;
} }
Vec2 sim_pos_from_world_tile_index(Vec2I32 world_tile_index) Vec2 sim_pos_from_world_tile_index(Vec2I32 world_tile_index)
{ {
Vec2 res = ZI; Vec2 result = ZI;
f32 tile_size = 1.f / SIM_TILES_PER_UNIT_SQRT; f32 tile_size = 1.f / SIM_TILES_PER_UNIT_SQRT;
res.x = (f32)world_tile_index.x * tile_size; result.x = (f32)world_tile_index.x * tile_size;
res.y = (f32)world_tile_index.y * tile_size; result.y = (f32)world_tile_index.y * tile_size;
return res; return result;
} }
Vec2I32 sim_local_tile_index_from_world_tile_index(Vec2I32 world_tile_index) Vec2I32 sim_local_tile_index_from_world_tile_index(Vec2I32 world_tile_index)
{ {
Vec2I32 res = world_tile_index; Vec2I32 result = world_tile_index;
res.x += res.x < 0; result.x += result.x < 0;
res.y += res.y < 0; result.y += result.y < 0;
res.x = res.x % SIM_TILES_PER_CHUNK_SQRT; result.x = result.x % SIM_TILES_PER_CHUNK_SQRT;
res.y = res.y % SIM_TILES_PER_CHUNK_SQRT; result.y = result.y % SIM_TILES_PER_CHUNK_SQRT;
res.x += (world_tile_index.x < 0) * (SIM_TILES_PER_CHUNK_SQRT - 1); result.x += (world_tile_index.x < 0) * (SIM_TILES_PER_CHUNK_SQRT - 1);
res.y += (world_tile_index.y < 0) * (SIM_TILES_PER_CHUNK_SQRT - 1); result.y += (world_tile_index.y < 0) * (SIM_TILES_PER_CHUNK_SQRT - 1);
return res; return result;
} }
Vec2I32 sim_world_tile_index_from_local_tile_index(Vec2I32 tile_chunk_index, Vec2I32 local_tile_index) Vec2I32 sim_world_tile_index_from_local_tile_index(Vec2I32 tile_chunk_index, Vec2I32 local_tile_index)
{ {
Vec2I32 res = ZI; Vec2I32 result = ZI;
res.x = (tile_chunk_index.x * SIM_TILES_PER_CHUNK_SQRT) + local_tile_index.x; result.x = (tile_chunk_index.x * SIM_TILES_PER_CHUNK_SQRT) + local_tile_index.x;
res.y = (tile_chunk_index.y * SIM_TILES_PER_CHUNK_SQRT) + local_tile_index.y; result.y = (tile_chunk_index.y * SIM_TILES_PER_CHUNK_SQRT) + local_tile_index.y;
return res; return result;
} }
Vec2I32 sim_tile_chunk_index_from_world_tile_index(Vec2I32 world_tile_index) Vec2I32 sim_tile_chunk_index_from_world_tile_index(Vec2I32 world_tile_index)
{ {
Vec2I32 res = world_tile_index; Vec2I32 result = world_tile_index;
res.x += res.x < 0; result.x += result.x < 0;
res.y += res.y < 0; result.y += result.y < 0;
res.x = res.x / SIM_TILES_PER_CHUNK_SQRT; result.x = result.x / SIM_TILES_PER_CHUNK_SQRT;
res.y = res.y / SIM_TILES_PER_CHUNK_SQRT; result.y = result.y / SIM_TILES_PER_CHUNK_SQRT;
res.x -= world_tile_index.x < 0; result.x -= world_tile_index.x < 0;
res.y -= world_tile_index.y < 0; result.y -= world_tile_index.y < 0;
return res; return result;
} }
void sim_snapshot_set_tile(Snapshot *ss, Vec2I32 world_tile_index, TileKind tile_kind) void sim_snapshot_set_tile(Snapshot *ss, Vec2I32 world_tile_index, TileKind tile_kind)

View File

@ -246,55 +246,55 @@ void sim_ent_set_id(Ent *ent, EntId id)
Ent *sim_ent_from_id(Snapshot *ss, EntId id) Ent *sim_ent_from_id(Snapshot *ss, EntId id)
{ {
Ent *res = sim_ent_nil(); Ent *result = sim_ent_nil();
if (!sim_ent_id_is_nil(id) && ss->valid) { if (!sim_ent_id_is_nil(id) && ss->valid) {
EntBin *bin = bin_from_id(ss, id); EntBin *bin = bin_from_id(ss, id);
for (Ent *e = ent_from_index(ss, bin->first); e->valid; e = ent_from_index(ss, e->next_in_id_bin)) { for (Ent *e = ent_from_index(ss, bin->first); e->valid; e = ent_from_index(ss, e->next_in_id_bin)) {
if (sim_ent_id_eq(e->id, id)) { if (sim_ent_id_eq(e->id, id)) {
res = e; result = e;
break; break;
} }
} }
} }
return res; return result;
} }
EntId sim_ent_random_id(void) EntId sim_ent_random_id(void)
{ {
EntId res = ZI; EntId result = ZI;
res.uid = UidFromTrueRand(); result.uid = UidFromTrueRand();
return res; return result;
} }
/* Returns the deterministic id of the contact constraint ent id that should be produced from e0 & e1 colliding */ /* Returns the deterministic id of the contact constraint ent id that should be produced from e0 & e1 colliding */
EntId sim_ent_contact_constraint_id_from_contacting_ids(EntId player_id, EntId id0, EntId id1) EntId sim_ent_contact_constraint_id_from_contacting_ids(EntId player_id, EntId id0, EntId id1)
{ {
EntId res = ZI; EntId result = ZI;
res.uid = SIM_ENT_CONTACT_BASIS_Uid; result.uid = SIM_ENT_CONTACT_BASIS_Uid;
res.uid = CombineUid(res.uid, player_id.uid); result.uid = CombineUid(result.uid, player_id.uid);
res.uid = CombineUid(res.uid, id0.uid); result.uid = CombineUid(result.uid, id0.uid);
res.uid = CombineUid(res.uid, id1.uid); result.uid = CombineUid(result.uid, id1.uid);
return res; return result;
} }
/* Returns the deterministic id of the debug contact constraint ent id that should be produced from e0 & e1 colliding */ /* Returns the deterministic id of the debug contact constraint ent id that should be produced from e0 & e1 colliding */
EntId sim_ent_collision_debug_id_from_ids(EntId player_id, EntId id0, EntId id1) EntId sim_ent_collision_debug_id_from_ids(EntId player_id, EntId id0, EntId id1)
{ {
EntId res = ZI; EntId result = ZI;
res.uid = SIM_ENT_COLLISION_DEBUG_BASIS_Uid; result.uid = SIM_ENT_COLLISION_DEBUG_BASIS_Uid;
res.uid = CombineUid(res.uid, player_id.uid); result.uid = CombineUid(result.uid, player_id.uid);
res.uid = CombineUid(res.uid, id0.uid); result.uid = CombineUid(result.uid, id0.uid);
res.uid = CombineUid(res.uid, id1.uid); result.uid = CombineUid(result.uid, id1.uid);
return res; return result;
} }
/* Returns the deterministic id of the tile chunk that should be produced at chunk pos */ /* Returns the deterministic id of the tile chunk that should be produced at chunk pos */
EntId sim_ent_tile_chunk_id_from_tile_chunk_index(Vec2I32 chunk_index) EntId sim_ent_tile_chunk_id_from_tile_chunk_index(Vec2I32 chunk_index)
{ {
EntId res = ZI; EntId result = ZI;
res.uid = SIM_ENT_TILE_CHUNK_BASIS_Uid; result.uid = SIM_ENT_TILE_CHUNK_BASIS_Uid;
res.uid = CombineUid(res.uid, UID(RandU64FromSeed(chunk_index.x), RandU64FromSeed(chunk_index.y))); result.uid = CombineUid(result.uid, UID(RandU64FromSeed(chunk_index.x), RandU64FromSeed(chunk_index.y)));
return res; return result;
} }
/* ========================== * /* ========================== *
@ -575,8 +575,8 @@ Ent *sim_tile_chunk_from_world_tile_index(Snapshot *ss, Vec2I32 world_tile_index
TileKind sim_get_chunk_tile(Ent *chunk_ent, Vec2I32 local_tile_index) TileKind sim_get_chunk_tile(Ent *chunk_ent, Vec2I32 local_tile_index)
{ {
TileKind res = chunk_ent->tile_chunk_tiles[local_tile_index.x + (local_tile_index.y * SIM_TILES_PER_CHUNK_SQRT)]; TileKind result = chunk_ent->tile_chunk_tiles[local_tile_index.x + (local_tile_index.y * SIM_TILES_PER_CHUNK_SQRT)];
return res; return result;
} }
/* ========================== * /* ========================== *

View File

@ -472,15 +472,15 @@ Inline b32 sim_ent_is_owner(Ent *ent)
Inline b32 sim_ent_should_simulate(Ent *ent) Inline b32 sim_ent_should_simulate(Ent *ent)
{ {
b32 res = 0; b32 result = 0;
if (sim_ent_is_valid_and_active(ent)) { if (sim_ent_is_valid_and_active(ent)) {
res = 1; result = 1;
if (sim_ent_has_prop(ent, SEPROP_SYNC_DST)) { if (sim_ent_has_prop(ent, SEPROP_SYNC_DST)) {
EntId local_player = ent->ss->local_player; EntId local_player = ent->ss->local_player;
res = sim_ent_id_eq(local_player, ent->owner) || sim_ent_id_eq(local_player, ent->predictor); result = sim_ent_id_eq(local_player, ent->owner) || sim_ent_id_eq(local_player, ent->predictor);
} }
} }
return res; return result;
} }
/* ========================== * /* ========================== *

View File

@ -7,11 +7,11 @@
internal b32 can_contact(Ent *e0, Ent *e1) internal b32 can_contact(Ent *e0, Ent *e1)
{ {
b32 res = 0; b32 result = 0;
res = e0 != e1 && result = e0 != e1 &&
!sim_ent_id_eq(e0->top, e1->top) && !sim_ent_id_eq(e0->top, e1->top) &&
!(sim_ent_has_prop(e0, SEPROP_WALL) && sim_ent_has_prop(e1, SEPROP_WALL)); !(sim_ent_has_prop(e0, SEPROP_WALL) && sim_ent_has_prop(e1, SEPROP_WALL));
return res; return result;
} }
void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_iteration) void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_iteration)
@ -81,14 +81,14 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
} }
/* Calculate collision */ /* Calculate collision */
CLD_CollisionResult collider_res = collider_collision_points(&e0_collider, &e1_collider, e0_xf, e1_xf); CLD_CollisionResult collision_result = collider_collision_points(&e0_collider, &e1_collider, e0_xf, e1_xf);
/* Parts of algorithm are hard-coded to support 2 contact points */ /* Parts of algorithm are hard-coded to support 2 contact points */
StaticAssert(countof(constraint_ent->contact_constraint_data.points) == 2); StaticAssert(countof(constraint_ent->contact_constraint_data.points) == 2);
StaticAssert(countof(collider_res.points) == 2); StaticAssert(countof(collision_result.points) == 2);
ContactConstraint *constraint = 0; ContactConstraint *constraint = 0;
if (collider_res.num_points > 0) { if (collision_result.num_points > 0) {
b32 is_start = 0; b32 is_start = 0;
if (!constraint_ent->valid) { if (!constraint_ent->valid) {
is_start = 1; is_start = 1;
@ -106,7 +106,7 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
sim_ent_activate(constraint_ent, tick); sim_ent_activate(constraint_ent, tick);
} }
constraint = &constraint_ent->contact_constraint_data; constraint = &constraint_ent->contact_constraint_data;
constraint->normal = collider_res.normal; constraint->normal = collision_result.normal;
constraint->friction = SqrtF32(e0->friction * e1->friction); constraint->friction = SqrtF32(e0->friction * e1->friction);
/* Delete old contacts that are no longer present */ /* Delete old contacts that are no longer present */
@ -114,8 +114,8 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
ContactPoint *old = &constraint->points[i]; ContactPoint *old = &constraint->points[i];
u32 id = old->id; u32 id = old->id;
b32 found = 0; b32 found = 0;
for (u32 j = 0; j < collider_res.num_points; ++j) { for (u32 j = 0; j < collision_result.num_points; ++j) {
if (collider_res.points[j].id == id) { if (collision_result.points[j].id == id) {
found = 1; found = 1;
break; break;
} }
@ -128,8 +128,8 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
} }
/* Update / insert returned contacts */ /* Update / insert returned contacts */
for (u32 i = 0; i < collider_res.num_points; ++i) { for (u32 i = 0; i < collision_result.num_points; ++i) {
CLD_CollisionPoint *res_point = &collider_res.points[i]; CLD_CollisionPoint *res_point = &collision_result.points[i];
Vec2 point = res_point->point; Vec2 point = res_point->point;
f32 sep = res_point->separation; f32 sep = res_point->separation;
u32 id = res_point->id; u32 id = res_point->id;
@ -162,7 +162,7 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
/* Skip solve based on collision direction */ /* Skip solve based on collision direction */
{ {
Vec2 normal = collider_res.normal; Vec2 normal = collision_result.normal;
Vec2 dir0 = e0->collision_dir; Vec2 dir0 = e0->collision_dir;
Vec2 dir1 = e1->collision_dir; Vec2 dir1 = e1->collision_dir;
f32 threshold = 0.5; f32 threshold = 0.5;
@ -181,14 +181,14 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
CollisionData data = ZI; CollisionData data = ZI;
data.e0 = e0->id; data.e0 = e0->id;
data.e1 = e1->id; data.e1 = e1->id;
data.normal = collider_res.normal; data.normal = collision_result.normal;
data.is_start = is_start; data.is_start = is_start;
data.dt = elapsed_dt; data.dt = elapsed_dt;
/* Calculate point */ /* Calculate point */
Vec2 midpoint = collider_res.points[0].point; Vec2 midpoint = collision_result.points[0].point;
if (collider_res.num_points > 1) { if (collision_result.num_points > 1) {
midpoint = AddVec2(midpoint, MulVec2(SubVec2(collider_res.points[1].point, midpoint), 0.5f)); midpoint = AddVec2(midpoint, MulVec2(SubVec2(collision_result.points[1].point, midpoint), 0.5f));
} }
data.point = midpoint; data.point = midpoint;
@ -240,7 +240,7 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
dbg->e0 = e0->id; dbg->e0 = e0->id;
dbg->e1 = e1->id; dbg->e1 = e1->id;
dbg->res = collider_res; dbg->collision_result = collision_result;
if (constraint) { if (constraint) {
CopyBytes(dbg->points, constraint->points, sizeof(dbg->points)); CopyBytes(dbg->points, constraint->points, sizeof(dbg->points));
@ -254,9 +254,9 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
/* Update closest points */ /* Update closest points */
{ {
CLD_ClosestResult closest_points_res = collider_closest_points(&e0_collider, &e1_collider, e0_xf, e1_xf); CLD_ClosestResult closest_points = collider_closest_points(&e0_collider, &e1_collider, e0_xf, e1_xf);
dbg->closest0 = closest_points_res.p0; dbg->closest0 = closest_points.p0;
dbg->closest1 = closest_points_res.p1; dbg->closest1 = closest_points.p1;
} }
} }
#endif #endif
@ -556,13 +556,13 @@ MotorJointDesc phys_motor_joint_def_init(void)
MotorJoint phys_motor_joint_from_def(MotorJointDesc def) MotorJoint phys_motor_joint_from_def(MotorJointDesc def)
{ {
MotorJoint res = ZI; MotorJoint result = ZI;
res.e0 = def.e0; result.e0 = def.e0;
res.e1 = def.e1; result.e1 = def.e1;
res.correction_rate = ClampF32(def.correction_rate, 0, 1); result.correction_rate = ClampF32(def.correction_rate, 0, 1);
res.max_force = def.max_force; result.max_force = def.max_force;
res.max_torque = def.max_torque; result.max_torque = def.max_torque;
return res; return result;
} }
void phys_prepare_motor_joints(PhysStepCtx *ctx) void phys_prepare_motor_joints(PhysStepCtx *ctx)
@ -755,16 +755,16 @@ MouseJointDesc phys_mouse_joint_def_init(void)
MouseJoint phys_mouse_joint_from_def(MouseJointDesc def) MouseJoint phys_mouse_joint_from_def(MouseJointDesc def)
{ {
MouseJoint res = ZI; MouseJoint result = ZI;
res.target = def.target; result.target = def.target;
res.point_local_start = def.point_local_start; result.point_local_start = def.point_local_start;
res.point_end = def.point_end; result.point_end = def.point_end;
res.linear_spring_hz = def.linear_spring_hz; result.linear_spring_hz = def.linear_spring_hz;
res.linear_spring_damp = def.linear_spring_damp; result.linear_spring_damp = def.linear_spring_damp;
res.angular_spring_hz = def.angular_spring_hz; result.angular_spring_hz = def.angular_spring_hz;
res.angular_spring_damp = def.angular_spring_damp; result.angular_spring_damp = def.angular_spring_damp;
res.max_force = def.max_force; result.max_force = def.max_force;
return res; return result;
} }
void phys_prepare_mouse_joints(PhysStepCtx *ctx) void phys_prepare_mouse_joints(PhysStepCtx *ctx)
@ -921,15 +921,15 @@ WeldJointDesc phys_weld_joint_def_init(void)
WeldJoint phys_weld_joint_from_def(WeldJointDesc def) WeldJoint phys_weld_joint_from_def(WeldJointDesc def)
{ {
WeldJoint res = ZI; WeldJoint result = ZI;
res.e0 = def.e0; result.e0 = def.e0;
res.e1 = def.e1; result.e1 = def.e1;
res.linear_spring_hz = def.linear_spring_hz; result.linear_spring_hz = def.linear_spring_hz;
res.linear_spring_damp = def.linear_spring_damp; result.linear_spring_damp = def.linear_spring_damp;
res.angular_spring_hz = def.angular_spring_hz; result.angular_spring_hz = def.angular_spring_hz;
res.angular_spring_damp = def.angular_spring_damp; result.angular_spring_damp = def.angular_spring_damp;
res.xf0_to_xf1 = def.xf; result.xf0_to_xf1 = def.xf;
return res; return result;
} }
void phys_prepare_weld_joints(PhysStepCtx *ctx) void phys_prepare_weld_joints(PhysStepCtx *ctx)

View File

@ -77,7 +77,7 @@ typedef struct CollisionDebugData CollisionDebugData;
struct CollisionDebugData { struct CollisionDebugData {
EntId e0; EntId e0;
EntId e1; EntId e1;
CLD_CollisionResult res; CLD_CollisionResult collision_result;
ContactPoint points[2]; ContactPoint points[2];
u32 num_points; u32 num_points;

View File

@ -104,14 +104,14 @@ SpaceCell *space_get_cell(Space *space, Vec2I32 cell_pos)
{ {
i32 bin_index = cell_coords_to_bin_index(space, cell_pos); i32 bin_index = cell_coords_to_bin_index(space, cell_pos);
SpaceCellBin *bin = &space->bins[bin_index]; SpaceCellBin *bin = &space->bins[bin_index];
SpaceCell *res = space_cell_nil(); SpaceCell *result = space_cell_nil();
for (SpaceCell *n = bin->first_cell; n; n = n->next_in_bin) { for (SpaceCell *n = bin->first_cell; n; n = n->next_in_bin) {
if (EqVec2I32(n->pos, cell_pos)) { if (EqVec2I32(n->pos, cell_pos)) {
res = n; result = n;
break; break;
} }
} }
return res; return result;
} }
internal void space_cell_node_alloc(Vec2I32 cell_pos, SpaceEntry *entry) internal void space_cell_node_alloc(Vec2I32 cell_pos, SpaceEntry *entry)

View File

@ -413,9 +413,9 @@ internal MergesortCompareFuncDef(tile_chunk_sort_x, arg_a, arg_b, udata)
i32 a_x = a->tile_chunk_index.x; i32 a_x = a->tile_chunk_index.x;
i32 b_x = b->tile_chunk_index.x; i32 b_x = b->tile_chunk_index.x;
i32 res = 0; i32 result = 0;
res = (a_x < b_x) - (a_x > b_x); result = (a_x < b_x) - (a_x > b_x);
return res; return result;
} }
internal MergesortCompareFuncDef(tile_chunk_sort_y, arg_a, arg_b, udata) internal MergesortCompareFuncDef(tile_chunk_sort_y, arg_a, arg_b, udata)
@ -426,9 +426,9 @@ internal MergesortCompareFuncDef(tile_chunk_sort_y, arg_a, arg_b, udata)
i32 a_y = a->tile_chunk_index.y; i32 a_y = a->tile_chunk_index.y;
i32 b_y = b->tile_chunk_index.y; i32 b_y = b->tile_chunk_index.y;
i32 res = 0; i32 result = 0;
res = (a_y < b_y) - (a_y > b_y); result = (a_y < b_y) - (a_y > b_y);
return res; return result;
} }
internal void test_generate_walls(Snapshot *world) internal void test_generate_walls(Snapshot *world)

View File

@ -258,10 +258,10 @@ internal P_ExitFuncDef(sprite_shutdown)
S_Tag sprite_tag_from_path(String path) S_Tag sprite_tag_from_path(String path)
{ {
S_Tag res = ZI; S_Tag result = ZI;
res.hash = HashFnv64(Fnv64Basis, path); result.hash = HashFnv64(Fnv64Basis, path);
res.path = path; result.path = path;
return res; return result;
} }
b32 sprite_tag_is_nil(S_Tag tag) b32 sprite_tag_is_nil(S_Tag tag)
@ -782,30 +782,30 @@ internal struct sprite_scope_cache_ref *scope_ensure_ref_from_ref(S_Scope *scope
S_Scope *sprite_scope_begin(void) S_Scope *sprite_scope_begin(void)
{ {
/* Alloc scope */ /* Alloc scope */
S_Scope *res = 0; S_Scope *result = 0;
struct sprite_scope_cache_ref **bins = 0; struct sprite_scope_cache_ref **bins = 0;
struct sprite_scope_cache_ref *pool = 0; struct sprite_scope_cache_ref *pool = 0;
{ {
P_Lock lock = P_LockE(&G.scopes_mutex); P_Lock lock = P_LockE(&G.scopes_mutex);
{ {
if (G.first_free_scope) { if (G.first_free_scope) {
res = G.first_free_scope; result = G.first_free_scope;
G.first_free_scope = res->next_free; G.first_free_scope = result->next_free;
bins = res->ref_node_bins; bins = result->ref_node_bins;
pool = res->ref_node_pool; pool = result->ref_node_pool;
} else { } else {
res = PushStructNoZero(G.scopes_arena, S_Scope); result = PushStructNoZero(G.scopes_arena, S_Scope);
bins = PushStructsNoZero(G.scopes_arena, struct sprite_scope_cache_ref *, CACHE_BINS_COUNT); bins = PushStructsNoZero(G.scopes_arena, struct sprite_scope_cache_ref *, CACHE_BINS_COUNT);
pool = PushStructsNoZero(G.scopes_arena, struct sprite_scope_cache_ref, MAX_SCOPE_REFERENCES); pool = PushStructsNoZero(G.scopes_arena, struct sprite_scope_cache_ref, MAX_SCOPE_REFERENCES);
} }
} }
P_Unlock(&lock); P_Unlock(&lock);
} }
ZeroStruct(res); ZeroStruct(result);
ZeroBytes(bins, sizeof(*bins) * CACHE_BINS_COUNT); ZeroBytes(bins, sizeof(*bins) * CACHE_BINS_COUNT);
res->ref_node_bins = bins; result->ref_node_bins = bins;
res->ref_node_pool = pool; result->ref_node_pool = pool;
return res; return result;
} }
void sprite_scope_end(S_Scope *scope) void sprite_scope_end(S_Scope *scope)
@ -949,10 +949,10 @@ internal struct sprite_scope_cache_ref *cache_entry_from_tag(S_Scope *scope, S_T
internal void *data_from_tag_internal(S_Scope *scope, S_Tag tag, enum cache_entry_kind kind, b32 await) internal void *data_from_tag_internal(S_Scope *scope, S_Tag tag, enum cache_entry_kind kind, b32 await)
{ {
/* TODO: Replace switch statements */ /* TODO: Replace switch statements */
void *res = 0; void *result = 0;
switch (kind) { switch (kind) {
case CACHE_ENTRY_KIND_TEXTURE: { res = G.loading_texture; } break; case CACHE_ENTRY_KIND_TEXTURE: { result = G.loading_texture; } break;
case CACHE_ENTRY_KIND_SHEET: { res = G.loading_sheet; } break; case CACHE_ENTRY_KIND_SHEET: { result = G.loading_sheet; } break;
default: { P_Panic(Lit("Unknown sprite cache entry kind")); } break; default: { P_Panic(Lit("Unknown sprite cache entry kind")); } break;
} }
@ -962,8 +962,8 @@ internal void *data_from_tag_internal(S_Scope *scope, S_Tag tag, enum cache_entr
enum cache_entry_state state = Atomic32Fetch(&ref.e->state); enum cache_entry_state state = Atomic32Fetch(&ref.e->state);
if (state == CACHE_ENTRY_STATE_LOADED) { if (state == CACHE_ENTRY_STATE_LOADED) {
switch (kind) { switch (kind) {
case CACHE_ENTRY_KIND_TEXTURE: { res = ref.e->texture; } break; case CACHE_ENTRY_KIND_TEXTURE: { result = ref.e->texture; } break;
case CACHE_ENTRY_KIND_SHEET: { res = ref.e->sheet; } break; case CACHE_ENTRY_KIND_SHEET: { result = ref.e->sheet; } break;
default: { P_Panic(Lit("Unknown sprite cache entry kind")); } break; default: { P_Panic(Lit("Unknown sprite cache entry kind")); } break;
} }
} else if (state == CACHE_ENTRY_STATE_NONE) { } else if (state == CACHE_ENTRY_STATE_NONE) {
@ -974,11 +974,11 @@ internal void *data_from_tag_internal(S_Scope *scope, S_Tag tag, enum cache_entr
switch (kind) { switch (kind) {
case CACHE_ENTRY_KIND_TEXTURE: { case CACHE_ENTRY_KIND_TEXTURE: {
cache_entry_load_texture(ref, tag); cache_entry_load_texture(ref, tag);
res = ref.e->texture; result = ref.e->texture;
} break; } break;
case CACHE_ENTRY_KIND_SHEET: { case CACHE_ENTRY_KIND_SHEET: {
cache_entry_load_sheet(ref, tag); cache_entry_load_sheet(ref, tag);
res = ref.e->sheet; result = ref.e->sheet;
} break; } break;
default: { P_Panic(Lit("Unknown sprite cache entry kind")); } break; default: { P_Panic(Lit("Unknown sprite cache entry kind")); } break;
} }
@ -996,7 +996,7 @@ internal void *data_from_tag_internal(S_Scope *scope, S_Tag tag, enum cache_entr
} }
} }
return res; return result;
} }
/* ========================== * /* ========================== *
@ -1044,24 +1044,24 @@ S_SheetFrame sprite_sheet_get_frame(S_Sheet *sheet, u32 index)
if (index < sheet->frames_count ) { if (index < sheet->frames_count ) {
return sheet->frames[index]; return sheet->frames[index];
} }
S_SheetFrame res = ZI; S_SheetFrame result = ZI;
res.index = 0; result.index = 0;
res.duration = 0.1; result.duration = 0.1;
res.clip = AllClipped; result.clip = AllClipped;
return res; return result;
} }
S_SheetSpan sprite_sheet_get_span(S_Sheet *sheet, String name) S_SheetSpan sprite_sheet_get_span(S_Sheet *sheet, String name)
{ {
S_SheetSpan res = ZI; S_SheetSpan result = ZI;
if (sheet->spans_count > 0) { if (sheet->spans_count > 0) {
u64 hash = HashFnv64(Fnv64Basis, name); u64 hash = HashFnv64(Fnv64Basis, name);
S_SheetSpan *entry = (S_SheetSpan *)DictValueFromHash(sheet->spans_dict, hash); S_SheetSpan *entry = (S_SheetSpan *)DictValueFromHash(sheet->spans_dict, hash);
if (entry) { if (entry) {
res = *entry; result = *entry;
} }
} }
return res; return result;
} }
S_SheetSlice sprite_sheet_get_slice(S_Sheet *sheet, String name, u32 frame_index) S_SheetSlice sprite_sheet_get_slice(S_Sheet *sheet, String name, u32 frame_index)
@ -1075,32 +1075,32 @@ S_SheetSlice sprite_sheet_get_slice(S_Sheet *sheet, String name, u32 frame_index
} }
/* Return 'pivot' by default */ /* Return 'pivot' by default */
S_SheetSlice res = ZI; S_SheetSlice result = ZI;
if (EqString(name, Lit("pivot"))) { if (EqString(name, Lit("pivot"))) {
/* 'pivot' slice does not exist, return center */ /* 'pivot' slice does not exist, return center */
res.center = VEC2(0, 0); result.center = VEC2(0, 0);
res.center_px = MulVec2(sheet->frame_size, 0.5f); result.center_px = MulVec2(sheet->frame_size, 0.5f);
res.dir_px = VEC2(res.center_px.x, 0); result.dir_px = VEC2(result.center_px.x, 0);
res.dir = VEC2(0, -0.5); result.dir = VEC2(0, -0.5);
} else { } else {
res = sprite_sheet_get_slice(sheet, Lit("pivot"), frame_index); result = sprite_sheet_get_slice(sheet, Lit("pivot"), frame_index);
} }
return res; return result;
} }
S_SheetSliceArray sprite_sheet_get_slices(S_Sheet *sheet, String name, u32 frame_index) S_SheetSliceArray sprite_sheet_get_slices(S_Sheet *sheet, String name, u32 frame_index)
{ {
S_SheetSliceArray res = ZI; S_SheetSliceArray result = ZI;
if (sheet->slice_groups_count > 0) { if (sheet->slice_groups_count > 0) {
u64 hash = HashFnv64(Fnv64Basis, name); u64 hash = HashFnv64(Fnv64Basis, name);
S_SheetSliceGroup *group = (S_SheetSliceGroup *)DictValueFromHash(sheet->slice_groups_dict, hash); S_SheetSliceGroup *group = (S_SheetSliceGroup *)DictValueFromHash(sheet->slice_groups_dict, hash);
if (group) { if (group) {
res.count = group->per_frame_count; result.count = group->per_frame_count;
res.slices = &group->frame_slices[frame_index * group->per_frame_count]; result.slices = &group->frame_slices[frame_index * group->per_frame_count];
} }
} }
return res; return result;
} }
/* ========================== * /* ========================== *

View File

@ -300,31 +300,31 @@ internal String get_ent_debug_text(Arena *arena, Ent *ent)
const u8 hex[] = "0123456789abcdef"; const u8 hex[] = "0123456789abcdef";
String res = ZI; String result = ZI;
res.text = PushDry(arena, u8); result.text = PushDry(arena, u8);
res.len += StringFormat(arena, Lit("[%F]"), FmtUid(ent->id.uid)).len; result.len += StringFormat(arena, Lit("[%F]"), FmtUid(ent->id.uid)).len;
{ {
b32 transmitting = sim_ent_has_prop(ent, SEPROP_SYNC_SRC); b32 transmitting = sim_ent_has_prop(ent, SEPROP_SYNC_SRC);
b32 receiving = sim_ent_has_prop(ent, SEPROP_SYNC_DST); b32 receiving = sim_ent_has_prop(ent, SEPROP_SYNC_DST);
if (transmitting & receiving) { if (transmitting & receiving) {
res.len += CopyString(arena, Lit(" networked (sending & receiving)")).len; result.len += CopyString(arena, Lit(" networked (sending & receiving)")).len;
} else if (transmitting) { } else if (transmitting) {
res.len += CopyString(arena, Lit(" networked (sending)")).len; result.len += CopyString(arena, Lit(" networked (sending)")).len;
} else if (receiving) { } else if (receiving) {
res.len += CopyString(arena, Lit(" networked (receiving)")).len; result.len += CopyString(arena, Lit(" networked (receiving)")).len;
} else { } else {
res.len += CopyString(arena, Lit(" local")).len; result.len += CopyString(arena, Lit(" local")).len;
} }
} }
res.len += CopyString(arena, Lit("\n")).len; result.len += CopyString(arena, Lit("\n")).len;
res.len += StringFormat(arena, Lit("owner: [%F]\n"), FmtUid(ent->owner.uid)).len; result.len += StringFormat(arena, Lit("owner: [%F]\n"), FmtUid(ent->owner.uid)).len;
res.len += CopyString(arena, Lit("\n")).len; result.len += CopyString(arena, Lit("\n")).len;
{ {
res.len += CopyString(arena, Lit("props: 0x")).len; result.len += CopyString(arena, Lit("props: 0x")).len;
for (u64 chunk_index = countof(ent->props); chunk_index-- > 0;) { for (u64 chunk_index = countof(ent->props); chunk_index-- > 0;) {
u64 chunk = ent->props[chunk_index]; u64 chunk = ent->props[chunk_index];
for (u64 part_index = 8; part_index-- > 0;) { for (u64 part_index = 8; part_index-- > 0;) {
@ -332,53 +332,53 @@ internal String get_ent_debug_text(Arena *arena, Ent *ent)
u8 part = (chunk >> (part_index * 8)) & 0xFF; u8 part = (chunk >> (part_index * 8)) & 0xFF;
StringFromChar(arena, hex[(part >> 4) & 0x0F]); StringFromChar(arena, hex[(part >> 4) & 0x0F]);
StringFromChar(arena, hex[(part >> 0) & 0x0F]); StringFromChar(arena, hex[(part >> 0) & 0x0F]);
res.len += 2; result.len += 2;
} }
} }
} }
res.len += CopyString(arena, Lit("\n")).len; result.len += CopyString(arena, Lit("\n")).len;
} }
if (!sim_ent_id_eq(ent->parent, SIM_ENT_ROOT_ID)) { if (!sim_ent_id_eq(ent->parent, SIM_ENT_ROOT_ID)) {
res.len += StringFormat(arena, Lit("parent: [%F]\n"), FmtUid(ent->parent.uid)).len; result.len += StringFormat(arena, Lit("parent: [%F]\n"), FmtUid(ent->parent.uid)).len;
} }
if (!sim_ent_id_is_nil(ent->next) || !sim_ent_id_is_nil(ent->prev)) { if (!sim_ent_id_is_nil(ent->next) || !sim_ent_id_is_nil(ent->prev)) {
res.len += StringFormat(arena, Lit("prev: [%F]\n"), FmtUid(ent->prev.uid)).len; result.len += StringFormat(arena, Lit("prev: [%F]\n"), FmtUid(ent->prev.uid)).len;
res.len += StringFormat(arena, Lit("next: [%F]\n"), FmtUid(ent->next.uid)).len; result.len += StringFormat(arena, Lit("next: [%F]\n"), FmtUid(ent->next.uid)).len;
} }
res.len += CopyString(arena, Lit("\n")).len; result.len += CopyString(arena, Lit("\n")).len;
/* Pos */ /* Pos */
Xform xf = sim_ent_get_xform(ent); Xform xf = sim_ent_get_xform(ent);
Vec2 linear_velocity = ent->linear_velocity; Vec2 linear_velocity = ent->linear_velocity;
f32 angular_velocity = ent->angular_velocity; f32 angular_velocity = ent->angular_velocity;
res.len += StringFormat(arena, Lit("pos: (%F, %F)\n"), FmtFloat(xf.og.x), FmtFloat(xf.og.y)).len; result.len += StringFormat(arena, Lit("pos: (%F, %F)\n"), FmtFloat(xf.og.x), FmtFloat(xf.og.y)).len;
res.len += StringFormat(arena, Lit("linear velocity: (%F, %F)\n"), FmtFloat(linear_velocity.x), FmtFloat(linear_velocity.y)).len; result.len += StringFormat(arena, Lit("linear velocity: (%F, %F)\n"), FmtFloat(linear_velocity.x), FmtFloat(linear_velocity.y)).len;
res.len += StringFormat(arena, Lit("angular velocity: %F\n"), FmtFloat(angular_velocity)).len; result.len += StringFormat(arena, Lit("angular velocity: %F\n"), FmtFloat(angular_velocity)).len;
/* Test */ /* Test */
res.len += StringFormat(arena, Lit("collision dir: (%F, %F)\n"), FmtFloat(ent->collision_dir.x), FmtFloat(ent->collision_dir.y)).len; result.len += StringFormat(arena, Lit("collision dir: (%F, %F)\n"), FmtFloat(ent->collision_dir.x), FmtFloat(ent->collision_dir.y)).len;
/* Children */ /* Children */
if (!sim_ent_id_is_nil(ent->first) || !sim_ent_id_is_nil(ent->last)) { if (!sim_ent_id_is_nil(ent->first) || !sim_ent_id_is_nil(ent->last)) {
Ent *child = sim_ent_from_id(ss, ent->first); Ent *child = sim_ent_from_id(ss, ent->first);
if (!sim_ent_id_eq(ent->first, ent->last) || !child->valid) { if (!sim_ent_id_eq(ent->first, ent->last) || !child->valid) {
res.len += StringFormat(arena, Lit("first child: [%F]\n"), FmtUid(ent->first.uid)).len; result.len += StringFormat(arena, Lit("first child: [%F]\n"), FmtUid(ent->first.uid)).len;
res.len += StringFormat(arena, Lit("last child: [%F]\n"), FmtUid(ent->last.uid)).len; result.len += StringFormat(arena, Lit("last child: [%F]\n"), FmtUid(ent->last.uid)).len;
} }
while (child->valid) { while (child->valid) {
res.len += CopyString(arena, Lit("\n---------------------------------\n")).len; result.len += CopyString(arena, Lit("\n---------------------------------\n")).len;
res.len += CopyString(arena, Lit("CHILD\n")).len; result.len += CopyString(arena, Lit("CHILD\n")).len;
String child_text = get_ent_debug_text(scratch.arena, child); String child_text = get_ent_debug_text(scratch.arena, child);
res.len += IndentString(arena, child_text, 4).len; result.len += IndentString(arena, child_text, 4).len;
child = sim_ent_from_id(ss, child->next); child = sim_ent_from_id(ss, child->next);
} }
} }
EndScratch(scratch); EndScratch(scratch);
return res; return result;
} }
/* ========================== * /* ========================== *
@ -514,34 +514,34 @@ internal MergesortCompareFuncDef(ent_draw_order_cmp, arg_a, arg_b, udata)
Ent *a = *(Ent **)arg_a; Ent *a = *(Ent **)arg_a;
Ent *b = *(Ent **)arg_b; Ent *b = *(Ent **)arg_b;
i32 res = 0; i32 result = 0;
if (res == 0) { if (result == 0) {
/* Sort by light */ /* Sort by light */
b32 a_cmp = sim_ent_has_prop(a, SEPROP_LIGHT_TEST); b32 a_cmp = sim_ent_has_prop(a, SEPROP_LIGHT_TEST);
b32 b_cmp = sim_ent_has_prop(b, SEPROP_LIGHT_TEST); b32 b_cmp = sim_ent_has_prop(b, SEPROP_LIGHT_TEST);
res = (a_cmp > b_cmp) - (a_cmp < b_cmp); result = (a_cmp > b_cmp) - (a_cmp < b_cmp);
} }
if (res == 0) { if (result == 0) {
/* Sort by layer */ /* Sort by layer */
i32 a_cmp = a->layer; i32 a_cmp = a->layer;
i32 b_cmp = b->layer; i32 b_cmp = b->layer;
res = (a_cmp < b_cmp) - (a_cmp > b_cmp); result = (a_cmp < b_cmp) - (a_cmp > b_cmp);
} }
if (res == 0) { if (result == 0) {
/* Sort by sprite */ /* Sort by sprite */
u64 a_cmp = a->sprite.hash; u64 a_cmp = a->sprite.hash;
u64 b_cmp = b->sprite.hash; u64 b_cmp = b->sprite.hash;
res = (a_cmp < b_cmp) - (a_cmp > b_cmp); result = (a_cmp < b_cmp) - (a_cmp > b_cmp);
} }
if (res == 0) { if (result == 0) {
/* Sort by activation */ /* Sort by activation */
u64 a_cmp = a->activation_tick; u64 a_cmp = a->activation_tick;
u64 b_cmp = b->activation_tick; u64 b_cmp = b->activation_tick;
res = (a_cmp < b_cmp) - (a_cmp > b_cmp); result = (a_cmp < b_cmp) - (a_cmp > b_cmp);
} }
return res; return result;
} }
/* ========================== * /* ========================== *
@ -766,8 +766,8 @@ internal void user_update(P_Window *window)
if (ent_collider.count > 0) { if (ent_collider.count > 0) {
/* TODO: Can just use boolean GJK */ /* TODO: Can just use boolean GJK */
Xform ent_xf = sim_ent_get_xform(ent); Xform ent_xf = sim_ent_get_xform(ent);
CLD_CollisionResult res = collider_collision_points(&ent_collider, &mouse_shape, ent_xf, mouse_xf); CLD_CollisionResult collision_result = collider_collision_points(&ent_collider, &mouse_shape, ent_xf, mouse_xf);
if (res.num_points > 0) { if (collision_result.num_points > 0) {
hovered_ent = sim_ent_from_id(G.ss_blended, ent->top); hovered_ent = sim_ent_from_id(G.ss_blended, ent->top);
break; break;
} }
@ -1474,7 +1474,7 @@ internal void user_update(P_Window *window)
#if COLLIDER_DEBUG #if COLLIDER_DEBUG
if (sim_ent_has_prop(ent, SEPROP_COLLISION_DEBUG)) { if (sim_ent_has_prop(ent, SEPROP_COLLISION_DEBUG)) {
CollisionDebugData *data = &ent->collision_debug_data; CollisionDebugData *data = &ent->collision_debug_data;
CLD_CollisionResult collider_res = data->res; CLD_CollisionResult collision_reuslt = data->collision_result;
Ent *e0 = sim_ent_from_id(G.ss_blended, data->e0); Ent *e0 = sim_ent_from_id(G.ss_blended, data->e0);
Ent *e1 = sim_ent_from_id(G.ss_blended, data->e1); Ent *e1 = sim_ent_from_id(G.ss_blended, data->e1);
CLD_Shape e0_collider = e0->local_collider; CLD_Shape e0_collider = e0->local_collider;
@ -1505,27 +1505,27 @@ internal void user_update(P_Window *window)
u32 color_a_clipped = Rgba32F(1, 0, 0, 1); u32 color_a_clipped = Rgba32F(1, 0, 0, 1);
u32 color_b_clipped = Rgba32F(0, 1, 0, 1); u32 color_b_clipped = Rgba32F(0, 1, 0, 1);
{ {
Vec2 a = MulXformV2(G.world_to_ui_xf, collider_res.a0); Vec2 a = MulXformV2(G.world_to_ui_xf, collision_reuslt.a0);
Vec2 b = MulXformV2(G.world_to_ui_xf, collider_res.b0); Vec2 b = MulXformV2(G.world_to_ui_xf, collision_reuslt.b0);
draw_line(G.render_sig, a, b, thickness, color_line); draw_line(G.render_sig, a, b, thickness, color_line);
draw_circle(G.render_sig, a, radius, color_a, 10); draw_circle(G.render_sig, a, radius, color_a, 10);
draw_circle(G.render_sig, b, radius, color_b, 10); draw_circle(G.render_sig, b, radius, color_b, 10);
Vec2 a_clipped = MulXformV2(G.world_to_ui_xf, collider_res.a0_clipped); Vec2 a_clipped = MulXformV2(G.world_to_ui_xf, collision_reuslt.a0_clipped);
Vec2 b_clipped = MulXformV2(G.world_to_ui_xf, collider_res.b0_clipped); Vec2 b_clipped = MulXformV2(G.world_to_ui_xf, collision_reuslt.b0_clipped);
draw_line(G.render_sig, a_clipped, b_clipped, thickness, color_line_clipped); draw_line(G.render_sig, a_clipped, b_clipped, thickness, color_line_clipped);
draw_circle(G.render_sig, a_clipped, radius, color_a_clipped, 10); draw_circle(G.render_sig, a_clipped, radius, color_a_clipped, 10);
draw_circle(G.render_sig, b_clipped, radius, color_b_clipped, 10); draw_circle(G.render_sig, b_clipped, radius, color_b_clipped, 10);
} }
{ {
Vec2 a = MulXformV2(G.world_to_ui_xf, collider_res.a1); Vec2 a = MulXformV2(G.world_to_ui_xf, collision_reuslt.a1);
Vec2 b = MulXformV2(G.world_to_ui_xf, collider_res.b1); Vec2 b = MulXformV2(G.world_to_ui_xf, collision_reuslt.b1);
draw_line(G.render_sig, a, b, thickness, color_line); draw_line(G.render_sig, a, b, thickness, color_line);
draw_circle(G.render_sig, a, radius, color_a, 10); draw_circle(G.render_sig, a, radius, color_a, 10);
draw_circle(G.render_sig, b, radius, color_b, 10); draw_circle(G.render_sig, b, radius, color_b, 10);
Vec2 a_clipped = MulXformV2(G.world_to_ui_xf, collider_res.a1_clipped); Vec2 a_clipped = MulXformV2(G.world_to_ui_xf, collision_reuslt.a1_clipped);
Vec2 b_clipped = MulXformV2(G.world_to_ui_xf, collider_res.b1_clipped); Vec2 b_clipped = MulXformV2(G.world_to_ui_xf, collision_reuslt.b1_clipped);
draw_line(G.render_sig, a_clipped, b_clipped, thickness, color_line_clipped); draw_line(G.render_sig, a_clipped, b_clipped, thickness, color_line_clipped);
draw_circle(G.render_sig, a_clipped, radius, color_a_clipped, 10); draw_circle(G.render_sig, a_clipped, radius, color_a_clipped, 10);
draw_circle(G.render_sig, b_clipped, radius, color_b_clipped, 10); draw_circle(G.render_sig, b_clipped, radius, color_b_clipped, 10);
@ -1577,7 +1577,7 @@ internal void user_update(P_Window *window)
/* Draw menkowski */ /* Draw menkowski */
{ {
u32 color = collider_res.solved ? Rgba32F(0, 0, 0.25, 1) : Rgba32F(0, 0.25, 0.25, 1); u32 color = collision_reuslt.solved ? Rgba32F(0, 0, 0.25, 1) : Rgba32F(0, 0.25, 0.25, 1);
f32 thickness = 2; f32 thickness = 2;
u32 detail = 512; u32 detail = 512;
(UNUSED)thickness; (UNUSED)thickness;
@ -1608,8 +1608,8 @@ internal void user_update(P_Window *window)
u32 color = Rgba32F(1, 1, 1, 0.25); u32 color = Rgba32F(1, 1, 1, 0.25);
V2Array m = { V2Array m = {
.points = collider_res.prototype.points, .points = collision_reuslt.prototype.points,
.count = collider_res.prototype.len .count = collision_reuslt.prototype.len
}; };
for (u64 i = 0; i < m.count; ++i) m.points[i] = MulXformV2(G.world_to_ui_xf, m.points[i]); for (u64 i = 0; i < m.count; ++i) m.points[i] = MulXformV2(G.world_to_ui_xf, m.points[i]);
draw_poly_line(G.render_sig, m, 1, thickness, color); draw_poly_line(G.render_sig, m, 1, thickness, color);
@ -1624,7 +1624,7 @@ internal void user_update(P_Window *window)
u32 color_second = Rgba32F(0, 1, 0, 0.75); u32 color_second = Rgba32F(0, 1, 0, 0.75);
u32 color_third = Rgba32F(0, 0, 1, 0.75); u32 color_third = Rgba32F(0, 0, 1, 0.75);
struct collider_menkowski_simplex simplex = collider_res.simplex; CLD_MenkowskiSimplex simplex = collision_reuslt.simplex;
Vec2 simplex_points[] = { simplex.a.p, simplex.b.p, simplex.c.p }; Vec2 simplex_points[] = { simplex.a.p, simplex.b.p, simplex.c.p };
for (u64 i = 0; i < countof(simplex_points); ++i) simplex_points[i] = MulXformV2(G.world_to_ui_xf, simplex_points[i]); for (u64 i = 0; i < countof(simplex_points); ++i) simplex_points[i] = MulXformV2(G.world_to_ui_xf, simplex_points[i]);
V2Array simplex_array = { .count = simplex.len, .points = simplex_points }; V2Array simplex_array = { .count = simplex.len, .points = simplex_points };
@ -1653,7 +1653,7 @@ internal void user_update(P_Window *window)
f32 arrow_thickness = 4; f32 arrow_thickness = 4;
f32 arrowhead_height = 10; f32 arrowhead_height = 10;
Vec2 start = MulXformV2(G.world_to_ui_xf, VEC2(0, 0)); Vec2 start = MulXformV2(G.world_to_ui_xf, VEC2(0, 0));
Vec2 end = MulXformV2(G.world_to_ui_xf, MulVec2(NormVec2(collider_res.normal), len)); Vec2 end = MulXformV2(G.world_to_ui_xf, MulVec2(NormVec2(collision_reuslt.normal), len));
draw_arrow_line(G.render_sig, start, end, arrow_thickness, arrowhead_height, color); draw_arrow_line(G.render_sig, start, end, arrow_thickness, arrowhead_height, color);
} }
} }