From d7b61c7e9e655a178c7972304d2d07422da18a68 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 6 Sep 2018 06:32:31 +1000 Subject: [PATCH] C client: and simplify axislinesrenderer too --- src/AxisLinesRenderer.c | 38 ++++++++++++++++++++------------------ src/PackedCol.c | 2 +- src/PackedCol.h | 4 ++-- src/Program.c | 2 +- src/SelectionBox.c | 29 ++--------------------------- src/SelectionBox.h | 7 ------- 6 files changed, 26 insertions(+), 56 deletions(-) diff --git a/src/AxisLinesRenderer.c b/src/AxisLinesRenderer.c index 73d886745..25ebc051d 100644 --- a/src/AxisLinesRenderer.c +++ b/src/AxisLinesRenderer.c @@ -41,28 +41,30 @@ void AxisLinesRenderer_Render(Real64 delta) { Gfx_SetTexturing(false); Vector3 P = LocalPlayer_Instance.Base.Position; P.Y += 0.05f; VertexP3fC4b vertices[axisLines_numVertices]; + + Vector3 coords[5]; coords[2] = P; + Vector3_Add1(&coords[0], &P, -axisLines_length); + Vector3_Add1(&coords[1], &P, -axisLines_size); + Vector3_Add1(&coords[3], &P, axisLines_size); + Vector3_Add1(&coords[4], &P, axisLines_length); + + static UInt8 faces[36] = { + 2,2,1, 2,2,3, 4,2,3, 4,2,1, /* X arrow */ + 1,2,2, 1,2,4, 3,2,4, 3,2,2, /* Z arrow */ + 1,2,3, 1,4,3, 3,4,1, 3,2,1, /* Y arrow */ + }; + + static PackedCol cols[3] = { PACKEDCOL_RED, PACKEDCOL_BLUE, PACKEDCOL_GREEN }; + Int32 i, count = Camera_Active->IsThirdPerson ? 12 : 8; VertexP3fC4b* ptr = vertices; - PackedCol red = PACKEDCOL_RED; - SelectionBox_HorQuad(&ptr, red, - P.X, P.Z - axisLines_size, - P.X + axisLines_length, P.Z + axisLines_size, - P.Y); - - PackedCol blue = PACKEDCOL_BLUE; - SelectionBox_HorQuad(&ptr, blue, - P.X - axisLines_size, P.Z, - P.X + axisLines_size, P.Z + axisLines_length, - P.Y); - - if (Camera_Active->IsThirdPerson) { - PackedCol green = PACKEDCOL_GREEN; - SelectionBox_VerQuad(&ptr, green, - P.X - axisLines_size, P.Y, P.Z + axisLines_size, - P.X + axisLines_size, P.Y + axisLines_length, P.Z - axisLines_size); + for (i = 0; i < count; i++, ptr++) { + ptr->X = coords[faces[i*3 + 0]].X; + ptr->Y = coords[faces[i*3 + 1]].Y; + ptr->Z = coords[faces[i*3 + 2]].Z; + ptr->Col = cols[i]; } Gfx_SetBatchFormat(VERTEX_FORMAT_P3FC4B); - Int32 count = (Int32)(ptr - vertices); GfxCommon_UpdateDynamicVb_IndexedTris(axisLines_vb, vertices, count); } diff --git a/src/PackedCol.c b/src/PackedCol.c index 8d6402324..400d70812 100644 --- a/src/PackedCol.c +++ b/src/PackedCol.c @@ -68,7 +68,7 @@ void PackedCol_ToHex(STRING_TRANSIENT String* str, PackedCol value) { } bool PackedCol_TryParseHex(STRING_PURE String* str, PackedCol* value) { - PackedCol empty = PACKEDCOL_CONST(0, 0, 0, 0); *value = empty; + PackedCol empty = { 0 }; *value = empty; /* accept XXYYZZ or #XXYYZZ forms */ if (str->length < 6) return false; if (str->length > 6 && (str->buffer[0] != '#' || str->length > 7)) return false; diff --git a/src/PackedCol.h b/src/PackedCol.h index decc4a0e2..701f04b62 100644 --- a/src/PackedCol.h +++ b/src/PackedCol.h @@ -16,9 +16,9 @@ typedef union PackedCol_ { } PackedCol; #if CC_BUILD_D3D9 -#define PACKEDCOL_CONST(r, g, b, a) { b, g, r, a }; +#define PACKEDCOL_CONST(r, g, b, a) { b, g, r, a } #else -#define PACKEDCOL_CONST(r, g, b, a) { r, g, b, a }; +#define PACKEDCOL_CONST(r, g, b, a) { r, g, b, a } #endif PackedCol PackedCol_Create4(UInt8 r, UInt8 g, UInt8 b, UInt8 a); diff --git a/src/Program.c b/src/Program.c index e068b909a..28ae51f4b 100644 --- a/src/Program.c +++ b/src/Program.c @@ -64,7 +64,7 @@ int main(void) { String title = String_FromConst(PROGRAM_APP_NAME); String rawArgs = Platform_GetCommandLineArgs(); /* NOTE: Make sure to comment this out before pushing a commit */ - rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.0.1 25565"); + //rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.0.1 25565"); String args[5]; Int32 argsCount = Array_Elems(args); String_UNSAFE_Split(&rawArgs, ' ', args, &argsCount); diff --git a/src/SelectionBox.c b/src/SelectionBox.c index 8ca746f93..eefb4193b 100644 --- a/src/SelectionBox.c +++ b/src/SelectionBox.c @@ -13,11 +13,11 @@ struct SelectionBox { Real32 MinDist, MaxDist; }; -void SelectionBox_Render(struct SelectionBox* box, VertexP3fC4b** vertices, VertexP3fC4b** lineVertices) { +static void SelectionBox_Render(struct SelectionBox* box, VertexP3fC4b** vertices, VertexP3fC4b** lineVertices) { Real32 offset = box->MinDist < 32.0f * 32.0f ? (1.0f / 32.0f) : (1.0f / 16.0f); Vector3 coords[2]; Vector3_Add1(&coords[0], &box->Min, -offset); - Vector3_Add1(&coords[1], &box->Max, offset); + Vector3_Add1(&coords[1], &box->Max, offset); Int32 i; VertexP3fC4b* ptr; @@ -59,31 +59,6 @@ void SelectionBox_Render(struct SelectionBox* box, VertexP3fC4b** vertices, Vert *lineVertices = ptr; } -void SelectionBox_VerQuad(VertexP3fC4b** vertices, PackedCol col, - Real32 x1, Real32 y1, Real32 z1, Real32 x2, Real32 y2, Real32 z2) { - VertexP3fC4b* ptr = *vertices; - VertexP3fC4b v; v.Col = col; - - v.X = x1; v.Y = y1; v.Z = z1; *ptr++ = v; - v.Y = y2; *ptr++ = v; - v.X = x2; v.Z = z2; *ptr++ = v; - v.Y = y1; *ptr++ = v; - *vertices = ptr; -} - -void SelectionBox_HorQuad(VertexP3fC4b** vertices, PackedCol col, - Real32 x1, Real32 z1, Real32 x2, Real32 z2, Real32 y) { - VertexP3fC4b* ptr = *vertices; - VertexP3fC4b v; v.Y = y; v.Col = col; - - v.X = x1; v.Z = z1; *ptr++ = v; - v.Z = z2; *ptr++ = v; - v.X = x2; *ptr++ = v; - v.Z = z1; *ptr++ = v; - *vertices = ptr; -} - - static Int32 SelectionBox_Compare(struct SelectionBox* a, struct SelectionBox* b) { Real32 aDist, bDist; if (a->MinDist == b->MinDist) { diff --git a/src/SelectionBox.h b/src/SelectionBox.h index b31a963ed..8358c14d4 100644 --- a/src/SelectionBox.h +++ b/src/SelectionBox.h @@ -7,13 +7,6 @@ */ struct IGameComponent; -void SelectionBox_VerQuad(VertexP3fC4b** vertices, PackedCol col, - Real32 x1, Real32 y1, Real32 z1, Real32 x2, Real32 y2, Real32 z2); -void SelectionBox_HorQuad(VertexP3fC4b** vertices, PackedCol col, - Real32 x1, Real32 z1, Real32 x2, Real32 z2, Real32 y); -void SelectionBox_Line(VertexP3fC4b** vertices, PackedCol col, - Real32 x1, Real32 y1, Real32 z1, Real32 x2, Real32 y2, Real32 z2); - void Selections_MakeComponent(struct IGameComponent* comp); void Selections_Render(Real64 delta); void Selections_Add(UInt8 id, Vector3I p1, Vector3I p2, PackedCol col);