let it leave me like a long breath

let it dissipate or fade in the background

coroutines!

Profile

xax: purple-orange {11/3 knotwork star, pointed down (Default)
howling howling howling

Nav

  • Recent Entries
  • Archive
  • Reading
  • Tags
  • Memories
  • Profile

Tags

  • art - 2 uses
  • asteroid garden - 4 uses
  • code - 19 uses
  • demos - 1 use
  • dreams - 5 uses
  • ff7 fangame - 23 uses
  • fic prompts - 13 uses
  • gamedev challenge - 82 uses
  • hell game - 76 uses
  • nanowrimo - 11 uses
  • plants - 9 uses
  • process - 52 uses
  • programming - 51 uses
  • screenshots - 5 uses
  • writing log - 83 uses

May 2025

S M T W T F S
    123
45678 910
1112131415 1617
18192021222324
25262728293031
  • Aug. 15th, 2020
  • xax: purple-orange {11/3 knotwork star, pointed down ({11/3}sided)
    [personal profile] xax
    Tags:
    • gamedev challenge
    posted @ 11:54 pm

    coroutines!

    continuing to try to get back into the 2-week project loop. this time i tried using coroutines. at first i was like "i could probably write my own" and then i was like, wait there's almost certainly a continuations library i could use. there was; i ended up using monad-coroutine, which i chose over Coroutine b/c it had more comprehensible types.

    i'm still not really sure if this was a good or necessary idea -- the goal was to write some code that i could use to do loading / background loading. these days, threads are generally the thing to use to do background loading -- one thread stays busy loading whatever, occasionally writing status messages to some thread-safe variable, and the rest of the program just displays a loading screen with the status messages displayed, waiting for the loading thread to signal that it's done and return all the processed data. rendering stuff complicates this somewhat: opengl has a constraint that only the original thread that initialized the opengl context (as in the rendering window) can perform actions that require the context, which definitely includes buffer allocation and might also include buffer writes.

    coroutines have been kind of popularized recently by go, i think? in that go's 'goroutines' are basically just coroutines baked into the language syntax. previously i knew of them through the classic of duff's device, which is not really a stunning endorcement of the concept. a coroutine is a pair of functions that return to each other, basically-- one function can yield, at which point the other function resumes where it was when it called, and then later on the other function can yield to allow the first function to resume. this isn't implemented through actual 'return' statements. but a timing-based coroutine -- calculate through this data, yielding a partial message when out of time, and resuming with a new quota of time -- is something that can be used to run loading screens, and it can run in the same thread so i don't have to worry about opengl weirdness.

    that being said, i don't actually know if this is a great solution: this coroutine library might be threaded anyway; the opengl restriction might not involve buffer writes; the opengl restriction is about OS-level threads and haskell 'threads' might not actually fork the real OS-level process. but this is something i know how to do and use, so i guess i'll use it.

    anyway i wrote the infrastructure so that i could fairly easily write a fold/accum function and then lift it up to run through a timed coroutine, outputting partial results as necessary, which was neat, but then i got bogged down in the actual thing i wanted it to do: load and unload map chunks in a priority queue based on distance from the player character. that was a lot more involved problem than just writing some timing infrastructure, so i kinda hit that and didn't really get anywhere.

    oh well that's how it goes sometimes. this code will still be around when i have some other stuff to load, i guess.


    • Previous Entry
    • Add Memory
    • Share This Entry
    • Next Entry
    • Reply
Page generated Feb. 9th, 2026 03:36 am
Powered by Dreamwidth Studios

Style Credit

  • Style: (No Theme) for vertical