From ff5f5c50bd2ce931a62b2eb1b0aed97c0fa370c5 Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Sun, 18 Mar 2018 00:40:38 +0100 Subject: Update to newest version DTCallback: Add fast callbacks (only Object/DefinitionCallback() is possible) and restructure CallA() for hopefully better performance DTCallback: Fix all custom calls to allow overriding in Definition- and Object-context DTFilterObjects: new addition DTMenuCompatibility: add Menu_Entry compatibility version due to the new Menu_Entry-API DTObjectSerializing: small progress, still WIP DTPlayers: Fix constant enum definitions (thanks to the preprocessor's precalculator) DTQuickSort: Add custom callback args DTScopedVars: Fix all custom calls to allow overriding in Definition- and Object-context DTScopedVars: CustomScopedVar-implementations must now return another less custom ScopedVar instead of a reference (due to _inherited()) DTTransform: disable MirrorZ DTTransform: fix Matrix3x3Multiply and thus PreTransform DTTransform: fix whitespace DTTransform: update comments DTUTility: Fix indentation and whitespace DTUtility: Add GetShape, InRect and GetPlayerByID DTCallback, DTObjectSerializing: Rely on the preprocessor's precalculator --- DTQuickSort.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'DTQuickSort.c') diff --git a/DTQuickSort.c b/DTQuickSort.c index 7434263..8f480ca 100644 --- a/DTQuickSort.c +++ b/DTQuickSort.c @@ -17,17 +17,17 @@ global func SortNumericInverse(int a, int b) return -SortNumeric(a, b); } -global func QSort(array& data, callback) // WARNING: Can cause stack-overflow with too much data +global func QSort(array& data, callback, callbackArgs) // WARNING: Can cause stack-overflow with too much data { if(callback == true) { callback = GlobalCallback("SortNumericInverse"); } - QSort_Part(data, callback || GlobalCallback("SortNumeric"), 0, GetLength(data) - 1); + QSort_Part(data, callback || GlobalCallback("SortNumeric"), 0, GetLength(data) - 1, callbackArgs); return data; } -global func QSort_Part(array& data, callback, int left, int right) +global func QSort_Part(array& data, callback, int left, int right, callbackArgs) { if(left < right) { @@ -35,16 +35,16 @@ global func QSort_Part(array& data, callback, int left, int right) var pPos = RandomX(left, right); var p = data[pPos]; var tmp; - + tmp = data[pPos]; data[pPos] = data[right]; data[right] = tmp; pPos = right; - + var i = left - 1; for(var j = left; j <= right; ++j) { - if(Call(callback, data[j], p) < 0) + if(Call(callback, data[j], p, callbackArgs) < 0) { ++i; tmp = data[i]; @@ -52,15 +52,15 @@ global func QSort_Part(array& data, callback, int left, int right) data[j] = tmp; } } - + ++i; - + tmp = data[i]; data[i] = data[pPos]; data[pPos] = tmp; // ----- - - QSort_Part(data, callback, left, i - 1); - QSort_Part(data, callback, i + 1, right); + + QSort_Part(data, callback, left, i - 1, callbackArgs); + QSort_Part(data, callback, i + 1, right, callbackArgs); } } -- cgit v1.2.3-54-g00ecf