First of all big thanks to Andrey for another donation!
всегда с интересом читаю твои статьи
wbr, f0rt
Большое спасибо, Андрей!
Today I’m going to share a couple of array functions I made (maybe not in the same post). I briefly looked through available BIS functions and haven’t found one that can reverse array so here it is, KK_fnc_arrayReverse:
The algorithm is pretty simple, take one element from the beginning and one from the end of array and swap them around, then take the 2nd element and the penultimate element and swap them around and so forth until you reach the middle of array. Because of this you only need to iterate through half of the array which should give boost in performance. I tested this on 10 element array, it took the function 0.089 ms, 20 elements took 0.16 ms for example. Since for [{},{},{}] do {} construct allows for some extended evaluation control, in the end it comes out pretty neat. It can even be ported to C++ with ease, let’s see if I can convince BIS people to add a dedicated command for array reversing. Examples of use:
As you have noticed, by default the original array will get modified. If you don’t want this, pass a copy of original array rather than its reference (+ operator):
Just thought of another very simple function, while typing this, which might be somewhat useful, KK_fnc_XYZtoXZY:
positionCameraToWorld for example is in [x,z,y] format, and so are the coordinates in mission.sqm, while everything else seems to be in [x,y,z] format. It is easy to convert it forth and back:
Enjoy,
KK
UPDATE: From today, dedicated command reverse is available on DEV branch. Just to compare, 10 element array is reversed in 0.0027 ms compared to 0.089 ms when done with above SQF function. Thank you, Jan!