Kaze Emanuar’s Adventures in Mario 64 Optimization: Calculating Sine

I’ve mentioned Kaze Emanuar’s efforts to make the best Mario 64 there can possibly be on its native hardware. He’s compiled it with optimization flags turned on, made its platforming engine much more efficient, and worked hard to minimize cache misses, which was a major source of slowdowns in the game’s code. Under his efforts, he’s gotten the engine running at 60fps (although not yet in a playable version of the original). While these optimizations are not the kind of thing that can keep being found indefinitely, he’s bound to run out of ways to tune up the code, currently he’s still finding new ways to speed it up.

I hope you’re ready for some F-U-N (approximation FUNctions)

He made a Youtube video detailing his most recent optimization find: getting the game’s trigonometric functions executing at their speediest. What is interesting is that the Mario 64 code already uses a couple of tricks to get sine and cosine results in a rapid manner: the game only uses 4096 discrete angles of movement direction, and contains a lookup table that covers each of those angles. But it turns out that this optimization is actually a mis-optimization, because the RAM bus hits incurred to read the values into the cache are actually more expensive than just figuring out the values in code on the N64’s hardware!

The video starts out decently comprehensible, but eventually descends into the process of figuring out sine and cosine on the fly, and the virtues of the various ways this can be done, so you can’t be faulted for bailing before the end, possibly at the moment the dreaded words “Taylor series” are mentioned. But it’s a fairly interesting watch until then!

Youtube Dev’s Experiences Making New Dual-Stick Shooter Roguelite

Helper Wesley on Youtube is making a Binding Of Isaac-style randomized twin stick shooter called Spent Shells, and published it on Newgrounds. It’s on itch.io too. It got about 35,000 plays and an award from the site, which is nice. It also got ripped off and put on a bunch of other sites, which wasn’t. But things seem to be going well with it.

Wesley put up a video with his experiences with its popularity and his attempts to monetize it. It’s only ten minutes, and it’s got a lot of useful information for things to do that might help out your own project, if that’s the kind of thing you do, or just an interesting look at an experience most of us won’t even have.

I Published My Roguelike Game – Dealing With The Aftermath (Youtube, 10 minutes)

Godot 4.0

Godot reaches version 4.0! It’s is the free and open-source multiplatform game development system and engine with the most mojo, and it’s only a 50MB download! Here’s the official list of new features, but here’s some highlights:

  • New rendering options for 2D and 3D, including Vulkan
  • Improved shadows
  • Automatic occlusion culling
  • New 2D level editing tools
  • Many shader improvements
  • Scripting improvements for both GDScript and C#, plus support for extensions written in C, C++ and Rust
  • The return of Godot Physics
  • Support for multiple windows
  • An improved UI editor
  • Improvements to animation
  • Editor support for Android and browsers
  • and exports for several new platforms, including Raspberry Pi and ARM-based Chromebooks.

Turbo Rascal

Turbo Rascal, more fully known as “Turbo Rascal Syntax Error” or TRSE, is a multiplatform game and demo development system, including a compiler, afull IDE and some miscellaneous utilities like an image editor. It’s based on Pascal, which might be annoying to people who have the conventions of C burnt into their brainmeat, but is easier on newbies on the whole, since its language idioms tend to be more readable for intent, and it doesn’t include structures like the ternary operator: (a ==0) ? isequal() : isnotequal();

While it supports a lot of different classic computing devices, TRSE’s “native” platforms, those it has the most support for, are the 8-bit Commodore machines. Using it, you can pretty rapidly put together a program to display an image on the C64’s hi-res screen:

It comes with a lot of example projects too, including a number of technically proficient demos that show off its capabilities. After you install a C64 emulator (VICE is recommended), the following can get up and running in less than a minute:

Turbo Rascal Syntax Error

The Arcade Blogger on the Development of Xevious

December 30th of last year, The Arcade Blogger did a piece on the creation of Namco’s classic vertical shooter Xevious.

Xevious was modestly successful in the US, where it was produced by Atari, but it Japan it did amazing numbers. Jeremy Parish (in his NES Works and related series) has mentioned several times that it was a vastly influential game in Japan, inspiring a whole generation of designers, and a whole bunch of clones and similar games. Its US release was around the time of the arcade crash, which was mostly an American thing. If it hadn’t had happened, maybe now we’d think about Xevious the way we consider Pac-Man.

The team behind Xevious

Xevious basically invented the vertical scrolling shooter where your ship has free movement of the screen. It also included a Bomb button to attack objects on the ground, displayed on the game’s background layer. It was a concept that would later be iterated upon in Konami’s Twinbee games.

Revealed in the article is an interesting fact. The scrolling background is stored in ROM as a huge 1024×2048 bitmapped image. That’s much wider than the screen is though. What the game does is send the player into a vertical portion of it 224 pixels wide.

When the player reaches the top, they wrap around to the bottom of another vertical stripe of the game world. In a complete loop, the player will travel from the bottom to the top 16 times. You can tell when you’re about to start another loop because the background will reach a place with trees all the way across!

You always start off a life in a tree-filled area because it begins you at the bottom of a stripe; each vertical pass over the map functions as a checkpoint. The stripes overlap somewhat, so you sometimes pass over an area you’ve seen before but offset by a bit.

For more facts on Xevious and its development, be sure to click through to the article!

The Arcade Blogger: The Development of Xevious

Classic Game Dev Andrew Braybook On Computer Conversions

Andred Braybrook is a legendary computer game dev from the Commodore 64 age, and before and after. In addition to the classic C64 games Uridium and Paradroid, which perform feats of scrolling that machine are really not designed for, he went on to many several other games, including the excellent computer ports of Taito’s sequel to Bubble Bobble, Rainbow Islands.

(Although Braybrook mentions that Taito hadn’t told him about the three secret islands that can appear at the end, so they got left out. They didn’t know about them either!)

Image from Braybrook’s blog

He has a blog post that details many aspects of he and his co-workers’ process back then that is fascinating to anyone with knowledge of these platforms, and even someone who doesn’t. Thanks to @acb@mastodon.social for the link!

Andrew Braybrook: How We Made Computer Game Conversions, from his blog

Breath of the Wild Cel Shading Break Glitch

The Legend of Zelda: Breath of the Wild is a gigantic game, and where content proliferates, so too do bugs. Many of these bugs are highly entertaining (my favorite is the bullet time bounce), but there are some that are just head-scratching, leaving one to wonder why does this happen? That the occur pulls back the curtain on the many technically complex things a big game like BotW does behind the scenes to realize its world, for, every step of a process that a system must go through is one more opportunity for something to go wrong.

Image from Nintendo Everything

Youtuber Jasper has made a 35 minute video about why, if Link stands in a specific spot in BotW, inside the broken corner of a stone wall, the cel shading usually applied to his model goes away, and he appears with normal light shading. In the way of Youtubers, the explanation is contained within a 35-minute discursive video that goes into the history of game lighting, why some older 3D games have graphics that have aged well while others don’t, the basics of cel shading, and still other topics. Here is that video, embedded:

The whole video is pretty interesting, and if you have the time and interest you should watch the whole thing. However, in the event that this is all tl;dw, allow me to summarize.

  1. Because Breath of the Wild is both a huge game and has a dynamic world, baking lighting in into textures would consume way too much storage and memory, so lighting has to be done dynamically.
  2. As an optimization measure, the more complex steps of cel shading are deferred to later in each frame’s rendering. The main rendering is done, then the cel shading is applied afterward, when the visibility of the area has been determined, so this effort-expensive process is only done for visible pixels.
  3. One of the deferred steps of rendering marks which of nine different kinds of material will be applied to each pixel. Terrain in BotW is not cel shaded, while characters link Link are, so they have different types of material that determine whether that shading is applied to them.
  4. In the location where Link’s cel shading disappears, there is a decal applied to the crumbling bridge that erroneously extends over the corner, and overwrites Link’s character material type with the terrain material, causing the cel shading not to be applied to him.

How Gravity Works in Super Mario Galaxy

Another Youtube video? Yeah I know. This one explains how gravity works in Super Mario Galaxy. It’s 29 minutes long. The basic gist is, there are eight kinds of invisible gravity field objects, based off of simple shapes, in the game, which are used in concert to create the various orientations that Mario switches to as he moves around: Parallel, Sphere, Cube, Disk, Torus, Cylinder, Wedge, Wire (basically an arbitrary path in space), and Cone, which is only used in two places.

An interesting fact from near the end of the video: gravity affects Mario’s shadow! Shadows point towards where Mario will fall, not according to how light strikes him, to give players a sense of where he is spatially in 3D space.

How Spherical Planets Bent the Rules in Super Mario Galaxy (Youtube, 30 minutes)

Super Mario Bros Level Glitches

The Youtube channel Retro Game Mechanics has done a series of three videos on glitches in Super Mario Bros. One involves using the NES game Tennis, which has a certain property of its code that allows you to load all kinds of funky levels in SMB.

They’re all interesting, but the one that floats my particular boat is the third, which turns into a deep dive in the compressed manner that Super Mario Bros. stores its levels in ROM, and uses to draw them during play in real time.

1. Access Glitch Worlds in Super Mario Bros. via NES Tennis (13 minutes)

2. Exploring Glitch Level Pointers In Super Mario Bros. (15 minutes)

3. Super Mario Bros. Glitch Levels Explained (30 minutes — this is the one embedded above)

Roguelike Celebration: Adam Newgas on Constraint-Based Generation

Honestly, I could devote a post to every Roguelike Celebration talk. I’ve been limiting myself to just one such post a week, on Saturdays. This one, a short sixteen minutes talk about terrain generation, is for the developers out there.

Constraint-based generation, also known as “wave function collapse,” is a system where, as objects are placed randomly during generation, the generator “solves” the world around them, placing later terrain as is necessitated by prior terrain. If the generator reaches a contradiction, a situation where there is no viable terrain that can be placed, it undoes the contradictory placement and continues from there.

It’s a technique that’s fairly popular in procedural generation circles, and among other games is used in Caves of Qud. It’s also fun to watch it work!

Metroid Prime’s Save System

Zoid Kirsh on Twitter (while Elon Musk hasn’t completely wrecked it yet) tweeted about how Metroid Prime’s save system works. Metroid Prime save files are less than 60 bytes long! A single Gamecube memory card block is eight kilobytes, so it’s a bit overkill, but it’s still nice when a developer is frugal!

Image, of Metroid Prime’s inventory screen, from Mobygames.

The way they explain it is that the game has a number of “world layers” which determine what is spawned in each area when it’s loaded. Which layer is active when a room is loaded is determined by a single bit in the save. That, plus some basic stats like health and ammo, and the record of object scans, all take up very little memory when bit-packed.

If Metroid Prime’s save file were 59 bytes long, that would mean it had 472 bits to work with. The passwords used by the original Metroid only stored 144 bits of data!

The Issues With NES Teenage Mutant Ninja Turtles

The title refers to the original NES TMNT, not the arcade version or the NES game based on it. This is the version that Konami released under their Ultra label. It sold well (real well!) but is widely considered an inferior game for a number of reasons. Those reasons are the subject of these three videos, from Youtube channel Displaced Gamers. I recommend them, even if I think every place they say gamer it would be more proper to say player.

The first video:

In a long and difficult game, one of the hardest sections comes relatively early. The only swimming section in the entire game, players must maneuver their supposedly-aquatic surrogates through a difficult course that has imprecise movement, water currents, high damage, instant kill hazards, a strict time limit, and, as the video shows, buggy implementation. Many players in the NES era gave up at this point, which is rather a shame considering it’s only at the end of level two. This video examines the code and demonstrates why it’s so challenging, and how it could be made fairer.

The second video:

TMNT has notoriously floaty jumps, a low frame rate, and a fairly weird implementation of gravity. Any platform game that allows players to adjust their jump height according to how long the hold down the jump button is fudging its physics behind the scenes, but TMNT does it rather poorly.

The third video:

Displaced Gamers examines additional problems with the game’s timing, particular with that of its input reading and attack animation. Like the other two videos, they suggest code changes (sometimes in the form of Game Genie codes) that fix the problem, if you happen to have a fondness for 6502 assembly. (I do!)

If you’d like to try NES Teenage Mutant Turtles, it’s included in the “Cowabunga Collection” that was released for Switch, Xbox X/S and Playstations 4 and 5. Fortunately, it also includes twelve much more playable titles.