Impulses

From Resonite Wiki
Revision as of 23:16, 3 February 2024 by 989onan (talk | contribs) (Create some info on impulses and their concept)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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


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 have data associated with them. This data includes

  • The user who sent the impulse, which can be read via a Local User Node.
  • 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.

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 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.

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

ASync

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 Delays, Cloud variable nodes, and 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.

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.