Fork me on GitHub
Braden Shepherdson21:11:48

a couple of re-frame design questions. I'm implementing a Z-machine, an interpreter for text adventure games, mostly as a learning exercise. I want to write a Gameboy emulator too, partly because I've long wanted to do that, and partly because it would be an interesting performance showcase for CLJS, assuming it's non-terrible.

Braden Shepherdson21:11:52

(1) the Z-machine's view is a stream of text paragraphs, essentially. I want to do infinite scrollback, and not have it re-render old paragraphs of text.

Braden Shepherdson21:11:45

how should I go about rendering that in Reagent without risking whole-document re-rendering?

Braden Shepherdson21:11:46

and (2) the Z-machine is either waiting for a single keystroke, waiting for a line of text, or running opcodes. in that last state, I want to give it a kick every frame, running 100 opcodes and returning a [z-machine new-state] pair. is there a doc on how to do that kind of each-frame polling?


@braden.shepherdson I don’t know I have a good answer for (1) (although I there maybe some stuff to search for online about “infinite scroll” in React that could help) for (2) I don’t know that it solves your problem fully, but do you know about :dispatch-later?

Braden Shepherdson21:11:25

it's also entirely possible that the regular queuing behavior of dispatch would work. that is, I can write a side-effecting event handler that (a) runs the Z-machine a bunch, (b) dispatches the right things based on its final state. and then those newly dispatched events get handled next frame, not synchronously.

Braden Shepherdson21:11:57

unlike a Gameboy, the timing isn't important, it just needs to not hog the CPU.

Braden Shepherdson21:11:05

well, perhaps it's best here to simply be naive and see if I get good behavior out of the box.

Braden Shepherdson21:11:13

for (1) and (2), actually.


@braden.shepherdson For a totally naive way of solving (1), you could store you entire text history as a vector and have your subscription return something like (take-last 10 text-lines) or use subvec to have a scrolling window


@braden.shepherdson “cpu hogging” reminded me of - which perhaps has some usefulness to you if you haven’t read it