Impulses: Difference between revisions

From Resonite Wiki
Create some info on impulses and their concept
 
put info on their proper pages for variable types
 
(17 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Stub}}
{{Stub}}
See Also: [[Dynamic Impulses]]


== Impulses ==
== Impulses ==
Impulses are a way for ProtoFlux to do actions that happen during a specific time, rather than a continuous per-game-tick basis. They can be considered as a sort of action. When an impulse is triggered it's like an event in a game. When the user hits a button that sends an impulse, when your feet visibly hit the ground, that can send an impulse. When you fill a glass entirely, an impulse can be sent.
Impulses (or Calls) are triggered actions. They normally do not have a duration (unless using Async calls) and happen in a singular instantaneous moment. Some examples of Impulses could be when a user clicks a button, when a user collides with something such as the ground, or when a object gets duplicated.
 
Impulses have some data associated with them. This data includes:
* The user who sent the impulse, which can be read via a [[ProtoFlux:Local User|Local User]] node during the impulse.
* The time of the impulse, read by the [[ProtoFlux:World_Time_Float|WorldTime]] (and similar) nodes.
 
When a ProtoFlux value is connected solely into nodes that receive Impulses, the value is no longer evaluated every game update but only when the node is impulsed. This is useful to optimize performance as instead of doing a constant evaluation, you wait until a Impulse is received to evaluate. A heavy computations which benefits from this approach is [[ProtoFlux:Find_Child_By_Name|FindChildByName]] which searches an entire hierarchy when it is evaluated. In this scenario, the search only has to be done once during the Impulse, and then optionally it can be cached using a Write node.
 
{{Note|Non-Asynchronous Impulse Code can freeze the game engine until the code is finished. This can cause performance issues in certain scenarios like when using loops with lots of iterations, and is why it is recommended to make such lengthy computations Asynchronous so they can be dealt with over a longer time period, and to not evaluate such things constantly.|warning}}


Impulses have data associated with them. This data includes
== Async ==
* The user who sent the impulse, which can be read via a [[ProtoFlux:Local User|Local User]] Node.
Async or Async Impulses are a way to take your code and run it over more than one engine update cycle. Async Impulses are required to run nodes that are in the ProtoFlux Async category as these nodes require a Async Operation to start executing and will often take some time to complete what they do. Nodes like this include but are not limited to [[ProtoFlux:Delay|Delays]], [[:Category:ProtoFlux:Variables:Cloud|Cloud variable nodes]], and [[ProtoFlux:ASync While|ASync Whiles]].  
* The index of the impulse of the total number of impulses sent down the line.
* the start time the impulse was sent.


Think of Impulses as an instant action, that doesn't have a duration, but rather an instant moment in time which all code must run before the next smallest unit of time can happen.
Async is a way in some cases to reduce lag in some code as instead of halting the engine while you do a bunch of work in one update, you can spread the work over time and over multiple updates instead.


When a protoflux value socket is connected solely into nodes that recieve Impulses, the value is no longer calculated every game tick but only when the node is impulsed. This is useful if you want to search the entire root for a slot, but then [[ProtoFlux:Write|Write]] it to a variable to keep it for later. In this scenario, the search only has to be done for one frame, and then the cached value can be used instead. Searching the entire root is extremely costly, but if the value is written and then cached, the performance impact is negligible.
Async however will not completely remove lag from actions done in world. So if you create a massive amount of data that has to be networked all at once, then making the code Async will not always prevent the lag from occurring. Likewise if running Async code constantly it can also cause performance issues.


{{Note|Non Async Impulse Code will freeze the game engine loop until the code is finished. This can cause huge performance issues, and is why it is highly recommended to put large computations on an ASync Thread|danger}}
Async is currently not multi-threaded which is talked about in this video (at 40:00): [https://youtu.be/1losWav_AZQ?t=2392 link to the video at the specified time]


== ASync ==
== Contexts ==
ASync or ASync Impulses are a way to take your code and offload it from the main game engine loop onto a background thread. Asyncs are required to run nodes that require an ASync context. Nodes like this include but are not limited to [[ProtoFlux:Delay|Delays]], [[:Category:ProtoFlux:Variables:Cloud|Cloud variable nodes]], and [[ProtoFlux:ASync While|ASync Whiles]]. Now putting everything on a background thread isn't recommened, but if you have a lot of code that has to run, then it is highly recommened to put it on async.


In an Async, The protoflux is ran in a background thread, which in some cases means it will be able to run on another CPU core, off of the core the main game is running on. If the code is extremely heavy, then the main game in most cases will not reduce in speed or performance. This is useful if you have to calculate 1 million digits of pi, or do a lot of math calculations.
Contexts are a way for ProtoFlux to store a state of local variables in the scope of the executing code. A new context can be created using the [[ProtoFlux:Start_ASync_Task|StartAsyncTask]] node. Variables in the context will still be able to be accessed and read with the same values even if Delays are used. A context can be thought of as what data is available during a certain Impulse.  


ASyncs however will not reduce lag from actions done in world. So if you create a massive amount of data that has to be networked all at once, then putting the code on an ASync will not prevent the lag from occurring.
For variable types, see [[ProtoFlux:Store|Store]], [[ProtoFlux:Local|Local]], and [[ProtoFlux:Data Model Store|Data Model Store]] pages.

Latest revision as of 16:33, 2 April 2024

This article or section is a Stub. You can help the Resonite Wiki by expanding it.


See Also: Dynamic Impulses

Impulses

Impulses (or Calls) are triggered actions. They normally do not have a duration (unless using Async calls) and happen in a singular instantaneous moment. Some examples of Impulses could be when a user clicks a button, when a user collides with something such as the ground, or when a object gets duplicated.

Impulses have some data associated with them. This data includes:

  • The user who sent the impulse, which can be read via a Local User node during the impulse.
  • The time of the impulse, read by the WorldTime (and similar) nodes.

When a ProtoFlux value is connected solely into nodes that receive Impulses, the value is no longer evaluated every game update but only when the node is impulsed. This is useful to optimize performance as instead of doing a constant evaluation, you wait until a Impulse is received to evaluate. A heavy computations which benefits from this approach is FindChildByName which searches an entire hierarchy when it is evaluated. In this scenario, the search only has to be done once during the Impulse, and then optionally it can be cached using a Write node.

Non-Asynchronous Impulse Code can freeze the game engine until the code is finished. This can cause performance issues in certain scenarios like when using loops with lots of iterations, and is why it is recommended to make such lengthy computations Asynchronous so they can be dealt with over a longer time period, and to not evaluate such things constantly.

Async

Async or Async Impulses are a way to take your code and run it over more than one engine update cycle. Async Impulses are required to run nodes that are in the ProtoFlux Async category as these nodes require a Async Operation to start executing and will often take some time to complete what they do. Nodes like this include but are not limited to Delays, Cloud variable nodes, and ASync Whiles.

Async is a way in some cases to reduce lag in some code as instead of halting the engine while you do a bunch of work in one update, you can spread the work over time and over multiple updates instead.

Async however will not completely remove lag from actions done in world. So if you create a massive amount of data that has to be networked all at once, then making the code Async will not always prevent the lag from occurring. Likewise if running Async code constantly it can also cause performance issues.

Async is currently not multi-threaded which is talked about in this video (at 40:00): link to the video at the specified time

Contexts

Contexts are a way for ProtoFlux to store a state of local variables in the scope of the executing code. A new context can be created using the StartAsyncTask node. Variables in the context will still be able to be accessed and read with the same values even if Delays are used. A context can be thought of as what data is available during a certain Impulse.

For variable types, see Store, Local, and Data Model Store pages.