Original Post
Frist of all, hi to all since this is my first post. Also, just say that I am a newbie , so apologize if my questions are to trivial. Of course, I have searched trough the forums with no success.
My question is the following. I have been reading about multithreaded engines, where, for instance, the physics subsystem run in its own thread, the AI in its own and so on, sound, input etc... As far as i understand, if a ray must be thrown in order to detect som ray intersection (for instance, firing a weapon, or checking an enemy if the player is in its line of sight), this ray casting operation is performed by the physics subsystem. Since the different subsystems, I assume they run asynchronously, what happens if an agent in the AI subsystem (for instance, an enemy that wants to check if the player is in its line of sight) by casting a ray? How this operation if performed since it has to be done by the physics subsystem which is running asyncrhonously? I have thought in three possible solutions, if any applies:
- Using an event system to communicate between subsystems. In this case, the enemy in the AI would send a ray cast event, which will be captured by the physics subsystem. The physics subsystem, at some point, will catch the event, process it, and if the intersection exists with the player, send a new event to the AI subsystem so the enemy can change its state and react.
- Calling directly the ray cast through the physics subsystem, and usign locks to avoid data corruption?
- Having a local view of the world in the AI system, which is periodically updated when receiving events, and having a local ray cast operation in the AI subsystem?
Which is the best solution if is one of those, or if not, how should be done.
Thank you very much,
Arnau.
My question is the following. I have been reading about multithreaded engines, where, for instance, the physics subsystem run in its own thread, the AI in its own and so on, sound, input etc... As far as i understand, if a ray must be thrown in order to detect som ray intersection (for instance, firing a weapon, or checking an enemy if the player is in its line of sight), this ray casting operation is performed by the physics subsystem. Since the different subsystems, I assume they run asynchronously, what happens if an agent in the AI subsystem (for instance, an enemy that wants to check if the player is in its line of sight) by casting a ray? How this operation if performed since it has to be done by the physics subsystem which is running asyncrhonously? I have thought in three possible solutions, if any applies:
- Using an event system to communicate between subsystems. In this case, the enemy in the AI would send a ray cast event, which will be captured by the physics subsystem. The physics subsystem, at some point, will catch the event, process it, and if the intersection exists with the player, send a new event to the AI subsystem so the enemy can change its state and react.
- Calling directly the ray cast through the physics subsystem, and usign locks to avoid data corruption?
- Having a local view of the world in the AI system, which is periodically updated when receiving events, and having a local ray cast operation in the AI subsystem?
Which is the best solution if is one of those, or if not, how should be done.
Thank you very much,
Arnau.