EXTRA: Subthreads - Sairion350/OStim GitHub Wiki
Written by Sairion
A very important part of ostim's API for me has been ease and speed of writing addon content for it, often that has meant cutting out rarely used features that would complicate the code (4 person scenes??).
OStim being single-scene only has meant that many tricks and other shortcuts could be used in addon code that would not be possible if we had to manage multiple threads. However, even though they are uncommon there is a need for running 2 scenes at once.
My compromise between keeping addon development simple and having this as a feature is subthreads.
Subthreads are simplified versions of OStim's main thread. They do not fire events, and you can't really interact with them. They're basically invisible to addons, so that we don't have to write extra code for them. This does mean that things like ocum cum, impregnation, etc will not happen in these subthread scenes, however, these subthread scenes will also be rare and only happen when a full OStim thread is running.
Unique subthread features:
- Can link them to the main thread, and they will end when it does, and try to keep speed in sync
- Automatically converts the main thread to a subthread if you need to use the main thread for something but want the current scene to continue
- high performance, supports 10 scenes by default but can be raised to 50
As an example of main thread conversion, ONights will still start full OStim scenes. However, if I start an ORomance scene while that one is running, the ONights thread will 'transform' into a subthread to allow the player's more prominent scene to be a full thread.
As for linking, suppose you and your followers get attacked by bandits and a scene starts, you can put the followers in scenes and link those scenes to main so they all end at the same time
A few more dev notes:
- If your addon focuses only on scenes with the player in them, you don't even have to look at this code. Subthreads only become a necessity when npc scenes are added to the equation
- You should never put the player in a subthread
- if your addon is like ocum in that it makes changes to ALL scenes, don't worry too much. Subthreads will always be in the distant background, and the player will almost always be in their own scene, so they won't notice/care about the missing effects (in theory)
- When a main thread converts to a subthread, ostim_end will fire. This is because ostim's thread is stopped, while osa's continues
Existing code does not need to be changed. As far as when you should manually start subthreads goes, not too often. Only if you know for certain 2 scenes will be running at once. NPC on NPC threads should still go in the main thread; if the player starts a scene ostim will automatically convert that to a subthread