16.06.2016, 13:17
The most common structure you use in SA-MP is a position (or a vector) Float:X, Float:Y, Float:Z. Now, all functions like SetPlayerPos and GetPlayerPos use the parameter way of accepting and returning (via by-ref parameters) this structure, but is there a better way?
It's occured to me during the writing of i_quat that I needed a function to return a quaternion (consisting of 4 Float numbers). Now I had multiple methods of returning this:
Which of these three methods you think is the best? The first method has the advantage of choosing a destination you wish for all returned values, be it a quadruple of variables or an array indices, but it's too long if you use it regularly. The second method is shorter and faster to use, but you have to remember which index means what (e.g. if it's WXYZ or XYZW). The third one can be used to easily pass its return to another function, but if you already have an array allocated for the return, it does another needless allocation. And you still cannot use the return like new Float:quat[4] = ReturnQuat();, because the expression has to be constant.
Which of these ways is the best one? I want my script to use standardized and most useful conventions for handling this.
It's occured to me during the writing of i_quat that I needed a function to return a quaternion (consisting of 4 Float numbers). Now I had multiple methods of returning this:
Code:
stock ReturnQuat(&Float:w, &Float:x, &Float:y, &Float:z) stock ReturnQuat(Float:quat[4]) quat[0] = w, quat[1] = x //etc. stock ReturnQuat() { Float:quat[4]; ... return quat; }
Which of these ways is the best one? I want my script to use standardized and most useful conventions for handling this.