Longship icon indicating copy to clipboard operation
Longship copied to clipboard

[Optimization] Optimize GetCharactersInRange

Open AlexMog opened this issue 5 years ago • 1 comments

Another instance of #6 but with characters. Again, Bruteforce usage, should use a geohash instead.

Class: Character

public static void GetCharactersInRange(Vector3 point, float radius, List<Character> characters)
	{
		foreach (Character character in m_characters)
		{
			if (Vector3.Distance(character.transform.position, point) < radius)
			{
				characters.Add(character);
			}
		}
	}

AlexMog avatar Feb 20 '21 20:02 AlexMog

Apply the same for

public static bool IsCharacterInRange(Vector3 point, float range)
	{
		foreach (Character character in m_characters)
		{
			if (Vector3.Distance(character.transform.position, point) < range)
			{
				return true;
			}
		}
		return false;
	}

in the same class

AlexMog avatar Feb 20 '21 20:02 AlexMog