get_angle() in Feature Requests
You often don't care about the angle from one object to another, just the vector.
If you want to make one mob move in the direction of another object (and not just limit the direction to the 8 cardinal directions) you don't need to get angles, just vectors.
// find the vector pointing from mob to some_atom.var/vector/v = vector(mob, some_atom)// make the mob walk in the direction the vector points.walk(mob, v)
If you were to use vectors, additional math would have to be expected internally to handle their processing, since you would basically be adding values within two lists.
And you would still need a get_angle() function to apply to the vectors.
For almost all cases you don't need to know the angle, knowing the vector is sufficient. For the cases where you'd use an angle you typically know it already. To make a projectile move in the direction the mob is facing, you'd know the mob's angle, you don't have to do any work to find it.
It'd take more work but it'd be worthwhile. Vectors have a lot of uses in games. Having built-in support for vectors would greatly improve performance and would make BYOND look more legitimate and appealing to game developers.
I don't see why. Do you have an example?
As I mentioned, a vector is not actually a direction
If you make a game where you click to shoot, you have to calculate the direction between the player and the location clicked. If you are attempting to shoot a fireball from the player to some targeted monster, you would have to calculate the angle between them. If you wanted to update the path of some sort of homing attack, you would want to constantly update the angle between itself and a potentially moving target on the fly
A vector is a direction and magnitude.
For both of those cases it's easier to use vectors.
It'd work like the example in my last post.
(2,3) is not a direction nor a magnitude.
Assuming that walk() is updated to take a vector as a direction, such angular conversations/calculations would just be getting done internally.
If you just attempted moving some objects by the slope between them, step sizes could be 100 pixels per tick
I would still want an easy way to access the angular data myself, as is provided in Unity's Vectors.
Vector var/x=0,y=0 New(var/x=0,var/y=0) src.Set(x,y) return ..() proc/Set(var/x,var/y) if(!isnull(x)) src.x=x if(!isnull(y)) src.y=y proc/GetAngle() return arctan(src.x,src.y) proc/GetLength() return sqrt(src.x*src.x + src.y*src.y) proc/SetAngle(var/newAngle) var/curLen=src.GetLength() src.x=curLen*cos(newAngle) src.y=curLen*sin(newAngle) proc/SetLength(var/newLen) var/curAngle=src.GetAngle() src.x=newLen*cos(curAngle) src.y=newLen*sin(curAngle) proc/Normalize() var/curLen=src.GetLength() if(curLen) src.x/=curLen src.y/=curLen else src.SetLength(1) proc/Scale(var/scaleBy) src.x*=scaleBy src.y*=scaleBy proc/Output(var/outputTo) outputTo<<"<b>([src.x], [src.y])" outputTo<<"Angle: [src.GetAngle()]" outputTo<<"Length: [src.GetLength()]"
src.x = curLen * cos(newAngle)
SetLength(newLen) var/curLen = GetLength() x = (x / curLen) * newLen y = (y / curLen) * newLen
vector/proc/add(vector/v) x += v.x y += v.y
vector/proc/add(vector/v) return new /vector(x + v.x, y + v.y)
var Vectors/Vec = new()Vectors var list/x = list() list/y = list() list/len = list() proc vec2(u, v) x += u y += v return x.len add(a, b) return vec2(x[a] + x[b], y[a] + y[b])// to run the test you'd do:var/a = Vec.vec2(rand(), rand())var/b = Vec.vec2(rand(), rand())var/c = Vec.add(a, b)
There are two ways to approach it. One way is to make procs that modify the current vector:
It took jt_vectors (which is similar to your approach) 0.120 seconds to do that 500 times while it only took Kaiochao's vectors 0.005 seconds. Another approach I came up with (shown below) took 0.021 seconds.
I was more concerned about the type of proc to implement vs what it actually did. Something like add(v1,v2) & subtract(v1,v2) vs one proc that took an argument for the type of math to perform like VectorMath(v1,v2,ADD)
A. I'm not sure why you consider them similar approaches?
B. I'm not sure where you're getting those numbers
mob/verb/test1() for(var/i = 1 to 500) var/a = new_vec2(rand(), rand()) var/b = new_vec2(rand(), rand()) var/c = vec2_add(a, b)
Of the three methods, you're both using objects to represent vectors.
I made three verbs that each looked like this:
The times were the total CPU times for the calls to the verb.
He isn't? He just has a bunch of global procedures defined, creating a new vector simply returns a list.
Yours is using a single Vector datum to hold a list of every vector in existence, which seems like it would be really awkward in practical use and never free memory.