For example sake:
- Let's say there are 10 rooms in the world.
- And let's say the world is inhabited by 10 entities.
- And each entity has it's own "daily routine" where it performs certain actions in the room and also might navigate between the rooms as well.
Given that the player can only be in one room at a time, what is a good way to keep track of the actions the other entities are performing in other rooms offscreen?
- The most straightforward option is to check on each of the 10 entities on every frame, check their position/state and determine whether or not the entity should be in the room where player is located in at any given time. ( This however feels really resource heavy especially as the room/entity amount is increased. )
Another option is to keep track of the time that has passed since the start of the game, then each of the entities checks whether its pattern intersects with the room the player is on, and if it does it checks against the time whether or not the entity is supposed to be in the same room at this particular time, entities whose patterns do not intersect with the current room the player is located in do nothing until the player enters a room which their pattern intersects and only at that point calculate whether or not they should render. ( But if they interact with the room, then they will have to always check the state of the rooms which intersect their route in order to determine their location at that point in time, which is not that great. )
The third option I came to would be to first of all only look at the routes which intersect the player location (as described previously), secondly upon entering a room, check if the player is in that room, if not then to only check the state of the room and how long will it take to proceed to the next room. For example a janitor NPC enters the room, checks the state of the room, sees that there is a spillage made by player, calculates how much time it will take to clean that up and how long the pathing will take etc. And until the mentioned time is due to enter the next room we only check if the player is in the room. The exact location of the NPC for rendering purposes would only be calculated when the player enters the room.
After brainstorming a while I came to the third option, but I was wondering if perhaps there is a known or better way to handle things like these?