Imagine having a big room (4000w x 4000h) which contains players and items (world objects). The room is spatially partitioned in a 10 x 10 grid for collision detection and changes in the viewport of the player.
- Green rectangle: Item
- Red rectangle: Player viewport
At the moment, on the server, every player contains a list of all world objects in his current viewport. When the player changes his position, new items are found in the viewport, compared with his current list of visible objects and the changes are send to the client. His current visible list is updated with the new found objects
HashSet<WorldObject> changes = new HashSet<>(foundObjects); changes.removeAll(player.getVisibleObjects());
The client maintains a list of all entities that it has seen, renders them in the world and waits for new input.
Now my problem arise when another player picks up an item, it notifies the surrounding players, update the local list of items accordingly and stops rendering the item. This works fine. But players outside the viewport are not notified about these changes, so once they are in the grid, they will still see the item being rendered.
How are these kind of problems commonly solved? Is my approach good?