From c0b0eb4b73fad627c13cd92770eeb33c5694a216 Mon Sep 17 00:00:00 2001 From: Arron Vinyard Date: Sun, 10 Apr 2022 17:38:26 -0400 Subject: [PATCH 1/6] Change sort optional parameters from Handle to any Not seeing any particular reason why the optional parameter needs to exclusively be a handle. This change shouldn't break any API. --- plugins/include/sorting.inc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/include/sorting.inc b/plugins/include/sorting.inc index ee777d8666..73dcd9800f 100644 --- a/plugins/include/sorting.inc +++ b/plugins/include/sorting.inc @@ -90,12 +90,12 @@ native void SortStrings(char[][] array, int array_size, SortOrder order = Sort_A * @param elem1 First element to compare. * @param elem2 Second element to compare. * @param array Array that is being sorted (order is undefined). - * @param hndl Handle optionally passed in while sorting. + * @param data Handle or value optionally passed in while sorting. * @return -1 if first should go before second * 0 if first is equal to second * 1 if first should go after second */ -typedef SortFunc1D = function int (int elem1, int elem2, const int[] array, Handle hndl); +typedef SortFunc1D = function int (int elem1, int elem2, const int[] array, any data); /** * Sorts a custom 1D array. You must pass in a comparison function. @@ -103,9 +103,9 @@ typedef SortFunc1D = function int (int elem1, int elem2, const int[] array, Hand * @param array Array to sort. * @param array_size Size of the array to sort. * @param sortfunc Sort function. - * @param hndl Optional Handle to pass through the comparison calls. + * @param data Optional Handle or value to pass through the comparison calls. */ -native void SortCustom1D(int[] array, int array_size, SortFunc1D sortfunc, Handle hndl=INVALID_HANDLE); +native void SortCustom1D(int[] array, int array_size, SortFunc1D sortfunc, any data=0); /** * Sort comparison function for 2D array elements (sub-arrays). @@ -114,15 +114,15 @@ native void SortCustom1D(int[] array, int array_size, SortFunc1D sortfunc, Handl * @param elem1 First array to compare. * @param elem2 Second array to compare. * @param array Array that is being sorted (order is undefined). - * @param hndl Handle optionally passed in while sorting. + * @param data Handle or value optionally passed in while sorting. * @return -1 if first should go before second * 0 if first is equal to second * 1 if first should go after second */ typeset SortFunc2D { - function int (int[] elem1, int[] elem2, const int[][] array, Handle hndl); - function int (char[] elem1, char[] elem2, const char[][] array, Handle hndl); + function int (int[] elem1, int[] elem2, const int[][] array, any data); + function int (char[] elem1, char[] elem2, const char[][] array, any data); }; /** @@ -133,7 +133,7 @@ typeset SortFunc2D * @param sortfunc Sort comparison function to use. * @param hndl Optional Handle to pass through the comparison calls. */ -native void SortCustom2D(any[][] array, int array_size, SortFunc2D sortfunc, Handle hndl=INVALID_HANDLE); +native void SortCustom2D(any[][] array, int array_size, SortFunc2D sortfunc, any data=0); /** * Sort an ADT Array. Specify the type as Integer, Float, or String. @@ -152,18 +152,18 @@ native void SortADTArray(Handle array, SortOrder order, SortType type); * @param index1 First index to compare. * @param index2 Second index to compare. * @param array Array that is being sorted (order is undefined). - * @param hndl Handle optionally passed in while sorting. + * @param data Handle or value optionally passed in while sorting. * @return -1 if first should go before second * 0 if first is equal to second * 1 if first should go after second */ -typedef SortFuncADTArray = function int (int index1, int index2, Handle array, Handle hndl); +typedef SortFuncADTArray = function int (int index1, int index2, Handle array, any data); /** * Custom sorts an ADT Array. You must pass in a comparison function. * * @param array Array Handle to sort * @param sortfunc Sort comparison function to use - * @param hndl Optional Handle to pass through the comparison calls. + * @param data Optional Handle or data to pass through the comparison calls. */ -native void SortADTArrayCustom(Handle array, SortFuncADTArray sortfunc, Handle hndl=INVALID_HANDLE); +native void SortADTArrayCustom(Handle array, SortFuncADTArray sortfunc, any data=0); From 83f00a920c76774b48136cb9320456f426969d4b Mon Sep 17 00:00:00 2001 From: Arron Vinyard Date: Sun, 10 Apr 2022 17:42:48 -0400 Subject: [PATCH 2/6] Update adt_array.inc --- plugins/include/adt_array.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/include/adt_array.inc b/plugins/include/adt_array.inc index 911b66702c..d598d24f1d 100644 --- a/plugins/include/adt_array.inc +++ b/plugins/include/adt_array.inc @@ -219,8 +219,8 @@ methodmap ArrayList < Handle { // Custom sorts an ADT Array. You must pass in a comparison function. // // @param sortfunc Sort comparison function to use - // @param hndl Optional Handle to pass through the comparison calls. - public native void SortCustom(SortFuncADTArray sortfunc, Handle hndl=INVALID_HANDLE); + // @param data Optional Handle or data to pass through the comparison calls. + public native void SortCustom(SortFuncADTArray sortfunc, any data=0); // Retrieve the size of the array. property int Length { From 38ae529a4da9083a5a2340fe106455dba9e50a8a Mon Sep 17 00:00:00 2001 From: Arron Vinyard Date: Sun, 10 Apr 2022 17:43:34 -0400 Subject: [PATCH 3/6] Update adt_array.inc --- plugins/include/adt_array.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/include/adt_array.inc b/plugins/include/adt_array.inc index d598d24f1d..a6d95c5bc0 100644 --- a/plugins/include/adt_array.inc +++ b/plugins/include/adt_array.inc @@ -219,7 +219,7 @@ methodmap ArrayList < Handle { // Custom sorts an ADT Array. You must pass in a comparison function. // // @param sortfunc Sort comparison function to use - // @param data Optional Handle or data to pass through the comparison calls. + // @param data Optional Handle or value to pass through the comparison calls. public native void SortCustom(SortFuncADTArray sortfunc, any data=0); // Retrieve the size of the array. From 7cc392392dca018f6fdf2ba6e9994b69d641df79 Mon Sep 17 00:00:00 2001 From: Arron Vinyard Date: Sun, 10 Apr 2022 17:52:52 -0400 Subject: [PATCH 4/6] Update smn_sorting.cpp --- core/logic/smn_sorting.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/logic/smn_sorting.cpp b/core/logic/smn_sorting.cpp index 82ad19589a..97cf6158f1 100644 --- a/core/logic/smn_sorting.cpp +++ b/core/logic/smn_sorting.cpp @@ -342,7 +342,7 @@ static cell_t sm_SortStrings(IPluginContext *pContext, const cell_t *params) struct sort_info { IPluginFunction *pFunc; - Handle_t hndl; + cell_t data; cell_t array_addr; cell_t *array_base; cell_t *array_remap; @@ -364,7 +364,7 @@ int sort1d_amx_custom(const void *elem1, const void *elem2) pf->PushCell(c1); pf->PushCell(c2); pf->PushCell(g_SortInfo.array_addr); - pf->PushCell(g_SortInfo.hndl); + pf->PushCell(g_SortInfo.data); pf->Invoke(&result); return result; @@ -386,7 +386,7 @@ static cell_t sm_SortCustom1D(IPluginContext *pContext, const cell_t *params) sort_info oldinfo = g_SortInfo; DetectExceptions eh(pContext); - g_SortInfo.hndl = params[4]; + g_SortInfo.data = params[4]; g_SortInfo.array_addr = params[1]; g_SortInfo.array_remap = NULL; g_SortInfo.array_base = NULL; @@ -419,7 +419,7 @@ static int sort2d_amx_custom_legacy(const void *elem1, const void *elem2) g_SortInfo.pFunc->PushCell(c1_addr); g_SortInfo.pFunc->PushCell(c2_addr); g_SortInfo.pFunc->PushCell(g_SortInfo.array_addr); - g_SortInfo.pFunc->PushCell(g_SortInfo.hndl); + g_SortInfo.pFunc->PushCell(g_SortInfo.data); g_SortInfo.pFunc->Invoke(&result); return result; @@ -451,7 +451,7 @@ static cell_t sm_SortCustom2D_Legacy(IPluginContext *pContext, const cell_t *par DetectExceptions eh(pContext); g_SortInfo.pFunc = pFunction; - g_SortInfo.hndl = params[4]; + g_SortInfo.data = params[4]; g_SortInfo.array_addr = params[1]; g_SortInfo.eh = &eh; @@ -495,7 +495,7 @@ static int sort2d_amx_custom(const void *elem1, const void *elem2) g_SortInfo.pFunc->PushCell(iv1); g_SortInfo.pFunc->PushCell(iv2); g_SortInfo.pFunc->PushCell(g_SortInfo.array_addr); - g_SortInfo.pFunc->PushCell(g_SortInfo.hndl); + g_SortInfo.pFunc->PushCell(g_SortInfo.data); g_SortInfo.pFunc->Invoke(&result); return result; @@ -522,7 +522,7 @@ static cell_t sm_SortCustom2D(IPluginContext *pContext, const cell_t *params) DetectExceptions eh(pContext); g_SortInfo.pFunc = pFunction; - g_SortInfo.hndl = params[4]; + g_SortInfo.data = params[4]; g_SortInfo.array_addr = params[1]; g_SortInfo.eh = &eh; @@ -630,7 +630,7 @@ struct sort_infoADT cell_t *array_base; cell_t array_bsize; Handle_t array_hndl; - Handle_t hndl; + cell_t data; ExceptionHandler *eh; }; @@ -646,7 +646,7 @@ int sort_adtarray_custom(const void *elem1, const void *elem2) pf->PushCell(((cell_t) ((cell_t *) elem1 - g_SortInfoADT.array_base)) / g_SortInfoADT.array_bsize); pf->PushCell(((cell_t) ((cell_t *) elem2 - g_SortInfoADT.array_base)) / g_SortInfoADT.array_bsize); pf->PushCell(g_SortInfoADT.array_hndl); - pf->PushCell(g_SortInfoADT.hndl); + pf->PushCell(g_SortInfoADT.data); pf->Invoke(&result); return result; @@ -681,7 +681,7 @@ static cell_t sm_SortADTArrayCustom(IPluginContext *pContext, const cell_t *para g_SortInfoADT.array_base = array; g_SortInfoADT.array_bsize = (cell_t) blocksize; g_SortInfoADT.array_hndl = params[1]; - g_SortInfoADT.hndl = params[3]; + g_SortInfoADT.data = params[3]; g_SortInfoADT.eh = &eh; qsort(array, arraysize, blocksize * sizeof(cell_t), sort_adtarray_custom); From bb3b73684a86940509733cbe1722b84d67bcf2cf Mon Sep 17 00:00:00 2001 From: Arron Vinyard Date: Sun, 10 Apr 2022 18:41:18 -0400 Subject: [PATCH 5/6] Fix SortFunc2D typedef --- plugins/include/sorting.inc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/plugins/include/sorting.inc b/plugins/include/sorting.inc index 73dcd9800f..66e6bc6df9 100644 --- a/plugins/include/sorting.inc +++ b/plugins/include/sorting.inc @@ -119,11 +119,7 @@ native void SortCustom1D(int[] array, int array_size, SortFunc1D sortfunc, any d * 0 if first is equal to second * 1 if first should go after second */ -typeset SortFunc2D -{ - function int (int[] elem1, int[] elem2, const int[][] array, any data); - function int (char[] elem1, char[] elem2, const char[][] array, any data); -}; +typedef SortFunc2D = function int (any[] elem1, any[] elem2, const any[][] array, any data); /** * Sorts a custom 2D array. You must pass in a comparison function. From 4d43cd83eb93ffe12f152bf967398d5121ea4490 Mon Sep 17 00:00:00 2001 From: Arron Vinyard Date: Sun, 10 Apr 2022 18:51:06 -0400 Subject: [PATCH 6/6] Change Sort(Custom/Func)1D params from int to any --- plugins/include/sorting.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/include/sorting.inc b/plugins/include/sorting.inc index 66e6bc6df9..9ecfc5ec4d 100644 --- a/plugins/include/sorting.inc +++ b/plugins/include/sorting.inc @@ -95,7 +95,7 @@ native void SortStrings(char[][] array, int array_size, SortOrder order = Sort_A * 0 if first is equal to second * 1 if first should go after second */ -typedef SortFunc1D = function int (int elem1, int elem2, const int[] array, any data); +typedef SortFunc1D = function int (any elem1, any elem2, const any[] array, any data); /** * Sorts a custom 1D array. You must pass in a comparison function. @@ -105,7 +105,7 @@ typedef SortFunc1D = function int (int elem1, int elem2, const int[] array, any * @param sortfunc Sort function. * @param data Optional Handle or value to pass through the comparison calls. */ -native void SortCustom1D(int[] array, int array_size, SortFunc1D sortfunc, any data=0); +native void SortCustom1D(any[] array, int array_size, SortFunc1D sortfunc, any data=0); /** * Sort comparison function for 2D array elements (sub-arrays). @@ -127,7 +127,7 @@ typedef SortFunc2D = function int (any[] elem1, any[] elem2, const any[][] array * @param array Array to sort. * @param array_size Size of the major array to sort (first index, outermost). * @param sortfunc Sort comparison function to use. - * @param hndl Optional Handle to pass through the comparison calls. + * @param data Optional Handle or value to pass through the comparison calls. */ native void SortCustom2D(any[][] array, int array_size, SortFunc2D sortfunc, any data=0); @@ -160,6 +160,6 @@ typedef SortFuncADTArray = function int (int index1, int index2, Handle array, a * * @param array Array Handle to sort * @param sortfunc Sort comparison function to use - * @param data Optional Handle or data to pass through the comparison calls. + * @param data Optional Handle or value to pass through the comparison calls. */ native void SortADTArrayCustom(Handle array, SortFuncADTArray sortfunc, any data=0);