Wednesday, October 28, 2026

Opération HUD

Donc, le grand enseignement de ma dernière scéance de playtesting, c'était "où est-ce que je peux voir combien il me reste de vie". Rien à faire, j'ai beau avoir expliqué aux gens que ce n'est pas encore un jeu, juste une série de salles pour tester les mécaniques, ils veulent tout de même voir une barre de vie, et probablement un compteur de score ou quelque-chose d'approchant qui dise si c'est bien ou pas de ramasser des pommes.

Here be a HUD. Or rather a status screen. That was more or less the thing I had to fix as pointed out by playtesting back in early September. Not as easy as copy-pasting some files from School Rush (that did have a nice one): the "Dreamland" project is still in its infancy and will still frequently need to show the Inspector widget debug screen. So a nice screen like the one you see is only usefull if it can turn into a purple checkerboard full of cryptic digits as soon as I press START.

Le couac, c'est que j'ai encore souvent besoin de cet écran du bas pour Inspector Widget, et ça risque de durer encore un moment. Avec SchoolRush, le livre-qui-dit-tout était arrivé assez tard dans le développement (les 4 niveaux principaux étaient déjà là, ainsi que tous les ennemis complètement codés), parce qu'une fois qu'il est là, tout le reste se retrouve caché. Au point qu'en commençant le travail sur "Dreamland", j'ai commencé à générer systématiquement deux .nds: un avec Inspector Widget et l'autre sans... mais c'est toujours celui "avec" que je fais tourner.

It eventually became a reality, thanks to some time spent locating the function handling "start pressed" and introducing some save-state/restore-state functions around it. And yes, I've been post-poning again and again over the last 2 months. It took a storm that put my Internet access down to "a few minutes/day" to make me focus on it. Hopefully, now the rest of the things that could use fixes and improvement and development will come more easily. 

Je vais donc tenter un truc: j'ai retrouvé les endroits dans le code où on entre et sort d'Inspector Widget et je vais tenter des fonctions "restore/release" du même style que celles que j'utilise dans les éditeurs pour passer d'un écran à l'autre. Tout ça avec un mélange de graphismes de Apple Assault et de School Rush :P Et principalement du code de school rush d'où j'ai retiré tout ce qui avait un lien avec le système multi-couche du livre interactif. ça picote encore un peu aux yeux, mais on peut y lire la quantité de vie qui reste si on est courageux.

Ah, et oui, c'est principalement grâce au fait que je me sois retrouvé sans WiFi pendant ~80% de mon congé de 4 jours :P

Now, saving the background layers configuration was one thing, but the lifebar in SchoolRush was mostly made of sprites and I'd rather keep it that way for Dreamland. But then I ended up spending another weekend's evenings trying to figuring out the why-and-where of completely weird display glitches, where the "bookmark" would be rendered with the wrong graphics, and showing them divided in two.

Par contre, une bonne partie de la fonctionnalité de l'écran de statut est dépendant des sprites. Et j'avais un petit fichier "hud.spr" qui contient juste une page avec tout ce qu'il faut ... Mais comme vous pouvez voir, ça ne marche pas fort. Le premier problème est lié au réglage de granularité: sur l'écran du haut on veut plein de sprites différents et on a 128K pour tout enregistrer mais juste 1024 valeurs possibles. Donc on n'essaie pas de pouvoir adresser chaque tile de sprite individuellement, mais plutôt chaque bloc de 16x16 édité dans SEDS. Rien de ce genre sur l'écran du bas où on aura de toutes façons que 64K au mieux (16K plus probablement). Le moteur devrait pouvoir prendre ça en charge (ne le faisait-il pas pour School Rush ?), mais quand on voit la colonne de moitiés power-ups qui arrive dans la tête de Bilou, ce n'est clairement pas le cas. Les autres sprites en bas de l'écran sont supposé montrer un décompteur de pommes et là aussi, on voit clairement que ça avance quart de sprite par quart de sprite plutôt qu'un sprite entier à la fois.

The reason for that was a bit ridiculous, and after hours of trial, errors and beard scratching, it turned out that changing a single line in the right function made everything work as intended. The key problem was around sprite granularity, a feature of the NDS that allows you to decide whether you'll show up to 64K of graphics with sprites as small as 8x8 pixels, or rather willing to use 128 or 256KB of graphics, but at the expense of using only 16x16 pixel sprites. Whatever you decide, you can only have up to 1024 individual visuals used by your sprites. That's hard-wired by the amount of bits the OAM slots dedicate to the "graphic index". With small hands and feet sprites, I hesitated a lot, but eventually turned up the granularity so I could make full use of the 128KB the main screen was allocated.

But the bottom screen has much less video memory assigned. Only 16K (so that the 4th slice of 128K can be used for better graphics on the main screen), so it doesn't really make sense to enforce 16x16 granularity there. Unfortunately, the code I had wasn't dealing with different values very well. That's how I ended up with half-split sprites (using the wrong pictures) in my first attempts, and I made things even worse by forgetting that the SpritePage::setOAM(index) function would lookup an internal table to know the graphic index to use in the OAM entry.

Mais avant de corriger ça il faut que je comprenne un autre truc louche: seuls les 6 ou 7 premiers sprites sont présents en mémoire pendant que le jeu tourne. Le reste a soit été effacé, soit n'est jamais arrivé en VRAM... Du coup, si j'essaie d'utiliser simplement la même granularité en bas qu'en haut, tout disparaît ^^". 

Et alors que je croyais avoir arrangé tout ça, je me suis retrouvé avec tous les sprites remplacés par des têtes de Bilou ... un petit air de déjà vu ;)

After a few more hours of guru meditation and a couple of outdoor walks, I realised that all computations were already performed as the sprites were first loaded in memory and that trying to "compensate again for sprite granularity" in the small functions used while the game logic runs and asks for a change of graphics for one sprite. The messy picture you see with all bilou heads is what happens if you try to over-compensate ... Curiously enough, top and bottom screen use different functions to update the OAM entries, and (useless) compensation for sprite granularity had already been removed in one of them (top screen), but not for the second (bottom screen). Having things computed at load time not only makes the core loop faster, it also saves us from the annoying question of "which granularity should I use when that SpritePage updates that OAM?" since that information is only available as part of the SpriteSet object ^^".

Au final, il n'y avait pas de code manquant mais bien du code en trop. Et il me restera du nettoyage à faire, parce que trop de fichiers on gardé la trace de tentatives de patch sur des lignes de code qui n'en avaient absolument pas besoin  ^^"
 

 

No comments: