understanding single updates and mutlithreading

Post » Sat Oct 29, 2016 9:07 pm

If I do the following in one script will I get two different update threads running at the same time from the same script?




Registerforsingleupdate(0.75)



Registerforsingleupdate(0.5)




So then



OnUpDate()



debug.messagebox("I just updated!")



endevent




I would see this message once at time intervals of : 0.5, 0.75 1.0, (then 2 messages at 1.5) ?

User avatar
Gavin Roberts
 
Posts: 3335
Joined: Fri Jun 08, 2007 8:14 pm

Post » Sun Oct 30, 2016 1:08 am

Although I haven't tested this myself, this issue is addressed in the documentation:


http://www.creationkit.com/index.php?title=RegisterForSingleUpdate_-_Form


"calling it back to back will result in the second registered update occurring, but not the first"



You would see it once at a time of 0.5.


RegisterForSingleUpdate() does not do intervals. It causes a single event.


RegisterForUpdate() can be used to create intervals; however, it is not recommended, especially "for any value less than a few seconds."


The recommended process is to register for a single update, allow OnUpdate() to complete its processing, and then register for another single update.


This is to avoid the problem of bogging down (and sometimes crashing) the system if your OnUpdate() event takes longer to process than the RegisterForUpdate() time.



Hope this helps,


legume.

User avatar
gemma
 
Posts: 3441
Joined: Tue Jul 25, 2006 7:10 am

Post » Sat Oct 29, 2016 6:26 pm

Thanks legume!


I have been using register for single update for years. In fact one of the original beta testers for the CK told me about this "pit fall" the same week the CK dropped.

So lucky me I was able to avoided a big problem others had to learn the hard way.


What still gives me a headache is the multi-threading. I was wondering how that affected the thought experiment.


I was much more comfortable in a ONE THING HAPPENS AT A TIME programming environment.


In Oblivion I figured out some amazing tricks that can only work in that kind of environment.


Such as moving an invisible dead actor from one combatant to another to do push actor away tricks by putting the token actor at just the right elevation to the target actor in the right FRAME. I could make one actor aikido flip another in Oblivion where the actors ragdoll would tumble feet over head in the air in a very realistic way.


The entire cell of actors could be handled with one token actor because I knew that for that one frame that token actor was where they needed to be and not yanked off by another script before I was done or locked by another thread.



So to be more clear on what I want to do, I have a long calculation (using many stat and condition cheeks) that is done and then applied to the actors stamina each 0.3 second using Reg For Single update.



And as for ALL my mods this has to work the same for all actors not just the player.


Even using a "this much time has passed" modifier in the calculations this still gives me an erratic stamina bar in low frame rate areas. What I am trying to do now is only do the calculation every 2 seconds but apply the running total every 0.3 seconds doing it all in the same script. I can do this by checking the seconds passed and only allowing the calculation every 2 seconds but the stamina change each 0.3.


I was wondering if I could separate the two by shooting them off into two different threads?



But I am starting to realize I should use two separate magic effects for this so that the stamina driver is not dragged down by the calculation script.


I am assuming that even with the two separate threads going, because they are in the same script the stamina driver will still get dragged down anyway by the calculations part.
User avatar
Beast Attire
 
Posts: 3456
Joined: Tue Oct 09, 2007 5:33 am


Return to V - Skyrim