Jump to content

What does GameFiber class exactly means?


GodlyDev

Recommended Posts

I'm not  a native "english-user"

So I cant understand what does GameFiber exactly means and how does it works.

I saw it many times in conversation parts, and I wonder why 

GameFiber.yield(100); or GameFiber.sleep(1000); exists..........

 

Can I have specific introduction bout dat?

Link to comment
Share on other sites

  • Management Team
3 hours ago, Lit'Wayne said:

I'm not  a native "english-user"

So I cant understand what does GameFiber exactly means and how does it works.

I saw it many times in conversation parts, and I wonder why 

GameFiber.yield(100); or GameFiber.sleep(1000); exists..........

 

Can I have specific introduction bout dat?

 

A GameFiber is essentially its own thread. Now, why is this important? While GTA V ticks scripts one at a time (so no benefit for multiple threads here), it allows you to use the commands you already mentioned. You can spawn a new GameFiber, have it do something and then wait for 5 seconds before doing something else. This will not interrupt any other fiber or game code and RAGE Plugin Hook will automatically resume the waiting fiber after 5 seconds for you and it will continue execution. So whenever you deal with operations that need to wait or handle blocking resources, using a GameFiber might be a good idea.

 

A word of caution though: For LSPDFR itself we have largely moved away from having many fibers like we used to in previous versions. The reason being that the code is less predictable since the order in which fibers will execute is more or less random and other plugin fibers might run in between. To save resources we like to do a few things only once per tick, which would not be possible if we used many fibers. For instance, at the start of the tick, we invalidate all entities that no longer exist and remove their internal tasks etc. This means that tasks down the road do not have to worry about running on a non-existent entity, saving us some call time as well. If we used fibers for everything like we did before, we would always have to double check. So while fibers provide a lot of benefits and are generally quite lightweight, for large scale projects they can cause more harm than good and should be used with caution.

Please do not PM me unless really necessary (knowing you helps). If you think you need my attention in a topic, tag me.

Link to comment
Share on other sites

1 hour ago, LMS said:

 

A GameFiber is essentially its own thread. Now, why is this important? While GTA V ticks scripts one at a time (so no benefit for multiple threads here), it allows you to use the commands you already mentioned. You can spawn a new GameFiber, have it do something and then wait for 5 seconds before doing something else. This will not interrupt any other fiber or game code and RAGE Plugin Hook will automatically resume the waiting fiber after 5 seconds for you and it will continue execution. So whenever you deal with operations that need to wait or handle blocking resources, using a GameFiber might be a good idea.

 

A word of caution though: For LSPDFR itself we have largely moved away from having many fibers like we used to in previous versions. The reason being that the code is less predictable since the order in which fibers will execute is more or less random and other plugin fibers might run in between. To save resources we like to do a few things only once per tick, which would not be possible if we used many fibers. For instance, at the start of the tick, we invalidate all entities that no longer exist and remove their internal tasks etc. This means that tasks down the road do not have to worry about running on a non-existent entity, saving us some call time as well. If we used fibers for everything like we did before, we would always have to double check. So while fibers provide a lot of benefits and are generally quite lightweight, for large scale projects they can cause more harm than good and should be used with caution.

Tune in tomorrow as LMS solves world hunger and climate change.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...