Determining whether an entity is currently in view

Place to get help with not working mods / modding interface.
pindab0ter
Burner Inserter
Burner Inserter
Posts: 9
Joined: Fri Nov 01, 2024 12:27 pm
Contact:

Determining whether an entity is currently in view

Post by pindab0ter »

Is there a way to determine whether an entity is currently being rendered to any player?

I would like to improve the performance of a mod by not processing entities that are not in any view.

The only way I can think of is to check every player, check whether they are in map view, if they are on the right surface, what their zoom level, resolution and display density scale are and then manually calculate whether a given entity should be able to be seen.

This sounds very CPU intensive to do every tick, and doesn't take into account a GUI camera for example.

Doe anyone know of a better way to do this?

Worst case, I'll just check whether any player is in camera view (not map view) on the surface the entity is on, without taking proximity into account.
Natha
Fast Inserter
Fast Inserter
Posts: 233
Joined: Sun Mar 15, 2015 1:48 pm
Contact:

Re: Determining whether an entity is currently in view

Post by Natha »

for display resolution and scale, you have events (search for "display") that you can listen on, thus calculating the "viewport" only during these events and storing it. For the zoom, you could create a custom event that binds to the mouse wheel, but the best approach would be to just assume the farest zoom.

GUI cameras are treated differently but they are mostly static I think. There are several gui element events that may help
Post Reply

Return to “Modding help”