Skip to content

Commit

Permalink
Fix 'download size:' in texture pack warning sometimes showing garbage
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Nov 17, 2018
1 parent d58440a commit fc052e9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 38 deletions.
5 changes: 3 additions & 2 deletions src/Builder.c
Expand Up @@ -492,7 +492,9 @@ void Builder_OnNewMapLoaded(void) {
*--------------------------------------------------Normal mesh builder----------------------------------------------------*
*#########################################################################################################################*/
static PackedCol Normal_LightCol(int x, int y, int z, Face face, BlockID block) {
PackedCol invalid = PACKEDCOL_CONST(0, 0, 0, 0);
int offset = (Block_LightOffset[block] >> face) & 1;

switch (face) {
case FACE_XMIN:
return x < offset ? Env_SunXSide : Lighting_Col_XSide_Fast(x - offset, y, z);
Expand All @@ -507,8 +509,7 @@ static PackedCol Normal_LightCol(int x, int y, int z, Face face, BlockID block)
case FACE_YMAX:
return y >= World_MaxY ? Env_SunCol : Lighting_Col_YMax_Fast(x, (y + 1) - offset, z);
}

PackedCol invalid = PACKEDCOL_CONST(0, 0, 0, 0); return invalid;
return invalid; /* should never happen */
}

static bool Normal_CanStretch(BlockID initial, int chunkIndex, int x, int y, int z, Face face) {
Expand Down
2 changes: 1 addition & 1 deletion src/Gui.c
Expand Up @@ -75,7 +75,7 @@ int Gui_CalcPos(uint8_t anchor, int offset, int size, int axisLen) {
}

bool Gui_Contains(int recX, int recY, int width, int height, int x, int y) {
return x >= recX && y >= recY && x < recX + width && y < recY + height;
return x >= recX && y >= recY && x < (recX + width) && y < (recY + height);
}

static void Gui_FileChanged(void* obj, struct Stream* stream, const String* name) {
Expand Down
7 changes: 4 additions & 3 deletions src/Menus.c
Expand Up @@ -3273,10 +3273,11 @@ static void TexPackOverlay_ContextRecreated(void* screen) {
String_FromConst("Do you want to download the server's texture pack?"),
String_FromConst("Texture pack url:"),
String_FromConst(""),
String_FromConst("Download size: Determining..."),
String_FromConst(""),
};
static String defCL = String_FromConst("Download size: Determining...");
static String https = String_FromConst("https://");
static String http = String_FromConst("http://");
static String http = String_FromConst("http://");
String contents; char contentsBuffer[STRING_SIZE];

float contentLengthMB;
Expand All @@ -3296,7 +3297,7 @@ static void TexPackOverlay_ContextRecreated(void* screen) {
String_InitArray(contents, contentsBuffer);
String_Format1(&contents, "Download size: %f3 MB", &contentLengthMB);
lines[3] = contents;
}
} else { lines[3] = defCL; }

Overlay_MakeLabels(s, s->Labels, lines);
WarningOverlay_MakeButtons((struct MenuScreen*)s, s->Buttons, true,
Expand Down
7 changes: 4 additions & 3 deletions src/ModelCache.c
Expand Up @@ -1021,14 +1021,15 @@ static void SpiderModel_GetPickingBounds(struct AABB* bb) { Model_RetAABB(-5,0,-
#define eighthPi (MATH_PI / 8.0f)

static void SpiderModel_DrawModel(struct Entity* entity) {
float rotX, rotY, rotZ;
Model_ApplyTexture(entity);
Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &Spider_Head, true);
Model_DrawPart(&Spider_Link);
Model_DrawPart(&Spider_End);

float rotX = Math_SinF(entity->Anim.WalkTime) * entity->Anim.Swing * MATH_PI;
float rotZ = Math_CosF(entity->Anim.WalkTime * 2) * entity->Anim.Swing * MATH_PI / 16.0f;
float rotY = Math_SinF(entity->Anim.WalkTime * 2) * entity->Anim.Swing * MATH_PI / 32.0f;
rotX = Math_SinF(entity->Anim.WalkTime) * entity->Anim.Swing * MATH_PI;
rotZ = Math_CosF(entity->Anim.WalkTime * 2) * entity->Anim.Swing * MATH_PI / 16.0f;
rotY = Math_SinF(entity->Anim.WalkTime * 2) * entity->Anim.Swing * MATH_PI / 32.0f;
Model_Rotation = ROTATE_ORDER_XZY;

Model_DrawRotate(rotX, quarterPi + rotY, eighthPi + rotZ, &Spider_LeftLeg, false);
Expand Down
61 changes: 32 additions & 29 deletions src/Widgets.c
Expand Up @@ -119,9 +119,10 @@ static void ButtonWidget_Render(void* widget, double delta) {
PackedCol normCol = PACKEDCOL_CONST(224, 224, 224, 255);
PackedCol activeCol = PACKEDCOL_CONST(255, 255, 160, 255);
PackedCol disabledCol = PACKEDCOL_CONST(160, 160, 160, 255);
PackedCol col, white = PACKEDCOL_WHITE;
struct ButtonWidget* w = widget;
struct Texture back;
PackedCol col;
struct Texture back;
float scale;

back = w->Active ? Button_SelectedTex : Button_ShadowTex;
if (w->Disabled) back = Button_DisabledTex;
Expand All @@ -135,9 +136,8 @@ static void ButtonWidget_Render(void* widget, double delta) {
Texture_Render(&back);
} else {
/* Split button down the middle */
float scale = (w->Width / 400.0f) * 0.5f;
scale = (w->Width / 400.0f) * 0.5f;
Gfx_BindTexture(back.ID); /* avoid bind twice */
PackedCol white = PACKEDCOL_WHITE;

back.Width = (w->Width / 2);
back.uv.U1 = 0.0f; back.uv.U2 = BUTTON_uWIDTH * scale;
Expand Down Expand Up @@ -220,16 +220,19 @@ static void ScrollbarWidget_GetScrollbarCoords(struct ScrollbarWidget* w, int* y

static void ScrollbarWidget_Render(void* widget, double delta) {
struct ScrollbarWidget* w = widget;
int x = w->X, width = w->Width;
int x, y, width, height;
PackedCol barCol;
bool hovered;

x = w->X; width = w->Width;
GfxCommon_Draw2DFlat(x, w->Y, width, w->Height, Scroll_BackCol);

int y, height;
ScrollbarWidget_GetScrollbarCoords(w, &y, &height);
x += SCROLL_BORDER; y += w->Y;
width -= SCROLL_BORDER * 2;

bool hovered = Mouse_Y >= y && Mouse_Y < (y + height) && Mouse_X >= x && Mouse_X < (x + width);
PackedCol barCol = hovered ? Scroll_HoverCol : Scroll_BarCol;
hovered = Mouse_Y >= y && Mouse_Y < (y + height) && Mouse_X >= x && Mouse_X < (x + width);
barCol = hovered ? Scroll_HoverCol : Scroll_BarCol;
GfxCommon_Draw2DFlat(x, y, width, height, barCol);

if (height < 20) return;
Expand Down Expand Up @@ -333,17 +336,17 @@ static void HotbarWidget_RenderHotbarOutline(struct HotbarWidget* w) {
static void HotbarWidget_RenderHotbarBlocks(struct HotbarWidget* w) {
/* TODO: Should hotbar use its own VB? */
VertexP3fT2fC4b vertices[INVENTORY_BLOCKS_PER_HOTBAR * ISOMETRICDRAWER_MAXVERTICES];
float width, scale;
int i, x, y;

IsometricDrawer_BeginBatch(vertices, ModelCache_Vb);
width = w->ElemSize + w->BorderSize;
scale = (w->ElemSize * 13.5f/16.0f) / 2.0f;

float width = w->ElemSize + w->BorderSize;
int i;
for (i = 0; i < INVENTORY_BLOCKS_PER_HOTBAR; i++) {
BlockID block = Inventory_Get(i);
int x = (int)(w->X + w->BarXOffset + width * i + w->ElemSize / 2);
int y = (int)(w->Y + (w->Height - w->BarHeight / 2));

float scale = (w->ElemSize * 13.5f / 16.0f) / 2.0f;
IsometricDrawer_DrawBatch(block, scale, x, y);
x = (int)(w->X + w->BarXOffset + width * i + w->ElemSize / 2);
y = (int)(w->Y + (w->Height - w->BarHeight / 2));
IsometricDrawer_DrawBatch(Inventory_Get(i), scale, x, y);
}
IsometricDrawer_EndBatch();
}
Expand Down Expand Up @@ -578,8 +581,7 @@ static void TableWidget_RecreateDescTex(struct TableWidget* w) {

Gfx_DeleteTexture(&w->DescTex.ID);
if (w->SelectedIndex == -1) return;
BlockID block = w->Elements[w->SelectedIndex];
TableWidget_MakeDescTex(w, block);
TableWidget_MakeDescTex(w, w->Elements[w->SelectedIndex]);
}

void TableWidget_MakeDescTex(struct TableWidget* w, BlockID block) {
Expand Down Expand Up @@ -1565,6 +1567,7 @@ void MenuInputWidget_Create(struct MenuInputWidget* w, int width, int height, co
*-----------------------------------------------------ChatInputWidget-----------------------------------------------------*
*#########################################################################################################################*/
static void ChatInputWidget_RemakeTexture(void* widget) {
String line; char lineBuffer[STRING_SIZE + 2];
struct InputWidget* w = widget;
struct DrawTextArgs args;
Size2D size = { 0, 0 };
Expand All @@ -1584,9 +1587,7 @@ static void ChatInputWidget_RemakeTexture(void* widget) {
Drawer2D_DrawText(&bmp, &args, 0, 0);
}

char lineBuffer[STRING_SIZE + 2];
String line = String_FromArray(lineBuffer);

String_InitArray(line, lineBuffer);
for (i = 0; i < Array_Elems(w->Lines); i++) {
if (!w->Lines[i].length) break;
line.length = 0;
Expand Down Expand Up @@ -1964,8 +1965,9 @@ static void PlayerListWidget_DeleteAt(struct PlayerListWidget* w, int i) {
}

static void PlayerListWidget_AddGroup(struct PlayerListWidget* w, int id, int* index) {
String group = TabList_UNSAFE_GetGroup(id);
String group;
int i;
group = TabList_UNSAFE_GetGroup(id);

for (i = Array_Elems(w->IDs) - 1; i > (*index); i--) {
w->IDs[i] = w->IDs[i - 1];
Expand All @@ -1980,11 +1982,11 @@ static void PlayerListWidget_AddGroup(struct PlayerListWidget* w, int id, int* i
}

static int PlayerListWidget_GetGroupCount(struct PlayerListWidget* w, int id, int i) {
String group = TabList_UNSAFE_GetGroup(id);
String curGroup;
int count = 0;
String group, curGroup;
int count;
group = TabList_UNSAFE_GetGroup(id);

for (; i < w->NamesCount; i++, count++) {
for (count = 0; i < w->NamesCount; i++, count++) {
curGroup = TabList_UNSAFE_GetGroup(w->IDs[i]);
if (!String_CaselessEquals(&group, &curGroup)) break;
}
Expand Down Expand Up @@ -2013,9 +2015,10 @@ static int PlayerListWidget_PlayerCompare(int x, int y) {
}

static int PlayerListWidget_GroupCompare(int x, int y) {
String xGroup, yGroup;
/* TODO: should we use colourless comparison? ClassicalSharp sorts groups with colours */
String xGroup = TabList_UNSAFE_GetGroup(x);
String yGroup = TabList_UNSAFE_GetGroup(y);
xGroup = TabList_UNSAFE_GetGroup(x);
yGroup = TabList_UNSAFE_GetGroup(y);
return String_Compare(&xGroup, &yGroup);
}

Expand Down Expand Up @@ -2711,7 +2714,7 @@ static void SpecialInputWidget_InitTabs(struct SpecialInputWidget* w) {
#define SPECIAL_CONTENT_SPACING 5
static Size2D SpecialInputWidget_MeasureTitles(struct SpecialInputWidget* w) {
struct DrawTextArgs args;
Size2D size = Size2D_Empty;
Size2D size = { 0, 0 };
int i;

DrawTextArgs_MakeEmpty(&args, &w->Font, false);
Expand Down

0 comments on commit fc052e9

Please sign in to comment.