From 3cea320efc545f83f9cf3984cd271509ca2decbc Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 21 Mar 2018 20:07:10 +1100 Subject: [PATCH] cleanup code a bit --- ClassicalSharp/Blocks/BlockInfo.cs | 4 ---- src/Client/2DStructs.c | 8 -------- src/Client/2DStructs.h | 3 --- src/Client/BlockID.h | 2 -- src/Client/Builder.c | 2 +- src/Client/Camera.c | 2 +- src/Client/Chat.c | 2 +- src/Client/Drawer2D.c | 4 ++-- src/Client/EntityComponents.c | 2 +- src/Client/HeldBlockRenderer.c | 4 ++-- src/Client/Picking.c | 4 ++-- src/Client/Vectors.h | 1 - src/Client/Widgets.c | 2 +- src/Client/WinWindow.c | 12 ++++++------ 14 files changed, 17 insertions(+), 35 deletions(-) diff --git a/ClassicalSharp/Blocks/BlockInfo.cs b/ClassicalSharp/Blocks/BlockInfo.cs index 8cf89ccd7..71f56261b 100644 --- a/ClassicalSharp/Blocks/BlockInfo.cs +++ b/ClassicalSharp/Blocks/BlockInfo.cs @@ -232,9 +232,6 @@ namespace ClassicalSharp { static StringBuffer buffer = new StringBuffer(64); static string DefaultName(BlockID block) { - #if USE16_BIT - if (block >= 256) return "ID " + block; - #endif if (block >= Block.CpeCount) return "Invalid"; // Find start and end of this particular block name @@ -353,7 +350,6 @@ namespace ClassicalSharp { f |= occludedY && (bothLiquid || (oMin.Y == 0 && bMax.Y == 1)) ? (1 << Side.Top) : 0; BlockInfo.hidden[(block * Count) | other] = (byte)f; } - } static bool IsHidden(BlockID block, BlockID other) { diff --git a/src/Client/2DStructs.c b/src/Client/2DStructs.c index 5888e9a71..5784522df 100644 --- a/src/Client/2DStructs.c +++ b/src/Client/2DStructs.c @@ -18,18 +18,10 @@ Size2D Size2D_Make(Int32 width, Int32 height) { Size2D s; s.Width = width; s.Height = height; return s; } -bool Size2D_Equals(Size2D a, Size2D b) { - return a.Width == b.Width && a.Height == b.Height; -} - Point2D Point2D_Make(Int32 x, Int32 y) { Point2D p; p.X = x; p.Y = y; return p; } -bool Point2D_Equals(Point2D a, Point2D b) { - return a.X == b.X && a.Y == b.Y; -} - TextureRec TextureRec_FromRegion(Real32 u, Real32 v, Real32 uWidth, Real32 vHeight) { TextureRec rec; rec.U1 = u; rec.V1 = v; diff --git a/src/Client/2DStructs.h b/src/Client/2DStructs.h index 5de47fd1a..386bb596c 100644 --- a/src/Client/2DStructs.h +++ b/src/Client/2DStructs.h @@ -22,10 +22,7 @@ bool Rectangle2D_Contains(Rectangle2D a, Int32 x, Int32 y); bool Rectangle2D_Equals(Rectangle2D a, Rectangle2D b); Size2D Size2D_Make(Int32 width, Int32 height); -bool Size2D_Equals(Size2D a, Size2D b); - Point2D Point2D_Make(Int32 x, Int32 y); -bool Point2D_Equals(Point2D a, Point2D b); /* Stores the four texture coordinates that describe a textured quad. */ typedef struct TextureRec_ { Real32 U1, V1, U2, V2; } TextureRec; diff --git a/src/Client/BlockID.h b/src/Client/BlockID.h index be33f926f..1da45bec7 100644 --- a/src/Client/BlockID.h +++ b/src/Client/BlockID.h @@ -85,10 +85,8 @@ #if USE16_BIT #define BLOCK_MAX_DEFINED 0x3FF -#define BLOCK_SHIFT 10 #else #define BLOCK_MAX_DEFINED 0xFF -#define BLOCK_SHIFT 8 #endif #define BLOCK_RAW_NAMES "Air Stone Grass Dirt Cobblestone Wood Sapling Bedrock Water StillWater Lava"\ diff --git a/src/Client/Builder.c b/src/Client/Builder.c index f906f3e52..2f242df06 100644 --- a/src/Client/Builder.c +++ b/src/Client/Builder.c @@ -153,7 +153,7 @@ void Builder_Stretch(Int32 x1, Int32 y1, Int32 z1) { Builder_X = x; Builder_Y = y; Builder_Z = z; Builder_FullBright = Block_FullBright[b]; - Int32 tileIdx = b << BLOCK_SHIFT; + UInt32 tileIdx = b * BLOCK_COUNT; /* All of these function calls are inlined as they can be called tens of millions to hundreds of millions of times. */ if (Builder_Counts[index] == 0 || diff --git a/src/Client/Camera.c b/src/Client/Camera.c index bf0a963d5..55fc4d21b 100644 --- a/src/Client/Camera.c +++ b/src/Client/Camera.c @@ -58,7 +58,7 @@ void PerspectiveCamera_RegrabMouse(void) { Int32 cenX = topLeft.X + Game_Width / 2; Int32 cenY = topLeft.Y + Game_Height / 2; - Point2D point = Point2D_Make(cenX, cenY); + Point2D point = { cenX, cenY }; Window_SetDesktopCursorPos(point); previous = point; delta = Point2D_Empty; diff --git a/src/Client/Chat.c b/src/Client/Chat.c index d24485d01..19b09a957 100644 --- a/src/Client/Chat.c +++ b/src/Client/Chat.c @@ -482,7 +482,7 @@ void TeleportCommand_Execute(STRING_PURE String* args, UInt32 argsCount) { return; } - Vector3 v = VECTOR3_CONST(x, y, z); + Vector3 v = { x, y, z }; LocationUpdate update; LocationUpdate_MakePos(&update, v, false); Entity* entity = &LocalPlayer_Instance.Base.Base; entity->VTABLE->SetLocation(entity, &update, false); diff --git a/src/Client/Drawer2D.c b/src/Client/Drawer2D.c index c3e7449cb..32c2d1980 100644 --- a/src/Client/Drawer2D.c +++ b/src/Client/Drawer2D.c @@ -130,7 +130,7 @@ Int32 Drawer2D_FontHeight(FontDesc* font, bool useShadow) { Texture Drawer2D_MakeTextTexture(DrawTextArgs* args, Int32 windowX, Int32 windowY) { Size2D size = Drawer2D_MeasureText(args); - if (Size2D_Equals(size, Size2D_Empty)) { + if (size.Width == 0.0f && size.Height == 0.0f) { return Texture_FromOrigin(NULL, windowX, windowY, 0, 0, 1.0f, 1.0f); } @@ -343,7 +343,7 @@ void Drawer2D_DrawBitmapText(DrawTextArgs* args, Int32 x, Int32 y) { Size2D Drawer2D_MeasureBitmapText(DrawTextArgs* args) { if (Drawer2D_IsEmptyText(&args->Text)) return Size2D_Empty; Int32 textHeight = Drawer2D_AdjTextSize(args->Font.Size); - Size2D total = Size2D_Make(0, Drawer2D_CellSize(textHeight)); + Size2D total = { 0, Drawer2D_CellSize(textHeight) }; Int32 point = Math_Floor(args->Font.Size); String text = args->Text; diff --git a/src/Client/EntityComponents.c b/src/Client/EntityComponents.c index dfeda5939..6e061da80 100644 --- a/src/Client/EntityComponents.c +++ b/src/Client/EntityComponents.c @@ -534,7 +534,7 @@ void ShadowComponent_CalcAlpha(Real32 playerY, ShadowData* data) { bool ShadowComponent_GetBlocks(Entity* entity, Vector3I* coords, Real32 x, Real32 z, Int32 posY, ShadowData* data) { Int32 blockX = Math_Floor(x), blockZ = Math_Floor(z); - Vector3I p = VECTOR3I_CONST(blockX, 0, blockZ); + Vector3I p = { blockX, 0, blockZ }; /* Check we have not processed this particular block already */ UInt32 i, posCount = 0; diff --git a/src/Client/HeldBlockRenderer.c b/src/Client/HeldBlockRenderer.c index e61cd5554..b6a5c1146 100644 --- a/src/Client/HeldBlockRenderer.c +++ b/src/Client/HeldBlockRenderer.c @@ -75,8 +75,8 @@ void HeldBlockRenderer_ResetHeldState(void) { void HeldBlockRenderer_SetBaseOffset(void) { bool sprite = Block_Draw[held_block] == DRAW_SPRITE; - Vector3 normalOffset = VECTOR3_CONST(0.56f, -0.72f, -0.72f); - Vector3 spriteOffset = VECTOR3_CONST(0.46f, -0.52f, -0.72f); + Vector3 normalOffset = { 0.56f, -0.72f, -0.72f }; + Vector3 spriteOffset = { 0.46f, -0.52f, -0.72f }; Vector3 offset = sprite ? spriteOffset : normalOffset; Vector3_Add(&held_entity.Position, &held_entity.Position, &offset); diff --git a/src/Client/Picking.c b/src/Client/Picking.c index 3d6abb0f3..91cd07def 100644 --- a/src/Client/Picking.c +++ b/src/Client/Picking.c @@ -17,7 +17,7 @@ void PickedPos_TestAxis(PickedPos* pos, Real32 dAxis, Face fAxis) { } void PickedPos_SetAsValid(PickedPos* pos, RayTracer* t, Vector3 intersect) { - Vector3I blockPos = VECTOR3I_CONST(t->X, t->Y, t->Z); + Vector3I blockPos = { t->X, t->Y, t->Z }; pos->Valid = true; pos->BlockPos = blockPos; pos->Block = t->Block; @@ -44,7 +44,7 @@ void PickedPos_SetAsValid(PickedPos* pos, RayTracer* t, Vector3 intersect) { } void PickedPos_SetAsInvalid(PickedPos* pos) { - Vector3I blockPos = VECTOR3I_CONST(-1, -1, -1); + Vector3I blockPos = { -1, -1, -1 }; pos->Valid = false; pos->BlockPos = blockPos; pos->Block = BLOCK_AIR; diff --git a/src/Client/Vectors.h b/src/Client/Vectors.h index 1eff8778a..ecc97e7f2 100644 --- a/src/Client/Vectors.h +++ b/src/Client/Vectors.h @@ -21,7 +21,6 @@ Real32 Vector3_Length(Vector3* v); Real32 Vector3_LengthSquared(Vector3* v); #define VECTOR3_CONST(x, y, z) { x, y, z }; -#define VECTOR3I_CONST(x, y, z) { x, y, z }; #define Vector3_UnitX VECTOR3_CONST(1.0f, 0.0f, 0.0f) #define Vector3_UnitY VECTOR3_CONST(0.0f, 1.0f, 0.0f) #define Vector3_UnitZ VECTOR3_CONST(0.0f, 0.0f, 1.0f) diff --git a/src/Client/Widgets.c b/src/Client/Widgets.c index 069614a51..3ee08ca73 100644 --- a/src/Client/Widgets.c +++ b/src/Client/Widgets.c @@ -1188,7 +1188,7 @@ void InputWidget_RemakeTexture(GuiElement* elem) { totalHeight += widget->LineSizes[i].Height; maxWidth = max(maxWidth, widget->LineSizes[i].Width); } - Size2D size = Size2D_Make(maxWidth, totalHeight); + Size2D size = { maxWidth, totalHeight }; widget->CaretAccumulator = 0; Int32 realHeight = 0; diff --git a/src/Client/WinWindow.c b/src/Client/WinWindow.c index e7977a830..7ebf7c39a 100644 --- a/src/Client/WinWindow.c +++ b/src/Client/WinWindow.c @@ -208,14 +208,14 @@ LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wParam, LPAR case WM_WINDOWPOSCHANGED: pos = (WINDOWPOS*)lParam; if (pos->hwnd == win_Handle) { - Point2D new_location = Point2D_Make(pos->x, pos->y); - if (!Point2D_Equals(Window_GetLocation(), new_location)) { + Point2D loc = Window_GetLocation(); + if (loc.X != pos->x || loc.Y != pos->y) { win_Bounds.X = pos->x; win_Bounds.Y = pos->y; Event_RaiseVoid(&WindowEvents_Moved); } - Size2D new_size = Size2D_Make(pos->cx, pos->cy); - if (!Size2D_Equals(Window_GetSize(), new_size)) { + Size2D size = Window_GetSize(); + if (size.Width != pos->cx || size.Height != pos->cy) { win_Bounds.Width = pos->cx; win_Bounds.Height = pos->cy; RECT rect; @@ -539,7 +539,7 @@ void Window_SetSize(Size2D size) { Rectangle2D Window_GetClientRectangle(void) { return win_ClientRect; } void Window_SetClientRectangle(Rectangle2D rect) { - Size2D size = Size2D_Make(rect.Width, rect.Height); + Size2D size = { rect.Width, rect.Height }; Window_SetClientSize(size); } @@ -659,8 +659,8 @@ Point2D Window_PointToScreen(Point2D p) { ErrorHandler_Fail("PointToScreen NOT IMPLEMENTED"); } -MSG msg; void Window_ProcessEvents(void) { + MSG msg; while (PeekMessageA(&msg, NULL, 0, 0, 1)) { TranslateMessage(&msg); DispatchMessageA(&msg);