Replace mjQUICKSORT with faster, native sorting function. fixes #1638

PiperOrigin-RevId: 688519096
Change-Id: I05ab1576703c2458968ef81915ac682a8beac391
This commit is contained in:
Kyle Bayes
2024-10-22 06:04:10 -07:00
committed by Copybara-Service
parent 9e1aa37b55
commit 2b0629d75f
5 changed files with 172 additions and 82 deletions
+11 -4
View File
@@ -766,10 +766,10 @@ static void setView(int view, mjrRect viewport, const mjvScene* scn, const mjrCo
// comparison function for geom sorting
quicksortfunc(geomcompare, context, el1, el2) {
static inline int geomcmp(int* i, int* j, void* context) {
mjvGeom* geom = (mjvGeom*) context;
float d1 = geom[*(int*)el1].camdist;
float d2 = geom[*(int*)el2].camdist;
float d1 = geom[*i].camdist;
float d2 = geom[*j].camdist;
if (d1 < d2) {
return -1;
@@ -780,6 +780,9 @@ quicksortfunc(geomcompare, context, el1, el2) {
}
}
// define geomSort function for sorting geoms
mjSORT(geomSort, int, geomcmp)
// adjust light n position and direction
@@ -907,7 +910,11 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
}
// sort transparent geoms according to distance to camera
mjQUICKSORT(scn->geomorder, nt, sizeof(int), geomcompare, scn->geoms);
if (nt > 1) {
int *buf = (int*) mju_malloc(nt * sizeof(int));
geomSort(scn->geomorder, buf, nt, scn->geoms);
mju_free(buf);
}
// allow only one reflective geom
int j = 0;