From dd3427db839ee46d7680298ac0f6743f810266c4 Mon Sep 17 00:00:00 2001 From: jacob Date: Wed, 30 Jul 2025 15:58:38 -0500 Subject: [PATCH] res -> result --- src/app/app_core.c | 18 +-- src/ase/ase_core.c | 77 ++++++----- src/base/base_math.c | 212 ++++++++++++++--------------- src/base/base_memory.c | 8 +- src/base/base_string.c | 80 +++++------ src/base/base_uid.c | 26 ++-- src/bitbuff/bitbuff_core.c | 114 ++++++++-------- src/collider/collider_core.c | 248 +++++++++++++++++----------------- src/config.h | 2 +- src/dxc/dxc_core_win32.cpp | 16 +-- src/gp/gp_core_dx12.c | 46 +++---- src/json/json_core.c | 46 +++---- src/kernel/kernel_core.h | 28 ++-- src/mixer/mixer_core.c | 20 +-- src/mp3/mp3_core_mmf.c | 10 +- src/net/net_core.c | 32 ++--- src/platform/platform_win32.c | 150 ++++++++++---------- src/resource/resource_core.c | 30 ++-- src/settings/settings_core.c | 8 +- src/sim/sim_core.c | 62 ++++----- src/sim/sim_ent.c | 48 +++---- src/sim/sim_ent.h | 8 +- src/sim/sim_phys.c | 92 ++++++------- src/sim/sim_phys.h | 2 +- src/sim/sim_space.c | 6 +- src/sim/sim_step.c | 12 +- src/sprite/sprite_core.c | 82 +++++------ src/user/user_core.c | 106 +++++++-------- 28 files changed, 794 insertions(+), 795 deletions(-) diff --git a/src/app/app_core.c b/src/app/app_core.c index e64649bc..651f0d88 100644 --- a/src/app/app_core.c +++ b/src/app/app_core.c @@ -80,7 +80,7 @@ struct app_arg_list { /* TODO: Remove this and do real argument parsing */ 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 i = 0; 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); arg->key = key; arg->value = value; - if (res.last) { - res.last->next = arg; + if (result.last) { + result.last->next = arg; } else { - res.first = arg; + result.first = arg; } - res.last = arg; - ++res.count; + result.last = arg; + ++result.count; } key_start = i + 1; mode = 1; @@ -139,7 +139,7 @@ internal struct app_arg_list parse_args(Arena *arena, String args_str) default: break; } } - return res; + return result; } /* ========================== * @@ -224,7 +224,7 @@ void P_AppStartup(String args_str) P_CloseFIle(settings_file); P_LogInfoF("Deserializing settings file data: %F", FmtString(file_data)); 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) { P_LogInfoF("Failed to load settings file with error - %F", FmtString(error)); String msg = StringFormat(temp.arena, @@ -240,7 +240,7 @@ void P_AppStartup(String args_str) P_Panic(msg); } P_LogInfoF("Settings file loaded successfully"); - window_settings = *res; + window_settings = *deser; } else { P_LogInfoF("Settings file not found, loading default"); window_settings = default_window_settings(window); diff --git a/src/ase/ase_core.c b/src/ase/ase_core.c index e530bf0d..ba3a1a96 100644 --- a/src/ase/ase_core.c +++ b/src/ase/ase_core.c @@ -162,13 +162,13 @@ internal u32 reverse_bits(u32 v, u32 bit_count) return v >> 1; } else { - u32 res = 0; + u32 result = 0; for (u32 i = 0; i <= (bit_count / 2); ++i) { u32 inv = (bit_count - (i + 1)); - res |= ((v >> i) & 0x1) << inv; - res |= ((v >> inv) & 0x1) << i; + result |= ((v >> i) & 0x1) << inv; + 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; - struct huffman res = ZI; - res.max_code_bits = max_code_bits; - res.entries_count = (1 << max_code_bits); - res.entries = PushStructsNoZero(arena, struct huffman_entry, res.entries_count); + struct huffman result = ZI; + result.max_code_bits = max_code_bits; + result.entries_count = (1 << max_code_bits); + result.entries = PushStructsNoZero(arena, struct huffman_entry, result.entries_count); u32 code_length_hist[HUFFMAN_BIT_COUNT] = ZI; 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) { Assert(code_bits < countof(next_code)); 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); for (u32 entry_index = 0; entry_index < entry_count; ++entry_index) { /* TODO: Optimize this. It's bloating up the loading times. */ u32 base_index = (code << arbitrary_bits) | entry_index; - u32 index = reverse_bits(base_index, res.max_code_bits); - struct huffman_entry *entry = &res.entries[index]; + u32 index = reverse_bits(base_index, result.max_code_bits); + struct huffman_entry *entry = &result.entries[index]; entry->symbol = (u16)i; entry->bits_used = (u16)code_bits; } } } - return res; + return result; } 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); struct huffman_entry *entry = &huffman->entries[index]; - u16 res = entry->symbol; + u16 result = entry->symbol; skip_bits(bb, entry->bits_used); Assert(entry->bits_used > 0); - - return res; + return result; } internal void inflate(u8 *dst, u8 *encoded) @@ -549,7 +548,7 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded) __prof; TempArena scratch = BeginScratch(arena); - Ase_DecodedImage res = ZI; + Ase_DecodedImage result = ZI; BB_Buff bb = BitbuffFromString(encoded); 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)); 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; } @@ -565,7 +564,7 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded) String msg = StringFormat(scratch.arena, Lit("Only 32 bit rgba color mode is supported (got %F)"), FmtUint(ase_header.color_depth)); - push_error_copy_msg(arena, &res.errors, msg); + push_error_copy_msg(arena, &result.errors, msg); goto abort; } @@ -578,10 +577,10 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded) u64 image_height = frame_height * frames_y; make_image_dimensions_squareish(&ase_header, &frames_x, &frames_y, &image_width, &image_height); - res.width = image_width; - res.height = image_height; + result.width = image_width; + result.height = image_height; /* 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; 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); if (layer->blend_mode != 0) { 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")); goto abort; } @@ -694,7 +693,7 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded) case CEL_TYPE_COMPRESSED_TILEMAP: { /* 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; } 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) { i32 image_x = image_left + cel_x; 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); } } @@ -794,12 +793,12 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded) abort: - if (res.errors.count <= 0) { - res.success = 1; + if (result.errors.count <= 0) { + result.success = 1; } EndScratch(scratch); - return res; + return result; } /* ========================== * @@ -810,7 +809,7 @@ Ase_DecodedSheet ase_decode_sheet(Arena *arena, String encoded) { __prof; - Ase_DecodedSheet res = ZI; + Ase_DecodedSheet result = ZI; BB_Buff bb = BitbuffFromString(encoded); 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(BB_NumBytesRemaining(&br) == 0); - res.image_size = VEC2(image_width, image_height); - res.frame_size = VEC2(frame_width, frame_height); - res.num_frames = num_frames; - res.num_spans = num_spans; - res.num_slice_keys = num_slice_keys; - res.frame_head = frame_head; - res.span_head = span_head; - res.slice_key_head = slice_key_head; + result.image_size = VEC2(image_width, image_height); + result.frame_size = VEC2(frame_width, frame_height); + result.num_frames = num_frames; + result.num_spans = num_spans; + result.num_slice_keys = num_slice_keys; + result.frame_head = frame_head; + result.span_head = span_head; + result.slice_key_head = slice_key_head; - if (res.errors.count <= 0) { - res.success = 1; + if (result.errors.count <= 0) { + result.success = 1; } - return res; + return result; } diff --git a/src/base/base_math.c b/src/base/base_math.c index b5bc7733..b506513f 100644 --- a/src/base/base_math.c +++ b/src/base/base_math.c @@ -663,31 +663,31 @@ f32 ArcTanF32(f32 x) //- ArcTan2 f32 ArcTan2F32(f32 y, f32 x) { - f32 res; + f32 result; if (x == 0) { if (y < 0) { - res = 3 * Pi / 2; + result = 3 * Pi / 2; } else if (y == 0) { - res = 0; + result = 0; } else { - res = Pi / 2; + result = Pi / 2; } } else if (y == 0) { if (x < 0) { - res = Pi; + result = Pi; } else { - res = 0; + result = 0; } } else @@ -705,9 +705,9 @@ f32 ArcTan2F32(f32 y, f32 x) { offset = 0; } - res = ArcTanF32(y / x) + offset; + result = ArcTanF32(y / x) + offset; } - return res; + return result; } //- ArcSin @@ -1032,22 +1032,22 @@ Xform XformFromPos(Vec2 v) Xform XformFromRot(f32 r) { - Xform res; + Xform result; f32 c = CosF32(r); f32 s = SinF32(r); - res.bx = VEC2(c, s); - res.by = VEC2(-s, c); - res.og = VEC2(0, 0); - return res; + result.bx = VEC2(c, s); + result.by = VEC2(-s, c); + result.og = VEC2(0, 0); + return result; } Xform XformFromScale(Vec2 scale) { - Xform res; - res.bx = VEC2(scale.x, 0); - res.by = VEC2(0, scale.y); - res.og = VEC2(0, 0); - return res; + Xform result; + result.bx = VEC2(scale.x, 0); + result.by = VEC2(0, scale.y); + result.og = VEC2(0, 0); + return result; } Xform XformFromTrs(Trs trs) @@ -1117,21 +1117,21 @@ Xform ScaleXform(Xform xf, Vec2 scale) Xform WorldScaleXform(Xform xf, Vec2 scale) { - Xform res; - res.bx = MulVec2Vec2(xf.bx, scale); - res.by = MulVec2Vec2(xf.by, scale); - res.og = MulVec2Vec2(xf.og, scale); - return res; + Xform result; + result.bx = MulVec2Vec2(xf.bx, scale); + result.by = MulVec2Vec2(xf.by, scale); + result.og = MulVec2Vec2(xf.og, scale); + return result; } //- Lerp Xform LerpXform(Xform a, Xform b, f32 t) { - Xform res; - res.bx = SlerpVec2(a.bx, b.bx, t); - res.by = SlerpVec2(a.by, b.by, t); - res.og = LerpVec2(a.og, b.og, t); - return res; + Xform result; + result.bx = SlerpVec2(a.bx, b.bx, t); + result.by = SlerpVec2(a.by, b.by, t); + result.og = LerpVec2(a.og, b.og, t); + return result; } //- Invert @@ -1155,13 +1155,13 @@ Xform InvertXform(Xform xf) //- Mul Xform MulXform(Xform a, Xform b) { - Xform res; - res.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; - res.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; - res.og = MulXformV2(a, b.og); - return res; + Xform result; + result.bx.x = a.bx.x * b.bx.x + a.by.x * b.bx.y; + result.bx.y = a.bx.y * b.bx.x + a.by.y * b.bx.y; + result.by.x = a.bx.x * b.by.x + a.by.x * b.by.y; + result.by.y = a.bx.y * b.by.x + a.by.y * b.by.y; + result.og = MulXformV2(a, b.og); + return result; } Vec2 MulXformBasisV2(Xform xf, Vec2 v) @@ -1174,27 +1174,27 @@ Vec2 MulXformBasisV2(Xform xf, Vec2 v) Vec2 MulXformV2(Xform xf, Vec2 v) { - Vec2 res = MulXformBasisV2(xf, v); - res = AddVec2(res, xf.og); - return res; + Vec2 result = MulXformBasisV2(xf, v); + result = AddVec2(result, xf.og); + return result; } Quad MulXformQuad(Xform xf, Quad quad) { - Quad res; - res.p0 = MulXformV2(xf, quad.p0); - res.p1 = MulXformV2(xf, quad.p1); - res.p2 = MulXformV2(xf, quad.p2); - res.p3 = MulXformV2(xf, quad.p3); - return res; + Quad result; + result.p0 = MulXformV2(xf, quad.p0); + result.p1 = MulXformV2(xf, quad.p1); + result.p2 = MulXformV2(xf, quad.p2); + result.p3 = MulXformV2(xf, quad.p3); + return result; } Vec2 InvertXformBasisMulV2(Xform xf, Vec2 v) { Xform inv = InvertXform(xf); - Vec2 res = MulXformBasisV2(inv, v); - return res; + Vec2 result = MulXformBasisV2(inv, v); + return result; } /* 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 Xform BasisFromXform(Xform xf) { - Xform res = ZI; - res.bx = xf.bx; - res.by = xf.by; - return res; + Xform result = ZI; + result.bx = xf.bx; + result.by = xf.by; + return result; } f32 DeterminantFromXform(Xform xf) @@ -1254,22 +1254,22 @@ Vec2 ScaleFromXform(Xform xf) Quad QuadFromRect(Rect rect) { - Quad res; - res.p0 = VEC2(rect.x, rect.y); /* Top left */ - res.p1 = VEC2(rect.x + rect.width, rect.y); /* Top right */ - res.p2 = VEC2(rect.x + rect.width, rect.y + rect.height); /* Bottom right */ - res.p3 = VEC2(rect.x, rect.y + rect.height); /* Bottom left */ - return res; + Quad result; + result.p0 = VEC2(rect.x, rect.y); /* Top left */ + result.p1 = VEC2(rect.x + rect.width, rect.y); /* Top right */ + result.p2 = VEC2(rect.x + rect.width, rect.y + rect.height); /* Bottom right */ + result.p3 = VEC2(rect.x, rect.y + rect.height); /* Bottom left */ + return result; } Quad QuadFromAabb(Aabb aabb) { - Quad res; - res.p0 = VEC2(aabb.p0.x, aabb.p0.y); /* Top left */ - res.p1 = VEC2(aabb.p1.x, aabb.p0.y); /* Top right */ - res.p2 = VEC2(aabb.p1.x, aabb.p1.y); /* Bottom right */ - res.p3 = VEC2(aabb.p0.x, aabb.p1.y); /* Bottom left */ - return res; + Quad result; + result.p0 = VEC2(aabb.p0.x, aabb.p0.y); /* Top left */ + result.p1 = VEC2(aabb.p1.x, aabb.p0.y); /* Top right */ + result.p2 = VEC2(aabb.p1.x, aabb.p1.y); /* Bottom right */ + result.p3 = VEC2(aabb.p0.x, aabb.p1.y); /* Bottom left */ + return result; } 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 right = MulVec2(dir_perp, width); - Quad res; - res.p0 = AddVec2(start, left); - res.p1 = AddVec2(start, right); - res.p2 = AddVec2(end, right); - res.p3 = AddVec2(end, left); - return res; + Quad result; + result.p0 = AddVec2(start, left); + result.p1 = AddVec2(start, right); + result.p2 = AddVec2(end, right); + result.p3 = AddVec2(end, left); + return result; } Quad QuadFromRay(Vec2 pos, Vec2 rel, f32 thickness) @@ -1307,22 +1307,22 @@ Quad ScaleQuad(Quad q, f32 s) Quad RoundQuad(Quad quad) { - Quad res; - res.p0 = RoundVec2(quad.p0); - res.p1 = RoundVec2(quad.p1); - res.p2 = RoundVec2(quad.p2); - res.p3 = RoundVec2(quad.p3); - return res; + Quad result; + result.p0 = RoundVec2(quad.p0); + result.p1 = RoundVec2(quad.p1); + result.p2 = RoundVec2(quad.p2); + result.p3 = RoundVec2(quad.p3); + return result; } Quad FloorQuad(Quad quad) { - Quad res; - res.p0 = FloorVec2(quad.p0); - res.p1 = FloorVec2(quad.p1); - res.p2 = FloorVec2(quad.p2); - res.p3 = FloorVec2(quad.p3); - return res; + Quad result; + result.p0 = FloorVec2(quad.p0); + result.p1 = FloorVec2(quad.p1); + result.p2 = FloorVec2(quad.p2); + result.p3 = FloorVec2(quad.p3); + return result; } //////////////////////////////// @@ -1331,12 +1331,12 @@ Quad FloorQuad(Quad quad) /* https://box2d.org/files/ErinCatto_SoftConstraints_GDC2011.pdf */ SoftSpring MakeSpring(f32 hertz, f32 damping_ratio, f32 dt) { - SoftSpring res; + SoftSpring result; if (hertz == 0.0f) { - res.bias_rate = 0; - res.mass_scale = 1; - res.impulse_scale = 0; + result.bias_rate = 0; + result.mass_scale = 1; + result.impulse_scale = 0; } else { @@ -1344,11 +1344,11 @@ SoftSpring MakeSpring(f32 hertz, f32 damping_ratio, f32 dt) f32 a = 2 * damping_ratio + angular_frequency * dt; f32 b = angular_frequency * a * dt; f32 c = 1 / (b + 1); - res.bias_rate = angular_frequency / a; - res.mass_scale = b * c; - res.impulse_scale = c; + result.bias_rate = angular_frequency / a; + result.mass_scale = b * 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], b30 = m2.e[3][0], b31 = m2.e[3][1], b32 = m2.e[3][2], b33 = m2.e[3][3]; - Mat4x4 res; - res.e[0][0] = a00 * b00 + a10 * b01 + a20 * b02 + a30 * b03; - res.e[0][1] = a01 * b00 + a11 * b01 + a21 * b02 + a31 * b03; - res.e[0][2] = a02 * b00 + a12 * b01 + a22 * b02 + a32 * b03; - res.e[0][3] = a03 * b00 + a13 * b01 + a23 * b02 + a33 * b03; - res.e[1][0] = a00 * b10 + a10 * b11 + a20 * b12 + a30 * b13; - res.e[1][1] = a01 * b10 + a11 * b11 + a21 * b12 + a31 * b13; - res.e[1][2] = a02 * b10 + a12 * b11 + a22 * b12 + a32 * b13; - res.e[1][3] = a03 * b10 + a13 * b11 + a23 * b12 + a33 * b13; - res.e[2][0] = a00 * b20 + a10 * b21 + a20 * b22 + a30 * b23; - res.e[2][1] = a01 * b20 + a11 * b21 + a21 * b22 + a31 * b23; - res.e[2][2] = a02 * b20 + a12 * b21 + a22 * b22 + a32 * b23; - res.e[2][3] = a03 * b20 + a13 * b21 + a23 * b22 + a33 * b23; - res.e[3][0] = a00 * b30 + a10 * b31 + a20 * b32 + a30 * b33; - res.e[3][1] = a01 * b30 + a11 * b31 + a21 * b32 + a31 * b33; - res.e[3][2] = a02 * b30 + a12 * b31 + a22 * b32 + a32 * b33; - res.e[3][3] = a03 * b30 + a13 * b31 + a23 * b32 + a33 * b33; + Mat4x4 result; + result.e[0][0] = a00 * b00 + a10 * b01 + a20 * b02 + a30 * b03; + result.e[0][1] = a01 * b00 + a11 * b01 + a21 * b02 + a31 * b03; + result.e[0][2] = a02 * b00 + a12 * b01 + a22 * b02 + a32 * b03; + result.e[0][3] = a03 * b00 + a13 * b01 + a23 * b02 + a33 * b03; + result.e[1][0] = a00 * b10 + a10 * b11 + a20 * b12 + a30 * b13; + result.e[1][1] = a01 * b10 + a11 * b11 + a21 * b12 + a31 * b13; + result.e[1][2] = a02 * b10 + a12 * b11 + a22 * b12 + a32 * b13; + result.e[1][3] = a03 * b10 + a13 * b11 + a23 * b12 + a33 * b13; + result.e[2][0] = a00 * b20 + a10 * b21 + a20 * b22 + a30 * b23; + result.e[2][1] = a01 * b20 + a11 * b21 + a21 * b22 + a31 * b23; + result.e[2][2] = a02 * b20 + a12 * b21 + a22 * b22 + a32 * b23; + result.e[2][3] = a03 * b20 + a13 * b21 + a23 * b22 + a33 * b23; + result.e[3][0] = a00 * b30 + a10 * b31 + a20 * b32 + a30 * b33; + result.e[3][1] = a01 * b30 + a11 * b31 + a21 * b32 + a31 * b33; + result.e[3][2] = a02 * b30 + a12 * b31 + a22 * b32 + a32 * b33; + result.e[3][3] = a03 * b30 + a13 * b31 + a23 * b32 + a33 * b33; - return res; + return result; } diff --git a/src/base/base_memory.c b/src/base/base_memory.c index 0b8b9336..21fadb11 100644 --- a/src/base/base_memory.c +++ b/src/base/base_memory.c @@ -80,16 +80,16 @@ void *memset(void *dst, i32 c, u64 n) __attribute((section(".text.memcmp"))) i32 memcmp(const void *p1, const void *p2, u64 n) { - i32 res = 0; + i32 result = 0; for (u64 i = 0; i < n; ++i) { - res = ((u8 *)p1)[i] - ((u8 *)p2)[i]; - if (res != 0) + result = ((u8 *)p1)[i] - ((u8 *)p2)[i]; + if (result != 0) { break; } } - return res; + return result; } #endif /* !CrtlibIsEnabled */ diff --git a/src/base/base_string.c b/src/base/base_string.c index 07a9e663..d20a73bf 100644 --- a/src/base/base_string.c +++ b/src/base/base_string.c @@ -174,23 +174,23 @@ String StringFromF64(Arena *arena, f64 f, u32 precision) String StringFromhandle(Arena *arena, u64 v0, u64 v1) { - String res = ZI; - res.text = PushDry(arena, u8); - res.len += CopyString(arena, Lit("h")).len; - res.len += StringFromU64(arena, v0, 16, 0).len; - res.len += CopyString(arena, Lit("x")).len; - res.len += StringFromU64(arena, v1, 16, 0).len; - return res; + String result = ZI; + result.text = PushDry(arena, u8); + result.len += CopyString(arena, Lit("h")).len; + result.len += StringFromU64(arena, v0, 16, 0).len; + result.len += CopyString(arena, Lit("x")).len; + result.len += StringFromU64(arena, v1, 16, 0).len; + return result; } //- Uid conversion String StringFromUid(Arena *arena, Uid uid) { - String res = ZI; - res.text = PushDry(arena, u8); - res.len += StringFromU64(arena, (uid.hi >> 32), 16, 8).len; - return res; + String result = ZI; + result.text = PushDry(arena, u8); + result.len += StringFromU64(arena, (uid.hi >> 32), 16, 8).len; + return result; } //////////////////////////////// @@ -210,11 +210,11 @@ String CopyString(Arena *arena, String src) String CopyStringToBuffer(String dst, String src) { - String res = ZI; - res.len = MinU64(dst.len, src.len); - res.text = dst.text; - CopyBytes(res.text, src.text, res.len); - return res; + String result = ZI; + result.len = MinU64(dst.len, src.len); + result.text = dst.text; + CopyBytes(result.text, src.text, result.len); + return result; } //- Repeat @@ -328,9 +328,9 @@ String IndentString(Arena *arena, String str, u32 indent) String LowerString(Arena *arena, String str) { - String res = ZI; - res.text = PushStructsNoZero(arena, u8, str.len); - res.len = str.len; + String result = ZI; + result.text = PushStructsNoZero(arena, u8, str.len); + result.len = str.len; for (u64 i = 0; i < str.len; ++i) { @@ -339,10 +339,10 @@ String LowerString(Arena *arena, String str) { c += 32; } - res.text[i] = c; + result.text[i] = c; } - return res; + return result; } //- Compare @@ -370,27 +370,27 @@ b32 EqString(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) { - res = str1.text[i] - str2.text[i]; - if (res != 0) + result = str1.text[i] - str2.text[i]; + if (result != 0) { break; } } - if (res == 0) + if (result == 0) { if (str1.len > str2.len) { - res = str1.text[str2.len]; + result = str1.text[str2.len]; } else if (str2.len > str1.len) { - res = str2.text[str1.len]; + result = str2.text[str1.len]; } } - return res; + return result; } //- Match @@ -657,7 +657,7 @@ void EndCodepointIter(CodepointIter *iter) /* utf8 <- utf16 */ String StringFromString16(Arena *arena, String16 str16) { - String res = { + String result = { .len = 0, .text = PushDry(arena, u8) }; @@ -673,16 +673,16 @@ String StringFromString16(Arena *arena, String16 str16) CopyBytes(dst, encoded.chars8, encoded.count8); pos16 += decoded.advance16; - res.len += encoded.count8; + result.len += encoded.count8; } - return res; + return result; } /* utf8 <- utf32 */ String StringFromString32(Arena *arena, String32 str32) { - String res = { + String result = { .len = 0, .text = PushDry(arena, u8) }; @@ -698,10 +698,10 @@ String StringFromString32(Arena *arena, String32 str32) CopyBytes(dst, &encoded.chars8, encoded.count8); pos32 += 1; - res.len += encoded.count8; + result.len += encoded.count8; } - return res; + return result; } //- String encode @@ -709,7 +709,7 @@ String StringFromString32(Arena *arena, String32 str32) /* utf16 <- utf8 */ String16 String16FromString(Arena *arena, String str8) { - String16 res = { + String16 result = { .len = 0, .text = PushDry(arena, u16) }; @@ -725,16 +725,16 @@ String16 String16FromString(Arena *arena, String str8) CopyBytes(dst, encoded.chars16, (encoded.count16 << 1)); pos8 += decoded.advance8; - res.len += encoded.count16; + result.len += encoded.count16; } - return res; + return result; } /* utf32 <- utf8 */ String32 String32FromString(Arena *arena, String str8) { - String32 res = { + String32 result = { .len = 0, .text = PushDry(arena, u32) }; @@ -750,10 +750,10 @@ String32 String32FromString(Arena *arena, String str8) *dst = encoded.chars32; pos8 += decoded.advance8; - res.len += 1; + result.len += 1; } - return res; + return result; } //////////////////////////////// diff --git a/src/base/base_uid.c b/src/base/base_uid.c index 2584d6af..926cb75b 100644 --- a/src/base/base_uid.c +++ b/src/base/base_uid.c @@ -1,22 +1,22 @@ /* Returns a uid generated from the system's random number generator */ Uid UidFromTrueRand(void) { - Uid res = ZI; - TrueRand(StringFromStruct(&res)); - return res; + Uid result = ZI; + TrueRand(StringFromStruct(&result)); + return result; } /* Combines 2 uids into a new uid */ Uid CombineUid(Uid a, Uid b) { - Uid res; - res.hi = (a.hi * 3) + b.hi; - res.lo = (a.lo * 3) + b.lo; - res.hi += res.lo; - res.lo += res.hi; - res.hi = RandU64FromSeed(res.hi); - res.lo = RandU64FromSeed(res.lo); - res.hi += res.lo; - res.lo += res.hi; - return res; + Uid result; + result.hi = (a.hi * 3) + b.hi; + result.lo = (a.lo * 3) + b.lo; + result.hi += result.lo; + result.lo += result.hi; + result.hi = RandU64FromSeed(result.hi); + result.lo = RandU64FromSeed(result.lo); + result.hi += result.lo; + result.lo += result.hi; + return result; } diff --git a/src/bitbuff/bitbuff_core.c b/src/bitbuff/bitbuff_core.c index d66ce25e..3037c078 100644 --- a/src/bitbuff/bitbuff_core.c +++ b/src/bitbuff/bitbuff_core.c @@ -5,10 +5,10 @@ BB_Buff AllocBitbuff(u64 arena_reserve) { - BB_Buff res = ZI; - res.arena = AllocArena(arena_reserve); - res.is_backed_by_arena = 1; - return res; + BB_Buff result = ZI; + result.arena = AllocArena(arena_reserve); + result.is_backed_by_arena = 1; + return result; } void ReleaseBitbuff(BB_Buff *bb) @@ -22,9 +22,9 @@ void ReleaseBitbuff(BB_Buff *bb) BB_Buff BitbuffFromString(String s) { - BB_Buff res = ZI; - res.fixed_buffer = s; - return res; + BB_Buff result = ZI; + result.fixed_buffer = s; + return result; } //////////////////////////////// @@ -32,31 +32,31 @@ BB_Buff BitbuffFromString(String s) BB_Writer BB_WriterFromBuff(BB_Buff *bb) { - BB_Writer res = ZI; - res.bb = bb; + BB_Writer result = ZI; + result.bb = bb; if (bb->is_backed_by_arena) { - res.base = ArenaBase(bb->arena); + result.base = ArenaBase(bb->arena); } else { - res.base = bb->fixed_buffer.text; + result.base = bb->fixed_buffer.text; } - res.cur_bit = 0; + result.cur_bit = 0; #if BB_DebugIsEnabled - res.debug_enabled = 1; + result.debug_enabled = 1; #endif - return res; + return result; } /* Use this when writing external formats that will not verify bitbuff debug symbols / magic numbers */ BB_Writer BB_WriterFromBuffNoDebug(BB_Buff *bb) { - BB_Writer res = BB_WriterFromBuff(bb); + BB_Writer result = BB_WriterFromBuff(bb); #if BB_DebugIsEnabled - res.debug_enabled = 0; + result.debug_enabled = 0; #endif - return res; + return result; } /* FIXME: Handle overflowed bw */ @@ -74,11 +74,11 @@ u64 BB_GetNumBytesWritten(BB_Writer *bw) /* FIXME: Handle overflowed bw */ String BB_GetWritten(Arena *arena, BB_Writer *bw) { - String res = ZI; - res.len = (bw->cur_bit + 7) >> 3; - res.text = PushStructsNoZero(arena, u8, res.len); - CopyBytes(res.text, bw->base, res.len); - return res; + String result = ZI; + result.len = (bw->cur_bit + 7) >> 3; + result.text = PushStructsNoZero(arena, u8, result.len); + CopyBytes(result.text, bw->base, result.len); + return result; } /* 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) */ b32 BB_CheckWriterOverflowBits(BB_Writer *bw, u64 num_bits) { - b32 res = 0; + b32 result = 0; BB_Buff *bb = bw->bb; if (bw->overflowed) { - res = 1; + result = 1; } else { @@ -116,13 +116,13 @@ b32 BB_CheckWriterOverflowBits(BB_Writer *bw, u64 num_bits) { /* Writer overflowed fixed buffer */ Assert(0); - res = 1; + result = 1; bw->cur_bit = max_len << 3; 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 res = ZI; + BB_Reader result = ZI; if (!bb->is_backed_by_arena) { - res.base = bb->fixed_buffer.text; - res.base_len = bb->fixed_buffer.len; + result.base = bb->fixed_buffer.text; + result.base_len = bb->fixed_buffer.len; } else { Arena *arena = bb->arena; - res.base = ArenaBase(arena); - res.base_len = arena->pos; + result.base = ArenaBase(arena); + result.base_len = arena->pos; } - res.cur_bit = 0; + result.cur_bit = 0; #if BB_DebugIsEnabled - res.debug_enabled = 1; + result.debug_enabled = 1; #endif - return res; + return result; } /* 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 res = BB_ReaderFromBuff(bb); + BB_Reader result = BB_ReaderFromBuff(bb); #if BB_DebugIsEnabled - res.debug_enabled = 0; + result.debug_enabled = 0; #endif - return res; + return result; } /* 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 res = 0; + b32 result = 0; if (br->overflowed) { - res = 1; + result = 1; } else { @@ -418,12 +418,12 @@ b32 BB_CheckReaderOverflowBits(BB_Reader *br, u64 num_bits) { /* Tried to read past bitbuff memory */ Assert(0); - res = 1; + result = 1; br->cur_bit = base_len_bits; br->overflowed = 1; } } - return res; + return result; } //////////////////////////////// @@ -451,7 +451,7 @@ u64 BB_ReadUBitsNoMagic(BB_Reader *br, u8 num_bits) return 0; } - u64 res = 0; + u64 result = 0; u8 offset = br->cur_bit & 7; u8 num_trailing_bits = 0; @@ -462,7 +462,7 @@ u64 BB_ReadUBitsNoMagic(BB_Reader *br, u8 num_bits) u8 mix_byte = *at; mix_byte >>= offset; mix_byte &= (1 << num_trailing_bits) - 1; - res = mix_byte; + result = mix_byte; num_bits -= 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); } tmp &= mask; - res |= tmp << num_trailing_bits; + result |= tmp << num_trailing_bits; br->cur_bit += num_bits; - return res; + return result; } 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); - u64 res = 0; + u64 result = 0; for (u64 i = 0; i <= 9; ++i) { u64 part = BB_ReadUBits(br, 8); u8 is_last_part = part <= 0x7F; - res |= (part & 0x7F) << (i * 7); + result |= (part & 0x7F) << (i * 7); if (is_last_part) { break; } } - return res; + return result; } /* Read a variable length signed integer. @@ -552,18 +552,18 @@ i64 BB_ReadIV(BB_Reader *br) } num_bits = MinU8(num_bits, 64); - i64 res; + i64 result; if (sign_bit) { /* Sign bit is 1, indicating result is stored in twos compliment */ - res = BB_IntFromTwosCompliment(tc, num_bits); + result = BB_IntFromTwosCompliment(tc, num_bits); } 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) { BB_ReadDebugMagic(br, BB_DebugMagicKind_String, 0); - String res = ZI; + String result = ZI; u64 len = BB_ReadUV(br); u8 *src = BB_ReadBytesRaw(br, len); if (src != 0) { - res.len = len; - res.text = PushStructsNoZero(arena, u8, len); - CopyBytes(res.text, src, len); + result.len = len; + result.text = PushStructsNoZero(arena, u8, len); + CopyBytes(result.text, src, len); } - return res; + return result; } /* Will fill dst with zeroes if bitbuff overflows */ diff --git a/src/collider/collider_core.c b/src/collider/collider_core.c index a37a4b68..8d406d36 100644 --- a/src/collider/collider_core.c +++ b/src/collider/collider_core.c @@ -63,22 +63,22 @@ internal CLD_SupportPoint collider_get_support_point_internal(CLD_Shape *shape, furthest = MulXformV2(xf, furthest); - CLD_SupportPoint res; - res.p = furthest; - res.i = furthest_index; - return res; + CLD_SupportPoint result; + result.p = furthest; + result.i = furthest_index; + return result; } CLD_Shape collider_from_quad(Quad quad) { - CLD_Shape res; - res.points[0] = quad.p0; - res.points[1] = quad.p1; - res.points[2] = quad.p2; - res.points[3] = quad.p3; - res.count = 4; - res.radius = 0; - return res; + CLD_Shape result; + result.points[0] = quad.p0; + result.points[1] = quad.p1; + result.points[2] = quad.p2; + result.points[3] = quad.p3; + result.count = 4; + result.radius = 0; + return result; } 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) { - CLD_MenkowskiPoint res; - res.s0 = collider_get_support_point(shape0, xf0, dir); - res.s1 = collider_get_support_point(shape1, xf1, NegVec2(dir)); - res.p = SubVec2(res.s0.p, res.s1.p); - return res; + CLD_MenkowskiPoint result; + result.s0 = collider_get_support_point(shape0, xf0, dir); + result.s1 = collider_get_support_point(shape1, xf1, NegVec2(dir)); + result.p = SubVec2(result.s0.p, result.s1.p); + 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 res; - res.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; - res.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; - return res; + Aabb result; + result.p0.x = collider_get_support_point(shape, xf, VEC2(-1, 0)).p.x - COLLISION_TOLERANCE; + result.p0.y = collider_get_support_point(shape, xf, VEC2(0, -1)).p.y - COLLISION_TOLERANCE; + result.p1.x = collider_get_support_point(shape, xf, VEC2(1, 0)).p.x + COLLISION_TOLERANCE; + result.p1.y = collider_get_support_point(shape, xf, VEC2(0, 1)).p.y + COLLISION_TOLERANCE; + return result; } Aabb collider_aabb_from_combined_aabb(Aabb b0, Aabb b1) { - Aabb res; - res.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)); - res.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)); - return res; + Aabb result; + result.p0.x = MinF32(MinF32(b0.p0.x, b0.p1.x), MinF32(b1.p0.x, b1.p1.x)); + result.p0.y = MinF32(MinF32(b0.p0.y, b0.p1.y), MinF32(b1.p0.y, b1.p1.y)); + result.p1.x = MaxF32(MaxF32(b0.p0.x, b0.p1.x), MaxF32(b1.p0.x, b1.p1.x)); + result.p1.y = MaxF32(MaxF32(b0.p0.y, b0.p1.y), MaxF32(b1.p0.y, b1.p1.y)); + return result; } 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: #endif - struct gjk_result res = { + struct gjk_result result = { .simplex = s, .overlapping = overlapping, .final_dir = dir, @@ -303,7 +303,7 @@ internal struct gjk_result gjk_get_simplex(CLD_Shape *shape0, CLD_Shape *shape1, #endif }; - return res; + return result; } /* ========================== * @@ -323,9 +323,9 @@ struct epa_result { }; #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 -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 { 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; u32 proto_count = 0; - if (gjk_res.overlapping) { - CLD_MenkowskiSimplex s = gjk_res.simplex; + if (gjk_result.overlapping) { + CLD_MenkowskiSimplex s = gjk_result.simplex; proto = PushDry(scratch.arena, CLD_MenkowskiPoint); { 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; } } else { - normal = NormVec2(gjk_res.final_dir); - closest_feature.len = gjk_res.simplex.len; - closest_feature.a = gjk_res.simplex.a; - closest_feature.b = gjk_res.simplex.b; + normal = NormVec2(gjk_result.final_dir); + closest_feature.len = gjk_result.simplex.len; + closest_feature.a = gjk_result.simplex.a; + closest_feature.b = gjk_result.simplex.b; } #if COLLIDER_DEBUG abort: #endif - struct epa_result res = { + struct epa_result result = { .normal = normal, .closest_feature = closest_feature }; #if COLLIDER_DEBUG - res.dbg_step = dbg_step; - u32 len = MinU32(proto_count, countof(res.prototype.points)); + result.dbg_step = dbg_step; + u32 len = MinU32(proto_count, countof(result.prototype.points)); 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 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); } - struct clip_line_to_line_result res; - res.a0_clipped = AddVec2(a0, MulVec2(vab0, a0t)); - res.a1_clipped = AddVec2(a1, MulVec2(vab1, a1t)); - res.b0_clipped = AddVec2(b0, MulVec2(vab0, -b0t)); - res.b1_clipped = AddVec2(b1, MulVec2(vab1, -b1t)); - return res; + struct clip_line_to_line_result result; + result.a0_clipped = AddVec2(a0, MulVec2(vab0, a0t)); + result.a1_clipped = AddVec2(a1, MulVec2(vab1, a1t)); + result.b0_clipped = AddVec2(b0, MulVec2(vab0, -b0t)); + result.b1_clipped = AddVec2(b1, MulVec2(vab1, -b1t)); + return result; } 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); } - Vec2 res = AddVec2(a, MulVec2(vab, t)); - return res; + Vec2 result = AddVec2(a, MulVec2(vab, t)); + 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 res = ZI; + CLD_CollisionResult result = ZI; const f32 tolerance = COLLISION_TOLERANCE; 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; #endif - struct gjk_result gjk_res = ZI; - struct epa_result epa_res = ZI; + struct gjk_result gjk_result = ZI; + struct epa_result epa_result = ZI; /* Run GJK */ #if COLLIDER_DEBUG - gjk_res = gjk_get_simplex(shape0, shape1, xf0, xf1, min_unique_pt_dist_sq, dbg_step); - dbg_step = gjk_res.dbg_step; + gjk_result = gjk_get_simplex(shape0, shape1, xf0, xf1, min_unique_pt_dist_sq, dbg_step); + dbg_step = gjk_result.dbg_step; #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 DBGSTEP; /* Run EPA */ #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); - dbg_step = epa_res.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_result.dbg_step; #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 - normal = epa_res.normal; + normal = epa_result.normal; DBGSTEP; /* Determine collision */ - if (gjk_res.overlapping) { + if (gjk_result.overlapping) { colliding = 1; } 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 */ if (f.len == 1) { 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 */ StaticAssert(countof(shape0->points) <= 16); - CLD_MenkowskiFeature f = epa_res.closest_feature; + CLD_MenkowskiFeature f = epa_result.closest_feature; { b32 collapse0 = 0; @@ -691,11 +691,11 @@ CLD_CollisionResult collider_collision_points(CLD_Shape *shape0, CLD_Shape *shap b32 ignore_b = 1; if (!collapse0 && !collapse1) { /* 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); - Vec2 a0_clipped = clip_res.a0_clipped; - Vec2 a1_clipped = clip_res.a1_clipped; - Vec2 b0_clipped = clip_res.b0_clipped; - Vec2 b1_clipped = clip_res.b1_clipped; + 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_result.a0_clipped; + Vec2 a1_clipped = clip_result.a1_clipped; + Vec2 b0_clipped = clip_result.b0_clipped; + Vec2 b1_clipped = clip_result.b1_clipped; /* Calc midpoint between clipped a & b */ Vec2 va0a1_clipped = SubVec2(a1_clipped, a0_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; } } - res.a0_clipped = a0_clipped; - res.a1_clipped = a1_clipped; - res.b0_clipped = b0_clipped; - res.b1_clipped = b1_clipped; + result.a0_clipped = a0_clipped; + result.a1_clipped = a1_clipped; + result.b0_clipped = b0_clipped; + result.b1_clipped = b1_clipped; } else { Vec2 p0 = a0.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_sep = DotVec2(normal, p1) - DotVec2(normal, p0); ignore_a = 0; - res.a0_clipped = p0; - res.a1_clipped = p1; - res.b0_clipped = p0; - res.b1_clipped = p1; + result.a0_clipped = p0; + result.a1_clipped = p1; + result.b0_clipped = p0; + result.b1_clipped = p1; } /* Insert points */ @@ -754,25 +754,25 @@ CLD_CollisionResult collider_collision_points(CLD_Shape *shape0, CLD_Shape *shap point->point = b_midpoint; } - res.a0 = a0.p; - res.a1 = a1.p; - res.b0 = b0.p; - res.b1 = b1.p; + result.a0 = a0.p; + result.a1 = a1.p; + result.b0 = b0.p; + result.b1 = b1.p; } } #if COLLIDER_DEBUG - res.solved = 1; + result.solved = 1; abort: - res.simplex = gjk_res.simplex; - res.prototype.len = epa_res.prototype.len; - CopyBytes(res.prototype.points, epa_res.prototype.points, sizeof(res.prototype.points[0]) * res.prototype.len); + result.simplex = gjk_result.simplex; + result.prototype.len = epa_result.prototype.len; + CopyBytes(result.prototype.points, epa_result.prototype.points, sizeof(result.prototype.points[0]) * result.prototype.len); #endif - res.normal = normal; - res.points[0] = points[0]; - res.points[1] = points[1]; - res.num_points = num_points; - return res; + result.normal = normal; + result.points[0] = points[0]; + result.points[1] = points[1]; + result.num_points = num_points; + 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 res = ZI; + CLD_ClosestResult result = ZI; const f32 tolerance = COLLISION_TOLERANCE; 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; #endif - struct gjk_result gjk_res = ZI; - struct epa_result epa_res = ZI; + struct gjk_result gjk_result = ZI; + struct epa_result epa_result = ZI; /* Run GJK */ #if COLLIDER_DEBUG - gjk_res = gjk_get_simplex(shape0, shape1, xf0, xf1, min_unique_pt_dist_sq, dbg_step); - dbg_step = gjk_res.dbg_step; + gjk_result = gjk_get_simplex(shape0, shape1, xf0, xf1, min_unique_pt_dist_sq, dbg_step); + dbg_step = gjk_result.dbg_step; #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 DBGSTEP; /* Run EPA */ #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); - dbg_step = epa_res.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_result.dbg_step; #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 DBGSTEP; @@ -822,12 +822,12 @@ CLD_ClosestResult collider_closest_points(CLD_Shape *shape0, CLD_Shape *shape1, * Resolve points * ========================== */ - colliding = gjk_res.overlapping; - CLD_MenkowskiFeature f = epa_res.closest_feature; + colliding = gjk_result.overlapping; + CLD_MenkowskiFeature f = epa_result.closest_feature; if (f.len == 1) { p0 = f.a.s0.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 { Assert(f.len == 2); /* 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 = MulVec2(p1, ratio); 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 - res.solved = 1; + result.solved = 1; abort: - res.simplex = gjk_res.simplex; - res.prototype.len = epa_res.prototype.len; - CopyBytes(res.prototype.points, epa_res.prototype.points, sizeof(res.prototype.points[0]) *res.prototype.len); - res.simplex = gjk_res.simplex; + result.simplex = gjk_result.simplex; + result.prototype.len = epa_result.prototype.len; + CopyBytes(result.prototype.points, epa_result.prototype.points, sizeof(result.prototype.points[0]) *result.prototype.len); + result.simplex = gjk_result.simplex; #endif - res.p0 = p0; - res.p1 = p1; - res.colliding = colliding; - return res; + result.p0 = p0; + result.p1 = p1; + result.colliding = colliding; + return result; } /* ========================== * @@ -885,12 +885,12 @@ f32 collider_time_of_impact(CLD_Shape *c0, CLD_Shape *c1, Vec2 dir; Vec2 dir_neg; { - CLD_ClosestResult closest_points_res = collider_closest_points(c0, c1, xf0_t0, xf1_t0); - if (closest_points_res.colliding) { + CLD_ClosestResult closest_points = collider_closest_points(c0, c1, xf0_t0, xf1_t0); + if (closest_points.colliding) { /* Shapes are penetrating at t=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); dir = DivVec2(dir, t0_sep); /* Normalize */ dir_neg = NegVec2(dir); @@ -949,24 +949,24 @@ f32 collider_time_of_impact(CLD_Shape *c0, CLD_Shape *c1, /* TODO: Remove this (debugging) */ 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) { f32 angle = ((f32)i / detail) * (2 * Pi); Vec2 dir = Vec2FromAngle(angle); 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; - ++res.count; + ++result.count; } } - return res; + return result; } /* TODO: Remove this (debugging) */ V2Array cloud(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1) { /* FIXME: Account for radius */ - V2Array res = { .points = PushDry(arena, Vec2) }; + V2Array result = { .points = PushDry(arena, Vec2) }; Vec2 *points0 = shape0->points; Vec2 *points1 = shape1->points; 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) { Vec2 p1 = MulXformV2(xf1, points1[j]); *PushStructNoZero(arena, Vec2) = SubVec2(p0, p1); - ++res.count; + ++result.count; } } - return res; + return result; } /* ========================== * diff --git a/src/config.h b/src/config.h index 0152dd11..1db7bf16 100644 --- a/src/config.h +++ b/src/config.h @@ -69,7 +69,7 @@ # define SIM_MAX_ANGULAR_VELOCITY F32Infinity #endif -#define COLLIDER_DEBUG 0 +#define COLLIDER_DEBUG 1 #define COLLIDER_DEBUG_DETAILED 1 #define COLLIDER_DEBUG_DETAILED_DRAW_MENKOWSKI 1 diff --git a/src/dxc/dxc_core_win32.cpp b/src/dxc/dxc_core_win32.cpp index d7c0bdf4..f98cba0a 100644 --- a/src/dxc/dxc_core_win32.cpp +++ b/src/dxc/dxc_core_win32.cpp @@ -6,8 +6,8 @@ DXC_Result dxc_compile(Arena *arena, String shader_source, i32 num_args, String (UNUSED)shader_source; (UNUSED)num_args; (UNUSED)args; - DXC_Result res = ZI; - return res; + DXC_Result result = ZI; + return result; } #else @@ -33,7 +33,7 @@ DXC_Result dxc_compile(Arena *arena, String shader_source, i32 num_args, String { __prof; TempArena scratch = BeginScratch(arena); - DXC_Result res = ZI; + DXC_Result result = ZI; wchar_t **wstr_args = PushStructs(scratch.arena, wchar_t *, num_args); 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; blob_str.len = dxc_errors->GetBufferSize(); blob_str.text = (u8 *)dxc_errors->GetBufferPointer(); - res.errors = CopyString(arena, blob_str); + result.errors = CopyString(arena, blob_str); } /* Get status */ HRESULT dxc_hr = 0; compile_results->GetStatus(&dxc_hr); - res.success = SUCCEEDED(dxc_hr); + result.success = SUCCEEDED(dxc_hr); /* CopyStruct shader output */ - if (res.success) { + if (result.success) { CComPtr dxc_shader = 0; compile_results->GetOutput(DXC_OUT_OBJECT, IID_PPV_ARGS(&dxc_shader), 0); if (dxc_shader != 0) { String blob_str = ZI; blob_str.len = dxc_shader->GetBufferSize(); blob_str.text = (u8 *)dxc_shader->GetBufferPointer(); - res.dxc = CopyString(arena, blob_str); + result.dxc = CopyString(arena, blob_str); } } EndScratch(scratch); - return res; + return result; } #endif diff --git a/src/gp/gp_core_dx12.c b/src/gp/gp_core_dx12.c index 3c8341ba..7412a081 100644 --- a/src/gp/gp_core_dx12.c +++ b/src/gp/gp_core_dx12.c @@ -1250,12 +1250,12 @@ internal Readonly struct pipeline g_nil_pipeline = ZI; internal struct pipeline *pipeline_from_name(struct pipeline_scope *scope, String name) { __prof; - struct pipeline *res = &g_nil_pipeline; + struct pipeline *result = &g_nil_pipeline; u64 hash = HashFnv64(Fnv64Basis, name); struct pipeline *tmp = (struct pipeline *)DictValueFromHash(scope->refs, hash); if (tmp) { - res = tmp; + result = tmp; } else { { 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) { 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) @@ -2041,18 +2041,18 @@ internal u64 command_buffer_hash_from_size(u64 size) internal u64 align_up_pow2(u64 v) { - u64 res = 0; + u64 result = 0; if (v > 0) { - res = v - 1; - res |= res >> 1; - res |= res >> 2; - res |= res >> 4; - res |= res >> 8; - res |= res >> 16; - res |= res >> 32; - ++res; + result = v - 1; + result |= result >> 1; + result |= result >> 2; + result |= result >> 4; + result |= result >> 8; + result |= result >> 16; + result |= result >> 32; + ++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) @@ -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) { - struct D3D12_GPU_DESCRIPTOR_HANDLE res = ZI; - res.ptr = cdh->start_gpu_handle.ptr + descriptor->index * G.desc_sizes[descriptor->heap->type]; - return res; + struct D3D12_GPU_DESCRIPTOR_HANDLE result = ZI; + result.ptr = cdh->start_gpu_handle.ptr + descriptor->index * G.desc_sizes[descriptor->heap->type]; + 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 res = ZI; + G_MemoryInfo result = ZI; HRESULT hr = 0; IDXGIAdapter3 *dxgiAdapter3 = 0; @@ -3163,19 +3163,19 @@ G_MemoryInfo gp_query_memory_info(void) if (SUCCEEDED(hr)) { struct DXGI_QUERY_VIDEO_MEMORY_INFO info = ZI; IDXGIAdapter3_QueryVideoMemoryInfo(dxgiAdapter3, 0, DXGI_MEMORY_SEGMENT_GROUP_LOCAL, &info); - res.local_used = info.CurrentUsage; - res.local_budget = info.Budget; + result.local_used = info.CurrentUsage; + result.local_budget = info.Budget; } if (SUCCEEDED(hr)) { struct DXGI_QUERY_VIDEO_MEMORY_INFO info = ZI; IDXGIAdapter3_QueryVideoMemoryInfo(dxgiAdapter3, 0, DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, &info); - res.non_local_used = info.CurrentUsage; - res.non_local_budget = info.Budget; + result.non_local_used = info.CurrentUsage; + result.non_local_budget = info.Budget; } if (dxgiAdapter3) { IDXGIAdapter_Release(dxgiAdapter3); } - return res; + return result; } /* ========================== * diff --git a/src/json/json_core.c b/src/json/json_core.c index 520cdf88..57f2c643 100644 --- a/src/json/json_core.c +++ b/src/json/json_core.c @@ -89,9 +89,9 @@ internal struct token *push_token(Arena *arena, struct token_list *list) 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; u64 pos = 0; @@ -113,7 +113,7 @@ internal struct token_list lex(Arena *arena, String src) } /* Create token */ - struct token *t = push_token(arena, &res); + struct token *t = push_token(arena, &result); t->start = pos; if (pos >= src.len) { @@ -341,13 +341,13 @@ internal struct token_list lex(Arena *arena, String src) t->end = pos; /* Exit early if unknown token encountered */ - return res; + return result; } else { 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 */ if (whole_present) { @@ -481,10 +481,10 @@ internal f64 interpret_number(String src) while (pos <= whole_right) { u8 digit = MinU8(src.text[pos] - 48, 9); u64 exp = whole_right - pos; - res += digit * PowU64(10, exp); + result += digit * PowU64(10, exp); ++pos; } - res *= whole_sign; + result *= whole_sign; } /* Process fraction part */ @@ -498,7 +498,7 @@ internal f64 interpret_number(String src) ++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 */ @@ -513,18 +513,18 @@ internal f64 interpret_number(String src) } if (exponent_sign >= 0) { - res *= PowU64(10, exponent_whole); + result *= PowU64(10, exponent_whole); } 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) { - String res = { + String result = { .len = 0, .text = PushDry(arena, u8) }; @@ -533,7 +533,7 @@ internal String interpret_string(Arena *arena, String src, String *error) if (error) { *error = Lit("Malformed string."); } - return res; + return result; } /* Ignore beginning quote */ u64 pos = 1; @@ -550,37 +550,37 @@ internal String interpret_string(Arena *arena, String src, String *error) case '"': case '\\': case '/': { - append_char(arena, &res, src.text[pos]); + append_char(arena, &result, src.text[pos]); ++pos; } break; /* Backspace */ case 'b': { - append_char(arena, &res, '\b'); + append_char(arena, &result, '\b'); ++pos; } break; /* Formfeed */ case 'f': { - append_char(arena, &res, '\f'); + append_char(arena, &result, '\f'); ++pos; } break; /* Linefeed */ case 'n': { - append_char(arena, &res, '\n'); + append_char(arena, &result, '\n'); ++pos; } break; /* Carriage return */ case 'r': { - append_char(arena, &res, '\r'); + append_char(arena, &result, '\r'); ++pos; } break; /* Horizontal tab */ case 't': { - append_char(arena, &res, '\t'); + append_char(arena, &result, '\t'); ++pos; } break; @@ -594,7 +594,7 @@ internal String interpret_string(Arena *arena, String src, String *error) default: { if (error) { *error = Lit("Invalid escape character in string."); - return res; + return result; } } break; } @@ -612,7 +612,7 @@ internal String interpret_string(Arena *arena, String src, String *error) } break; default: { - append_char(arena, &res, src.text[pos]); + append_char(arena, &result, src.text[pos]); ++pos; } break; } @@ -625,7 +625,7 @@ internal String interpret_string(Arena *arena, String src, String *error) } } - return res; + return result; } /* ========================== * diff --git a/src/kernel/kernel_core.h b/src/kernel/kernel_core.h index e95a3f67..ed22724c 100644 --- a/src/kernel/kernel_core.h +++ b/src/kernel/kernel_core.h @@ -72,19 +72,19 @@ typedef struct K_float4x4 K_float4x4; struct K_float4x4 { f32 v[4][4]; }; Inline struct K_float4x4 K_Float4x4FromMat4x4(Mat4x4 v) { - struct K_float4x4 res; - StaticAssert(sizeof(res) == sizeof(v)); - CopyBytes(&res, v.e, sizeof(res)); - return res; + struct K_float4x4 result; + StaticAssert(sizeof(result) == sizeof(v)); + CopyBytes(&result, v.e, sizeof(result)); + return result; } struct K_float2x3 { f32 v[2][3]; }; Inline struct K_float2x3 K_Float2x3FromXform(Xform v) { - struct K_float2x3 res; - StaticAssert(sizeof(res) == sizeof(v)); - CopyBytes(&res, &v, sizeof(res)); - return res; + struct K_float2x3 result; + StaticAssert(sizeof(result) == sizeof(v)); + CopyBytes(&result, &v, sizeof(result)); + return result; } #else @@ -106,12 +106,12 @@ Inline struct K_float2x3 K_Float2x3FromXform(Xform v) float4 float4_from_uint_norm(uint v) { - float4 res; - res.r = ((v >> 0) & 0xFF) / 255.0; - res.g = ((v >> 8) & 0xFF) / 255.0; - res.b = ((v >> 16) & 0xFF) / 255.0; - res.a = ((v >> 24) & 0xFF) / 255.0; - return res; + float4 result; + result.r = ((v >> 0) & 0xFF) / 255.0; + result.g = ((v >> 8) & 0xFF) / 255.0; + result.b = ((v >> 16) & 0xFF) / 255.0; + result.a = ((v >> 24) & 0xFF) / 255.0; + return result; } /* Linear color from normalized sRGB */ diff --git a/src/mixer/mixer_core.c b/src/mixer/mixer_core.c index 748c755b..7ea40194 100644 --- a/src/mixer/mixer_core.c +++ b/src/mixer/mixer_core.c @@ -194,7 +194,7 @@ M_Handle mixer_play_ex(SND_Sound *sound, M_TrackDesc desc) /* NOTE: This is quite inefficient. */ M_TrackDesc mixer_track_get(M_Handle handle) { - M_TrackDesc res = ZI; + M_TrackDesc result = ZI; struct track *track = track_from_handle(handle); if (track) { @@ -204,13 +204,13 @@ M_TrackDesc mixer_track_get(M_Handle handle) /* Confirm handle is still valid now that we're locked */ track = track_from_handle(handle); if (track) { - res = track->desc; + result = track->desc; } } P_Unlock(&lock); } - return res; + return result; } /* NOTE: This is quite inefficient. */ @@ -263,9 +263,9 @@ M_PcmF32 mixer_update(Arena *arena, u64 frame_count) TempArena scratch = BeginScratch(arena); - M_PcmF32 res = ZI; - res.count = frame_count * 2; - res.samples = PushStructs(arena, f32, res.count); + M_PcmF32 result = ZI; + result.count = frame_count * 2; + result.samples = PushStructs(arena, f32, result.count); Vec2 listener_pos = 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; M_PcmF32 mix_pcm = { - .count = res.count, - .samples = PushStructs(scratch.arena, f32, res.count) + .count = result.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) { - 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); - return res; + return result; } diff --git a/src/mp3/mp3_core_mmf.c b/src/mp3/mp3_core_mmf.c index eb350dd3..23e446fb 100644 --- a/src/mp3/mp3_core_mmf.c +++ b/src/mp3/mp3_core_mmf.c @@ -20,7 +20,7 @@ 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 channel_count; @@ -84,7 +84,7 @@ MP3_Result mp3_decode(Arena *arena, String encoded, u32 sample_rate, u32 flags) * Read * ========================== */ - res.samples = PushDry(arena, i16); + result.samples = PushDry(arena, i16); u64 sample_bytes_read = 0; for (;;) { IMFSample *sample; @@ -96,7 +96,7 @@ MP3_Result mp3_decode(Arena *arena, String encoded, u32 sample_rate, u32 flags) /* Check if done */ if (sample_flags & MF_SOURCE_READERF_ENDOFSTREAM) { - res.success = 1; + result.success = 1; break; } Assert(sample_flags == 0); @@ -119,7 +119,7 @@ MP3_Result mp3_decode(Arena *arena, String encoded, u32 sample_rate, u32 flags) IMFSample_Release(sample); } - res.samples_count = sample_bytes_read / bytes_per_sample; + result.samples_count = sample_bytes_read / bytes_per_sample; /* ========================== * * Cleanup @@ -130,5 +130,5 @@ MP3_Result mp3_decode(Arena *arena, String encoded, u32 sample_rate, u32 flags) IStream_Release(i_stream); MFShutdown(); - return res; + return result; } diff --git a/src/net/net_core.c b/src/net/net_core.c index 74bb0fee..29ba85d0 100644 --- a/src/net/net_core.c +++ b/src/net/net_core.c @@ -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) { - struct host_channel_list res = ZI; + struct host_channel_list result = ZI; if (host_channel_id_eq(channel_id, HOST_CHANNEL_ID_ALL)) { for (u64 i = 0; i < host->num_channels_reserved; ++i) { struct host_channel *channel = &host->channels[i]; if (channel->valid) { struct host_channel_node *n = PushStruct(arena, struct host_channel_node); n->channel = channel; - if (res.last) { - res.last->next = n; + if (result.last) { + result.last->next = n; } else { - res.first = n; + result.first = n; } - res.last = n; + result.last = n; } } } else { @@ -231,11 +231,11 @@ internal struct host_channel_list host_channels_from_id(Arena *arena, N_Host *ho if (channel->valid) { struct host_channel_node *n = PushStruct(arena, struct host_channel_node); n->channel = channel; - res.first = n; - res.last = n; + result.first = n; + result.last = n; } } - return res; + return result; } 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) { - u64 res = Fnv64Basis; - res = HashFnv64(res, StringFromStruct(&channel_id)); - res = HashFnv64(res, StringFromStruct(&msg_id)); - return res; + u64 result = Fnv64Basis; + result = HashFnv64(result, StringFromStruct(&channel_id)); + result = HashFnv64(result, StringFromStruct(&msg_id)); + return result; } 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"); P_Sock *sock = host->sock; - P_SockReadResult res = ZI; - while ((res = P_ReadSock(scratch.arena, sock)).valid) { - P_Address address = res.address; - String data = res.data; + P_SockReadResult result = ZI; + while ((result = P_ReadSock(scratch.arena, sock)).valid) { + P_Address address = result.address; + String data = result.data; if (data.len > 0) { struct host_rcv_packet *packet = PushStruct(scratch.arena, struct host_rcv_packet); packet->address = address; diff --git a/src/platform/platform_win32.c b/src/platform/platform_win32.c index fbacb7c6..c33a7f6c 100644 --- a/src/platform/platform_win32.c +++ b/src/platform/platform_win32.c @@ -145,8 +145,8 @@ b32 P_W32_TryReleaseThread(P_W32_Thread *thread, f32 timeout_seconds) { /* Wait for thread to stop */ DWORD timeout_ms = (timeout_seconds > 10000000) ? INFINITE : RoundF32ToI32(timeout_seconds * 1000); - DWORD wait_res = WaitForSingleObject(handle, timeout_ms); - if (wait_res == WAIT_OBJECT_0) + DWORD wait_result = WaitForSingleObject(handle, timeout_ms); + if (wait_result == WAIT_OBJECT_0) { /* Release thread */ success = 1; @@ -1195,7 +1195,7 @@ P_DateTime P_W32_DateTimeFromWin32SystemTime(SYSTEMTIME st) String P_W32_StringFromWin32Path(Arena *arena, wchar_t *src) { - String res = { + String result = { .len = 0, .text = PushDry(arena, u8) }; @@ -1215,11 +1215,11 @@ String P_W32_StringFromWin32Path(Arena *arena, wchar_t *src) } dest[i] = byte; } - res.len += encoded.count8; + result.len += encoded.count8; 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 res = ZI; + P_W32_Address result = ZI; if (addr.family == P_AddressFamily_Ipv4) { - res.family = AF_INET; - res.size = sizeof(struct sockaddr_in); - res.sin.sin_port = addr.portnb; - res.sin.sin_family = res.family; - CopyBytes(&res.sin.sin_addr, addr.ipnb, 4); + result.family = AF_INET; + result.size = sizeof(struct sockaddr_in); + result.sin.sin_port = addr.portnb; + result.sin.sin_family = result.family; + CopyBytes(&result.sin.sin_addr, addr.ipnb, 4); } else { - res.family = AF_INET6; - res.sin6.sin6_port = addr.portnb; - res.sin6.sin6_family = res.family; - res.size = sizeof(struct sockaddr_in6); - CopyBytes(&res.sin6.sin6_addr.s6_addr, addr.ipnb, 16); + result.family = AF_INET6; + result.sin6.sin6_port = addr.portnb; + result.sin6.sin6_family = result.family; + result.size = sizeof(struct sockaddr_in6); + 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 */ @@ -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 res = ZI; + P_Address result = ZI; if (ws_addr.family == AF_INET) { - res.family = P_AddressFamily_Ipv4; - res.portnb = ws_addr.sin.sin_port; - CopyBytes(res.ipnb, &ws_addr.sin.sin_addr, 4); - res.valid = 1; + result.family = P_AddressFamily_Ipv4; + result.portnb = ws_addr.sin.sin_port; + CopyBytes(result.ipnb, &ws_addr.sin.sin_addr, 4); + result.valid = 1; } else if (ws_addr.family == AF_INET6) { - res.family = P_AddressFamily_Ipv6; - res.portnb = ws_addr.sin6.sin6_port; - CopyBytes(res.ipnb, &ws_addr.sin6.sin6_addr.s6_addr, 16); - res.valid = 1; + result.family = P_AddressFamily_Ipv6; + result.portnb = ws_addr.sin6.sin6_port; + CopyBytes(result.ipnb, &ws_addr.sin6.sin6_addr.s6_addr, 16); + result.valid = 1; } - return res; + return result; } //////////////////////////////// @@ -2068,8 +2068,8 @@ i64 P_TimeNs(void) struct P_W32_SharedCtx *g = &P_W32_shared_ctx; LARGE_INTEGER qpc; QueryPerformanceCounter(&qpc); - i64 res = (qpc.QuadPart - g->timer_start_qpc) * g->ns_per_qpc; - return res; + i64 result = (qpc.QuadPart - g->timer_start_qpc) * g->ns_per_qpc; + return result; } //////////////////////////////// @@ -2079,14 +2079,14 @@ String P_GetWritePath(Arena *arena) { u16 *p = 0; /* TODO: cache this? */ - HRESULT res = SHGetKnownFolderPath( + HRESULT result = SHGetKnownFolderPath( &FOLDERID_LocalAppData, 0, 0, &p ); String path = ZI; - if (res == S_OK) + if (result == S_OK) { path = P_W32_StringFromWin32Path(arena, p); } @@ -2521,14 +2521,14 @@ P_WatchInfoList P_ReadWatchWait(Arena *arena, P_Watch *dw) ov.hEvent, 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; 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); if (list.last) @@ -2544,8 +2544,8 @@ P_WatchInfoList P_ReadWatchWait(Arena *arena, P_Watch *dw) ++list.count; String16 name16 = ZI; - name16.text = res->FileName; - name16.len = res->FileNameLength / sizeof(wchar_t); + name16.text = result->FileName; + name16.len = result->FileNameLength / sizeof(wchar_t); info->name = StringFromString16(arena, name16); 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: { @@ -2589,17 +2589,17 @@ P_WatchInfoList P_ReadWatchWait(Arena *arena, P_Watch *dw) } break; } - if (res->NextEntryOffset == 0) + if (result->NextEntryOffset == 0) { done = 1; } 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); 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 res = ZI; + P_Address result = ZI; struct addrinfo hints = ZI; hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; hints.ai_flags = AI_PASSIVE; - struct addrinfo *ai_res = 0; - i32 status = getaddrinfo(ip_cstr, port_cstr, &hints, &ai_res); + struct addrinfo *ai_result = 0; + i32 status = getaddrinfo(ip_cstr, port_cstr, &hints, &ai_result); 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; - res.valid = 1; - res.family = P_AddressFamily_Ipv4; - res.portnb = sockaddr->sin_port; + struct sockaddr_in *sockaddr = (struct sockaddr_in *)ai_result->ai_addr; + result.valid = 1; + result.family = P_AddressFamily_Ipv4; + result.portnb = sockaddr->sin_port; StaticAssert(sizeof(sockaddr->sin_addr) == 4); - CopyBytes(res.ipnb, (void *)&sockaddr->sin_addr, 4); + CopyBytes(result.ipnb, (void *)&sockaddr->sin_addr, 4); break; } - else if (ai_res->ai_family == AF_INET6) + else if (ai_result->ai_family == AF_INET6) { /* TODO: Enable ipv6 */ #if 0 - struct sockaddr_in6 *sockaddr = (struct sockaddr_in6 *)ai_res->ai_addr; - res.valid = 1; - res.family = P_AddressFamily_Ipv6; - res.portnb = sockaddr->sin6_port; + struct sockaddr_in6 *sockaddr = (struct sockaddr_in6 *)ai_result->ai_addr; + result.valid = 1; + result.family = P_AddressFamily_Ipv6; + result.portnb = sockaddr->sin6_port; StaticAssert(sizeof(sockaddr->sin6_addr) == 16); - CopyBytes(res.ipnb, (void *)&sockaddr->sin6_addr, 16); + CopyBytes(result.ipnb, (void *)&sockaddr->sin6_addr, 16); break; #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) @@ -2903,8 +2903,8 @@ P_Address P_AddressFromString(String str) } } - P_Address res = P_AddressFromIpPortCstr(ip_cstr, port_cstr); - return res; + P_Address result = P_AddressFromIpPortCstr(ip_cstr, port_cstr); + return result; } 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 res = ZI; + String result = ZI; if (address.family == P_AddressFamily_Ipv6) { @@ -2954,10 +2954,10 @@ String P_StringFromAddress(Arena *arena, P_Address address) ip[i] = ntohs(address.ipnb[i]); } 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) @@ -3025,7 +3025,7 @@ P_SockReadResult P_ReadSock(Arena *arena, P_Sock *sock) read_buff.len = 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; 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); 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) { AddGstat(GSTAT_SOCK_BYTES_RECEIVED, size); - res.data.text = read_buff.text; - res.data.len = size; - res.valid = 1; + result.data.text = read_buff.text; + result.data.len = size; + result.valid = 1; /* PopStruct arena back to end of msg */ PopTo(arena, arena->pos - read_buff_size + size); @@ -3055,7 +3055,7 @@ P_SockReadResult P_ReadSock(Arena *arena, P_Sock *sock) #endif } - return res; + return result; } 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 res = ZI; + String result = ZI; if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(0)) { HANDLE handle = GetClipboardData(CF_UNICODETEXT); if (handle) { u16 *src_wstr = (u16 *)GlobalLock(handle); - res = StringFromString16(arena, String16FromWstrNoLimit(src_wstr)); + result = StringFromString16(arena, String16FromWstrNoLimit(src_wstr)); GlobalUnlock(handle); } CloseClipboard(); } - return res; + return result; } u32 P_GetLogicalProcessorCount(void) diff --git a/src/resource/resource_core.c b/src/resource/resource_core.c index f74f5eb3..05c94ce3 100644 --- a/src/resource/resource_core.c +++ b/src/resource/resource_core.c @@ -45,16 +45,16 @@ R_Resource resource_open(String name) { __prof; #if RESOURCES_EMBEDDED - R_Resource res = ZI; + R_Resource result = ZI; struct tar_entry *entry = tar_get(&G.archive, name); - res._data = entry->data; - res._name = entry->file_name; - res._exists = entry->valid; - return res; + result._data = entry->data; + result._name = entry->file_name; + result._exists = entry->valid; + return result; #else - R_Resource res = ZI; - if (name.len < countof(res._name_text)) { - u8 path_text[RESOURCE_NAME_LEN_MAX + (sizeof("res/") - 1)]; + R_Resource result = ZI; + if (name.len < countof(result._name_text)) { + u8 path_text[RESOURCE_NAME_LEN_MAX + (sizeof("result/") - 1)]; String path = ZI; { path_text[0] = 'r'; @@ -81,16 +81,16 @@ R_Resource resource_open(String name) P_CloseFIle(file); } - res._exists = file.valid && file_map.valid; - res._data = data; - res._file = file; - res._file_map = file_map; - res._name_len = name.len; - CopyBytes(res._name_text, name.text, name.len); + result._exists = file.valid && file_map.valid; + result._data = data; + result._file = file; + result._file_map = file_map; + result._name_len = name.len; + CopyBytes(result._name_text, name.text, name.len); } else { Assert(0); } - return res; + return result; #endif } diff --git a/src/settings/settings_core.c b/src/settings/settings_core.c index 9dd68317..79e0f531 100644 --- a/src/settings/settings_core.c +++ b/src/settings/settings_core.c @@ -46,14 +46,14 @@ P_WindowSettings *settings_deserialize(Arena *arena, String src, String *error_o JSON_Error json_error = ZI; 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) { - json_error = *parse_res.errors.first; + if (parse_result.errors.count > 0) { + json_error = *parse_result.errors.first; goto abort; } - JSON_Blob *root = parse_res.root; + JSON_Blob *root = parse_result.root; if (!root) { error = Lit("Root object not found."); goto abort; diff --git a/src/sim/sim_core.c b/src/sim/sim_core.c index ef43f932..096f33bd 100644 --- a/src/sim/sim_core.c +++ b/src/sim/sim_core.c @@ -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 *res = sim_client_nil(); + Client *result = sim_client_nil(); u64 channel_hash = hash_from_channel_id(channel_id); u64 bin_index = channel_hash % store->num_client_lookup_bins; 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)) { if (client->channel_hash == channel_hash) { - res = client; + result = client; break; } } - return res; + return result; } 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 res = VEC2I32(pos.x * SIM_TILES_PER_UNIT_SQRT, pos.y * SIM_TILES_PER_UNIT_SQRT); - res.x -= pos.x < 0; - res.y -= pos.y < 0; - return res; + Vec2I32 result = VEC2I32(pos.x * SIM_TILES_PER_UNIT_SQRT, pos.y * SIM_TILES_PER_UNIT_SQRT); + result.x -= pos.x < 0; + result.y -= pos.y < 0; + return result; } 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; - res.x = (f32)world_tile_index.x * tile_size; - res.y = (f32)world_tile_index.y * tile_size; - return res; + result.x = (f32)world_tile_index.x * tile_size; + result.y = (f32)world_tile_index.y * tile_size; + return result; } Vec2I32 sim_local_tile_index_from_world_tile_index(Vec2I32 world_tile_index) { - Vec2I32 res = world_tile_index; - res.x += res.x < 0; - res.y += res.y < 0; - res.x = res.x % SIM_TILES_PER_CHUNK_SQRT; - res.y = res.y % SIM_TILES_PER_CHUNK_SQRT; - res.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); - return res; + Vec2I32 result = world_tile_index; + result.x += result.x < 0; + result.y += result.y < 0; + result.x = result.x % SIM_TILES_PER_CHUNK_SQRT; + result.y = result.y % SIM_TILES_PER_CHUNK_SQRT; + result.x += (world_tile_index.x < 0) * (SIM_TILES_PER_CHUNK_SQRT - 1); + result.y += (world_tile_index.y < 0) * (SIM_TILES_PER_CHUNK_SQRT - 1); + return result; } Vec2I32 sim_world_tile_index_from_local_tile_index(Vec2I32 tile_chunk_index, Vec2I32 local_tile_index) { - Vec2I32 res = ZI; - res.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; - return res; + Vec2I32 result = ZI; + result.x = (tile_chunk_index.x * SIM_TILES_PER_CHUNK_SQRT) + local_tile_index.x; + result.y = (tile_chunk_index.y * SIM_TILES_PER_CHUNK_SQRT) + local_tile_index.y; + return result; } Vec2I32 sim_tile_chunk_index_from_world_tile_index(Vec2I32 world_tile_index) { - Vec2I32 res = world_tile_index; - res.x += res.x < 0; - res.y += res.y < 0; - res.x = res.x / SIM_TILES_PER_CHUNK_SQRT; - res.y = res.y / SIM_TILES_PER_CHUNK_SQRT; - res.x -= world_tile_index.x < 0; - res.y -= world_tile_index.y < 0; - return res; + Vec2I32 result = world_tile_index; + result.x += result.x < 0; + result.y += result.y < 0; + result.x = result.x / SIM_TILES_PER_CHUNK_SQRT; + result.y = result.y / SIM_TILES_PER_CHUNK_SQRT; + result.x -= world_tile_index.x < 0; + result.y -= world_tile_index.y < 0; + return result; } void sim_snapshot_set_tile(Snapshot *ss, Vec2I32 world_tile_index, TileKind tile_kind) diff --git a/src/sim/sim_ent.c b/src/sim/sim_ent.c index 0ba54453..3d4ba556 100644 --- a/src/sim/sim_ent.c +++ b/src/sim/sim_ent.c @@ -246,55 +246,55 @@ void sim_ent_set_id(Ent *ent, 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) { 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)) { if (sim_ent_id_eq(e->id, id)) { - res = e; + result = e; break; } } } - return res; + return result; } EntId sim_ent_random_id(void) { - EntId res = ZI; - res.uid = UidFromTrueRand(); - return res; + EntId result = ZI; + result.uid = UidFromTrueRand(); + return result; } /* 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 res = ZI; - res.uid = SIM_ENT_CONTACT_BASIS_Uid; - res.uid = CombineUid(res.uid, player_id.uid); - res.uid = CombineUid(res.uid, id0.uid); - res.uid = CombineUid(res.uid, id1.uid); - return res; + EntId result = ZI; + result.uid = SIM_ENT_CONTACT_BASIS_Uid; + result.uid = CombineUid(result.uid, player_id.uid); + result.uid = CombineUid(result.uid, id0.uid); + result.uid = CombineUid(result.uid, id1.uid); + return result; } /* 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 res = ZI; - res.uid = SIM_ENT_COLLISION_DEBUG_BASIS_Uid; - res.uid = CombineUid(res.uid, player_id.uid); - res.uid = CombineUid(res.uid, id0.uid); - res.uid = CombineUid(res.uid, id1.uid); - return res; + EntId result = ZI; + result.uid = SIM_ENT_COLLISION_DEBUG_BASIS_Uid; + result.uid = CombineUid(result.uid, player_id.uid); + result.uid = CombineUid(result.uid, id0.uid); + result.uid = CombineUid(result.uid, id1.uid); + return result; } /* 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 res = ZI; - res.uid = SIM_ENT_TILE_CHUNK_BASIS_Uid; - res.uid = CombineUid(res.uid, UID(RandU64FromSeed(chunk_index.x), RandU64FromSeed(chunk_index.y))); - return res; + EntId result = ZI; + result.uid = SIM_ENT_TILE_CHUNK_BASIS_Uid; + result.uid = CombineUid(result.uid, UID(RandU64FromSeed(chunk_index.x), RandU64FromSeed(chunk_index.y))); + 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 res = chunk_ent->tile_chunk_tiles[local_tile_index.x + (local_tile_index.y * SIM_TILES_PER_CHUNK_SQRT)]; - return res; + TileKind result = chunk_ent->tile_chunk_tiles[local_tile_index.x + (local_tile_index.y * SIM_TILES_PER_CHUNK_SQRT)]; + return result; } /* ========================== * diff --git a/src/sim/sim_ent.h b/src/sim/sim_ent.h index fd534f61..794d1328 100644 --- a/src/sim/sim_ent.h +++ b/src/sim/sim_ent.h @@ -472,15 +472,15 @@ Inline b32 sim_ent_is_owner(Ent *ent) Inline b32 sim_ent_should_simulate(Ent *ent) { - b32 res = 0; + b32 result = 0; if (sim_ent_is_valid_and_active(ent)) { - res = 1; + result = 1; if (sim_ent_has_prop(ent, SEPROP_SYNC_DST)) { 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; } /* ========================== * diff --git a/src/sim/sim_phys.c b/src/sim/sim_phys.c index 9c21bc7f..01c574f1 100644 --- a/src/sim/sim_phys.c +++ b/src/sim/sim_phys.c @@ -7,11 +7,11 @@ internal b32 can_contact(Ent *e0, Ent *e1) { - b32 res = 0; - res = e0 != e1 && + b32 result = 0; + result = e0 != e1 && !sim_ent_id_eq(e0->top, e1->top) && !(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) @@ -81,14 +81,14 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_ } /* 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 */ StaticAssert(countof(constraint_ent->contact_constraint_data.points) == 2); - StaticAssert(countof(collider_res.points) == 2); + StaticAssert(countof(collision_result.points) == 2); ContactConstraint *constraint = 0; - if (collider_res.num_points > 0) { + if (collision_result.num_points > 0) { b32 is_start = 0; if (!constraint_ent->valid) { 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); } constraint = &constraint_ent->contact_constraint_data; - constraint->normal = collider_res.normal; + constraint->normal = collision_result.normal; constraint->friction = SqrtF32(e0->friction * e1->friction); /* 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]; u32 id = old->id; b32 found = 0; - for (u32 j = 0; j < collider_res.num_points; ++j) { - if (collider_res.points[j].id == id) { + for (u32 j = 0; j < collision_result.num_points; ++j) { + if (collision_result.points[j].id == id) { found = 1; break; } @@ -128,8 +128,8 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_ } /* Update / insert returned contacts */ - for (u32 i = 0; i < collider_res.num_points; ++i) { - CLD_CollisionPoint *res_point = &collider_res.points[i]; + for (u32 i = 0; i < collision_result.num_points; ++i) { + CLD_CollisionPoint *res_point = &collision_result.points[i]; Vec2 point = res_point->point; f32 sep = res_point->separation; 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 */ { - Vec2 normal = collider_res.normal; + Vec2 normal = collision_result.normal; Vec2 dir0 = e0->collision_dir; Vec2 dir1 = e1->collision_dir; f32 threshold = 0.5; @@ -181,14 +181,14 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_ CollisionData data = ZI; data.e0 = e0->id; data.e1 = e1->id; - data.normal = collider_res.normal; + data.normal = collision_result.normal; data.is_start = is_start; data.dt = elapsed_dt; /* Calculate point */ - Vec2 midpoint = collider_res.points[0].point; - if (collider_res.num_points > 1) { - midpoint = AddVec2(midpoint, MulVec2(SubVec2(collider_res.points[1].point, midpoint), 0.5f)); + Vec2 midpoint = collision_result.points[0].point; + if (collision_result.num_points > 1) { + midpoint = AddVec2(midpoint, MulVec2(SubVec2(collision_result.points[1].point, midpoint), 0.5f)); } 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->e1 = e1->id; - dbg->res = collider_res; + dbg->collision_result = collision_result; if (constraint) { 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 */ { - CLD_ClosestResult closest_points_res = collider_closest_points(&e0_collider, &e1_collider, e0_xf, e1_xf); - dbg->closest0 = closest_points_res.p0; - dbg->closest1 = closest_points_res.p1; + CLD_ClosestResult closest_points = collider_closest_points(&e0_collider, &e1_collider, e0_xf, e1_xf); + dbg->closest0 = closest_points.p0; + dbg->closest1 = closest_points.p1; } } #endif @@ -556,13 +556,13 @@ MotorJointDesc phys_motor_joint_def_init(void) MotorJoint phys_motor_joint_from_def(MotorJointDesc def) { - MotorJoint res = ZI; - res.e0 = def.e0; - res.e1 = def.e1; - res.correction_rate = ClampF32(def.correction_rate, 0, 1); - res.max_force = def.max_force; - res.max_torque = def.max_torque; - return res; + MotorJoint result = ZI; + result.e0 = def.e0; + result.e1 = def.e1; + result.correction_rate = ClampF32(def.correction_rate, 0, 1); + result.max_force = def.max_force; + result.max_torque = def.max_torque; + return result; } 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 res = ZI; - res.target = def.target; - res.point_local_start = def.point_local_start; - res.point_end = def.point_end; - res.linear_spring_hz = def.linear_spring_hz; - res.linear_spring_damp = def.linear_spring_damp; - res.angular_spring_hz = def.angular_spring_hz; - res.angular_spring_damp = def.angular_spring_damp; - res.max_force = def.max_force; - return res; + MouseJoint result = ZI; + result.target = def.target; + result.point_local_start = def.point_local_start; + result.point_end = def.point_end; + result.linear_spring_hz = def.linear_spring_hz; + result.linear_spring_damp = def.linear_spring_damp; + result.angular_spring_hz = def.angular_spring_hz; + result.angular_spring_damp = def.angular_spring_damp; + result.max_force = def.max_force; + return result; } 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 res = ZI; - res.e0 = def.e0; - res.e1 = def.e1; - res.linear_spring_hz = def.linear_spring_hz; - res.linear_spring_damp = def.linear_spring_damp; - res.angular_spring_hz = def.angular_spring_hz; - res.angular_spring_damp = def.angular_spring_damp; - res.xf0_to_xf1 = def.xf; - return res; + WeldJoint result = ZI; + result.e0 = def.e0; + result.e1 = def.e1; + result.linear_spring_hz = def.linear_spring_hz; + result.linear_spring_damp = def.linear_spring_damp; + result.angular_spring_hz = def.angular_spring_hz; + result.angular_spring_damp = def.angular_spring_damp; + result.xf0_to_xf1 = def.xf; + return result; } void phys_prepare_weld_joints(PhysStepCtx *ctx) diff --git a/src/sim/sim_phys.h b/src/sim/sim_phys.h index 5fce0b65..7d45403c 100644 --- a/src/sim/sim_phys.h +++ b/src/sim/sim_phys.h @@ -77,7 +77,7 @@ typedef struct CollisionDebugData CollisionDebugData; struct CollisionDebugData { EntId e0; EntId e1; - CLD_CollisionResult res; + CLD_CollisionResult collision_result; ContactPoint points[2]; u32 num_points; diff --git a/src/sim/sim_space.c b/src/sim/sim_space.c index a94d1a04..0c9526d5 100644 --- a/src/sim/sim_space.c +++ b/src/sim/sim_space.c @@ -104,14 +104,14 @@ SpaceCell *space_get_cell(Space *space, Vec2I32 cell_pos) { i32 bin_index = cell_coords_to_bin_index(space, cell_pos); 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) { if (EqVec2I32(n->pos, cell_pos)) { - res = n; + result = n; break; } } - return res; + return result; } internal void space_cell_node_alloc(Vec2I32 cell_pos, SpaceEntry *entry) diff --git a/src/sim/sim_step.c b/src/sim/sim_step.c index 06cf5e9a..b16bd509 100644 --- a/src/sim/sim_step.c +++ b/src/sim/sim_step.c @@ -413,9 +413,9 @@ internal MergesortCompareFuncDef(tile_chunk_sort_x, arg_a, arg_b, udata) i32 a_x = a->tile_chunk_index.x; i32 b_x = b->tile_chunk_index.x; - i32 res = 0; - res = (a_x < b_x) - (a_x > b_x); - return res; + i32 result = 0; + result = (a_x < b_x) - (a_x > b_x); + return result; } 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 b_y = b->tile_chunk_index.y; - i32 res = 0; - res = (a_y < b_y) - (a_y > b_y); - return res; + i32 result = 0; + result = (a_y < b_y) - (a_y > b_y); + return result; } internal void test_generate_walls(Snapshot *world) diff --git a/src/sprite/sprite_core.c b/src/sprite/sprite_core.c index 5ccb84fc..77d78c80 100644 --- a/src/sprite/sprite_core.c +++ b/src/sprite/sprite_core.c @@ -258,10 +258,10 @@ internal P_ExitFuncDef(sprite_shutdown) S_Tag sprite_tag_from_path(String path) { - S_Tag res = ZI; - res.hash = HashFnv64(Fnv64Basis, path); - res.path = path; - return res; + S_Tag result = ZI; + result.hash = HashFnv64(Fnv64Basis, path); + result.path = path; + return result; } 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) { /* Alloc scope */ - S_Scope *res = 0; + S_Scope *result = 0; struct sprite_scope_cache_ref **bins = 0; struct sprite_scope_cache_ref *pool = 0; { P_Lock lock = P_LockE(&G.scopes_mutex); { if (G.first_free_scope) { - res = G.first_free_scope; - G.first_free_scope = res->next_free; - bins = res->ref_node_bins; - pool = res->ref_node_pool; + result = G.first_free_scope; + G.first_free_scope = result->next_free; + bins = result->ref_node_bins; + pool = result->ref_node_pool; } 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); pool = PushStructsNoZero(G.scopes_arena, struct sprite_scope_cache_ref, MAX_SCOPE_REFERENCES); } } P_Unlock(&lock); } - ZeroStruct(res); + ZeroStruct(result); ZeroBytes(bins, sizeof(*bins) * CACHE_BINS_COUNT); - res->ref_node_bins = bins; - res->ref_node_pool = pool; - return res; + result->ref_node_bins = bins; + result->ref_node_pool = pool; + return result; } 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) { /* TODO: Replace switch statements */ - void *res = 0; + void *result = 0; switch (kind) { - case CACHE_ENTRY_KIND_TEXTURE: { res = G.loading_texture; } break; - case CACHE_ENTRY_KIND_SHEET: { res = G.loading_sheet; } break; + case CACHE_ENTRY_KIND_TEXTURE: { result = G.loading_texture; } break; + case CACHE_ENTRY_KIND_SHEET: { result = G.loading_sheet; } 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); if (state == CACHE_ENTRY_STATE_LOADED) { switch (kind) { - case CACHE_ENTRY_KIND_TEXTURE: { res = ref.e->texture; } break; - case CACHE_ENTRY_KIND_SHEET: { res = ref.e->sheet; } break; + case CACHE_ENTRY_KIND_TEXTURE: { result = ref.e->texture; } break; + case CACHE_ENTRY_KIND_SHEET: { result = ref.e->sheet; } break; default: { P_Panic(Lit("Unknown sprite cache entry kind")); } break; } } 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) { case CACHE_ENTRY_KIND_TEXTURE: { cache_entry_load_texture(ref, tag); - res = ref.e->texture; + result = ref.e->texture; } break; case CACHE_ENTRY_KIND_SHEET: { cache_entry_load_sheet(ref, tag); - res = ref.e->sheet; + result = ref.e->sheet; } 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 ) { return sheet->frames[index]; } - S_SheetFrame res = ZI; - res.index = 0; - res.duration = 0.1; - res.clip = AllClipped; - return res; + S_SheetFrame result = ZI; + result.index = 0; + result.duration = 0.1; + result.clip = AllClipped; + return result; } S_SheetSpan sprite_sheet_get_span(S_Sheet *sheet, String name) { - S_SheetSpan res = ZI; + S_SheetSpan result = ZI; if (sheet->spans_count > 0) { u64 hash = HashFnv64(Fnv64Basis, name); S_SheetSpan *entry = (S_SheetSpan *)DictValueFromHash(sheet->spans_dict, hash); if (entry) { - res = *entry; + result = *entry; } } - return res; + return result; } 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 */ - S_SheetSlice res = ZI; + S_SheetSlice result = ZI; if (EqString(name, Lit("pivot"))) { /* 'pivot' slice does not exist, return center */ - res.center = VEC2(0, 0); - res.center_px = MulVec2(sheet->frame_size, 0.5f); - res.dir_px = VEC2(res.center_px.x, 0); - res.dir = VEC2(0, -0.5); + result.center = VEC2(0, 0); + result.center_px = MulVec2(sheet->frame_size, 0.5f); + result.dir_px = VEC2(result.center_px.x, 0); + result.dir = VEC2(0, -0.5); } 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 res = ZI; + S_SheetSliceArray result = ZI; if (sheet->slice_groups_count > 0) { u64 hash = HashFnv64(Fnv64Basis, name); S_SheetSliceGroup *group = (S_SheetSliceGroup *)DictValueFromHash(sheet->slice_groups_dict, hash); if (group) { - res.count = group->per_frame_count; - res.slices = &group->frame_slices[frame_index * group->per_frame_count]; + result.count = group->per_frame_count; + result.slices = &group->frame_slices[frame_index * group->per_frame_count]; } } - return res; + return result; } /* ========================== * diff --git a/src/user/user_core.c b/src/user/user_core.c index 0fc64826..80f1b0d1 100644 --- a/src/user/user_core.c +++ b/src/user/user_core.c @@ -300,31 +300,31 @@ internal String get_ent_debug_text(Arena *arena, Ent *ent) const u8 hex[] = "0123456789abcdef"; - String res = ZI; - res.text = PushDry(arena, u8); + String result = ZI; + 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 receiving = sim_ent_has_prop(ent, SEPROP_SYNC_DST); if (transmitting & receiving) { - res.len += CopyString(arena, Lit(" networked (sending & receiving)")).len; + result.len += CopyString(arena, Lit(" networked (sending & receiving)")).len; } else if (transmitting) { - res.len += CopyString(arena, Lit(" networked (sending)")).len; + result.len += CopyString(arena, Lit(" networked (sending)")).len; } else if (receiving) { - res.len += CopyString(arena, Lit(" networked (receiving)")).len; + result.len += CopyString(arena, Lit(" networked (receiving)")).len; } 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;) { u64 chunk = ent->props[chunk_index]; 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; StringFromChar(arena, hex[(part >> 4) & 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)) { - 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)) { - res.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("prev: [%F]\n"), FmtUid(ent->prev.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 */ Xform xf = sim_ent_get_xform(ent); Vec2 linear_velocity = ent->linear_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; - res.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("pos: (%F, %F)\n"), FmtFloat(xf.og.x), FmtFloat(xf.og.y)).len; + result.len += StringFormat(arena, Lit("linear velocity: (%F, %F)\n"), FmtFloat(linear_velocity.x), FmtFloat(linear_velocity.y)).len; + result.len += StringFormat(arena, Lit("angular velocity: %F\n"), FmtFloat(angular_velocity)).len; /* 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 */ if (!sim_ent_id_is_nil(ent->first) || !sim_ent_id_is_nil(ent->last)) { Ent *child = sim_ent_from_id(ss, ent->first); 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; - res.len += StringFormat(arena, Lit("last child: [%F]\n"), FmtUid(ent->last.uid)).len; + result.len += StringFormat(arena, Lit("first child: [%F]\n"), FmtUid(ent->first.uid)).len; + result.len += StringFormat(arena, Lit("last child: [%F]\n"), FmtUid(ent->last.uid)).len; } while (child->valid) { - res.len += CopyString(arena, Lit("\n---------------------------------\n")).len; - res.len += CopyString(arena, Lit("CHILD\n")).len; + result.len += CopyString(arena, Lit("\n---------------------------------\n")).len; + result.len += CopyString(arena, Lit("CHILD\n")).len; 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); } } 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 *b = *(Ent **)arg_b; - i32 res = 0; + i32 result = 0; - if (res == 0) { + if (result == 0) { /* Sort by light */ b32 a_cmp = sim_ent_has_prop(a, 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 */ i32 a_cmp = a->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 */ u64 a_cmp = a->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 */ u64 a_cmp = a->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) { /* TODO: Can just use boolean GJK */ Xform ent_xf = sim_ent_get_xform(ent); - CLD_CollisionResult res = collider_collision_points(&ent_collider, &mouse_shape, ent_xf, mouse_xf); - if (res.num_points > 0) { + CLD_CollisionResult collision_result = collider_collision_points(&ent_collider, &mouse_shape, ent_xf, mouse_xf); + if (collision_result.num_points > 0) { hovered_ent = sim_ent_from_id(G.ss_blended, ent->top); break; } @@ -1474,7 +1474,7 @@ internal void user_update(P_Window *window) #if COLLIDER_DEBUG if (sim_ent_has_prop(ent, SEPROP_COLLISION_DEBUG)) { 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 *e1 = sim_ent_from_id(G.ss_blended, data->e1); 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_b_clipped = Rgba32F(0, 1, 0, 1); { - Vec2 a = MulXformV2(G.world_to_ui_xf, collider_res.a0); - Vec2 b = MulXformV2(G.world_to_ui_xf, collider_res.b0); + Vec2 a = MulXformV2(G.world_to_ui_xf, collision_reuslt.a0); + Vec2 b = MulXformV2(G.world_to_ui_xf, collision_reuslt.b0); 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, b, radius, color_b, 10); - Vec2 a_clipped = MulXformV2(G.world_to_ui_xf, collider_res.a0_clipped); - Vec2 b_clipped = MulXformV2(G.world_to_ui_xf, collider_res.b0_clipped); + Vec2 a_clipped = MulXformV2(G.world_to_ui_xf, collision_reuslt.a0_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_circle(G.render_sig, a_clipped, radius, color_a_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 b = MulXformV2(G.world_to_ui_xf, collider_res.b1); + Vec2 a = MulXformV2(G.world_to_ui_xf, collision_reuslt.a1); + Vec2 b = MulXformV2(G.world_to_ui_xf, collision_reuslt.b1); 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, b, radius, color_b, 10); - Vec2 a_clipped = MulXformV2(G.world_to_ui_xf, collider_res.a1_clipped); - Vec2 b_clipped = MulXformV2(G.world_to_ui_xf, collider_res.b1_clipped); + Vec2 a_clipped = MulXformV2(G.world_to_ui_xf, collision_reuslt.a1_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_circle(G.render_sig, a_clipped, radius, color_a_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 */ { - 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; u32 detail = 512; (UNUSED)thickness; @@ -1608,8 +1608,8 @@ internal void user_update(P_Window *window) u32 color = Rgba32F(1, 1, 1, 0.25); V2Array m = { - .points = collider_res.prototype.points, - .count = collider_res.prototype.len + .points = collision_reuslt.prototype.points, + .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]); 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_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 }; 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 }; @@ -1653,7 +1653,7 @@ internal void user_update(P_Window *window) f32 arrow_thickness = 4; f32 arrowhead_height = 10; 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); } }