Is it possible to get all objects of specified type with given range without iterating through all objects in the world?
Get nearest objects
As long as a user does not have at least one reviewed and activated contribution, the user is unable to edit his profile, set a avatar, title picture or a signature.
-
-
Is it possible to get all objects of specified type with given range without iterating through all objects in the world?
To be honest, I don‘t think so. Of couse you are able to minimize the amout of Objects by referring to the Type e.g.:However, I do not know of a more effective approach :confused:
-
Thanks for suggestion, but seems i found a better method:
[ICODE]NetObjectManager.GetObjectsWithin(Vector2 position, float range)[/ICODE]it greatly reduces a number of objects to iterate through
-
Thanks for suggestion, but seems i found a better method:
[ICODE]NetObjectManager.GetObjectsWithin(Vector2 position, float range)[/ICODE]it greatly reduces a number of objects to iterate through
Thanks for suggestion, but seems i found a better method:
[ICODE]NetObjectManager.GetObjectsWithin(Vector2 position, float range)[/ICODE]it greatly reduces a number of objects to iterate through
Take care of using
[ICODE]NetObjectManager.GetObjectsWithin(Vector2 position, float range) [/ICODE]
It iterate on all the objects
Here it's the code of the function, like you can see there is even a commentary saying it's slow to use it.C#public IEnumerable<INetObject> GetObjectsWithin(Vector2 position, float range) { // don't use this, its fairly slow. O(N) return this.objects.Select(pair => pair.Value).OfType<INetObjectPosition>().Where(obj => Vector2.WrappedDistance(obj.Position.XZ, position) <= range).Cast<INetObject>(); }
If you really need to get object inside a radius a lot of time, I think the best solution is to make a dictionary where you store object and the chunk where they are, then you only get the chunk around the position you need to check.
But if you use it less than 1 time/s you can use the same function.
Depending on why you need to do that player will not notice it since it's only server sided. -
Take care of using
[ICODE]NetObjectManager.GetObjectsWithin(Vector2 position, float range) [/ICODE]
It iterate on all the objects
Here it's the code of the function, like you can see there is even a commentary saying it's slow to use it.C#public IEnumerable<INetObject> GetObjectsWithin(Vector2 position, float range) { // don't use this, its fairly slow. O(N) return this.objects.Select(pair => pair.Value).OfType<INetObjectPosition>().Where(obj => Vector2.WrappedDistance(obj.Position.XZ, position) <= range).Cast<INetObject>(); }
If you really need to get object inside a radius a lot of time, I think the best solution is to make a dictionary where you store object and the chunk where they are, then you only get the chunk around the position you need to check.
But if you use it less than 1 time/s you can use the same function.
Depending on why you need to do that player will not notice it since it's only server sided.Yeah i know how it works, just wanted do not do it by myself.
Since GetObjectsOfType is working the same way and i need to get objects in range anyway, don't think there is a shoter way to do this.
Calling this only at OnCreate so i suppose that perfomance is not a problem
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!