AlexMog / Longship

Valheim Dedicated server Fixes, Optimizations and High-Level API
MIT License
29 stars 3 forks source link

[Optimization] Optimize FindClosestBeaconInRange #7

Open AlexMog opened 3 years ago

AlexMog commented 3 years ago

Same as #6 but with Beacons.

I'm not sure that code is used frequently, need more investigation.

Class: Beacon

public static Beacon FindClosestBeaconInRange(Vector3 point)
    {
        Beacon beacon = null;
        float num = 999999f;
        foreach (Beacon instance in m_instances)
        {
            float num2 = Vector3.Distance(point, instance.transform.position);
            if (num2 < instance.m_range && (beacon == null || num2 < num))
            {
                beacon = instance;
                num = num2;
            }
        }
        return beacon;
    }