[–] 3 points 1 day ago

In my first game Boohu, my game loop was messy, with game logic interleaved with drawing, but my later games Harmonist and Shamogu use Gruid's Update/Draw loop attached to a model (containing state), inspired from Elm's architecture and bubbletea's, but a bit less "functional-style" to adapt it to a grid-based roguelike needs.

The Update method is called with an input message each time there's an incoming one. It updates the state of the game, and it may return one or more Effect values. Effects are functions that are run asynchronously on a goroutine, and may send one or more custom messages to the Update game loop. This is useful for extra messages beyond the basic ones for input events from the backend (SDL, terminal or js/wasm). For example, I use it for interruptable animations, to send "next animation frame" messages at appropriate times, with a number identifier that ties them to a particular animation, so that they may be ignored if that animation has been interrupted (by a keypress or some other action).

The Draw method is called after every Update and returns a grid of cells with color, letter (possibly represented by a tile), and attributes (possibly custom ones). The grid is typically cached, though a new one can be returned in a kinda functional way. Gruid then sends the grid to the backend for screen drawing and to the replay recorder, but it only sends the grid changes from previous frame, not the whole grid (unless screen was exposed). That system means that, following the spirit of typical terminal applications, when the game is idle with no animations going on, no drawing happens and the cpu is idle. This is nice, because typically animations are pretty short, so having a drawing function getting called all the time even when nothing changed would've been wasteful.

Both Update and Draw dispatch to different code paths depending on the model's state (typically to distinguish between map mode, inventory mode, new game screen, and so on).

  • source
  • [–] 1 point 1 week ago

    I've written all my three roguelikes in Go. Mostly because I was already familiar with Go and had enjoyed it for a non-roguelike project previously (a markup language). Certainly not because Go libraries for roguelikes were good at the time, they weren't!

    For my first game, Boohu, due to the lack of any decent libraries for Go roguelikes at the time, I wrote from scratch most logic, using the termbox-go and then tcell terminal packages for UI, and later with alternate wasm and Tcl/Tk backends for tiles. The code ended up kind of messy in many places, being my first roguelike and all and having to roll my own stuff for everything, looking at roguelikedev and roguebasin articles, with no gamedev experience at all. That's in part why that game is basically just in maintenance mode now (but I made it work with Tcl/Tk 9 recently by forking and porting the unmaintained "gothic" Go bindings for Tcl/Tk 8.6).

    After some early releases of Harmonist, I started working on Gruid, a Go roguelike framework, taking some ideas from the Elm Architecture and Go's bubbletea tui package, with extra pathfinding and mapgen packages (partly based on Harmonist and Boohu's code), and support for terminal, SDL (2 or 3), and wasm backends. And record/replay functionality that results in compact files and that works accross backends, as in "play in ascii in terminal, then watch in tiles in SDL": definitely one of the things I'm particularly happy with!

    I then ported Harmonist's code with some effort to use Gruid, and even had Boohu use it for pathfinding (but not UI, as Boohu's UI code would sadly need a boring complete rewrite). Shamogu is the first game I wrote with Gruid from the beginning, and it felt very nice, so that's the one I'd currently suggest looking at for anyone wanting to write a roguelike in Go.

    Also worth noting that earlier this year I rolled my own SDL2 minimal bindings, based on the veandco/go-sdl2 ones but cutting code size by an order of magnitude. That made it easy to port them to SDL3, too, and much faster to build than the full ones they're based on.

    Which chains with another thing I'm pretty happy with Gruid, which is that there are few external dependencies outside of standard library: just the SDL 2 or 3 shared libraries for the native graphical build, tcell for the terminal build, and no dependencies at all for the wasm one.

  • source
  • [–] 3 points 1 week ago

    Nice to see FAQ Fridays getting revived here, thanks for your efforts! Back then, I started participating around the #20s of the revisited ones, so I never answered this one.

    I don't use many tools actually, so it's kind of a short answer: basically just vim for writing code, git for versioning, and a Tcl/Tk script named drawtile for drawing monochromatic 16x24 tiles. If counting more secondary tools, I'd mention ripgrep and fzf, which I use occasionally.

    BTW, I did miss the first friday of the revival, but I might comment there later.

  • source