EndBASIC 0.14: Are we multimedia yet?
EndBASIC 0.14: Are we multimedia yet?
EndBASIC 0.14:我们实现多媒体了吗?
Just a little over a month ago, I was announcing EndBASIC 0.13 with a brand new compiler and VM implementation. 0.13 was the result of six months of work and I had to “flush those out” to clear my mind. At the end of the day, however, 0.13 “just” improved performance. Yes, the wins were massive, but they didn’t do much to make EndBASIC any cooler for you. 就在一个多月前,我发布了带有全新编译器和虚拟机实现的 EndBASIC 0.13。0.13 是我六个月工作的结晶,我必须将其“发布出来”以清空思绪。然而归根结底,0.13 “仅仅”是提升了性能。没错,性能提升非常巨大,但对于让 EndBASIC 变得更酷这件事来说,并没有太大帮助。
Today’s 0.14 is a different beast. This shiny release is a collection of new features all over the place with the special addition of basic sound support. Specifically because of the latter, 0.14 marks a major milestone because it unlocks the last frontier towards a possible 1.0. There are many more things I wanted to include in this release—and one feature I had to eventually give up on due to its difficulty—but at some point one has to stop and get the code out. So here we are! 今天的 0.14 则完全不同。这个闪亮的新版本汇集了各方面的功能,并特别增加了基础的声音支持。正是因为后者,0.14 成为一个重要的里程碑,因为它攻克了迈向 1.0 版本前的最后一道难关。我原本还想在这个版本中加入更多功能——其中一个功能因为难度太大最终不得不放弃——但人总得在某个节点停下来发布代码。所以,我们现在就发布了!
There is a lot to talk about, but before we get to that, here are the must-visit links: 有很多内容要聊,但在开始之前,请务必访问以下链接:
- Launch the online interpreter
- 启动在线解释器
- Download for desktop and embedded devices
- 下载桌面版和嵌入式设备版
- Read the release notes
- 阅读发布说明
- Visit the interactive projects gallery
- 访问交互式项目库
Graphics, more graphics!
图形,更多的图形!
The primary thing I wanted to do after the large performance wins brought by 0.13 was to offer extra graphics primitives to let the extra performance shine. We now have commands to draw triangles (GFX_TRI and GFX_TRIF), polygons (GFX_POLY and GFX_POLYF), and to bucket-fill an area (GFX_FILL). 在 0.13 带来巨大的性能提升后,我最想做的事情就是提供额外的图形原语,让这些性能优势得以发挥。我们现在有了绘制三角形(GFX_TRI 和 GFX_TRIF)、多边形(GFX_POLY 和 GFX_POLYF)以及区域填充(GFX_FILL)的命令。
As part of this work, I “productionized” one of the very first demos I wrote for EndBASIC—a little program that renders a number of circles and makes them bounce within a container box—to demonstrate the new graphics primitives. This demo is now bundled within EndBASIC’s DEMOS drive and accessible via the gallery. You can witness it below, and beware that this is a real-time running program, not a video! You can interact with it right here, in the browser. 作为这项工作的一部分,我将我为 EndBASIC 编写的最早的演示程序之一进行了“产品化”——这是一个渲染多个圆并在容器框内反弹的小程序——用以展示新的图形原语。该演示现在已捆绑在 EndBASIC 的 DEMOS 驱动器中,并可通过项目库访问。你可以在下方看到它,请注意这是一个实时运行的程序,而不是视频!你可以在浏览器中直接与它交互。
Retro VGA, anyone?
有人想要复古 VGA 风格吗?
Back when I added support for LCD displays and the NetBSD-backed console for the EndBOX, I had to implement a bitmap font rendering “engine” for framebuffers. While this was cool, it also introduced inconsistencies with the web and SDL consoles, which relied on the IBM Plex Mono TTF font. This font looked nice and was inspired by old PC fonts, but it was still too… “modern”. 当初我为 EndBOX 添加 LCD 显示支持和基于 NetBSD 的控制台时,我不得不为帧缓冲区实现一个位图字体渲染“引擎”。虽然这很酷,但也导致了与依赖 IBM Plex Mono TTF 字体的 Web 和 SDL 控制台之间的不一致。这种字体看起来不错,灵感也来自旧式 PC 字体,但它仍然太……“现代”了。
So, to unify the look and feel of all consoles, and to make EndBASIC look more “retro”, I yanked all TTF support and instead switched to using my own font rendering facilities. As part of this, I added the standard IBM VGA 8x16 font to the fonts collection and made it the default across all consoles. 因此,为了统一所有控制台的外观和感觉,并使 EndBASIC 看起来更“复古”,我移除了所有 TTF 支持,转而使用我自己的字体渲染设施。作为此举的一部分,我将标准的 IBM VGA 8x16 字体添加到了字体集合中,并将其设为所有控制台的默认字体。
This makes the console look retro, but also dull, and if you launch EndBASIC for the first time, you might never imagine that its console can mix text and graphics. So to make it clear from the get go that the console is hybrid, I’ve also modified the welcome banner, which had remained unmodified for years, so that it displays a little icon next to it. Here, take a peek! 这让控制台看起来很复古,但也显得有些沉闷。如果你第一次启动 EndBASIC,你可能根本想不到它的控制台可以混合显示文本和图形。因此,为了从一开始就明确控制台是混合模式的,我还修改了多年未变的欢迎横幅,在旁边添加了一个小图标。来,看一眼!
macOS, finally fixed
macOS,终于修复了
The SDL graphical console in EndBASIC has been around for years now, and when I originally wrote the code, it worked correctly on macOS. Unfortunately, while my original implementation offloaded all graphics operations to a separate thread, it had a critical flaw: that separate thread was not the primary thread. macOS didn’t complain at the time, but since a not-so-recent release, EndBASIC started crashing on startup. EndBASIC 中的 SDL 图形控制台已经存在多年了,当我最初编写代码时,它在 macOS 上运行正常。不幸的是,虽然我最初的实现将所有图形操作卸载到了一个单独的线程中,但它有一个致命缺陷:那个单独的线程不是主线程。当时 macOS 并没有报错,但从最近的某个版本开始,EndBASIC 开始在启动时崩溃。
Fixing this issue was conceptually easy because the separate threading architecture was already in place, but flipping roles proved to be tricky. In any case, this finally works again as well! 修复这个问题在概念上很简单,因为单独的线程架构已经就位,但转换角色却很棘手。无论如何,它终于又可以正常工作了!
That said, I’ll warn you that running the prebuilt EndBASIC binaries on macOS is kinda annoying. I have not codesigned them because I do not have an Apple Developer certificate, and with every macOS release, it is getting exceedingly more difficult to run unsigned binaries. In my last attempt in macOS Tahoe, you have to approve both running the binary and the bundled shared libraries, one at a time. Windows also shows the same scary warnings about untrusted binaries, but at least it’s easier to bypass them. 话虽如此,我得提醒你,在 macOS 上运行预编译的 EndBASIC 二进制文件有点烦人。我没有对它们进行代码签名,因为我没有 Apple 开发者证书,而且随着 macOS 的每一次发布,运行未签名的二进制文件变得越来越困难。在我最近在 macOS Tahoe 上的尝试中,你必须逐一批准运行二进制文件和捆绑的共享库。Windows 也会显示同样关于不受信任二进制文件的可怕警告,但至少绕过它们更容易。
I understand trusting random binaries from the Internet is a hard pill to swallow, so at the very least let me tell you that the binaries you can download are all produced via GitHub Actions from checked-in code so you have a clear audit trail of where they came from. This was a pain to set up years ago, but I intentionally did it so that you wouldn’t have to trust a “random binary from developer workstation” situation. 我理解信任来自互联网的随机二进制文件很难,所以至少我可以告诉你,你可以下载的二进制文件都是通过 GitHub Actions 从已提交的代码中生成的,因此你有明确的审计追踪来了解它们的来源。几年前设置这个过程很痛苦,但我特意这样做,是为了让你不必去信任那种“来自开发者工作站的随机二进制文件”。
shebang support
Shebang 支持
Another trick up the sleeve is new support for direct execution of EndBASIC binaries in Unix-like systems. Nothing fancy, right? This is table stakes for an interpreter, after all. But nonetheless, it’s a cool new feature! 另一个新招是支持在类 Unix 系统中直接执行 EndBASIC 二进制文件。没什么大不了的,对吧?毕竟,这是解释器的基本要求。但尽管如此,这仍然是一个很酷的新功能!
This was trivial to do in principle, but there was a little wrinkle: some programs may want specific console dimensions and, if you use the common #!/usr/bin/env endbasic shebang, you just cannot specify the console flag because the shebang line can only contain two arguments. I had to implement a secondary mechanism to tune console settings, and of course this was inspired by Emacs’ property line. The shebang can be followed by a magic comment to specify which console to use for a given program so that programs are “standalone”:
原则上这很容易实现,但有一个小麻烦:有些程序可能需要特定的控制台尺寸,如果你使用常见的 #!/usr/bin/env endbasic shebang,你无法指定控制台标志,因为 shebang 行只能包含两个参数。我不得不实现一种辅助机制来调整控制台设置,当然,这受到了 Emacs 属性行的启发。Shebang 后面可以跟一个魔术注释来指定给定程序使用的控制台,从而使程序能够“独立”运行:
#!/usr/bin/env endbasic
REM endbasic cli: console=sdl:resolution=1024x768
I’ll remind you that #!/usr/bin/env is considered harmful (by me, yes).
我要提醒你,#!/usr/bin/env 被认为是危险的(没错,我是这么认为的)。
Here is a little video demonstrating two runnable scripts, one providing a textual interface (same terminal window), and one spawning the graphical console as a separate window: 这里有一个小视频演示了两个可运行脚本,一个提供文本界面(在同一个终端窗口中),另一个将图形控制台作为单独的窗口启动:
Sound, finally
声音,终于来了
And we get to the biggest feature I had been wanting to implement for literally years: sound support. I had been putting it off, thinking that it would be really tedious to plumb through, but then it hit me: audio is just one more output “type” of a console. I didn’t have to implement a brand new abstra… 最后我们来到了我真正想实现多年的最大功能:声音支持。我一直推迟它,认为实现起来会非常繁琐,但后来我突然意识到:音频只是控制台的另一种输出“类型”。我不需要实现一个全新的抽象……