Fiber confusion (SOLVED?)

About Monkey 2 Forums Monkey 2 Programming Help Fiber confusion (SOLVED?)

This topic contains 3 replies, has 3 voices, and was last updated by  cocon 1 year, 12 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #7945

    Hezkore
    Participant

    I’m trying to make a new fiber/thread that keeps going in the background at all times in my game.
    It updates some stuff much faster than the 60 FPS I render in the game.
    But the fiber pauses the game, and I thought that was the whole point of fibers, to not pause the game?
    I’m guessing I’m doing something wrong?

    Here’s some test code, what am I doing wrong?
    Press space to run a fiber and notice the text stops scrolling.

    UPDATE: It seems Fiber.Sleep() pauses the fiber, while Sleep() pauses the whole app!
    I’m still wondering if I’m doing this correctly.

    #7952

    nerobot
    Participant

    UPDATE: It seems Fiber.Sleep() pauses the fiber, while Sleep() pauses the whole app!
    I’m still wondering if I’m doing this correctly.

    You are right – should to use Fiber.Sleep() inside of fiber to sleep it.

    What are you wanna get at the end?

    Monkey2 also has Timer and Future stuff, maybe you need one of them.

    #7956

    Hezkore
    Participant

    My game is a music game, so it has to update the music at all times in the background.
    Correct timing of every note is important!
    So I want a fiber running in the background taking care of all that while the game runs normally.

    I’d like to never force the fiber to sleep, but if I don’t put it to sleep, the game still pauses.

    #7984

    cocon
    Participant

    From Mark’s blog…
    http://monkey2.monkey-x.com/
    “However, unlike real threads, fibers don’t run ‘in parallel’.”

     

    I had tried also some stuff with fibers a while ago and I found that their usage is quite limited, but it’s very specific. From what I found in practical terms, fibers are more useful in event oriented applications (like Ted2Go) where you don’t want your application run in a 60fps loop but neither you want intense loops to freeze your user interface. For example if you have an intense loop, you can throw it in a thread, to let your main app – the gui mostly – be responsive.

     

     

    Generally if your game runs at 60fps you won’t have any problems to use fibers, unless you want to do even more intense calculations (like lightmapping).

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.