OpenDreamProject / OpenDream

A project for running games made in the DM programming language
MIT License
208 stars 112 forks source link

Slight optimisation in viewer() and oviewer() #1918

Closed TheTyrant25 closed 3 months ago

TheTyrant25 commented 3 months ago

In DreamProcNativeRoot.cs there is a line used in viewer() and oviewer():

if (Math.Abs(centerPos.X - mob.X) <= depth && Math.Abs(centerPos.Y - mob.Y) <= depth && centerPos.Z == mob.Z)

if you have more than one Z level, then more mobs will be outside of the Z level than in it. Therefore, you can slightly speed up the code by having the Z level check run first, and short circuit the rest of the if condition, evaluating it slightly faster:

if (centerPos.Z == mob.Z && Math.Abs(centerPos.X - mob.X) <= depth && Math.Abs(centerPos.Y - mob.Y) <= depth)