The perennial thorn in my side when dealing with Gargoyle is the complexity of the text buffer code. The redraw function alone consists of more than 300 lines of fairly dense code, most of which was hacked in after the fact to fix bugs and support new features like hyperlinks and text selection.
At a more fundamental level, the issue is that the buffer stores output as a series of discrete characters, written one at a time. Contextual information, such as whether the character is part of a word, sentence, or paragraph, is essentially discarded. This simplifies reflow and redraw operations, as you can break the character stream into lines of convenient length and iterate through those lines to display as needed. But it makes it rather complicated to style any unit larger than a character.
Even now there are some Glk styles that Gargoyle doesn’t implement: indentation and justification. Adjustable font sizes would be prohibitively complex to add to the current system; everything is built on the assumption that the buffer has a set number of lines with a fixed height and variable width.
The situation is about to get a lot worse; Glk CSS will add more ways to style spans of text, more ways to alter font attributes. It also provides no equivalent to the measure and distinguish functions, so there’s no nice way for Gargoyle to tell games that some styles just won’t work. Realistically, this was never more than a salve to my conscience, as game authors were unlikely to work around Gargoyle’s limits, but it did let me feel better about those limits.
In a sense, the situation is already worse. I’ve committed to adding support for HTML TADS in Gargoyle, which is a significant undertaking in its own right. Trying to implement a markup language with no structural sense of what is being marked up would be messy. Trying to maintain it would be a nightmare.
I don’t like to rewrite code. It’s hard to distinguish the legitimate special cases from the ugly workarounds, and the inevitable result is hours of testing just to get back to square one. Despite my remarks above, the text buffer code works well for hundreds of games and thousands of players. The overwhelming majority of text displayed on the screen is written to a buffer. In a real sense it is the face of Gargoyle, and any significant change risks giving it a black eye.
But I’ve reached a point where either I do the rewrite or I walk away. For a while, I was leaning toward the latter. With the occasional cherished exception, work on Gargoyle is thankless community service. It has zero relevance to my career and garners only modest accolades in a scene dominated by artists and technical wizards. Novelty trumps refinement as a cultural value, and nothing I contribute will be essentially unique.
For all that, I find myself gearing up for one more push. Partly because the memory of the last release has faded; partly because of Chris Spiegel’s efforts to get the source code into better shape. Partly because the project offers a lot of intellectual challenges and commensurate personal rewards. Partly because it feels like the right thing to do.