itec
Joined: 10 Feb 2006 Posts: 35 Location: Finland
|
Posted: Wed Apr 30, 2008 3:17 pm Post subject: Coordinates |
|
|
Here's a topic that I think would need some improvement. Current habit is to use coordinates in four different variables. Instead of that, I suggest everyone to start using coordinates in a struct: {x, y, z, realm} It's more easy to use (takes less time writing), simpler, cleaner. In the end, it would be best if core functions would also act like this, ie:
PlayMovingEffectXYZ( srcloc, dstloc, effect, speed, loop, explode)
instead of:
PlayMovingEffectXYZ( srcx, srcy, srcz, dstx, dsty, dstz, effect, speed, loop, explode, realm )
Quiet a bit neater, eh? Also if we add little bit of polymorphism-like support, you could use UObjects as the first two parameters as well.
To start with, here's a few simple functions.
| Code: |
/*
GetCoords
Takes objects location and sets it in a struct.
Returns: struct with x, y, z, and realm.
*/
function GetCoords( object )
return struct{"x" := object.x, "y" := object.y, "z" := object.z, "realm" := object.realm };
endfunction
/*
NewCoords
Easy way to create Coordinate Struct
Returns: coordinate struct
*/
function NewCoords( x, y, z := 0, realm := _DEFAULT_REALM )
return struct{"x" := x, "y" := y, "z" := z, "realm" := realm};
endfunction
/*
SameCoords
To check if two set of coordinates match.
For example, can be used to check if mobile has moved.
Returns:
1 if same
0 if different
*/
function SameCoords( first, second )
return (
first.x == second.x &&
first.y == second.y &&
first.z == second.z &&
first.realm == second.realm
);
endfunction
|
Best part is, in many situations UObject is compatible with the Coords Struct. |
|