The naive approach would be to do collision detection by not just querying the room but also the adjacent rooms, but this does not cover the case that an item might be so large that it passes through multiple rooms.
So we need a different solution.
One would be to dissolve the ownership of items by rooms and have an object which intersects multiple rooms owned by all those rooms. But you might have other reasons for maintaining a 1:n
relationship between rooms and items. In that case you might need a separate linked list of items per room which are in the room but not owned by the room.
Keep in mind that this will create some redundancies in case of collisions which happen on edges. When both A and B are on the edge between the same two rooms, then they will be found in both rooms. So when you check for collisions with A, you will find B twice. So you might want to use a three-step process for collision detection:
- Create a list of potentially colliding items by iterating the "owned" and "inside" lists of all rooms the current item intersects.
- Remove all duplicates from that list.
- Check for collision.
You could combine 1 and 2 by storing the potentially colliding items in a binary tree instead of a list. That allows you to detect duplicates the moment you try to insert them into the tree and discard them.