Skip to content
Permalink
Browse files

Make selection box rendering a little bit faster

  • Loading branch information
UnknownShadow200 committed Dec 1, 2019
1 parent 8ce8360 commit f475eec3528988107c7bedc4d3e391d1dde09adc
Showing with 10 additions and 15 deletions.
  1. +1 −1 src/Screens.c
  2. +1 −0 src/Screens.h
  3. +8 −14 src/SelectionBox.c
@@ -1209,7 +1209,7 @@ static void GeneratingScreen_EndGeneration(void) {
struct LocationUpdate update;
float x, z;

Gui_Remove(LoadingScreen_UNSAFE_RawPointer);
Gui_Remove((struct Screen*)&LoadingScreen_Instance);
Gen_Done = false;

if (!Gen_Blocks) { Chat_AddRaw("&cFailed to generate the map."); return; }
@@ -37,6 +37,7 @@ extern struct Screen* LoadingScreen_UNSAFE_RawPointer;
void ChatScreen_OpenInput(const String* text);
/* Appends text to the chat input in the HUD. */
void ChatScreen_AppendInput(const String* text);
/* Sets number of visible lines in the main chat widget. */
void ChatScreen_SetChatlines(int lines);
struct Widget* ChatScreen_GetHotbar(void);
#endif
@@ -82,20 +82,14 @@ static void SelectionBox_UpdateDist(Vec3 p, float x2, float y2, float z2, float*
if (dist > *furthest) *furthest = dist;
}

static void SelectionBox_Intersect(struct SelectionBox* box, Vec3 origin) {
Vec3 min = box->Min, max = box->Max;
float closest = MATH_POS_INF, furthest = -MATH_POS_INF;
/* Bottom corners */
SelectionBox_UpdateDist(origin, min.X, min.Y, min.Z, &closest, &furthest);
SelectionBox_UpdateDist(origin, max.X, min.Y, min.Z, &closest, &furthest);
SelectionBox_UpdateDist(origin, max.X, min.Y, max.Z, &closest, &furthest);
SelectionBox_UpdateDist(origin, min.X, min.Y, max.Z, &closest, &furthest);
/* 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;
static void SelectionBox_Intersect(struct SelectionBox* box, Vec3 P) {
float dx1 = (P.X - box->Min.X) * (P.X - box->Min.X), dx2 = (P.X - box->Max.X) * (P.X - box->Max.X);
float dy1 = (P.Y - box->Min.Y) * (P.Y - box->Min.Y), dy2 = (P.Y - box->Max.Y) * (P.Y - box->Max.Y);
float dz1 = (P.Z - box->Min.Z) * (P.Z - box->Min.Z), dz2 = (P.Z - box->Max.Z) * (P.Z - box->Max.Z);

/* Distance to closest and furthest of the eight box corners */
box->MinDist = min(dx1, dx2) + min(dy1, dy2) + min(dz1, dz2);
box->MaxDist = max(dx1, dx2) + max(dy1, dy2) + max(dz1, dz2);
}


0 comments on commit f475eec

Please sign in to comment.
You can’t perform that action at this time.