#Best way to run loops side-by-side with an external game loop

8 messages · Page 1 of 1 (latest)

topaz flint
#

I'm creating an external desktop application (if you're curious: using Wails) to serve as an Helper to play a 2D RPG Game.

The idea is to have some checkboxes and inputs for some numbers, each ui input element will activate/deactivate certain functionalities that helps in a different aspect of the game, for example:

  • Checkbox that activates (in some way I don't know how it works best in go) a loop that sends a specific keyboard button press from time to time
  • A Checkbox paired with an InputText that sets a number that is checked every second in the game and takes a screenshot whenever it reaches it
  • etc...

My question is, as someone 1 day old to the language, how is the best way to go about creating such loops that I will be putting varying functionalities inside that can be "activated"/"deactivated" based on user input?
I understand that I'll have user input boolean and number states that I'll use to control the loops, but I don't know much about how Go works with loops like that.

lapis sapphire
#

this isn't really something that's core to the language, but rather to the calling patterns of the specific graphics library you're using

#

it might be callback-based when it changes, it might want you to have a tight loop that blocks internally, i'm not sure. hopefully their docs can help to explain its expectations of how you consume input.

topaz flint
#

I mean, should I create threads? For example, in elixir there is a whole thing about Agents, Tasks, spawning Processes, etc

#

what kind of pattern I could use in go to have multiple functionalities that runs independently in their own loop and can be turned on/off?

lapis sapphire
#

a trivial method could be to have each handled in its own goroutine, which functions similarly to a thread (but with far less dedicated resource usage, which means you can spawn orders of magnitude more goroutines than you typically would with threads)

wet knoll
#

most heavy client libraries are single threaded

#

the libraries specify which operations can be made from any thread, or from the main thread running the main loop of the library