cleanup code a bit

This commit is contained in:
UnknownShadow200 2018-03-21 20:07:10 +11:00
parent 9473646252
commit 3cea320efc
14 changed files with 17 additions and 35 deletions

View File

@ -232,9 +232,6 @@ namespace ClassicalSharp {
static StringBuffer buffer = new StringBuffer(64); static StringBuffer buffer = new StringBuffer(64);
static string DefaultName(BlockID block) { static string DefaultName(BlockID block) {
#if USE16_BIT
if (block >= 256) return "ID " + block;
#endif
if (block >= Block.CpeCount) return "Invalid"; if (block >= Block.CpeCount) return "Invalid";
// Find start and end of this particular block name // 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; f |= occludedY && (bothLiquid || (oMin.Y == 0 && bMax.Y == 1)) ? (1 << Side.Top) : 0;
BlockInfo.hidden[(block * Count) | other] = (byte)f; BlockInfo.hidden[(block * Count) | other] = (byte)f;
} }
} }
static bool IsHidden(BlockID block, BlockID other) { static bool IsHidden(BlockID block, BlockID other) {

View File

@ -18,18 +18,10 @@ Size2D Size2D_Make(Int32 width, Int32 height) {
Size2D s; s.Width = width; s.Height = height; return s; 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 Point2D_Make(Int32 x, Int32 y) {
Point2D p; p.X = x; p.Y = y; return p; 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 TextureRec_FromRegion(Real32 u, Real32 v, Real32 uWidth, Real32 vHeight) {
TextureRec rec; TextureRec rec;
rec.U1 = u; rec.V1 = v; rec.U1 = u; rec.V1 = v;

View File

@ -22,10 +22,7 @@ bool Rectangle2D_Contains(Rectangle2D a, Int32 x, Int32 y);
bool Rectangle2D_Equals(Rectangle2D a, Rectangle2D b); bool Rectangle2D_Equals(Rectangle2D a, Rectangle2D b);
Size2D Size2D_Make(Int32 width, Int32 height); Size2D Size2D_Make(Int32 width, Int32 height);
bool Size2D_Equals(Size2D a, Size2D b);
Point2D Point2D_Make(Int32 x, Int32 y); Point2D Point2D_Make(Int32 x, Int32 y);
bool Point2D_Equals(Point2D a, Point2D b);
/* Stores the four texture coordinates that describe a textured quad. */ /* Stores the four texture coordinates that describe a textured quad. */
typedef struct TextureRec_ { Real32 U1, V1, U2, V2; } TextureRec; typedef struct TextureRec_ { Real32 U1, V1, U2, V2; } TextureRec;

View File

@ -85,10 +85,8 @@
#if USE16_BIT #if USE16_BIT
#define BLOCK_MAX_DEFINED 0x3FF #define BLOCK_MAX_DEFINED 0x3FF
#define BLOCK_SHIFT 10
#else #else
#define BLOCK_MAX_DEFINED 0xFF #define BLOCK_MAX_DEFINED 0xFF
#define BLOCK_SHIFT 8
#endif #endif
#define BLOCK_RAW_NAMES "Air Stone Grass Dirt Cobblestone Wood Sapling Bedrock Water StillWater Lava"\ #define BLOCK_RAW_NAMES "Air Stone Grass Dirt Cobblestone Wood Sapling Bedrock Water StillWater Lava"\

View File

@ -153,7 +153,7 @@ void Builder_Stretch(Int32 x1, Int32 y1, Int32 z1) {
Builder_X = x; Builder_Y = y; Builder_Z = z; Builder_X = x; Builder_Y = y; Builder_Z = z;
Builder_FullBright = Block_FullBright[b]; 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. */ /* 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 || if (Builder_Counts[index] == 0 ||

View File

@ -58,7 +58,7 @@ void PerspectiveCamera_RegrabMouse(void) {
Int32 cenX = topLeft.X + Game_Width / 2; Int32 cenX = topLeft.X + Game_Width / 2;
Int32 cenY = topLeft.Y + Game_Height / 2; Int32 cenY = topLeft.Y + Game_Height / 2;
Point2D point = Point2D_Make(cenX, cenY); Point2D point = { cenX, cenY };
Window_SetDesktopCursorPos(point); Window_SetDesktopCursorPos(point);
previous = point; previous = point;
delta = Point2D_Empty; delta = Point2D_Empty;

View File

@ -482,7 +482,7 @@ void TeleportCommand_Execute(STRING_PURE String* args, UInt32 argsCount) {
return; return;
} }
Vector3 v = VECTOR3_CONST(x, y, z); Vector3 v = { x, y, z };
LocationUpdate update; LocationUpdate_MakePos(&update, v, false); LocationUpdate update; LocationUpdate_MakePos(&update, v, false);
Entity* entity = &LocalPlayer_Instance.Base.Base; Entity* entity = &LocalPlayer_Instance.Base.Base;
entity->VTABLE->SetLocation(entity, &update, false); entity->VTABLE->SetLocation(entity, &update, false);

View File

@ -130,7 +130,7 @@ Int32 Drawer2D_FontHeight(FontDesc* font, bool useShadow) {
Texture Drawer2D_MakeTextTexture(DrawTextArgs* args, Int32 windowX, Int32 windowY) { Texture Drawer2D_MakeTextTexture(DrawTextArgs* args, Int32 windowX, Int32 windowY) {
Size2D size = Drawer2D_MeasureText(args); 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); 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) { Size2D Drawer2D_MeasureBitmapText(DrawTextArgs* args) {
if (Drawer2D_IsEmptyText(&args->Text)) return Size2D_Empty; if (Drawer2D_IsEmptyText(&args->Text)) return Size2D_Empty;
Int32 textHeight = Drawer2D_AdjTextSize(args->Font.Size); 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); Int32 point = Math_Floor(args->Font.Size);
String text = args->Text; String text = args->Text;

View File

@ -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) { bool ShadowComponent_GetBlocks(Entity* entity, Vector3I* coords, Real32 x, Real32 z, Int32 posY, ShadowData* data) {
Int32 blockX = Math_Floor(x), blockZ = Math_Floor(z); 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 */ /* Check we have not processed this particular block already */
UInt32 i, posCount = 0; UInt32 i, posCount = 0;

View File

@ -75,8 +75,8 @@ void HeldBlockRenderer_ResetHeldState(void) {
void HeldBlockRenderer_SetBaseOffset(void) { void HeldBlockRenderer_SetBaseOffset(void) {
bool sprite = Block_Draw[held_block] == DRAW_SPRITE; bool sprite = Block_Draw[held_block] == DRAW_SPRITE;
Vector3 normalOffset = VECTOR3_CONST(0.56f, -0.72f, -0.72f); Vector3 normalOffset = { 0.56f, -0.72f, -0.72f };
Vector3 spriteOffset = VECTOR3_CONST(0.46f, -0.52f, -0.72f); Vector3 spriteOffset = { 0.46f, -0.52f, -0.72f };
Vector3 offset = sprite ? spriteOffset : normalOffset; Vector3 offset = sprite ? spriteOffset : normalOffset;
Vector3_Add(&held_entity.Position, &held_entity.Position, &offset); Vector3_Add(&held_entity.Position, &held_entity.Position, &offset);

View File

@ -17,7 +17,7 @@ void PickedPos_TestAxis(PickedPos* pos, Real32 dAxis, Face fAxis) {
} }
void PickedPos_SetAsValid(PickedPos* pos, RayTracer* t, Vector3 intersect) { 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->Valid = true;
pos->BlockPos = blockPos; pos->BlockPos = blockPos;
pos->Block = t->Block; pos->Block = t->Block;
@ -44,7 +44,7 @@ void PickedPos_SetAsValid(PickedPos* pos, RayTracer* t, Vector3 intersect) {
} }
void PickedPos_SetAsInvalid(PickedPos* pos) { void PickedPos_SetAsInvalid(PickedPos* pos) {
Vector3I blockPos = VECTOR3I_CONST(-1, -1, -1); Vector3I blockPos = { -1, -1, -1 };
pos->Valid = false; pos->Valid = false;
pos->BlockPos = blockPos; pos->BlockPos = blockPos;
pos->Block = BLOCK_AIR; pos->Block = BLOCK_AIR;

View File

@ -21,7 +21,6 @@ Real32 Vector3_Length(Vector3* v);
Real32 Vector3_LengthSquared(Vector3* v); Real32 Vector3_LengthSquared(Vector3* v);
#define VECTOR3_CONST(x, y, z) { x, y, z }; #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_UnitX VECTOR3_CONST(1.0f, 0.0f, 0.0f)
#define Vector3_UnitY VECTOR3_CONST(0.0f, 1.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) #define Vector3_UnitZ VECTOR3_CONST(0.0f, 0.0f, 1.0f)

View File

@ -1188,7 +1188,7 @@ void InputWidget_RemakeTexture(GuiElement* elem) {
totalHeight += widget->LineSizes[i].Height; totalHeight += widget->LineSizes[i].Height;
maxWidth = max(maxWidth, widget->LineSizes[i].Width); maxWidth = max(maxWidth, widget->LineSizes[i].Width);
} }
Size2D size = Size2D_Make(maxWidth, totalHeight); Size2D size = { maxWidth, totalHeight };
widget->CaretAccumulator = 0; widget->CaretAccumulator = 0;
Int32 realHeight = 0; Int32 realHeight = 0;

View File

@ -208,14 +208,14 @@ LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wParam, LPAR
case WM_WINDOWPOSCHANGED: case WM_WINDOWPOSCHANGED:
pos = (WINDOWPOS*)lParam; pos = (WINDOWPOS*)lParam;
if (pos->hwnd == win_Handle) { if (pos->hwnd == win_Handle) {
Point2D new_location = Point2D_Make(pos->x, pos->y); Point2D loc = Window_GetLocation();
if (!Point2D_Equals(Window_GetLocation(), new_location)) { if (loc.X != pos->x || loc.Y != pos->y) {
win_Bounds.X = pos->x; win_Bounds.Y = pos->y; win_Bounds.X = pos->x; win_Bounds.Y = pos->y;
Event_RaiseVoid(&WindowEvents_Moved); Event_RaiseVoid(&WindowEvents_Moved);
} }
Size2D new_size = Size2D_Make(pos->cx, pos->cy); Size2D size = Window_GetSize();
if (!Size2D_Equals(Window_GetSize(), new_size)) { if (size.Width != pos->cx || size.Height != pos->cy) {
win_Bounds.Width = pos->cx; win_Bounds.Height = pos->cy; win_Bounds.Width = pos->cx; win_Bounds.Height = pos->cy;
RECT rect; RECT rect;
@ -539,7 +539,7 @@ void Window_SetSize(Size2D size) {
Rectangle2D Window_GetClientRectangle(void) { return win_ClientRect; } Rectangle2D Window_GetClientRectangle(void) { return win_ClientRect; }
void Window_SetClientRectangle(Rectangle2D rect) { void Window_SetClientRectangle(Rectangle2D rect) {
Size2D size = Size2D_Make(rect.Width, rect.Height); Size2D size = { rect.Width, rect.Height };
Window_SetClientSize(size); Window_SetClientSize(size);
} }
@ -659,8 +659,8 @@ Point2D Window_PointToScreen(Point2D p) {
ErrorHandler_Fail("PointToScreen NOT IMPLEMENTED"); ErrorHandler_Fail("PointToScreen NOT IMPLEMENTED");
} }
MSG msg;
void Window_ProcessEvents(void) { void Window_ProcessEvents(void) {
MSG msg;
while (PeekMessageA(&msg, NULL, 0, 0, 1)) { while (PeekMessageA(&msg, NULL, 0, 0, 1)) {
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessageA(&msg); DispatchMessageA(&msg);