Lately I've been working on my network multiplayer game in Python (tile based) and wanted to make networking more efficient, so that player only gets positions of objects in his view (view, just like BYOND's client.view is changeable in my game).
The first thing that came to my mind is to just have double for loop and scan map for objects that are in client's view, but I guess it isn't very efficient method :(
The next method is to divide map by multiple chunks (just like on the screenshot) and send to user info about all new objects and old objects updates (if they moved/ changed) from chucks overlapping client's view (red dotted area). It makes client to get more info than needed but you only need to look for objects in few places. I guess this is the correct approach, but it also gets more compliacated and less efficient if client's view can be changed (i.e from like 11x11 to 31x21 tiles). I wonder if BYOND does use this method and if so, what's the best size of chucks to create?
![](https://i.ibb.co/q9QsM0K/Screenshot-from-2020-08-25-14-15-20.png)
Last method is just to send all events to every client on the map level which is the easiest, but makes client to get a lot of unnecessary packets and also provides opportunity for making cheats (2d equivalents of wallhack... well previous method also does allow that but to much lesser extent).
How does BYOND handle it?
It's common practice to use quadtrees for collision detection. What you're asking for seems conceptually to me like a specialized version of collision detection: each player represents a rectangle on the map that is their viewport, and when an object updates you want a list of viewports it collides with. (Strictly speaking, you'll want a union of the viewports it collided with before updating, and viewports it collides with after updating.)