wiremod / wire

Garry's Mod add-on that allows users to wire up components in order to make more elaborate automatic and user-controlled contraptions.
http://www.wiremod.com
Apache License 2.0
547 stars 332 forks source link

Optimize overlay visibility logic #3084

Closed thecraftianman closed 3 weeks ago

thecraftianman commented 1 month ago

When many entities derived from base_wire_entity exist at once, they all separately (and continuously) perform their own logic to test if the overlay should be visible or not, which can have a pretty notable performance impact clientside. This PR combines all of these potential calls into a single Think hook, which is way faster.

Here's a comparison between having 93 base_wire_entity-derived entities out before and after measured over 20 seconds for this logic:

image45 image46

thegrb93 commented 1 month ago

I think the PlayerWasLookingAtMe var won't ever be updated to false with this change. Need to check that, and check that overlay text/data is updating correctly.

thecraftianman commented 1 month ago

PlayerWasLookingAtMe gets updated to false during the looked_at:BeingLookedAtByLocalPlayer() call that occurs when looking away from the entity at something else. I did just find that it isn't properly adjusted when looking between two Wire entities, though, so I'm fixing that now.

I've tested this with multiple entities that update their own overlay text, and everything appears to still function as expected.

thegrb93 commented 1 month ago

Will check it out in a bit