Make selection box rendering a little bit faster

This commit is contained in:
UnknownShadow200 2019-12-01 17:25:00 +11:00
parent 8ce836010a
commit f475eec352
3 changed files with 10 additions and 15 deletions

View File

@ -1209,7 +1209,7 @@ static void GeneratingScreen_EndGeneration(void) {
struct LocationUpdate update; struct LocationUpdate update;
float x, z; float x, z;
Gui_Remove(LoadingScreen_UNSAFE_RawPointer); Gui_Remove((struct Screen*)&LoadingScreen_Instance);
Gen_Done = false; Gen_Done = false;
if (!Gen_Blocks) { Chat_AddRaw("&cFailed to generate the map."); return; } if (!Gen_Blocks) { Chat_AddRaw("&cFailed to generate the map."); return; }

View File

@ -37,6 +37,7 @@ extern struct Screen* LoadingScreen_UNSAFE_RawPointer;
void ChatScreen_OpenInput(const String* text); void ChatScreen_OpenInput(const String* text);
/* Appends text to the chat input in the HUD. */ /* Appends text to the chat input in the HUD. */
void ChatScreen_AppendInput(const String* text); void ChatScreen_AppendInput(const String* text);
/* Sets number of visible lines in the main chat widget. */
void ChatScreen_SetChatlines(int lines); void ChatScreen_SetChatlines(int lines);
struct Widget* ChatScreen_GetHotbar(void); struct Widget* ChatScreen_GetHotbar(void);
#endif #endif

View File

@ -82,20 +82,14 @@ static void SelectionBox_UpdateDist(Vec3 p, float x2, float y2, float z2, float*
if (dist > *furthest) *furthest = dist; if (dist > *furthest) *furthest = dist;
} }
static void SelectionBox_Intersect(struct SelectionBox* box, Vec3 origin) { static void SelectionBox_Intersect(struct SelectionBox* box, Vec3 P) {
Vec3 min = box->Min, max = box->Max; float dx1 = (P.X - box->Min.X) * (P.X - box->Min.X), dx2 = (P.X - box->Max.X) * (P.X - box->Max.X);
float closest = MATH_POS_INF, furthest = -MATH_POS_INF; float dy1 = (P.Y - box->Min.Y) * (P.Y - box->Min.Y), dy2 = (P.Y - box->Max.Y) * (P.Y - box->Max.Y);
/* Bottom corners */ float dz1 = (P.Z - box->Min.Z) * (P.Z - box->Min.Z), dz2 = (P.Z - box->Max.Z) * (P.Z - box->Max.Z);
SelectionBox_UpdateDist(origin, min.X, min.Y, min.Z, &closest, &furthest);
SelectionBox_UpdateDist(origin, max.X, min.Y, min.Z, &closest, &furthest); /* Distance to closest and furthest of the eight box corners */
SelectionBox_UpdateDist(origin, max.X, min.Y, max.Z, &closest, &furthest); box->MinDist = min(dx1, dx2) + min(dy1, dy2) + min(dz1, dz2);
SelectionBox_UpdateDist(origin, min.X, min.Y, max.Z, &closest, &furthest); box->MaxDist = max(dx1, dx2) + max(dy1, dy2) + max(dz1, dz2);
/* Top corners */
SelectionBox_UpdateDist(origin, min.X, max.Y, min.Z, &closest, &furthest);
SelectionBox_UpdateDist(origin, max.X, max.Y, min.Z, &closest, &furthest);
SelectionBox_UpdateDist(origin, max.X, max.Y, max.Z, &closest, &furthest);
SelectionBox_UpdateDist(origin, min.X, max.Y, max.Z, &closest, &furthest);
box->MinDist = closest; box->MaxDist = furthest;
} }