[+] Added exported functions for array sorting:
// Sorts given integer array in ascending order
procedure SortInt32 (Arr: pointer to array of integer; MinInd, MaxInd: integer); stdcall;
- Example:
- Let us sort arbitrary array of 10 numbers.
- !#VA(arr[10]:y);
- !!VR(arr):C39/12/20/92/78/17/17/43/6/32;
- !!SN:F^SortInt32^/?(arr)/0/9;
- !!IF:M^%(arr[0]) %(arr[1]) %(arr[2]) %(arr[3]) %(arr[4]) %(arr[5]) %(arr[6]) %(arr[7]) %(arr[8]) %(arr[9])^;
// Sorts given integer array in ascending order using custom ERM comparator function
procedure Erm_CustomStableSortInt32 (Arr: pointer to array of integer; MinInd, MaxInd: integer; ComparatorFuncId: integer; State: integer); stdcall;
The caller passes ID of ERM function, which will be used for items comparison. The function must return:
- 0 if two values are equal;
- positive number if the first value is greater than the second one (i.e. +1);
- negative number if the first value is smaller, than the second one (i.e. -1).
The comparator function prototype is:
- !?FU(tst_CompareItems);
- !#VA(value1:x) (value2:x) (state:x) (result:x);
Function will always receive special 'State' argument, containing the value, you specified calling Erm_CustomStableSortInt32.
This value may hold array ID, some structure address or any other useful custom data.
- Example:
- Let us sort array of 10 monster IDs by each monster hit points.
- !?PI;
- !#VA(arr[10]:y);
- !!VR(arr):C39/12/20/92/78/17/13/43/6/32;
- !!SN:F^Erm_CustomStableSortInt32^/?(arr)/0/9/(tst_SortByMonHp)/0;
- !!IF:M^Monsters: %(arr[0]) %(arr[1]) %(arr[2]) %(arr[3]) %(arr[4]) %(arr[5]) %(arr[6]) %(arr[7]) %(arr[8]) %(arr[9])^;
- !!re i/(@arr[0])/(@arr[-1]):;
- !!MA:Pyi/?yi;
- !!en:;
- !!IF:M^Their hit points: %(arr[0]) %(arr[1]) %(arr[2]) %(arr[3]) %(arr[4]) %(arr[5]) %(arr[6]) %(arr[7]) %(arr[8]) %(arr[9])^;
- !?FU(tst_SortByMonHp);
- !#VA(mon1:x) (mon2:x) (state:x) (result:x);
- !!VR(result):S0;
- !!MA:P(mon1)/?(hp1:y);
- !!MA:P(mon2)/?(hp2:y);
- !!if&(hp1)>(hp2):;
- !!VR(result):S1;
- !!el&(hp1)<(hp2):;
- !!VR(result):S-1;
- !!en;