Jump to content

Question on Events and threads (Papyrus scripting)


PJMail

Recommended Posts

Excellent! More things to trip me up... The 'native but not frame locked' list is very useful - how was it determined? I'm asking because I wonder if it is complete or the result of collective experience so there may be other functions that just weren't tested (I am thinking of the multitude of conditional functions)...
Link to comment
Share on other sites

  • Replies 55
  • Created
  • Last Reply

Top Posters In This Topic

No idea, but based on the qualtiy of the language on the latent functions page it is bound to be incomplete: Latent Functions "If you call one of these functions, you unlock your script so that other waiting calls can now execute "

 

Eh, WTF ? I expect a latent function LOCKS a script so that other waiting calls can NOT execute. Matbe it wants to mean that other waiting SCRIPTS can execute or something.

 

This page is from skyrim so functions may not be 100% accurate, but even so, the language is far more appropriate https://www.creationkit.com/index.php?title=Category:Non-delayed_Native_Function

 

So we have a mix of:

 

Native functions which sync to framerate ("delayed")

Native functions which do not synt to framerate ("non-delayed")

Functions which are latent to hold/lock a script/thread whilst executing

Functions which are not latent to return immediatley

Non native functions which do not sync to the games frame-rate.

 

From this can we infer that Delayed == Latent ? I dont know.

Link to comment
Share on other sites

No idea, but based on the qualtiy of the language on the latent functions page it is bound to be incomplete: Latent Functions "If you call one of these functions, you unlock your script so that other waiting calls can now execute "

 

Eh, WTF ? I expect a latent function LOCKS a script so that other waiting calls can NOT execute. Matbe it wants to mean that other waiting SCRIPTS can execute or something.

 

This page is from skyrim so functions may not be 100% accurate, but even so, the language is far more appropriate https://www.creationkit.com/index.php?title=Category:Non-delayed_Native_Function

 

So we have a mix of:

 

Native functions which sync to framerate ("delayed")

Native functions which do not synt to framerate ("non-delayed")

Functions which are latent to hold/lock a script/thread whilst executing

Functions which are not latent to return immediatley

Non native functions which do not sync to the games frame-rate.

 

From this can we infer that Delayed == Latent ? I dont know.

 

From F4SE code I can see only 2 types of native functions - Wait/NoWait (or Latent/NonLatent). It is the same flag named differently in different implementations. See NoWait flag and isLatent flag

As I understand this flag means that if native function is marked as NoWait (I use this version of F4SE) then returning from this function call (from Papyrus script point of view) will not be postponed to the next frame.

I see nothing about locking or not locking of executing Papyrus script that calling native function. I mean that "latent" is not related to script "locking".

I don't know exactly about "locking" of script but assumption that script is always "not locked" during call of native function seems reasonable for me - the approach when script is "unlocked" for usage by other "thread" looks like cooperative multi-tasking implementation. Probably, calls of NoWait functions does not release lock of script, but it need to be proved.

 

So I guess statement "Delayed == Latent" is near to be truth. I haven't proof of that, but we need to understand that it is the problem of terminology, not behavior. I would rephrase it as "Latent function can be delayed"

 

P.S. It looks like that word "thread" used in CK documentation is wrong. The thing named "thread" in docs should be named "task".

Edited by DlinnyLag
Link to comment
Share on other sites

"Non-native" functions have been mentioned a lot but not defined. I have searched the existing documentation and references and found nothing.

Any examples of a "non-native" function?

 

And you suggest Delayed == Latent so that would suggest that a function that is not Latent is non-delayed - yet there are a large number of functions that are not listed as latent yet are also not listed as non-delayed. Which one are they then?

 

This is my fundamental question as I would like to know which functions 'allow' other threads (tasks?) to 'slip in' and execute another (or same) part of the script.

 

A function that 'waits' for an event (animation completion, timer, etc) is obviously a place where that happens.

 

However, If a function's return is 'delayed' until the next frame then I would assume that is also where other threads get a chance to slip in (cooperative multitasking)?

 

So (referring to SKK's script) Utility.RandomInt() should be considered as 'Delayed' (waits for next frame) and 'Latent' (allows other threads/tasks to execute before it returns)... I also assume it is 'native' (not knowing what that actually means).

 

If 'blocking' actually happens then surely it is not at a script level, but at the 'object instance & script'. 2 actors using the same script (from the same base form) obviously don't block each others script. And what happens if an Actor has multiple scripts attached? Do each of those scripts have their own thread (from a blocking point of view?).

Edited by PJMail
Link to comment
Share on other sites

Preliminary tests show that the suggestion by SKK (Latent == delayed) seems correct, but not the reverse.

I have found examples where Delayed != Latent.

 

Also Contrary to the FO4 doco - Enable() (and I assume disable()) is Latent and Delayed (not non-delayed as documented)

While EnableNoWait() is Non-delayed and NOT latent.

 

Also the examples imply that SetValue is latent (will unblock the script) but it does not (but it is non-delayed).

I suspect they were really talking about another script could get in and change the global - perhaps...

 

And - unfortunately for me - everything else (including conditional functions) is delayed...

Morever, they are Delayed & NOT latent (the worst option) - suggesting that Delayed does not imply Latent...

 

I trigger 2 timers close to simultaneously In the same script) , each running the same loop 300 times (with the tested function in the loop) and a trace every 60 iterations. No other functions in the loop apart from trace (which is supposed to be not latent and non-delayed).

I also have them increment a common variable, and this increases at ~ double the rate - suggesting both loops are not blocked between executions of the trace function.

 

Enable() generates an interleaved log (at 12 interations/second per timer)

EnableNowait() generates a complete log from timer 1 followed by a complete log of timer 2, both at 180 iterations/second.

Is3Dloaded() generates 2 sequential logs as well, but at 12 iterations/second.

 

Yes, I am running this on a potato...

Edited by PJMail
Link to comment
Share on other sites

Any examples of a "non-native" function?

 

Any function that hasn't native flag

 

I would like to know which functions 'allow' other threads (tasks?) to 'slip in' and execute another (or same) part of the script.

In my previous message I explained my assumption that calls of any native function (except, maybe NoWait) will allow other wating tasks to execute "this" script.

So calls of any function (still not sure about NoWait) outside of "this" script, native or non-native, unlocks "this" script.

SK docs has list of built-in NoWait functions. But I can't fully trust these docs %)

 

The reason why I name "non-delayed" functions from link above as NoWait function - doc and code

 

Regarding to statement from docs:

Note that if a function in this list is also latent, then it will still take time to execute, but it will dispatch immediately.

 

I can not trust this documentation.

Edited by DlinnyLag
Link to comment
Share on other sites

Ahh - so Non-native really just means user written functions?

 

yes %)

 

And from my tests it seems conditional (native) functions (which are not 'nowait' - like is3dloaded) do NOT allow waiting tasks to execute in this script.

 

And this is strange. Docs says nothing about what flags has is3dloaded function.

If my assuptions above are correct, then this might mean that is3dloaded is executed very long time...

Probably, it internally (not like other functions) wait for the next frame to obtain actual information about 3D model, but marked with NoWait flag.

Another hypothesis - as you might know time slot allocated for scripts execution is limited. Probably is3dloaded is NoWait and executed too long so exceed this limit. And engine decied to continue this task on the next frame. But I don't know how limit exceeding is tested in engine.

Edited by DlinnyLag
Link to comment
Share on other sites

I guess I've found answers what are latent/non-latent and delayed/non-delayed functions

 

Lets look to the code in F4SE

 

We can see, for example, function Set that is marked as NoWait

But in same time we can name it latent, as it enqueue some internal function execution, instead of immediate execution.

 

There are still question about how exacly control returned to the script code after calling latent + NoWait function.

When internal function is enqueued then calling stackId is stored, so it is possible to use it for returnng control to script's code.

 

So finally:

non-latent + non-delayed - does not release script's lock on call. Executed immediately. Can return some result back to script "immediately" (quotes because I don't know how scripts execution time limits checks are implemented). Can be called (and will be executed) at same time from multiple scripts.

non-latent + delayed- releases script's lock on call. Executed on the next frame. Can return some result to the script.

latent + non-delayed - does not release script's lock on call. Execution is postponed, probably to the next frame or later. Can return some result back to script. Lock remain on script until postponed function is not finished.

latent + delayed - releases script's lock on call. Execution is postponed, probably to the next frame or later. As I understand, it is not supposed to use this type of functions to return some result back to script.

Edited by DlinnyLag
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...