Fixed a node sorting bug
This commit is contained in:
@@ -1,5 +1 @@
|
|||||||
//this file is a polyfill TODO: fix this
|
//this file is a polyfill TODO: fix this
|
||||||
|
|
||||||
fn getRealPos(node: opaque) {
|
|
||||||
return [0, 0];
|
|
||||||
}
|
|
||||||
@@ -130,21 +130,15 @@ fn depthComparator(lhs: opaque, rhs: opaque) { //for sorting by depth
|
|||||||
var lhsPos = lhs.callNodeFn("getRealPos");
|
var lhsPos = lhs.callNodeFn("getRealPos");
|
||||||
var rhsPos = rhs.callNodeFn("getRealPos");
|
var rhsPos = rhs.callNodeFn("getRealPos");
|
||||||
|
|
||||||
var result = null;
|
if (lhsPos == null || rhsPos == null) { //BUGFIX: children without that function
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (lhsPos[1] == rhsPos[1]) { //BUGFIX: prevent z-fighting
|
if (lhsPos[1] == rhsPos[1]) { //BUGFIX: prevent z-fighting
|
||||||
if (lhsPos[0] == rhsPos[0]) {
|
return lhsPos[0] <= rhsPos[0];
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
result = lhsPos[0] < rhsPos[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
result = lhsPos[1] < rhsPos[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return lhsPos[1] < rhsPos[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getCameraPos(node: opaque) {
|
fn getCameraPos(node: opaque) {
|
||||||
|
|||||||
@@ -128,16 +128,15 @@ static void recursiveLiteralQuicksortUtil(Toy_Interpreter* interpreter, Box_Node
|
|||||||
|
|
||||||
//iterate through the array
|
//iterate through the array
|
||||||
for (int checker = 0; checker < count - 1; checker++) {
|
for (int checker = 0; checker < count - 1; checker++) {
|
||||||
//if node is null, it is always sorted to the end
|
//if node is null, it is always "sorted" to the end
|
||||||
if (ptr[checker] == NULL) {
|
while (ptr[checker] == NULL && count > 0) {
|
||||||
swapUtil(&ptr[checker], &ptr[checker + 1]);
|
swapUtil(&ptr[checker], &ptr[count - 1]);
|
||||||
runner++;
|
count--;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ptr[checker + 1] == NULL) {
|
//base case
|
||||||
runner++;
|
if (count < 2) {
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Toy_LiteralArray arguments;
|
Toy_LiteralArray arguments;
|
||||||
@@ -147,7 +146,7 @@ static void recursiveLiteralQuicksortUtil(Toy_Interpreter* interpreter, Box_Node
|
|||||||
Toy_initLiteralArray(&returns);
|
Toy_initLiteralArray(&returns);
|
||||||
|
|
||||||
Toy_pushLiteralArray(&arguments, TOY_TO_OPAQUE_LITERAL(ptr[checker], OPAQUE_TAG_NODE));
|
Toy_pushLiteralArray(&arguments, TOY_TO_OPAQUE_LITERAL(ptr[checker], OPAQUE_TAG_NODE));
|
||||||
Toy_pushLiteralArray(&arguments, TOY_TO_OPAQUE_LITERAL(ptr[checker + 1], OPAQUE_TAG_NODE));
|
Toy_pushLiteralArray(&arguments, TOY_TO_OPAQUE_LITERAL(ptr[count - 1], OPAQUE_TAG_NODE));
|
||||||
|
|
||||||
Toy_callLiteralFn(interpreter, fnCompare, &arguments, &returns);
|
Toy_callLiteralFn(interpreter, fnCompare, &arguments, &returns);
|
||||||
|
|
||||||
@@ -167,13 +166,8 @@ static void recursiveLiteralQuicksortUtil(Toy_Interpreter* interpreter, Box_Node
|
|||||||
swapUtil(&ptr[runner], &ptr[count - 1]);
|
swapUtil(&ptr[runner], &ptr[count - 1]);
|
||||||
|
|
||||||
//recurse on each end
|
//recurse on each end
|
||||||
if (runner > 0) {
|
|
||||||
recursiveLiteralQuicksortUtil(interpreter, &ptr[0], runner, fnCompare);
|
recursiveLiteralQuicksortUtil(interpreter, &ptr[0], runner, fnCompare);
|
||||||
}
|
|
||||||
|
|
||||||
if (runner < count) {
|
|
||||||
recursiveLiteralQuicksortUtil(interpreter, &ptr[runner + 1], count - runner - 1, fnCompare);
|
recursiveLiteralQuicksortUtil(interpreter, &ptr[runner + 1], count - runner - 1, fnCompare);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOX_API void Box_sortChildrenNode(Box_Node* node, Toy_Interpreter* interpreter, Toy_Literal fnCompare) {
|
BOX_API void Box_sortChildrenNode(Box_Node* node, Toy_Interpreter* interpreter, Toy_Literal fnCompare) {
|
||||||
|
|||||||
Reference in New Issue
Block a user